{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject, Coord } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @function\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const options = {pivot: [0, 25]};\n * const rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * const addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate(\n geojson: T,\n angle: number,\n options?: {\n pivot?: 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 pivot = options.pivot;\n const mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n const pivotCoord = pivot ?? centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n const initialAngle = rhumbBearing(pivotCoord, pointCoords);\n const finalAngle = initialAngle + angle;\n const distance = rhumbDistance(pivotCoord, pointCoords);\n const newCoords = getCoords(\n rhumbDestination(pivotCoord, distance, finalAngle)\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAqBhC,SAAS,gBACP,SACA,OACA,SAIG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,QAAQ,QAAQ;AACtB,QAAM,SAAS,QAAQ;AAGvB,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU,EAAG,QAAO;AAGxB,QAAM,aAAa,wBAAS,SAAS,OAAO;AAG5C,MAAI,WAAW,SAAS,WAAW,OAAW,WAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,UAAM,eAAe,aAAa,YAAY,WAAW;AACzD,UAAM,aAAa,eAAe;AAClC,UAAM,WAAW,cAAc,YAAY,WAAW;AACtD,UAAM,YAAY;AAAA,MAChB,iBAAiB,YAAY,UAAU,UAAU;AAAA,IACnD;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AAGA,IAAO,gCAAQ;","names":[]}