Code

Fix snapping regression introduced by rev. #9118
authorDiederik van Lierop <mailat-signdiedenrezidotnl>
Thu, 22 Apr 2010 20:42:03 +0000 (22:42 +0200)
committerDiederik van Lierop <mailat-signdiedenrezidotnl>
Thu, 22 Apr 2010 20:42:03 +0000 (22:42 +0200)
src/display/curve.cpp
src/display/curve.h
src/object-snapper.cpp
src/sp-image.cpp

index 1b54c981c25c8277917bc8477283972d549e2485..73b8dc36dbf3a1c2fda0079aa573c5748b17513b 100644 (file)
@@ -44,7 +44,7 @@ SPCurve::SPCurve(Geom::PathVector const& pathv)
 }
 
 SPCurve *
-SPCurve::new_from_rect(Geom::Rect const &rect)
+SPCurve::new_from_rect(Geom::Rect const &rect, bool all_four_sides)
 {
     SPCurve *c =  new SPCurve();
 
@@ -54,7 +54,16 @@ SPCurve::new_from_rect(Geom::Rect const &rect)
     for (int i=3; i>=1; i--) {
         c->lineto(rect.corner(i));
     }
-    c->closepath();
+
+    if (all_four_sides) {
+        // When _constrained_ snapping to a path, the 2geom::SimpleCrosser will be invoked which doesn't consider the closing segment.
+        // of a path. Consequently, in case we want to snap to for example the page border, we must provide all four sides of the
+        // rectangle explicitly
+        c->lineto(rect.corner(0));
+    } else {
+        // ... instead of just three plus a closing segment
+        c->closepath();
+    }
 
     return c;
 }
index 79a385b09f2a9e5eee526e8e6a269b10077d90b8..fe072019522aff84a053137832ba6d381d10603f 100644 (file)
@@ -27,7 +27,7 @@ public:
     /* Constructors */
     explicit SPCurve();
     explicit SPCurve(Geom::PathVector const& pathv);
-    static SPCurve * new_from_rect(Geom::Rect const &rect);
+    static SPCurve * new_from_rect(Geom::Rect const &rect, bool all_four_sides = false);
 
     virtual ~SPCurve();
 
index a3285b4069e57c531291a8e812aaffe5e12dc2ba..77449ddc3d3092cadb4be15f06eed8180a53358e 100644 (file)
@@ -733,7 +733,7 @@ Geom::PathVector* Inkscape::ObjectSnapper::_getBorderPathv() const
 
 Geom::PathVector* Inkscape::ObjectSnapper::_getPathvFromRect(Geom::Rect const rect) const
 {
-    SPCurve const *border_curve = SPCurve::new_from_rect(rect);
+    SPCurve const *border_curve = SPCurve::new_from_rect(rect, true);
     if (border_curve) {
         Geom::PathVector *dummy = new Geom::PathVector(border_curve->get_pathvector());
         return dummy;
index bb867e969aa205906e117efb6f09f73d1aee1917..68bafdeab9345e0c50c9e0bc43d99e4136740124 100644 (file)
@@ -1552,7 +1552,7 @@ sp_image_set_curve(SPImage *image)
         NRRect rect;
         sp_image_bbox(image, &rect, Geom::identity(), 0);
         Geom::Rect rect2 = to_2geom(*rect.upgrade());
-        SPCurve *c = SPCurve::new_from_rect(rect2);
+        SPCurve *c = SPCurve::new_from_rect(rect2, true);
 
         if (image->curve) {
             image->curve = image->curve->unref();