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 for_each<F>(&mut self, f: F) |
57 pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Point> { |
58 where F: (Fn(&mut Point)) |
58 self.islands |
59 { |
59 .iter_mut() |
60 self.islands.iter_mut().for_each(|p| p.for_each(|x| f(x))); |
60 .flat_map(|i| i.iter_mut()) |
61 self.fill_points.iter_mut().for_each(|p| f(p)); |
61 .chain(self.fill_points.iter_mut()) |
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 self.for_each(|p| p.x = r - p.x); |
292 |
|
293 self.iter_mut().for_each(|p| p.x = r - p.x); |
293 } |
294 } |
294 |
295 |
295 pub fn flip(&mut self) { |
296 pub fn flip(&mut self) { |
296 let t = self.size.height as i32 - 1; |
297 let t = self.size.height as i32 - 1; |
297 self.for_each(|p| p.y = t - p.y); |
298 |
|
299 self.iter_mut().for_each(|p| p.y = t - p.y); |
298 } |
300 } |
299 } |
301 } |
300 |
302 |
301 #[test()] |
303 #[test()] |
302 fn points_test() { |
304 fn points_test() { |
319 assert_eq!( |
321 assert_eq!( |
320 segments.last(), |
322 segments.last(), |
321 Some(&Line::new(Point::new(20, 15), Point::new(10, 15))) |
323 Some(&Line::new(Point::new(20, 15), Point::new(10, 15))) |
322 ); |
324 ); |
323 |
325 |
324 points.for_each(|p| p.x = 2); |
326 points.iter_mut().for_each(|p| p.x = 2); |
325 |
327 |
326 assert_eq!(points.fill_points[0].x, 2); |
328 assert_eq!(points.fill_points[0].x, 2); |
327 assert_eq!(points.islands[0].get_edge(0).start.x, 2); |
329 assert_eq!(points.islands[0].get_edge(0).start.x, 2); |
328 } |
330 } |