Skip to content

Commit cd921a8

Browse files
committed
Added float triangle for angle testing
1 parent 89920b4 commit cd921a8

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

olcUTIL_Geometry2D.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,9 @@ namespace olc::utils::geom2d
28512851
std::reverse(returnPolygon.edges.begin(), returnPolygon.edges.end());
28522852
}
28532853

2854-
while (indexList.size() > 3)
2854+
uint32_t loopCounter = 1000;
2855+
2856+
while (indexList.size() > 3 && loopCounter > 0)
28552857
{
28562858
for (size_t i = 0; i < indexList.size(); i++)
28572859
{
@@ -2864,10 +2866,10 @@ namespace olc::utils::geom2d
28642866
thisTriangle.pos[1] = returnPolygon.pos[b];
28652867
thisTriangle.pos[2] = returnPolygon.pos[c];
28662868

2867-
olc::v_2d<T> pb_pa = returnPolygon.pos[b] - returnPolygon.pos[a];
2868-
olc::v_2d<T> pc_pa = returnPolygon.pos[c] - returnPolygon.pos[a];
2869+
vf2d pb_pa = returnPolygon.pos[b] - returnPolygon.pos[a];
2870+
vf2d pc_pa = returnPolygon.pos[c] - returnPolygon.pos[a];
28692871

2870-
if (pb_pa.cross(pc_pa) > 0.0f)
2872+
if (pb_pa.x * pc_pa.y - pb_pa.y * pc_pa.x > 0.0f)
28712873
{
28722874
continue;
28732875
}
@@ -2881,7 +2883,8 @@ namespace olc::utils::geom2d
28812883
continue;
28822884
}
28832885

2884-
if (contains(thisTriangle, returnPolygon.pos[j]) == true)
2886+
triangle<float> fTriangle(thisTriangle.pos[0], thisTriangle.pos[1], thisTriangle.pos[2]);
2887+
if (contains(fTriangle, vf2d(returnPolygon.pos[j])) == true)
28852888
{
28862889
isEar = false;
28872890
break;
@@ -2896,6 +2899,8 @@ namespace olc::utils::geom2d
28962899
break;
28972900
}
28982901
}
2902+
2903+
loopCounter--;
28992904
}
29002905

29012906
triangle<T> lastTriangle;

0 commit comments

Comments
 (0)