29#ifndef NOMLIB_MATH_RECT_HEADERS
30#define NOMLIB_MATH_RECT_HEADERS
33#include "nomlib/config.hpp"
34#include "nomlib/math/Point2.hpp"
35#include "nomlib/math/Size2.hpp"
36#include "nomlib/ptree/Value.hpp"
41const std::string RECT_DELIMITER =
", ";
66 Rect ( T left, T top, T right, T bottom ) :
92 x { static_cast<T> ( copy.
x ) },
93 y { static_cast<T> ( copy.
y ) },
94 w { static_cast<T> ( copy.
w ) },
95 h { static_cast<T> ( copy.
h ) }
105 ( xx >= this->
x && xx <= this->
x + this->
w ) &&
106 ( yy >= this->
y && yy <= this->
y + this->
h )
121 T rightA, rightB = 0;
123 T bottomA, bottomB = 0;
127 rightA = leftA + this->
w;
129 bottomA = topA + this->
h;
133 rightB = leftB + rectangle.
w;
135 bottomB = topB + rectangle.
h;
137 if ( bottomA <= topB )
return false;
138 if ( topA >= bottomB )
return false;
139 if ( rightA <= leftB )
return false;
140 if ( leftA >= rightB )
return false;
154 object[
"x"] = this->
x;
155 object[
"y"] = this->
y;
156 object[
"width"] = this->
w;
157 object[
"height"] = this->
h;
165 return Point2i( NOM_SCAST( T, this->
x ), NOM_SCAST( T, this->
y ) );
169 const Size2i
size(
void )
const
171 return Size2i( NOM_SCAST( T, this->
w ), NOM_SCAST( T, this->
h ) );
174 const T& left()
const
184 const T& right()
const
186 return(this->x + this->w);
189 const T& bottom()
const
191 return(this->y + this->h);
194 template <
typename U>
195 void set_position(
const Point2<U>& pos)
201 template <
typename U>
202 void set_size(
const Size2<U>& dims)
245inline std::ostream& operator <<( std::ostream& os,
const Rect<T>& rect )
268inline bool operator == (
const Rect<T>& lhs,
const Rect<T>& rhs )
270 return ( lhs.x == rhs.x ) && ( lhs.w == rhs.w )
272 ( lhs.y == rhs.y ) && ( lhs.h == rhs.h );
287 return ! ( lhs == rhs );
300 return Rect<T> ( lhs.x + rhs.x,
317 return Rect<T>(lhs + rhs.x, lhs + rhs.y, lhs + rhs.w, lhs + rhs.h);
330 return Rect<T>(lhs.x + rhs, lhs.y + rhs, lhs.w + rhs, lhs.h + rhs);
375 return Rect<T> ( lhs.x - rhs.x,
392 return Rect<T>(lhs - rhs.x, lhs - rhs.y, lhs - rhs.w, lhs - rhs.h);
405 return Rect<T>(lhs.x - rhs, lhs.y - rhs, lhs.w - rhs, lhs.h - rhs);
434 return Rect<T> ( lhs.x * rhs.x,
451 return Rect<T>(lhs * rhs.x, lhs * rhs.y, lhs * rhs.w, lhs * rhs.h);
483 return Rect<T> ( lhs.x / rhs.x,
788 return ( lhs.x < rhs.x ) && ( lhs.y < rhs.y )
790 ( lhs.w < rhs.w ) && ( lhs.h < rhs.h );
801 return ( rhs.x < lhs.x ) && ( rhs.y < lhs.y )
803 ( rhs.w < lhs.w ) && ( rhs.h < lhs.h );
814 return ( lhs.x <= rhs.x ) && ( lhs.y <= rhs.y )
816 ( lhs.w <= rhs.w ) && ( lhs.h <= rhs.h );
827 return ( rhs.x <= lhs.x ) && ( rhs.y <= lhs.y )
829 ( 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.
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.
static NOM_EXPORT const Rect zero
Rect(T left, T top, T right, T bottom)
Construct a Rectangle from coordinates.
Rect(const Rect< U > ©)
Copy constructor.
static NOM_EXPORT const Rect null
bool contains(T xx, T yy) const
const Size2i size(void) const
Size coordinates (width & height) container.