Code smells

This commit is contained in:
2021-03-04 20:35:23 -06:00
parent e64f75e3cc
commit 7ed771d467
31 changed files with 310 additions and 339 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
@@ -13,7 +12,6 @@ namespace PathFinding
/// <param name="position"></param>
public delegate void Callback(T collider, Vector2 position);
private readonly IPlanarCollection<T> collection;
private readonly int width;
private readonly int height;
@@ -39,8 +37,9 @@ namespace PathFinding
return false;
}
var element = collection[origin.X, origin.Y];
var path = FindDirectionTowardsDestination(element.GetPaths(), origin, destination);
if (element == null) return false;
var path = FindDirectionTowardsDestination(element.MoveSet.GetMoves(), origin, destination);
if (!IsPathable(origin, destination, path.Direction))
{
// Assumption: if a single best-choice step towards the destination cannot happen, no pathing can happen.
@@ -69,7 +68,7 @@ namespace PathFinding
public void PathEvery(Vector2 from, Callback callback)
{
var element = collection[from.X, from.Y];
foreach (var path in element.GetPaths())
foreach (var path in element.MoveSet.GetMoves())
{
var shouldPath = true;
var next = Vector2.Add(from, path.Direction); ;
@@ -106,16 +105,15 @@ namespace PathFinding
}
}
public Path FindDirectionTowardsDestination(ICollection<Path> paths, Vector2 origin, Vector2 destination) =>
public static Move FindDirectionTowardsDestination(ICollection<Move> paths, Vector2 origin, Vector2 destination) =>
paths.Aggregate((a, b) => Vector2.Distance(destination, Vector2.Add(origin, a.Direction)) < Vector2.Distance(destination, Vector2.Add(origin, b.Direction)) ? a : b);
public bool IsPathable(Vector2 origin, Vector2 destination, T element)
public static bool IsPathable(Vector2 origin, Vector2 destination, T element)
{
var path = FindDirectionTowardsDestination(element.GetPaths(), origin, destination);
var path = FindDirectionTowardsDestination(element.MoveSet.GetMoves(), origin, destination);
return IsPathable(origin, destination, path.Direction);
}
public bool IsPathable(Vector2 origin, Vector2 destination, Vector2 direction)
public static bool IsPathable(Vector2 origin, Vector2 destination, Vector2 direction)
{
direction = Vector2.Normalize(direction);
var next = Vector2.Add(origin, direction);