|
|
@ -275,7 +275,7 @@ where T: Add<Output = T> + Sub<Output = T> + Div<Output = T> |
|
|
+ Debug + Copy + From<i32> {
|
|
|
+ Debug + Copy + From<i32> {
|
|
|
|
|
|
|
|
|
fn new(p :&'a Polygon<T>, direction :Direction) -> Self {
|
|
|
fn new(p :&'a Polygon<T>, direction :Direction) -> Self {
|
|
|
let top = p.vert_min();
|
|
|
|
|
|
|
|
|
let top = p.vert_min(direction);
|
|
|
let next = p.next_y(top, direction);
|
|
|
let next = p.next_y(top, direction);
|
|
|
let edge = match next {
|
|
|
let edge = match next {
|
|
|
None => None,
|
|
|
None => None,
|
|
|
@ -330,7 +330,7 @@ where T: Add<Output = T> + Sub<Output = T> + Div<Output = T> |
|
|
impl<T> Polygon<T>
|
|
|
impl<T> Polygon<T>
|
|
|
where T: Add<Output = T> + Sub<Output = T> + Div<Output = T>
|
|
|
where T: Add<Output = T> + Sub<Output = T> + Div<Output = T>
|
|
|
+ Copy + Debug + From<i32> {
|
|
|
+ Copy + Debug + From<i32> {
|
|
|
fn vert_min<'a>(&'a self) -> usize {
|
|
|
|
|
|
|
|
|
fn vert_min<'a>(&'a self, d :Direction) -> usize {
|
|
|
let Polygon(Coordinates(cs)) = self;
|
|
|
let Polygon(Coordinates(cs)) = self;
|
|
|
|
|
|
|
|
|
type ICoord<'a,T> = (usize, &'a Coordinate<T>);
|
|
|
type ICoord<'a,T> = (usize, &'a Coordinate<T>);
|
|
|
@ -341,7 +341,12 @@ where T: Add<Output = T> + Sub<Output = T> + Div<Output = T> |
|
|
Some(a) => {
|
|
|
Some(a) => {
|
|
|
let Coordinate(_, ay, _) = a.1;
|
|
|
let Coordinate(_, ay, _) = a.1;
|
|
|
let Coordinate(_, xy, _) = x.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<Output = T> + Sub<Output = T> + Div<Output = T> |
|
|
cmp::Ordering::Less => None,
|
|
|
cmp::Ordering::Less => None,
|
|
|
// TODO On equal we need to find out which one of both to
|
|
|
// TODO On equal we need to find out which one of both to
|
|
|
// keep in the list… (the outermost)
|
|
|
// 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::Equal => inner(p, c, p.step(n, d), d),
|
|
|
cmp::Ordering::Greater => Some(n),
|
|
|
cmp::Ordering::Greater => Some(n),
|
|
|
}
|
|
|
}
|
|
|
|