/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import has from"../../../../../../../core/has.js";import{loadLibtess as e}from"../../../../../../../geometry/libtess.js";import{clipMarshall as t,triangulate as r,triangulateLibtess as s}from"../../../mesh/templates/templateUtils.js";import{MeshWriter as i}from"../mesh/MeshWriter.js";const o=100,n=has("featurelayer-fast-triangulation-enabled");class a extends i{async loadDependencies(){await Promise.all([super.loadDependencies(),e()])}_write(e,t,r){const s=r?.asOptimized()??t.readGeometryForDisplay(),i=this._clip(s);i&&(e.recordStart(this.instanceId,this.attributeLayout),this._writeGeometry(e,t,i.justXY()),e.recordEnd())}_clip(e){if(!e)return null;const r=this.hasEffects;return t(e,r?256:8)}_writeGeometry(e,t,i){const a=(i=i.justXY()).maxLength>o,c=[],l=this.createTesselationParams(t);if(!a&&n&&r(c,i))return void(c.length&&this._writeVertices(e,t,i.coords,l,c));const d=s(i);this._writeVertices(e,t,d,l)}_writeVertices(e,t,r,s,i){const o=t.getDisplayId(),n=e.vertexCount(),a=this.hasEffects;let c=0;if(i)for(const l of i){const t=r[2*l],i=r[2*l+1];a&&e.recordBounds(t,i,0,0),this._writeVertex(e,o,t,i,s),c++}else for(let l=0;l<r.length;l+=2){const t=Math.round(r[l]),i=Math.round(r[l+1]);a&&e.recordBounds(t,i,0,0),this._writeVertex(e,o,t,i,s),c++}e.indexEnsureSize(c);for(let l=0;l<c;l++)e.indexWrite(l+n)}}export{a as AFillMeshWriter};
