Skip to content

Commit

Permalink
tighten CCW (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish authored Jul 30, 2023
1 parent ffdd97d commit 7c454dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utilities/include/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ inline HOST_DEVICE int CCW(glm::vec2 p0, glm::vec2 p1, glm::vec2 p2,
glm::vec2 v2 = p2 - p0;
float area = v1.x * v2.y - v1.y * v2.x;
float base2 = glm::max(glm::dot(v1, v1), glm::dot(v2, v2));
if (area * area <= base2 * tol * tol)
if (area * area * 4 <= base2 * tol * tol)
return 0;
else
return area > 0 ? 1 : -1;
Expand Down
17 changes: 17 additions & 0 deletions test/polygon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ TEST(Polygon, ColinearY) {
TestPoly(polys, 16);
}

TEST(Polygon, NearlyColinearY) {
Polygons polys;
polys.push_back({
{3.5, 0}, //
{3.0, 0.5}, //
{3.0, 0.0144}, //
{2.0, 0.4}, //
{1.8, 0.1}, //
{1.6, 0.0155}, //
{1.5, 0.0147}, //
{1.4, 0.0144}, //
{1.0, 0.1}, //
{0, 0}, //
});
TestPoly(polys, 8, 0.001);
}

TEST(Polygon, Concave) {
Polygons polys;
polys.push_back({
Expand Down

0 comments on commit 7c454dc

Please sign in to comment.