From fff18e481f3ed199ac29514d36cc9cf8988a885f Mon Sep 17 00:00:00 2001 From: David Allemang Date: Thu, 26 Jan 2023 16:41:25 -0500 Subject: [PATCH] OPT: Clean up extraneous recontext logic --- vis/include/combo_iterator.hpp | 2 +- vis/include/geometry.hpp | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/vis/include/combo_iterator.hpp b/vis/include/combo_iterator.hpp index 1669b2b..569887a 100644 --- a/vis/include/combo_iterator.hpp +++ b/vis/include/combo_iterator.hpp @@ -84,7 +84,7 @@ private: int size; public: - Combos(const std::vector &options, int k) + Combos(const std::vector &options, size_t k) : options(options), k(k), size(choose(options.size(), k)) { } diff --git a/vis/include/geometry.hpp b/vis/include/geometry.hpp index 4f83d82..dabe6c0 100644 --- a/vis/include/geometry.hpp +++ b/vis/include/geometry.hpp @@ -15,21 +15,21 @@ template struct Primitive { static_assert(N > 0, "Primitives must contain at least one point. Primitive<0> or lower is impossible."); - std::array inds; + std::array indices; Primitive() = default; Primitive(const Primitive &) = default; Primitive(const Primitive &sub, unsigned root) { - std::copy(sub.inds.begin(), sub.inds.end(), inds.begin()); - inds[N - 1] = root; + std::copy(sub.indices.begin(), sub.indices.end(), indices.begin()); + indices[N - 1] = root; } ~Primitive() = default; void apply(const tc::Cosets<> &table, int gen) { - for (auto &ind: inds) { + for (auto &ind: indices) { ind = table.get(ind, gen); } } @@ -50,19 +50,12 @@ std::vector generators(const tc::Group<> &context) { * Produces the indexes of sg_gens within g_gens; sorted. */ std::vector recontext_gens( - const tc::Group<> &context, const std::vector &g_gens, const std::vector &sg_gens) { - size_t inv_gen_map[context.rank()]; - for (size_t i = 0; i < g_gens.size(); i++) { - inv_gen_map[g_gens[i]] = i; - } - std::vector s_sg_gens; - s_sg_gens.reserve(sg_gens.size()); - for (const auto gen : sg_gens) { - s_sg_gens.push_back(inv_gen_map[gen]); + for (const auto &gen: sg_gens) { + s_sg_gens.push_back(std::find(g_gens.begin(), g_gens.end(), gen) - g_gens.begin()); } return s_sg_gens; @@ -90,7 +83,7 @@ std::vector> recontext( const std::vector &g_gens, const std::vector &sg_gens ) { - const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens); + const auto proper_sg_gens = recontext_gens(g_gens, sg_gens); const auto table = context.sub(g_gens).solve({}); const auto cosets = context.sub(sg_gens).solve({}); @@ -103,7 +96,7 @@ std::vector> recontext( std::vector> res(prims); for (Primitive &prim: res) { - for (auto &ind: prim.inds) { + for (auto &ind: prim.indices) { ind = map[ind]; } } @@ -139,7 +132,7 @@ std::vector>> each_tile( const std::vector &sg_gens ) { std::vector> base = recontext(prims, context, g_gens, sg_gens); - const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens); + const auto proper_sg_gens = recontext_gens(g_gens, sg_gens); const auto table = context.sub(g_gens).solve({}); @@ -197,7 +190,7 @@ std::vector> triangulate( throw std::logic_error("g_gens size must be one less than N"); } - const auto &combos = Combos(g_gens, g_gens.size() - 1U); + const auto &combos = Combos(g_gens, g_gens.size() - 1); std::vector>> meshes;