From 3008a12bc1eaa1a3f6f2f86b7630f9cdf652ff99 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 7 Jun 2026 21:45:12 -0400 Subject: [PATCH 1/3] Matrix coercion for arith operators --- .../casting/arithmetic/MatrixArithmetic.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt b/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt index cf52cca..2ca8bbe 100644 --- a/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt +++ b/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt @@ -10,12 +10,17 @@ import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate import at.petrak.hexcasting.api.casting.iota.DoubleIota import at.petrak.hexcasting.api.casting.iota.Iota +import at.petrak.hexcasting.api.casting.iota.Vec3Iota import at.petrak.hexcasting.api.casting.math.HexDir import at.petrak.hexcasting.api.casting.math.HexPattern import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.DOUBLE +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.VEC3 import org.ejml.simple.SimpleMatrix +import ram.talia.moreiotas.api.asSimpleMatrix import ram.talia.moreiotas.api.casting.iota.MatrixIota import ram.talia.moreiotas.api.matrixWrongSize +import ram.talia.moreiotas.api.util.Anyone import ram.talia.moreiotas.common.casting.arithmetic.operator.matrix.OperatorMatrixAdd import ram.talia.moreiotas.common.casting.arithmetic.operator.matrix.OperatorMatrixDiv import ram.talia.moreiotas.common.casting.arithmetic.operator.matrix.OperatorMatrixMul @@ -95,10 +100,25 @@ object MatrixArithmetic : Arithmetic { op.apply(Operator.downcast(i, MATRIX).simpleMatrix) ) } - private fun make2SameSize(op: BinaryOperator): OperatorBinary = OperatorBinary(IotaMultiPredicate.all(IotaPredicate.ofType(MATRIX))) + val numVecMatPred = IotaPredicate.any(IotaPredicate.ofType(DOUBLE), IotaPredicate.ofType(VEC3), IotaPredicate.ofType(MATRIX)) + + fun parseNumVecMat(iota: Iota, argc: Int, idx: Int): SimpleMatrix { + return when (iota) { + is DoubleIota -> SimpleMatrix(1, 1, false, iota.double) + is Vec3Iota -> iota.vec3.asSimpleMatrix + is MatrixIota -> iota.simpleMatrix + else -> throw MishapInvalidIota.of( + iota, + argc - (idx + 1), + "numvecmat" + ) + } + } + + private fun make2SameSize(op: BinaryOperator): OperatorBinary = OperatorBinary(IotaMultiPredicate.all(numVecMatPred)) { i, j -> - val mat0 = Operator.downcast(i, MATRIX).simpleMatrix - val mat1 = Operator.downcast(j, MATRIX).simpleMatrix + val mat0 = parseNumVecMat(i, 2, 0) + val mat1 = parseNumVecMat(j, 2, 1) if (mat0.numRows != mat1.numRows || mat0.numCols != mat1.numCols) throw MishapInvalidIota.matrixWrongSize(MatrixIota(mat1), 0, mat0.numRows, mat1.numCols) From aa63715223bddc1911520bf37e4b3c4bff02e0cd Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Sun, 7 Jun 2026 21:45:17 -0400 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9639576..7714aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed - Fixed item stack iotas using an untranslated lang key when referenced in a mishap message. +- Fixed the element-wise matrix operations not coercing numbers or vectors to matrices like the other matrix patterns do. - Fixed Patternmaster's Purification throwing an exception when used on any non-static pattern, by beholderface in [#59](https://github.com/FallingColors/MoreIotas/pull/59). - Fixed a crash when trying to invert a non-invertible matrix, by c-Caelum in [#66](https://github.com/FallingColors/MoreIotas/pull/66). From 913d51909abff66dbbfb3e10b3d261206b1cd9e7 Mon Sep 17 00:00:00 2001 From: Robotgiggle <88736742+Robotgiggle@users.noreply.github.com> Date: Tue, 16 Jun 2026 00:56:53 -0400 Subject: [PATCH 3/3] Named arguments for parseNumVecMat --- .../moreiotas/common/casting/arithmetic/MatrixArithmetic.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt b/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt index 2ca8bbe..caed1d7 100644 --- a/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt +++ b/Common/src/main/java/ram/talia/moreiotas/common/casting/arithmetic/MatrixArithmetic.kt @@ -117,8 +117,8 @@ object MatrixArithmetic : Arithmetic { private fun make2SameSize(op: BinaryOperator): OperatorBinary = OperatorBinary(IotaMultiPredicate.all(numVecMatPred)) { i, j -> - val mat0 = parseNumVecMat(i, 2, 0) - val mat1 = parseNumVecMat(j, 2, 1) + val mat0 = parseNumVecMat(i, argc = 2, idx = 0) + val mat1 = parseNumVecMat(j, argc = 2, idx = 1) if (mat0.numRows != mat1.numRows || mat0.numCols != mat1.numCols) throw MishapInvalidIota.matrixWrongSize(MatrixIota(mat1), 0, mat0.numRows, mat1.numCols)