mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-04-11 13:23:13 +00:00
arb:: utilities for making Archimedean tilings
This commit is contained in:
parent
3b5e31156d
commit
32c6228319
@ -107,6 +107,11 @@ EX void load(const string& fname) {
|
||||
ep.force_eat(")");
|
||||
};
|
||||
while(true) {
|
||||
|
||||
ep.extra_params["distunit"] = distunit;
|
||||
ep.extra_params["angleunit"] = angleunit;
|
||||
ep.extra_params["angleofs"] = angleofs;
|
||||
|
||||
ep.skip_white();
|
||||
if(ep.next() == 0) break;
|
||||
if(ep.eat("#")) {
|
||||
|
@ -42,6 +42,7 @@ struct archimedean_tiling {
|
||||
|
||||
void make_match(int a, int i, int b, int j);
|
||||
void prepare();
|
||||
void compute_sum();
|
||||
void compute_geometry();
|
||||
|
||||
void parse();
|
||||
@ -135,11 +136,20 @@ void archimedean_tiling::make_match(int a, int i, int b, int j) {
|
||||
/** mostly to protect the user from entering too large numbers */
|
||||
const int MAX_EDGE_ARCM = FULL_EDGE;
|
||||
|
||||
void archimedean_tiling::prepare() {
|
||||
|
||||
void archimedean_tiling::compute_sum() {
|
||||
N = isize(faces);
|
||||
euclidean_angle_sum = 0;
|
||||
for(int f: faces) euclidean_angle_sum += (f-2.) / f;
|
||||
|
||||
real_faces = 0, real_face_type = 0;
|
||||
for(int i=0; i<N; i++) if(faces[i] > 2) real_faces++, real_face_type += faces[i];
|
||||
real_face_type /= 2;
|
||||
}
|
||||
|
||||
void archimedean_tiling::prepare() {
|
||||
|
||||
compute_sum();
|
||||
|
||||
for(int i: faces) if(i > MAX_EDGE_ARCM) {
|
||||
errormsg = XLAT("currently no more than %1 edges", its(MAX_EDGE_ARCM));
|
||||
errors++;
|
||||
@ -161,10 +171,6 @@ void archimedean_tiling::prepare() {
|
||||
return;
|
||||
}
|
||||
|
||||
real_faces = 0, real_face_type = 0;
|
||||
for(int i=0; i<N; i++) if(faces[i] > 2) real_faces++, real_face_type += faces[i];
|
||||
real_face_type /= 2;
|
||||
|
||||
if(real_faces) {
|
||||
for(int i=1; i<isize(faces); i++) if(faces[i] == 2 && faces[i-1] == 2) {
|
||||
errormsg = XLAT("Not implemented.");
|
||||
@ -189,7 +195,6 @@ void archimedean_tiling::prepare() {
|
||||
|
||||
/* build the 'adjacent' table */
|
||||
|
||||
N = isize(faces);
|
||||
int M = 2 * N + 2;
|
||||
adjacent.clear();
|
||||
adjacent.resize(M);
|
||||
|
50
util.cpp
50
util.cpp
@ -223,7 +223,55 @@ cld exp_parser::parse(int prio) {
|
||||
force_eat(",");
|
||||
cld b = rparse(0);
|
||||
force_eat(")");
|
||||
return edge_of_triangle_with_angles(M_PI/2, M_PI/real(a), M_PI/real(b));
|
||||
res = edge_of_triangle_with_angles(M_PI/2, M_PI/a, M_PI/b);
|
||||
}
|
||||
else if(eat("arcmedge(")) {
|
||||
vector<int> vals;
|
||||
vals.push_back(iparse(0));
|
||||
while(true) {
|
||||
skip_white();
|
||||
if(eat(",")) vals.push_back(iparse(0));
|
||||
else break;
|
||||
}
|
||||
force_eat(")");
|
||||
arcm::archimedean_tiling test;
|
||||
test.faces = vals;
|
||||
test.compute_sum();
|
||||
test.compute_geometry();
|
||||
res = test.edgelength;
|
||||
if(extra_params.count("distunit"))
|
||||
res /= extra_params["distunit"];
|
||||
}
|
||||
else if(eat("regangle(")) {
|
||||
ld edgelen = rparse(0);
|
||||
if(extra_params.count("distunit")) {
|
||||
println(hlog, "got edgelen = ", edgelen);
|
||||
println(hlog, "distunit = ", real(extra_params["distunit"]));
|
||||
edgelen = real(edgelen * extra_params["distunit"]);
|
||||
println(hlog, "got edgelen = ", edgelen);
|
||||
}
|
||||
|
||||
force_eat(",");
|
||||
int edges = iparse(0);
|
||||
force_eat(")");
|
||||
ld alpha = M_PI / edges;
|
||||
ld c = asin_auto(sin_auto(edgelen/2) / sin(alpha));
|
||||
hyperpoint h = xpush(c) * spin(M_PI - 2*alpha) * xpush0(c);
|
||||
res = 2 * atan2(h);
|
||||
if(real(res) < 0) res = -res;
|
||||
while(real(res) > 2 * M_PI) res -= 2 * M_PI;
|
||||
if(real(res) > M_PI) res = 2 * M_PI - res;
|
||||
res = M_PI - res;
|
||||
|
||||
if(extra_params.count("angleofs"))
|
||||
res -= extra_params["angleofs"];
|
||||
|
||||
if(extra_params.count("angleunit"))
|
||||
res /= extra_params["angleunit"];
|
||||
}
|
||||
else if(eat("test(")) {
|
||||
res = parsepar();
|
||||
println(hlog, "res = ", make_pair(real(res), imag(res)));
|
||||
}
|
||||
else if(eat("ifp(")) {
|
||||
cld cond = parse(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user