Box2D

Description

struct Tinman.Terrain.Util.Box2D

A two-dimensional bounding box with 64-bit floating-point precision.

The coordinates refer to infinitesimal points (pixel-is-point semantic).

Public / Constants

Empty


public static readonly attribute Empty → (Box2D)

An empty bounding box at the coordinate origin.

See also

Box2D.IsEmpty

Inverse


public static readonly attribute Inverse → (Box2D)

An inverse bounding box that can be used as the initial value for computing bounds via subsequent calls to Grow.

See also

Box2D.IsInverse

Max


public static readonly attribute Max → (Box2D)

The largest possible box.

Note that the dimension of this box cannot be represented with regular 64-bit floating point numbers and will instead be positive infinity.

Public / Methods

Check​Intersection

3 overloads


[Pure]
public method CheckIntersection1 → (1)

box in : Box2D

The other bounding box.

returns → int32

-1 if the bounding boxes do not overlap, 1 if box in fully contains this bounding box and 0 if both bounding boxes overlap.

Checks the intersection between this bounding box and the given one.


[Pure]
public method CheckIntersection2 → (2)

in : Vec2D

First point of line segment.

in : Vec2D

Second point of line segment.

returns → int32

-1 no intersection.
0 intersection and one line segment point is inside of this box.
1 intersection and both line segment points are inside of this box.
2 intersection and both line segment points are outside of this box.

Checks the intersection between this bounding box and the given line segment.


[Pure]
public method CheckIntersection3 → (4)

ax in : float64

X-coordinate of first point of line segment.

ay in : float64

Y-coordinate of first point of line segment.

bx in : float64

X-coordinate of second point of line segment.

by in : float64

Y-coordinate of second point of line segment.

returns → int32

-1 no intersection.
0 intersection and only one line segment point is inside of this box.
1 intersection and both line segment points are inside of this box.
2 intersection and both line segment points are outside of this box.

Checks the intersection between this bounding box and the given line segment.

Check​Intersection​Edges


[Pure]
public method CheckIntersectionEdges → (4)

ax in : float64

X-coordinate of first point of line segment.

ay in : float64

Y-coordinate of first point of line segment.

bx in : float64

X-coordinate of second point of line segment.

by in : float64

Y-coordinate of second point of line segment.

returns → bool

true if the line segment intersects with any edge of the given box,
false if there is no intersection.

Checks the intersection between the edges of this bounding box and the given line segment.

Clamp

2 overloads


[Pure]
public method Clamp1 → (2)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

returns → Vec2D

The clamped point.

Clamps the given point to this box.


[Pure]
public method Clamp2 → (1)

in : Vec2D

The point coordinates.

returns → Vec2D

The clamped point.

Clamps the given point to this box.

Compute​Overlap


[Pure]
public method ComputeOverlap → (1)

box in : Box2D

Second bounding box.

returns → float64

The amount of overlap (i.e. the volume of the intersection).

Computes the overlap of this bounding box and the given one.

Contains

3 overloads


[Pure]
public method Contains1 → (1)

xyz in : Vec2D

The point coordinates.

returns → bool

true if this box contains the point, false if not.

Checks if this box contains the given point.


[Pure]
public method Contains2 → (2)

in : float64

The point X-coordinate.

in : float64

The point Y-coordinate.

returns → bool

true if this box contains the point, false if not.

Checks if this box contains the given point.


[Pure]
public method Contains3 → (1)

box in : Box2D

The other box.

returns → bool

true if this box fully contains the given box, false if not.

Checks if this box contains the given box.

Disjoint


[Pure]
public method Disjoint → (1)

box in : Box2D

The other box.

returns → bool

true if this box and the given box are disjoint, false if not.

Checks if this box and the given box are disjoint (i.e. do not intersect).

Equals​Almost


[Pure]
public method EqualsAlmost → (1)

other in : Box2D

The other box

returns → bool

true if both boxes are similar, false if they are not.

Checks if this box and the given one are similar but necessarily equal.

See also

Maths.Similar2

From​Points

2 overloads


[Pure]
public static method FromPoints1 → (4)

x1 in : float64

X-coordinate of first corner point.

y1 in : float64

Y-coordinate of first corner point.

x2 in : float64

X-coordinate of second corner point.

y2 in : float64

Y-coordinate of second corner point.

returns → Box2D

The bounding box.

Creates a new instance of Box2D from the given corner points.


[Pure]
public static method FromPoints2 → (2)

