Code

excise never-used code and stale comments
[inkscape.git] / src / selection.cpp
index 87e0788d888e042b7cb452f604d57c0b1df0f1d8..473a7202e594e1eecabcac3e1b9067774d7a64c9 100644 (file)
@@ -303,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;
     }
 
@@ -337,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.
  */