CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

csBox2 Class Reference
[Geometry utilities]

A bounding box in 2D space. More...

#include <csgeom/box.h>

List of all members.

Public Member Functions

float MinX () const
 Get the minimum X value of the box.
float MinY () const
 Get the minimum Y value of the box.
float MaxX () const
 Get the maximum X value of the box.
float MaxY () const
 Get the maximum Y value of the box.
float Min (int idx) const
 Get Min component for 0 (x) or 1 (y).
float Max (int idx) const
 Get Max component for 0 (x) or 1 (y).
const csVector2Min () const
 Get the 2d vector of minimum (x, y) values.
const csVector2Max () const
 Get the 2d vector of maximum (x, y) values.
csVector2 GetCorner (int corner) const
 Return every corner of this bounding box from 0 to 3.
csVector2 GetCenter () const
 Get the center of this box.
void SetCenter (const csVector2 &c)
 Set the center of this box.
void SetSize (const csVector2 &s)
 Set the size of the box but keep the center intact.
void GetEdgeInfo (int edge, int &v1, int &v2) const
 Given an edge index (CS_BOX_EDGE_xy_Xy etc.) return the two vertices (index CS_BOX_CORNER_xy etc.).
csSegment2 GetEdge (int edge) const
 Return every edge (segment) of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.).
void GetEdge (int edge, csSegment2 &e) const
 Return every edge (segment) of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.).
bool Intersect (csVector2 *poly, int num_poly) const
 Test if a polygon if visible in the box.
bool In (float x, float y) const
 Test if the given coordinate is in this box.
bool In (const csVector2 &v) const
 Test if the given coordinate is in this box.
bool Overlap (const csBox2 &box) const
 Test if this box overlaps with the given box.
bool Contains (const csBox2 &box) const
 Test if this box contains the other box.
bool Empty () const
 Test if this box is empty.
float SquaredOriginDist () const
 Calculate the squared distance between (0,0) and the box This routine is extremely efficient.
float SquaredOriginMaxDist () const
 Calculate the squared distance between (0,0) and the point on the box which is furthest away from (0,0).
void StartBoundingBox ()
 Initialize this box to empty.
void StartBoundingBox (const csVector2 &v)
 Initialize this box to one vertex.
void StartBoundingBox (float x, float y)
 Same but given some coordinates.
void AddBoundingVertex (float x, float y)
 Add a new vertex and recalculate the bounding box.
void AddBoundingVertex (const csVector2 &v)
 Add a new vertex and recalculate the bounding box.
void AddBoundingVertexSmart (float x, float y)
 Add a new vertex and recalculate the bounding box.
void AddBoundingVertexSmart (const csVector2 &v)
 Add a new vertex and recalculate the bounding box.
bool AddBoundingVertexTest (float x, float y)
 Add a new vertex and recalculate the bounding box.
bool AddBoundingVertexTest (const csVector2 &v)
 Add a new vertex and recalculate the bounding box.
bool AddBoundingVertexSmartTest (float x, float y)
 Add a new vertex and recalculate the bounding box.
bool AddBoundingVertexSmartTest (const csVector2 &v)
 Add a new vertex and recalculate the bounding box.
 csBox2 ()
 Initialize this box to empty.
 csBox2 (const csVector2 &v)
 Initialize this box with one point.
 csBox2 (float x1, float y1, float x2, float y2)
 Initialize this box with the given values.
 csBox2 (const csRect &r)
 Initialize this box from the given csRect.
void Set (const csVector2 &bmin, const csVector2 &bmax)
 Sets the bounds of the box with the given values.
void Set (float x1, float y1, float x2, float y2)
 Sets the bounds of the box with the given values.
void SetMin (int idx, float val)
 Set Min component for 0 (x) or 1 (y).
void SetMax (int idx, float val)
 Set Max component for 0 (x) or 1 (y).
csString Description () const
 Return a textual representation of the box in the form "(minx,miny)-(maxx,maxy)".
csBox2operator+= (const csBox2 &box)
 Compute the union of two bounding boxes.
csBox2operator+= (const csVector2 &point)
 Compute the union of a point with this bounding box.
csBox2operator *= (const csBox2 &box)
 Compute the intersection of two bounding boxes.
bool TestIntersect (const csBox2 &box) const
 Test if the two boxes have an intersection.

Static Public Member Functions

