From 26bc9aeb8e981cfb51e7112cdd05b12c1b1e0ada Mon Sep 17 00:00:00 2001 From: buliabyak Date: Sun, 18 Mar 2007 21:03:20 +0000 Subject: [PATCH] add growBy and constructors from NRRect(L) --- src/libnr/nr-rect.cpp | 20 ++++++++++++++++++++ src/libnr/nr-rect.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index f3eb498af..d34c548ad 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -247,6 +247,16 @@ Rect::Rect(const Point &p0, const Point &p1) _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y])) {} +Rect::Rect(NRRect *r) + : _min(r->x0, r->y0), + _max(r->x1, r->y1) +{} + +Rect::Rect(NRRectL *r) + : _min(r->x0, r->y0), + _max(r->x1, r->y1) +{} + /** returns the four corners of the rectangle in the correct winding order */ Point Rect::corner(unsigned i) const { switch (i % 4) { @@ -285,6 +295,16 @@ void Rect::expandTo(Point p) { } } +void Rect::growBy(double size) { + for ( unsigned d = 0 ; d < 2 ; d++ ) { + _min[d] -= size; + _max[d] += size; + if ( _min[d] > _max[d] ) { + _min[d] = _max[d] = ( _min[d] + _max[d] ) / 2; + } + } +} + /** Returns the set of points shared by both rectangles. */ Maybe intersection(Maybe const & a, Maybe const & b) { if ( !a || !b ) { diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index 1062df955..2439df95d 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -25,6 +25,9 @@ #include #include +struct NRRect; +struct NRRectL; + namespace NR { struct Matrix; @@ -39,6 +42,8 @@ class Rect { public: Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {} Rect(Point const &p0, Point const &p1); + Rect(NRRect *r); + Rect(NRRectL *r); Point const &min() const { return _min; } Point const &max() const { return _max; } @@ -125,6 +130,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()); -- 2.30.2