Bounds2 Struct Reference

An axis aligned box class in 2D. More...

Inheritance diagram for Bounds2:
ICollisionBasics

List of all members.

Public Member Functions

bool IsEmpty ()
 Return true if the size is (0,0).
 Bounds2 (Vector2 min, Vector2 max)
 Bounds2 constructor.
 Bounds2 (Vector2 point)
 Bounds2 constructor.
bool Overlaps (Bounds2 bounds)
 Return true if this and 'bounds' overlap.
Bounds2 Intersection (Bounds2 bounds)
 Return the Bounds2 resulting from the intersection of 2 bounds.
Bounds2 Scale (Vector2 scale, Vector2 center)
 Scale bounds around a given pivot.
void Add (Vector2 point)
 Add the contribution of 'point' to this Bounds2.
void Add (Bounds2 bounds)
 Add the contribution of 'bounds' to this Bounds2.
override string ToString ()
 Return the string representation of this Bounds2.
bool IsInside (Vector2 point)
 Return true if 'point' is inside the primitive (in its negative space).
void ClosestSurfacePoint (Vector2 point, out Vector2 ret, out float sign)
 Return the closest point to 'point' that lies on the surface of the primitive.
float SignedDistance (Vector2 point)
 Return the signed distance (penetration distance) from 'point' to the surface of the primitive.
bool NegativeClipSegment (ref Vector2 A, ref Vector2 B)
 Assuming the primitive is convex, clip the segment AB against the primitive.
Bounds2 OutrageousYTopBottomSwap ()
 Swap y coordinates for top and bottom, handy for hacking uvs in system that use 0,0 as top left.
Bounds2 OutrageousYVCoordFlip ()
 Similar to OutrageousYTopBottomSwap, but instead of swapping top and bottom y, it just does y=1-y.

Static Public Member Functions

static Bounds2 SafeBounds (Vector2 min, Vector2 max)
 Create a Bounds2 that goes through 2 points, the min and max are recalculated.
static Bounds2 CenteredSquare (float h)
 Return a box that goes from (-h,-h) to (h,h).
static Bounds2 operator+ (Bounds2 bounds, Vector2 value)
 Translate bounds.
static Bounds2 operator- (Bounds2 bounds, Vector2 value)
 Translate bounds.

Public Attributes

Vector2 Min
 Minimum point (lower left).
Vector2 Max
 Maximum point (upper right)

Static Public Attributes

static Bounds2 Zero = new Bounds2( new Vector2(0.0f,0.0f), new Vector2(0.0f,0.0f) )
 (0,0) -> (0,0) box.
static Bounds2 Quad0_1 = new Bounds2( new Vector2(0.0f,0.0f), new Vector2(1.0f,1.0f) )
 (0,0) -> (1,1) box.
static Bounds2 QuadMinus1_1 = new Bounds2( new Vector2(-1.0f,-1.0f), new Vector2(1.0f,1.0f) )
 (-1,-1) -> (1,1) box.

Properties

float Aspect [get]
 The Width/Height ratio.
Vector2 Center [get]
 The center of the bounds (Max+Min)/2.
Vector2 Size [get]
 The Size the bounds (Max-Min).
Vector2 Point00 [get]
 The bottom left point (which is also Min).
Vector2 Point11 [get]
 The top right point (which is also Max).
Vector2 Point10 [get]
 The bottom right point.
Vector2 Point01 [get]
 The top left point.

Detailed Description

An axis aligned box class in 2D.


Constructor & Destructor Documentation

Bounds2 ( Vector2  min,
Vector2  max 
)

Bounds2 constructor.

All functions in Bounds2 assume that Min is less or equal Max. If it is not the case, the user takes responsability for it. SafeBounds will ensure this is the case whatever the input is, but the default constructor will just blindly takes anything the user passes without trying to fix it.

Parameters:
minThe bottom left point. Min is set to that value without further checking.
maxThe top right point. Max is set to that value without further checking.
Bounds2 ( Vector2  point)

Bounds2 constructor.

Return a zero size bounds. You can then use Add to expand it.

Parameters:
pointLocation of the Bounds2.

Member Function Documentation

static Bounds2 CenteredSquare ( float  h) [static]

Return a box that goes from (-h,-h) to (h,h).

We don't check for sign.

Parameters:
hHalf size of the square.
void ClosestSurfacePoint ( Vector2  point,
out Vector2  ret,
out float  sign 
)

Return the closest point to 'point' that lies on the surface of the primitive.

If that point is inside the primitive, sign is negative.

Implements ICollisionBasics.

bool NegativeClipSegment ( ref Vector2  A,
ref Vector2  B 
)

Assuming the primitive is convex, clip the segment AB against the primitive.

Return false if AB is entirely in positive halfspace, else clip against negative space and return true.

Implements ICollisionBasics.

Bounds2 OutrageousYTopBottomSwap ( )

Swap y coordinates for top and bottom, handy for hacking uvs in system that use 0,0 as top left.

Also, this will generate an invalid Bounds2 and all functions in that class will break (intersections, add etc.)

Functions like Point00, Point10 etc can still be used.

Bounds2 OutrageousYVCoordFlip ( )

Similar to OutrageousYTopBottomSwap, but instead of swapping top and bottom y, it just does y=1-y.

Same comment as OutrageousYTopBottomSwap.

static Bounds2 SafeBounds ( Vector2  min,
Vector2  max 
) [static]

Create a Bounds2 that goes through 2 points, the min and max are recalculated.

Parameters:
minFirst point.
maxSecond point.
Bounds2 Scale ( Vector2  scale,
Vector2  center 
)

Scale bounds around a given pivot.

Parameters:
scaleAmount of scale.
centerScale center.