Show / Hide Table of Contents

Struct Box3d

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

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

Constructors

Box3d(Vector3d, Vector3d)

Initializes a new instance of the Box3d struct.

Declaration
public Box3d(Vector3d min, Vector3d max)
Parameters
Type Name Description
Vector3d min

The minimum point this box encloses.

Vector3d max

The maximum point this box encloses.

Box3d(double, double, double, double, double, double)

Initializes a new instance of the Box3d struct.

Declaration
public Box3d(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
Parameters
Type Name Description
double minX

The minimum X value to be enclosed.

double minY

The minimum Y value to be enclosed.

double minZ

The minimum Z value to be enclosed.

double maxX

The maximum X value to be enclosed.

double maxY

The maximum Y value to be enclosed.

double maxZ

The maximum Z value to be enclosed.

Fields

Empty

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

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

For example:

Vector3d[] points = GetPoints();
Box3d aabb = Box3d.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 Vector3d Max
Field Value
Type Description
Vector3d
Remarks

A box with a minimum point greater than the maximum is not considered valid except for a single configuration where Min = Vector3d.PositiveInfinity and Max = Vector3d.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 Vector3d Min
Field Value
Type Description
Vector3d
Remarks

A box with a minimum point greater than the maximum is not considered valid except for a single configuration where Min = Vector3d.PositiveInfinity and Max = Vector3d.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 Box3d UnitCube
Field Value
Type Description
Box3d

Zero

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

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

If you want an empty box, consider using Empty.

Properties

Center

Gets or sets a vector describing the center of the box.

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

Depth

The depth of the box.

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

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 Vector3d HalfSize { get; }
Property Value
Type Description
Vector3d
Remarks

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

HasZeroVolume

If this box has zero volume.

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

Height

The height of the box.

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

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 Vector3d Location { get; }
Property Value
Type Description
Vector3d

Size

Gets the size of the box.

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

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

Volume

The volume of the box.

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

Width

The width of the box.

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

Methods

Ceiling(Box3d)

Returns a box that contains rounded up integers.

Declaration
public static Box3d Ceiling(Box3d box)
Parameters
Type Name Description
Box3d box

The box to round.

Returns
Type Description
Box3d

The box that contains rounded up integers.

Contains(Box3d)

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(Box3d other)
Parameters
Type Name Description
Box3d other

The box to check.

Returns
Type Description
bool

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

ContainsExclusive(Vector3d)

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

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

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

See Also
ContainsInclusive(Vector3d)

ContainsInclusive(Vector3d)

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

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

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

See Also
ContainsExclusive(Vector3d)

DistanceToNearestEdge(Vector3d)

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

Declaration
public readonly double DistanceToNearestEdge(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to find distance for.

Returns
Type Description
double

The distance between the specified point and the nearest edge.

DistanceToNearestPointInBox(Vector3d)

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

Declaration
public readonly double DistanceToNearestPointInBox(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to find distance for.

Returns
Type Description
double

The distance between the specified point and the nearest edge.

Remarks

The distance to points inside the box is zero.

Equals(Box3d)

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

Declaration
public readonly bool Equals(Box3d other)
Parameters
Type Name Description
Box3d 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)

Extend(Vector3d)

Extends this box to encapsulate a given point.

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

The point to contain.

Remarks

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

Examples

For example:

Vector3d[] points = GetPoints();
Box3d aabb = Box3d.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.

ExtendNative(Vector3d)

Extends this box to encapsulate a given point. With NaN propagation and -0 behaviour being platform dependent.

Declaration
public void ExtendNative(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to contain.

Remarks

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

Examples

For example:

Vector3d[] points = GetPoints();
Box3d aabb = Box3d.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(Vector3d)

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

Declaration
public readonly Box3d Extended(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to contain.

Returns
Type Description
Box3d

The extended box.

Remarks

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

Examples

For example:

Vector3d[] points = GetPoints();
Box3d aabb = Box3d.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.

ExtendedNative(Vector3d)

Returns a box that is extended to encapsulate a given point. With NaN propagation and -0 behaviour being platform dependent.

Declaration
public readonly Box3d ExtendedNative(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to contain.

Returns
Type Description
Box3d

The extended box.

Remarks

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

Examples

For example:

Vector3d[] points = GetPoints();
Box3d aabb = Box3d.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.

Floor(Box3d)

Returns a box that contains rounded down integers.

Declaration
public static Box3d Floor(Box3d box)
Parameters
Type Name Description
Box3d box

The box to round.

Returns
Type Description
Box3d

The box that contains rounded down integers.

FloorCeiling(Box3d)

Returns a box where Min has been rounded down and Max has been rounded up.

Declaration
public static Box3d FloorCeiling(Box3d box)
Parameters
Type Name Description
Box3d box

The box to round.

Returns
Type Description
Box3d

The box that contains rounded down integers.

FromCenterAndHalfSize(Vector3d, Vector3d)

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

Declaration
public static Box3d FromCenterAndHalfSize(Vector3d center, Vector3d halfSize)
Parameters
Type Name Description
Vector3d center

The center of the box.

Vector3d halfSize

The half size of the box.

Returns
Type Description
Box3d

The created box.

FromMinMax(Vector3d, Vector3d)

Creates a box from a minimum and maximum point.

Declaration
public static Box3d FromMinMax(Vector3d min, Vector3d max)
Parameters
Type Name Description
Vector3d min

The minimum point on the XY plane this box encloses.

Vector3d max

The maximum point on the XY plane this box encloses.

Returns
Type Description
Box3d

The created box.

FromSize(Vector3d, Vector3d)

Creates a box from a point and size.

Declaration
public static Box3d FromSize(Vector3d point, Vector3d size)
Parameters
Type Name Description
Vector3d point

The minimum point of the box.

Vector3d size

The size of the box.

Returns
Type Description
Box3d

The created box.

FromTwoPoints(Vector3d, Vector3d)

Create a box from two unordered points, i.e. creates a box that contains two points.

Declaration
public static Box3d FromTwoPoints(Vector3d p1, Vector3d p2)
Parameters
Type Name Description
Vector3d p1

The first point to contain.

Vector3d p2

The second point to contain.

Returns
Type Description
Box3d

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(Vector3d)

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(Vector3d size)
Parameters
Type Name Description
Vector3d size

The size to inflate by.

Inflated(Vector3d)

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 Box3d Inflated(Vector3d size)
Parameters
Type Name Description
Vector3d size

The size to inflate by.

Returns
Type Description
Box3d

The inflated box.

Intersect(Box3d)

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

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

The Box with which to intersect.

Intersect(Box3d, Box3d)

Returns the intersection of two boxes, or Empty if there is no intersection.

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

The first box.

Box3d b

The second box.

Returns
Type Description
Box3d

The intersection of the two boxes.

IntersectNative(Box3d, Box3d)

Returns the intersection of two boxes, or Empty if there is no intersection. With NaN propagation and -0 behaviour being platform depedent.

Declaration
public static Box3d IntersectNative(Box3d a, Box3d b)
Parameters
Type Name Description
Box3d a

The first box.

Box3d b

The second box.

Returns
Type Description
Box3d

The intersection of the two boxes.

Intersected(Box3d)

Returns the intersection of itself and the specified box.

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

The Box with which to intersect.

Returns
Type Description
Box3d

The intersection of itself and the specified Box.

IntersectsWith(Box3d)

Determines if this box intersects with another box.

Declaration
public readonly bool IntersectsWith(Box3d other)
Parameters
Type Name Description
Box3d 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(Box3d).

NearestPointInBox(Vector3d)

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

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

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

Returns
Type Description
Vector3d

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

NearestPointOnEdge(Vector3d)

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

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

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

Returns
Type Description
Vector3d

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

Round(Box3d)

Returns a box that contains rounded integers.

Declaration
public static Box3d Round(Box3d box)
Parameters
Type Name Description
Box3d box

The box to round.

Returns
Type Description
Box3d

The box that contains rounded integers.

Scale(Vector3d, Vector3d)

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

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

The scale to scale the box.

Vector3d anchor

The anchor to scale the box from.

Scaled(Vector3d, Vector3d)

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

Declaration
public readonly Box3d Scaled(Vector3d scale, Vector3d anchor)
Parameters
Type Name Description
Vector3d scale

The scale to scale the box.

Vector3d anchor

The anchor to scale the box from.

Returns
Type Description
Box3d

The scaled box.

SignedDistanceToNearestEdge(Vector3d)

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

Declaration
public readonly double SignedDistanceToNearestEdge(Vector3d point)
Parameters
Type Name Description
Vector3d point

The point to find distance for.

Returns
Type Description
double

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(Box3d)

Determines if this box intersects or touches with another box.

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

The box to test.

Returns
Type Description
bool

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

Translate(Vector3d)

Translates this box by the given distance.

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

The distance to translate the box.

Translated(Vector3d)

Returns a box translated by the given distance.

Declaration
public readonly Box3d Translated(Vector3d distance)
Parameters
Type Name Description
Vector3d distance

The distance to translate the box.

Returns
Type Description
Box3d

The translated box.

Operators

operator ==(Box3d, Box3d)

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

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

The left operand.

Box3d right

The right operand.

Returns
Type Description
bool

explicit operator Box3(Box3d)

Converts this Box3d to a Box3.

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

The box to cast.

Returns
Type Description
Box3

explicit operator Box3i(Box3d)

Converts this Box3d to a Box3i using truncation.

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

The box to cast.

Returns
Type Description
Box3i

operator !=(Box3d, Box3d)

Inequality comparator.

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

The left operand.

Box3d right

The right operand.

Returns
Type Description
bool

Implements

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