summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/arc-context.cpp4
-rw-r--r--src/box3d-context.cpp7
-rw-r--r--src/connector-context.cpp2
-rw-r--r--src/context-fns.cpp47
-rw-r--r--src/desktop-events.cpp14
-rw-r--r--src/display/snap-indicator.cpp7
-rw-r--r--src/draw-context.cpp7
-rw-r--r--src/gradient-context.cpp3
-rw-r--r--src/nodepath.cpp6
-rw-r--r--src/object-edit.cpp2
-rw-r--r--src/pencil-context.cpp5
-rw-r--r--src/rect-context.cpp7
-rw-r--r--src/seltrans.cpp4
-rw-r--r--src/snap.cpp51
-rw-r--r--src/snap.h40
-rw-r--r--src/snapped-point.cpp8
-rw-r--r--src/snapped-point.h16
-rw-r--r--src/spiral-context.cpp6
-rw-r--r--src/star-context.cpp6
19 files changed, 164 insertions, 78 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index 07f5f4826..6169d000f 100644
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
@@ -265,7 +265,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, ac->item);
- ac->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, ac->center).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, ac->center);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -292,7 +292,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, ac->item);
- motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
sp_arc_drag(ac, motion_dt, event->motion.state);
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index ca6822dda..a7cead93e 100644
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -332,7 +332,8 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven
/* Snap center */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, bc->item);
- bc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt);
+ bc->center = button_dt;
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
( GDK_KEY_PRESS_MASK |
@@ -363,7 +364,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, bc->item);
- motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK;
@@ -396,7 +397,7 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven
bc->drag_ptB_proj.normalize();
bc->drag_ptC_proj = cur_persp->tmat.preimage (motion_dt, bc->drag_ptB_proj[Proj::X], Proj::X);
}
- bc->drag_ptC = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, bc->drag_ptC).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, bc->drag_ptC);
}
sp_box3d_drag(*bc, event->motion.state);
diff --git a/src/connector-context.cpp b/src/connector-context.cpp
index 3c1669fa6..e33b11e64 100644
--- a/src/connector-context.cpp
+++ b/src/connector-context.cpp
@@ -532,7 +532,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
// as there's no other points to go off.
SnapManager &m = cc->desktop->namedview->snap_manager;
m.setup(cc->desktop);
- p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
}
spcc_connector_set_initial_point(cc, p);
diff --git a/src/context-fns.cpp b/src/context-fns.cpp
index 83048af40..61b6a2fc4 100644
--- a/src/context-fns.cpp
+++ b/src/context-fns.cpp
@@ -86,7 +86,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
bool const control = state & GDK_CONTROL_MASK;
SnapManager &m = desktop->namedview->snap_manager;
- m.setup(desktop, item);
+ m.setup(NULL, item);
Inkscape::SnappedPoint snappoint;
if (control) {
@@ -141,23 +141,27 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
/* Choose the best snap and update points accordingly */
if (s[0].getDistance() < s[1].getDistance()) {
- p[0] = s[0].getPoint();
- p[1] = 2 * center - s[0].getPoint();
- snappoint = s[0];
+ if (s[0].getSnapped()) {
+ p[0] = s[0].getPoint();
+ p[1] = 2 * center - s[0].getPoint();
+ snappoint = s[0];
+ }
} else {
- p[0] = 2 * center - s[1].getPoint();
- p[1] = s[1].getPoint();
- snappoint = s[1];
+ if (s[1].getSnapped()) {
+ p[0] = 2 * center - s[1].getPoint();
+ p[1] = s[1].getPoint();
+ snappoint = s[1];
+ }
}
- desktop->snapindicator->set_new_snappoint(snappoint);
-
} else {
/* Our origin is the opposite corner. Snap the drag point along the constraint vector */
p[0] = center;
snappoint = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1],
Inkscape::Snapper::ConstraintLine(p[1] - p[0]));
- p[1] = snappoint.getPoint();
+ if (snappoint.getSnapped()) {
+ p[1] = snappoint.getPoint();
+ }
}
} else if (shift) {
@@ -175,13 +179,17 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
s[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1]);
if (s[0].getDistance() < s[1].getDistance()) {
- p[0] = s[0].getPoint();
- p[1] = 2 * center - s[0].getPoint();
- snappoint = s[0];
+ if (s[0].getSnapped()) {
+ p[0] = s[0].getPoint();
+ p[1] = 2 * center - s[0].getPoint();
+ snappoint = s[0];
+ }
} else {
- p[0] = 2 * center - s[1].getPoint();
- p[1] = s[1].getPoint();
- snappoint = s[1];
+ if (s[1].getSnapped()) {
+ p[0] = 2 * center - s[1].getPoint();
+ p[1] = s[1].getPoint();
+ snappoint = s[1];
+ }
}
} else {
@@ -189,12 +197,13 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
/* There's no constraint on the corner point, so just snap it to anything */
p[0] = center;
snappoint = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt);
- p[1] = snappoint.getPoint();
+ if (snappoint.getSnapped()) {
+ p[1] = snappoint.getPoint();
+ }
}
if (snappoint.getSnapped()) {
- // this does not work well enough yet.
-// desktop->snapindicator->set_new_snappoint(snappoint);
+ desktop->snapindicator->set_new_snappoint(snappoint);
}
p[0] = sp_desktop_dt2root_xy_point(desktop, p[0]);
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index 29734f459..e151f0ac9 100644
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
@@ -144,9 +144,8 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- Inkscape::SnappedPoint snappoint = m.guideSnap(event_dt, normal);
- event_dt = snappoint.getPoint();
-
+ m.guideSnap(event_dt, normal);
+
sp_guideline_set_position(SP_GUIDELINE(guide), event_dt.to_2geom());
desktop->set_coordinate_status(event_dt);
desktop->setPosition (event_dt);
@@ -160,7 +159,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- event_dt = m.guideSnap(event_dt, normal).getPoint();
+ m.guideSnap(event_dt, normal);
dragging = false;
gtk_object_destroy(GTK_OBJECT(guide));
@@ -243,9 +242,8 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
// which are dragged off the ruler, are being snapped in sp_dt_ruler_event
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- Inkscape::SnappedPoint snappoint = m.guideSnap(motion_dt, guide->normal_to_line);
- motion_dt = snappoint.getPoint();
-
+ m.guideSnap(motion_dt, guide->normal_to_line);
+
sp_guide_moveto(*guide, motion_dt.to_2geom(), false);
moved = true;
desktop->set_coordinate_status(motion_dt);
@@ -263,7 +261,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint();
+ m.guideSnap(event_dt, guide->normal_to_line);
if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
sp_guide_moveto(*guide, event_dt.to_2geom(), true);
diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp
index e08fc06d6..59578123e 100644
--- a/src/display/snap-indicator.cpp
+++ b/src/display/snap-indicator.cpp
@@ -40,6 +40,13 @@ SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
remove_snappoint();
g_assert(_desktop != NULL);
+
+ /* Commented out for now, because this might hide any snapping bug!
+ if (!p.getSnapped()) {
+ return; // If we haven't snapped, then it is of no use to draw a snapindicator
+ }
+ */
+
SPNamedView *nv = sp_desktop_namedview(_desktop);
if (nv->snapindicator) {
diff --git a/src/draw-context.cpp b/src/draw-context.cpp
index 50799b55f..f4d7a8569 100644
--- a/src/draw-context.cpp
+++ b/src/draw-context.cpp
@@ -356,9 +356,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N
/* Snap it along best vector */
SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
- Inkscape::SnappedPoint const s = m.constrainedSnap( Inkscape::Snapper::SNAPPOINT_NODE,
- p, Inkscape::Snapper::ConstraintLine(best));
- p = s.getPoint();
+ m.constrainedSnap( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best));
}
}
@@ -372,8 +370,7 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin
SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
- Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
- p = s.getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
}
static SPCurve *
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index 86bce50b9..e4cdd707f 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -554,7 +554,8 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
/* Snap center to nearest magnetic point */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- rc->origin = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt);
+ rc->origin = button_dt;
}
ret = TRUE;
diff --git a/src/nodepath.cpp b/src/nodepath.cpp
index c3d0f09b4..ffbec8a8b 100644
--- a/src/nodepath.cpp
+++ b/src/nodepath.cpp
@@ -1233,7 +1233,7 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath,
Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
m.setup(nodepath->desktop, SP_PATH(n->subpath->nodepath->item), &unselected_nodes);
Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, n->pos + delta);
- if (s.getDistance() < best) {
+ if (s.getSnapped() && (s.getDistance() < best)) {
best = s.getDistance();
best_abs = s;
best_pt = s.getPoint() - n->pos;
@@ -3684,8 +3684,8 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint /*state*/,
s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p);
}
- *p = s.getPoint();
-
+ s.getPoint(*p);
+
sp_node_adjust_handle(n, -which);
return FALSE;
diff --git a/src/object-edit.cpp b/src/object-edit.cpp
index 3d4aaae39..0abf84a1f 100644
--- a/src/object-edit.cpp
+++ b/src/object-edit.cpp
@@ -224,7 +224,7 @@ static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
NR::Point s = p * i2d;
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, item);
- s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, s).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, s);
return s * i2d.inverse();
}
diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index ae3a2fa48..87cbb8d12 100644
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
@@ -248,7 +248,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
} else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
}
@@ -325,8 +325,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev
} else if ((mevent.state & GDK_SHIFT_MASK) == 0) {
SnapManager &m = dt->namedview->snap_manager;
m.setup(dt, NULL);
- Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
- p = s.getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p);
}
if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context!
spdc_add_freehand_point(pc, p, mevent.state);
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index ad383b014..b8047b201 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -306,8 +306,8 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
/* Snap center */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, rc->item);
- Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt);
- rc->center = s.getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt);
+ rc->center = button_dt;
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
( GDK_KEY_PRESS_MASK |
@@ -338,8 +338,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, rc->item);
- Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
- motion_dt = s.getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
sp_rect_drag(*rc, motion_dt, event->motion.state);
gobble_motion_events(GDK_BUTTON1_MASK);
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index e34f6ba83..432b1e670 100644
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -1261,7 +1261,7 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
{
SnapManager &m = _desktop->namedview->snap_manager;
m.setup(_desktop);
- pt = m.freeSnap(Snapper::SNAPPOINT_NODE, pt).getPoint();
+ m.freeSnap(Snapper::SNAPPOINT_NODE, pt);
if (state & GDK_CONTROL_MASK) {
if ( fabs(_point[NR::X] - pt[NR::X]) > fabs(_point[NR::Y] - pt[NR::Y]) ) {
@@ -1369,7 +1369,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
** FIXME: this will snap to more than just the grid, nowadays.
*/
- dxy = m.freeSnap(Snapper::SNAPPOINT_NODE, dxy).getPoint();
+ m.freeSnap(Snapper::SNAPPOINT_NODE, dxy);
} else if (!shift) {
diff --git a/src/snap.cpp b/src/snap.cpp
index 885147063..bc81bdf3a 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -179,6 +179,26 @@ bool SnapManager::getSnapModeGuide() const
* \return Snapped point.
*/
+void SnapManager::freeSnapVoid(Inkscape::Snapper::PointType point_type,
+ NR::Point &p,
+ bool first_point,
+ NR::Maybe<NR::Rect> const &bbox_to_snap) const
+{
+ Inkscape::SnappedPoint const s = freeSnap(point_type, p, first_point, bbox_to_snap);
+ s.getPoint(p);
+}
+
+/**
+ * Try to snap a point to any of the specified snappers.
+ *
+ * \param point_type Type of point.
+ * \param p Point.
+ * \param first_point If true then this point is the first one from a whole bunch of points
+ * \param points_to_snap The whole bunch of points, all from the same selection and having the same transformation
+ * \param snappers List of snappers to try to snap to
+ * \return Snapped point.
+ */
+
Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::Snapper::PointType point_type,
NR::Point const &p,
bool first_point,
@@ -224,6 +244,28 @@ Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::Snapper::PointType point_
* \return Snapped point.
*/
+void SnapManager::constrainedSnapVoid(Inkscape::Snapper::PointType point_type,
+ NR::Point &p,
+ Inkscape::Snapper::ConstraintLine const &constraint,
+ bool first_point,
+ NR::Maybe<NR::Rect> const &bbox_to_snap) const
+{
+ Inkscape::SnappedPoint const s = constrainedSnap(point_type, p, constraint, first_point, bbox_to_snap);
+ s.getPoint(p);
+}
+
+/**
+ * Try to snap a point to any interested snappers. A snap will only occur along
+ * a line described by a Inkscape::Snapper::ConstraintLine.
+ *
+ * \param point_type Type of point.
+ * \param p Point.
+ * \param first_point If true then this point is the first one from a whole bunch of points
+ * \param points_to_snap The whole bunch of points, all from the same selection and having the same transformation
+ * \param constraint Constraint line.
+ * \return Snapped point.
+ */
+
Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::Snapper::PointType point_type,
NR::Point const &p,
Inkscape::Snapper::ConstraintLine const &constraint,
@@ -257,19 +299,19 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::Snapper::PointType
return findBestSnap(p, sc, true);
}
-Inkscape::SnappedPoint SnapManager::guideSnap(NR::Point const &p,
- NR::Point const &guide_normal) const
+void SnapManager::guideSnap(NR::Point &p, NR::Point const &guide_normal) const
{
// This method is used to snap a guide to nodes, while dragging the guide around
if (!(object.GuidesMightSnap() && _snap_enabled_globally)) {
- return Inkscape::SnappedPoint(p, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false);
+ return;
}
SnappedConstraints sc;
object.guideSnap(sc, p, guide_normal);
- return findBestSnap(p, sc, false);
+ Inkscape::SnappedPoint const s = findBestSnap(p, sc, false);
+ s.getPoint(p);
}
@@ -309,6 +351,7 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
** Also used to globally disable all snapping
*/
if (SomeSnapperMightSnap() == false) {
+ g_assert(points.size() > 0);
return Inkscape::SnappedPoint();
}
diff --git a/src/snap.h b/src/snap.h
index f49eb7145..900f548ce 100644
--- a/src/snap.h
+++ b/src/snap.h
@@ -50,19 +50,33 @@ public:
void setup(SPDesktop const *desktop_for_snapindicator = NULL, SPItem const *item_to_ignore = NULL, std::vector<NR::Point> *unselected_nodes = NULL);
void setup(SPDesktop const *desktop_for_snapindicator, std::vector<SPItem const *> &items_to_ignore, std::vector<NR::Point> *unselected_nodes = NULL);
+ // freeSnapVoid() is preferred over freeSnap(), because it only returns a
+ // point, by overwriting p, if snapping has occured; otherwise p is untouched
+ void freeSnapVoid(Inkscape::Snapper::PointType point_type,
+ NR::Point &p,
+ bool first_point = true,
+ NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
+
Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType point_type,
NR::Point const &p,
bool first_point = true,
NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
-
+
+ // constrainedSnapVoid() is preferred over constrainedSnap(), because it only returns a
+ // point, by overwriting p, if snapping has occured; otherwise p is untouched
+ void constrainedSnapVoid(Inkscape::Snapper::PointType point_type,
+ NR::Point &p,
+ Inkscape::Snapper::ConstraintLine const &constraint,
+ bool first_point = true,
+ NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
+
Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType point_type,
NR::Point const &p,
Inkscape::Snapper::ConstraintLine const &constraint,
bool first_point = true,
NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
- Inkscape::SnappedPoint guideSnap(NR::Point const &p,
- NR::Point const &guide_normal) const;
+ void guideSnap(NR::Point &p, NR::Point const &guide_normal) const;
Inkscape::SnappedPoint freeSnapTranslation(Inkscape::Snapper::PointType point_type,
std::vector<NR::Point> const &p,
@@ -84,18 +98,18 @@ public:
NR::Point const &o) const;
Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::Snapper::PointType point_type,
- std::vector<NR::Point> const &p,
- NR::Coord const &s,
- NR::Point const &o,
- NR::Dim2 d,
- bool uniform) const;
+ std::vector<NR::Point> const &p,
+ NR::Coord const &s,
+ NR::Point const &o,
+ NR::Dim2 d,
+ bool uniform) const;
Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::Snapper::PointType point_type,
- std::vector<NR::Point> const &p,
- Inkscape::Snapper::ConstraintLine const &constraint,
- NR::Point const &s, // s[0] = skew factor, s[1] = scale factor
- NR::Point const &o,
- NR::Dim2 d) const;
+ std::vector<NR::Point> const &p,
+ Inkscape::Snapper::ConstraintLine const &constraint,
+ NR::Point const &s, // s[0] = skew factor, s[1] = scale factor
+ NR::Point const &o,
+ NR::Dim2 d) const;
Inkscape::GuideSnapper guide; ///< guide snapper
Inkscape::ObjectSnapper object; ///< snapper to other objects
diff --git a/src/snapped-point.cpp b/src/snapped-point.cpp
index 4e5ca836d..02f7ed165 100644
--- a/src/snapped-point.cpp
+++ b/src/snapped-point.cpp
@@ -80,9 +80,13 @@ bool Inkscape::SnappedPoint::getSecondAlwaysSnap() const
}
-NR::Point Inkscape::SnappedPoint::getPoint() const
+void Inkscape::SnappedPoint::getPoint(NR::Point &p) const
{
- return _point;
+ // When we have snapped
+ 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
}
// search for the closest snapped point
diff --git a/src/snapped-point.h b/src/snapped-point.h
index 372031955..2c74025c8 100644
--- a/src/snapped-point.h
+++ b/src/snapped-point.h
@@ -53,7 +53,21 @@ public:
NR::Coord getSecondDistance() const;
NR::Coord getSecondTolerance() const;
bool getSecondAlwaysSnap() const;
- NR::Point getPoint() const;
+
+ /* 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(NR::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
+ */
+ NR::Point getPoint() const {return _point;}
+
bool getAtIntersection() const {return _at_intersection;}
bool getSnapped() const {return _distance < NR_HUGE;}
NR::Point getTransformation() const {return _transformation;}
diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp
index a4c402f40..57c06e4a3 100644
--- a/src/spiral-context.cpp
+++ b/src/spiral-context.cpp
@@ -267,7 +267,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
( GDK_KEY_PRESS_MASK |
@@ -296,7 +296,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
sp_spiral_drag(sc, motion_dt, event->motion.state);
gobble_motion_events(GDK_BUTTON1_MASK);
@@ -440,7 +440,7 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state)
NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1);
SPSpiral *spiral = SP_SPIRAL(sc->item);
diff --git a/src/star-context.cpp b/src/star-context.cpp
index 816e6b779..afdb14a0c 100644
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
@@ -282,7 +282,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, sc->center);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -309,7 +309,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
sp_star_drag (sc, motion_dt, event->motion.state);
@@ -455,7 +455,7 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
/* Snap corner point with no constraints */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, sc->item);
- p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1).getPoint();
+ m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1);
SPStar *star = SP_STAR(sc->item);