From 2ab87bfa9b256815917915b06f05b4dd2c232246 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 15 Jul 2019 16:38:18 +0300 Subject: [PATCH] fix extent warning and clamp exceeding coords --- src/data/load_geometry.js | 6 ++++-- test/unit/data/load_geometry.test.js | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/data/load_geometry.js b/src/data/load_geometry.js index 69e8b7f6db8..4116e6ee5fb 100644 --- a/src/data/load_geometry.js +++ b/src/data/load_geometry.js @@ -1,6 +1,6 @@ // @flow -import { warnOnce } from '../util/util'; +import { warnOnce, clamp } from '../util/util'; import EXTENT from './extent'; @@ -17,7 +17,7 @@ function createBounds(bits) { }; } -const bounds = createBounds(16); +const bounds = createBounds(15); /** * Loads a geometry from a VectorTileFeature and scales it to the common extent @@ -39,6 +39,8 @@ export default function loadGeometry(feature: VectorTileFeature): Array bounds.max || point.y < bounds.min || point.y > bounds.max) { warnOnce('Geometry exceeds allowed extent, reduce your vector tile buffer size'); + point.x = clamp(point.x, bounds.min, bounds.max); + point.y = clamp(point.y, bounds.min, bounds.max); } } } diff --git a/test/unit/data/load_geometry.test.js b/test/unit/data/load_geometry.test.js index f24f9e00a0a..4adb556eda7 100644 --- a/test/unit/data/load_geometry.test.js +++ b/test/unit/data/load_geometry.test.js @@ -17,9 +17,9 @@ test('loadGeometry', (t) => { t.end(); }); -test('loadGeometry extent error', (t) => { +test('loadGeometry warns and clamps when exceeding extent', (t) => { const feature = vt.layers.road.feature(0); - feature.extent = 1024; + feature.extent = 2048; let numWarnings = 0; @@ -31,10 +31,18 @@ test('loadGeometry extent error', (t) => { } }; - loadGeometry(feature); + const lines = loadGeometry(feature); t.equal(numWarnings, 1); + let maxValue = -Infinity; + for (const line of lines) { + for (const {x, y} of line) { + maxValue = Math.max(x, y, maxValue); + } + } + t.equal(maxValue, 16383); + // Put it back console.warn = warn;