Struct Int2
- Namespace
- Stride.Core.Mathematics
- Assembly
- Stride.Core.Mathematics.dll
Represents a two dimensional mathematical vector.
[DataContract("Int2")]
[DataStyle(DataStyle.Compact)]
public struct Int2 : IEquatable<Int2>, ISpanFormattable, IFormattable- Implements
Constructors
Int2(Vector2)
Initializes a new instance of the Int2 struct.
public Int2(Vector2 value)Parameters
- valueVector2
- A vector containing the values with which to initialize the X and Y components. 
Int2(int)
Initializes a new instance of the Int2 struct.
public Int2(int value)Parameters
- valueint
- The value that will be assigned to all components. 
Int2(int, int)
Initializes a new instance of the Int2 struct.
public Int2(int x, int y)Parameters
- xint
- Initial value for the X component of the vector. 
- yint
- Initial value for the Y component of the vector. 
Int2(int[])
Initializes a new instance of the Int2 struct.
public Int2(int[] values)Parameters
- valuesint[]
- The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements. 
Exceptions
- ArgumentNullException
- Thrown when - valuesis- null.
- ArgumentOutOfRangeException
- Thrown when - valuescontains more or less than three elements.
Fields
One
A Int2 with all of its components set to one.
public static readonly Int2 OneField Value
SizeInBytes
The size of the Int2 type, in bytes.
public static readonly int SizeInBytesField Value
UnitX
The X unit Int2 (1, 0, 0).
public static readonly Int2 UnitXField Value
UnitY
The Y unit Int2 (0, 1, 0).
public static readonly Int2 UnitYField Value
X
The X component of the vector.
[DataMember(0)]
public int XField Value
Y
The Y component of the vector.
[DataMember(1)]
public int YField Value
Zero
A Int2 with all of its components set to zero.
public static readonly Int2 ZeroField Value
Properties
this[int]
Gets or sets the component at the specified index.
public int this[int index] { readonly get; set; }Parameters
- indexint
- The index of the component to access. Use 0 for the X component and 1 for the Y component. 
Property Value
- int
- The value of the X or Y component, depending on the index. 
Exceptions
- ArgumentOutOfRangeException
- Thrown when the - indexis out of the range [0, 1].
Methods
Add(Int2, Int2)
Adds two vectors.
public static Int2 Add(Int2 left, Int2 right)Parameters
Returns
- Int2
- The sum of the two vectors. 
Add(ref readonly Int2, ref readonly Int2, out Int2)
Adds two vectors.
public static void Add(ref readonly Int2 left, ref readonly Int2 right, out Int2 result)Parameters
- leftInt2
- The first vector to add. 
- rightInt2
- The second vector to add. 
- resultInt2
- When the method completes, contains the sum of the two vectors. 
Clamp(Int2, Int2, Int2)
Restricts a value to be within a specified range.
public static Int2 Clamp(Int2 value, Int2 min, Int2 max)Parameters
Returns
- Int2
- The clamped value. 
Clamp(ref readonly Int2, ref readonly Int2, ref readonly Int2, out Int2)
Restricts a value to be within a specified range.
public static void Clamp(ref readonly Int2 value, ref readonly Int2 min, ref readonly Int2 max, out Int2 result)Parameters
- valueInt2
- The value to clamp. 
- minInt2
- The minimum value. 
- maxInt2
- The maximum value. 
- resultInt2
- When the method completes, contains the clamped value. 
Deconstruct(out int, out int)
Deconstructs the vector's components into named variables.
public readonly void Deconstruct(out int x, out int y)Parameters
Divide(Int2, int)
Scales a vector by the given value.
public static Int2 Divide(Int2 value, int scale)Parameters
Returns
- Int2
- The scaled vector. 
Divide(ref readonly Int2, int, out Int2)
Scales a vector by the given value.
public static void Divide(ref readonly Int2 value, int scale, out Int2 result)Parameters
- valueInt2
- The vector to scale. 
- scaleint
- The amount by which to scale the vector. 
- resultInt2
- When the method completes, contains the scaled vector. 
Dot(Int2, Int2)
Calculates the dot product of two vectors.
public static int Dot(Int2 left, Int2 right)Parameters
Returns
- int
- The dot product of the two vectors. 
Dot(ref readonly Int2, ref readonly Int2, out int)
Calculates the dot product of two vectors.
public static void Dot(ref readonly Int2 left, ref readonly Int2 right, out int result)Parameters
- leftInt2
- First source vector. 
- rightInt2
- Second source vector. 
- resultint
- When the method completes, contains the dot product of the two vectors. 
Equals(Int2)
Determines whether the specified Int2 is equal to this instance.
public readonly bool Equals(Int2 other)Parameters
Returns
Equals(object?)
Determines whether the specified object is equal to this instance.
public override readonly bool Equals(object? value)Parameters
- valueobject
- The object to compare with this instance. 
Returns
- bool
- trueif the specified object is equal to this instance; otherwise,- false.
GetHashCode()
Returns a hash code for this instance.
public override readonly int GetHashCode()Returns
- int
- A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
Length()
Calculates the length of the vector.
public readonly int Length()Returns
- int
- The length of the vector. 
Remarks
LengthSquared() may be preferred when only the relative length is needed and speed is of the essence.
LengthSquared()
Calculates the squared length of the vector.
public readonly int LengthSquared()Returns
- int
- The squared length of the vector. 
Remarks
This method may be preferred to Length() when only a relative length is needed and speed is of the essence.
Lerp(Int2, Int2, float)
Performs a linear interpolation between two vectors.
public static Int2 Lerp(Int2 start, Int2 end, float amount)Parameters
- startInt2
- Start vector. 
- endInt2
- End vector. 
- amountfloat
- Value between 0 and 1 indicating the weight of - end.
Returns
- Int2
- The linear interpolation of the two vectors. 
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.
Lerp(ref readonly Int2, ref readonly Int2, float, out Int2)
Performs a linear interpolation between two vectors.
public static void Lerp(ref readonly Int2 start, ref readonly Int2 end, float amount, out Int2 result)Parameters
- startInt2
- Start vector. 
- endInt2
- End vector. 
- amountfloat
- Value between 0 and 1 indicating the weight of - end.
- resultInt2
- When the method completes, contains the linear interpolation of the two vectors. 
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.
Max(Int2, Int2)
Returns a vector containing the largest components of the specified vectors.
public static Int2 Max(Int2 left, Int2 right)Parameters
Returns
- Int2
- A vector containing the largest components of the source vectors. 
Max(ref readonly Int2, ref readonly Int2, out Int2)
Returns a vector containing the smallest components of the specified vectors.
public static void Max(ref readonly Int2 left, ref readonly Int2 right, out Int2 result)Parameters
- leftInt2
- The first source vector. 
- rightInt2
- The second source vector. 
- resultInt2
- When the method completes, contains an new vector composed of the largest components of the source vectors. 
Min(Int2, Int2)
Returns a vector containing the smallest components of the specified vectors.
public static Int2 Min(Int2 left, Int2 right)Parameters
Returns
- Int2
- A vector containing the smallest components of the source vectors. 
Min(ref readonly Int2, ref readonly Int2, out Int2)
Returns a vector containing the smallest components of the specified vectors.
public static void Min(ref readonly Int2 left, ref readonly Int2 right, out Int2 result)Parameters
- leftInt2
- The first source vector. 
- rightInt2
- The second source vector. 
- resultInt2
- When the method completes, contains an new vector composed of the smallest components of the source vectors. 
Modulate(Int2, Int2)
Modulates a vector with another by performing component-wise multiplication.
public static Int2 Modulate(Int2 left, Int2 right)Parameters
Returns
- Int2
- The modulated vector. 
Modulate(ref readonly Int2, ref readonly Int2, out Int2)
Modulates a vector with another by performing component-wise multiplication.
public static void Modulate(ref readonly Int2 left, ref readonly Int2 right, out Int2 result)Parameters
- leftInt2
- The first vector to modulate. 
- rightInt2
- The second vector to modulate. 
- resultInt2
- When the method completes, contains the modulated vector. 
Multiply(Int2, int)
Scales a vector by the given value.
public static Int2 Multiply(Int2 value, int scale)Parameters
Returns
- Int2
- The scaled vector. 
Multiply(ref readonly Int2, int, out Int2)
Scales a vector by the given value.
public static void Multiply(ref readonly Int2 value, int scale, out Int2 result)Parameters
- valueInt2
- The vector to scale. 
- scaleint
- The amount by which to scale the vector. 
- resultInt2
- When the method completes, contains the scaled vector. 
Negate(Int2)
Reverses the direction of a given vector.
public static Int2 Negate(Int2 value)Parameters
- valueInt2
- The vector to negate. 
Returns
- Int2
- A vector facing in the opposite direction. 
Negate(ref readonly Int2, out Int2)
Reverses the direction of a given vector.
public static void Negate(ref readonly Int2 value, out Int2 result)Parameters
- valueInt2
- The vector to negate. 
- resultInt2
- When the method completes, contains a vector facing in the opposite direction. 
Pow(int)
Raises the exponent for each components.
public void Pow(int exponent)Parameters
- exponentint
- The exponent. 
SmoothStep(Int2, Int2, float)
Performs a cubic interpolation between two vectors.
public static Int2 SmoothStep(Int2 start, Int2 end, float amount)Parameters
- startInt2
- Start vector. 
- endInt2
- End vector. 
- amountfloat
- Value between 0 and 1 indicating the weight of - end.
Returns
- Int2
- The cubic interpolation of the two vectors. 
SmoothStep(ref readonly Int2, ref readonly Int2, float, out Int2)
Performs a cubic interpolation between two vectors.
public static void SmoothStep(ref readonly Int2 start, ref readonly Int2 end, float amount, out Int2 result)Parameters
- startInt2
- Start vector. 
- endInt2
- End vector. 
- amountfloat
- Value between 0 and 1 indicating the weight of - end.
- resultInt2
- When the method completes, contains the cubic interpolation of the two vectors. 
Subtract(Int2, Int2)
Subtracts two vectors.
public static Int2 Subtract(Int2 left, Int2 right)Parameters
Returns
- Int2
- The difference of the two vectors. 
Subtract(ref readonly Int2, ref readonly Int2, out Int2)
Subtracts two vectors.
public static void Subtract(ref readonly Int2 left, ref readonly Int2 right, out Int2 result)Parameters
- leftInt2
- The first vector to subtract. 
- rightInt2
- The second vector to subtract. 
- resultInt2
- When the method completes, contains the difference of the two vectors. 
ToArray()
Creates an array containing the elements of the vector.
public readonly int[] ToArray()Returns
- int[]
- A two-element array containing the components of the vector. 
ToString()
Returns a string that represents this instance.
public override readonly string ToString()Returns
ToString(string?, IFormatProvider?)
Returns a string that represents this instance.
public readonly string ToString(string? format, IFormatProvider? formatProvider)Parameters
- formatstring
- The format. 
- formatProviderIFormatProvider
- The format provider. 
Returns
Operators
operator +(Int2, Int2)
Adds two vectors.
public static Int2 operator +(Int2 left, Int2 right)Parameters
Returns
- Int2
- The sum of the two vectors. 
operator /(Int2, float)
Scales a vector by the given value.
public static Int2 operator /(Int2 value, float scale)Parameters
Returns
- Int2
- The scaled vector. 
operator ==(Int2, Int2)
Tests for equality between two objects.
public static bool operator ==(Int2 left, Int2 right)Parameters
Returns
- bool
- trueif- lefthas the same value as- right; otherwise,- false.
explicit operator Vector2(Int2)
public static explicit operator Vector2(Int2 value)Parameters
- valueInt2
- The value. 
Returns
- Vector2
- The result of the conversion. 
explicit operator Vector4(Int2)
public static explicit operator Vector4(Int2 value)Parameters
- valueInt2
- The value. 
Returns
- Vector4
- The result of the conversion. 
explicit operator Vector2(Int2)
Casts from Stride.Maths to System.Numerics vectors
public static explicit operator Vector2(Int2 v)Parameters
- vInt2
- Value to cast 
Returns
explicit operator Int2(Vector2)
Casts from System.Numerics to Stride.Maths vectors
public static explicit operator Int2(Vector2 v)Parameters
- vVector2
- Value to cast 
Returns
operator !=(Int2, Int2)
Tests for inequality between two objects.
public static bool operator !=(Int2 left, Int2 right)Parameters
Returns
- bool
- trueif- lefthas a different value than- right; otherwise,- false.
operator *(Int2, float)
Scales a vector by the given value.
public static Int2 operator *(Int2 value, float scale)Parameters
Returns
- Int2
- The scaled vector. 
operator *(float, Int2)
Scales a vector by the given value.
public static Int2 operator *(float scale, Int2 value)Parameters
Returns
- Int2
- The scaled vector. 
operator -(Int2, Int2)
Subtracts two vectors.
public static Int2 operator -(Int2 left, Int2 right)Parameters
Returns
- Int2
- The difference of the two vectors. 
operator -(Int2)
Reverses the direction of a given vector.
public static Int2 operator -(Int2 value)Parameters
- valueInt2
- The vector to negate. 
Returns
- Int2
- A vector facing in the opposite direction. 
operator +(Int2)
Assert a vector (return it unchanged).
public static Int2 operator +(Int2 value)Parameters
- valueInt2
- The vector to assert (unchange). 
Returns
- Int2
- The asserted (unchanged) vector.