@@ -1575,8 +1575,9 @@ bool TriangulatePolygon(
15751575 triangulatedFaceCounts.push_back (2 );
15761576#endif
15771577 } else {
1578+ // Use double for accuracy. `float` precision may classify small-are polygon as degenerated.
15781579 // Find the normal axis of the polygon using Newell's method
1579- T n = {BaseTy ( 0 ), BaseTy ( 0 ), BaseTy ( 0 ) };
1580+ value::double3 n = {0 , 0 , 0 };
15801581
15811582 size_t vi0;
15821583 size_t vi0_2;
@@ -1608,13 +1609,19 @@ bool TriangulatePolygon(
16081609 T b = {point1[0 ] + point2[0 ], point1[1 ] + point2[1 ],
16091610 point1[2 ] + point2[2 ]};
16101611
1611- n[0 ] += (a[1 ] * b[2 ]);
1612- n[1 ] += (a[2 ] * b[0 ]);
1613- n[2 ] += (a[0 ] * b[1 ]);
1612+ n[0 ] += double (a[1 ] * b[2 ]);
1613+ n[1 ] += double (a[2 ] * b[0 ]);
1614+ n[2 ] += double (a[0 ] * b[1 ]);
1615+ DCOUT (" v0 " << v0);
1616+ DCOUT (" v1 " << v1);
1617+ DCOUT (" n " << n);
16141618 }
1615- BaseTy length_n = vlength (n);
1619+ // BaseTy length_n = vlength(n);
1620+ double length_n = vlength (n);
1621+
16161622 // Check if zero length normal
1617- if (std::fabs (length_n) < std::numeric_limits<BaseTy>::epsilon ()) {
1623+ if (std::fabs (length_n) < std::numeric_limits<double >::epsilon ()) {
1624+ DCOUT (" length_n " << length_n);
16181625 err = " Degenerated polygon found.\n " ;
16191626 return false ;
16201627 }
@@ -1623,7 +1630,9 @@ bool TriangulatePolygon(
16231630 n = vnormalize (n);
16241631
16251632 T axis_w, axis_v, axis_u;
1626- axis_w = n;
1633+ axis_w[0 ] = BaseTy (n[0 ]);
1634+ axis_w[1 ] = BaseTy (n[1 ]);
1635+ axis_w[2 ] = BaseTy (n[2 ]);
16271636 T a;
16281637 if (std::fabs (axis_w[0 ]) > BaseTy (0.9999999 )) { // TODO: use 1.0 - eps?
16291638 a = {BaseTy (0 ), BaseTy (1 ), BaseTy (0 )};
0 commit comments