Skip to content

Commit

Permalink
build: Update proj4 library.
Browse files Browse the repository at this point in the history
This is part of #1132.
  • Loading branch information
manthey committed Dec 22, 2021
1 parent a39b280 commit 9ba31e7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
32 changes: 25 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jquery": "^3.6.0",
"kdbush": "^3.0.0",
"mousetrap": "^1.6.5",
"proj4": "2.6.0",
"proj4": "^2.7.5",
"vgl": "0.3.11"
},
"optionalDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions src/trackFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,21 @@ var trackFeature = function (arg) {
if (d.posidx1 === undefined) {
pos = m_tracks.positionFunc(tracks[i][d.posidx], d.posidx, tracks[i], i);
} else {
pos0 = trans.forward(m_tracks.positionFunc(tracks[i][d.posidx0], d.posidx0, tracks[i], i));
pos1 = trans.forward(m_tracks.positionFunc(tracks[i][d.posidx1], d.posidx1, tracks[i], i));
pos0 = trans.forward(m_tracks.positionFunc(tracks[i][d.posidx0], d.posidx0, tracks[i], i), true);
pos1 = trans.forward(m_tracks.positionFunc(tracks[i][d.posidx1], d.posidx1, tracks[i], i), true);
pos = trans.inverse({
x: pos0.x * d.factor0 + pos1.x * d.factor1,
y: pos0.y * d.factor0 + pos1.y * d.factor1,
z: (pos0.z || 0) * d.factor0 + (pos1.z || 0) * d.factor1
});
}, true);
}
d.x = pos.x;
d.y = pos.y;
d.z = pos.z || 0;
if (calcAngle) {
if (d.posidx1 === undefined) {
pos0 = trans.forward(d.angidx0 === d.posidx ? pos : m_tracks.positionFunc(tracks[i][d.angidx0], d.angidx0, tracks[i], i));
pos1 = trans.forward(d.angidx1 === d.posidx ? pos : m_tracks.positionFunc(tracks[i][d.angidx1], d.angidx1, tracks[i], i));
pos0 = trans.forward(d.angidx0 === d.posidx ? pos : m_tracks.positionFunc(tracks[i][d.angidx0], d.angidx0, tracks[i], i), true);
pos1 = trans.forward(d.angidx1 === d.posidx ? pos : m_tracks.positionFunc(tracks[i][d.angidx1], d.angidx1, tracks[i], i), true);
}
d.angle = Math.atan2(pos1.y - pos0.y, pos1.x - pos0.x);
}
Expand Down
13 changes: 7 additions & 6 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ var transform = function (options) {
var mp = vec3.transformMat4(util.vec3AsArray(), [point.x, point.y, point.z || 0], m_source_matrix_inv);
point = {x: mp[0], y: mp[1], z: mp[2]};
}
var pt = m_proj.forward(point);
var pt = m_proj.forward(point, true);
pt.z = point.z || 0;
if (m_target_matrix) {
var ip = vec3.transformMat4(util.vec3AsArray(), [pt.x, pt.y, pt.z], m_target_matrix);
Expand All @@ -214,7 +214,7 @@ var transform = function (options) {
var mp = vec3.transformMat4(util.vec3AsArray(), [point.x, point.y, point.z || 0], m_target_matrix_inv);
point = {x: mp[0], y: mp[1], z: mp[2]};
}
var pt = m_proj.inverse(point);
var pt = m_proj.inverse(point, true);
pt.z = point.z || 0;
if (m_source_matrix) {
var ip = vec3.transformMat4(util.vec3AsArray(), [pt.x, pt.y, pt.z], m_source_matrix);
Expand Down Expand Up @@ -359,7 +359,7 @@ transform.transformCoordinates = function (srcPrj, tgtPrj, coordinates, numberOf
}
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});
output = trans.forward({x: +coordinates.x, y: +coordinates.y, z: +coordinates.z || 0}, true);
if ('z' in coordinates) {
return output;
}
Expand All @@ -368,7 +368,7 @@ transform.transformCoordinates = function (srcPrj, tgtPrj, coordinates, numberOf
if (Array.isArray(coordinates) && coordinates.length === 1 &&
util.isObject(coordinates[0]) && 'x' in coordinates[0] &&
'y' in coordinates[0]) {
output = trans.forward({x: +coordinates[0].x, y: +coordinates[0].y, z: +coordinates[0].z || 0});
output = trans.forward({x: +coordinates[0].x, y: +coordinates[0].y, z: +coordinates[0].z || 0}, true);
if ('z' in coordinates[0]) {
return [output];
}
Expand Down Expand Up @@ -549,7 +549,7 @@ transform.transformCoordinatesArray = function (trans, coordinates, numberOfComp
initPoint.x = xAcc(i);
initPoint.y = yAcc(i);
initPoint.z = zAcc(i);
projPoint = trans.forward(initPoint);
projPoint = trans.forward(initPoint, true);
writer(i, projPoint.x, projPoint.y, projPoint.z);
}
return output;
Expand Down Expand Up @@ -582,11 +582,12 @@ transform.transformCoordinatesFlatArray3 = function (srcPrj, tgtPrj, coordinates
var src = proj4.Proj(srcPrj),
tgt = proj4.Proj(tgtPrj),
projPoint, initPoint = {};
let trans = new proj4(src, tgt);
for (i = coordinates.length - 3; i >= 0; i -= 3) {
initPoint.x = +coordinates[i];
initPoint.y = +coordinates[i + 1];
initPoint.z = +(coordinates[i + 2] || 0.0);
projPoint = proj4.transform(src, tgt, initPoint);
projPoint = trans.forward(initPoint, true);
coordinates[i] = projPoint.x;
coordinates[i + 1] = projPoint.y;
coordinates[i + 2] = projPoint.z === undefined ? initPoint.z : projPoint.z;
Expand Down
18 changes: 9 additions & 9 deletions tests/cases/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ describe('geo.transform', function () {
function test_point(pt) {
var pt1 = $.extend({}, pt[0]), pt2 = $.extend({}, pt[1]);
it(str(pt[0]) + ' -> ' + str(pt[1]), function () {
expect(r2(proj.forward(pt1), pt[1])).toBeLessThan(tgt_unit);
expect(r2(proj.forward(pt1), pt[1], true)).toBeLessThan(tgt_unit);
});
it(str(pt[0]) + ' <- ' + str(pt[1]), function () {
expect(r2(pt[0], proj.inverse(pt2))).toBeLessThan(src_unit);
expect(r2(pt[0], proj.inverse(pt2, true))).toBeLessThan(src_unit);
});
}

pts.forEach(test_point);
it('Array of points ( forward )', function () {
var a = pts.map(function (d) { return $.extend({}, d[0]); }),
c = proj.forward(a);
c = proj.forward(a, true);
pts.forEach(function (d, i) {
expect(r2(d[1], c[i])).toBeLessThan(tgt_unit);
});
});
it('Array of points ( inverse )', function () {
var a = pts.map(function (d) { return $.extend({}, d[1]); }),
c = proj.inverse(a);
c = proj.inverse(a, true);
pts.forEach(function (d, i) {
expect(r2(d[0], c[i])).toBeLessThan(src_unit);
});
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('geo.transform', function () {
expect(geo.transform.defs.hasOwnProperty('my projection')).toBe(true);
var p = geo.transform({source: 'EPSG:4326', target: 'my projection'});

expect(p.forward({x: 10, y: -10, z: 0})).toEqual({x: 10, y: -10, z: 0});
expect(p.forward({x: 10, y: -10, z: 0}, true)).toEqual({x: 10, y: -10, z: 0});
});

it('lookup', function (done) {
Expand Down Expand Up @@ -439,13 +439,13 @@ describe('geo.transform', function () {
});
it('transform object forward', function () {
var proj = geo.transform({source: source, target: target});
expect(closeToEqual(proj.forward({x: 1, y: 2}), {x: -1052.974, y: -1158.014, z: 0})).toBe(true);
expect(closeToEqual(proj.inverse({x: -1052.974, y: -1158.014}), {x: 1, y: 2, z: 0})).toBe(true);
expect(closeToEqual(proj.forward({x: 1, y: 2}, true), {x: -1052.974, y: -1158.014, z: 0})).toBe(true);
expect(closeToEqual(proj.inverse({x: -1052.974, y: -1158.014}, true), {x: 1, y: 2, z: 0})).toBe(true);
});
it('transform object inverse', function () {
var proj = geo.transform({source: target, target: source});
expect(closeToEqual(proj.inverse({x: 1, y: 2}), {x: -1052.974, y: -1158.014, z: 0})).toBe(true);
expect(closeToEqual(proj.forward({x: -1052.974, y: -1158.014}), {x: 1, y: 2, z: 0})).toBe(true);
expect(closeToEqual(proj.inverse({x: 1, y: 2}, true), {x: -1052.974, y: -1158.014, z: 0})).toBe(true);
expect(closeToEqual(proj.forward({x: -1052.974, y: -1158.014}, true), {x: 1, y: 2, z: 0})).toBe(true);
});
});
});

0 comments on commit 9ba31e7

Please sign in to comment.