/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{GeometryCursor as e}from"../../../geometry/GeometryCursor.js";import{collectPath as t}from"../../../geometry/geometryCursorCollectUtils.js";import r from"../../../geometry/SpatialReference.js";import{isExtent as s}from"../../../geometry/support/jsonTypeUtils.js";import{clipCursorToTileExtent as i,lazySimplifyOGCOperator as o,lazyOffsetOperator as n,lazyGraphicBufferOperator as m}from"../CIMEffects.js";import{CurveHelper as f,pixelTolerance as l}from"../CurveHelper.js";const a=10;class u{static{this.instance=null}static local(){return null===u.instance&&(u.instance=new u),u.instance}execute(e,t,r){return new c(e,t,r)}}class c{constructor(e,t,r){const s=r.geomUnitsPerPoint,i=r.maxInflateSize;this._preventClipping=r.preventClipping,this._inputGeometries=e,this._tileKey=r.tileKey,this._curveHelper=new f,this._offset=(t.offset??1)*s,this._method=t.method??"Square",this._maxInflateSize=Math.max(Math.abs(i*s),a),this._offsetFlattenError=l*s}next(){let f;for(;f=this._inputGeometries.next();){if(0===this._offset)return f.clone();if("esriGeometryEnvelope"===f.geometryType){if("Rounded"===this._method&&this._offset>0){const r=t(f),s=this._curveHelper.offset(r,-this._offset,this._method,4,this._offsetFlattenError);if(s){const t=e.createEmptyOptimizedCIM(f.geometryType);return t.pushPath(s),t}return null}const r=f.asJSON();if(s(r)&&Math.min(r.xmax-r.xmin,r.ymax-r.ymin)+2*this._offset>0)return e.fromJSONCIM({xmin:r.xmin-this._offset,xmax:r.xmax+this._offset,ymin:r.ymin-this._offset,ymax:r.ymax+this._offset})}const l=!this._preventClipping&&this._tileKey?i(f,this._maxInflateSize,!0):f.clone();if(!l)continue;const a=o.module,u=n.module,c=m.module,p=a.execute({...l.asJSON(),spatialReference:{wkid:r.WebMercator.wkid}});if(!p)continue;let _,y=h(this._method);return"esriGeometryPolygon"===f.geometryType?("square"===y&&(y="bevel"),_=c.executeMany([p],[this._offset],y,"round")[0]):_=u.execute(p,-this._offset,{joins:y,flattenError:this._offsetFlattenError,miterLimit:4}),_?e.fromJSONCIM(_):null}return null}}function h(e){switch(e){case"Rounded":return"round";case"Bevelled":return"bevel";case"Mitered":return"miter";case"Square":return"square"}}export{u as EffectOffset};
