Loading lib/Point.js +19 −16 Original line number Diff line number Diff line Loading @@ -4,16 +4,19 @@ function Point(x, y, z) { if (!(this instanceof Point)) { return new Point(x, y, z); } if (typeof x === 'object') { if (Array.isArray(x)) { this.x = x[0]; this.y = x[1]; this.z = x[2] || 0.0; } else if (typeof x === 'string' && typeof y === 'undefined') { }else if(typeof x === 'object'){ this.x = x.x; this.y = x.y; this.z = x.z || 0.0; } else if (typeof x === 'string' && typeof y === 'undefined') { var coords = x.split(','); this.x = parseFloat(coords[0]); this.y = parseFloat(coords[1]); this.z = parseFloat(coords[2]) || 0.0; this.x = parseFloat(coords[0], 10); this.y = parseFloat(coords[1], 10); this.z = parseFloat(coords[2], 10) || 0.0; } else { this.x = x; Loading @@ -31,18 +34,18 @@ function Point(x, y, z) { } }; this.toString = function() { return ("x=" + this.x + ",y=" + this.y); if(this.z){ return "x=" + this.x + ",y=" + this.y + ",z="+this.z; }else{ return "x=" + this.x + ",y=" + this.y; } }; /** * APIMethod: toShortString * Return a short string version of the point. * * Return: * {String} Shortened String representation of ..Point object. * (ex. <i>"5, 42"</i>) */ this.toShortString = function() { return (this.x + ", " + this.y); if(this.z){ return this.x + "," + this.y+ "," + this.z; }else{ return this.x + "," + this.y; } }; } Loading package.json +1 −1 Original line number Diff line number Diff line { "name": "proj4", "version": "1.5.0-dev.3", "version": "1.5.0-dev.4", "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.", "main": "lib/index.js", "directories": { Loading test/test.js +299 −216 Original line number Diff line number Diff line // You can do this in the grunt config for each mocha task, see the `options` config Loading Loading @@ -43,7 +39,8 @@ describe('proj4', function () { describe('core', function() { testPoints.forEach(function(testPoint) { describe(testPoint.code, function() { var xyAcc=2,llAcc=6; var xyAcc = 2, llAcc = 6; if ('acc' in testPoint) { if ('xy' in testPoint.acc) { xyAcc = testPoint.acc.xy; Loading Loading @@ -75,7 +72,10 @@ describe('proj4', function () { assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.ll[0],y:testPoint.ll[1]}; var pt = { x: testPoint.ll[0], y: testPoint.ll[1] }; var xy = proj4(testPoint.code, pt); assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close'); assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close'); Loading @@ -94,7 +94,10 @@ describe('proj4', function () { assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.ll[0],y:testPoint.ll[1]}; var pt = { x: testPoint.ll[0], y: testPoint.ll[1] }; var xy = proj4(proj4.WGS84, testPoint.code, pt); assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close'); assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close'); Loading @@ -113,7 +116,10 @@ describe('proj4', function () { assert.closeTo(ll[1], testPoint.ll[1], llEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.xy[0],y:testPoint.xy[1]}; var pt = { x: testPoint.xy[0], y: testPoint.xy[1] }; var ll = proj4(testPoint.code, proj4.WGS84, pt); assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close'); assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'y is close'); Loading Loading @@ -205,12 +211,89 @@ describe('proj4', function () { assert.equal(point.toMGRS(3), "25XEN041865", "MGRS reference with 3-digit accuracy correct."); }); }) describe('points', function() { describe('from params', function() { it('should work with 2 params', function() { var point = proj4.Point(1, 2); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toShortString(), "1,2"); assert.equal(point.toString(), "x=1,y=2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point(1, 2, 3); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from an obj', function() { it('should work with 2 params', function() { var point = proj4.Point({x:1, y:2}); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point({x:1, y:2, z:3}); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from an array', function() { it('should work with 2 params', function() { var point = proj4.Point([1,2]); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point([1,2,3]); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from a string', function() { it('should work with 2 params', function() { var point = proj4.Point('1,2'); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point('1,2,3'); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.equal(point.toShortString(), "1,2,3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); }); }); }); window.run(); }; Loading
lib/Point.js +19 −16 Original line number Diff line number Diff line Loading @@ -4,16 +4,19 @@ function Point(x, y, z) { if (!(this instanceof Point)) { return new Point(x, y, z); } if (typeof x === 'object') { if (Array.isArray(x)) { this.x = x[0]; this.y = x[1]; this.z = x[2] || 0.0; } else if (typeof x === 'string' && typeof y === 'undefined') { }else if(typeof x === 'object'){ this.x = x.x; this.y = x.y; this.z = x.z || 0.0; } else if (typeof x === 'string' && typeof y === 'undefined') { var coords = x.split(','); this.x = parseFloat(coords[0]); this.y = parseFloat(coords[1]); this.z = parseFloat(coords[2]) || 0.0; this.x = parseFloat(coords[0], 10); this.y = parseFloat(coords[1], 10); this.z = parseFloat(coords[2], 10) || 0.0; } else { this.x = x; Loading @@ -31,18 +34,18 @@ function Point(x, y, z) { } }; this.toString = function() { return ("x=" + this.x + ",y=" + this.y); if(this.z){ return "x=" + this.x + ",y=" + this.y + ",z="+this.z; }else{ return "x=" + this.x + ",y=" + this.y; } }; /** * APIMethod: toShortString * Return a short string version of the point. * * Return: * {String} Shortened String representation of ..Point object. * (ex. <i>"5, 42"</i>) */ this.toShortString = function() { return (this.x + ", " + this.y); if(this.z){ return this.x + "," + this.y+ "," + this.z; }else{ return this.x + "," + this.y; } }; } Loading
package.json +1 −1 Original line number Diff line number Diff line { "name": "proj4", "version": "1.5.0-dev.3", "version": "1.5.0-dev.4", "description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.", "main": "lib/index.js", "directories": { Loading
test/test.js +299 −216 Original line number Diff line number Diff line // You can do this in the grunt config for each mocha task, see the `options` config Loading Loading @@ -43,7 +39,8 @@ describe('proj4', function () { describe('core', function() { testPoints.forEach(function(testPoint) { describe(testPoint.code, function() { var xyAcc=2,llAcc=6; var xyAcc = 2, llAcc = 6; if ('acc' in testPoint) { if ('xy' in testPoint.acc) { xyAcc = testPoint.acc.xy; Loading Loading @@ -75,7 +72,10 @@ describe('proj4', function () { assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.ll[0],y:testPoint.ll[1]}; var pt = { x: testPoint.ll[0], y: testPoint.ll[1] }; var xy = proj4(testPoint.code, pt); assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close'); assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close'); Loading @@ -94,7 +94,10 @@ describe('proj4', function () { assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.ll[0],y:testPoint.ll[1]}; var pt = { x: testPoint.ll[0], y: testPoint.ll[1] }; var xy = proj4(proj4.WGS84, testPoint.code, pt); assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close'); assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close'); Loading @@ -113,7 +116,10 @@ describe('proj4', function () { assert.closeTo(ll[1], testPoint.ll[1], llEPSLN, 'y is close'); }); it('shortcut method should work with an object', function() { var pt = {x:testPoint.xy[0],y:testPoint.xy[1]}; var pt = { x: testPoint.xy[0], y: testPoint.xy[1] }; var ll = proj4(testPoint.code, proj4.WGS84, pt); assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close'); assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'y is close'); Loading Loading @@ -205,12 +211,89 @@ describe('proj4', function () { assert.equal(point.toMGRS(3), "25XEN041865", "MGRS reference with 3-digit accuracy correct."); }); }) describe('points', function() { describe('from params', function() { it('should work with 2 params', function() { var point = proj4.Point(1, 2); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toShortString(), "1,2"); assert.equal(point.toString(), "x=1,y=2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point(1, 2, 3); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from an obj', function() { it('should work with 2 params', function() { var point = proj4.Point({x:1, y:2}); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point({x:1, y:2, z:3}); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from an array', function() { it('should work with 2 params', function() { var point = proj4.Point([1,2]); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point([1,2,3]); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toShortString(), "1,2,3"); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); describe('from a string', function() { it('should work with 2 params', function() { var point = proj4.Point('1,2'); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 0); assert.equal(point.toString(), "x=1,y=2"); assert.equal(point.toShortString(), "1,2"); assert.deepEqual(point.toArray(), [1, 2]); }); it('should work with 3 params', function() { var point = proj4.Point('1,2,3'); assert.equal(point.x, 1); assert.equal(point.y, 2); assert.equal(point.z, 3); assert.equal(point.toString(), "x=1,y=2,z=3"); assert.equal(point.toShortString(), "1,2,3"); assert.deepEqual(point.toArray(), [1, 2, 3]); }); }); }); }); }); window.run(); };