diff options
| author | Diederik van Lierop <mailat-signdiedenrezidotnl> | 2010-05-08 21:27:22 +0000 |
|---|---|---|
| committer | Diederik van Lierop <mailat-signdiedenrezidotnl> | 2010-05-08 21:27:22 +0000 |
| commit | f9ab8626b2915e99acb6c5d759f5fa5d9e350a89 (patch) | |
| tree | 34016bf36e7e846ce9fe103107f4a5eda2516510 /src/snapped-point.cpp | |
| parent | Extensions. Fix for XAML export objects properties and layer visibility (Bug ... (diff) | |
| download | inkscape-f9ab8626b2915e99acb6c5d759f5fa5d9e350a89.tar.gz inkscape-f9ab8626b2915e99acb6c5d759f5fa5d9e350a89.zip | |
Fix bounding box snapping (LP562205, comment 6, issue II)
(bzr r9402)
Diffstat (limited to 'src/snapped-point.cpp')
| -rw-r--r-- | src/snapped-point.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index 508ec8f62..352f2dd1e 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -14,11 +14,12 @@ #include "preferences.h" // overloaded constructor -Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained, Geom::OptRect target_bbox) +Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &constrained_snap, bool const &fully_constrained, Geom::OptRect target_bbox) : _point(p), _source(source), _source_num(source_num), _target(target), _distance(d), _tolerance(std::max(t,1.0)), _always_snap(a), _target_bbox(target_bbox) { // tolerance should never be smaller than 1 px, as it is used for normalization in isOtherSnapBetter. We don't want a division by zero. _at_intersection = false; + _constrained_snap = constrained_snap; _fully_constrained = fully_constrained; _second_distance = NR_HUGE; _second_tolerance = 1; @@ -27,13 +28,14 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const _pointer_distance = NR_HUGE; } -Inkscape::SnappedPoint::SnappedPoint(Inkscape::SnapCandidatePoint const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained) +Inkscape::SnappedPoint::SnappedPoint(Inkscape::SnapCandidatePoint const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &constrained_snap, bool const &fully_constrained) : _target(target), _distance(d), _tolerance(std::max(t,1.0)), _always_snap(a) { _point = p.getPoint(); _source = p.getSourceType(); _source_num = p.getSourceNum(); _at_intersection = false; + _constrained_snap = constrained_snap; _fully_constrained = fully_constrained; _second_distance = NR_HUGE; _second_tolerance = 1; @@ -44,8 +46,8 @@ Inkscape::SnappedPoint::SnappedPoint(Inkscape::SnapCandidatePoint const &p, Snap } -Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2) - : _point(p), _source(source), _source_num(source_num), _target(target), _at_intersection(at_intersection), _fully_constrained(fully_constrained), _distance(d), _tolerance(std::max(t,1.0)), _always_snap(a), +Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, bool const &constrained_snap, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2) + : _point(p), _source(source), _source_num(source_num), _target(target), _at_intersection(at_intersection), _constrained_snap(constrained_snap), _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 @@ -62,6 +64,7 @@ Inkscape::SnappedPoint::SnappedPoint() _source_num = 0, _target = SNAPTARGET_UNDEFINED, _at_intersection = false; + _constrained_snap = false; _fully_constrained = false; _distance = NR_HUGE; _tolerance = 1; @@ -155,7 +158,8 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth // 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_p = std::min(dist_pointer_this, dist_pointer_other) + 1; + // make sure norm_p is never too close to zero (e.g. when snapping the bbox-corner that was grabbed), by incr. with 1 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; @@ -180,9 +184,9 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth // 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 or an intersection), while the previous one was only partly constrained (e.g. to a line) - bool c3 = other_one.getFullyConstrained() && !getFullyConstrained(); + bool c3 = (other_one.getFullyConstrained() && !other_one.getConstrainedSnap()) && !getFullyConstrained(); // Do not consider constrained snaps here, because these will always be fully constrained anyway // 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(); + bool c3n = !other_one.getFullyConstrained() && (getFullyConstrained() && !getConstrainedSnap()); // When both are fully constrained AND coincident, then prefer nodes over intersections bool d = other_one.getFullyConstrained() && getFullyConstrained() && (Geom::L2(other_one.getPoint() - getPoint()) < 1e-9); @@ -192,7 +196,7 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth // or, if it's just as close then consider the second distance bool c5a = (dist_other == dist_this); - bool c5b = other_one.getSecondSnapDistance() < getSecondSnapDistance(); + bool c5b = (other_one.getSecondSnapDistance() < getSecondSnapDistance()) && (getSecondSnapDistance() < NR_HUGE); // std::cout << other_one.getPoint() << " (Other one, dist = " << dist_other << ") vs. " << getPoint() << " (this one, dist = " << dist_this << ") ---> "; // std::cout << "c1 = " << c1 << " | c2 = " << c2 << " | c2n = " << c2n << " | c3 = " << c3 << " | c3n = " << c3n << " | c4 = " << c4 << " | c4n = " << c4n << " | c5a = " << c5a << " | c5b = " << c5b << std::endl; |
