Show / Hide Table of Contents

Struct Box2

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

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

Constructors

Box2(Vector2, Vector2)

Initializes a new instance of the Box2 struct.

Declaration
public Box2(Vector2 min, Vector2 max)
Parameters
Type Name Description
Vector2 min

The minimum point on the XY plane this box encloses.

Vector2 max

The maximum point on the XY plane this box encloses.

Box2(float, float, float, float)

Initializes a new instance of the Box2 struct.

Declaration
public Box2(float minX, float minY, float maxX, float maxY)
Parameters
Type Name Description
float minX

The minimum X value to be enclosed.

float minY

The minimum Y value to be enclosed.

float maxX

The maximum X value to be enclosed.

float maxY

The maximum Y value to be enclosed.

Fields

Empty

Gets a box with all components zero.

Declaration
public static readonly Box2 Empty
Field Value
Type Description
Box2

UnitSquare

Gets a box with a location 0,0 with the a size of 1.

Declaration
public static readonly Box2 UnitSquare
Field Value
Type Description
Box2

Properties

Bottom

Gets or sets the bottom location of the box.

Declaration
public float Bottom { get; set; }
Property Value
Type Description
float

Center

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

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

CenteredSize

Gets or sets a vector describing the size of the Box2 structure.

Declaration
public Vector2 CenteredSize { get; set; }
Property Value
Type Description
Vector2

HalfSize

Gets or sets a vector describing half the size of the box.

Declaration
public Vector2 HalfSize { get; set; }
Property Value
Type Description
Vector2

Height

Gets or sets the height of the box.

Declaration
public float Height { get; set; }
Property Value
Type Description
float

IsZero

Gets a value indicating whether all values are zero.

Declaration
public bool IsZero { get; }
Property Value
Type Description
bool

Left

Gets or sets the left location of the box.

Declaration
public float Left { get; set; }
Property Value
Type Description
float

Location

Gets the location of the box.

Declaration
public Vector2 Location { get; }
Property Value
Type Description
Vector2

Max

Gets or sets the maximum boundary of the structure.

Declaration
public Vector2 Max { readonly get; set; }
Property Value
Type Description
Vector2

Min

Gets or sets the minimum boundary of the structure.

Declaration
public Vector2 Min { readonly get; set; }
Property Value
Type Description
Vector2

Right

Gets or sets the right location of the box.

Declaration
public float Right { get; set; }
Property Value
Type Description
float

Size

Gets or sets the size of the box.

Declaration
public Vector2 Size { get; set; }
Property Value
Type Description
Vector2

SizeX

Gets or sets the horizontal size.

Declaration
public float SizeX { get; set; }
Property Value
Type Description
float

SizeY

Gets or sets the vertical size.

Declaration
public float SizeY { get; set; }
Property Value
Type Description
float

Top

Gets or sets the top location of the box.

Declaration
public float Top { get; set; }
Property Value
Type Description
float

Width

Gets or sets the width of the box.

Declaration
public float Width { get; set; }
Property Value
Type Description
float

X

Gets or sets the X location of the box.

Declaration
public float X { get; set; }
Property Value
Type Description
float

Y

Gets or sets the Y location of the box.

Declaration
public float Y { get; set; }
Property Value
Type Description
float

Methods

Ceiling(Box2)

Gets a Box structure that contains rounded up integers.

Declaration
public static Box2i Ceiling(Box2 value)
Parameters
Type Name Description
Box2 value

A Box to round.

Returns
Type Description
Box2i

A Box structure that contains rounded up integers.

Contains(Box2)

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

Declaration
[Pure]
public readonly bool Contains(Box2 other)
Parameters
Type Name Description
Box2 other

The box to query.

Returns
Type Description
bool

Whether this box contains the other box.

Contains(Vector2)

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

Declaration
[Pure]
[Obsolete("This function used to exclude borders, but to follow changes from the other Box structs it's deprecated. Use ContainsInclusive and ContainsExclusive for the desired behaviour.")]
public readonly bool Contains(Vector2 point)
Parameters
Type Name Description
Vector2 point

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

Contains(Vector2, bool)

Returns whether the box contains the specified point.

Declaration
[Pure]
public bool Contains(Vector2 point, bool boundaryInclusive)
Parameters
Type Name Description
Vector2 point

The point to query.

bool boundaryInclusive

Whether points on the box boundary should be recognised as contained as well.

Returns
Type Description
bool

Whether this box contains the point.

ContainsExclusive(Vector2)

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

Declaration
[Pure]
public readonly bool ContainsExclusive(Vector2 point)
Parameters
Type Name Description
Vector2 point

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

ContainsInclusive(Vector2)

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

Declaration
[Pure]
public readonly bool ContainsInclusive(Vector2 point)
Parameters
Type Name Description
Vector2 point

The point to query.

Returns
Type Description
bool

Whether this box contains the point.

DistanceToNearestEdge(Vector2)

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

Declaration
[Pure]
public readonly float DistanceToNearestEdge(Vector2 point)
Parameters
Type Name Description
Vector2 point

The point to find distance for.

Returns
Type Description
float

The distance between the specified point and the nearest edge.

Equals(Box2)

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

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

Extend this Box2 to encapsulate a given point.

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

The point to contain.

Extended(Vector2)

