1 use itertools::Itertools; |
1 use itertools::Itertools; |
2 use std::cmp::min; |
2 use std::cmp::min; |
3 |
3 |
4 use integral_geometry::{Line, Ray, Point, Polygon, Rect, RectInclusive, Size}; |
4 use integral_geometry::{Line, Ray, Point, Polygon, Rect, Size}; |
5 use land2d::Land2D; |
5 use land2d::Land2D; |
6 |
6 |
7 use outline_template::OutlineTemplate; |
7 use outline_template::OutlineTemplate; |
8 |
8 |
9 pub struct OutlinePoints { |
9 pub struct OutlinePoints { |
10 pub islands: Vec<Polygon>, |
10 pub islands: Vec<Polygon>, |
11 pub fill_points: Vec<Point>, |
11 pub fill_points: Vec<Point>, |
12 pub size: Size, |
12 pub size: Size, |
13 pub play_box: RectInclusive, |
13 pub play_box: Rect, |
14 intersections_box: RectInclusive, |
14 intersections_box: Rect, |
15 } |
15 } |
16 |
16 |
17 impl OutlinePoints { |
17 impl OutlinePoints { |
18 pub fn from_outline_template<I: Iterator<Item = u32>>( |
18 pub fn from_outline_template<I: Iterator<Item = u32>>( |
19 outline_template: &OutlineTemplate, |
19 outline_template: &OutlineTemplate, |
20 play_box: RectInclusive, |
20 play_box: Rect, |
21 size: Size, |
21 size: Size, |
22 random_numbers: &mut I, |
22 random_numbers: &mut I, |
23 ) -> Self { |
23 ) -> Self { |
24 Self { |
24 Self { |
25 play_box, |
25 play_box, |
29 .iter() |
29 .iter() |
30 .map(|i| { |
30 .map(|i| { |
31 i.iter() |
31 i.iter() |
32 .zip(random_numbers.tuples()) |
32 .zip(random_numbers.tuples()) |
33 .map(|(rect, (rnd_a, rnd_b))| { |
33 .map(|(rect, (rnd_a, rnd_b))| { |
34 play_box.top_left() + rect.quotient(rnd_a, rnd_b) |
34 play_box.top_left() + rect.quotient(rnd_a as usize, rnd_b as usize) |
35 }) |
35 }) |
36 .collect::<Vec<_>>() |
36 .collect::<Vec<_>>() |
37 .into() |
37 .into() |
38 }) |
38 }) |
39 .collect(), |
39 .collect(), |
40 fill_points: outline_template.fill_points.clone(), |
40 fill_points: outline_template.fill_points.clone(), |
41 intersections_box: RectInclusive::at_origin(size) |
41 intersections_box: Rect::at_origin(size) |
42 .with_margin(size.to_square().width as i32 * -2), |
42 .with_margin(size.to_square().width as i32 * -2), |
43 } |
43 } |
44 } |
44 } |
45 |
45 |
46 pub fn total_len(&self) -> usize { |
46 pub fn total_len(&self) -> usize { |
72 ray.orientation(edge.start) != ray.orientation(edge.end) |
72 ray.orientation(edge.start) != ray.orientation(edge.end) |
73 } |
73 } |
74 |
74 |
75 #[inline] |
75 #[inline] |
76 fn solve_intersection( |
76 fn solve_intersection( |
77 intersections_box: &RectInclusive, |
77 intersections_box: &Rect, |
78 ray: &Ray, |
78 ray: &Ray, |
79 edge: &Line |
79 edge: &Line |
80 ) -> Option<(i32, u32)> |
80 ) -> Option<(i32, u32)> |
81 { |
81 { |
82 let edge_dir = edge.scaled_direction(); |
82 let edge_dir = edge.scaled_direction(); |
311 islands: vec![ |
311 islands: vec![ |
312 Polygon::new(&[Point::new(0, 0), Point::new(20, 0), Point::new(30, 30)]), |
312 Polygon::new(&[Point::new(0, 0), Point::new(20, 0), Point::new(30, 30)]), |
313 Polygon::new(&[Point::new(10, 15), Point::new(15, 20), Point::new(20, 15)]), |
313 Polygon::new(&[Point::new(10, 15), Point::new(15, 20), Point::new(20, 15)]), |
314 ], |
314 ], |
315 fill_points: vec![Point::new(1, 1)], |
315 fill_points: vec![Point::new(1, 1)], |
316 play_box: RectInclusive::at_origin(size).with_margin(10), |
316 play_box: Rect::at_origin(size).with_margin(10), |
317 size: Size::square(100), |
317 size: Size::square(100), |
318 intersections_box: RectInclusive::at_origin(size), |
318 intersections_box: Rect::at_origin(size), |
319 }; |
319 }; |
320 |
320 |
321 let segments: Vec<Line> = points.segments_iter().collect(); |
321 let segments: Vec<Line> = points.segments_iter().collect(); |
322 assert_eq!( |
322 assert_eq!( |
323 segments.first(), |
323 segments.first(), |