UNPKG

@phun-ky/angle

Version:

A JavaScript function to calculate the angle between two coordinates

55 lines (54 loc) 3.33 kB
/** * @phun-ky/angle * A JavaScript function to calculate the angle between two coordinates * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net> * @version 1.0.27 * @license * Copyright (c) 2024 Alexander Vassbotn Røyne-Helgesen * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).angle={})}(this,(function(e){"use strict"; /** * @phun-ky/typeof * A set of JavaScript helper functions to check for types * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net> * @version 1.2.21 * @license * Copyright (c) 2024 Alexander Vassbotn Røyne-Helgesen * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */const t=e=>!(e=>"number"==typeof e)(e),o=e=>void 0===e;e.angle=(e,n,r,f,i=!0)=>{if(o(e)||o(n)||o(r)||o(f))throw new SyntaxError("Missing input for `angle`");if(t(e)||t(n)||t(r)||t(f))throw TypeError(`Parameters for \`angle\` do not have the required type. Requires number! Got: ${typeof e} ${typeof n} ${typeof r} ${typeof f}`);const a=f-n,p=r-e;let s=Math.atan2(a,p);return s*=180/Math.PI,i&&s<0&&(s+=360),s}})); //# sourceMappingURL=angle.js.map