Code

Add translator hint.
[inkscape.git] / src / libnr / nr-rect.h
index 6ae1e4e9948bbb18a409d1e85a7b9ae7d090023a..46aff13f4fa938212f39df8654abeaacd1cdcaf5 100644 (file)
 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, in the sense of having
- * a zero area, is not permitted.  Infinities are, however. */
+ * min[dim] <= _pt[dim] <= max[dim].  A rectangle may be empty, in the
+ * sense of having zero area, but it will always contain at least one
+ * point.  Infinities are also permitted.
+ */
 class Rect {
 public:
     Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {}
@@ -56,6 +53,11 @@ public:
     /** returns the midpoint of this rect. */
     Point midpoint() const;
 
+    /** True iff either width or height is less than \a epsilon. */
+    bool isEmpty(double epsilon=1e-6) const {
+        return isEmpty<X>(epsilon) || isEmpty<Y>(epsilon);
+    }
+
     bool intersects(Rect const &r) const {
         return intersects<X>(r) && intersects<Y>(r);
     }
@@ -124,6 +126,8 @@ public:
         _max[NR::Y] += by;
     }
 
+    void growBy (gdouble by);
+
     /** Scales the rect by s, with origin at 0, 0 */
     inline Rect operator*(double const s) const {
         return Rect(s * min(), s * max());
@@ -152,6 +156,11 @@ private:
         return _max[axis] - _min[axis];
     }
 
+    template <NR::Dim2 axis>
+    bool isEmpty(double epsilon) const {
+        return extent<axis>() < epsilon;
+    }
+
     template <Dim2 axis>
     bool intersects(Rect const &r) const {
         return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis];
@@ -256,6 +265,7 @@ struct NRRect {
 #define nr_rect_d_set_empty(r) (*(r) = NR_RECT_EMPTY)
 #define nr_rect_l_set_empty(r) (*(r) = NR_RECT_L_EMPTY)
 
+/** "Empty" here includes the case of zero width or zero height. */
 #define nr_rect_d_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
 #define nr_rect_l_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))