flatten-js
Version:
Javascript library for 2d geometry
1 lines • 8.13 kB
JSON
{"dependencies":[{"name":"C:\\Users\\alexbol\\WebstormProjects\\flatten-js\\package.json","includedInParent":true,"mtime":1520238055570}],"generated":{"js":"\"use strict\";var t=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,s=void 0;try{for(var c,h=t[Symbol.iterator]();!(r=(c=h.next()).done)&&(n.push(c.value),!e||n.length!==e);r=!0);}catch(t){i=!0,s=t}finally{try{!r&&h.return&&h.return()}finally{if(i)throw s}}return n}(t,e);throw new TypeError(\"Invalid attempt to destructure non-iterable instance\")}}(),e=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,\"value\"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();function n(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}module.exports=function(r){r.Arc=function(){function i(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new r.Point,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2*Math.PI,h=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];n(this,i),this.pc=t.clone(),this.r=e,this.startAngle=s,this.endAngle=c,this.counterClockwise=h}return e(i,[{key:\"clone\",value:function(){return new r.Arc(this.pc.clone(),this.r,this.startAngle,this.endAngle,this.counterClockwise)}},{key:\"contains\",value:function(t){if(!r.Utils.EQ(this.pc.distanceTo(t)[0],this.r))return!1;if(t.equalTo(this.start))return!0;var e=new r.Vector(this.pc,t).slope,n=new r.Arc(this.pc,this.r,this.startAngle,e,this.counterClockwise);return r.Utils.LE(n.length,this.length)}},{key:\"split\",value:function(t){if(!this.contains(t))return[];if(r.Utils.EQ_0(this.sweep))return[this.clone()];if(this.start.equalTo(t)||this.end.equalTo(t))return[this.clone()];var e=new r.Vector(this.pc,t).slope;return[new r.Arc(this.pc,this.r,this.startAngle,e,this.counterClockwise),new r.Arc(this.pc,this.r,e,this.endAngle,this.counterClockwise)]}},{key:\"middle\",value:function(){var t=this.counterClockwise===r.CCW?this.startAngle+this.sweep/2:this.startAngle-this.sweep/2;return new r.Arc(this.pc,this.r,this.startAngle,t,this.counterClockwise).end}},{key:\"chordHeight\",value:function(){return(1-Math.cos(Math.abs(this.sweep/2)))*this.r}},{key:\"intersect\",value:function(t){return t instanceof r.Line?t.intersect(this):t instanceof r.Circle?i.intersectArc2Circle(this,t):t instanceof r.Segment?t.intersect(this):t instanceof r.Arc?i.intersectArc2Arc(this,t):void 0}},{key:\"distanceTo\",value:function(e){var n=r.Distance;if(e instanceof r.Point){var i=n.point2arc(e,this),s=t(i,2),c=s[0],h=s[1];return[c,h=h.reverse()]}if(e instanceof r.Circle){var o=n.arc2circle(this,e),a=t(o,2);return[a[0],a[1]]}if(e instanceof r.Line){var l=n.arc2line(this,e),u=t(l,2);return[u[0],u[1]]}if(e instanceof r.Segment){var f=n.segment2arc(e,this),g=t(f,2),v=g[0],p=g[1];return[v,p=p.reverse()]}if(e instanceof r.Arc){var d=n.arc2arc(this,e),A=t(d,2);return[A[0],A[1]]}if(e instanceof r.Polygon){var w=n.shape2polygon(this,e),y=t(w,2);return[y[0],y[1]]}if(e instanceof r.PlanarSet){var k=n.shape2planarSet(this,e),C=t(k,2);return[C[0],C[1]]}}},{key:\"breakToFunctional\",value:function(){for(var t=[],e=[0,Math.PI/2,2*Math.PI/2,3*Math.PI/2],n=[this.pc.translate(this.r,0),this.pc.translate(0,this.r),this.pc.translate(-this.r,0),this.pc.translate(0,-this.r)],i=[],s=0;s<4;s++)n[s].on(this)&&i.push(new r.Arc(this.pc,this.r,this.startAngle,e[s],this.counterClockwise));if(0==i.length)t.push(this.clone());else{i.sort(function(t,e){return t.length-e.length});for(var c=0;c<i.length;c++){var h=t.length>0?t[t.length-1]:void 0,o=void 0;o=h?new r.Arc(this.pc,this.r,h.endAngle,i[c].endAngle,this.counterClockwise):new r.Arc(this.pc,this.r,this.startAngle,i[c].endAngle,this.counterClockwise),r.Utils.EQ_0(o.length)||t.push(o.clone())}var a=t.length>0?t[t.length-1]:void 0,l=void 0;l=a?new r.Arc(this.pc,this.r,a.endAngle,this.endAngle,this.counterClockwise):new r.Arc(this.pc,this.r,this.startAngle,this.endAngle,this.counterClockwise),r.Utils.EQ_0(l.length)||t.push(l.clone())}return t}},{key:\"tangentInStart\",value:function(){var t=new r.Vector(this.pc,this.start),e=this.counterClockwise?Math.PI/2:-Math.PI/2;return t.rotate(e).normalize()}},{key:\"tangentInEnd\",value:function(){var t=new r.Vector(this.pc,this.end),e=this.counterClockwise?-Math.PI/2:Math.PI/2;return t.rotate(e).normalize()}},{key:\"reverse\",value:function(){return new i(this.pc,this.r,this.endAngle,this.startAngle,!this.counterClockwise)}},{key:\"definiteIntegral\",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.breakToFunctional().reduce(function(e,n){return e+n.circularSegmentDefiniteIntegral(t)},0)}},{key:\"circularSegmentDefiniteIntegral\",value:function(t){var e=new r.Line(this.start,this.end),n=this.pc.leftTo(e),i=new r.Segment(this.start,this.end).definiteIntegral(t),s=this.circularSegmentArea();return n?i-s:i+s}},{key:\"circularSegmentArea\",value:function(){return.5*this.r*this.r*(this.sweep-Math.sin(this.sweep))}},{key:\"svg\",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{stroke:\"black\",strokeWidth:\"3\",fill:\"none\"},e=this.sweep<=Math.PI?\"0\":\"1\",n=this.counterClockwise?\"1\":\"0\",i=t.stroke,s=t.strokeWidth,c=t.fill;return r.Utils.EQ(this.sweep,2*Math.PI)?new r.Circle(this.pc,this.r).svg(t):'\\n<path d=\"M'+this.start.x+\",\"+this.start.y+\"\\n A\"+this.r+\",\"+this.r+\" 0 \"+e+\",\"+n+\" \"+this.end.x+\",\"+this.end.y+'\"\\n stroke=\"'+i+'\" stroke-width=\"'+s+'\" fill=\"'+c+'\"/>'}},{key:\"sweep\",get:function(){if(r.Utils.EQ(this.startAngle,this.endAngle))return 0;if(r.Utils.EQ(Math.abs(this.startAngle-this.endAngle),r.PIx2))return r.PIx2;var t=void 0;return t=this.counterClockwise?r.Utils.GT(this.endAngle,this.startAngle)?this.endAngle-this.startAngle:this.endAngle-this.startAngle+r.PIx2:r.Utils.GT(this.startAngle,this.endAngle)?this.startAngle-this.endAngle:this.startAngle-this.endAngle+r.PIx2,r.Utils.GT(t,r.PIx2)&&(t-=r.PIx2),r.Utils.LT(t,0)&&(t+=r.PIx2),t}},{key:\"start\",get:function(){return new r.Point(this.pc.x+this.r,this.pc.y).rotate(this.startAngle,this.pc)}},{key:\"end\",get:function(){return new r.Point(this.pc.x+this.r,this.pc.y).rotate(this.endAngle,this.pc)}},{key:\"center\",get:function(){return this.pc.clone()}},{key:\"vertices\",get:function(){return[this.start.clone(),this.end.clone()]}},{key:\"length\",get:function(){return Math.abs(this.sweep*this.r)}},{key:\"box\",get:function(){var t=this.breakToFunctional().reduce(function(t,e){return t.merge(e.start.box)},new r.Box);return t=t.merge(this.end.box)}}],[{key:\"intersectArc2Arc\",value:function(t,e){var n=[];if(t.box.notIntersect(e.box))return n;if(t.pc.equalTo(e.pc)&&r.Utils.EQ(t.r,e.r)){var i=void 0;return(i=t.start).on(e)&&n.push(i),(i=t.end).on(e)&&n.push(i),(i=e.start).on(t)&&n.push(i),(i=e.end).on(t)&&n.push(i),n}var s=new r.Circle(t.pc,t.r),c=new r.Circle(e.pc,e.r),h=s.intersect(c),o=!0,a=!1,l=void 0;try{for(var u,f=h[Symbol.iterator]();!(o=(u=f.next()).done);o=!0){var g=u.value;g.on(t)&&g.on(e)&&n.push(g)}}catch(t){a=!0,l=t}finally{try{!o&&f.return&&f.return()}finally{if(a)throw l}}return n}},{key:\"intersectArc2Circle\",value:function(t,e){var n=[];if(t.box.notIntersect(e.box))return n;if(e.pc.equalTo(t.pc)&&r.Utils.EQ(e.r,t.r))return n.push(t.start),n.push(t.end),n;var i=e,s=new r.Circle(t.pc,t.r),c=i.intersect(s),h=!0,o=!1,a=void 0;try{for(var l,u=c[Symbol.iterator]();!(h=(l=u.next()).done);h=!0){var f=l.value;f.on(t)&&n.push(f)}}catch(t){o=!0,a=t}finally{try{!h&&u.return&&u.return()}finally{if(o)throw a}}return n}}]),i}(),r.arc=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return new(Function.prototype.bind.apply(r.Arc,[null].concat(e)))}};"},"hash":"1efb43980e0143e923fa508cb30bb714","cacheData":{"env":{}}}