use crate::ff::FiniteField;
use std::fmt::{Debug, Formatter, Result};
#[derive(Clone)]
pub struct Point<K: FiniteField + Clone> {
pub x: K,
pub z: K,
}
impl<K: FiniteField + Clone + Debug> Debug for Point<K> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "({:?}:{:?})", self.x, self.z)
}
}
impl<K: FiniteField + Clone> Point<K> {
#[inline]
pub fn from_x(x: K) -> Self {
Self { x, z: K::one() }
}
}
impl<K: FiniteField + Clone> PartialEq<Self> for Point<K> {
fn eq(&self, other: &Self) -> bool {
let other_zero = other.z.is_zero();
if self.z.is_zero() {
other_zero
} else if other_zero {
false
} else {
let ratio = self.x.div(&self.z).unwrap();
let other_ratio = &other.x.div(&other.z).unwrap();
ratio.equals(&other_ratio)
}
}
}