ref: 2099a25ee06bad044e366278878126f8184ef9e3
parent: b9de65c9a2f2f6377394bf7ac09267ad6618b1a9
author: ISSOtm <eldredhabert0@gmail.com>
date: Wed Mar 9 19:51:53 EST 2022
Avoid using `transform_reduce` Not available in libstdc++ 7, apparently
--- a/src/gfx/pal_packing.cpp
+++ b/src/gfx/pal_packing.cpp
@@ -208,20 +208,19 @@
* Computes the "relative size" of a proto-palette on this palette
*/
double relSizeOf(ProtoPalette const &protoPal) const {
- // NOTE: this function must not call `uniqueColors`, or one of its callers will break
- return std::transform_reduce(
- protoPal.begin(), protoPal.end(), 0.0, std::plus<>(), [this](uint16_t color) {
- // NOTE: The paper and the associated code disagree on this: the code has
- // this `1 +`, whereas the paper does not; its lack causes a division by 0
- // if the symbol is not found anywhere, so I'm assuming the paper is wrong.
- return 1.
- / (1
- + std::count_if(
- begin(), end(), [this, &color](ProtoPalAttrs const &attrs) {
- ProtoPalette const &pal = (*_protoPals)[attrs.palIndex];
- return std::find(pal.begin(), pal.end(), color) != pal.end();
- }));
- });
+ // NOTE: this function must not call `uniqueColors`, or one of its callers will break!
+ double relSize = 0.;
+ for (uint16_t color : protoPal) {
+ // NOTE: The paper and the associated code disagree on this: the code has
+ // this `1 +`, whereas the paper does not; its lack causes a division by 0
+ // if the symbol is not found anywhere, so I'm assuming the paper is wrong.
+ relSize +=
+ 1. / (1 + std::count_if(begin(), end(), [this, &color](ProtoPalAttrs const &attrs) {
+ ProtoPalette const &pal = (*_protoPals)[attrs.palIndex];
+ return std::find(pal.begin(), pal.end(), color) != pal.end();
+ }));
+ }
+ return relSize;
}
/**