Package uk.ac.starlink.ttools.plot2.geom
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 class
Represents 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 TypeMethodDescriptionboolean
getCell
(int icell) Returns the cell at a given position in this shapes list of cells.int
Returns the number of cells in this shape.int
getIndex
(int ix, int iy) Returns the index of the cell at a given X,Y position.int
getIndex
(MatrixShape.Cell cell) Returns the index of a given cell.int
getWidth()
Returns the linear size of this matrix.boolean
Indicates whether this shape contains cells on the diagonal.int
hashCode()
boolean
hasLower()
Indicates whether this shape contains cells below the diagonal.boolean
hasUpper()
Indicates whether this shape contains cells above the diagonal.iterator()
Returns an iterator over this shape's cells.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.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:
iterator
in interfaceIterable<MatrixShape.Cell>
- Returns:
- cell iterator
-
toString
-
hashCode
public int hashCode() -
equals
-