diff --git a/BGC.Net.sln b/BasicGeometry.Net.sln similarity index 78% rename from BGC.Net.sln rename to BasicGeometry.Net.sln index e3c2cb2..2801b93 100644 --- a/BGC.Net.sln +++ b/BasicGeometry.Net.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGC", "BGC\BGC.csproj", "{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicGeometry", "BasicGeometry\BasicGeometry.csproj", "{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGCDev", "BGCDev\BGCDev.csproj", "{3D09FF57-02E6-449D-9DE7-0843633FCBA0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicGeometryDev", "BasicGeometryDev\BasicGeometryDev.csproj", "{3D09FF57-02E6-449D-9DE7-0843633FCBA0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGCTest", "BGCTest\BGCTest.csproj", "{51A07B27-43FF-4A12-AEC1-50D32EDA3815}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicGeometryTest", "BasicGeometryTest\BasicGeometryTest.csproj", "{51A07B27-43FF-4A12-AEC1-50D32EDA3815}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BGC/Angle.cs b/BasicGeometry/Angle.cs similarity index 98% rename from BGC/Angle.cs rename to BasicGeometry/Angle.cs index cc23133..8861d61 100644 --- a/BGC/Angle.cs +++ b/BasicGeometry/Angle.cs @@ -20,7 +20,7 @@ * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public enum AngleUnit { diff --git a/BGC/BGC.csproj b/BasicGeometry/BasicGeometry.csproj similarity index 100% rename from BGC/BGC.csproj rename to BasicGeometry/BasicGeometry.csproj diff --git a/BGC/FP32Angle.cs b/BasicGeometry/FP32Angle.cs similarity index 99% rename from BGC/FP32Angle.cs rename to BasicGeometry/FP32Angle.cs index 8a3846d..6962498 100644 --- a/BGC/FP32Angle.cs +++ b/BasicGeometry/FP32Angle.cs @@ -21,7 +21,7 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public static class FP32Angle { diff --git a/BGC/FP32Degrees.cs b/BasicGeometry/FP32Degrees.cs similarity index 98% rename from BGC/FP32Degrees.cs rename to BasicGeometry/FP32Degrees.cs index 3773ceb..4fa98b0 100644 --- a/BGC/FP32Degrees.cs +++ b/BasicGeometry/FP32Degrees.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP32Degrees { diff --git a/BGC/FP32Matrix2x2.cs b/BasicGeometry/FP32Matrix2x2.cs similarity index 89% rename from BGC/FP32Matrix2x2.cs rename to BasicGeometry/FP32Matrix2x2.cs index 0320d1b..e8ab41c 100644 --- a/BGC/FP32Matrix2x2.cs +++ b/BasicGeometry/FP32Matrix2x2.cs @@ -21,29 +21,16 @@ using System; * Date: 10 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP32Matrix2x2 { - public float r1c1, r1c2; - - public float r2c1, r2c2; - - public FP32Matrix2x2() - { - this.r1c1 = 0.0f; - this.r1c2 = 0.0f; - - this.r2c1 = 0.0f; - this.r2c2 = 0.0f; - } + public float r1c1 = 0.0f, r1c2 = 0.0f; + public float r2c1 = 0.0f, r2c2 = 0.0f; public FP32Matrix2x2(float d1, float d2) { this.r1c1 = d1; - this.r1c2 = 0.0f; - - this.r2c1 = 0.0f; this.r2c2 = d2; } @@ -96,11 +83,13 @@ namespace BGC float r2c1 = -this.r2c1; float r2c2 = this.r1c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; + float multiplier = 1.0f / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; + this.r1c1 = r1c1 * multiplier; + this.r1c2 = r1c2 * multiplier; + + this.r2c1 = r2c1 * multiplier; + this.r2c2 = r2c2 * multiplier; return true; } @@ -181,11 +170,13 @@ namespace BGC float r2c1 = -matrix.r2c1; float r2c2 = matrix.r1c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; + float multiplier = 1.0f / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; + this.r1c1 = r1c1 * multiplier; + this.r1c2 = r1c2 * multiplier; + + this.r2c1 = r2c1 * multiplier; + this.r2c2 = r2c2 * multiplier; return true; } @@ -252,11 +243,7 @@ namespace BGC public static void Divide(in FP32Matrix2x2 dividend, float divisor, out FP32Matrix2x2 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetRightProduct(in FP32Matrix2x2 matrix, in FP32Vector2 vector, out FP32Vector2 result) diff --git a/BGC/FP32Matrix2x3.cs b/BasicGeometry/FP32Matrix2x3.cs similarity index 91% rename from BGC/FP32Matrix2x3.cs rename to BasicGeometry/FP32Matrix2x3.cs index 9d20a22..90f1f63 100644 --- a/BGC/FP32Matrix2x3.cs +++ b/BasicGeometry/FP32Matrix2x3.cs @@ -20,25 +20,13 @@ using System; * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP32Matrix2x3 { - public float r1c1, r1c2; - public float r2c1, r2c2; - public float r3c1, r3c2; - - public FP32Matrix2x3() - { - this.r1c1 = 0.0f; - this.r1c2 = 0.0f; - - this.r2c1 = 0.0f; - this.r2c2 = 0.0f; - - this.r3c1 = 0.0f; - this.r3c2 = 0.0f; - } + public float r1c1 = 0.0f, r1c2 = 0.0f; + public float r2c1 = 0.0f, r2c2 = 0.0f; + public float r3c1 = 0.0f, r3c2 = 0.0f; public FP32Matrix2x3(in FP32Matrix2x3 matrix) { @@ -230,14 +218,7 @@ namespace BGC public static void Divide(in FP32Matrix2x3 dividend, float divisor, out FP32Matrix2x3 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - - quotient.r3c1 = dividend.r3c1 / divisor; - quotient.r3c2 = dividend.r3c2 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetRightProduct(in FP32Matrix2x3 matrix, in FP32Vector2 vector, out FP32Vector3 result) diff --git a/BGC/FP32Matrix3x2.cs b/BasicGeometry/FP32Matrix3x2.cs similarity index 91% rename from BGC/FP32Matrix3x2.cs rename to BasicGeometry/FP32Matrix3x2.cs index 09c8570..eeac152 100644 --- a/BGC/FP32Matrix3x2.cs +++ b/BasicGeometry/FP32Matrix3x2.cs @@ -18,23 +18,12 @@ * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP32Matrix3x2 { - public float r1c1, r1c2, r1c3; - public float r2c1, r2c2, r2c3; - - public FP32Matrix3x2() - { - this.r1c1 = 0.0f; - this.r1c2 = 0.0f; - this.r1c3 = 0.0f; - - this.r2c1 = 0.0f; - this.r2c2 = 0.0f; - this.r2c3 = 0.0f; - } + public float r1c1 = 0.0f, r1c2 = 0.0f, r1c3 = 0.0f; + public float r2c1 = 0.0f, r2c2 = 0.0f, r2c3 = 0.0f; public FP32Matrix3x2(in FP32Matrix3x2 matrix) { @@ -213,13 +202,7 @@ namespace BGC public static void Divide(in FP32Matrix3x2 dividend, float divisor, out FP32Matrix3x2 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - quotient.r1c3 = dividend.r1c3 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - quotient.r2c3 = dividend.r2c3 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetRightProduct(in FP32Matrix3x2 matrix, in FP32Vector3 vector, out FP32Vector2 result) diff --git a/BGC/FP32Matrix3x3.cs b/BasicGeometry/FP32Matrix3x3.cs similarity index 87% rename from BGC/FP32Matrix3x3.cs rename to BasicGeometry/FP32Matrix3x3.cs index 42d8d53..5eb1f00 100644 --- a/BGC/FP32Matrix3x3.cs +++ b/BasicGeometry/FP32Matrix3x3.cs @@ -21,43 +21,18 @@ using System; * Date: 10 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP32Matrix3x3 { - public float r1c1, r1c2, r1c3; - - public float r2c1, r2c2, r2c3; - - public float r3c1, r3c2, r3c3; - - public FP32Matrix3x3() - { - this.r1c1 = 0.0f; - this.r1c2 = 0.0f; - this.r1c3 = 0.0f; - - this.r2c1 = 0.0f; - this.r2c2 = 0.0f; - this.r2c3 = 0.0f; - - this.r3c1 = 0.0f; - this.r3c2 = 0.0f; - this.r3c3 = 0.0f; - } + public float r1c1 = 0.0f, r1c2 = 0.0f, r1c3 = 0.0f; + public float r2c1 = 0.0f, r2c2 = 0.0f, r2c3 = 0.0f; + public float r3c1 = 0.0f, r3c2 = 0.0f, r3c3 = 0.0f; public FP32Matrix3x3(float d1, float d2, float d3) { this.r1c1 = d1; - this.r1c2 = 0.0f; - this.r1c3 = 0.0f; - - this.r2c1 = 0.0f; this.r2c2 = d2; - this.r2c3 = 0.0f; - - this.r3c1 = 0.0f; - this.r3c2 = 0.0f; this.r3c3 = d3; } @@ -131,17 +106,19 @@ namespace BGC float r3c2 = this.r1c2 * this.r3c1 - this.r1c1 * this.r3c2; float r3c3 = this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; - this.r1c3 = r1c3 / determinant; + float mutiplier = 1.0f / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; - this.r2c3 = r2c3 / determinant; + this.r1c1 = r1c1 * mutiplier; + this.r1c2 = r1c2 * mutiplier; + this.r1c3 = r1c3 * mutiplier; - this.r3c1 = r3c1 / determinant; - this.r3c2 = r3c2 / determinant; - this.r3c3 = r3c3 / determinant; + this.r2c1 = r2c1 * mutiplier; + this.r2c2 = r2c2 * mutiplier; + this.r2c3 = r2c3 * mutiplier; + + this.r3c1 = r3c1 * mutiplier; + this.r3c2 = r3c2 * mutiplier; + this.r3c3 = r3c3 * mutiplier; return true; } @@ -267,17 +244,19 @@ namespace BGC float r3c2 = matrix.r1c2 * matrix.r3c1 - matrix.r1c1 * matrix.r3c2; float r3c3 = matrix.r1c1 * matrix.r2c2 - matrix.r1c2 * matrix.r2c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; - this.r1c3 = r1c3 / determinant; + float mutiplier = 1.0f / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; - this.r2c3 = r2c3 / determinant; + this.r1c1 = r1c1 * mutiplier; + this.r1c2 = r1c2 * mutiplier; + this.r1c3 = r1c3 * mutiplier; - this.r3c1 = r3c1 / determinant; - this.r3c2 = r3c2 / determinant; - this.r3c3 = r3c3 / determinant; + this.r2c1 = r2c1 * mutiplier; + this.r2c2 = r2c2 * mutiplier; + this.r2c3 = r2c3 * mutiplier; + + this.r3c1 = r3c1 * mutiplier; + this.r3c2 = r3c2 * mutiplier; + this.r3c3 = r3c3 * mutiplier; return true; } @@ -386,17 +365,7 @@ namespace BGC public static void Divide(in FP32Matrix3x3 dividend, float divisor, out FP32Matrix3x3 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - quotient.r1c3 = dividend.r1c3 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - quotient.r2c3 = dividend.r2c3 / divisor; - - quotient.r3c1 = dividend.r3c1 / divisor; - quotient.r3c2 = dividend.r3c2 / divisor; - quotient.r3c3 = dividend.r3c3 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetRightProduct(in FP32Matrix3x3 matrix, in FP32Vector3 vector, out FP32Vector3 result) diff --git a/BGC/FP32MatrixProduct.cs b/BasicGeometry/FP32MatrixProduct.cs similarity index 99% rename from BGC/FP32MatrixProduct.cs rename to BasicGeometry/FP32MatrixProduct.cs index 4dcc962..75ae41f 100644 --- a/BGC/FP32MatrixProduct.cs +++ b/BasicGeometry/FP32MatrixProduct.cs @@ -20,7 +20,7 @@ using System; * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP32MatrixProduct { diff --git a/BGC/FP32Quaternion.cs b/BasicGeometry/FP32Quaternion.cs similarity index 98% rename from BGC/FP32Quaternion.cs rename to BasicGeometry/FP32Quaternion.cs index 3cea6de..230807e 100644 --- a/BGC/FP32Quaternion.cs +++ b/BasicGeometry/FP32Quaternion.cs @@ -1,10 +1,10 @@ using System; -namespace BGC +namespace BasicGeometry { public struct FP32Quaternion { - public float s0, x1, x2, x3; + public float s0 = 0.0f, x1 = 0.0f, x2 = 0.0f, x3 = 0.0f; public FP32Quaternion(float s0, float x1, float x2, float x3) { diff --git a/BGC/FP32Radians.cs b/BasicGeometry/FP32Radians.cs similarity index 98% rename from BGC/FP32Radians.cs rename to BasicGeometry/FP32Radians.cs index 8aba01e..a6bf46f 100644 --- a/BGC/FP32Radians.cs +++ b/BasicGeometry/FP32Radians.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP32Radians { diff --git a/BGC/FP32Rotation3.cs b/BasicGeometry/FP32Rotation3.cs similarity index 94% rename from BGC/FP32Rotation3.cs rename to BasicGeometry/FP32Rotation3.cs index dce0102..a020a3d 100644 --- a/BGC/FP32Rotation3.cs +++ b/BasicGeometry/FP32Rotation3.cs @@ -21,11 +21,11 @@ using System; * Date: 2 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP32Rotation3 { - private float angle; + private float angle = 0.0f; private FP32Vector3 axis; diff --git a/BGC/FP32Turns.cs b/BasicGeometry/FP32Turns.cs similarity index 98% rename from BGC/FP32Turns.cs rename to BasicGeometry/FP32Turns.cs index 65a89d0..36bf85b 100644 --- a/BGC/FP32Turns.cs +++ b/BasicGeometry/FP32Turns.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP32Turns { diff --git a/BGC/FP32Utility.cs b/BasicGeometry/FP32Utility.cs similarity index 95% rename from BGC/FP32Utility.cs rename to BasicGeometry/FP32Utility.cs index e606c83..eb5ce94 100644 --- a/BGC/FP32Utility.cs +++ b/BasicGeometry/FP32Utility.cs @@ -1,6 +1,6 @@ using System; -namespace BGC +namespace BasicGeometry { public class FP32Utility { diff --git a/BGC/FP32Vector2.cs b/BasicGeometry/FP32Vector2.cs similarity index 96% rename from BGC/FP32Vector2.cs rename to BasicGeometry/FP32Vector2.cs index adbd69a..ea3e8a2 100644 --- a/BGC/FP32Vector2.cs +++ b/BasicGeometry/FP32Vector2.cs @@ -21,14 +21,14 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP32Vector2 { public static readonly FP32Vector2 ZERO = new FP32Vector2(0.0f, 0.0f); - public float x1; - public float x2; + public float x1 = 0.0f; + public float x2 = 0.0f; public FP32Vector2(float x1, float x2) { @@ -157,7 +157,7 @@ namespace BGC difference.x2 = minuend.x2 - subtrahend.x2; } - public static void Muliply(in FP32Vector2 multiplicand, float multiplier, out FP32Vector2 product) + public static void Multiply(in FP32Vector2 multiplicand, float multiplier, out FP32Vector2 product) { product.x1 = multiplicand.x1 * multiplier; product.x2 = multiplicand.x2 * multiplier; @@ -165,8 +165,7 @@ namespace BGC public static void Divide(in FP32Vector2 dividend, float divisor, out FP32Vector2 quotient) { - quotient.x1 = dividend.x1 / divisor; - quotient.x2 = dividend.x2 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetMean2(in FP32Vector2 vector1, in FP32Vector2 vector2, out FP32Vector2 result) diff --git a/BGC/FP32Vector3.cs b/BasicGeometry/FP32Vector3.cs similarity index 96% rename from BGC/FP32Vector3.cs rename to BasicGeometry/FP32Vector3.cs index 1ae9290..8b5b51f 100644 --- a/BGC/FP32Vector3.cs +++ b/BasicGeometry/FP32Vector3.cs @@ -21,15 +21,15 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP32Vector3 { public static readonly FP32Vector3 ZERO = new FP32Vector3(0.0f, 0.0f, 0.0f); - public float x1; - public float x2; - public float x3; + public float x1 = 0.0f; + public float x2 = 0.0f; + public float x3 = 0.0f; public FP32Vector3(float x1, float x2, float x3) { @@ -172,7 +172,7 @@ namespace BGC difference.x3 = minuend.x3 - subtrahend.x3; } - public static void Muliply(in FP32Vector3 multiplicand, float multiplier, out FP32Vector3 product) + public static void Multiply(in FP32Vector3 multiplicand, float multiplier, out FP32Vector3 product) { product.x1 = multiplicand.x1 * multiplier; product.x2 = multiplicand.x2 * multiplier; @@ -181,9 +181,7 @@ namespace BGC public static void Divide(in FP32Vector3 dividend, float divisor, out FP32Vector3 quotient) { - quotient.x1 = dividend.x1 / divisor; - quotient.x2 = dividend.x2 / divisor; - quotient.x3 = dividend.x3 / divisor; + Multiply(dividend, 1.0f / divisor, out quotient); } public static void GetMean2(in FP32Vector3 vector1, in FP32Vector3 vector2, out FP32Vector3 result) diff --git a/BGC/FP32Versor.cs b/BasicGeometry/FP32Versor.cs similarity index 89% rename from BGC/FP32Versor.cs rename to BasicGeometry/FP32Versor.cs index c9555b4..0912aab 100644 --- a/BGC/FP32Versor.cs +++ b/BasicGeometry/FP32Versor.cs @@ -19,22 +19,14 @@ * Date: 20 Oct 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP32Versor { - private float s0; - private float x1; - private float x2; - private float x3; - - public FP32Versor() - { - this.s0 = 1.0f; - this.x1 = 0.0f; - this.x2 = 0.0f; - this.x3 = 0.0f; - } + private float s0 = 1.0f; + private float x1 = 0.0f; + private float x2 = 0.0f; + private float x3 = 0.0f; public FP32Versor(float s0, float x1, float x2, float x3) { @@ -178,12 +170,6 @@ namespace BGC if (1.0f - FP32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + FP32Utility.TWO_EPSYLON) { - if (-1.0f + FP32Utility.EPSYLON < s0) - { - return; - } - - this.Reset(); return; } @@ -254,18 +240,18 @@ namespace BGC private void Normalize(float squareModule) { - if (squareModule <= FP32Utility.SQUARE_EPSYLON || (this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3) <= FP32Utility.SQUARE_EPSYLON * squareModule) + if (squareModule <= FP32Utility.SQUARE_EPSYLON) { this.Reset(); return; } - float module = MathF.Sqrt(squareModule); + float multiplier = MathF.Sqrt(1.0f / squareModule); - this.s0 /= module; - this.x1 /= module; - this.x2 /= module; - this.x3 /= module; + this.s0 *= multiplier; + this.x1 *= multiplier; + this.x2 *= multiplier; + this.x3 *= multiplier; } public static void Combine(in FP32Versor second, in FP32Versor first, out FP32Versor result) @@ -282,10 +268,12 @@ namespace BGC result.x2 = x2; result.x3 = x3; - if (squareModule < 1.0f - FP32Utility.TWO_EPSYLON || 1.0f + FP32Utility.TWO_EPSYLON < squareModule) + if (1.0f - FP32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + FP32Utility.TWO_EPSYLON) { - result.Normalize(squareModule); + return; } + + result.Normalize(squareModule); } public static void LoadIdle(out FP32Versor versor) @@ -307,12 +295,6 @@ namespace BGC if (1.0f - FP32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + FP32Utility.TWO_EPSYLON) { - if (-1.0f + FP32Utility.EPSYLON < s0) - { - return; - } - - versor.Reset(); return; } diff --git a/BGC/FP64Angle.cs b/BasicGeometry/FP64Angle.cs similarity index 99% rename from BGC/FP64Angle.cs rename to BasicGeometry/FP64Angle.cs index 1ecc3cc..3b58553 100644 --- a/BGC/FP64Angle.cs +++ b/BasicGeometry/FP64Angle.cs @@ -21,7 +21,7 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public static class FP64Angle { diff --git a/BGC/FP64Degrees.cs b/BasicGeometry/FP64Degrees.cs similarity index 98% rename from BGC/FP64Degrees.cs rename to BasicGeometry/FP64Degrees.cs index 8d57e79..075b600 100644 --- a/BGC/FP64Degrees.cs +++ b/BasicGeometry/FP64Degrees.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP64Degrees { diff --git a/BGC/FP64Matrix2x2.cs b/BasicGeometry/FP64Matrix2x2.cs similarity index 89% rename from BGC/FP64Matrix2x2.cs rename to BasicGeometry/FP64Matrix2x2.cs index e60d392..f4bdd97 100644 --- a/BGC/FP64Matrix2x2.cs +++ b/BasicGeometry/FP64Matrix2x2.cs @@ -21,29 +21,16 @@ using System; * Date: 10 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP64Matrix2x2 { - public double r1c1, r1c2; - - public double r2c1, r2c2; - - public FP64Matrix2x2() - { - this.r1c1 = 0.0; - this.r1c2 = 0.0; - - this.r2c1 = 0.0; - this.r2c2 = 0.0; - } + public double r1c1 = 0.0, r1c2 = 0.0; + public double r2c1 = 0.0, r2c2 = 0.0; public FP64Matrix2x2(double d1, double d2) { this.r1c1 = d1; - this.r1c2 = 0.0; - - this.r2c1 = 0.0; this.r2c2 = d2; } @@ -96,11 +83,13 @@ namespace BGC double r2c1 = -this.r2c1; double r2c2 = this.r1c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; + double multiplier = 1.0 / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; + this.r1c1 = r1c1 * multiplier; + this.r1c2 = r1c2 * multiplier; + + this.r2c1 = r2c1 * multiplier; + this.r2c2 = r2c2 * multiplier; return true; } @@ -181,11 +170,13 @@ namespace BGC double r2c1 = -matrix.r2c1; double r2c2 = matrix.r1c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; + double multiplier = 1.0 / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; + this.r1c1 = r1c1 * multiplier; + this.r1c2 = r1c2 * multiplier; + + this.r2c1 = r2c1 * multiplier; + this.r2c2 = r2c2 * multiplier; return true; } @@ -252,11 +243,7 @@ namespace BGC public static void Divide(in FP64Matrix2x2 dividend, double divisor, out FP64Matrix2x2 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetRightProduct(in FP64Matrix2x2 matrix, in FP64Vector2 vector, out FP64Vector2 result) diff --git a/BGC/FP64Matrix2x3.cs b/BasicGeometry/FP64Matrix2x3.cs similarity index 90% rename from BGC/FP64Matrix2x3.cs rename to BasicGeometry/FP64Matrix2x3.cs index 3ff7947..3605e4a 100644 --- a/BGC/FP64Matrix2x3.cs +++ b/BasicGeometry/FP64Matrix2x3.cs @@ -20,25 +20,13 @@ using System; * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP64Matrix2x3 { - public double r1c1, r1c2; - public double r2c1, r2c2; - public double r3c1, r3c2; - - public FP64Matrix2x3() - { - this.r1c1 = 0.0; - this.r1c2 = 0.0; - - this.r2c1 = 0.0; - this.r2c2 = 0.0; - - this.r3c1 = 0.0; - this.r3c2 = 0.0; - } + public double r1c1 = 0.0, r1c2 = 0.0; + public double r2c1 = 0.0, r2c2 = 0.0; + public double r3c1 = 0.0, r3c2 = 0.0; public FP64Matrix2x3(in FP64Matrix2x3 matrix) { @@ -230,14 +218,7 @@ namespace BGC public static void Divide(in FP64Matrix2x3 dividend, double divisor, out FP64Matrix2x3 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - - quotient.r3c1 = dividend.r3c1 / divisor; - quotient.r3c2 = dividend.r3c2 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetRightProduct(in FP64Matrix2x3 matrix, in FP64Vector2 vector, out FP64Vector3 result) diff --git a/BGC/FP64Matrix3x2.cs b/BasicGeometry/FP64Matrix3x2.cs similarity index 91% rename from BGC/FP64Matrix3x2.cs rename to BasicGeometry/FP64Matrix3x2.cs index e64f1e6..84bd384 100644 --- a/BGC/FP64Matrix3x2.cs +++ b/BasicGeometry/FP64Matrix3x2.cs @@ -20,23 +20,12 @@ using System; * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP64Matrix3x2 { - public double r1c1, r1c2, r1c3; - public double r2c1, r2c2, r2c3; - - public FP64Matrix3x2() - { - this.r1c1 = 0.0; - this.r1c2 = 0.0; - this.r1c3 = 0.0; - - this.r2c1 = 0.0; - this.r2c2 = 0.0; - this.r2c3 = 0.0; - } + public double r1c1 = 0.0, r1c2 = 0.0, r1c3 = 0.0; + public double r2c1 = 0.0, r2c2 = 0.0, r2c3 = 0.0; public FP64Matrix3x2(in FP64Matrix3x2 matrix) { @@ -216,13 +205,7 @@ namespace BGC public static void Divide(in FP64Matrix3x2 dividend, double divisor, out FP64Matrix3x2 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - quotient.r1c3 = dividend.r1c3 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - quotient.r2c3 = dividend.r2c3 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetRightProduct(in FP64Matrix3x2 matrix, in FP64Vector3 vector, out FP64Vector2 result) diff --git a/BGC/FP64Matrix3x3.cs b/BasicGeometry/FP64Matrix3x3.cs similarity index 87% rename from BGC/FP64Matrix3x3.cs rename to BasicGeometry/FP64Matrix3x3.cs index dd61343..fafad05 100644 --- a/BGC/FP64Matrix3x3.cs +++ b/BasicGeometry/FP64Matrix3x3.cs @@ -21,43 +21,18 @@ using System; * Date: 10 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP64Matrix3x3 { - public double r1c1, r1c2, r1c3; - - public double r2c1, r2c2, r2c3; - - public double r3c1, r3c2, r3c3; - - public FP64Matrix3x3() - { - this.r1c1 = 0.0; - this.r1c2 = 0.0; - this.r1c3 = 0.0; - - this.r2c1 = 0.0; - this.r2c2 = 0.0; - this.r2c3 = 0.0; - - this.r3c1 = 0.0; - this.r3c2 = 0.0; - this.r3c3 = 0.0; - } + public double r1c1 = 0.0, r1c2 = 0.0, r1c3 = 0.0; + public double r2c1 = 0.0, r2c2 = 0.0, r2c3 = 0.0; + public double r3c1 = 0.0, r3c2 = 0.0, r3c3 = 0.0; public FP64Matrix3x3(double d1, double d2, double d3) { this.r1c1 = d1; - this.r1c2 = 0.0; - this.r1c3 = 0.0; - - this.r2c1 = 0.0; this.r2c2 = d2; - this.r2c3 = 0.0; - - this.r3c1 = 0.0; - this.r3c2 = 0.0; this.r3c3 = d3; } @@ -131,17 +106,19 @@ namespace BGC double r3c2 = this.r1c2 * this.r3c1 - this.r1c1 * this.r3c2; double r3c3 = this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; - this.r1c3 = r1c3 / determinant; + double mutiplier = 1.0 / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; - this.r2c3 = r2c3 / determinant; + this.r1c1 = r1c1 * mutiplier; + this.r1c2 = r1c2 * mutiplier; + this.r1c3 = r1c3 * mutiplier; - this.r3c1 = r3c1 / determinant; - this.r3c2 = r3c2 / determinant; - this.r3c3 = r3c3 / determinant; + this.r2c1 = r2c1 * mutiplier; + this.r2c2 = r2c2 * mutiplier; + this.r2c3 = r2c3 * mutiplier; + + this.r3c1 = r3c1 * mutiplier; + this.r3c2 = r3c2 * mutiplier; + this.r3c3 = r3c3 * mutiplier; return true; } @@ -263,17 +240,19 @@ namespace BGC double r3c2 = matrix.r1c2 * matrix.r3c1 - matrix.r1c1 * matrix.r3c2; double r3c3 = matrix.r1c1 * matrix.r2c2 - matrix.r1c2 * matrix.r2c1; - this.r1c1 = r1c1 / determinant; - this.r1c2 = r1c2 / determinant; - this.r1c3 = r1c3 / determinant; + double mutiplier = 1.0 / determinant; - this.r2c1 = r2c1 / determinant; - this.r2c2 = r2c2 / determinant; - this.r2c3 = r2c3 / determinant; + this.r1c1 = r1c1 * mutiplier; + this.r1c2 = r1c2 * mutiplier; + this.r1c3 = r1c3 * mutiplier; - this.r3c1 = r3c1 / determinant; - this.r3c2 = r3c2 / determinant; - this.r3c3 = r3c3 / determinant; + this.r2c1 = r2c1 * mutiplier; + this.r2c2 = r2c2 * mutiplier; + this.r2c3 = r2c3 * mutiplier; + + this.r3c1 = r3c1 * mutiplier; + this.r3c2 = r3c2 * mutiplier; + this.r3c3 = r3c3 * mutiplier; return true; } @@ -382,17 +361,7 @@ namespace BGC public static void Divide(in FP64Matrix3x3 dividend, double divisor, out FP64Matrix3x3 quotient) { - quotient.r1c1 = dividend.r1c1 / divisor; - quotient.r1c2 = dividend.r1c2 / divisor; - quotient.r1c3 = dividend.r1c3 / divisor; - - quotient.r2c1 = dividend.r2c1 / divisor; - quotient.r2c2 = dividend.r2c2 / divisor; - quotient.r2c3 = dividend.r2c3 / divisor; - - quotient.r3c1 = dividend.r3c1 / divisor; - quotient.r3c2 = dividend.r3c2 / divisor; - quotient.r3c3 = dividend.r3c3 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetRightProduct(in FP64Matrix3x3 matrix, in FP64Vector3 vector, out FP64Vector3 result) diff --git a/BGC/FP64MatrixProduct.cs b/BasicGeometry/FP64MatrixProduct.cs similarity index 99% rename from BGC/FP64MatrixProduct.cs rename to BasicGeometry/FP64MatrixProduct.cs index b4c9e83..8a6d2fc 100644 --- a/BGC/FP64MatrixProduct.cs +++ b/BasicGeometry/FP64MatrixProduct.cs @@ -20,7 +20,7 @@ using System; * Author: Andrey Pokidov * Date: 11 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP64MatrixProduct { diff --git a/BGC/FP64Quaternion.cs b/BasicGeometry/FP64Quaternion.cs similarity index 98% rename from BGC/FP64Quaternion.cs rename to BasicGeometry/FP64Quaternion.cs index e002258..f7ada4c 100644 --- a/BGC/FP64Quaternion.cs +++ b/BasicGeometry/FP64Quaternion.cs @@ -1,11 +1,11 @@ using System; using System.Numerics; -namespace BGC +namespace BasicGeometry { public struct FP64Quaternion { - public double s0, x1, x2, x3; + public double s0 = 0.0, x1 = 0.0, x2 = 0.0, x3 = 0.0; public FP64Quaternion(double s0, double x1, double x2, double x3) { diff --git a/BGC/FP64Radians.cs b/BasicGeometry/FP64Radians.cs similarity index 98% rename from BGC/FP64Radians.cs rename to BasicGeometry/FP64Radians.cs index 23b99e0..8163a72 100644 --- a/BGC/FP64Radians.cs +++ b/BasicGeometry/FP64Radians.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP64Radians { diff --git a/BGC/FP64Turns.cs b/BasicGeometry/FP64Turns.cs similarity index 98% rename from BGC/FP64Turns.cs rename to BasicGeometry/FP64Turns.cs index 7cbd2c4..731f361 100644 --- a/BGC/FP64Turns.cs +++ b/BasicGeometry/FP64Turns.cs @@ -4,7 +4,7 @@ * Date: 18 Nov 2024 */ -namespace BGC +namespace BasicGeometry { public class FP64Turns { diff --git a/BGC/FP64Utility.cs b/BasicGeometry/FP64Utility.cs similarity index 96% rename from BGC/FP64Utility.cs rename to BasicGeometry/FP64Utility.cs index 723738b..bfa9ce0 100644 --- a/BGC/FP64Utility.cs +++ b/BasicGeometry/FP64Utility.cs @@ -1,6 +1,6 @@ using System; -namespace BGC +namespace BasicGeometry { public class FP64Utility { diff --git a/BGC/FP64Vector2.cs b/BasicGeometry/FP64Vector2.cs similarity index 96% rename from BGC/FP64Vector2.cs rename to BasicGeometry/FP64Vector2.cs index dbc081b..82d9f84 100644 --- a/BGC/FP64Vector2.cs +++ b/BasicGeometry/FP64Vector2.cs @@ -21,14 +21,14 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP64Vector2 { public static readonly FP64Vector2 ZERO = new FP64Vector2(0.0, 0.0); - public double x1; - public double x2; + public double x1 = 0.0; + public double x2 = 0.0; public FP64Vector2(double x1, double x2) { @@ -157,7 +157,7 @@ namespace BGC difference.x2 = minuend.x2 - subtrahend.x2; } - public static void Muliply(in FP64Vector2 multiplicand, double multiplier, out FP64Vector2 product) + public static void Multiply(in FP64Vector2 multiplicand, double multiplier, out FP64Vector2 product) { product.x1 = multiplicand.x1 * multiplier; product.x2 = multiplicand.x2 * multiplier; @@ -165,8 +165,7 @@ namespace BGC public static void Divide(in FP64Vector2 dividend, double divisor, out FP64Vector2 quotient) { - quotient.x1 = dividend.x1 / divisor; - quotient.x2 = dividend.x2 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetMean2(in FP64Vector2 vector1, in FP64Vector2 vector2, out FP64Vector2 result) diff --git a/BGC/FP64Vector3.cs b/BasicGeometry/FP64Vector3.cs similarity index 96% rename from BGC/FP64Vector3.cs rename to BasicGeometry/FP64Vector3.cs index 4829ffd..9bbf09b 100644 --- a/BGC/FP64Vector3.cs +++ b/BasicGeometry/FP64Vector3.cs @@ -21,15 +21,15 @@ using System; * Date: 1 Feb 2019 */ -namespace BGC +namespace BasicGeometry { public struct FP64Vector3 { public static readonly FP64Vector3 ZERO = new FP64Vector3(0.0, 0.0, 0.0); - public double x1; - public double x2; - public double x3; + public double x1 = 0.0; + public double x2 = 0.0; + public double x3 = 0.0; public FP64Vector3(double x1, double x2, double x3) { @@ -172,7 +172,7 @@ namespace BGC difference.x3 = minuend.x3 - subtrahend.x3; } - public static void Muliply(in FP64Vector3 multiplicand, double multiplier, out FP64Vector3 product) + public static void Multiply(in FP64Vector3 multiplicand, double multiplier, out FP64Vector3 product) { product.x1 = multiplicand.x1 * multiplier; product.x2 = multiplicand.x2 * multiplier; @@ -181,9 +181,7 @@ namespace BGC public static void Divide(in FP64Vector3 dividend, double divisor, out FP64Vector3 quotient) { - quotient.x1 = dividend.x1 / divisor; - quotient.x2 = dividend.x2 / divisor; - quotient.x3 = dividend.x3 / divisor; + Multiply(dividend, 1.0 / divisor, out quotient); } public static void GetMean2(in FP64Vector3 vector1, in FP64Vector3 vector2, out FP64Vector3 result) diff --git a/BGC/FP64Versor.cs b/BasicGeometry/FP64Versor.cs similarity index 92% rename from BGC/FP64Versor.cs rename to BasicGeometry/FP64Versor.cs index 89c5e4b..bd1396e 100644 --- a/BGC/FP64Versor.cs +++ b/BasicGeometry/FP64Versor.cs @@ -20,22 +20,14 @@ * Date: 20 Oct 2024 */ -namespace BGC +namespace BasicGeometry { public struct FP64Versor { - private double s0; - private double x1; - private double x2; - private double x3; - - public FP64Versor() - { - this.s0 = 1.0; - this.x1 = 0.0; - this.x2 = 0.0; - this.x3 = 0.0; - } + private double s0 = 1.0; + private double x1 = 0.0; + private double x2 = 0.0; + private double x3 = 0.0; public FP64Versor(double s0, double x1, double x2, double x3) { @@ -182,12 +174,6 @@ namespace BGC if (1.0 - FP64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + FP64Utility.TWO_EPSYLON) { - if (-1.0 + FP64Utility.EPSYLON < s0) - { - return; - } - - this.Reset(); return; } @@ -290,10 +276,12 @@ namespace BGC result.x2 = x2; result.x3 = x3; - if (squareModule < 1.0 - FP64Utility.TWO_EPSYLON || 1.0 + FP64Utility.TWO_EPSYLON < squareModule) + if (1.0 - FP64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + FP64Utility.TWO_EPSYLON) { - result.Normalize(squareModule); + return; } + + result.Normalize(squareModule); } public static void LoadIdle(out FP64Versor versor) @@ -315,12 +303,6 @@ namespace BGC if (1.0 - FP64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + FP64Utility.TWO_EPSYLON) { - if (-1.0 + FP64Utility.EPSYLON < s0) - { - return; - } - - versor.Reset(); return; } diff --git a/BGCDev/BGCDev.csproj b/BasicGeometryDev/BasicGeometryDev.csproj similarity index 78% rename from BGCDev/BGCDev.csproj rename to BasicGeometryDev/BasicGeometryDev.csproj index 4adcca4..96a08b9 100644 --- a/BGCDev/BGCDev.csproj +++ b/BasicGeometryDev/BasicGeometryDev.csproj @@ -8,7 +8,7 @@ - + diff --git a/BGCDev/Program.cs b/BasicGeometryDev/Program.cs similarity index 98% rename from BGCDev/Program.cs rename to BasicGeometryDev/Program.cs index ba50ee8..4b05e60 100644 --- a/BGCDev/Program.cs +++ b/BasicGeometryDev/Program.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using System.Diagnostics; -using BGC; +using BasicGeometry; public static class Program { diff --git a/BGCTest/BGCTest.csproj b/BasicGeometryTest/BasicGeometryTest.csproj similarity index 87% rename from BGCTest/BGCTest.csproj rename to BasicGeometryTest/BasicGeometryTest.csproj index 0084bbd..673efb3 100644 --- a/BGCTest/BGCTest.csproj +++ b/BasicGeometryTest/BasicGeometryTest.csproj @@ -12,7 +12,7 @@ - + diff --git a/BGCTest/F32Vector2Test.cs b/BasicGeometryTest/F32Vector2Test.cs similarity index 85% rename from BGCTest/F32Vector2Test.cs rename to BasicGeometryTest/F32Vector2Test.cs index b53986f..96ab1c9 100644 --- a/BGCTest/F32Vector2Test.cs +++ b/BasicGeometryTest/F32Vector2Test.cs @@ -3,9 +3,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; -using BGC; +using BasicGeometry; -namespace BGCTest +namespace BasicGeometryTest { [TestClass] public class FP32Vector2Test