bool Intersect (float minx, float miny, float maxx, float maxy, csVector2 *poly, int num_poly)
 Test if a polygon if visible in the box.
bool Intersect (const csVector2 &minbox, const csVector2 &maxbox, csVector2 *poly, int num_poly)
 Test if a polygon if visible in the box.

Protected Attributes

csVector2 minbox
 The top-left coordinate of the bounding box.
csVector2 maxbox
 The bottom-right coordinate of the bounding box.

Friends

csBox2 operator+ (const csBox2 &box1, const csBox2 &box2)
 Compute the union of two bounding boxes.
csBox2 operator+ (const csBox2 &box, const csVector2 &point)
 Compute the union of a bounding box and a point.
csBox2 operator * (const csBox2 &box1, const csBox2 &box2)
 Compute the intersection of two bounding boxes.
bool operator== (const csBox2 &box1, const csBox2 &box2)
 Tests if two bounding boxes are equal.
bool operator!= (const csBox2 &box1, const csBox2 &box2)
 Tests if two bounding boxes are unequal.
bool operator< (const csBox2 &box1, const csBox2 &box2)
 Tests if box1 is a subset of box2.
bool operator> (const csBox2 &box1, const csBox2 &box2)
 Tests if box1 is a superset of box2.
bool operator< (const csVector2 &point, const csBox2 &box)
 Tests if a point is contained in a box.


Detailed Description

A bounding box in 2D space.

In order to operate correctly, this bounding box assumes that all values entered or compared against lie within the range (-CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE). It is not recommended to use points outside of this range.

Definition at line 95 of file box.h.


Constructor & Destructor Documentation

csBox2::csBox2  )  [inline]
 

Initialize this box to empty.

Definition at line 373 of file box.h.

References CS_BOUNDINGBOX_MAXVALUE, maxbox, and minbox.

csBox2::csBox2 const csVector2 v  )  [inline]
 

Initialize this box with one point.

Definition at line 377 of file box.h.

References maxbox, and minbox.

csBox2::csBox2 float  x1,
float  y1,
float  x2,
float  y2
[inline]
 

Initialize this box with the given values.

Definition at line 380 of file box.h.

References Empty(), maxbox, minbox, and StartBoundingBox().

csBox2::csBox2 const csRect r  )  [inline]
 

Initialize this box from the given csRect.

Definition at line 385 of file box.h.

References maxbox, and minbox.


Member Function Documentation

void csBox2::AddBoundingVertex const csVector2 v  )  [inline]
 

Add a new vertex and recalculate the bounding box.

Definition at line 296 of file box.h.

References AddBoundingVertex(), csVector2::x, and csVector2::y.

void csBox2::AddBoundingVertex float  x,
float  y
[inline]
 

Add a new vertex and recalculate the bounding box.

Definition at line 289 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by AddBoundingVertex().

void csBox2::AddBoundingVertexSmart const csVector2 v  )  [inline]
 

Add a new vertex and recalculate the bounding box.

This version is a little more optimal. It assumes however that at least one point has been added to the bounding box.

Definition at line 317 of file box.h.

References AddBoundingVertexSmart(), csVector2::x, and csVector2::y.

void csBox2::AddBoundingVertexSmart float  x,
float  y
[inline]
 

Add a new vertex and recalculate the bounding box.

This version is a little more optimal. It assumes however that at least one point has been added to the bounding box.

Definition at line 306 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by AddBoundingVertexSmart().

bool csBox2::AddBoundingVertexSmartTest const csVector2 v  )  [inline]
 

Add a new vertex and recalculate the bounding box.

This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Return true if the box was modified.

Definition at line 367 of file box.h.

References AddBoundingVertexSmartTest(), csVector2::x, and csVector2::y.

bool csBox2::AddBoundingVertexSmartTest float  x,
float  y
[inline]
 

Add a new vertex and recalculate the bounding box.

This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Return true if the box was modified.

Definition at line 351 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by AddBoundingVertexSmartTest().

bool csBox2::AddBoundingVertexTest const csVector2 v  )  [inline]
 

Add a new vertex and recalculate the bounding box.

Return true if the box was modified.

Definition at line 340 of file box.h.

References AddBoundingVertexTest(), csVector2::x, and csVector2::y.

bool csBox2::AddBoundingVertexTest float  x,
float  y
[inline]
 

Add a new vertex and recalculate the bounding box.

Return true if the box was modified.

