{"version":3,"sources":["../../index.ts"],"sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { Feature, Point, GeoJsonProperties } from \"geojson\";\nimport {\n convertLength,\n Coord,\n degreesToRadians,\n earthRadius,\n point,\n Units,\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the\n * origin Point with the (varant) given bearing.\n *\n * @function\n * @param {Coord} origin starting point\n * @param {number} distance distance from the starting point\n * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @param {Object} [options.properties={}] translate properties to destination point\n * @returns {Feature} Destination point.\n * @example\n * var pt = turf.point([-75.343, 39.984], {\"marker-color\": \"F00\"});\n * var distance = 50;\n * var bearing = 90;\n * var options = {units: 'miles'};\n *\n * var destination = turf.rhumbDestination(pt, distance, bearing, options);\n *\n * //addToMap\n * var addToMap = [pt, destination]\n * destination.properties['marker-color'] = '#00F';\n */\nfunction rhumbDestination

(\n origin: Coord,\n distance: number,\n bearing: number,\n options: {\n units?: Units;\n properties?: P;\n } = {}\n): Feature {\n const wasNegativeDistance = distance < 0;\n let distanceInMeters = convertLength(\n Math.abs(distance),\n options.units,\n \"meters\"\n );\n if (wasNegativeDistance) distanceInMeters = -Math.abs(distanceInMeters);\n const coords = getCoord(origin);\n const destination = calculateRhumbDestination(\n coords,\n distanceInMeters,\n bearing\n );\n\n // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)\n // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678\n destination[0] +=\n destination[0] - coords[0] > 180\n ? -360\n : coords[0] - destination[0] > 180\n ? 360\n : 0;\n return point(destination, options.properties);\n}\n\n/**\n * Returns the destination point having travelled along a rhumb line from origin point the given\n * distance on the given bearing.\n * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines\n *\n * @private\n * @param {Array} origin - point\n * @param {number} distance - Distance travelled, in same units as earth radius (default: metres).\n * @param {number} bearing - Bearing in degrees from north.\n * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).\n * @returns {Array} Destination point.\n */\nfunction calculateRhumbDestination(\n origin: number[],\n distance: number,\n bearing: number,\n radius?: number\n) {\n // φ => phi\n // λ => lambda\n // ψ => psi\n // Δ => Delta\n // δ => delta\n // θ => theta\n\n radius = radius === undefined ? earthRadius : Number(radius);\n\n const delta = distance / radius; // angular distance in radians\n const lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋\n const phi1 = degreesToRadians(origin[1]);\n const theta = degreesToRadians(bearing);\n\n const DeltaPhi = delta * Math.cos(theta);\n let phi2 = phi1 + DeltaPhi;\n\n // check for some daft bugger going past the pole, normalise latitude if so\n if (Math.abs(phi2) > Math.PI / 2) {\n phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;\n }\n\n const DeltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n // E-W course becomes ill-conditioned with 0/0\n const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);\n\n const DeltaLambda = (delta * Math.sin(theta)) / q;\n const lambda2 = lambda1 + DeltaLambda;\n\n return [\n (((lambda2 * 180) / Math.PI + 540) % 360) - 180,\n (phi2 * 180) / Math.PI,\n ]; // normalise to −180..+180°\n}\n\nexport { rhumbDestination };\nexport default rhumbDestination;\n"],"mappings":";AAEA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AA0BzB,SAAS,iBACP,QACA,UACA,SACA,UAGI,CAAC,GACc;AACnB,QAAM,sBAAsB,WAAW;AACvC,MAAI,mBAAmB;AAAA,IACrB,KAAK,IAAI,QAAQ;AAAA,IACjB,QAAQ;AAA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