--- a/rust/landgen/src/template_based.rs Wed Oct 31 23:36:05 2018 +0100
+++ b/rust/landgen/src/template_based.rs Thu Nov 01 02:55:22 2018 +0300
@@ -1,7 +1,6 @@
use itertools::Itertools;
-use integral_geometry::Point;
-use integral_geometry::Rect;
+use integral_geometry::{Point, Size, Rect};
use land2d::Land2D;
use LandGenerationParameters;
use LandGenerator;
@@ -9,8 +8,7 @@
struct OutlinePoints {
islands: Vec<Vec<Point>>,
fill_points: Vec<Point>,
- width: usize,
- height: usize,
+ size: Size,
}
impl OutlinePoints {
@@ -33,18 +31,14 @@
}).collect()
}).collect(),
fill_points: outline_template.fill_points.clone(),
- width: outline_template.width,
- height: outline_template.height,
+ size: outline_template.size
}
}
- fn for_each<F: Fn(&mut Point)>(&mut self, f: F) {
- self.islands
- .iter_mut()
+ fn iter_mut(&mut self) -> impl Iterator<Item = &mut Point> {
+ self.islands.iter_mut()
.flat_map(|i| i.iter_mut())
.chain(self.fill_points.iter_mut())
- .into_iter()
- .for_each(f);
}
fn distort<I: Iterator<Item = u32>>(&mut self, random_numbers: &mut I) {
@@ -55,8 +49,7 @@
struct OutlineTemplate {
islands: Vec<Vec<Rect>>,
fill_points: Vec<Point>,
- width: usize,
- height: usize,
+ size: Size,
can_flip: bool,
can_invert: bool,
can_mirror: bool,
@@ -82,23 +75,22 @@
let mut points =
OutlinePoints::from_outline_template(&self.outline_template, random_numbers);
- let mut land = Land2D::new(points.width, points.height, parameters.basic);
+ let mut land = Land2D::new(points.size, parameters.basic);
let top_left = Point::new(
(land.width() - land.play_width() / 2) as i32,
(land.height() - land.play_height()) as i32,
);
- points.width = land.width();
- points.height = land.height();
+ points.size = land.size();
- points.for_each(|p| *p += top_left);
+ points.iter_mut().for_each(|p| *p += top_left);
// mirror
if self.outline_template.can_mirror {
if let Some(b) = random_numbers.next() {
if b & 1 != 0 {
- points.for_each(|p| p.x = land.width() as i32 - 1 - p.x);
+ points.iter_mut().for_each(|p| p.x = land.width() as i32 - 1 - p.x);
}
}
}
@@ -107,7 +99,8 @@
if self.outline_template.can_flip {
if let Some(b) = random_numbers.next() {
if b & 1 != 0 {
- points.for_each(|p| p.y = land.height() as i32 - 1 - p.y);
+ points.iter_mut().for_each(|p|
+ p.y = land.height() as i32 - 1 - p.y);
}
}
}
@@ -131,10 +124,9 @@
let mut points = OutlinePoints {
islands: vec![vec![]],
fill_points: vec![Point::new(1, 1)],
- width: 100,
- height: 100,
+ size: Size::square(100)
};
- points.for_each(|p| p.x = 2);
+ points.iter_mut().for_each(|p| p.x = 2);
assert_eq!(points.fill_points[0].x, 2);
}