Code

Fix regression in object snapper which caused self-snapping
authordvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 7 Aug 2008 19:32:35 +0000 (19:32 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 7 Aug 2008 19:32:35 +0000 (19:32 +0000)
build.xml
src/object-snapper.cpp
src/ui/clipboard.cpp

index 4a8bb093363df78a19646f20f7bc26c182533b99..05ea97f109f381b1cc8dab9de52fde01b4a839f2 100644 (file)
--- a/build.xml
+++ b/build.xml
         </excludeinc>
         <flags>
             -Wall -Wformat -Werror=format-security -W -Wpointer-arith -Wcast-align -Wsign-compare -Woverloaded-virtual -Wswitch
-            -O2
+                       -O2
             -mms-bitfields
         </flags>
         <defines>
         </flags>
     </rc>
     <link command="${arch}g++" out="${build}/inkscape.exe"
-              strip="true" symfile="${build}/inkscape.dbg"
+              strip="false" symfile="${build}/inkscape.dbg"
               stripcommand="${archutil}strip"
               objcopycommand="${archutil}objcopy">
        <flags>
-           -mwindows
+           -mconsole
        </flags>
        <fileset dir="${build}">
            <include name="inkres.o"/>
index 020a4793d81f232524716ecaa52d2a4c73305880..ad5874a7e7d7c82f14218766cb39baf705d8f70c 100644 (file)
@@ -450,12 +450,24 @@ 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 = (*it_pv).allNearestPoints(p_doc);
+            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)); 
+            }
+            
             for (std::vector<double>::const_iterator np = anp.begin(); np != anp.end(); np++) {
                 bool c1 = true;
                 bool c2 = true;
                 Geom::Point start_pt = desktop->doc2dt((*it_pv).pointAt(floor(*np))); 
                 Geom::Point end_pt = desktop->doc2dt((*it_pv).pointAt(ceil(*np)));
+                
                 if (being_edited) {
                     /* If the path is being edited, then we should only snap though to stationary pieces of the path
                      * and not to the pieces that are being dragged around. This way we avoid 
@@ -464,15 +476,14 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                      */                    
                     g_assert(unselected_nodes != NULL);
                     c1 = isUnselectedNode(from_2geom(start_pt), unselected_nodes);
-                    c2 = isUnselectedNode(from_2geom(end_pt), unselected_nodes);     
+                    c2 = isUnselectedNode(from_2geom(end_pt), unselected_nodes);
                 }
                 
                 Geom::Point const sp_doc = (*it_pv).pointAt(*np);
                 Geom::Point const sp_dt = desktop->doc2dt(sp_doc);
                 
-                if (!being_edited || (c2 && c2)) {
+                if (!being_edited || (c1 && c2)) {
                     NR::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));                         
index e7f2d82ee23d40e0179aa5dc02de69517f5bc616..ce506523a2b6ce9ed60f3a510c91befbb37463d6 100644 (file)
@@ -787,10 +787,10 @@ void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place)
     sp_document_ensure_up_to_date(target_document); // What does this do?
     
     boost::optional<NR::Rect> sel_bbox = selection->bounds(); //In desktop coordinates
-    // PS: We could also have used the min/max corners calculated above, because we know that
-    // after pasting the upper left corner of the selection will be aligend to the corresponding page corner
-    // Using the boundingbox of the selection is more foolproof though
-        if (sel_bbox) {
+    // PS: We could also have used the min/max corners calculated above, instead of selection->bounds() because 
+    // we know that after pasting the upper left corner of the selection will be aligend to the corresponding 
+    // page corner. Using the boundingbox of the selection is more foolproof though
+    if (sel_bbox) {
         Geom::Point pos_mouse = to_2geom(desktop->point()); //Location of mouse pointer in desktop coordinates
         // Now calculate how far we would have to move the pasted objects to get their
         // midpoint at the location of the mouse pointer
@@ -803,7 +803,7 @@ void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place)
         offset = rel_pos_original;        
     } else { // Stick to the grid if snapping is enabled, otherwise paste at mouse position;
         SnapManager &m = desktop->namedview->snap_manager;
-        m.setup(NULL, NULL); //Don't display snapindicator
+        m.setup(NULL, NULL); //Don't display the snapindicator
         offset = rel_pos_original + m.multipleOfGridPitch(rel_pos_mouse - rel_pos_original); 
     }