# HG changeset patch # User unc0rr # Date 1539894849 -7200 # Node ID a325ed57ebfe1afb4755041f955e325e46ee631d # Parent 7e7a03e85ac40c16249c163dbc29e0073a2428dd Don't generate unnecessary duplication in case of equal coordinates diff -r 7e7a03e85ac4 -r a325ed57ebfe rust/integral-geometry/src/lib.rs --- a/rust/integral-geometry/src/lib.rs Thu Oct 18 22:23:25 2018 +0200 +++ b/rust/integral-geometry/src/lib.rs Thu Oct 18 22:34:09 2018 +0200 @@ -170,7 +170,7 @@ pub fn new(vector: Point) -> Self { Self { vector, - iteration: 0, + iteration: if vector.x == vector.y { 4 } else { 8 }, } } } @@ -179,7 +179,7 @@ type Item = Point; fn next(&mut self) -> Option { - if self.iteration < 8 { + if self.iteration > 0 { self.vector.x = -self.vector.x; if self.iteration & 1 == 0 { self.vector.y = -self.vector.y; @@ -189,7 +189,7 @@ std::mem::swap(&mut self.vector.x, &mut self.vector.y); } - self.iteration += 1; + self.iteration -= 1; Some(self.vector) } else { @@ -236,7 +236,7 @@ } #[test] - fn equidistant() { + fn equidistant_full() { let n = EquidistantPoints::new(Point::new(1, 3)); let v = get_points(&[ (-1, -3), @@ -254,4 +254,14 @@ assert_eq!(a, b); } } + + #[test] + fn equidistant_half() { + let n = EquidistantPoints::new(Point::new(2, 2)); + let v = get_points(&[(-2, -2), (2, -2), (-2, 2), (2, 2), (123, 456)]); + + for (&a, b) in v.iter().zip(n) { + assert_eq!(a, b); + } + } } diff -r 7e7a03e85ac4 -r a325ed57ebfe rust/land2d/src/lib.rs --- a/rust/land2d/src/lib.rs Thu Oct 18 22:23:25 2018 +0200 +++ b/rust/land2d/src/lib.rs Thu Oct 18 22:34:09 2018 +0200 @@ -4,7 +4,7 @@ use std::cmp; use std::ops; -use integral_geometry::{Point, LinePoints}; +use integral_geometry::{LinePoints, ArcPoints, Point}; pub struct Land2D { pixels: vec2d::Vec2D, @@ -149,9 +149,15 @@ } pub fn fill_from_iter(&mut self, i: I, value: T) -> usize - where I: std::iter::Iterator + where + I: std::iter::Iterator, { - i.map(|p| self.map(p.y, p.x, |v| {*v = value; 1})).count() + i.map(|p| { + self.map(p.y, p.x, |v| { + *v = value; + 1 + }) + }).count() } pub fn draw_line(&mut self, from: Point, to: Point, value: T) -> usize { @@ -279,9 +285,9 @@ radius: i32, f: F, ) -> usize { - >::apply_around_circle(radius, &mut |dx, dy| { - self.fill_circle_lines(x, y, dx, dy, &f) - }) + ArcPoints::new(radius) + .map(&mut |p: Point| self.fill_circle_lines(x, y, p.x, p.y, &f)) + .sum() } #[inline] @@ -307,13 +313,16 @@ pub fn draw_thick_line( &mut self, - x1: i32, - y1: i32, - x2: i32, - y2: i32, + from: Point, to: Point, radius: i32, value: T, ) -> usize { + for deltas in ArcPoints::new(radius) { + for points in LinePoints::new(from, to) { + + } + } + >::apply_around_circle(radius, &mut |dx, dy| { >::apply_along_line(x1, y1, x2, y2, &mut |x, y| { >::change_dots_around(x, y, dx, dy, &mut |x, y| {