/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{GeometryCursor as t}from"../../../geometry/GeometryCursor.js";import e from"../../../geometry/support/PolylineBuilder.js";import{PathEffectCursor as n}from"../CIMCursor.js";class r{static{this.instance=null}static local(){return null===r.instance&&(r.instance=new r),r.instance}execute(t,e,n){return new s(t,e,n)}}class s extends n{constructor(t,e,n){super(t,!1,!0),this._suppress=void 0!==e.suppress&&e.suppress,this._invert=void 0!==e.invert&&e.invert}processPath(n){if(n.totalSize<=0)return null;if(!this._suppress){const e=t.createEmptyOptimizedCIM("esriGeometryPolygon",!1,!1,n.yFactor);for(n.seekPathEnd();n.nextPoint();)e.pushXY(n.x,n.y);return e}const r=[],s=new Array(n.pathSize);let o=0;for(n.seekPathStart();n.nextPoint();)s[o++]=n.getControlPoint(),r.push([n.x,n.y]);let i=!0,l=!0,h=!1,p=!this._invert;o=0;const u=new e;let c=r[0];for(;o<r.length-1;){const t=r[o+1],e=s[o],n=s[o+1];o++,l&&(p=e||n?this._invert:!this._invert,l=!1),p?(u.addSegment(c,t,i),i=!1):h=!0,c=t,n&&(p?(p=!1,i=!0):p=!0)}const a=u.getGeometry();if(0===a.length)return null;if(!h&&r[0][0]===r[r.length-1][0]&&r[0][1]===r[r.length-1][1]){const e=a[a.length-1];return e[0][0]===e[e.length-1][0]&&e[0][1]===e[e.length-1][1]||e.push([e[0][0],e[0][1]]),t.fromJSONCIM({paths:a})}const g=a[a.length-1];return u.getPointCount()>1&&"esriGeometryPolygon"===n.geometryType&&g[0][0]===g[g.length-1][0]&&g[0][1]===g[g.length-1][1]&&a.length>1&&(a[a.length-1].push(...a[0]),a.splice(0,1)),t.fromJSONCIM({paths:a})}}export{r as EffectSuppress};
