diff --git a/cosets/src/main.cpp b/cosets/src/main.cpp index 0ac8492..5a46978 100644 --- a/cosets/src/main.cpp +++ b/cosets/src/main.cpp @@ -32,12 +32,9 @@ public: program = build_program("main", vs, fs); - verts_data = vertices<3>({}, Multiplicites<3>({ - {0, 1, 5}, - {1, 2, 3} - }), { - 10, 1, 1 - }); + verts_data = vertices<3>( + schlafli<3>({5, 3}), + {10, 1, 1}); glGenBuffers(1, &verts); glBindBuffer(GL_ARRAY_BUFFER, verts); @@ -81,9 +78,7 @@ public: glBindVertexArray(tri); glUniform4f(0, 1, 1, 1, 1); - glDrawArrays(GL_POINTS, 0, verts_data.size() - 3); - glUniform4f(0, 1, 1, 1, .1); - glDrawArrays(GL_TRIANGLES, verts_data.size() - 3, 3); + glDrawArrays(GL_POINTS, 0, verts_data.size()); swapbuffers(); } diff --git a/cosets/src/mesh.cpp b/cosets/src/mesh.cpp index eb26070..4eb26ab 100644 --- a/cosets/src/mesh.cpp +++ b/cosets/src/mesh.cpp @@ -1,16 +1,20 @@ #include "util/mesh.hpp" int main(int argc, char *argv[]) { - auto vs = vertices<3>({}, Multiplicites<3>({ - {0, 1, 4}, - {1, 2, 3} - }), { - 1.0f, 1.0f, 1.0f - }); + const auto &mults = schlafli<4>({4, 3, 3}); + const std::vector &vs = vertices<4>(mults, {10, 1, 1, 1}); - for (const auto &v : vs) { + for (const auto &v:vs) { std::cout << glm::to_string(v) << std::endl; } - return 0; +// Table *table = solve({}, mults); +// std::cout << table->size() << std::endl; +// +// for (const auto &rel : mults.relations()) { +// for (const auto &e : rel) { +// std::cout << e << " "; +// } +// std::cout << std::endl; +// } } \ No newline at end of file diff --git a/cosets/src/mirrors.cpp b/cosets/src/mirrors.cpp index 51ba1d6..d6281bf 100644 --- a/cosets/src/mirrors.cpp +++ b/cosets/src/mirrors.cpp @@ -1,7 +1,7 @@ #include "util/mirrors.hpp" int main(int argc, char *argv[]) { - auto normals = mirror<3>(Multiplicites<3>({ + auto normals = mirror<3>(Multiplicities<3>({ {0, 1, 4}, {1, 2, 3} })); diff --git a/cosets/src/util/coxeter.hpp b/cosets/src/util/coxeter.hpp index 054a49f..54d39d6 100644 --- a/cosets/src/util/coxeter.hpp +++ b/cosets/src/util/coxeter.hpp @@ -5,39 +5,60 @@ #include #include #include - -struct Mult { - int a, b, mult; -}; +#include +#include template -struct Multiplicites { - std::vector mults; - - explicit Multiplicites(const std::vector &vals) { - mults = std::vector(N * (N - 1) / 2, 2); - for (const auto &mult : vals) { - set(mult.a, mult.b, mult.mult); - } - } +struct Mults { + std::map, int> mults{}; void set(int a, int b, int mult) { - if (a > N or b > N) throw std::logic_error("mirror does not exist"); - if (a == b) throw std::logic_error("cannot compare mirror to itself"); - if (a < b) std::swap(a, b); // a is bigger - - mults[a + b] = mult; + if (a > b) std::swap(a, b); + mults[std::make_tuple(a, b)] = mult; } [[nodiscard]] int get(int a, int b) const { - if (a > N or b > N) throw std::logic_error("mirror does not exist"); - if (a == b) throw std::logic_error("cannot compare mirror to itself"); - if (a < b) std::swap(a, b); // a is bigger + if (a == b) return 1; + if (a > b) std::swap(a, b); - return mults[a + b]; + const auto &tup = std::make_tuple(a, b); + const auto &res = mults.find(tup); + + if (res == mults.end()) return 2; + return res->second; + } + + [[nodiscard]] std::vector relation(int a, int b) const { + std::vector res{}; + int mult = get(a, b); + + for (int i = 0; i < mult; ++i) { + res.push_back(a); + res.push_back(b); + } + + return res; + } + + [[nodiscard]] std::vector> relations() const { + std::vector> res{}; + for (int a = 0; a < N; ++a) { + for (int b = a; b < N; ++b) { + res.push_back(relation(a, b)); + } + } + return res; } }; +template +Mults schlafli(const int (&symbol)[N - 1]) { + Mults mults{}; + for (int i = 0; i < N; ++i) { + mults.set(i, i + 1, symbol[i]); + } + return mults; +} struct Table { int N; @@ -171,7 +192,10 @@ std::ostream &operator<<(std::ostream &out, const Row &row) { return out; } -Table *solve(int gens, const std::vector &subgens, const std::vector> &rels) { +template +Table *solve(const std::vector &subgens, const Mults &mults) { + const auto rels = mults.relations(); + int gens = N; auto *table = new Table(gens); for (int gen : subgens) diff --git a/cosets/src/util/mesh.hpp b/cosets/src/util/mesh.hpp index 9380bb6..23197d4 100644 --- a/cosets/src/util/mesh.hpp +++ b/cosets/src/util/mesh.hpp @@ -7,58 +7,44 @@ #include template -std::vector -vertices(const std::vector &subgens, const Multiplicites &mults, const float (&coords)[N]) { +std::vector> coxeter_rels() { std::vector> rels{}; - rels.reserve(N + N * (N - 1) / 2); - for (int i = 0; i < N; ++i) { - rels.push_back({i, i}); - } - for (int a = 0; a < N; ++a) { - for (int b = 0; b < a; ++b) { - int mult = mults.get(a, b); + return rels; +} - std::vector rel{}; - for (int i = 0; i < mult; ++i) { - rel.push_back(a); - rel.push_back(b); - } - rels.push_back(rel); - } - } - - Table *table = solve(N, subgens, rels); - -// std::cout << table->size() << std::endl; -// std::cout << *table << std::endl; - -// for (const auto &v : table->words()) { -// std::cout << "[ "; -// for (auto e : v) { -// std::cout << e << " "; -// } -// std::cout << "]\n"; -// } - - const std::vector &normals = mirror<3>(mults); - const std::vector &corners = plane_intersections(normals); +template +glm::vec4 identity(const std::vector &normals, const float(&coords)[N]) { + const std::vector corners = plane_intersections(normals); const std::vector coords_vec(coords, coords + N); - const glm::vec4 &identity = glm::normalize(barycentric(corners, coords_vec)); + const glm::vec4 identity = barycentric(corners, coords_vec); + return glm::normalize(identity); +} + +template +std::vector +vertices(const Mults &mults, const float (&coords)[N]) { + Table *table = solve({}, mults); + + const std::vector normals = mirror(mults); + glm::vec4 ident = identity(normals, coords); std::vector verts{}; - for (const auto &word : table->words()) { - glm::vec4 vert = identity; + glm::vec4 vert = ident; for (const auto &gen : word) { vert = reflect(vert, normals[gen]); } verts.push_back(vert); } - for (const auto &e : corners) { - verts.push_back(e * 1.1f); - } - return verts; -} \ No newline at end of file +} + +template +std::vector lines(const Mults &mults) { +// Table *table = solve(N, {}, coxeter_rels(mults)); + + return {}; +} + diff --git a/cosets/src/util/mirrors.hpp b/cosets/src/util/mirrors.hpp index 6a629bd..ce107bd 100644 --- a/cosets/src/util/mirrors.hpp +++ b/cosets/src/util/mirrors.hpp @@ -11,7 +11,7 @@ #include "coxeter.hpp" template -std::vector mirror(const Multiplicites &mults) { +std::vector mirror(const Mults &mults) { static_assert(1 <= N and N <= 4, "Vector size is unsupported"); std::vector mirrors{};