yep
This commit is contained in:
@@ -14,11 +14,14 @@ namespace PathFinding
|
||||
private readonly IPlanarCollection<T> collection;
|
||||
private readonly int width;
|
||||
private readonly int height;
|
||||
public PathFinder2D(IPlanarCollection<T> collection)
|
||||
|
||||
/// <param name="width">Horizontal size, in steps, of the pathable plane.</param>
|
||||
/// <param name="height">Vertical size, in steps, of the pathable plane.</param>
|
||||
public PathFinder2D(IPlanarCollection<T> collection, int width, int height)
|
||||
{
|
||||
this.collection = collection;
|
||||
width = collection.GetLength(0);
|
||||
height = collection.GetLength(1);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,13 +32,13 @@ namespace PathFinding
|
||||
/// <param name="destination">The destination.</param>
|
||||
/// <param name="callback">Do cool stuff here.</param>
|
||||
/// <returns>True if the element reached the destination.</returns>
|
||||
public bool PathTo(Vector2 origin, Vector2 destination, Callback callback = null)
|
||||
public bool PathTo(Vector2 origin, Vector2 destination, Callback? callback = null)
|
||||
{
|
||||
if (destination.X > width - 1 || destination.Y > height - 1 || destination.X < 0 || destination.Y < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var element = collection[origin.Y, origin.X];
|
||||
var element = collection[origin];
|
||||
if (element == null) return false;
|
||||
|
||||
var path = FindDirectionTowardsDestination(element.MoveSet.GetMoves(), origin, destination);
|
||||
@@ -50,7 +53,7 @@ namespace PathFinding
|
||||
while (shouldPath && next != destination)
|
||||
{
|
||||
next = Vector2.Add(next, path.Direction);
|
||||
var collider = collection[(int)next.Y, (int)next.X];
|
||||
var collider = collection[next];
|
||||
if (collider != null)
|
||||
{
|
||||
callback?.Invoke(collider, next);
|
||||
@@ -66,7 +69,7 @@ namespace PathFinding
|
||||
|
||||
public void PathEvery(Vector2 from, Callback callback)
|
||||
{
|
||||
var element = collection[from.Y, from.X];
|
||||
var element = collection[from];
|
||||
if (element == null)
|
||||
{
|
||||
Console.WriteLine("Null element in PathEvery");
|
||||
@@ -103,7 +106,7 @@ namespace PathFinding
|
||||
var next = Vector2.Add(origin, direction);
|
||||
while (next.X >= 0 && next.X < width && next.Y >= 0 && next.Y < height)
|
||||
{
|
||||
var element = collection[next.Y, next.X];
|
||||
var element = collection[next];
|
||||
if (element != null) callback(element, next);
|
||||
next = Vector2.Add(next, direction);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user