perf: Add some code paths to reduce transform calls.
This reduces functions calls for webgl polygons and lines.
MODIFY
CHANGELOG.md
CHANGELOG.md
# GeoJS Change Log
+## Version 1.8.7
+
+### Improvements
+
+- Add some code paths to reduce transform calls ([#1207](../../pull/1207))
+
## Version 1.8.6
### Improvements

MODIFY
src/transform.js
src/transform.js
@@ -767,6 +767,21 @@ transform.vincentyDistance = function (pt1, pt2, gcs, baseGcs, ellipsoid, maxIte
};
};
+/**
+ * Return a boolean indicating if the projections only differ in their y
+ * coordinate.
+ *
+ * @param {string} srcPrj The source projection.
+ * @param {string} tgtPrj The destination projection.
+ * @returns {boolean} truthy if only the y coordinate is different between
+ * projections.
+ */
+transform.onlyInvertedY = function (srcPrj, tgtPrj) {
+ const smatch = srcPrj.match(axisPattern),
+ tmatch = tgtPrj.match(axisPattern);
+ return smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3];
+};
+
/* Expose proj4 to make it easier to debug */
transform.proj4 = proj4;

MODIFY
src/webgl/lineFeature.js
src/webgl/lineFeature.js
@@ -134,6 +134,9 @@ var webgl_lineFeature = function (arg) {
strokeOffset: 0, posStrokeOffset: 0, negStrokeOffset: 0
}],
v = vert[1],
+ target_gcs = m_this.gcs(),
+ map_gcs = m_this.layer().map().gcs(),
+ simpleInverse = transform.onlyInvertedY(target_gcs, map_gcs),
pos, posIdx3, firstpos, firstPosIdx3,
lineFunc = m_this.line(),
strokeWidthFunc = m_this.style.get('strokeWidth'), strokeWidthVal,
@@ -188,7 +191,7 @@ var webgl_lineFeature = function (arg) {
for (j = 0; j < lineItem.length; j += 1) {
pos = posFunc(lineItem[j], j, d, i);
position.push(pos.x);
- position.push(pos.y);
+ position.push(simpleInverse ? -pos.y : pos.y);
position.push(pos.z || 0.0);
if (!j) {
firstpos = pos;
@@ -208,8 +211,9 @@ var webgl_lineFeature = function (arg) {
}
}
- position = transform.transformCoordinates(
- m_this.gcs(), m_this.layer().map().gcs(), position, 3);
+ if (!simpleInverse) {
+ position = transform.transformCoordinates(target_gcs, map_gcs, position, 3);
+ }
m_origin = new Float32Array(m_this.style.get('origin')(position));
if (m_origin[0] || m_origin[1] || m_origin[2]) {
for (i = 0; i < position.length; i += 3) {

MODIFY
src/webgl/polygonFeature.js
src/webgl/polygonFeature.js
@@ -82,6 +82,7 @@ var webgl_polygonFeature = function (arg) {
items = [],
target_gcs = m_this.gcs(),
map_gcs = m_this.layer().map().gcs(),
+ simpleInverse = transform.onlyInvertedY(target_gcs, map_gcs),
numPts = 0,
geom = m_mapper.geometryData(),
color, opacity, fill, d, d3, vertices, i, j, k, n,
@@ -117,7 +118,7 @@ var webgl_polygonFeature = function (arg) {
for (i = d3 = 0; i < outer.length; i += 1, d3 += 3) {
c = posFunc(outer[i], i, item, itemIndex);
geometry[d3] = c.x;
- geometry[d3 + 1] = c.y;
+ geometry[d3 + 1] = simpleInverse ? -c.y : c.y;
// ignore the z values until we support them
geometry[d3 + 2] = 0; // c.z || 0;
}
@@ -134,7 +135,7 @@ var webgl_polygonFeature = function (arg) {
for (i = 0; i < hole.length; i += 1, d3 += 3) {
c = posFunc(hole[i], i, item, itemIndex);
geometry.vertices[d3] = c.x;
- geometry.vertices[d3 + 1] = c.y;
+ geometry.vertices[d3 + 1] = simpleInverse ? -c.y : c.y;
// ignore the z values until we support them
geometry.vertices[d3 + 2] = 0; // c.z || 0;
}
@@ -142,12 +143,14 @@ var webgl_polygonFeature = function (arg) {
}
// transform to map gcs
+ if (!simpleInverse) {
geometry.vertices = transform.transformCoordinates(
target_gcs,
map_gcs,
geometry.vertices,
geometry.dimensions
);
+ }
record = {
// triangulate

perf: Add some code paths to reduce transform calls.

This reduces functions calls for webgl polygons and lines.