Porytiles
Loading...
Searching...
No Matches
color_set.cpp
Go to the documentation of this file.
2
3namespace porytiles {
4
5bool ColorSet::test(ColorIndex index) const
6{
7 return colors_.test(index.index());
8}
9
10void ColorSet::set(ColorIndex index, bool value)
11{
12 colors_.set(index.index(), value);
13}
14
16{
17 colors_.reset(index.index());
18}
19
21{
22 ColorSet result;
23 auto union_bits = a.colors() | b.colors();
24 for (std::size_t i = 0; i < num_colors; ++i) {
25 if (union_bits.test(i)) {
26 result.set(ColorIndex{static_cast<std::uint8_t>(i)});
27 }
28 }
29 return result;
30}
31
33{
34 ColorSet result;
35 auto intersection_bits = a.colors() & b.colors();
36 for (std::size_t i = 0; i < num_colors; ++i) {
37 if (intersection_bits.test(i)) {
38 result.set(ColorIndex{static_cast<std::uint8_t>(i)});
39 }
40 }
41 return result;
42}
43
44std::size_t color_set_count(const ColorSet &set)
45{
46 return set.colors().count();
47}
48
49bool is_subset(const ColorSet &a, const ColorSet &b)
50{
51 // a is a subset of b if every bit in a is also in b
52 // This is equivalent to: (a & ~b) == 0
53 // Or: (a & b) == a
54 auto intersection = a.colors() & b.colors();
55 return intersection == a.colors();
56}
57
58std::size_t intersection_size(const ColorSet &a, const ColorSet &b)
59{
61}
62
63std::size_t union_size(const ColorSet &a, const ColorSet &b)
64{
65 return color_set_count(color_set_union(a, b));
66}
67
68} // namespace porytiles
Represents a color index value for palette operations.
std::size_t index() const
A set of colors represented as a bitset.
Definition color_set.hpp:26
const std::bitset< num_colors > & colors() const
Definition color_set.hpp:36
void reset(ColorIndex index)
Definition color_set.cpp:15
void set(ColorIndex index, bool value=true)
Definition color_set.cpp:10
bool test(ColorIndex index) const
Definition color_set.cpp:5
bool is_subset(const ColorSet &a, const ColorSet &b)
Checks if one ColorSet is a subset of another.
Definition color_set.cpp:49
ColorSet color_set_union(const ColorSet &a, const ColorSet &b)
Computes the union of two ColorSets.
Definition color_set.cpp:20
constexpr std::size_t num_colors
Maximum allowable color count for GBA hardware.
Definition color_set.hpp:17
ColorSet color_set_intersection(const ColorSet &a, const ColorSet &b)
Computes the intersection of two ColorSets.
Definition color_set.cpp:32
std::size_t intersection_size(const ColorSet &a, const ColorSet &b)
Computes the intersection size between two ColorSets.
Definition color_set.cpp:58
std::size_t color_set_count(const ColorSet &set)
Counts the number of colors in a ColorSet.
Definition color_set.cpp:44
std::size_t union_size(const ColorSet &a, const ColorSet &b)
Computes the union size of two ColorSets.
Definition color_set.cpp:63