50 BOX2(
const Vec& aPos,
const Vec& aSize = Vec(0, 0) ) :
59 m_Pos.x =
m_Pos.y = coord_limits::lowest() / 2 + coord_limits::epsilon();
60 m_Size.x =
m_Size.y = coord_limits::max() - coord_limits::epsilon();
74 template <
class Container>
75 void Compute(
const Container& aPointList )
79 typename Container::const_iterator i;
81 if( !aPointList.size() )
84 vmin = vmax = aPointList[0];
86 for( i = aPointList.begin(); i != aPointList.end(); ++i )
89 vmin.x = std::min( vmin.x, p.x );
90 vmin.y = std::min( vmin.y, p.y );
91 vmax.x = std::max( vmax.x, p.x );
92 vmax.y = std::max( vmax.y, p.y );
104 void Move(
const Vec& aMoveVector )
106 m_Pos += aMoveVector;
136 Vec rel_pos = aPoint -
m_Pos;
151 return ( rel_pos.x >= 0 ) && ( rel_pos.y >= 0 ) && ( rel_pos.y <= size.y) &&
152 ( rel_pos.x <= size.x);
232 int top = std::max( me.
m_Pos.y, aRect.
m_Pos.y );
255 Vec topLeft, bottomRight;
257 topLeft.x = std::max( me.
m_Pos.x, rect.
m_Pos.x );
259 topLeft.y = std::max( me.
m_Pos.y, rect.
m_Pos.y );
262 if ( topLeft.x < bottomRight.x && topLeft.y < bottomRight.y )
263 return BOX2<Vec>( topLeft, bottomRight - topLeft );
265 return BOX2<Vec>( Vec( 0, 0 ), Vec( 0, 0 ) );
270 std::stringstream ss;
272 ss <<
"( box corner " <<
m_Pos.Format() <<
" w " <<
m_Size.x <<
" h " <<
m_Size.y <<
" )";
369 Vec rect_end = rect.
GetEnd();
374 end.x = std::max( end.x, rect_end.x );
375 end.y = std::max( end.y, rect_end.y );
394 end.x = std::max( end.x, aPoint.x );
395 end.y = std::max( end.y, aPoint.y );
417 return m_Size.EuclideanNorm();
428 return xdiff * xdiff + ydiff * ydiff;
488 return ( t1.m_Pos == t2.m_Pos && t1.m_Size == t2.m_Size );
497 return ( t1.m_Pos != t2.m_Pos || t1.m_Size != t2.m_Size );
ecoord_type Diagonal() const
Return the length of the diagonal of the rectangle.
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
void Offset(const Vec &offset)
bool operator!=(const BOX2< Vec > &aOther) const
coord_type GetTop() const
void MoveBottomTo(coord_type aBottom)
BOX2< Vec > & Inflate(int aDelta)
Inflate the rectangle horizontally and vertically by aDelta.
coord_type GetRight() const
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
ecoord_type SquaredDistance(const Vec &aP) const
void SetSize(const Vec &size)
coord_type GetBottom() const
void SetX(coord_type val)
A 2D bounding box built on top of an origin point and size vector.
bool operator==(const BOX2< Vec > &aOther) const
bool Intersects(const BOX2< Vec > &aRect) const
bool Contains(coord_type x, coord_type y) const
void MoveLeftTo(coord_type aLeft)
void SetOrigin(coord_type x, coord_type y)
Vec::extended_type ecoord_type
coord_type GetWidth() const
ecoord_type SquaredDistance(const BOX2< Vec > &aBox) const
Return the square of the minimum distance between self and box aBox.
BOX2< Vec > & Normalize()
Ensure that the height ant width are positive.
bool Contains(const Vec &aPoint) const
void SetSize(coord_type w, coord_type h)
BOX2(const Vec &aPos, const Vec &aSize=Vec(0, 0))
bool Contains(const BOX2< Vec > &aRect) const
ecoord_type GetArea() const
Return the area of the rectangle.
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
void Offset(coord_type dx, coord_type dy)
void SetEnd(coord_type x, coord_type y)
const Vec & GetPosition() const
void SetHeight(coord_type val)
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
void SetEnd(const Vec &pos)
void SetY(coord_type val)
BOX2< Vec > & Merge(const Vec &aPoint)
Modify the position and size of the rectangle in order to contain the given point.
void SetOrigin(const Vec &pos)
coord_type GetHeight() const
const Vec & GetSize() const
coord_type GetLeft() const
const Vec & GetOrigin() const
void MoveTopTo(coord_type aTop)
ecoord_type Distance(const Vec &aP) const
std::numeric_limits< coord_type > coord_limits
ecoord_type Distance(const BOX2< Vec > &aBox) const
Return the minimum distance between self and aBox.
Vec::coord_type coord_type
const std::string Format() const
void SetWidth(coord_type val)
BOX2< Vec > Intersect(const BOX2< Vec > &aRect)
Return the intersection of this with another rectangle.
void MoveRightTo(coord_type aRight)