Revision: 76191
          http://sourceforge.net/p/brlcad/code/76191
Author:   starseeker
Date:     2020-06-24 13:47:45 +0000 (Wed, 24 Jun 2020)
Log Message:
-----------
API shouldn't insist on sqrt - it isn't always needed, and the caller may not 
wish to pay the performance penalty.

Modified Paths:
--------------
    brlcad/trunk/include/bg/lseg.h
    brlcad/trunk/src/libbg/lseg_lseg.c
    brlcad/trunk/src/libbg/tests/lseg_lseg.c
    brlcad/trunk/src/libbrep/opennurbs_ext.cpp

Modified: brlcad/trunk/include/bg/lseg.h
===================================================================
--- brlcad/trunk/include/bg/lseg.h      2020-06-24 06:47:35 UTC (rev 76190)
+++ brlcad/trunk/include/bg/lseg.h      2020-06-24 13:47:45 UTC (rev 76191)
@@ -36,11 +36,28 @@
 
 __BEGIN_DECLS
 
+#if 0
+/* Compute the closest 2D point on the 2D line segment P0->P1 to point Q.
+ * Returns the distance squared from Q to the closest point and the closest
+ * point in question if c is non-NULL.
+ */
+BG_EXPORT double
+bg_lseg2_pt2_dist_sq(point2d_t *c, const point2d_t P0, const point2d_t P1, 
const point2d_t Q);
+
+/* Compute the closest point on the line segment P0->P1 to point Q.  Returns
+ * the distance squared from Q to the closest point and the closest point in
+ * question if c is non-NULL.
+ */
+BG_EXPORT double
+bg_lseg_pt_dist_sq(point_t *c, const point_t P0, const point_t P1, const 
point_t Q);
+#endif
+
 /* Compute the closest points on the line segments P0->P1 and Q0->Q1.  Returns
- * the distance between the closest points and (optionally) the closest points
- * in question (c1 is the point on P0->P1, c2 is the point on Q0->Q1). */
+ * the distance squared between the closest points and (optionally) the closest
+ * points in question (c1 is the point on P0->P1, c2 is the point on Q0->Q1).
+ */
 BG_EXPORT double
-bg_lseg_lseg_dist(point_t *c1, point_t *c2,
+bg_lseg_lseg_dist_sq(point_t *c1, point_t *c2,
        const point_t P0, const point_t P1, const point_t Q0, const point_t Q1);
 
 __END_DECLS

Modified: brlcad/trunk/src/libbg/lseg_lseg.c
===================================================================
--- brlcad/trunk/src/libbg/lseg_lseg.c  2020-06-24 06:47:35 UTC (rev 76190)
+++ brlcad/trunk/src/libbg/lseg_lseg.c  2020-06-24 13:47:45 UTC (rev 76191)
@@ -207,11 +207,11 @@
 
 
 double
-bg_lseg_lseg_dist(point_t *c1, point_t *c2,
+bg_lseg_lseg_dist_sq(point_t *c1, point_t *c2,
                  const point_t P0, const point_t P1, const point_t Q0, const 
point_t Q1)
 {
     vect_t diff, r1a, r1b, r2a, r2b, r1, r2;
-    double ldist;
+    double ldist_sq;
     struct bg_lseg_result result;
     struct bg_lseg_tmp_vals v;
 
@@ -324,8 +324,8 @@
        VMOVE(*c2, r2);
     }
     VSUB2(diff, r1, r2);
-    ldist = sqrt(VDOT(diff, diff));
-    return ldist;
+    ldist_sq = VDOT(diff, diff);
+    return ldist_sq;
 }
 
 

Modified: brlcad/trunk/src/libbg/tests/lseg_lseg.c
===================================================================
--- brlcad/trunk/src/libbg/tests/lseg_lseg.c    2020-06-24 06:47:35 UTC (rev 
76190)
+++ brlcad/trunk/src/libbg/tests/lseg_lseg.c    2020-06-24 13:47:45 UTC (rev 
76191)
@@ -48,7 +48,7 @@
        VSET(Q0, 3.44524589136147830,7.67444957869714628,22.91984784277452647);
        VSET(Q1, 3.56555225936148323,7.98564760063074353,23.37334866995422900);
 
-       dist = bg_lseg_lseg_dist(&c0, &c1, P0, P1, Q0, Q1);
+       dist = sqrt(bg_lseg_lseg_dist_sq(&c0, &c1, P0, P1, Q0, Q1));
 
        if (dist < 0) {
            bu_exit(-1, "Fatal error - mesh validity test failed\n");

Modified: brlcad/trunk/src/libbrep/opennurbs_ext.cpp
===================================================================
--- brlcad/trunk/src/libbrep/opennurbs_ext.cpp  2020-06-24 06:47:35 UTC (rev 
76190)
+++ brlcad/trunk/src/libbrep/opennurbs_ext.cpp  2020-06-24 13:47:45 UTC (rev 
76191)
@@ -368,7 +368,7 @@
        double ndist;
        if (t) {
            point_t c1i, l1i;
-           ndist = bg_lseg_lseg_dist(&c1i, &l1i, C0, C1, L0, L1);
+           ndist = sqrt(bg_lseg_lseg_dist_sq(&c1i, &l1i, C0, C1, L0, L1));
            double nt;
            ON_3dPoint tp(c1i[0], c1i[1], c1i[2]);
            if (!ON_NurbsCurve_GetClosestPoint(&nt, nc, tp, maximum_distance, 
&domain)) {
@@ -380,7 +380,7 @@
            }
            (*t) = nt;
        } else {
-           ndist = bg_lseg_lseg_dist(NULL, NULL, C0, C1, L0, L1);
+           ndist = sqrt(bg_lseg_lseg_dist_sq(NULL, NULL, C0, C1, L0, L1));
        }
        if (dist) {
            (*dist) = ndist;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to