Skip to content

Commit

Permalink
Typo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
artifixer committed May 14, 2024
1 parent 382f834 commit 84a6e3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/articles/DistanceMatrix/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Distance Matrix is a subsystem that provides a means for handling distances betw
Additionally, there are built-in implementations for `Settlement`, `Clan`, and `Kingdom` types, along with a behavior to keep the distances updated.

## Usage
Use [``DistanceMatrix``](xref:Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix) class to work with your custom distance matrix.
Use [``DistanceMatrix<T>``](xref:Bannerlord.ButterLib.DistanceMatrix.DistanceMatrix-1) class to work with your custom distance matrix.
Use [``CampaignExtensions``](xref:Bannerlord.ButterLib.Common.Extensions.CampaignExtensions) to access the built-in implementations.

If you plan to use built-in implementations and behavior, don't forget to enable the SubSystem in your `SubModule` class:
Expand All @@ -20,11 +20,11 @@ Example usage of built-in `DistanceMatrix` for `Clan` type:
var clanDistanceMatrix = Campaign.Current.GetDefaultClanDistanceMatrix();

var playerClan = Clan.PlayerClan;
var playerNeighbors = clanDistanceMatrix.GetNearestNeighbors(playerClan, 10);
var playerNeighbours = clanDistanceMatrix.GetNearestNeighbours(playerClan, 10);

Clan inquiredClan = Clan.All.FirstOrDefault(clan => clan.Fiefs.Count > 0 && Clan.All.Any(x => x.Fiefs.Count > 0 && clan.MapFaction.IsAtWarWith(x.MapFaction)));
var unfriendlyNeighbors = clanDistanceMatrix.GetNearestNeighbors(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList();
var unfriendlyNeighborsN = clanDistanceMatrix.GetNearestNeighborsNormalized(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList();
var unfriendlyNeighbours = clanDistanceMatrix.GetNearestNeighbours(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList();
var unfriendlyNeighboursN = clanDistanceMatrix.GetNearestNeighboursNormalized(inquiredObject: inquiredClan, 20, x => !float.IsNaN(x.Distance) && x.OtherObject != inquiredClan && x.OtherObject.MapFaction.IsAtWarWith(inquiredClan.MapFaction)).ToList();
```

Example usage of Distance Matrix with custom selector and distance calculator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ public override void SetDistance(T object1, T object2, float distance)
}

/// <inheritdoc/>
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count) => GetNearestNeighbors(inquiredObject, count, IsNotNaN());
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count) => GetNearestNeighbours(inquiredObject, count, IsNotNaN());

/// <inheritdoc/>
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate) =>
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate) =>
_flatenedDictionary.TryGetValue(inquiredObject, out var nearestNeighbors) ? nearestNeighbors.Where(searchPredicate).Take(count) : [];

/// <inheritdoc/>
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f) =>
GetNearestNeighborsNormalized(inquiredObject, count, IsNotNaN(), scaleMin, scaleMax);
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f) =>
GetNearestNeighboursNormalized(inquiredObject, count, IsNotNaN(), scaleMin, scaleMax);

/// <inheritdoc/>
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f)
public override IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f)
{
if (_flatenedDictionary.TryGetValue(inquiredObject, out var nearestNeighbors))
{
Expand Down
8 changes: 4 additions & 4 deletions src/Bannerlord.ButterLib/DistanceMatrix/DistanceMatrixT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected DistanceMatrix(Func<IEnumerable<T>> customListGetter, Func<T, T, float
/// <param name="inquiredObject">Object to search nearest neighbours for.</param>
/// <param name="count">Number of neighbours to be returned.</param>
/// <returns></returns>
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count);
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count);

/// <summary>
/// Search for nearest neighbours of the specified type <typeparamref name="T"/> object
Expand All @@ -119,7 +119,7 @@ protected DistanceMatrix(Func<IEnumerable<T>> customListGetter, Func<T, T, float
/// <param name="count">Number of neighbours to be returned.</param>
/// <param name="searchPredicate">A search predicate to filter through neighbours before returning nearest ones that qualify.</param>
/// <returns></returns>
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbors(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate);
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighbours(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate);

/// <summary>
/// Search for nearest neighbours of the specified type <typeparamref name="T"/> object
Expand All @@ -132,7 +132,7 @@ protected DistanceMatrix(Func<IEnumerable<T>> customListGetter, Func<T, T, float
/// <param name="scaleMin">Minimum normalized value.</param>
/// <param name="scaleMax">Maximum normalized value.</param>
/// <returns></returns>
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f);
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, float scaleMin = 0f, float scaleMax = 100f);

/// <summary>
/// Search for nearest neighbours of the specified type <typeparamref name="T"/> object
Expand All @@ -146,5 +146,5 @@ protected DistanceMatrix(Func<IEnumerable<T>> customListGetter, Func<T, T, float
/// <param name="scaleMin">Minimum normalized value.</param>
/// <param name="scaleMax">Maximum normalized value.</param>
/// <returns></returns>
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighborsNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f);
public abstract IEnumerable<(T OtherObject, float Distance)> GetNearestNeighboursNormalized(T inquiredObject, int count, Func<(T OtherObject, float Distance), bool> searchPredicate, float scaleMin = 0f, float scaleMax = 100f);
}

0 comments on commit 84a6e3c

Please sign in to comment.