author | unc0rr |
Sat, 03 Nov 2018 21:09:01 +0100 | |
changeset 14143 | c27461e6a9eb |
parent 14142 | 69db1d2e4cec |
child 14145 | 6e0be42d0a8f |
permissions | -rw-r--r-- |
14090 | 1 |
use itertools::Itertools; |
14102 | 2 |
use std::cmp::min; |
14090 | 3 |
|
14099 | 4 |
use integral_geometry::{Line, Point, Rect, Size}; |
14090 | 5 |
use land2d::Land2D; |
6 |
||
7 |
use outline_template::OutlineTemplate; |
|
8 |
||
9 |
pub struct OutlinePoints { |
|
10 |
pub islands: Vec<Vec<Point>>, |
|
11 |
pub fill_points: Vec<Point>, |
|
12 |
pub size: Size, |
|
14099 | 13 |
pub play_box: Rect, |
14090 | 14 |
} |
15 |
||
16 |
impl OutlinePoints { |
|
17 |
pub fn from_outline_template<I: Iterator<Item = u32>>( |
|
18 |
outline_template: &OutlineTemplate, |
|
14099 | 19 |
play_box: Rect, |
20 |
size: Size, |
|
14090 | 21 |
random_numbers: &mut I, |
22 |
) -> Self { |
|
23 |
Self { |
|
14099 | 24 |
play_box, |
25 |
size, |
|
14090 | 26 |
islands: outline_template |
27 |
.islands |
|
28 |
.iter() |
|
29 |
.map(|i| { |
|
30 |
i.iter() |
|
31 |
.zip(random_numbers.tuples()) |
|
32 |
.map(|(rect, (rnd_a, rnd_b))| { |
|
14099 | 33 |
rect.top_left() |
34 |
+ Point::new( |
|
35 |
(rnd_a % rect.width) as i32, |
|
36 |
(rnd_b % rect.height) as i32, |
|
37 |
) |
|
38 |
+ play_box.top_left() |
|
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
39 |
}) |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
40 |
.collect() |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
41 |
}) |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
42 |
.collect(), |
14090 | 43 |
fill_points: outline_template.fill_points.clone(), |
44 |
} |
|
45 |
} |
|
46 |
||
47 |
pub fn total_len(&self) -> usize { |
|
48 |
self.islands.iter().map(|i| i.len()).sum::<usize>() + self.fill_points.len() |
|
49 |
} |
|
50 |
||
14121 | 51 |
pub fn iter(&self) -> impl Iterator<Item = &Point> { |
52 |
self.islands |
|
53 |
.iter() |
|
54 |
.flat_map(|i| i.iter()) |
|
55 |
.chain(self.fill_points.iter()) |
|
56 |
} |
|
57 |
||
14090 | 58 |
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Point> { |
59 |
self.islands |
|
60 |
.iter_mut() |
|
61 |
.flat_map(|i| i.iter_mut()) |
|
62 |
.chain(self.fill_points.iter_mut()) |
|
63 |
} |
|
64 |
||
65 |
fn divide_edge<I: Iterator<Item = u32>>( |
|
66 |
&self, |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
67 |
segment: Line, |
14121 | 68 |
distance_divisor: u32, |
14090 | 69 |
random_numbers: &mut I, |
70 |
) -> Option<Point> { |
|
14121 | 71 |
#[inline] |
72 |
fn intersect(p: &Point, m: &Point, p1: &Point, p2: &Point) -> bool { |
|
14130 | 73 |
let t1 = (*m - *p1).cross(*p); |
74 |
let t2 = (*m - *p2).cross(*p); |
|
14121 | 75 |
|
76 |
(t1 > 0) != (t2 > 0) |
|
77 |
} |
|
78 |
||
79 |
#[inline] |
|
80 |
fn solve_intersection(p: &Point, m: &Point, s: &Point, e: &Point) -> Option<(i32, u32)> { |
|
81 |
let f = *e - *s; |
|
14129 | 82 |
let aqpb = p.cross(f) as i64; |
14121 | 83 |
|
84 |
if aqpb != 0 { |
|
85 |
let iy = ((((s.x - m.x) as i64 * p.y as i64 + m.y as i64 * p.x as i64) |
|
86 |
* f.y as i64 |
|
87 |
- s.y as i64 * f.x as i64 * p.y as i64) |
|
88 |
/ aqpb) as i32; |
|
89 |
let ix = if p.y.abs() > f.y.abs() { |
|
90 |
(iy - m.y) * p.x / p.y + m.x |
|
91 |
} else { |
|
92 |
(iy - s.y) * f.x / f.y + s.x |
|
93 |
}; |
|
94 |
||
95 |
let intersection_point = Point::new(ix, iy); |
|
96 |
let diff_point = *m - intersection_point; |
|
14129 | 97 |
let t = p.dot(diff_point); |
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
98 |
if diff_point.max_norm() >= std::i16::MAX as i32 { |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
99 |
Some((t, std::i32::MAX as u32)) |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
100 |
} else { |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
101 |
let d = diff_point.integral_norm(); |
14121 | 102 |
|
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
103 |
Some((t, d)) |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
104 |
} |
14121 | 105 |
} else { |
106 |
None |
|
107 |
} |
|
108 |
} |
|
109 |
||
14102 | 110 |
let min_distance = 40; |
111 |
// new point should fall inside this box |
|
112 |
let map_box = self.play_box.with_margin(min_distance); |
|
113 |
||
14128 | 114 |
let p = segment.scaled_normal(); |
14137 | 115 |
let p_norm = p.integral_norm(); |
14102 | 116 |
let mid_point = segment.center(); |
117 |
||
14137 | 118 |
if (p_norm < min_distance as u32 * 3) || !map_box.contains_inside(mid_point) { |
14102 | 119 |
return None; |
120 |
} |
|
121 |
||
122 |
let mut dist_left = (self.size.width + self.size.height) as u32; |
|
123 |
let mut dist_right = dist_left; |
|
124 |
||
125 |
// find distances to map borders |
|
126 |
if p.x != 0 { |
|
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
127 |
// where the normal line intersects the left map border |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
128 |
let left_intersection = Point::new( |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
129 |
map_box.left(), |
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
130 |
(map_box.left() - mid_point.x) * p.y / p.x + mid_point.y, |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
131 |
); |
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
132 |
dist_left = (mid_point - left_intersection).integral_norm(); |
14102 | 133 |
|
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
134 |
// same for the right border |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
135 |
let right_intersection = Point::new( |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
136 |
map_box.right(), |
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
137 |
(map_box.right() - mid_point.x) * p.y / p.x + mid_point.y, |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
138 |
); |
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
139 |
dist_right = (mid_point - right_intersection).integral_norm(); |
14102 | 140 |
|
14132
269f13ac670d
simplify normal direction check for bounds distances
alfadur
parents:
14131
diff
changeset
|
141 |
if p.x > 0 { |
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
142 |
std::mem::swap(&mut dist_left, &mut dist_right); |
14102 | 143 |
} |
144 |
} |
|
145 |
||
146 |
if p.y != 0 { |
|
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
147 |
// where the normal line intersects the top map border |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
148 |
let top_intersection = Point::new( |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
149 |
(map_box.top() - mid_point.y) * p.x / p.y + mid_point.x, |
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
150 |
map_box.top(), |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
151 |
); |
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
152 |
let dl = (mid_point - top_intersection).integral_norm(); |
14102 | 153 |
|
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
154 |
// same for the bottom border |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
155 |
let bottom_intersection = Point::new( |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
156 |
(map_box.bottom() - mid_point.y) * p.x / p.y + mid_point.x, |
14143
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
157 |
map_box.bottom(), |
c27461e6a9eb
Implement non-overflowing calculations for high values
unc0rr
parents:
14142
diff
changeset
|
158 |
); |
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
159 |
let dr = (mid_point - bottom_intersection).integral_norm(); |
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
160 |
|
14132
269f13ac670d
simplify normal direction check for bounds distances
alfadur
parents:
14131
diff
changeset
|
161 |
if p.y < 0 { |
14102 | 162 |
dist_left = min(dist_left, dl); |
163 |
dist_right = min(dist_right, dr); |
|
164 |
} else { |
|
165 |
dist_left = min(dist_left, dr); |
|
14131
21642eb0ff29
import some clarity into border distance computation
alfadur
parents:
14130
diff
changeset
|
166 |
dist_right = min(dist_right, dl); |
14102 | 167 |
} |
168 |
} |
|
169 |
||
170 |
// now go through all other segments |
|
14121 | 171 |
for s in self.segments_iter() { |
172 |
if s != segment { |
|
173 |
if intersect(&p, &mid_point, &s.start, &s.end) { |
|
174 |
if let Some((t, d)) = solve_intersection(&p, &mid_point, &s.start, &s.end) { |
|
175 |
if t > 0 { |
|
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
176 |
dist_right = min(dist_right, d); |
14121 | 177 |
} else { |
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
178 |
dist_left = min(dist_left, d); |
14121 | 179 |
} |
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
14102 | 184 |
|
14121 | 185 |
// go through all points, including fill points |
186 |
for pi in self.iter() { |
|
187 |
if *pi != segment.start && *pi != segment.end { |
|
188 |
if intersect(&p, &pi, &segment.start, &segment.end) { |
|
189 |
// ray from segment.start |
|
190 |
if let Some((t, d)) = solve_intersection(&p, &mid_point, &segment.start, &pi) { |
|
191 |
if t > 0 { |
|
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
192 |
dist_right = min(dist_right, d); |
14121 | 193 |
} else { |
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
194 |
dist_left = min(dist_left, d); |
14121 | 195 |
} |
196 |
} |
|
197 |
||
198 |
// ray from segment.end |
|
199 |
if let Some((t, d)) = solve_intersection(&p, &mid_point, &segment.end, &pi) { |
|
200 |
if t > 0 { |
|
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
201 |
dist_right = min(dist_right, d); |
14121 | 202 |
} else { |
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
203 |
dist_left = min(dist_left, d); |
14121 | 204 |
} |
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
||
14137 | 210 |
let max_dist = p_norm * 100 / distance_divisor; |
14121 | 211 |
dist_left = min(dist_left, max_dist); |
212 |
dist_right = min(dist_right, max_dist); |
|
213 |
||
214 |
if dist_right + dist_left < min_distance as u32 * 2 + 10 { |
|
215 |
// limits are too narrow, just divide |
|
216 |
Some(mid_point) |
|
217 |
} else { |
|
14134
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
218 |
// select distance within [-dist_right; dist_left], keeping min_distance in mind |
be4419243735
fix normal offset for split points and make directions more consistent
alfadur
parents:
14132
diff
changeset
|
219 |
let d = -(dist_right as i32) |
14121 | 220 |
+ min_distance |
221 |
+ random_numbers.next().unwrap() as i32 |
|
222 |
% (dist_right as i32 + dist_left as i32 - min_distance * 2); |
|
223 |
||
224 |
Some(Point::new( |
|
14137 | 225 |
mid_point.x + p.x * d / p_norm as i32, |
226 |
mid_point.y + p.y * d / p_norm as i32, |
|
14121 | 227 |
)) |
228 |
} |
|
14090 | 229 |
} |
230 |
||
14121 | 231 |
fn divide_edges<I: Iterator<Item = u32>>( |
232 |
&mut self, |
|
233 |
distance_divisor: u32, |
|
234 |
random_numbers: &mut I, |
|
235 |
) { |
|
14090 | 236 |
for is in 0..self.islands.len() { |
237 |
let mut i = 0; |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
238 |
let mut segment; |
14090 | 239 |
|
240 |
loop { |
|
241 |
{ |
|
242 |
let island = &self.islands[is]; |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
243 |
let mut end_point; |
14090 | 244 |
if i < island.len() { |
245 |
end_point = if i + 1 < island.len() { |
|
246 |
island[i + 1] |
|
247 |
} else { |
|
248 |
island[0] |
|
249 |
}; |
|
250 |
} else { |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
251 |
break; |
14090 | 252 |
} |
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
253 |
|
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
254 |
segment = Line::new(island[i], end_point); |
14090 | 255 |
} |
256 |
||
14121 | 257 |
if let Some(new_point) = self.divide_edge(segment, distance_divisor, random_numbers) |
258 |
{ |
|
14090 | 259 |
self.islands[is].insert(i + 1, new_point); |
260 |
i += 2; |
|
261 |
} else { |
|
262 |
i += 1; |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
14121 | 268 |
pub fn bezierize(&mut self) {} |
14090 | 269 |
|
14121 | 270 |
pub fn distort<I: Iterator<Item = u32>>( |
271 |
&mut self, |
|
272 |
distance_divisor: u32, |
|
273 |
random_numbers: &mut I, |
|
274 |
) { |
|
14090 | 275 |
loop { |
276 |
let old_len = self.total_len(); |
|
14121 | 277 |
self.divide_edges(distance_divisor, random_numbers); |
14090 | 278 |
|
14114 | 279 |
if self.total_len() == old_len { |
14090 | 280 |
break; |
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
pub fn draw<T: Copy + PartialEq>(&self, land: &mut Land2D<T>, value: T) { |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
286 |
for segment in self.segments_iter() { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
287 |
land.draw_line(segment, value); |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
288 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
289 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
290 |
|
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
291 |
fn segments_iter(&self) -> OutlineSegmentsIterator { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
292 |
OutlineSegmentsIterator { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
293 |
outline: self, |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
294 |
island: 0, |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
295 |
index: 0, |
14090 | 296 |
} |
297 |
} |
|
14116 | 298 |
|
299 |
pub fn mirror(&mut self) { |
|
14121 | 300 |
let r = self.size.width as i32 - 1; |
301 |
||
302 |
self.iter_mut().for_each(|p| p.x = r - p.x); |
|
14116 | 303 |
} |
304 |
||
305 |
pub fn flip(&mut self) { |
|
14121 | 306 |
let t = self.size.height as i32 - 1; |
307 |
||
308 |
self.iter_mut().for_each(|p| p.y = t - p.y); |
|
14116 | 309 |
} |
14090 | 310 |
} |
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
311 |
|
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
312 |
struct OutlineSegmentsIterator<'a> { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
313 |
outline: &'a OutlinePoints, |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
314 |
island: usize, |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
315 |
index: usize, |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
316 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
317 |
|
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
318 |
impl<'a> Iterator for OutlineSegmentsIterator<'a> { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
319 |
type Item = Line; |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
320 |
|
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
321 |
fn next(&mut self) -> Option<Self::Item> { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
322 |
if self.island < self.outline.islands.len() { |
14099 | 323 |
if self.index + 1 < self.outline.islands[self.island].len() { |
324 |
let result = Some(Line::new( |
|
325 |
self.outline.islands[self.island][self.index], |
|
326 |
self.outline.islands[self.island][self.index + 1], |
|
327 |
)); |
|
328 |
||
329 |
self.index += 1; |
|
330 |
||
331 |
result |
|
332 |
} else if self.index + 1 == self.outline.islands[self.island].len() { |
|
333 |
let result = Some(Line::new( |
|
334 |
self.outline.islands[self.island][self.index], |
|
335 |
self.outline.islands[self.island][0], |
|
336 |
)); |
|
337 |
||
338 |
self.island += 1; |
|
339 |
self.index = 0; |
|
340 |
||
341 |
result |
|
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
342 |
} else { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
343 |
self.island += 1; |
14099 | 344 |
self.index = 0; |
14097
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
345 |
self.next() |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
346 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
347 |
} else { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
348 |
None |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
349 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
350 |
} |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14090
diff
changeset
|
351 |
} |
14099 | 352 |
|
353 |
#[test()] |
|
354 |
fn points_test() { |
|
355 |
let mut points = OutlinePoints { |
|
356 |
islands: vec![ |
|
357 |
vec![Point::new(0, 0), Point::new(20, 0), Point::new(30, 30)], |
|
358 |
vec![Point::new(10, 15), Point::new(15, 20), Point::new(20, 15)], |
|
359 |
], |
|
360 |
fill_points: vec![Point::new(1, 1)], |
|
361 |
play_box: Rect::from_box(0, 100, 0, 100).with_margin(10), |
|
362 |
size: Size::square(100), |
|
363 |
}; |
|
364 |
||
365 |
let segments: Vec<Line> = points.segments_iter().collect(); |
|
366 |
assert_eq!( |
|
367 |
segments.first(), |
|
368 |
Some(&Line::new(Point::new(0, 0), Point::new(20, 0))) |
|
369 |
); |
|
370 |
assert_eq!( |
|
371 |
segments.last(), |
|
372 |
Some(&Line::new(Point::new(20, 15), Point::new(10, 15))) |
|
373 |
); |
|
374 |
||
375 |
points.iter_mut().for_each(|p| p.x = 2); |
|
376 |
assert_eq!(points.fill_points[0].x, 2); |
|
377 |
assert_eq!(points.islands[0][0].x, 2); |
|
378 |
} |