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.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp
index 526ffeb..8aa8877 100644
--- a/lib/src/graph.cpp
+++ b/lib/src/graph.cpp
@@ -141,27 +141,38 @@ unsigned get_triangle_signature(unsigned j1, unsigned j2, unsigned j3) {
}
graph::graph(double Lx, double Ly, std::mt19937& rng) {
- L = {Lx, Ly};
-
// 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 N = round(Lx * Ly / 2 + d(rng) - 0.5);
- unsigned nv = N;
+ L = {Lx, Ly};
+
+ this->helper(N, rng);
+}
+
+graph::graph(unsigned n, double a, std::mt19937& rng) {
+ L = {2 * n * a, 2 * n / a};
+
+ this->helper(n, rng);
+}
+
+void graph::helper(unsigned n, std::mt19937& rng) {
+ std::uniform_real_distribution<double> d(0.0, 1.0);
+ unsigned nv = n;
vertices.resize(nv);
// the coordinates of the lattice, from which a delaunay triangulation
// and corresponding voronoi tessellation will be built. Everyone is in the
// rectangle (0, 0) (Lx, Ly)
for (vertex &v : vertices) {
- v = {{Lx * d(rng), Ly * d(rng)}};
+ v = {{L.x * d(rng), L.y * d(rng)}};
}
// set up the voronoi objects
jcv_diagram diagram;
memset(&diagram, 0, sizeof(jcv_diagram));
- jcv_rect bounds = {{-Lx, -Ly}, {2 * Lx, 2 * Ly}};
+ jcv_rect bounds = {{-L.x, -L.y}, {2 * L.x, 2 * L.y}};
std::vector<jcv_point> points(9 * nv);
for (unsigned i = 0; i < nv; i++) {