Skip to content

Commit

Permalink
feat: add IPathfinder (#50)
Browse files Browse the repository at this point in the history
* feat: Add IPathfinder

* docs: add documentation
  • Loading branch information
joachimdekker authored May 8, 2024
1 parent 27525ac commit c51b832
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Aplib.Extensions/Aplib.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Aplib.Core\Aplib.Core.csproj"/>
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions Aplib.Extensions/IPathfinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace Aplib.Extensions
{
/// <summary>
/// Defines a pathfinding algorithm used to find a path from a starting point to an end point.
/// </summary>
/// <typeparam name="T">The type of the elements in the path.</typeparam>
public interface IPathfinder<T>
{
/// <summary>
/// Finds a path from the specified starting point to the specified end point.
/// </summary>
/// <typeparam name="T">The type of the elements in the path.</typeparam>
/// <param name="begin">The starting point of the path.</param>
/// <param name="end">The end point of the path.</param>
/// <returns>A read-only span of elements representing the path from the starting point to the end point.</returns>
public ReadOnlySpan<T> FindPath(T begin, T end);

/// <summary>
/// Gets the next step towards the specified end point from the current point in the path.
/// </summary>
/// <typeparam name="T">The type of the elements in the path.</typeparam>
/// <param name="current">The current point in the path.</param>
/// <param name="end">The end point of the path.</param>
/// <returns>The next step towards the end point.</returns>
public T GetNextStep(T current, T end);

/// <summary>
/// Tries to get the next step towards the specified end point from the current point in the path.
/// </summary>
/// <typeparam name="T">The type of the elements in the path.</typeparam>
/// <param name="current">The current point in the path.</param>
/// <param name="end">The end point of the path.</param>
/// <param name="nextStep">When this method returns, contains the next step towards the end point if it exists, or the default value of type T if there is no next step.</param>
/// <returns>true if the next step towards the end point is obtained successfully; otherwise, false.</returns>
public bool TryGetNextStep(T current, T end, out T nextStep);
}
}
6 changes: 6 additions & 0 deletions Aplib.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aplib.Core", "Aplib.Core\Ap
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aplib.Core.Tests", "Aplib.Tests\Aplib.Core.Tests.csproj", "{67D4F6C5-758D-489F-A100-8B259B2158D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aplib.Extensions", "Aplib.Extensions\Aplib.Extensions.csproj", "{8D5F1FCC-D4DF-4D50-BCC4-EBE52D0D4F5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Release|Any CPU.Build.0 = Release|Any CPU
{8D5F1FCC-D4DF-4D50-BCC4-EBE52D0D4F5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D5F1FCC-D4DF-4D50-BCC4-EBE52D0D4F5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D5F1FCC-D4DF-4D50-BCC4-EBE52D0D4F5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D5F1FCC-D4DF-4D50-BCC4-EBE52D0D4F5B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit c51b832

Please sign in to comment.