From 1063d02f94d3a2f72065ab0b3ebac598137ea8db Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 20 Apr 2006 21:22:16 +0000 Subject: [PATCH] Add ptToLine2 function returning the squared distance of a point to a line. --- lib/common/geom.c | 11 +++++++++++ lib/common/geomprocs.h | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/common/geom.c b/lib/common/geom.c index 91d5d04fb..d362f0cd2 100644 --- a/lib/common/geom.c +++ b/lib/common/geom.c @@ -503,3 +503,14 @@ box flip_rec_box(box b, point p) rv.UR.y += p.y; return rv; } + +/* ptToLine2: + * Return distance from point p to line a-b squared. + */ +double ptToLine2 (pointf a, pointf b, pointf p) +{ + double dx = b.x-a.x; + double dy = b.y-a.y; + double a2 = (p.y-a.y)*dx - (p.x-a.x)*dy; + return (a2*a2) / (dx*dx + dy*dy); +} diff --git a/lib/common/geomprocs.h b/lib/common/geomprocs.h index 1f780a6d3..65fa3c914 100644 --- a/lib/common/geomprocs.h +++ b/lib/common/geomprocs.h @@ -48,6 +48,7 @@ extern bool box_contains(box, box); extern bool boxf_contains(boxf, boxf); extern box flip_rec_box(box b, point p); +extern double ptToLine2 (pointf l1, pointf l2, pointf p); extern int lineToBox(pointf p1, pointf p2, boxf b); extern point ccwrotatep(point p, int ccwrot); -- 2.40.0