Skip to content

Commit ca94f16

Browse files
committed
Add support for GlobeCoordinate precision null
1 parent 6d2b78c commit ca94f16

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
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._precision - otherGlobeCoordinate._precision ) < 0.00000001
146+
return ( this._precision === otherGlobeCoordinate._precision
147+
|| Math.abs( this._precision - otherGlobeCoordinate._precision ) < 0.00000001 )
147148
&& gc1Iso6709 === gc2Iso6709
148149
&& this._globe === otherGlobeCoordinate._globe;
149150
}

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

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define( [
1414
QUnit.module( 'globeCoordinate.GlobeCoordinate.js' );
1515

1616
QUnit.test( 'Basic checks', function( assert ) {
17-
assert.expect( 13 );
17+
assert.expect( 10 );
1818
var c;
1919

2020
assert.throws(
@@ -76,26 +76,26 @@ define( [
7676
'string',
7777
'Verified iso6709()'
7878
);
79+
} );
7980

80-
// test with no precision provided
81-
c = new globeCoordinate.GlobeCoordinate( { latitude: 20, longitude: 25.5 } );
81+
QUnit.test( 'Precision defaults to null', function( assert ) {
82+
assert.expect( 3 );
83+
var c = new globeCoordinate.GlobeCoordinate( { latitude: 0, longitude: 0 } );
8284

83-
assert.equal(
84-
c.getLatitude(),
85-
20,
86-
'Verified getLatitude()'
85+
assert.ok(
86+
c.getPrecision() === null,
87+
'Verified getPrecision()'
8788
);
8889

89-
assert.equal(
90-
c.getLongitude(),
91-
25.5,
92-
'Verified getLatitude()'
90+
assert.deepEqual(
91+
c.getDecimal(),
92+
{ latitude: 0, longitude: 0, precision: null },
93+
'Verified getDecimal()'
9394
);
9495

95-
assert.equal(
96-
c.getPrecision(),
97-
null,
98-
'Verified precision is null'
96+
assert.ok(
97+
c.equals( c ),
98+
'Validated equality'
9999
);
100100
} );
101101

@@ -119,6 +119,36 @@ define( [
119119
);
120120
} );
121121

122+
QUnit.test( 'ISO 6709 strings', function( assert ) {
123+
assert.expect( 12 );
124+
var gcDefs = [
125+
{ precision: 10, expected: '+10+010/' },
126+
{ precision: 2, expected: '+14+012/' },
127+
{ precision: 1, expected: '+13+012/' },
128+
{ precision: 0.1, expected: '+1307+01207/' },
129+
{ precision: 0.01, expected: '+130724+0120724/' },
130+
{ precision: 1 / 60, expected: '+1307+01207/' },
131+
{ precision: 1 / 3600, expected: '+130724+0120724/' },
132+
{ precision: 1 / 36000, expected: '+130724.4+0120724.4/' },
133+
{ precision: 1 / 360000, expected: '+130724.42+0120724.42/' },
134+
{ precision: 0, expected: '+130724.42+0120724.42/' },
135+
{ precision: null, expected: '+130724.42+0120724.42/' },
136+
{ expected: '+130724.42+0120724.42/' }
137+
],
138+
c;
139+
140+
$.each( gcDefs, function( i, gcDef ) {
141+
c = new globeCoordinate.GlobeCoordinate(
142+
{ latitude: 13.12345, longitude: 12.12345, precision: gcDef.precision }
143+
);
144+
145+
assert.ok(
146+
c.iso6709() === gcDef.expected,
147+
'Validated ISO 6709 string of data set #' + i + '.'
148+
);
149+
} );
150+
} );
151+
122152
QUnit.test( 'Strict (in)equality', function( assert ) {
123153
assert.expect( 169 );
124154
var gcDefs = [

0 commit comments

Comments
 (0)