29#ifndef NOMLIB_MATH_RECT_HEADERS
30#define NOMLIB_MATH_RECT_HEADERS
32#include "nomlib/config.hpp"
33#include "nomlib/math/Point2.hpp"
34#include "nomlib/math/Size2.hpp"
35#include "nomlib/ptree/Value.hpp"
40const std::string RECT_DELIMITER =
", ";
65 Rect ( T left, T top, T right, T bottom ) :
91 x { static_cast<T> ( copy.
x ) },
92 y { static_cast<T> ( copy.
y ) },
93 w { static_cast<T> ( copy.
w ) },
94 h { static_cast<T> ( copy.
h ) }
120 T rightA, rightB = 0;
122 T bottomA, bottomB = 0;
126 rightA = leftA + this->
w;
128 bottomA = topA + this->
h;
132 rightB = leftB + rectangle.
w;
134 bottomB = topB + rectangle.
h;
136 if ( bottomA <= topB )
return false;
137 if ( topA >= bottomB )
return false;
138 if ( rightA <= leftB )
return false;
139 if ( leftA >= rightB )
return false;
153 object[
"x"] = this->
x;
154 object[
"y"] = this->
y;
155 object[
"width"] = this->
w;
156 object[
"height"] = this->
h;
164 return Point2i( NOM_SCAST( T, this->
x ), NOM_SCAST( T, this->
y ) );
168 const Size2i
size(
void )
const
170 return Size2i( NOM_SCAST( T, this->
w ), NOM_SCAST( T, this->
h ) );
173 const T& left()
const
183 const T& right()
const
185 return(this->
x + this->
w);
188 const T& bottom()
const
190 return(this->
y + this->
h);
193 template <
typename U>
194 void set_position(
const Point2<U>& pos)
200 template <
typename U>
201 void set_size(
const Size2<U>& dims)
244inline std::ostream& operator <<( std::ostream& os,
const Rect<T>& rect )
266inline bool operator == (
const Rect<T>& lhs,
const Rect<T>& rhs )
268 return ( lhs.x == rhs.x ) && ( lhs.w == rhs.w )
270 ( lhs.y == rhs.y ) && ( lhs.h == rhs.h );
284 return ! ( lhs == rhs );
296 return Rect<T> ( lhs.x + rhs.x,
312 return Rect<T>(lhs + rhs.x, lhs + rhs.y, lhs + rhs.w, lhs + rhs.h);
324 return Rect<T>(lhs.x + rhs, lhs.y + rhs, lhs.w + rhs, lhs.h + rhs);
366 return Rect<T> ( lhs.x - rhs.x,
382 return Rect<T>(lhs - rhs.x, lhs - rhs.y, lhs - rhs.w, lhs - rhs.h);
394 return Rect<T>(lhs.x - rhs, lhs.y - rhs, lhs.w - rhs, lhs.h - rhs);
421 return Rect<T> ( lhs.x * rhs.x,
437 return Rect<T>(lhs * rhs.x, lhs * rhs.y, lhs * rhs.w, lhs * rhs.h);
467 return Rect<T> ( lhs.x / rhs.x,
757 return ( lhs.x < rhs.x ) && ( lhs.y < rhs.y )
759 ( lhs.w < rhs.w ) && ( lhs.h < rhs.h );
769 return ( rhs.x < lhs.x ) && ( rhs.y < lhs.y )
771 ( rhs.w < lhs.w ) && ( rhs.h < lhs.h );
781 return ( lhs.x <= rhs.x ) && ( lhs.y <= rhs.y )
783 ( lhs.w <= rhs.w ) && ( lhs.h <= rhs.h );
793 return ( rhs.x <= lhs.x ) && ( rhs.y <= lhs.y )
795 ( rhs.w <= lhs.w ) && ( rhs.h <= lhs.h );
T x
Represents the X-axis coordinate point.
T y
Represents the Y-axis coordinate point.
Rectangle shape container.
bool intersects(const Rect< T > &rectangle) const
Checks to see if our rectangle overlaps with another.
bool contains(T x, T y) const
const Point2i position(void) const
Rect(const Point2< T > &pos, const Size2< T > &size)
Construct an object from a Point2 and Size2 container types.
const Object serialize(void) const
Save an object to a nom::Value object.
bool contains(const Point2< T > &pos) const
Rect(void)
Default constructor; initialize values to Rect<T>::null.
Rect(T left, T top, T right, T bottom)
Construct a Rectangle from coordinates.
Rect(const Rect< U > ©)
Copy constructor.
const Size2i size(void) const
Size coordinates (width & height) container.