Skip to content

Commit a50a48e

Browse files
committed
Rewrite globeCoordinate.GlobeCoordinate.equals
1 parent eb1aa93 commit a50a48e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/globeCoordinate/globeCoordinate.GlobeCoordinate.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,23 @@
137137
* @return {boolean}
138138
*/
139139
equals: function( otherGlobeCoordinate ) {
140-
if( !( otherGlobeCoordinate instanceof globeCoordinate.GlobeCoordinate ) ) {
140+
if ( !( otherGlobeCoordinate instanceof SELF )
141+
|| otherGlobeCoordinate._globe !== this._globe
142+
) {
141143
return false;
142144
}
143145

144-
var gc1Iso6709 = globeCoordinate.iso6709( this.getDecimal() ),
145-
gc2Iso6709 = globeCoordinate.iso6709( otherGlobeCoordinate.getDecimal() );
146-
147-
return ( this._precision === otherGlobeCoordinate._precision
148-
|| Math.abs( this._precision - otherGlobeCoordinate._precision ) < 0.00000001 )
149-
&& gc1Iso6709 === gc2Iso6709
150-
&& this._globe === otherGlobeCoordinate._globe;
146+
// 0.00000001° corresponds to approx. 1 mm on Earth and can always be considered equal.
147+
var oneMillimeter = 0.00000001,
148+
epsilon = Math.max(
149+
// A change worth 1/2 precision might already become a visible change
150+
Math.min( this._precision, otherGlobeCoordinate._precision ) / 2,
151+
oneMillimeter
152+
);
153+
154+
return Math.abs( otherGlobeCoordinate._precision - this._precision ) < oneMillimeter
155+
&& Math.abs( otherGlobeCoordinate._latitude - this._latitude ) < epsilon
156+
&& Math.abs( otherGlobeCoordinate._longitude - this._longitude ) < epsilon;
151157
}
152158
};
153159

0 commit comments

Comments
 (0)