Struct Vector2i
Represents a 2D vector using two 32-bit integer numbers.
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Vector2i : IEquatable<Vector2i>, IFormattable
Remarks
The Vector2i structure is suitable for interoperation with unmanaged code requiring two consecutive integers.
Constructors
Vector2i(int)
Initializes a new instance of the Vector2i struct.
Declaration
public Vector2i(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value that will initialize this instance. |
Vector2i(int, int)
Initializes a new instance of the Vector2i struct.
Declaration
public Vector2i(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
int | x | The x component of the Vector2i. |
int | y | The y component of the Vector2i. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly Vector2i One
Field Value
Type | Description |
---|---|
Vector2i |
SizeInBytes
Defines the size of the Vector2i struct in bytes.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
int |
UnitX
Defines a unit-length Vector2i that points towards the X-axis.
Declaration
public static readonly Vector2i UnitX
Field Value
Type | Description |
---|---|
Vector2i |
UnitY
Defines a unit-length Vector2i that points towards the Y-axis.
Declaration
public static readonly Vector2i UnitY
Field Value
Type | Description |
---|---|
Vector2i |
X
The X component of the Vector2i.
Declaration
public int X
Field Value
Type | Description |
---|---|
int |
Y
The Y component of the Vector2i.
Declaration
public int Y
Field Value
Type | Description |
---|---|
int |
Zero
Defines an instance with all components set to 0.
Declaration
public static readonly Vector2i Zero
Field Value
Type | Description |
---|---|
Vector2i |
Properties
EuclideanLength
Gets the euclidean length of the vector.
Declaration
public readonly float EuclideanLength { get; }
Property Value
Type | Description |
---|---|
float |
EuclideanLengthSquared
Gets the squared euclidean length of the vector.
Declaration
public readonly int EuclideanLengthSquared { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Gets or sets the value at the index of the vector.
Declaration
public int this[int index] { readonly get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the component from the vector. |
Property Value
Type | Description |
---|---|
int |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | Thrown if the index is less than 0 or greater than 1. |
ManhattanLength
Gets the manhattan length of the vector.
Declaration
public readonly int ManhattanLength { get; }
Property Value
Type | Description |
---|---|
int |
PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
Declaration
public readonly Vector2i PerpendicularLeft { get; }
Property Value
Type | Description |
---|---|
Vector2i |
PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Declaration
public readonly Vector2i PerpendicularRight { get; }
Property Value
Type | Description |
---|---|
Vector2i |
Yx
Gets or sets a Vector2i with the Y and X components of this instance.
Declaration
public Vector2i Yx { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2i |
Methods
Abs()
Returns a new vector that is the component-wise absolute value of the vector.
Declaration
public readonly Vector2i Abs()
Returns
Type | Description |
---|---|
Vector2i | The component-wise absolute value vector. |
Abs(Vector2i)
Take the component-wise absolute value of a vector.
Declaration
public static Vector2i Abs(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The vector to apply component-wise absolute value to. |
Returns
Type | Description |
---|---|
Vector2i | The component-wise absolute value vector. |
Abs(in Vector2i, out Vector2i)
Take the component-wise absolute value of a vector.
Declaration
public static void Abs(in Vector2i vec, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The vector to apply component-wise absolute value to. |
Vector2i | result | The component-wise absolute value vector. |
Add(Vector2i, Vector2i)
Adds two vectors.
Declaration
[Pure]
public static Vector2i Add(Vector2i a, Vector2i b)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | Left operand. |
Vector2i | b | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of operation. |
Add(in Vector2i, in Vector2i, out Vector2i)
Adds two vectors.
Declaration
public static void Add(in Vector2i a, in Vector2i b, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | Left operand. |
Vector2i | b | Right operand. |
Vector2i | result | Result of operation. |
Clamp(Vector2i, Vector2i, Vector2i)
Clamp a vector to the given minimum and maximum vectors.
Declaration
[Pure]
public static Vector2i Clamp(Vector2i vec, Vector2i min, Vector2i max)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Input vector. |
Vector2i | min | Minimum vector. |
Vector2i | max | Maximum vector. |
Returns
Type | Description |
---|---|
Vector2i | The clamped vector. |
Clamp(in Vector2i, in Vector2i, in Vector2i, out Vector2i)
Clamp a vector to the given minimum and maximum vectors.
Declaration
public static void Clamp(in Vector2i vec, in Vector2i min, in Vector2i max, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Input vector. |
Vector2i | min | Minimum vector. |
Vector2i | max | Maximum vector. |
Vector2i | result | The clamped vector. |
ComponentMax(Vector2i, Vector2i)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
[Pure]
public static Vector2i ComponentMax(Vector2i a, Vector2i b)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Returns
Type | Description |
---|---|
Vector2i | The component-wise maximum. |
ComponentMax(in Vector2i, in Vector2i, out Vector2i)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
public static void ComponentMax(in Vector2i a, in Vector2i b, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Vector2i | result | The component-wise maximum. |
ComponentMin(Vector2i, Vector2i)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
[Pure]
public static Vector2i ComponentMin(Vector2i a, Vector2i b)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Returns
Type | Description |
---|---|
Vector2i | The component-wise minimum. |
ComponentMin(in Vector2i, in Vector2i, out Vector2i)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
public static void ComponentMin(in Vector2i a, in Vector2i b, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Vector2i | result | The component-wise minimum. |
Deconstruct(out int, out int)
Deconstructs the vector into it's individual components.
Declaration
[Pure]
public readonly void Deconstruct(out int x, out int y)
Parameters
Type | Name | Description |
---|---|---|
int | x | The X component of the vector. |
int | y | The Y component of the vector. |
Divide(Vector2i, Vector2i)
Divides a vector by the components of a vector using integer division, floor(a/b).
Declaration
[Pure]
public static Vector2i Divide(Vector2i vector, Vector2i scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
Vector2i | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the operation. |
Divide(Vector2i, int)
Divides a vector by a scalar using integer division, floor(a/b).
Declaration
[Pure]
public static Vector2i Divide(Vector2i vector, int scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
int | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the operation. |
Divide(in Vector2i, in Vector2i, out Vector2i)
Divides a vector by the components of a vector using integer division, floor(a/b).
Declaration
public static void Divide(in Vector2i vector, in Vector2i scale, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
Vector2i | scale | Right operand. |
Vector2i | result | Result of the operation. |
Divide(in Vector2i, int, out Vector2i)
Divides a vector by a scalar using integer division, floor(a/b).
Declaration
public static void Divide(in Vector2i vector, int scale, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
int | scale | Right operand. |
Vector2i | result | Result of the operation. |
Equals(Vector2i)
Indicates whether the current object is equal to another object of the same type.
Declaration
public readonly bool Equals(Vector2i other)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | 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
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
Multiply(Vector2i, Vector2i)
Multiplies a vector by the components a vector (scale).
Declaration
[Pure]
public static Vector2i Multiply(Vector2i vector, Vector2i scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
Vector2i | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the operation. |
Multiply(Vector2i, int)
Multiplies a vector by an integer scalar.
Declaration
[Pure]
public static Vector2i Multiply(Vector2i vector, int scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
int | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the operation. |
Multiply(in Vector2i, in Vector2i, out Vector2i)
Multiplies a vector by the components of a vector (scale).
Declaration
public static void Multiply(in Vector2i vector, in Vector2i scale, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
Vector2i | scale | Right operand. |
Vector2i | result | Result of the operation. |
Multiply(in Vector2i, int, out Vector2i)
Multiplies a vector by an integer scalar.
Declaration
public static void Multiply(in Vector2i vector, int scale, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vector | Left operand. |
int | scale | Right operand. |
Vector2i | result | Result of the operation. |
Subtract(Vector2i, Vector2i)
Subtract one Vector from another.
Declaration
[Pure]
public static Vector2i Subtract(Vector2i a, Vector2i b)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of subtraction. |
Subtract(in Vector2i, in Vector2i, out Vector2i)
Subtract one Vector from another.
Declaration
public static void Subtract(in Vector2i a, in Vector2i b, out Vector2i result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | a | First operand. |
Vector2i | b | Second operand. |
Vector2i | result | Result of subtraction. |
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 readonly 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. |
ToVector2()
Declaration
public readonly Vector2 ToVector2()
Returns
Type | Description |
---|---|
Vector2 | The resulting Vector3 instance. |
ToVector2(in Vector2i, out Vector2)
Declaration
public static void ToVector2(in Vector2i input, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | input | The given Vector2i to convert. |
Vector2 | result | The resulting Vector2. |
Operators
operator +(Vector2i, Vector2i)
Adds the specified instances.
Declaration
[Pure]
public static Vector2i operator +(Vector2i left, Vector2i right)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | left | Left operand. |
Vector2i | right | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of addition. |
operator /(Vector2i, Vector2i)
Component-wise division between the specified instance by a scale vector.
Declaration
[Pure]
public static Vector2i operator /(Vector2i vec, Vector2i scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Left operand. |
Vector2i | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the division. |
operator /(Vector2i, int)
Divides the instance by a scalar using integer division, floor(a/b).
Declaration
[Pure]
public static Vector2i operator /(Vector2i vec, int scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Left operand. |
int | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of the division. |
operator ==(Vector2i, Vector2i)
Compares the specified instances for equality.
Declaration
public static bool operator ==(Vector2i left, Vector2i right)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | left | Left operand. |
Vector2i | right | Right operand. |
Returns
Type | Description |
---|---|
bool | True if both instances are equal; false otherwise. |
explicit operator Vector2h(Vector2i)
Converts OpenTK.Vector2i to OpenTK.Vector2h.
Declaration
[Pure]
public static explicit operator Vector2h(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The Vector2i to convert. |
Returns
Type | Description |
---|---|
Vector2h | The resulting Vector2h. |
explicit operator Point(Vector2i)
Declaration
[Pure]
public static explicit operator Point(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The Vector2i to cast. |
Returns
Type | Description |
---|---|
Point | The resulting Point. |
explicit operator Size(Vector2i)
Declaration
[Pure]
public static explicit operator Size(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The Vector2i to cast. |
Returns
Type | Description |
---|---|
Size | The resulting Size. |
implicit operator Vector2(Vector2i)
Converts OpenTK.Vector2i to OpenTK.Vector2.
Declaration
[Pure]
public static implicit operator Vector2(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The Vector2i to convert. |
Returns
Type | Description |
---|---|
Vector2 | The resulting Vector2. |
implicit operator Vector2d(Vector2i)
Converts OpenTK.Vector2i to OpenTK.Vector2d.
Declaration
[Pure]
public static implicit operator Vector2d(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | The Vector2i to convert. |
Returns
Type | Description |
---|---|
Vector2d | The resulting Vector2d. |
implicit operator Vector2i((int X, int Y))
Initializes a new instance of the Vector2i struct using a tuple containing the component values.
Declaration
[Pure]
public static implicit operator Vector2i((int X, int Y) values)
Parameters
Type | Name | Description |
---|---|---|
(int X, int Y) | values | A tuple containing the component values. |
Returns
Type | Description |
---|---|
Vector2i | A new instance of the Vector2i struct with the given component values. |
operator !=(Vector2i, Vector2i)
Compares the specified instances for inequality.
Declaration
public static bool operator !=(Vector2i left, Vector2i right)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | left | Left operand. |
Vector2i | right | Right operand. |
Returns
Type | Description |
---|---|
bool | True if both instances are not equal; false otherwise. |
operator *(Vector2i, Vector2i)
Component-wise multiplication between the specified instance by a scale vector.
Declaration
[Pure]
public static Vector2i operator *(Vector2i vec, Vector2i scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Right operand. |
Vector2i | scale | Left operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of multiplication. |
operator *(Vector2i, int)
Multiplies the specified instance by a scalar.
Declaration
[Pure]
public static Vector2i operator *(Vector2i vec, int scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Left operand. |
int | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of multiplication. |
operator *(int, Vector2i)
Multiplies the specified instance by a scalar.
Declaration
[Pure]
public static Vector2i operator *(int scale, Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
int | scale | Left operand. |
Vector2i | vec | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of multiplication. |
operator -(Vector2i, Vector2i)
Subtracts the specified instances.
Declaration
[Pure]
public static Vector2i operator -(Vector2i left, Vector2i right)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | left | Left operand. |
Vector2i | right | Right operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of subtraction. |
operator -(Vector2i)
Negates the specified instance.
Declaration
[Pure]
public static Vector2i operator -(Vector2i vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2i | vec | Operand. |
Returns
Type | Description |
---|---|
Vector2i | Result of negation. |