29 #include "nomlib/math/Coords.hpp"
46 width ( 0 ), height ( 0 )
50 width ( coords.width ),
51 height ( coords.height )
54 Coords Coords::getPosition (
void )
const
56 return Coords ( this->x, this->y );
59 Coords Coords::getSize (
void )
const
61 return Coords ( this->width, this->height );
64 void Coords::setPosition ( int32 x, int32 y )
70 void Coords::setSize ( int32 width, int32 height )
73 this->height = height;
79 ( x >= this->x && x <= this->x + this->width ) &&
80 ( y >= this->y && y <= this->y + this->height )
86 return this->
contains ( pos.x, pos.y );
91 uint32 leftA, leftB = 0;
92 uint32 rightA, rightB = 0;
93 uint32 topA, topB = 0;
94 uint32 bottomA, bottomB = 0;
98 rightA = this->x + this->width;
100 bottomA = this->y + this->height;
104 rightB = rectangle.x + rectangle.width;
106 bottomB = rectangle.y + rectangle.height;
108 if ( bottomA <= topB )
return false;
109 if ( topA >= bottomB )
return false;
110 if ( rightA <= leftB )
return false;
111 if ( leftA >= rightB )
return false;
131 std::ostream& operator << ( std::ostream& os,
const Coords& coords )
133 os << coords.x << coords_delimiter
134 << coords.y << coords_delimiter
135 << coords.width << coords_delimiter
144 this->width = other.width;
145 this->height = other.height;
150 bool operator == (
const Coords& left,
const Coords& right )
152 return (left.x == right.x ) &&
153 (left.y == right.y ) &&
154 (left.width == right.width ) &&
155 (left.height == right.height );
158 bool operator != (
const Coords& left,
const Coords& right )
160 return ! ( left == right );
163 Coords operator + (
const Coords& left,
const Coords& right )
165 return Coords ( static_cast<int32> ( left.x + right.x ),
166 static_cast<int32> ( left.y + right.y ),
167 static_cast<int32> ( left.width + right.width ),
168 static_cast<int32> ( left.height + right.height )
172 Coords operator ++ ( Coords& left )
174 return Coords ( static_cast<int32> ( left.x ++ ),
175 static_cast<int32> ( left.y ++ ),
176 static_cast<int32> ( left.width ++ ),
177 static_cast<int32> ( left.height ++ )
181 Coords operator - (
const Coords& left,
const Coords& right )
183 return Coords ( static_cast<int32> ( left.x - right.x ),
184 static_cast<int32> ( left.y - right.y ),
185 static_cast<int32> ( left.width - right.width ),
186 static_cast<int32> ( left.height - right.height )
190 Coords operator -- ( Coords& left )
192 return Coords ( static_cast<int32> ( left.x -- ),
193 static_cast<int32> ( left.y -- ),
194 static_cast<int32> ( left.width -- ),
195 static_cast<int32> ( left.height -- )
199 Coords operator * (
const Coords& left,
const Coords& right )
201 return Coords ( static_cast<int32> ( left.x * right.x ),
202 static_cast<int32> ( left.y * right.y ),
203 static_cast<int32> ( left.width * right.width ),
204 static_cast<int32> ( left.height * right.height )
208 Coords operator / (
const Coords& left,
const Coords& right )
210 return Coords ( static_cast<int32> ( left.x / right.x ),
211 static_cast<int32> ( left.y / right.y ),
212 static_cast<int32> ( left.width / right.width ),
213 static_cast<int32> ( left.height / right.height )
217 Coords& operator += ( Coords& left,
const Coords& right )
219 return left = left + right;
222 Coords& operator -= ( Coords& left,
const Coords& right )
224 return left = left - right;
227 Coords& operator *= ( Coords& left,
const Coords& right )
229 return left = left * right;
Coords & operator=(const Coords &other)
Copy assignment operator.
const Coords & get(void) const
Convenience getter for obtaining a copy of this object.
static const Coords null
Convenience object that will always contain a value of -1.
Coords(void)
Default constructor; sets all values to their respective defaults.
bool intersects(Coords &rectangle) const
Checks to see if our rectangle overlaps with another.
bool contains(int32 x, int32 y) const
Coordinate values (x, y, z, width, height ) wrapper.