Skip to content

Instantly share code, notes, and snippets.

@DavidMcLaughlin208
DavidMcLaughlin208 / IterateBetweenTwoPointsOnMatrix.java
Last active March 15, 2025 12:21
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;