Show / Hide Table of Contents

Struct Box2i

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

Implements
IEquatable<Box2i>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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

Properties

Center

Gets a vector describing the center of the box.

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

HalfSize

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

Declaration
public Vector2i HalfSize { get; set; }
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

Size

Gets a vector describing the size of the Box2i structure.

Declaration
public Vector2i Size { get; }
Property Value
Type Description
Vector2i

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, 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.

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.

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)

Declaration
public bool Equals(Box2i other)
Parameters
Type Name Description
Box2i other
Returns
Type Description
bool

Equals(object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj
Returns
Type Description
bool
Overrides
ValueType.Equals(object)

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.

GetHashCode()

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int
Overrides
ValueType.GetHashCode()

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, 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.

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

Declaration
public override string ToString()
Returns
Type Description
string
Overrides
ValueType.ToString()

ToString(IFormatProvider)

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

ToString(string, IFormatProvider)

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

ToString(string)

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

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.

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)

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

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

Implements

IEquatable<T>
IFormattable
In This Article
Back to top Generated by DocFX