Box2I

Description

struct Tinman.Terrain.Util.Box2I

A two-dimensional bounding box with 32-bit integer precision.

The coordinates refer to blocks (pixel-is-area semantic).

    0 1 2 3 4 5

0   . . . . . .   X1 := 1, Y1 := 2
1   . . . . . .
2   . # # # . .   X2 := 3, Y2 := 3
3   . # # # . .
4   . . . . . .   Width := 3, Height := 2
5   . . . . . .

Public / Constants

Empty


public static readonly attribute Empty → (Box2I)

An empty bounding box at the coordinate origin.

See also

Box2I.IsEmpty

Inverse


public static readonly attribute Inverse → (Box2I)

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

See also

Box2I.IsInverse

Max


public static readonly attribute Max → (Box2I)

The largest possible box.

Note that the dimension of this box is 2^32 (4294967296), which cannot be expressed using 32-bits. So instead 0 is returned.

Public / Methods

Check​Intersection


[Pure]
public method CheckIntersection → (1)

box in : Box2I

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.

Clamp

2 overloads


[Pure]
public method Clamp1 → (2)

in : int32

X-coordinate of point.

in : int32

Y-coordinate of point.

returns → Vec2I

The clamped point.

Clamps the given point to this box.


[Pure]
public method Clamp2 → (1)

in : Vec2I

The point coordinates.

returns → Vec2I

The clamped point.

Clamps the given point to this box.

Compute​Overlap


[Pure]
public method ComputeOverlap → (1)

box in : Box2I

Second bounding box.

returns → int64

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)

xy in : Vec2I

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

The point X-coordinate.

in : int32

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

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

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

From​Points

2 overloads


[Pure]
public static method FromPoints1 → (4)

x1 in : int32

X-coordinate of first corner point (inclusive).

y1 in : int32

Y-coordinate of first corner point (inclusive).

x2 in : int32

X-coordinate of second corner point (inclusive).

y2 in : int32

Y-coordinate of second corner point (inclusive).

returns → Box2I

The bounding box.

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


[Pure]
public static method FromPoints2 → (2)

in : Vec2I

First corner point (inclusive).

in : Vec2I

Second corner point (inclusive).

returns → Box2I

The bounding box.

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

From​Rect


[Pure]
public static method FromRect → (4)

in : int32

X-coordinate of top-left corner of rectangle.

in : int32

Y-coordinate of top-left corner of rectangle.

width in : int32

Width of rectangle.

height in : int32

Height of rectangle.

returns → Box2I

The bounding box.

Creates a new instance of Box2I from the given rectangle.

Grow

3 overloads


public method Grow1 → (1)

box in : Box2I

To other box.

returns → Box2I

The resulting box.

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


public method Grow2 → (1)

in : Vec2I

Coordinates of point to cover.

returns → Box2I

The resulting box.

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


public method Grow3 → (2)

in : int32

X-coordinate of point to cover.

in : int32

Y-coordinate of point to cover.

returns → Box2I

The resulting box.

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

Intersect


[Pure]
public method Intersect → (1)

box in : Box2I

The bounding box.

returns → Box2I

The resulting bounding box.

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

Pad


public method Pad → (4)

top in : int32

The amount by which to decrease Y1.

left in : int32

The amount by which to decrease X1.

bottom in : int32

The amount by which to increase Y2.

right in : int32

The amount by which to increase X2.

returns → Box2I

The padded bounding box.

Pads this bounding box by moving the edges individually.

Translate

2 overloads


[Pure]
public method Translate1 → (1)

in : Vec2I

The translation vector.

returns → Box2I

The translated bounding box.

Translates this bounding box.


[Pure]
public method Translate2 → (2)

in : int32

Translation amount along X-axis.

in : int32

Translation amount along Y-axis.

returns → Box2I

The translated bounding box.

Translates this bounding box.

Public / Attributes

Area


public attribute Area → (get)

value : int64

The area.

Returns the area of this bounding box.

The area will always be 0 when IsEmpty returns true.

Bottom​Left


public attribute BottomLeft → (get)

value : Vec2I

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

Returns the bottom-left corner of this box (inclusive).

Bottom​Right


public attribute BottomRight → (get)

value : Vec2I

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

Returns the bottom-right corner of this box (inclusive).

Center


public attribute Center → (get)

value : Vec2I

The coordinates of the box center.

Return the center of this box.

Height


public attribute Height → (get)

value : int32

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?

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

Box2I.Inverse

Size


public attribute Size → (get)

value : Vec2I

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

Returns the size of this box.

Top​Left


public attribute TopLeft → (get)

value : Vec2I

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

Returns the top-left corner of this box (inclusive).

Top​Right


public attribute TopRight → (get)

value : Vec2I

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

Returns the top-right corner of this box (inclusive).

Width


public attribute Width → (get)

value : int32

The box width.

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

X1


public readonly attribute X1 → (int32)

X-coordinate of minimum corner of bounding box.

X2


public readonly attribute X2 → (int32)

X-coordinate of maximum corner of bounding box.

Y1


public readonly attribute Y1 → (int32)

Y-coordinate of minimum corner of bounding box.

Y2


public readonly attribute Y2 → (int32)

Y-coordinate of maximum corner of bounding box.

Serialization

Serializer


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

The serialization helper object for values of Box2I.