refactor: primitives now use Core.Math for math
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user