Revision: 56709
          http://sourceforge.net/p/brlcad/code/56709
Author:   phoenixyjll
Date:     2013-08-09 03:09:43 +0000 (Fri, 09 Aug 2013)
Log Message:
-----------
Don't call Split() when t is on the boundary of domain - Split() may fail 
returning two NULL pointers. And the first point is not always on the first 
segment, so we might need to duplicate more than one segments.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/boolean.cpp

Modified: brlcad/trunk/src/libbrep/boolean.cpp
===================================================================
--- brlcad/trunk/src/libbrep/boolean.cpp        2013-08-09 00:21:10 UTC (rev 
56708)
+++ brlcad/trunk/src/libbrep/boolean.cpp        2013-08-09 03:09:43 UTC (rev 
56709)
@@ -220,12 +220,6 @@
     }
     sorted_pointers.QuickSort(compare_t);
 
-    if (sorted_pointers.Count()) {
-       intersect.Append(*sorted_pointers[0]);
-       intersect.Last()->m_seg = in->outerloop.Count();
-       sorted_pointers.Append(intersect.Last());
-    }
-
     for (int i = 0; i < intersect.Count(); i++) {
        // We assume that the starting point is outside.
        if (intersect[i].m_rank % 2 == 0) {
@@ -235,6 +229,7 @@
        }
     }
 
+    // Split the outer loop.
     ON_SimpleArray<ON_Curve*> outerloop;
     int isect_iter = 0;
     for (int i = 0; i < in->outerloop.Count(); i++) {
@@ -246,8 +241,15 @@
        for (; isect_iter < sorted_pointers.Count() && 
sorted_pointers[isect_iter]->m_seg == i; isect_iter++) {
            const IntersectPoint* isect_pt = sorted_pointers[isect_iter];
            ON_Curve* left = NULL;
-           if (curve_on_loop)
-               curve_on_loop->Split(isect_pt->m_t, left, curve_on_loop);
+           if (curve_on_loop) {
+               if (ON_NearZero(isect_pt->m_t - curve_on_loop->Domain().Max())) 
{
+                   // Don't call Split(), which may fail when the point is
+                   // at the ends.
+                   left = curve_on_loop;
+                   curve_on_loop = NULL;
+               } else if (!ON_NearZero(isect_pt->m_t, 
curve_on_loop->Domain().Min()))
+                   curve_on_loop->Split(isect_pt->m_t, left, curve_on_loop);
+           }
            if (left != NULL)
                outerloop.Append(left);
            else {
@@ -265,15 +267,20 @@
 
     // Append the first element at the last to handle some special cases.
     if (sorted_pointers.Count()) {
-       ON_Curve* dup = outerloop[0]->Duplicate();
-       if (dup != NULL) {
-           outerloop.Append(dup);
-           intersect.Last()->m_pos = outerloop.Count() - 1;
+       intersect.Append(*sorted_pointers[0]);
+       intersect.Last()->m_seg += in->outerloop.Count();
+       sorted_pointers.Append(intersect.Last());
+       for (int i = 0; i <= sorted_pointers[0]->m_pos; i++) {
+           ON_Curve* dup = outerloop[i]->Duplicate();
+           if (dup != NULL) {
+               outerloop.Append(dup);
+           }
+           else {
+               bu_log("ON_Curve::Duplicate() failed.\n");
+               outerloop.Append(outerloop[i]);
+           }
        }
-       else {
-           bu_log("ON_Curve::Duplicate() failed.\n");
-           outerloop.Append(outerloop[0]);
-       }
+       intersect.Last()->m_pos = outerloop.Count() - 1;
     }
 
     std::stack<int> s;
@@ -360,9 +367,11 @@
        out.Append(newface);
     }
 
-    // Remove the duplicated first segment.
-    if (sorted_pointers.Count())
-       outerloop.Remove();
+    // Remove the duplicated segments before the first intersection point.
+    if (sorted_pointers.Count()) {
+       for (int i = 0; i <= sorted_pointers[0]->m_pos; i++)
+           outerloop.Remove(0);
+    }
 
     if (out.Count() == 0) {
        out.Append(in->Duplicate());

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


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to