summaryrefslogtreecommitdiffstats
path: root/src/libnr/nr-rect.cpp
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2007-03-18 21:03:20 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2007-03-18 21:03:20 +0000
commit7d4bbe6947b39c4843a89c03846af91c9c5045e5 (patch)
tree3f0977acf839b91350bff8e56d290a5d27f6574a /src/libnr/nr-rect.cpp
parentupdate po file (diff)
downloadinkscape-7d4bbe6947b39c4843a89c03846af91c9c5045e5.tar.gz
inkscape-7d4bbe6947b39c4843a89c03846af91c9c5045e5.zip
add growBy and constructors from NRRect(L)
(bzr r2699)
Diffstat (limited to 'src/libnr/nr-rect.cpp')
-rw-r--r--src/libnr/nr-rect.cpp20
1 files changed, 20 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 ) {