Porytiles
Loading...
Searching...
No Matches
porytiles2::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 porytiles2::CanonicalPixelTile< PixelType >:
[legend]
Collaboration diagram for porytiles2::CanonicalPixelTile< PixelType >:
[legend]

Public Member Functions

 CanonicalPixelTile (const PixelTile< PixelType > &tile)
 Constructs a CanonicalPixelTile by finding the canonical orientation of the input tile.
 
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 porytiles2::PixelTile< PixelType >
virtual ~PixelTile ()=default
 
 PixelTile ()
 
 PixelTile (std::array< PixelType, tile::size_pix > pix)
 
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.
 
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
 

Detailed Description

template<SupportsTransparency PixelType>
class porytiles2::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()

template<SupportsTransparency PixelType>
porytiles2::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.

Member Function Documentation

◆ h_flip()

template<SupportsTransparency PixelType>
bool porytiles2::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 115 of file canonical_pixel_tile.hpp.

◆ operator<=>()

template<SupportsTransparency PixelType>
auto porytiles2::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 porytiles2::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 129 of file canonical_pixel_tile.hpp.


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