refactor: primitives now use Core.Math for math
This commit is contained in:
		| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -156,7 +154,7 @@ public readonly struct ColorHSV(float hue, float saturation, float value) | |||||||
|     /// Generates a hash code for the <see cref="ColorHSV"/>. |     /// Generates a hash code for the <see cref="ColorHSV"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="ColorHSV"/>.</returns> |     /// <returns>A hash code for the <see cref="ColorHSV"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(Hue, Saturation, Value); |     public override int GetHashCode() => System.HashCode.Combine(Hue, Saturation, Value); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -138,7 +136,7 @@ public readonly struct ColorRGB(byte r, byte g, byte b) | |||||||
|     /// Generates a hash code for the <see cref="ColorRGB"/>. |     /// Generates a hash code for the <see cref="ColorRGB"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="ColorRGB"/>.</returns> |     /// <returns>A hash code for the <see cref="ColorRGB"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(R, G, B); |     public override int GetHashCode() => System.HashCode.Combine(R, G, B); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -121,7 +119,7 @@ public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255) | |||||||
|     /// Generates a hash code for the <see cref="ColorRGBA"/>. |     /// Generates a hash code for the <see cref="ColorRGBA"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="ColorRGBA"/>.</returns> |     /// <returns>A hash code for the <see cref="ColorRGBA"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(R, G, B, A); |     public override int GetHashCode() => System.HashCode.Combine(R, G, B, A); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| using System; |  | ||||||
| using System.Diagnostics.CodeAnalysis; | using System.Diagnostics.CodeAnalysis; | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
| @@ -68,12 +67,12 @@ public readonly struct Line2D(Vector2D from, Vector2D to) | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     public static float GetT(Line2D line, Vector2D point) |     public static float GetT(Line2D line, Vector2D point) | ||||||
|     { |     { | ||||||
|         float fromX = MathF.Abs(line.From.X); |         float fromX = Math.Abs(line.From.X); | ||||||
|         float toX = MathF.Abs(line.To.X); |         float toX = Math.Abs(line.To.X); | ||||||
|         float pointX = MathF.Abs(point.X); |         float pointX = Math.Abs(point.X); | ||||||
|  |  | ||||||
|         float min = MathF.Min(fromX, toX); |         float min = Math.Min(fromX, toX); | ||||||
|         float max = MathF.Max(fromX, toX) - min; |         float max = Math.Max(fromX, toX) - min; | ||||||
|  |  | ||||||
|         pointX -= min; |         pointX -= min; | ||||||
|  |  | ||||||
| @@ -114,8 +113,8 @@ public readonly struct Line2D(Vector2D from, Vector2D to) | |||||||
|     /// </summary> |     /// </summary> | ||||||
|     public static bool OnSegment(Line2D line, Vector2D point) |     public static bool OnSegment(Line2D line, Vector2D point) | ||||||
|     { |     { | ||||||
|         if (point.X <= MathF.Max(line.From.X, line.To.X) && point.X >= MathF.Min(line.From.X, line.To.X) && |         if (point.X <= Math.Max(line.From.X, line.To.X) && point.X >= Math.Min(line.From.X, line.To.X) && | ||||||
|             point.Y <= MathF.Max(line.From.Y, line.To.Y) && point.Y >= MathF.Min(line.From.Y, line.To.Y)) |             point.Y <= Math.Max(line.From.Y, line.To.Y) && point.Y >= Math.Min(line.From.Y, line.To.Y)) | ||||||
|             return true; |             return true; | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
| @@ -173,7 +172,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to) | |||||||
|  |  | ||||||
|         float t = (pointVector.X * edgeVector.X + pointVector.Y * edgeVector.Y) / (edgeVector.X * edgeVector.X + edgeVector.Y * edgeVector.Y); |         float t = (pointVector.X * edgeVector.X + pointVector.Y * edgeVector.Y) / (edgeVector.X * edgeVector.X + edgeVector.Y * edgeVector.Y); | ||||||
|  |  | ||||||
|         t = MathF.Max(0, MathF.Min(1, t)); |         t = Math.Max(0, Math.Min(1, t)); | ||||||
|  |  | ||||||
|         float closestX = line.From.X + t * edgeVector.X; |         float closestX = line.From.X + t * edgeVector.X; | ||||||
|         float closestY = line.From.Y + t * edgeVector.Y; |         float closestY = line.From.Y + t * edgeVector.Y; | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -178,11 +176,11 @@ public readonly struct Quaternion(float x, float y, float z, float w) | |||||||
|         if (dot > 0.9995f) |         if (dot > 0.9995f) | ||||||
|             return Lerp(from, to, t); |             return Lerp(from, to, t); | ||||||
|  |  | ||||||
|         float angle = MathF.Acos(dot); |         float angle = Math.Acos(dot); | ||||||
|         float sinAngle = MathF.Sin(angle); |         float sinAngle = Math.Sin(angle); | ||||||
|  |  | ||||||
|         float fromWeight = MathF.Sin((1f - t) * angle) / sinAngle; |         float fromWeight = Math.Sin((1f - t) * angle) / sinAngle; | ||||||
|         float toWeight = MathF.Sin(t * angle) / sinAngle; |         float toWeight = Math.Sin(t * angle) / sinAngle; | ||||||
|  |  | ||||||
|         return from * fromWeight + to * toWeight; |         return from * fromWeight + to * toWeight; | ||||||
|     } |     } | ||||||
| @@ -213,8 +211,8 @@ public readonly struct Quaternion(float x, float y, float z, float w) | |||||||
|     public static Quaternion FromAxisAngle(Vector3D axis, float angle) |     public static Quaternion FromAxisAngle(Vector3D axis, float angle) | ||||||
|     { |     { | ||||||
|         float halfAngle = angle * .5f; |         float halfAngle = angle * .5f; | ||||||
|         float sinHalf = MathF.Sin(halfAngle); |         float sinHalf = Math.Sin(halfAngle); | ||||||
|         return new Quaternion(axis.X * sinHalf, axis.Y * sinHalf, axis.Z * sinHalf, MathF.Cos(halfAngle)); |         return new Quaternion(axis.X * sinHalf, axis.Y * sinHalf, axis.Z * sinHalf, Math.Cos(halfAngle)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// <summary> |     /// <summary> | ||||||
| @@ -301,7 +299,7 @@ public readonly struct Quaternion(float x, float y, float z, float w) | |||||||
|     /// Generates a hash code for the <see cref="Quaternion"/>. |     /// Generates a hash code for the <see cref="Quaternion"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="Quaternion"/>.</returns> |     /// <returns>A hash code for the <see cref="Quaternion"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(X, Y, Z); |     public override int GetHashCode() => System.HashCode.Combine(X, Y, Z); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| [System.Diagnostics.DebuggerDisplay("A: {A.ToString(), nq}, B: {B.ToString(), nq}, B: {C.ToString(), nq}")] | [System.Diagnostics.DebuggerDisplay("A: {A.ToString(), nq}, B: {B.ToString(), nq}, B: {C.ToString(), nq}")] | ||||||
| @@ -10,7 +8,7 @@ public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C) | |||||||
|     public readonly Vector2D C { get; init; } = C; |     public readonly Vector2D C { get; init; } = C; | ||||||
|  |  | ||||||
|     public readonly float Area |     public readonly float Area | ||||||
|         => .5f * MathF.Abs( |         => .5f * Math.Abs( | ||||||
|                 A.X * (B.Y - C.Y) + |                 A.X * (B.Y - C.Y) + | ||||||
|                 B.X * (C.Y - A.Y) + |                 B.X * (C.Y - A.Y) + | ||||||
|                 C.X * (A.Y - B.Y) |                 C.X * (A.Y - B.Y) | ||||||
| @@ -25,7 +23,7 @@ public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C) | |||||||
|         float slopeBC = (triangle.C.Y - triangle.B.Y) / (triangle.C.X - triangle.B.X); |         float slopeBC = (triangle.C.Y - triangle.B.Y) / (triangle.C.X - triangle.B.X); | ||||||
|  |  | ||||||
|         Vector2D center; |         Vector2D center; | ||||||
|         if (MathF.Abs(slopeAB - slopeBC) > float.Epsilon) |         if (Math.Abs(slopeAB - slopeBC) > float.Epsilon) | ||||||
|         { |         { | ||||||
|             float x = (slopeAB * slopeBC * (triangle.A.Y - triangle.C.Y) + slopeBC * (triangle.A.X + triangle.B.X) - slopeAB * (triangle.B.X + triangle.C.X)) / (2f * (slopeBC - slopeAB)); |             float x = (slopeAB * slopeBC * (triangle.A.Y - triangle.C.Y) + slopeBC * (triangle.A.X + triangle.B.X) - slopeAB * (triangle.B.X + triangle.C.X)) / (2f * (slopeBC - slopeAB)); | ||||||
|             float y = -(x - (triangle.A.X + triangle.B.X) / 2f) / slopeAB + (triangle.A.Y + triangle.B.Y) / 2f; |             float y = -(x - (triangle.A.X + triangle.B.X) / 2f) / slopeAB + (triangle.A.Y + triangle.B.Y) / 2f; | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -316,7 +314,7 @@ public readonly struct Vector2D(float x, float y) | |||||||
|     /// Generates a hash code for the <see cref="Vector2D"/>. |     /// Generates a hash code for the <see cref="Vector2D"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="Vector2D"/>.</returns> |     /// <returns>A hash code for the <see cref="Vector2D"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(X, Y); |     public override int GetHashCode() => System.HashCode.Combine(X, Y); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
| @@ -1,5 +1,3 @@ | |||||||
| using System; |  | ||||||
|  |  | ||||||
| namespace Syntriax.Engine.Core; | namespace Syntriax.Engine.Core; | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
| @@ -290,7 +288,7 @@ public readonly struct Vector3D(float x, float y, float z) | |||||||
|     /// Generates a hash code for the <see cref="Vector3D"/>. |     /// Generates a hash code for the <see cref="Vector3D"/>. | ||||||
|     /// </summary> |     /// </summary> | ||||||
|     /// <returns>A hash code for the <see cref="Vector3D"/>.</returns> |     /// <returns>A hash code for the <see cref="Vector3D"/>.</returns> | ||||||
|     public override int GetHashCode() => HashCode.Combine(X, Y, Z); |     public override int GetHashCode() => System.HashCode.Combine(X, Y, Z); | ||||||
| } | } | ||||||
|  |  | ||||||
| /// <summary> | /// <summary> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user