CPArray2D

class CPArray2D[T](val width: Int, val height: Int)(using c: ClassTag[T])

Immutable 2D-array. Optionally, has a clear value that is used to clear out array.

Type parameters:
T

Type of the array element.

Value parameters:
height

Height of the array. Must be >= 0.

width

Width of the array. Must be >= 0.

Note:

If clear value is not set, the default clear value is null.

Companion:
object
Source:
CPArray2D.scala
class Object
trait Matchable
class Any

Value members

Constructors

def this(t: T)(using ClassTag[T])

Creates 1x1 array with a given single value.

Creates 1x1 array with a given single value.

Value parameters:
t

Value to set at [0,0] coordinate.

Source:
CPArray2D.scala
def this(w: Int, h: Int, clearVal: T)(using ClassTag[T])

Creates wxh array with specified clear value.

Creates wxh array with specified clear value.

Value parameters:
clearVal

Clear value.

h

Array height.

w

Array width.

Source:
CPArray2D.scala
def this(dim: CPDim, clearVal: T)(using ClassTag[T])

Creates array with specified dimension and clear value.

Creates array with specified dimension and clear value.

Value parameters:
clearVal

Clear value.

dim

Array dimension.

Source:
CPArray2D.scala
def this(dim: CPDim)(using ClassTag[T])

Creates array with specified dimension.

Creates array with specified dimension.

Value parameters:
dim

Array dimension.

Source:
CPArray2D.scala

Concrete methods

def clear(): Unit

Clears this array with the clear value.

Clears this array with the clear value.

Note:

If the clear value is not set, the default value is null.

Source:
CPArray2D.scala
def clear(clearVal: T): Unit

Clears this array with given clear value.

Clears this array with given clear value.

Source:
CPArray2D.scala
def contains(p: T => Boolean): Boolean

Checks whether this array contains at least one element satisfying given predicate.

Checks whether this array contains at least one element satisfying given predicate.

Value parameters:
p

Predicate to test.

Source:
CPArray2D.scala
def copy(): CPArray2D[T]

Gets a deep copy of this array.

Gets a deep copy of this array.

Source:
CPArray2D.scala
def copyTo(other: CPArray2D[T], frame: CPRect): Unit

Copies a given frame into another 2D array.

Copies a given frame into another 2D array.

Value parameters:
frame

A frame to copy.

other

Another array to copy to.

Source:
CPArray2D.scala
def count(p: T => Boolean): Int

Counts how many elements in this array satisfying given predicate.

Counts how many elements in this array satisfying given predicate.

Value parameters:
p

Predicate to test.

Source:
CPArray2D.scala
override def equals(obj: Any): Boolean
Definition Classes
Any
Source:
CPArray2D.scala
def extract(rect: CPRect)(using c: ClassTag[T]): CPArray2D[T]

Extracts deep copy sub-array with given shape.

Extracts deep copy sub-array with given shape.

Value parameters:
rect

A shape to extract as a deep copy.

Returns:

Deep copy sub-array with given shape.

Source:
CPArray2D.scala
def flip(using c: ClassTag[T]): CPArray2D[T]

Creates copy of this array with flipped X and Y coordinates.

Creates copy of this array with flipped X and Y coordinates.

Source:
CPArray2D.scala
def foldHor[Z](z: Z)(op: (Z, T) => Z): Z

Collapses given array into a single value given the initial value and associative binary operation acting as an accumulator. Folding over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

Collapses given array into a single value given the initial value and associative binary operation acting as an accumulator. Folding over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

   +-----------------+
   |(0,0) (1,0) (2,0)|
   |(0,1) (1,1) (2,1)|
   |(0,2) (1,2) (2,2)|
   +-----------------+

this method will iterate in the following order:

   (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2)
Value parameters:
op

Accumulating binary operation.

z

Initial value.

Source:
CPArray2D.scala
def foldVert[Z](z: Z)(op: (Z, T) => Z): Z

Collapses given array into a single value given the initial value and associative binary operation acting as an accumulator. Folding over the elements in this 2D array will be vertical first. In other words, given the 2D array with the following coordinates:

Collapses given array into a single value given the initial value and associative binary operation acting as an accumulator. Folding over the elements in this 2D array will be vertical first. In other words, given the 2D array with the following coordinates:

   +-----------------+
   |(0,0) (1,0) (2,0)|
   |(0,1) (1,1) (2,1)|
   |(0,2) (1,2) (2,2)|
   +-----------------+

