TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

struct Box2I in Tinman.Terrain.Util

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

struct Box2I implements IEquatable<Box2I>

Remarks

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

Serialization

Serializer

The serialization helper object for values of Box2I.

public static readonly field Serializer
type ITypeSerializer<Box2I>

Public / Constants

Empty

An empty bounding box at the coordinate origin.

public static readonly field Empty
type Box2I

Inverse

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

public static readonly field Inverse
type Box2I

Public / Attributes

Area

Returns the area of this bounding box.

public property Area { get }
type int64
value The area.

Remarks:

The area will always be 0 when IsEmpty returns true.

BottomLeft

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

public property BottomLeft { get }
type Vec2I
value The bottom-left corner: X1 is stored in X, Y2 is stored in Y.

BottomRight

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

public property BottomRight { get }
type Vec2I
value The bottom-right corner: X2 is stored in X, Y2 is stored in Y.

Center

public property Center { get }
type Vec2I
value

Height

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

public property Height { get }
type int32
value The box height.

IsEmpty

Is this bounding box empty?

public property IsEmpty { get }
type bool
value true if this bounding box is empty, false if not.

Size

Returns the size of this box.

public property Size { get }
type Vec2I
value The box size: The Width is stored in X, the Height in Y.

TopLeft

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

public property TopLeft { get }
type Vec2I
value The top-left corner: X1 is stored in X, Y1 is stored in Y.

TopRight

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

public property TopRight { get }
type Vec2I
value The top-right corner: X2 is stored in X, Y1 is stored in Y.

Width

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

public property Width { get }
type int32
value The box width.

X1

X-coordinate of minimum corner of bounding box.

public readonly field X1
type int32

X2

X-coordinate of maximum corner of bounding box.

public readonly field X2
type int32

Y1

Y-coordinate of minimum corner of bounding box.

public readonly field Y1
type int32

Y2

Y-coordinate of maximum corner of bounding box.

public readonly field Y2
type int32

Public / Methods

CheckIntersection

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

[Pure]
public method CheckIntersection (Box2I box)
type int32
params box The bounding box.
returns -1 if the bounding boxes do not overlap, 1 if box fully contains this bounding box and 0 if both bounding boxes overlap without containing each other.

Clamp

Clamps the given coordinates to this bounding box.

[Pure]
public method Clamp (Vec2I v)
type Vec2I
params v The coordinates to clamp.
returns The clamped coordinates.

Clamps the given coordinates to this bounding box.

[Pure]
public method Clamp (int32 x, int32 y)
type Vec2I
params x X-coordinate to clamp.
  y Y-coordinate to clamp.
returns The clamped coordinates.

ComputeOverlap

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

[Pure]
public method ComputeOverlap (Box2I box)
type int64
params box Second bounding box.
returns [>=0] The amount of overlap (i.e. the volume of the intersection).

Contains

Checks if this box contains the given point.

[Pure]
public method Contains (Vec2I xy)
type bool
params xy The point coordinates.
returns true if this box contains the point, false if not.

Checks if this box contains the given box.

[Pure]
public method Contains (Box2I box)
type bool
params box The other box.
returns true if this box fully contains the given box, false if not.

Checks if this box contains the given point.

[Pure]
public method Contains (int32 x, int32 y)
type bool
params x The point X-coordinate.
  y The point Y-coordinate.
returns true if this box contains the point, false if not.

Disjoint

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

[Pure]
public method Disjoint (Box2I box)
type bool
params box The other box.
returns true if this box and the given box are disjoint, false if not.

Equals

[Pure]
public method Equals (Box2I other)
type bool
params other

FromPoints

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

[Pure]
public static method FromPoints (Vec2I a, Vec2I b)
type Box2I
params a First corner point (inclusive).
  b Second corner point (inclusive).
returns The bounding box.

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

[Pure]
public static method FromPoints (int32 x1, int32 y1, int32 x2, int32 y2)
type Box2I
params x1 X-coordinate of first corner point (inclusive).
  y1 Y-coordinate of first corner point (inclusive).
  x2 X-coordinate of second corner point (inclusive).
  y2 Y-coordinate of second corner point (inclusive).
returns The bounding box.

FromRect

Creates a new instance of Box2I from the given rectangle.

[Pure]
public static method FromRect (int32 x, int32 y, int32 width, int32 height)
type Box2I
params x X-coordinate of top-left corner of rectangle.
  y Y-coordinate of top-left corner of rectangle.
  width Width of rectangle.
  height Height of rectangle.
returns The bounding box.

Grow

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

public method Grow (Box2I box)
type Box2I
params box To other box.
returns The resulting box.

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

public method Grow (Vec2I v)
type Box2I
params v Coordinates of point to cover.
returns The resulting box.

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

public method Grow (int32 x, int32 y)
type Box2I
params x X-coordinate of point to cover.
  y Y-coordinate of point to cover.
returns The resulting box.

Intersect

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

[Pure]
public method Intersect (Box2I box)
type Box2I
params box The bounding box.
returns The resulting bounding box.

Pad

Pads this bounding box by moving the edges individually.

public method Pad (int32 top, int32 left, int32 bottom, int32 right)
type Box2I
params top The amount by which to decrease Y1.
  left The amount by which to decrease X1.
  bottom The amount by which to increase Y2.
  right The amount by which to increase X2.
returns The padded bounding box.

ToString

Returns a simple string representation of this bounding box.

[Pure]
public override method ToString ()
type string
returns [not-null] The string representation.

Translate

Translates this bounding box.

[Pure]
public method Translate (Vec2I v)
type Box2I
params v The translation vector.
returns The translated bounding box.

Translates this bounding box.

[Pure]
public method Translate (int32 x, int32 y)
type Box2I
params x Translation amount along X-axis.
  y Translation amount along Y-axis.
returns The translated bounding box.