Skip to content

Commit 7c454dc

Browse files
authored
tighten CCW (#508)
1 parent ffdd97d commit 7c454dc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/utilities/include/public.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ inline HOST_DEVICE int CCW(glm::vec2 p0, glm::vec2 p1, glm::vec2 p2,
106106
glm::vec2 v2 = p2 - p0;
107107
float area = v1.x * v2.y - v1.y * v2.x;
108108
float base2 = glm::max(glm::dot(v1, v1), glm::dot(v2, v2));
109-
if (area * area <= base2 * tol * tol)
109+
if (area * area * 4 <= base2 * tol * tol)
110110
return 0;
111111
else
112112
return area > 0 ? 1 : -1;

test/polygon_test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ TEST(Polygon, ColinearY) {
301301
TestPoly(polys, 16);
302302
}
303303

304+
TEST(Polygon, NearlyColinearY) {
305+
Polygons polys;
306+
polys.push_back({
307+
{3.5, 0}, //
308+
{3.0, 0.5}, //
309+
{3.0, 0.0144}, //
310+
{2.0, 0.4}, //
311+
{1.8, 0.1}, //
312+
{1.6, 0.0155}, //
313+
{1.5, 0.0147}, //
314+
{1.4, 0.0144}, //
315+
{1.0, 0.1}, //
316+
{0, 0}, //
317+
});
318+
TestPoly(polys, 8, 0.001);
319+
}
320+
304321
TEST(Polygon, Concave) {
305322
Polygons polys;
306323
polys.push_back({

0 commit comments

Comments
 (0)