From 60d0d15dab82c2393149398bd18715b8503902f2 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 8 Oct 2022 01:54:30 +0200 Subject: [PATCH] tes:: refactored find_connection --- arbitrile.cpp | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/arbitrile.cpp b/arbitrile.cpp index a910c02c..3111bec9 100644 --- a/arbitrile.cpp +++ b/arbitrile.cpp @@ -1377,6 +1377,28 @@ EX transmatrix get_adj(arbi_tiling& c, int t, int dl) { return get_adj(c, t, dl, co.sid, co.eid, co.mirror); } +/** Returns if F describes the same tile as T, taking possible symmetries into account. Paramater co is the expected edge (co.sid tells us the tile type); if yes, co may be adjusted */ +EX bool find_connection(const transmatrix& T, const transmatrix& F, connection_t& co) { + + if(!same_point_may_warn(tC0(F), tC0(T))) return false; + + auto& xsh = current.shapes[co.sid]; + int n = isize(xsh.connections); + for(int oth = 0; oth < n; oth++) { + int oth1 = gmod(oth+1, n); + int eid1 = gmod(co.eid+1, n); + if(same_point_may_warn(F * xsh.vertices[oth], T * xsh.vertices[co.eid]) && same_point_may_warn(F * xsh.vertices[oth1], T * xsh.vertices[eid1])) { + co.eid = oth; + return true; + } + if(same_point_may_warn(F * xsh.vertices[oth], T * xsh.vertices[eid1]) && same_point_may_warn(F * xsh.vertices[oth1], T * xsh.vertices[co.eid])) { + co.eid = oth; co.mirror = !co.mirror; + return true; + } + } + return false; + } + struct hrmap_arbi : hrmap { heptagon *origin; heptagon *getOrigin() override { return origin; } @@ -1433,8 +1455,6 @@ struct hrmap_arbi : hrmap { auto& co = sh.connections[d]; - auto& xsh = current.shapes[co.sid]; - if(cgflags & qAFFINE) { set visited; @@ -1492,24 +1512,14 @@ struct hrmap_arbi : hrmap { alt = (heptagon*) s; } - for(auto& p2: altmap[alt]) if(id_of(p2.first) == co.sid && same_point_may_warn(tC0(p2.second), tC0(T))) { - for(int oth=0; oth < p2.first->type; oth++) { - int oth1 = gmod(oth+1, p2.first->type); - int eid1 = gmod(co.eid+1, p2.first->type); - if(same_point_may_warn(p2.second * xsh.vertices[oth], T * xsh.vertices[co.eid]) && same_point_may_warn(p2.second * xsh.vertices[oth1], T * xsh.vertices[eid1])) { - if(p2.first->move(oth)) { - throw hr_exception("already connected!"); - } - h->c.connect(d, p2.first, oth%p2.first->type, co.mirror); - return p2.first; - } - if(same_point_may_warn(p2.second * xsh.vertices[oth], T * xsh.vertices[eid1]) && same_point_may_warn(p2.second * xsh.vertices[oth1], T * xsh.vertices[co.eid])) { - if(p2.first->move(oth)) { - throw hr_exception("already connected!"); - } - h->c.connect(d, p2.first, oth%p2.first->type, co.mirror^1); - return p2.first; + for(auto& p2: altmap[alt]) if(id_of(p2.first) == co.sid) { + connection_t co1 = co; + if(find_connection(T, p2.second, co1)) { + if(p2.first->move(co1.eid)) { + throw hr_exception("already connected!"); } + h->c.connect(d, p2.first, co1.eid, co1.mirror); + return p2.first; } }