From 693913ffdbb28014bef1b9fa82fcceb04ae1e52b Mon Sep 17 00:00:00 2001 From: Homer Reid Date: Tue, 10 Jul 2018 18:28:31 -0400 Subject: [PATCH] update point_in_prism to avoid double-counting of polygon edge intersections when plumb lines pass through vertices --- utils/geom.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/geom.c b/utils/geom.c index 80e9bf0..a2619f8 100644 --- a/utils/geom.c +++ b/utils/geom.c @@ -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 ( ( tTMAX ) ? 0 : 1 ); } // like the previous routine, but only count intersections if s>=0