/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{pt2px as t}from"../../../../../../../core/screenUtils.js";import{applyParentTransform as e}from"../../../../../../../symbols/cim/utils.js";import{spritePadding as i}from"../../../definitions.js";class o{static from(t){return"width"in t?this.fromSimpleMeshParams(t):this.fromComplexMeshParams(t)}static fromSimpleMeshParams(e){const i=new o(e.sprite,e.color,e.outlineColor,e.minPixelBuffer,e.placement,e.scaleInfo,e.effects),{type:s,width:h,height:r,angle:n,alignment:a,outlineSize:c,referenceSize:f,sprite:l,overrideOutlineColor:m}=e;return i.rawWidth=t(h),i.rawHeight=t(r),i.angle=n,i.alignment=a,i.outlineSize=t(c),i.referenceSize=t(f),i.overrideOutlineColor=m,i.offsetX=t(e.offsetX),i.offsetY=t(e.offsetY),"simple"!==s||l.sdf||(i.rawWidth=l.width,i.rawHeight=l.height),i._computeSize(e,!1),i}static fromComplexMeshParams(i){const s=new o(i.sprite,i.color,i.outlineColor,i.minPixelBuffer,i.placement,i.scaleInfo,i.effects);let{alignment:h,transforms:r,size:n,scaleX:a,anchorX:c,anchorY:f,angle:l,colorLocked:m,frameHeight:d,widthRatio:u,offsetX:p,offsetY:g,outlineSize:x,referenceSize:w,scaleFactor:z,sizeRatio:X,isAbsoluteAnchorPoint:S,rotateClockwise:Y,scaleSymbolsProportionally:H,sprite:C}=i;if(r&&r.infos.length>0){const t=e(n,l,Y,p,g,r);n=t.size,l=t.rotation,p=t.offsetX,g=t.offsetY,Y=!1}z&&(n*=z,p*=z,g*=z);const M=a*(C.width/C.height);s.alignment=h,s.rawHeight=t(n),s.rawWidth=s.rawHeight*M,s.referenceSize=t(w),s.sizeRatio=X,s.sdfDecodeCoeff=(C.sdfDecodeCoeff??1)*X,s.angle=l,s.rotateClockwise=Y,s.anchorX=c,s.anchorY=f,s.offsetX=t(p),s.offsetY=t(g),S&&n&&(C.sdf?s.anchorX=c/(n*u):s.anchorX=c/(n*M),s.anchorY=f/n);const W=H&&d?n/d:1;return s.outlineSize=0===x||isNaN(x)?0:t(x)*W,s.scaleSymbolsProportionally=H,s.colorLocked=m,s._computeSize(i,!0),s}constructor(t,e,i,o,s,h,r){this.sprite=t,this.color=e,this.outlineColor=i,this.minPixelBuffer=o,this.placement=s,this.scaleInfo=h,this.effects=r,this.rawWidth=0,this.rawHeight=0,this.angle=0,this.outlineSize=0,this.referenceSize=0,this.sizeRatio=1,this.sdfDecodeCoeff=1,this.alignment=0,this.scaleSymbolsProportionally=!1,this.overrideOutlineColor=!1,this.colorLocked=!1,this.anchorX=0,this.anchorY=0,this.computedWidth=0,this.computedHeight=0,this.texXmin=0,this.texYmin=0,this.texXmax=0,this.texYmax=0,this.offsetX=0,this.offsetY=0,this.rotateClockwise=!0}get boundsInfo(){return{size:Math.max(this.computedHeight,this.computedWidth),offsetX:this.offsetX,offsetY:this.offsetY}}_computeSize(t,e){const{sprite:o,hasSizeVV:r}=t,n=!!o.sdf,a=o.sdfPaddingRatio??.5,{rawWidth:c,rawHeight:f,sizeRatio:l,outlineSize:m}=this,d=o.rect;let u=c*l,p=f*l,g=0,x=0;if(n){const t=1/(1-a);if(u*=t,p*=t,r)this.computedWidth=u,this.computedHeight=p;else{const t=e&&c>f?u:c,i=f,s=m+2*1;this.computedWidth=Math.min(t+s,u),this.computedHeight=Math.min(i+s,p);const h=Math.max(o.width,o.height)/Math.max(u,p);g=(this.computedWidth-u)*h,x=(this.computedHeight-p)*h}}else this.computedWidth=u*(d.width/o.width),this.computedHeight=p*(d.height/o.height),g=2*i,x=2*i;const w=d.x+i-g/2,z=d.y+i-x/2,X=w+o.width+g,S=z+o.height+x;this.texXmin=s(w),this.texYmin=s(z),this.texXmax=h(X),this.texYmax=h(S),this.computedWidth*=(this.texXmax-this.texXmin)/(X-w),this.computedHeight*=(this.texYmax-this.texYmin)/(S-z),this.anchorX*=u/this.computedWidth,this.anchorY*=p/this.computedHeight}}function s(t,e=1e-7){const i=Math.ceil(t);return i-t<e?i:Math.floor(t)}function h(t,e=1e-7){const i=Math.floor(t);return t-i<e?i:Math.ceil(t)}export{o as ComputedMarkerParams};
