From 58b0e69b7336a8a06c447cf786f73df903120e53 Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Sun, 11 Mar 2007 19:57:07 +0000 Subject: Switch selection bounds and center to use NR::Maybe, addressing most of the recent bbox regressions. (bzr r2604) --- src/selection.cpp | 61 +++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 49 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index d39086e8c..c6b307c3b 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -306,15 +306,11 @@ Inkscape::XML::Node *Selection::singleRepr() { NRRect *Selection::bounds(NRRect *bbox) const { g_return_val_if_fail (bbox != NULL, NULL); - NR::Rect const b = bounds(); - bbox->x0 = b.min()[NR::X]; - bbox->y0 = b.min()[NR::Y]; - bbox->x1 = b.max()[NR::X]; - bbox->y1 = b.max()[NR::Y]; + *bbox = NRRect(bounds()); return bbox; } -NR::Rect Selection::bounds() const +NR::Maybe Selection::bounds() const { GSList const *items = const_cast(this)->itemList(); @@ -322,13 +318,7 @@ NR::Rect Selection::bounds() const for ( GSList const *i = items ; i != NULL ; i = i->next ) { bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data))); } - - // TODO: return NR::Maybe - if (bbox) { - return *bbox; - } else { - return NR::Rect(NR::Point(0, 0), NR::Point(0, 0)); - } + return bbox; } NRRect *Selection::boundsInDocument(NRRect *bbox) const { @@ -352,32 +342,27 @@ NRRect *Selection::boundsInDocument(NRRect *bbox) const { return bbox; } -NR::Rect Selection::boundsInDocument() const { +NR::Maybe Selection::boundsInDocument() const { NRRect r; - NR::Maybe rect(boundsInDocument(&r)->upgrade()); - if (rect) { - return *rect; - } else { - // FIXME - return NR::Rect(NR::Point(0, 0), NR::Point(0, 0)); - } + return boundsInDocument(&r)->upgrade(); } /** Extract the position of the center from the first selected object */ -NR::Point Selection::center() const { +NR::Maybe Selection::center() const { GSList *items = (GSList *) const_cast(this)->itemList(); NR::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 - center = first->getCenter(); - } else { - center = bounds().midpoint(); + return first->getCenter(); } + } + NR::Maybe bbox = bounds(); + if (bbox) { + return bounds()->midpoint(); } else { - center = bounds().midpoint(); + return NR::Nothing(); } - return center; } /** @@ -417,28 +402,6 @@ std::vector Selection::getSnapPointsConvexHull() const { return pHull; } -std::vector Selection::getBBoxPoints() const { - GSList const *items = const_cast(this)->itemList(); - std::vector p; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - NR::Maybe b = sp_item_bbox_desktop(SP_ITEM(iter->data)); - if (b) { - p.push_back(b->min()); - p.push_back(b->max()); - } - } - - return p; -} - -std::vector Selection::getBBoxPointsOuter() const { - std::vector p; - NR::Rect bbox = bounds(); - p.push_back(bbox.min()); - p.push_back(bbox.max()); - return p; -} - void Selection::_removeObjectDescendants(SPObject *obj) { GSList *iter, *next; for ( iter = _objs ; iter ; iter = next ) { -- cgit v1.2.3