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
#![no_std]
mod range;
mod ray;
mod rect;
mod vec2;
pub use roots;
pub use num_traits;
pub use ordered_float;
pub use primitive_from;
pub use self::range::range;
pub use self::range::Range;
pub use self::ray::ray;
pub use self::ray::CastResult;
pub use self::ray::Ray;
pub use self::rect::rect;
pub use self::rect::Rect;
pub use self::vec2::arr2_as;
pub use self::vec2::vec2;
pub use self::vec2::vec2same;
pub use self::vec2::Vec2;
#[derive(Copy, Clone)]
pub struct XAXIS;
impl Axis for XAXIS {
type Next = YAXIS;
#[inline(always)]
#[must_use]
fn is_xaxis(&self) -> bool {
true
}
#[inline(always)]
#[must_use]
fn next(&self) -> Self::Next {
YAXIS
}
}
#[derive(Copy, Clone)]
pub struct YAXIS;
impl Axis for YAXIS {
type Next = XAXIS;
#[inline(always)]
#[must_use]
fn is_xaxis(&self) -> bool {
false
}
#[inline(always)]
#[must_use]
fn next(&self) -> Self::Next {
XAXIS
}
}
pub trait Axis: Sync + Send + Copy + Clone {
type Next: Axis;
fn is_xaxis(&self) -> bool;
fn next(&self) -> Self::Next;
#[inline(always)]
#[must_use]
fn is_equal_to<B: Axis>(&self, other: B) -> bool {
if self.is_xaxis() && other.is_xaxis() {
return true;
}
if !self.is_xaxis() && !other.is_xaxis() {
return true;
}
false
}
}
#[derive(Copy, Clone, Debug)]
pub struct FixedAspectVec2 {
pub ratio: AspectRatio,
pub width: f64,
}
impl FixedAspectVec2 {
#[inline(always)]
#[must_use]
pub fn as_vec(&self) -> Vec2<f64> {
let height = self.ratio.height_over_width() * self.width;
vec2(self.width, height)
}
}
#[derive(Copy, Clone, Debug)]
pub struct AspectRatio(pub Vec2<f64>);
impl AspectRatio {
#[inline(always)]
#[must_use]
pub fn width_over_height(&self) -> f64 {
let v = self.0;
v.x as f64 / v.y as f64
}
#[inline(always)]
#[must_use]
pub fn height_over_width(&self) -> f64 {
let v = self.0;
v.y as f64 / v.x as f64
}
}