-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdanehansen-Point.min.js
120 lines (113 loc) · 8.54 KB
/
danehansen-Point.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("@danehansen/math"));
else if(typeof define === 'function' && define.amd)
define(["@danehansen/math"], factory);
else if(typeof exports === 'object')
exports["danehansen"] = factory(require("@danehansen/math"));
else
root["danehansen"] = root["danehansen"] || {}, root["danehansen"]["point"] = factory(root["danehansen"]["math"]);
})(self, function(__WEBPACK_EXTERNAL_MODULE__danehansen_math__) {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/point.js":
/*!**********************!*\
!*** ./src/point.js ***!
\**********************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"add\": () => (/* binding */ add),\n/* harmony export */ \"angle\": () => (/* binding */ angle),\n/* harmony export */ \"distance\": () => (/* binding */ distance),\n/* harmony export */ \"interpolate\": () => (/* binding */ interpolate),\n/* harmony export */ \"intersection\": () => (/* binding */ intersection),\n/* harmony export */ \"length\": () => (/* binding */ length),\n/* harmony export */ \"normalize\": () => (/* binding */ normalize),\n/* harmony export */ \"polar\": () => (/* binding */ polar),\n/* harmony export */ \"randomPointInCircle\": () => (/* binding */ randomPointInCircle),\n/* harmony export */ \"rotate\": () => (/* binding */ rotate),\n/* harmony export */ \"round\": () => (/* binding */ round),\n/* harmony export */ \"toString\": () => (/* binding */ toString)\n/* harmony export */ });\n/* harmony import */ var _danehansen_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @danehansen/math */ \"@danehansen/math\");\n/* harmony import */ var _danehansen_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_danehansen_math__WEBPACK_IMPORTED_MODULE_0__);\n\nfunction add(a, b) {\n return {\n x: a.x + b.x,\n y: a.y + b.y\n };\n}\nfunction angle(point) {\n return Math.atan2(point.y, point.x);\n}\nfunction distance(a, b) {\n return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));\n}\nfunction interpolate(start, end, amount) {\n return {\n x: start.x + (end.x - start.x) * amount,\n y: start.y + (end.y - start.y) * amount\n };\n}\nfunction intersection(startA, endA, startB, endB) {\n var x1 = startA.x;\n var y1 = startA.y;\n var x2 = endA.x;\n var y2 = endA.y;\n var x3 = startB.x;\n var y3 = startB.y;\n var x4 = endB.x;\n var y4 = endB.y;\n var a = x1 - x2;\n var b = y3 - y4;\n var c = y1 - y2;\n var d = x3 - x4;\n var e = a * b - c * d;\n\n if (e === 0) {\n return null;\n }\n\n var f = x1 * y2 - y1 * x2;\n var g = x3 * y4 - y3 * x4;\n return {\n x: (f * d - a * g) / e,\n y: (f * b - c * g) / e\n };\n}\nfunction length(point) {\n return distance(point, {\n x: 0,\n y: 0\n });\n}\nfunction normalize(point, thickness) {\n var l = length(point);\n var ratio = thickness / l;\n return {\n x: point.x * ratio,\n y: point.y * ratio\n };\n}\nfunction polar(len, angle) {\n return {\n x: Math.cos(angle) * len,\n y: Math.sin(angle) * len\n };\n}\nfunction randomPointInCircle(center, radius) {\n var random = {};\n\n do {\n random.x = Math.random() * radius * 2 + center.x - radius;\n random.y = Math.random() * radius * 2 + center.y - radius;\n } while (distance(random, center) > radius);\n\n return random;\n}\nfunction rotate(point, angle) {\n var center = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {\n x: 0,\n y: 0\n };\n var sin = Math.sin(angle);\n var cos = Math.cos(angle);\n var x = point.x,\n y = point.y;\n var centerX = center.x;\n var centerY = center.y;\n x -= centerX;\n y -= centerY;\n return {\n x: x * cos - y * sin + centerX,\n y: x * sin + y * cos + centerY\n };\n}\nfunction round(point) {\n var increment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;\n return {\n x: (0,_danehansen_math__WEBPACK_IMPORTED_MODULE_0__.round)(point.x, increment),\n y: (0,_danehansen_math__WEBPACK_IMPORTED_MODULE_0__.round)(point.y, increment)\n };\n}\nfunction toString(point) {\n return \"{x: \".concat(point.x, \", y: \").concat(point.y, \"}\");\n}\n\n//# sourceURL=webpack://danehansen.point/./src/point.js?");
/***/ }),
/***/ "@danehansen/math":
/*!*************************************************************************************************************************************!*\
!*** external {"amd":"@danehansen/math","commonjs":"@danehansen/math","commonjs2":"@danehansen/math","root":["danehansen","math"]} ***!
\*************************************************************************************************************************************/
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE__danehansen_math__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./src/point.js");
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});