Refactor and enhance math utilities and code generation
Refactored `StbImage` classes to be publicly accessible. Updated namespaces and introduced `NumericTypeAttribute` for metadata. Enhanced `VectorGenerator` with new utility methods (`any`, `all`, `length`, etc.) and improved code generation. Consolidated vector operations in `math` utilities. Refactored `Plane` and `svd` classes for better encapsulation and readability. Improved `DynamicArray` with `uint` indexer support and cleaner loops. Added SIMD-based benchmarking placeholders in `MathematicsBenchmark`. Removed redundant code and unused files, including `IUnsafeSet.cs`. Updated project file to include `CodeGen` as an analyzer. Introduced `SupportedVectorMath` and `SupportedMatrixMath` enums for better operation definitions. Improved code style, fixed minor bugs, and cleaned up unused code in `Program.cs`. Enhanced maintainability and readability across the codebase.
This commit is contained in:
@@ -1890,34 +1890,6 @@ public static partial class math
|
||||
return abs(x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a float2 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing length.</param>
|
||||
/// <returns>Length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float length(float2 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a float3 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing length.</param>
|
||||
/// <returns>Length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float length(float3 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a float4 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing length.</param>
|
||||
/// <returns>Length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float length(float4 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the length of a double value. Equivalent to the absolute value.</summary>
|
||||
/// <param name="x">Value to use when computing squared length.</param>
|
||||
/// <returns>Squared length of x.</returns>
|
||||
@@ -1927,34 +1899,6 @@ public static partial class math
|
||||
return abs(x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a double2 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double length(double2 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a double3 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double length(double3 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
/// <summary>Returns the length of a double4 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double length(double4 x)
|
||||
{
|
||||
return sqrt(dot(x, x));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the squared length of a float value. Equivalent to squaring the value.</summary>
|
||||
/// <param name="x">Value to use when computing squared length.</param>
|
||||
/// <returns>Squared length of x.</returns>
|
||||
@@ -1964,34 +1908,6 @@ public static partial class math
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a float2 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float lengthsq(float2 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a float3 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float lengthsq(float3 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a float4 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float lengthsq(float4 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the squared length of a double value. Equivalent to squaring the value.</summary>
|
||||
/// <param name="x">Value to use when computing squared length.</param>
|
||||
/// <returns>Squared length of x.</returns>
|
||||
@@ -2001,34 +1917,6 @@ public static partial class math
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a double2 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double lengthsq(double2 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a double3 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double lengthsq(double3 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared length of a double4 vector.</summary>
|
||||
/// <param name="x">Vector to use when computing squared length.</param>
|
||||
/// <returns>Squared length of vector x.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double lengthsq(double4 x)
|
||||
{
|
||||
return dot(x, x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the distance between two float values.</summary>
|
||||
/// <param name="x">First value to use in distance computation.</param>
|
||||
/// <param name="y">Second value to use in distance computation.</param>
|
||||
@@ -2039,37 +1927,6 @@ public static partial class math
|
||||
return abs(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two float2 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distance(float2 x, float2 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two float3 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distance(float3 x, float3 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two float4 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distance(float4 x, float4 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the distance between two double values.</summary>
|
||||
/// <param name="x">First value to use in distance computation.</param>
|
||||
/// <param name="y">Second value to use in distance computation.</param>
|
||||
@@ -2080,37 +1937,6 @@ public static partial class math
|
||||
return abs(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two double2 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distance(double2 x, double2 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two double3 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distance(double3 x, double3 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the distance between two double4 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distance(double4 x, double4 y)
|
||||
{
|
||||
return length(y - x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the squared distance between two float values.</summary>
|
||||
/// <param name="x">First value to use in distance computation.</param>
|
||||
/// <param name="y">Second value to use in distance computation.</param>
|
||||
@@ -2121,37 +1947,6 @@ public static partial class math
|
||||
return (y - x) * (y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two float2 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distancesq(float2 x, float2 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two float3 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distancesq(float3 x, float3 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two float4 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float distancesq(float4 x, float4 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the squared distance between two double values.</summary>
|
||||
/// <param name="x">First value to use in distance computation.</param>
|
||||
/// <param name="y">Second value to use in distance computation.</param>
|
||||
@@ -2162,37 +1957,6 @@ public static partial class math
|
||||
return (y - x) * (y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two double2 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distancesq(double2 x, double2 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two double3 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distancesq(double3 x, double3 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
/// <summary>Returns the squared distance between two double4 vectors.</summary>
|
||||
/// <param name="x">First vector to use in distance computation.</param>
|
||||
/// <param name="y">Second vector to use in distance computation.</param>
|
||||
/// <returns>The squared distance between x and y.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double distancesq(double4 x, double4 y)
|
||||
{
|
||||
return lengthsq(y - x);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the cross product of two float3 vectors.</summary>
|
||||
/// <param name="x">First vector to use in cross product.</param>
|
||||
/// <param name="y">Second vector to use in cross product.</param>
|
||||
@@ -2237,60 +2001,6 @@ public static partial class math
|
||||
return t * t * (3.0 - (2.0 * t));
|
||||
}
|
||||
|
||||
/// <summary>Returns true if any component of the input bool2 vector is true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if any the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool any(bool2 x)
|
||||
{
|
||||
return x.x || x.y;
|
||||
}
|
||||
|
||||
/// <summary>Returns true if any component of the input bool3 vector is true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if any the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool any(bool3 x)
|
||||
{
|
||||
return x.x || x.y || x.z;
|
||||
}
|
||||
|
||||
/// <summary>Returns true if any components of the input bool4 vector is true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if any the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool any(bool4 x)
|
||||
{
|
||||
return x.x || x.y || x.z || x.w;
|
||||
}
|
||||
|
||||
/// <summary>Returns true if all components of the input bool2 vector are true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if all the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool all(bool2 x)
|
||||
{
|
||||
return x.x && x.y;
|
||||
}
|
||||
|
||||
/// <summary>Returns true if all components of the input bool3 vector are true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if all the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool all(bool3 x)
|
||||
{
|
||||
return x.x && x.y && x.z;
|
||||
}
|
||||
|
||||
/// <summary>Returns true if all components of the input bool4 vector are true, false otherwise.</summary>
|
||||
/// <param name="x">Vector of values to compare.</param>
|
||||
/// <returns>True if all the components of x are true, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool all(bool4 x)
|
||||
{
|
||||
return x.x && x.y && x.z && x.w;
|
||||
}
|
||||
|
||||
/// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
|
||||
/// <param name="falseValue">Value to use if test is false.</param>
|
||||
/// <param name="trueValue">Value to use if test is true.</param>
|
||||
@@ -2378,449 +2088,6 @@ public static partial class math
|
||||
return select(0.0, 1.0, x >= threshold);
|
||||
}
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 reflect(float2 i, float2 n)
|
||||
{
|
||||
return i - 2f * n * dot(i, n);
|
||||
}
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 reflect(float3 i, float3 n)
|
||||
{
|
||||
return i - 2f * n * dot(i, n);
|
||||
}
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 reflect(float4 i, float4 n)
|
||||
{
|
||||
return i - 2f * n * dot(i, n);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double2 reflect(double2 i, double2 n)
|
||||
{
|
||||
return i - 2 * n * dot(i, n);
|
||||
}
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double3 reflect(double3 i, double3 n)
|
||||
{
|
||||
return i - 2 * n * dot(i, n);
|
||||
}
|
||||
|
||||
/// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <returns>Reflection vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 reflect(double4 i, double4 n)
|
||||
{
|
||||
return i - 2 * n * dot(i, n);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 refract(float2 i, float2 n, float indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
|
||||
return select(new(0.0f), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 refract(float3 i, float3 n, float indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
|
||||
return select(new(0.0f), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 refract(float4 i, float4 n, float indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
|
||||
return select(new(0.0f), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double2 refract(double2 i, double2 n, double indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
|
||||
return select(new(0.0), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double3 refract(double3 i, double3 n, double indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
|
||||
return select(new(0.0), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
/// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
|
||||
/// <param name="i">Incident vector.</param>
|
||||
/// <param name="n">Normal vector.</param>
|
||||
/// <param name="indexOfRefraction">Index of refraction.</param>
|
||||
/// <returns>Refraction vector.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 refract(double4 i, double4 n, double indexOfRefraction)
|
||||
{
|
||||
var ni = dot(n, i);
|
||||
var k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
|
||||
return select(new(0.0), indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float2,Unity.Mathematics.float2,Unity.Mathematics.float2)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 project(float2 a, float2 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float3,Unity.Mathematics.float3,Unity.Mathematics.float3)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 project(float3 a, float3 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float4,Unity.Mathematics.float4,Unity.Mathematics.float4)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 project(float4 a, float4 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.float2,Unity.Mathematics.float2)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 projectsafe(float2 a, float2 ontoB, float2 defaultValue = new float2())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.float3,Unity.Mathematics.float3)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 projectsafe(float3 a, float3 ontoB, float3 defaultValue = new float3())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.float4,Unity.Mathematics.float4)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 projectsafe(float4 a, float4 ontoB, float4 defaultValue = new float4())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double2,Unity.Mathematics.double2,Unity.Mathematics.double2)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double2 project(double2 a, double2 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double3,Unity.Mathematics.double3,Unity.Mathematics.double3)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double3 project(double3 a, double3 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
|
||||
/// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
|
||||
/// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double4,Unity.Mathematics.double4,Unity.Mathematics.double4)"/>
|
||||
/// which will use a given default value if the result is not finite.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <returns>Vector projection of a onto b.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 project(double4 a, double4 ontoB)
|
||||
{
|
||||
return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.double2,Unity.Mathematics.double2)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double2 projectsafe(double2 a, double2 ontoB, double2 defaultValue = new double2())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.double3,Unity.Mathematics.double3)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double3 projectsafe(double3 a, double3 ontoB, double3 defaultValue = new double3())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
|
||||
/// your inputs will generate a finite result or you don't care if the result is finite, then you can call
|
||||
/// <see cref="project(Unity.Mathematics.double4,Unity.Mathematics.double4)"/> instead which is faster than this
|
||||
/// function.
|
||||
/// </remarks>
|
||||
/// <param name="a">Vector to project.</param>
|
||||
/// <param name="ontoB">Non-zero vector to project onto.</param>
|
||||
/// <param name="defaultValue">Default value to return if projection is not finite.</param>
|
||||
/// <returns>Vector projection of a onto b or the default value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 projectsafe(double4 a, double4 ontoB, double4 defaultValue = new double4())
|
||||
{
|
||||
var proj = project(a, ontoB);
|
||||
|
||||
return select(defaultValue, proj, all(isfinite(proj)));
|
||||
}
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 faceforward(float2 n, float2 i, float2 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 faceforward(float3 n, float3 i, float3 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 faceforward(float4 n, float4 i, float4 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double2 faceforward(double2 n, double2 i, double2 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double3 faceforward(double3 n, double3 i, double3 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
|
||||
/// <param name="n">Vector to conditionally flip.</param>
|
||||
/// <param name="i">First vector in direction comparison.</param>
|
||||
/// <param name="ng">Second vector in direction comparison.</param>
|
||||
/// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 faceforward(double4 n, double4 i, double4 ng)
|
||||
{
|
||||
return select(n, -n, dot(ng, i) >= 0.0f);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Returns the sine and cosine of the input float value x through the out parameters s and c.</summary>
|
||||
/// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
|
||||
/// <param name="x">Input angle in radians.</param>
|
||||
|
||||
Reference in New Issue
Block a user