Hey this actually is deterministic atm

This commit is contained in:
2023-12-18 22:49:26 +03:00
parent 2e72347721
commit dd9950d6c5
3 changed files with 53 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ namespace Syntriax.Engine.Physics2D.Primitives;
public record Line(Vector2 From, Vector2 To)
{
public Line Reversed => new(To, From);
public Vector2 Direction => Vector2.Normalize(To - From);
public float Length => (From - To).Length();
public float LengthSquared => (From - To).LengthSquared();
@@ -39,7 +40,15 @@ public record Line(Vector2 From, Vector2 To)
pointX -= min;
return pointX / max;
float t = pointX / max;
// FIXME
// I don't even know, apparently whatever I wrote up there doesn't take into account of the direction of the line
// Which... I can see how, but I am also not sure how I can make it take into account. Or actually I'm for some reason
// too unmotivated to find a solution. Future me, find a better way if possible, please.
if (!Lerp(t).ApproximatelyEquals(point))
return 1f - t;
return t;
}
public bool Exist(List<Vector2> vertices)
@@ -60,9 +69,22 @@ public record Line(Vector2 From, Vector2 To)
}
public float IntersectionParameterT(Line other)
=> ((other.From.X - From.X) * (To.Y - From.Y) - (other.From.Y - From.Y) * (To.X - From.X)) /
((other.To.Y - other.From.Y) * (To.X - From.X) - (other.To.X - other.From.X) * (To.Y - From.Y));
{
float numerator = (From.X - other.From.X) * (other.From.Y - other.To.Y) - (From.Y - other.From.Y) * (other.From.X - other.To.X);
float denominator = (From.X - To.X) * (other.From.Y - other.To.Y) - (From.Y - To.Y) * (other.From.X - other.To.X);
// Lines are parallel
if (denominator == 0)
return float.NaN;
return numerator / denominator;
}
public Vector2 Lerp(float t)
=> new Vector2(
From.X + (To.X - From.X) * t,
From.Y + (To.Y - From.Y) * t
);
public Vector2 Resolve(float x)
=> new Vector2(x, LineEquation.Resolve(x));