@@ -487,7 +487,7 @@ static void FindProjectionAxes(const std::vector<size_t> &polygon_indices,
487487 double eps = std::numeric_limits<double >::epsilon ();
488488 if (cx > eps || cy > eps || cz > eps) {
489489 if (cx > cy && cx > cz) {
490- /* axes stay {1, 2} */
490+ // axes stay {1, 2}
491491 } else {
492492 axes[0 ] = 0 ;
493493 if (cz > cx && cz > cy) {
@@ -808,12 +808,15 @@ size_t TriangulateSweepLine(const std::vector<size_t> &polygon_indices,
808808 };
809809 std::vector<EdgeInfo> status;
810810
811+ // Tolerance for near-horizontal edge detection and edge-x comparison.
812+ static const double kEdgeTolerance = 1e-12 ;
813+
811814 // Compute x-coordinate where edge e_k intersects sweep line at y.
812815 auto edgeXAtY = [&](size_t eidx, double y) -> double {
813816 size_t from = eidx;
814817 size_t to = (eidx + 1 ) % n;
815818 double dy = py[to] - py[from];
816- if (std::fabs (dy) < 1e-15 ) return std::min (px[from], px[to]);
819+ if (std::fabs (dy) < kEdgeTolerance ) return std::min (px[from], px[to]);
817820 return px[from] + (px[to] - px[from]) * (y - py[from]) / dy;
818821 };
819822
@@ -825,7 +828,7 @@ size_t TriangulateSweepLine(const std::vector<size_t> &polygon_indices,
825828 double best_x = -std::numeric_limits<double >::max ();
826829 for (size_t j = 0 ; j < status.size (); j++) {
827830 double ex = edgeXAtY (status[j].edge_idx , vy);
828- if (ex <= vx + 1e-12 && ex > best_x) {
831+ if (ex <= vx + kEdgeTolerance && ex > best_x) {
829832 best_x = ex;
830833 best = static_cast <int >(j);
831834 }
0 commit comments