From e8f4c644181a8a68e2c33e1783f77a400dc1a29f Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 9 Jan 2010 22:14:38 +0100 Subject: Refactoring the snapping API (making it easier to maintain and understand for the devs) (bzr r8960) --- src/snapped-point.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/snapped-point.cpp') diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index 102e761b9..e3559d655 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -25,6 +25,24 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; + _target_bbox = Geom::Rect(); +} + +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) + : _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; + _fully_constrained = fully_constrained; + _second_distance = NR_HUGE; + _second_tolerance = 1; + _second_always_snap = false; + _transformation = Geom::Point(1,1); + _pointer_distance = NR_HUGE; + _target_bbox = Geom::Rect(); + } 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) @@ -35,6 +53,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const // isOtherSnapBetter. We don't want a division by zero. _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; + _target_bbox = Geom::Rect(); } Inkscape::SnappedPoint::SnappedPoint() @@ -53,6 +72,26 @@ Inkscape::SnappedPoint::SnappedPoint() _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; + _target_bbox = Geom::Rect(); +} + +Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p) +{ + _point = p; + _source = SNAPSOURCE_UNDEFINED, + _source_num = 0, + _target = SNAPTARGET_UNDEFINED, + _at_intersection = false; + _fully_constrained = false; + _distance = NR_HUGE; + _tolerance = 1; + _always_snap = false; + _second_distance = NR_HUGE; + _second_tolerance = 1; + _second_always_snap = false; + _transformation = Geom::Point(1,1); + _pointer_distance = NR_HUGE; + _target_bbox = Geom::Rect(); } Inkscape::SnappedPoint::~SnappedPoint() @@ -69,7 +108,7 @@ void Inkscape::SnappedPoint::getPoint(Geom::Point &p) const } // search for the closest snapped point -bool getClosestSP(std::list &list, Inkscape::SnappedPoint &result) +bool getClosestSP(std::list const &list, Inkscape::SnappedPoint &result) { bool success = false; @@ -86,6 +125,10 @@ bool getClosestSP(std::list &list, Inkscape::SnappedPoin bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &other_one, bool weighted) const { + if (!other_one.getSnapped()) { + return false; + } + double dist_other = other_one.getSnapDistance(); double dist_this = getSnapDistance(); -- cgit v1.2.3 From db3380152e87e88c89691882ffb32bef78db07b0 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Tue, 19 Jan 2010 21:16:06 +0100 Subject: When snapping to a bounding box, flash that bounding box together with the snap indicator (bzr r8999) --- src/snapped-point.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/snapped-point.cpp') diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp index e3559d655..089aa4323 100644 --- a/src/snapped-point.cpp +++ b/src/snapped-point.cpp @@ -14,8 +14,8 @@ #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) - : _point(p), _source(source), _source_num(source_num), _target(target), _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 &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; @@ -25,7 +25,6 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; - _target_bbox = Geom::Rect(); } 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) @@ -41,7 +40,7 @@ Inkscape::SnappedPoint::SnappedPoint(Inkscape::SnapCandidatePoint const &p, Snap _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; - _target_bbox = Geom::Rect(); + _target_bbox = p.getTargetBBox(); } @@ -53,7 +52,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapSourceType const // isOtherSnapBetter. We don't want a division by zero. _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; - _target_bbox = Geom::Rect(); + _target_bbox = Geom::OptRect(); } Inkscape::SnappedPoint::SnappedPoint() @@ -72,7 +71,7 @@ Inkscape::SnappedPoint::SnappedPoint() _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; - _target_bbox = Geom::Rect(); + _target_bbox = Geom::OptRect(); } Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p) @@ -91,7 +90,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p) _second_always_snap = false; _transformation = Geom::Point(1,1); _pointer_distance = NR_HUGE; - _target_bbox = Geom::Rect(); + _target_bbox = Geom::OptRect(); } Inkscape::SnappedPoint::~SnappedPoint() @@ -104,7 +103,7 @@ void Inkscape::SnappedPoint::getPoint(Geom::Point &p) const 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 + } //otherwise p will be left untouched; this way the caller doesn't have to check whether we've snapped } // search for the closest snapped point -- cgit v1.2.3