[orx-math] Make Matrix and SparseMatrix serializable with kotlinx.serialization

This commit is contained in:
Edwin Jakobs
2025-08-16 21:06:39 +02:00
parent 4db699a81d
commit 535c1f9685
2 changed files with 5 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package org.openrndr.extra.math.matrix package org.openrndr.extra.math.matrix
import kotlinx.serialization.Serializable
/** /**
* Represents a two-dimensional matrix with support for basic operations such as indexing, * Represents a two-dimensional matrix with support for basic operations such as indexing,
* copying, and mathematical computations. * copying, and mathematical computations.
@@ -7,6 +9,7 @@ package org.openrndr.extra.math.matrix
* @property rows The number of rows in the matrix. * @property rows The number of rows in the matrix.
* @property cols The number of columns in the matrix. * @property cols The number of columns in the matrix.
*/ */
@Serializable
class Matrix(val rows: Int, val cols: Int) { class Matrix(val rows: Int, val cols: Int) {
val data = Array(rows) { DoubleArray(cols) } val data = Array(rows) { DoubleArray(cols) }

View File

@@ -1,5 +1,6 @@
package org.openrndr.extra.math.matrix package org.openrndr.extra.math.matrix
import kotlinx.serialization.Serializable
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.sqrt import kotlin.math.sqrt
@@ -37,6 +38,7 @@ private fun countNonZeroElements(matrix: Matrix): Int {
* @property columnIndices Array containing the column indices of the non-zero values. * @property columnIndices Array containing the column indices of the non-zero values.
* @property rowPointers Array containing the starting position of each row in the values array. * @property rowPointers Array containing the starting position of each row in the values array.
*/ */
@Serializable
class SparseMatrix( class SparseMatrix(
val rows: Int, val rows: Int,
val cols: Int, val cols: Int,