UNPKG

@spatial/boolean-equal

Version:

turf boolean-equal module

43 lines (36 loc) 1.57 kB
'use strict'; var GeojsonEquality = require('geojson-equality'); var cleanCoords = require('@spatial/clean-coords'); var invariant = require('@spatial/invariant'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var GeojsonEquality__default = /*#__PURE__*/_interopDefaultLegacy(GeojsonEquality); var cleanCoords__default = /*#__PURE__*/_interopDefaultLegacy(cleanCoords); /** * Determine whether two geometries of the same type have identical X,Y coordinate values. * See http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm * * @name booleanEqual * @param {Geometry|Feature} feature1 GeoJSON input * @param {Geometry|Feature} feature2 GeoJSON input * @returns {boolean} true if the objects are equal, false otherwise * @example * var pt1 = turf.point([0, 0]); * var pt2 = turf.point([0, 0]); * var pt3 = turf.point([1, 1]); * * turf.booleanEqual(pt1, pt2); * //= true * turf.booleanEqual(pt2, pt3); * //= false */ function booleanEqual(feature1, feature2) { // validation if (!feature1) throw new Error('feature1 is required'); if (!feature2) throw new Error('feature2 is required'); const type1 = invariant.getType(feature1); const type2 = invariant.getType(feature2); if (type1 !== type2) return false; const equality = new GeojsonEquality__default['default']({precision: 6}); return equality.compare(cleanCoords__default['default'](feature1), cleanCoords__default['default'](feature2)); } module.exports = booleanEqual;