Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::CellRect Class Reference

An owning, invariant-preserving half-open cell rectangle. More...

#include <geometry.hpp>

Public Member Functions

 CellRect () noexcept=default
 Create the empty rectangle at (0, 0); no errors.
CellPoint origin () const noexcept
 Return the cell origin by value; no errors.
CellSize size () const noexcept
 Return the normalized cell extents by value; no errors.
std::int32_t right () const noexcept
 Return the representable exclusive horizontal end; no errors.
std::int32_t bottom () const noexcept
 Return the representable exclusive vertical end; no errors.
bool empty () const noexcept
 Whether either extent is zero; no errors.
bool contains (CellPoint point) const noexcept
 Test half-open point membership; an empty rectangle contains no point.
bool contains (CellRect rect) const noexcept
 Test cell-set inclusion; every empty rectangle is a subset of every rectangle.
CellRect intersection (CellRect clip) const noexcept
 Intersect with a clipping rectangle; no errors or invalidation.
std::expected< CellRect, GeometryError > translated (CellPoint offset) const noexcept
 Return an owning translated rectangle, preserving its extents.
bool operator== (const CellRect &other) const noexcept=default
 Compare origin and extents, including the position of empty rectangles.

Static Public Member Functions

static std::expected< CellRect, GeometryError > from (CellPoint origin, CellSize available) noexcept
 Create a rectangle after normalizing negative available extents to zero.

Detailed Description

An owning, invariant-preserving half-open cell rectangle.

The covered cells are [x, right()) x [y, bottom()). Extents are nonnegative; origin and exclusive ends fit int32_t. A zero extent on either axis is empty. All results own their data. No references are borrowed, no allocation occurs, and no implicit Canvas/GUI conversion exists. Values are thread-agnostic; concurrent reads are safe and shared assignment requires synchronization. Operations do not invalidate any values or trigger layout/paint invalidation.

Member Function Documentation

◆ bottom()

std::int32_t portals::CellRect::bottom ( ) const
nodiscardnoexcept

Return the representable exclusive vertical end; no errors.

Returns
The exclusive y coordinate, including for empty rectangles.

◆ contains() [1/2]

bool portals::CellRect::contains ( CellPoint point) const
nodiscardnoexcept

Test half-open point membership; an empty rectangle contains no point.

Parameters
pointCell coordinate tested against the half-open bounds.
Returns
True only when both coordinates lie inside a nonempty rectangle.

◆ contains() [2/2]

bool portals::CellRect::contains ( CellRect rect) const
nodiscardnoexcept

Test cell-set inclusion; every empty rectangle is a subset of every rectangle.

Parameters
rectRectangle whose covered cell set is tested.
Returns
True for an empty rect or when all its covered cells lie inside this rectangle.

◆ empty()

bool portals::CellRect::empty ( ) const
nodiscardnoexcept

Whether either extent is zero; no errors.

Returns
True when width or height is zero.

◆ from()

std::expected< CellRect, GeometryError > portals::CellRect::from ( CellPoint origin,
CellSize available )
staticnodiscardnoexcept

Create a rectangle after normalizing negative available extents to zero.

Parameters
originSigned cell origin, copied without borrowing storage.
availableSigned available cell extents, copied and normalized.
Returns
An independent rectangle, or COORDINATE_OVERFLOW if an end cannot fit.
Note
No exceptions or invalidation; an empty axis still has a checked origin.

◆ intersection()

CellRect portals::CellRect::intersection ( CellRect clip) const
nodiscardnoexcept

Intersect with a clipping rectangle; no errors or invalidation.

Parameters
clipOwning-value clipping bounds, copied without borrowing storage.
Returns
An independent rectangle at the per-axis maximum of the input origins.

Each disjoint/touching axis has zero extent, independently of the other axis. Empty results retain that deterministic origin and the other axis's overlap; their position does not imply point membership. No unchecked subtraction occurs.

◆ operator==()

bool portals::CellRect::operator== ( const CellRect & other) const
defaultnoexcept

Compare origin and extents, including the position of empty rectangles.

Parameters
otherValue whose corresponding fields are compared.
Returns
True when every compared field is equal; false otherwise.

◆ origin()

CellPoint portals::CellRect::origin ( ) const
nodiscardnoexcept

Return the cell origin by value; no errors.

Returns
The inclusive top-left cell coordinate, copied by value.

◆ right()

std::int32_t portals::CellRect::right ( ) const
nodiscardnoexcept

Return the representable exclusive horizontal end; no errors.

Returns
The exclusive x coordinate, including for empty rectangles.

◆ size()

CellSize portals::CellRect::size ( ) const
nodiscardnoexcept

Return the normalized cell extents by value; no errors.

Returns
Nonnegative width in columns and height in rows.

◆ translated()

std::expected< CellRect, GeometryError > portals::CellRect::translated ( CellPoint offset) const
nodiscardnoexcept

Return an owning translated rectangle, preserving its extents.

Parameters
offsetSigned cell displacement, copied without borrowing storage.
Returns
An independent rectangle or COORDINATE_OVERFLOW for an origin or end.
Note
No exceptions, mutation or invalidation, including on failure.

The documentation for this class was generated from the following file: