From c6de4b26b6f9768161bff7e175f55e9015712d50 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 25 Jun 2024 14:48:50 +0100 Subject: [PATCH] format again --- .../Common/System/PlatDetect.cs | 8 +- .../ConstantHelper.cs | 142 ++-- Speckle.DoubleNumerics.Tests/MathHelper.cs | 8 +- .../Matrix3x2Tests.cs | 13 +- .../Matrix4x4Tests.cs | 94 +-- .../Performance/Common/System/PerfUtils.cs | 18 +- .../Performance/HashCodeTest.cs | 2 +- .../Performance/Perf.Vector2.cs | 353 ++++---- Speckle.DoubleNumerics.Tests/PlaneTests.cs | 2 +- .../QuaternionTests.cs | 32 +- Speckle.DoubleNumerics.Tests/Util.cs | 32 +- Speckle.DoubleNumerics.Tests/Vector2Tests.cs | 6 +- Speckle.DoubleNumerics.Tests/Vector4Tests.cs | 18 +- Speckle.DoubleNumerics/HashHelpers.cs | 10 +- Speckle.DoubleNumerics/Matrix3x2.cs | 784 +++++++++--------- Speckle.DoubleNumerics/Matrix4x4.cs | 168 ++-- Speckle.DoubleNumerics/Plane.cs | 220 ++--- Speckle.DoubleNumerics/Quaternion.cs | 762 ++++++++--------- Speckle.DoubleNumerics/Vector2.cs | 9 +- Speckle.DoubleNumerics/Vector2_Intrinsics.cs | 57 +- Speckle.DoubleNumerics/Vector3.cs | 2 +- Speckle.DoubleNumerics/Vector3_Intrinsics.cs | 24 +- Speckle.DoubleNumerics/Vector4_Intrinsics.cs | 22 +- 23 files changed, 1375 insertions(+), 1411 deletions(-) diff --git a/Speckle.DoubleNumerics.Tests/Common/System/PlatDetect.cs b/Speckle.DoubleNumerics.Tests/Common/System/PlatDetect.cs index 94b2d9c..9ea684f 100644 --- a/Speckle.DoubleNumerics.Tests/Common/System/PlatDetect.cs +++ b/Speckle.DoubleNumerics.Tests/Common/System/PlatDetect.cs @@ -169,13 +169,7 @@ private static Version GetOSXKernelVersion() } [DllImport("libc", SetLastError = true)] - private static extern int sysctlbyname( - string ctlName, - byte[] oldp, - ref IntPtr oldpLen, - byte[]? newp, - IntPtr newpLen - ); + private static extern int sysctlbyname(string ctlName, byte[] oldp, ref IntPtr oldpLen, byte[]? newp, IntPtr newpLen); [DllImport("ntdll.dll")] private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); diff --git a/Speckle.DoubleNumerics.Tests/ConstantHelper.cs b/Speckle.DoubleNumerics.Tests/ConstantHelper.cs index 3a8ac46..1ffca14 100644 --- a/Speckle.DoubleNumerics.Tests/ConstantHelper.cs +++ b/Speckle.DoubleNumerics.Tests/ConstantHelper.cs @@ -12,140 +12,140 @@ internal class ConstantHelper [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Byte GetByteWithAllBitsSet() { - Byte value = 0; - unsafe + Byte value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = 0xff; - } + *&value = 0xff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SByte GetSByteWithAllBitsSet() { - SByte value = 0; - unsafe + SByte value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = (SByte)0xff; - } + *&value = (SByte)0xff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static UInt16 GetUInt16WithAllBitsSet() { - UInt16 value = 0; - unsafe + UInt16 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = 0xffff; - } + *&value = 0xffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Int16 GetInt16WithAllBitsSet() { - Int16 value = 0; - unsafe + Int16 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = (Int16)0xffff; - } + *&value = (Int16)0xffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static UInt32 GetUInt32WithAllBitsSet() { - UInt32 value = 0; - unsafe + UInt32 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = 0xffffffff; - } + *&value = 0xffffffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Int32 GetInt32WithAllBitsSet() { - Int32 value = 0; - unsafe + Int32 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = (Int32)0xffffffff; - } + *&value = (Int32)0xffffffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static UInt64 GetUInt64WithAllBitsSet() { - UInt64 value = 0; - unsafe + UInt64 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = 0xffffffffffffffff; - } + *&value = 0xffffffffffffffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Int64 GetInt64WithAllBitsSet() { - Int64 value = 0; - unsafe + Int64 value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = (Int64)0xffffffffffffffff; - } + *&value = (Int64)0xffffffffffffffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Double GetDoubleWithAllBitsSet() { - Double value = 0; - unsafe + Double value = 0; + unsafe + { + unchecked { - unchecked - { - *((Int32*)&value) = (Int32)0xffffffffffffffff; - } + *((Int32*)&value) = (Int32)0xffffffffffffffff; } - return value; } + return value; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Single GetSingleWithAllBitsSet() { - Single value = 0; - unsafe + Single value = 0; + unsafe + { + unchecked { - unchecked - { - *&value = 0xffffffff; - } + *&value = 0xffffffff; } - return value; } -} \ No newline at end of file + return value; + } +} diff --git a/Speckle.DoubleNumerics.Tests/MathHelper.cs b/Speckle.DoubleNumerics.Tests/MathHelper.cs index f82b27a..37fd0cd 100644 --- a/Speckle.DoubleNumerics.Tests/MathHelper.cs +++ b/Speckle.DoubleNumerics.Tests/MathHelper.cs @@ -22,7 +22,8 @@ static class MathHelper public static bool Equal(Vector3 a, Vector3 b) => Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z); - public static bool Equal(Vector4 a, Vector4 b) => Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z) && Equal(a.W, b.W); + public static bool Equal(Vector4 a, Vector4 b) => + Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z) && Equal(a.W, b.W); public static bool Equal(Matrix4x4 a, Matrix4x4 b) => Equal(a.M11, b.M11) @@ -52,7 +53,8 @@ public static bool Equal(Matrix3x2 a, Matrix3x2 b) => public static bool Equal(Plane a, Plane b) => Equal(a.Normal, b.Normal) && Equal(a.D, b.D); - public static bool Equal(Quaternion a, Quaternion b) => Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z) && Equal(a.W, b.W); + public static bool Equal(Quaternion a, Quaternion b) => + Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z) && Equal(a.W, b.W); public static bool EqualRotation(Quaternion a, Quaternion b) => Equal(a, b) || Equal(a, -b); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/Matrix3x2Tests.cs b/Speckle.DoubleNumerics.Tests/Matrix3x2Tests.cs index caca298..73f68cb 100644 --- a/Speckle.DoubleNumerics.Tests/Matrix3x2Tests.cs +++ b/Speckle.DoubleNumerics.Tests/Matrix3x2Tests.cs @@ -158,8 +158,7 @@ public void Matrix3x2InvertScaleTest() [Fact] public void Matrix3x2InvertAffineTest() { - Matrix3x2 mtx = - Matrix3x2.CreateRotation(2) * Matrix3x2.CreateScale(23, -42) * Matrix3x2.CreateTranslation(17, 53); + Matrix3x2 mtx = Matrix3x2.CreateRotation(2) * Matrix3x2.CreateScale(23, -42) * Matrix3x2.CreateTranslation(17, 53); Matrix3x2 actual; Assert.True(Matrix3x2.Invert(mtx, out actual)); @@ -298,11 +297,11 @@ public void Matrix3x2InvertTest1() // all the elements in Actual is NaN Assert.True( double.IsNaN(actual.M11) - && double.IsNaN(actual.M12) - && double.IsNaN(actual.M21) - && double.IsNaN(actual.M22) - && double.IsNaN(actual.M31) - && double.IsNaN(actual.M32), + && double.IsNaN(actual.M12) + && double.IsNaN(actual.M21) + && double.IsNaN(actual.M22) + && double.IsNaN(actual.M31) + && double.IsNaN(actual.M32), "Matrix3x2.Invert did not return the expected value." ); } diff --git a/Speckle.DoubleNumerics.Tests/Matrix4x4Tests.cs b/Speckle.DoubleNumerics.Tests/Matrix4x4Tests.cs index d5b5d47..70098d1 100644 --- a/Speckle.DoubleNumerics.Tests/Matrix4x4Tests.cs +++ b/Speckle.DoubleNumerics.Tests/Matrix4x4Tests.cs @@ -529,9 +529,7 @@ public void Matrix4x4CreateFromAxisAngleTest() actual = Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, radians); Assert.True(MathHelper.Equal(expected, actual)); - expected = Matrix4x4.CreateFromQuaternion( - Quaternion.CreateFromAxisAngle(Vector3.Normalize(Vector3.One), radians) - ); + expected = Matrix4x4.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.Normalize(Vector3.One), radians)); actual = Matrix4x4.CreateFromAxisAngle(Vector3.Normalize(Vector3.One), radians); Assert.True(MathHelper.Equal(expected, actual)); @@ -842,8 +840,7 @@ public void Matrix4x4CreateWorldTest() Assert.Equal(objectPosition, actual.Translation); Assert.True(Vector3.Dot(Vector3.Normalize(objectUpVector), new Vector3(actual.M21, actual.M22, actual.M23)) > 0); Assert.True( - Vector3.Dot(Vector3.Normalize(objectForwardDirection), new Vector3(-actual.M31, -actual.M32, -actual.M33)) - > 0.999 + Vector3.Dot(Vector3.Normalize(objectForwardDirection), new Vector3(-actual.M31, -actual.M32, -actual.M33)) > 0.999 ); } @@ -1126,21 +1123,21 @@ public void Matrix4x4InvertTest1() // all the elements in Actual is NaN Assert.True( double.IsNaN(actual.M11) - && double.IsNaN(actual.M12) - && double.IsNaN(actual.M13) - && double.IsNaN(actual.M14) - && double.IsNaN(actual.M21) - && double.IsNaN(actual.M22) - && double.IsNaN(actual.M23) - && double.IsNaN(actual.M24) - && double.IsNaN(actual.M31) - && double.IsNaN(actual.M32) - && double.IsNaN(actual.M33) - && double.IsNaN(actual.M34) - && double.IsNaN(actual.M41) - && double.IsNaN(actual.M42) - && double.IsNaN(actual.M43) - && double.IsNaN(actual.M44), + && double.IsNaN(actual.M12) + && double.IsNaN(actual.M13) + && double.IsNaN(actual.M14) + && double.IsNaN(actual.M21) + && double.IsNaN(actual.M22) + && double.IsNaN(actual.M23) + && double.IsNaN(actual.M24) + && double.IsNaN(actual.M31) + && double.IsNaN(actual.M32) + && double.IsNaN(actual.M33) + && double.IsNaN(actual.M34) + && double.IsNaN(actual.M41) + && double.IsNaN(actual.M42) + && double.IsNaN(actual.M43) + && double.IsNaN(actual.M44), "Matrix4x4.Invert did not return the expected value." ); } @@ -1791,12 +1788,7 @@ private void CreateBillboardFact(Vector3 placeDirection, Vector3 cameraUpVector, Vector3 cameraPosition = new(3.0, 4.0, 5.0); Vector3 objectPosition = cameraPosition + placeDirection * 10.0; Matrix4x4 expected = expectedRotation * Matrix4x4.CreateTranslation(objectPosition); - Matrix4x4 actual = Matrix4x4.CreateBillboard( - objectPosition, - cameraPosition, - cameraUpVector, - new Vector3(0, 0, -1) - ); + Matrix4x4 actual = Matrix4x4.CreateBillboard(objectPosition, cameraPosition, cameraUpVector, new Vector3(0, 0, -1)); Assert.True(MathHelper.Equal(expected, actual), "Matrix4x4.CreateBillboard did not return the expected value."); } @@ -1816,11 +1808,7 @@ public void Matrix4x4CreateBillboardTest01() => [Fact] public void Matrix4x4CreateBillboardTest02() => // Object placed at Backward of camera. This result must be same as 0 degrees rotate along y-axis. - CreateBillboardFact( - new Vector3(0, 0, 1), - new Vector3(0, 1, 0), - Matrix4x4.CreateRotationY(MathHelper.ToRadians(0)) - ); + CreateBillboardFact(new Vector3(0, 0, 1), new Vector3(0, 1, 0), Matrix4x4.CreateRotationY(MathHelper.ToRadians(0))); // A test for CreateBillboard (Vector3, Vector3, Vector3, Vector3?) // Place object at Right side of camera on XZ-plane @@ -1944,12 +1932,7 @@ public void Matrix4x4CreateBillboardTooCloseTest1() // Doesn't pass camera face direction. CreateBillboard uses new Vector3(0, 0, -1) direction. Result must be same as 180 degrees rotate along y-axis. Matrix4x4 expected = Matrix4x4.CreateRotationY(MathHelper.ToRadians(180.0)) * Matrix4x4.CreateTranslation(objectPosition); - Matrix4x4 actual = Matrix4x4.CreateBillboard( - objectPosition, - cameraPosition, - cameraUpVector, - new Vector3(0, 0, 1) - ); + Matrix4x4 actual = Matrix4x4.CreateBillboard(objectPosition, cameraPosition, cameraUpVector, new Vector3(0, 0, 1)); Assert.True(MathHelper.Equal(expected, actual), "Matrix4x4.CreateBillboard did not return the expected value."); } @@ -1965,12 +1948,7 @@ public void Matrix4x4CreateBillboardTooCloseTest2() // Passes Vector3.Right as camera face direction. Result must be same as -90 degrees rotate along y-axis. Matrix4x4 expected = Matrix4x4.CreateRotationY(MathHelper.ToRadians(-90.0)) * Matrix4x4.CreateTranslation(objectPosition); - Matrix4x4 actual = Matrix4x4.CreateBillboard( - objectPosition, - cameraPosition, - cameraUpVector, - new Vector3(1, 0, 0) - ); + Matrix4x4 actual = Matrix4x4.CreateBillboard(objectPosition, cameraPosition, cameraUpVector, new Vector3(1, 0, 0)); Assert.True(MathHelper.Equal(expected, actual), "Matrix4x4.CreateBillboard did not return the expected value."); } @@ -2464,21 +2442,21 @@ public void Matrix4x4TranslationTest() // Make sure it only modifies expected value of matrix. Assert.True( a.M11 == b.M11 - && a.M12 == b.M12 - && a.M13 == b.M13 - && a.M14 == b.M14 - && a.M21 == b.M21 - && a.M22 == b.M22 - && a.M23 == b.M23 - && a.M24 == b.M24 - && a.M31 == b.M31 - && a.M32 == b.M32 - && a.M33 == b.M33 - && a.M34 == b.M34 - && a.M41 != b.M41 - && a.M42 != b.M42 - && a.M43 != b.M43 - && a.M44 == b.M44 + && a.M12 == b.M12 + && a.M13 == b.M13 + && a.M14 == b.M14 + && a.M21 == b.M21 + && a.M22 == b.M22 + && a.M23 == b.M23 + && a.M24 == b.M24 + && a.M31 == b.M31 + && a.M32 == b.M32 + && a.M33 == b.M33 + && a.M34 == b.M34 + && a.M41 != b.M41 + && a.M42 != b.M42 + && a.M43 != b.M43 + && a.M44 == b.M44 ); } diff --git a/Speckle.DoubleNumerics.Tests/Performance/Common/System/PerfUtils.cs b/Speckle.DoubleNumerics.Tests/Performance/Common/System/PerfUtils.cs index 1785937..55ffa9b 100644 --- a/Speckle.DoubleNumerics.Tests/Performance/Common/System/PerfUtils.cs +++ b/Speckle.DoubleNumerics.Tests/Performance/Common/System/PerfUtils.cs @@ -18,8 +18,8 @@ public class PerfUtils /// public PerfUtils() { - _rand = new Random(1234132); - } + _rand = new Random(1234132); + } /// /// Initializes a new PerfUtils object with the given seed. Use this if also @@ -28,8 +28,8 @@ public PerfUtils() /// public PerfUtils(int seed) { - _rand = new Random(seed); - } + _rand = new Random(seed); + } /// /// Helper method to create a string containing a number of random @@ -37,10 +37,10 @@ public PerfUtils(int seed) /// public string CreateString(int length) { - byte[] bytes = new byte[length]; - _rand.NextBytes(bytes); - return Convert.ToBase64String(bytes); - } + byte[] bytes = new byte[length]; + _rand.NextBytes(bytes); + return Convert.ToBase64String(bytes); + } /// Gets a test file full path that is associated with the call site. /// An optional index value to use as a suffix on the file name. Typically a loop index. @@ -61,4 +61,4 @@ public string GetTestFilePath( index.GetValueOrDefault() ) ); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/Performance/HashCodeTest.cs b/Speckle.DoubleNumerics.Tests/Performance/HashCodeTest.cs index b719489..4f3a312 100644 --- a/Speckle.DoubleNumerics.Tests/Performance/HashCodeTest.cs +++ b/Speckle.DoubleNumerics.Tests/Performance/HashCodeTest.cs @@ -27,4 +27,4 @@ public static void HashTest() } } */ -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/Performance/Perf.Vector2.cs b/Speckle.DoubleNumerics.Tests/Performance/Perf.Vector2.cs index 8c4c5b9..8fc804e 100644 --- a/Speckle.DoubleNumerics.Tests/Performance/Perf.Vector2.cs +++ b/Speckle.DoubleNumerics.Tests/Performance/Perf.Vector2.cs @@ -13,9 +13,9 @@ public class Perf_Vector2 { public static IEnumerable TestOperations() { - foreach (Operations op in Enum.GetValues(typeof(Operations))) - yield return new object[] { op }; - } + foreach (Operations op in Enum.GetValues(typeof(Operations))) + yield return new object[] { op }; + } /* [Benchmark] @@ -31,178 +31,183 @@ public void Operation(Operations operation) } */ - public void ExecuteTest(Operations operation, int innerIterations, System.Numerics.Vector2 v1, System.Numerics.Vector2 v2) + public void ExecuteTest( + Operations operation, + int innerIterations, + System.Numerics.Vector2 v1, + System.Numerics.Vector2 v2 + ) { - System.Numerics.Vector2 res; - switch (operation) - { - case Operations.Add_Operator: - for (int i = 0; i < innerIterations; i++) - { - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - res = v1 + v2; - } - break; - case Operations.Add_Function: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - System.Numerics.Vector2.Add(v1, v2); - } - break; - case Operations.Sub_Operator: - for (int i = 0; i < innerIterations; i++) - { - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - res = v1 - v2; - } - break; - case Operations.Sub_Function: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - System.Numerics.Vector2.Subtract(v1, v2); - } - break; - case Operations.Mul_Operator: - for (int i = 0; i < innerIterations; i++) - { - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - res = v1 * v2; - } - break; - case Operations.Mul_Function: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - System.Numerics.Vector2.Multiply(v1, v2); - } - break; - case Operations.Dot: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - System.Numerics.Vector2.Dot(v1, v2); - } - break; - case Operations.SquareRoot: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - System.Numerics.Vector2.SquareRoot(v1); - } - break; - case Operations.Length_Squared: - for (int i = 0; i < innerIterations; i++) - { - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - v1.LengthSquared(); - } - break; - case Operations.Normalize: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - System.Numerics.Vector2.Normalize(v1); - } - break; - case Operations.Distance_Squared: - for (int i = 0; i < innerIterations; i++) - { - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - System.Numerics.Vector2.DistanceSquared(v1, v2); - } - break; - } + System.Numerics.Vector2 res; + switch (operation) + { + case Operations.Add_Operator: + for (int i = 0; i < innerIterations; i++) + { + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + res = v1 + v2; + } + break; + case Operations.Add_Function: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + System.Numerics.Vector2.Add(v1, v2); + } + break; + case Operations.Sub_Operator: + for (int i = 0; i < innerIterations; i++) + { + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + res = v1 - v2; + } + break; + case Operations.Sub_Function: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + System.Numerics.Vector2.Subtract(v1, v2); + } + break; + case Operations.Mul_Operator: + for (int i = 0; i < innerIterations; i++) + { + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + res = v1 * v2; + } + break; + case Operations.Mul_Function: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + System.Numerics.Vector2.Multiply(v1, v2); + } + break; + case Operations.Dot: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + System.Numerics.Vector2.Dot(v1, v2); + } + break; + case Operations.SquareRoot: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + System.Numerics.Vector2.SquareRoot(v1); + } + break; + case Operations.Length_Squared: + for (int i = 0; i < innerIterations; i++) + { + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + v1.LengthSquared(); + } + break; + case Operations.Normalize: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + System.Numerics.Vector2.Normalize(v1); + } + break; + case Operations.Distance_Squared: + for (int i = 0; i < innerIterations; i++) + { + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + System.Numerics.Vector2.DistanceSquared(v1, v2); + } + break; } + } public enum Operations { @@ -218,4 +223,4 @@ public enum Operations Normalize = 10, Distance_Squared = 11 } -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/PlaneTests.cs b/Speckle.DoubleNumerics.Tests/PlaneTests.cs index 7efaa70..d9ec4f7 100644 --- a/Speckle.DoubleNumerics.Tests/PlaneTests.cs +++ b/Speckle.DoubleNumerics.Tests/PlaneTests.cs @@ -384,4 +384,4 @@ public unsafe void PlaneFieldOffsetTest() Assert.Equal(new IntPtr(basePtr + 0), new IntPtr(&plane.Normal)); Assert.Equal(new IntPtr(basePtr + 3), new IntPtr(&plane.D)); } -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/QuaternionTests.cs b/Speckle.DoubleNumerics.Tests/QuaternionTests.cs index dd97a25..60d3a62 100644 --- a/Speckle.DoubleNumerics.Tests/QuaternionTests.cs +++ b/Speckle.DoubleNumerics.Tests/QuaternionTests.cs @@ -274,9 +274,9 @@ public void QuaternionConstructorTest() Assert.True( MathHelper.Equal(target.X, x) - && MathHelper.Equal(target.Y, y) - && MathHelper.Equal(target.Z, z) - && MathHelper.Equal(target.W, w), + && MathHelper.Equal(target.Y, y) + && MathHelper.Equal(target.Z, z) + && MathHelper.Equal(target.W, w), "Quaternion.constructor (x,y,z,w) did not return the expected value." ); } @@ -291,9 +291,9 @@ public void QuaternionConstructorTest1() Quaternion target = new Quaternion(v, w); Assert.True( MathHelper.Equal(target.X, v.X) - && MathHelper.Equal(target.Y, v.Y) - && MathHelper.Equal(target.Z, v.Z) - && MathHelper.Equal(target.W, w), + && MathHelper.Equal(target.Y, v.Y) + && MathHelper.Equal(target.Z, v.Z) + && MathHelper.Equal(target.W, w), "Quaternion.constructor (Vector3,w) did not return the expected value." ); } @@ -739,10 +739,7 @@ public void QuaternionFromRotationMatrixTest1() // make sure convert back to matrix is same as we passed matrix. Matrix4x4 m2 = Matrix4x4.CreateFromQuaternion(actual); - Assert.True( - MathHelper.Equal(matrix, m2), - "Quaternion.CreateFromRotationMatrix did not return the expected value." - ); + Assert.True(MathHelper.Equal(matrix, m2), "Quaternion.CreateFromRotationMatrix did not return the expected value."); } // A test for CreateFromRotationMatrix (Matrix4x4) @@ -898,10 +895,7 @@ public void QuaternionFromRotationMatrixWithScaledMatrixTest1() // make sure convert back to matrix is same as we passed matrix. Matrix4x4 m2 = Matrix4x4.CreateFromQuaternion(actual); - Assert.True( - MathHelper.Equal(matrix, m2), - "Quaternion.CreateFromRotationMatrix did not return the expected value." - ); + Assert.True(MathHelper.Equal(matrix, m2), "Quaternion.CreateFromRotationMatrix did not return the expected value."); } // A test for CreateFromRotationMatrix (Matrix4x4) @@ -922,10 +916,7 @@ public void QuaternionFromRotationMatrixWithScaledMatrixTest2() // make sure convert back to matrix is same as we passed matrix. Matrix4x4 m2 = Matrix4x4.CreateFromQuaternion(actual); - Assert.True( - MathHelper.Equal(matrix, m2), - "Quaternion.CreateFromRotationMatrix did not return the expected value." - ); + Assert.True(MathHelper.Equal(matrix, m2), "Quaternion.CreateFromRotationMatrix did not return the expected value."); } // A test for CreateFromRotationMatrix (Matrix4x4) @@ -946,10 +937,7 @@ public void QuaternionFromRotationMatrixWithScaledMatrixTest3() // make sure convert back to matrix is same as we passed matrix. Matrix4x4 m2 = Matrix4x4.CreateFromQuaternion(actual); - Assert.True( - MathHelper.Equal(matrix, m2), - "Quaternion.CreateFromRotationMatrix did not return the expected value." - ); + Assert.True(MathHelper.Equal(matrix, m2), "Quaternion.CreateFromRotationMatrix did not return the expected value."); } // A test for Equals (Quaternion) diff --git a/Speckle.DoubleNumerics.Tests/Util.cs b/Speckle.DoubleNumerics.Tests/Util.cs index f2eda2a..ada5f18 100644 --- a/Speckle.DoubleNumerics.Tests/Util.cs +++ b/Speckle.DoubleNumerics.Tests/Util.cs @@ -109,36 +109,28 @@ public static T Abs(T value) } public static T Sqrt(T value) - where T : struct => - (T)(dynamic)(Math.Sqrt((dynamic)value)); + where T : struct => (T)(dynamic)(Math.Sqrt((dynamic)value)); public static T Multiply(T left, T right) - where T : struct => - (T)((dynamic)left * right); + where T : struct => (T)((dynamic)left * right); public static T Divide(T left, T right) - where T : struct => - (T)((dynamic)left / right); + where T : struct => (T)((dynamic)left / right); public static T Add(T left, T right) - where T : struct => - (T)((dynamic)left + right); + where T : struct => (T)((dynamic)left + right); public static T Subtract(T left, T right) - where T : struct => - (T)((dynamic)left - right); + where T : struct => (T)((dynamic)left - right); public static T Xor(T left, T right) - where T : struct => - (T)((dynamic)left ^ right); + where T : struct => (T)((dynamic)left ^ right); public static T AndNot(T left, T right) - where T : struct => - (T)((dynamic)left & ~(dynamic)right); + where T : struct => (T)((dynamic)left & ~(dynamic)right); public static T OnesComplement(T left) - where T : struct => - (T)(~(dynamic)left); + where T : struct => (T)(~(dynamic)left); public static double Clamp(double value, double min, double max) => value > max @@ -148,12 +140,10 @@ public static double Clamp(double value, double min, double max) => : value; public static T Zero() - where T : struct => - (T)(dynamic)0; + where T : struct => (T)(dynamic)0; public static T One() - where T : struct => - (T)(dynamic)1; + where T : struct => (T)(dynamic)1; public static bool GreaterThan(T left, T right) where T : struct @@ -208,4 +198,4 @@ public static bool AllEqual(T[] left, T[] right) } return true; } -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics.Tests/Vector2Tests.cs b/Speckle.DoubleNumerics.Tests/Vector2Tests.cs index a86e676..2fe8385 100644 --- a/Speckle.DoubleNumerics.Tests/Vector2Tests.cs +++ b/Speckle.DoubleNumerics.Tests/Vector2Tests.cs @@ -70,11 +70,7 @@ public void Vector2ToStringTest() Vector2 v1 = new Vector2(2.0, 3.0); string v1str = v1.ToString(); - string expectedv1 = string.Format( - CultureInfo.CurrentCulture, - "<{1:G}{0} {2:G}>", - new object[] { separator, 2, 3 } - ); + string expectedv1 = string.Format(CultureInfo.CurrentCulture, "<{1:G}{0} {2:G}>", new object[] { separator, 2, 3 }); Assert.Equal(expectedv1, v1str); string v1strformatted = v1.ToString("c", CultureInfo.CurrentCulture); diff --git a/Speckle.DoubleNumerics.Tests/Vector4Tests.cs b/Speckle.DoubleNumerics.Tests/Vector4Tests.cs index 981a022..c67312f 100644 --- a/Speckle.DoubleNumerics.Tests/Vector4Tests.cs +++ b/Speckle.DoubleNumerics.Tests/Vector4Tests.cs @@ -1030,9 +1030,9 @@ public void Vector4ConstructorTest() Assert.True( MathHelper.Equal(target.X, x) - && MathHelper.Equal(target.Y, y) - && MathHelper.Equal(target.Z, z) - && MathHelper.Equal(target.W, w), + && MathHelper.Equal(target.Y, y) + && MathHelper.Equal(target.Z, z) + && MathHelper.Equal(target.W, w), "Vector4 constructor(x,y,z,w) did not return the expected value." ); } @@ -1048,9 +1048,9 @@ public void Vector4ConstructorTest1() Vector4 target = new Vector4(a, z, w); Assert.True( MathHelper.Equal(target.X, a.X) - && MathHelper.Equal(target.Y, a.Y) - && MathHelper.Equal(target.Z, z) - && MathHelper.Equal(target.W, w), + && MathHelper.Equal(target.Y, a.Y) + && MathHelper.Equal(target.Z, z) + && MathHelper.Equal(target.W, w), "Vector4 constructor(Vector2,z,w) did not return the expected value." ); } @@ -1066,9 +1066,9 @@ public void Vector4ConstructorTest2() Assert.True( MathHelper.Equal(target.X, a.X) - && MathHelper.Equal(target.Y, a.Y) - && MathHelper.Equal(target.Z, a.Z) - && MathHelper.Equal(target.W, w), + && MathHelper.Equal(target.Y, a.Y) + && MathHelper.Equal(target.Z, a.Z) + && MathHelper.Equal(target.W, w), "Vector4 constructor(Vector3,w) did not return the expected value." ); } diff --git a/Speckle.DoubleNumerics/HashHelpers.cs b/Speckle.DoubleNumerics/HashHelpers.cs index da02b67..28f0bae 100644 --- a/Speckle.DoubleNumerics/HashHelpers.cs +++ b/Speckle.DoubleNumerics/HashHelpers.cs @@ -8,9 +8,9 @@ internal static class HashHelpers { public static int Combine(int h1, int h2) { - // The jit optimizes this to use the ROL instruction on x86 - // Related GitHub pull request: dotnet/coreclr#1830 - uint shift5 = ((uint)h1 << 5) | ((uint)h1 >> 27); - return ((int)shift5 + h1) ^ h2; - } + // The jit optimizes this to use the ROL instruction on x86 + // Related GitHub pull request: dotnet/coreclr#1830 + uint shift5 = ((uint)h1 << 5) | ((uint)h1 >> 27); + return ((int)shift5 + h1) ^ h2; + } } diff --git a/Speckle.DoubleNumerics/Matrix3x2.cs b/Speckle.DoubleNumerics/Matrix3x2.cs index 8129d97..b8b2293 100644 --- a/Speckle.DoubleNumerics/Matrix3x2.cs +++ b/Speckle.DoubleNumerics/Matrix3x2.cs @@ -71,9 +71,9 @@ public Vector2 Translation get => new(M31, M32); set { - M31 = value.X; - M32 = value.Y; - } + M31 = value.X; + M32 = value.Y; + } } /// @@ -81,13 +81,13 @@ public Vector2 Translation /// public Matrix3x2(double m11, double m12, double m21, double m22, double m31, double m32) { - M11 = m11; - M12 = m12; - M21 = m21; - M22 = m22; - M31 = m31; - M32 = m32; - } + M11 = m11; + M12 = m12; + M21 = m21; + M22 = m22; + M31 = m31; + M32 = m32; + } /// /// Creates a translation matrix from the given vector. @@ -96,18 +96,18 @@ public Matrix3x2(double m11, double m12, double m21, double m22, double m31, dou /// A translation matrix. public static Matrix3x2 CreateTranslation(Vector2 position) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = 1.0; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = 1.0; + result.M11 = 1.0; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = 1.0; - result.M31 = position.X; - result.M32 = position.Y; + result.M31 = position.X; + result.M32 = position.Y; - return result; - } + return result; + } /// /// Creates a translation matrix from the given X and Y components. @@ -117,29 +117,29 @@ public static Matrix3x2 CreateTranslation(Vector2 position) /// A translation matrix. public static Matrix3x2 CreateTranslation(double xPosition, double yPosition) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = 1.0; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = 1.0; + result.M11 = 1.0; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = 1.0; - result.M31 = xPosition; - result.M32 = yPosition; + result.M31 = xPosition; + result.M32 = yPosition; - return result; - } + return result; + } public string ToMultiLineString() { - var ci = CultureInfo.CurrentCulture; + var ci = CultureInfo.CurrentCulture; - var sb = new StringBuilder(); - sb.AppendLine($"{M11.ToString(ci), -19} {M12.ToString(ci), -19}"); - sb.AppendLine($"{M21.ToString(ci), -19} {M22.ToString(ci), -19}"); - sb.AppendLine($"{M31.ToString(ci), -19} {M32.ToString(ci), -19}"); - return sb.ToString(); - } + var sb = new StringBuilder(); + sb.AppendLine($"{M11.ToString(ci), -19} {M12.ToString(ci), -19}"); + sb.AppendLine($"{M21.ToString(ci), -19} {M22.ToString(ci), -19}"); + sb.AppendLine($"{M31.ToString(ci), -19} {M32.ToString(ci), -19}"); + return sb.ToString(); + } /// /// Creates a scale matrix from the given X and Y components. @@ -149,17 +149,17 @@ public string ToMultiLineString() /// A scaling matrix. public static Matrix3x2 CreateScale(double xScale, double yScale) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = xScale; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = yScale; - result.M31 = 0.0; - result.M32 = 0.0; + result.M11 = xScale; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = yScale; + result.M31 = 0.0; + result.M32 = 0.0; - return result; - } + return result; + } /// /// Creates a scale matrix that is offset by a given center point. @@ -170,20 +170,20 @@ public static Matrix3x2 CreateScale(double xScale, double yScale) /// A scaling matrix. public static Matrix3x2 CreateScale(double xScale, double yScale, Vector2 centerPoint) { - Matrix3x2 result; + Matrix3x2 result; - double tx = centerPoint.X * (1 - xScale); - double ty = centerPoint.Y * (1 - yScale); + double tx = centerPoint.X * (1 - xScale); + double ty = centerPoint.Y * (1 - yScale); - result.M11 = xScale; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = yScale; - result.M31 = tx; - result.M32 = ty; + result.M11 = xScale; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = yScale; + result.M31 = tx; + result.M32 = ty; - return result; - } + return result; + } /// /// Creates a scale matrix from the given vector scale. @@ -192,17 +192,17 @@ public static Matrix3x2 CreateScale(double xScale, double yScale, Vector2 center /// A scaling matrix. public static Matrix3x2 CreateScale(Vector2 scales) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = scales.X; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = scales.Y; - result.M31 = 0.0; - result.M32 = 0.0; + result.M11 = scales.X; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = scales.Y; + result.M31 = 0.0; + result.M32 = 0.0; - return result; - } + return result; + } /// /// Creates a scale matrix from the given vector scale with an offset from the given center point. @@ -212,20 +212,20 @@ public static Matrix3x2 CreateScale(Vector2 scales) /// A scaling matrix. public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint) { - Matrix3x2 result; + Matrix3x2 result; - double tx = centerPoint.X * (1 - scales.X); - double ty = centerPoint.Y * (1 - scales.Y); + double tx = centerPoint.X * (1 - scales.X); + double ty = centerPoint.Y * (1 - scales.Y); - result.M11 = scales.X; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = scales.Y; - result.M31 = tx; - result.M32 = ty; + result.M11 = scales.X; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = scales.Y; + result.M31 = tx; + result.M32 = ty; - return result; - } + return result; + } /// /// Creates a scale matrix that scales uniformly with the given scale. @@ -234,17 +234,17 @@ public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint) /// A scaling matrix. public static Matrix3x2 CreateScale(double scale) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = scale; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = scale; - result.M31 = 0.0; - result.M32 = 0.0; + result.M11 = scale; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = scale; + result.M31 = 0.0; + result.M32 = 0.0; - return result; - } + return result; + } /// /// Creates a scale matrix that scales uniformly with the given scale with an offset from the given center. @@ -254,20 +254,20 @@ public static Matrix3x2 CreateScale(double scale) /// A scaling matrix. public static Matrix3x2 CreateScale(double scale, Vector2 centerPoint) { - Matrix3x2 result; + Matrix3x2 result; - double tx = centerPoint.X * (1 - scale); - double ty = centerPoint.Y * (1 - scale); + double tx = centerPoint.X * (1 - scale); + double ty = centerPoint.Y * (1 - scale); - result.M11 = scale; - result.M12 = 0.0; - result.M21 = 0.0; - result.M22 = scale; - result.M31 = tx; - result.M32 = ty; + result.M11 = scale; + result.M12 = 0.0; + result.M21 = 0.0; + result.M22 = scale; + result.M31 = tx; + result.M32 = ty; - return result; - } + return result; + } /// /// Creates a skew matrix from the given angles in radians. @@ -277,20 +277,20 @@ public static Matrix3x2 CreateScale(double scale, Vector2 centerPoint) /// A skew matrix. public static Matrix3x2 CreateSkew(double radiansX, double radiansY) { - Matrix3x2 result; + Matrix3x2 result; - double xTan = Math.Tan(radiansX); - double yTan = Math.Tan(radiansY); + double xTan = Math.Tan(radiansX); + double yTan = Math.Tan(radiansY); - result.M11 = 1.0; - result.M12 = yTan; - result.M21 = xTan; - result.M22 = 1.0; - result.M31 = 0.0; - result.M32 = 0.0; + result.M11 = 1.0; + result.M12 = yTan; + result.M21 = xTan; + result.M22 = 1.0; + result.M31 = 0.0; + result.M32 = 0.0; - return result; - } + return result; + } /// /// Creates a skew matrix from the given angles in radians and a center point. @@ -301,23 +301,23 @@ public static Matrix3x2 CreateSkew(double radiansX, double radiansY) /// A skew matrix. public static Matrix3x2 CreateSkew(double radiansX, double radiansY, Vector2 centerPoint) { - Matrix3x2 result; + Matrix3x2 result; - double xTan = Math.Tan(radiansX); - double yTan = Math.Tan(radiansY); + double xTan = Math.Tan(radiansX); + double yTan = Math.Tan(radiansY); - double tx = -centerPoint.Y * xTan; - double ty = -centerPoint.X * yTan; + double tx = -centerPoint.Y * xTan; + double ty = -centerPoint.X * yTan; - result.M11 = 1.0; - result.M12 = yTan; - result.M21 = xTan; - result.M22 = 1.0; - result.M31 = tx; - result.M32 = ty; + result.M11 = 1.0; + result.M12 = yTan; + result.M21 = xTan; + result.M22 = 1.0; + result.M31 = tx; + result.M32 = ty; - return result; - } + return result; + } /// /// Creates a rotation matrix using the given rotation in radians. @@ -326,58 +326,58 @@ public static Matrix3x2 CreateSkew(double radiansX, double radiansY, Vector2 cen /// A rotation matrix. public static Matrix3x2 CreateRotation(double radians) { - Matrix3x2 result; - - radians = Math.IEEERemainder(radians, Math.PI * 2); - - double c, - s; - - const double epsilon = 0.001 * Math.PI / 180; // 0.1% of a degree - - if (radians > -epsilon && radians < epsilon) - { - // Exact case for zero rotation. - c = 1; - s = 0; - } - else if (radians > Math.PI / 2 - epsilon && radians < Math.PI / 2 + epsilon) - { - // Exact case for 90 degree rotation. - c = 0; - s = 1; - } - else if (radians < -Math.PI + epsilon || radians > Math.PI - epsilon) - { - // Exact case for 180 degree rotation. - c = -1; - s = 0; - } - else if (radians > -Math.PI / 2 - epsilon && radians < -Math.PI / 2 + epsilon) - { - // Exact case for 270 degree rotation. - c = 0; - s = -1; - } - else - { - // Arbitrary rotation. - c = Math.Cos(radians); - s = Math.Sin(radians); - } - - // [ c s ] - // [ -s c ] - // [ 0 0 ] - result.M11 = c; - result.M12 = s; - result.M21 = -s; - result.M22 = c; - result.M31 = 0.0; - result.M32 = 0.0; - - return result; + Matrix3x2 result; + + radians = Math.IEEERemainder(radians, Math.PI * 2); + + double c, + s; + + const double epsilon = 0.001 * Math.PI / 180; // 0.1% of a degree + + if (radians > -epsilon && radians < epsilon) + { + // Exact case for zero rotation. + c = 1; + s = 0; + } + else if (radians > Math.PI / 2 - epsilon && radians < Math.PI / 2 + epsilon) + { + // Exact case for 90 degree rotation. + c = 0; + s = 1; + } + else if (radians < -Math.PI + epsilon || radians > Math.PI - epsilon) + { + // Exact case for 180 degree rotation. + c = -1; + s = 0; + } + else if (radians > -Math.PI / 2 - epsilon && radians < -Math.PI / 2 + epsilon) + { + // Exact case for 270 degree rotation. + c = 0; + s = -1; } + else + { + // Arbitrary rotation. + c = Math.Cos(radians); + s = Math.Sin(radians); + } + + // [ c s ] + // [ -s c ] + // [ 0 0 ] + result.M11 = c; + result.M12 = s; + result.M21 = -s; + result.M22 = c; + result.M31 = 0.0; + result.M32 = 0.0; + + return result; + } /// /// Creates a rotation matrix using the given rotation in radians and a center point. @@ -387,62 +387,62 @@ public static Matrix3x2 CreateRotation(double radians) /// A rotation matrix. public static Matrix3x2 CreateRotation(double radians, Vector2 centerPoint) { - Matrix3x2 result; - - radians = Math.IEEERemainder(radians, Math.PI * 2); - - double c, - s; - - const double epsilon = 0.001 * Math.PI / 180; // 0.1% of a degree - - if (radians > -epsilon && radians < epsilon) - { - // Exact case for zero rotation. - c = 1; - s = 0; - } - else if (radians > Math.PI / 2 - epsilon && radians < Math.PI / 2 + epsilon) - { - // Exact case for 90 degree rotation. - c = 0; - s = 1; - } - else if (radians < -Math.PI + epsilon || radians > Math.PI - epsilon) - { - // Exact case for 180 degree rotation. - c = -1; - s = 0; - } - else if (radians > -Math.PI / 2 - epsilon && radians < -Math.PI / 2 + epsilon) - { - // Exact case for 270 degree rotation. - c = 0; - s = -1; - } - else - { - // Arbitrary rotation. - c = Math.Cos(radians); - s = Math.Sin(radians); - } - - double x = centerPoint.X * (1 - c) + centerPoint.Y * s; - double y = centerPoint.Y * (1 - c) - centerPoint.X * s; - - // [ c s ] - // [ -s c ] - // [ x y ] - result.M11 = c; - result.M12 = s; - result.M21 = -s; - result.M22 = c; - result.M31 = x; - result.M32 = y; - - return result; + Matrix3x2 result; + + radians = Math.IEEERemainder(radians, Math.PI * 2); + + double c, + s; + + const double epsilon = 0.001 * Math.PI / 180; // 0.1% of a degree + + if (radians > -epsilon && radians < epsilon) + { + // Exact case for zero rotation. + c = 1; + s = 0; + } + else if (radians > Math.PI / 2 - epsilon && radians < Math.PI / 2 + epsilon) + { + // Exact case for 90 degree rotation. + c = 0; + s = 1; + } + else if (radians < -Math.PI + epsilon || radians > Math.PI - epsilon) + { + // Exact case for 180 degree rotation. + c = -1; + s = 0; + } + else if (radians > -Math.PI / 2 - epsilon && radians < -Math.PI / 2 + epsilon) + { + // Exact case for 270 degree rotation. + c = 0; + s = -1; + } + else + { + // Arbitrary rotation. + c = Math.Cos(radians); + s = Math.Sin(radians); } + double x = centerPoint.X * (1 - c) + centerPoint.Y * s; + double y = centerPoint.Y * (1 - c) - centerPoint.X * s; + + // [ c s ] + // [ -s c ] + // [ x y ] + result.M11 = c; + result.M12 = s; + result.M21 = -s; + result.M22 = c; + result.M31 = x; + result.M32 = y; + + return result; + } + /// /// Calculates the determinant for this matrix. /// The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1). @@ -474,25 +474,25 @@ public double GetDeterminant() => /// True if the operation succeeded, False otherwise. public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result) { - double det = (matrix.M11 * matrix.M22) - (matrix.M21 * matrix.M12); + double det = (matrix.M11 * matrix.M22) - (matrix.M21 * matrix.M12); - if (Math.Abs(det) < double.Epsilon) - { - result = new Matrix3x2(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN); - return false; - } + if (Math.Abs(det) < double.Epsilon) + { + result = new Matrix3x2(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN); + return false; + } - double invDet = 1.0 / det; + double invDet = 1.0 / det; - result.M11 = matrix.M22 * invDet; - result.M12 = -matrix.M12 * invDet; - result.M21 = -matrix.M21 * invDet; - result.M22 = matrix.M11 * invDet; - result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * invDet; - result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * invDet; + result.M11 = matrix.M22 * invDet; + result.M12 = -matrix.M12 * invDet; + result.M21 = -matrix.M21 * invDet; + result.M22 = matrix.M11 * invDet; + result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * invDet; + result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * invDet; - return true; - } + return true; + } /// /// Linearly interpolates from matrix1 to matrix2, based on the third parameter. @@ -503,22 +503,22 @@ public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result) /// The interpolated matrix. public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, double amount) { - Matrix3x2 result; + Matrix3x2 result; - // First row - result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount; - result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount; + // First row + result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount; + result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount; - // Second row - result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount; - result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount; + // Second row + result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount; + result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount; - // Third row - result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount; - result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount; + // Third row + result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount; + result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount; - return result; - } + return result; + } /// /// Negates the given matrix by multiplying all values by -1. @@ -527,17 +527,17 @@ public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, double amount /// The negated matrix. public static Matrix3x2 Negate(Matrix3x2 value) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = -value.M11; - result.M12 = -value.M12; - result.M21 = -value.M21; - result.M22 = -value.M22; - result.M31 = -value.M31; - result.M32 = -value.M32; + result.M11 = -value.M11; + result.M12 = -value.M12; + result.M21 = -value.M21; + result.M22 = -value.M22; + result.M31 = -value.M31; + result.M32 = -value.M32; - return result; - } + return result; + } /// /// Adds each matrix element in value1 with its corresponding element in value2. @@ -547,17 +547,17 @@ public static Matrix3x2 Negate(Matrix3x2 value) /// The matrix containing the summed values. public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = value1.M11 + value2.M11; - result.M12 = value1.M12 + value2.M12; - result.M21 = value1.M21 + value2.M21; - result.M22 = value1.M22 + value2.M22; - result.M31 = value1.M31 + value2.M31; - result.M32 = value1.M32 + value2.M32; + result.M11 = value1.M11 + value2.M11; + result.M12 = value1.M12 + value2.M12; + result.M21 = value1.M21 + value2.M21; + result.M22 = value1.M22 + value2.M22; + result.M31 = value1.M31 + value2.M31; + result.M32 = value1.M32 + value2.M32; - return result; - } + return result; + } /// /// Subtracts each matrix element in value2 from its corresponding element in value1. @@ -567,17 +567,17 @@ public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2) /// The matrix containing the resulting values. public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = value1.M11 - value2.M11; - result.M12 = value1.M12 - value2.M12; - result.M21 = value1.M21 - value2.M21; - result.M22 = value1.M22 - value2.M22; - result.M31 = value1.M31 - value2.M31; - result.M32 = value1.M32 - value2.M32; + result.M11 = value1.M11 - value2.M11; + result.M12 = value1.M12 - value2.M12; + result.M21 = value1.M21 - value2.M21; + result.M22 = value1.M22 - value2.M22; + result.M31 = value1.M31 - value2.M31; + result.M32 = value1.M32 - value2.M32; - return result; - } + return result; + } /// /// Multiplies two matrices together and returns the resulting matrix. @@ -587,22 +587,22 @@ public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2) /// The product matrix. public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 result; + Matrix3x2 result; - // First row - result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; - result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; + // First row + result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; + result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; - // Second row - result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; - result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; + // Second row + result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; + result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; - // Third row - result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; - result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; + // Third row + result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; + result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; - return result; - } + return result; + } /// /// Scales all elements in a matrix by the given scalar factor. @@ -612,17 +612,17 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2) /// The resulting matrix. public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) { - Matrix3x2 result; + Matrix3x2 result; - result.M11 = value1.M11 * value2; - result.M12 = value1.M12 * value2; - result.M21 = value1.M21 * value2; - result.M22 = value1.M22 * value2; - result.M31 = value1.M31 * value2; - result.M32 = value1.M32 * value2; + result.M11 = value1.M11 * value2; + result.M12 = value1.M12 * value2; + result.M21 = value1.M21 * value2; + result.M22 = value1.M22 * value2; + result.M31 = value1.M31 * value2; + result.M32 = value1.M32 * value2; - return result; - } + return result; + } /// /// Negates the given matrix by multiplying all values by -1. @@ -631,17 +631,17 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The negated matrix. public static Matrix3x2 operator -(Matrix3x2 value) { - Matrix3x2 m; + Matrix3x2 m; - m.M11 = -value.M11; - m.M12 = -value.M12; - m.M21 = -value.M21; - m.M22 = -value.M22; - m.M31 = -value.M31; - m.M32 = -value.M32; + m.M11 = -value.M11; + m.M12 = -value.M12; + m.M21 = -value.M21; + m.M22 = -value.M22; + m.M31 = -value.M31; + m.M32 = -value.M32; - return m; - } + return m; + } /// /// Adds each matrix element in value1 with its corresponding element in value2. @@ -651,17 +651,17 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The matrix containing the summed values. public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 m; + Matrix3x2 m; - m.M11 = value1.M11 + value2.M11; - m.M12 = value1.M12 + value2.M12; - m.M21 = value1.M21 + value2.M21; - m.M22 = value1.M22 + value2.M22; - m.M31 = value1.M31 + value2.M31; - m.M32 = value1.M32 + value2.M32; + m.M11 = value1.M11 + value2.M11; + m.M12 = value1.M12 + value2.M12; + m.M21 = value1.M21 + value2.M21; + m.M22 = value1.M22 + value2.M22; + m.M31 = value1.M31 + value2.M31; + m.M32 = value1.M32 + value2.M32; - return m; - } + return m; + } /// /// Subtracts each matrix element in value2 from its corresponding element in value1. @@ -671,17 +671,17 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The matrix containing the resulting values. public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 m; + Matrix3x2 m; - m.M11 = value1.M11 - value2.M11; - m.M12 = value1.M12 - value2.M12; - m.M21 = value1.M21 - value2.M21; - m.M22 = value1.M22 - value2.M22; - m.M31 = value1.M31 - value2.M31; - m.M32 = value1.M32 - value2.M32; + m.M11 = value1.M11 - value2.M11; + m.M12 = value1.M12 - value2.M12; + m.M21 = value1.M21 - value2.M21; + m.M22 = value1.M22 - value2.M22; + m.M31 = value1.M31 - value2.M31; + m.M32 = value1.M32 - value2.M32; - return m; - } + return m; + } /// /// Multiplies two matrices together and returns the resulting matrix. @@ -691,22 +691,22 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The product matrix. public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2) { - Matrix3x2 m; + Matrix3x2 m; - // First row - m.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; - m.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; + // First row + m.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; + m.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; - // Second row - m.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; - m.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; + // Second row + m.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; + m.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; - // Third row - m.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; - m.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; + // Third row + m.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; + m.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; - return m; - } + return m; + } /// /// Scales all elements in a matrix by the given scalar factor. @@ -716,17 +716,17 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The resulting matrix. public static Matrix3x2 operator *(Matrix3x2 value1, double value2) { - Matrix3x2 m; + Matrix3x2 m; - m.M11 = value1.M11 * value2; - m.M12 = value1.M12 * value2; - m.M21 = value1.M21 * value2; - m.M22 = value1.M22 * value2; - m.M31 = value1.M31 * value2; - m.M32 = value1.M32 * value2; + m.M11 = value1.M11 * value2; + m.M12 = value1.M12 * value2; + m.M21 = value1.M21 * value2; + m.M22 = value1.M22 * value2; + m.M31 = value1.M31 * value2; + m.M32 = value1.M32 * value2; - return m; - } + return m; + } /// /// Returns a boolean indicating whether the given matrices are equal. @@ -735,15 +735,15 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The second source matrix. /// True if the matrices are equal; False otherwise. public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2) => - ( - value1.M11 == value2.M11 - && value1.M22 == value2.M22 - && // Check diagonal element first for early out. - value1.M12 == value2.M12 - && value1.M21 == value2.M21 - && value1.M31 == value2.M31 - && value1.M32 == value2.M32 - ); + ( + value1.M11 == value2.M11 + && value1.M22 == value2.M22 + && // Check diagonal element first for early out. + value1.M12 == value2.M12 + && value1.M21 == value2.M21 + && value1.M31 == value2.M31 + && value1.M32 == value2.M32 + ); /// /// Returns a boolean indicating whether the given matrices are not equal. @@ -752,14 +752,14 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The second source matrix. /// True if the matrices are not equal; False if they are equal. public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2) => - ( - value1.M11 != value2.M11 - || value1.M12 != value2.M12 - || value1.M21 != value2.M21 - || value1.M22 != value2.M22 - || value1.M31 != value2.M31 - || value1.M32 != value2.M32 - ); + ( + value1.M11 != value2.M11 + || value1.M12 != value2.M12 + || value1.M21 != value2.M21 + || value1.M22 != value2.M22 + || value1.M31 != value2.M31 + || value1.M32 != value2.M32 + ); /// /// Returns a boolean indicating whether the matrix is equal to the other given matrix. @@ -767,15 +767,15 @@ public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) /// The other matrix to test equality against. /// True if this matrix is equal to other; False otherwise. public bool Equals(Matrix3x2 other) => - ( - M11 == other.M11 - && M22 == other.M22 - && // Check diagonal element first for early out. - M12 == other.M12 - && M21 == other.M21 - && M31 == other.M31 - && M32 == other.M32 - ); + ( + M11 == other.M11 + && M22 == other.M22 + && // Check diagonal element first for early out. + M12 == other.M12 + && M21 == other.M21 + && M31 == other.M31 + && M32 == other.M32 + ); /// /// Returns a boolean indicating whether the given Object is equal to this matrix instance. @@ -784,32 +784,32 @@ public bool Equals(Matrix3x2 other) => /// True if the Object is equal to this matrix; False otherwise. public override bool Equals(object? obj) { - if (obj is Matrix3x2 x2) - { - return Equals(x2); - } - - return false; + if (obj is Matrix3x2 x2) + { + return Equals(x2); } + return false; + } + /// /// Returns a String representing this matrix instance. /// /// The string representation. public override string ToString() { - CultureInfo ci = CultureInfo.CurrentCulture; - return String.Format( - ci, - "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}", - M11.ToString(ci), - M12.ToString(ci), - M21.ToString(ci), - M22.ToString(ci), - M31.ToString(ci), - M32.ToString(ci) - ); - } + CultureInfo ci = CultureInfo.CurrentCulture; + return String.Format( + ci, + "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}", + M11.ToString(ci), + M12.ToString(ci), + M21.ToString(ci), + M22.ToString(ci), + M31.ToString(ci), + M32.ToString(ci) + ); + } /// /// Returns the hash code for this instance. @@ -822,4 +822,4 @@ public override int GetHashCode() => + M22.GetHashCode() + M31.GetHashCode() + M32.GetHashCode(); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Matrix4x4.cs b/Speckle.DoubleNumerics/Matrix4x4.cs index 71c77a9..e94e68a 100644 --- a/Speckle.DoubleNumerics/Matrix4x4.cs +++ b/Speckle.DoubleNumerics/Matrix4x4.cs @@ -1374,9 +1374,9 @@ public double GetDeterminant() double in_jm = i * n - j * m; return a * (f * kp_lo - g * jp_ln + h * jo_kn) - - b * (e * kp_lo - g * ip_lm + h * io_km) - + c * (e * jp_ln - f * ip_lm + h * in_jm) - - d * (e * jo_kn - f * io_km + g * in_jm); + - b * (e * kp_lo - g * ip_lm + h * io_km) + + c * (e * jp_ln - f * ip_lm + h * in_jm) + - d * (e * jo_kn - f * io_km + g * in_jm); } /// @@ -2021,44 +2021,28 @@ public static Matrix4x4 Multiply(Matrix4x4 value1, Matrix4x4 value2) Matrix4x4 result; // First row - result.M11 = - value1.M11 * value2.M11 + value1.M12 * value2.M21 + value1.M13 * value2.M31 + value1.M14 * value2.M41; - result.M12 = - value1.M11 * value2.M12 + value1.M12 * value2.M22 + value1.M13 * value2.M32 + value1.M14 * value2.M42; - result.M13 = - value1.M11 * value2.M13 + value1.M12 * value2.M23 + value1.M13 * value2.M33 + value1.M14 * value2.M43; - result.M14 = - value1.M11 * value2.M14 + value1.M12 * value2.M24 + value1.M13 * value2.M34 + value1.M14 * value2.M44; + result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21 + value1.M13 * value2.M31 + value1.M14 * value2.M41; + result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22 + value1.M13 * value2.M32 + value1.M14 * value2.M42; + result.M13 = value1.M11 * value2.M13 + value1.M12 * value2.M23 + value1.M13 * value2.M33 + value1.M14 * value2.M43; + result.M14 = value1.M11 * value2.M14 + value1.M12 * value2.M24 + value1.M13 * value2.M34 + value1.M14 * value2.M44; // Second row - result.M21 = - value1.M21 * value2.M11 + value1.M22 * value2.M21 + value1.M23 * value2.M31 + value1.M24 * value2.M41; - result.M22 = - value1.M21 * value2.M12 + value1.M22 * value2.M22 + value1.M23 * value2.M32 + value1.M24 * value2.M42; - result.M23 = - value1.M21 * value2.M13 + value1.M22 * value2.M23 + value1.M23 * value2.M33 + value1.M24 * value2.M43; - result.M24 = - value1.M21 * value2.M14 + value1.M22 * value2.M24 + value1.M23 * value2.M34 + value1.M24 * value2.M44; + result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21 + value1.M23 * value2.M31 + value1.M24 * value2.M41; + result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22 + value1.M23 * value2.M32 + value1.M24 * value2.M42; + result.M23 = value1.M21 * value2.M13 + value1.M22 * value2.M23 + value1.M23 * value2.M33 + value1.M24 * value2.M43; + result.M24 = value1.M21 * value2.M14 + value1.M22 * value2.M24 + value1.M23 * value2.M34 + value1.M24 * value2.M44; // Third row - result.M31 = - value1.M31 * value2.M11 + value1.M32 * value2.M21 + value1.M33 * value2.M31 + value1.M34 * value2.M41; - result.M32 = - value1.M31 * value2.M12 + value1.M32 * value2.M22 + value1.M33 * value2.M32 + value1.M34 * value2.M42; - result.M33 = - value1.M31 * value2.M13 + value1.M32 * value2.M23 + value1.M33 * value2.M33 + value1.M34 * value2.M43; - result.M34 = - value1.M31 * value2.M14 + value1.M32 * value2.M24 + value1.M33 * value2.M34 + value1.M34 * value2.M44; + result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value1.M33 * value2.M31 + value1.M34 * value2.M41; + result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value1.M33 * value2.M32 + value1.M34 * value2.M42; + result.M33 = value1.M31 * value2.M13 + value1.M32 * value2.M23 + value1.M33 * value2.M33 + value1.M34 * value2.M43; + result.M34 = value1.M31 * value2.M14 + value1.M32 * value2.M24 + value1.M33 * value2.M34 + value1.M34 * value2.M44; // Fourth row - result.M41 = - value1.M41 * value2.M11 + value1.M42 * value2.M21 + value1.M43 * value2.M31 + value1.M44 * value2.M41; - result.M42 = - value1.M41 * value2.M12 + value1.M42 * value2.M22 + value1.M43 * value2.M32 + value1.M44 * value2.M42; - result.M43 = - value1.M41 * value2.M13 + value1.M42 * value2.M23 + value1.M43 * value2.M33 + value1.M44 * value2.M43; - result.M44 = - value1.M41 * value2.M14 + value1.M42 * value2.M24 + value1.M43 * value2.M34 + value1.M44 * value2.M44; + result.M41 = value1.M41 * value2.M11 + value1.M42 * value2.M21 + value1.M43 * value2.M31 + value1.M44 * value2.M41; + result.M42 = value1.M41 * value2.M12 + value1.M42 * value2.M22 + value1.M43 * value2.M32 + value1.M44 * value2.M42; + result.M43 = value1.M41 * value2.M13 + value1.M42 * value2.M23 + value1.M43 * value2.M33 + value1.M44 * value2.M43; + result.M44 = value1.M41 * value2.M14 + value1.M42 * value2.M24 + value1.M43 * value2.M34 + value1.M44 * value2.M44; return result; } @@ -2255,25 +2239,25 @@ public static Matrix4x4 Multiply(Matrix4x4 value1, double value2) /// The second matrix to compare. /// True if the given matrices are equal; False otherwise. public static bool operator ==(Matrix4x4 value1, Matrix4x4 value2) => - ( - value1.M11 == value2.M11 - && value1.M22 == value2.M22 - && value1.M33 == value2.M33 - && value1.M44 == value2.M44 - && // Check diagonal element first for early out. - value1.M12 == value2.M12 - && value1.M13 == value2.M13 - && value1.M14 == value2.M14 - && value1.M21 == value2.M21 - && value1.M23 == value2.M23 - && value1.M24 == value2.M24 - && value1.M31 == value2.M31 - && value1.M32 == value2.M32 - && value1.M34 == value2.M34 - && value1.M41 == value2.M41 - && value1.M42 == value2.M42 - && value1.M43 == value2.M43 - ); + ( + value1.M11 == value2.M11 + && value1.M22 == value2.M22 + && value1.M33 == value2.M33 + && value1.M44 == value2.M44 + && // Check diagonal element first for early out. + value1.M12 == value2.M12 + && value1.M13 == value2.M13 + && value1.M14 == value2.M14 + && value1.M21 == value2.M21 + && value1.M23 == value2.M23 + && value1.M24 == value2.M24 + && value1.M31 == value2.M31 + && value1.M32 == value2.M32 + && value1.M34 == value2.M34 + && value1.M41 == value2.M41 + && value1.M42 == value2.M42 + && value1.M43 == value2.M43 + ); /// /// Returns a boolean indicating whether the given two matrices are not equal. @@ -2282,24 +2266,24 @@ public static Matrix4x4 Multiply(Matrix4x4 value1, double value2) /// The second matrix to compare. /// True if the given matrices are not equal; False if they are equal. public static bool operator !=(Matrix4x4 value1, Matrix4x4 value2) => - ( - value1.M11 != value2.M11 - || value1.M12 != value2.M12 - || value1.M13 != value2.M13 - || value1.M14 != value2.M14 - || value1.M21 != value2.M21 - || value1.M22 != value2.M22 - || value1.M23 != value2.M23 - || value1.M24 != value2.M24 - || value1.M31 != value2.M31 - || value1.M32 != value2.M32 - || value1.M33 != value2.M33 - || value1.M34 != value2.M34 - || value1.M41 != value2.M41 - || value1.M42 != value2.M42 - || value1.M43 != value2.M43 - || value1.M44 != value2.M44 - ); + ( + value1.M11 != value2.M11 + || value1.M12 != value2.M12 + || value1.M13 != value2.M13 + || value1.M14 != value2.M14 + || value1.M21 != value2.M21 + || value1.M22 != value2.M22 + || value1.M23 != value2.M23 + || value1.M24 != value2.M24 + || value1.M31 != value2.M31 + || value1.M32 != value2.M32 + || value1.M33 != value2.M33 + || value1.M34 != value2.M34 + || value1.M41 != value2.M41 + || value1.M42 != value2.M42 + || value1.M43 != value2.M43 + || value1.M44 != value2.M44 + ); /// /// Returns a boolean indicating whether this matrix instance is equal to the other given matrix. @@ -2307,25 +2291,25 @@ public static Matrix4x4 Multiply(Matrix4x4 value1, double value2) /// The matrix to compare this instance to. /// True if the matrices are equal; False otherwise. public bool Equals(Matrix4x4 other) => - ( - M11 == other.M11 - && M22 == other.M22 - && M33 == other.M33 - && M44 == other.M44 - && // Check diagonal element first for early out. - M12 == other.M12 - && M13 == other.M13 - && M14 == other.M14 - && M21 == other.M21 - && M23 == other.M23 - && M24 == other.M24 - && M31 == other.M31 - && M32 == other.M32 - && M34 == other.M34 - && M41 == other.M41 - && M42 == other.M42 - && M43 == other.M43 - ); + ( + M11 == other.M11 + && M22 == other.M22 + && M33 == other.M33 + && M44 == other.M44 + && // Check diagonal element first for early out. + M12 == other.M12 + && M13 == other.M13 + && M14 == other.M14 + && M21 == other.M21 + && M23 == other.M23 + && M24 == other.M24 + && M31 == other.M31 + && M32 == other.M32 + && M34 == other.M34 + && M41 == other.M41 + && M42 == other.M42 + && M43 == other.M43 + ); /// /// Returns a boolean indicating whether the given Object is equal to this matrix instance. @@ -2405,4 +2389,4 @@ public override int GetHashCode() => + M42.GetHashCode() + M43.GetHashCode() + M44.GetHashCode(); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Plane.cs b/Speckle.DoubleNumerics/Plane.cs index 397ee76..b3233fb 100644 --- a/Speckle.DoubleNumerics/Plane.cs +++ b/Speckle.DoubleNumerics/Plane.cs @@ -31,9 +31,9 @@ public struct Plane : IEquatable /// The distance of the Plane along its normal from the origin. public Plane(double x, double y, double z, double d) { - Normal = new Vector3(x, y, z); - D = d; - } + Normal = new Vector3(x, y, z); + D = d; + } /// /// Constructs a Plane from the given normal and distance along the normal from the origin. @@ -42,9 +42,9 @@ public Plane(double x, double y, double z, double d) /// The Plane's distance from the origin along its normal vector. public Plane(Vector3 normal, double d) { - Normal = normal; - D = d; - } + Normal = normal; + D = d; + } /// /// Constructs a Plane from the given Vector4. @@ -53,9 +53,9 @@ public Plane(Vector3 normal, double d) /// and whose W component defines the distance along that normal from the origin. public Plane(Vector4 value) { - Normal = new Vector3(value.X, value.Y, value.Z); - D = value.W; - } + Normal = new Vector3(value.X, value.Y, value.Z); + D = value.W; + } /// /// Creates a Plane that contains the three given points. @@ -67,27 +67,27 @@ public Plane(Vector4 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 point3) { - double ax = point2.X - point1.X; - double ay = point2.Y - point1.Y; - double az = point2.Z - point1.Z; + double ax = point2.X - point1.X; + double ay = point2.Y - point1.Y; + double az = point2.Z - point1.Z; - double bx = point3.X - point1.X; - double by = point3.Y - point1.Y; - double bz = point3.Z - point1.Z; + double bx = point3.X - point1.X; + double by = point3.Y - point1.Y; + double bz = point3.Z - point1.Z; - // N=Cross(a,b) - double nx = ay * bz - az * by; - double ny = az * bx - ax * bz; - double nz = ax * by - ay * bx; + // N=Cross(a,b) + double nx = ay * bz - az * by; + double ny = az * bx - ax * bz; + double nz = ax * by - ay * bx; - // Normalize(N) - double ls = nx * nx + ny * ny + nz * nz; - double invNorm = 1.0 / Math.Sqrt(ls); + // Normalize(N) + double ls = nx * nx + ny * ny + nz * nz; + double invNorm = 1.0 / Math.Sqrt(ls); - Vector3 normal = new(nx * invNorm, ny * invNorm, nz * invNorm); + Vector3 normal = new(nx * invNorm, ny * invNorm, nz * invNorm); - return new Plane(normal, -(normal.X * point1.X + normal.Y * point1.Y + normal.Z * point1.Z)); - } + return new Plane(normal, -(normal.X * point1.X + normal.Y * point1.Y + normal.Z * point1.Z)); + } /// /// Creates a new Plane whose normal vector is the source Plane's normal vector normalized. @@ -97,18 +97,18 @@ public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 p [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Normalize(Plane value) { - const double FLT_EPSILON = 1.192092896e-07; // smallest such that 1.0+FLT_EPSILON != 1.0 - double f = value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z; + const double FLT_EPSILON = 1.192092896e-07; // smallest such that 1.0+FLT_EPSILON != 1.0 + double f = value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z; - if (Math.Abs(f - 1.0) < FLT_EPSILON) - { - return value; // It already normalized, so we don't need to further process. - } + if (Math.Abs(f - 1.0) < FLT_EPSILON) + { + return value; // It already normalized, so we don't need to further process. + } - double fInv = 1.0 / Math.Sqrt(f); + double fInv = 1.0 / Math.Sqrt(f); - return new Plane(value.Normal.X * fInv, value.Normal.Y * fInv, value.Normal.Z * fInv, value.D * fInv); - } + return new Plane(value.Normal.X * fInv, value.Normal.Y * fInv, value.Normal.Z * fInv, value.D * fInv); + } /// /// Transforms a normalized Plane by a Matrix. @@ -120,21 +120,21 @@ public static Plane Normalize(Plane value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Transform(Plane plane, Matrix4x4 matrix) { - Matrix4x4 m; - Matrix4x4.Invert(matrix, out m); - - double x = plane.Normal.X, - y = plane.Normal.Y, - z = plane.Normal.Z, - w = plane.D; - - return new Plane( - x * m.M11 + y * m.M12 + z * m.M13 + w * m.M14, - x * m.M21 + y * m.M22 + z * m.M23 + w * m.M24, - x * m.M31 + y * m.M32 + z * m.M33 + w * m.M34, - x * m.M41 + y * m.M42 + z * m.M43 + w * m.M44 - ); - } + Matrix4x4 m; + Matrix4x4.Invert(matrix, out m); + + double x = plane.Normal.X, + y = plane.Normal.Y, + z = plane.Normal.Z, + w = plane.D; + + return new Plane( + x * m.M11 + y * m.M12 + z * m.M13 + w * m.M14, + x * m.M21 + y * m.M22 + z * m.M23 + w * m.M24, + x * m.M31 + y * m.M32 + z * m.M33 + w * m.M34, + x * m.M41 + y * m.M42 + z * m.M43 + w * m.M44 + ); + } /// /// Transforms a normalized Plane by a Quaternion rotation. @@ -146,39 +146,39 @@ public static Plane Transform(Plane plane, Matrix4x4 matrix) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Transform(Plane plane, Quaternion rotation) { - // Compute rotation matrix. - double x2 = rotation.X + rotation.X; - double y2 = rotation.Y + rotation.Y; - double z2 = rotation.Z + rotation.Z; - - double wx2 = rotation.W * x2; - double wy2 = rotation.W * y2; - double wz2 = rotation.W * z2; - double xx2 = rotation.X * x2; - double xy2 = rotation.X * y2; - double xz2 = rotation.X * z2; - double yy2 = rotation.Y * y2; - double yz2 = rotation.Y * z2; - double zz2 = rotation.Z * z2; - - double m11 = 1.0 - yy2 - zz2; - double m21 = xy2 - wz2; - double m31 = xz2 + wy2; - - double m12 = xy2 + wz2; - double m22 = 1.0 - xx2 - zz2; - double m32 = yz2 - wx2; - - double m13 = xz2 - wy2; - double m23 = yz2 + wx2; - double m33 = 1.0 - xx2 - yy2; - - double x = plane.Normal.X, - y = plane.Normal.Y, - z = plane.Normal.Z; - - return new Plane(x * m11 + y * m21 + z * m31, x * m12 + y * m22 + z * m32, x * m13 + y * m23 + z * m33, plane.D); - } + // Compute rotation matrix. + double x2 = rotation.X + rotation.X; + double y2 = rotation.Y + rotation.Y; + double z2 = rotation.Z + rotation.Z; + + double wx2 = rotation.W * x2; + double wy2 = rotation.W * y2; + double wz2 = rotation.W * z2; + double xx2 = rotation.X * x2; + double xy2 = rotation.X * y2; + double xz2 = rotation.X * z2; + double yy2 = rotation.Y * y2; + double yz2 = rotation.Y * z2; + double zz2 = rotation.Z * z2; + + double m11 = 1.0 - yy2 - zz2; + double m21 = xy2 - wz2; + double m31 = xz2 + wy2; + + double m12 = xy2 + wz2; + double m22 = 1.0 - xx2 - zz2; + double m32 = yz2 - wx2; + + double m13 = xz2 - wy2; + double m23 = yz2 + wx2; + double m33 = 1.0 - xx2 - yy2; + + double x = plane.Normal.X, + y = plane.Normal.Y, + z = plane.Normal.Z; + + return new Plane(x * m11 + y * m21 + z * m31, x * m12 + y * m22 + z * m32, x * m13 + y * m23 + z * m33, plane.D); + } /// /// Calculates the dot product of a Plane and Vector4. @@ -187,7 +187,8 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// The Vector4. /// The dot product. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Plane plane, Vector4 value) => plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D * value.W; + public static double Dot(Plane plane, Vector4 value) => + plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D * value.W; /// /// Returns the dot product of a specified Vector3 and the normal vector of this Plane plus the distance (D) value of the Plane. @@ -196,7 +197,8 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// The Vector3. /// The resulting value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double DotCoordinate(Plane plane, Vector3 value) => plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D; + public static double DotCoordinate(Plane plane, Vector3 value) => + plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D; /// /// Returns the dot product of a specified Vector3 and the Normal vector of this Plane. @@ -205,7 +207,8 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// The Vector3. /// The resulting dot product. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double DotNormal(Plane plane, Vector3 value) => plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z; + public static double DotNormal(Plane plane, Vector3 value) => + plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z; /// /// Returns a boolean indicating whether the two given Planes are equal. @@ -215,12 +218,12 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// True if the Planes are equal; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Plane value1, Plane value2) => - ( - value1.Normal.X == value2.Normal.X - && value1.Normal.Y == value2.Normal.Y - && value1.Normal.Z == value2.Normal.Z - && value1.D == value2.D - ); + ( + value1.Normal.X == value2.Normal.X + && value1.Normal.Y == value2.Normal.Y + && value1.Normal.Z == value2.Normal.Z + && value1.D == value2.D + ); /// /// Returns a boolean indicating whether the two given Planes are not equal. @@ -230,12 +233,12 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// True if the Planes are not equal; False if they are equal. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Plane value1, Plane value2) => - ( - value1.Normal.X != value2.Normal.X - || value1.Normal.Y != value2.Normal.Y - || value1.Normal.Z != value2.Normal.Z - || value1.D != value2.D - ); + ( + value1.Normal.X != value2.Normal.X + || value1.Normal.Y != value2.Normal.Y + || value1.Normal.Z != value2.Normal.Z + || value1.D != value2.D + ); /// /// Returns a boolean indicating whether the given Plane is equal to this Plane instance. @@ -243,7 +246,8 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// The Plane to compare this instance to. /// True if the other Plane is equal to this instance; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Plane other) => (Normal.X == other.Normal.X && Normal.Y == other.Normal.Y && Normal.Z == other.Normal.Z && D == other.D); + public bool Equals(Plane other) => + (Normal.X == other.Normal.X && Normal.Y == other.Normal.Y && Normal.Z == other.Normal.Z && D == other.D); /// /// Returns a boolean indicating whether the given Object is equal to this Plane instance. @@ -253,28 +257,28 @@ public static Plane Transform(Plane plane, Quaternion rotation) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object? obj) { - if (obj is Plane plane) - { - return Equals(plane); - } - - return false; + if (obj is Plane plane) + { + return Equals(plane); } + return false; + } + /// /// Returns a String representing this Plane instance. /// /// The string representation. public override string ToString() { - CultureInfo ci = CultureInfo.CurrentCulture; + CultureInfo ci = CultureInfo.CurrentCulture; - return String.Format(ci, "{{Normal:{0} D:{1}}}", Normal.ToString(), D.ToString(ci)); - } + return String.Format(ci, "{{Normal:{0} D:{1}}}", Normal.ToString(), D.ToString(ci)); + } /// /// Returns the hash code for this instance. /// /// The hash code. public override int GetHashCode() => Normal.GetHashCode() + D.GetHashCode(); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Quaternion.cs b/Speckle.DoubleNumerics/Quaternion.cs index dcb6fc2..a611bce 100644 --- a/Speckle.DoubleNumerics/Quaternion.cs +++ b/Speckle.DoubleNumerics/Quaternion.cs @@ -51,11 +51,11 @@ public struct Quaternion : IEquatable /// The W component of the Quaternion. public Quaternion(double x, double y, double z, double w) { - X = x; - Y = y; - Z = z; - W = w; - } + X = x; + Y = y; + Z = z; + W = w; + } /// /// Constructs a Quaternion from the given vector and rotation parts. @@ -64,11 +64,11 @@ public Quaternion(double x, double y, double z, double w) /// The rotation part of the Quaternion. public Quaternion(Vector3 vectorPart, double scalarPart) { - X = vectorPart.X; - Y = vectorPart.Y; - Z = vectorPart.Z; - W = scalarPart; - } + X = vectorPart.X; + Y = vectorPart.Y; + Z = vectorPart.Z; + W = scalarPart; + } /// /// Calculates the length of the Quaternion. @@ -76,10 +76,10 @@ public Quaternion(Vector3 vectorPart, double scalarPart) /// The computed length of the Quaternion. public double Length() { - double ls = X * X + Y * Y + Z * Z + W * W; + double ls = X * X + Y * Y + Z * Z + W * W; - return Math.Sqrt(ls); - } + return Math.Sqrt(ls); + } /// /// Calculates the length squared of the Quaternion. This operation is cheaper than Length(). @@ -94,19 +94,19 @@ public double Length() /// The normalized Quaternion. public static Quaternion Normalize(Quaternion value) { - Quaternion ans; + Quaternion ans; - double ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W; + double ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W; - double invNorm = 1.0 / Math.Sqrt(ls); + double invNorm = 1.0 / Math.Sqrt(ls); - ans.X = value.X * invNorm; - ans.Y = value.Y * invNorm; - ans.Z = value.Z * invNorm; - ans.W = value.W * invNorm; + ans.X = value.X * invNorm; + ans.Y = value.Y * invNorm; + ans.Z = value.Z * invNorm; + ans.W = value.W * invNorm; - return ans; - } + return ans; + } /// /// Creates the conjugate of a specified Quaternion. @@ -115,15 +115,15 @@ public static Quaternion Normalize(Quaternion value) /// A new Quaternion that is the conjugate of the specified one. public static Quaternion Conjugate(Quaternion value) { - Quaternion ans; + Quaternion ans; - ans.X = -value.X; - ans.Y = -value.Y; - ans.Z = -value.Z; - ans.W = value.W; + ans.X = -value.X; + ans.Y = -value.Y; + ans.Z = -value.Z; + ans.W = value.W; - return ans; - } + return ans; + } /// /// Returns the inverse of a Quaternion. @@ -132,22 +132,22 @@ public static Quaternion Conjugate(Quaternion value) /// The inverted Quaternion. public static Quaternion Inverse(Quaternion value) { - // -1 ( a -v ) - // q = ( ------------- ------------- ) - // ( a^2 + |v|^2 , a^2 + |v|^2 ) + // -1 ( a -v ) + // q = ( ------------- ------------- ) + // ( a^2 + |v|^2 , a^2 + |v|^2 ) - Quaternion ans; + Quaternion ans; - double ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W; - double invNorm = 1.0 / ls; + double ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W; + double invNorm = 1.0 / ls; - ans.X = -value.X * invNorm; - ans.Y = -value.Y * invNorm; - ans.Z = -value.Z * invNorm; - ans.W = value.W * invNorm; + ans.X = -value.X * invNorm; + ans.Y = -value.Y * invNorm; + ans.Z = -value.Z * invNorm; + ans.W = value.W * invNorm; - return ans; - } + return ans; + } /// /// Creates a Quaternion from a normalized vector axis and an angle to rotate about the vector. @@ -158,19 +158,19 @@ public static Quaternion Inverse(Quaternion value) /// The created Quaternion. public static Quaternion CreateFromAxisAngle(Vector3 axis, double angle) { - Quaternion ans; + Quaternion ans; - double halfAngle = angle * 0.5; - double s = Math.Sin(halfAngle); - double c = Math.Cos(halfAngle); + double halfAngle = angle * 0.5; + double s = Math.Sin(halfAngle); + double c = Math.Cos(halfAngle); - ans.X = axis.X * s; - ans.Y = axis.Y * s; - ans.Z = axis.Z * s; - ans.W = c; + ans.X = axis.X * s; + ans.Y = axis.Y * s; + ans.Z = axis.Z * s; + ans.W = c; - return ans; - } + return ans; + } /// /// Creates a new Quaternion from the given yaw, pitch, and roll, in radians. @@ -181,36 +181,36 @@ public static Quaternion CreateFromAxisAngle(Vector3 axis, double angle) /// public static Quaternion CreateFromYawPitchRoll(double yaw, double pitch, double roll) { - // Roll first, about axis the object is facing, then - // pitch upward, then yaw to face into the new heading - double sr, - cr, - sp, - cp, - sy, - cy; - - double halfRoll = roll * 0.5; - sr = Math.Sin(halfRoll); - cr = Math.Cos(halfRoll); - - double halfPitch = pitch * 0.5; - sp = Math.Sin(halfPitch); - cp = Math.Cos(halfPitch); - - double halfYaw = yaw * 0.5; - sy = Math.Sin(halfYaw); - cy = Math.Cos(halfYaw); - - Quaternion result; - - result.X = cy * sp * cr + sy * cp * sr; - result.Y = sy * cp * cr - cy * sp * sr; - result.Z = cy * cp * sr - sy * sp * cr; - result.W = cy * cp * cr + sy * sp * sr; - - return result; - } + // Roll first, about axis the object is facing, then + // pitch upward, then yaw to face into the new heading + double sr, + cr, + sp, + cp, + sy, + cy; + + double halfRoll = roll * 0.5; + sr = Math.Sin(halfRoll); + cr = Math.Cos(halfRoll); + + double halfPitch = pitch * 0.5; + sp = Math.Sin(halfPitch); + cp = Math.Cos(halfPitch); + + double halfYaw = yaw * 0.5; + sy = Math.Sin(halfYaw); + cy = Math.Cos(halfYaw); + + Quaternion result; + + result.X = cy * sp * cr + sy * cp * sr; + result.Y = sy * cp * cr - cy * sp * sr; + result.Z = cy * cp * sr - sy * sp * cr; + result.W = cy * cp * cr + sy * sp * sr; + + return result; + } /// /// Creates a Quaternion from the given rotation matrix. @@ -219,53 +219,53 @@ public static Quaternion CreateFromYawPitchRoll(double yaw, double pitch, double /// The created Quaternion. public static Quaternion CreateFromRotationMatrix(Matrix4x4 matrix) { - double trace = matrix.M11 + matrix.M22 + matrix.M33; - - Quaternion q = new(); - - if (trace > 0.0) + double trace = matrix.M11 + matrix.M22 + matrix.M33; + + Quaternion q = new(); + + if (trace > 0.0) + { + double s = Math.Sqrt(trace + 1.0); + q.W = s * 0.5; + s = 0.5 / s; + q.X = (matrix.M23 - matrix.M32) * s; + q.Y = (matrix.M31 - matrix.M13) * s; + q.Z = (matrix.M12 - matrix.M21) * s; + } + else + { + if (matrix.M11 >= matrix.M22 && matrix.M11 >= matrix.M33) + { + double s = Math.Sqrt(1.0 + matrix.M11 - matrix.M22 - matrix.M33); + double invS = 0.5 / s; + q.X = 0.5 * s; + q.Y = (matrix.M12 + matrix.M21) * invS; + q.Z = (matrix.M13 + matrix.M31) * invS; + q.W = (matrix.M23 - matrix.M32) * invS; + } + else if (matrix.M22 > matrix.M33) { - double s = Math.Sqrt(trace + 1.0); - q.W = s * 0.5; - s = 0.5 / s; - q.X = (matrix.M23 - matrix.M32) * s; - q.Y = (matrix.M31 - matrix.M13) * s; - q.Z = (matrix.M12 - matrix.M21) * s; + double s = Math.Sqrt(1.0 + matrix.M22 - matrix.M11 - matrix.M33); + double invS = 0.5 / s; + q.X = (matrix.M21 + matrix.M12) * invS; + q.Y = 0.5 * s; + q.Z = (matrix.M32 + matrix.M23) * invS; + q.W = (matrix.M31 - matrix.M13) * invS; } else { - if (matrix.M11 >= matrix.M22 && matrix.M11 >= matrix.M33) - { - double s = Math.Sqrt(1.0 + matrix.M11 - matrix.M22 - matrix.M33); - double invS = 0.5 / s; - q.X = 0.5 * s; - q.Y = (matrix.M12 + matrix.M21) * invS; - q.Z = (matrix.M13 + matrix.M31) * invS; - q.W = (matrix.M23 - matrix.M32) * invS; - } - else if (matrix.M22 > matrix.M33) - { - double s = Math.Sqrt(1.0 + matrix.M22 - matrix.M11 - matrix.M33); - double invS = 0.5 / s; - q.X = (matrix.M21 + matrix.M12) * invS; - q.Y = 0.5 * s; - q.Z = (matrix.M32 + matrix.M23) * invS; - q.W = (matrix.M31 - matrix.M13) * invS; - } - else - { - double s = Math.Sqrt(1.0 + matrix.M33 - matrix.M11 - matrix.M22); - double invS = 0.5 / s; - q.X = (matrix.M31 + matrix.M13) * invS; - q.Y = (matrix.M32 + matrix.M23) * invS; - q.Z = 0.5 * s; - q.W = (matrix.M12 - matrix.M21) * invS; - } + double s = Math.Sqrt(1.0 + matrix.M33 - matrix.M11 - matrix.M22); + double invS = 0.5 / s; + q.X = (matrix.M31 + matrix.M13) * invS; + q.Y = (matrix.M32 + matrix.M23) * invS; + q.Z = 0.5 * s; + q.W = (matrix.M12 - matrix.M21) * invS; } - - return q; } + return q; + } + /// /// Calculates the dot product of two Quaternions. /// @@ -287,51 +287,51 @@ public static double Dot(Quaternion quaternion1, Quaternion quaternion2) => /// The interpolated Quaternion. public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, double amount) { - const double epsilon = 1e-6; + const double epsilon = 1e-6; - double t = amount; + double t = amount; - double cosOmega = - quaternion1.X * quaternion2.X - + quaternion1.Y * quaternion2.Y - + quaternion1.Z * quaternion2.Z - + quaternion1.W * quaternion2.W; + double cosOmega = + quaternion1.X * quaternion2.X + + quaternion1.Y * quaternion2.Y + + quaternion1.Z * quaternion2.Z + + quaternion1.W * quaternion2.W; - bool flip = false; + bool flip = false; - if (cosOmega < 0.0) - { - flip = true; - cosOmega = -cosOmega; - } + if (cosOmega < 0.0) + { + flip = true; + cosOmega = -cosOmega; + } - double s1, - s2; + double s1, + s2; - if (cosOmega > (1.0 - epsilon)) - { - // Too close, do straight linear interpolation. - s1 = 1.0 - t; - s2 = (flip) ? -t : t; - } - else - { - double omega = Math.Acos(cosOmega); - double invSinOmega = 1 / Math.Sin(omega); + if (cosOmega > (1.0 - epsilon)) + { + // Too close, do straight linear interpolation. + s1 = 1.0 - t; + s2 = (flip) ? -t : t; + } + else + { + double omega = Math.Acos(cosOmega); + double invSinOmega = 1 / Math.Sin(omega); - s1 = Math.Sin((1.0 - t) * omega) * invSinOmega; - s2 = (flip) ? -Math.Sin(t * omega) * invSinOmega : Math.Sin(t * omega) * invSinOmega; - } + s1 = Math.Sin((1.0 - t) * omega) * invSinOmega; + s2 = (flip) ? -Math.Sin(t * omega) * invSinOmega : Math.Sin(t * omega) * invSinOmega; + } - Quaternion ans; + Quaternion ans; - ans.X = s1 * quaternion1.X + s2 * quaternion2.X; - ans.Y = s1 * quaternion1.Y + s2 * quaternion2.Y; - ans.Z = s1 * quaternion1.Z + s2 * quaternion2.Z; - ans.W = s1 * quaternion1.W + s2 * quaternion2.W; + ans.X = s1 * quaternion1.X + s2 * quaternion2.X; + ans.Y = s1 * quaternion1.Y + s2 * quaternion2.Y; + ans.Z = s1 * quaternion1.Z + s2 * quaternion2.Z; + ans.W = s1 * quaternion1.W + s2 * quaternion2.W; - return ans; - } + return ans; + } /// /// Linearly interpolates between two quaternions. @@ -342,43 +342,43 @@ public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, d /// The interpolated Quaternion. public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, double amount) { - double t = amount; - double t1 = 1.0 - t; - - Quaternion r = new(); - - double dot = - quaternion1.X * quaternion2.X - + quaternion1.Y * quaternion2.Y - + quaternion1.Z * quaternion2.Z - + quaternion1.W * quaternion2.W; - - if (dot >= 0.0) - { - r.X = t1 * quaternion1.X + t * quaternion2.X; - r.Y = t1 * quaternion1.Y + t * quaternion2.Y; - r.Z = t1 * quaternion1.Z + t * quaternion2.Z; - r.W = t1 * quaternion1.W + t * quaternion2.W; - } - else - { - r.X = t1 * quaternion1.X - t * quaternion2.X; - r.Y = t1 * quaternion1.Y - t * quaternion2.Y; - r.Z = t1 * quaternion1.Z - t * quaternion2.Z; - r.W = t1 * quaternion1.W - t * quaternion2.W; - } + double t = amount; + double t1 = 1.0 - t; + + Quaternion r = new(); + + double dot = + quaternion1.X * quaternion2.X + + quaternion1.Y * quaternion2.Y + + quaternion1.Z * quaternion2.Z + + quaternion1.W * quaternion2.W; + + if (dot >= 0.0) + { + r.X = t1 * quaternion1.X + t * quaternion2.X; + r.Y = t1 * quaternion1.Y + t * quaternion2.Y; + r.Z = t1 * quaternion1.Z + t * quaternion2.Z; + r.W = t1 * quaternion1.W + t * quaternion2.W; + } + else + { + r.X = t1 * quaternion1.X - t * quaternion2.X; + r.Y = t1 * quaternion1.Y - t * quaternion2.Y; + r.Z = t1 * quaternion1.Z - t * quaternion2.Z; + r.W = t1 * quaternion1.W - t * quaternion2.W; + } - // Normalize it. - double ls = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W; - double invNorm = 1.0 / Math.Sqrt(ls); + // Normalize it. + double ls = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W; + double invNorm = 1.0 / Math.Sqrt(ls); - r.X *= invNorm; - r.Y *= invNorm; - r.Z *= invNorm; - r.W *= invNorm; + r.X *= invNorm; + r.Y *= invNorm; + r.Z *= invNorm; + r.W *= invNorm; - return r; - } + return r; + } /// /// Concatenates two Quaternions; the result represents the value1 rotation followed by the value2 rotation. @@ -388,34 +388,34 @@ public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, do /// A new Quaternion representing the concatenation of the value1 rotation followed by the value2 rotation. public static Quaternion Concatenate(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - // Concatenate rotation is actually q2 * q1 instead of q1 * q2. - // So that's why value2 goes q1 and value1 goes q2. - double q1x = value2.X; - double q1y = value2.Y; - double q1z = value2.Z; - double q1w = value2.W; + // Concatenate rotation is actually q2 * q1 instead of q1 * q2. + // So that's why value2 goes q1 and value1 goes q2. + double q1x = value2.X; + double q1y = value2.Y; + double q1z = value2.Z; + double q1w = value2.W; - double q2x = value1.X; - double q2y = value1.Y; - double q2z = value1.Z; - double q2w = value1.W; + double q2x = value1.X; + double q2y = value1.Y; + double q2z = value1.Z; + double q2w = value1.W; - // cross(av, bv) - double cx = q1y * q2z - q1z * q2y; - double cy = q1z * q2x - q1x * q2z; - double cz = q1x * q2y - q1y * q2x; + // cross(av, bv) + double cx = q1y * q2z - q1z * q2y; + double cy = q1z * q2x - q1x * q2z; + double cz = q1x * q2y - q1y * q2x; - double dot = q1x * q2x + q1y * q2y + q1z * q2z; + double dot = q1x * q2x + q1y * q2y + q1z * q2z; - ans.X = q1x * q2w + q2x * q1w + cx; - ans.Y = q1y * q2w + q2y * q1w + cy; - ans.Z = q1z * q2w + q2z * q1w + cz; - ans.W = q1w * q2w - dot; + ans.X = q1x * q2w + q2x * q1w + cx; + ans.Y = q1y * q2w + q2y * q1w + cy; + ans.Z = q1z * q2w + q2z * q1w + cz; + ans.W = q1w * q2w - dot; - return ans; - } + return ans; + } /// /// Flips the sign of each component of the quaternion. @@ -424,15 +424,15 @@ public static Quaternion Concatenate(Quaternion value1, Quaternion value2) /// The negated Quaternion. public static Quaternion Negate(Quaternion value) { - Quaternion ans; + Quaternion ans; - ans.X = -value.X; - ans.Y = -value.Y; - ans.Z = -value.Z; - ans.W = -value.W; + ans.X = -value.X; + ans.Y = -value.Y; + ans.Z = -value.Z; + ans.W = -value.W; - return ans; - } + return ans; + } /// /// Adds two Quaternions element-by-element. @@ -442,15 +442,15 @@ public static Quaternion Negate(Quaternion value) /// The result of adding the Quaternions. public static Quaternion Add(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X + value2.X; - ans.Y = value1.Y + value2.Y; - ans.Z = value1.Z + value2.Z; - ans.W = value1.W + value2.W; + ans.X = value1.X + value2.X; + ans.Y = value1.Y + value2.Y; + ans.Z = value1.Z + value2.Z; + ans.W = value1.W + value2.W; - return ans; - } + return ans; + } /// /// Subtracts one Quaternion from another. @@ -460,15 +460,15 @@ public static Quaternion Add(Quaternion value1, Quaternion value2) /// The result of the subtraction. public static Quaternion Subtract(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X - value2.X; - ans.Y = value1.Y - value2.Y; - ans.Z = value1.Z - value2.Z; - ans.W = value1.W - value2.W; + ans.X = value1.X - value2.X; + ans.Y = value1.Y - value2.Y; + ans.Z = value1.Z - value2.Z; + ans.W = value1.W - value2.W; - return ans; - } + return ans; + } /// /// Multiplies two Quaternions together. @@ -478,32 +478,32 @@ public static Quaternion Subtract(Quaternion value1, Quaternion value2) /// The result of the multiplication. public static Quaternion Multiply(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - double q1x = value1.X; - double q1y = value1.Y; - double q1z = value1.Z; - double q1w = value1.W; + double q1x = value1.X; + double q1y = value1.Y; + double q1z = value1.Z; + double q1w = value1.W; - double q2x = value2.X; - double q2y = value2.Y; - double q2z = value2.Z; - double q2w = value2.W; + double q2x = value2.X; + double q2y = value2.Y; + double q2z = value2.Z; + double q2w = value2.W; - // cross(av, bv) - double cx = q1y * q2z - q1z * q2y; - double cy = q1z * q2x - q1x * q2z; - double cz = q1x * q2y - q1y * q2x; + // cross(av, bv) + double cx = q1y * q2z - q1z * q2y; + double cy = q1z * q2x - q1x * q2z; + double cz = q1x * q2y - q1y * q2x; - double dot = q1x * q2x + q1y * q2y + q1z * q2z; + double dot = q1x * q2x + q1y * q2y + q1z * q2z; - ans.X = q1x * q2w + q2x * q1w + cx; - ans.Y = q1y * q2w + q2y * q1w + cy; - ans.Z = q1z * q2w + q2z * q1w + cz; - ans.W = q1w * q2w - dot; + ans.X = q1x * q2w + q2x * q1w + cx; + ans.Y = q1y * q2w + q2y * q1w + cy; + ans.Z = q1z * q2w + q2z * q1w + cz; + ans.W = q1w * q2w - dot; - return ans; - } + return ans; + } /// /// Multiplies a Quaternion by a scalar value. @@ -513,15 +513,15 @@ public static Quaternion Multiply(Quaternion value1, Quaternion value2) /// The result of the multiplication. public static Quaternion Multiply(Quaternion value1, double value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X * value2; - ans.Y = value1.Y * value2; - ans.Z = value1.Z * value2; - ans.W = value1.W * value2; + ans.X = value1.X * value2; + ans.Y = value1.Y * value2; + ans.Z = value1.Z * value2; + ans.W = value1.W * value2; - return ans; - } + return ans; + } /// /// Divides a Quaternion by another Quaternion. @@ -531,40 +531,40 @@ public static Quaternion Multiply(Quaternion value1, double value2) /// The result of the division. public static Quaternion Divide(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - double q1x = value1.X; - double q1y = value1.Y; - double q1z = value1.Z; - double q1w = value1.W; + double q1x = value1.X; + double q1y = value1.Y; + double q1z = value1.Z; + double q1w = value1.W; - //------------------------------------- - // Inverse part. - double ls = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W; - double invNorm = 1.0 / ls; + //------------------------------------- + // Inverse part. + double ls = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W; + double invNorm = 1.0 / ls; - double q2x = -value2.X * invNorm; - double q2y = -value2.Y * invNorm; - double q2z = -value2.Z * invNorm; - double q2w = value2.W * invNorm; + double q2x = -value2.X * invNorm; + double q2y = -value2.Y * invNorm; + double q2z = -value2.Z * invNorm; + double q2w = value2.W * invNorm; - //------------------------------------- - // Multiply part. + //------------------------------------- + // Multiply part. - // cross(av, bv) - double cx = q1y * q2z - q1z * q2y; - double cy = q1z * q2x - q1x * q2z; - double cz = q1x * q2y - q1y * q2x; + // cross(av, bv) + double cx = q1y * q2z - q1z * q2y; + double cy = q1z * q2x - q1x * q2z; + double cz = q1x * q2y - q1y * q2x; - double dot = q1x * q2x + q1y * q2y + q1z * q2z; + double dot = q1x * q2x + q1y * q2y + q1z * q2z; - ans.X = q1x * q2w + q2x * q1w + cx; - ans.Y = q1y * q2w + q2y * q1w + cy; - ans.Z = q1z * q2w + q2z * q1w + cz; - ans.W = q1w * q2w - dot; + ans.X = q1x * q2w + q2x * q1w + cx; + ans.Y = q1y * q2w + q2y * q1w + cy; + ans.Z = q1z * q2w + q2z * q1w + cz; + ans.W = q1w * q2w - dot; - return ans; - } + return ans; + } /// /// Flips the sign of each component of the quaternion. @@ -573,15 +573,15 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The negated Quaternion. public static Quaternion operator -(Quaternion value) { - Quaternion ans; + Quaternion ans; - ans.X = -value.X; - ans.Y = -value.Y; - ans.Z = -value.Z; - ans.W = -value.W; + ans.X = -value.X; + ans.Y = -value.Y; + ans.Z = -value.Z; + ans.W = -value.W; - return ans; - } + return ans; + } /// /// Adds two Quaternions element-by-element. @@ -591,15 +591,15 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The result of adding the Quaternions. public static Quaternion operator +(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X + value2.X; - ans.Y = value1.Y + value2.Y; - ans.Z = value1.Z + value2.Z; - ans.W = value1.W + value2.W; + ans.X = value1.X + value2.X; + ans.Y = value1.Y + value2.Y; + ans.Z = value1.Z + value2.Z; + ans.W = value1.W + value2.W; - return ans; - } + return ans; + } /// /// Subtracts one Quaternion from another. @@ -609,15 +609,15 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The result of the subtraction. public static Quaternion operator -(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X - value2.X; - ans.Y = value1.Y - value2.Y; - ans.Z = value1.Z - value2.Z; - ans.W = value1.W - value2.W; + ans.X = value1.X - value2.X; + ans.Y = value1.Y - value2.Y; + ans.Z = value1.Z - value2.Z; + ans.W = value1.W - value2.W; - return ans; - } + return ans; + } /// /// Multiplies two Quaternions together. @@ -627,32 +627,32 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The result of the multiplication. public static Quaternion operator *(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - double q1x = value1.X; - double q1y = value1.Y; - double q1z = value1.Z; - double q1w = value1.W; + double q1x = value1.X; + double q1y = value1.Y; + double q1z = value1.Z; + double q1w = value1.W; - double q2x = value2.X; - double q2y = value2.Y; - double q2z = value2.Z; - double q2w = value2.W; + double q2x = value2.X; + double q2y = value2.Y; + double q2z = value2.Z; + double q2w = value2.W; - // cross(av, bv) - double cx = q1y * q2z - q1z * q2y; - double cy = q1z * q2x - q1x * q2z; - double cz = q1x * q2y - q1y * q2x; + // cross(av, bv) + double cx = q1y * q2z - q1z * q2y; + double cy = q1z * q2x - q1x * q2z; + double cz = q1x * q2y - q1y * q2x; - double dot = q1x * q2x + q1y * q2y + q1z * q2z; + double dot = q1x * q2x + q1y * q2y + q1z * q2z; - ans.X = q1x * q2w + q2x * q1w + cx; - ans.Y = q1y * q2w + q2y * q1w + cy; - ans.Z = q1z * q2w + q2z * q1w + cz; - ans.W = q1w * q2w - dot; + ans.X = q1x * q2w + q2x * q1w + cx; + ans.Y = q1y * q2w + q2y * q1w + cy; + ans.Z = q1z * q2w + q2z * q1w + cz; + ans.W = q1w * q2w - dot; - return ans; - } + return ans; + } /// /// Multiplies a Quaternion by a scalar value. @@ -662,15 +662,15 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The result of the multiplication. public static Quaternion operator *(Quaternion value1, double value2) { - Quaternion ans; + Quaternion ans; - ans.X = value1.X * value2; - ans.Y = value1.Y * value2; - ans.Z = value1.Z * value2; - ans.W = value1.W * value2; + ans.X = value1.X * value2; + ans.Y = value1.Y * value2; + ans.Z = value1.Z * value2; + ans.W = value1.W * value2; - return ans; - } + return ans; + } /// /// Divides a Quaternion by another Quaternion. @@ -680,40 +680,40 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The result of the division. public static Quaternion operator /(Quaternion value1, Quaternion value2) { - Quaternion ans; + Quaternion ans; - double q1x = value1.X; - double q1y = value1.Y; - double q1z = value1.Z; - double q1w = value1.W; + double q1x = value1.X; + double q1y = value1.Y; + double q1z = value1.Z; + double q1w = value1.W; - //------------------------------------- - // Inverse part. - double ls = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W; - double invNorm = 1.0 / ls; + //------------------------------------- + // Inverse part. + double ls = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W; + double invNorm = 1.0 / ls; - double q2x = -value2.X * invNorm; - double q2y = -value2.Y * invNorm; - double q2z = -value2.Z * invNorm; - double q2w = value2.W * invNorm; + double q2x = -value2.X * invNorm; + double q2y = -value2.Y * invNorm; + double q2z = -value2.Z * invNorm; + double q2w = value2.W * invNorm; - //------------------------------------- - // Multiply part. + //------------------------------------- + // Multiply part. - // cross(av, bv) - double cx = q1y * q2z - q1z * q2y; - double cy = q1z * q2x - q1x * q2z; - double cz = q1x * q2y - q1y * q2x; + // cross(av, bv) + double cx = q1y * q2z - q1z * q2y; + double cy = q1z * q2x - q1x * q2z; + double cz = q1x * q2y - q1y * q2x; - double dot = q1x * q2x + q1y * q2y + q1z * q2z; + double dot = q1x * q2x + q1y * q2y + q1z * q2z; - ans.X = q1x * q2w + q2x * q1w + cx; - ans.Y = q1y * q2w + q2y * q1w + cy; - ans.Z = q1z * q2w + q2z * q1w + cz; - ans.W = q1w * q2w - dot; + ans.X = q1x * q2w + q2x * q1w + cx; + ans.Y = q1y * q2w + q2y * q1w + cy; + ans.Z = q1z * q2w + q2z * q1w + cz; + ans.W = q1w * q2w - dot; - return ans; - } + return ans; + } /// /// Returns a boolean indicating whether the two given Quaternions are equal. @@ -721,7 +721,8 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The first Quaternion to compare. /// The second Quaternion to compare. /// True if the Quaternions are equal; False otherwise. - public static bool operator ==(Quaternion value1, Quaternion value2) => (value1.X == value2.X && value1.Y == value2.Y && value1.Z == value2.Z && value1.W == value2.W); + public static bool operator ==(Quaternion value1, Quaternion value2) => + (value1.X == value2.X && value1.Y == value2.Y && value1.Z == value2.Z && value1.W == value2.W); /// /// Returns a boolean indicating whether the two given Quaternions are not equal. @@ -729,7 +730,8 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// The first Quaternion to compare. /// The second Quaternion to compare. /// True if the Quaternions are not equal; False if they are equal. - public static bool operator !=(Quaternion value1, Quaternion value2) => (value1.X != value2.X || value1.Y != value2.Y || value1.Z != value2.Z || value1.W != value2.W); + public static bool operator !=(Quaternion value1, Quaternion value2) => + (value1.X != value2.X || value1.Y != value2.Y || value1.Z != value2.Z || value1.W != value2.W); /// /// Returns a boolean indicating whether the given Quaternion is equal to this Quaternion instance. @@ -745,35 +747,35 @@ public static Quaternion Divide(Quaternion value1, Quaternion value2) /// True if the Object is equal to this Quaternion; False otherwise. public override bool Equals(object? obj) { - if (obj is Quaternion quaternion) - { - return Equals(quaternion); - } - - return false; + if (obj is Quaternion quaternion) + { + return Equals(quaternion); } + return false; + } + /// /// Returns a String representing this Quaternion instance. /// /// The string representation. public override string ToString() { - CultureInfo ci = CultureInfo.CurrentCulture; - - return String.Format( - ci, - "{{X:{0} Y:{1} Z:{2} W:{3}}}", - X.ToString(ci), - Y.ToString(ci), - Z.ToString(ci), - W.ToString(ci) - ); - } + CultureInfo ci = CultureInfo.CurrentCulture; + + return String.Format( + ci, + "{{X:{0} Y:{1} Z:{2} W:{3}}}", + X.ToString(ci), + Y.ToString(ci), + Z.ToString(ci), + W.ToString(ci) + ); + } /// /// Returns the hash code for this instance. /// /// The hash code. public override int GetHashCode() => X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode(); -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Vector2.cs b/Speckle.DoubleNumerics/Vector2.cs index c3dcfa1..a4b448a 100644 --- a/Speckle.DoubleNumerics/Vector2.cs +++ b/Speckle.DoubleNumerics/Vector2.cs @@ -205,7 +205,8 @@ public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max) /// Value between 0 and 1 indicating the weight of the second source vector. /// The interpolated vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 Lerp(Vector2 value1, Vector2 value2, double amount) => new(value1.X + (value2.X - value1.X) * amount, value1.Y + (value2.Y - value1.Y) * amount); + public static Vector2 Lerp(Vector2 value1, Vector2 value2, double amount) => + new(value1.X + (value2.X - value1.X) * amount, value1.Y + (value2.Y - value1.Y) * amount); /// /// Transforms a vector by the given matrix. @@ -240,7 +241,8 @@ public static Vector2 Transform(Vector2 position, Matrix4x4 matrix) => /// The transformation matrix. /// The transformed vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 TransformNormal(Vector2 normal, Matrix3x2 matrix) => new(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22); + public static Vector2 TransformNormal(Vector2 normal, Matrix3x2 matrix) => + new(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22); /// /// Transforms a vector normal by the given matrix. @@ -249,7 +251,8 @@ public static Vector2 Transform(Vector2 position, Matrix4x4 matrix) => /// The transformation matrix. /// The transformed vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 matrix) => new(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22); + public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 matrix) => + new(normal.X * matrix.M11 + normal.Y * matrix.M21, normal.X * matrix.M12 + normal.Y * matrix.M22); /// /// Transforms a vector by the given Quaternion rotation value. diff --git a/Speckle.DoubleNumerics/Vector2_Intrinsics.cs b/Speckle.DoubleNumerics/Vector2_Intrinsics.cs index aa5d525..a437a5e 100644 --- a/Speckle.DoubleNumerics/Vector2_Intrinsics.cs +++ b/Speckle.DoubleNumerics/Vector2_Intrinsics.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; namespace Speckle.DoubleNumerics; + // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler. // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic. // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member. @@ -37,9 +38,9 @@ public Vector2(Double value) /// The Y component. public Vector2(Double x, Double y) { - X = x; - Y = y; - } + X = x; + Y = y; + } #endregion Constructors #region Public Instance Methods @@ -60,25 +61,25 @@ public Vector2(Double x, Double y) /// or if there are not enough elements to copy. public void CopyTo(Double[]? array, int index) { - if (array == null) - { - // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull. - throw new NullReferenceException(Strings.Arg_NullArgumentNullRef); - } - if (index < 0 || index >= array.Length) - { - throw new ArgumentOutOfRangeException( - nameof(index), - String.Format(Strings.Arg_ArgumentOutOfRangeException, index) - ); - } - if ((array.Length - index) < 2) - { - throw new ArgumentException(String.Format(Strings.Arg_ElementsInSourceIsGreaterThanDestination, index)); - } - array[index] = X; - array[index + 1] = Y; + if (array == null) + { + // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull. + throw new NullReferenceException(Strings.Arg_NullArgumentNullRef); + } + if (index < 0 || index >= array.Length) + { + throw new ArgumentOutOfRangeException( + nameof(index), + String.Format(Strings.Arg_ArgumentOutOfRangeException, index) + ); } + if ((array.Length - index) < 2) + { + throw new ArgumentException(String.Format(Strings.Arg_ElementsInSourceIsGreaterThanDestination, index)); + } + array[index] = X; + array[index + 1] = Y; + } /// /// Returns a boolean indicating whether the given Vector2 is equal to this Vector2 instance. @@ -106,7 +107,8 @@ public void CopyTo(Double[]? array, int index) /// The second source vector. /// The minimized vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 Min(Vector2 value1, Vector2 value2) => new((value1.X < value2.X) ? value1.X : value2.X, (value1.Y < value2.Y) ? value1.Y : value2.Y); + public static Vector2 Min(Vector2 value1, Vector2 value2) => + new((value1.X < value2.X) ? value1.X : value2.X, (value1.Y < value2.Y) ? value1.Y : value2.Y); /// /// Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors @@ -115,7 +117,8 @@ public void CopyTo(Double[]? array, int index) /// The second source vector /// The maximized vector [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector2 Max(Vector2 value1, Vector2 value2) => new((value1.X > value2.X) ? value1.X : value2.X, (value1.Y > value2.Y) ? value1.Y : value2.Y); + public static Vector2 Max(Vector2 value1, Vector2 value2) => + new((value1.X > value2.X) ? value1.X : value2.X, (value1.Y > value2.Y) ? value1.Y : value2.Y); /// /// Returns a vector whose elements are the absolute values of each of the source vector's elements. @@ -199,9 +202,9 @@ public void CopyTo(Double[]? array, int index) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector2 operator /(Vector2 value1, double value2) { - double invDiv = 1.0 / value2; - return new Vector2(value1.X * invDiv, value1.Y * invDiv); - } + double invDiv = 1.0 / value2; + return new Vector2(value1.X * invDiv, value1.Y * invDiv); + } /// /// Negates a given vector. @@ -230,4 +233,4 @@ public void CopyTo(Double[]? array, int index) public static bool operator !=(Vector2 left, Vector2 right) => !(left == right); #endregion Public Static Operators -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Vector3.cs b/Speckle.DoubleNumerics/Vector3.cs index 8b904d7..d6e693e 100644 --- a/Speckle.DoubleNumerics/Vector3.cs +++ b/Speckle.DoubleNumerics/Vector3.cs @@ -381,4 +381,4 @@ public static Vector3 Transform(Vector3 value, Quaternion rotation) public static Vector3 Negate(Vector3 value) => -value; #endregion Public operator methods -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Vector3_Intrinsics.cs b/Speckle.DoubleNumerics/Vector3_Intrinsics.cs index 06d0f53..a53b74b 100644 --- a/Speckle.DoubleNumerics/Vector3_Intrinsics.cs +++ b/Speckle.DoubleNumerics/Vector3_Intrinsics.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; namespace Speckle.DoubleNumerics; + // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler. // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic. // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member. @@ -113,7 +114,8 @@ public void CopyTo(Double[]? array, int index) /// The second vector. /// The dot product. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Vector3 vector1, Vector3 vector2) => vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; + public static double Dot(Vector3 vector1, Vector3 vector2) => + vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; /// /// Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors. @@ -168,7 +170,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second source vector. /// The summed vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector3 operator +(Vector3 left, Vector3 right) => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + public static Vector3 operator +(Vector3 left, Vector3 right) => + new(left.X + right.X, left.Y + right.Y, left.Z + right.Z); /// /// Subtracts the second vector from the first. @@ -177,7 +180,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second source vector. /// The difference vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector3 operator -(Vector3 left, Vector3 right) => new(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + public static Vector3 operator -(Vector3 left, Vector3 right) => + new(left.X - right.X, left.Y - right.Y, left.Z - right.Z); /// /// Multiplies two vectors together. @@ -186,7 +190,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second source vector. /// The product vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector3 operator *(Vector3 left, Vector3 right) => new(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + public static Vector3 operator *(Vector3 left, Vector3 right) => + new(left.X * right.X, left.Y * right.Y, left.Z * right.Z); /// /// Multiplies a vector by the given scalar. @@ -213,7 +218,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second source vector. /// The vector resulting from the division. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector3 operator /(Vector3 left, Vector3 right) => new(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + public static Vector3 operator /(Vector3 left, Vector3 right) => + new(left.X / right.X, left.Y / right.Y, left.Z / right.Z); /// /// Divides the vector by the given scalar. @@ -244,7 +250,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second vector to compare. /// True if the vectors are equal; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Vector3 left, Vector3 right) => (left.X == right.X && left.Y == right.Y && left.Z == right.Z); + public static bool operator ==(Vector3 left, Vector3 right) => + (left.X == right.X && left.Y == right.Y && left.Z == right.Z); /// /// Returns a boolean indicating whether the two given vectors are not equal. @@ -253,7 +260,8 @@ public static Vector3 Max(Vector3 value1, Vector3 value2) => /// The second vector to compare. /// True if the vectors are not equal; False if they are equal. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(Vector3 left, Vector3 right) => (left.X != right.X || left.Y != right.Y || left.Z != right.Z); + public static bool operator !=(Vector3 left, Vector3 right) => + (left.X != right.X || left.Y != right.Y || left.Z != right.Z); #endregion Public Static Operators -} \ No newline at end of file +} diff --git a/Speckle.DoubleNumerics/Vector4_Intrinsics.cs b/Speckle.DoubleNumerics/Vector4_Intrinsics.cs index 1934210..6d51ed8 100644 --- a/Speckle.DoubleNumerics/Vector4_Intrinsics.cs +++ b/Speckle.DoubleNumerics/Vector4_Intrinsics.cs @@ -5,6 +5,7 @@ using System.Runtime.CompilerServices; namespace Speckle.DoubleNumerics; + // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler. // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic. // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member. @@ -140,7 +141,8 @@ public void CopyTo(Double[]? array, int index) /// The second vector. /// The dot product. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Vector4 vector1, Vector4 vector2) => vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; + public static double Dot(Vector4 vector1, Vector4 vector2) => + vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; /// /// Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors. @@ -178,7 +180,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The source vector. /// The absolute value vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 Abs(Vector4 value) => new(Math.Abs(value.X), Math.Abs(value.Y), Math.Abs(value.Z), Math.Abs(value.W)); + public static Vector4 Abs(Vector4 value) => + new(Math.Abs(value.X), Math.Abs(value.Y), Math.Abs(value.Z), Math.Abs(value.W)); /// /// Returns a vector whose elements are the square root of each of the source vector's elements. @@ -186,7 +189,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The source vector. /// The square root vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 SquareRoot(Vector4 value) => new(Math.Sqrt(value.X), Math.Sqrt(value.Y), Math.Sqrt(value.Z), Math.Sqrt(value.W)); + public static Vector4 SquareRoot(Vector4 value) => + new(Math.Sqrt(value.X), Math.Sqrt(value.Y), Math.Sqrt(value.Z), Math.Sqrt(value.W)); #endregion Public Static Methods @@ -198,7 +202,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The second source vector. /// The summed vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 operator +(Vector4 left, Vector4 right) => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + public static Vector4 operator +(Vector4 left, Vector4 right) => + new(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); /// /// Subtracts the second vector from the first. @@ -207,7 +212,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The second source vector. /// The difference vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 operator -(Vector4 left, Vector4 right) => new(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + public static Vector4 operator -(Vector4 left, Vector4 right) => + new(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); /// /// Multiplies two vectors together. @@ -216,7 +222,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The second source vector. /// The product vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 operator *(Vector4 left, Vector4 right) => new(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + public static Vector4 operator *(Vector4 left, Vector4 right) => + new(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); /// /// Multiplies a vector by the given scalar. @@ -243,7 +250,8 @@ public static Vector4 Max(Vector4 value1, Vector4 value2) => /// The second source vector. /// The vector resulting from the division. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 operator /(Vector4 left, Vector4 right) => new(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + public static Vector4 operator /(Vector4 left, Vector4 right) => + new(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); /// /// Divides the vector by the given scalar.