summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a8d9eb)
raw | patch | inline | side by side (parent: 2a8d9eb)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sat, 15 Sep 2007 08:19:07 +0000 (08:19 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sat, 15 Sep 2007 08:19:07 +0000 (08:19 +0000) |
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index ab222f286a44935e4167806f7f4c585c09e42569..53f04f8c42986497fd3c7ecfbd1de66a9568205d 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
_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()
_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
}
//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;
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());
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.
}
}
}
-
+
//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!
}
/* 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 fa0cfa14c294c69cb3e1dcd9b843e2d9d2f8f1c5..e473e3fe90dfb1655d7eb7ba8ad35943afe4337c 100644 (file)
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
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 ca3de5927e7c41705de52a7df30b384719cabc5f..af5db825c0c19efc905bfef8a4559a298fa10da9 100644 (file)
--- a/src/selection.cpp
+++ b/src/selection.cpp
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
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 f43f4ded952fd4c9f0be6a3a41969fa5a98f5b10..f1035e9eef6028a234a0eac680c841f90ed6808a 100644 (file)
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
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);
}
}
}
index 163a9f5f81cfd181b2cd85e5089757fa6c318ec2..7781b15f0350b30c5fd937db21a792b4a11a900d 100644 (file)
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]);
index d71c6fe0ccf5aaca614fe35581baed9ca6e13be4..4071a639c6da560f615fc738c2baedbb45c7f370 100644 (file)
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];
index 528129fb999859411d22f191888365441d4e7d90..44b26d45f6e2998689f774781216d08b142dbb9c 100644 (file)
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 4a5c0079b4fb6bd1499083cd63ad09d3f9eb5b92..8f91c97e650c80db84fb57a0aadc9ae23f312741 100644 (file)
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
}
}
-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));
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 fbd4d6818c52c138cf39deb36b81be90b5065f3c..b3867f146156ca4b53f960b46ff537c58488bed3 100644 (file)
--- a/src/sp-item.h
+++ b/src/sp-item.h
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);