Skip to content

Commit 18377e2

Browse files
committed
Added magnitude to MatrixPosition#move
1 parent 748488c commit 18377e2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/togetherjava/aoc/core/math/matrix/MatrixPosition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import org.togetherjava.aoc.core.math.Direction;
44

55
public record MatrixPosition(int row, int col) {
6+
67
public MatrixPosition move(int rows, int cols) {
78
return new MatrixPosition(row + rows, col + cols);
89
}
910

1011
public MatrixPosition move(Direction direction) {
1112
return new MatrixPosition(row - direction.getY(), col + direction.getX());
1213
}
14+
15+
public MatrixPosition move(Direction direction, int magnitude) {
16+
return new MatrixPosition(row - (direction.getY() * magnitude), col + (direction.getX() * magnitude));
17+
}
1318
}

0 commit comments

Comments
 (0)