manifold3d_types/math/
point2.rs1use manifold3d_sys::ManifoldVec2;
2use std::ops::{Add, Sub};
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub struct Point2 {
6 pub x: f64,
7 pub y: f64,
8}
9
10impl Point2 {
11 pub fn new(x: f64, y: f64) -> Self {
12 Self { x, y }
13 }
14}
15
16impl From<ManifoldVec2> for Point2 {
17 fn from(value: ManifoldVec2) -> Self {
18 Point2 {
19 x: value.x,
20 y: value.y,
21 }
22 }
23}
24
25impl From<Point2> for ManifoldVec2 {
26 fn from(value: Point2) -> Self {
27 ManifoldVec2 {
28 x: value.x,
29 y: value.y,
30 }
31 }
32}
33
34impl Add for Point2 {
35 type Output = Self;
36
37 fn add(self, rhs: Self) -> Self::Output {
38 Point2::new(self.x + rhs.x, self.y + rhs.y)
39 }
40}
41
42impl<T> Add<T> for Point2
43where
44 f64: From<T>,
45 T: num_traits::ToPrimitive,
46{
47 type Output = Self;
48
49 fn add(self, rhs: T) -> Self::Output {
50 let value = f64::from(rhs);
51 Point2::new(self.x + value, self.y + value)
52 }
53}
54
55impl Sub for Point2 {
56 type Output = Self;
57
58 fn sub(self, rhs: Self) -> Self::Output {
59 Point2::new(self.x - rhs.x, self.y - rhs.y)
60 }
61}
62
63impl<T> Sub<T> for Point2
64where
65 f64: From<T>,
66 T: num_traits::ToPrimitive,
67{
68 type Output = Self;
69
70 fn sub(self, rhs: T) -> Self::Output {
71 let value = f64::from(rhs);
72 Point2::new(self.x - value, self.y - value)
73 }
74}