summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/snapped-point.cpp9
-rw-r--r--src/snapped-point.h52
2 files changed, 39 insertions, 22 deletions
diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp
index fc6e5e87f..44b69050f 100644
--- a/src/snapped-point.cpp
+++ b/src/snapped-point.cpp
@@ -18,6 +18,7 @@ Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const
: _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.
+ _at_intersection = false;
_fully_constrained = fully_constrained;
_second_distance = NR_HUGE;
_second_tolerance = 1;
@@ -40,10 +41,11 @@ Inkscape::SnappedPoint::SnappedPoint()
{
_point = Geom::Point(0,0);
_target = SNAPTARGET_UNDEFINED,
+ _at_intersection = false;
+ _fully_constrained = false;
_distance = NR_HUGE;
_tolerance = 1;
_always_snap = false;
- _at_intersection = false;
_second_distance = NR_HUGE;
_second_tolerance = 1;
_second_always_snap = false;
@@ -89,7 +91,7 @@ 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) {
- // weigth factor: controls which node should be preferrerd for snapping, which is either
+ // 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);
@@ -114,7 +116,7 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth
}
// If it's closer
- bool c1 = dist_other < dist_this;
+ 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
@@ -127,6 +129,7 @@ bool Inkscape::SnappedPoint::isOtherSnapBetter(Inkscape::SnappedPoint const &oth
bool c4a = (dist_other == dist_this);
bool c4b = other_one.getSecondSnapDistance() < getSecondSnapDistance();
+ // std::cout << other_one.getPoint() << " (Other one) vs. " << getPoint() << " (this one) ---> ";
// 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);
}
diff --git a/src/snapped-point.h b/src/snapped-point.h
index b50207429..dbd672bdf 100644
--- a/src/snapped-point.h
+++ b/src/snapped-point.h
@@ -35,7 +35,7 @@ enum SnapTargetType {
SNAPTARGET_BBOX_EDGE,
SNAPTARGET_GRADIENT
};
-
+
/// Class describing the result of an attempt to snap.
class SnappedPoint
{
@@ -56,49 +56,64 @@ public:
bool getSecondAlwaysSnap() const {return _second_always_snap;}
Geom::Coord getPointerDistance() const {return _pointer_distance;}
void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;}
-
+
/* This is the preferred method to find out which point we have snapped
* to, because it only returns a point if snapping has actually occured
* (by overwriting p)
- */
+ */
void getPoint(Geom::Point &p) const;
-
+
/* This method however always returns a point, even if no snapping
* has occured; A check should be implemented in the calling code
* to check for snapping. Use this method only when really needed, e.g.
* when the calling code is trying to snap multiple points and must
* determine itself which point is most appropriate
- */
+ */
Geom::Point getPoint() const {return _point;}
-
+
bool getAtIntersection() const {return _at_intersection;}
- bool getFullyConstrained() const {return _fully_constrained;}
+ bool getFullyConstrained() const {return _fully_constrained;}
bool getSnapped() const {return _distance < NR_HUGE;}
Geom::Point getTransformation() const {return _transformation;}
void setTransformation(Geom::Point const t) {_transformation = t;}
void setTarget(SnapTargetType const target) {_target = target;}
SnapTargetType getTarget() {return _target;}
-
+
bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
-
+
+ /*void dump() const {
+ std::cout << "_point = " << _point << std::endl;
+ std::cout << "_target = " << _target << std::endl;
+ std::cout << "_at_intersection = " << _at_intersection << std::endl;
+ std::cout << "_fully_constrained = " << _fully_constrained << std::endl;
+ std::cout << "_distance = " << _distance << std::endl;
+ std::cout << "_tolerance = " << _tolerance << std::endl;
+ std::cout << "_always_snap = " << _always_snap << std::endl;
+ std::cout << "_second_distance = " << _second_distance << std::endl;
+ std::cout << "_second_tolerance = " << _second_tolerance << std::endl;
+ std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
+ std::cout << "_transformation = " << _transformation << std::endl;
+ std::cout << "_pointer_distance = " << _pointer_distance << std::endl;
+ }*/
+
protected:
Geom::Point _point; // Location of the snapped point
SnapTargetType _target; // Describes to what we've snapped to
bool _at_intersection; // If true, the snapped point is at an intersection
- bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
+ bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
// When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
-
+
/* Distance from original point to snapped point. If the snapped point is at
an intersection of e.g. two lines, then this is the distance to the closest
- line */
- Geom::Coord _distance;
- /* The snapping tolerance in screen pixels (depends on zoom)*/
+ line */
+ Geom::Coord _distance;
+ /* The snapping tolerance in screen pixels (depends on zoom)*/
Geom::Coord _tolerance;
/* If true then "Always snap" is on */
bool _always_snap;
-
+
/* If the snapped point is at an intersection of e.g. two lines, then this is
- the distance to the fartest line */
+ the distance to the fartest line */
Geom::Coord _second_distance;
/* The snapping tolerance in screen pixels (depends on zoom)*/
Geom::Coord _second_tolerance;
@@ -108,13 +123,12 @@ protected:
Geom::Point _transformation;
/* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
Geom::Coord _pointer_distance;
-};
+};
-}
+}// end of namespace Inkscape
bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
-
#endif /* !SEEN_SNAPPEDPOINT_H */
/*