Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/66072
Change subject: [coordinate.js] Refactored precision handling
......................................................................
[coordinate.js] Refactored precision handling
Moved the precision levels into the settings object and removed functions
altering
the precision from the Coordinate prototype since a Coordinate object is meant
to
be immutable.
Change-Id: I39753f037a0e6a2eca4264da68f041155ebdf6e1
---
M DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
M DataValues/resources/coordinate.js/src/coordinate.js
M DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
M DataValues/resources/coordinate.js/tests/coordinate.tests.js
4 files changed, 30 insertions(+), 115 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/72/66072/1
diff --git a/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
b/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
index dd532ba..f12b452 100644
--- a/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
+++ b/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
@@ -143,33 +143,6 @@
getPrecision: function() { return this._precision; },
/**
- * Sets the precision.
- *
- * TODO: Make this an immutable object, deprecate this function.
- *
- * @param {number} precision
- */
- setPrecision: function( precision ) { this._precision =
precision; },
-
- /**
- * Increases the precision by one step.
- *
- * TODO: Make this an immutable object, deprecate this function.
- */
- increasePrecision: function() {
- this._precision = coordinate.increasePrecision(
this._precision );
- },
-
- /**
- * Decreases the precision by one step.
- *
- * TODO: Make this an immutable object, deprecate this function.
- */
- decreasePrecision: function() {
- this._precision = coordinate.decreasePrecision(
this._precision );
- },
-
- /**
* Returns the precision text.
*
* @return {string}
diff --git a/DataValues/resources/coordinate.js/src/coordinate.js
b/DataValues/resources/coordinate.js/src/coordinate.js
index b2f30dc..3937104 100644
--- a/DataValues/resources/coordinate.js/src/coordinate.js
+++ b/DataValues/resources/coordinate.js/src/coordinate.js
@@ -30,30 +30,27 @@
degree: '°',
minute: '\'',
second: '"',
- precisionTexts: [
- { precision: 1, text: 'to a degree' },
- { precision: 1 / 60, text: 'to an arcminute' },
- { precision: 1 / 3600, text: 'to an arcsecond'
},
- { precision: 1 / 36000, text: 'to a tenth of an
arcsecond' },
- { precision: 1 / 360000, text: 'to the
hundredth of an arcsecond' },
- { precision: 1 / 3600000, text: 'to the
thousandth of an arcsecond' }
- ]
+ precision: {
+ levels: [
+ 10,
+ 1,
+ 0.1, 1/60,
+ 0.01, 1/3600,
+ 0.001, 1/36000,
+ 0.0001, 1/360000,
+ 0.00001, 1/3600000,
+ 0.000001
+ ],
+ texts: [
+ { precision: 1, text: 'to a degree' },
+ { precision: 1 / 60, text: 'to an
arcminute' },
+ { precision: 1 / 3600, text: 'to an
arcsecond' },
+ { precision: 1 / 36000, text: 'to a
tenth of an arcsecond' },
+ { precision: 1 / 360000, text: 'to the
hundredth of an arcsecond' },
+ { precision: 1 / 3600000, text: 'to the
thousandth of an arcsecond' }
+ ]
+ }
},
-
- /**
- * Default precision levels.
- * @type {number[]}
- */
- precisionLevels: [
- 10,
- 1,
- 0.1, 1/60,
- 0.01, 1/3600,
- 0.001, 1/36000,
- 0.0001, 1/360000,
- 0.00001, 1/3600000,
- 0.000001
- ],
/**
* Returns the given precision increased by one step.
@@ -62,14 +59,14 @@
* @return {number}
*/
increasePrecision: function( precision ) {
- var index = this.precisionLevels.indexOf( precision );
+ var index = this.settings.precision.levels.indexOf(
precision );
- if( index === this.precisionLevels.length - 1 || index
=== -1 ) {
+ if( index === this.settings.precision.levels.length - 1
|| index === -1 ) {
var newPrecision = precision / 10;
return ( newPrecision < 1e-9 ) ? 1e-9 :
newPrecision;
}
- return this.precisionLevels[index + 1];
+ return this.settings.precision.levels[index + 1];
},
/**
@@ -83,7 +80,7 @@
return 1e-9;
}
- var index = this.precisionLevels.indexOf( precision );
+ var index = this.settings.precision.levels.indexOf(
precision );
if( index === 0 ) {
return 180;
@@ -91,7 +88,7 @@
return Math.min( precision * 10, 180 );
}
- return this.precisionLevels[index-1];
+ return this.settings.precision.levels[index-1];
},
/**
@@ -105,12 +102,12 @@
// Figure out if the precision is very close to a
precision that can be expressed with a
// string:
- for( var i in this.settings.precisionTexts ) {
+ for( var i in this.settings.precision.texts ) {
if(
-
this.settings.precisionTexts.hasOwnProperty( i )
- && Math.abs( precision -
this.settings.precisionTexts[i].precision ) < 0.0000001
+
this.settings.precision.texts.hasOwnProperty( i )
+ && Math.abs( precision -
this.settings.precision.texts[i].precision ) < 0.0000001
) {
- precisionText =
this.settings.precisionTexts[i].text;
+ precisionText =
this.settings.precision.texts[i].text;
}
}
diff --git
a/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
b/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
index bd06329..6ec7477 100644
--- a/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
+++ b/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
@@ -136,61 +136,6 @@
} );
- QUnit.test( 'Precision handling', function( assert ) {
- var c = new coordinate.Coordinate( '1.5 1.25' );
-
- assert.equal(
- c.getPrecision(),
- 0.01,
- 'Increased precision'
- );
-
- c.decreasePrecision();
- c.decreasePrecision();
-
- assert.equal(
- c.getPrecision(),
- 0.1,
- 'Decreased precision'
- );
-
- assert.equal(
- c.longitudeDecimal(),
- 1.3,
- 'Verified applied precision'
- );
-
- c.increasePrecision();
- c.increasePrecision();
-
- assert.equal(
- c.getPrecision(),
- 0.01,
- 'Increased precision'
- );
-
- assert.equal(
- c.longitudeDecimal(),
- 1.25,
- 'Verified applied precision'
- );
-
- c.setPrecision( 1 );
-
- assert.equal(
- c.getPrecision(),
- 1,
- 'Set precision'
- );
-
- assert.equal(
- c.longitudeDecimal(),
- 1,
- 'Verified applied precision'
- );
-
- } );
-
QUnit.test( 'iso6709()', function( assert ) {
var c;
diff --git a/DataValues/resources/coordinate.js/tests/coordinate.tests.js
b/DataValues/resources/coordinate.js/tests/coordinate.tests.js
index f26c3c6..727dcdd 100644
--- a/DataValues/resources/coordinate.js/tests/coordinate.tests.js
+++ b/DataValues/resources/coordinate.js/tests/coordinate.tests.js
@@ -159,7 +159,7 @@
// Look up precision text:
if( typeof expected.tech === 'number' ) {
- $.each( coordinate.settings.precisionTexts,
function( i, textDefinition ) {
+ $.each( coordinate.settings.precision.texts,
function( i, textDefinition ) {
if( textDefinition.precision ===
expected.tech ) {
assert.strictEqual(
--
To view, visit https://gerrit.wikimedia.org/r/66072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I39753f037a0e6a2eca4264da68f041155ebdf6e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits