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AAA,IACvB,KAAK,KAAA,CAAA;AAAA,IACL,KAAK,IAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,gCAAA,OAAgB,CAAA;AAAA,IACzB,OAAA;AACE,MAAA,MAAM,IAAI,KAAA,CAAM,gBAAgB,CAAA;AAAA,EACpC;AAEF;AAGA,IAAO,6BAAA,EAAQ,cAAA;AD1Ff;AACE;AACA;AACF,wFAAC","file":"/home/runner/work/turf/turf/packages/turf-transform-scale/dist/cjs/index.cjs","sourcesContent":[null,"import { Corners, Coord } from \"@turf/helpers\";\nimport { FeatureCollection, GeoJSON, GeometryCollection } from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { center } from \"@turf/center\";\nimport { centroid } from \"@turf/centroid\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { coordEach, featureEach } from \"@turf/meta\";\nimport { point, isObject } from \"@turf/helpers\";\nimport { getCoord, getCoords, getType } from \"@turf/invariant\";\n\n/**\n * Scale GeoJSON objects from a given point by a scaling factor e.g. factor=2\n * would make each object 200% larger.\n * If a FeatureCollection is provided, the origin point will be calculated\n * based on each individual feature _unless_ an exact\n *\n * @function\n * @param {GeoJSON|GeometryCollection} geojson objects to be scaled\n * @param {number} factor of scaling, positive values greater than 0. Numbers between 0 and 1 will shrink the geojson, numbers greater than 1 will expand it, a factor of 1 will not change the geojson.\n * @param {Object} [options={}] Optional parameters\n * @param {Corners|Coord} [options.origin='centroid'] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance improvement if true)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const scaledPoly = turf.transformScale(poly, 3);\n *\n * //addToMap\n * const addToMap = [poly, scaledPoly];\n * scaledPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformScale(\n geojson: T,\n factor: number,\n options?: {\n origin?: Corners | Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const origin = options.origin || \"centroid\";\n const mutate = options.mutate || false;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson required\");\n if (typeof factor !== \"number\" || factor <= 0)\n throw new Error(\"invalid factor\");\n const originIsPoint = Array.isArray(origin) || typeof origin === \"object\";\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n // Scale each Feature separately if a feature collection AND the user didn't\n // pass a single explicit point to scale the whole collection from.\n if (geojson.type === \"FeatureCollection\" && !originIsPoint) {\n featureEach(geojson, function (feature, index) {\n // The type guard above is not recognised in the callback so we have to\n // cast to accept responsibility.\n (geojson as FeatureCollection).features[index] = scale(\n feature,\n factor,\n origin\n );\n });\n return geojson;\n }\n // Scale Feature/Geometry\n return scale(geojson, factor, origin);\n}\n\n/**\n * Scale Feature/Geometry\n *\n * @private\n * @param {GeoJSON|GeometryCollection} feature feature or geometry collection to scale\n * @param {number} factor of scaling, positive or negative values greater than 0\n * @param {Corners|Coord} [origin=\"centroid\"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)\n * @returns {GeoJSON|GeometryCollection} scaled GeoJSON Feature/Geometry\n */\nfunction scale(\n feature: T,\n factor: number,\n origin: Corners | Coord\n): T {\n // Default params\n const isPoint = getType(feature) === \"Point\";\n // Work with a Coord equivalent of the origin from here on.\n const originCoord: Coord = defineOrigin(feature, origin);\n\n // Shortcut no-scaling\n if (factor === 1 || isPoint) return feature;\n\n // Scale each coordinate\n coordEach(feature, function (coord) {\n const originalDistance = rhumbDistance(originCoord, coord);\n const bearing = rhumbBearing(originCoord, coord);\n const newDistance = originalDistance * factor;\n const newCoord = getCoords(\n rhumbDestination(originCoord, newDistance, bearing)\n );\n coord[0] = newCoord[0];\n coord[1] = newCoord[1];\n if (coord.length === 3) coord[2] *= factor;\n });\n\n delete feature.bbox;\n\n return feature;\n}\n\n/**\n * Define Origin\n *\n * @private\n * @param {GeoJSON|GeometryCollection} geojson GeoJSON\n * @param {Corners|Coord} origin sw/se/nw/ne/center/centroid\n * @returns {Feature} Point origin\n */\nfunction defineOrigin(\n geojson: GeoJSON | GeometryCollection,\n origin: Corners | Coord\n): Coord {\n // Default params\n if (origin === undefined || origin === null) origin = \"centroid\";\n\n // Input Coord\n if (Array.isArray(origin) || typeof origin === \"object\")\n return getCoord(origin);\n\n // Define BBox\n const bbox = geojson.bbox\n ? geojson.bbox\n : turfBBox(geojson, { recompute: true });\n const west = bbox[0];\n const south = bbox[1];\n const east = bbox[2];\n const north = bbox[3];\n\n // Having to disable eslint below for lines which fail the no-fallthrough\n // rule, though only because of the ts-expect-error rules. Once we remove\n // southeast, bottomright, rightbottom, etc we should be able to remove all\n // these supressions.\n /* eslint-disable no-fallthrough */\n switch (origin) {\n case \"sw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomleft\":\n return point([west, south]);\n case \"se\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"southeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastsouth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"bottomright\":\n return point([east, south]);\n case \"nw\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northwest\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"westnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topleft\":\n return point([west, north]);\n case \"ne\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"northeast\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"eastnorth\":\n // @ts-expect-error undocumented, to be removed for v8 #techdebt\n case \"topright\":\n return point([east, north]);\n case \"center\":\n return center(geojson);\n case undefined:\n case null:\n case \"centroid\":\n return centroid(geojson);\n default:\n throw new Error(\"invalid origin\");\n }\n /* eslint-enable no-fallthrough */\n}\n\nexport { transformScale };\nexport default transformScale;\n"]}