@@ -162,8 +162,8 @@ int Vect__intersect_y_line_with_poly(const struct line_pnts *Points, double y,
162162 if (a == b )
163163 continue ;
164164
165- p = (d - c ) / (b - a );
166- x = c + p * (y - a );
165+ p = (y - a ) / (b - a ); /* always within [0, 1] */
166+ x = c + p * (d - c );
167167
168168 if (0 > Vect_append_point (Inter , x , y , 0 ))
169169 return -1 ;
@@ -217,8 +217,8 @@ int Vect__intersect_x_line_with_poly(const struct line_pnts *Points, double x,
217217 if (a == b )
218218 continue ;
219219
220- p = (d - c ) / (b - a );
221- y = c + p * (x - a );
220+ p = (x - a ) / (b - a ); /* always within [0, 1] */
221+ y = c + p * (d - c );
222222
223223 if (0 > Vect_append_point (Inter , x , y , 0 ))
224224 return -1 ;
@@ -584,6 +584,9 @@ int Vect_get_point_in_poly_isl(const struct line_pnts *Points,
584584 }
585585
586586 /* get centroid, center of gravity of the polygon line, not the area */
587+ /* original version, does not consider isles
588+ * the centroid can be inside an isle or completely outside of the area
589+ * for very thin polygons, the centroid might be on the boundary */
587590 Vect_find_poly_centroid (Points , & cent_x , & cent_y );
588591 /* is it w/in poly? */
589592 point_in_sles = 0 ;
@@ -603,6 +606,9 @@ int Vect_get_point_in_poly_isl(const struct line_pnts *Points,
603606 }
604607
605608 /* get centroid, center of gravity of the area */
609+ /* new version, considers isles
610+ * the centroid can still be inside an isle or completely outside of the
611+ * area for very thin polygons, the centroid might be on the boundary */
606612 Vect_find_poly_centroid_cog (Points , IPoints , n_isles , & cent_x , & cent_y );
607613 /* is it w/in poly? */
608614 point_in_sles = 0 ;
0 commit comments