CPArray2D

org.cosplay.CPArray2D
See theCPArray2D companion object
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.

Attributes

Note

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

Companion
object
Source
CPArray2D.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

Source
CPArray2D.scala

Concrete methods

def clear(): Unit

Clears this array with the clear value.

Clears this array with the clear value.

Attributes

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.

Attributes

Source
CPArray2D.scala
def column(i: Int)(using ClassTag[T]): Seq[T]

Gets i-th column for this 2D array.

Gets i-th column for this 2D array.

Attributes

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.

Attributes

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

Gets a deep copy of this array.

Gets a deep copy of this array.

Attributes

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.

Attributes

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.

Attributes

Source
CPArray2D.scala
override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

See also
Source
CPArray2D.scala
def map[B](f: T => B)(using 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.

Attributes

Source
CPArray2D.scala
def map[B](f: (T, Int, Int) => B)(using 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.

Attributes

Source
CPArray2D.scala
def row(i: Int)(using ClassTag[T]): Seq[T]

Gets i-th row for this 2D array.

Gets i-th row for this 2D array.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

Returns

Trimmed out (smaller) copy of this array.

Note

If trimming is not possible, returns this array.

Source
CPArray2D.scala

Concrete fields

val dim: CPDim

Dimension of this array.

Dimension of this array.

Attributes

Source
CPArray2D.scala
val height: Int

Attributes

Source
CPArray2D.scala
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.

Attributes

Source
CPArray2D.scala
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.

Attributes

Source
CPArray2D.scala
val rect: CPRect

Shape of this array as a rectangle.

Shape of this array as a rectangle.

Attributes

Source
CPArray2D.scala
val size: Int

Number of cells in this 2D array.

Number of cells in this 2D array.

Attributes

Source
CPArray2D.scala
val width: Int

Attributes

Source
CPArray2D.scala
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.

Attributes

Source
CPArray2D.scala
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.

Attributes

Source
CPArray2D.scala