diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2008-12-10 21:51:33 +0000 |
|---|---|---|
| committer | dvlierop2 <dvlierop2@users.sourceforge.net> | 2008-12-10 21:51:33 +0000 |
| commit | 7871a41b0b05192d52c1fa308fe788c2c30fe1a6 (patch) | |
| tree | 8afcac51da062efe12e17d8c51183103261ec265 /src/snapped-point.cpp | |
| parent | * Removing the bitmap files that aren't being used. (diff) | |
| download | inkscape-7871a41b0b05192d52c1fa308fe788c2c30fe1a6.tar.gz inkscape-7871a41b0b05192d52c1fa308fe788c2c30fe1a6.zip | |
- Fix bug #304405 (snapping to an intersection of lines at infinity is wrong)
- Replace tabs by spaces
(bzr r6985)
Diffstat (limited to 'src/snapped-point.cpp')
| -rw-r--r-- | src/snapped-point.cpp | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index c5eaba749..fc6e5e87f 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -17,7 +17,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained) : _point(p), _target(target), _distance(d), _tolerance(std::max(t,1.0)), _always_snap(a) { - // tolerance should never be smaller than 1 px, as it is used for normalization in isOtherSnapBetter. We don't want a division by zero. + // tolerance should never be smaller than 1 px, as it is used for normalization in isOtherSnapBetter. We don't want a division by zero. _fully_constrained = fully_constrained; _second_distance = NR_HUGE; _second_tolerance = 1; @@ -30,7 +30,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const : _point(p), _target(target), _at_intersection(at_intersection), _fully_constrained(fully_constrained), _distance(d), _tolerance(std::max(t,1.0)), _always_snap(a), _second_distance(d2), _second_tolerance(std::max(t2,1.0)), _second_always_snap(a2) { - // tolerance should never be smaller than 1 px, as it is used for normalization in + // tolerance should never be smaller than 1 px, as it is used for normalization in // isOtherSnapBetter. We don't want a division by zero. _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; @@ -39,7 +39,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const Inkscape::SnappedPoint::SnappedPoint() { _point = Geom::Point(0,0); - _target = SNAPTARGET_UNDEFINED, + _target = SNAPTARGET_UNDEFINED, _distance = NR_HUGE; _tolerance = 1; _always_snap = false; @@ -58,7 +58,7 @@ Inkscape::SnappedPoint::~SnappedPoint() void Inkscape::SnappedPoint::getPoint(Geom::Point &p) const { // When we have snapped - if (getSnapped()) { + if (getSnapped()) { // then return the snapped point by overwriting p p = _point; } //otherwise p will be left untouched; this way the caller doesn't have to check wether we've snapped @@ -81,55 +81,54 @@ bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoin bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &other_one, bool weighted) const { - - double dist_other = other_one.getSnapDistance(); - double dist_this = getSnapDistance(); - - // The distance to the pointer should only be taken into account when finding the best snapped source node (when + + double dist_other = other_one.getSnapDistance(); + double dist_this = getSnapDistance(); + + // The distance to the pointer should only be taken into account when finding the best snapped source node (when // 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) { - // weigth factor: controls which node should be preferrerd 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); - if (prefs->getBool("/options/snapclosestonly/value", false)) { - 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; - } - } - + // weigth factor: controls which node should be preferrerd 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); + if (prefs->getBool("/options/snapclosestonly/value", false)) { + 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 it's closer bool c1 = dist_other < dist_this; // or, if it's for a snapper with "always snap" turned on, and the previous wasn't bool c2 = other_one.getAlwaysSnap() && !getAlwaysSnap(); // But in no case fall back from a snapper with "always snap" on to one with "always snap" off bool c2n = !other_one.getAlwaysSnap() && getAlwaysSnap(); - // or, if we have a fully constrained snappoint (e.g. to a node), while the previous one was only partly constrained (e.g. to a line) + // or, if we have a fully constrained snappoint (e.g. to a node or an intersection), while the previous one was only partly constrained (e.g. to a line) bool c3 = other_one.getFullyConstrained() && !getFullyConstrained(); - // But in no case fall back; (has less priority than c3n, so it is allowed to fall back when c3 is true, see below) - bool c3n = !other_one.getFullyConstrained() && getFullyConstrained(); + // But in no case fall back; (has less priority than c3n, so it is allowed to fall back when c3 is true, see below) + bool c3n = !other_one.getFullyConstrained() && getFullyConstrained(); // or, if it's just as close then consider the second distance - // (which is only relevant for points at an intersection) - bool c4a = (dist_other == dist_this); + bool c4a = (dist_other == dist_this); bool c4b = other_one.getSecondSnapDistance() < getSecondSnapDistance(); - + // std::cout << "c1 = " << c1 << " | c2 = " << c2 << " | c2n = " << c2n << " | c3 = " << c3 << " | c3n = " << c3n << " | c4a = " << c4a << " | c4b = " << c4b << std::endl; - return (c1 || c2 || c3 || (c4a && c4b)) && !c2n && (!c3n || c2); + return (c1 || c2 || c3 || (c4a && c4b)) && !c2n && (!c3n || c2); } /* |
