Skip to content

Commit d357585

Browse files
committed
Add support for GlobeCoordinate precision null
1 parent 727ff2f commit d357585

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

lib/globeCoordinate/globeCoordinate.GlobeCoordinate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param {Object} gcDef Needs the following attributes:
1313
* - {number} latitude
1414
* - {number} longitude
15-
* - {number} precision
15+
* - {number|null} [precision]
1616
*
1717
* @throws {Error} when latitude is greater than 360.
1818
* @throws {Error} when longitude is greater than 360.
@@ -27,7 +27,7 @@
2727

2828
this._latitude = gcDef.latitude;
2929
this._longitude = gcDef.longitude;
30-
this._precision = gcDef.precision;
30+
this._precision = gcDef.precision || null;
3131

3232
// TODO: Capture altitude and globe
3333

@@ -70,7 +70,7 @@
7070

7171
/**
7272
* Precision
73-
* @property {number}
73+
* @property {number|null}
7474
* @private
7575
*/
7676
_precision: null,
@@ -101,7 +101,7 @@
101101
/**
102102
* Returns the precision.
103103
*
104-
* @return {number}
104+
* @return {number|null}
105105
*/
106106
getPrecision: function() { return this._precision; },
107107

@@ -143,7 +143,8 @@
143143
var gc1Iso6709 = globeCoordinate.iso6709( this.getDecimal() ),
144144
gc2Iso6709 = globeCoordinate.iso6709( otherGlobeCoordinate.getDecimal() );
145145

146-
return Math.abs( this.getPrecision() - otherGlobeCoordinate.getPrecision() ) < 0.00000001
146+
return ( this._precision === otherGlobeCoordinate._precision
147+
|| Math.abs( this._precision - otherGlobeCoordinate._precision ) < 0.00000001 )
147148
&& gc1Iso6709 === gc2Iso6709;
148149
}
149150
};

tests/lib/globeCoordinate/globeCoordinate.GlobeCoordinate.tests.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,57 @@ define( [
9494

9595
} );
9696

97+
QUnit.test( 'Precision defaults to null', function( assert ) {
98+
assert.expect( 3 );
99+
var c = new globeCoordinate.GlobeCoordinate( { latitude: 0, longitude: 0 } );
100+
101+
assert.ok(
102+
c.getPrecision() === null,
103+
'Verified getPrecision()'
104+
);
105+
106+
assert.deepEqual(
107+
c.getDecimal(),
108+
{ latitude: 0, longitude: 0, precision: null },
109+
'Verified getDecimal()'
110+
);
111+
112+
assert.ok(
113+
c.equals( c ),
114+
'Validated equality'
115+
);
116+
} );
117+
118+
QUnit.test( 'ISO 6709 strings', function( assert ) {
119+
assert.expect( 12 );
120+
var gcDefs = [
121+
{ precision: 10, expected: '+10+010/' },
122+
{ precision: 2, expected: '+14+012/' },
123+
{ precision: 1, expected: '+13+012/' },
124+
{ precision: 0.1, expected: '+1307+01207/' },
125+
{ precision: 0.01, expected: '+130724+0120724/' },
126+
{ precision: 1 / 60, expected: '+1307+01207/' },
127+
{ precision: 1 / 3600, expected: '+130724+0120724/' },
128+
{ precision: 1 / 36000, expected: '+130724.4+0120724.4/' },
129+
{ precision: 1 / 360000, expected: '+130724.42+0120724.42/' },
130+
{ precision: 0, expected: '+130724.42+0120724.42/' },
131+
{ precision: null, expected: '+130724.42+0120724.42/' },
132+
{ expected: '+130724.42+0120724.42/' }
133+
],
134+
c;
135+
136+
$.each( gcDefs, function( i, gcDef ) {
137+
c = new globeCoordinate.GlobeCoordinate(
138+
{ latitude: 13.12345, longitude: 12.12345, precision: gcDef.precision }
139+
);
140+
141+
assert.ok(
142+
c.iso6709() === gcDef.expected,
143+
'Validated ISO 6709 string of data set #' + i + '.'
144+
);
145+
} );
146+
} );
147+
97148
QUnit.test( 'Strict (in)equality', function( assert ) {
98149
assert.expect( 121 );
99150
var gcDefs = [

0 commit comments

Comments
 (0)