Box2F

Description

struct Tinman.Terrain.Util.Box2F

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

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

Public / Constants

Empty


public static readonly attribute Empty → (Box2F)

An empty bounding box at the coordinate origin.

See also

Box2F.IsEmpty

Inverse


public static readonly attribute Inverse → (Box2F)

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

See also

Box2F.IsInverse

Max


public static readonly attribute Max → (Box2F)

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 : Box2F

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 : Vec2F

First point of line segment.

in : Vec2F

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 : float32

X-coordinate of first point of line segment.

ay in : float32

Y-coordinate of first point of line segment.

bx in : float32

X-coordinate of second point of line segment.

by in : float32

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 : float32

X-coordinate of first point of line segment.

ay in : float32

Y-coordinate of first point of line segment.

bx in : float32

X-coordinate of second point of line segment.

by in : float32

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 : float32

X-coordinate of point.

in : float32

Y-coordinate of point.

returns → Vec2F

The clamped point.

Clamps the given point to this box.


[Pure]
public method Clamp2 → (1)

in : Vec2F

The point coordinates.

returns → Vec2F

The clamped point.

Clamps the given point to this box.

Compute​Overlap


[Pure]
public method ComputeOverlap → (1)

box in : Box2F

Second bounding box.

returns → float32

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 : Vec2F

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 : float32

The point X-coordinate.

in : float32

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 : Box2F

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 : Box2F

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 : Box2F

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.Similar1

From​Points

2 overloads


[Pure]
public static method FromPoints1 → (4)

x1 in : float32

X-coordinate of first corner point.

y1 in : float32

Y-coordinate of first corner point.

x2 in : float32

X-coordinate of second corner point.

y2 in : float32

Y-coordinate of second corner point.

returns → Box2F

The bounding box.

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


[Pure]
public static method FromPoints2 → (2)

in : Vec2F

First corner point.

in : Vec2F

Second corner point.

returns → Box2F

The bounding box.

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

From​Rect


[Pure]
public static method FromRect → (4)

in : float32

X-coordinate of first corner point.

in : float32

Y-coordinate of first corner point.

width in : float32

Width of rectangle.

height in : float32

Height of rectangle.

returns → Box2F

The bounding box.

Creates a new instance of Box2F from the given rectangle.

Grow

3 overloads


public method Grow1 → (1)

box in : Box2F

To other box.

returns → Box2F

The resulting box.

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


public method Grow2 → (1)

in : Vec2F

Coordinates of point to cover (can be NaN).

returns → Box2F

The resulting box.

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


public method Grow3 → (2)

in : float32

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

in : float32

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

returns → Box2F

The resulting box.

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

Intersect


[Pure]
public method Intersect → (1)

box in : Box2F

The bounding box.

returns → Box2F

The resulting bounding box.

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

Pad


[Pure]
public method Pad → (1)

amount in : float32

The amount to grow.

returns → Box2F

The resulting box

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

Scale


[Pure]
public method Scale → (1)

factor in : float32

The scale factor.

returns → Box2F

The resulting bounding box.

Scales the coordinates of this bounding box.

Translate

2 overloads


[Pure]
public method Translate1 → (1)

in : Vec2F

The translation vector.

returns → Box2F

The translated bounding box.

Translates this bounding box.


[Pure]
public method Translate2 → (2)

in : float32

Translation amount along X-axis.

in : float32

Translation amount along Y-axis.

returns → Box2F

The resulting bounding box.

Translates this bounding box.

Public / Attributes

Area


public attribute Area → (get)

value : float32

[>=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 : Vec2F

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

Returns the bottom-left corner of this box.

Bottom​Right


public attribute BottomRight → (get)

value : Vec2F

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

Returns the bottom-right corner of this box.

Center


public attribute Center → (get)

value : Vec2F

The coordinates of the box center.

Return the center of this box.

Height


public attribute Height → (get)

value : float32

[>=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

Box2F.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

Box2F.Inverse

Size


public attribute Size → (get)

value : Vec2F

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

Returns the size of this box.

Top​Left


public attribute TopLeft → (get)

value : Vec2F

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

Returns the top-left corner of this box.

Top​Right


public attribute TopRight → (get)

value : Vec2F

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

Returns the top-right corner of this box.

Width


public attribute Width → (get)

value : float32

[>=0]
The box width.

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

X1


public readonly attribute X1 → (float32)

X-coordinate of minimum corner of bounding box.

X2


public readonly attribute X2 → (float32)

X-coordinate of maximum corner of bounding box.

Y1


public readonly attribute Y1 → (float32)

Y-coordinate of minimum corner of bounding box.

Y2


public readonly attribute Y2 → (float32)

Y-coordinate of maximum corner of bounding box.

Serialization

Serializer


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

The serialization helper object for values of Box2F.