diff options
| author | bulia byak <buliabyak@gmail.com> | 2007-03-18 21:03:20 +0000 |
|---|---|---|
| committer | buliabyak <buliabyak@users.sourceforge.net> | 2007-03-18 21:03:20 +0000 |
| commit | 7d4bbe6947b39c4843a89c03846af91c9c5045e5 (patch) | |
| tree | 3f0977acf839b91350bff8e56d290a5d27f6574a /src | |
| parent | update po file (diff) | |
| download | inkscape-7d4bbe6947b39c4843a89c03846af91c9c5045e5.tar.gz inkscape-7d4bbe6947b39c4843a89c03846af91c9c5045e5.zip | |
add growBy and constructors from NRRect(L)
(bzr r2699)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnr/nr-rect.cpp | 20 | ||||
| -rw-r--r-- | src/libnr/nr-rect.h | 7 |
2 files changed, 27 insertions, 0 deletions
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<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> 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 <libnr/nr-maybe.h> #include <libnr/nr-point-matrix-ops.h> +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()); |
