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

An 8x8 tile backed by mask-based storage that maps shape regions to pixel values. More...

#include <shape_tile.hpp>

Inheritance diagram for porytiles2::ShapeTile< PixelType >:
[legend]

Public Member Functions

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.
 

Static Public Member Functions

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::ShapeTile< PixelType >

An 8x8 tile backed by mask-based storage that maps shape regions to pixel values.

ShapeTile represents tiles as a collection of shape masks (ShapeMask) mapped to pixel values (PixelType). Unlike PixelTile which stores literal per-pixel data, ShapeTile stores tiles as a set of shape regions where each region is defined by a ShapeMask (which pixels are "on" in that region) and maps to a single pixel value.

This representation enables:

  • Shape-based tile comparison that separates geometry from color assignments
  • Canonical orientation finding through lexicographic shape comparison
  • Color-agnostic tile deduplication and analysis

Multiple ShapeMask instances can be combined to define different color regions within a single tile. Each mask identifies which pixels belong to a particular region, and the associated PixelType provides the color or data for those pixels.

Key design features:

  • operator== and operator<=> compare both shape masks AND pixel values for full equality and ordering
  • compare_shape_only() provides specialized shape-only comparison, ignoring pixel values - this is critical for canonical orientation finding
  • Flipping operations transform all masks while preserving color mappings
Invariant
Default-constructed ShapeTile is transparent (satisfies SupportsTransparency design invariant). That is, ShapeTile{} produces a transparent tile with an empty colors_ map, and an empty map is considered fully transparent by is_transparent().
Shape masks in a ShapeTile must not overlap. Each pixel position in the tile should be covered by at most one ShapeMask. Overlapping masks indicate a programmer error and will cause tile conversion operations to panic.
Template Parameters
PixelTypeThe pixel type stored for each shape region

Definition at line 44 of file shape_tile.hpp.

Constructor & Destructor Documentation

◆ ~ShapeTile()

template<typename PixelType >
virtual porytiles2::ShapeTile< PixelType >::~ShapeTile ( )
virtualdefault

◆ ShapeTile()

template<typename PixelType >
porytiles2::ShapeTile< PixelType >::ShapeTile ( )
default

Member Function Documentation

◆ colors()

template<typename PixelType >
const std::map< ShapeMask, PixelType > & porytiles2::ShapeTile< PixelType >::colors ( ) const
inline

Returns the internal map of shape masks to pixel values.

Provides read-only access to the underlying std::map that stores the shape-to-pixel mappings. Each entry in the map represents a shape region (ShapeMask) and its associated pixel value (PixelType).

Returns
A const reference to the colors map

Definition at line 132 of file shape_tile.hpp.

◆ compare_shape_only()

template<typename PixelType >
static bool porytiles2::ShapeTile< PixelType >::compare_shape_only ( const ShapeTile< PixelType > &  lhs,
const ShapeTile< PixelType > &  rhs 
)
inlinestatic

Compares two ShapeTiles based ONLY on shape masks, ignoring pixel values.

This static method performs a lexicographic comparison of the shape masks (keys) only, completely ignoring the associated pixel values. This is a specialized comparison used for canonical orientation finding - tiles with identical shapes but different colors will compare based solely on their geometric structure.

This comparison is used to find the "minimal" or "canonical" orientation of a tile among its flipped variants, ensuring that tiles with the same shape structure but different color assignments can be identified as having equivalent geometry.

Note: This is different from operator< and operator<=>, which compare both shape masks AND pixel values.

Parameters
lhsThe left-hand ShapeTile to compare
rhsThe right-hand ShapeTile to compare
Returns
True if lhs's shape masks are lexicographically less than rhs's shape masks

Definition at line 70 of file shape_tile.hpp.

◆ flip()

template<typename PixelType >
ShapeTile porytiles2::ShapeTile< PixelType >::flip ( bool  h,
bool  v 
) const
inline

Creates a flipped version of this ShapeTile.

Returns a new ShapeTile with all shape masks flipped according to the specified parameters, while preserving the pixel value mappings. Horizontal flip reflects the tile across a vertical axis, vertical flip reflects across a horizontal axis.

Each ShapeMask in the tile is flipped individually using its flip() method, and the resulting flipped mask is mapped to the same pixel value as the original mask. This preserves the color assignments while transforming the tile's geometric structure.

If neither h nor v is true, returns a copy of the original tile.

Parameters
hTrue to flip horizontally
vTrue to flip vertically
Returns
A new ShapeTile with the specified flips applied

Definition at line 110 of file shape_tile.hpp.

◆ is_transparent()

template<typename PixelType >
bool porytiles2::ShapeTile< PixelType >::is_transparent ( ) const
inline

Checks if this entire ShapeTile is transparent.

A ShapeTile is transparent if all of its shape masks are transparent (i.e., every ShapeMask has all bits unset). This check only examines the shape masks, not the pixel values associated with them.

Returns
True if all shape masks in the tile are transparent, false otherwise

Definition at line 86 of file shape_tile.hpp.

◆ operator<=>()

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

◆ set()

template<typename PixelType >
void porytiles2::ShapeTile< PixelType >::set ( const ShapeMask mask,
const PixelType &  color 
)
inline

Sets or updates the pixel value for a specific shape mask.

Associates the given pixel value with the specified shape mask. If the mask already exists in the tile, its pixel value is updated. If the mask does not exist, a new entry is created.

Parameters
maskThe shape mask identifying which pixels belong to this region
colorThe pixel value to associate with this shape mask

Definition at line 147 of file shape_tile.hpp.


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