utiles_core/
point.rs

1//! 2d/3d points
2use std::fmt::Debug;
3use std::ops::{Add, Sub};
4
5use serde::{Deserialize, Serialize};
6
7/// Point2d struct for 2d points
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub struct Point2d<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> {
10    /// x value
11    pub x: T,
12
13    /// y value
14    pub y: T,
15}
16
17/// Point3d struct for 3d points
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
19pub struct Point3d<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> {
20    /// x value
21    pub x: T,
22
23    /// y value
24    pub y: T,
25
26    /// z value
27    pub z: T,
28}
29
30impl<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> Point2d<T> {
31    /// Create a new `Point2d`
32    pub fn new(x: T, y: T) -> Self {
33        Point2d { x, y }
34    }
35
36    /// Return the x value
37    pub fn x(&self) -> T {
38        self.x
39    }
40
41    /// Return the y value
42    pub fn y(&self) -> T {
43        self.y
44    }
45}
46
47impl<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> Point3d<T> {
48    /// Create a new `Point3d`
49    pub fn new(x: T, y: T, z: T) -> Self {
50        Point3d { x, y, z }
51    }
52
53    /// Return the x value
54    pub fn x(&self) -> T {
55        self.x
56    }
57
58    /// Return the y value
59    pub fn y(&self) -> T {
60        self.y
61    }
62
63    /// Return the z value
64    pub fn z(&self) -> T {
65        self.z
66    }
67}