import*as UI from"../ui/ui.js";export class BezierUI{constructor(t,i,r,s,e){this.width=t,this.height=i,this.marginTop=r,this.radius=s,this.linearLine=e}static drawVelocityChart(t,i,r){const s=Height;let e=["M",0,s];const n=1/40;let o=t.evaluateAt(0);for(let h=n;h<1.025;h+=n){const i=t.evaluateAt(h);let n=(i.y-o.y)/(i.x-o.x);const a=o.x*(1-h)+i.x*h;n=Math.tanh(n/1.5),e=e.concat(["L",(a*r).toFixed(2),(s-n*s).toFixed(2)]),o=i}e=e.concat(["L",r.toFixed(2),s,"Z"]),i.setAttribute("d",e.join(" "))}curveWidth(){return this.width-2*this.radius}curveHeight(){return this.height-2*this.radius-2*this.marginTop}_drawLine(t,i,r,s,e,n){const o=UI.UIUtils.createSVGChild(t,"line",i);o.setAttribute("x1",String(r+this.radius)),o.setAttribute("y1",String(s+this.radius+this.marginTop)),o.setAttribute("x2",String(e+this.radius)),o.setAttribute("y2",String(n+this.radius+this.marginTop))}_drawControlPoints(t,i,r,s,e){this._drawLine(t,"bezier-control-line",i,r,s,e);const n=UI.UIUtils.createSVGChild(t,"circle","bezier-control-circle");n.setAttribute("cx",String(s+this.radius)),n.setAttribute("cy",String(e+this.radius+this.marginTop)),n.setAttribute("r",String(this.radius))}drawCurve(t,i){if(!t)return;const r=this.curveWidth(),s=this.curveHeight();i.setAttribute("width",String(this.width)),i.setAttribute("height",String(this.height)),i.removeChildren();const e=UI.UIUtils.createSVGChild(i,"g");this.linearLine&&this._drawLine(e,"linear-line",0,s,r,0);const n=UI.UIUtils.createSVGChild(e,"path","bezier-path"),o=[new UI.Geometry.Point(t.controlPoints[0].x*r+this.radius,(1-t.controlPoints[0].y)*s+this.radius+this.marginTop),new UI.Geometry.Point(t.controlPoints[1].x*r+this.radius,(1-t.controlPoints[1].y)*s+this.radius+this.marginTop),new UI.Geometry.Point(r+this.radius,this.marginTop+this.radius)];n.setAttribute("d","M"+this.radius+","+(s+this.radius+this.marginTop)+" C"+o.join(" ")),this._drawControlPoints(e,0,s,t.controlPoints[0].x*r,(1-t.controlPoints[0].y)*s),this._drawControlPoints(e,r,0,t.controlPoints[1].x*r,(1-t.controlPoints[1].y)*s)}}export const Height=26;