]> granicus.if.org Git - graphviz/commitdiff
Add ptToLine2 function returning the squared distance of a point to a line.
authorerg <devnull@localhost>
Thu, 20 Apr 2006 21:22:16 +0000 (21:22 +0000)
committererg <devnull@localhost>
Thu, 20 Apr 2006 21:22:16 +0000 (21:22 +0000)
lib/common/geom.c
lib/common/geomprocs.h

index 91d5d04fbcc7f70c1033b22d2dece0a41f091d21..d362f0cd2ce8c3ba26b0f17cd2d3862ad74acfd4 100644 (file)
@@ -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);
+}
index 1f780a6d326b7069f6abd15ddd72d7a7f144aa66..65fa3c914d79b8e069b80305f455c0d74293f97f 100644 (file)
@@ -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);