```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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
```
``````use crate::Vec2;

/// 2D vector with single precision.
///
/// The components are laid out in this order: `[x, y]`. This struct is aligned to 4 bytes, not 8.
///
/// This struct is here for consistency and does not explicitly use SIMD instructions.
/// Internally, it is just an array of two floats.
///
/// ## Examples
///
/// ```
/// use mafs::{Vec2, Fvec2};
///
/// // Construction
/// let a = Fvec2::new(2.0, 3.0);
/// let b = Fvec2::new(6.0, 9.0);
/// let c = Fvec2::splat(0.0); // Set all four components to the same value
///
/// // Arithmetics
/// assert_eq!(a + b, Fvec2::new(8.0, 12.0));
/// assert_eq!(a - b, Fvec2::new(-4.0, -6.0));
/// assert_eq!(a * b, Fvec2::new(12.0, 27.0));
/// assert_eq!(b / a, Fvec2::new(3.0, 3.0));
///
/// // Euclidian norm
/// assert_eq!(a.norm(), 13.0f32.sqrt());
/// assert_eq!(a.normalize().norm(), 1.0);
///
/// // Specialized operations
/// assert_eq!(a.dot(b), 39.0);
/// assert_eq!(b.dot(a), a.dot(b));
/// assert_eq!(Fvec2::new(-0.5, 0.5).floor(), Fvec2::new(-1.0, 0.0));
///
/// // Comparisons
/// assert_eq!(a.min_componentwise(b), Fvec2::new(2.0, 3.0));
/// assert_eq!(a.max_componentwise(b), Fvec2::new(6.0, 9.0));
///
/// // Reduction
/// assert_eq!(a.min_reduce(), 2.0);
/// assert_eq!(b.max_reduce(), 9.0);
/// ```
#[repr(C)]
#[derive(Copy, Clone)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
pub struct Fvec2 {
pub(crate) inner: [f32; 2],
}

impl std::fmt::Debug for Fvec2 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.as_array().fmt(f)
}
}

impl Vec2<f32> for Fvec2 {
#[inline]
fn new(x: f32, y: f32) -> Fvec2 {
Fvec2 { inner: [x, y] }
}

#[inline]
fn as_array(&self) -> &[f32; 2] {
&self.inner
}

#[inline]
fn as_mut_array(&mut self) -> &mut [f32; 2] {
&mut self.inner
}

#[inline]
fn add_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [self.inner[0] + rhs.inner[0], self.inner[1] + rhs.inner[1]],
}
}

#[inline]
fn sub_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [self.inner[0] - rhs.inner[0], self.inner[1] - rhs.inner[1]],
}
}

#[inline]
fn mul_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [self.inner[0] * rhs.inner[0], self.inner[1] * rhs.inner[1]],
}
}

#[inline]
fn div_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [self.inner[0] / rhs.inner[0], self.inner[1] / rhs.inner[1]],
}
}

#[inline]
fn min_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [
self.inner[0].min(rhs.inner[0]),
self.inner[1].min(rhs.inner[1]),
],
}
}

#[inline]
fn max_componentwise(&self, rhs: Fvec2) -> Fvec2 {
Fvec2 {
inner: [
self.inner[0].max(rhs.inner[0]),
self.inner[1].max(rhs.inner[1]),
],
}
}

#[inline]
fn floor(&self) -> Fvec2 {
Fvec2 {
inner: [self.inner[0].floor(), self.inner[1].floor()],
}
}

#[inline]
fn min_reduce(&self) -> f32 {
self.inner[0].min(self.inner[1])
}

#[inline]
fn max_reduce(&self) -> f32 {
self.inner[0].max(self.inner[1])
}

#[inline]
fn eq_reduce(&self, rhs: Fvec2) -> bool {
self.inner[0] == rhs.inner[0] && self.inner[1] == rhs.inner[1]
}

#[inline]
fn dot(&self, rhs: Fvec2) -> f32 {
self.inner[0] * rhs.inner[0] + self.inner[1] * rhs.inner[1]
}
}

implement_scalarops!(Fvec2, f32);
implement_vecops!(Fvec2, f32);
``````