diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2009-04-12 11:38:21 +0000 |
|---|---|---|
| committer | dvlierop2 <dvlierop2@users.sourceforge.net> | 2009-04-12 11:38:21 +0000 |
| commit | 92e3a3aa6fedb352e7a20d87d2480a0a504e541a (patch) | |
| tree | cf18174de25be64e06960d3715440b74edf3467e /src/snapped-point.cpp | |
| parent | Fix two missing icons in live effect parameters (diff) | |
| download | inkscape-92e3a3aa6fedb352e7a20d87d2480a0a504e541a.tar.gz inkscape-92e3a3aa6fedb352e7a20d87d2480a0a504e541a.zip | |
Fix snapping during constrained translation, when only snapping the node closest to the mouse pointer
(bzr r7687)
Diffstat (limited to 'src/snapped-point.cpp')
| -rw-r--r-- | src/snapped-point.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index 7e9a16a66..2d028c6d7 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -73,7 +73,7 @@ bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoin bool success = false; for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); i++) { - if ((i == list.begin()) || (*i).getSnapDistance() < result.getSnapDistance()) { + if ((i == list.begin()) || (*i).getSnapDistance() < result.getSnapDistance()) { result = *i; success = true; } @@ -92,7 +92,10 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth // there's more than one). It is not useful when trying to find the best snapped target point. // (both the snap distance and the pointer distance are measured in document pixels, not in screen pixels) if (weighted) { - // Weight factor: controls which node should be preferred for snapping, which is either + + Geom::Coord const dist_pointer_other = other_one.getPointerDistance(); + Geom::Coord const dist_pointer_this = getPointerDistance(); + // Weight factor: controls which node should be preferred for snapping, which is either // the node with the closest snap (w = 0), or the node closest to the mousepointer (w = 1) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double w = prefs->getDoubleLimited("/options/snapweight/value", 0.5, 0, 1); @@ -100,19 +103,21 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth w = 1; } if (w > 0) { - // When accounting for the distance to the mouse pointer, then at least one of the snapped points should - // have that distance set. If not, then this is a bug. Either "weighted" must be set to false, or the - // mouse pointer distance must be set. - g_assert(getPointerDistance() != NR_HUGE || other_one.getPointerDistance() != NR_HUGE); - // The snap distance will always be smaller than the tolerance set for the snapper. The pointer distance can - // however be very large. To compare these in a fair way, we will have to normalize these metrics first - // The closest pointer distance will be normalized to 1.0; the other one will be > 1.0 - // The snap distance will be normalized to 1.0 if it's equal to the snapper tolerance - double const norm_p = std::min(getPointerDistance(), other_one.getPointerDistance()); - double const norm_t_other = std::min(50.0, other_one.getTolerance()); - double const norm_t_this = std::min(50.0, getTolerance()); - dist_other = w * other_one.getPointerDistance() / norm_p + (1-w) * dist_other / norm_t_other; - dist_this = w * getPointerDistance() / norm_p + (1-w) * dist_this / norm_t_this; + if (!(w == 1 && dist_pointer_this == dist_pointer_other)) { + // When accounting for the distance to the mouse pointer, then at least one of the snapped points should + // have that distance set. If not, then this is a bug. Either "weighted" must be set to false, or the + // mouse pointer distance must be set. + g_assert(dist_pointer_this != NR_HUGE || dist_pointer_other != NR_HUGE); + // The snap distance will always be smaller than the tolerance set for the snapper. The pointer distance can + // however be very large. To compare these in a fair way, we will have to normalize these metrics first + // The closest pointer distance will be normalized to 1.0; the other one will be > 1.0 + // The snap distance will be normalized to 1.0 if it's equal to the snapper tolerance + double const norm_p = std::min(dist_pointer_this, dist_pointer_other); + double const norm_t_other = std::min(50.0, other_one.getTolerance()); + double const norm_t_this = std::min(50.0, getTolerance()); + dist_other = w * dist_pointer_other / norm_p + (1-w) * dist_other / norm_t_other; + dist_this = w * dist_pointer_this / norm_p + (1-w) * dist_this / norm_t_this; + } } } |
