summaryrefslogtreecommitdiff
path: root/lib/src/graph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/graph.cpp')
-rw-r--r--lib/src/graph.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp
index 0cc6a18..526ffeb 100644
--- a/lib/src/graph.cpp
+++ b/lib/src/graph.cpp
@@ -18,11 +18,11 @@ double mod(double a, double b) {
}
}
-graph::graph(unsigned int Nx, unsigned int Ny) {
+graph::graph(unsigned Nx, unsigned Ny) {
L = {(double)Nx, (double)Ny};
- unsigned int ne = Nx * Ny;
- unsigned int nv = ne / 2;
+ unsigned ne = Nx * Ny;
+ unsigned nv = ne / 2;
vertices.resize(nv);
edges.reserve(ne);
@@ -30,7 +30,7 @@ graph::graph(unsigned int Nx, unsigned int Ny) {
dual_vertices.resize(nv);
dual_edges.reserve(ne);
- for (unsigned int i = 0; i < nv; i++) {
+ for (unsigned i = 0; i < nv; i++) {
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 = {
@@ -50,18 +50,18 @@ graph::graph(unsigned int Nx, unsigned int Ny) {
};
}
- 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;
+ for (unsigned y = 0; y < Ny; y++) {
+ for (unsigned x = 0; x < Nx; x++) {
+ unsigned v1 = (Nx * y) / 2 + ((x + y % 2) / 2) % (Nx / 2);
+ unsigned v2 = ((Nx * (y + 1)) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2)) % nv;
bool crossed_x = x == Nx - 1;
bool crossed_y = y == Ny - 1;
edges.push_back({{v1, v2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}});
- 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;
+ unsigned dv1 = (Nx * y) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2);
+ unsigned dv2 = ((Nx * (y + 1)) / 2 + ((x + y % 2) / 2) % (Nx / 2)) % nv;
dual_edges.push_back({{dv1, dv2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}});
}
@@ -93,21 +93,21 @@ class triangleException: public std::exception
}
} triex;
-unsigned int get_triangle_signature(unsigned int j1, unsigned int j2, unsigned int j3) {
- // this yucky function takes three unsigned integers representing the
+unsigned get_triangle_signature(unsigned j1, unsigned j2, unsigned j3) {
+ // this yucky function takes three unsignedegers representing the
// location in the nine periodic copies of each corner of a delauney triangle
- // and returns a signature for that triangle, which is an unsigned integer
+ // and returns a signature for that triangle, which is an unsignedeger
// that uniquely labels the way the triangle crosses boundaries of the
// copies. This allows us to differentiate delauney triangles with identical
// vertices but which should be identified with different faces
- unsigned int x1 = j1 % 3;
- unsigned int y1 = j1 / 3;
+ unsigned x1 = j1 % 3;
+ unsigned y1 = j1 / 3;
- unsigned int x2 = j2 % 3;
- unsigned int y2 = j2 / 3;
+ unsigned x2 = j2 % 3;
+ unsigned y2 = j2 / 3;
- unsigned int x3 = j3 % 3;
- unsigned int y3 = j3 / 3;
+ unsigned x3 = j3 % 3;
+ unsigned y3 = j3 / 3;
if ((j1 == j2) && (j2 == j3)) {
return 0;
@@ -146,9 +146,9 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
// randomly choose N to be floor(Lx * Ly / 2) or ceil(Lx * Ly / 2) with
// probability proportional to the distance from each
std::uniform_real_distribution<double> d(0.0, 1.0);
- unsigned int N = round(Lx * Ly / 2 + d(rng) - 0.5);
+ unsigned N = round(Lx * Ly / 2 + d(rng) - 0.5);
- unsigned int nv = N;
+ unsigned nv = N;
vertices.resize(nv);
// the coordinates of the lattice, from which a delaunay triangulation
@@ -164,7 +164,7 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
jcv_rect bounds = {{-Lx, -Ly}, {2 * Lx, 2 * Ly}};
std::vector<jcv_point> points(9 * nv);
- for (unsigned int i = 0; i < nv; i++) {
+ for (unsigned i = 0; i < nv; i++) {
const vertex& v = vertices[i];
points[9 * i + 0] = {v.r.x - L.x, v.r.y - L.y};
points[9 * i + 1] = {v.r.x + 0.0, v.r.y - L.y};
@@ -181,7 +181,7 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
const jcv_site* sites = jcv_diagram_get_sites(&diagram);
- std::unordered_map<std::array<unsigned int, 4>, unsigned int> known_vertices;
+ std::unordered_map<std::array<unsigned, 4>, unsigned> known_vertices;
for (int i = 0; i < diagram.numsites; i++) {
const jcv_site* site = &sites[i];
@@ -189,8 +189,8 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
// we only care about processing the cells of our original, central sites
if (site->index % 9 == 4) {
bool self_bonded = false;
- unsigned int i1 = (unsigned int)(site->index / 9);
- unsigned int j1 = (unsigned int)(site->index % 9);
+ unsigned i1 = (unsigned)(site->index / 9);
+ unsigned j1 = (unsigned)(site->index % 9);
const jcv_graphedge* e = site->edges;
const jcv_graphedge* ep = site->edges;
while (ep->next) {
@@ -205,27 +205,27 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
if (neighbor == NULL) {
throw clippingex;
}
- unsigned int i2 = (unsigned int)(neighbor->index / 9);
- unsigned int j2 = (unsigned int)(neighbor->index % 9);
- unsigned int x2 = j2 % 3;
- unsigned int y2 = j2 / 3;
+ unsigned i2 = (unsigned)(neighbor->index / 9);
+ unsigned j2 = (unsigned)(neighbor->index % 9);
+ unsigned x2 = j2 % 3;
+ unsigned y2 = j2 / 3;
vertices[i1].polygon.push_back({e->pos[0].x, e->pos[0].y});
if (ep->neighbor == NULL) {
throw clippingex;
}
- unsigned int i3p = (unsigned int)(ep->neighbor->index / 9);
- unsigned int j3p = (unsigned int)(ep->neighbor->index % 9);
+ unsigned i3p = (unsigned)(ep->neighbor->index / 9);
+ unsigned j3p = (unsigned)(ep->neighbor->index % 9);
- unsigned int sig1 = get_triangle_signature(j1, j2, j3p);
+ unsigned sig1 = get_triangle_signature(j1, j2, j3p);
- std::array<unsigned int, 4> t1 = {i1, i2, i3p, sig1};
+ std::array<unsigned, 4> t1 = {i1, i2, i3p, sig1};
std::sort(t1.begin(), t1.begin() + 3);
auto it1 = known_vertices.find(t1);
- unsigned int vi1;
+ unsigned vi1;
if (it1 == known_vertices.end()) {
vi1 = dual_vertices.size();
@@ -259,17 +259,17 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
throw clippingex;
}
- unsigned int i3n = (unsigned int)(en->neighbor->index / 9);
- unsigned int j3n = (unsigned int)(en->neighbor->index % 9);
+ unsigned i3n = (unsigned)(en->neighbor->index / 9);
+ unsigned j3n = (unsigned)(en->neighbor->index % 9);
- unsigned int sig2 = get_triangle_signature(j1, j2, j3n);
+ unsigned sig2 = get_triangle_signature(j1, j2, j3n);
- std::array<unsigned int, 4> t2 = {i1, i2, i3n, sig2};
+ std::array<unsigned, 4> t2 = {i1, i2, i3n, sig2};
std::sort(t2.begin(), t2.begin() + 3);
auto it2 = known_vertices.find(t2);
- unsigned int vi2;
+ unsigned vi2;
if (it2 == known_vertices.end()) {
vi2 = dual_vertices.size();
@@ -279,8 +279,8 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) {
vi2 = it2->second;
}
- bool dcrossed_x = (unsigned int)floor(e->pos[0].x / L.x) != (unsigned int)floor(e->pos[1].x / L.x);
- bool dcrossed_y = (unsigned int)floor(e->pos[0].y / L.y) != (unsigned int)floor(e->pos[1].y / L.y);
+ bool dcrossed_x = (unsigned)floor(e->pos[0].x / L.x) != (unsigned)floor(e->pos[1].x / L.x);
+ bool dcrossed_y = (unsigned)floor(e->pos[0].y / L.y) != (unsigned)floor(e->pos[1].y / L.y);
dual_edges.push_back({{vi1, vi2},
{mod((e->pos[0].x + e->pos[1].x) / 2, L.x),