operator == method
equal operation
Implementation
@override
bool operator ==(other) {
if (other is! BaseProjectivePointNative) {
return false;
}
// Extract coordinates for the current point.
final BigInt x1 = _coords[0];
final BigInt y1 = _coords[1];
final BigInt z1 = _coords[2];
// Get the prime field modulus from the curve.
final p = curve.p;
// Calculate the square of z1 modulo p.
final zz1 = (z1 * z1) % p;
// If 'other' represents an infinity point, check if this point is also at infinity.
if (other.isZero()) {
return y1 == BigInt.zero || z1 == BigInt.zero;
}
// Extract coordinates for 'other' point.
BigInt x2;
BigInt y2;
BigInt z2;
if (other is ProjectivAffinePoint) {
x2 = other.x;
y2 = other.y;
z2 = BigInt.one;
} else if (other is ProjectiveECCPoint) {
x2 = other._coords[0];
y2 = other._coords[1];
z2 = other._coords[2];
} else {
return false;
}
// Ensure both points belong to the same curve.
if (curve != other.curve) {
return false;
}
// Calculate the square of z2 modulo p.
final zz2 = (z2 * z2) % p;
// Check if the points are equal in projective coordinates.
return ((x1 * zz2 - x2 * zz1) % p == BigInt.zero) &&
((y1 * zz2 * z2 - y2 * zz1 * z1) % p == BigInt.zero);
}