UNPKG

g2o-graphics

Version:
3 lines (2 loc) 4.54 kB
import{Path as t,dispose as s,Anchor as i,G20 as e}from"g2o";import{state as r,effect as o}from"g2o-reactive";const n=Math.cos,h=Math.sin;class a extends t{#t=[];#s=r(1);#i=r(0);#e=r(6);constructor(t,s={}){if(super(t,[],!0,!1,!0,function(t){const s={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:t.fillColor,fillOpacity:t.fillOpacity,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWidth:t.strokeWidth};return s}(s)),"number"==typeof s.radius&&(this.radius=s.radius),"number"==typeof s.sides){const t=3,i=24;this.sides=Math.min(Math.max(s.sides,t),i)}"number"==typeof s.twist&&(this.twist=s.twist),this.#t.push(o((()=>{this.update()}))),this.flagReset(!0)}dispose(){s(this.#t),super.dispose()}update(){return function(t,s,r,o){const a=s+1;o.length>a&&o.splice(a,o.length-a);for(;o.length<a;)o.push(new i(e.vector(0,0)));for(let i=0;i<a;i++){const e=2*Math.PI*i/s+r,a=t*n(e),u=t*h(e),d=o.getAt(i);d.origin.set(a,u),d.command=0===i?"M":"L"}}(this.radius,this.sides,this.twist,this.vertices),super.update(),this}flagReset(t=!1){return super.flagReset(t),this}get radius(){return this.#s.get()}set radius(t){this.#s.set(t)}get sides(){return this.#e.get()}set sides(t){this.#e.set(t)}get twist(){return this.#i.get()}set twist(t){this.#i.set(t)}}class u extends t{#t=[];#r=r(Math.SQRT2);#o=r(Math.SQRT2);#s=r(.2);constructor(t,s={}){void 0===s.radius&&"number"==typeof s.width&&"number"==typeof s.height&&(s.radius=Math.floor(Math.min(s.width,s.height)/12));const r=[];for(let t=0;t<10;t++){const s=e.vector(0,0),o=0===t?"M":"C";r.push(new i(s,o))}super(t,r,!0,!1,!0,function(t){const s={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:t.fillColor,fillOpacity:t.fillOpacity,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWidth:t.strokeWidth};return s}(s)),"number"==typeof s.width&&(this.width=s.width),"number"==typeof s.height&&(this.height=s.height),"number"==typeof s.radius&&(this.radius=s.radius),this.#t.push(o((()=>{this.update()})))}dispose(){s(this.#t),super.dispose()}update(){return function(t,s,i,e){const r=i,o=i;let n;const h=t/2,a=s/2;n=e.getAt(0),n.x=-(h-r),n.y=-a,n=e.getAt(1),n.x=h-r,n.y=-a,n.controls.a.clear(),n.controls.b.x=r,n.controls.b.y=0,n=e.getAt(2),n.x=h,n.y=-(a-o),n.controls.b.clear(),n.controls.a.clear(),n=e.getAt(3),n.x=h,n.y=a-o,n.controls.a.clear(),n.controls.b.x=0,n.controls.b.y=o,n=e.getAt(4),n.x=h-r,n.y=a,n.controls.b.clear(),n.controls.a.clear(),n=e.getAt(5),n.x=-(h-r),n.y=a,n.controls.a.clear(),n.controls.b.x=-r,n.controls.b.y=0,n=e.getAt(6),n.x=-h,n.y=a-o,n.controls.a.clear(),n.controls.b.clear(),n=e.getAt(7),n.x=-h,n.y=-(a-o),n.controls.a.clear(),n.controls.b.x=0,n.controls.b.y=-o,n=e.getAt(8),n.x=-(h-r),n.y=-a,n.controls.a.clear(),n.controls.b.clear(),n=e.getAt(9),n.copy(e.getAt(8))}(this.width,this.height,this.radius,this.vertices),super.update(),this}get width(){return this.#r.get()}set width(t){this.#r.set(t)}get height(){return this.#o.get()}set height(t){this.#o.set(t)}get radius(){return this.#s.get()}set radius(t){this.#s.set(t)}}const d=Math.cos,c=Math.sin;class l extends t{#t=[];#n=r(.5);#h=r(1);#a=r(8);#i=r(0);constructor(t,s={}){super(t,[],!0,!1,!0,function(t){const s={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:t.fillColor,fillOpacity:t.fillOpacity,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWidth:t.strokeWidth};return s}(s)),"number"==typeof s.innerRadius&&(this.innerRadius=s.innerRadius),"number"==typeof s.outerRadius&&(this.outerRadius=s.outerRadius),"number"==typeof s.points&&(this.points=s.points),"number"==typeof s.twist&&(this.twist=s.twist),this.#t.push(o((()=>{this.update()})))}dispose(){s(this.#t),super.dispose()}update(){return function(t,s,r,o,n){const h=2*t,a=h+1;n.length>a&&n.splice(a,n.length-a);for(;n.length<a;)n.push(new i(e.vector(0,0)));for(let t=0;t<a;t++){const i=2*Math.PI*t/h+o,e=t%2==0?r:s,a=e*d(i),u=e*c(i),l=n.getAt(t);l.origin.set(a,u),l.command=0===t?"M":"L"}}(this.points,this.innerRadius,this.outerRadius,this.twist,this.vertices),super.update(),this}get innerRadius(){return this.#n.get()}set innerRadius(t){this.#n.set(t)}get outerRadius(){return this.#h.get()}set outerRadius(t){this.#h.set(t)}get points(){return this.#a.get()}set points(t){this.#a.set(t)}get twist(){return this.#i.get()}set twist(t){this.#i.set(t)}}export{a as RegularPolygon,u as RoundedRectangle,l as Star}; //# sourceMappingURL=index.min.js.map