From: dvlierop2 Date: Wed, 29 Jul 2009 20:55:51 +0000 (+0000) Subject: Snap guides to intersections of curves too (see bug #405419) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4394252f0fb4638b298d505f940b58d7af22470b;p=inkscape.git Snap guides to intersections of curves too (see bug #405419) --- diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 5dd9350dc..aece2e9ec 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -296,6 +296,13 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s // Iterate through all nodes, find out which one is the closest to this guide, and snap to it! _collectNodes(t, true); + // Although we won't snap to paths here (which would give us under constrained snaps) we can still snap to intersections of paths. + if (_snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToPageBorder()) { + _collectPaths(t, true); + _snapPaths(sc, t, p, SNAPSOURCE_GUIDE, true, NULL, NULL); + // The paths themselves should be discarded in findBestSnap(), as we should only snap to their intersections + } + SnappedPoint s; Geom::Coord tol = getSnapperTolerance(); @@ -683,7 +690,7 @@ void Inkscape::ObjectSnapper::guideFreeSnap(SnappedConstraints &sc, _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity()); _snapTranslatingGuideToNodes(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, guide_normal); - // _snapRotatingGuideToNodes has not been implemented yet. + } // This method is used to snap the origin of a guide to nodes/paths, while dragging the origin along the guide @@ -707,7 +714,7 @@ void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity()); _snapTranslatingGuideToNodes(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, guide_normal); - // _snapRotatingGuideToNodes has not been implemented yet. + } /** @@ -734,7 +741,8 @@ bool Inkscape::ObjectSnapper::GuidesMightSnap() const // almost the same as This || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxNode()) || (_snapmanager->snapprefs.getSnapModeBBox() && (_snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints())) || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapLineMidpoints() || _snapmanager->snapprefs.getSnapObjectMidpoints())) - || (_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getIncludeItemCenter()); + || (_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getIncludeItemCenter()) + || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapIntersectionCS())); return (_snap_enabled && _snapmanager->snapprefs.getSnapModeGuide() && snap_to_something); } diff --git a/src/snap.cpp b/src/snap.cpp index 4d5dad55a..9b8a7aea7 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -428,7 +428,9 @@ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) // We won't snap to grids, what's the use? - Inkscape::SnappedPoint const s = findBestSnap(p, Inkscape::SNAPSOURCE_GUIDE, sc, false); + // Including snapping to intersections of curves, but not to the curves themself! (see _snapTranslatingGuideToNodes in object-snapper.cpp) + Inkscape::SnappedPoint const s = findBestSnap(p, Inkscape::SNAPSOURCE_GUIDE, sc, false, true); + s.getPoint(p); } @@ -900,13 +902,15 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapSkew(Inkscape::SnapPreference * \param source_type Detailed description of the source type, will be used by the snap indicator * \param sc A structure holding all snap targets that have been found so far * \param constrained True if the snap is constrained, e.g. for stretching or for purely horizontal translation. + * \param noCurves If true, then do consider snapping to intersections of curves, but not to the curves themself * \return An instance of the SnappedPoint class, which holds data on the snap source, snap target, and various metrics */ Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p, Inkscape::SnapSourceType const source_type, SnappedConstraints &sc, - bool constrained) const + bool constrained, + bool noCurves) const { /* @@ -928,9 +932,11 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p, } // search for the closest snapped curve - Inkscape::SnappedCurve closestCurve; - if (getClosestCurve(sc.curves, closestCurve)) { - sp_list.push_back(Inkscape::SnappedPoint(closestCurve)); + if (!noCurves) { + Inkscape::SnappedCurve closestCurve; + if (getClosestCurve(sc.curves, closestCurve)) { + sp_list.push_back(Inkscape::SnappedPoint(closestCurve)); + } } if (snapprefs.getSnapIntersectionCS()) { diff --git a/src/snap.h b/src/snap.h index 866775789..e360eda00 100644 --- a/src/snap.h +++ b/src/snap.h @@ -193,7 +193,7 @@ private: void _displaySnapsource(Inkscape::SnapPreferences::PointType point_type, std::pair const &p) const; - Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, Inkscape::SnapSourceType const source_type, SnappedConstraints &sc, bool constrained) const; + Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, Inkscape::SnapSourceType const source_type, SnappedConstraints &sc, bool constrained, bool noCurves = false) const; }; #endif /* !SEEN_SNAP_H */