From 4649658a9b46cf6cb56d10b0dcee5ec4d69c429a Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Tue, 14 Mar 2023 15:03:27 +0000 Subject: [PATCH] Add off-axis movement --- DLASystem.cpp | 70 ++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/DLASystem.cpp b/DLASystem.cpp index aa73cec..4549677 100644 --- a/DLASystem.cpp +++ b/DLASystem.cpp @@ -109,42 +109,44 @@ void DLASystem::addParticleOnAddCircle() { cerr << "FAIL " << pos[0] << " " << pos[1] << endl; } +const static size_t NEIGHBOURS = 26; + // send back the position of a neighbour of a given grid cell // NOTE: there is no check that the neighbour is inside the grid, // this has to be done separately... void DLASystem::setPosNeighbour(double setpos[], double pos[], int val) { - switch (val) { - case 0: - setpos[0] = pos[0] + 1.0; - setpos[1] = pos[1]; - setpos[2] = pos[2]; - break; - case 1: - setpos[0] = pos[0] - 1.0; - setpos[1] = pos[1]; - setpos[2] = pos[2]; - break; - case 2: - setpos[0] = pos[0]; - setpos[1] = pos[1] + 1.0; - setpos[2] = pos[2]; - break; - case 3: - setpos[0] = pos[0]; - setpos[1] = pos[1] - 1.0; - setpos[2] = pos[2]; - break; - case 4: - setpos[0] = pos[0]; - setpos[1] = pos[1]; - setpos[2] = pos[2] + 1.0; - break; - case 5: - setpos[0] = pos[0]; - setpos[1] = pos[1]; - setpos[2] = pos[2] - 1.0; - break; - } + const static double offsets[NEIGHBOURS][3] = { + {-1, -1, -1}, + {-1, -1, 0}, + {-1, -1, 1}, + {-1, 0, -1}, + {-1, 0, 0}, + {-1, 0, 1}, + {-1, 1, -1}, + {-1, 1, 0}, + {-1, 1, 1}, + {0, -1, -1}, + {0, -1, 0}, + {0, -1, 1}, + {0, 0, -1}, + {0, 0, 1}, + {0, 1, -1}, + {0, 1, 0}, + {0, 1, 1}, + {1, -1, -1}, + {1, -1, 0}, + {1, -1, 1}, + {1, 0, -1}, + {1, 0, 0}, + {1, 0, 1}, + {1, 1, -1}, + {1, 1, 0}, + {1, 1, 1} + }; + + setpos[0] = pos[0] + offsets[val][0]; + setpos[1] = pos[1] + offsets[val][1]; + setpos[2] = pos[2] + offsets[val][2]; } // when we add a particle to the cluster, we should update the cluster radius @@ -170,7 +172,7 @@ void DLASystem::updateClusterRadius(double pos[]) { // make a random move of the last particle in the particleList void DLASystem::moveLastParticle() { - int rr = rgen.randomInt(6); // pick a random number in the range 0-3, which direction do we hop? + int rr = rgen.randomInt(NEIGHBOURS); // pick a random number in the range 0-3, which direction do we hop? double newpos[3]; Particle *lastP = particleList[numParticles - 1]; @@ -227,7 +229,7 @@ DLASystem::DLASystem(const int maxParticles, const string &csvPath, const double // allocate memory for the grid, remember to free the memory in destructor grid = new int **[gridSize]; for (int i = 0; i < gridSize; i++) { - grid[i] = new int*[gridSize]; + grid[i] = new int *[gridSize]; for (int j = 0; j < gridSize; ++j) { grid[i][j] = new int[gridSize];