invoke

open operator override fun <T> invoke(original: SparseMatrix<T>): MutableSparseMatrix<T>

Create a copy of the original matrix. Note that the returned type may differ depending on the type of the parameter. In particular if the parameter is an instance of Matrix the returned type is a MutableMatrix instance.

Parameters

original

The matrix to create a copy of


open operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, initValue: T, validator: (Int, Int) -> Boolean): MutableSparseMatrix<T>

Create a sparse matrix that has the given maximum X and Y values, is initialized with the parameter value, and uses the function to determine whether the cell exists.

Note that all coordinates are initialized with initValue, even when currently sparse. If the validator returns that the cell is no longer sparse this initial value is returned.

Return

The resulting matrix.

Parameters

maxWidth

The maximum width of the matrix

maxHeight

The maximum height of the matrix

initValue

The initial value for each cell in the matrix.

validator

Function that determines whether the cell at the given coordinates exists.


open inline operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, noinline validator: (Int, Int) -> Boolean, init: (Int, Int) -> T): MutableSparseMatrix<T>

Create a mutable sparse matrix that has the given maximum X and Y values, has the given validator to determine sparseness and uses the given function to initialize the matrix (values set on construction).

Return

The resulting matrix.

Parameters

maxWidth

The width of the matrix

maxHeight

The height of the matrix

validator

A function that is used to determine whether a particular coordinate is contained in the matrix.

init

An initialization function that sets the values for the matrix.


open inline operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, init: SparseMatrix.SparseInit<T>.(Int, Int) -> SparseMatrix.SparseValue<T>): MutableSparseMatrix<T>

Create a mutable sparse matrix with given maximum X and Y that is initialized using the given "constructor" function. This function invokes the initializer on construction only.

Example (creating a matrix with a hole in the middle):

val donut = SparseMatrix(3, 3) { x, y ->
when {
y == 0 -> value(x + 1)
y == 2 -> value(7-x)
x == 0 -> value(8)
x == 2 -> value(4)
else -> sparse
}
}

Return

A matrix initialized according to the init function

Parameters

maxWidth

The width of the matrix

maxHeight

The height of the matrix

init

The function used to initialize the matrix.