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
use crate::datatypes::Vec3D;

use super::Position3D;

// ---

impl Position3D {
    /// The origin.
    pub const ZERO: Self = Self::new(0.0, 0.0, 0.0);

    /// Create a new position.
    #[inline]
    pub const fn new(x: f32, y: f32, z: f32) -> Self {
        Self(Vec3D::new(x, y, z))
    }

    /// The x coordinate, i.e. index 0
    #[inline]
    pub fn x(&self) -> f32 {
        self.0.x()
    }

    /// The y coordinate, i.e. index 1
    #[inline]
    pub fn y(&self) -> f32 {
        self.0.y()
    }

    /// The z coordinate, i.e. index 2
    #[inline]
    pub fn z(&self) -> f32 {
        self.0.z()
    }
}

#[cfg(feature = "glam")]
impl From<Position3D> for glam::Vec3 {
    #[inline]
    fn from(pt: Position3D) -> Self {
        Self::new(pt.x(), pt.y(), pt.z())
    }
}

#[cfg(feature = "mint")]
impl From<Position3D> for mint::Point3<f32> {
    #[inline]
    fn from(position: Position3D) -> Self {
        Self {
            x: position.x(),
            y: position.y(),
            z: position.z(),
        }
    }
}

#[cfg(feature = "mint")]
impl From<mint::Point3<f32>> for Position3D {
    #[inline]
    fn from(position: mint::Point3<f32>) -> Self {
        Self(Vec3D([position.x, position.y, position.z]))
    }
}