Porytiles
Loading...
Searching...
No Matches
porytiles2::CanonicalShapeTile< PixelType > Class Template Reference

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

#include <canonical_shape_tile.hpp>

Inheritance diagram for porytiles2::CanonicalShapeTile< PixelType >:
[legend]
Collaboration diagram for porytiles2::CanonicalShapeTile< PixelType >:
[legend]

Public Member Functions

 CanonicalShapeTile (const ShapeTile< PixelType > &tile)
 Constructs a CanonicalShapeTile by finding the canonical orientation of the input tile.
 
auto operator<=> (const CanonicalShapeTile &other) const =default
 Three-way comparison operator that compares all fields.
 
bool h_flip () const
 Returns the horizontal flip flag.
 
bool v_flip () const
 Returns the vertical flip flag.
 
- Public Member Functions inherited from porytiles2::ShapeTile< PixelType >
virtual ~ShapeTile ()=default
 
 ShapeTile ()=default
 
auto operator<=> (const ShapeTile &other) const =default
 
bool is_transparent () const
 Checks if this entire ShapeTile is transparent.
 
ShapeTile flip (bool h, bool v) const
 Creates a flipped version of this ShapeTile.
 
const std::map< ShapeMask, PixelType > & colors () const
 Returns the internal map of shape masks to pixel values.
 
void set (const ShapeMask &mask, const PixelType &color)
 Sets or updates the pixel value for a specific shape mask.
 

Additional Inherited Members

- Static Public Member Functions inherited from porytiles2::ShapeTile< PixelType >
static bool compare_shape_only (const ShapeTile &lhs, const ShapeTile &rhs)
 Compares two ShapeTiles based ONLY on shape masks, ignoring pixel values.
 

Detailed Description

template<typename PixelType>
class porytiles2::CanonicalShapeTile< PixelType >

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

CanonicalShapeTile 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 shape among these four variants.

This representation enables:

  • Shape-based tile deduplication: can detect when two tiles are isomorphic under flip or color transformations
  • Canonical shape 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.

Key difference from CanonicalPixelTile:

  • Uses ShapeTile::compare_shape_only() which compares ONLY shape masks (geometry), not pixel values (colors)
  • This means tiles with the same shape but different color assignments will canonicalize to the same shape structure
  • This is critical for shape-based tile deduplication that is color-agnostic

This approach is particularly useful for:

  • Tileset generation where tiles should be deduplicated based on shape regardless of colors
  • Hardware targeting that supports tile flipping (e.g., GBA hardware attributes)
  • Optimizing tileset size by identifying tiles that are rotations/flips of each other by shape
  • Palette-independent tile analysis and optimization
Template Parameters
PixelTypeThe pixel type stored for each shape region

Definition at line 44 of file canonical_shape_tile.hpp.

Constructor & Destructor Documentation

◆ CanonicalShapeTile()

template<typename PixelType >
porytiles2::CanonicalShapeTile< PixelType >::CanonicalShapeTile ( const ShapeTile< PixelType > &  tile)
inlineexplicit

Constructs a CanonicalShapeTile 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 ShapeTile 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 ShapeTile::compare_shape_only, which compares ONLY the shape masks (geometry) and ignores pixel values. This means two tiles with identical shapes but different color assignments will canonicalize to the same shape structure (though their pixel values will differ).

Parameters
tileThe input ShapeTile to canonicalize

Definition at line 66 of file canonical_shape_tile.hpp.

Member Function Documentation

◆ h_flip()

template<typename PixelType >
bool porytiles2::CanonicalShapeTile< 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 CanonicalShapeTile'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 125 of file canonical_shape_tile.hpp.

◆ operator<=>()

template<typename PixelType >
auto porytiles2::CanonicalShapeTile< PixelType >::operator<=> ( const CanonicalShapeTile< PixelType > &  other) const
default

Three-way comparison operator that compares all fields.

Performs member-wise comparison in declaration order:

  1. Base ShapeTile (shape masks AND pixel values via ShapeTile::operator<=>)
  2. h_flip_ flag
  3. v_flip_ flag

This operator is consistent with operator==, ensuring that:

  • If (a <=> b) == 0, then (a == b) is true
  • If (a == b) is true, then (a <=> b) == 0
Parameters
otherThe CanonicalShapeTile to compare against
Returns
A std::strong_ordering indicating less than, equal to, or greater than relationship

◆ v_flip()

template<typename PixelType >
bool porytiles2::CanonicalShapeTile< 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 CanonicalShapeTile'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 139 of file canonical_shape_tile.hpp.


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