From 2b9a37884b27e272c48c3c44e4ddd0d091b7f16d Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 24 Jan 2019 18:55:15 -0500 Subject: made square graph construction sane --- lib/src/graph.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'lib/src') diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index f59a817..0cc6a18 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -34,36 +34,36 @@ graph::graph(unsigned int Nx, unsigned int Ny) { vertices[i].r.x = (double)((1 + i / (Nx / 2)) % 2 + 2 * (i % (Nx / 2))); vertices[i].r.y = (double)(i / (Nx / 2)); vertices[i].polygon = { - {vertices[i].r.x - 0.5, vertices[i].r.y}, - {vertices[i].r.x, vertices[i].r.y - 0.5}, - {vertices[i].r.x + 0.5, vertices[i].r.y}, - {vertices[i].r.x, vertices[i].r.y + 0.5} + {vertices[i].r.x - 1.0, vertices[i].r.y}, + {vertices[i].r.x, vertices[i].r.y - 1.0}, + {vertices[i].r.x + 1.0, vertices[i].r.y}, + {vertices[i].r.x, vertices[i].r.y + 1.0} }; dual_vertices[i].r.x = (double)((i / (Nx / 2)) % 2 + 2 * (i % (Nx / 2))); dual_vertices[i].r.y = (double)(i / (Nx / 2)); dual_vertices[i].polygon = { - {dual_vertices[i].r.x - 0.5, vertices[i].r.y}, - {dual_vertices[i].r.x, vertices[i].r.y - 0.5}, - {dual_vertices[i].r.x + 0.5, vertices[i].r.y}, - {dual_vertices[i].r.x, vertices[i].r.y + 0.5} + {dual_vertices[i].r.x - 1.0, vertices[i].r.y}, + {dual_vertices[i].r.x, vertices[i].r.y - 1.0}, + {dual_vertices[i].r.x + 1.0, vertices[i].r.y}, + {dual_vertices[i].r.x, vertices[i].r.y + 1.0} }; } - for (unsigned int x = 0; x < Ny; x++) { - for (unsigned int y = 0; y < Nx; y++) { - unsigned int v1 = (Nx * x) / 2 + ((y + x % 2) / 2) % (Nx / 2); - unsigned int v2 = ((Nx * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (Nx / 2)) % nv; + for (unsigned int y = 0; y < Ny; y++) { + for (unsigned int x = 0; x < Nx; x++) { + unsigned int v1 = (Nx * y) / 2 + ((x + y % 2) / 2) % (Nx / 2); + unsigned int v2 = ((Nx * (y + 1)) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2)) % nv; - bool crossed_x = y == Nx - 1; - bool crossed_y = x == Ny - 1; + bool crossed_x = x == Nx - 1; + bool crossed_y = y == Ny - 1; - edges.push_back({{v1, v2}, {0.5 + (double)y, 0.5 + (double)x}, {crossed_x, crossed_y}}); + edges.push_back({{v1, v2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}}); - unsigned int dv1 = (Nx * x) / 2 + ((y + (x + 1) % 2) / 2) % (Nx / 2); - unsigned int dv2 = ((Nx * (x + 1)) / 2 + ((y + x % 2) / 2) % (Nx / 2)) % nv; + unsigned int dv1 = (Nx * y) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2); + unsigned int dv2 = ((Nx * (y + 1)) / 2 + ((x + y % 2) / 2) % (Nx / 2)) % nv; - dual_edges.push_back({{dv1, dv2}, {0.5 + (double)y, 0.5 + (double)x}, {crossed_x, crossed_y}}); + dual_edges.push_back({{dv1, dv2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}}); } } -- cgit v1.2.3-70-g09d2