Porytiles
Loading...
Searching...
No Matches
porytiles::CanonicalPixelTile< PixelType > Class Template Reference

A PixelTile representation that stores the canonical (lexicographically minimal) orientation among all flipped variants. More...

#include <canonical_pixel_tile.hpp>

Inheritance diagram for porytiles::CanonicalPixelTile< PixelType >:
[legend]
Collaboration diagram for porytiles::CanonicalPixelTile< PixelType >:
[legend]

Public Member Functions

 CanonicalPixelTile (const PixelTile< PixelType > &tile)
 Constructs a CanonicalPixelTile by finding the canonical orientation of the input tile.
 
 CanonicalPixelTile (const PixelTile< PixelType > &tile, const PixelType &extrinsic_transparency)
 Canonicalizes the input tile's orientation under cross-ET strict weak ordering.
 
auto operator<=> (const CanonicalPixelTile &other) const =default
 Three-way comparison operator that compares all fields in lexicographic order.
 
bool h_flip () const
 Returns the horizontal flip flag.
 
bool v_flip () const
 Returns the vertical flip flag.
 
- Public Member Functions inherited from porytiles::PixelTile< PixelType >
virtual ~PixelTile ()=default
 
 PixelTile ()
 
 PixelTile (std::array< PixelType, tile::size_pix > pix)
 
 PixelTile (const PixelType &fill_value)
 Constructs a PixelTile with all pixels set to a fill value.
 
auto operator<=> (const PixelTile &) const =default
 
bool is_transparent () const
 Checks if this entire PixelTile is transparent (intrinsic transparency only).
 
bool is_transparent (const PixelType &extrinsic) const
 Checks if this entire PixelTile is transparent.
 
bool equals_ignoring_transparency (const PixelTile &other) const
 Compares this PixelTile with another, treating all transparent pixels as equal.
 
bool equals_ignoring_transparency (const PixelTile &other, const PixelType &extrinsic) const
 Compares this PixelTile with another, treating all transparent pixels as equal.
 
bool equals_ignoring_transparency (const PixelTile &other, const PixelType &extrinsic, const PixelType &other_extrinsic) const
 Compares this PixelTile with another, treating transparent pixels as equal, using independent extrinsic transparency values for each tile.
 
PixelType at (std::size_t i) const
 
PixelType at (std::size_t row, std::size_t col) const
 
void set (std::size_t i, const PixelType &p)
 
void set (std::size_t row, std::size_t col, const PixelType &p)
 
PixelTile flip (bool h_flip, bool v_flip) const
 Creates a flipped copy of this PixelTile.
 
std::set< PixelType > unique_nontransparent_colors () const
 Returns the set of unique non-transparent colors present in this PixelTile (intrinsic transparency only).
 
std::set< PixelType > unique_nontransparent_colors (const PixelType &extrinsic) const
 Returns the set of unique non-transparent colors present in this PixelTile.
 
const std::array< PixelType, tile::size_pix > & pix () const
 

Additional Inherited Members

- Static Public Member Functions inherited from porytiles::PixelTile< PixelType >
static std::weak_ordering cross_et_compare (const PixelTile &a, const PixelType &a_et, const PixelTile &b, const PixelType &b_et)
 Strict weak ordering that treats transparent pixels under each side's own ET as equivalent.
 

Detailed Description

template<SupportsTransparency PixelType>
class porytiles::CanonicalPixelTile< PixelType >

A PixelTile representation that stores the canonical (lexicographically minimal) orientation among all flipped variants.

CanonicalPixelTile finds and stores the canonical orientation of a tile by evaluating all four possible flip combinations (no flip, horizontal only, vertical only, and both horizontal and vertical). The canonical orientation is defined as the lexicographically minimal tile data among these four variants.

This representation enables:

  • Tile deduplication: tiles that are identical under flipping can be recognized as equivalent
  • Canonical comparison: tiles can be compared in a normalized form regardless of their original orientation
  • Orientation tracking: the flip flags record how to transform the canonical form back to the original orientation

The stored flip flags (h_flip_ and v_flip_) represent the transformation needed to convert the canonical tile back to the original input tile. For example, if the input tile's horizontal flip is its canonical form, h_flip() will return true, indicating that horizontally flipping the canonical tile reproduces the original.

