/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{labelPlacementOffsetPadding as e}from"../definitions.js";import i from"./BoundingBox.js";import{serializeList as t,deserializeList as s}from"../util/serializationUtils.js";const r=2;class h{constructor(e,i,t,s,r,h,a,n,l,o,d,c=[],u=0,f=0){this.displayId=e,this.labelClassId=i,this.labelIdHash=t,this.hash=s,this.anchorX=r,this.anchorY=h,this.directionX=a,this.directionY=n,this.maxScale=l,this.minScale=o,this.referenceBounds=d,this.bounds=c,this.recordStart=u,this.recordCount=f,this.priority=0,this._colliders=null,this.uniqueSymbol=null,this.selectedForRendering=!1}get xTile(){return this.anchorX}get yTile(){return this.anchorY}colliders(i){if(!this._colliders){const t=i.attributeView,s=e;let h=this.referenceBounds?.size??0;const a=i.layerView.labelingCollisionInfos[0].vvEvaluators[0];if(null!=a){const e=a(t.getVisualVariableData(this.displayId,0));h=isNaN(e)||null==e||e===1/0?h:e}const n=this.minScale?i.layerView.view.featuresTilingScheme.scaleToZoom(this.minScale):0,l=this.maxScale?i.layerView.view.featuresTilingScheme.scaleToZoom(this.maxScale):25,o=this.directionX*(s+h/2),d=this.directionY*(s+h/2);this._colliders=this.bounds.map(e=>({labelId:this.labelIdHash,xTile:this.anchorX,yTile:this.anchorY,dxPixels:e.x-e.halfWidth+o,dyPixels:e.y-e.halfHeight+d,hard:!0,partIndex:1,width:e.width+r,height:e.height+r,angle:0,xScreen:0,yScreen:0,dxScreen:0,dyScreen:0,enabled:!0,minLod:n,maxLod:l}))}return this._colliders}get id(){return this.displayId}serialize(e){e.push(this.displayId),e.push(this.labelClassId),e.push(this.labelIdHash),e.push(this.hash),e.push(this.recordStart),e.push(this.recordCount),e.writeF32(this.anchorX),e.writeF32(this.anchorY),e.writeF32(this.directionX),e.writeF32(this.directionY),e.writeF32(this.maxScale),e.writeF32(this.minScale),this.referenceBounds?(e.writeF32(this.referenceBounds.size),e.writeF32(this.referenceBounds.offsetX),e.writeF32(this.referenceBounds.offsetY)):(e.writeF32(0),e.writeF32(0),e.writeF32(0)),t(e,this.bounds)}static deserialize(e){const t=e.readInt32(),r=e.readInt32(),a=e.readInt32(),n=e.readInt32(),l=e.readInt32(),o=e.readInt32(),d=e.readF32(),c=e.readF32(),u=e.readF32(),f=e.readF32(),m=e.readF32(),F=e.readF32(),w=e.readF32(),I=e.readF32(),p=e.readF32(),S=s(e,i)??[];return new h(t,r,a,n,d,c,u,f,m,F,{size:w,offsetX:I,offsetY:p},S,l,o)}}export{h as LabelMetric};
