mirror of
https://github.com/gbdev/rgbds.git
synced 2026-06-09 18:22:35 +00:00
998f636495
- Fix logic for color set comparison (which affects sorting them) - Prune color sets which are proper subsets of newly-encountered ones (a comment implied we were already doing this, but we weren't) - Add more verbose logging to debug this behavior
35 lines
972 B
C++
35 lines
972 B
C++
// SPDX-License-Identifier: MIT
|
|
|
|
#ifndef RGBDS_GFX_COLOR_SET_HPP
|
|
#define RGBDS_GFX_COLOR_SET_HPP
|
|
|
|
#include <array>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
class ColorSet {
|
|
public:
|
|
static constexpr size_t capacity = 4;
|
|
|
|
private:
|
|
// Up to 4 colors, sorted, and where UINT16_MAX means the slot is empty
|
|
// (OK because it's not a valid color index)
|
|
// Sorting is done on the raw numerical values to lessen `compare`'s complexity
|
|
std::array<uint16_t, capacity> _colorIndices{UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT16_MAX};
|
|
|
|
public:
|
|
// Adds the specified color to the set, or **silently drops it** if the set is full.
|
|
void add(uint16_t color);
|
|
|
|
enum ComparisonResult { INCOMPARABLE, SUBSET_OR_EQUAL, STRICT_SUPERSET };
|
|
ComparisonResult compare(ColorSet const &other) const;
|
|
|
|
size_t size() const;
|
|
bool empty() const;
|
|
|
|
decltype(_colorIndices)::const_iterator begin() const;
|
|
decltype(_colorIndices)::const_iterator end() const;
|
|
};
|
|
|
|
#endif // RGBDS_GFX_COLOR_SET_HPP
|