/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{G as t}from"./GeometryCursor.js";import{G as e,d as s,g as n}from"./Geometry.js";import{a as r,P as o,E as m,n as i}from"./MultiPathImpl.js";import{g as u,c}from"./Envelope.js";import{u as h,v as l,w as a,T as d,x as p,C as y}from"./SpatialReference.js";var _=y;function g(t,e){return{m_geometry:t,m_side:e}}function f(t,e,s,n,r,o){if(e.isEmpty()){const t=g(e,0);return void r.push(t)}if(s.isEmpty()){const t=g(e,0);return void r.push(t)}const i=[],u=new m;{const m=u.createGeometryUserIndex(),c=u.addGeometry(e),y=u.addGeometry(s),f=new d(o);let C=0,E=null;if(u.hasCurves()){E=new _;const t=u.getEnvelope2D(o);C=h(n.total());const e=l(n.total(),t);a(u,e,n.total(),12e3,E,null,o)}u.dbgVerifyCurves(),f.setEditShapeCrackAndCluster(u,n),f.cut(t,m,c,y,i);for(const t of i){null!==E&&E.stitchCurves(u,t,C,!1);const e=g(u.getGeometry(t),p(u.getGeometryUserIndex(t,m)));r.push(e)}null!==E&&E.clearStitcher(u)}}function C(t,e,s,n,r,u){if(e.isEmpty()){const t=g(e,0);return void r.push(t)}if(s.isEmpty()){const t=g(e,0);return void r.push(t)}const c=[],p=new m;{const t=p.createGeometryUserIndex(),y=p.addGeometry(e),f=p.addGeometry(s),C=new d(u);let E=0,G=null;if(p.hasCurves()){G=new _;const t=p.getEnvelope2D(u);E=h(n.total());const e=l(n.total(),t);a(p,e,n.total(),12e3,G,null,u)}p.dbgVerifyCurves(),C.setEditShapeCrackAndCluster(p,n),C.cut(!1,t,y,f,c),null!==G&&G.stitchCurves(p,i,E,!0);let v=p.getGeometry(y);const w=new o,x=new o,I=[];for(let e=0;e<c.length;e++){let s=null;{const r=new m,o=r.addGeometry(v),d=r.addGeometry(p.getGeometry(c[e]));if(r.hasCurves()){const t=r.getEnvelope2D(u);E=h(n.total());const e=l(n.total(),t);a(r,e,n.total(),12e3,G,null,u)}C.setEditShapeCrackAndCluster(r,n);const y=C.intersection(o,d);if(null!==G&&G.stitchCurves(r,i,E,!0),s=r.getGeometry(y),s.isEmpty())continue;const _=p.getGeometryUserIndex(c[e],t);2===_?w.add(s,!1):1===_?x.add(s,!1):I.push(s)}{const t=new m,s=t.addGeometry(v),r=t.addGeometry(p.getGeometry(c[e]));if(t.hasCurves()){const e=t.getEnvelope2D(u);E=h(n.total());const s=l(n.total(),e);a(t,s,n.total(),12e3,G,null,u)}C.setEditShapeCrackAndCluster(t,n);const o=C.difference(s,r);null!==G&&G.stitchCurves(t,i,E,!0);v=t.getGeometry(o)}}if(!v.isEmpty()&&c.length>0&&I.push(v),w.isEmpty()&&x.isEmpty())return;if(!w.isEmpty()){const t=g(w,1);r.push(t)}if(!x.isEmpty()){const t=g(x,2);r.push(t)}for(let e=0,s=I.length;e<s;++e){const t=g(I[e],3);r.push(t)}}}class E{getOperatorType(){return 10005}accelerateGeometry(t,e,s){return!1}canAccelerateGeometry(t){return!1}supportsCurves(){return!0}execute(t,e,s,n,r){return new G(t,e,s,n,r)}}class G extends t{constructor(t,e,s,n,o){super(),this.m_cutIndex=-1,this.m_cuts=[],this.m_progressTracker=o,this.m_cuttee=e.clone(),this.m_cutter=new r({copy:s}),this.m_bConsiderTouch=t;const m=u(e,s);this.m_tolerance=c(n,m,!0)}next(){return-1===this.m_cutIndex&&this.generateCuts(),++this.m_cutIndex<this.m_cuts.length?this.m_cuts[this.m_cutIndex]:null}getGeometryID(){return this.m_cutIndex}tock(){return!0}getRank(){return 1}generateCuts(){switch(this.m_cuttee.getGeometryType()){case e.enumPolyline:this.generatePolylineCuts();break;case e.enumPolygon:this.generatePolygonCuts()}}generatePolylineCuts(){const t=new r,e=new r,n=new r;this.m_cuts.length=0,this.m_cuts.push(t),this.m_cuts.push(e);const o=[];f(this.m_bConsiderTouch,this.m_cuttee,this.m_cutter,this.m_tolerance,o,this.m_progressTracker);for(let r=0;r<o.length;r++){const m=o[r];1===m.m_side?t.add(m.m_geometry,!1):2===m.m_side||4===m.m_side?e.add(m.m_geometry,!1):3===m.m_side?this.m_cuts.push(m.m_geometry):0===m.m_side?n.add(m.m_geometry,!1):s("")}n.isEmpty()||t.isEmpty()&&e.isEmpty()&&!(this.m_cuts.length>=3)||this.m_cuts.push(n),t.isEmpty()&&e.isEmpty()&&this.m_cuts.length<3&&(this.m_cuts.length=0)}generatePolygonCuts(){const t=new o,e=new o,r=new o;this.m_cuts.length=0,this.m_cuts.push(t),this.m_cuts.push(e);const m=[];C(this.m_bConsiderTouch,this.m_cuttee,this.m_cutter,this.m_tolerance,m,this.m_progressTracker);for(let n=0;n<m.length;n++){const o=m[n];1===o.m_side?t.add(o.m_geometry,!1):2===o.m_side?e.add(o.m_geometry,!1):3===o.m_side?this.m_cuts.push(o.m_geometry):0===o.m_side?r.add(o.m_geometry,!1):s("")}n(r.isEmpty()||1===m.length),t.isEmpty()&&e.isEmpty()&&this.m_cuts.length<3&&(this.m_cuts.length=0)}}export{E as O};
