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

use super::Texcoord2D;

// ---

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

    /// The corner opposite the origin.
    pub const ONE: Self = Self::new(1.0, 1.0);

    /// Create a new texture coordinate.
    #[inline]
    pub const fn new(u: f32, v: f32) -> Self {
        Self(Vec2D::new(u, v))
    }

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

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

#[cfg(feature = "glam")]
impl From<Texcoord2D> for glam::Vec2 {
    #[inline]
    fn from(pt: Texcoord2D) -> Self {
        Self::new(pt.u(), pt.v())
    }
}

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

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