mirror of
https://github.com/Turfjs/turf.git
synced 2026-01-25 16:07:00 +00:00
* Added JSDoc for internal types and constants e.g. Unts and earthRadius. Minimal other changes to bring JSDoc types into line with code types. Added GeoJsonProperties to documentation.yml for type linking. * Generated README.md files based on updated source that now includes JSDoc for internal types and constants e.g. Units. Also synced up some out of data JSDoc types with what is in the code. * Switched the structure of documentation.yml to be more traditionally nested. We'll use this new structure from the turf-www repo to generate the website documentation in a more robust manner. * For some reason leaving this function documented as the default (geojsonRbush) causes @turf/turf last-checks to fail. Specifically defining it as rbush like it used to be, except with the @function tag rather than @name.
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { Feature, Geometry } from "geojson";
|
|
import { geojsonEquality } from "geojson-equality-ts";
|
|
import { cleanCoords } from "@turf/clean-coords";
|
|
import { getGeom } from "@turf/invariant";
|
|
|
|
/**
|
|
* 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
|
|
*
|
|
* @function
|
|
* @param {Geometry|Feature} feature1 GeoJSON input
|
|
* @param {Geometry|Feature} feature2 GeoJSON input
|
|
* @param {Object} [options={}] Optional parameters
|
|
* @param {number} [options.precision=6] decimal precision to use when comparing coordinates
|
|
* @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: Feature<any> | Geometry,
|
|
feature2: Feature<any> | Geometry,
|
|
options: {
|
|
precision?: number;
|
|
} = {}
|
|
): boolean {
|
|
let precision = options.precision;
|
|
|
|
precision =
|
|
precision === undefined || precision === null || isNaN(precision)
|
|
? 6
|
|
: precision;
|
|
|
|
if (typeof precision !== "number" || !(precision >= 0)) {
|
|
throw new Error("precision must be a positive number");
|
|
}
|
|
|
|
const type1 = getGeom(feature1).type;
|
|
const type2 = getGeom(feature2).type;
|
|
if (type1 !== type2) return false;
|
|
|
|
return geojsonEquality(cleanCoords(feature1), cleanCoords(feature2), {
|
|
precision,
|
|
});
|
|
}
|
|
|
|
export { booleanEqual };
|
|
export default booleanEqual;
|