Struct int2
Represents a 2D vector using two single-precision integers.
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct int2 : IEquatable<int2>
Remarks
The int2 structure is suitable for interoperation with unmanaged code requiring two consecutive ints.
Constructors
int2(Int32)
Constructs a new int2.
Declaration
public int2(int val)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | val | This value will be set for the x and y component. |
int2(Int32, Int32)
Constructs a new int2.
Declaration
public int2(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The x coordinate of the net int2. |
| System.Int32 | y | The y coordinate of the net int2. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly int2 One
Field Value
| Type | Description |
|---|---|
| int2 |
UnitX
Defines a unit-length int2 that points towards the x-axis.
Declaration
public static readonly int2 UnitX
Field Value
| Type | Description |
|---|---|
| int2 |
UnitY
Defines a unit-length int2 that points towards the y-axis.
Declaration
public static readonly int2 UnitY
Field Value
| Type | Description |
|---|---|
| int2 |
x
The x component of the int2.
Declaration
public int x
Field Value
| Type | Description |
|---|---|
| System.Int32 |
y
The y component of the int2.
Declaration
public int y
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Zero
Defines a zero-length int2.
Declaration
public static readonly int2 Zero
Field Value
| Type | Description |
|---|---|
| int2 |
Properties
g
The green component (same as y)
Declaration
public int g { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Item[Int32]
Gets or sets the individual components x and y, depending on their index.
Declaration
public int this[int idx] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | idx | The index (between 0 and 1). |
Property Value
| Type | Description |
|---|---|
| System.Int32 | The x or y component of the int2. |
Length
Gets the length (magnitude) of the vector.
Declaration
public readonly float Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Single | The length. |
LengthSquared
Gets the square of the vector length (magnitude).
Declaration
public readonly int LengthSquared { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The length squared. |
Remarks
This property avoids the costly square root operation required by the Length property. This makes it more suitable for comparisons.
ParseConverter
Gets and sets the Converter object. Has the ability to convert a string to a int2.
Declaration
public static Converter<string, int2> ParseConverter { get; set; }
Property Value
| Type | Description |
|---|---|
| Converter<System.String, int2> | The parse property. |
PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
Declaration
public readonly int2 PerpendicularLeft { get; }
Property Value
| Type | Description |
|---|---|
| int2 | The perpendicular left. |
PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Declaration
public readonly int2 PerpendicularRight { get; }
Property Value
| Type | Description |
|---|---|
| int2 | The perpendicular right. |
r
The red component (same as x)
Declaration
public int r { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
rg
The rg component (same as xy)
Declaration
public int2 rg { get; set; }
Property Value
| Type | Description |
|---|---|
| int2 |
xy
Gets and sets an OpenTK.int2 with the x and y components of this instance.
Declaration
public int2 xy { get; set; }
Property Value
| Type | Description |
|---|---|
| int2 |
yx
Gets or sets an OpenTK.int2 with the y and x components of this instance.
Declaration
public int2 yx { get; set; }
Property Value
| Type | Description |
|---|---|
| int2 |
Methods
Add(int2, int2)
Adds two vectors.
Declaration
public static int2 Add(int2 a, int2 b)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | Left operand. |
| int2 | b | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of operation. |
Clamp(int2, int2, int2)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static int2 Clamp(int2 vec, int2 min, int2 max)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | Input vector |
| int2 | min | Minimum vector |
| int2 | max | Maximum vector |
Returns
| Type | Description |
|---|---|
| int2 | The clamped vector |
ComponentMax(int2, int2)
Calculate the component-wise maximum of two vectors
Declaration
public static int2 ComponentMax(int2 a, int2 b)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | First operand |
| int2 | b | Second operand |
Returns
| Type | Description |
|---|---|
| int2 | The component-wise maximum |
ComponentMin(int2, int2)
Calculate the component-wise minimum of two vectors
Declaration
public static int2 ComponentMin(int2 a, int2 b)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | First operand |
| int2 | b | Second operand |
Returns
| Type | Description |
|---|---|
| int2 | The component-wise minimum |
Divide(int2, int2)
Divides a vector by the components of a vector (scale).
Declaration
public static int2 Divide(int2 vector, int2 scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vector | Left operand. |
| int2 | scale | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of the operation. |
Divide(int2, Int32)
Divides a vector by a scalar.
Declaration
public static int2 Divide(int2 vector, int scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vector | Left operand. |
| System.Int32 | scale | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of the operation. |
Dot(int2, int2)
Calculate the dot (scalar) product of two vectors
Declaration
public static int Dot(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | First operand |
| int2 | right | Second operand |
Returns
| Type | Description |
|---|---|
| System.Int32 | The dot product of the two inputs |
Equals(int2)
Indicates whether the current vector is equal to another vector.
Declaration
public bool Equals(int2 other)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | other | A vector to compare with this vector. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the current vector is equal to the vector parameter; otherwise, false. |
Equals(Object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The object to compare to. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the instances are equal; false otherwise. |
Overrides
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A System.Int32 containing the unique hash code for this instance. |
Overrides
Lerp(int2, int2, float2)
Returns a new Vector that is the linear blend of the 2 given Vectors. Each component of vector a is blended with its equivalent in vector b.
Declaration
public static float2 Lerp(int2 a, int2 b, float2 blend)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | First input vector |
| int2 | b | Second input vector |
| float2 | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
| Type | Description |
|---|---|
| float2 |
Lerp(int2, int2, Single)
Returns a new Vector that is the linear blend of the 2 given Vectors. Each component of vector a is blended with its equivalent in vector b.
Declaration
public static float2 Lerp(int2 a, int2 b, float blend)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | First input vector |
| int2 | b | Second input vector |
| System.Single | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
| Type | Description |
|---|---|
| float2 |
Max(int2, int2)
Returns the int3 with the minimum magnitude
Declaration
public static int2 Max(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand |
| int2 | right | Right operand |
Returns
| Type | Description |
|---|---|
| int2 | The minimum int3 |
Min(int2, int2)
Returns the int3 with the minimum magnitude
Declaration
public static int2 Min(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand |
| int2 | right | Right operand |
Returns
| Type | Description |
|---|---|
| int2 | The minimum int3 |
Multiply(int2, int2)
Multiplies a vector by the components a vector (scale).
Declaration
public static int2 Multiply(int2 vector, int2 scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vector | Left operand. |
| int2 | scale | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of the operation. |
Multiply(int2, Int32)
Multiplies a vector by a scalar.
Declaration
public static int2 Multiply(int2 vector, int scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vector | Left operand. |
| System.Int32 | scale | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of the operation. |
Normalize()
Scales the int2 to unit length.
Declaration
public float2 Normalize()
Returns
| Type | Description |
|---|---|
| float2 |
Normalize(int2)
Scale a vector to unit length
Declaration
public static float2 Normalize(int2 vec)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | The input vector |
Returns
| Type | Description |
|---|---|
| float2 | The normalized vector |
NormalizeFast()
Scales the int2 to approximately unit length.
Declaration
public float2 NormalizeFast()
Returns
| Type | Description |
|---|---|
| float2 |
NormalizeFast(int2)
Scale a vector to approximately unit length
Declaration
public static float2 NormalizeFast(int2 vec)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | The input vector |
Returns
| Type | Description |
|---|---|
| float2 | The normalized vector |
Parse(String, IFormatProvider)
Parses a string into a int2.
Declaration
public static int2 Parse(string source, IFormatProvider provider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | source | |
| System.IFormatProvider | provider |
Returns
| Type | Description |
|---|---|
| int2 |
Pow(int2, Int32)
Returns a int2 where all components are raised to the specified power.
Declaration
public static int2 Pow(int2 val, int exp)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | val | The int3 to be raised to a power. |
| System.Int32 | exp | A int that specifies a power. |
Returns
| Type | Description |
|---|---|
| int2 |
Step(int2, int2)
Performs Step(Single, Single) for each component of the input vectors.
Declaration
public static int2 Step(int2 edge, int2 val)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | edge | Specifies the location of the edge of the step function. |
| int2 | val | Specifies the value to be used to generate the step function. |
Returns
| Type | Description |
|---|---|
| int2 |
Subtract(int2, int2)
Subtract one Vector from another
Declaration
public static int2 Subtract(int2 a, int2 b)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | a | First operand |
| int2 | b | Second operand |
Returns
| Type | Description |
|---|---|
| int2 | Result of subtraction |
ToArray()
Returns an array of ints with the two components of the vector.
Declaration
public int[] ToArray()
Returns
| Type | Description |
|---|---|
| System.Int32[] | Returns an array of ints with the two components of the vector. |
ToString()
Returns a System.String that represents the current int2.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A System.String that represents this instance. |
Overrides
ToString(IFormatProvider)
Returns a System.String that represents the current int2.
Declaration
public string ToString(IFormatProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IFormatProvider | provider | Provides information about a specific culture. |
Returns
| Type | Description |
|---|---|
| System.String | A System.String that represents this instance. |
Operators
Addition(int2, int2)
Adds the specified instances.
Declaration
public static int2 operator +(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| int2 | right | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of addition. |
Addition(int2, Int32)
Adds a scalar to the specified instance.
Declaration
public static int2 operator +(int2 left, int scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| System.Int32 | scalar | The scalar. |
Returns
| Type | Description |
|---|---|
| int2 | Result of addition. |
Division(int2, Int32)
Divides the specified instance by a scalar.
Declaration
public static int2 operator /(int2 vec, int scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | Left operand |
| System.Int32 | scale | Right operand |
Returns
| Type | Description |
|---|---|
| int2 | Result of the division. |
Equality(int2, int2)
Compares the specified instances for equality.
Declaration
public static bool operator ==(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| int2 | right | Right operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if both instances are equal; false otherwise. |
Inequality(int2, int2)
Compares the specified instances for inequality.
Declaration
public static bool operator !=(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| int2 | right | Right operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if both instances are not equal; false otherwise. |
Multiply(int2, int2)
Multiplies two instances.
Declaration
public static int2 operator *(int2 vec1, int2 vec2)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec1 | Left operand. |
| int2 | vec2 | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of multiplication. |
Multiply(int2, Int32)
Multiplies the specified instance by a scalar.
Declaration
public static int2 operator *(int2 vec, int scale)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | Left operand. |
| System.Int32 | scale | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of multiplication. |
Multiply(Int32, int2)
Multiplies the specified instance by a scalar.
Declaration
public static int2 operator *(int scale, int2 vec)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | scale | Left operand. |
| int2 | vec | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of multiplication. |
Subtraction(int2, int2)
Subtracts the specified instances.
Declaration
public static int2 operator -(int2 left, int2 right)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| int2 | right | Right operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of subtraction. |
Subtraction(int2, Int32)
Subtracts a scalar from the specified instance.
Declaration
public static int2 operator -(int2 left, int scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | left | Left operand. |
| System.Int32 | scalar | The scalar. |
Returns
| Type | Description |
|---|---|
| int2 | Result of addition. |
UnaryNegation(int2)
Negates the specified instance.
Declaration
public static int2 operator -(int2 vec)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | vec | Operand. |
Returns
| Type | Description |
|---|---|
| int2 | Result of negation. |