aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/java/coffee/liz/ecs
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-01-25 21:01:28 -0800
committerElizabeth Hunt <me@liz.coffee>2026-01-25 21:01:28 -0800
commit83cb0653209f3300e220e76d3f57a000ef4219a6 (patch)
tree5115f2f6c7cba0227253d832010536bec2e36c4d /core/src/main/java/coffee/liz/ecs
parentde98c427504cde19c7d5ada5c0a238ca91147a4f (diff)
downloadthe-abstraction-engine-v2-83cb0653209f3300e220e76d3f57a000ef4219a6.tar.gz
the-abstraction-engine-v2-83cb0653209f3300e220e76d3f57a000ef4219a6.zip
Make life grid a torus and vastly simplify audio 'visualization'
Diffstat (limited to 'core/src/main/java/coffee/liz/ecs')
-rw-r--r--core/src/main/java/coffee/liz/ecs/math/Mat2.java13
1 files changed, 5 insertions, 8 deletions
diff --git a/core/src/main/java/coffee/liz/ecs/math/Mat2.java b/core/src/main/java/coffee/liz/ecs/math/Mat2.java
index 8be945c..9975227 100644
--- a/core/src/main/java/coffee/liz/ecs/math/Mat2.java
+++ b/core/src/main/java/coffee/liz/ecs/math/Mat2.java
@@ -31,7 +31,8 @@ public final class Mat2 {
}
/**
- * Convolves a {@link Convolver} across a matrix.
+ * Convolves a {@link Convolver} across a matrix reaching neighbors around the
+ * grid like a torus.
*
* @param mat
* is the row-indexed 2d matrix to convolve.
@@ -49,7 +50,7 @@ public final class Mat2 {
* @param <R>
* is the type of the resulting type of each convolution.
*/
- public static <T, R, U> List<List<U>> convolve(final List<List<T>> mat, final Vec2<Integer> axes,
+ public static <T, R, U> List<List<U>> convolveTorus(final List<List<T>> mat, final Vec2<Integer> axes,
final Supplier<R> init, final Convolver<T, R> convolver, final BiFunction<T, R, U> finalReduction) {
final List<List<R>> rows = new ArrayList<>();
for (int y = 0; y < mat.size(); y++) {
@@ -58,13 +59,9 @@ public final class Mat2 {
final T center = mat.get(y).get(x);
R result = init.get();
for (int dy = -axes.getY(); dy <= axes.getY(); dy++) {
- final int ry = y + dy;
- if (ry < 0 || ry >= mat.size())
- continue;
+ final int ry = Math.floorMod(y + dy, mat.size());
for (int dx = -axes.getX(); dx <= axes.getX(); dx++) {
- final int rx = x + dx;
- if (rx < 0 || rx >= mat.get(ry).size())
- continue;
+ final int rx = Math.floorMod(x + dx, mat.get(ry).size());
result = convolver.convolve(mat.get(ry).get(rx), Vec2i.builder().x(dx).y(dy).build(), result);
}
}