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
#[cfg(all(not(feature = "std"), feature = "no-std-float"))]
use crate::NoStdFloat;
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Default, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
impl f32x2 {
pub fn new(a: f32, b: f32) -> f32x2 {
f32x2([a, b])
}
pub fn splat(x: f32) -> f32x2 {
f32x2([x, x])
}
pub fn abs(self) -> f32x2 {
f32x2([
self.x().abs(),
self.y().abs(),
])
}
pub fn min(self, other: f32x2) -> f32x2 {
f32x2([
self.x().min(other.x()),
self.y().min(other.y()),
])
}
pub fn max(self, other: f32x2) -> f32x2 {
f32x2([
self.x().max(other.x()),
self.y().max(other.y()),
])
}
pub fn max_component(self) -> f32 {
self.x().max(self.y())
}
pub fn x(&self) -> f32 { self.0[0] }
pub fn y(&self) -> f32 { self.0[1] }
}
impl core::ops::Add<f32x2> for f32x2 {
type Output = f32x2;
fn add(self, other: f32x2) -> f32x2 {
f32x2([
self.x() + other.x(),
self.y() + other.y(),
])
}
}
impl core::ops::Sub<f32x2> for f32x2 {
type Output = f32x2;
fn sub(self, other: f32x2) -> f32x2 {
f32x2([
self.x() - other.x(),
self.y() - other.y(),
])
}
}
impl core::ops::Mul<f32x2> for f32x2 {
type Output = f32x2;
fn mul(self, other: f32x2) -> f32x2 {
f32x2([
self.x() * other.x(),
self.y() * other.y(),
])
}
}
impl core::ops::Div<f32x2> for f32x2 {
type Output = f32x2;
fn div(self, other: f32x2) -> f32x2 {
f32x2([
self.x() / other.x(),
self.y() / other.y(),
])
}
}