From d46ff633fa3f700c3314a4043dc60fa40b4d827f Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 6 Sep 2011 01:56:33 -0400 Subject: [PATCH] Fix math error in IsPointOnLine() The math in C didn't match the math in the comment (and, apparently, hasn't for quite some time). To test: Draw three lines, from 1000,3000 to 1500,2500, then to 2000,3000, then back to the start at 1000,3000. Without this patch, the first and last lines are removed and replaced with a copy of the second line. --- src/search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index f12f473d..60e8dde9 100644 --- a/src/search.c +++ b/src/search.c @@ -727,7 +727,7 @@ IsPointOnLine (Coord X, Coord Y, Coord Radius, LineTypePtr Line) else D1 = 0; /* Get distance from (X, Y) to Q */ D2 = ((double) (X - Line->Point1.X) * (Line->Point2.Y - Line->Point1.Y) - + (double) (Y - Line->Point1.Y) * (Line->Point2.X - Line->Point1.X)) / L; + - (double) (Y - Line->Point1.Y) * (Line->Point2.X - Line->Point1.X)) / L; /* Total distance is then the pythagorean sum of these */ return sqrt (D1*D1 + D2*D2) <= Radius + Line->Thickness / 2; } -- 2.11.4.GIT