mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix(street-level): deduplicate overlapping dateline tile halves
This commit is contained in:
1 parent
6dd4d0156f
commit
ba58a5ec50
4 files changed
+28
-1
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { tilesForBbox } from './tileMath.js';
|
||||
test('coarse dateline coverage counts each tile exactly once', () => {
|
||||
for (const z of [0, 1, 2]) {
|
||||
const result = tilesForBbox([170, -1, -170, 1], z);
|
||||
const keys = result.tiles.map((t) => `${t.x}/${t.y}/${t.z}`);
|
||||
assert.equal(new Set(keys).size, keys.length);
|
||||
assert.equal(result.total, keys.length);
|
||||
const limited = tilesForBbox([170, -1, -170, 1], z, { limit: 1 });
|
||||
assert.equal(limited.total, keys.length);
|
||||
assert.equal(limited.truncated, keys.length > 1);
|
||||
assert.equal(limited.tiles.length, 1);
|
||||
}
|
||||
});
|
||||
@@ -147,7 +147,12 @@ export function tilesForBbox(bbox, z, { limit = Infinity, focus = null } = {}) {
|
||||
return Math.min(dx, n - dx) ** 2 + (tile.y - centre.y) ** 2;
|
||||
};
|
||||
// Each tile's distance is computed once; ties keep their row order.
|
||||
const ranked = tiles
|
||||
const unique = [
|
||||
...new Map(
|
||||
tiles.map((tile) => [`${tile.x}/${tile.y}/${tile.z}`, tile]),
|
||||
).values(),
|
||||
];
|
||||
const ranked = unique
|
||||
.map((tile) => ({ tile, d: distance2(tile) }))
|
||||
.sort((a, b) => a.d - b.d)
|
||||
.map(({ tile }) => tile);
|
||||
|
||||
Reference in new issue
Block a user