manifold3d_types/math/
point3.rs1use manifold3d_sys::ManifoldVec3;
2use std::ops::{Add, Sub};
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub struct Point3 {
6 pub x: f64,
7 pub y: f64,
8 pub z: f64,
9}
10
11impl Point3 {
12 pub fn new(x: f64, y: f64, z: f64) -> Self {
13 Self { x, y, z }
14 }
15}
16
17impl From<ManifoldVec3> for Point3 {
18 fn from(value: ManifoldVec3) -> Self {
19 Point3 {
20 x: value.x,
21 y: value.y,
22 z: value.z,
23 }
24 }
25}
26
27impl From<Point3> for ManifoldVec3 {
28 fn from(value: Point3) -> Self {
29 ManifoldVec3 {
30 x: value.x,
31 y: value.y,
32 z: value.z,
33 }
34 }
35}
36
37impl Add for Point3 {
38 type Output = Self;
39
40 fn add(self, rhs: Self) -> Self::Output {
41 Point3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
42 }
43}
44
45impl<T> Add<T> for Point3
46where
47 f64: From<T>,
48 T: num_traits::ToPrimitive,
49{
50 type Output = Self;
51
52 fn add(self, rhs: T) -> Self::Output {
53 let value = f64::from(rhs);
54 Point3::new(self.x + value, self.y + value, self.z + value)
55 }
56}
57
58impl Sub for Point3 {
59 type Output = Self;
60
61 fn sub(self, rhs: Self) -> Self::Output {
62 Point3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
63 }
64}
65
66impl<T> Sub<T> for Point3
67where
68 f64: From<T>,
69 T: num_traits::ToPrimitive,
70{
71 type Output = Self;
72
73 fn sub(self, rhs: T) -> Self::Output {
74 let value = f64::from(rhs);
75 Point3::new(self.x - value, self.y - value, self.z - value)
76 }
77}
78
79#[cfg(feature = "nalgebra_interop")]
80impl From<nalgebra::Point3<f64>> for Point3 {
81 fn from(value: nalgebra::Point3<f64>) -> Self {
82 Point3 {
83 x: value.x,
84 y: value.y,
85 z: value.z,
86 }
87 }
88}
89
90#[cfg(feature = "nalgebra_interop")]
91impl From<Point3> for nalgebra::Point3<f64> {
92 fn from(value: Point3) -> Self {
93 nalgebra::Point3::new(value.x, value.y, value.z)
94 }
95}