summaryrefslogtreecommitdiff
path: root/src/fortune
diff options
context:
space:
mode:
authorpants <jaron@kent-dobias.com>2016-08-31 11:57:40 -0400
committerpants <jaron@kent-dobias.com>2016-08-31 11:57:40 -0400
commit0f6782c9e5a9171d69d8e62dff33a558ba542d58 (patch)
tree79ebe235b2c9fb957946428e87d2629f07dfde10 /src/fortune
parentc2164e4a38b79c8a02bd7c0f4481f222c7b4dae6 (diff)
downloadfuse_networks-0f6782c9e5a9171d69d8e62dff33a558ba542d58.tar.gz
fuse_networks-0f6782c9e5a9171d69d8e62dff33a558ba542d58.tar.bz2
fuse_networks-0f6782c9e5a9171d69d8e62dff33a558ba542d58.zip
did some refactoring
Diffstat (limited to 'src/fortune')
-rw-r--r--src/fortune/main.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/src/fortune/main.c b/src/fortune/main.c
index 7571945..543f6e4 100644
--- a/src/fortune/main.c
+++ b/src/fortune/main.c
@@ -77,7 +77,7 @@ unsigned int delete_duplicates(unsigned int ne, unsigned int *etv) {
return newsize;
}
-intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xmax, double ymin, double ymax)
+intptr_t *run_voronoi(unsigned int num, double *lattice, bool periodic, double xmin, double xmax, double ymin, double ymax)
{
struct Site *(*next)();
@@ -91,45 +91,50 @@ intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xma
freeinit(&sfl, sizeof *sites);
- unsigned int eff_num = 9 * num;
- double *eff_lattice = (double *)malloc(2 * eff_num * sizeof(double));
+ unsigned int eff_num = num;
+ double *eff_lattice = lattice;
- for (unsigned int i = 0; i < num; i++) {
- // original sites - our baby boys
- eff_lattice[2*i] = lattice[2*i];
- eff_lattice[2*i+1] = lattice[2*i+1];
+ if (periodic) {
+ unsigned int eff_num = 9 * num;
+ double *eff_lattice = (double *)malloc(2 * eff_num * sizeof(double));
- // sites to the right
- eff_lattice[2*(num+i)+1] = lattice[2*i+1] - xmin + xmax;
- eff_lattice[2*(num+i)] = lattice[2*i];
+ for (unsigned int i = 0; i < num; i++) {
+ // original sites - our baby boys
+ eff_lattice[2*i] = lattice[2*i];
+ eff_lattice[2*i+1] = lattice[2*i+1];
- // sites to the left
- eff_lattice[2*(2*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(2*num+i)] = lattice[2*i];
+ // sites to the right
+ eff_lattice[2*(num+i)+1] = lattice[2*i+1] - xmin + xmax;
+ eff_lattice[2*(num+i)] = lattice[2*i];
- // sites to the top
- eff_lattice[2*(3*num+i)+1] = lattice[2*i+1];
- eff_lattice[2*(3*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the left
+ eff_lattice[2*(2*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(2*num+i)] = lattice[2*i];
- // sites to the bottom
- eff_lattice[2*(4*num+i)+1] = lattice[2*i+1];
- eff_lattice[2*(4*num+i)] = lattice[2*i] - ymax + ymin;
+ // sites to the top
+ eff_lattice[2*(3*num+i)+1] = lattice[2*i+1];
+ eff_lattice[2*(3*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the upper right
- eff_lattice[2*(5*num+i)+1] = lattice[2*i+1] - xmin + xmax;
- eff_lattice[2*(5*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the bottom
+ eff_lattice[2*(4*num+i)+1] = lattice[2*i+1];
+ eff_lattice[2*(4*num+i)] = lattice[2*i] - ymax + ymin;
- // sites to the upper left
- eff_lattice[2*(6*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(6*num+i)] = lattice[2*i] - ymin + ymax;
+ // sites to the upper right
+ eff_lattice[2*(5*num+i)+1] = lattice[2*i+1] - xmin + xmax;
+ eff_lattice[2*(5*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the lower left
- eff_lattice[2*(7*num+i)+1] = lattice[2*i+1] - xmax + xmin;
- eff_lattice[2*(7*num+i)] = lattice[2*i] + ymin - ymax;
+ // sites to the upper left
+ eff_lattice[2*(6*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(6*num+i)] = lattice[2*i] - ymin + ymax;
- // sites to the lower right
- eff_lattice[2*(8*num+i)+1] = lattice[2*i+1] + xmax - xmin;
- eff_lattice[2*(8*num+i)] = lattice[2*i] + ymin - ymax;
+ // sites to the lower left
+ eff_lattice[2*(7*num+i)+1] = lattice[2*i+1] - xmax + xmin;
+ eff_lattice[2*(7*num+i)] = lattice[2*i] + ymin - ymax;
+
+ // sites to the lower right
+ eff_lattice[2*(8*num+i)+1] = lattice[2*i+1] + xmax - xmin;
+ eff_lattice[2*(8*num+i)] = lattice[2*i] + ymin - ymax;
+ }
}
nsites = eff_num;
@@ -160,7 +165,7 @@ intptr_t *run_voronoi(unsigned int num, double *lattice, double xmin, double xma
unsigned int *real_edge_list = edge_list;
unsigned int *real_dual_list = dual_list;
- {
+ if (periodic) {
real_vert_count = 0;
real_edge_count = 0;
real_dual_count = 0;