Skip to content

Commit

Permalink
Merge pull request #1023 from OpenGeoscience/transform-optimization
Browse files Browse the repository at this point in the history
Optimize a transform code path.
  • Loading branch information
manthey authored Sep 26, 2019
2 parents 9a3f7f8 + aabd307 commit 7fd780d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 7fd780d

Please sign in to comment.