branch | transitional_engine |
changeset 15933 | 33798b649d9c |
parent 15930 | f39f0f614dbf |
child 15934 | 022ec6b916b7 |
15932:230dc46487ea | 15933:33798b649d9c |
---|---|
1 use std::{cmp, ops::Index, ops::IndexMut}; |
1 use std::{cmp, ops::Index, ops::IndexMut}; |
2 |
2 use vec2d::Vec2D; |
3 use integral_geometry::{ArcPoints, EquidistantPoints, Line, Point, PotSize, Rect, Size, SizeMask}; |
3 use integral_geometry::{ArcPoints, EquidistantPoints, Line, Point, PotSize, Rect, Size, SizeMask}; |
4 |
4 |
5 pub struct Land2D<T> { |
5 pub struct Land2D<T> { |
6 pixels: vec2d::Vec2D<T>, |
6 pixels: vec2d::Vec2D<T>, |
7 play_box: Rect, |
7 play_box: Rect, |
293 fn index_mut(&mut self, row: usize) -> &mut [T] { |
293 fn index_mut(&mut self, row: usize) -> &mut [T] { |
294 &mut self.pixels[row] |
294 &mut self.pixels[row] |
295 } |
295 } |
296 } |
296 } |
297 |
297 |
298 impl<T> From<Vec2D<T>> for Land2D<T> { |
|
299 fn from(vec: Vec2D<T>) -> Self { |
|
300 let actual_size = vec.size(); |
|
301 let pot_size = actual_size.next_power_of_two(); |
|
302 |
|
303 assert_eq!(actual_size, pot_size.size()); |
|
304 |
|
305 let top_left = Point::new(0, 0); |
|
306 let play_box = Rect::from_size(top_left, actual_size); |
|
307 Self { |
|
308 play_box, |
|
309 pixels: vec, |
|
310 mask: pot_size.to_mask(), |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
298 #[cfg(test)] |
315 #[cfg(test)] |
299 mod tests { |
316 mod tests { |
300 use super::*; |
317 use super::*; |
301 |
318 |
302 #[test] |
319 #[test] |