From 4582ff808a6776266e017cbb5df5b70c461483bc Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 11 Aug 2010 00:18:26 +0200 Subject: Implement constrained snapping to nodes (bzr r9696) --- src/line-snapper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/line-snapper.cpp') diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index 19e6c0fe6..0a1567a47 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -64,7 +64,8 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, Inkscape::SnapCandidatePoint const &p, Geom::OptRect const &/*bbox_to_snap*/, SnapConstraint const &c, - std::vector const */*it*/) const + std::vector const */*it*/, + std::vector */*unselected_nodes*/) const { if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false) { -- cgit v1.2.3 From 4254ddc1b51813c1cd7c8eec31fcbcf16802b1cf Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Fri, 20 Aug 2010 22:20:02 +0200 Subject: When doing a constrained snap, then don't try snapping the mouse pointer itself but try snapping its projection (onto the constraint) instead (bzr r9719) --- src/line-snapper.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/line-snapper.cpp') diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index 0a1567a47..be64438ed 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -72,11 +72,14 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, return; } + // project the mouse pointer onto the constraint. Only the projected point will be considered for snapping + Geom::Point pp = c.projection(p.getPoint()); + /* Get the lines that we will try to snap to */ - const LineList lines = _getSnapLines(p.getPoint()); + const LineList lines = _getSnapLines(pp); for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) { - Geom::Point const point_on_line = c.hasPoint() ? c.getPoint() : p.getPoint(); + Geom::Point const point_on_line = c.hasPoint() ? c.getPoint() : pp; Geom::Line gridguide_line(i->second, i->second + Geom::rot90(i->first)); if (c.isCircular()) { @@ -88,7 +91,7 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, Geom::Coord radius = c.getRadius(); if (dist == radius) { // Only one point of intersection; - _addSnappedPoint(sc, p_proj, Geom::L2(p.getPoint() - p_proj), p.getSourceType(), p.getSourceNum(), true); + _addSnappedPoint(sc, p_proj, Geom::L2(pp - p_proj), p.getSourceType(), p.getSourceNum(), true); } else if (dist < radius) { // Two points of intersection, symmetrical with respect to the projected point // Calculate half the length of the linesegment between the two points of intersection @@ -96,8 +99,8 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, Geom::Coord d = Geom::L2(gridguide_line.versor()); // length of versor, needed to normalize the versor if (d > 0) { Geom::Point v = l*gridguide_line.versor()/d; - _addSnappedPoint(sc, p_proj + v, Geom::L2(p.getPoint() - (p_proj + v)), p.getSourceType(), p.getSourceNum(), true); - _addSnappedPoint(sc, p_proj - v, Geom::L2(p.getPoint() - (p_proj - v)), p.getSourceType(), p.getSourceNum(), true); + _addSnappedPoint(sc, p_proj + v, Geom::L2(pp - (p_proj + v)), p.getSourceType(), p.getSourceNum(), true); + _addSnappedPoint(sc, p_proj - v, Geom::L2(pp - (p_proj - v)), p.getSourceType(), p.getSourceNum(), true); } } } else { @@ -116,7 +119,7 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, if (inters) { Geom::Point t = constraint_line.pointAt((*inters).ta); - const Geom::Coord dist = Geom::L2(t - p.getPoint()); + const Geom::Coord dist = Geom::L2(t - pp); if (dist < getSnapperTolerance()) { // When doing a constrained snap, we're already at an intersection. // This snappoint is therefore fully constrained, so there's no need -- cgit v1.2.3 From 176e8ce89cd15a6bb3469ebac57736b3a0688e35 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Tue, 19 Oct 2010 22:50:03 +0200 Subject: Use a better snap metric for constrained snapping (i.e. calculate the distance to the original point, not the projected point). This should more accurately predict what the user wants to snap to (bzr r9837) --- src/line-snapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/line-snapper.cpp') diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index be64438ed..22a964d43 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -99,8 +99,8 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, Geom::Coord d = Geom::L2(gridguide_line.versor()); // length of versor, needed to normalize the versor if (d > 0) { Geom::Point v = l*gridguide_line.versor()/d; - _addSnappedPoint(sc, p_proj + v, Geom::L2(pp - (p_proj + v)), p.getSourceType(), p.getSourceNum(), true); - _addSnappedPoint(sc, p_proj - v, Geom::L2(pp - (p_proj - v)), p.getSourceType(), p.getSourceNum(), true); + _addSnappedPoint(sc, p_proj + v, Geom::L2(p.getPoint() - (p_proj + v)), p.getSourceType(), p.getSourceNum(), true); + _addSnappedPoint(sc, p_proj - v, Geom::L2(p.getPoint() - (p_proj - v)), p.getSourceType(), p.getSourceNum(), true); } } } else { @@ -119,7 +119,7 @@ void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc, if (inters) { Geom::Point t = constraint_line.pointAt((*inters).ta); - const Geom::Coord dist = Geom::L2(t - pp); + const Geom::Coord dist = Geom::L2(t - p.getPoint()); if (dist < getSnapperTolerance()) { // When doing a constrained snap, we're already at an intersection. // This snappoint is therefore fully constrained, so there's no need -- cgit v1.2.3