Add geoVecEquals for strict comparisons

This commit is contained in:
Bryan Housel
2017-12-23 22:33:35 -05:00
parent d6e8ca2a1c
commit 9fbb4d350f
3 changed files with 14 additions and 0 deletions

View File

@@ -8,6 +8,11 @@ var EQUATORIAL_RADIUS = 6356752.314245179;
var POLAR_RADIUS = 6378137.0;
// vector addition
export function geoVecEquals(a, b) {
return (a[0] === b[0]) && (a[1] === b[1]);
}
// vector addition
export function geoVecAdd(a, b) {
return [ a[0] + b[0], a[1] + b[1] ];

View File

@@ -23,6 +23,7 @@ export { geoPolygonIntersectsPolygon } from './geo.js';
export { geoScaleToZoom } from './geo.js';
export { geoSphericalDistance } from './geo.js';
export { geoVecAdd } from './geo.js';
export { geoVecEquals } from './geo.js';
export { geoVecFloor } from './geo.js';
export { geoVecSubtract } from './geo.js';
export { geoVecScale } from './geo.js';

View File

@@ -1,5 +1,13 @@
describe('iD.geo', function() {
describe('geoVecEquals', function() {
it('tests vectors for equality', function() {
expect(iD.geoVecEquals([1, 2], [1, 2])).to.be.true;
expect(iD.geoVecEquals([1, 2], [1, 0])).to.be.false;
expect(iD.geoVecEquals([1, 2], [2, 1])).to.be.false;
});
});
describe('geoVecAdd', function() {
it('adds vectors', function() {
expect(iD.geoVecAdd([1, 2], [3, 4])).to.eql([4, 6]);