-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f2e3d9
commit 284b3a3
Showing
7 changed files
with
467 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,198 @@ | ||
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@danehansen/math")):"function"==typeof define&&define.amd?define(["@danehansen/math"],t):"object"==typeof exports?exports.Point=t(require("@danehansen/math")):(n.danehansen=n.danehansen||{},n.danehansen.Point=t(n.danehansen.math))}(this,function(n){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var e={};return t.m=n,t.c=e,t.i=function(n){return n},t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:r})},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=1)}([function(t,e){t.exports=n},function(n,t,e){"use strict";function r(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),i=e(0),u={x:0,y:0},a=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;r(this,n),c.call(this),this.x=t,this.y=e}return o(n,null,[{key:"distance",value:function(n,t){return Math.sqrt(Math.pow(n.x-t.x,2)+Math.pow(n.y-t.y,2))}},{key:"interpolate",value:function(t,e,r){return new n(t.x+(e.x-t.x)*r,t.y+(e.y-t.y)*r)}},{key:"intersection",value:function(t,e,r,o){var i=t.x,u=t.y,a=e.x,c=e.y,s=r.x,f=r.y,h=o.x,y=o.y,l=i-a,x=f-y,d=u-c,p=s-h,v=l*x-d*p;if(0===v)return null;var m=i*c-u*a,b=s*y-f*h;return new n((m*p-l*b)/v,(m*x-d*b)/v)}},{key:"polar",value:function(t,e){return new n(Math.cos(e)*t,Math.sin(e)*t)}},{key:"randomPointInCircle",value:function(t,e){var r={};do{r.x=Math.random()*e*2+t.x-e,r.y=Math.random()*e*2+t.y-e}while(n.distance(r,t)>e);return r}},{key:"round",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return new n((0,i.round)(t.x,e),(0,i.round)(t.y,e))}}]),o(n,[{key:"rotate",value:function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:u,e=Math.sin(n),r=Math.cos(n),o=this.x,i=this.y,a=t.x,c=t.y;o-=a,i-=c,this.x=o*r-i*e+a,this.y=o*e+i*r+c}},{key:"length",get:function(){return n.distance(this,u)}}]),n}(),c=function(){var n=this;this.add=function(t){n.offset(t.x,t.y)},this.angle=function(){return Math.atan2(n.y,n.x)},this.clone=function(){return new a(n.x,n.y)},this.copyFrom=function(t){n.setTo(t.x,t.y)},this.equals=function(t){return n.x===t.x&&n.y===t.y},this.normalize=function(t){var e=t/n.length;n.x*=e,n.y*=e},this.offset=function(t,e){n.x+=t,n.y+=e},this.setTo=function(t,e){n.x=t,n.y=e},this.subtract=function(t){n.x-=t.x,n.y-=t.y},this.toString=function(){return"{x: "+n.x+", y: "+n.y+"}"}};n.exports=a}])}); | ||
(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["point"] = factory(require("@danehansen/math")); | ||
else | ||
root["danehansen"] = root["danehansen"] || {}, root["danehansen"]["point"] = factory(root["danehansen"]["math"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 1); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
|
||
module.exports = __WEBPACK_EXTERNAL_MODULE_0__; | ||
|
||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
|
||
"use strict"; | ||
|
||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.add = add; | ||
exports.angle = angle; | ||
exports.distance = distance; | ||
exports.interpolate = interpolate; | ||
exports.intersection = intersection; | ||
exports.length = length; | ||
exports.normalize = normalize; | ||
exports.polar = polar; | ||
exports.randomPointInCircle = randomPointInCircle; | ||
exports.rotate = rotate; | ||
exports.round = round; | ||
exports.toString = toString; | ||
|
||
var _math = __webpack_require__(0); | ||
|
||
function add(a, b) { | ||
return { x: a.x + b.x, y: a.y + b.y }; | ||
} | ||
|
||
function angle(point) { | ||
return Math.atan2(point.y, point.x); | ||
} | ||
|
||
function distance(a, b) { | ||
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)); | ||
} | ||
|
||
function interpolate(start, end, amount) { | ||
return { x: start.x + (end.x - start.x) * amount, y: start.y + (end.y - start.y) * amount }; | ||
} | ||
|
||
function intersection(startA, endA, startB, endB) { | ||
var x1 = startA.x; | ||
var y1 = startA.y; | ||
var x2 = endA.x; | ||
var y2 = endA.y; | ||
var x3 = startB.x; | ||
var y3 = startB.y; | ||
var x4 = endB.x; | ||
var y4 = endB.y; | ||
var a = x1 - x2; | ||
var b = y3 - y4; | ||
var c = y1 - y2; | ||
var d = x3 - x4; | ||
var e = a * b - c * d; | ||
if (e === 0) { | ||
return null; | ||
} | ||
var f = x1 * y2 - y1 * x2; | ||
var g = x3 * y4 - y3 * x4; | ||
return { x: (f * d - a * g) / e, y: (f * b - c * g) / e }; | ||
} | ||
|
||
function length(point) { | ||
return distance(point, { x: 0, y: 0 }); | ||
} | ||
|
||
function normalize(point, thickness) { | ||
var l = length(point); | ||
var ratio = thickness / l; | ||
return { x: point.x * ratio, y: point.y * ratio }; | ||
} | ||
|
||
function polar(len, angle) { | ||
return { x: Math.cos(angle) * len, y: Math.sin(angle) * len }; | ||
} | ||
|
||
function randomPointInCircle(center, radius) { | ||
var random = {}; | ||
do { | ||
random.x = Math.random() * radius * 2 + center.x - radius; | ||
random.y = Math.random() * radius * 2 + center.y - radius; | ||
} while (distance(random, center) > radius); | ||
return random; | ||
} | ||
|
||
function rotate(point, angle) { | ||
var center = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { x: 0, y: 0 }; | ||
|
||
var sin = Math.sin(angle); | ||
var cos = Math.cos(angle); | ||
var x = point.x, | ||
y = point.y; | ||
|
||
var centerX = center.x; | ||
var centerY = center.y; | ||
x -= centerX; | ||
y -= centerY; | ||
return { x: x * cos - y * sin + centerX, y: x * sin + y * cos + centerY }; | ||
} | ||
|
||
function round(point) { | ||
var increment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
|
||
return { x: (0, _math.round)(point.x, increment), y: (0, _math.round)(point.y, increment) }; | ||
} | ||
|
||
function toString(point) { | ||
return '{x: ' + point.x + ', y: ' + point.y + '}'; | ||
} | ||
|
||
/***/ }) | ||
/******/ ]); | ||
}); |
Oops, something went wrong.