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
mod range;
mod rect;
pub use self::range::Range;
pub use self::rect::Rect;
#[derive(Copy,Clone)]
pub struct XAXISS;
impl AxisTrait for XAXISS{
type Next=YAXISS;
#[inline(always)]
fn is_xaxis(&self)->bool{
true
}
#[inline(always)]
fn next(&self)->Self::Next{
YAXISS
}
}
#[derive(Copy,Clone)]
pub struct YAXISS;
impl AxisTrait for YAXISS{
type Next=XAXISS;
#[inline(always)]
fn is_xaxis(&self)->bool{
false
}
#[inline(always)]
fn next(&self)->Self::Next{
XAXISS
}
}
pub trait AxisTrait:Sync+Send+Copy+Clone{
type Next:AxisTrait;
fn is_xaxis(&self)->bool;
fn next(&self)->Self::Next;
#[inline(always)]
fn is_equal_to<B:AxisTrait>(&self,other:B)->bool{
if self.is_xaxis() && other.is_xaxis(){
return true;
}
if !self.is_xaxis() && !other.is_xaxis(){
return true;
}
return false;
}
}
pub struct AxisWrapRef<'a,T:'a>(pub &'a [T;2]);
impl<'a,T:'a> AxisWrapRef<'a,T>{
pub fn get<A:AxisTrait>(&self,axis:A)->&'a T{
if axis.is_xaxis(){
&self.0[0]
}else{
&self.0[1]
}
}
}