Apply offsets to the logical plot grid
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PlotGridLayoutTest {
|
||||
@Test
|
||||
void zeroOffsetsPreserveTheExistingPlotGrid() {
|
||||
PlotGridLayout grid = new PlotGridLayout(32, 10, 32, 4, 4, 0, 0, 0, 62);
|
||||
|
||||
assertEquals(BlockVector3.at(0, 62, 0), grid.gridMin(0, 0, 0));
|
||||
assertEquals(BlockVector3.at(35, 71, 35), grid.gridMax(0, 0, 1, 1, 0));
|
||||
assertEquals(BlockVector3.at(2, 62, 2), grid.plotMin(0, 0, 0));
|
||||
assertEquals(BlockVector3.at(33, 71, 33), grid.plotMax(0, 0, 1, 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void offsetsShiftGridAndPlotsOnAllAxesIncludingHigherLevels() {
|
||||
PlotGridLayout grid = new PlotGridLayout(32, 10, 32, 2, 6, -7, 3, 11, 62);
|
||||
|
||||
assertEquals(BlockVector3.at(-45, 97, -23), grid.gridMin(-1, -1, 2));
|
||||
assertEquals(BlockVector3.at(30, 106, 44), grid.gridMax(-1, -1, 2, 2, 2));
|
||||
assertEquals(BlockVector3.at(-42, 97, -22), grid.plotMin(-1, -1, 2));
|
||||
assertEquals(BlockVector3.at(27, 106, 43), grid.plotMax(-1, -1, 2, 2, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapsNegativePlotBoundsBackToTheirLogicalIndices() {
|
||||
PlotGridLayout grid = new PlotGridLayout(32, 10, 32, 2, 6, -7, 3, 11, 62);
|
||||
Cuboid plot = new Cuboid(grid.plotMin(-1, -1, 0), grid.plotMax(-1, -1, 2, 2, 0));
|
||||
|
||||
assertEquals(-1, grid.plotXIndexFromMin(plot));
|
||||
assertEquals(-1, grid.plotZIndexFromMin(plot));
|
||||
}
|
||||
}
|
||||
@@ -26,21 +26,21 @@ import org.junit.jupiter.api.Test;
|
||||
class SpawnLayoutTest {
|
||||
@Test
|
||||
void defaultMultipliersPreserveTheOnePlotSpawnBounds() {
|
||||
Cuboid spawn = SpawnLayout.bounds(1, 1, 1, 32, 10, 32, 4, 4, 62);
|
||||
Cuboid spawn = SpawnLayout.bounds(1, 1, 1, 32, 10, 32, 4, 4, 62, 0, 0, 0);
|
||||
|
||||
assertEqualsBounds(spawn, 2, 62, 2, 33, 71, 33);
|
||||
}
|
||||
|
||||
@Test
|
||||
void appliesEachMultiplierToItsOwnAlignedGridDimension() {
|
||||
Cuboid spawn = SpawnLayout.bounds(2, 3, 4, 32, 10, 32, 4, 4, 62);
|
||||
Cuboid spawn = SpawnLayout.bounds(2, 3, 4, 32, 10, 32, 4, 4, 62, 0, 0, 0);
|
||||
|
||||
assertEqualsBounds(spawn, 2, 62, 2, 69, 91, 141);
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesTheEntireSpawnHeightAgainstWorldBounds() {
|
||||
Cuboid spawn = SpawnLayout.bounds(1, 3, 1, 32, 10, 32, 4, 4, 62);
|
||||
Cuboid spawn = SpawnLayout.bounds(1, 3, 1, 32, 10, 32, 4, 4, 62, 0, 0, 0);
|
||||
|
||||
assertTrue(SpawnLayout.withinBuildHeight(spawn, -64, 320));
|
||||
assertFalse(SpawnLayout.withinBuildHeight(spawn, -64, 91));
|
||||
@@ -48,15 +48,23 @@ class SpawnLayoutTest {
|
||||
|
||||
@Test
|
||||
void alignsSpawnAxesToTheirIndependentRoadWidths() {
|
||||
Cuboid spawn = SpawnLayout.bounds(2, 1, 3, 32, 10, 32, 6, 2, 62);
|
||||
Cuboid spawn = SpawnLayout.bounds(2, 1, 3, 32, 10, 32, 6, 2, 62, 0, 0, 0);
|
||||
|
||||
assertEqualsBounds(spawn, 3, 62, 1, 72, 71, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
void alignsSpawnBoundsWithAllGridOffsets() {
|
||||
Cuboid spawn = SpawnLayout.bounds(2, 2, 3, 32, 10, 32, 6, 2, 62, -7, 3, 11);
|
||||
|
||||
assertEqualsBounds(spawn, -4, 65, 12, 65, 84, 111);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsNonPositiveSpawnMultipliers() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> SpawnLayout.bounds(0, 1, 1, 32, 10, 32, 4, 4, 62));
|
||||
IllegalArgumentException.class,
|
||||
() -> SpawnLayout.bounds(0, 1, 1, 32, 10, 32, 4, 4, 62, 0, 0, 0));
|
||||
}
|
||||
|
||||
private static void assertEqualsBounds(
|
||||
|
||||
Reference in New Issue
Block a user