Struct Box2d
Defines an axis-aligned 2d box (rectangle).
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Box2d : IEquatable<Box2d>, IFormattable
Constructors
Box2d(Vector2d, Vector2d)
Initializes a new instance of the Box2d struct.
Declaration
public Box2d(Vector2d min, Vector2d max)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | min | The minimum point on the XY plane this box encloses. |
Vector2d | max | The maximum point on the XY plane this box encloses. |
Box2d(double, double, double, double)
Initializes a new instance of the Box2d struct.
Declaration
public Box2d(double minX, double minY, double maxX, double maxY)
Parameters
Type | Name | Description |
---|---|---|
double | minX | The minimum X value to be enclosed. |
double | minY | The minimum Y value to be enclosed. |
double | maxX | The maximum X value to be enclosed. |
double | maxY | The maximum Y value to be enclosed. |
Fields
Empty
Gets a box with all components zero.
Declaration
public static readonly Box2d Empty
Field Value
Type | Description |
---|---|
Box2d |
UnitSquare
Gets a box with a location 0,0 with the a size of 1.
Declaration
public static readonly Box2d UnitSquare
Field Value
Type | Description |
---|---|
Box2d |
Properties
Bottom
Gets or sets the bottom location of the box.
Declaration
public double Bottom { get; set; }
Property Value
Type | Description |
---|---|
double |
Center
Gets or sets a vector describing the center of the box.
Declaration
public Vector2d Center { get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
CenteredSize
Gets or sets a vector describing the size of the Box2d structure.
Declaration
public Vector2d CenteredSize { get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
HalfSize
Gets or sets a vector describing half the size of the box.
Declaration
public Vector2d HalfSize { get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
Height
Gets or sets the height of the box.
Declaration
public double Height { get; set; }
Property Value
Type | Description |
---|---|
double |
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 double Left { get; set; }
Property Value
Type | Description |
---|---|
double |
Location
Gets the location of the box.
Declaration
public Vector2d Location { get; }
Property Value
Type | Description |
---|---|
Vector2d |
Max
Gets or sets the maximum boundary of the structure.
Declaration
public Vector2d Max { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
Min
Gets or sets the minimum boundary of the structure.
Declaration
public Vector2d Min { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
Right
Gets or sets the right location of the box.
Declaration
public double Right { get; set; }
Property Value
Type | Description |
---|---|
double |
Size
Gets or sets the size of the box.
Declaration
public Vector2d Size { get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
SizeX
Gets or sets the horizontal size.
Declaration
public double SizeX { get; set; }
Property Value
Type | Description |
---|---|
double |
SizeY
Gets or sets the vertical size.
Declaration
public double SizeY { get; set; }
Property Value
Type | Description |
---|---|
double |
Top
Gets or sets the top location of the box.
Declaration
public double Top { get; set; }
Property Value
Type | Description |
---|---|
double |
Width
Gets or sets the width of the box.
Declaration
public double Width { get; set; }
Property Value
Type | Description |
---|---|
double |
X
Gets or sets the X location of the box.
Declaration
public double X { get; set; }
Property Value
Type | Description |
---|---|
double |
Y
Gets or sets the Y location of the box.
Declaration
public double Y { get; set; }
Property Value
Type | Description |
---|---|
double |
Methods
Ceiling(Box2d)
Gets a Box structure that contains rounded up integers.
Declaration
public static Box2i Ceiling(Box2d value)
Parameters
Type | Name | Description |
---|---|---|
Box2d | value | A Box to round. |
Returns
Type | Description |
---|---|
Box2i | A Box structure that contains rounded up integers. |
Contains(Box2d)
Returns whether the box contains the specified box (borders inclusive).
Declaration
[Pure]
public readonly bool Contains(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | The box to query. |
Returns
Type | Description |
---|---|
bool | Whether this box contains the other box. |
Contains(Vector2d)
Returns whether the box contains the specified point (borders inclusive).
Declaration
[Pure]
[Obsolete("This function excludes borders even though it's documentation says otherwise. Use ContainsInclusive and ContainsExclusive for the desired behaviour.")]
public readonly bool Contains(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to query. |
Returns
Type | Description |
---|---|
bool | Whether this box contains the point. |
Contains(Vector2d, bool)
Returns whether the box contains the specified point.
Declaration
[Pure]
public bool Contains(Vector2d point, bool boundaryInclusive)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | 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(Vector2d)
Returns whether the box contains the specified point (borders exclusive).
Declaration
[Pure]
public readonly bool ContainsExclusive(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to query. |
Returns
Type | Description |
---|---|
bool | Whether this box contains the point. |
ContainsInclusive(Vector2d)
Returns whether the box contains the specified point (borders inclusive).
Declaration
[Pure]
public readonly bool ContainsInclusive(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to query. |
Returns
Type | Description |
---|---|
bool | Whether this box contains the point. |
DistanceToNearestEdge(Vector2d)
Returns the distance between the nearest edge and the specified point.
Declaration
[Pure]
public readonly double DistanceToNearestEdge(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to find distance for. |
Returns
Type | Description |
---|---|
double | The distance between the specified point and the nearest edge. |
Equals(Box2d)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
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 |
Overrides
Extend(Vector2d)
Extend this Box2d to encapsulate a given point.
Declaration
public void Extend(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to contain. |
Extended(Vector2d)
Extend this Box2d to encapsulate a given point.
Declaration
[Pure]
public readonly Box2d Extended(Vector2d point)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | point | The point to contain. |
Returns
Type | Description |
---|---|
Box2d | The inflated box. |
Floor(Box2d)
Gets a Box structure that contains rounded down integers.
Declaration
public static Box2i Floor(Box2d value)
Parameters
Type | Name | Description |
---|---|---|
Box2d | value | A Box to round. |
Returns
Type | Description |
---|---|
Box2i | A Box structure that contains rounded down integers. |
FromPositions(Vector2d, Vector2d)
Initializes a new instance of the Box2 struct.
Declaration
public static Box2d FromPositions(Vector2d min, Vector2d max)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | min | The minimum point on the XY plane this box encloses. |
Vector2d | max | The maximum point on the XY plane this box encloses. |
Returns
Type | Description |
---|---|
Box2d | A box. |
FromPositions(double, double, double, double)
Initializes a new instance of the Box2 struct.
Declaration
public static Box2d FromPositions(double minX, double minY, double maxX, double maxY)
Parameters
Type | Name | Description |
---|---|---|
double | minX | The minimum X value to be enclosed. |
double | minY | The minimum Y value to be enclosed. |
double | maxX | The maximum X value to be enclosed. |
double | maxY | The maximum Y value to be enclosed. |
Returns
Type | Description |
---|---|
Box2d | A box. |
FromSize(Vector2d, Vector2d)
Creates a box.
Declaration
public static Box2d FromSize(Vector2d location, Vector2d size)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | location | The location of the box. |
Vector2d | size | The size of the box. |
Returns
Type | Description |
---|---|
Box2d | 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
Inflate(Vector2d)
Inflates this Box2d by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize. Use the Extend(Vector2d) method for the point-encapsulation functionality in OpenTK version 4.8.1 and earlier.
Declaration
public void Inflate(Vector2d size)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | size | The size to inflate by. |
Inflated(Vector2d)
Inflates this Box2d by the given size in all directions. A negative size will shrink the box to a maximum of -HalfSize. Use the Extended(Vector2d) method for the point-encapsulation functionality in OpenTK version 4.8.1 and earlier.
Declaration
[Pure]
public readonly Box2d Inflated(Vector2d size)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | size | The size to inflate by. |
Returns
Type | Description |
---|---|
Box2d | The inflated box. |
Intersect(Box2d)
Replaces this Box with the intersection of itself and the specified Box.
Declaration
public void Intersect(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | The Box with which to intersect. |
Intersect(Box2d, Box2d)
Returns the intersection of two Boxes.
Declaration
public static Box2d Intersect(Box2d a, Box2d b)
Parameters
Type | Name | Description |
---|---|---|
Box2d | a | The first box. |
Box2d | b | The second box. |
Returns
Type | Description |
---|---|
Box2d | The intersection of two Boxes. |
Intersected(Box2d)
Returns the intersection of itself and the specified Box.
Declaration
public Box2d Intersected(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | The Box with which to intersect. |
Returns
Type | Description |
---|---|
Box2d | The intersection of itself and the specified Box. |
IntersectsWith(Box2d)
Determines if this Box intersects with another Box.
Declaration
public bool IntersectsWith(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | The Box to test. |
Returns
Type | Description |
---|---|
bool | This method returns true if there is any intersection, otherwise false. |
Round(Box2d)
Gets a Box structure that contains rounded integers.
Declaration
public static Box2i Round(Box2d value)
Parameters
Type | Name | Description |
---|---|---|
Box2d | value | A Box to round. |
Returns
Type | Description |
---|---|
Box2i | A Box structure that contains rounded integers. |
Scale(Vector2d, Vector2d)
Scales this Box2d by the given amount.
Declaration
public void Scale(Vector2d scale, Vector2d anchor)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | scale | The scale to scale the box. |
Vector2d | anchor | The anchor to scale the box from. |
Scaled(Vector2d, Vector2d)
Returns a Box2d scaled by a given amount from an anchor point.
Declaration
[Pure]
public readonly Box2d Scaled(Vector2d scale, Vector2d anchor)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | scale | The scale to scale the box. |
Vector2d | anchor | The anchor to scale the box from. |
Returns
Type | Description |
---|---|
Box2d | 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
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 ( |
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 ( |
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 ( |
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
Returns
Type | Description |
---|---|
string | The value of the current instance in the specified format. |
TouchWith(Box2d)
Determines if this Box intersects or touches with another Box.
Declaration
public bool TouchWith(Box2d other)
Parameters
Type | Name | Description |
---|---|---|
Box2d | other | The Box to test. |
Returns
Type | Description |
---|---|
bool | This method returns true if there is any intersection or touches, otherwise false. |
Translate(Vector2d)
Translates this Box2d by the given amount.
Declaration
public void Translate(Vector2d distance)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | distance | The distance to translate the box. |
Translated(Vector2d)
Returns a Box2d translated by the given amount.
Declaration
[Pure]
public readonly Box2d Translated(Vector2d distance)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | distance | The distance to translate the box. |
Returns
Type | Description |
---|---|
Box2d | The translated box. |
Union(Box2d, Box2d)
Gets a Box structure that contains the union of two Box structures.
Declaration
public static Box2d Union(Box2d a, Box2d b)
Parameters
Type | Name | Description |
---|---|---|
Box2d | a | A Box to union. |
Box2d | b | a box to union. |
Returns
Type | Description |
---|---|
Box2d | A Box structure that bounds the union of the two Box structures. |
Operators
operator ==(Box2d, Box2d)
Equality comparator.
Declaration
public static bool operator ==(Box2d left, Box2d right)
Parameters
Type | Name | Description |
---|---|---|
Box2d | left | The left operand. |
Box2d | right | The right operand. |
Returns
Type | Description |
---|---|
bool |
operator !=(Box2d, Box2d)
Inequality comparator.
Declaration
public static bool operator !=(Box2d left, Box2d right)
Parameters
Type | Name | Description |
---|---|---|
Box2d | left | The left operand. |
Box2d | right | The right operand. |
Returns
Type | Description |
---|---|
bool |