Code

Snap guides to intersections of curves too (see bug #405419)
authordvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 29 Jul 2009 20:55:51 +0000 (20:55 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 29 Jul 2009 20:55:51 +0000 (20:55 +0000)
src/object-snapper.cpp
src/snap.cpp
src/snap.h

index 5dd9350dcf11b3d8cc110ea13c6cae0f5a12744d..aece2e9ec42be1153f9b583d886689d765e0ead0 100644 (file)
@@ -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);
 }
index 4d5dad55a53b2289341c9457e7cf12549846a983..9b8a7aea7ea5960a513db73556ba39bc316b91f3 100644 (file)
@@ -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()) {
index 866775789ff43c1d80047be2ac921aaae2772953..e360eda004a360b412616a108631a7d70e71a281 100644 (file)
@@ -193,7 +193,7 @@ private:
 
     void _displaySnapsource(Inkscape::SnapPreferences::PointType point_type, std::pair<Geom::Point, int> 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 */