Refactor backend into domain-first slices

This commit is contained in:
2026-03-19 18:15:44 -04:00
parent 07a3142316
commit 9a5040cf1f
53 changed files with 94 additions and 140 deletions

View File

@@ -0,0 +1,36 @@
namespace SpaceGame.Api.Shared.Runtime;
public readonly record struct Vector3(float X, float Y, float Z)
{
public static Vector3 Zero => new(0f, 0f, 0f);
public float DistanceTo(Vector3 other)
{
var dx = X - other.X;
var dy = Y - other.Y;
var dz = Z - other.Z;
return MathF.Sqrt((dx * dx) + (dy * dy) + (dz * dz));
}
public float LengthSquared() => (X * X) + (Y * Y) + (Z * Z);
public Vector3 MoveToward(Vector3 target, float maxDistance)
{
var delta = target.Subtract(this);
var distance = MathF.Sqrt(delta.LengthSquared());
if (distance <= 0.0001f || distance <= maxDistance)
{
return target;
}
var scale = maxDistance / distance;
return new Vector3(
X + (delta.X * scale),
Y + (delta.Y * scale),
Z + (delta.Z * scale));
}
public Vector3 Subtract(Vector3 other) => new(X - other.X, Y - other.Y, Z - other.Z);
public Vector3 Divide(float scalar) => MathF.Abs(scalar) <= 0.0001f ? Zero : new Vector3(X / scalar, Y / scalar, Z / scalar);
}