summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b3b33c7)
raw | patch | inline | side by side (parent: b3b33c7)
author | mental <mental@users.sourceforge.net> | |
Sun, 11 Mar 2007 21:41:42 +0000 (21:41 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sun, 11 Mar 2007 21:41:42 +0000 (21:41 +0000) |
index 82a88faa3047d5fc18f7897a28ea9658c73a853e..5521f91cb994fd5fb6a2e9b7a2865497d86ec72c 100644 (file)
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
NR::Maybe<NR::Rect> 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<NR::Rect> 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 2d4629d42e1c42044795982b64ead958e633d5ce..a9487045a11b05a4a4b52c69c62eb184430d7e49 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
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 b632261aa235ef0500df2ba4d51cf8a42f5b2fcc..6ae1e4e9948bbb18a409d1e85a7b9ae7d090023a 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
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()) {}
/** returns the midpoint of this rect. */
Point midpoint() const;
- /** does this rectangle have zero area? */
- bool isEmpty() const {
- return isEmpty<X>() || isEmpty<Y>();
- }
-
bool intersects(Rect const &r) const {
return intersects<X>(r) && intersects<Y>(r);
}
return _max[axis] - _min[axis];
}
- template <Dim2 axis>
- bool isEmpty() const {
- return !( _min[axis] < _max[axis] );
- }
-
template <Dim2 axis>
bool intersects(Rect const &r) const {
return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis];
index 105a91b4c607798fafff793b90a6b871a000735c..72a7c39e61f633358f33764f9e4df99550d2aee8 100644 (file)
@@ -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 e682f394bb74c41029ce91c6aec088aa84c729ba..ed4db90b773f57cd1dc888dbdbc70defeb1468a6 100644 (file)
--- a/src/sp-offset.cpp
+++ b/src/sp-offset.cpp
SPItem *item = shape;
NR::Maybe<NR::Rect> 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 9be74a556f9151431dee10c24372351cd6702599..b9ed94c0ce0369d7b1e0a931722402ed45be1dab 100644 (file)
--- a/src/widgets/icon.cpp
+++ b/src/widgets/icon.cpp
}
/* 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;