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