|
Porytiles
|
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. | |
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.
ShapeMask{} produces a fully transparent mask with all bits unset (all rows are 0). Definition at line 31 of file shape_mask.hpp.
|
default |
|
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.
| rows | An array of 8 bytes representing the tile rows |
Definition at line 44 of file shape_mask.hpp.
| 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.
| h | True to flip horizontally |
| v | True to flip vertically |
Definition at line 10 of file shape_mask.cpp.
| 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).
| row | The row index (0-7) |
| col | The column index (0-7) |
Definition at line 37 of file shape_mask.cpp.
| 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.
Definition at line 42 of file shape_mask.cpp.
|
default |
|
inline |
Returns the raw row data.
Returns a const reference to the internal array of 8 bytes representing the tile rows.
Definition at line 118 of file shape_mask.hpp.
| 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).
| row | The row index (0-7) |
| col | The column index (0-7) |
Definition at line 27 of file shape_mask.cpp.
| 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).
| row | The row index (0-7) |
| col | The column index (0-7) |
Definition at line 32 of file shape_mask.cpp.