Fix debugscript, some quadtree stuff and don't intersect vertical/horz lines when...
authorDavid Gow <[email protected]>
Thu, 9 Oct 2014 11:57:47 +0000 (19:57 +0800)
committerDavid Gow <[email protected]>
Thu, 9 Oct 2014 11:57:47 +0000 (19:57 +0800)
src/Makefile
src/bezier.h
src/debugscript.cpp
src/document.cpp

index 04e52fe..b7489c8 100644 (file)
@@ -158,7 +158,7 @@ clean_bin :
        $(RM) $(BIN)
 
 clean :
-       $(RM) $(BIN) $(DEPS) $(LINKOBJ) ../obj/$(MAIN)
+       $(RM) $(BIN) $(DEPS) $(LINKOBJ) ../obj/$(MAIN) ../obj/quadtree.?
        $(RM) tests/*~
        $(RM) tests/*.test
        $(RM) tests/*.out
index 3f47555..d3c0e2d 100644 (file)
@@ -258,47 +258,47 @@ namespace IPDF
                        // Find points of intersection with the rectangle.
                        Debug("Clipping Bezier to BRect %s", r.Str().c_str());
 
+                       bool isVerticalLine = (x0 == x1 && x1 == x2 && x2 == x3);
+                       bool isHorizontalLine = (y0 == y1 && y1 == y2 && y2 == y3);
 
                        // Find its roots.
-                       std::vector<BReal> x_intersection = SolveXParam(r.x);
-                       //Debug("Found %d intersections on left edge", x_intersection.size());
+                       
+                       std::vector<BReal> intersection;
 
-                       // And for the other side.
+                       if (!isVerticalLine)
+                       {
+                               std::vector<BReal> x_intersection = SolveXParam(r.x);
+                               intersection.insert(intersection.end(), x_intersection.begin(), x_intersection.end());
 
-                       std::vector<BReal> x_intersection_pt2 = SolveXParam(r.x + r.w);
-                       x_intersection.insert(x_intersection.end(), x_intersection_pt2.begin(), x_intersection_pt2.end());
-                       //Debug("Found %d intersections on right edge (total x: %d)", x_intersection_pt2.size(), x_intersection.size());
+                               // And for the other side.
+
+                               std::vector<BReal> x_intersection_pt2 = SolveXParam(r.x + r.w);
+                               intersection.insert(intersection.end(), x_intersection_pt2.begin(), x_intersection_pt2.end());
+                       }
 
                        // Find its roots.
-                       std::vector<BReal> y_intersection = SolveYParam(r.y);
-                       //Debug("Found %d intersections on top edge", y_intersection.size());
+                       if (!isHorizontalLine)
+                       {
+                               std::vector<BReal> y_intersection = SolveYParam(r.y);
+                               intersection.insert(intersection.end(), y_intersection.begin(), y_intersection.end());
 
-                       std::vector<BReal> y_intersection_pt2 = SolveYParam(r.y+r.h);
-                       y_intersection.insert(y_intersection.end(), y_intersection_pt2.begin(), y_intersection_pt2.end());
-                       //Debug("Found %d intersections on bottom edge (total y: %d)", y_intersection_pt2.size(), y_intersection.size());
+                               std::vector<BReal> y_intersection_pt2 = SolveYParam(r.y+r.h);
+                               intersection.insert(intersection.end(), y_intersection_pt2.begin(), y_intersection_pt2.end());
+                       }
 
                        // Merge and sort.
-                       x_intersection.insert(x_intersection.end(), y_intersection.begin(), y_intersection.end());
-                       x_intersection.push_back(BReal(0));
-                       x_intersection.push_back(BReal(1));
-                       std::sort(x_intersection.begin(), x_intersection.end());
-
-                       //Debug("Found %d intersections.\n", x_intersection.size());
-                       /*for(auto t : x_intersection)
-                       {
-                               BReal ptx, pty;
-                               Evaluate(ptx, pty, t);
-                               Debug("Root: t = %f, (%f,%f)", Double(t), Double(ptx), Double(pty));
-                       }*/
+                       intersection.push_back(BReal(0));
+                       intersection.push_back(BReal(1));
+                       std::sort(intersection.begin(), intersection.end());
                        
                        std::vector<Bezier> all_beziers;
-                       if (x_intersection.size() <= 2)
+                       if (intersection.size() <= 2)
                        {
                                all_beziers.push_back(*this);
                                return all_beziers;
                        }
-                       BReal t0 = *(x_intersection.begin());
-                       for (auto it = x_intersection.begin()+1; it != x_intersection.end(); ++it)
+                       BReal t0 = *(intersection.begin());
+                       for (auto it = intersection.begin()+1; it != intersection.end(); ++it)
                        {
                                BReal t1 = *it;
                                if (t1 == t0) continue;
index 59631aa..4de62bb 100644 (file)
@@ -7,6 +7,7 @@ using namespace std;
 
 void DebugScript::ParseAction(View * view, Screen * scr)
 {
+       *m_input >> std::ws;
        if (m_input == NULL || !m_input->good())
                return;
        istream & inp = *m_input;
index d01e075..b10ebf5 100644 (file)
@@ -445,7 +445,7 @@ done: // matches is not amused, but sulix is nice and moved it inside the #ifdef
                m_count++;
                PropagateQuadChanges(qti);
        }
-       return m_count;
+       return m_count-1;
 #else // words fail me (still not amused)
        return (m_count++);
 #endif

UCC git Repository :: git.ucc.asn.au