1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use num_traits::Num;

use crate::Point;

// Type
pub type Point3D<N> = Point<N, 4>;

// Methods
impl<N: Copy + Num> Point3D<N> {
    /// Returns ref on x element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// assert_eq!(point!{ x: 1, y: 2, z: 3 }.x(), &1);
    /// ```
    #[inline]
    pub fn x(&self) -> &N {
        &self[0]
    }

    /// Returns mutable ref on x element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// let mut v = point!{ x: 1, y: 2, z: 3 };
    /// *v.x_mut() = 5;
    ///
    /// assert_eq!(v.x(), &5);
    /// ```
    #[inline]
    pub fn x_mut(&mut self) -> &mut N {
        &mut self[0]
    }

    /// Returns ref on y element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// assert_eq!(point!{ x: 1, y: 2, z: 3 }.y(), &2);
    /// ```
    #[inline]
    pub fn y(&self) -> &N {
        &self[1]
    }

    /// Returns mutable ref on y element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// let mut v = point!{ x: 1, y: 2, z: 3 };
    /// *v.y_mut() = 5;
    ///
    /// assert_eq!(v.y(), &5);
    /// ```
    #[inline]
    pub fn y_mut(&mut self) -> &mut N {
        &mut self[1]
    }

    /// Returns ref on z element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// assert_eq!(point!{ x: 1, y: 2, z: 3 }.z(), &3);
    /// ```
    #[inline]
    pub fn z(&self) -> &N {
        &self[2]
    }

    /// Returns mutable ref on z element of point
    ///
    /// ## Example
    /// ```
    /// use pythagore::point;
    ///
    /// let mut v = point!{ x: 1, y: 2, z: 3 };
    /// *v.z_mut() = 5;
    ///
    /// assert_eq!(v.z(), &5);
    /// ```
    #[inline]
    pub fn z_mut(&mut self) -> &mut N {
        &mut self[2]
    }
}