summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDiederik van Lierop <mail@diedenrezi.nl>2007-04-17 21:26:43 +0000
committerdvlierop2 <dvlierop2@users.sourceforge.net>2007-04-17 21:26:43 +0000
commitf12da8471875838ac6cf1f8c8db16637cb97c200 (patch)
treeb5da97b8edbc054dcadf5589e04b9bb744f0b303 /src
parentflipping patch by maximilian albert (diff)
downloadinkscape-f12da8471875838ac6cf1f8c8db16637cb97c200.tar.gz
inkscape-f12da8471875838ac6cf1f8c8db16637cb97c200.zip
Improve snapper performance (mainly in by editting WillSnapSomething())
(bzr r2917)
Diffstat (limited to 'src')
-rw-r--r--src/guide-snapper.cpp10
-rw-r--r--src/guide-snapper.h2
-rw-r--r--src/object-snapper.cpp49
-rw-r--r--src/object-snapper.h2
-rw-r--r--src/snap.cpp1
-rw-r--r--src/snapper.cpp11
-rw-r--r--src/snapper.h10
7 files changed, 52 insertions, 33 deletions
diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp
index a05ecd3e6..9fd13705c 100644
--- a/src/guide-snapper.cpp
+++ b/src/guide-snapper.cpp
@@ -26,7 +26,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point
{
LineList s;
- if ( NULL == _named_view ) {
+ if ( NULL == _named_view || willSnapSomething() == false) {
return s;
}
@@ -44,6 +44,14 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point
return s;
}
+/**
+ * \return true if this Snapper will snap at least one kind of point.
+ */
+bool Inkscape::GuideSnapper::willSnapSomething() const
+{
+ return _named_view == NULL ? false : (_enabled && _snap_to != 0 && _named_view->showguides);
+}
+
/*
Local Variables:
mode:c++
diff --git a/src/guide-snapper.h b/src/guide-snapper.h
index 37e3e3006..37ea08701 100644
--- a/src/guide-snapper.h
+++ b/src/guide-snapper.h
@@ -29,6 +29,8 @@ class GuideSnapper : public LineSnapper
{
public:
GuideSnapper(SPNamedView const *nv, NR::Coord const d);
+
+ bool willSnapSomething() const;
private:
LineList _getSnapLines(NR::Point const &p) const;
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 5492fc439..e39d398b1 100644
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
@@ -38,28 +38,30 @@ void Inkscape::ObjectSnapper::_findCandidates(std::list<SPItem*>& c,
std::list<SPItem const *> const &it,
NR::Point const &p) const
{
- SPDesktop const *desktop = SP_ACTIVE_DESKTOP;
- for (SPObject* o = sp_object_first_child(r); o != NULL; o = SP_OBJECT_NEXT(o)) {
- if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !desktop->itemIsHidden(SP_ITEM(o))) {
-
- /* See if this item is on the ignore list */
- std::list<SPItem const *>::const_iterator i = it.begin();
- while (i != it.end() && *i != o) {
- i++;
- }
-
- if (i == it.end()) {
- /* See if the item is within range */
- if (SP_IS_GROUP(o)) {
- _findCandidates(c, o, it, p);
- } else {
- NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(SP_ITEM(o));
- if ( b && NR::expand(*b, -getDistance()).contains(p) ) {
- c.push_back(SP_ITEM(o));
+ if (willSnapSomething()) {
+ SPDesktop const *desktop = SP_ACTIVE_DESKTOP;
+ for (SPObject* o = sp_object_first_child(r); o != NULL; o = SP_OBJECT_NEXT(o)) {
+ if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !desktop->itemIsHidden(SP_ITEM(o))) {
+
+ /* See if this item is on the ignore list */
+ std::list<SPItem const *>::const_iterator i = it.begin();
+ while (i != it.end() && *i != o) {
+ i++;
+ }
+
+ if (i == it.end()) {
+ /* See if the item is within range */
+ if (SP_IS_GROUP(o)) {
+ _findCandidates(c, o, it, p);
+ } else {
+ NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(SP_ITEM(o));
+ if ( b && NR::expand(*b, -getDistance()).contains(p) ) {
+ c.push_back(SP_ITEM(o));
+ }
}
}
+
}
-
}
}
}
@@ -181,6 +183,15 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(NR::Point con
return _doFreeSnap(p, it);
}
+/**
+ * \return true if this Snapper will snap at least one kind of point.
+ */
+bool Inkscape::ObjectSnapper::willSnapSomething() const
+{
+ return (_enabled && _snap_to != 0 && (_snap_to_paths || _snap_to_nodes));
+}
+
+
/*
Local Variables:
mode:c++
diff --git a/src/object-snapper.h b/src/object-snapper.h
index 4e74b2f74..f9c7a9817 100644
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
@@ -43,6 +43,8 @@ public:
return _snap_to_paths;
}
+ bool willSnapSomething() const;
+
private:
SnappedPoint _doFreeSnap(NR::Point const &p,
std::list<SPItem const *> const &it) const;
diff --git a/src/snap.cpp b/src/snap.cpp
index 1714b6b67..b03b3f89d 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -89,6 +89,7 @@ bool SnapManager::willSnapSomething() const
i++;
}
+
return (i != s.end());
}
diff --git a/src/snapper.cpp b/src/snapper.cpp
index 105ec4631..390e0957e 100644
--- a/src/snapper.cpp
+++ b/src/snapper.cpp
@@ -21,7 +21,7 @@ Inkscape::Snapper::PointType const Inkscape::Snapper::SNAP_POINT = 0x2;
* \param nv Named view.
* \param d Snap distance.
*/
-Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_view(nv), _distance(d), _enabled(true)
+Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_view(nv), _enabled(true), _distance(d)
{
g_assert(_named_view != NULL);
g_assert(SP_IS_NAMEDVIEW(_named_view));
@@ -70,15 +70,6 @@ bool Inkscape::Snapper::getSnapTo(PointType t) const
}
/**
- * \return true if this Snapper will snap at least one kind of point.
- */
-bool Inkscape::Snapper::willSnapSomething() const
-{
- return (_enabled && _snap_to != 0);
-}
-
-
-/**
* \param s true to enable this snapper, otherwise false.
*/
diff --git a/src/snapper.h b/src/snapper.h
index 89e4f9d72..21e96b019 100644
--- a/src/snapper.h
+++ b/src/snapper.h
@@ -44,7 +44,11 @@ public:
bool getSnapTo(PointType t) const;
::NR::Coord getDistance() const;
- bool willSnapSomething() const;
+ /**
+ * \return true if this Snapper will snap at least one kind of point.
+ */
+ virtual bool willSnapSomething() const {return (_enabled && _snap_to != 0);} // will likely be overridden by derived classes
+
void setEnabled(bool s);
@@ -92,6 +96,8 @@ public:
std::list<SPItem const *> const &it) const;
protected:
SPNamedView const *_named_view;
+ int _snap_to; ///< bitmap of point types that we will snap to
+ bool _enabled; ///< true if this snapper is enabled, otherwise false
private:
@@ -122,8 +128,6 @@ private:
std::list<SPItem const *> const &it) const = 0;
::NR::Coord _distance; ///< snap distance (desktop coordinates)
- int _snap_to; ///< bitmap of point types that we will snap to
- bool _enabled; ///< true if this snapper is enabled, otherwise false
};
}