re_types/components/
texcoord2d_ext.rs

1use crate::datatypes::Vec2D;
2
3use super::Texcoord2D;
4
5// ---
6
7impl Texcoord2D {
8    /// The origin.
9    pub const ZERO: Self = Self::new(0.0, 0.0);
10
11    /// The corner opposite the origin.
12    pub const ONE: Self = Self::new(1.0, 1.0);
13
14    /// Create a new texture coordinate.
15    #[inline]
16    pub const fn new(u: f32, v: f32) -> Self {
17        Self(Vec2D::new(u, v))
18    }
19
20    /// The first coordinate, i.e. index 0.
21    #[inline]
22    pub fn u(&self) -> f32 {
23        self.0.x()
24    }
25
26    /// The second coordinate, i.e. index 1.
27    #[inline]
28    pub fn v(&self) -> f32 {
29        self.0.y()
30    }
31}
32
33#[cfg(feature = "glam")]
34impl From<Texcoord2D> for glam::Vec2 {
35    #[inline]
36    fn from(pt: Texcoord2D) -> Self {
37        Self::new(pt.u(), pt.v())
38    }
39}
40
41#[cfg(feature = "mint")]
42impl From<Texcoord2D> for mint::Point2<f32> {
43    #[inline]
44    fn from(position: Texcoord2D) -> Self {
45        Self {
46            x: position.u(),
47            y: position.v(),
48        }
49    }
50}
51
52#[cfg(feature = "mint")]
53impl From<mint::Point2<f32>> for Texcoord2D {
54    #[inline]
55    fn from(position: mint::Point2<f32>) -> Self {
56        Self(Vec2D([position.x, position.y]))
57    }
58}