Revision: 64385
          http://sourceforge.net/p/brlcad/code/64385
Author:   n_reed
Date:     2015-03-12 22:36:53 +0000 (Thu, 12 Mar 2015)
Log Message:
-----------
when overlap curve endpoints meet within intersection tolerance, fill small 
gaps between the endpoints so that loops constructed from the curves will pass 
an IsClosed() test

Modified Paths:
--------------
    brlcad/branches/brep-debug/src/libbrep/intersect.cpp

Modified: brlcad/branches/brep-debug/src/libbrep/intersect.cpp
===================================================================
--- brlcad/branches/brep-debug/src/libbrep/intersect.cpp        2015-03-12 
22:22:35 UTC (rev 64384)
+++ brlcad/branches/brep-debug/src/libbrep/intersect.cpp        2015-03-12 
22:36:53 UTC (rev 64385)
@@ -2518,10 +2518,29 @@
     return (pointA.DistanceTo(pointB) < isect_tol) && !isnan(uA) && !isnan(vA) 
&& !isnan(uB) & !isnan(vB);
 }
 
+// if curve end is greater than tol distance from pt, append a linear
+// segment to the curve so it extends to the pt
+HIDDEN void
+extend_curve_end_to_pt(ON_Curve *&curve, ON_3dPoint pt, double tol)
+{
+    ON_NurbsCurve *nc = curve->NurbsCurve();
+    if (nc->PointAtEnd().DistanceTo(pt) > tol) {
+       ON_LineCurve line_bridge(nc->PointAtEnd(), pt);
 
+       ON_NurbsCurve bridge;
+       if (line_bridge.GetNurbForm(bridge)) {
+           nc->Append(bridge);
+       }
+       delete curve;
+       curve = nc;
+    }
+}
+
 HIDDEN ON_Curve *
 link_curves(ON_Curve *&c1, ON_Curve *&c2)
 {
+    extend_curve_end_to_pt(c1, c2->PointAtEnd(), ON_ZERO_TOLERANCE);
+
     ON_NurbsCurve *nc1 = c1->NurbsCurve();
     ON_NurbsCurve *nc2 = c2->NurbsCurve();
     if (nc1 && nc2) {
@@ -2540,6 +2559,16 @@
     return NULL;
 }
 
+// if curve start and end are within tolerance, append a linear
+// segment to the curve to close it completely so it passes
+// IsClosed() tests
+HIDDEN void
+fill_gap_if_closed(ON_Curve *&curve, double tol)
+{
+    if (curve->PointAtStart().DistanceTo(curve->PointAtEnd()) <= tol) {
+       extend_curve_end_to_pt(curve, curve->PointAtStart(), ON_ZERO_TOLERANCE);
+    }
+}
 
 struct OverlapSegment {
     ON_Curve *m_curve3d, *m_curveA, *m_curveB;
@@ -3862,6 +3891,9 @@
                delete overlaps[j];
                overlaps[j] = NULL;
            }
+           fill_gap_if_closed(overlaps[i]->m_curve3d, isect_tol);
+           fill_gap_if_closed(overlaps[i]->m_curveA, isect_tolA);
+           fill_gap_if_closed(overlaps[i]->m_curveB, isect_tolB);
        }
     }
 

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to