Skip to content

Commit 9f54f10

Browse files
Fix color clamping code.
My last modification to clamp_colors() broke it. Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 9ac43fd commit 9f54f10

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/qvi-scope.cc

+14-3
Original file line numberDiff line numberDiff line change
@@ -963,14 +963,25 @@ agg_split_affinity_preserving(
963963
}
964964

965965
/**
966-
* Takes a vector of colors and clamps their values to [0, values.size()) in
967-
* place.
966+
* Takes a vector of colors and clamps their values to [0, ndc)
967+
* in place, where ndc is the number of distinct numbers found in values.
968968
*/
969969
static int
970970
clamp_colors(
971971
std::vector<int> &values
972972
) {
973-
std::iota(values.begin(), values.end(), 0);
973+
// Recall: sets are ordered.
974+
std::set<int> valset(values.begin(), values.end());
975+
// Maps the input vector colors to their clamped values.
976+
std::map<int, int> colors2clamped;
977+
// color': the clamped color.
978+
int colorp = 0;
979+
for (auto val : valset) {
980+
colors2clamped.insert({val, colorp++});
981+
}
982+
for (uint_t i = 0; i < values.size(); ++i) {
983+
values[i] = colors2clamped[values[i]];
984+
}
974985
return QV_SUCCESS;
975986
}
976987

0 commit comments

Comments
 (0)