Show / Hide Table of Contents

Struct Box2d

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

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

Properties

Center

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

Declaration
public Vector2d Center { 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

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

Size

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

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

Methods

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

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.

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)

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

GetHashCode()

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

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.

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

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

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

Implements

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