Optimize a transform code path.
This is used when drawing lines and polygons in pixel coordinates.
MODIFY
CHANGELOG.md
CHANGELOG.md
### 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)

MODIFY
src/transform.js
src/transform.js
@@ -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});

MODIFY
tests/cases/lineFeature.js
tests/cases/lineFeature.js
@@ -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});

Optimize a transform code path.

This is used when drawing lines and polygons in pixel coordinates.