plotboilerplate
Version:
A simple javascript plotting boilerplate for 2d stuff.
1 lines • 128 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor(){for(var e in this.draggable=!0,this.selectable=!0,this.isSelected=!1,this.visible=!0,t.model)this[e]=t.model[e]}}t.model={draggable:!0,selectable:!0,isSelected:!1,visible:!0};class e{static next(){return""+e.current++}}e.current=0;class s{constructor(t){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[],this.vertex=t}addClickListener(t){return s._addListener(this.click,t),this}removeClickListener(t){return this.click=s._removeListener(this.click,t),this}addDragListener(t){return s._addListener(this.drag,t),this}removeDragListener(t){return this.drag=s._removeListener(this.drag,t),this}addDragStartListener(t){return s._addListener(this.dragStart,t),this}removeDragStartListener(t){return this.dragStart=s._removeListener(this.dragStart,t),this}addDragEndListener(t){return s._addListener(this.dragEnd,t),this}removeDragEndListener(t){return this.dragEnd=s._removeListener(this.dragEnd,t),this}fireClickEvent(t){s._fireEvent(this,this.click,t)}fireDragEvent(t){s._fireEvent(this,this.drag,t)}fireDragStartEvent(t){s._fireEvent(this,this.dragStart,t)}fireDragEndEvent(t){s._fireEvent(this,this.dragEnd,t)}removeAllListeners(){this.click=[],this.drag=[],this.dragStart=[],this.dragEnd=[]}static _fireEvent(t,e,s){const i=s;for(var r in void 0===i.params?i.params={vertex:t.vertex}:i.params.vertex=t.vertex,e)e[r](i)}static _addListener(t,e){for(var s in t)if(t[s]==e)return!1;return t.push(e),!0}static _removeListener(t,e){for(var s=0;s<t.length;s++)if(t[s]==e)return t.splice(s,1);return t}}class i extends o{constructor(t,e){super(t,e,((t,e)=>new i(t,e))),this.className="Vector"}perp(){var t=this.clone();return t.sub(this.a),(t=new i(new h,new h(-t.b.y,t.b.x))).a.add(this.a),t.b.add(this.a),t}inverse(){var t=this.a;return this.a=this.b,this.b=t,this}inv(){return this.b.x=this.a.x-(this.b.x-this.a.x),this.b.y=this.a.y-(this.b.y-this.a.y),this}intersection(t){var e=this.denominator(t);if(0==e)return null;var s=this.a.y-t.a.y,i=this.a.x-t.a.x,r=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*i,n=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*i;return s=r/e,i=n/e,new h(this.a.x+s*(this.b.x-this.a.x),this.a.y+s*(this.b.y-this.a.y))}getOrthogonal(){const t=this.a.clone(),e=this.b.clone().sub(this.a),s=e.x;return e.x=-e.y,e.y=s,new i(t,e.add(this.a))}}i.utils={buildArrowHead:(t,e,s,i,r)=>{const n=Math.atan2((e.y-t.y)*r,(e.x-t.x)*i),a=[];return a.push(new h(e.x*i-s*Math.cos(n),e.y*r-s*Math.sin(n))),a.push(new h(e.x*i-1.35*s*Math.cos(n-Math.PI/8),e.y*r-1.35*s*Math.sin(n-Math.PI/8))),a.push(new h(e.x*i,e.y*r)),a.push(new h(e.x*i-1.35*s*Math.cos(n+Math.PI/8),e.y*r-1.35*s*Math.sin(n+Math.PI/8))),a}};class r{constructor(t,s){this.className="Circle",this.uid=e.next(),this.center=t,this.radius=s}containsPoint(t){return this.center.distance(t)<this.radius}containsCircle(t){return this.center.distance(t.center)+t.radius<this.radius}lineDistance(t){return t.getClosestPoint(this.center).distance(this.center)-this.radius}vertAt(t){return r.circleUtils.vertAt(t,this.radius).add(this.center)}tangentAt(t){const e=r.circleUtils.vertAt(t,this.radius);return new i(e,new h(0,0)).add(this.center).perp()}circleIntersection(t){if(this.center.distance(t.center)>this.radius+t.radius)return null;if(this.center.distance(t.center)<Math.abs(this.radius-t.radius))return null;var e=this.center,s=t.center,i=e.distance(s),r=(this.radius*this.radius-t.radius*t.radius+i*i)/(2*i),n=Math.sqrt(this.radius*this.radius-r*r),a=s.clone().scale(r/i,e),o=a.x+n*(s.y-e.y)/i,c=a.y-n*(s.x-e.x)/i,d=a.x-n*(s.y-e.y)/i,u=a.y+n*(s.x-e.x)/i;return new l(new h(o,c),new h(d,u))}lineIntersection(t,e){const s=new h,i=new h,r=new h(t).sub(this.center),n=new h(e).sub(this.center),a=r.difference(n);0===Math.abs(a.y)&&(a.y=1e-6);const o=r.distance(n),c=r.x*n.y-r.y*n.x,d=o*o;if(this.radius*this.radius*d-c*c<0)return null;const u=this.radius*this.radius*o*o-c*c,g=Math.sqrt(u);return s.x=(c*a.y+Math.sign(a.y)*a.x*g)/d,i.x=(c*a.y-Math.sign(a.y)*a.x*g)/d,s.y=(-c*a.x+Math.abs(a.y)*g)/d,i.y=(-c*a.x-Math.abs(a.y)*g)/d,new l(s.add(this.center),i.add(this.center))}closestPoint(t){const e=this.lineIntersection(this.center,t);return e?e.a.distance(t)<e.b.distance(t)?e.a:e.b:new h}destroy(){this.center.destroy(),this.isDestroyed=!0}}r.circleUtils={vertAt:(t,e)=>new h(Math.cos(t)*e,Math.sin(t)*e)};class n{constructor(t,s,i){this.className="Triangle",this.uid=e.next(),this.a=t,this.b=s,this.c=i,this.calcCircumcircle()}static fromArray(t){if(t.length<3)throw`Cannot create triangle from array with less than three vertices (${t.length})`;return new n(t[0],t[1],t[2])}getArea(){return Math.abs(n.utils.signedArea(this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y))}getCentroid(){return new h((this.a.x+this.b.x+this.c.x)/3,(this.a.y+this.b.y+this.c.y)/3)}scaleToCentroid(t){let e=this.getCentroid();return this.a.scale(t,e),this.b.scale(t,e),this.c.scale(t,e),this}getCircumcircle(){return this.calcCircumcircle(),new r(this.center.clone(),this.radius)}isAdjacent(t){var e=this.a.equals(t.a)||this.a.equals(t.b)||this.a.equals(t.c),s=this.b.equals(t.a)||this.b.equals(t.b)||this.b.equals(t.c),i=this.c.equals(t.a)||this.c.equals(t.b)||this.c.equals(t.c);return e&&s||e&&i||s&&i}getThirdVertex(t,e){return this.a.equals(t)&&this.b.equals(e)||this.a.equals(e)&&this.b.equals(t)?this.c:this.b.equals(t)&&this.c.equals(e)||this.b.equals(e)&&this.c.equals(t)?this.a:this.b}calcCircumcircle(){const t=this.b.x-this.a.x,e=this.b.y-this.a.y,s=this.c.x-this.a.x,i=this.c.y-this.a.y,r=t*(this.a.x+this.b.x)+e*(this.a.y+this.b.y),a=s*(this.a.x+this.c.x)+i*(this.a.y+this.c.y),o=2*(t*(this.c.y-this.b.y)-e*(this.c.x-this.b.x));let l,c;if(Math.abs(o)<n.EPSILON){const t=this.bounds();this.center=new h((t.min.x+t.max.x)/2,(t.min.y+t.max.y)/2),l=this.center.x-t.min.x,c=this.center.y-t.min.y}else{const n=(i*r-e*a)/o,d=(t*a-s*r)/o;this.center=new h(n,d),l=this.center.x-this.a.x,c=this.center.y-this.a.y}this.radius_squared=l*l+c*c,this.radius=Math.sqrt(this.radius_squared)}inCircumcircle(t){const e=this.center.x-t.x,s=this.center.y-t.y;return e*e+s*s<=this.radius_squared}bounds(){return new d(new h(n.utils.min3(this.a.x,this.b.x,this.c.x),n.utils.min3(this.a.y,this.b.y,this.c.y)),new h(n.utils.max3(this.a.x,this.b.x,this.c.x),n.utils.max3(this.a.y,this.b.y,this.c.y)))}toPolygon(){return new c([this.a,this.b,this.c])}determinant(){return n.utils.determinant(this.a,this.b,this.c)}containsPoint(t){return n.utils.pointIsInTriangle(t.x,t.y,this.a.x,this.a.y,this.b.x,this.b.y,this.c.x,this.c.y)}getIncircularTriangle(){const t=new l(this.a,this.b),e=new l(this.b,this.c),s=new l(this.c,this.a),i=a.nsectAngle(this.b,this.a,this.c,2)[0],r=a.nsectAngle(this.c,this.b,this.a,2)[0],h=i.intersection(r),o=t.getClosestPoint(h),c=e.getClosestPoint(h),d=s.getClosestPoint(h);return new n(o,c,d)}getIncircle(){return this.getIncircularTriangle().getCircumcircle()}getIncenter(){return this.center&&this.radius||this.calcCircumcircle(),this.center.clone()}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+", c : "+this.c.toString()+"}"}destroy(){this.a.destroy(),this.b.destroy(),this.c.destroy(),this.isDestroyed=!0}}n.EPSILON=1e-6,n.utils={max3:(t,e,s)=>t>=e&&t>=s?t:e>=t&&e>=s?e:s,min3:(t,e,s)=>t<=e&&t<=s?t:e<=t&&e<=s?e:s,signedArea:(t,e,s,i,r,n)=>.5*(-i*r+e*(-s+r)+t*(i-n)+s*n),pointIsInTriangle(t,e,s,i,r,a,h,o){var l=n.utils.signedArea(s,i,r,a,h,o),c=1/(2*l)*(i*h-s*o+(o-i)*t+(s-h)*e),d=1/(2*l)*(s*a-i*r+(i-a)*t+(r-s)*e);return c>0&&d>0&&1-c-d>0},determinant:(t,e,s)=>(e.y-t.y)*(s.x-e.x)-(s.y-e.y)*(e.x-t.x)};const a={mapAngleTo2PI(t){const e=Math.asin(Math.sin(t));return Math.cos(t)<0?Math.PI-e:e<0?e+2*Math.PI:e},dist4:(t,e,s,i)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-i,2)),dotProduct:(t,e)=>t.x*e.x+t.y*e.y,nsectAngle(t,e,s,i){const r=new n(t,e,s),a=new l(t,e),h=new l(t,s);var o=a.angle(h);const c=r.determinant()>0;o<0&&(o=2*Math.PI+o),c||(o=-1*(2*Math.PI-o));const d=Math.max(a.length(),h.length())/a.length();for(var u=[],g=1;g<i;g++)u.push(new l(t,e.clone().rotate(o/i*-g,t)).scale(d));return u},wrapMax:(t,e)=>(e+t%e)%e,wrapMinMax:(t,e,s)=>e+a.wrapMax(t-e,s-e)};class h{constructor(i,r){if(this.className="Vertex",this.uid=e.next(),void 0===i)this.x=0,this.y=0;else if("number"==typeof i&&"number"==typeof r)this.x=i,this.y=r;else{const t=i;"number"==typeof t.x&&"number"==typeof t.y?(this.x=t.x,this.y=t.y):(this.x="number"==typeof i?i:void 0===i?0:NaN,this.y="number"==typeof r?r:void 0===r?0:NaN)}this.attr=new t,this.listeners=new s(this)}set(t,e){if("number"==typeof t&&"number"==typeof e)this.x=t,this.y=e;else{const s=t;"number"==typeof s.x&&"number"==typeof s.y?(this.x=s.x,this.y=s.y):(this.x="number"==typeof t?t:void 0===t?0:NaN,this.y="number"==typeof e?e:void 0===e?0:NaN)}return this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}invX(){return this.x=-this.x,this}invY(){return this.y=-this.y,this}add(t,e){if("number"==typeof t&&"number"==typeof e)this.x+=t,this.y+=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x+=s.x,this.y+=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x+=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y+=e}}return this}addXY(t,e){return this.x+=t,this.y+=e,this}addX(t){return this.x+=t,this}addY(t){return this.y+=t,this}sub(t,e){if("number"==typeof t&&"number"==typeof e)this.x-=t,this.y-=e;else{const s=t;if("number"==typeof s.x&&"number"==typeof s.y)this.x-=s.x,this.y-=s.y;else{if("number"!=typeof t)throw`Cannot add ${typeof t} to numeric x component!`;if(this.x-=t,"number"!=typeof e)throw`Cannot add ${typeof e} to numeric y component!`;this.y-=e}}return this}subXY(t,e){return this.x-=t,this.y-=e,this}subX(t){return this.x-=t,this}subY(t){return this.y-=t,this}equals(t){var e=Math.abs(this.x-t.x)<h.EPSILON,s=Math.abs(this.y-t.y)<h.EPSILON;return e&&s}clone(){return new h(this.x,this.y)}distance(t){return a.dist4(this.x,this.y,t.x,t.y)}angle(t){const e=void 0===t?Math.PI/2-Math.atan2(this.x,this.y):Math.PI/2-Math.atan2(t.x-this.x,t.y-this.y);return e<0?2*Math.PI+e:e}difference(t){return new h(t.x-this.x,t.y-this.y)}scale(t,e){return this.scaleXY({x:t,y:t},e)}lerp(t,e){var s=this.difference(t);return this.x+=s.x*e,this.y+=s.y*e,this}lerpAbs(t,e){var s=this.distance(t),i=this.difference(t),r=i.x/s,n=i.y/s;return this.x+=r*e,this.y+=n*e,this}scaleXY(t,e){return e&&void 0!==e||(e={x:0,y:0}),this.x=e.x+(this.x-e.x)*t.x,this.y=e.y+(this.y-e.y)*t.y,this}rotate(t,e){e&&void 0!==e||(e={x:0,y:0}),this.sub(e),t+=Math.atan2(this.y,this.x);let s=this.distance(h.ZERO);return this.x=s*Math.cos(t),this.y=s*Math.sin(t),this.add(e),this}multiplyScalar(t){return this.x*=t,this.y*=t,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}inv(){return this.x=-this.x,this.y=-this.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}toString(t){return void 0===t?"("+this.x+","+this.y+")":"("+this.x.toFixed(t)+","+this.y.toFixed(t)+")"}destroy(){this.listeners.removeAllListeners(),this.isDestroyed=!0}static randomVertex(t){return new h(t.min.x+Math.random()*(t.max.x-t.min.x),t.min.y+Math.random()*(t.max.y-t.min.y))}}h.ZERO=new h(0,0),h.EPSILON=1e-6,h.utils={buildArrowHead:(t,e,s,i,r)=>{console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");var n=Math.atan2((e.y-t.y)*r,(e.x-t.x)*i),a=[];return a.push(new h(e.x*i-s*Math.cos(n),e.y*r-s*Math.sin(n))),a.push(new h(e.x*i-1.35*s*Math.cos(n-Math.PI/8),e.y*r-1.35*s*Math.sin(n-Math.PI/8))),a.push(new h(e.x*i,e.y*r)),a.push(new h(e.x*i-1.35*s*Math.cos(n+Math.PI/8),e.y*r-1.35*s*Math.sin(n+Math.PI/8))),a},arrayToJSON:(t,e)=>JSON.stringify(t.map((function(t){return void 0===typeof e?{x:t.x,y:t.y}:{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}})))};class o{constructor(t,s,i){this.uid=e.next(),this.a=t,this.b=s,this.factory=i}length(){return Math.sqrt(Math.pow(this.b.x-this.a.x,2)+Math.pow(this.b.y-this.a.y,2))}setLength(t){return this.scale(t/this.length())}sub(t){return this.a.sub(t),this.b.sub(t),this}add(t){return this.a.add(t),this.b.add(t),this}normalize(){return this.b.set(this.a.x+(this.b.x-this.a.x)/this.length(),this.a.y+(this.b.y-this.a.y)/this.length()),this}scale(t){return this.b.set(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t),this}moveTo(t){let e=this.a.difference(t);return this.a.add(e),this.b.add(e),this}angle(t){null!=t&&void 0!==t||(t=this.factory(new h(0,0),new h(100,0)));const e=this.b.clone().sub(this.a),s=t.b.clone().sub(t.a);return Math.atan2(s.x,s.y)-Math.atan2(e.x,e.y)}vertAt(t){return new h(this.a.x+(this.b.x-this.a.x)*t,this.a.y+(this.b.y-this.a.y)*t)}denominator(t){return(t.b.y-t.a.y)*(this.b.x-this.a.x)-(t.b.x-t.a.x)*(this.b.y-this.a.y)}colinear(t,e){return Math.abs(this.denominator(t))<(void 0===e?h.EPSILON:e)}getClosestT(t){var e=o.vtutils.dist2(this.a,this.b);return 0===e?0:((t.x-this.a.x)*(this.b.x-this.a.x)+(t.y-this.a.y)*(this.b.y-this.a.y))/e}hasPoint(t,e,s){const i=this.getClosestT(t),r=Math.sqrt(o.vtutils.dist2(t,this.vertAt(i)));return void 0!==e&&e?r<(null!=s?s:h.EPSILON)&&i>=0&&i<=1:r<(null!=s?s:h.EPSILON)}getClosestPoint(t){var e=this.getClosestT(t);return this.vertAt(e)}pointDistance(t){return Math.sqrt(o.vtutils.dist2(t,this.vertAt(this.getClosestT(t))))}clone(){return this.factory(this.a.clone(),this.b.clone())}toString(){return"{ a : "+this.a.toString()+", b : "+this.b.toString()+" }"}destroy(){this.a.destroy(),this.b.destroy(),this.isDestroyed=!0}}o.vtutils={dist2:(t,e)=>(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)};class l extends o{constructor(t,e){super(t,e,((t,e)=>new l(t,e))),this.className="Line"}intersection(t){const e=this.denominator(t);if(0==e)return null;let s=this.a.y-t.a.y,i=this.a.x-t.a.x;const r=(t.b.x-t.a.x)*s-(t.b.y-t.a.y)*i,n=(this.b.x-this.a.x)*s-(this.b.y-this.a.y)*i;s=r/e,i=n/e;const a=this.a.x+s*(this.b.x-this.a.x),o=this.a.y+s*(this.b.y-this.a.y);return isNaN(s)||isNaN(a)||isNaN(o)?null:new h(a,o)}getStartPoint(){return this.a}getEndPoint(){return this.b}getStartTangent(){return this.b}getEndTangent(){return this.a}reverse(){var t=this.a;return this.a=this.b,this.b=t,this}}class c{constructor(t,s){this.className="Polygon",this.uid=e.next(),void 0===t&&(t=[]),this.vertices=t,this.isOpen=s||!1}addVertex(t){this.vertices.push(t)}addVertexAt(t,e){this.vertices.splice(e,0,t)}getEdgeAt(t){return new l(this.getVertexAt(t),this.getVertexAt(t+1))}getEdges(){const t=[];for(var e=0;e+1<this.vertices.length;e++)t.push(this.getEdgeAt(e));return!this.isOpen&&this.vertices.length>0&&t.push(this.getEdgeAt(this.vertices.length-1)),t}getInnerAngleAt(t){const e=this.vertices[t],s=this.vertices[(t+this.vertices.length-1)%this.vertices.length].clone(),i=this.vertices[(t+1)%this.vertices.length].clone(),r=this.isAngleAcute(t),n=new h(0,0),o=new h(e.x-s.x,e.y-s.y),l=new h(i.x-e.x,i.y-e.y),c=n.distance(o),d=n.distance(l),u=a.dotProduct(o,l),g=c*d;return r?Math.PI-Math.acos(u/g):Math.PI+Math.acos(u/g)}isAngleAcute(t){const e=this.vertices[(t+this.vertices.length-1)%this.vertices.length].clone(),s=this.vertices[t],i=this.vertices[(t+1)%this.vertices.length].clone();return n.utils.determinant(e,s,i)<0}getVertexAt(t){return t<0?this.vertices[this.vertices.length-Math.abs(t)%this.vertices.length]:this.vertices[t%this.vertices.length]}move(t){for(var e in this.vertices)this.vertices[e].add(t);return this}containsVert(t){for(var e=!1,s=0,i=this.vertices.length-1;s<this.vertices.length;i=s++){let r=this.vertices[s].x,n=this.vertices[s].y,a=this.vertices[i].x,h=this.vertices[i].y;n>t.y!=h>t.y&&t.x<(a-r)*(t.y-n)/(h-n)+r&&(e=!e)}return e}containsVerts(t){return t.every((t=>this.containsVert(t)))}containsPolygon(t){for(var e=0;e<t.vertices.length;e++)if(!this.containsVert(t.vertices[e]))return!1;const s=new l(new h,new h);for(e=0;e<t.vertices.length;e++)if(s.a.set(t.vertices[e]),s.b.set(t.vertices[(e+1)%t.vertices.length]),this.lineIntersections(s,!0).length>0)return!1;return!0}area(){return c.utils.area(this.vertices)}signedArea(){return c.utils.signedArea(this.vertices)}isClockwise(){return c.utils.isClockwise(this.vertices)}perimeter(){let t=0;for(var e=1;e<this.vertices.length;e++)t+=this.vertices[e-1].distance(this.vertices[e]);return!this.isOpen&&this.vertices.length>1&&(t+=this.vertices[0].distance(this.vertices[this.vertices.length-1])),t}scale(t,e){for(var s in this.vertices)"function"==typeof this.vertices[s].scale?this.vertices[s].scale(t,e):console.log("There seems to be a null vertex!",this.vertices[s]);return this}rotate(t,e){for(var s in this.vertices)this.vertices[s].rotate(t,e);return this}getMeanCenter(){if(0===this.vertices.length)return null;const t=this.vertices[0].clone();for(var e=1;e<this.vertices.length;e++)t.add(this.vertices[e]);return t.x/=this.vertices.length,t.y/=this.vertices.length,t}lineIntersections(t,e=!1){const s=[];for(var i=0;i<this.vertices.length;i++){const r=new l(this.vertices[i],this.vertices[(i+1)%this.vertices.length]),n=r.intersection(t);this.isOpen&&i+1===this.vertices.length||null===n||!r.hasPoint(n,!0)||e&&!t.hasPoint(n,e)||s.push(n)}return s}closestLineIntersection(t,e=!1){const s=this.lineIntersections(t,e);if(s.length<=0)return null;let i=new h(Number.MAX_VALUE,Number.MAX_VALUE),r=Number.MAX_VALUE;for(var n in s){const e=s[n],a=e.distance(t.a);a<r&&(r=a,i=e)}return i}getInterpolationPolygon(t){const e=[];for(var s=0;s<this.vertices.length;s++){const r=this.vertices[s],n=this.vertices[(s+1)%this.vertices.length];if(e.push(r.clone()),!this.isOpen||s+1!==this.vertices.length){const s=1/(t+1);for(var i=1;i<=t;i++)e.push(r.clone().lerp(n,s*i))}}return new c(e,this.isOpen)}getEvenDistributionPolygon(t){if(t<=0)throw new Error("pointCount must be larger than zero; is "+t+".");const e=new c([],this.isOpen);if(0===this.vertices.length)return e;let s=new h(this.vertices[0]);if(e.vertices.push(s),1===this.vertices.length)return e;const i=this.perimeter()/t,r=this.vertices.length;let n=1,a=new h(this.vertices[1]),o=s.distance(a),l=this.isOpen?r:r+1,d=i;for(var u=1;u<t&&n<l;)if(d<o){let t=s.clone().lerpAbs(a,d);e.vertices.push(t),d+=i,u++}else n++,s=a,a=new h(this.vertices[n%r]),d-=o,o=s.distance(a);return e}getBounds(){return d.computeFromVertices(this.vertices)}clone(){return new c(this.vertices.map((t=>t.clone())),this.isOpen)}elimitateColinearEdges(t){const e=void 0===t?1:t,s=this.vertices.slice();let i=0;for(var r=new l(new h,new h),n=new l(new h,new h);i+1<s.length&&s.length>2;){const t=s[i],a=s[(i+1)%s.length];r.a=t,r.b=a,n.a=a;let h=!1,o=i+2;do{let t=s[o%s.length];n.b=t,h=r.colinear(n,e),h&&o++}while(h);o-i>2&&s.splice(i+1,o-i-2),i++}return new c(s,this.isOpen)}toQuadraticBezierData(){if(this.vertices.length<3)return[];var t=[],e=this.vertices[0],s=this.vertices[1],i=new h(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(i);for(var r=this.isOpen?this.vertices.length:this.vertices.length+1,n=1;n<r;n++){e=this.vertices[n%this.vertices.length],s=this.vertices[(n+1)%this.vertices.length];i=new h(e.x+(s.x-e.x)/2,e.y+(s.y-e.y)/2);t.push(e),t.push(i),e=s}return t}toQuadraticBezierSVGString(){var t=this.toQuadraticBezierData();if(0==t.length)return"";for(var e=["M "+t[0].x+" "+t[0].y],s=1;s<t.length;s+=2)e.push("Q "+t[s].x+" "+t[s].y+", "+t[s+1].x+" "+t[s+1].y);return e.join(" ")}toCubicBezierData(t){if(void 0===t&&(t=1),this.vertices.length<3)return[];var e=[],s=this.vertices[0],i=this.vertices[1],r=new h(s.x+(i.x-s.x)/2,s.y+(i.y-s.y)/2);e.push(r);for(var n=this.isOpen?this.vertices.length-1:this.vertices.length,a=0;a<n;a++){s=this.vertices[a%this.vertices.length],i=this.vertices[(a+1)%this.vertices.length];var o=this.vertices[(a+2)%this.vertices.length],l=new h(s.x+(i.x-s.x)/2,s.y+(i.y-s.y)/2),c=new h(i.x+(o.x-i.x)/2,i.y+(o.y-i.y)/2),d=new h(l.x+(i.x-l.x)*t,l.y+(i.y-l.y)*t),u=new h(c.x+(i.x-c.x)*t,c.y+(i.y-c.y)*t);e.push(d),e.push(u),e.push(c)}return e}toCubicBezierSVGString(t){var e=this.toCubicBezierData(t);if(0==e.length)return"";for(var s=["M "+e[0].x+" "+e[0].y],i=1;i<e.length;i+=3)s.push("C "+e[i].x+" "+e[i].y+", "+e[i+1].x+" "+e[i+1].y+", "+e[i+2].x+" "+e[i+2].y);return s.join(" ")}toCubicBezierPath(t){for(var e=this.toCubicBezierData(t),s=[],i=0;i+3<e.length;i+=3)s.push([e[i],e[i+3],e[i+1],e[i+2]]);return g.fromArray(s)}destroy(){for(var t=0;t<this.vertices.length;t++)this.vertices[t].destroy();this.isDestroyed=!0}}c.utils={area(t){let e=0;for(var s=0,i=t.length;s<i;s++){e+=t[s].x*t[(s+1)%i].y*.5,e-=t[(s+1)%i].x*t[s].y*.5}return Math.abs(e)},isClockwise:t=>c.utils.signedArea(t)<0,signedArea(t){let e=0;const s=t.length;for(var i=0;i<s;i++){const r=(i+1)%s;e+=(t[r].x-t[i].x)*(t[i].y+t[r].y)}return e}};class d{constructor(t,e){this.min=t,this.max=e,this.width=e.x-t.x,this.height=e.y-t.y}toPolygon(){return new c([new h(this.min),new h(this.max.x,this.min.y),new h(this.max),new h(this.min.x,this.max.y)],!1)}getCenter(){return new h(this.min.x+(this.max.x-this.min.x)/2,this.min.y+(this.max.y-this.min.y)/2)}randomPoint(t=0,e=0){const s=t>0&&t<1?this.width*t:t,i=e>0&&e<1?this.height*e:e;return new h(this.min.x+s+Math.random()*(this.width-2*s),this.min.y+i+Math.random()*(this.height-2*i))}toString(){return`{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`}clone(){return new d({x:this.min.x,y:this.min.y},{x:this.max.x,y:this.max.y})}static computeFromVertices(t){if(0==t.length)return new d(new h(0,0),new h(0,0));let e,s=t[0].x,i=t[0].x,r=t[0].y,n=t[0].y;for(var a in t)e=t[a],s=Math.min(s,e.x),i=Math.max(i,e.x),r=Math.min(r,e.y),n=Math.max(n,e.y);return new d(new h(s,r),new h(i,n))}static fromDimension(t,e,s){return new d(null!=s?s:{x:0,y:0},{x:(s?s.x:0)+t,y:(s?s.y:0)+e})}}class u{constructor(t,s,i,r){this.START_POINT=u.START_POINT,this.START_CONTROL_POINT=u.START_CONTROL_POINT,this.END_CONTROL_POINT=u.END_CONTROL_POINT,this.END_POINT=u.END_POINT,this.uid=e.next(),this.startPoint=t,this.startControlPoint=i,this.endPoint=s,this.endControlPoint=r,this.curveIntervals=30,this.segmentCache=[],this.segmentLengths=[],this.updateArcLengths()}moveCurvePoint(t,e,s,i){t==this.START_POINT?(this.getStartPoint().add(e),s&&this.getStartControlPoint().add(e)):t==this.START_CONTROL_POINT?this.getStartControlPoint().add(e):t==this.END_CONTROL_POINT?this.getEndControlPoint().add(e):t==this.END_POINT?(this.getEndPoint().add(e),s&&this.getEndControlPoint().add(e)):console.log(`[CubicBezierCurve.moveCurvePoint] pointID '${t}' invalid.`),i&&this.updateArcLengths()}translate(t){return this.startPoint.add(t),this.startControlPoint.add(t),this.endControlPoint.add(t),this.endPoint.add(t),this}reverse(){let t=this.startPoint;return this.startPoint=this.endPoint,this.endPoint=t,t=this.startControlPoint,this.startControlPoint=this.endControlPoint,this.endControlPoint=t,this}getLength(){return this.arcLength}updateArcLengths(){let t=this.startPoint.clone(),e=new h(0,0),s=1/this.curveIntervals;this.segmentCache=[],this.segmentCache.push(this.startPoint),this.segmentLengths=[];let i=0;var r=0;let n;for(;r<=1;)e=this.getPointAt(r),this.segmentCache.push(e),n=t.distance(e),this.segmentLengths.push(n),i+=n,t=e,r+=s;this.arcLength=i}getClosestT(t){var e={t:0,tPrev:0,tNext:1},s=0;do{e=this.locateIntervalByDistance(t,e.tPrev,e.tNext,this.curveIntervals),s++}while(s<4&&this.getPointAt(e.tPrev).distance(this.getPointAt(e.tNext))>1);return e.t}locateIntervalByDistance(t,e,s,i){var r=-1,n=0,a=0;const h=s-e;for(var o=0;o<=i;o++){a=e+h*(o/i);var l=this.getPointAt(a).distance(t);(-1==r||l<n)&&(r=o,n=l)}return{t:e+h*(r/i),tPrev:e+h*(Math.max(0,r-1)/i),tNext:e+h*(Math.min(i,r+1)/i)}}getBounds(){var t=new h(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new h(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);let s;for(var i=0;i<this.segmentCache.length;i++)s=this.segmentCache[i],t.x=Math.min(t.x,s.x),t.y=Math.min(t.y,s.y),e.x=Math.max(e.x,s.x),e.y=Math.max(e.y,s.y);return new d(t,e)}getStartPoint(){return this.startPoint}getEndPoint(){return this.endPoint}getStartControlPoint(){return this.startControlPoint}getEndControlPoint(){return this.endControlPoint}getPointByID(t){if(t==this.START_POINT)return this.startPoint;if(t==this.END_POINT)return this.endPoint;if(t==this.START_CONTROL_POINT)return this.startControlPoint;if(t==this.END_CONTROL_POINT)return this.endControlPoint;throw new Error(`Invalid point ID '${t}'.`)}getPointAt(t){const e=this.startPoint.x*Math.pow(1-t,3)+3*this.startControlPoint.x*t*Math.pow(1-t,2)+3*this.endControlPoint.x*Math.pow(t,2)*(1-t)+this.endPoint.x*Math.pow(t,3),s=this.startPoint.y*Math.pow(1-t,3)+3*this.startControlPoint.y*t*Math.pow(1-t,2)+3*this.endControlPoint.y*Math.pow(t,2)*(1-t)+this.endPoint.y*Math.pow(t,3);return new h(e,s)}getPoint(t){return this.getPointAt(t/this.arcLength)}getTangentAt(t){const e=this.getStartPoint(),s=this.getStartControlPoint(),i=this.getEndControlPoint(),r=this.getEndPoint(),n=t*t,a=1-2*t+n,o=-3*e.x*a+s.x*(3*a-6*(t-n))+i.x*(6*(t-n)-3*n)+3*r.x*n,l=-3*e.y*a+s.y*(3*a-6*(t-n))+i.y*(6*(t-n)-3*n)+3*r.y*n;return new h(o,l)}trimStart(t){return this.trimStartAt(this.convertU2T(t))}trimStartAt(t){const e=u.utils.getSubCurvePointsAt(this,t,1);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}trimEnd(t){return this.trimEndAt(this.convertU2T(t))}trimEndAt(t){const e=u.utils.getSubCurvePointsAt(this,0,t);return this.startPoint.set(e[0]),this.startControlPoint.set(e[2]),this.endPoint.set(e[1]),this.endControlPoint.set(e[3]),this.updateArcLengths(),this}getSubCurve(t,e){return this.getSubCurveAt(this.convertU2T(t),this.convertU2T(e))}getSubCurveAt(t,e){const s=u.utils.getSubCurvePointsAt(this,t,e);return new u(s[0],s[1],s[2],s[3])}convertU2T(t){return Math.max(0,Math.min(1,t/this.arcLength))}getTangent(t){return this.getTangentAt(this.convertU2T(t))}getPerpendicular(t){return this.getPerpendicularAt(this.convertU2T(t))}getPerpendicularAt(t){const e=this.getTangentAt(t);return new h(e.y,-e.x)}clone(){return new u(this.getStartPoint().clone(),this.getEndPoint().clone(),this.getStartControlPoint().clone(),this.getEndControlPoint().clone())}getStartTangent(){return this.startControlPoint}getEndTangent(){return this.endControlPoint}equals(t){return!!t&&(!!(t.startPoint&&t.endPoint&&t.startControlPoint&&t.endControlPoint)&&(this.startPoint.equals(t.startPoint)&&this.endPoint.equals(t.endPoint)&&this.startControlPoint.equals(t.startControlPoint)&&this.endControlPoint.equals(t.endControlPoint)))}destroy(){this.startPoint.destroy(),this.endPoint.destroy(),this.startControlPoint.destroy(),this.endControlPoint.destroy(),this.isDestroyed=!0}static isInstance(t){return t instanceof u}toJSON(t){return"{ "+(t?"\n\t":"")+'"startPoint" : ['+this.getStartPoint().x+","+this.getStartPoint().y+"], "+(t?"\n\t":"")+'"endPoint" : ['+this.getEndPoint().x+","+this.getEndPoint().y+"], "+(t?"\n\t":"")+'"startControlPoint": ['+this.getStartControlPoint().x+","+this.getStartControlPoint().y+"], "+(t?"\n\t":"")+'"endControlPoint" : ['+this.getEndControlPoint().x+","+this.getEndControlPoint().y+"]"+(t?"\n\t":"")+" }"}static fromJSON(t){var e=JSON.parse(t);return u.fromObject(e)}static fromObject(t){if("object"!=typeof t)throw"Can only build from object.";if(!t.startPoint)throw'Object member "startPoint" missing.';if(!t.endPoint)throw'Object member "endPoint" missing.';if(!t.startControlPoint)throw'Object member "startControlPoint" missing.';if(!t.endControlPoint)throw'Object member "endControlPoint" missing.';return new u(new h(t.startPoint[0],t.startPoint[1]),new h(t.endPoint[0],t.endPoint[1]),new h(t.startControlPoint[0],t.startControlPoint[1]),new h(t.endControlPoint[0],t.endControlPoint[1]))}static fromArray(t){if(!Array.isArray(t))throw"Can only build from object.";if(4!=t.length)throw"Can only build from array with four elements.";return new u(t[0],t[1],t[2],t[3])}}u.START_POINT=0,u.START_CONTROL_POINT=1,u.END_CONTROL_POINT=2,u.END_POINT=3,u.utils={getSubCurvePointsAt:(t,e,s)=>{const r=new i(t.getPointAt(e),t.getTangentAt(e)),n=new i(t.getPointAt(s),t.getTangentAt(s).inv());return r.b.add(r.a),n.b.add(n.a),r.scale(.33333333*(s-e)),n.scale(.33333333*(s-e)),[r.a,n.a,r.b,n.b]}};class g{constructor(){this.className="BezierPath",this.START_POINT=0,this.START_CONTROL_POINT=1,this.END_CONTROL_POINT=2,this.END_POINT=3,this.uid=e.next(),this.totalArcLength=0,this.adjustCircular=!1,this.bezierCurves=[]}addCurve(t){if(null==t||void 0===t)throw"Cannot add null curve to bézier path.";this.bezierCurves.push(t),this.bezierCurves.length>1?(t.startPoint=this.bezierCurves[this.bezierCurves.length-2].endPoint,this.adjustSuccessorControlPoint(this.bezierCurves.length-2,!0,!0)):this.totalArcLength+=t.getLength()}locateCurveByStartPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startPoint.equals(t))return e;return-1}locateCurveByEndPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endPoint.equals(t))return e;return-1}locateCurveByStartControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].startControlPoint.equals(t))return e;return-1}locateCurveByEndControlPoint(t){for(var e=0;e<this.bezierCurves.length;e++)if(this.bezierCurves[e].endControlPoint.equals(t))return e;return-1}getLength(){return this.totalArcLength}updateArcLengths(){this.totalArcLength=0;for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].updateArcLengths(),this.totalArcLength+=this.bezierCurves[t].getLength()}getCurveCount(){return this.bezierCurves.length}getCurveAt(t){return this.bezierCurves[t]}translate(t){for(var e=0;e<this.bezierCurves.length;e++){(s=this.bezierCurves[e]).getStartPoint().add(t),s.getStartControlPoint().add(t),s.getEndControlPoint().add(t)}var s;return(s=this.bezierCurves[this.bezierCurves.length-1]).getEndPoint().add(t),this.updateArcLengths(),this}scale(t,e){return this.scaleXY({x:e,y:e},t)}scaleXY(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().scaleXY(t,e),i.getStartControlPoint().scaleXY(t,e),i.getEndControlPoint().scaleXY(t,e)}return this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().scaleXY(t,e),this.updateArcLengths(),this}rotate(t,e){for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];i.getStartPoint().rotate(t,e),i.getStartControlPoint().rotate(t,e),i.getEndControlPoint().rotate(t,e)}this.bezierCurves.length>0&&!this.adjustCircular&&this.bezierCurves[this.bezierCurves.length-1].getEndPoint().rotate(t,e)}getClosestT(t){for(var e=-1,s=0,i=0,r=0,n=0,a=0,h=0;h<this.bezierCurves.length;h++)r=this.bezierCurves[h].getClosestT(t),i=this.bezierCurves[h].getPointAt(r).distance(t),(-1==e||i<s)&&(e=h,s=i,n=a+r*this.bezierCurves[h].getLength()),a+=this.bezierCurves[h].getLength();return Math.max(0,Math.min(1,n/this.totalArcLength))}getPoint(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getPoint(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(t,0)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;if(e>=this.bezierCurves.length)return this.bezierCurves[this.bezierCurves.length-1].getEndPoint().clone();var i=t-s;return this.bezierCurves[e].getPoint(i)}getPointAt(t){return this.getPoint(t*this.totalArcLength)}getTangentAt(t){return this.getTangent(t*this.totalArcLength)}getTangent(t){(t<0||t>this.totalArcLength)&&(console.warn("[BezierPath.getTangent(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));for(var e=0,s=0;e<this.bezierCurves.length&&s+this.bezierCurves[e].getLength()<t;)s+=this.bezierCurves[e].getLength(),e++;var i=t-s;return this.bezierCurves[e].getTangent(i)}getPerpendicularAt(t){return this.getPerpendicular(t*this.totalArcLength)}getPerpendicular(t){(t<0||t>this.totalArcLength)&&(console.log("[BezierPath.getPerpendicular(u)] u is out of bounds: "+t+"."),t=Math.min(this.totalArcLength,Math.max(0,t)));var e=g._locateUIndex(this,t),s=this.bezierCurves[e.i],i=t-e.uPart;return s.getPerpendicular(i)}static _locateUIndex(t,e){for(var s=0,i=0,r=0;s<t.bezierCurves.length&&i+t.bezierCurves[s].getLength()<e;)i+=t.bezierCurves[s].getLength(),s+1<t.bezierCurves.length&&(r+=t.bezierCurves[s].getLength()),s++;return{i:s,uPart:i,uBefore:r}}getSubPathAt(t,e){t=Math.max(0,t),e=Math.min(1,e);let s=t*this.totalArcLength,i=e*this.totalArcLength;var r=g._locateUIndex(this,s),n=g._locateUIndex(this,i),a=(s-r.uBefore)/this.bezierCurves[r.i].getLength();if(r.i==n.i){var h=(i-n.uBefore)/this.bezierCurves[n.i].getLength(),o=this.bezierCurves[r.i].getSubCurveAt(a,h);return g.fromArray([o])}var l=[];if(r.i>n.i){o=this.bezierCurves[r.i].getSubCurveAt(a,0);l.push(o);for(var c=r.i-1;c>n.i;c--)l.push(this.bezierCurves[c].clone().reverse());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(1,h))}else{o=this.bezierCurves[r.i].getSubCurveAt(a,1);l.push(o);for(c=r.i+1;c<n.i&&c<this.bezierCurves.length;c++)l.push(this.bezierCurves[c].clone());h=(i-n.uBefore)/this.bezierCurves[n.i].getLength();l.push(this.bezierCurves[n.i].getSubCurveAt(0,h))}return g.fromArray(l)}moveCurvePoint(t,e,s){if(this.getCurveAt(t).moveCurvePoint(e,s,!0,!0),e==this.START_POINT&&(t>0||this.adjustCircular))this.getCurveAt(t-1<0?this.bezierCurves.length+(t-1):t-1).moveCurvePoint(this.END_CONTROL_POINT,s,!0,!1);else if(e==this.END_POINT&&(t+1<this.bezierCurves.length||this.adjustCircular)){this.getCurveAt((t+1)%this.bezierCurves.length).moveCurvePoint(this.START_CONTROL_POINT,s,!0,!1)}else e==this.START_CONTROL_POINT&&t>0?this.adjustPredecessorControlPoint(t,!0,!1):e==this.END_CONTROL_POINT&&t+1<this.getCurveCount()&&this.adjustSuccessorControlPoint(t,!0,!1);this.updateArcLengths()}adjustPredecessorControlPoint(t,e,s){if(this.adjustCircular||!(t<=0)){var i=this.getCurveAt(t),r=this.getCurveAt(t-1<0?this.getCurveCount()+(t-1):t-1);g.adjustNeighbourControlPoint(i,r,i.getStartPoint(),i.getStartControlPoint(),r.getEndPoint(),r.getEndControlPoint(),e,s)}}adjustSuccessorControlPoint(t,e,s){if(this.adjustCircular||!(t+1>this.getCurveCount())){var i=this.getCurveAt(t),r=this.getCurveAt((t+1)%this.getCurveCount());g.adjustNeighbourControlPoint(i,r,i.getEndPoint(),i.getEndControlPoint(),r.getStartPoint(),r.getStartControlPoint(),e,s)}}static adjustNeighbourControlPoint(t,e,s,i,r,n,a,o){var l=new h(i.x-s.x,i.y-s.y),c=new h(n.x-r.x,n.y-r.y),d=Math.sqrt(Math.pow(l.x,2)+Math.pow(l.y,2)),u=Math.sqrt(Math.pow(c.x,2)+Math.pow(c.y,2));d<=.1||(a?n.set(r.x-l.x*(u/d),r.y-l.y*(u/d)):n.set(r.x-l.x,r.y-l.y),e.updateArcLengths())}getBounds(){const t=new h(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),e=new h(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);for(var s,i=0;i<this.bezierCurves.length;i++)s=this.bezierCurves[i].getBounds(),t.x=Math.min(t.x,s.min.x),t.y=Math.min(t.y,s.min.y),e.x=Math.max(e.x,s.max.x),e.y=Math.max(e.y,s.max.y);return new d(t,e)}getEvenDistributionVertices(t){if(t<2)throw new Error("pointCount must be larger than one; is "+t+".");const e=[];if(0===this.bezierCurves.length)return e;var s=new h(this.bezierCurves[0].startPoint);e.push(s);const i=this.totalArcLength/(t-1),r=this.bezierCurves.length;let n=0,a=this.bezierCurves[0].arcLength,o=i,l=1;for(;l<t&&n<r;)if(o<a){var c=this.bezierCurves[n].getPoint(o);e.push(c),o+=i,l++}else n++,o-=a,a=n<r?this.bezierCurves[n].arcLength:0;return e.push(new h(this.bezierCurves[r-1].endPoint)),e}clone(){for(var t=new g,e=0;e<this.bezierCurves.length;e++)t.bezierCurves.push(this.bezierCurves[e].clone()),e>0&&(t.bezierCurves[e-1].endPoint=t.bezierCurves[e].startPoint);return t.updateArcLengths(),t.adjustCircular=this.adjustCircular,t}equals(t){if(!t)return!1;if(!t.bezierCurves)return!1;if(void 0===t.bezierCurves.length)return!1;if(t.bezierCurves.length!=this.bezierCurves.length)return!1;for(var e=0;e<this.bezierCurves.length;e++)if(!this.bezierCurves[e].equals(t.bezierCurves[e]))return!1;return!0}destroy(){for(var t=0;t<this.bezierCurves.length;t++)this.bezierCurves[t].destroy();this.isDestroyed=!0}toPathPoints(){if(0===this.bezierCurves.length)return[];if(1===this.bezierCurves.length)return[this.bezierCurves[0].startPoint,this.bezierCurves[0].startControlPoint,this.bezierCurves[0].endControlPoint,this.bezierCurves[0].endPoint];const t=[];t.push(this.bezierCurves[0].startPoint),t.push(this.bezierCurves[0].startControlPoint);for(var e=1;e<this.bezierCurves.length;e++)t.push(this.bezierCurves[e-1].endControlPoint),t.push(this.bezierCurves[e-1].endPoint),t.push(this.bezierCurves[e].startPoint),t.push(this.bezierCurves[e].startControlPoint);return t.push(this.bezierCurves[0].endControlPoint),t.push(this.bezierCurves[0].endPoint),t}toJSON(t){var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++)s>0&&e.push(","),t?e.push("\n\t"):e.push(" "),e.push(this.bezierCurves[s].toJSON(t));return 0!=this.bezierCurves.length&&e.push(" "),e.push("]"),e.join("")}static fromJSON(t){var e=JSON.parse(t);return g.fromArray(e)}static fromCurve(t){const e=new g;return e.addCurve(t),e}static fromArray(t){if(!Array.isArray(t))throw"[BezierPath.fromArray] Passed object must be an array.";const e=t;if(e.length<1)throw"[BezierPath.fromArray] Passed array must contain at least one bezier curve (has "+e.length+").";for(var s=new g,i=null,r=0;r<e.length;r++){var n;if(u.isInstance(e[r]))n=e[r].clone();else if(0 in e[r]&&1 in e[r]&&2 in e[r]&&3 in e[r]){if(!(e[r][0]&&e[r][1]&&e[r][2]&&e[r][3]))throw"Cannot convert path data to BezierPath instance. At least one element is undefined (index="+r+"): "+e[r];n=u.fromArray(e[r])}else n=u.fromObject(e[r]);i&&(n.startPoint=i.endPoint),s.bezierCurves.push(n),i=n}return s.updateArcLengths(),s}toReducedListRepresentation(t){void 0===t&&(t=1);var e=[];e.push("[");for(var s=0;s<this.bezierCurves.length;s++){var i=this.bezierCurves[s];e.push(i.getStartPoint().x.toFixed(t)),e.push(","),e.push(i.getStartPoint().y.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().x.toFixed(t)),e.push(","),e.push(i.getStartControlPoint().y.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().x.toFixed(t)),e.push(","),e.push(i.getEndControlPoint().y.toFixed(t)),e.push(",")}if(0!=this.bezierCurves.length){i=this.bezierCurves[this.bezierCurves.length-1];e.push(i.getEndPoint().x.toFixed(t)),e.push(","),e.push(i.getEndPoint().y.toFixed(t))}return e.push("]"),e.join("")}static fromReducedListRepresentation(t,e){var s=JSON.parse(t);if(!s.length)throw console.log("Cannot parse bezier path from non-array object nor from empty point list."),"Cannot parse bezier path from non-array object nor from empty point list.";if(s.length<8)throw console.log("Cannot build bezier path. The passed array must contain at least 8 elements (numbers)."),"Cannot build bezier path. The passed array must contain at least 8 elements (numbers).";return g.fromReducedList(s,e)}static fromReducedList(t,e){var s,i,r,n=new g,a=new h,o=0;do{0==o&&(a=new h(t[o],t[o+1])),s=new h(t[o+2],t[o+3]),i=new h(t[o+4],t[o+5]),r=new h(t[o+6],t[o+7]);var l=new u(a,r,s,i);n.bezierCurves.push(l),a=r,o+=6}while(o+2<t.length);return n.adjustCircular=null!=e&&e,e&&(n.bezierCurves[n.bezierCurves.length-1].endPoint=n.bezierCurves[0].startPoint),n.updateArcLengths(),n}}g.START_POINT=0,g.START_CONTROL_POINT=1,g.END_CONTROL_POINT=2,g.END_POINT=3;class f{constructor(t,s,i){this.className="CircleSector",this.uid=e.next(),this.circle=t,this.startAngle=s,this.endAngle=i}containsAngle(t){return this.startAngle<=this.endAngle?t>=this.startAngle&&t<this.endAngle:t>=this.startAngle||t<this.endAngle}angleAt(t){if(this.startAngle<=this.endAngle){return(this.startAngle+(this.endAngle-this.startAngle)*t)%(2*Math.PI)}return(this.startAngle+(2*Math.PI-this.startAngle+this.endAngle)*t)%(2*Math.PI)}getStartPoint(){return this.circle.vertAt(this.startAngle)}getEndPoint(){return this.circle.vertAt(this.endAngle)}circleSectorIntersection(t){const e=this.circle.circleIntersection(t.circle);if(!e)return null;const s=this.circle.center.angle(e.a),i=this.circle.center.angle(e.b);if(!this.containsAngle(s)||!this.containsAngle(i))return null;const n=t.circle.center.angle(e.a),a=t.circle.center.angle(e.b);if(!t.containsAngle(n)||!t.containsAngle(a))return null;var h=new f(this.circle,this.endAngle,this.startAngle).angleAt(.5);const o=new f(new r(this.circle.center.clone(),this.circle.radius),s,i);return o.containsAngle(h)&&(o.startAngle=i,o.endAngle=s),o}destroy(){this.circle.destroy(),this.isDestroyed=!0}}f.circleSectorUtils={polarToCartesian:(t,e,s,i)=>({x:t+s*Math.cos(i),y:e+s*Math.sin(i)}),describeSVGArc:(t,e,s,i,r,n)=>{void 0===n&&(n={moveToStart:!0});const a=f.circleSectorUtils.polarToCartesian(t,e,s,r),h=f.circleSectorUtils.polarToCartesian(t,e,s,i);if(2*Math.PI-Math.abs(i-r)<.001){const a=f.circleSectorUtils.describeSVGArc(t,e,s,i,i+(r-i)/2,n),h=f.circleSectorUtils.describeSVGArc(t,e,s,i+(r-i)/2,r,n);return a.concat(h)}const o=r-i;var l,c;o<0?(l=Math.abs(o)<Math.PI?1:0,c=1):(l=Math.abs(o)>Math.PI?1:0,c=1);const d=[];return n.moveToStart&&d.push("M",h.x,h.y),d.push("A",s,s,0,l,c,a.x,a.y),d}};const v=180/Math.PI;class x{constructor(t,e,s,i,r,n,a,o,l,c,d,u){if(this.svgNode=t,this.offset=new h(0,0).set(e),this.scale=new h(1,1).set(s),this.fillShapes=r,this.isSecondary=Boolean(a),this.drawConfig=n,this.drawlibConfiguration={},this.cache=new Map,this.setSize(i),a){if(!(o&&l&&c&&d))throw"Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";this.gNode=o,this.bufferGNode=l,this.nodeDefs=c,this.bufferedNodeDefs=d,u&&(this.nodeStyle=u)}else this.addStyleDefs(n),this.addDefsNode(),this.gNode=this.createSVGNode("g"),this.bufferGNode=this.createSVGNode("g"),this.svgNode.appendChild(this.gNode)}addStyleDefs(t){this.nodeStyle=this.createSVGNode("style"),this.svgNode.appendChild(this.nodeStyle),this.rebuildStyleDefs(t)}rebuildStyleDefs(t){const e={bezier:"CubicBezierCurve",polygon:"Polygon",triangle:"Triangle",ellipse:"Ellipse",ellipseSector:"EllipseSector",circle:"Circle",circleSector:"CircleSector",vertex:"Vertex",line:"Line",vector:"Vector",image:"Image",text:"Text"},s=[];for(var i in e){const r=e[i],n=t[i];n?s.push(`.${r} { fill : none; stroke: ${n.color}; stroke-width: ${n.lineWidth}px }`):console.warn(`Warning: your draw config is missing the key '${i}' which is required.`)}this.customStyleDefs&&(s.push("\n/* Custom styles */\n"),this.customStyleDefs.forEach(((t,e)=>{s.push(e+" { "+t+" }")}))),this.nodeStyle.innerHTML=s.join("\n")}addDefsNode(){this.nodeDefs=this.createSVGNode("defs"),this.bufferedNodeDefs=this.createSVGNode("defs"),this.svgNode.appendChild(this.nodeDefs)}addCustomStyleDefs(t){this.customStyleDefs=t}findElement(t,e){if(!t)return null;var s=this.cache.get(t);return s&&s.nodeName.toUpperCase()===e.toUpperCase()?(this.cache.delete(t),s):null}createSVGNode(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}makeNode(t){var e=this.findElement(this.curId,t);return e||(e=this.createSVGNode(t)),this.drawlibConfiguration.blendMode&&e.style["mix-blend-mode"](this.drawlibConfiguration.blendMode),e}_bindFillDraw(t,e,s,i,r){return this._configureNode(t,e,this.fillShapes,s,i,r),this._bindNode(t,void 0)}_bindNode(t,e){return t.parentNode||(null!=e?e:this.bufferGNode).appendChild(t),t}_addCSSClasses(t,e){this.curClassName?t.setAttribute("class",`${e} ${this.curClassName}`):t.setAttribute("class",e)}_configureNode(t,e,s,i,r,n){return this._addCSSClasses(t,e),t.setAttribute("fill",s&&i?i:"none"),t.setAttribute("stroke",s?"none":i||"none"),t.setAttribute("stroke-width",`${r||1}`),this.curId&&t.setAttribute("id",`${this.curId}`),this.applyStrokeOpts(t,n),t}setSize(t){this.canvasSize=t,this.svgNode.setAttribute("viewBox",`0 0 ${this.canvasSize.width} ${this.canvasSize.height}`),this.svgNode.setAttribute("width",`${this.canvasSize.width}`),this.svgNode.setAttribute("height",`${this.canvasSize.height}`)}copyInstance(t){return new x(this.svgNode,this.offset,this.scale,this.canvasSize,t,this.drawConfig,!0,this.gNode,this.bufferGNode,this.nodeDefs,this.bufferedNodeDefs,this.nodeStyle)}setConfiguration(t){this.drawlibConfiguration=t}setCurrentId(t){this.curId=t}setCurrentClassName(t){this.curClassName=t}beginDrawCycle(t){this.cache.clear();for(var e=0;e<this.bufferGNode.childNodes.length;e++){var s=this.bufferGNode.childNodes[e];this.cache.set(s.getAttribute("id"),s)}this.removeAllChildNodes()}endDrawCycle(t){this.rebuildStyleDefs(this.drawConfig),this.isSecondary||(this.svgNode.replaceChild(this.bufferedNodeDefs,this.nodeDefs),this.svgNode.replaceChild(this.bufferGNode,this.gNode));const e=this.gNode;this.gNode=this.bufferGNode,this.bufferGNode=e;const s=this.nodeDefs;this.nodeDefs=this.bufferedNodeDefs,this.bufferedNodeDefs=s}applyStrokeOpts(t,e){e&&e.dashArray&&e.dashArray.length>0&&x.nodeSupportsLineDash(t.tagName)&&(t.setAttribute("stroke-dasharray",e.dashArray.map((t=>t*this.scale.x)).join(" ")),e.dashOffset&&t.setAttribute("stroke-dashoffset",""+e.dashOffset*this.scale.x))}_x(t){return this.offset.x+this.scale.x*t}_y(t){return this.offset.y+this.scale.y*t}line(t,e,s,i,r){const n=this.makeLineNode(t,e,s,i,r);return this._bindFillDraw(n,"line",s,i||1,r)}arrow(t,e,s,i,r=8,n){const a=this.makeNode("g"),h={x:0,y:0},o=this.makeArrowHeadNode(t,e,s,i,r,void 0,h),l=this.makeLineNode(t,h,s,i,n);return a.appendChild(l),a.appendChild(o),this._addCSSClasses(a,"linear-arrow"),this._bindNode(a,void 0),a}cubicBezierArrow(t,e,s,i,r,n,a=8,o){const l=this.makeNode("g"),c=new h(0,0),d=this.makeArrowHeadNode(i,e,r,n,a,void 0,c),u=c.difference(e),g=this.makeCubicBezierNode(t,{x:e.x-u.x,y:e.y-u.y},s,{x:i.x-u.x,y:i.y-u.y},r,n,o);return l.appendChild(g),l.appendChild(d),this._addCSSClasses(l,"cubicbezier-arrow"),this._bindNode(l,void 0),l}arrowHead(t,e,s,i,r=8,n){const a=this.makeArrowHeadNode(t,e,s,i,r,n);return this._bindFillDraw(a,"arrowhead",s,i||1,n)}image(t,e,s,i=1){const r=this.makeNode("image"),n=t=>{if(t.naturalWidth){const n=s.x/t.naturalWidth,a=s.y/t.naturalHeight;r.setAttribute("width",""+t.naturalWidth*this.scale.x),r.setAttribute("height",""+t.naturalHeight*this.scale.y),r.setAttribute("display",null),r.setAttribute("opacity",`${i}`),r.setAttribute("transform",`translate(${this._x(e.x)} ${this._y(e.y)}) scale(${n} ${a})`)}};return t.addEventListener("load",(e=>{n(t)})),r.setAttribute("x","0"),r.setAttribute("y","0"),r.setAttribute("display","none"),n(t),r.setAttribute("href",t.src),this._bindFillDraw(r,"image",null,null)}texturedPoly(t,s,i,r,n){const a=new h(s.min).clone().rotate(n,r),o=this.makeNode("clipPath"),l=`clippath_${e.next()}`;o.setAttribute("id",l);const c=this.makeNode("g"),d=this.makeNode("image");d.setAttribute("x",`${this._x(a.x)}`),d.setAttribute("y",`${this._y(a.y)}`),d.setAttribute("width",`${s.width}`),d.setAttribute("height",`${s.height}`),d.setAttribute("href",t.src),d.setAttribute("transform",`rotate(${n*v}, ${this._x(a.x)}, ${this._y(a.y)})`);const u=this.makeNode("path"),g=[];if(i.vertices.length>0){g.push("M",`${this._x(i.vertices[0].x)}`,`${this._y(i.vertices[0].y)}`);for(var f=1;f<i.vertices.length;f++)g.push("L",`${this._x(i.vertices[f].x)}`,`${this._y(i.vertices[f].y)}`)}u.setAttribute("d",g.join(" ")),o.appendChild(u),this.bufferedNodeDefs.appendChild(o),c.appendChild(d),c.setAttribute("transform-origin",`${this._x(a.x)} ${this._y(a.y)}`),c.setAttribute("transform",`scale(${this.scale.x}, ${this.scale.y})`);const x=this.makeNode("g");return x.appendChild(c),x.setAttribute("clip-path",`url(#${l})`),this._bindFillDraw(x,"image",null,null),x}cubicBezier(t,e,s,i,r,n,a){const h=this.makeCubicBezierNode(t,e,s,i,r,n,a);return this._bindNode(h,void 0)}cubicBezierPath(t,e,s,i){const r=this.makeNode("path");if(this.applyStrokeOpts(r,i),!t||0==t.length)return r;const n=["M",this._x(t[0].x),this._y(t[0].y)];for(var a,h,o,l=1;l<t.length;l+=3)h=t[l],o=t[l+1],a=t[l+2],n.push("C",this._x(h.x),this._y(h.y),this._x(o.x),this._y(o.y),this._x(a.x),this._y(a.y));return r.setAttribute("d",n.join(" ")),this._bindFillDraw(r,"cubicBezierPath",e,s||1)}handle(t,e){this.point(t,"rgb(0,32,192)"),this.square(e,5,"rgba(0,128,192,0.5)")}handleLine(t,e){this.line(t,e,"rgb(128,128,128,0.5)")}dot(t,e){const s=this.makeNode("line");return s.setAttribute("x1",`${this._x(t.x)}`),s.setAttribute("y1",`${this._y(t.y)}`),s.setAttribute("x2",`${this._x(t.x)}`),s.setAttribute("y2",`${this._y(t.y)}`),this._bindFillDraw(s,"dot",e,1)}point(t,e){const s=this.makeNode("circle");return s.setAttribute("cx",`${this._x(t.x)}`),s.setAttribute("cy",`${this._y(t.y)}`),s.setAttribute("r","3"),this._bindFillDraw(s,"point",e,1)}circle(t,e,s,i,r){const n=this.makeNode("circle");return this.applyStrokeOpts(n,r),n.setAttribute("cx",`${this._x(t.x)}`),n.setAttribute("cy",`${this._y(t.y)}`),n.setAttribute("r",""+e*this.scale.x),this._bindFillDraw(n,"circle",s,i||1)}circleArc(t,e,s,i,r,n,a){const h=this.makeNode("path");this.applyStrokeOpts(h,a);const o=f.circleSectorUtils.describeSVGArc(this._x(t.x),this._y(t.y),e*this.scale.x,s,i);return h.setAttribute("d",o.join(" ")),this._bindFillDraw(h,"circleArc",r,n||1)}ellipse(t,e,s,i,r,n,a){void 0===n&&(n=0);const h=this.makeNode("ellipse");return this.applyStrokeOpts(h,a),h.setAttribute("cx",`${this._x(t.x)}`),h.setAttribute("cy",`${this._y(t.y)}`),h.setAttribute("rx",""+e*this.scale.x),h.setAttribute("ry",""+s*this.scale.y),h.setAttribute("transform",`rotate(${180*n/Math.PI} ${this._x(t.x)} ${this._y(t.y)})`),this._bindFillDraw(h,"ellipse",i,r||1)}square(t,e,s,i,r){const n=this.makeNode("rectangle");return this.applyStrokeOpts(n,r),n.setAttribute("x",`${this._x(t.x-e/2)}`),n.setAttribute("y",`${this._y(t.y-e/2)}`),n.setAttribute("width",""+e*this.scale.x),n.setAttribute("height",""+e*this.scale.y),this._bindFillDraw(n,"square",s,i||1)}rect(t,e,s,i,r,n){const a=this.makeNode("rect");return this.applyStrokeOpts(a,n),a.setAttribute("x",`${this._x(t.x)}`),a.setAttribute("y",`${this._y(t.y)}`),a.setAttribute("width",""+e*this.scale.x),a.setAttribu