-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New calculators and some minor improvements
- Loading branch information
1 parent
418ad95
commit 3828725
Showing
20 changed files
with
328 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using CMGTGraph.Types; | ||
|
||
namespace CMGTGraph.Calculators | ||
{ | ||
/// <summary> | ||
/// This uses Diagonal distance. Use this if you can move in 8 directions. | ||
/// </summary> | ||
public class PointDiagonalCalculator : ICalculator<Point> | ||
{ | ||
private readonly float _straight; | ||
|
||
private readonly float _diagonal; | ||
|
||
private PointDiagonalCalculator(float straight = 1f, float diagonal = 1.41421356237f) | ||
{ | ||
_straight = straight; | ||
_diagonal = diagonal; | ||
} | ||
|
||
public static readonly PointDiagonalCalculator Octile; | ||
|
||
/// <summary> | ||
/// Diagonal calculator which treats diagonal and straight edges equally in the heuristic. | ||
/// </summary> | ||
public static readonly PointDiagonalCalculator Chebyshev; | ||
|
||
static PointDiagonalCalculator() | ||
{ | ||
Octile = new PointDiagonalCalculator(1f, (float) Math.Sqrt(2f)); | ||
Chebyshev = new PointDiagonalCalculator(1f, 1f); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float SqrDistance(Point a, Point b) | ||
{ | ||
var d = Distance(a, b); | ||
return d * d; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float Distance(Point a, Point b) | ||
{ | ||
var dx = Math.Abs(a.X - b.X); | ||
var dy = Math.Abs(a.Y - b.Y); | ||
return _straight * (dx + dy) + (_diagonal - 2 * _straight) * Math.Min(dx, dy); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using CMGTGraph.Types; | ||
|
||
namespace CMGTGraph.Calculators | ||
{ | ||
public class PointFDiagonalCalculator : ICalculator<PointF> | ||
{ | ||
private readonly float _straight; | ||
// SQRT 2 | ||
private readonly float _diagonal; | ||
|
||
private PointFDiagonalCalculator(float straight = 1f, float diagonal = 1.41421356237f) | ||
{ | ||
_straight = straight; | ||
_diagonal = diagonal; | ||
} | ||
|
||
public static readonly PointFDiagonalCalculator Octile; | ||
/// <summary> | ||
/// Diagonal calculator which treats diagonal and straight edges equally in the heuristic. | ||
/// </summary> | ||
public static readonly PointFDiagonalCalculator Chebyshev; | ||
|
||
static PointFDiagonalCalculator() | ||
{ | ||
Octile = new PointFDiagonalCalculator(); | ||
Chebyshev = new PointFDiagonalCalculator(1f, 1f); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float SqrDistance(PointF a, PointF b) | ||
{ | ||
var d = Distance(a, b); | ||
return d * d; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float Distance(PointF a, PointF b) | ||
{ | ||
var dx = Math.Abs(a.X - b.X); | ||
var dy = Math.Abs(a.Y - b.Y); | ||
return _straight * (dx + dy) + (_diagonal - 2 * _straight) * Math.Min(dx, dy); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using CMGTGraph.Types; | ||
|
||
namespace CMGTGraph.Calculators | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class PointFManhattanCalculator : ICalculator<PointF> | ||
{ | ||
public static readonly PointFManhattanCalculator This; | ||
|
||
private PointFManhattanCalculator() | ||
{ | ||
} | ||
|
||
static PointFManhattanCalculator() => This = new PointFManhattanCalculator(); | ||
|
||
/// <inheritdoc /> | ||
public float SqrDistance(PointF a, PointF b) | ||
{ | ||
var d = Distance(a, b); | ||
return d * d; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float Distance(PointF a, PointF b) | ||
{ | ||
return Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using CMGTGraph.Types; | ||
|
||
namespace CMGTGraph.Calculators | ||
{ | ||
/// <summary> | ||
/// This uses Manhattan square distance as the distance calculation. | ||
/// Use this when you can move in 4 directions | ||
/// </summary> | ||
public class PointManhattanCalculator : ICalculator<Point> | ||
{ | ||
public static readonly PointManhattanCalculator This; | ||
|
||
private PointManhattanCalculator() | ||
{ } | ||
|
||
static PointManhattanCalculator() => This = new PointManhattanCalculator(); | ||
|
||
/// <inheritdoc /> | ||
public float SqrDistance(Point a, Point b) | ||
{ | ||
var d = Distance(a, b); | ||
return d * d; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public float Distance(Point a, Point b) | ||
{ | ||
return Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.