Skip to content

Instantly share code, notes, and snippets.

View DavidMcLaughlin208's full-sized avatar

David McLaughlin DavidMcLaughlin208

View GitHub Profile
@DavidMcLaughlin208
DavidMcLaughlin208 / IterateBetweenTwoPointsOnMatrix.java
Last active June 9, 2024 16:49
Algorithm to move from one point on a 2D matrix to another in the shortest most logical route
public void iterateAndApplyMethodBetweenTwoPoints(Vector2 pos1, Vector2 pos2, Supplier<FunctionInput> function) {
// If the two points are the same no need to iterate. Just run the provided function
if (pos1.epsilonEquals(pos2)) {
function.invoke();
return;
}
int matrixX1 = pos1.x;
int matrixY1 = pos1.y;
int matrixX2 = pos2.x;
@DavidMcLaughlin208
DavidMcLaughlin208 / Pavlidis.java
Last active May 29, 2020 21:44
Pavlidis' Contour Tracing Algorithm Implementation in Java
public class Pavlidis {
private Pavlidis() { throw new IllegalStateException("Cannot instantiate Pavlidis"); }
private static final Map<Direction, Map<DirectionalVector, Direction>> directionMap = new HashMap<>();
private static final Map<Direction, Direction> rotateDirectionMap = new HashMap<>();
static {
// This is used to determine the next relative direction when moving to a found element
directionMap.put(Direction.North, new HashMap<>());