Definition at line 326 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by AddBoundingVertexTest().

bool csBox2::Contains const csBox2 box  )  const [inline]
 

Test if this box contains the other box.

Definition at line 240 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

csString csBox2::Description  )  const
 

Return a textual representation of the box in the form "(minx,miny)-(maxx,maxy)".

bool csBox2::Empty  )  const [inline]
 

Test if this box is empty.

Definition at line 247 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by csBox2().

csVector2 csBox2::GetCenter  )  const [inline]
 

Get the center of this box.

Definition at line 143 of file box.h.

References minbox.

csVector2 csBox2::GetCorner int  corner  )  const
 

Return every corner of this bounding box from 0 to 3.

This contrasts with Min() and Max() because those are only the min and max corners. Corner 0 = xy, 1 = xY, 2 = Xy, 3 = XY. Use CS_BOX_CORNER_xy etc. defines. CS_BOX_CENTER2 also works.

Referenced by GetEdge().

void csBox2::GetEdge int  edge,
csSegment2 e
const [inline]
 

Return every edge (segment) of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.).

Definition at line 179 of file box.h.

References GetCorner(), csSegment2::SetEnd(), and csSegment2::SetStart().

csSegment2 csBox2::GetEdge int  edge  )  const [inline]
 

Return every edge (segment) of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.).

Definition at line 170 of file box.h.

References GetCorner().

void csBox2::GetEdgeInfo int  edge,
int &  v1,
int &  v2
const [inline]
 

Given an edge index (CS_BOX_EDGE_xy_Xy etc.) return the two vertices (index CS_BOX_CORNER_xy etc.).

Definition at line 160 of file box.h.

bool csBox2::In const csVector2 v  )  const [inline]
 

Test if the given coordinate is in this box.

Definition at line 226 of file box.h.

References In(), csVector2::x, and csVector2::y.

bool csBox2::In float  x,
float  y
const [inline]
 

Test if the given coordinate is in this box.

Definition at line 218 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by In().

bool csBox2::Intersect csVector2 poly,
int  num_poly
const [inline]
 

Test if a polygon if visible in the box.

This function does not test the case where the box is fully contained in the polygon. But all other cases are tested.

Definition at line 212 of file box.h.

References Intersect(), maxbox, and minbox.

bool csBox2::Intersect const csVector2 minbox,
const csVector2 maxbox,
csVector2 poly,
int  num_poly
[inline, static]
 

Test if a polygon if visible in the box.

This function does not test the case where the box is fully contained in the polygon. But all other cases are tested.

Definition at line 200 of file box.h.

References Intersect(), csVector2::x, and csVector2::y.

bool csBox2::Intersect float  minx,
float  miny,
float  maxx,
float  maxy,
csVector2 poly,
int  num_poly
[static]
 

Test if a polygon if visible in the box.

This function does not test the case where the box is fully contained in the polygon. But all other cases are tested.

Referenced by Intersect().

const csVector2& csBox2::Max  )  const [inline]
 

Get the 2d vector of maximum (x, y) values.

Definition at line 128 of file box.h.

float csBox2::Max int  idx  )  const [inline]
 

Get Max component for 0 (x) or 1 (y).

Definition at line 124 of file box.h.

References maxbox, csVector2::x, and csVector2::y.

float csBox2::MaxX  )  const [inline]
 

Get the maximum X value of the box.

Definition at line 118 of file box.h.

References maxbox, and csVector2::x.

float csBox2::MaxY  )  const [inline]
 

Get the maximum Y value of the box.

Definition at line 120 of file box.h.

References maxbox, and csVector2::y.

const csVector2& csBox2::Min  )  const [inline]
 

Get the 2d vector of minimum (x, y) values.

Definition at line 126 of file box.h.

float csBox2::Min int  idx  )  const [inline]
 

Get Min component for 0 (x) or 1 (y).

Definition at line 122 of file box.h.

References minbox, csVector2::x, and csVector2::y.

float csBox2::MinX  )  const [inline]
 

Get the minimum X value of the box.

Definition at line 114 of file box.h.

References minbox, and csVector2::x.

float csBox2::MinY  )  const [inline]
 

Get the minimum Y value of the box.

Definition at line 116 of file box.h.

References minbox, and csVector2::y.

csBox2& csBox2::operator *= const csBox2 box  ) 
 

Compute the intersection of two bounding boxes.

