more opt and fix bug

This commit is contained in:
Zoë Gidiere committed 2023-10-08 01:14:11 -06:00
1 parent be1a09b97a
commit 2144da5466
1 file changed
+17 -14
@@ -267,41 +267,44 @@ public class PseudoErosionSampler implements NoiseSampler {
} }
// Iterate over nearby cells // Iterate over nearby cells
cellDataIndex = 21;
for(int xi = -NEARBY_CELLS_RADIUS; xi <= NEARBY_CELLS_RADIUS; xi++) { for(int xi = -NEARBY_CELLS_RADIUS; xi <= NEARBY_CELLS_RADIUS; xi++) {
int xiKey = ((xi + PRECOMPUTE_RADIUS) * PRECOMPUTE_SIZE) + PRECOMPUTE_RADIUS; cellDataIndex += 3;
for(int yi = -NEARBY_CELLS_RADIUS; yi <= NEARBY_CELLS_RADIUS; yi++) { for(int yi = -NEARBY_CELLS_RADIUS; yi <= NEARBY_CELLS_RADIUS; yi++) {
// Find cell position with the lowest lookup value within moore neighborhood of neighbor // Find cell position with the lowest lookup value within moore neighborhood of neighbor
double lowestLookup = Double.MAX_VALUE; double lowestLookup = Double.MAX_VALUE;
double connectedCellX = 0; double connectedCellX = 0;
double connectedCellY = 0; double connectedCellY = 0;
int xni = xi - MAX_CONNECTION_RADIUS; int cellDataIndexN = cellDataIndex - 22;
int yni = yi - MAX_CONNECTION_RADIUS; int yniMin = yi - MAX_CONNECTION_RADIUS;
int linearIndexIterator = (((((xni + PRECOMPUTE_RADIUS) * PRECOMPUTE_SIZE) + PRECOMPUTE_RADIUS) + yni) * 3) + 2; int yniMax = yi + MAX_CONNECTION_RADIUS;
for(; xni <= xi + MAX_CONNECTION_RADIUS; xni++) { for(int xni = xi - MAX_CONNECTION_RADIUS; xni <= xi + MAX_CONNECTION_RADIUS; xni++) {
for(; yni <= yi + MAX_CONNECTION_RADIUS; yni++) { for(int yni = yniMin; yni <= yniMax; yni++) {
double lookup = cellData[linearIndexIterator]; double lookup = cellData[cellDataIndexN];
if(lookup < lowestLookup) { if(lookup < lowestLookup) {
lowestLookup = lookup; lowestLookup = lookup;
connectedCellX = cellData[linearIndexIterator - 2]; connectedCellX = cellData[cellDataIndexN - 2];
connectedCellY = cellData[linearIndexIterator - 1]; connectedCellY = cellData[cellDataIndexN - 1];
} }
linearIndexIterator += 3; cellDataIndexN += 3;
} }
cellDataIndexN += 12;
} }
int linearIndex = (xiKey + yi) * 3; double cellX = cellData[cellDataIndex];
double cellX = cellData[linearIndex]; double cellY = cellData[cellDataIndex + 1];
double cellY = cellData[linearIndex + 1];
// Calculate SDF for line between the current cell position and the surrounding cell with the lowest lookup // Calculate SDF for line between the current cell position and the surrounding cell with the lowest lookup
double distance = lineSdf2D(x, y, cellX, cellY, connectedCellX, connectedCellY); double distance = lineSdf2D(x, y, cellX, cellY, connectedCellX, connectedCellY);
// Set final return to the lowest computed distance // Set final return to the lowest computed distance
finalDistance = Math.min(finalDistance, distance); finalDistance = Math.min(finalDistance, distance);
cellDataIndex += 3;
} }
cellDataIndex += 3;
} }
return finalDistance; return finalDistance;