closest_point_calculation(): improve "closest point is on segment" detection

This commit is contained in:
stefan schippers 2023-09-22 09:33:41 +02:00
parent a53ea21026
commit 9e1feacab4
1 changed files with 2 additions and 2 deletions

View File

@ -420,12 +420,12 @@ static int closest_point_calculation(double x1, double y1, double x2, double y2,
}
sq_distance = (*x0 - x3) * (*x0 - x3) + (*y0 - y3) * (*y0 - y3);
if(x3 >= x1 && x3 <= x2) { /* point is within x1,y1 - x2,y2 */
if(projection <= 1 && projection >= 0) { /* point is within x1,y1 - x2,y2 */
if(sq_distance == 0) ret = 2;
else if(sq_distance < sq_cs) ret = 1;
}
dbg(1, "x3 = %g y3=%g dist=%g ret=%d\n", x3, y3, sqrt(sq_distance), ret);
dbg(0, "x3 = %g y3=%g dist=%g ret=%d\n", x3, y3, sqrt(sq_distance), ret);
if(ret == 1) {
*x0 = my_round(x3 / cs) * cs;
*y0 = my_round(y3 / cs) * cs;