Code

excise never-used code and stale comments
[inkscape.git] / src / selection.cpp
index 4c99885eb389c16e82d54186614e8d2bd423d5d4..473a7202e594e1eecabcac3e1b9067774d7a64c9 100644 (file)
@@ -39,7 +39,6 @@ Selection::Selection(SPDesktop *desktop) :
     _flags(0),
     _idle(0)
 {
-    clearOnceInaccessible(&_desktop);
 }
 
 Selection::~Selection() {
@@ -290,7 +289,7 @@ NRRect *Selection::bounds(NRRect *bbox) const
     bbox->x0 = b.min()[NR::X];
     bbox->y0 = b.min()[NR::Y];
     bbox->x1 = b.max()[NR::X];
-    bbox->x1 = b.max()[NR::Y];
+    bbox->y1 = b.max()[NR::Y];
     return bbox;
 }
 
@@ -304,8 +303,10 @@ NR::Rect Selection::bounds() const
     GSList const *i = items;
     NR::Rect bbox = sp_item_bbox_desktop(SP_ITEM(i->data));
 
+    GSList const *i_start = i;
     while (i != NULL) {
-        bbox = NR::Rect::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
+        if (i != i_start)
+            bbox = NR::Rect::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
         i = i->next;
     }
 
@@ -338,6 +339,23 @@ NR::Rect Selection::boundsInDocument() const {
     return NR::Rect(*boundsInDocument(&r));
 }
 
+/** Extract the position of the center from the first selected object */
+NR::Point Selection::center() const {
+    GSList *items = (GSList *) const_cast<Selection *>(this)->itemList();
+    NR::Point center;
+    if (items) {
+        SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection
+        if (first->isCenterSet()) { // only if set explicitly
+            center = first->getCenter();
+        } else {
+            center = bounds().midpoint();
+        }
+    } else {
+        center = bounds().midpoint();
+    }
+    return center;
+}
+
 /**
  * Compute the list of points in the selection that are to be considered for snapping.
  */
@@ -357,20 +375,20 @@ std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
     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; 
+
+    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); 
+       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::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);
 
     return pHull;
 }
@@ -436,6 +454,20 @@ guint Selection::numberOfLayers() {
        return ret;
 }
 
+guint Selection::numberOfParents() {
+      GSList const *items = const_cast<Selection *>(this)->itemList();
+       GSList *parents = NULL;
+       for (GSList const *iter = items; iter != NULL; iter = iter->next) {
+               SPObject *parent = SP_OBJECT_PARENT(iter->data);
+               if (g_slist_find (parents, parent) == NULL) {
+                       parents = g_slist_prepend (parents, parent);
+               }
+       }
+       guint ret = g_slist_length (parents);
+       g_slist_free (parents);
+       return ret;
+}
+
 }
 
 /*