@@ -27,6 +27,10 @@ pub enum Division {
27
27
OneThousandTwentyFourth ,
28
28
}
29
29
30
+ const HIGHEST_ZOOM_STEP : u8 = 10 ;
31
+
32
+
33
+
30
34
impl Division {
31
35
32
36
pub fn from_isize < T : ToPrimitive > ( num : T ) -> Division {
@@ -50,6 +54,21 @@ impl Division {
50
54
}
51
55
}
52
56
57
+ /// Zoom into a higher resolution division by the number of steps given.
58
+ pub fn zoom_in ( & self , steps : u8 ) -> Division {
59
+ let zoom_step = self . to_u8 ( ) . unwrap ( ) + steps;
60
+ assert ! ( zoom_step <= HIGHEST_ZOOM_STEP ) ;
61
+ NumCast :: from ( zoom_step) . unwrap ( )
62
+ }
63
+
64
+ /// Zoom into a higher resolution division by the number of steps given.
65
+ pub fn zoom_out ( & self , steps : u8 ) -> Division {
66
+ let current_zoom_step = self . to_u8 ( ) . unwrap ( ) ;
67
+ assert ! ( steps <= current_zoom_step) ;
68
+ let zoom_step = current_zoom_step - steps;
69
+ NumCast :: from ( zoom_step) . unwrap ( )
70
+ }
71
+
53
72
}
54
73
55
74
impl NumCast for Division {
@@ -112,11 +131,11 @@ impl Sub<isize> for Division {
112
131
}
113
132
114
133
/// The 'Division Type'. Used for handling 'Thirds'.
115
- /// Whole represents a Whole division, while TwoThirds
116
- /// represents two thirds of a division.
134
+ /// Whole represents a Whole division, while TwoThirds represents two thirds of a division.
117
135
#[ derive( Debug , Copy , Clone , RustcEncodable , RustcDecodable , PartialEq , Eq ) ]
118
136
pub enum DivType {
119
- Whole , TwoThirds
137
+ Whole ,
138
+ TwoThirds ,
120
139
}
121
140
122
141
@@ -132,6 +151,13 @@ impl NumCast for DivType {
132
151
}
133
152
}
134
153
154
+ impl :: rand:: Rand for DivType {
155
+ fn rand < R : :: rand:: Rng > ( rng : & mut R ) -> DivType {
156
+ let rand: bool = rng. gen ( ) ;
157
+ if rand { DivType :: Whole } else { DivType :: TwoThirds }
158
+ }
159
+ }
160
+
135
161
impl FromPrimitive for DivType {
136
162
fn from_i64 ( n : i64 ) -> Option < Self > { Self :: from_u64 ( n as u64 ) }
137
163
fn from_u64 ( n : u64 ) -> Option < Self > {
0 commit comments