summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-11 21:41:42 +0000
committermental <mental@users.sourceforge.net>2007-03-11 21:41:42 +0000
commit7146a6c31b8507c9dfba86d3e91fa8c42e955e06 (patch)
tree8b2af16f2ed3611f9ac3ec26dfcd34694ed974ed /src/libnr
parentEliminate remaining sources of empty NR::Rects (diff)
downloadinkscape-7146a6c31b8507c9dfba86d3e91fa8c42e955e06.tar.gz
inkscape-7146a6c31b8507c9dfba86d3e91fa8c42e955e06.zip
ban empty rectangles entirely and remove isEmpty test
(bzr r2606)
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/nr-rect.cpp7
-rw-r--r--src/libnr/nr-rect.h20
2 files changed, 13 insertions, 14 deletions
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<X>() || isEmpty<Y>();
- }
-
bool intersects(Rect const &r) const {
return intersects<X>(r) && intersects<Y>(r);
}
@@ -154,11 +153,6 @@ private:
}
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];
}