Index2D
Index2D
Two-dimensional index for referencing elements in an Array2D
.
add : Index2D, Index2D, Shape2D -> Result Index2D [OutOfBounds]
Add indices, returning a new index with the sum of the two row
values
and sum of the two col
values as component parts. If the resulting index
is not within the array shape then return Err OutOfBounds
.
sub : Index2D, Index2D, Shape2D -> Result Index2D [OutOfBounds]
Subtract indices, returning a new index with the difference of the two row
values and difference of the two col
values as component parts. If the
resulting index is not within the array shape then return Err OutOfBounds
.
incRow : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Go to the next row index within the array shape, wrapping to the next column
when the end of a row is reached. If the next index is outside of the array
shape then return Err OutOfBounds
.
incCol : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Go to the next column index within the array shape, wrapping to the next row
when the end of a column is reached. If the next index is outside of the
array shape then return Err OutOfBounds
.
decRow : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Go to the previous row index within the array shape, wrapping to the
previous column when the start of a row is reached. If the next index is
outside of the array shape then return Err OutOfBounds
.
decCol : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Go to the previous column index within the array shape, wrapping to the
previous row when the start of a column is reached. If the next index is
outside of the array shape then return Err OutOfBounds
.
adjacentTo : Index2D, Shape2D, [ PrevRow, SameRow, NextRow ], [ PrevCol, SameCol, NextCol ] -> Result Index2D [OutOfBounds]
Try to get an index adjacent to the current index. If the specified adjacent
index is outside of the array shape then return Err OutOfBounds
. Note that
adjacent index shape SameRow SameCol
will return Ok index
.
allAdjacentTo : Index2D, Shape2D -> List Index2D
List all indices adjacent to the given index and within the array shape. The list will contain 0 to 8 indices, and will not include the given index.
flipRow : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Change the row
component of the index, reflecting over the center row or
rows. This swaps the first row with the last row, second row with second to
last row, etc.
flipCol : Index2D, Shape2D -> Result Index2D [OutOfBounds]
Change the col
component of the index, reflecting over the center column
or columns. This swaps the first column with the last column, second column
with second to last column, etc.
transpose : Index2D -> Index2D
Get the transpose for an index.
Swaps the row
and col
index components, reflecting the index over the
center diagonal line. This operation is independent of array shape, since
transposing an array also changes its shape.
first : Shape2D -> Result Index2D [ShapeWasEmpty]
The first index within the given array shape. If the shape is for an empty
array then return Err ShapeWasEmpty
.
last : Shape2D -> Result Index2D [ShapeWasEmpty]
The last index within the given array shape. If the shape is for an empty
array then return Err ShapeWasEmpty
.
isRowStart : Index2D -> Bool
Predicate to determine if an index is the first index in a row.
isColStart : Index2D -> Bool
Predicate to determine if an index is the first index in a column.
isRowEnd : Index2D, Shape2D -> Bool
Predicate to determine if an index is the last index in a row for a given array shape.
isColEnd : Index2D, Shape2D -> Bool
Predicate to determine if an index is the last index in a column for a given array shape.