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
//!	A library that provides a way to easily extract 1d ranges from a 2d container based off of the x or y axis statically through
//! type parameters. This is useful if you have a function that operates on an axis that recursively calls itself but at the same time alternates its axis. Also provides useful functions that operate on types that implement Ord such as grow_to_fit().


mod range;
mod rect;

pub use self::range::Range;
pub use self::rect::Rect;

///The x axis implementation of the AxisTrait
#[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
    }
}

///The y axis implementation of the AxisTrait
#[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
    }
}

///Axis trait can be used to extract the x or y portions of a container.
///when you know the axis as compile time.
///The X implementation of this trait's Next associated trait is the Y implementation.
///The Y implementation of this trait's Next associated trait is the X implementation. 
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;
        }
        false
    }
}


///A wrapper around an array that lets you extract the x and y components using the AxisTrait.
pub struct AxisWrapRef<'a,T:'a>(pub &'a [T;2]);
impl<'a,T:'a> AxisWrapRef<'a,T>{
    #[inline(always)]
    pub fn get<A:AxisTrait>(&self,axis:A)->&'a T{
        if axis.is_xaxis(){
            &self.0[0]
        }else{
            &self.0[1]
        }
    }
}