Struct CellRect
A rectangular block of cells in a text mode grid, addressed as a top-left (row, column) origin plus a row count and a column count.
Implements
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
public readonly struct CellRect : IEquatable<CellRect>
Remarks
Every member names its axis outright rather than using x and y. The module addresses cells two different ways: CellGrid takes (row, column) while TextModeConsole takes (x, y), where x is the column and y is the row. A rectangle named with x and y would sit on the wrong side of that split and invite the exact mistake this type exists to prevent.
A rectangle whose Rows or Columns is zero or negative is empty and covers no cells. A rectangle may extend past the edge of a grid; use Clamp(int, int) to reduce one to the part that actually exists.
Constructors
CellRect(int, int, int, int)
Creates a new cell rectangle.
Declaration
public CellRect(int row, int column, int rows, int columns)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | Row index of the top edge (0-based). |
| int | column | Column index of the left edge (0-based). |
| int | rows | Number of rows covered. Zero or less produces an empty rectangle. |
| int | columns | Number of columns covered. Zero or less produces an empty rectangle. |
Fields
Column
Column index of the left edge (0-based, left to right).
Declaration
public readonly int Column
Field Value
| Type | Description |
|---|---|
| int |
Columns
Number of columns covered.
Declaration
public readonly int Columns
Field Value
| Type | Description |
|---|---|
| int |
Empty
A rectangle covering no cells, positioned at the grid origin.
Declaration
public static readonly CellRect Empty
Field Value
| Type | Description |
|---|---|
| CellRect |
Row
Row index of the top edge (0-based, top to bottom).
Declaration
public readonly int Row
Field Value
| Type | Description |
|---|---|
| int |
Rows
Number of rows covered.
Declaration
public readonly int Rows
Field Value
| Type | Description |
|---|---|
| int |
Properties
CellCount
Gets the number of cells covered, or zero when the rectangle is empty.
Declaration
public int CellCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets whether the rectangle covers no cells because it has no rows or no columns.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LastColumn
Gets the column index of the right edge, inclusive. Meaningless when the rectangle is empty.
Declaration
public int LastColumn { get; }
Property Value
| Type | Description |
|---|---|
| int |
LastRow
Gets the row index of the bottom edge, inclusive. Meaningless when the rectangle is empty.
Declaration
public int LastRow { get; }
Property Value
| Type | Description |
|---|---|
| int |
Origin
Gets the top-left corner as a cell position.
Declaration
public CellPosition Origin { get; }
Property Value
| Type | Description |
|---|---|
| CellPosition |
Methods
Clamp(CellGrid)
Reduces this rectangle to the part that falls inside the given grid.
Declaration
public CellRect Clamp(CellGrid grid)
Parameters
| Type | Name | Description |
|---|---|---|
| CellGrid | grid | The grid to clamp against. A null grid produces Empty. |
Returns
| Type | Description |
|---|---|
| CellRect | The clamped rectangle, or Empty if nothing remains. |
Clamp(int, int)
Reduces this rectangle to the part that falls inside a grid of the given size.
Declaration
public CellRect Clamp(int gridRows, int gridColumns)
Parameters
| Type | Name | Description |
|---|---|---|
| int | gridRows | Number of rows in the grid. |
| int | gridColumns | Number of columns in the grid. |
Returns
| Type | Description |
|---|---|
| CellRect | The clamped rectangle, or Empty if nothing remains. |
Remarks
Returns Empty when the rectangle lies wholly outside the grid, so the result is always safe to iterate without further bounds checks.
Contains(CellPosition)
Checks whether a cell position falls inside this rectangle.
Declaration
public bool Contains(CellPosition position)
Parameters
| Type | Name | Description |
|---|---|---|
| CellPosition | position | The position to test. |
Returns
| Type | Description |
|---|---|
| bool | True if the position is covered. |
Contains(int, int)
Checks whether a cell coordinate falls inside this rectangle.
Declaration
public bool Contains(int row, int column)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | Row index to test. |
| int | column | Column index to test. |
Returns
| Type | Description |
|---|---|
| bool | True if the coordinate is covered. |
Equals(CellRect)
Checks whether this rectangle covers exactly the same cells as another.
Declaration
public bool Equals(CellRect other)
Parameters
| Type | Name | Description |
|---|---|---|
| CellRect | other | The rectangle to compare against. |
Returns
| Type | Description |
|---|---|
| bool | True if both rectangles are empty, or both have the same origin and size. |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
FromCorners(CellPosition, CellPosition)
Creates a rectangle from two corner positions, in either order.
Declaration
public static CellRect FromCorners(CellPosition first, CellPosition second)
Parameters
| Type | Name | Description |
|---|---|---|
| CellPosition | first | One corner. |
| CellPosition | second | The opposite corner. |
Returns
| Type | Description |
|---|---|
| CellRect | A rectangle covering both corners and everything between them. |
FullGrid(CellGrid)
Creates a rectangle covering every cell of the given grid.
Declaration
public static CellRect FullGrid(CellGrid grid)
Parameters
| Type | Name | Description |
|---|---|---|
| CellGrid | grid | The grid to cover. A null grid produces Empty. |
Returns
| Type | Description |
|---|---|
| CellRect | A rectangle spanning the whole grid. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Operators
operator ==(CellRect, CellRect)
Equality operator.
Declaration
public static bool operator ==(CellRect left, CellRect right)
Parameters
| Type | Name | Description |
|---|---|---|
| CellRect | left | Left operand. |
| CellRect | right | Right operand. |
Returns
| Type | Description |
|---|---|
| bool | True if both rectangles cover the same cells. |
operator !=(CellRect, CellRect)
Inequality operator.
Declaration
public static bool operator !=(CellRect left, CellRect right)
Parameters
| Type | Name | Description |
|---|---|---|
| CellRect | left | Left operand. |
| CellRect | right | Right operand. |
Returns
| Type | Description |
|---|---|
| bool | True if the rectangles cover different cells. |