Commit 9f54f10 1 parent 9ac43fd commit 9f54f10 Copy full SHA for 9f54f10
File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -963,14 +963,25 @@ agg_split_affinity_preserving(
963
963
}
964
964
965
965
/* *
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 .
968
968
*/
969
969
static int
970
970
clamp_colors (
971
971
std::vector<int > &values
972
972
) {
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
+ }
974
985
return QV_SUCCESS;
975
986
}
976
987
You can’t perform that action at this time.
0 commit comments