summaryrefslogtreecommitdiffstats
path: root/src/seltrans.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/seltrans.cpp')
-rw-r--r--src/seltrans.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index 34ea17a64..4bb1b3d2b 100644
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -295,7 +295,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
_snap_points = snap_points_hull;
// Unfortunately, by now we will have lost the font-baseline snappoints :-(
}
-
+
// Find bbox hulling all special points, which excludes stroke width. Here we need to include the
// path nodes, for example because a rectangle which has been converted to a path doesn't have
// any other special points
@@ -326,6 +326,23 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
_opposite_for_specpoints = snap_points_bbox.min() + snap_points_bbox.dimensions() * Geom::Scale(1-x, 1-y);
_opposite = _opposite_for_bboxpoints;
}
+
+ // When snapping the node closest to the mouse pointer is absolutely preferred over the closest snap
+ // (i.e. when weight == 1), then we will not even try to snap to other points and discard those other
+ // points immediately.
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (prefs->getBool("/options/snapclosestonly/value", false)) {
+ _keepClosestPointOnly(_snap_points, p);
+ _keepClosestPointOnly(_bbox_points, p);
+ if (_snap_points.size() == 1 && _bbox_points.size() == 1) { //both vectors can only have either one or zero elements
+ // So we have exactly one bbox corner and one node left; now find out which is closest and delete the other one
+ if (Geom::L2(_snap_points.at(0) - p) < Geom::L2(_bbox_points.at(0) - p)) {
+ _bbox_points.clear();
+ } else {
+ _snap_points.clear();
+ }
+ }
+ }
// The lines below are usefull for debugging any snapping issues, as they'll spit out all points that are considered for snapping
@@ -1415,7 +1432,7 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state)
Inkscape::SnappedPoint best_snapped_point;
for (std::list<Inkscape::SnappedPoint>::const_iterator i = s.begin(); i != s.end(); i++) {
if (i->getSnapped()) {
- if (best_snapped_point.isOtherOneBetter(*i, true)) {
+ if (best_snapped_point.isOtherSnapBetter(*i, true)) {
best_snapped_point = *i;
dxy = i->getTransformation();
}
@@ -1544,6 +1561,25 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale)
return visual_bbox.min() + visual_bbox.dimensions() * Geom::Scale(_handle_x, _handle_y);
}
+void Inkscape::SelTrans::_keepClosestPointOnly(std::vector<Geom::Point> &points, const Geom::Point &reference)
+{
+ if (points.size() < 2) return;
+
+ Geom::Point closest_point = Geom::Point(NR_HUGE, NR_HUGE);
+ Geom::Coord closest_dist = NR_HUGE;
+
+ for(std::vector<Geom::Point>::const_iterator i = points.begin(); i != points.end(); i++) {
+ Geom::Coord dist = Geom::L2(*i - reference);
+ if (i == points.begin() || dist < closest_dist) {
+ closest_point = *i;
+ closest_dist = dist;
+ }
+ }
+
+ points.clear();
+ points.push_back(closest_point);
+}
+
/*
Local Variables:
mode:c++