diff --git a/src/selection.cpp b/src/selection.cpp
index c6b307c3b0ddd0918411f374e2852f560e0988ed..44f601362e1494eedce9c43b9a8381d5e3be7391 100644 (file)
--- a/src/selection.cpp
+++ b/src/selection.cpp
#include "xml/repr.h"
#include "sp-shape.h"
+#include "sp-path.h"
#include <sigc++/functors/mem_fun.h>
return obj ? SP_OBJECT_REPR(obj) : NULL;
}
-NRRect *Selection::bounds(NRRect *bbox) const
+NRRect *Selection::bounds(NRRect *bbox, SPItem::BBoxType type) const
{
g_return_val_if_fail (bbox != NULL, NULL);
- *bbox = NRRect(bounds());
+ *bbox = NRRect(bounds(type));
return bbox;
}
-NR::Maybe<NR::Rect> Selection::bounds() const
+NR::Maybe<NR::Rect> Selection::bounds(SPItem::BBoxType type) const
{
GSList const *items = const_cast<Selection *>(this)->itemList();
NR::Maybe<NR::Rect> bbox = NR::Nothing();
for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
+ bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type));
}
return bbox;
}
-NRRect *Selection::boundsInDocument(NRRect *bbox) const {
+NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const {
g_return_val_if_fail (bbox != NULL, NULL);
GSList const *items=const_cast<Selection *>(this)->itemList();
for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) {
SPItem *item=SP_ITEM(iter->data);
- NR::Matrix const i2doc(sp_item_i2doc_affine(item));
- sp_item_invoke_bbox(item, bbox, i2doc, FALSE);
+ NR::Matrix i2doc(sp_item_i2doc_affine(item));
+ sp_item_invoke_bbox(item, bbox, i2doc, FALSE, type);
}
return bbox;
}
-NR::Maybe<NR::Rect> Selection::boundsInDocument() const {
+NR::Maybe<NR::Rect> Selection::boundsInDocument(SPItem::BBoxType type) const {
NRRect r;
- return boundsInDocument(&r)->upgrade();
+ return boundsInDocument(&r, type)->upgrade();
}
/** Extract the position of the center from the first selected object */
/**
* Compute the list of points in the selection that are to be considered for snapping.
+ * This includes all special points of each item in the selection, except path nodes
*/
std::vector<NR::Point> Selection::getSnapPoints() const {
GSList const *items = const_cast<Selection *>(this)->itemList();
std::vector<NR::Point> p;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p));
+ // getSnapPoints() is only being used in the selector tool, which should
+ // not snap path nodes. Only the node tool should snap those.
+ SPItem *this_item = SP_ITEM(iter->data);
+ 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));
+ }
}
return p;
std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
GSList const *items = const_cast<Selection *>(this)->itemList();
+
std::vector<NR::Point> p;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p));
}
- std::vector<NR::Point>::iterator i;
- NR::ConvexHull cvh(*(p.begin()));
- for (i = p.begin(); i != p.end(); i++) {
- // these are the points we get back
- cvh.add(*i);
- }
+ std::vector<NR::Point> pHull;
+ if (!p.empty()) {
+ std::vector<NR::Point>::iterator i;
+ NR::ConvexHull cvh(p.front());
+ for (i = p.begin(); i != p.end(); i++) {
+ // these are the points we get back
+ cvh.add(*i);
+ }
- NR::Rect rHull = cvh.bounds();
- std::vector<NR::Point> pHull(4);
- pHull[0] = rHull.corner(0);
- pHull[1] = rHull.corner(1);
- pHull[2] = rHull.corner(2);
- pHull[3] = rHull.corner(3);
+ NR::Maybe<NR::Rect> rHull = cvh.bounds();
+ if (rHull) {
+ for ( unsigned i = 0 ; i < 4 ; ++i ) {
+ pHull.push_back(rHull->corner(i));
+ }
+ }
+ }
return pHull;
}