Class MatrixShape
java.lang.Object
uk.ac.starlink.ttools.plot2.geom.MatrixShape
- All Implemented Interfaces:
Iterable<MatrixShape.Cell>
Defines the shape of an ordered list of cells from a square matrix,
and a mapping between an index and the cells.
The list may include zero or more of diagonal, upper-triangle and
lower-triangle cells of the matrix.
- Since:
- 1 Jun 2023
- Author:
- Mark Taylor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents one cell in a 2x2 matrix. -
Constructor Summary
ConstructorsConstructorDescriptionMatrixShape(int nx) Constructs a MatrixShape containing all cells in the matrix.MatrixShape(int nx, boolean hasDiagonal, boolean hasLower, boolean hasUpper) Constructs a MatrixShape containing selected cells. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetCell(int icell) Returns the cell at a given position in this shapes list of cells.intReturns the number of cells in this shape.intgetIndex(int ix, int iy) Returns the index of the cell at a given X,Y position.intgetIndex(MatrixShape.Cell cell) Returns the index of a given cell.intgetWidth()Returns the linear size of this matrix.booleanIndicates whether this shape contains cells on the diagonal.inthashCode()booleanhasLower()Indicates whether this shape contains cells below the diagonal.booleanhasUpper()Indicates whether this shape contains cells above the diagonal.iterator()Returns an iterator over this shape's cells.toString()Methods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
MatrixShape
public MatrixShape(int nx, boolean hasDiagonal, boolean hasLower, boolean hasUpper) Constructs a MatrixShape containing selected cells.- Parameters:
nx- linear size of matrixhasDiagonal- true iff list includes cells on the diagonal (x==y)hasLower- true iff list includes cells below the diagonal (x>y)hasUpper- true iff list includes cells above the diagonal (x<y)
-
MatrixShape
public MatrixShape(int nx) Constructs a MatrixShape containing all cells in the matrix.- Parameters:
nx- linear size of matrix
-
-
Method Details
-
getWidth
public int getWidth()Returns the linear size of this matrix.- Returns:
- width (N) of NxN matrix
-
hasDiagonal
public boolean hasDiagonal()Indicates whether this shape contains cells on the diagonal.- Returns:
- true iff diagonal cells are included (x==y)
-
hasLower
public boolean hasLower()Indicates whether this shape contains cells below the diagonal.- Returns:
- true iff below-diagonal cells are included (x>y)
-
hasUpper
public boolean hasUpper()Indicates whether this shape contains cells above the diagonal.- Returns:
- true iff above-diagonal cells are included (x<y)
-
getCellCount
public int getCellCount()Returns the number of cells in this shape.- Returns:
- cell count
-
getIndex
public int getIndex(int ix, int iy) Returns the index of the cell at a given X,Y position.- Parameters:
ix- X indexiy- Y index- Returns:
- index of given cell into list, or -1
-
getIndex
Returns the index of a given cell.- Parameters:
cell- cell- Returns:
- index of given cell into list, or -1
-
getCell
Returns the cell at a given position in this shapes list of cells.- Parameters:
icell- cell index- Returns:
- cell, or null if out of range
-
iterator
Returns an iterator over this shape's cells.- Specified by:
iteratorin interfaceIterable<MatrixShape.Cell>- Returns:
- cell iterator
-
toString
-
hashCode
-
equals
-