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

Optimize a transform code path. #1023

Merged
merged 1 commit into from
Sep 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Improvements
- Points with small radii or thin strokes are rendered better (#1021)
- When only updating point styles, don't recompute geometry transforms (#1022)
- Optimized a transform code path for pixel coordinates (#1023)

### Changes
- Switched the default tile server to Stamen Design's toner-lite. (#1020)
Expand Down
13 changes: 12 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,24 @@ transform.lookup = function (projection) {
transform.transformCoordinates = function (srcPrj, tgtPrj, coordinates, numberOfComponents) {
'use strict';

if (srcPrj === tgtPrj) {
if (srcPrj === tgtPrj || (Array.isArray(coordinates) && !coordinates.length)) {
return coordinates;
}

if (Array.isArray(coordinates) && coordinates.length >= 3 && numberOfComponents === 3 && !util.isObject(coordinates[0])) {
return transform.transformCoordinatesFlatArray3(srcPrj, tgtPrj, coordinates);
}
if (Array.isArray(coordinates) && coordinates.length && util.isObject(coordinates[0]) && 'x' in coordinates[0] && 'y' in coordinates[0]) {
var smatch = srcPrj.match(axisPattern),
tmatch = tgtPrj.match(axisPattern);
// if the two projections only differ in the middle axis
if (smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3]) {
if ('z' in coordinates[0]) {
return coordinates.map(p => ({x: +p.x, y: -p.y, z: +p.z || 0}));
}
return coordinates.map(p => ({x: +p.x, y: -p.y}));
}
}
var trans = transform({source: srcPrj, target: tgtPrj}), output;
if (util.isObject(coordinates) && 'x' in coordinates && 'y' in coordinates) {
output = trans.forward({x: +coordinates.x, y: +coordinates.y, z: +coordinates.z || 0});
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ describe('geo.lineFeature', function () {
line.rdpSimplifyData(testLines, 2, undefined, lineFunc);
counts = countLines(line.data().map(line.style.get('line')));
expect(counts).toEqual({lines: 8, vertices: 17});
line.rdpSimplifyData(testLines, 5, undefined, lineFunc);
line.rdpSimplifyData(testLines, 5.01, undefined, lineFunc);
counts = countLines(line.data().map(line.style.get('line')));
expect(counts).toEqual({lines: 8, vertices: 11});
expect(counts).toEqual({lines: 8, vertices: 9});
line.rdpSimplifyData(testLines, 20, undefined, lineFunc);
counts = countLines(line.data().map(line.style.get('line')));
expect(counts).toEqual({lines: 8, vertices: 0});
Expand Down