From 94291cf95dad342c682d612fda0698b5b9e85949 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 22 Apr 2010 22:42:03 +0200 Subject: [PATCH] Fix snapping regression introduced by rev. #9118 --- src/display/curve.cpp | 13 +++++++++++-- src/display/curve.h | 2 +- src/object-snapper.cpp | 2 +- src/sp-image.cpp | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 1b54c981c..73b8dc36d 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -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; } diff --git a/src/display/curve.h b/src/display/curve.h index 79a385b09..fe0720195 100644 --- a/src/display/curve.h +++ b/src/display/curve.h @@ -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(); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index a3285b406..77449ddc3 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -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; diff --git a/src/sp-image.cpp b/src/sp-image.cpp index bb867e969..68bafdeab 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -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(); -- 2.30.2