From e5a7533fad6f7f22b6ecef0e2ae5cc3032950fa7 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Wed, 8 Jan 2020 20:00:09 +0100 Subject: [PATCH] Start fixing vertex order --- fractional/src/easel.rs | 21 ++++++++++++++++++--- fractional/src/main.rs | 5 +++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fractional/src/easel.rs b/fractional/src/easel.rs index cb87ea0..16973f9 100644 --- a/fractional/src/easel.rs +++ b/fractional/src/easel.rs @@ -275,7 +275,7 @@ where T: Add + Sub + Div + Debug + Copy + From { fn new(p :&'a Polygon, direction :Direction) -> Self { - let top = p.vert_min(); + let top = p.vert_min(direction); let next = p.next_y(top, direction); let edge = match next { None => None, @@ -330,7 +330,7 @@ where T: Add + Sub + Div impl Polygon where T: Add + Sub + Div + Copy + Debug + From { - fn vert_min<'a>(&'a self) -> usize { + fn vert_min<'a>(&'a self, d :Direction) -> usize { let Polygon(Coordinates(cs)) = self; type ICoord<'a,T> = (usize, &'a Coordinate); @@ -341,7 +341,12 @@ where T: Add + Sub + Div Some(a) => { let Coordinate(_, ay, _) = a.1; let Coordinate(_, xy, _) = x.1; - if xy < ay {Some(x)} else {Some(a)} + match d { + Direction::Left => + if xy < ay {Some(x)} else {Some(a)}, + Direction::Right => + if xy <= ay {Some(x)} else {Some(a)}, + } }, }; @@ -401,6 +406,16 @@ where T: Add + Sub + Div cmp::Ordering::Less => None, // TODO On equal we need to find out which one of both to // keep in the list… (the outermost) + // But how can we find the outermost... + // I think it depends on the previous and next one + // which means this might not be best suited for + // a recursive approach...we could keep both... + // Anyway, it looks like this is only a problem + // for the first vertex so maybe it is enough + // to choose the correct one when starting which + // would be in the vert_min method. + // Well, after adding some logic to vert_min it + // seems it is also relevant for the last one. cmp::Ordering::Equal => inner(p, c, p.step(n, d), d), cmp::Ordering::Greater => Some(n), } diff --git a/fractional/src/main.rs b/fractional/src/main.rs index afe19e9..92f1652 100644 --- a/fractional/src/main.rs +++ b/fractional/src/main.rs @@ -342,8 +342,9 @@ fn _democanvas( xcb :&XcbEasel let rot1 = TMatrix::combine(vec!(rz, rx, t)); let rot2 = TMatrix::combine(vec!(rz, ry, t)); - let objects = vec!( (tetrahedron.transform(&rot1), 0xFFFF00) - , ( cube.transform(&rot2), 0x0000FF) ); + let objects = vec!( (tetrahedron.transform(&rot1), 0xFFFF00) ); + //let objects = vec!( (tetrahedron.transform(&rot1), 0xFFFF00) + // , ( cube.transform(&rot2), 0x0000FF) ); //let objects = vec!( (triangle.transform(&rot1), 0xFFFF00) ); >::clear(&mut canvas);