Catlike Coding
Unity Code Documentation
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
CatlikeCoding.Clipping.Bounds2D Struct Reference

A 2D bounding box. More...

Public Member Functions

 Bounds2D (float centerX, float centerY, float extendsX, float extendsY)
 Create a CatlikeCoding.Clipping.Bounds2D struct instance. More...
 
bool Contains (Vector2 point)
 Return whether a point is contained by the bounds. More...
 
bool Equals (Bounds2D other)
 Determines whether this bounds exactly matches another bounds. More...
 
Bounds2D GetIntersectionWith (Bounds2D other)
 Gets the intersection of this and another bounds. More...
 
Bounds2D GetUnionWith (Bounds2D other)
 Get the union of this and another bounds. More...
 
override string ToString ()
 Return a string representation of a CatlikeCoding.Clipping.Bounds2D. More...
 

Static Public Member Functions

static Bounds2D CreateFromMinMax (Vector2 min, Vector2 max)
 Create new bounds from minimum and maximum point. More...
 

Public Attributes

Vector2 center
 Center of the bounds. More...
 
Vector2 extends
 Extends of the bounds. They should not be negative. More...
 

Static Public Attributes

static readonly Bounds2D Zero
 Predefined bounds with both a center and extends of zero. More...
 

Properties

Bounds AsBounds [get]
 Get the bounds converted to a 3D Bounds. More...
 
Vector4 AsVector4 [get]
 Get the bounds converted to a Vector4. More...
 
Vector2 BottomLeft [get]
 Get the bottom left corner. This is minimum X and Y. More...
 
Vector2 BottomRight [get]
 Get the bottom right corner. This is maximum X and minimum Y. More...
 
Vector2 Size [get]
 Get the size. This is double the extends. More...
 
Vector2 TopLeft [get]
 Get the top left corner. This is minimum X and maximum Y. More...
 
Vector2 TopRight [get]
 Get the top right corner. This is maximum X and Y. More...
 

Detailed Description

A 2D bounding box.

A cousin of Unity's 3D Bounds struct, it has a 2D center and extends vector.

The default interpretation is that the X-axis goes from left to right and the Y-axis goes from bottom to top.

Constructor & Destructor Documentation

CatlikeCoding.Clipping.Bounds2D.Bounds2D ( float  centerX,
float  centerY,
float  extendsX,
float  extendsY 
)

Create a CatlikeCoding.Clipping.Bounds2D struct instance.

Parameters
centerXCenter x.
centerYCenter y.
extendsXExtends x.
extendsYExtends y.

Member Function Documentation

bool CatlikeCoding.Clipping.Bounds2D.Contains ( Vector2  point)

Return whether a point is contained by the bounds.

Parameters
pointA 2D point.
static Bounds2D CatlikeCoding.Clipping.Bounds2D.CreateFromMinMax ( Vector2  min,
Vector2  max 
)
static

Create new bounds from minimum and maximum point.

Returns
The bounds defined by the points.
Parameters
minMinimum point, corresponding to the bottom left corner of the bounds.
maxMaximum point, corresponding to the top right corner of the bounds.
bool CatlikeCoding.Clipping.Bounds2D.Equals ( Bounds2D  other)

Determines whether this bounds exactly matches another bounds.

Only exact matches are equal, so it's only really useful for checking if cached bounds are still valid.

Parameters
otherThe bounds to compare with.
Returns
Whether the bounds are equal.
Bounds2D CatlikeCoding.Clipping.Bounds2D.GetIntersectionWith ( Bounds2D  other)

Gets the intersection of this and another bounds.

Returns
Bounds that exactly match the overlapping area of the two bounds, if it exists. Otherwise the result is positioned at the midpoint between the bounds and its surface area is zero.
Bounds2D CatlikeCoding.Clipping.Bounds2D.GetUnionWith ( Bounds2D  other)

Get the union of this and another bounds.

Returns
Bounds that exactly contains the two bounds.
override string CatlikeCoding.Clipping.Bounds2D.ToString ( )

Return a string representation of a CatlikeCoding.Clipping.Bounds2D.

Useful for debugging.

Returns
A string that looks like "(center: (0, 0), extends: (5, 5))".

Member Data Documentation

Vector2 CatlikeCoding.Clipping.Bounds2D.center

Center of the bounds.

Vector2 CatlikeCoding.Clipping.Bounds2D.extends

Extends of the bounds. They should not be negative.

readonly Bounds2D CatlikeCoding.Clipping.Bounds2D.Zero
static

Predefined bounds with both a center and extends of zero.

Property Documentation

Bounds CatlikeCoding.Clipping.Bounds2D.AsBounds
get

Get the bounds converted to a 3D Bounds.

Both the Z-position and Z-extends are zero.

Vector4 CatlikeCoding.Clipping.Bounds2D.AsVector4
get

Get the bounds converted to a Vector4.

The center is stored in XY and the extends is stored in ZW.

Vector2 CatlikeCoding.Clipping.Bounds2D.BottomLeft
get

Get the bottom left corner. This is minimum X and Y.

Vector2 CatlikeCoding.Clipping.Bounds2D.BottomRight
get

Get the bottom right corner. This is maximum X and minimum Y.

Vector2 CatlikeCoding.Clipping.Bounds2D.Size
get

Get the size. This is double the extends.

Vector2 CatlikeCoding.Clipping.Bounds2D.TopLeft
get

Get the top left corner. This is minimum X and maximum Y.

Vector2 CatlikeCoding.Clipping.Bounds2D.TopRight
get

Get the top right corner. This is maximum X and Y.