Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions utils/geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,14 @@ boolean intersect_line_with_segment(double px, double py, double dx, double dy,
double t = (M00*RHSy-M10*RHSx)/DetM;
if (s) *s = (M11*RHSx-M01*RHSy)/DetM;

if (t<0.0 || t>1.0) // intersection of lines does not lie between vertices
return 0;

return 1;
// the plumb line intersects the segment if 0<=t<=1, with t==0,1
// corresponding to the endpoints; for our purposes we count
// the intersection if the plumb line runs through the t==0 vertex, but
// NOT the t==1 vertex, to avoid double-counting for complete polygons.
#define DELTAT 1.0e-6
#define TMIN (0.0)
#define TMAX (1.0-DELTAT)
return ( ( t<TMIN || t>TMAX ) ? 0 : 1 );
Copy link
Collaborator

@stevengj stevengj Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer rounding to float for this kind of approximate comparison, i.e. wouldn't

return t < 0 || ((float)t) >= 1 ? 0 : 1;

work?

}

// like the previous routine, but only count intersections if s>=0
Expand Down