From 1ae6235112448547c758dd643a9ddd267a6cd580 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Thu, 18 Sep 2008 17:42:51 +0000 Subject: More NR ==> Geom conversion (points and some matrices/transforms) (bzr r6836) --- src/selection.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 9e134ff08..9b9b48485 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -393,6 +393,31 @@ boost::optional Selection::bounds(SPItem::BBoxType type) const return bbox; } +// TODO: This should be replaces by a proper 2geom function +inline Geom::Rect union_bounds_2geom(boost::optional const & a, Geom::Rect const &b) { + if (a) { + return union_bounds_2geom(*a, b); + } else { + return b; + } +} + +boost::optional Selection::bounds_2geom(SPItem::BBoxType type) const +{ + GSList const *items = const_cast(this)->itemList(); + + boost::optional bbox; + for ( GSList const *i = items ; i != NULL ; i = i->next ) { + bbox = union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type)); + } + // TODO: eliminate this conversion after the switch to 2geom + boost::optional bbox_ret; + if (bbox) { + bbox_ret = to_2geom(*bbox); + } + return bbox_ret; +} + NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const { g_return_val_if_fail (bbox != NULL, NULL); @@ -420,9 +445,9 @@ boost::optional Selection::boundsInDocument(SPItem::BBoxType type) con } /** Extract the position of the center from the first selected object */ -boost::optional Selection::center() const { +boost::optional Selection::center() const { GSList *items = (GSList *) const_cast(this)->itemList(); - NR::Point center; + Geom::Point center; if (items) { SPItem *first = reinterpret_cast(g_slist_last(items)->data); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly @@ -431,9 +456,9 @@ boost::optional Selection::center() const { } boost::optional bbox = bounds(); if (bbox) { - return bounds()->midpoint(); + return to_2geom(bounds()->midpoint()); } else { - return boost::optional(); + return boost::optional(); } } -- cgit v1.2.3