This commit is contained in:
2024-10-26 22:09:41 -05:00
parent 550942281b
commit f8bf967581
4 changed files with 107 additions and 53 deletions

View File

@@ -20,34 +20,4 @@ public record Path
Step = step;
this.Distance = distance;
}
public Path Invert() => new(Vector2.Negate(Step), Distance);
//public enum PathingResult
//{
// Obstructed,
// CompletedWithoutObstruction
//}
}
public static class PathExtensions
{
public static Path GetNearestPath(this IEnumerable<Path> paths, Vector2 start, Vector2 end)
{
if (!paths.DefaultIfEmpty().Any())
{
throw new ArgumentException("No paths to get nearest path from.");
}
var shortestPath = paths.First();
foreach (var path in paths.Skip(1))
{
var distance = Vector2.Distance(start + path.Step, end);
var shortestDistance = Vector2.Distance(start + shortestPath.Step, end);
if (distance < shortestDistance)
{
shortestPath = path;
}
}
return shortestPath;
}
}
public Path Invert() => new(Vector2.Negate(Step), Distance);