fix: Build Errors

This commit is contained in:
Syntriax 2024-01-22 18:46:51 +03:00
parent 0519adfcce
commit 8af2379afa
4 changed files with 19 additions and 19 deletions

View File

@ -19,15 +19,15 @@ public static class PhysicsMath
foreach (Vector2 point in vertices) foreach (Vector2 point in vertices)
{ {
minX = Math.Min(minX, point.X); minX = MathF.Min(minX, point.X);
minY = Math.Min(minY, point.Y); minY = MathF.Min(minY, point.Y);
maxX = Math.Max(maxX, point.X); maxX = MathF.Max(maxX, point.X);
maxY = Math.Max(maxY, point.Y); maxY = MathF.Max(maxY, point.Y);
} }
float dx = maxX - minX; float dx = maxX - minX;
float dy = maxY - minY; float dy = maxY - minY;
float deltaMax = Math.Max(dx, dy); float deltaMax = MathF.Max(dx, dy);
float midX = (minX + maxX) / 2; float midX = (minX + maxX) / 2;
float midY = (minY + maxY) / 2; float midY = (minY + maxY) / 2;
@ -61,8 +61,8 @@ public static class PhysicsMath
// point q lies on line segment 'pr' // point q lies on line segment 'pr'
public static bool OnSegment(Vector2 p, Vector2 q, Vector2 r) public static bool OnSegment(Vector2 p, Vector2 q, Vector2 r)
{ {
if (q.X <= Math.Max(p.X, r.X) && q.X >= Math.Min(p.X, r.X) && if (q.X <= MathF.Max(p.X, r.X) && q.X >= MathF.Min(p.X, r.X) &&
q.Y <= Math.Max(p.Y, r.Y) && q.Y >= Math.Min(p.Y, r.Y)) q.Y <= MathF.Max(p.Y, r.Y) && q.Y >= MathF.Min(p.Y, r.Y))
return true; return true;
return false; return false;
@ -102,13 +102,13 @@ public static class PhysicsMath
return true; return true;
const float floatNormal = (1 << 23) * float.Epsilon; const float floatNormal = (1 << 23) * float.Epsilon;
float absA = Math.Abs(a); float absA = MathF.Abs(a);
float absB = Math.Abs(b); float absB = MathF.Abs(b);
float diff = Math.Abs(a - b); float diff = MathF.Abs(a - b);
if (a == 0.0f || b == 0.0f || diff < floatNormal) if (a == 0.0f || b == 0.0f || diff < floatNormal)
return diff < (epsilon * floatNormal); return diff < (epsilon * floatNormal);
return diff / Math.Min(absA + absB, float.MaxValue) < epsilon; return diff / MathF.Min(absA + absB, float.MaxValue) < epsilon;
} }
} }

View File

@ -99,7 +99,7 @@ public record Line(Vector2 From, Vector2 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);
// Clamp t to the range [0, 1] to ensure the closest point is on the edge // Clamp t to the range [0, 1] to ensure the closest point is on the edge
t = Math.Max(0, Math.Min(1, t)); t = MathF.Max(0, MathF.Min(1, t));
// Calculate the closest point on the edge // Calculate the closest point on the edge
float closestX = From.X + t * edgeVector.X; float closestX = From.X + t * edgeVector.X;

View File

@ -16,15 +16,15 @@ public record Shape(IList<Vector2> Vertices)
foreach (Vector2 point in Vertices) foreach (Vector2 point in Vertices)
{ {
minX = Math.Min(minX, point.X); minX = MathF.Min(minX, point.X);
minY = Math.Min(minY, point.Y); minY = MathF.Min(minY, point.Y);
maxX = Math.Max(maxX, point.X); maxX = MathF.Max(maxX, point.X);
maxY = Math.Max(maxY, point.Y); maxY = MathF.Max(maxY, point.Y);
} }
float dx = maxX - minX; float dx = maxX - minX;
float dy = maxY - minY; float dy = maxY - minY;
float deltaMax = Math.Max(dx, dy); float deltaMax = MathF.Max(dx, dy);
float midX = (minX + maxX) / 2; float midX = (minX + maxX) / 2;
float midY = (minY + maxY) / 2; float midY = (minY + maxY) / 2;

View File

@ -6,7 +6,7 @@ namespace Syntriax.Engine.Physics2D.Primitives;
public record Triangle(Vector2 A, Vector2 B, Vector2 C) public record Triangle(Vector2 A, Vector2 B, Vector2 C)
{ {
public float Area => Math.Abs(( public float Area => MathF.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)
@ -23,7 +23,7 @@ public record Triangle(Vector2 A, Vector2 B, Vector2 C)
float slopeBC = (C.Y - B.Y) / (C.X - B.X); float slopeBC = (C.Y - B.Y) / (C.X - B.X);
Vector2 center; Vector2 center;
if (Math.Abs(slopeAB - slopeBC) > float.Epsilon) if (MathF.Abs(slopeAB - slopeBC) > float.Epsilon)
{ {
float x = (slopeAB * slopeBC * (A.Y - C.Y) + slopeBC * (A.X + B.X) - slopeAB * (B.X + C.X)) / (2 * (slopeBC - slopeAB)); float x = (slopeAB * slopeBC * (A.Y - C.Y) + slopeBC * (A.X + B.X) - slopeAB * (B.X + C.X)) / (2 * (slopeBC - slopeAB));
float y = -(x - (A.X + B.X) / 2) / slopeAB + (A.Y + B.Y) / 2; float y = -(x - (A.X + B.X) / 2) / slopeAB + (A.Y + B.Y) / 2;