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