From: mental Date: Sun, 11 Mar 2007 21:41:42 +0000 (+0000) Subject: ban empty rectangles entirely and remove isEmpty test X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=96d6bc601d13d7b733fbd67725bcc3e83fb96e24;p=inkscape.git ban empty rectangles entirely and remove isEmpty test --- diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 82a88faa3..5521f91cb 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -260,7 +260,7 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item) sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item)); NR::Maybe bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine - g_assert( bbox && !bbox->isEmpty() ); + g_assert( bbox ); NR::Coord const width = bbox->dimensions()[NR::X]; NR::Coord const height = bbox->dimensions()[NR::Y]; @@ -318,7 +318,7 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item)); NR::Matrix bbox2user; NR::Maybe bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine - if ( bbox && !bbox->isEmpty() ) { + if ( bbox ) { bbox2user = NR::Matrix(bbox->dimensions()[NR::X], 0, 0, bbox->dimensions()[NR::Y], bbox->min()[NR::X], bbox->min()[NR::Y]); diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index 2d4629d42..a9487045a 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -244,7 +244,12 @@ namespace NR { Rect::Rect(const Point &p0, const Point &p1) : _min(std::min(p0[X], p1[X]), std::min(p0[Y], p1[Y])), - _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y])) {} + _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y])) +{ + if ( _min[X] == _max[X] || _min[Y] == _max[Y] ) { + throw EmptyRectangle(); + } +} /** returns the four corners of the rectangle in the correct winding order */ Point Rect::corner(unsigned i) const { diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index b632261aa..6ae1e4e99 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -28,12 +28,16 @@ namespace NR { struct Matrix; +class EmptyRectangle : public std::logic_error { +public: + EmptyRectangle() : logic_error("Attempt to create empty rectangle") {} +}; + /** A rectangle is always aligned to the X and Y axis. This means it * can be defined using only 4 coordinates, and determining * intersection is very efficient. The points inside a rectangle are - * min[dim] <= _pt[dim] <= max[dim]. Emptiness, however, is defined - * as having zero area, meaning an empty rectangle may still contain - * points. Infinities are also permitted. */ + * min[dim] <= _pt[dim] <= max[dim]. Emptiness, in the sense of having + * a zero area, is not permitted. Infinities are, however. */ class Rect { public: Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {} @@ -52,11 +56,6 @@ public: /** returns the midpoint of this rect. */ Point midpoint() const; - /** does this rectangle have zero area? */ - bool isEmpty() const { - return isEmpty() || isEmpty(); - } - bool intersects(Rect const &r) const { return intersects(r) && intersects(r); } @@ -153,11 +152,6 @@ private: return _max[axis] - _min[axis]; } - template - bool isEmpty() const { - return !( _min[axis] < _max[axis] ); - } - template bool intersects(Rect const &r) const { return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis]; diff --git a/src/sp-item-transform.cpp b/src/sp-item-transform.cpp index 105a91b4c..72a7c39e6 100644 --- a/src/sp-item-transform.cpp +++ b/src/sp-item-transform.cpp @@ -103,7 +103,7 @@ get_scale_transform_with_stroke (NR::Rect &bbox_param, gdouble strokewidth, bool gdouble h1 = y1 - y0; gdouble r0 = strokewidth; - if (bbox.isEmpty() || bbox.extent(NR::X) < 1e-06 || bbox.extent(NR::Y) < 1e-06) { + if (bbox.extent(NR::X) < 1e-06 || bbox.extent(NR::Y) < 1e-06) { NR::Matrix move = NR::Matrix(NR::translate(x0 - bbox.min()[NR::X], y0 - bbox.min()[NR::Y])); return (move); // cannot scale from empty boxes at all, so only translate } diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index e682f394b..ed4db90b7 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -585,7 +585,7 @@ sp_offset_set_shape(SPShape *shape) SPItem *item = shape; NR::Maybe bbox = sp_item_bbox_desktop (item); - if ( bbox && !bbox->isEmpty() ) { + if ( bbox ) { gdouble size = L2(bbox->dimensions()); gdouble const exp = NR::expansion(item->transform); if (exp != 0) diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 9be74a556..b9ed94c0c 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -623,7 +623,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root, } /* This is in document coordinates, i.e. pixels */ - if ( dbox && !dbox->isEmpty() ) { + if ( dbox ) { NRGC gc(NULL); /* Update to renderable state */ double sf = 1.0;