equal
deleted
inserted
replaced
52 .iter() |
52 .iter() |
53 .flat_map(|p| p.iter()) |
53 .flat_map(|p| p.iter()) |
54 .chain(self.fill_points.iter()) |
54 .chain(self.fill_points.iter()) |
55 } |
55 } |
56 |
56 |
57 pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Point> { |
57 pub fn for_each<F>(&mut self, f: F) |
58 self.islands |
58 where F: (Fn(&mut Point)) |
59 .iter_mut() |
59 { |
60 .flat_map(|i| i.iter_mut()) |
60 self.islands.iter_mut().for_each(|p| p.for_each(|x| f(x))); |
61 .chain(self.fill_points.iter_mut()) |
61 self.fill_points.iter_mut().for_each(|p| f(p)); |
62 } |
62 } |
63 |
63 |
64 fn divide_edge<I: Iterator<Item = u32>>( |
64 fn divide_edge<I: Iterator<Item = u32>>( |
65 &self, |
65 &self, |
66 segment: Line, |
66 segment: Line, |
287 self.islands.iter().flat_map(|p| p.iter_edges()) |
287 self.islands.iter().flat_map(|p| p.iter_edges()) |
288 } |
288 } |
289 |
289 |
290 pub fn mirror(&mut self) { |
290 pub fn mirror(&mut self) { |
291 let r = self.size.width as i32 - 1; |
291 let r = self.size.width as i32 - 1; |
292 |
292 self.for_each(|p| p.x = r - p.x); |
293 self.iter_mut().for_each(|p| p.x = r - p.x); |
|
294 } |
293 } |
295 |
294 |
296 pub fn flip(&mut self) { |
295 pub fn flip(&mut self) { |
297 let t = self.size.height as i32 - 1; |
296 let t = self.size.height as i32 - 1; |
298 |
297 self.for_each(|p| p.y = t - p.y); |
299 self.iter_mut().for_each(|p| p.y = t - p.y); |
|
300 } |
298 } |
301 } |
299 } |
302 |
300 |
303 #[test()] |
301 #[test()] |
304 fn points_test() { |
302 fn points_test() { |
321 assert_eq!( |
319 assert_eq!( |
322 segments.last(), |
320 segments.last(), |
323 Some(&Line::new(Point::new(20, 15), Point::new(10, 15))) |
321 Some(&Line::new(Point::new(20, 15), Point::new(10, 15))) |
324 ); |
322 ); |
325 |
323 |
326 points.iter_mut().for_each(|p| p.x = 2); |
324 points.for_each(|p| p.x = 2); |
327 |
325 |
328 assert_eq!(points.fill_points[0].x, 2); |
326 assert_eq!(points.fill_points[0].x, 2); |
329 assert_eq!(points.islands[0].get_edge(0).start.x, 2); |
327 assert_eq!(points.islands[0].get_edge(0).start.x, 2); |
330 } |
328 } |