yep
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user