invoke
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
The matrix to create a copy of
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
The maximum width of the matrix
The maximum height of the matrix
The initial value for each cell in the matrix.
Function that determines whether the cell at the given coordinates exists.
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
The width of the matrix
The height of the matrix
A function that is used to determine whether a particular coordinate is contained in the matrix.
An initialization function that sets the values for the matrix.
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
The width of the matrix
The height of the matrix
The function used to initialize the matrix.