UNPKG

mathleet

Version:

Library of helpful math utilities.

3 lines (2 loc) 1.72 kB
/*! mathleet v0.1.0 | (c) 2021 Ryan Hefner | MIT License | https://github.com/[object Object] !*/ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).mathleet={})}(this,(function(t){"use strict";var n=function(t){return t.map((function(t){return Number(t)})).filter((function(t){return!isNaN(t)}))},e=function(t,e){return n(t.map((function(t){return t[e]}))).reduce((function(t,n){return n+t}),0)},r=function(t){var e=n(t);return Math.min.apply(Math,e)},u=function(t){var e=n(t);return Math.max.apply(Math,e)},o=function(t,e){return void 0===e&&(e=0),n(t).reduce((function(t,n){return n+t}),e)},i=function(t,n){return void 0===n&&(n=0),o(t,n)/t.length},a=function(t){return t*(180/Math.PI)},f={x:0,y:0};t.angle=function(t,n,e){void 0===t&&(t=f),void 0===n&&(n=f),void 0===e&&(e=f);var r=Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)),u=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),o=Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2)),i=Math.pow(r,2)+Math.pow(o,2)-Math.pow(u,2),c=2*r*o;return a(Math.acos(i/c))},t.degrees=a,t.filterNumbers=n,t.keyAvg=function(t,n){return e(t,n)/t.length},t.keySum=e,t.numMax=u,t.numMin=r,t.outside=function(t,n,e){return void 0===e&&(e=0),t<n-e||t>n+e},t.radians=function(t){return t*(Math.PI/180)},t.rangeAvg=function(t,n,e){void 0===n&&(n=0),void 0===e&&(e=1);var o=r(t),a=u(t)-o,f=o+a*n,c=o+a*e,h=t.filter((function(t){return t>=f&&t<=c}));return i(h)},t.sum=o,t.sumAvg=i,t.velocity=function(t,n){return t/n},t.within=function(t,n,e){return void 0===e&&(e=0),t>=n-e&&t<=n+e},Object.defineProperty(t,"__esModule",{value:!0})}));