diff --git a/Nerd_STF/Mathematics/Float2.cs b/Nerd_STF/Mathematics/Float2.cs index d0e367d..e479088 100644 --- a/Nerd_STF/Mathematics/Float2.cs +++ b/Nerd_STF/Mathematics/Float2.cs @@ -16,6 +16,7 @@ public record struct Float2 : IAbsolute, IAverage, ICeiling new(1, 1); public static Float2 Zero => new(0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y); public float Magnitude => Mathf.Sqrt(x * x + y * y); public Float2 Normalized => this * Mathf.InverseSqrt(x * x + y * y); diff --git a/Nerd_STF/Mathematics/Float3.cs b/Nerd_STF/Mathematics/Float3.cs index 9f407d3..72a48d7 100644 --- a/Nerd_STF/Mathematics/Float3.cs +++ b/Nerd_STF/Mathematics/Float3.cs @@ -20,6 +20,7 @@ public record struct Float3 : IAbsolute, IAverage, public static Float3 One => new(1, 1, 1); public static Float3 Zero => new(0, 0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y + z * z); public float Magnitude => Mathf.Sqrt(x * x + y * y + z * z); public Float3 Normalized => this * Mathf.InverseSqrt(x * x + y * y + z * z); diff --git a/Nerd_STF/Mathematics/Float4.cs b/Nerd_STF/Mathematics/Float4.cs index 3c094ee..3107213 100644 --- a/Nerd_STF/Mathematics/Float4.cs +++ b/Nerd_STF/Mathematics/Float4.cs @@ -21,6 +21,7 @@ public record struct Float4 : IAbsolute, public static Float4 One => new(1, 1, 1, 1); public static Float4 Zero => new(0, 0, 0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y + z * z + w * w); public float Magnitude => Mathf.Sqrt(x * x + y * y + z * z + w * w); public Float4 Normalized => this * Mathf.InverseSqrt(x * x + y * y + z * z + w * w); diff --git a/Nerd_STF/Mathematics/Geometry/Line.cs b/Nerd_STF/Mathematics/Geometry/Line.cs index dcac2d3..d9438df 100644 --- a/Nerd_STF/Mathematics/Geometry/Line.cs +++ b/Nerd_STF/Mathematics/Geometry/Line.cs @@ -130,7 +130,7 @@ public record class Line : IAbsolute, IAverage, ICeiling, ICla public bool Contains(Float3 vert) { Float3 diffA = a - vert, diffB = a - b; - float lerpVal = diffA.Magnitude / diffB.Magnitude; + float lerpVal = diffA.Magnitude * diffB.InverseMagnitude; return Float3.Lerp(a, b, lerpVal) == vert; } diff --git a/Nerd_STF/Mathematics/Int2.cs b/Nerd_STF/Mathematics/Int2.cs index 5ccc8e7..094892f 100644 --- a/Nerd_STF/Mathematics/Int2.cs +++ b/Nerd_STF/Mathematics/Int2.cs @@ -14,6 +14,7 @@ public record struct Int2 : IAbsolute, IAverage, IClamp, IClam public static Int2 One => new(1, 1); public static Int2 Zero => new(0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y); public float Magnitude => Mathf.Sqrt(x * x + y * y); public Int2 Normalized => (Int2)((Float2)this * Mathf.InverseSqrt(x * x + y * y)); diff --git a/Nerd_STF/Mathematics/Int3.cs b/Nerd_STF/Mathematics/Int3.cs index 7b14136..705ea5d 100644 --- a/Nerd_STF/Mathematics/Int3.cs +++ b/Nerd_STF/Mathematics/Int3.cs @@ -18,6 +18,7 @@ public record struct Int3 : IAbsolute, IAverage, IClamp, IClam public static Int3 One => new(1, 1, 1); public static Int3 Zero => new(0, 0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y + z * z); public float Magnitude => Mathf.Sqrt(x * x + y * y + z * z); public Int3 Normalized => (Int3)((Float3)this * Mathf.InverseSqrt(x * x + y * y + z * z)); diff --git a/Nerd_STF/Mathematics/Int4.cs b/Nerd_STF/Mathematics/Int4.cs index bb096d4..3fbbcff 100644 --- a/Nerd_STF/Mathematics/Int4.cs +++ b/Nerd_STF/Mathematics/Int4.cs @@ -18,6 +18,7 @@ public record struct Int4 : IAbsolute, IAverage, IClamp, IClam public static Int4 One => new(1, 1, 1, 1); public static Int4 Zero => new(0, 0, 0, 0); + public float InverseMagnitude => Mathf.InverseSqrt(x * x + y * y + z * z + w * w); public float Magnitude => Mathf.Sqrt(x * x + y * y + z * z + w * w); public Int4 Normalized => (Int4)((Float4)this * Mathf.InverseSqrt(x * x + y * y + z * z + w * w));