Extend this Box2 to encapsulate a given point.

Declaration
[Pure]
public readonly Box2 Extended(Vector2 point)
Parameters
Type Name Description
Vector2 point

The point to contain.

Returns
Type Description
Box2

The inflated box.

Floor(Box2)

Gets a Box structure that contains rounded down integers.

Declaration
public static Box2i Floor(Box2 value)
Parameters
Type Name Description
Box2 value

A Box to round.

Returns
Type Description
Box2i

A Box structure that contains rounded down integers.

FromPositions(Vector2, Vector2)

Initializes a new instance of the Box2 struct.

Declaration
public static Box2 FromPositions(Vector2 min, Vector2 max)
Parameters
Type Name Description
Vector2 min

The minimum point on the XY plane this box encloses.

Vector2 max

The maximum point on the XY plane this box encloses.

Returns
Type Description
Box2

A box.

FromPositions(float, float, float, float)

Initializes a new instance of the Box2 struct.

Declaration
public static Box2 FromPositions(float minX, float minY, float maxX, float maxY)
Parameters
Type Name Description
float minX

The minimum X value to be enclosed.

float minY

The minimum Y value to be enclosed.

float maxX

The maximum X value to be enclosed.

float maxY

The maximum Y value to be enclosed.

Returns
Type Description
Box2

A box.

FromSize(Vector2, Vector2)

Creates a box.

Declaration
public static Box2 FromSize(Vector2 location, Vector2 size)
Parameters
Type Name Description
Vector2 location

The location of the box.

Vector2 size

The size of the box.

Returns
Type Description
Box2

A 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(Vector2)

Inflates this Box2 by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize. Use the Extend(Vector2) method for the point-encapsulation functionality in OpenTK version 4.8.1 and earlier.

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

The size to inflate by.

Inflated(Vector2)

Inflates this Box2 by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize. Use the Extended(Vector2) method for the point-encapsulation functionality in OpenTK version 4.8.1 and earlier.

Declaration
[Pure]
public readonly Box2 Inflated(Vector2 size)
Parameters
Type Name Description
Vector2 size

The size to inflate by.

Returns
Type Description
Box2

The inflated box.

Intersect(Box2)

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

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

The Box with which to intersect.

Intersect(Box2, Box2)

Returns the intersection of two Boxes.

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

The first box.

Box2 b

The second box.

Returns
Type Description
Box2

The intersection of two Boxes.

Intersected(Box2)

Returns the intersection of itself and the specified Box.

Declaration
public Box2 Intersected(Box2 other)
Parameters
Type Name Description
Box2 other

The Box with which to intersect.

Returns
Type Description
Box2

The intersection of itself and the specified Box.

IntersectsWith(Box2)

Determines if this Box intersects with another Box.

Declaration
public bool IntersectsWith(Box2 other)
Parameters
Type Name Description
Box2 other

The Box to test.

Returns
Type Description
bool

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

Round(Box2)

Gets a Box structure that contains rounded integers.

Declaration
public static Box2i Round(Box2 value)
Parameters
Type Name Description
Box2 value

A Box to round.

Returns
Type Description
Box2i

A Box structure that contains rounded integers.

Scale(Vector2, Vector2)

Scales this Box2 by the given amount.

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

The scale to scale the box.

Vector2 anchor

The anchor to scale the box from.

Scaled(Vector2, Vector2)

Returns a Box2 scaled by a given amount from an anchor point.

Declaration
[Pure]
public readonly Box2 Scaled(Vector2 scale, Vector2 anchor)
Parameters
Type Name Description
Vector2 scale

The scale to scale the box.

Vector2 anchor

The anchor to scale the box from.

Returns
Type Description
Box2

The scaled box.

ToString()

Returns the fully qualified type name of this instance.

Declaration
public override 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 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 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 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.

TouchWith(Box2)

Determines if this Box intersects or touches with another Box.

Declaration
public bool TouchWith(Box2 other)
Parameters
Type Name Description
Box2 other

The Box to test.

Returns
Type Description
bool

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

Translate(Vector2)

Translates this Box2 by the given amount.

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

The distance to translate the box.

Translated(Vector2)

Returns a Box2 translated by the given amount.

Declaration
[Pure]
public readonly Box2 Translated(Vector2 distance)
Parameters
Type Name Description
Vector2 distance

The distance to translate the box.

Returns
Type Description
Box2

The translated box.

Union(Box2, Box2)

Gets a Box structure that contains the union of two Box structures.

Declaration
public static Box2 Union(Box2 a, Box2 b)
Parameters
Type Name Description
Box2 a

A Box to union.

Box2 b

a box to union.

Returns
Type Description
Box2

A Box structure that bounds the union of the two Box structures.

Operators

operator ==(Box2, Box2)

Equality comparator.

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

The left operand.

Box2 right

The right operand.

Returns
Type Description
bool

explicit operator RectangleF(Box2)

Converts this Box2i to a Rectangle using Min as the position and Size as the size.

Declaration
[Pure]
public static explicit operator RectangleF(Box2 box)
Parameters
Type Name Description
Box2 box

The box to cast.

Returns
Type Description
RectangleF

operator !=(Box2, Box2)

Inequality comparator.

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

The left operand.

Box2 right

The right operand.

Returns
Type Description
bool

Implements

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