Porytiles
Loading...
Searching...
No Matches
porytiles2::ShapeMask Class Reference

Represents which pixels in an 8x8 tile are non-transparent. More...

#include <shape_mask.hpp>

Public Member Functions

 ShapeMask ()=default
 
 ShapeMask (const std::array< uint8_t, tile::side_length_pix > &rows)
 Constructs a ShapeMask from an array of row data.
 
auto operator<=> (const ShapeMask &) const =default
 
ShapeMask flip (bool h, bool v) const
 Returns a flipped version of this mask.
 
void set (int row, int col)
 Sets the bit at the specified row and column to 1.
 
void unset (int row, int col)
 Sets the bit at the specified row and column to 0.
 
bool get (int row, int col) const
 Gets the bit value at the specified row and column.
 
bool is_transparent () const
 Checks if this entire ShapeMask is transparent.
 
const std::array< uint8_t, 8 > & rows () const
 Returns the raw row data.
 

Detailed Description

Represents which pixels in an 8x8 tile are non-transparent.

ShapeMask uses 1 bit per pixel to track the "shape" of 8x8 tile. Each of the 8 rows is stored as a uint8_t, where the most significant bit represents the leftmost pixel (column 0) and the least significant bit represents the rightmost pixel (column 7).

The class provides flipping operations and bitwise manipulation to set or unset individual pixels. Comparison operators are lexicographic on the rows array.

In the tile canonicalization system, ShapeMask serves as a shape-based tile representation that separates tile geometry from color assignments. It is the fundamental building block for representing tile shapes. Multiple ShapeMask instances can be combined to define different color regions within a single tile, with each mask mapping to a specific color index. The flipping operations and lexicographic comparison enable the compiler to find canonical (minimal) orientations for tiles in a color-agnostic way, allowing deduplication of tiles that are identical under flips or color transformations.

Invariant
Default-constructed ShapeMask is transparent (satisfies SupportsTransparency design invariant). That is, ShapeMask{} produces a fully transparent mask with all bits unset (all rows are 0).

Definition at line 31 of file shape_mask.hpp.

Constructor & Destructor Documentation

◆ ShapeMask() [1/2]

porytiles2::ShapeMask::ShapeMask ( )
default

◆ ShapeMask() [2/2]

porytiles2::ShapeMask::ShapeMask ( const std::array< uint8_t, tile::side_length_pix > &  rows)
inlineexplicit

Constructs a ShapeMask from an array of row data.

Each element in the array represents one row of the 8x8 tile, where bit 7 is the leftmost pixel and bit 0 is the rightmost pixel.

Parameters
rowsAn array of 8 bytes representing the tile rows

Definition at line 44 of file shape_mask.hpp.

Member Function Documentation

◆ flip()

ShapeMask porytiles2::ShapeMask::flip ( bool  h,
bool  v 
) const

Returns a flipped version of this mask.

Creates a new ShapeMask that is horizontally and/or vertically flipped. Horizontal flipping reverses the bits in each row. Vertical flipping reverses the order of the rows. If neither h nor v is true, returns a copy of the original mask.

Parameters
hTrue to flip horizontally
vTrue to flip vertically
Returns
The flipped mask

Definition at line 10 of file shape_mask.cpp.

◆ get()

bool porytiles2::ShapeMask::get ( int  row,
int  col 
) const

Gets the bit value at the specified row and column.

Returns true if the pixel at the given position is marked as non-transparent (bit is 1), false otherwise. Column 0 is the leftmost pixel (bit 7) and column 7 is the rightmost pixel (bit 0).

Parameters
rowThe row index (0-7)
colThe column index (0-7)
Returns
True if the bit is set, false otherwise

Definition at line 37 of file shape_mask.cpp.

◆ is_transparent()

bool porytiles2::ShapeMask::is_transparent ( ) const

Checks if this entire ShapeMask is transparent.

A ShapeMask is transparent if every bit in every mask integer is unset.

Returns
True if all bits in the mask are unset, false otherwise

Definition at line 42 of file shape_mask.cpp.

◆ operator<=>()

auto porytiles2::ShapeMask::operator<=> ( const ShapeMask ) const
default

◆ rows()

const std::array< uint8_t, 8 > & porytiles2::ShapeMask::rows ( ) const
inline

Returns the raw row data.

Returns a const reference to the internal array of 8 bytes representing the tile rows.

Returns
A const reference to the rows array

Definition at line 118 of file shape_mask.hpp.

◆ set()

void porytiles2::ShapeMask::set ( int  row,
int  col 
)

Sets the bit at the specified row and column to 1.

Marks the pixel at the given position as non-transparent. Column 0 is the leftmost pixel (bit 7) and column 7 is the rightmost pixel (bit 0).

Parameters
rowThe row index (0-7)
colThe column index (0-7)

Definition at line 27 of file shape_mask.cpp.

◆ unset()

void porytiles2::ShapeMask::unset ( int  row,
int  col 
)

Sets the bit at the specified row and column to 0.

Marks the pixel at the given position as transparent. Column 0 is the leftmost pixel (bit 7) and column 7 is the rightmost pixel (bit 0).

Parameters
rowThe row index (0-7)
colThe column index (0-7)

Definition at line 32 of file shape_mask.cpp.


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