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
use super::*;

/// Two-dimensional vector: `x` and `y`.
///
/// Internally, this is two `f32` values.
#[derive(Debug, Clone, Copy)]
pub struct Vec2 {
  x: f32,
  y: f32,
}
unsafe impl Zeroable for Vec2 {}
unsafe impl Pod for Vec2 {}
impl Default for Vec2 {
  fn default() -> Self {
    Self::zeroed()
  }
}
impl From<[f32; 2]> for Vec2 {
  fn from(val: [f32; 2]) -> Self {
    Self {
      x: val[0],
      y: val[1],
    }
  }
}
impl From<(f32, f32)> for Vec2 {
  fn from(val: (f32, f32)) -> Self {
    Self { x: val.0, y: val.1 }
  }
}
impl Vec2 {
  /// `x` component
  pub fn x(self) -> f32 {
    self.x
  }
  /// `x` component unique reference
  pub fn x_mut(&mut self) -> &mut f32 {
    &mut self.x
  }
  /// `y` component
  pub fn y(self) -> f32 {
    self.y
  }
  /// `y` component unique reference
  pub fn y_mut(&mut self) -> &mut f32 {
    &mut self.y
  }
  /// Swizzle: `xx`
  pub fn xx(self) -> Self {
    Self {
      x: self.x,
      y: self.x,
    }
  }
  /// Swizzle: `xy`
  pub fn xy(self) -> Self {
    self
  }
  /// Swizzle: `yx`
  pub fn yx(self) -> Self {
    Self {
      x: self.y,
      y: self.x,
    }
  }
  /// Swizzle: `yy`
  pub fn yy(self) -> Self {
    Self {
      x: self.y,
      y: self.y,
    }
  }

  /// Component-wise absolute value.
  pub fn abs(self) -> Self {
    Self {
      x: lokacore::abs_f32(self.x),
      y: lokacore::abs_f32(self.y),
    }
  }
}