Skip to content

Commit cac6466

Browse files
Material Engcopybara-github
authored andcommitted
Update RankedSuggestions function signature.
PiperOrigin-RevId: 550948964
1 parent c3681e1 commit cac6466

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

cpp/score/score.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <algorithm>
2020
#include <cmath>
21+
#include <cstdint>
2122
#include <map>
2223
#include <utility>
2324
#include <vector>
@@ -40,12 +41,12 @@ bool CompareScoredHCT(const std::pair<Hct, double>& a,
4041
}
4142

4243
std::vector<Argb> RankedSuggestions(
43-
const std::map<Argb, int>& argb_to_population,
44+
const std::map<Argb, uint32_t>& argb_to_population,
4445
const ScoreOptions& options) {
4546
// Get the HCT color for each Argb value, while finding the per hue count and
4647
// total count.
4748
std::vector<Hct> colors_hct;
48-
std::vector<int> hue_population(360, 0);
49+
std::vector<uint32_t> hue_population(360, 0);
4950
double population_sum = 0;
5051
for (const auto& [argb, population] : argb_to_population) {
5152
Hct hct(argb);

cpp/score/score.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ScoreOptions {
5252
* # of colors display in Android 12's wallpaper picker.
5353
*/
5454
std::vector<Argb> RankedSuggestions(
55-
const std::map<Argb, int>& argb_to_population,
55+
const std::map<Argb, uint32_t>& argb_to_population,
5656
const ScoreOptions& options = {});
5757
} // namespace material_color_utilities
5858

cpp/score/score_test.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "cpp/score/score.h"
1818

19+
#include <cstdint>
1920
#include <map>
2021
#include <vector>
2122

@@ -27,7 +28,7 @@ namespace material_color_utilities {
2728
namespace {
2829

2930
TEST(ScoreTest, PrioritizesChroma) {
30-
std::map<Argb, int> argb_to_population = {
31+
std::map<Argb, uint32_t> argb_to_population = {
3132
{0xff000000, 1}, {0xffffffff, 1}, {0xff0000ff, 1}};
3233

3334
std::vector<Argb> ranked =
@@ -38,7 +39,7 @@ TEST(ScoreTest, PrioritizesChroma) {
3839
}
3940

4041
TEST(ScoreTest, PrioritizesChromaWhenProportionsEqual) {
41-
std::map<Argb, int> argb_to_population = {
42+
std::map<Argb, uint32_t> argb_to_population = {
4243
{0xffff0000, 1}, {0xff00ff00, 1}, {0xff0000ff, 1}};
4344

4445
std::vector<Argb> ranked =
@@ -51,7 +52,7 @@ TEST(ScoreTest, PrioritizesChromaWhenProportionsEqual) {
5152
}
5253

5354
TEST(ScoreTest, GeneratesGblueWhenNoColorsAvailable) {
54-
std::map<Argb, int> argb_to_population = {{0xff000000, 1}};
55+
std::map<Argb, uint32_t> argb_to_population = {{0xff000000, 1}};
5556

5657
std::vector<Argb> ranked =
5758
RankedSuggestions(argb_to_population, {.desired = 4});
@@ -61,7 +62,7 @@ TEST(ScoreTest, GeneratesGblueWhenNoColorsAvailable) {
6162
}
6263

6364
TEST(ScoreTest, DedupesNearbyHues) {
64-
std::map<Argb, int> argb_to_population = {
65+
std::map<Argb, uint32_t> argb_to_population = {
6566
{0xff008772, 1}, // H 180 C 42 T 50
6667
{0xff318477, 1} // H 184 C 35 T 50
6768
};
@@ -74,7 +75,7 @@ TEST(ScoreTest, DedupesNearbyHues) {
7475
}
7576

7677
TEST(ScoreTest, MaximizesHueDistance) {
77-
std::map<Argb, int> argb_to_population = {
78+
std::map<Argb, uint32_t> argb_to_population = {
7879
{0xff008772, 1}, // H 180 C 42 T 50
7980
{0xff008587, 1}, // H 198 C 50 T 50
8081
{0xff007ebc, 1} // H 245 C 50 T 50
@@ -89,7 +90,7 @@ TEST(ScoreTest, MaximizesHueDistance) {
8990
}
9091

9192
TEST(ScoreTest, GeneratedScenarioOne) {
92-
std::map<Argb, int> argb_to_population = {
93+
std::map<Argb, uint32_t> argb_to_population = {
9394
{0xff7ea16d, 67},
9495
{0xffd8ccae, 67},
9596
{0xff835c0d, 49},
@@ -106,7 +107,7 @@ TEST(ScoreTest, GeneratedScenarioOne) {
106107
}
107108

108109
TEST(ScoreTest, GeneratedScenarioTwo) {
109-
std::map<Argb, int> argb_to_population = {
110+
std::map<Argb, uint32_t> argb_to_population = {
110111
{0xffd33881, 14},
111112
{0xff3205cc, 77},
112113
{0xff0b48cf, 36},
@@ -124,7 +125,7 @@ TEST(ScoreTest, GeneratedScenarioTwo) {
124125
}
125126

126127
TEST(ScoreTest, GeneratedScenarioThree) {
127-
std::map<Argb, int> argb_to_population = {
128+
std::map<Argb, uint32_t> argb_to_population = {
128129
{0xffbe94a6, 23},
129130
{0xffc33fd7, 42},
130131
{0xff899f36, 90},
@@ -142,7 +143,7 @@ TEST(ScoreTest, GeneratedScenarioThree) {
142143
}
143144

144145
TEST(ScoreTest, GeneratedScenarioFour) {
145-
std::map<Argb, int> argb_to_population = {
146+
std::map<Argb, uint32_t> argb_to_population = {
146147
{0xffdf241c, 85}, {0xff685859, 44}, {0xffd06d5f, 34},
147148
{0xff561c54, 27}, {0xff713090, 88},
148149
};
@@ -157,7 +158,7 @@ TEST(ScoreTest, GeneratedScenarioFour) {
157158
}
158159

159160
TEST(ScoreTest, GeneratedScenarioFive) {
160-
std::map<Argb, int> argb_to_population = {
161+
std::map<Argb, uint32_t> argb_to_population = {
161162
{0xffbe66f8, 41}, {0xff4bbda9, 88}, {0xff80f6f9, 44},
162163
{0xffab8017, 43}, {0xffe89307, 65},
163164
};
@@ -173,7 +174,7 @@ TEST(ScoreTest, GeneratedScenarioFive) {
173174
}
174175

175176
TEST(ScoreTest, GeneratedScenarioSix) {
176-
std::map<Argb, int> argb_to_population = {
177+
std::map<Argb, uint32_t> argb_to_population = {
177178
{0xff18ea8f, 93}, {0xff327593, 18}, {0xff066a18, 53},
178179
{0xfffa8a23, 74}, {0xff04ca1f, 62},
179180
};
@@ -188,7 +189,7 @@ TEST(ScoreTest, GeneratedScenarioSix) {
188189
}
189190

190191
TEST(ScoreTest, GeneratedScenarioSeven) {
191-
std::map<Argb, int> argb_to_population = {
192+
std::map<Argb, uint32_t> argb_to_population = {
192193
{0xff2e05ed, 23}, {0xff153e55, 90}, {0xff9ab220, 23},
193194
{0xff153379, 66}, {0xff68bcc3, 81},
194195
};
@@ -203,7 +204,7 @@ TEST(ScoreTest, GeneratedScenarioSeven) {
203204
}
204205

205206
TEST(ScoreTest, GeneratedScenarioEight) {
206-
std::map<Argb, int> argb_to_population = {
207+
std::map<Argb, uint32_t> argb_to_population = {
207208
{0xff816ec5, 24},
208209
{0xff6dcb94, 19},
209210
{0xff3cae91, 98},
@@ -219,7 +220,7 @@ TEST(ScoreTest, GeneratedScenarioEight) {
219220
}
220221

221222
TEST(ScoreTest, GeneratedScenarioNine) {
222-
std::map<Argb, int> argb_to_population = {
223+
std::map<Argb, uint32_t> argb_to_population = {
223224
{0xff206f86, 52}, {0xff4a620d, 96}, {0xfff51401, 85},
224225
{0xff2b8ebf, 3}, {0xff277766, 59},
225226
};
@@ -235,7 +236,7 @@ TEST(ScoreTest, GeneratedScenarioNine) {
235236
}
236237

237238
TEST(ScoreTest, GeneratedScenarioTen) {
238-
std::map<Argb, int> argb_to_population = {
239+
std::map<Argb, uint32_t> argb_to_population = {
239240
{0xff8b1d99, 54},
240241
{0xff27effe, 43},
241242
{0xff6f558d, 2},

0 commit comments

Comments
 (0)