From 2efe1119117c7847d728ae0467ed4502d2b2d4de Mon Sep 17 00:00:00 2001 From: Gui <51219838+gui-ace@users.noreply.github.com> Date: Wed, 9 Sep 2026 12:09:09 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8B=A1=E5=A4=A7=E3=82=BF=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E7=AF=84=E5=9B=B2=E6=9B=B4=E6=96=B0=E3=81=A7=E5=BA=A7?= =?UTF-8?q?=E6=A8=99=E3=82=92=E4=BA=8C=E9=87=8D=E7=B8=AE=E5=B0=8F=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=B8=8D=E5=85=B7=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dynmap/hdmap/IsoHDPerspective.java | 4 +- .../hdmap/IsoHDPerspectiveTileCoordsTest.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 DynmapCore/src/test/java/org/dynmap/hdmap/IsoHDPerspectiveTileCoordsTest.java diff --git a/DynmapCore/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java b/DynmapCore/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java index 101f0e12f..4ed045661 100644 --- a/DynmapCore/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java +++ b/DynmapCore/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java @@ -1126,8 +1126,8 @@ public List getTileCoords(DynmapWorld world, int minx, int for(int k = 0; k < 2; k++) { corner.z = blocks[k].z; world_to_map.transform(corner, tcorner); /* Get map coordinate of corner */ - int tx = fastFloor(tcorner.x/(tileSize << tilescale)); - int ty = fastFloor(tcorner.y/(tileSize << tilescale)); + int tx = fastFloor(tcorner.x/tileSize); + int ty = fastFloor(tcorner.y/tileSize); if(mintilex > tx) mintilex = tx; if(maxtilex < tx) maxtilex = tx; if(mintiley > ty) mintiley = ty; diff --git a/DynmapCore/src/test/java/org/dynmap/hdmap/IsoHDPerspectiveTileCoordsTest.java b/DynmapCore/src/test/java/org/dynmap/hdmap/IsoHDPerspectiveTileCoordsTest.java new file mode 100644 index 000000000..3c93b875e --- /dev/null +++ b/DynmapCore/src/test/java/org/dynmap/hdmap/IsoHDPerspectiveTileCoordsTest.java @@ -0,0 +1,69 @@ +package org.dynmap.hdmap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.dynmap.ConfigurationNode; +import org.dynmap.utils.TileFlags.TileCoord; +import org.junit.Test; + +public class IsoHDPerspectiveTileCoordsTest { + private IsoHDPerspective perspective(double azimuth, double inclination, double scale) { + ConfigurationNode config = new ConfigurationNode(); + config.put("name", "tile-coordinates-test"); + config.put("azimuth", azimuth); + config.put("inclination", inclination); + config.put("scale", scale); + return new IsoHDPerspective(null, config); + } + + @Test + public void scaledRangeUsesSameTileSizeAsPointUpdate() { + IsoHDPerspective p = perspective(180, 90, 4); + List point = p.getTileCoords(null, 1025, 64, 1025, 2); + assertEquals(1, point.size()); + assertEquals(8, point.get(0).x); + assertEquals(-9, point.get(0).y); + List range = p.getTileCoords(null, 1025, 64, 1025, 1025, 64, 1025, 2); + assertTrue(range.containsAll(point)); + assertEquals(3, range.size()); + for (TileCoord tile : range) { + assertEquals(8, tile.x); + assertTrue(tile.y >= -10 && tile.y <= -8); + } + } + + @Test + public void rangesCoverEveryBlockAcrossScalesPerspectivesAndBoundaries() { + double[][] views = {{180, 90, 4}, {135, 60, 16}, {45, 30, 1}, {0, 20, 64}}; + for (double[] view : views) { + IsoHDPerspective p = perspective(view[0], view[1], view[2]); + for (int scale = 0; scale <= 4; scale++) { + int boundary = 128 << scale; + int[] positions = {-boundary - 1, -boundary, -1, 0, boundary - 1, boundary, 1025}; + for (int x : positions) { + for (int z : positions) { + for (int y : new int[] {-64, 64, 319}) { + Set range = new HashSet<>(p.getTileCoords(null, + x, y, z, x + 2, y + 2, z + 2, scale)); + for (int dx = 0; dx <= 2; dx++) { + for (int dy = 0; dy <= 2; dy++) { + for (int dz = 0; dz <= 2; dz++) { + assertTrue("Missing point tile: scale=" + scale + ", x=" + x + + ", y=" + y + ", z=" + z, + range.containsAll(p.getTileCoords(null, + x + dx, y + dy, z + dz, scale))); + } + } + } + } + } + } + } + } + } +}