/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../../../../../../core/Logger.js";import{deg2rad as i}from"../../../../../../../core/mathUtils.js";import{pt2px as e}from"../../../../../../../core/screenUtils.js";import{CIMSymbolUnits as r}from"../../../../../../../symbols/cim/types.js";const a=()=>t.getLogger("esri.views.2d.engine.webgl.shaderGraph.techniques.fill.GradientSizeHelper");class s{constructor(t,i){this._size=t,this._sizeUnits=i,this._relativeSize=null}get relativeSize(){return this._relativeSize??=this.calculateRelativeSize(),this._relativeSize}calculateRelativeSize(){if(this._sizeUnits===r.Relative){const t=Math.min(this._size/100,1);return[t,t]}return this.calculateRelativeSizeFromAbsolute()}}class n extends s{constructor(t,i,e,r){super(i,e),this.rotationMatrix00=1,this.rotationMatrix01=0,this.rotationMatrix10=0,this.rotationMatrix11=1,this.bounds={xmin:1/0,ymin:1/0,xmax:-1/0,ymax:-1/0},this.rotationMatrix00=Math.cos(r),this.rotationMatrix01=-Math.sin(r),this.rotationMatrix10=-this.rotationMatrix01,this.rotationMatrix11=this.rotationMatrix00;const{bounds:a,rotationMatrix00:s,rotationMatrix01:n,rotationMatrix10:o,rotationMatrix11:c}=this;t.forEachVertex((t,i)=>{const e=t*s+i*n,r=t*o+i*c;a.xmin=Math.min(a.xmin,e),a.ymin=Math.min(a.ymin,r),a.xmax=Math.max(a.xmax,e),a.ymax=Math.max(a.ymax,r)}),this.center=[(a.xmin+a.xmax)/2,(a.ymin+a.ymax)/2]}}class o extends n{constructor(t,i,e,r){super(t,i,e,r),this.method="linear"}getRelativePosition(t,i){const{rotationMatrix00:e,rotationMatrix01:r,bounds:a}=this,{xmin:s,xmax:n}=a;return[(t*e+i*r-s)/(n-s),0]}calculateRelativeSizeFromAbsolute(){const{_size:t,bounds:i}=this,{xmin:r,xmax:a}=i;return[e(t)/(a-r),0]}}class c extends n{constructor(t,i,e,r){super(t,i,e,r),this.method="rectangular"}getRelativePosition(t,i){const{bounds:e,center:r,rotationMatrix00:a,rotationMatrix01:s,rotationMatrix10:n,rotationMatrix11:o}=this,c=t*n+i*o,x=t*a+i*s-r[0],l=c-r[1];return[x*(2/(e.xmax-e.xmin)),-l*(2/(e.ymax-e.ymin))]}calculateRelativeSizeFromAbsolute(){const{_size:t,bounds:i}=this,{xmin:r,ymin:a,xmax:s,ymax:n}=i;return[e(2*t)/(s-r),e(2*t)/(n-a)]}}class x extends n{constructor(t,i,e){super(t,i,e,0),this.method="circular";const{xmin:r,xmax:a,ymin:s,ymax:n}=this.bounds,o=a-r,c=n-s;this.radius=Math.sqrt(o*o+c*c)/2}getRelativePosition(t,i){const{center:e,radius:r}=this;return[(t-e[0])/r,-((i-e[1])/r)]}calculateRelativeSizeFromAbsolute(){const{_size:t}=this;return[e(t)/this.radius,0]}}function l(t,e){if(null==t)return null;const r=i(e.angle),s=e.gradientSize,n=e.gradientSizeUnits;switch(e.gradientMethod.toLowerCase()){case"linear":return new o(t,s,n,r);case"rectangular":return new c(t,s,n,r);case"circular":return new x(t,s,n);default:return a().errorOnce(`Gradient fill method "${e.gradientMethod}" currently unsupported.`),null}}export{s as AGradientSizeHelper,l as getGradientSizeHelper};
