#include "graph.hpp" graph::graph(unsigned int L) { double dx = 1.0 / L; unsigned int nv = 2 * pow(L / 2, 2); unsigned int ne = pow(L, 2); vertices.resize(nv); edges.reserve(ne); dual_vertices.resize(nv); dual_edges.reserve(ne); for (unsigned int i = 0; i < nv; i++) { vertices[i].r.x = dx * ((1 + i / (L / 2)) % 2 + 2 * (i % (L / 2))); vertices[i].r.y = dx * (i / (L / 2)); dual_vertices[i].r.x = dx * ((i / (L / 2)) % 2 + 2 * (i % (L / 2))); dual_vertices[i].r.y = dx * (i / (L / 2)); } for (unsigned int x = 0; x < L; x++) { for (unsigned int y = 0; y < L; y++) { unsigned int v1 = (L * x) / 2 + ((y + x % 2) / 2) % (L / 2); unsigned int v2 = ((L * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2)) % nv; edges.push_back({v1, v2}); unsigned int dv1 = (L * x) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2); unsigned int dv2 = ((L * (x + 1)) / 2 + ((y + x % 2) / 2) % (L / 2)) % nv; dual_edges.push_back({dv1, dv2}); } } }