/*
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","../../../../geometry/support/aaBoundingRect","../../../../geometry/support/centroid","../../../../geometry/support/jsonUtils","../../../../geometry/support/quantizationUtils","../../../../geometry/support/spatialReferenceUtils","../../../../layers/graphics/featureConversionUtils","../../../../layers/graphics/OptimizedGeometry"],(function(e,t,i,n,s,o,r,l,u){"use strict";const a=new u,h=new u,c="esriGeometryPolyline";function y(e){e.coords.length=0,e.lengths.length=0}let g=function(){function u(){this.bounds=i.create(),this.graphic=null}u.acquire=function(e=null,t,i,n,s){let o;return 0===u._pool.length?o=new u:(o=u._pool.pop(),this._set.delete(o)),o.acquire(e,t,i,n,s),o},u.release=function(e){e&&!this._set.has(e)&&(e.release(),this._pool.push(e),this._set.add(e))},u.getCentroidQuantized=function(e,i){if(s.isPolygon(e.geometry)){const s=e.symbol;if(t.isNone(s))return null;if((null==s?void 0:s.layers.length)>0&&s.layers.some((e=>"text"===e.type||"marker"===e.type))){const t=n.polygonCentroid(e.geometry);return null!==t?o.quantizePoint(i,{},{x:t[0],y:t[1]},!1,!1):null}}return null};var g=u.prototype;return g.acquire=function(e=null,t,i,n,s){e&&this.set(e,t,i,n,s)},g.release=function(){this.graphic=null,this.symbolResource=null,this.geometry=null},g.set=function(e,t,i,n,s){this.graphic=e,this.geometry=i,this.symbolResource=t,this.bounds=n,s&&(this.size=s)},g.getGeometryQuantized=function(e,t,n,u){const g=this.geometry;if(s.isPolygon(g)){const t=g.rings;if(1===t.length&&2===t[0].length)return o.quantizeGeometry(e,{paths:[[t[0][0],t[0][1]]]})}else{if(s.isPolyline(g))return y(a),y(h),l.convertFromPolyline(a,g),l.generalizeOptimizedGeometry(h,a,g.hasZ,g.hasM,c,e.scale[0]),l.quantizeOptimizedGeometry(a,h,g.hasZ,g.hasM,c,e),l.convertToPolyline(a,g.hasZ,g.hasM);if(s.isMultipoint(g)){const s=.5*u*Math.max(Math.abs(this.size[0])+this.size[2]-this.size[0],Math.abs(this.size[1])+this.size[3]-this.size[1]),l=r.getInfo(n);let a=g.points;if(l){const[e,n]=l.valid,o=n-e;a=a.filter((r=>{if(r[0]+s>n||r[0]-s<e){const e=[...r];return r[0]+s>n?e[0]-=o:e[0]+=o,i.containsPointWithMargin(t,r,s)||i.containsPointWithMargin(t,e,s)}return i.containsPointWithMargin(t,r,s)}))}return 0===a.length?{points:a}:o.quantizeGeometry(e,{points:a})}}return o.quantizeGeometry(e,this.geometry)},e._createClass(u,[{key:"symbol",get:function(){return this.symbolResource.symbol}}]),u}();return g._pool=[],g._set=new Set,g}));