this method will iterate in the following order:

   (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
Value parameters:
op

Accumulating binary operation.

z

Initial value.

Source:
CPArray2D.scala
def foreach(f: T => Unit): Unit

Calls given function for each array element.

Calls given function for each array element.

Value parameters:
f

Function to call for each element.

Source:
CPArray2D.scala
def get(x: Int, y: Int): T

Gets array value for given XY-coordinate.

Gets array value for given XY-coordinate.

Value parameters:
x

X-coordinate.

y

Y-coordinate.

Source:
CPArray2D.scala
def isValid(x: Int, y: Int): Boolean

Checks whether given XY-coordinate is valid for this array.

Checks whether given XY-coordinate is valid for this array.

Value parameters:
x

X-coordinate to check.

y

Y-coordinate to check.

Source:
CPArray2D.scala
def loop(f: (T, Int, Int) => Unit): Unit

Calls given function for each array element. Iteration over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

Calls given function for each array element. Iteration over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

   +-----------------+
   |(0,0) (1,0) (2,0)|
   |(0,1) (1,1) (2,1)|
   |(0,2) (1,2) (2,2)|
   +-----------------+

this method will iterate in the following order:

   (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2)
Value parameters:
f

Function to call for each element. The function takes value and its XY-coordinate in the array.

See also:
Source:
CPArray2D.scala
def loopHor(f: (T, Int, Int) => Unit): Unit

Calls given function for each array element. Iteration over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

Calls given function for each array element. Iteration over the elements in this 2D array will be horizontal first. In other words, given the 2D array with the following coordinates:

   +-----------------+
   |(0,0) (1,0) (2,0)|
   |(0,1) (1,1) (2,1)|
   |(0,2) (1,2) (2,2)|
   +-----------------+

this method will iterate in the following order:

   (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2)
Value parameters:
f

Function to call for each element. The function takes value and its XY-coordinate in the array.

See also:
Source:
CPArray2D.scala
def loopVert(f: (T, Int, Int) => Unit): Unit

Calls given function for each array element. Iteration over the elements in this 2D array will be vertical first. In other words, given the 2D array with the following coordinates:

Calls given function for each array element. Iteration over the elements in this 2D array will be vertical first. In other words, given the 2D array with the following coordinates:

   +-----------------+
   |(0,0) (1,0) (2,0)|
   |(0,1) (1,1) (2,1)|
   |(0,2) (1,2) (2,2)|
   +-----------------+

this method will iterate in the following order:

   (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
Value parameters:
f

Function to call for each element. The function takes value and its XY-coordinate in the array.

See also:
Source:
CPArray2D.scala
def map[B](f: T => B)(using c: ClassTag[B]): CPArray2D[B]

Maps this array to an array of different type.

Maps this array to an array of different type.

Type parameters:
B

Type of the new array.

Value parameters:
f

Mapping function.

Source:
CPArray2D.scala
def map[B](f: (T, Int, Int) => B)(using c: ClassTag[B]): CPArray2D[B]

Map this array using extended mapping function.

Map this array using extended mapping function.

Type parameters:
B

Type of the new array.

Value parameters:
f

Mapping function that takes value and its XY-coordinate in the array.

Source:
CPArray2D.scala
def set(x: Int, y: Int, t: T): Unit

Sets array value at a given XY-coordinate.

Sets array value at a given XY-coordinate.

Value parameters:
t

Value to set.

x

X-coordinate.

y

Y-coordinate.

Source:
CPArray2D.scala
def split(num: Int)(using c: ClassTag[T]): Seq[CPArray2D[T]]

Splits this array into num evenly split sub-arrays.

Splits this array into num evenly split sub-arrays.

Value parameters:
num

Number of sub-arrays to split into.

Returns:

Sequence of sub-arrays.

Note:

num must be > 0. If this array is empty, an empty sequence will be returned.

Source:
CPArray2D.scala
def split(w: Int, h: Int)(using c: ClassTag[T]): Seq[CPArray2D[T]]

Splits this array into a sequence of wxh arrays.

Splits this array into a sequence of wxh arrays.

Value parameters:
h

Height of the split.

w

Width of the split.

Returns:

Sequence of wxh arrays.

Note:

w and h must be > 0.

Given w and h must produce an even split. If this array is empty, an empty sequence will be returned.

Source:
CPArray2D.scala
def trim(blank: T)(using c: ClassTag[T]): CPArray2D[T]

Creates new trimmed array with a given blank value.

Creates new trimmed array with a given blank value.

Value parameters:
blank

Blank value to use for trimming.

Note:

If trimming is not possible, returns this array.

Source:
CPArray2D.scala
def trim(f: T => Boolean)(using c: ClassTag[T]): CPArray2D[T]

Creates new trimmed array. Rows and columns are trimmed if all their values satisfy given predicate.

Creates new trimmed array. Rows and columns are trimmed if all their values satisfy given predicate.

Value parameters:
f

Trimming predicate. If true the value will be considered blank.

Returns:

Trimmed out (smaller) copy of this array.

Note:

If trimming is not possible, returns this array.

Source:
CPArray2D.scala

Concrete fields

final val dim: CPDim

Dimension of this array.

Dimension of this array.

Source:
CPArray2D.scala
val height: Int
final val isEmpty: Boolean

Checks whether or not this array is empty, i.e. it's size == 0.

Checks whether or not this array is empty, i.e. it's size == 0.

Source:
CPArray2D.scala
final val nonEmpty: Boolean

Checks whether or not this array is not empty, i.e. it's size != 0.

Checks whether or not this array is not empty, i.e. it's size != 0.

Source:
CPArray2D.scala
final val rect: CPRect

Shape of this array as a rectangle.

Shape of this array as a rectangle.

Source:
CPArray2D.scala
final val size: Int

Number of cells in this 2D array.

Number of cells in this 2D array.

Source:
CPArray2D.scala
val width: Int
final val xMax: Int

Maximum X-coordinate. If width is zero this will equal to -1.

Maximum X-coordinate. If width is zero this will equal to -1.

Source:
CPArray2D.scala
final val yMax: Int

Maximum Y-coordinate. If height is zero this will equal to -1.

Maximum Y-coordinate. If height is zero this will equal to -1.

Source:
CPArray2D.scala