operator + method

Implementation

@override
BaseProjectivePointNative operator +(BaseProjectivePointNative other) {
  if (isZero()) {
    return other;
  }
  if (other.isZero()) {
    return this;
  }
  final point = switch (other) {
    final ProjectiveECCPoint point => point,
    _ => ProjectiveECCPoint.fromAffine(other),
  };
  // Get the prime field value
  final BigInt primeField = curve.p;

  // Extract coordinates of the first point
  final BigInt x1 = _coords[0];
  final BigInt y1 = _coords[1];
  final BigInt z1 = _coords[2];

  // Extract coordinates of the second point
  final BigInt x2 = point._coords[0];
  final BigInt y2 = point._coords[1];
  final BigInt z2 = point._coords[2];

  // Perform point addition
  final List<BigInt> result = _addPoints(x1, y1, z1, x2, y2, z2, primeField);

  final BigInt x3 = result[0];
  final BigInt y3 = result[1];
  final BigInt z3 = result[2];

  if (y3 == BigInt.zero || z3 == BigInt.zero) {
    return ProjectiveECCPoint.infinity(curve);
  }

  return ProjectiveECCPoint._(curve, [x3, y3, z3], order: order);
}