equal
deleted
inserted
replaced
2 extern crate vec2d; |
2 extern crate vec2d; |
3 |
3 |
4 use std::cmp; |
4 use std::cmp; |
5 use std::ops; |
5 use std::ops; |
6 |
6 |
7 use integral_geometry::{Point, LinePoints}; |
7 use integral_geometry::{LinePoints, ArcPoints, Point}; |
8 |
8 |
9 pub struct Land2D<T> { |
9 pub struct Land2D<T> { |
10 pixels: vec2d::Vec2D<T>, |
10 pixels: vec2d::Vec2D<T>, |
11 width_mask: usize, |
11 width_mask: usize, |
12 height_mask: usize, |
12 height_mask: usize, |
147 |
147 |
148 result |
148 result |
149 } |
149 } |
150 |
150 |
151 pub fn fill_from_iter<I>(&mut self, i: I, value: T) -> usize |
151 pub fn fill_from_iter<I>(&mut self, i: I, value: T) -> usize |
152 where I: std::iter::Iterator<Item = Point> |
152 where |
|
153 I: std::iter::Iterator<Item = Point>, |
153 { |
154 { |
154 i.map(|p| self.map(p.y, p.x, |v| {*v = value; 1})).count() |
155 i.map(|p| { |
|
156 self.map(p.y, p.x, |v| { |
|
157 *v = value; |
|
158 1 |
|
159 }) |
|
160 }).count() |
155 } |
161 } |
156 |
162 |
157 pub fn draw_line(&mut self, from: Point, to: Point, value: T) -> usize { |
163 pub fn draw_line(&mut self, from: Point, to: Point, value: T) -> usize { |
158 self.fill_from_iter(LinePoints::new(from, to), value) |
164 self.fill_from_iter(LinePoints::new(from, to), value) |
159 } |
165 } |
277 x: i32, |
283 x: i32, |
278 y: i32, |
284 y: i32, |
279 radius: i32, |
285 radius: i32, |
280 f: F, |
286 f: F, |
281 ) -> usize { |
287 ) -> usize { |
282 <Land2D<T>>::apply_around_circle(radius, &mut |dx, dy| { |
288 ArcPoints::new(radius) |
283 self.fill_circle_lines(x, y, dx, dy, &f) |
289 .map(&mut |p: Point| self.fill_circle_lines(x, y, p.x, p.y, &f)) |
284 }) |
290 .sum() |
285 } |
291 } |
286 |
292 |
287 #[inline] |
293 #[inline] |
288 fn change_dots_around<U: Default + ops::AddAssign, F: FnMut(i32, i32) -> U>( |
294 fn change_dots_around<U: Default + ops::AddAssign, F: FnMut(i32, i32) -> U>( |
289 x: i32, |
295 x: i32, |
305 result |
311 result |
306 } |
312 } |
307 |
313 |
308 pub fn draw_thick_line( |
314 pub fn draw_thick_line( |
309 &mut self, |
315 &mut self, |
310 x1: i32, |
316 from: Point, to: Point, |
311 y1: i32, |
|
312 x2: i32, |
|
313 y2: i32, |
|
314 radius: i32, |
317 radius: i32, |
315 value: T, |
318 value: T, |
316 ) -> usize { |
319 ) -> usize { |
|
320 for deltas in ArcPoints::new(radius) { |
|
321 for points in LinePoints::new(from, to) { |
|
322 |
|
323 } |
|
324 } |
|
325 |
317 <Land2D<T>>::apply_around_circle(radius, &mut |dx, dy| { |
326 <Land2D<T>>::apply_around_circle(radius, &mut |dx, dy| { |
318 <Land2D<T>>::apply_along_line(x1, y1, x2, y2, &mut |x, y| { |
327 <Land2D<T>>::apply_along_line(x1, y1, x2, y2, &mut |x, y| { |
319 <Land2D<T>>::change_dots_around(x, y, dx, dy, &mut |x, y| { |
328 <Land2D<T>>::change_dots_around(x, y, dx, dy, &mut |x, y| { |
320 self.map(x, y, |p| { |
329 self.map(x, y, |p| { |
321 if *p != value { |
330 if *p != value { |