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AAA;AAAA,MAAA,KAEjE,OAAO,gCAAA,OAAS,EAAS,EAAE,UAAA,EAAY,OAAA,CAAQ,WAAW,CAAC,CAAA;AAAA,EACpE;AACF;AAGA,IAAO,4BAAA,EAAQ,YAAA;AD7Cf;AACE;AACA;AACF,mFAAC","file":"/home/runner/work/turf/turf/packages/turf-center-of-mass/dist/cjs/index.cjs","sourcesContent":[null,"import { Feature, GeoJsonProperties, Point, Position } from \"geojson\";\nimport { convex } from \"@turf/convex\";\nimport { centroid } from \"@turf/centroid\";\nimport { point } from \"@turf/helpers\";\nimport { getType, getCoord } from \"@turf/invariant\";\nimport { coordEach } from \"@turf/meta\";\n\n/**\n * Takes any {@link Feature} or a {@link FeatureCollection} and returns its [center of mass](https://en.wikipedia.org/wiki/Center_of_mass) using this formula: [Centroid of Polygon](https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon).\n *\n * @function\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate Properties to Feature\n * @returns {Feature} the center of mass\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var center = turf.centerOfMass(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, center]\n */\nfunction centerOfMass

(\n geojson: any,\n options: {\n properties?: P;\n } = {}\n): Feature {\n switch (getType(geojson)) {\n case \"Point\":\n return point(getCoord(geojson), options.properties);\n case \"Polygon\":\n var coords: Position[] = [];\n coordEach(geojson, function (coord) {\n coords.push(coord);\n });\n\n // First, we neutralize the feature (set it around coordinates [0,0]) to prevent rounding errors\n // We take any point to translate all the points around 0\n var centre = centroid(geojson, { properties: options.properties });\n var translation = centre.geometry.coordinates;\n var sx = 0;\n var sy = 0;\n var sArea = 0;\n var i, pi, pj, xi, xj, yi, yj, a;\n\n var neutralizedPoints = coords.map(function (point) {\n return [point[0] - translation[0], point[1] - translation[1]];\n });\n\n for (i = 0; i < coords.length - 1; i++) {\n // pi is the current point\n pi = neutralizedPoints[i];\n xi = pi[0];\n yi = pi[1];\n\n // pj is the next point (pi+1)\n pj = neutralizedPoints[i + 1];\n xj = pj[0];\n yj = pj[1];\n\n // a is the common factor to compute the signed area and the final coordinates\n a = xi * yj - xj * yi;\n\n // sArea is the sum used to compute the signed area\n sArea += a;\n\n // sx and sy are the sums used to compute the final coordinates\n sx += (xi + xj) * a;\n sy += (yi + yj) * a;\n }\n\n // Shape has no area: fallback on turf.centroid\n if (sArea === 0) {\n return centre;\n } else {\n // Compute the signed area, and factorize 1/6A\n var area = sArea * 0.5;\n var areaFactor = 1 / (6 * area);\n\n // Compute the final coordinates, adding back the values that have been neutralized\n return point(\n [translation[0] + areaFactor * sx, translation[1] + areaFactor * sy],\n options.properties\n );\n }\n default:\n // Not a polygon: Compute the convex hull and work with that\n var hull = convex(geojson);\n\n if (hull) return centerOfMass(hull, { properties: options.properties });\n // Hull is empty: fallback on the centroid\n else return centroid(geojson, { properties: options.properties });\n }\n}\n\nexport { centerOfMass };\nexport default centerOfMass;\n"]}