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
#![no_std]
mod range;
mod ray;
mod rect;
mod vec2;
#[cfg(feature = "std")]
pub use roots;
pub use num_traits;
pub use partial_min_max;
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(Eq,PartialEq,Copy, Clone,Debug)]
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(Eq,PartialEq,Copy, Clone,Debug)]
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
}
}
#[derive(Eq,PartialEq,Copy,Clone,Debug)]
pub enum AxisDyn{
X(XAXIS),
Y(YAXIS)
}
impl AxisDyn{
#[inline(always)]
pub fn is_axis(self)->bool{
match self{
AxisDyn::X(_)=>{
true
},
AxisDyn::Y(_)=>{
false
}
}
}
#[inline(always)]
pub fn map_val<T>(self,val1:T,val2:T)->T{
match self{
AxisDyn::X(_)=>{
val1
},
AxisDyn::Y(_)=>{
val2
}
}
}
#[inline(always)]
pub fn map<T>(self,func1:impl FnOnce(XAXIS)->T,func2:impl FnOnce(YAXIS)->T)->T{
match self{
AxisDyn::X(a)=>{
func1(a)
},
AxisDyn::Y(b)=>{
func2(b)
}
}
}
}
pub trait Axis: Sync + Send + Copy + Clone {
type Next: Axis;
fn is_xaxis(&self) -> bool;
fn next(&self) -> Self::Next;
#[inline(always)]
fn to_dyn(&self)->AxisDyn{
if self.is_xaxis(){
AxisDyn::X(XAXIS)
}else{
AxisDyn::Y(YAXIS)
}
}
#[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
}
}