csBox2& csBox2::operator+= const csVector2 point  ) 
 

Compute the union of a point with this bounding box.

csBox2& csBox2::operator+= const csBox2 box  ) 
 

Compute the union of two bounding boxes.

bool csBox2::Overlap const csBox2 box  )  const [inline]
 

Test if this box overlaps with the given box.

Definition at line 232 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

void csBox2::Set float  x1,
float  y1,
float  x2,
float  y2
[inline]
 

Sets the bounds of the box with the given values.

Definition at line 396 of file box.h.

References maxbox, minbox, StartBoundingBox(), csVector2::x, and csVector2::y.

void csBox2::Set const csVector2 bmin,
const csVector2 bmax
[inline]
 

Sets the bounds of the box with the given values.

Definition at line 389 of file box.h.

References maxbox, and minbox.

void csBox2::SetCenter const csVector2 c  ) 
 

Set the center of this box.

This will not change the size of the box but just relocate the center.

void csBox2::SetMax int  idx,
float  val
[inline]
 

Set Max component for 0 (x) or 1 (y).

Definition at line 410 of file box.h.

References maxbox, csVector2::x, and csVector2::y.

void csBox2::SetMin int  idx,
float  val
[inline]
 

Set Min component for 0 (x) or 1 (y).

Definition at line 403 of file box.h.

References minbox, csVector2::x, and csVector2::y.

void csBox2::SetSize const csVector2 s  ) 
 

Set the size of the box but keep the center intact.

float csBox2::SquaredOriginDist  )  const
 

Calculate the squared distance between (0,0) and the box This routine is extremely efficient.

float csBox2::SquaredOriginMaxDist  )  const
 

Calculate the squared distance between (0,0) and the point on the box which is furthest away from (0,0).

This routine is extremely efficient.

void csBox2::StartBoundingBox float  x,
float  y
[inline]
 

Same but given some coordinates.

Definition at line 282 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

void csBox2::StartBoundingBox const csVector2 v  )  [inline]
 

Initialize this box to one vertex.

Definition at line 275 of file box.h.

References maxbox, and minbox.

void csBox2::StartBoundingBox  )  [inline]
 

Initialize this box to empty.

Definition at line 268 of file box.h.

References maxbox, minbox, csVector2::x, and csVector2::y.

Referenced by csBox2(), and Set().

bool csBox2::TestIntersect const csBox2 box  )  const
 

Test if the two boxes have an intersection.


Friends And Related Function Documentation

csBox2 operator * const csBox2 box1,
const csBox2 box2
[friend]
 

Compute the intersection of two bounding boxes.

bool operator!= const csBox2 box1,
const csBox2 box2
[friend]
 

Tests if two bounding boxes are unequal.

csBox2 operator+ const csBox2 box,
const csVector2 point
[friend]
 

Compute the union of a bounding box and a point.

csBox2 operator+ const csBox2 box1,
const csBox2 box2
[friend]
 

Compute the union of two bounding boxes.

bool operator< const csVector2 point,
const csBox2 box
[friend]
 

Tests if a point is contained in a box.

bool operator< const csBox2 box1,
const csBox2 box2
[friend]
 

Tests if box1 is a subset of box2.

bool operator== const csBox2 box1,
const csBox2 box2
[friend]
 

Tests if two bounding boxes are equal.

bool operator> const csBox2 box1,
const csBox2 box2
[friend]
 

Tests if box1 is a superset of box2.


Member Data Documentation

csVector2 csBox2::maxbox [protected]
 

The bottom-right coordinate of the bounding box.

Definition at line 110 of file box.h.

Referenced by AddBoundingVertex(), AddBoundingVertexSmart(), AddBoundingVertexSmartTest(), AddBoundingVertexTest(), Contains(), csBox2(), Empty(), In(), Intersect(), Max(), MaxX(), MaxY(), Overlap(), Set(), SetMax(), and StartBoundingBox().

csVector2 csBox2::minbox [protected]
 

The top-left coordinate of the bounding box.

Definition at line 108 of file box.h.

Referenced by AddBoundingVertex(), AddBoundingVertexSmart(), AddBoundingVertexSmartTest(), AddBoundingVertexTest(), Contains(), csBox2(), Empty(), GetCenter(), In(), Intersect(), Min(), MinX(), MinY(), Overlap(), Set(), SetMin(), and StartBoundingBox().


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.3.9.1