Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extent warning and clamp exceeding coords #8479

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/data/load_geometry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import { warnOnce } from '../util/util';
import { warnOnce, clamp } from '../util/util';

import EXTENT from './extent';

Expand All @@ -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
Expand All @@ -39,6 +39,8 @@ export default function loadGeometry(feature: VectorTileFeature): Array<Array<Po

if (point.x < bounds.min || point.x > 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will clamping here change the current behavior (especially with respect to geometries split across tile boundaries? Or is it always broken when points are beyond the bounds?

Copy link
Member Author

@mourner mourner Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's broken. It's just that the bounds were increased 2x when we switched to bigger line layout, and got back when we reverted that. The clamping at minimum doesn't make things worse, but also often makes things better.

point.y = clamp(point.y, bounds.min, bounds.max);
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions test/unit/data/load_geometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down