openvm_ecc_guest/
affine_point.rs
1use core::ops::Neg;
2
3use openvm_algebra_guest::Field;
4
5#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
6#[repr(C)]
7pub struct AffinePoint<F> {
8 pub x: F,
9 pub y: F,
10}
11
12impl<F: Field> AffinePoint<F> {
13 pub const fn new(x: F, y: F) -> Self {
14 Self { x, y }
15 }
16
17 pub fn neg_borrow<'a>(&'a self) -> Self
18 where
19 &'a F: Neg<Output = F>,
20 {
21 Self {
22 x: self.x.clone(),
23 y: Neg::neg(&self.y),
24 }
25 }
26
27 pub fn is_infinity(&self) -> bool {
28 self.x == F::ZERO && self.y == F::ZERO
29 }
30}
31
32impl<F> Neg for AffinePoint<F>
34where
35 F: Neg<Output = F>,
36{
37 type Output = AffinePoint<F>;
38
39 fn neg(self) -> AffinePoint<F> {
40 Self {
41 x: self.x,
42 y: self.y.neg(),
43 }
44 }
45}