From 5efc49cb127300c765bde6baf4ce0fa3ac8b51ab Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 9 Mar 2022 21:43:36 +0100 Subject: [PATCH] Change `UseTab` to `ForIndentation` This fixes many whitespace issues --- .clang-format | 2 +- include/gfx/pal_packing.hpp | 2 +- include/gfx/rgba.hpp | 2 +- src/gfx/convert.cpp | 18 +++++++++--------- src/gfx/main.cpp | 32 ++++++++++++++++---------------- src/gfx/pal_packing.cpp | 36 ++++++++++++++++++------------------ src/gfx/pal_sorting.cpp | 4 ++-- src/gfx/rgba.cpp | 32 ++++++++++++++++---------------- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/.clang-format b/.clang-format index 3cc484ea..6a22c6ee 100644 --- a/.clang-format +++ b/.clang-format @@ -96,4 +96,4 @@ SpacesInSquareBrackets: false Standard: c++17 TabWidth: 4 UseCRLF: false -UseTab: AlignWithSpaces +UseTab: ForIndentation diff --git a/include/gfx/pal_packing.hpp b/include/gfx/pal_packing.hpp index 87b89633..997fe66b 100644 --- a/include/gfx/pal_packing.hpp +++ b/include/gfx/pal_packing.hpp @@ -25,7 +25,7 @@ namespace packing { * Returns which palette each proto-palette maps to, and how many palettes are necessary */ std::tuple, size_t> - overloadAndRemove(std::vector const &protoPalettes); + overloadAndRemove(std::vector const &protoPalettes); } diff --git a/include/gfx/rgba.hpp b/include/gfx/rgba.hpp index 06dc77e0..a9917fb7 100644 --- a/include/gfx/rgba.hpp +++ b/include/gfx/rgba.hpp @@ -22,7 +22,7 @@ struct Rgba { * Constructs the color from a "packed" RGBA representation (0xRRGGBBAA) */ explicit Rgba(uint32_t rgba = 0) - : red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {} + : red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {} /** * Returns this RGBA as a 32-bit number that can be printed in hex (`%08x`) to yield its CSS diff --git a/src/gfx/convert.cpp b/src/gfx/convert.cpp index 63a3260e..84baad99 100644 --- a/src/gfx/convert.cpp +++ b/src/gfx/convert.cpp @@ -52,8 +52,8 @@ public: size_t size() const { return std::count_if(_colors.begin(), _colors.end(), [](decltype(_colors)::value_type const &slot) { - return slot.has_value() && !slot->isTransparent(); - }); + return slot.has_value() && !slot->isTransparent(); + }); } decltype(_colors) const &raw() const { return _colors; } @@ -138,8 +138,8 @@ public: uint8_t mask = 1 << color->grayIndex(); if (bins & mask) { // Two in the same bin! options.verbosePrint( - "Color #%08x conflicts with another one, not using grayscale sorting\n", - color->toCSS()); + "Color #%08x conflicts with another one, not using grayscale sorting\n", + color->toCSS()); return false; } bins |= mask; @@ -348,7 +348,7 @@ public: public: TilesVisitor(Png const &png, bool columnMajor, uint32_t width, uint32_t height) - : _png(png), _columnMajor(columnMajor), _width(width), _height(height) {} + : _png(png), _columnMajor(columnMajor), _width(width), _height(height) {} class Tile { Png const &_png; @@ -435,7 +435,7 @@ struct AttrmapEntry { }; static std::tuple, std::vector> - generatePalettes(std::vector const &protoPalettes, Png const &png) { + generatePalettes(std::vector const &protoPalettes, Png const &png) { // Run a "pagination" problem solver // TODO: allow picking one of several solvers? auto [mappings, nbPalettes] = packing::overloadAndRemove(protoPalettes); @@ -471,7 +471,7 @@ static std::tuple, std::vector> } static std::tuple, std::vector> - makePalsAsSpecified(std::vector const &protoPalettes, Png const &png) { + makePalsAsSpecified(std::vector const &protoPalettes, Png const &png) { if (options.palSpecType == Options::EMBEDDED) { // Generate a palette spec from the first few colors in the embedded palette auto [embPalSize, embPalRGB, embPalAlpha] = png.getEmbeddedPal(); @@ -876,8 +876,8 @@ contained:; // Sort the proto-palettes by size, which improves the packing algorithm's efficiency // We sort after all insertions to avoid moving items: https://stackoverflow.com/a/2710332 std::sort( - protoPalettes.begin(), protoPalettes.end(), - [](ProtoPalette const &lhs, ProtoPalette const &rhs) { return lhs.size() < rhs.size(); }); + protoPalettes.begin(), protoPalettes.end(), + [](ProtoPalette const &lhs, ProtoPalette const &rhs) { return lhs.size() < rhs.size(); }); auto [mappings, palettes] = options.palSpecType == Options::NO_SPEC ? generatePalettes(protoPalettes, png) diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index 2b6c2923..151afe0f 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -93,31 +93,31 @@ static char const *optstring = "Aa:b:Cc:Dd:FfhL:mN:n:o:Pp:s:Tt:U:uVvx:Z"; * over short opt matching */ static struct option const longopts[] = { - {"output-attr-map", no_argument, NULL, 'A'}, + {"output-attr-map", no_argument, NULL, 'A'}, {"attr-map", required_argument, NULL, 'a'}, - {"base-tiles", required_argument, NULL, 'b'}, + {"base-tiles", required_argument, NULL, 'b'}, {"color-curve", no_argument, NULL, 'C'}, - {"colors", required_argument, NULL, 'c'}, + {"colors", required_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'D'}, // Ignored - {"depth", required_argument, NULL, 'd'}, + {"depth", required_argument, NULL, 'd'}, {"fix", no_argument, NULL, 'f'}, - {"fix-and-save", no_argument, NULL, 'F'}, // Deprecated - {"horizontal", no_argument, NULL, 'h'}, // Deprecated - {"slice", required_argument, NULL, 'L'}, + {"fix-and-save", no_argument, NULL, 'F'}, // Deprecated + {"horizontal", no_argument, NULL, 'h'}, // Deprecated + {"slice", required_argument, NULL, 'L'}, {"mirror-tiles", no_argument, NULL, 'm'}, - {"nb-tiles", required_argument, NULL, 'N'}, + {"nb-tiles", required_argument, NULL, 'N'}, {"nb-palettes", required_argument, NULL, 'n'}, - {"output", required_argument, NULL, 'o'}, + {"output", required_argument, NULL, 'o'}, {"output-palette", no_argument, NULL, 'P'}, - {"palette", required_argument, NULL, 'p'}, + {"palette", required_argument, NULL, 'p'}, {"output-tilemap", no_argument, NULL, 'T'}, - {"tilemap", required_argument, NULL, 't'}, + {"tilemap", required_argument, NULL, 't'}, {"unit-size", required_argument, NULL, 'U'}, - {"unique-tiles", no_argument, NULL, 'u'}, + {"unique-tiles", no_argument, NULL, 'u'}, {"version", no_argument, NULL, 'V'}, - {"verbose", no_argument, NULL, 'v'}, + {"verbose", no_argument, NULL, 'v'}, {"trim-end", required_argument, NULL, 'x'}, - {"columns", no_argument, NULL, 'Z'}, + {"columns", no_argument, NULL, 'Z'}, {NULL, no_argument, NULL, 0 } }; @@ -293,9 +293,9 @@ int main(int argc, char *argv[]) { constexpr std::string_view chars = // Both must start with a dot! #if defined(_MSC_VER) || defined(__MINGW32__) - "./\\"sv; + "./\\"sv; #else - "./"sv; + "./"sv; #endif size_t i = options.input.find_last_of(chars); if (i != options.input.npos && options.input[i] == '.') { diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index 9ffcb4d6..bff907d7 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -71,7 +71,7 @@ class AssignedProtos { public: template AssignedProtos(std::vector const &protoPals, Ts &&...elems) - : _assigned{std::forward(elems)...}, _protoPals{&protoPals} {} + : _assigned{std::forward(elems)...}, _protoPals{&protoPals} {} private: template typename Constness> @@ -142,8 +142,8 @@ public: template void assign(Ts &&...args) { auto freeSlot = std::find_if_not( - _assigned.begin(), _assigned.end(), - [](std::optional const &slot) { return slot.has_value(); }); + _assigned.begin(), _assigned.end(), + [](std::optional const &slot) { return slot.has_value(); }); if (freeSlot == _assigned.end()) { // We are full, use a new slot _assigned.emplace_back(std::forward(args)...); @@ -158,8 +158,8 @@ public: bool empty() const { return std::find_if_not( - _assigned.begin(), _assigned.end(), - [](std::optional const &slot) { return slot.has_value(); }) + _assigned.begin(), _assigned.end(), + [](std::optional const &slot) { return slot.has_value(); }) == _assigned.end(); } size_t nbProtoPals() const { return std::distance(begin(), end()); } @@ -210,18 +210,18 @@ public: 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 + 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. + 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(); - })); - }); + begin(), end(), [this, &color](ProtoPalAttrs const &attrs) { + ProtoPalette const &pal = (*_protoPals)[attrs.palIndex]; + return std::find(pal.begin(), pal.end(), color) != pal.end(); + })); + }); } /** @@ -342,7 +342,7 @@ static void decant(std::vector &assignments, } std::tuple, size_t> - overloadAndRemove(std::vector const &protoPalettes) { + overloadAndRemove(std::vector const &protoPalettes) { options.verbosePrint("Paginating palettes using \"overload-and-remove\" strategy...\n"); struct Iota { @@ -414,12 +414,12 @@ std::tuple, size_t> return pal.size() / bestPal.relSizeOf(pal); }; auto [minEfficiencyIter, maxEfficiencyIter] = - std::minmax_element(bestPal.begin(), bestPal.end(), + std::minmax_element(bestPal.begin(), bestPal.end(), [&efficiency, &protoPalettes](ProtoPalAttrs const &lhs, ProtoPalAttrs const &rhs) { - return efficiency(protoPalettes[lhs.palIndex]) + return efficiency(protoPalettes[lhs.palIndex]) < efficiency(protoPalettes[rhs.palIndex]); - }); + }); // All efficiencies are identical iff min equals max // TODO: maybe not ideal to re-compute these two? @@ -452,7 +452,7 @@ std::tuple, size_t> ProtoPalAttrs const &attrs = queue.front(); ProtoPalette const &protoPal = protoPalettes[attrs.palIndex]; auto iter = - std::find_if(assignments.begin(), assignments.end(), + std::find_if(assignments.begin(), assignments.end(), [&protoPal](AssignedProtos const &pal) { return pal.canFit(protoPal); }); if (iter == assignments.end()) { // No such page, create a new one options.verbosePrint("Adding new palette for overflow\n"); diff --git a/src/gfx/pal_sorting.cpp b/src/gfx/pal_sorting.cpp index 5ae66295..658593fa 100644 --- a/src/gfx/pal_sorting.cpp +++ b/src/gfx/pal_sorting.cpp @@ -36,8 +36,8 @@ void indexed(std::vector &palettes, int palSize, png_color const *palRG // Check that the palette only uses those colors if (std::all_of(palette.begin(), palette.end(), [&colors](uint16_t color) { - return std::find(colors.begin(), colors.end(), color) != colors.end(); - })) { + return std::find(colors.begin(), colors.end(), color) != colors.end(); + })) { if (palette.size() != options.maxPalSize()) { warning("Unused color in PNG embedded palette was re-added; please use `-c " "embedded` to get this in future versions"); diff --git a/src/gfx/rgba.cpp b/src/gfx/rgba.cpp index 0902ebd5..11d8e422 100644 --- a/src/gfx/rgba.cpp +++ b/src/gfx/rgba.cpp @@ -12,22 +12,22 @@ * with ties resolved by comparing the difference of the squares. */ static std::array reverse_curve{ - 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // These - 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, // comments - 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, // prevent - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, // clang-format - 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, // from - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, // reflowing - 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, // these - 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 16 - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, // 16-iterm - 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, // lines, - 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // which, - 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, // in - 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, // my - 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, // opinion, - 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, // help - 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 31, // visualization! + 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // These + 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, // comments + 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, // prevent + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, // clang-format + 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, // from + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, // reflowing + 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, // these + 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 16 + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, // 16-iterm + 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, // lines, + 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // which, + 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, // in + 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, // my + 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, // opinion, + 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, // help + 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 31, // visualization! }; uint16_t Rgba::cgbColor() const {