in : Vec2D

First corner point.

in : Vec2D

Second corner point.

returns → Box2D

The bounding box.

Creates a new instance of Box2D from the given corner points.

From​Rect


[Pure]
public static method FromRect → (4)

in : float64

X-coordinate of first corner point.

in : float64

Y-coordinate of first corner point.

width in : float64

Width of rectangle.

height in : float64

Height of rectangle.

returns → Box2D

The bounding box.

Creates a new instance of Box2D from the given rectangle.

Grow

3 overloads


public method Grow1 → (1)

box in : Box2D

To other box.

returns → Box2D

The resulting box.

Enlarges the extends of this box so that it covers the given box.


public method Grow2 → (1)

in : Vec2D

Coordinates of point to cover (can be NaN).

returns → Box2D

The resulting box.

Enlarges the extends of this box so that it covers the given point.


public method Grow3 → (2)

in : float64

X-coordinate of point to cover (can be NaN).

in : float64

Y-coordinate of point to cover (can be NaN).

returns → Box2D

The resulting box.

Enlarges the extends of this box so that it covers the given point.

Intersect


[Pure]
public method Intersect → (1)

box in : Box2D

The bounding box.

returns → Box2D

The resulting bounding box.

Computes the intersection of the given bounding box and this one.

Pad


[Pure]
public method Pad → (1)

amount in : float64

The amount to grow.

returns → Box2D

The resulting box

Uniformly pads (i.e. grows) this box by the given amount in.

Scale


[Pure]
public method Scale → (1)

factor in : float64

The scale factor.

returns → Box2D

The resulting bounding box.

Scales the coordinates of this bounding box.

Translate

2 overloads


[Pure]
public method Translate1 → (1)

in : Vec2D

The translation vector.

returns → Box2D

The translated bounding box.

Translates this bounding box.


[Pure]
public method Translate2 → (2)

in : float64

Translation amount along X-axis.

in : float64

Translation amount along Y-axis.

returns → Box2D

The resulting bounding box.

Translates this bounding box.

Public / Attributes

Area


public attribute Area → (get)

value : float64

[>=0]
The bounding box volume.

Returns the volume of this bounding box.

The volume will always be 0 when IsEmpty returns true.

Bottom​Left


public attribute BottomLeft → (get)

value : Vec2D

The bottom-left corner: X1 is stored in Vec2D.X, Y2 is stored in Vec2D.Y.

Returns the bottom-left corner of this box.

Bottom​Right


public attribute BottomRight → (get)

value : Vec2D

The bottom-right corner: X2 is stored in Vec2D.X, Y2 is stored in Vec2D.Y.

Returns the bottom-right corner of this box.

Center


public attribute Center → (get)

value : Vec2D

The coordinates of the box center.

Return the center of this box.

Height


public attribute Height → (get)

value : float64

[>=0]
The box height.

Returns the extends of this box along the Y-axis.

Is​Empty


public attribute IsEmpty → (get)

value : bool

true if this bounding box is empty, false if not.

Is this bounding box empty?

See also

Box2D.Empty

Is​Inverse


public attribute IsInverse → (get)

value : bool

true if this is the inverse bounding box, false if not.

Is this the inverse bounding box?

See also

Box2D.Inverse

Size


public attribute Size → (get)

value : Vec2D

The box size: The Width is stored in Vec2D.X, the Height in Vec2D.Y.

Returns the size of this box.

Top​Left


public attribute TopLeft → (get)

value : Vec2D

The top-left corner: X1 is stored in Vec2D.X, Y1 is stored in Vec2D.Y.

Returns the top-left corner of this box.

Top​Right


public attribute TopRight → (get)

value : Vec2D

The top-right corner: X2 is stored in Vec2D.X, Y1 is stored in Vec2D.Y.

Returns the top-right corner of this box.

Width


public attribute Width → (get)

value : float64

[>=0]
The box width.

Returns the extends of this box along the X-axis.

X1


public readonly attribute X1 → (float64)

X-coordinate of minimum corner of bounding box.

X2


public readonly attribute X2 → (float64)

X-coordinate of maximum corner of bounding box.

Y1


public readonly attribute Y1 → (float64)

Y-coordinate of minimum corner of bounding box.

Y2


public readonly attribute Y2 → (float64)

Y-coordinate of maximum corner of bounding box.

Serialization

Serializer


public static readonly attribute Serializer → (ITypeSerializer<Box2D>)

The serialization helper object for values of Box2D.