Show / Hide Table of Contents

Struct Box3i

Defines an axis-aligned 2d box (cube).

Implements
IEquatable<Box3i>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Box3i : IEquatable<Box3i>, IFormattable

Constructors

Box3i(Vector3i, Vector3i)

Initializes a new instance of the Box3i struct.

Declaration
public Box3i(Vector3i min, Vector3i max)
Parameters
Type Name Description
Vector3i min

The minimum point this box encloses.

Vector3i max

The maximum point this box encloses.

Box3i(int, int, int, int, int, int)

Initializes a new instance of the Box3i struct.

Declaration
public Box3i(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
Parameters
Type Name Description
int minX

The minimum X value to be enclosed.

int minY

The minimum Y value to be enclosed.

int minZ

The minimum Z value to be enclosed.

int maxX

The maximum X value to be enclosed.

int maxY

The maximum Y value to be enclosed.

int maxZ

The maximum Z value to be enclosed.

Fields

Empty

An empty box with Min = Vector3i.MaxValue and Max = Vector3i.MinValue. This box can be used with Extend(Vector3i) to create a bounding box without a special case for the first point.

Declaration
public static readonly Box3i Empty
Field Value
Type Description
Box3i
Examples

For example:

Vector3i[] points = GetPoints();
Box3i aabb = Box3i.Empty;
for (int i = 0; i < points.Length; i++)
{
    aabb.Extend(points[i]):
}

Will calculate the bounding box of all the points in the array without needing a special case for the first point.

Max

The maximum boundary of the box. This field is not guaranteed to be greater than Max.

Declaration
public Vector3i Max
Field Value
Type Description
Vector3i
Remarks

A box with a minimum point greater than the maximum is not considered valid except for a single configuration where Min = Vector3i.PositiveInfinity and Max = Vector3i.NegativeInfinity as is the case with Empty.

Min

The minimum boundary of the box. This field is not guaranteed to be less than Max.

Declaration
public Vector3i Min
Field Value
Type Description
Vector3i
Remarks

A box with a minimum point greater than the maximum is not considered valid except for a single configuration where Min = Vector3i.PositiveInfinity and Max = Vector3i.NegativeInfinity as is the case with Empty.

See Also
Empty
IsEmpty

UnitCube

A box with a Min = (0, 0, 0) and Max = (1, 1, 1).

Declaration
public static readonly Box3i UnitCube
Field Value
Type Description
Box3i

Zero

A box with Min = Vector3i.Zero and Min = Vector3i.Zero.

Declaration
public static readonly Box3i Zero
Field Value
Type Description
Box3i
Remarks

If you want an empty box, consider using Empty.

Properties

Center

Gets a vector describing the center of the box.

Declaration
public readonly Vector3 Center { get; }
Property Value
Type Description
Vector3

Depth

The depth of the box.

Declaration
public readonly int Depth { get; }
Property Value
Type Description
int

HalfSize

Gets half the size of the box. The distance from the center of the box to the edge of the box in X and Y.

Declaration
public readonly Vector3 HalfSize { get; }
Property Value
Type Description
Vector3
Remarks

This function never returns negative values, so Empty will have a size of (0, 0).

HasZeroArea

If this box has zero area.

Declaration
public readonly bool HasZeroArea { get; }
Property Value
Type Description
bool

Height

The height of the box.

Declaration
public readonly int Height { get; }
Property Value
Type Description
int

IsEmpty

If this box is equal to Empty.

Declaration
public readonly bool IsEmpty { get; }
Property Value
Type Description
bool

IsPoint

If this box is a point, i.e. its minimum point is equal to its maximum point.

Declaration
public readonly bool IsPoint { get; }
Property Value
Type Description
bool

Location

Gets the location of the box from a Location + Size perspective. Basically an alias for Min.

Declaration
public readonly Vector3i Location { get; }
Property Value
Type Description
Vector3i

LongVolume

The area of the box as a long.

Declaration
public readonly long LongVolume { get; }
Property Value
Type Description
long

Size

Gets the size of the box.

Declaration
public readonly Vector3i Size { get; }
Property Value
Type Description
Vector3i
Remarks

This function never returns negative values, so Empty will have a size of (0, 0).

Volume

The area of the box.

Declaration
public readonly int Volume { get; }
Property Value
Type Description
int

Width

The width of the box.

Declaration
public readonly int Width { get; }
Property Value
Type Description
int

Methods

Contains(Box3i)

Returns whether the box other is entirely contained within this box. A box is considered to be able to contain itself.

Declaration
public readonly bool Contains(Box3i other)
Parameters
Type Name Description
Box3i other

The box to check.

Returns
Type Description
bool

true if the box other is entirely contained within the this box; otherwise, false.

ContainsExclusive(Vector3i)

Returns whether the box contains the specified point (borders exclusive).

Declaration
public readonly bool ContainsExclusive(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

ContainsInclusive(Vector3i)

Returns whether the box contains the specified point (borders inclusive).

Declaration
public readonly bool ContainsInclusive(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

Equals(Box3i)

Indicates whether the current object is equal to another object of the same type.

Declaration
public readonly bool Equals(Box3i other)
Parameters
Type Name Description
Box3i other

An object to compare with this object.

Returns
Type Description
bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

Declaration
public override readonly bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare with the current instance.

Returns
Type Description
bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Overrides
ValueType.Equals(object)

EuclidianDistanceToNearestEdge(Vector3i)

Returns the euclidian distance between the nearest point on an edge and the specified point.

Declaration
public readonly float EuclidianDistanceToNearestEdge(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

EuclidianDistanceToNearestPointInBox(Vector3i)

Returns the euclidian distance between the nearest point inside the box and the specified point.

Declaration
public readonly float EuclidianDistanceToNearestPointInBox(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

Remarks

The distance to points inside the box is zero.

Extend(Vector3i)

Extends this box to encapsulate a given point.

Declaration
public void Extend(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to contain.

Remarks

This can be used in combination with Empty to make an efficient bounding box calculation.

Examples

For example:

Vector3i[] points = GetPoints();
Box3i aabb = Box3i.Empty;
for (int i = 0; i < points.Length; i++)
{
    aabb.Extend(points[i]):
}

Will calculate the bounding box of all the points in the array without needing a special case for the first point.

Extended(Vector3i)

Returns a box that is extended to encapsulate a given point.

Declaration
public readonly Box3i Extended(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to contain.

Returns
Type Description
Box3i

The extended box.

Remarks

This can be used in combination with Empty to make an efficient bounding box calculation.

Examples

For example:

Vector3i[] points = GetPoints();
Box3i aabb = Box3i.Empty;
for (int i = 0; i < points.Length; i++)
{
    aabb = aabb.Extended(points[i]):
}

Will calculate the bounding box of all the points in the array without needing a special case for the first point.

FromPositionAndHalfSize(Vector3i, Vector3i)

Creates a box from a center point and a half size.

Declaration
public static Box3i FromPositionAndHalfSize(Vector3i center, Vector3i halfSize)
Parameters
Type Name Description
Vector3i center

The center of the box.

Vector3i halfSize

The half size of the box.

Returns
Type Description
Box3i

The created box.

FromPositions(Vector3i, Vector3i)

Creates a box from a minimum and maximum point.

Declaration
public static Box3i FromPositions(Vector3i min, Vector3i max)
Parameters
Type Name Description
Vector3i min

The minimum point on the XY plane this box encloses.

Vector3i max

The maximum point on the XY plane this box encloses.

Returns
Type Description
Box3i

The created box.

FromSize(Vector3i, Vector3i)

Creates a box from a point and size.

Declaration
public static Box3i FromSize(Vector3i point, Vector3i size)
Parameters
Type Name Description
Vector3i point

The minimum point of the box.

Vector3i size

The size of the box.

Returns
Type Description
Box3i

The created box.

GetHashCode()

Returns the hash code for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int

A 32-bit signed integer that is the hash code for this instance.

Overrides
ValueType.GetHashCode()

Inflate(Vector3i)

Inflates this box by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize.

Declaration
public void Inflate(Vector3i size)
Parameters
Type Name Description
Vector3i size

The size to inflate by.

Inflated(Vector3i)

Returns a box inflated by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize.

Declaration
public readonly Box3i Inflated(Vector3i size)
Parameters
Type Name Description
Vector3i size

The size to inflate by.

Returns
Type Description
Box3i

The inflated box.

Intersect(Box3i)

Replaces this box with the intersection of itself and the specified box.

Declaration
public void Intersect(Box3i other)
Parameters
Type Name Description
Box3i other

The Box with which to intersect.

Intersect(Box3i, Box3i)

Returns the intersection of two boxes.

Declaration
public static Box3i Intersect(Box3i a, Box3i b)
Parameters
Type Name Description
Box3i a

The first box.

Box3i b

The second box.

Returns
Type Description
Box3i

The intersection of the two boxes.

Intersect(in Box3i, in Box3i)

Returns the intersection of two boxes.

Declaration
public static Box3i Intersect(in Box3i a, in Box3i b)
Parameters
Type Name Description
Box3i a

The first box.

Box3i b

The second box.

Returns
Type Description
Box3i

The intersection of the two boxes.

Intersected(Box3i)

Returns the intersection of itself and the specified box.

Declaration
public readonly Box3i Intersected(Box3i other)
Parameters
Type Name Description
Box3i other

The Box with which to intersect.

Returns
Type Description
Box3i

The intersection of itself and the specified box.

IntersectsWith(Box3i)

Determines if this box intersects with another box.

Declaration
public readonly bool IntersectsWith(Box3i other)
Parameters
Type Name Description
Box3i other

The box to test.

Returns
Type Description
bool

This method returns true if there is any intersection, otherwise false.

Remarks

Two boxes next to each other do not intersect, for detecting that case use Touches(Box3i).

ManhattanDistanceToNearestEdge(Vector3)

Returns the manhattan distance between the nearest point on an edge and the specified point.

Declaration
public readonly float ManhattanDistanceToNearestEdge(Vector3 point)
Parameters
Type Name Description
Vector3 point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

ManhattanDistanceToNearestEdge(Vector3i)

Returns the manhattan distance between the nearest point on an edge and the specified point.

Declaration
public readonly int ManhattanDistanceToNearestEdge(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
int

The distance between the specified point and the nearest edge.

ManhattanDistanceToNearestPointInBox(Vector3i)

Returns the manhattan distance between the nearest point in the box and the specified point.

Declaration
public readonly int ManhattanDistanceToNearestPointInBox(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
int

The distance between the specified point and the nearest edge.

Remarks

The distance to points inside the box is zero.

NearestPointInBox(Vector3i)

Returns the nearest point in or on the edge of the box to the given point, point.

Declaration
public readonly Vector3i NearestPointInBox(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point for which the nearest point in the box should be found.

Returns
Type Description
Vector3i

The nearest point on or on the edge of the box to the point, point.

NearestPointOnEdge(Vector3i)

Returns the nearest point that is on the edge of the box.

Declaration
public readonly Vector3i NearestPointOnEdge(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point for which the nearest point on the edge of the box should be found.

Returns
Type Description
Vector3i

The nearest point on the edge of the box to the point, point.

Scale(Vector3i, Vector3i)

Scales this box by the given scale, scale, and from the given anchor point, anchor.

Declaration
public void Scale(Vector3i scale, Vector3i anchor)
Parameters
Type Name Description
Vector3i scale

The scale to scale the box.

Vector3i anchor

The anchor to scale the box from.

Scaled(Vector3i, Vector3i)

Returns a box scaled by the given scale, scale, and from the given anchor point, anchor.

Declaration
public readonly Box3i Scaled(Vector3i scale, Vector3i anchor)
Parameters
Type Name Description
Vector3i scale

The scale to scale the box.

Vector3i anchor

The anchor to scale the box from.

Returns
Type Description
Box3i

The scaled box.

SignedEuclidianDistanceToNearestEdge(Vector3i)

Returns the signed distance between the nearest edge and the specified point.

Declaration
public readonly float SignedEuclidianDistanceToNearestEdge(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

SignedManhattanDistanceToNearestEdge(Vector3)

Returns the signed manhattan distance between the nearest edge and the specified point.

Declaration
public readonly float SignedManhattanDistanceToNearestEdge(Vector3 point)
Parameters
Type Name Description
Vector3 point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

SignedManhattanDistanceToNearestEdge(Vector3i)

Returns the signed manhattan distance between the nearest edge and the specified point.

Declaration
public readonly int SignedManhattanDistanceToNearestEdge(Vector3i point)
Parameters
Type Name Description
Vector3i point

The point to find distance for.

Returns
Type Description
int

The distance between the specified point and the nearest edge.

ToString()

Returns the fully qualified type name of this instance.

Declaration
public override readonly string ToString()
Returns
Type Description
string

The fully qualified type name.

Overrides
ValueType.ToString()

ToString(IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
Type Name Description
IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string, IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

Touches(Box3i)

Determines if this box intersects or touches with another box.

Declaration
public readonly bool Touches(Box3i other)
Parameters
Type Name Description
Box3i other

The box to test.

Returns
Type Description
bool

This method returns true if there is any intersection or touches, otherwise false.

Translate(Vector3i)

Translates this box by the given distance.

Declaration
public void Translate(Vector3i distance)
Parameters
Type Name Description
Vector3i distance

The distance to translate the box.

Translated(Vector3i)

Returns a box translated by the given distance.

Declaration
public readonly Box3i Translated(Vector3i distance)
Parameters
Type Name Description
Vector3i distance

The distance to translate the box.

Returns
Type Description
Box3i

The translated box.

Operators

operator ==(Box3i, Box3i)

Equality comparator. Two boxes are considered equal if both the Min and Max fields are equal.

Declaration
public static bool operator ==(Box3i left, Box3i right)
Parameters
Type Name Description
Box3i left

The left operand.

Box3i right

The right operand.

Returns
Type Description
bool

explicit operator Box3(Box3i)

Converts this Box3i to a Box3.

Declaration
public static explicit operator Box3(Box3i box)
Parameters
Type Name Description
Box3i box

The box to cast.

Returns
Type Description
Box3

explicit operator Box3d(Box3i)

Converts this Box3i to a Box3d.

Declaration
public static explicit operator Box3d(Box3i box)
Parameters
Type Name Description
Box3i box

The box to cast.

Returns
Type Description
Box3d

operator !=(Box3i, Box3i)

Inequality comparator.

Declaration
public static bool operator !=(Box3i left, Box3i right)
Parameters
Type Name Description
Box3i left

The left operand.

Box3i right

The right operand.

Returns
Type Description
bool

Implements

IEquatable<T>
IFormattable
In this article
Back to top Generated by DocFX