Code

Use new methods from 2geom's API
authordvlierop2 <dvlierop2@users.sourceforge.net>
Fri, 15 Aug 2008 20:26:58 +0000 (20:26 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Fri, 15 Aug 2008 20:26:58 +0000 (20:26 +0000)
src/object-snapper.cpp
src/snapped-curve.cpp

index 7582a4c171f64292dec1168350c238f3e9622b04..4b6673bd0bdd0195f5c9326d533c8995d5bafa76 100644 (file)
@@ -453,19 +453,13 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
         // std::cout << "Dumping the pathvector: " << svgd << std::endl;        
         
         for(Geom::PathVector::iterator it_pv = (*it_p)->begin(); it_pv != (*it_p)->end(); ++it_pv) {
-            std::vector<double> anp;
-            
             // Find a nearest point for each curve within this path
-            // (path->allNearestPoints() will not do this for us! It was originally 
-            // intended to find for example multiple equidistant solutions)
-            unsigned int num_curves = (*it_pv).size();
-            if ( (*it_pv).closed() ) ++num_curves;
-            for (double t = 0; (t+1) <= double(num_curves); t++) {
-                // Find a nearest point with time value in the range [t, t+1]
-                anp.push_back((*it_pv).nearestPoint(p_doc, t, t+1)); 
-            }
+            // n curves will return n time values with 0 <= t <= 1
+            std::vector<double> anp = (*it_pv).nearestPointPerCurve(p_doc);
             
-            for (std::vector<double>::const_iterator np = anp.begin(); np != anp.end(); np++) {
+            std::vector<double>::const_iterator np = anp.begin();
+            unsigned int index = 0;
+            for (; np != anp.end(); np++, index++) {
                 bool c1 = true;
                 bool c2 = true;
                 Geom::Point start_pt = desktop->doc2dt((*it_pv).pointAt(floor(*np))); 
@@ -482,14 +476,13 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                     c2 = isUnselectedNode(end_pt, unselected_nodes);
                 }
                 
-                Geom::Point const sp_doc = (*it_pv).pointAt(*np);
+                Geom::Curve const *curve = &((*it_pv).at_index(index));
+                Geom::Point const sp_doc = curve->pointAt(*np);
                 Geom::Point const sp_dt = desktop->doc2dt(sp_doc);
                 
                 if (!being_edited || (c1 && c2)) {
                     Geom::Coord const dist = Geom::distance(sp_doc, p_doc);
                     if (dist < getSnapperTolerance()) {
-                        double t = MIN(*np, (*it_pv).size()); // make sure that t is within bounds;
-                        Geom::Curve const *curve = &((*it_pv).at_index(int(t)));                         
                         sc.curves.push_back(Inkscape::SnappedCurve(from_2geom(sp_dt), dist, getSnapperTolerance(), getSnapperAlwaysSnap(), curve));   
                     }
                 }
index 17d417d408314b375f6c6acc90a4b36e9664a259..dfed84531d807e3bb23736d4f6a5bf24333dedb1 100644 (file)
@@ -55,8 +55,7 @@ Inkscape::SnappedPoint Inkscape::SnappedCurve::intersect(SnappedCurve const &cur
     // The point of intersection should be considered for snapping, but might be outside the snapping range\r
     // PS: We need p (the location of the mouse pointer) for find out which intersection is the\r
     // closest, as there might be multiple intersections of two curves\r
-    Geom::SimpleCrosser xr;\r
-    Geom::Crossings cs = xr.crossings(*(this->_curve), *(curve._curve));\r
+    Geom::Crossings cs = crossings(*(this->_curve), *(curve._curve));\r
      \r
     if (cs.size() > 0) {\r
         // There might be multiple intersections: find the closest\r