/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../../chunks/_rollupPluginBabelHelpers","../../../../../../core/maybe","../../../../../../layers/graphics/featureConversionUtils","../../enums","../../number","../../Utils","../../materialKey/MaterialKey","./templateUtils","./WGLLineTemplate"],(function(e,t,r,i,o,s,n,l,a){"use strict";const y=100,m=1;return c=>function(c){function u(...e){var t;return(t=c.call(this,...e)||this).forceLibtess=!1,t._bitset=0,t._lineTemplate=null,t.geometryType=i.WGLGeometryType.FILL,t}e._inheritsLoose(u,c);var h=u.prototype;return h._maybeAddLineTemplate=function(e){this._lineTemplate=a.fromFillOutline(e)},h._write=function(e,r,i,o){const s="esriGeometryPoint"===r.geometryType,l=n.FillMaterialKey.load(this._materialKey);e.recordStart(r.getDisplayId(),this._materialKey,this.geometryType,s),this._writeGeometry(e,r,l,o,s),n.hasOutlineFillSymbology(l)&&t.isSome(this._lineTemplate)&&this._lineTemplate.writeGeometry(e,r,o,s),e.recordEnd()},h._writeGeometry=function(e,r,i,o,s){const n=this._getGeometry(r,o,s);if(t.isNone(n))return;const a=[];if(!(n.maxLength>y)&&!this.forceLibtess&&l.triangulate(a,n))return void(a.length&&this._writeVertices(e,r,n.coords,n.lengths,i,a));const m=l.triangulateLibtess(n);this._writeVertices(e,r,m,[m.length/2],i)},h._writeVertex=function(e,t,r,s,l,a){const y=o.i1616to32(m*s,m*l);if(e.vertexBounds(s,l,0,0),e.vertexWrite(y),e.vertexWrite(t),r.symbologyType===i.WGLSymbologyType.DOT_DENSITY)e.vertexWriteF32(1/Math.abs(a.readGeometryArea()));else{e.vertexWrite(this.fillColor);const t=n.hasSimpleSymbology(r);t||(e.vertexWrite(this.tl),e.vertexWrite(this.br)),e.vertexWrite(this.aux2_1),e.vertexWrite(this.aux2_2),e.vertexWrite(this.aux3),t||e.vertexWrite(this._minMaxZoom)}},h._writeVertices=function(e,t,r,i,o,n){const l=t.getDisplayId(),a=this._bitset<<24|l,y=i.reduce(((e,t)=>e+t)),m=s.getStrides(o.geometryType,o.symbologyType).geometry/4,c=e.vertexCount();e.vertexEnsureSize(m*y);let u=0;if(n)for(const s of n){const i=r[2*s],n=r[2*s+1];this._writeVertex(e,a,o,i,n,t),u++}else for(let s=0;s<r.length;s+=2){const i=Math.round(r[s]),n=Math.round(r[s+1]);this._writeVertex(e,a,o,i,n,t),u++}e.indexEnsureSize(u);for(let s=0;s<u;s++)e.indexWrite(s+c)},h._getGeometry=function(e,t,i){const o=t?r.deltaDecodeGeometry(r.convertFromGeometry(t),2):e.readGeometryForDisplay();if(!o)return null;const s=i?256:8;return l.clipMarshall(o,s)},u}(c)}));
