mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-11 20:46:13 -05:00
working on memoization
This commit is contained in:
38
vis/include/geometry.hpp
Normal file
38
vis/include/geometry.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <tc/core.hpp>
|
||||
#include <optional>
|
||||
#include <cmath>
|
||||
|
||||
size_t key(const std::vector<int> &gens) {
|
||||
size_t bits = 0;
|
||||
for (const auto &gen : gens) {
|
||||
bits |= 1U << gen;
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
struct CosetMemo {
|
||||
const tc::Group &parent;
|
||||
std::vector<std::vector<std::optional<tc::Cosets>>> results;
|
||||
|
||||
explicit CosetMemo(const tc::Group &parent)
|
||||
: parent(parent) {
|
||||
size_t W = std::pow(2, parent.ngens);
|
||||
|
||||
for (size_t i = 0; i < W; ++i) {
|
||||
results.emplace_back(W, std::nullopt);
|
||||
}
|
||||
}
|
||||
|
||||
tc::Cosets solve(const std::vector<int> &group_gens, const std::vector<int> &sub_gens) {
|
||||
size_t group_key = key(group_gens);
|
||||
size_t sub_key = key(sub_gens);
|
||||
|
||||
if (!results[group_key][sub_key]) {
|
||||
results[group_key][sub_key] = parent.subgroup(group_gens).solve(sub_gens);
|
||||
}
|
||||
|
||||
return results[group_key][sub_key].value();
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <tc/cosets.h>
|
||||
#include <tc/core.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
@@ -27,7 +27,7 @@ std::vector<glm::vec4> mirror(const tc::Group &group) {
|
||||
glm::vec4 vp{};
|
||||
for (int m = 0; m < p; ++m) {
|
||||
glm::vec4 vq = mirrors[m];
|
||||
vp[m] = (cos(M_PI / group.rel(p, m).mult) - dot(m, vp, vq)) / vq[m];
|
||||
vp[m] = (cos(M_PI / group.get(p, m)) - dot(m, vp, vq)) / vq[m];
|
||||
}
|
||||
vp[p] = std::sqrt(1 - glm::dot(vp, vp));
|
||||
|
||||
42
vis/include/util.hpp
Normal file
42
vis/include/util.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void utilShaderSource(GLuint shader, const std::vector<std::string> &sources) {
|
||||
char const *ptrs[sources.size()];
|
||||
for (size_t i = 0; i < sources.size(); ++i) {
|
||||
ptrs[i] = sources[i].c_str();
|
||||
}
|
||||
glShaderSource(shader, sources.size(), ptrs, nullptr);
|
||||
}
|
||||
|
||||
std::string utilShaderInfoLog(GLuint shader) {
|
||||
int len;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
|
||||
char buffer[len];
|
||||
glGetShaderInfoLog(shader, len, nullptr, buffer);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
std::string utilProgramInfoLog(GLuint program) {
|
||||
int len;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
|
||||
char buffer[len];
|
||||
glGetProgramInfoLog(program, len, nullptr, buffer);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
std::string utilInfo() {
|
||||
std::stringstream ss;
|
||||
ss
|
||||
<< "Graphics Information:" << std::endl
|
||||
<< " Vendor: " << glGetString(GL_VENDOR) << std::endl
|
||||
<< " Renderer: " << glGetString(GL_RENDERER) << std::endl
|
||||
<< " OpenGL version: " << glGetString(GL_VERSION) << std::endl
|
||||
<< " Shading version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
Reference in New Issue
Block a user