-
Notifications
You must be signed in to change notification settings - Fork 17
/
simplifygeometry-0.0.2.min.js
1 lines (1 loc) · 2.07 KB
/
simplifygeometry-0.0.2.min.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.simplifyGeometry=e()}}(function(){var e,t,n;return function r(e,t,n){function i(o,u){if(!t[o]){if(!e[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[o]={exports:{}};e[o][0].call(l.exports,function(t){var n=e[o][1][t];return i(n?n:t)},l,l.exports,r,e,t,n)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,n){var r=e("./line"),i=function(e,t){var n=0,s=0;for(var o=1;o<=e.length-2;o++){var u=(new r(e[0],e[e.length-1])).perpendicularDistance(e[o]);u>n&&(s=o,n=u)}if(n>t)var a=i(e.slice(0,s),t),f=i(e.slice(s,e.length),t),l=a.concat(f);else e.length>1?l=[e[0],e[e.length-1]]:l=[e[0]];return l};t.exports=i},{"./line":2}],2:[function(e,t,n){var r=function(e,t){this.p1=e,this.p2=t};r.prototype.rise=function(){return this.p2[1]-this.p1[1]},r.prototype.run=function(){return this.p2[0]-this.p1[0]},r.prototype.slope=function(){return this.rise()/this.run()},r.prototype.yIntercept=function(){return this.p1[1]-this.p1[0]*this.slope(this.p1,this.p2)},r.prototype.isVertical=function(){return!isFinite(this.slope())},r.prototype.isHorizontal=function(){return this.p1[1]==this.p2[1]},r.prototype._perpendicularDistanceHorizontal=function(e){return Math.abs(this.p1[1]-e[1])},r.prototype._perpendicularDistanceVertical=function(e){return Math.abs(this.p1[0]-e[0])},r.prototype._perpendicularDistanceHasSlope=function(e){var t=this.slope(),n=this.yIntercept();return Math.abs(t*e[0]-e[1]+n)/Math.sqrt(Math.pow(t,2)+1)},r.prototype.perpendicularDistance=function(e){return this.isVertical()?this._perpendicularDistanceVertical(e):this.isHorizontal()?this._perpendicularDistanceHorizontal(e):this._perpendicularDistanceHasSlope(e)},t.exports=r},{}]},{},[1])(1)});