Struct float2
Represents a 2D vector using two single-precision floating-point numbers.
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct float2 : IEquatable<float2>
Remarks
The float2 structure is suitable for interoperation with unmanaged code requiring two consecutive floats.
Constructors
float2(Single)
Constructs a new float2.
Declaration
public float2(float val)
Parameters
Type | Name | Description |
---|---|---|
System.Single | val | This value will be set for the x and y component. |
float2(Single, Single)
Constructs a new float2.
Declaration
public float2(float x, float y)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The x coordinate of the net float2. |
System.Single | y | The y coordinate of the net float2. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly float2 One
Field Value
Type | Description |
---|---|
float2 |
UnitX
Defines a unit-length float2 that points towards the x-axis.
Declaration
public static readonly float2 UnitX
Field Value
Type | Description |
---|---|
float2 |
UnitY
Defines a unit-length float2 that points towards the y-axis.
Declaration
public static readonly float2 UnitY
Field Value
Type | Description |
---|---|
float2 |
x
The x component of the float2.
Declaration
public float x
Field Value
Type | Description |
---|---|
System.Single |
y
The y component of the float2.
Declaration
public float y
Field Value
Type | Description |
---|---|
System.Single |
Zero
Defines a zero-length float2.
Declaration
public static readonly float2 Zero
Field Value
Type | Description |
---|---|
float2 |
Properties
g
The green component (same as y)
Declaration
public float g { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
Item[Int32]
Gets or sets the individual components x and y, depending on their index.
Declaration
public float this[int idx] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | idx | The index (between 0 and 1). |
Property Value
Type | Description |
---|---|
System.Single | The x or y component of the float2. |
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 float LengthSquared { get; }
Property Value
Type | Description |
---|---|
System.Single | 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 float2.
Declaration
public static Converter<string, float2> ParseConverter { get; set; }
Property Value
Type | Description |
---|---|
Converter<System.String, float2> | The parse property. |
PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
Declaration
public readonly float2 PerpendicularLeft { get; }
Property Value
Type | Description |
---|---|
float2 | The perpendicular left. |
PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Declaration
public readonly float2 PerpendicularRight { get; }
Property Value
Type | Description |
---|---|
float2 | The perpendicular right. |
r
The red component (same as x)
Declaration
public float r { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
rg
The rg component (same as xy)
Declaration
public float2 rg { get; set; }
Property Value
Type | Description |
---|---|
float2 |
xy
Gets and sets an OpenTK.float2 with the x and y components of this instance.
Declaration
public float2 xy { get; set; }
Property Value
Type | Description |
---|---|
float2 |
yx
Gets or sets an OpenTK.float2 with the y and x components of this instance.
Declaration
public float2 yx { get; set; }
Property Value
Type | Description |
---|---|
float2 |
Methods
Add(float2, float2)
Adds two vectors.
Declaration
public static float2 Add(float2 a, float2 b)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | Left operand. |
float2 | b | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of operation. |
Barycentric(float2, float2, float2, Single, Single)
Interpolate 3 Vectors using Barycentric coordinates
Declaration
public static float2 Barycentric(float2 a, float2 b, float2 c, float u, float v)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First input Vector |
float2 | b | Second input Vector |
float2 | c | Third input Vector |
System.Single | u | First Barycentric Coordinate |
System.Single | v | Second Barycentric Coordinate |
Returns
Type | Description |
---|---|
float2 | a when u=1,v=9, b when u=0,v=1, c when u=v=1, and a linear combination of a,b,c otherwise |
Clamp(float2, float2, float2)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static float2 Clamp(float2 vec, float2 min, float2 max)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | Input vector |
float2 | min | Minimum vector |
float2 | max | Maximum vector |
Returns
Type | Description |
---|---|
float2 | The clamped vector |
ComponentMax(float2, float2)
Calculate the component-wise maximum of two vectors
Declaration
public static float2 ComponentMax(float2 a, float2 b)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First operand |
float2 | b | Second operand |
Returns
Type | Description |
---|---|
float2 | The component-wise maximum |
ComponentMin(float2, float2)
Calculate the component-wise minimum of two vectors
Declaration
public static float2 ComponentMin(float2 a, float2 b)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First operand |
float2 | b | Second operand |
Returns
Type | Description |
---|---|
float2 | The component-wise minimum |
Divide(float2, float2)
Divides a vector by the components of a vector (scale).
Declaration
public static float2 Divide(float2 vector, float2 scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vector | Left operand. |
float2 | scale | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of the operation. |
Divide(float2, Single)
Divides a vector by a scalar.
Declaration
public static float2 Divide(float2 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vector | Left operand. |
System.Single | scale | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of the operation. |
Dot(float2, float2)
Calculate the dot (scalar) product of two vectors
Declaration
public static float Dot(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | First operand |
float2 | right | Second operand |
Returns
Type | Description |
---|---|
System.Single | The dot product of the two inputs |
Equals(float2)
Indicates whether the current vector is equal to another vector.
Declaration
public bool Equals(float2 other)
Parameters
Type | Name | Description |
---|---|---|
float2 | 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
GetBarycentric(float2, float2, float2, float2, out Single, out Single)
Calculates the barycentric coordinates for the given point in the given triangle, such that ua + vb + (1-u-v)*c = point.
Declaration
public static void GetBarycentric(float2 a, float2 b, float2 c, float2 point, out float u, out float v)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | The first point of the triangle. |
float2 | b | The second point of the triangle. |
float2 | c | The third point of the triangle. |
float2 | point | The point to calculate the barycentric coordinates for. |
System.Single | u | The resulting barycentric u coordinate (weight for vertex a). |
System.Single | v | The resulting barycentric v coordinate (weight for vertex b). |
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 containing the unique hashcode for this instance. |
Overrides
IsTriangleCW(float2, float2, float2)
Checks if the three given 2D points form a clockwise (CW) triangle
Declaration
public static bool IsTriangleCW(float2 a, float2 b, float2 c)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | The first point of the triangle. |
float2 | b | The second point of the triangle. |
float2 | c | The third point of the triangle. |
Returns
Type | Description |
---|---|
System.Boolean | true if the triangle is clockwise, otherwise false. |
Lerp(float2, float2, 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(float2 a, float2 b, float2 blend)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First input vector |
float2 | b | Second input vector |
float2 | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
float2 |
Lerp(float2, float2, Single)
Returns a new Vector that is the linear blend of the 2 given Vectors
Declaration
public static float2 Lerp(float2 a, float2 b, float blend)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First input vector |
float2 | b | Second input vector |
System.Single | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
float2 | a when blend=0, b when blend=1, and a linear combination otherwise |
Max(float2, float2)
Returns the float3 with the minimum magnitude
Declaration
public static float2 Max(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand |
float2 | right | Right operand |
Returns
Type | Description |
---|---|
float2 | The minimum float3 |
Min(float2, float2)
Returns the float3 with the minimum magnitude
Declaration
public static float2 Min(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand |
float2 | right | Right operand |
Returns
Type | Description |
---|---|
float2 | The minimum float3 |
Multiply(float2, float2)
Multiplies a vector by the components a vector (scale).
Declaration
public static float2 Multiply(float2 vector, float2 scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vector | Left operand. |
float2 | scale | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of the operation. |
Multiply(float2, Single)
Multiplies a vector by a scalar.
Declaration
public static float2 Multiply(float2 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vector | Left operand. |
System.Single | scale | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of the operation. |
Normalize()
Scales the float2 to unit length.
Declaration
public float2 Normalize()
Returns
Type | Description |
---|---|
float2 |
Normalize(float2)
Scale a vector to unit length
Declaration
public static float2 Normalize(float2 vec)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | The input vector |
Returns
Type | Description |
---|---|
float2 | The normalized vector |
NormalizeFast()
Scales the float2 to approximately unit length.
Declaration
public float2 NormalizeFast()
Returns
Type | Description |
---|---|
float2 |
NormalizeFast(float2)
Scale a vector to approximately unit length
Declaration
public static float2 NormalizeFast(float2 vec)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | The input vector |
Returns
Type | Description |
---|---|
float2 | The normalized vector |
Parse(String, IFormatProvider)
Parses a string into a float2.
Declaration
public static float2 Parse(string source, IFormatProvider provider = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | |
System.IFormatProvider | provider |
Returns
Type | Description |
---|---|
float2 |
PointInRectangle(float2, float2, float2)
Checks if the given point lies within the given rectangle using screen coordinates (meaning top is smaller than bottom).
Declaration
public static bool PointInRectangle(float2 topLeft, float2 bottomRight, float2 point)
Parameters
Type | Name | Description |
---|---|---|
float2 | topLeft | The top left point of the rectangle. |
float2 | bottomRight | The bottom right point of the triangle. |
float2 | point | The point to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the point lies withing the rectangle. False if the point lies outside the rectangle. |
PointInTriangle(float2, float2, float2, float2, out Single, out Single)
Checks if the give point is inside the given triangle (a, b, c). Returns the barycentric coordinates using GetBarycentric(float2, float2, float2, float2, out Single, out Single).
Declaration
public static bool PointInTriangle(float2 a, float2 b, float2 c, float2 point, out float u, out float v)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | The first point of the triangle. |
float2 | b | The second point of the triangle. |
float2 | c | The third point of the triangle. |
float2 | point | The point to calculate the barycentric coordinates for. |
System.Single | u | The resulting barycentric u coordinate (weight for vertex a). |
System.Single | v | The resulting barycentric v coordinate (weight for vertex b). |
Returns
Type | Description |
---|---|
System.Boolean | true, if the point is inside the triangle a, b, c. Otherwise false. |
Pow(float2, Single)
Returns a float2 where all components are raised to the specified power.
Declaration
public static float2 Pow(float2 val, float exp)
Parameters
Type | Name | Description |
---|---|---|
float2 | val | The float3 to be raised to a power. |
System.Single | exp | A float that specifies a power. |
Returns
Type | Description |
---|---|
float2 |
Step(float2, float2)
Performs Step(Single, Single) for each component of the input vectors.
Declaration
public static float2 Step(float2 edge, float2 val)
Parameters
Type | Name | Description |
---|---|---|
float2 | edge | Specifies the location of the edge of the step function. |
float2 | val | Specifies the value to be used to generate the step function. |
Returns
Type | Description |
---|---|
float2 |
Subtract(float2, float2)
Subtract one Vector from another
Declaration
public static float2 Subtract(float2 a, float2 b)
Parameters
Type | Name | Description |
---|---|---|
float2 | a | First operand |
float2 | b | Second operand |
Returns
Type | Description |
---|---|
float2 | Result of subtraction |
ToArray()
Returns an array of floats with the two components of the vector.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
System.Single[] | Returns an array of floats with the two components of the vector. |
ToString()
Returns a System.String that represents the current float2.
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 float2.
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(float2, float2)
Adds the specified instances.
Declaration
public static float2 operator +(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
float2 | right | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of addition. |
Addition(float2, Single)
Adds a scalar to the specified instance.
Declaration
public static float2 operator +(float2 left, float scalar)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
System.Single | scalar | The scalar. |
Returns
Type | Description |
---|---|
float2 | Result of addition. |
Division(float2, Single)
Divides the specified instance by a scalar.
Declaration
public static float2 operator /(float2 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | Left operand |
System.Single | scale | Right operand |
Returns
Type | Description |
---|---|
float2 | Result of the division. |
Equality(float2, float2)
Compares the specified instances for equality.
Declaration
public static bool operator ==(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
float2 | right | Right operand. |
Returns
Type | Description |
---|---|
System.Boolean | True if both instances are equal; false otherwise. |
Inequality(float2, float2)
Compares the specified instances for inequality.
Declaration
public static bool operator !=(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
float2 | right | Right operand. |
Returns
Type | Description |
---|---|
System.Boolean | True if both instances are not equal; false otherwise. |
Multiply(float2, float2)
Multiplies two instances.
Declaration
public static float2 operator *(float2 vec1, float2 vec2)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec1 | Left operand. |
float2 | vec2 | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of multiplication. |
Multiply(float2, Single)
Multiplies the specified instance by a scalar.
Declaration
public static float2 operator *(float2 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | Left operand. |
System.Single | scale | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of multiplication. |
Multiply(Single, float2)
Multiplies the specified instance by a scalar.
Declaration
public static float2 operator *(float scale, float2 vec)
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | Left operand. |
float2 | vec | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of multiplication. |
Subtraction(float2, float2)
Subtracts the specified instances.
Declaration
public static float2 operator -(float2 left, float2 right)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
float2 | right | Right operand. |
Returns
Type | Description |
---|---|
float2 | Result of subtraction. |
Subtraction(float2, Single)
Subtracts a scalar from the specified instance.
Declaration
public static float2 operator -(float2 left, float scalar)
Parameters
Type | Name | Description |
---|---|---|
float2 | left | Left operand. |
System.Single | scalar | The scalar. |
Returns
Type | Description |
---|---|
float2 | Result of addition. |
UnaryNegation(float2)
Negates the specified instance.
Declaration
public static float2 operator -(float2 vec)
Parameters
Type | Name | Description |
---|---|---|
float2 | vec | Operand. |
Returns
Type | Description |
---|---|
float2 | Result of negation. |