diff options
Diffstat (limited to 'src/line-snapper.cpp')
| -rw-r--r-- | src/line-snapper.cpp | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index cf46671c8..3b91fb015 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -2,74 +2,65 @@ #include "libnr/nr-point-fns.h" #include "geom.h" #include "line-snapper.h" +#include "snapped-line.cpp" Inkscape::LineSnapper::LineSnapper(SPNamedView const *nv, NR::Coord const d) : Snapper(nv, d) { } -Inkscape::SnappedPoint Inkscape::LineSnapper::_doFreeSnap(Inkscape::Snapper::PointType const &t, +void Inkscape::LineSnapper::_doFreeSnap(SnappedConstraints &sc, + Inkscape::Snapper::PointType const &t, NR::Point const &p, bool const &f, std::vector<NR::Point> &points_to_snap, std::list<SPItem const *> const &it) const { - /* Snap along x (ie to vertical lines) */ - Inkscape::SnappedPoint const v = _doConstrainedSnap(t, p, f, points_to_snap, component_vectors[NR::X], it); - /* Snap along y (ie to horizontal lines) */ - Inkscape::SnappedPoint const h = _doConstrainedSnap(t, p, f, points_to_snap, component_vectors[NR::Y], it); + /* Snap along x (i.e. to vertical lines) */ + _doConstrainedSnap(sc, t, p, f, points_to_snap, component_vectors[NR::X], it); + /* Snap along y (i.e. to horizontal lines) */ + _doConstrainedSnap(sc, t, p, f, points_to_snap, component_vectors[NR::Y], it); - /* If we snapped to both, combine the two results. This is so that, for example, - ** we snap nicely to the intersection of two guidelines. - */ - if (v.getDistance() < NR_HUGE && h.getDistance() < NR_HUGE) { - return SnappedPoint(NR::Point(v.getPoint()[NR::X], h.getPoint()[NR::Y]), hypot(v.getDistance(), h.getDistance())); - } - - /* If we snapped to a vertical line, return that */ - if (v.getDistance() < NR_HUGE) { - return v; - } - - /* Otherwise just return any horizontal snap; if we didn't snap to that either - ** we haven't snapped to anything. - */ - return h; } -Inkscape::SnappedPoint Inkscape::LineSnapper::_doConstrainedSnap(Inkscape::Snapper::PointType const &t, +void Inkscape::LineSnapper::_doConstrainedSnap(SnappedConstraints &sc, + Inkscape::Snapper::PointType const &t, NR::Point const &p, bool const &f, std::vector<NR::Point> &points_to_snap, ConstraintLine const &c, std::list<SPItem const *> const &it) const + { Inkscape::SnappedPoint s = SnappedPoint(p, NR_HUGE); /* Get the lines that we will try to snap to */ const LineList lines = _getSnapLines(p); - + for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) { /* Normal to the line we're trying to snap along */ NR::Point const n(NR::rot90(NR::unit_vector(c.getDirection()))); - /* Constant term of the line we're trying to snap along */ - NR::Coord const q = dot(n, c.hasPoint() ? c.getPoint() : p); + NR::Point const point_on_line = c.hasPoint() ? c.getPoint() : p; + + /* Constant term of the line we're trying to snap along */ + NR::Coord const q = dot(n, point_on_line); /* Try to intersect this line with the target line */ - NR::Point t = p; + NR::Point t = NR::Point(NR_HUGE, NR_HUGE); IntersectorKind const k = intersector_line_intersection(n, q, component_vectors[i->first], i->second, t); - + if (k == INTERSECTS) { const NR::Coord dist = L2(t - p); - if (dist < getDistance() && dist < s.getDistance() ) { - s = SnappedPoint(t, dist); + //Store any line that's within snapping range + if (dist < getDistance()) { + _addSnappedLine(sc, t, dist, c.getDirection(), t); + //SnappedInfiniteLine dummy = SnappedInfiniteLine(t, dist, c.getDirection(), t); + //sc.infinite_lines.push_back(dummy); } } } - - return s; } /* |
