refactor: primitives now use Core.Math for math

This commit is contained in:
Syntriax 2025-05-02 18:57:42 +03:00
parent 16e4077d40
commit 5de08b8fe4
8 changed files with 22 additions and 37 deletions

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <summary>
@ -156,7 +154,7 @@ public readonly struct ColorHSV(float hue, float saturation, float value)
/// Generates a hash code for the <see cref="ColorHSV"/>.
/// </summary>
/// <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>

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <summary>
@ -138,7 +136,7 @@ public readonly struct ColorRGB(byte r, byte g, byte b)
/// Generates a hash code for the <see cref="ColorRGB"/>.
/// </summary>
/// <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>

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <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"/>.
/// </summary>
/// <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>

View File

@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Syntriax.Engine.Core;
@ -68,12 +67,12 @@ public readonly struct Line2D(Vector2D from, Vector2D to)
/// </summary>
public static float GetT(Line2D line, Vector2D point)
{
float fromX = MathF.Abs(line.From.X);
float toX = MathF.Abs(line.To.X);
float pointX = MathF.Abs(point.X);
float fromX = Math.Abs(line.From.X);
float toX = Math.Abs(line.To.X);
float pointX = Math.Abs(point.X);
float min = MathF.Min(fromX, toX);
float max = MathF.Max(fromX, toX) - min;
float min = Math.Min(fromX, toX);
float max = Math.Max(fromX, toX) - min;
pointX -= min;
@ -114,8 +113,8 @@ public readonly struct Line2D(Vector2D from, Vector2D to)
/// </summary>
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) &&
point.Y <= MathF.Max(line.From.Y, line.To.Y) && point.Y >= MathF.Min(line.From.Y, line.To.Y))
if (point.X <= Math.Max(line.From.X, line.To.X) && point.X >= Math.Min(line.From.X, line.To.X) &&
point.Y <= Math.Max(line.From.Y, line.To.Y) && point.Y >= Math.Min(line.From.Y, line.To.Y))
return true;
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);
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 closestY = line.From.Y + t * edgeVector.Y;

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <summary>
@ -178,11 +176,11 @@ public readonly struct Quaternion(float x, float y, float z, float w)
if (dot > 0.9995f)
return Lerp(from, to, t);
float angle = MathF.Acos(dot);
float sinAngle = MathF.Sin(angle);
float angle = Math.Acos(dot);
float sinAngle = Math.Sin(angle);
float fromWeight = MathF.Sin((1f - t) * angle) / sinAngle;
float toWeight = MathF.Sin(t * angle) / sinAngle;
float fromWeight = Math.Sin((1f - t) * angle) / sinAngle;
float toWeight = Math.Sin(t * angle) / sinAngle;
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)
{
float halfAngle = angle * .5f;
float sinHalf = MathF.Sin(halfAngle);
return new Quaternion(axis.X * sinHalf, axis.Y * sinHalf, axis.Z * sinHalf, MathF.Cos(halfAngle));
float sinHalf = Math.Sin(halfAngle);
return new Quaternion(axis.X * sinHalf, axis.Y * sinHalf, axis.Z * sinHalf, Math.Cos(halfAngle));
}
/// <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"/>.
/// </summary>
/// <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>

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
[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 float Area
=> .5f * MathF.Abs(
=> .5f * Math.Abs(
A.X * (B.Y - C.Y) +
B.X * (C.Y - A.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);
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 y = -(x - (triangle.A.X + triangle.B.X) / 2f) / slopeAB + (triangle.A.Y + triangle.B.Y) / 2f;

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <summary>
@ -316,7 +314,7 @@ public readonly struct Vector2D(float x, float y)
/// Generates a hash code for the <see cref="Vector2D"/>.
/// </summary>
/// <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>

View File

@ -1,5 +1,3 @@
using System;
namespace Syntriax.Engine.Core;
/// <summary>
@ -290,7 +288,7 @@ public readonly struct Vector3D(float x, float y, float z)
/// Generates a hash code for the <see cref="Vector3D"/>.
/// </summary>
/// <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>