46 pub fn size(&self) -> PotSize { |
46 pub fn size(&self) -> PotSize { |
47 self.mask.to_size() |
47 self.mask.to_size() |
48 } |
48 } |
49 |
49 |
50 #[inline] |
50 #[inline] |
51 pub fn play_width(&self) -> usize { |
51 pub fn play_width(&self) -> u32 { |
52 self.play_box.width() |
52 self.play_box.width() |
53 } |
53 } |
54 |
54 |
55 #[inline] |
55 #[inline] |
56 pub fn play_height(&self) -> usize { |
56 pub fn play_height(&self) -> u32 { |
57 self.play_box.height() |
57 self.play_box.height() |
58 } |
58 } |
59 |
59 |
60 #[inline] |
60 #[inline] |
61 pub fn play_size(&self) -> Size { |
61 pub fn play_size(&self) -> Size { |
67 self.play_box |
67 self.play_box |
68 } |
68 } |
69 |
69 |
70 #[inline] |
70 #[inline] |
71 pub fn is_valid_x(&self, x: i32) -> bool { |
71 pub fn is_valid_x(&self, x: i32) -> bool { |
72 self.mask.contains_x(x as usize) |
72 self.mask.contains_x(x as u32) |
73 } |
73 } |
74 |
74 |
75 #[inline] |
75 #[inline] |
76 pub fn is_valid_y(&self, y: i32) -> bool { |
76 pub fn is_valid_y(&self, y: i32) -> bool { |
77 self.mask.contains_y(y as usize) |
77 self.mask.contains_y(y as u32) |
78 } |
78 } |
79 |
79 |
80 #[inline] |
80 #[inline] |
81 pub fn is_valid_coordinate(&self, x: i32, y: i32) -> bool { |
81 pub fn is_valid_coordinate(&self, x: i32, y: i32) -> bool { |
82 self.is_valid_x(x) && self.is_valid_y(y) |
82 self.is_valid_x(x) && self.is_valid_y(y) |
148 xr: usize, |
148 xr: usize, |
149 y: usize, |
149 y: usize, |
150 dir: isize, |
150 dir: isize, |
151 ) { |
151 ) { |
152 let yd = y as isize + dir; |
152 let yd = y as isize + dir; |
153 if mask.contains_y(yd as usize) { |
153 if mask.contains_y(yd as u32) { |
154 stack.push((xl, xr, yd as usize, dir)); |
154 stack.push((xl, xr, yd as usize, dir)); |
155 } |
155 } |
156 } |
156 } |
157 |
157 |
158 let start_x_l = (start_point.x - 1) as usize; |
158 let start_x_l = (start_point.x - 1) as usize; |
329 mod tests { |
329 mod tests { |
330 use super::*; |
330 use super::*; |
331 |
331 |
332 #[test] |
332 #[test] |
333 fn basics() { |
333 fn basics() { |
334 let l: Land2D<u8> = Land2D::new(Size::new(30, 50), 0); |
334 let l: Land2D<u8> = Land2D::new(&Size::new(30, 50), 0); |
335 |
335 |
336 assert_eq!(l.play_width(), 30); |
336 assert_eq!(l.play_width(), 30); |
337 assert_eq!(l.play_height(), 50); |
337 assert_eq!(l.play_height(), 50); |
338 assert_eq!(l.width(), 32); |
338 assert_eq!(l.width(), 32); |
339 assert_eq!(l.height(), 64); |
339 assert_eq!(l.height(), 64); |
346 assert!(!l.is_valid_coordinate(31, 64)); |
346 assert!(!l.is_valid_coordinate(31, 64)); |
347 } |
347 } |
348 |
348 |
349 #[test] |
349 #[test] |
350 fn fill() { |
350 fn fill() { |
351 let mut l: Land2D<u8> = Land2D::new(Size::square(128), 0); |
351 let mut l: Land2D<u8> = Land2D::new(&Size::square(128), 0); |
352 |
352 |
353 l.draw_line(Line::new(Point::new(0, 0), Point::new(32, 96)), 1); |
353 l.draw_line(Line::new(Point::new(0, 0), Point::new(32, 96)), 1); |
354 l.draw_line(Line::new(Point::new(32, 96), Point::new(64, 32)), 1); |
354 l.draw_line(Line::new(Point::new(32, 96), Point::new(64, 32)), 1); |
355 l.draw_line(Line::new(Point::new(64, 32), Point::new(96, 80)), 1); |
355 l.draw_line(Line::new(Point::new(64, 32), Point::new(96, 80)), 1); |
356 l.draw_line(Line::new(Point::new(96, 80), Point::new(128, 0)), 1); |
356 l.draw_line(Line::new(Point::new(96, 80), Point::new(128, 0)), 1); |