aboutsummaryrefslogtreecommitdiff
path: root/src/math/polygon/polygon_graph.rs
diff options
context:
space:
mode:
authorArne Dußin2020-11-24 11:41:33 +0100
committerArne Dußin2020-11-24 11:41:33 +0100
commite3f5f944ed90fa7fb96ad2b670ea34c0765df1ad (patch)
tree4b83288cd1d1e8b5b0a65f000ed0eb5b6896486e /src/math/polygon/polygon_graph.rs
parente62275d90d3ebf379e8ab268cb77d8eaf6d1cf07 (diff)
downloadgraf_karto-e3f5f944ed90fa7fb96ad2b670ea34c0765df1ad.tar.gz
graf_karto-e3f5f944ed90fa7fb96ad2b670ea34c0765df1ad.zip
Fix polygon corners not always running counterclockwise
Diffstat (limited to 'src/math/polygon/polygon_graph.rs')
-rw-r--r--src/math/polygon/polygon_graph.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/math/polygon/polygon_graph.rs b/src/math/polygon/polygon_graph.rs
index 9477fbc..6fdb6cd 100644
--- a/src/math/polygon/polygon_graph.rs
+++ b/src/math/polygon/polygon_graph.rs
@@ -261,7 +261,7 @@ impl<T: Scalar + Copy + PartialOrd> PolygonGraph<T> {
let mut current_node = &self.nodes[0];
// Pretend we're coming from the top to start in the right direction.
let mut last_vec = current_node.vec - Vec2::new(T::zero(), T::one());
- let mut bounding_polygon = Polygon::new(vec![current_node.vec]);
+ let mut bounding_corners = vec![current_node.vec];
loop {
/* Find the next point by choosing the one with the greatest angle. This means we are
* "bending" to the leftmost edge at each step. Since we are going around the polygon
@@ -281,17 +281,17 @@ impl<T: Scalar + Copy + PartialOrd> PolygonGraph<T> {
.expect("Adjacency list is empty. The polygon has an open edge (is broken)");
// When we have come back to the start, the traversal is completed
- if *next_corner == bounding_polygon.corners[0] {
+ if *next_corner == bounding_corners[0] {
break;
}
- bounding_polygon.corners.push(*next_corner);
+ bounding_corners.push(*next_corner);
last_vec = current_node.vec;
current_node = &self.nodes[find_node(&self.nodes, &next_corner)
.expect("Failure to find node that should be inside list.")];
}
- bounding_polygon
+ Polygon::new(bounding_corners)
}
}
@@ -433,15 +433,15 @@ mod test {
assert_eq!(
bounding.corners[(start_i + 1) % num_corners],
- Vec2::new(2., 0.)
+ Vec2::new(0., 2.)
);
assert_eq!(
bounding.corners[(start_i + 2) % num_corners],
- Vec2::new(2.5, -0.5)
+ Vec2::new(2., 2.)
);
assert_eq!(
bounding.corners[(start_i + 3) % num_corners],
- Vec2::new(2.5, 0.0)
+ Vec2::new(3., 1.)
);
assert_eq!(
bounding.corners[(start_i + 4) % num_corners],
@@ -449,15 +449,15 @@ mod test {
);
assert_eq!(
bounding.corners[(start_i + 5) % num_corners],
- Vec2::new(3., 1.)
+ Vec2::new(2.5, 0.0)
);
assert_eq!(
bounding.corners[(start_i + 6) % num_corners],
- Vec2::new(2., 2.)
+ Vec2::new(2.5, -0.5)
);
assert_eq!(
bounding.corners[(start_i + 7) % num_corners],
- Vec2::new(0., 2.)
+ Vec2::new(2., 0.)
);
}
}