template struct Core::TRect
Overview
Rectangle template class. More…
#include <corerect.h> template <typename Type> struct TRect { // fields Type left; Type top; Type right; Type bottom; // construction TRect(Type l = 0, Type t = 0, Type r = 0, Type b = 0); TRect(const TPoint<Type>& p1, const TPoint<Type>& p2); TRect(Type l, Type t, const TPoint<Type>& size); TRect(const TPoint<Type>& size); // methods TRect& operator () (Type l, Type t, Type r, Type b); Type getWidth() const; Type getHeight() const; TRect& setWidth(Type w); TRect& setHeight(Type w); TPoint<Type> getSize() const; TRect& setSize(const TPoint<Type>& size); TPoint<Type> getLeftTop() const; TPoint<Type> getRightTop() const; TPoint<Type> getLeftBottom() const; TPoint<Type> getRightBottom() const; TPoint<Type> getCenter() const; TRect& offset(Type dx, Type dy = 0); TRect& offset(const TPoint<Type>& p); TRect& moveTo(const TPoint<Type>& p); TRect& contract(Type v); TRect& expand(Type v); TRect& zoom(float factor); bool bound(const TRect& r); bool boundH(const TRect& r); bool boundV(const TRect& r); TRect& join(const TRect& r); TRect& join(const TPoint<Type>& p); TRect& center(const TRect& r); TRect& centerH(const TRect& r); TRect& centerV(const TRect& r); TRect& align(const TRect& r, const Alignment& alignment); TRect& fitProportionally(const TRect& r); TRect& normalize(); TRect& setEmpty(); TRect& setReallyEmpty(); bool isEmpty() const; bool intersect(const TRect& r) const; bool pointInside(const TPoint<Type>& p) const; bool rectInside(const TRect& r) const; bool operator == (const TRect& r) const; bool operator != (const TRect& r) const; };
Detailed Documentation
Rectangle template class.
Fields
Type left
left coordinate
Type top
top coordinate
Type right
right coordinate
Type bottom
bottom coordinate
Construction
TRect(Type l = 0, Type t = 0, Type r = 0, Type b = 0)
Construct rectangle from coordinates.
TRect(const TPoint<Type>& p1, const TPoint<Type>& p2)
Construct rectangle from points (left/top, right/bottom).
TRect(Type l, Type t, const TPoint<Type>& size)
Construct rectangle from left/top and size.
TRect(const TPoint<Type>& size)
Construct rectangle at (0,0) with given size.
Methods
TRect& operator () (Type l, Type t, Type r, Type b)
Assign new coordinates.
Type getWidth() const
Get width.
Type getHeight() const
Get height.
TRect& setWidth(Type w)
Set width without moving.
TRect& setHeight(Type w)
Set height without moving.
TPoint<Type> getSize() const
Get size of rectangle as a point.
TRect& setSize(const TPoint<Type>& size)
Set width and height without moving.
TPoint<Type> getLeftTop() const
Get left/top position.
TPoint<Type> getRightTop() const
Get right/top position.
TPoint<Type> getLeftBottom() const
Get left/bottom position.
TPoint<Type> getRightBottom() const
Get right/bottom position.
TPoint<Type> getCenter() const
Get center point of rectangle.
TRect& offset(Type dx, Type dy = 0)
Offset by given delta.
TRect& offset(const TPoint<Type>& p)
Offset by point.
TRect& moveTo(const TPoint<Type>& p)
Move origin to new position.
TRect& contract(Type v)
Shrink all edges by given value.
TRect& expand(Type v)
Expand all edges by given value.
TRect& zoom(float factor)
Multiply all edges by given value.
bool bound(const TRect& r)
Bound to given rectangle (can cause shrink).
Returns false, if result is empty.
bool boundH(const TRect& r)
Bound to given rectangle horizontally (can cause shrink).
Returns false, if result is empty.
bool boundV(const TRect& r)
Bound to given rectangle vertically (can cause shrink).
Returns false, if result is empty.
TRect& join(const TRect& r)
Join given rectangle (can cause expansion).
TRect& join(const TPoint<Type>& p)
Join with point (can cause expansion).
TRect& center(const TRect& r)
Center in given parent rectangle.
TRect& centerH(const TRect& r)
Center horizontally in given parent rectangle.
TRect& centerV(const TRect& r)
Center vertically in given parent rectangle.
TRect& align(const TRect& r, const Alignment& alignment)
Align in given parent rectangle.
TRect& fitProportionally(const TRect& r)
Scale proportionally to fit into parent rectangle.
(There may be space left in one direction.)
TRect& normalize()
Swap corners if width/height is negative.
TRect& setEmpty()
Set coordinates to (0,0,0,0).
TRect& setReallyEmpty()
Set empty using +- kMaxCoord.
Use when joining rectangles.
bool isEmpty() const
Check if rectangle is empty.
bool intersect(const TRect& r) const
Check if this rectangle intersects with other rectangle.
bool pointInside(const TPoint<Type>& p) const
Check if point is inside.
bool rectInside(const TRect& r) const
Check if rectangle is inside.
bool operator == (const TRect& r) const
Compare rectangles.
bool operator != (const TRect& r) const
Compare rectangles.