# Class MatrixShape

java.lang.Object
uk.ac.starlink.ttools.plot2.geom.MatrixShape

All Implemented Interfaces:
  `Iterable<MatrixShape.Cell>`

@Equality public class MatrixShape extends Object implements 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 Classes
Modifier and Type
Class
Description
`static class`
`MatrixShape.Cell`
Represents one cell in a 2x2 matrix.

## Constructor Summary

Constructors
Constructor
Description
`MatrixShape(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 Type
Method
Description
`boolean`
`equals(Object o)`
`MatrixShape.Cell`
`getCell(int icell)`
Returns the cell at a given position in this shapes list of cells.
`int`
`getCellCount()`
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`
`hasDiagonal()`
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<MatrixShape.Cell>`
`iterator()`
Returns an iterator over this shape's cells.
`String`
`toString()`

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### 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 matrix
  `hasDiagonal` - 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 index
  `iy` - Y index
Returns:
  index of given cell into list, or -1

### getIndex

public int getIndex(MatrixShape.Cell cell)
Returns the index of a given cell.

Parameters:
  `cell` - cell
Returns:
  index of given cell into list, or -1

### getCell

public MatrixShape.Cell getCell(int icell)
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

public Iterator<MatrixShape.Cell> iterator()
Returns an iterator over this shape's cells.

Specified by:
  `iterator` in interface `Iterable<MatrixShape.Cell>`
Returns:
  cell iterator

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`