From 6ad63b113d801ece589b22b9fea37e5751eec153 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 10:20:56 +0100 Subject: [PATCH 1/6] Improve code and apidoc formating --- src/ol/format/polylineformat.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index 69c46a84e6..adf8ea65fc 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -28,8 +28,7 @@ goog.inherits(ol.format.Polyline, ol.format.Text); * @param {number=} opt_dimension The dimension of the coordinates in the array. * @return {string} The encoded string. */ -ol.format.Polyline.encodeFlatCoordinates = - function(flatPoints, opt_dimension) { +ol.format.Polyline.encodeFlatCoordinates = function(flatPoints, opt_dimension) { var dimension = goog.isDef(opt_dimension) ? opt_dimension : 2; return ol.format.Polyline.encodeDeltas(flatPoints, dimension); }; @@ -40,7 +39,7 @@ ol.format.Polyline.encodeFlatCoordinates = * * @param {string} encoded An encoded string. * @param {number=} opt_dimension The dimension of the coordinates in the - * encoded string. + * encoded string. * @return {Array.} A flat array of coordinates. */ ol.format.Polyline.decodeFlatCoordinates = function(encoded, opt_dimension) { @@ -57,7 +56,8 @@ ol.format.Polyline.decodeFlatCoordinates = function(encoded, opt_dimension) { * @param {Array.} numbers A list of n-dimensional points. * @param {number} dimension The dimension of the points in the list. * @param {number=} opt_factor The factor by which the numbers will be - * multiplied. The remaining decimal places will get rounded away. + * multiplied. The remaining decimal places will get rounded away. + * Default is `1e5`. * @return {string} The encoded string. */ ol.format.Polyline.encodeDeltas = function(numbers, dimension, opt_factor) { @@ -90,7 +90,7 @@ ol.format.Polyline.encodeDeltas = function(numbers, dimension, opt_factor) { * @param {string} encoded An encoded string. * @param {number} dimension The dimension of the points in the encoded string. * @param {number=} opt_factor The factor by which the resulting numbers will - * be divided. + * be divided. Default is `1e5`. * @return {Array.} A list of n-dimensional points. */ ol.format.Polyline.decodeDeltas = function(encoded, dimension, opt_factor) { @@ -125,7 +125,8 @@ ol.format.Polyline.decodeDeltas = function(encoded, dimension, opt_factor) { * * @param {Array.} numbers A list of floating point numbers. * @param {number=} opt_factor The factor by which the numbers will be - * multiplied. The remaining decimal places will get rounded away. + * multiplied. The remaining decimal places will get rounded away. + * Default is `1e5`. * @return {string} The encoded string. */ ol.format.Polyline.encodeFloats = function(numbers, opt_factor) { @@ -145,6 +146,7 @@ ol.format.Polyline.encodeFloats = function(numbers, opt_factor) { * * @param {string} encoded An encoded string. * @param {number=} opt_factor The factor by which the result will be divided. + * Default is `1e5`. * @return {Array.} A list of floating point numbers. */ ol.format.Polyline.decodeFloats = function(encoded, opt_factor) { @@ -240,7 +242,7 @@ ol.format.Polyline.decodeUnsignedIntegers = function(encoded) { * * @param {number} num Floating point number that should be encoded. * @param {number=} opt_factor The factor by which num will be multiplied. - * The remaining decimal places will get rounded away. + * The remaining decimal places will get rounded away. * @return {string} The encoded string. */ ol.format.Polyline.encodeFloat = function(num, opt_factor) { From b2b5e60f876312777ad15482f937ec3d8d81fe45 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 11:48:02 +0100 Subject: [PATCH 2/6] Remove unused ol.format.Polyline.decodeFloat function --- src/ol/format/polylineformat.js | 14 ------------ test/spec/ol/format/polylineformat.test.js | 26 +++++++++++----------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index adf8ea65fc..764e523bff 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -252,20 +252,6 @@ ol.format.Polyline.encodeFloat = function(num, opt_factor) { }; -/** - * Decode one single floating point number from an encoded string - * - * @param {string} encoded An encoded string. - * @param {number=} opt_factor The factor by which the result will be divided. - * @return {number} The decoded floating point number. - */ -ol.format.Polyline.decodeFloat = function(encoded, opt_factor) { - var factor = goog.isDef(opt_factor) ? opt_factor : 1e5; - var result = ol.format.Polyline.decodeSignedInteger(encoded); - return result / factor; -}; - - /** * Encode one single signed integer and return an encoded string * diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index ac137aa19f..52215a49b9 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -163,24 +163,24 @@ describe('ol.format.Polyline', function() { describe('decodeFloat', function() { it('returns expected value', function() { - var decodeFloat = ol.format.Polyline.decodeFloat; + var decodeFloats = ol.format.Polyline.decodeFloats; - expect(decodeFloat('?')).to.eql(0.00000); - expect(decodeFloat('@')).to.eql(-0.00001); - expect(decodeFloat('A')).to.eql(0.00001); - expect(decodeFloat('B')).to.eql(-0.00002); - expect(decodeFloat('C')).to.eql(0.00002); - expect(decodeFloat(']')).to.eql(0.00015); - expect(decodeFloat('^')).to.eql(-0.00016); + expect(decodeFloats('?')).to.eql([0.00000]); + expect(decodeFloats('@')).to.eql([-0.00001]); + expect(decodeFloats('A')).to.eql([0.00001]); + expect(decodeFloats('B')).to.eql([-0.00002]); + expect(decodeFloats('C')).to.eql([0.00002]); + expect(decodeFloats(']')).to.eql([0.00015]); + expect(decodeFloats('^')).to.eql([-0.00016]); - expect(decodeFloat('@', 10)).to.eql(-0.1); - expect(decodeFloat('A', 10)).to.eql(0.1); + expect(decodeFloats('@', 10)).to.eql([-0.1]); + expect(decodeFloats('A', 10)).to.eql([0.1]); - expect(decodeFloat('__@')).to.eql(16 * 32 / 1e5); - expect(decodeFloat('___@')).to.eql(16 * 32 * 32 / 1e5); + expect(decodeFloats('__@')).to.eql([16 * 32 / 1e5]); + expect(decodeFloats('___@')).to.eql([16 * 32 * 32 / 1e5]); // from the "Encoded Polyline Algorithm Format" page at Google - expect(decodeFloat('`~oia@')).to.eql(-179.98321); + expect(decodeFloats('`~oia@')).to.eql([-179.98321]); }); }); From 11f718ab22b23906ac6c379c7a85f195b4f759d9 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 11:52:55 +0100 Subject: [PATCH 3/6] Remove unused ol.format.Polyline.decodeSignedInteger function --- src/ol/format/polylineformat.js | 12 ------------ test/spec/ol/format/polylineformat.test.js | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index 764e523bff..c19f4dae72 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -264,18 +264,6 @@ ol.format.Polyline.encodeSignedInteger = function(num) { }; -/** - * Decode one single signed integer from an encoded string - * - * @param {string} encoded An encoded string. - * @return {number} The decoded signed integer. - */ -ol.format.Polyline.decodeSignedInteger = function(encoded) { - var result = ol.format.Polyline.decodeUnsignedInteger(encoded); - return ((result & 1) ? ~(result >> 1) : (result >> 1)); -}; - - /** * Encode one single unsigned integer and return an encoded string * diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index 52215a49b9..c91f570dba 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -206,19 +206,19 @@ describe('ol.format.Polyline', function() { describe('decodeSignedInteger', function() { it('returns expected value', function() { - var decodeSignedInteger = ol.format.Polyline.decodeSignedInteger; + var decodeSignedIntegers = ol.format.Polyline.decodeSignedIntegers; - expect(decodeSignedInteger('?')).to.eql(0); - expect(decodeSignedInteger('@')).to.eql(-1); - expect(decodeSignedInteger('A')).to.eql(1); - expect(decodeSignedInteger('B')).to.eql(-2); - expect(decodeSignedInteger('C')).to.eql(2); - expect(decodeSignedInteger(']')).to.eql(15); - expect(decodeSignedInteger('^')).to.eql(-16); + expect(decodeSignedIntegers('?')).to.eql([0]); + expect(decodeSignedIntegers('@')).to.eql([-1]); + expect(decodeSignedIntegers('A')).to.eql([1]); + expect(decodeSignedIntegers('B')).to.eql([-2]); + expect(decodeSignedIntegers('C')).to.eql([2]); + expect(decodeSignedIntegers(']')).to.eql([15]); + expect(decodeSignedIntegers('^')).to.eql([-16]); - expect(decodeSignedInteger('_@')).to.eql(16); - expect(decodeSignedInteger('__@')).to.eql(16 * 32); - expect(decodeSignedInteger('___@')).to.eql(16 * 32 * 32); + expect(decodeSignedIntegers('_@')).to.eql([16]); + expect(decodeSignedIntegers('__@')).to.eql([16 * 32]); + expect(decodeSignedIntegers('___@')).to.eql([16 * 32 * 32]); }); }); From 040b954e156cf2ed363f4c4261505556872fb697 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 11:58:11 +0100 Subject: [PATCH 4/6] Remove unused ol.format.Polyline.encodeFloat function --- src/ol/format/polylineformat.js | 15 ------------- test/spec/ol/format/polylineformat.test.js | 26 +++++++++++----------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index c19f4dae72..a30d20eaea 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -237,21 +237,6 @@ ol.format.Polyline.decodeUnsignedIntegers = function(encoded) { }; -/** - * Encode one single floating point number and return an encoded string - * - * @param {number} num Floating point number that should be encoded. - * @param {number=} opt_factor The factor by which num will be multiplied. - * The remaining decimal places will get rounded away. - * @return {string} The encoded string. - */ -ol.format.Polyline.encodeFloat = function(num, opt_factor) { - var factor = goog.isDef(opt_factor) ? opt_factor : 1e5; - num = Math.round(num * factor); - return ol.format.Polyline.encodeSignedInteger(num); -}; - - /** * Encode one single signed integer and return an encoded string * diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index c91f570dba..d8689d30b5 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -140,24 +140,24 @@ describe('ol.format.Polyline', function() { describe('encodeFloat', function() { it('returns expected value', function() { - var encodeFloat = ol.format.Polyline.encodeFloat; + var encodeFloats = ol.format.Polyline.encodeFloats; - expect(encodeFloat(0.00000)).to.eql('?'); - expect(encodeFloat(-0.00001)).to.eql('@'); - expect(encodeFloat(0.00001)).to.eql('A'); - expect(encodeFloat(-0.00002)).to.eql('B'); - expect(encodeFloat(0.00002)).to.eql('C'); - expect(encodeFloat(0.00015)).to.eql(']'); - expect(encodeFloat(-0.00016)).to.eql('^'); + expect(encodeFloats([0.00000])).to.eql('?'); + expect(encodeFloats([-0.00001])).to.eql('@'); + expect(encodeFloats([0.00001])).to.eql('A'); + expect(encodeFloats([-0.00002])).to.eql('B'); + expect(encodeFloats([0.00002])).to.eql('C'); + expect(encodeFloats([0.00015])).to.eql(']'); + expect(encodeFloats([-0.00016])).to.eql('^'); - expect(encodeFloat(-0.1, 10)).to.eql('@'); - expect(encodeFloat(0.1, 10)).to.eql('A'); + expect(encodeFloats([-0.1], 10)).to.eql('@'); + expect(encodeFloats([0.1], 10)).to.eql('A'); - expect(encodeFloat(16 * 32 / 1e5)).to.eql('__@'); - expect(encodeFloat(16 * 32 * 32 / 1e5)).to.eql('___@'); + expect(encodeFloats([16 * 32 / 1e5])).to.eql('__@'); + expect(encodeFloats([16 * 32 * 32 / 1e5])).to.eql('___@'); // from the "Encoded Polyline Algorithm Format" page at Google - expect(encodeFloat(-179.9832104)).to.eql('`~oia@'); + expect(encodeFloats([-179.9832104])).to.eql('`~oia@'); }); }); From c31f70bf084a1e4124f13c2b0854c043705583c6 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 12:01:14 +0100 Subject: [PATCH 5/6] Remove unused ol.format.Polyline.encodeSignedInteger function --- src/ol/format/polylineformat.js | 12 ------------ test/spec/ol/format/polylineformat.test.js | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index a30d20eaea..34720b105f 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -237,18 +237,6 @@ ol.format.Polyline.decodeUnsignedIntegers = function(encoded) { }; -/** - * Encode one single signed integer and return an encoded string - * - * @param {number} num Signed integer that should be encoded. - * @return {string} The encoded string. - */ -ol.format.Polyline.encodeSignedInteger = function(num) { - var signedNum = (num < 0) ? ~(num << 1) : (num << 1); - return ol.format.Polyline.encodeUnsignedInteger(signedNum); -}; - - /** * Encode one single unsigned integer and return an encoded string * diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index d8689d30b5..6394adf04f 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -188,19 +188,19 @@ describe('ol.format.Polyline', function() { describe('encodeSignedInteger', function() { it('returns expected value', function() { - var encodeSignedInteger = ol.format.Polyline.encodeSignedInteger; + var encodeSignedIntegers = ol.format.Polyline.encodeSignedIntegers; - expect(encodeSignedInteger(0)).to.eql('?'); - expect(encodeSignedInteger(-1)).to.eql('@'); - expect(encodeSignedInteger(1)).to.eql('A'); - expect(encodeSignedInteger(-2)).to.eql('B'); - expect(encodeSignedInteger(2)).to.eql('C'); - expect(encodeSignedInteger(15)).to.eql(']'); - expect(encodeSignedInteger(-16)).to.eql('^'); + expect(encodeSignedIntegers([0])).to.eql('?'); + expect(encodeSignedIntegers([-1])).to.eql('@'); + expect(encodeSignedIntegers([1])).to.eql('A'); + expect(encodeSignedIntegers([-2])).to.eql('B'); + expect(encodeSignedIntegers([2])).to.eql('C'); + expect(encodeSignedIntegers([15])).to.eql(']'); + expect(encodeSignedIntegers([-16])).to.eql('^'); - expect(encodeSignedInteger(16)).to.eql('_@'); - expect(encodeSignedInteger(16 * 32)).to.eql('__@'); - expect(encodeSignedInteger(16 * 32 * 32)).to.eql('___@'); + expect(encodeSignedIntegers([16])).to.eql('_@'); + expect(encodeSignedIntegers([16 * 32])).to.eql('__@'); + expect(encodeSignedIntegers([16 * 32 * 32])).to.eql('___@'); }); }); From 7f8d4937f578c17176ac64871b6e00ef2741dd12 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Feb 2014 12:06:28 +0100 Subject: [PATCH 6/6] Remove unused ol.format.Polyline.decodeUnsignedInteger function --- src/ol/format/polylineformat.js | 22 ---------------------- test/spec/ol/format/polylineformat.test.js | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/ol/format/polylineformat.js b/src/ol/format/polylineformat.js index 34720b105f..cceee15d53 100644 --- a/src/ol/format/polylineformat.js +++ b/src/ol/format/polylineformat.js @@ -256,28 +256,6 @@ ol.format.Polyline.encodeUnsignedInteger = function(num) { }; -/** - * Decode one single unsigned integer from an encoded string - * - * @param {string} encoded An encoded string. - * @return {number} The decoded unsigned integer. - */ -ol.format.Polyline.decodeUnsignedInteger = function(encoded) { - var result = 0; - var shift = 0; - var i, ii; - for (i = 0, ii = encoded.length; i < ii; ++i) { - var b = encoded.charCodeAt(i) - 63; - result |= (b & 0x1f) << shift; - if (b < 0x20) { - break; - } - shift += 5; - } - return result; -}; - - /** * @inheritDoc */ diff --git a/test/spec/ol/format/polylineformat.test.js b/test/spec/ol/format/polylineformat.test.js index 6394adf04f..8190eae7e0 100644 --- a/test/spec/ol/format/polylineformat.test.js +++ b/test/spec/ol/format/polylineformat.test.js @@ -246,21 +246,21 @@ describe('ol.format.Polyline', function() { describe('decodeUnsignedInteger', function() { it('returns expected value', function() { - var decodeUnsignedInteger = ol.format.Polyline.decodeUnsignedInteger; + var decodeUnsignedIntegers = ol.format.Polyline.decodeUnsignedIntegers; - expect(decodeUnsignedInteger('?')).to.eql(0); - expect(decodeUnsignedInteger('@')).to.eql(1); - expect(decodeUnsignedInteger('A')).to.eql(2); - expect(decodeUnsignedInteger(']')).to.eql(30); - expect(decodeUnsignedInteger('^')).to.eql(31); - expect(decodeUnsignedInteger('_@')).to.eql(32); + expect(decodeUnsignedIntegers('?')).to.eql([0]); + expect(decodeUnsignedIntegers('@')).to.eql([1]); + expect(decodeUnsignedIntegers('A')).to.eql([2]); + expect(decodeUnsignedIntegers(']')).to.eql([30]); + expect(decodeUnsignedIntegers('^')).to.eql([31]); + expect(decodeUnsignedIntegers('_@')).to.eql([32]); - expect(decodeUnsignedInteger('__@')).to.eql(32 * 32); - expect(decodeUnsignedInteger('__D')).to.eql(5 * 32 * 32); - expect(decodeUnsignedInteger('___@')).to.eql(32 * 32 * 32); + expect(decodeUnsignedIntegers('__@')).to.eql([32 * 32]); + expect(decodeUnsignedIntegers('__D')).to.eql([5 * 32 * 32]); + expect(decodeUnsignedIntegers('___@')).to.eql([32 * 32 * 32]); // from the "Encoded Polyline Algorithm Format" page at Google - expect(decodeUnsignedInteger('mD')).to.eql(174); + expect(decodeUnsignedIntegers('mD')).to.eql([174]); }); });