danmatrix / Exports / DanMatrix
DanMatrix is a class to handle two-dimension vectors, or matrices
Name | Description |
---|---|
T |
is the type of element storable in the matrix |
- addColumn
- addRow
- clone
- colsNum
- get
- getColumnAt
- getColumnsIterator
- getCoord
- getMatrixString
- getRowAt
- getRowsIterator
- insertColumnAt
- insertRowAt
- lookForValue
- removeColumnAt
- removeRowAt
- replaceColumnAt
- replaceRowAt
- rowsNum
- set
- setCoord
- setupMatrix
• new DanMatrix<T
>(props?
): DanMatrix
<T
>
The public constructor of DanMatrix
Name |
---|
T |
Name | Type | Description |
---|---|---|
props? |
DanMatrixConstructorType <T > |
the optional input of type DanMatrixConstructorType |
DanMatrix
<T
>
• Private
_2dvector: T
[][]
The data structure containing the real data.
It's defined as an Array of Array of T
Type Param
is the type of element storable in the matrix
▸ addColumn(column
): boolean
Add a column to the matrix
Name | Type | Description |
---|---|---|
column |
T [] |
the column to be added |
boolean
true if the new column was correctly added, otherwise it returns false
Throws
Error if a wrong input is passed
▸ addRow(row
): boolean
Add a row to the matrix
Name | Type | Description |
---|---|---|
row |
T [] |
the row to be added |
boolean
true if the new row was correctly added, otherwise it returns false
Throws
Error if a wrong input is passed
▸ clone(): DanMatrix
<T
>
Clone the current DanMatrix instance
DanMatrix
<T
>
a new DanMatrix instance equal to the current one
▸ colsNum(): number
Get the number of columns of the matrix
number
the number of columns of the matrix
▸ get(x
, y
): undefined
| T
Get the matrix value at (x, y)
Name | Type | Description |
---|---|---|
x |
number |
the x coordinate (index of the rows) |
y |
number |
the y coordinate (index of the columns) |
undefined
| T
the value at (x, y) or undefined if the coordinates are wrong
▸ getColumnAt(columnIndex
): undefined
| T
[]
Get matrix column at columnIndex
Name | Type | Description |
---|---|---|
columnIndex |
number |
the column index |
undefined
| T
[]
the requested column as array of values
Throws
Error if a wrong input is passed
▸ getColumnsIterator(): DanMatrixColumnsIterator
<T
>
Get matrix columns iterator
the matrix columns iterator
▸ getCoord(coord
): undefined
| T
Get the matrix value at coord
Name | Type | Description |
---|---|---|
coord |
string |
a string representation of the coordinates using the dash '-' as separator. Example: "1-4" represents x:1 and y:4 |
undefined
| T
the value at coord
or undefined if the string coordinates are wrong
▸ getMatrixString(fixedSpacing?
): string
Get a string representation of the current DanMatrix instance
Name | Type | Default value | Description |
---|---|---|---|
fixedSpacing |
number |
15 |
an optional numeric value for the cell spacing (default is 15) |
string
a string representation of the current DanMatrix instance
▸ getRowAt(rowIndex
): undefined
| T
[]
Get matrix row at rowIndex
Name | Type | Description |
---|---|---|
rowIndex |
number |
the row index |
undefined
| T
[]
the requested row as array of values
Throws
Error if a wrong input is passed
▸ getRowsIterator(): DanMatrixRowsIterator
<T
>
Get matrix rows iterator
the matrix rows iterator
▸ insertColumnAt(columnIndex
, column
): boolean
Insert a column at the specific columnIndex
index
Name | Type | Description |
---|---|---|
columnIndex |
number |
the column index |
column |
T [] |
the column to insert as an array of values |
boolean
true if the new column was correctly inserted, otherwise it returns false
Throws
Error if a wrong input is passed
▸ insertRowAt(rowIndex
, row
): boolean
Insert a row at the specific rowIndex
index
Name | Type | Description |
---|---|---|
rowIndex |
number |
the row index |
row |
T [] |
the row to insert as an array of values |
boolean
true if the new row was correctly inserted, otherwise it returns false
Throws
Error if a wrong input is passed
▸ lookForValue(val
): string
[]
Look for a specific value inside the matrix
Name | Type | Description |
---|---|---|
val |
T |
the value you're looking for |
string
[]
- an array of string coordinates where the value was found
▸ removeColumnAt(columnIndex
): boolean
Remove matrix column at index 'columnIndex'
Name | Type | Description |
---|---|---|
columnIndex |
number |
the index of the column to be removed. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown |
boolean
true if the column removal was successful, otherwise it returns false
Throws
exception "Error('Wrong input')" when any parameter in input is wrong
▸ removeRowAt(rowIndex
): boolean
Remove matrix row at index 'rowIndex'
Name | Type | Description |
---|---|---|
rowIndex |
number |
the index of the row to be removed. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown |
boolean
true if the row removal was successful, otherwise it returns false
Throws
exception "Error('Wrong input')" when any parameter in input is wrong
▸ replaceColumnAt(columnIndex
, column
): boolean
Replace matrix column at index 'columnIndex'
Name | Type | Description |
---|---|---|
columnIndex |
number |
the index of the column to be replaced. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown |
column |
T [] |
the array of values which must replace the existing column. If it's not an array or if the array is empty, an exception "Error('Wrong input')" is thrown |
boolean
true if the column replacement was successful, otherwise it returns false
Throws
exception "Error('Wrong input')" when any parameter in input is wrong
▸ replaceRowAt(rowIndex
, row
): boolean
Replace matrix row at index 'rowIndex'
Name | Type | Description |
---|---|---|
rowIndex |
number |
the index of the row to be replaced. If it's not an integer number or if it's less than zero, an exception "Error('Wrong input')" is thrown |
row |
T [] |
the array of values which must replace the existing row. If it's not an array or if the array is empty, an exception "Error('Wrong input')" is thrown |
boolean
true if the row replacement was successful, otherwise it returns false
Throws
exception "Error('Wrong input')" when any parameter in input is wrong
▸ rowsNum(): number
Get the number of rows of the matrix
number
the number of rows of the matrix
▸ set(x
, y
, val
): undefined
| T
Set a value at (x, y)
Name | Type | Description |
---|---|---|
x |
number |
the x coordinate (index of the rows) |
y |
number |
the y coordinate (index of the columns) |
val |
T |
the value to set |
undefined
| T
the new value set at (x, y) or undefined if the coordinates are wrong
▸ setCoord(coord
, val
): undefined
| T
Set a value at coord
Name | Type | Description |
---|---|---|
coord |
string |
a string representation of the coordinates using the dash '-' as separator. Example: "1-4" represents x:1 and y:4 |
val |
T |
the value to set |
undefined
| T
the value at coord
or undefined if the string coordinates are wrong
▸ setupMatrix(props?
): void
The public method to setup the matrix
Name | Type | Description |
---|---|---|
props? |
DanMatrixConstructorType <T > |
the optional input of type DanMatrixConstructorType |
void
Throws
Error if a wrong input is passed