summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDiederik van Lierop <mail@diedenrezi.nl>2007-09-15 08:19:07 +0000
committerdvlierop2 <dvlierop2@users.sourceforge.net>2007-09-15 08:19:07 +0000
commit18bccf196727b9f6726f487e4d021a8b0801a9b7 (patch)
tree49afb3526a085d14b4d83a64501cabb677f755d0 /src
parentr16583@tres: ted | 2007-09-14 09:15:49 -0700 (diff)
downloadinkscape-18bccf196727b9f6726f487e4d021a8b0801a9b7.tar.gz
inkscape-18bccf196727b9f6726f487e4d021a8b0801a9b7.zip
avoid code duplication, i.e. use sp_item_snappoints in the object-snapper.cpp
(bzr r3752)
Diffstat (limited to 'src')
-rw-r--r--src/object-snapper.cpp61
-rw-r--r--src/object-snapper.h7
-rw-r--r--src/selection.cpp4
-rw-r--r--src/sp-item-group.cpp2
-rw-r--r--src/sp-item-notify-moveto.cpp2
-rw-r--r--src/sp-item-rm-unsatisfied-cns.cpp2
-rw-r--r--src/sp-item-update-cns.cpp2
-rw-r--r--src/sp-item.cpp6
-rw-r--r--src/sp-item.h2
9 files changed, 33 insertions, 55 deletions
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index ab222f286..53f04f8c4 100644
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
@@ -31,9 +31,9 @@ Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d)
_snap_to_bboxnode(true), _snap_to_bboxpath(true), _strict_snapping(true),
_include_item_center(false)
{
- _candidates = new std::list<SPItem*>;
- _points_to_snap_to = new std::list<NR::Point>;
- _paths_to_snap_to = new std::list<Path*>;
+ _candidates = new std::vector<SPItem*>;
+ _points_to_snap_to = new std::vector<NR::Point>;
+ _paths_to_snap_to = new std::vector<Path*>;
}
Inkscape::ObjectSnapper::~ObjectSnapper()
@@ -44,7 +44,7 @@ Inkscape::ObjectSnapper::~ObjectSnapper()
_points_to_snap_to->clear();
delete _points_to_snap_to;
- for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
+ for (std::vector<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
delete *k;
}
_paths_to_snap_to->clear();
@@ -143,44 +143,19 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t,
// first point and store the collection for later use. This dramatically improves the performance
if (first_point) {
_points_to_snap_to->clear();
- for (std::list<SPItem*>::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) {
+ for (std::vector<SPItem*>::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) {
- NR::Matrix i2doc(NR::identity());
- SPItem *root_item = NULL;
+ //NR::Matrix i2doc(NR::identity());
+ SPItem *root_item = *i;
if (SP_IS_USE(*i)) {
- i2doc = sp_use_get_root_transform(SP_USE(*i));
root_item = sp_use_root(SP_USE(*i));
- } else {
- i2doc = sp_item_i2doc_affine(*i);
- root_item = *i;
- }
-
- SPCurve *curve = NULL;
-
- if (SP_IS_SHAPE(root_item)) {
- SPShape const *sh = SP_SHAPE(root_item);
- curve = sh->curve;
- } else if (SP_IS_IMAGE(root_item)) {
- SPImage const *im = SP_IMAGE(root_item);
- curve = im->curve;
}
-
+
//Collect all nodes so we can snap to them
if (_snap_to_itemnode) {
if (!(_strict_snapping && !p_is_a_node) || p_is_a_guide) {
- if (curve) {
- int j = 0;
- while (SP_CURVE_BPATH(curve)[j].code != NR_END) {
- /* Get this node in desktop coordinates */
- NArtBpath const &bp = SP_CURVE_BPATH(curve)[j];
- _points_to_snap_to->push_back(desktop->doc2dt(bp.c(3) * i2doc));
- j++;
- }
- if (_include_item_center) {
- _points_to_snap_to->push_back(root_item->getCenter());
- }
- }
- }
+ sp_item_snappoints(root_item, _include_item_center, SnapPointsIter(*_points_to_snap_to));
+ }
}
//Collect the bounding box's corners so we can snap to them
@@ -198,7 +173,7 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t,
}
//Do the snapping, using all the nodes and corners collected above
- for (std::list<NR::Point>::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) {
+ for (std::vector<NR::Point>::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) {
/* Try to snap to this node of the path */
NR::Coord dist = NR_HUGE;
NR::Point snapped_point;
@@ -216,6 +191,7 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t,
snapped_point = *k;
break;
}
+
if (dist < getDistance() && dist < s.getDistance()) {
s = SnappedPoint(snapped_point, dist);
}
@@ -248,11 +224,11 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t,
// e.g. when translating an item using the selector tool, then we will only do this for the
// first point and store the collection for later use. This dramatically improves the performance
if (first_point) {
- for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
+ for (std::vector<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
delete *k;
}
_paths_to_snap_to->clear();
- for (std::list<SPItem*>::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) {
+ for (std::vector<SPItem*>::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) {
/* Transform the requested snap point to this item's coordinates */
NR::Matrix i2doc(NR::identity());
@@ -277,8 +253,7 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t,
bool very_lenghty_prose = false;
if (SP_IS_TEXT(root_item) || SP_IS_FLOWTEXT(root_item)) {
very_lenghty_prose = sp_text_get_length(SP_TEXT(root_item)) > 240;
- }
-
+ }
// On my AMD 3000+, the snapping lag becomes annoying at approx. 240 chars
// which corresponds to a lag of 500 msec. This is for snapping a rect
// to a single line of text.
@@ -320,9 +295,9 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t,
}
}
}
-
+
//Now we can finally do the real snapping, using the paths collected above
- for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
+ for (std::vector<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
if (*k) {
if (first_point) {
(*k)->ConvertWithBackData(0.01); //This is extremely time consuming!
@@ -398,7 +373,7 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::guideSnap(NR::Point const &p,
}
/* Get a list of all the SPItems that we will try to snap to */
- std::list<SPItem*> cand;
+ std::vector<SPItem*> cand;
std::list<SPItem const *> const it; //just an empty list
std::vector<NR::Point> points_to_snap;
diff --git a/src/object-snapper.h b/src/object-snapper.h
index fa0cfa14c..e473e3fe9 100644
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
@@ -85,10 +85,9 @@ public:
private:
//store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
- std::list<SPItem*> *_candidates;
- std::list<NR::Point> *_points_to_snap_to;
- std::list<Path*> *_paths_to_snap_to;
-
+ std::vector<SPItem*> *_candidates;
+ std::vector<NR::Point> *_points_to_snap_to;
+ std::vector<Path*> *_paths_to_snap_to;
SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t,
NR::Point const &p,
bool const &first_point,
diff --git a/src/selection.cpp b/src/selection.cpp
index ca3de5927..af5db825c 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -381,7 +381,7 @@ std::vector<NR::Point> Selection::getSnapPoints(bool includeItemCenter) const {
if (!SP_IS_PATH(this_item)) {
// Only snap if we don't have a path at hand
// (Same check occurs in sp-item-group)
- sp_item_snappoints(this_item, SnapPointsIter(p));
+ sp_item_snappoints(this_item, false, SnapPointsIter(p));
}
//Include the transformation origin for snapping
//For a group only the group's origin is considered
@@ -398,7 +398,7 @@ std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
std::vector<NR::Point> p;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p));
+ sp_item_snappoints(SP_ITEM(iter->data), false, SnapPointsIter(p));
}
std::vector<NR::Point> pHull;
diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index f43f4ded9..f1035e9ee 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -301,7 +301,7 @@ static void sp_group_snappoints (SPItem const *item, SnapPointsIter p)
if (SP_IS_ITEM(o) && !SP_IS_PATH(o)) {
// getSnapPoints() and sp_group_snappoints are only being used in the selector tool,
// which should not snap path nodes. Only the node tool should snap those.
- sp_item_snappoints(SP_ITEM(o), p);
+ sp_item_snappoints(SP_ITEM(o), false, p);
}
}
}
diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp
index 163a9f5f8..7781b15f0 100644
--- a/src/sp-item-notify-moveto.cpp
+++ b/src/sp-item-notify-moveto.cpp
@@ -25,7 +25,7 @@ void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoin
g_return_if_fail( dir_lensq != 0 );
vector<NR::Point> snappoints;
- sp_item_snappoints(&item, SnapPointsIter(snappoints));
+ sp_item_snappoints(&item, true, SnapPointsIter(snappoints));
g_return_if_fail( snappoint_ix < int(snappoints.size()) );
double const pos0 = dot(dir, snappoints[snappoint_ix]);
diff --git a/src/sp-item-rm-unsatisfied-cns.cpp b/src/sp-item-rm-unsatisfied-cns.cpp
index d71c6fe0c..4071a639c 100644
--- a/src/sp-item-rm-unsatisfied-cns.cpp
+++ b/src/sp-item-rm-unsatisfied-cns.cpp
@@ -12,7 +12,7 @@ void sp_item_rm_unsatisfied_cns(SPItem &item)
return;
}
vector<NR::Point> snappoints;
- sp_item_snappoints(&item, SnapPointsIter(snappoints));
+ sp_item_snappoints(&item, true, SnapPointsIter(snappoints));
for (unsigned i = item.constraints.size(); i--;) {
g_assert( i < item.constraints.size() );
SPGuideConstraint const &cn = item.constraints[i];
diff --git a/src/sp-item-update-cns.cpp b/src/sp-item-update-cns.cpp
index 528129fb9..44b26d45f 100644
--- a/src/sp-item-update-cns.cpp
+++ b/src/sp-item-update-cns.cpp
@@ -10,7 +10,7 @@ using std::vector;
void sp_item_update_cns(SPItem &item, SPDesktop const &desktop)
{
vector<NR::Point> snappoints;
- sp_item_snappoints(&item, SnapPointsIter(snappoints));
+ sp_item_snappoints(&item, true, SnapPointsIter(snappoints));
/* TODO: Implement the ordering. */
vector<SPGuideConstraint> found_cns;
satisfied_guide_cns(desktop, snappoints, found_cns);
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 4a5c0079b..8f91c97e6 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -785,7 +785,7 @@ static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p)
}
}
-void sp_item_snappoints(SPItem const *item, SnapPointsIter p)
+void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p)
{
g_assert (item != NULL);
g_assert (SP_IS_ITEM(item));
@@ -794,6 +794,10 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p)
if (item_class.snappoints) {
item_class.snappoints(item, p);
}
+
+ if (includeItemCenter) {
+ *p = item->getCenter();
+ }
}
void
diff --git a/src/sp-item.h b/src/sp-item.h
index fbd4d6818..b3867f146 100644
--- a/src/sp-item.h
+++ b/src/sp-item.h
@@ -221,7 +221,7 @@ unsigned int sp_item_display_key_new(unsigned int numkeys);
NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
void sp_item_invoke_hide(SPItem *item, unsigned int key);
-void sp_item_snappoints(SPItem const *item, SnapPointsIter p);
+void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p);
void sp_item_adjust_pattern(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);
void sp_item_adjust_gradient(SPItem *item, /* NR::Matrix const &premul, */ NR::Matrix const &postmul, bool set = false);