54 BOX2(
const Vec& aPos,
const Vec& aSize ) :
69 return Vec( m_Pos.x + ( m_Size.x / 2 ),
70 m_Pos.y + ( m_Size.y / 2 ) );
78 template <
class Container>
79 void Compute(
const Container& aPointList )
83 typename Container::const_iterator
i;
85 if( !aPointList.size() )
88 vmin = vmax = aPointList[0];
90 for( i = aPointList.begin(); i != aPointList.end(); ++
i )
108 void Move(
const Vec& aMoveVector )
110 m_Pos += aMoveVector;
121 m_Size.y = -m_Size.y;
127 m_Size.x = -m_Size.x;
141 Vec rel_pos = aPoint -
m_Pos;
156 return ( rel_pos.x >= 0 ) && ( rel_pos.y >= 0 ) && ( rel_pos.y <= size.y) && ( rel_pos.x <= size.x);
178 coord_type
GetX()
const {
return m_Pos.x; }
179 coord_type
GetY()
const {
return m_Pos.y; }
187 coord_type
GetRight()
const {
return m_Pos.x + m_Size.x; }
188 coord_type
GetBottom()
const {
return m_Pos.y + m_Size.y; }
194 void MoveBottomTo( coord_type aBottom ) { m_Size.y = aBottom - m_Pos.y; }
196 void MoveRightTo( coord_type aRight ) { m_Size.x = aRight - m_Pos.x; }
199 void SetOrigin( coord_type x, coord_type y ) { m_Pos.x = x; m_Pos.y = y; }
200 void SetSize(
const Vec& size ) { m_Size = size; }
201 void SetSize( coord_type w, coord_type h ) { m_Size.x = w; m_Size.y = h; }
202 void Offset( coord_type dx, coord_type dy ) { m_Pos.x += dx; m_Pos.y += dy; }
205 m_Pos.x += offset.x; m_Pos.y +=
209 void SetX( coord_type val ) { m_Pos.x = val; }
210 void SetY( coord_type val ) { m_Pos.y = val; }
211 void SetWidth( coord_type val ) { m_Size.x = val; }
216 m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
244 if( left <= right && top <= bottom )
254 std::stringstream ss;
256 ss <<
"( box corner " << m_Pos.Format() <<
" w " << m_Size.x <<
" h " << m_Size.y <<
" )";
270 if( m_Size.x < -2 * dx )
273 m_Pos.x += m_Size.x / 2;
285 if( m_Size.x > -2 * dx )
288 m_Pos.x -= m_Size.x / 2;
301 if( m_Size.y < -2 * dy )
304 m_Pos.y += m_Size.y / 2;
316 if( m_Size.y > 2 * dy )
319 m_Pos.y -= m_Size.y / 2;
356 Vec rect_end = rect.
GetEnd();
361 end.x =
std::max( end.x, rect_end.x );
362 end.y =
std::max( end.y, rect_end.y );
378 m_Pos.x =
std::min( m_Pos.x, aPoint.x );
379 m_Pos.y =
std::min( m_Pos.y, aPoint.y );
380 end.x =
std::max( end.x, aPoint.x );
381 end.y =
std::max( end.y, aPoint.y );
403 return m_Size.EuclideanNorm();
408 ecoord_type x2 = m_Pos.x + m_Size.x;
409 ecoord_type y2 = m_Pos.y + m_Size.y;
410 ecoord_type xdiff =
std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type) 0 );
411 ecoord_type ydiff =
std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type) 0 );
412 return xdiff * xdiff + ydiff * ydiff;
432 ecoord_type d = aBox.
m_Pos.x + aBox.
m_Size.x - m_Pos.x;
435 else if( aBox.
m_Pos.x > m_Pos.x + m_Size.x )
437 ecoord_type d = aBox.
m_Pos.x - m_Size.x - m_Pos.x;
443 ecoord_type d = aBox.
m_Pos.y + aBox.
m_Size.y - m_Pos.y;
446 else if( aBox.
m_Pos.y > m_Pos.y + m_Size.y )
448 ecoord_type d = aBox.
m_Pos.y - m_Size.y - m_Pos.y;
ecoord_type Distance(const Vec &aP) const
const Vec & GetOrigin() const
void Move(const Vec &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
void Offset(const Vec &offset)
ecoord_type SquaredDistance(const Vec &aP) const
const std::string Format() const
bool Contains(const Vec &aPoint) const
Function Contains.
void MoveBottomTo(coord_type aBottom)
BOX2< Vec > & Inflate(int aDelta)
Function Inflate inflates the rectangle horizontally and vertically by aDelta.
coord_type GetRight() const
ecoord_type GetArea() const
Function GetArea returns the area of the rectangle.
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
void SetSize(const Vec &size)
const Vec & GetSize() const
void SetX(coord_type val)
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
coord_type GetTop() const
coord_type GetWidth() const
void MoveLeftTo(coord_type aLeft)
void SetOrigin(coord_type x, coord_type y)
Vec::extended_type ecoord_type
bool Contains(coord_type x, coord_type y) const
Function Contains.
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
const Vec & GetPosition() const
void SetSize(coord_type w, coord_type h)
coord_type GetBottom() const
bool Intersects(const BOX2< Vec > &aRect) const
Function Intersects.
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies 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)
ecoord_type SquaredDistance(const BOX2< Vec > &aBox) const
Function SquaredDistance returns the square of the minimum distance between self and box aBox...
ecoord_type Distance(const BOX2< Vec > &aBox) const
Function Distance returns the minimum distance between self and box aBox.
BOX2(const Vec &aPos, const Vec &aSize)
coord_type GetHeight() const
void SetHeight(coord_type val)
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
ecoord_type Diagonal() const
Function GetArea returns the length of the diagonal of the rectangle.
void SetEnd(const Vec &pos)
void SetY(coord_type val)
BOX2< Vec > & Merge(const Vec &aPoint)
Function Merge modifies the position and size of the rectangle in order to contain the given point...
void SetOrigin(const Vec &pos)
coord_type GetLeft() const
void MoveTopTo(coord_type aTop)
bool Contains(const BOX2< Vec > &aRect) const
Function Contains.
std::numeric_limits< coord_type > coord_limits
Vec::coord_type coord_type
void SetWidth(coord_type val)
void MoveRightTo(coord_type aRight)