Skip to content

Commit

Permalink
libdeng2|Rectangle: Added expanded(), fromSize() constructor, union
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 25, 2013
1 parent 22fcd54 commit 094645a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doomsday/libdeng2/include/de/rectangle.h
Expand Up @@ -49,6 +49,10 @@ class Rectangle
Rectangle(Type left, Type top, SizeType width, SizeType height)
: topLeft(left, top), bottomRight(left + width, top + height) {}
Rectangle(Corner const &tl, Corner const &br) : topLeft(tl), bottomRight(br) {}
static RectangleType fromSize(Corner const &tl, Size const &size) {
return RectangleType(tl.x, tl.y, size.x, size.y);
}

SizeType width() const { return abs(bottomRight.x - topLeft.x); }
SizeType height() const { return abs(bottomRight.y - topLeft.y); }
Size size() const { return Size(width(), height()); }
Expand All @@ -65,6 +69,9 @@ class Rectangle
topLeft = topLeft.min(point);
bottomRight = bottomRight.max(point);
}
RectangleType expanded(Type n) const {
return RectangleType(topLeft - Corner(n, n), bottomRight + Corner(n, n));
}
RectangleType adjusted(CornerVectorType const &tl, CornerVectorType const &br) const {
return RectangleType(topLeft + tl, bottomRight + br);
}
Expand All @@ -74,6 +81,15 @@ class Rectangle
bool operator == (RectangleType const &other) const {
return topLeft == other.topLeft && bottomRight == other.bottomRight;
}
RectangleType operator | (RectangleType const &other) const {
return RectangleType(topLeft.min(other.topLeft),
bottomRight.max(other.bottomRight));
}
RectangleType &operator |= (RectangleType const &other) {
topLeft = topLeft.min(other.topLeft);
bottomRight = bottomRight.max(other.bottomRight);
return *this;
}
String asText() const {
return "[" + topLeft.asText() + "->" + bottomRight.asText() +
" size:" + size().asText() + "]";
Expand Down

0 comments on commit 094645a

Please sign in to comment.