This approach is particularly useful for:

  • Tileset generation where tiles should be deduplicated regardless of orientation
  • Hardware targeting that supports tile flipping (e.g., GBA hardware attributes)
  • Optimizing tileset size by identifying tiles that are rotations/flips of each other
Template Parameters
PixelTypeThe pixel type of this tile; must satisfy SupportsTransparency concept

Definition at line 38 of file canonical_pixel_tile.hpp.

Constructor & Destructor Documentation

◆ CanonicalPixelTile() [1/2]

template<SupportsTransparency PixelType>
porytiles::CanonicalPixelTile< PixelType >::CanonicalPixelTile ( const PixelTile< PixelType > &  tile)
inlineexplicit

Constructs a CanonicalPixelTile by finding the canonical orientation of the input tile.

This constructor evaluates all four possible flip combinations of the input tile:

  • No flip (original orientation)
  • Horizontal flip only
  • Vertical flip only
  • Both horizontal and vertical flip

The lexicographically minimal tile among these four variants is selected as the canonical form and stored as the base PixelTile data. The flip flags that transform this canonical form back to the input tile are stored in h_flip_ and v_flip_.

The lexicographic comparison is performed using the default PixelTile comparison operator (operator<=>), which compares pixel data element-by-element.

Parameters
tileThe input PixelTile to canonicalize

Definition at line 59 of file canonical_pixel_tile.hpp.

◆ CanonicalPixelTile() [2/2]

template<SupportsTransparency PixelType>
porytiles::CanonicalPixelTile< PixelType >::CanonicalPixelTile ( const PixelTile< PixelType > &  tile,
const PixelType &  extrinsic_transparency 
)
inline

Canonicalizes the input tile's orientation under cross-ET strict weak ordering.

Picks the lex-min orientation among the four flip combinations, using PixelTile<PixelType>::cross_et_compare with extrinsic_transparency supplied as both sides of the comparison. This produces an orientation that is stable across ET values: two tiles whose opaque-pixel patterns coincide but whose transparent pixels differ by ET will canonicalize to equivalent orientations (equivalent under cross_et_compare), which is the precondition for matching them in ET-aware lookup maps.

Only enabled for pixel types that support parameterized is_transparent (e.g., Rgba32). This constructor exists to support cross-tileset animation matching, where tiles compiled under different extrinsic transparency values must canonicalize to equivalent orientations so the matcher's cross-ET comparator finds them equal.

Parameters
tileThe input PixelTile to canonicalize.
extrinsic_transparencyThe extrinsic transparency value to use for cross-ET comparison during canonicalization (applied to both sides, since we are comparing the tile's own flipped variants).

Definition at line 110 of file canonical_pixel_tile.hpp.

Member Function Documentation

◆ h_flip()

template<SupportsTransparency PixelType>
bool porytiles::CanonicalPixelTile< PixelType >::h_flip ( ) const
inline

Returns the horizontal flip flag.

Indicates whether the canonical tile must be horizontally flipped to reproduce the original input tile. If true, applying a horizontal flip to this CanonicalPixelTile's tile data will yield the original tile orientation.

Returns
True if horizontal flip is needed to reconstruct the original tile, false otherwise

Definition at line 164 of file canonical_pixel_tile.hpp.

◆ operator<=>()

template<SupportsTransparency PixelType>
auto porytiles::CanonicalPixelTile< PixelType >::operator<=> ( const CanonicalPixelTile< PixelType > &  other) const
default

Three-way comparison operator that compares all fields in lexicographic order.

Provides complete ordering by comparing first the base PixelTile data, then h_flip_, then v_flip_. This enables CanonicalPixelTile instances to be used in ordered containers like std::set or std::map.

Two CanonicalPixelTile instances are equal if and only if they have identical canonical tile data and identical flip flags.

Parameters
otherThe CanonicalPixelTile to compare against
Returns
A comparison category indicating less than, equal to, or greater than relationship

◆ v_flip()

template<SupportsTransparency PixelType>
bool porytiles::CanonicalPixelTile< PixelType >::v_flip ( ) const
inline

Returns the vertical flip flag.

Indicates whether the canonical tile must be vertically flipped to reproduce the original input tile. If true, applying a vertical flip to this CanonicalPixelTile's tile data will yield the original tile orientation.

Returns
True if vertical flip is needed to reconstruct the original tile, false otherwise

Definition at line 178 of file canonical_pixel_tile.hpp.


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