@arcgis/core 4.31.0-next.20240713 → 4.31.0-next.20240716

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/956cfaab50468b1de65a.js +1 -0
  3. package/assets/esri/core/workers/chunks/{d60b9ab97c56b1a3f0c2.js → dfee89697ffa6921fbee.js} +9 -9
  4. package/assets/esri/themes/base/widgets/_Tooltip.scss +9 -3
  5. package/assets/esri/themes/dark/main.css +1 -1
  6. package/assets/esri/themes/light/main.css +1 -1
  7. package/assets/esri/themes/light/view.css +1 -1
  8. package/chunks/Clipper-D_zmIu84.js +1 -1
  9. package/chunks/Densificator-DB2izaQs.js +1 -1
  10. package/chunks/OperatorDifference.js +5 -0
  11. package/chunks/OperatorRelationsBase-C_y-7Mq7.js +5 -0
  12. package/chunks/OperatorSimplify.js +1 -1
  13. package/chunks/Polyline.js +1 -1
  14. package/chunks/RelationalOperations-wfnLPxD3.js +5 -0
  15. package/geometry/operators/gx/operatorCut.js +1 -1
  16. package/geometry/operators/gx/operatorDensify.js +1 -1
  17. package/geometry/operators/gx/operatorIntersection.js +1 -1
  18. package/geometry/operators/gx/operatorUnion.js +1 -1
  19. package/geometry/operators/operatorContains.js +5 -0
  20. package/geometry/operators/operatorCrosses.js +5 -0
  21. package/geometry/operators/operatorDifference.js +5 -0
  22. package/geometry/operators/operatorDisjoint.js +1 -1
  23. package/geometry/operators/operatorEquals.js +5 -0
  24. package/geometry/operators/operatorIntersects.js +5 -0
  25. package/geometry/operators/operatorOverlaps.js +5 -0
  26. package/geometry/operators/operatorRelate.js +5 -0
  27. package/geometry/operators/operatorTouches.js +5 -0
  28. package/geometry/operators/operatorUnion.js +1 -1
  29. package/geometry/operators/operatorWithin.js +5 -0
  30. package/interfaces.d.ts +14 -1
  31. package/layers/support/SubtypeSublayer.js +1 -1
  32. package/package.json +2 -2
  33. package/support/revision.js +1 -1
  34. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  35. package/views/3d/webgl-engine/core/shaderLibrary/attributes/VertexTextureCoordinates.glsl.js +5 -5
  36. package/views/3d/webgl-engine/core/shaderLibrary/shading/ComputeNormalTexture.glsl.js +1 -1
  37. package/views/3d/webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js +1 -1
  38. package/views/3d/webgl-engine/core/shaderLibrary/shading/ReadBaseColorTexture.glsl.js +5 -5
  39. package/views/3d/webgl-engine/materials/DefaultTechniqueConfiguration.js +1 -1
  40. package/views/3d/webgl-engine/shaders/DefaultMaterialTechniqueConfiguration.js +1 -1
  41. package/views/interactive/tooltip/Tooltip.js +1 -1
  42. package/views/interactive/tooltip/content/TooltipContent.js +1 -1
  43. package/assets/esri/core/workers/chunks/543f9db420c99d429637.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{l as e,K as t,F as s,G as i,N as r,j as n,g as h,b as a,t as o,O as m,R as g,U as l,V as _,W as d,X as p,f as u,Y as c,Z as f,D as x,_ as E,H as I,$ as S,a0 as C,P,a1 as y,a2 as N,a3 as v,a4 as b,a5 as w,a6 as V,I as H,B as T,a7 as k,k as F,S as G,a8 as B,a as D,M as A,a9 as U,aa as O,ab as Y,ac as X,ad as q,ae as R,af as M,ag as L,ah as z,ai as W,T as Q,aj as Z,ak as j,al as K,am as J,C as $,an as ee,Q as te,q as se,ao as ie,ap as re,p as ne,m as he,aq as ae,ar as oe,as as me,L as ge,n as le,at as _e,au as de,av as pe,aw as ue,ax as ce,ay as fe,u as xe,az as Ee,aA as Ie,aB as Se,aC as Ce,aD as Pe,aE as ye,i as Ne,aF as ve,aG as be,aH as we,aI as Ve,aJ as He,aK as Te,aL as ke,aM as Fe,aN as Ge,aO as Be,aP as De,aQ as Ae}from"./Polyline.js";import{S as Ue}from"./SimpleGeometryCursor.js";import{a as Oe,b as Ye}from"./Densificator-DB2izaQs.js";class Xe{assign(e){this.m_reason=e.m_reason,this.m_vertexIndex1=e.m_vertexIndex1,this.m_vertexIndex2=e.m_vertexIndex2}constructor(e,t,s){void 0!==e?(this.m_reason=e,this.m_vertexIndex1=t,this.m_vertexIndex2=s):(this.m_reason=0,this.m_vertexIndex1=-1,this.m_vertexIndex2=-2)}clear(){e(0)}}class qe{constructor(e){this.m_currentShift=63n,this.m_currentElt=0n,this.m_iCurrentElt=-1,this.m_parent=e,this.m_aiSetElts=e.getSetIndexes_()}next(){if(this.m_currentShift++,64n===this.m_currentShift){if(this.m_iCurrentElt++,this.m_iCurrentElt===this.m_aiSetElts.length)return qe.npos();this.m_currentShift=0n,this.m_currentElt=this.m_parent.m_bits[this.m_aiSetElts[this.m_iCurrentElt]]}for(;this.m_currentShift<63n&&!(this.m_currentElt&1n<<this.m_currentShift);)this.m_currentShift++;return this.m_currentElt&1n<<this.m_currentShift?64*this.m_aiSetElts[this.m_iCurrentElt]+Number(this.m_currentShift):this.next()}static npos(){return Number.MAX_SAFE_INTEGER}}function Re(e){return 1n<<(0x3fn&BigInt(e))}function Me(e){return e>>6}class Le{constructor(e){this.m_bits=[]}assignMove(){return this}assignCopy(){return this}getSetElts_(){const e=[];return this.m_bits.map((t=>{t&&e.push(t)})),e}getSetIndexes_(){const e=[];return this.m_bits.map(((t,s)=>{t&&e.push(s)})),e}hasBit(e){const t=Re(e),s=Me(e);return void 0!==this.m_bits[s]&&!!(this.m_bits[s]&t)}setBit(e){const t=Re(e),s=Me(e);void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]|=t}clearBit(e){}flipBit(e){const t=Re(e),s=Me(e);return void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]^=t,0n!==(this.m_bits[s]&t)}clear(){this.m_bits.length=0}isZero(){return!1}equals(e){const t=this.getSetElts_(),s=e.getSetElts_();if(t.length!==s.length)return!1;for(let i=0;i<t.length;++i)if(t[i]!==s[i])return!1;return!0}notEquals(e){return!this.equals(e)}assignOr(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]|=e.m_bits[s];return this}assignSubtract(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]&=~e.m_bits[s];return this}assignAnd(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]&=e.m_bits[s];return this}assignXor(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]^=e.m_bits[s];return this}getHashCode(){return this.getSetElts_().reduce(((e,t)=>ue(e,t)),0)}getUnorderedBitIterator(){return new qe(this)}}class ze extends de{constructor(e){super(),this.m_bufferLeft=new G,this.m_bufferRight=new G,this.m_intervalLeft=le.constructEmpty(),this.m_intervalRight=le.constructEmpty(),this.m_yScanline=Number.NaN,this.m_helper=e}compare(e,t,s){const i=t,r=e.getElement(s);this.m_helper.querySegmentXY(i,this.m_bufferLeft),this.m_helper.querySegmentXY(r,this.m_bufferRight);const n=this.m_bufferLeft.get(),h=this.m_bufferRight.get();if(this.m_intervalLeft.setCoords(n.getStartX(),n.getEndX()),this.m_intervalRight.setCoords(h.getStartX(),h.getEndX()),this.m_intervalLeft.vmax<this.m_intervalRight.vmin)return-1;if(this.m_intervalLeft.vmin>this.m_intervalRight.vmax)return 1;const a=n.getStartY()===n.getEndY(),o=h.getStartY()===h.getEndY();if(a||o){if(a&&o)return 0;if(n.getStartY()===h.getStartY()&&n.getStartX()===h.getStartX())return a?1:-1;if(n.getEndY()===h.getEndY()&&n.getEndX()===h.getEndX())return a?-1:1}let m=n.intersectionOfYMonotonicWithAxisX(this.m_yScanline,this.m_intervalLeft.vmin),g=h.intersectionOfYMonotonicWithAxisX(this.m_yScanline,this.m_intervalRight.vmin);if(m===g){const e=n.getEndY(),t=h.getEndY(),s=Math.min(e,t);let i=.5*(s+this.m_yScanline);i===this.m_yScanline&&(i=s),m=n.intersectionOfYMonotonicWithAxisX(i,this.m_intervalLeft.vmin),g=h.intersectionOfYMonotonicWithAxisX(i,this.m_intervalRight.vmin)}return m<g?-1:m>g?1:0}setY(e){this.m_yScanline=e}}class We{constructor(e){this.m_segmentBuffer=new G,this.m_point=F.getNAN(),this.m_parent=e}setPointXY(e){this.m_point.assign(e)}compare(e,t){const s=e.getElement(t);this.m_parent.querySegmentXY(s,this.m_segmentBuffer);const i=this.m_segmentBuffer.get(),r=new le;if(r.setCoords(i.getStartX(),i.getEndX()),this.m_point.x<r.vmin)return-1;if(this.m_point.x>r.vmax)return 1;const n=i.intersectionOfYMonotonicWithAxisX(this.m_point.y,this.m_point.x);return this.m_point.x<n?-1:this.m_point.x>n?1:0}}var Qe,Ze;function je(e,t){return{parentage:e,rank:t}}function Ke(e,t){const s=e.length;if(s!==t.length)return!1;const i=e[0].parentage;if(i!==t[0].parentage)return!1;if(-1===i)return!0;for(let r=1;r<s;++r)if(e[r].parentage!==t[r].parentage)return!1;return!0}function Je(e,t,s){s.length=0;let i=!1;{let r=e.getHalfEdgeVertexIterator(t);for(;r!==H;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(je(h,n)),r=e.incrementVertexIterator(r)}}{let r=e.getHalfEdgeVertexIterator(e.getHalfEdgeTwin(t));for(;r!==H;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(je(h,n)),r=e.incrementVertexIterator(r)}}i&&s.sort(((e,t)=>e.rank>t.rank?-1:e.rank<t.rank?1:e.parentage<t.parentage?-1:e.parentage>t.parentage?1:0)),-1===s[0].parentage&&(s.length=1)}!function(e){e[e.enumInputModeBuildGraph=0]="enumInputModeBuildGraph",e[e.enumInputModeSimplifyAlternate=1]="enumInputModeSimplifyAlternate",e[e.enumInputModeSimplifyWinding=2]="enumInputModeSimplifyWinding"}(Qe||(Qe={})),function(e){e[e.enumSegmentParentageBreakNode=1]="enumSegmentParentageBreakNode",e[e.enumPathBreakNode=2]="enumPathBreakNode"}(Ze||(Ze={}));class $e{constructor(){this.m_shape=null,this.m_clusterData=new M(8),this.m_clusterVertices=new M(2),this.m_firstCluster=H,this.m_lastCluster=H,this.m_halfEdgeData=new M(8),this.m_chainData=new M(8),this.m_chainAreas=null,this.m_chainPerimeters=null,this.m_universeChain=-1,this.m_simplifiedGeometry=-1,this.m_edgeIndices=[],this.m_clusterIndices=[],this.m_chainIndices=[],this.m_bBuildGeometryParentageSets=!1,this.m_chainBitSetIndex=-1,this.m_edgeBitSetIndex=-1,this.m_edgeBitSetIndexLeft=-1,this.m_emptyBitSet=null,this.m_geometryMapID=null,this.m_uniqueBitSets=null,this.m_chainBitSets=[],this.m_edgeBitSets=[],this.m_checkDirtyPlanesweepTolerance=Number.NaN,this.m_geometryIDIndex=-1,this.m_clusterIndex=-1,this.m_halfEdgeIndex=-1,this.m_tmpHalfEdgeParentageIndex=-1,this.m_tmpHalfEdgeParentageIndexLeft=-1,this.m_tmpHalfEdgeWindingNumberIndex=-1,this.m_tmpHalfEdgeOddEvenNumberIndex=-1,this.m_segmentParentageIndex=-1,this.m_segmentIndexHe=-1,this.m_clusterBreakNodeIndex=-1,this.m_universeGeomID=-1,this.m_pointCount=0,this.m_progressCounter=0,this.m_bBuildChains=!0,this.m_bDirtyCheckFailed=!1}setCheckDirtyPlanesweepTolerance(e){this.m_checkDirtyPlanesweepTolerance=e}dirtyCheckFailed(){return this.m_bDirtyCheckFailed}getShape(){return this.m_shape}setEditShape(e,t,s=!0,i=!1){i?this.setEditShapeImpl3D_(e,Qe.enumInputModeBuildGraph,null,t,!1):this.setEditShapeImpl_(e,Qe.enumInputModeBuildGraph,null,t,s)}setAndSimplifyEditShapeAlternate(e,t,s=null,r=!1){const n=[];n.push(t),this.m_simplifiedGeometry=t,r?this.setEditShapeImpl3D_(e,Qe.enumInputModeSimplifyAlternate,n,s,!1):this.setEditShapeImpl_(e,Qe.enumInputModeSimplifyAlternate,n,s,e.getGeometryType(t)===i.enumPolygon)}setAndSimplifyEditShapeWinding(e,t,s=null){const i=[];i.push(t),this.m_simplifiedGeometry=t,this.setEditShapeImpl_(e,Qe.enumInputModeSimplifyWinding,i,s,!0)}removeShape(){null!==this.m_shape&&(-1!==this.m_geometryIDIndex&&(this.m_shape.removeGeometryUserIndex(this.m_geometryIDIndex),this.m_geometryIDIndex=-1),-1!==this.m_clusterIndex&&(this.m_shape.removeUserIndex(this.m_clusterIndex),this.m_clusterIndex=-1),-1!==this.m_halfEdgeIndex&&(this.m_shape.removeUserIndex(this.m_halfEdgeIndex),this.m_halfEdgeIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),-1!==this.m_tmpHalfEdgeWindingNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeWindingNumberIndex),this.m_tmpHalfEdgeWindingNumberIndex=-1),-1!==this.m_tmpHalfEdgeOddEvenNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeOddEvenNumberIndex),this.m_tmpHalfEdgeOddEvenNumberIndex=-1),-1!==this.m_segmentParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_segmentParentageIndex),this.m_segmentParentageIndex=-1),-1!==this.m_segmentIndexHe&&(this.deleteUserIndexForHalfEdges(this.m_segmentIndexHe),this.m_segmentIndexHe=-1),-1!==this.m_clusterBreakNodeIndex&&(this.deleteUserIndexForClusters(this.m_clusterBreakNodeIndex),this.m_clusterBreakNodeIndex=-1),this.deleteEdgeBitSets_(),this.deleteChainBitSets_(),this.m_emptyBitSet=null,this.m_geometryMapID=null,this.m_shape=null,this.m_clusterData.deleteAll(!0),this.m_clusterVertices.deleteAll(!0),this.m_firstCluster=H,this.m_lastCluster=H,this.m_halfEdgeData.deleteAll(!0),this.m_edgeIndices.length=0,this.m_clusterIndices.length=0,this.m_chainIndices.length=0,this.m_chainData.deleteAll(!0),this.m_universeChain=H,this.m_chainAreas=null)}getClusterHalfEdge(e){return this.m_clusterData.getField(e,2)}queryXY(e,t){const s=this.getClusterVertexIndex_(e);t.assign(this.m_shape.getXYWithIndex(s))}queryXYZ(t,s){e(0)}getClusterParentage(e){return this.m_clusterData.getField(e,1)}getFirstCluster(){return this.m_firstCluster}getPrevCluster(e){return this.m_clusterData.getField(e,3)}getNextCluster(e){return this.m_clusterData.getField(e,4)}getClusterChain(e){return this.m_clusterData.getField(e,6)}getClusterVertexIterator(e){return this.m_clusterData.getField(e,7)}incrementVertexIterator(e){return this.m_clusterVertices.getField(e,1)}getVertexFromVertexIterator(e){return this.m_clusterVertices.getField(e,0)}getClusterUserIndex(e,t){const s=this.getClusterIndex_(e),i=this.m_clusterIndices[t];return i.size()<=s?-1:i.read(s)}setClusterUserIndex(e,t,s){const i=this.getClusterIndex_(e),r=this.m_clusterIndices[t];r.size()<=i&&r.resize(this.m_clusterData.size(),-1),r.write(i,s)}hasClusterUserIndexFlags(e,t,s){if(-1===t)return!1;const i=this.getClusterUserIndex(e,t);return-1!==i&&!!(s&i)}setClusterUserIndexFlags(e,t,s){const i=this.getClusterIndex_(e),r=this.m_clusterIndices[t];r.size()<=i&&r.resize(this.m_clusterData.size(),-1);let n=r.read(i);-1===n&&(n=0),r.write(i,s|n)}clearClusterUserIndexFlags(t,s,i){e(0)}createUserIndexForClusters(e=-1){const t=new c(this.m_clusterData.capacity(),e);for(let s=0,i=this.m_clusterIndices.length;s<i;s++)if(null===this.m_clusterIndices[s])return this.m_clusterIndices[s]=t,s;this.m_clusterIndices.push(t);return this.m_clusterIndices.length-1}deleteUserIndexForClusters(e){this.m_clusterIndices[e]=null}getHalfEdgeOrigin(e){return this.m_halfEdgeData.getField(e,1)}getHalfEdgeTo(e){return this.getHalfEdgeOrigin(this.getHalfEdgeTwin(e))}getHalfEdgeTwin(e){return this.m_halfEdgeData.getField(e,4)}getHalfEdgePrev(e){return this.m_halfEdgeData.getField(e,5)}getHalfEdgeNext(e){return this.m_halfEdgeData.getField(e,6)}getHalfEdgeChain(e){return this.m_halfEdgeData.getField(e,2)}getHalfEdgeFaceParentage(e){return this.getChainParentage(this.getHalfEdgeChain(e))}getHalfEdgeVertexIterator(e){return this.m_halfEdgeData.getField(e,7)}getHalfEdgeFromXY(e,t){this.queryXY(this.getHalfEdgeOrigin(e),t)}getHalfEdgeToXY(e,t){this.queryXY(this.getHalfEdgeTo(e),t)}isHalfEdgeCurve(e){if(-1!==this.m_segmentIndexHe){return-1!==this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe)}return!1}getHalfEdgeFromXYZ(t,s){e(0)}getHalfEdgeToXYZ(t,s){e(0)}getHalfEdgeParentage(e){return this.m_halfEdgeData.getField(e,3)&$e.c_EdgeParentageMask}getHalfEdgeUserIndex(e,t){const s=this.getHalfEdgeIndex_(e),i=this.m_edgeIndices[t];return i.size()<=s?-1:i.read(s)}setHalfEdgeUserIndex(e,t,s){const i=this.getHalfEdgeIndex_(e),r=this.m_edgeIndices[t];r.size()<=i&&r.resize(this.m_halfEdgeData.size(),-1),r.write(i,s)}createUserIndexForHalfEdges(t){void 0===t&&(t=-1);const s=new c(this.m_halfEdgeData.capacity(),t);for(let e=0,r=this.m_edgeIndices.length;e<r;e++)if(null===this.m_edgeIndices[e])return this.m_edgeIndices[e]=s,e;this.m_edgeIndices.push(s);const i=this.m_edgeIndices.length-1;return e(i>=0&&i<=Number.MAX_SAFE_INTEGER),i}deleteUserIndexForHalfEdges(e){this.m_edgeIndices[e]=null}deleteEdgesBreakFaces_(e){for(let t=0,s=e.length;t<s;t++){const s=e[t],i=this.getHalfEdgeChain(s),r=this.getHalfEdgeTwin(s),n=this.getHalfEdgeChain(r);this.setChainHalfEdge_(i,H),this.setChainHalfEdge_(n,H),this.updateVertexToHalfEdgeConnection_(s,!0),this.deleteEdgeImpl_(s)}}doesHalfEdgeBelongToAPolygonInterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolygonExterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolygonBoundary(t,s){return e(0),!1}doesHalfEdgeBelongToAPolylineInterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolylineExterior(t,s){return e(0),!1}doesClusterBelongToAPolygonInterior(t,s){return e(0),!1}doesClusterBelongToAPolygonExterior(t,s){return e(0),!1}doesClusterBelongToAPolygonBoundary(t,s){return e(0),!1}getFirstChain(){return this.m_universeChain}getChainHalfEdge(e){return this.m_chainData.getField(e,1)}getChainParentage(e){return this.m_chainData.getField(e,2)}getChainParent(e){return this.m_chainData.getField(e,3)}getChainFirstIsland(e){return this.m_chainData.getField(e,4)}getChainNextInParent(e){return this.m_chainData.getField(e,5)}getChainNext(e){return this.m_chainData.getField(e,7)}getChainArea(e){const t=this.getChainIndex_(e);let s=this.m_chainAreas.read(t);return Number.isNaN(s)&&(this.updateChainAreaAndPerimeter_(e),s=this.m_chainAreas.read(t)),s}getChainPerimeter(t){return e(0),0}getChainUserIndex(t,s){return e(0),0}setChainUserIndex(t,s,i){e(0)}createUserIndexForChains(){return e(0),0}deleteUserIndexForChains(t){e(0)}extractPolygonFromChainAndIslands(t,s,i,r){return e(0),0}getGeometryID(t){const s=this.m_shape.getGeometryUserIndex(t,this.m_geometryIDIndex);return e(s>=0),1<<Math.min(s,31)}getClusterFromVertex(e){return this.m_shape.getUserIndex(e,this.m_clusterIndex)}getHalfEdgeFromVertex(e){return this.m_shape.getUserIndex(e,this.m_halfEdgeIndex)}buildGeometryParentageSets(){this.m_bBuildGeometryParentageSets=!0}getChainBitSet(t){return e(0),new Le}getChainBoundaryBitSet(t){return e(0),new Le}getChainPolygons(t){return e(0),[]}getGeometriesFromBits(t){return e(0),[]}getVertexDominant(e,t){if(t===H)return e;const s=this.getClusterFromVertex(e);return this.getVertexDominantFromCluster(s,t)}getVertexDominantFromCluster(e,t){if(t!==H){let s=H;for(let i=this.getClusterVertexIterator(e);i!==H;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);s===H&&(s=e);const r=this.m_shape.getPathFromVertex(e);if(this.m_shape.getGeometryFromPath(r)===t){s=e;break}}return s}{const t=this.getClusterVertexIterator(e);if(t!==H){return this.getVertexFromVertexIterator(t)}return H}}isBreakNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode)}setBreakNode(t,s){e(-1!==this.m_clusterBreakNodeIndex),s?this.setClusterUserIndexFlags(t,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode):this.clearClusterUserIndexFlags(t,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode)}isStrongPathNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode)}setStrongPathNode(e,t){if(-1===this.m_clusterBreakNodeIndex){if(!t)return;this.m_clusterBreakNodeIndex=this.createUserIndexForClusters()}t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode)}getSegmentParentage(e){if(-1===this.m_segmentParentageIndex)return-1;const t=this.getHalfEdgeUserIndex(e,this.m_segmentParentageIndex);return t>=0?t:-1}isCrossroadAhead(e){const t=this.getHalfEdgeNext(e);if(this.isStrongPathNode(this.getHalfEdgeOrigin(t)))return!0;const s=this.getHalfEdgeTwin(t),i=this.getHalfEdgeNext(s);return e!==this.getHalfEdgeTwin(i)}isCrossroadBehind(t){return e(0),!1}getHalfEdgeConnector(e,t){const s=this.getClusterHalfEdge(e);if(s===H)return H;let i=s,r=H,n=H;do{if(this.getHalfEdgeTo(i)===t)return i;if(r===H){if(r=this.getClusterHalfEdge(t),r===H)return H;n=r}if(this.getHalfEdgeTo(n)===e)return i=this.getHalfEdgeTwin(n),i;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(i)),n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(i!==s&&n!==r);return H}querySegmentXY(e,t){if(-1!==this.m_segmentIndexHe){let s=this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe);if(-1!==s){if(-2!==s){const e=this.m_shape.getSegmentFromIndex(s);t.copyFrom(e,!0)}else{s=this.getHalfEdgeUserIndex(this.getHalfEdgeTwin(e),this.m_segmentIndexHe);const i=this.m_shape.getSegmentFromIndex(s);t.copyFrom(i,!0),t.get().reverse()}return}}t.createLine();const s=t.get(),i=F.getNAN();this.getHalfEdgeFromXY(e,i),s.setStartXY(i),this.getHalfEdgeToXY(e,i),s.setEndXY(i)}isCurveEdge(e){if(-1!==this.m_segmentIndexHe){return-1!==this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe)}return!1}compareEdgeAnglesCurveHelper_(t,s,i){const r=new G,n=new G;this.querySegmentXY(t,r),this.querySegmentXY(s,n);const h=r.get(),a=n.get();if(h.equals(a))return 0;const o=new F;this.getHalfEdgeFromXY(t,o);const m=new F;this.getHalfEdgeToXY(t,m);const g=new F;this.getHalfEdgeToXY(s,g),e(!m.isEqualPoint2D(g));const l=h.getTangent(0),_=a.getTangent(0);return F.compareVectors(l,_)}compareEdgeAnglesHelper_(e,t,s){if(e===t)return 0;if(this.isHalfEdgeCurve(e)||this.isHalfEdgeCurve(t))return this.compareEdgeAnglesCurveHelper_(e,t,s);const i=F.getNAN();this.getHalfEdgeToXY(e,i);const r=F.getNAN();if(this.getHalfEdgeToXY(t,r),i.isEqualPoint2D(r))return 0;const n=F.getNAN();this.getHalfEdgeFromXY(e,n);const h=F.getNAN();h.setSub(i,n);const a=F.getNAN();if(a.setSub(r,n),!s||a.y>=0&&h.y>0){return F.compareVectors(h,a)}return 0}compareEdgeAngles_(e,t){return this.compareEdgeAnglesHelper_(e,t,!1)}compareEdgeAnglesForPair_(e,t){return this.compareEdgeAnglesHelper_(e,t,!0)}compareEdgeAngles3D_(t,s){return e(0),0}compareEdgeAnglesForPair3D_(t,s){return e(0),0}dbgDumpChains_(){}dbgDumpChainToPolygon_(t,s){e(0)}deleteEdgeInternal_(t){const s=this.getHalfEdgeChain(t),i=this.getHalfEdgeTwin(t),r=this.getHalfEdgeChain(i);e(r===s),e(t===this.getHalfEdgeNext(i)||i===this.getHalfEdgeNext(t));let n=this.getHalfEdgeNext(t);n===i&&(n=this.getHalfEdgeNext(n),n===t&&(n=H));const h=this.getChainIndex_(s),a=this.m_chainAreas.read(h);Number.isNaN(a)||(this.setChainArea_(s,Number.NaN),this.setChainPerimeter_(s,Number.NaN));const o=this.getChainHalfEdge(s);o!==t&&o!==i||this.setChainHalfEdge_(s,n),this.updateVertexToHalfEdgeConnection_(t,!0),this.deleteEdgeImpl_(t)}getFirstUnvisitedHalfEdgeOnCluster_(e,t,s){let i=t!==H?t:this.getClusterHalfEdge(e);if(i===H)return H;const r=i;for(;;){if(1!==this.getHalfEdgeUserIndex(i,s))return i;const e=this.getHalfEdgeNext(this.getHalfEdgeTwin(i));if(e===r)return H;i=e}}removeSpikes_(){let e=!1;const t=this.createUserIndexForHalfEdges();for(let s=this.getFirstCluster();s!==H;s=this.getNextCluster(s)){let i=H;for(;;){let r=this.getFirstUnvisitedHalfEdgeOnCluster_(s,i,t);if(r===H)break;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(r));let n=r;for(;;){const s=this.getHalfEdgeNext(n),h=this.getHalfEdgePrev(n),a=this.getHalfEdgeTwin(n);if(h===a){if(this.deleteEdgeInternal_(n),e=!0,i!==n&&i!==a||(i=H),n===r||h===r){if(r=s,n===r||h===r)break;n=s;continue}}else this.setHalfEdgeUserIndex(n,t,1);if(n=s,n===r)break}}}return this.deleteUserIndexForHalfEdges(t),e}progress_(e,t=!1){}newCluster_(){const e=this.m_clusterData.newElement();return this.m_clusterData.setField(e,1,0),e}newHalfEdgePair_(){const e=this.m_halfEdgeData.newElement();this.m_halfEdgeData.setField(e,2,0),this.m_halfEdgeData.setField(e,3,0);const t=this.m_halfEdgeData.newElement();return this.m_halfEdgeData.setField(t,2,0),this.m_halfEdgeData.setField(t,3,0),this.setHalfEdgeTwin_(e,t),this.setHalfEdgeTwin_(t,e),e}newChain_(){const e=this.m_chainData.newElement();return this.m_chainData.setField(e,2,0),e}deleteChain_(t){return e(0),0}getClusterIndex_(e){return this.m_clusterData.elementToIndex(e)}setClusterVertexIterator_(e,t){this.m_clusterData.setField(e,7,t)}setClusterHalfEdge_(e,t){this.m_clusterData.setField(e,2,t)}setClusterParentage_(e,t){this.m_clusterData.setField(e,1,t)}setPrevCluster_(e,t){this.m_clusterData.setField(e,3,t)}setNextCluster_(e,t){this.m_clusterData.setField(e,4,t)}setClusterVertexIndex_(e,t){this.m_clusterData.setField(e,5,t)}getClusterVertexIndex_(e){return this.m_clusterData.getField(e,5)}setClusterChain_(e,t){this.m_clusterData.setField(e,6,t)}addClusterToExteriorChain_(e,t){this.setClusterChain_(t,e)}getHalfEdgeIndex_(e){return this.m_halfEdgeData.elementToIndex(e)}setHalfEdgeOrigin_(e,t){this.m_halfEdgeData.setField(e,1,t)}setHalfEdgeTwin_(e,t){this.m_halfEdgeData.setField(e,4,t)}setHalfEdgePrev_(e,t){this.m_halfEdgeData.setField(e,5,t)}setHalfEdgeNext_(e,t){this.m_halfEdgeData.setField(e,6,t)}setHalfEdgeChain_(e,t){this.m_halfEdgeData.setField(e,2,t)}setHalfEdgeParentage_(e,t){this.m_halfEdgeData.setField(e,3,t)}getHalfEdgeParentageMask_(e){return this.m_halfEdgeData.getField(e,3)}setHalfEdgeVertexIterator_(e,t){this.m_halfEdgeData.setField(e,7,t)}updateVertexToHalfEdgeConnectionHelper_(e,t){const s=t?H:e;for(let i=this.getHalfEdgeVertexIterator(e);i!==H;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);this.m_shape.setUserIndex(e,this.m_halfEdgeIndex,s)}}updateVertexToHalfEdgeConnection_(e,t){e!==H&&(this.updateVertexToHalfEdgeConnectionHelper_(e,t),this.updateVertexToHalfEdgeConnectionHelper_(this.getHalfEdgeTwin(e),t))}getChainIndex_(e){return this.m_chainData.elementToIndex(e)}setChainHalfEdge_(e,t){this.m_chainData.setField(e,1,t)}setChainParentage_(e,t){this.m_chainData.setField(e,2,t)}setChainParent_(e,t){this.m_chainData.setField(e,3,t);const s=this.getChainFirstIsland(t);this.setChainNextInParent_(e,s),this.setChainFirstIsland_(t,e)}setChainFirstIsland_(e,t){this.m_chainData.setField(e,4,t)}setChainNextInParent_(e,t){this.m_chainData.setField(e,5,t)}setChainPrev_(e,t){this.m_chainData.setField(e,6,t)}setChainNext_(e,t){this.m_chainData.setField(e,7,t)}setChainArea_(e,t){const s=this.getChainIndex_(e);this.m_chainAreas.write(s,t)}setChainPerimeter_(e,t){const s=this.getChainIndex_(e);this.m_chainPerimeters.write(s,t)}updateChainAreaAndPerimeter_(e){const t=this.m_shape.hasCurves(),s=new ce(0),i=new ce(0),r=this.getChainHalfEdge(e),n=F.getNAN(),h=F.getNAN(),a=F.getNAN();this.getHalfEdgeFromXY(r,n),h.setCoordsPoint2D(n);let o=r;do{this.getHalfEdgeToXY(o,a),t&&this.isCurveEdge(o)||i.pe(F.distance(h,a));this.getHalfEdgeChain(this.getHalfEdgeTwin(o))!==e&&s.pe((a.x-n.x-(h.x-n.x))*(a.y-n.y+(h.y-n.y))*.5),h.setCoordsPoint2D(a),o=this.getHalfEdgeNext(o)}while(o!==r);if(t){const t=new G;o=r;do{this.getHalfEdgeToXY(o,a);const r=this.isCurveEdge(o);r&&(this.querySegmentXY(o,t),i.pe(t.get().calculateLength2D()));if(this.getHalfEdgeChain(this.getHalfEdgeTwin(o))!==e&&r){const e=t.get().calculateArea2DHelper();s.pe(e)}o=this.getHalfEdgeNext(o)}while(o!==r)}const m=this.getChainIndex_(e);this.m_chainAreas.write(m,s.getResult()),this.m_chainPerimeters.write(m,i.getResult())}getChainTopmostEdge_(t){return e(0),0}planeSweepParentage_(e,t){const s=new ze(this),i=new _;i.setCapacity(this.m_pointCount/2),i.setComparator(s);const r=[],n=this.createUserIndexForHalfEdges();let h=null;const a=F.getNAN();for(let o=this.getFirstCluster();o!==H;o=this.getNextCluster(o)){this.progress_(t);const m=this.getClusterHalfEdge(o);if(m!==H){if(r.length=0,!this.tryOptimizedInsertion_(i,n,r,o,m)){this.queryXY(o,a),s.setY(a.y);let e=m;do{const t=this.getHalfEdgeUserIndex(e,n);-1!==t&&(i.deleteNode(t),this.setHalfEdgeUserIndex(e,n,M.impossibleIndex2())),e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(m!==e);e=m;do{if(-1===this.getHalfEdgeUserIndex(e,n)){const t=i.addElement(e);r.push(t)}e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(m!==e)}for(let t=r.length-1;t>=0;t--){const s=r[t],h=i.getElement(s),a=this.getHalfEdgeTwin(h);this.setHalfEdgeUserIndex(a,n,s),this.planeSweepParentagePropagateParentage_(i,s,e)}}else if(this.getClusterChain(o)===H){null===h&&(h=new We(this)),this.queryXY(o,a),h.setPointXY(a);const e=i.searchLowerBound(h);let t=this.m_universeChain;if(-1!==e){let s=i.getElement(e);this.getHalfEdgeChain(s)===this.getHalfEdgeChain(this.getHalfEdgeTwin(s))&&(s=this.getLeftSkipPolylines_(i,e)),s!==H&&(t=this.getHalfEdgeChain(s))}this.addClusterToExteriorChain_(t,o)}}this.deleteUserIndexForHalfEdges(n)}planeSweepParentagePropagateParentage_(t,s,i){const r=t.getElement(s),n=this.getHalfEdgeChain(r);if(this.getChainParent(n)!==H)return;const h=this.getLeftSkipPolylines_(t,s),a=this.getHalfEdgeTwin(r),o=this.getHalfEdgeChain(a);let m=this.getChainParent(n),g=this.getChainParent(o);if(h===H)m===H&&(o===n?(this.setChainParent_(o,this.m_universeChain),g=this.m_universeChain,m=g):(g===H&&(this.setChainParent_(o,this.m_universeChain),g=this.m_universeChain),this.setChainParent_(n,o),m=o));else{const e=this.getHalfEdgeChain(h);if(g===H){if(this.getChainArea(e)<=0){const t=this.getChainParent(e);this.setChainParent_(o,t),g=t}else this.setChainParent_(o,e),g=e;o===n&&(m=g)}}m===H&&(this.trySetChainParentFromTwin_(n,o),m=this.getChainParent(n)),e(m!==H),i===Qe.enumInputModeBuildGraph?this.propagateParentageBuildGraph_(t,s,r,h):i===Qe.enumInputModeSimplifyWinding?this.propagateParentageWinding_(t,s,r,h,a,n,o):i===Qe.enumInputModeSimplifyAlternate&&this.propagateParentageAlternate_(t,s,r,h,a,n,o)}propagateParentageBuildGraph_(e,t,s,i){let r,n=t;i===H?(n=e.getNext(n),r=this.getHalfEdgeChain(s)):r=this.getHalfEdgeChain(i);let h=null,a=this.getChainParentage(r);for(this.m_bBuildGeometryParentageSets&&(h=this.getChainBitSet(r));-1!==n;n=e.getNext(n)){const t=e.getElement(n),s=this.getHalfEdgeTwin(t);r=this.getHalfEdgeChain(t);const i=this.getHalfEdgeChain(s);if(this.m_bBuildGeometryParentageSets){let e=this.getChainBitSet(i);e=new Le({copy:e}),e.assignOr(h),this.setChainBitSet_(i,e);let s=this.getChainBitSet(r);const n=this.getLeftEdgeBitSet_(t),a=new Le({copy:h});if(a.assignSubtract(n),a.isZero())break;s=new Le({copy:s}),s.assignOr(a),this.setChainBitSet_(r,s),h=s}const o=this.getChainParentage(i),m=o|a;m!==o&&this.setChainParentage_(i,m);let g=this.getChainParentage(r);const l=a&~this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeParentageIndexLeft);if(l&&(g|=l,this.setChainParentage_(r,g)),0===l)break;a=g}}propagateParentageWinding_(t,s,i,r,n,h,a){if(h===a)return;let o=this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex);o+=this.getHalfEdgeUserIndex(n,this.m_tmpHalfEdgeWindingNumberIndex);let m=0;const g=[],l=[];l.push(0);for(let _=t.getFirst();_!==s;_=t.getNext(_)){const s=t.getElement(_),i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeChain(s),n=this.getHalfEdgeChain(i);if(r!==n){let t=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex);t+=this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),m+=t;let h=!1;0!==g.length&&g.at(-1)===n&&(l.pop(),g.pop(),h=!0),e(this.getChainParent(n)!==H),h&&this.getChainParent(n)===r||(l.push(m),g.push(r))}}if(m+=o,0!==g.length&&g.at(-1)===a&&(l.pop(),g.pop()),0!==m){if(0===l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(h,t)}}else if(0!==l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(h,t)}}propagateParentageAlternate_(t,s,i,r,n,h,a){e(0)}tryOptimizedInsertion_(e,t,s,i,r){let n=r,h=-1,a=H,o=0;do{if(2===o)return!1;const e=this.getHalfEdgeUserIndex(n,t);if(-1!==e){if(-1!==h)return!1;h=e}else{if(a!==H)return!1;a=n}o++,n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(r!==n);return a!==H&&-1!==h&&(this.setHalfEdgeUserIndex(e.getElement(h),t,M.impossibleIndex2()),e.setElement(h,a),s.push(h),!0)}trySetChainParentFromTwin_(e,t){const s=this.getChainArea(e);if(0===s)return!1;const i=this.getChainArea(t);if(s>0&&i<0||s<0&&i>0)return this.setChainParent_(e,t),!0;{const s=this.getChainParent(t);if(s!==H)return this.setChainParent_(e,s),!0}return!1}createHalfEdges_(e,t){this.m_halfEdgeIndex=this.m_shape.createUserIndex();for(let s=0,r=t.size();s<r;s++){const r=t.read(s),n=this.m_shape.getUserIndex(r,this.m_clusterIndex),h=this.m_shape.getPathFromVertex(r),a=this.m_shape.getGeometryFromPath(h),o=this.m_shape.getGeometryType(a);if(u(o)){const t=this.m_shape.getNextVertex(r);if(t===H)continue;const s=this.m_shape.getUserIndex(t,this.m_clusterIndex);if(n===s)continue;const h=this.newHalfEdgePair_(),m=this.getHalfEdgeTwin(h),g=this.m_clusterVertices.newElement();this.m_clusterVertices.setField(g,0,r),this.m_clusterVertices.setField(g,1,-1),this.setHalfEdgeVertexIterator_(h,g),this.m_shape.setUserIndex(r,this.m_halfEdgeIndex,h),this.setHalfEdgeOrigin_(h,n);const l=this.getClusterHalfEdge(n);if(l===H)this.setClusterHalfEdge_(n,h),this.setHalfEdgePrev_(h,m),this.setHalfEdgeNext_(m,h);else{const e=this.getHalfEdgePrev(l);this.setHalfEdgePrev_(l,m),this.setHalfEdgeNext_(m,l),this.setHalfEdgeNext_(e,h),this.setHalfEdgePrev_(h,e)}this.setHalfEdgeOrigin_(m,s);const _=this.getClusterHalfEdge(s);if(_===H)this.setClusterHalfEdge_(s,m),this.setHalfEdgeNext_(h,m),this.setHalfEdgePrev_(m,h);else{const e=this.getHalfEdgePrev(_);this.setHalfEdgePrev_(_,h),this.setHalfEdgeNext_(h,_),this.setHalfEdgeNext_(e,m),this.setHalfEdgePrev_(m,e)}const d=this.getGeometryID(a);if(e===Qe.enumInputModeBuildGraph){const e=o===i.enumPolygon?d:0;if(this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeParentageIndex,0),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,e),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeParentageIndexLeft,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,0),this.m_bBuildGeometryParentageSets){const e=new Le,t=this.m_shape.getGeometryUserIndex(a,this.m_geometryIDIndex);e.setBit(t),this.setEdgeBitSet_(h,e),this.setEdgeBitSet_(m,null),this.setLeftEdgeBitSet_(m,e),this.setLeftEdgeBitSet_(h,null)}}else if(e===Qe.enumInputModeSimplifyWinding){const e=this.m_shape.getXY(r),s=this.m_shape.getXY(t);let i=0,n=0;e.compare(s)<0?i=1:n=-1,this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,i),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeWindingNumberIndex,n)}else e===Qe.enumInputModeSimplifyAlternate&&(this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,1),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeOddEvenNumberIndex,1));const p=o===i.enumPolygon?$e.c_EdgeBitMask:0;this.setHalfEdgeParentage_(h,d|p),this.setHalfEdgeParentage_(m,d|p)}}if(this.m_shape.hasCurves()){this.m_segmentIndexHe=this.createUserIndexForHalfEdges();for(let e=0,s=t.size();e<s;e++){const s=t.read(e);if(this.m_shape.getSegment(s)){const e=this.m_shape.getUserIndex(s,this.m_halfEdgeIndex);e!==H&&(this.setHalfEdgeUserIndex(e,this.m_segmentIndexHe,this.m_shape.getVertexIndex(s)),this.setHalfEdgeUserIndex(this.getHalfEdgeTwin(e),this.m_segmentIndexHe,-2))}}}}mergeVertexListsOfEdges_(e,t){{const s=this.getHalfEdgeVertexIterator(t);if(s!==H){const i=this.getHalfEdgeVertexIterator(e);this.m_clusterVertices.setField(s,1,i),this.setHalfEdgeVertexIterator_(e,s),this.setHalfEdgeVertexIterator_(t,H)}}const s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeTwin(t);{const e=this.getHalfEdgeVertexIterator(i);if(e!==H){const t=this.getHalfEdgeVertexIterator(s);this.m_clusterVertices.setField(e,1,t),this.setHalfEdgeVertexIterator_(s,e),this.setHalfEdgeVertexIterator_(i,H)}}if(-1!==this.m_segmentIndexHe){let r=this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe);if(-1!==r){if(-2===r){const s=this.getHalfEdgeUserIndex(t,this.m_segmentIndexHe);this.setHalfEdgeUserIndex(e,this.m_segmentIndexHe,s)}if(r=this.getHalfEdgeUserIndex(s,this.m_segmentIndexHe),-2===r){const e=this.getHalfEdgeUserIndex(i,this.m_segmentIndexHe);this.setHalfEdgeUserIndex(s,this.m_segmentIndexHe,e)}}}}sortHalfEdgesByAngle_(e){const t=[];for(let s=this.getFirstCluster();s!==H;s=this.getNextCluster(s)){t.length=0;const i=this.getClusterHalfEdge(s);if(i!==H){let r=i;do{t.push(r),r=this.getHalfEdgeNext(this.getHalfEdgeTwin(r))}while(r!==i);if(t.length>1){let r=!0;t.length>2?(t.sort(((e,t)=>this.compareEdgeAngles_(e,t))),t.push(t[0])):this.compareEdgeAnglesForPair_(t[0],t[1])>0?t[1]=q(t[0],t[0]=t[1]):r=!1;let n=t[0],h=n,a=this.getHalfEdgeTo(h),o=this.getHalfEdgeTwin(h),m=H;for(let s=1,i=t.length;s<i;s++){const i=t[s],r=this.getHalfEdgeTwin(i),g=this.getHalfEdgeOrigin(r);if(g!==a||i===h)this.updateVertexToHalfEdgeConnection_(m,!1),m=H,h=i,a=g,o=r;else{if(e===Qe.enumInputModeBuildGraph){const e=this.getHalfEdgeParentageMask_(h)|this.getHalfEdgeParentageMask_(i);if(this.setHalfEdgeParentage_(h,e),this.setHalfEdgeParentage_(o,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndexLeft)),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndexLeft)|this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeParentageIndexLeft)),this.m_bBuildGeometryParentageSets){let e,t,s;e=this.getEdgeBitSet_(h),t=this.getEdgeBitSet_(i),s=new Le({copy:e}),s.assignOr(t),this.setEdgeBitSet_(h,s),e=this.getEdgeBitSet_(o),t=this.getEdgeBitSet_(r),s=new Le({copy:e}),s.assignOr(t),this.setEdgeBitSet_(o,s),e=this.getLeftEdgeBitSet_(h),t=this.getLeftEdgeBitSet_(i),s=new Le({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(h,s),e=this.getLeftEdgeBitSet_(o),t=this.getLeftEdgeBitSet_(r),s=new Le({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(o,s)}}else if(-1!==this.m_tmpHalfEdgeWindingNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),t=this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,e),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeWindingNumberIndex,t)}else if(-1!==this.m_tmpHalfEdgeOddEvenNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeOddEvenNumberIndex),t=this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeOddEvenNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,e),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeOddEvenNumberIndex,t)}this.mergeVertexListsOfEdges_(h,i),this.deleteEdgeImpl_(i),m=h,t[s]=H,i===n&&(t[0]=H,n=H)}}if(this.updateVertexToHalfEdgeConnection_(m,!1),m=H,!r){n=H;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s!==H){n=s;break}}i!==n&&this.setClusterHalfEdge_(s,n);continue}n=H;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s===H)continue;if(n===H){n=s,h=n,a=this.getHalfEdgeTo(h),o=this.getHalfEdgeTwin(h);continue}if(s===h)continue;const i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeOrigin(i);this.setHalfEdgeNext_(o,s),this.setHalfEdgePrev_(s,o),h=s,a=r,o=i}this.setClusterHalfEdge_(s,n)}}}}sortHalfEdgesByAngleHelper_(t){e(0)}sortHalfEdgesByAngle3D_(t){e(0)}buildChains_(e){this.m_universeChain=this.newChain_(),this.setChainHalfEdge_(this.m_universeChain,H);let t=this.m_universeChain;const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==H;i=this.getNextCluster(i)){const e=this.getClusterHalfEdge(i);if(e!==H){let i=e;do{if(1!==this.getHalfEdgeUserIndex(i,s)){const e=this.newChain_();let r;this.setChainHalfEdge_(e,i),this.setChainPrev_(e,t),this.setChainNext_(t,e),this.m_bBuildGeometryParentageSets&&(r=new Le),t=e;let n=0,h=i;do{-1!==this.m_tmpHalfEdgeParentageIndex&&(n|=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)),this.m_bBuildGeometryParentageSets&&r.assignOr(this.getEdgeBitSet_(h)),this.setHalfEdgeChain_(h,e),this.setHalfEdgeUserIndex(h,s,1),h=this.getHalfEdgeNext(h)}while(h!==i);this.m_bBuildGeometryParentageSets&&this.setChainBitSet_(e,r),this.setChainParentage_(e,n)}i=this.getHalfEdgeNext(this.getHalfEdgeTwin(i))}while(i!==e)}}this.m_chainAreas=new L(this.m_chainData.size(),Number.NaN),this.m_chainPerimeters=new L(this.m_chainData.size(),Number.NaN),this.setChainArea_(this.m_universeChain,Number.POSITIVE_INFINITY),this.setChainPerimeter_(this.m_universeChain,Number.POSITIVE_INFINITY),this.deleteUserIndexForHalfEdges(s)}simplify_(t){e(0)}simplifyAlternate_(){e(0)}simplifyWinding_(){e(0)}setEditShapeImpl_(e,t,s,i,r){this.removeShape(),this.m_bBuildChains=r,this.m_shape=e,this.m_geometryIDIndex=this.m_shape.createGeometryUserIndex();let n=this.m_shape.getTotalPointCount();if(s){n=0;for(let e=0,t=s.length;e<t;e++)n+=this.m_shape.getPointCount(s[e])}const h=new c(0);let a=0,o=0;{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==H;){this.m_shape.setGeometryUserIndex(e,this.m_geometryIDIndex,o++);for(let t=this.m_shape.getFirstPath(e);t!==H;t=this.m_shape.getNextPath(t)){let e=this.m_shape.getFirstVertex(t);for(let s=0,i=this.m_shape.getPathSize(t);s<i;s++)h.add(e),e=this.m_shape.getNextVertex(e)}z(this.m_shape.getGeometryType(e))||(a+=this.m_shape.getPathCount(e)),null!=s?(e=t<s.length?s[t]:H,t++):e=this.m_shape.getNextGeometry(e)}}this.m_universeGeomID=1<<Math.min(o,31),this.m_pointCount=h.size(),this.m_shape.sortVerticesSimpleByY(h,0,this.m_pointCount),this.m_clusterVertices.setCapacity(this.m_pointCount),this.progress_(i,!0),this.m_clusterData.setCapacity(this.m_pointCount+10),this.m_halfEdgeData.setCapacity(2*this.m_pointCount+32),this.m_chainData.setCapacity(Math.max(32,a)),this.m_clusterIndex=this.m_shape.createUserIndex();const m=F.getNAN();let g=0;const l=F.getNAN();for(let _=0;_<=this.m_pointCount;_++){if(_<this.m_pointCount){const e=h.read(_);this.m_shape.queryXY(e,l)}else l.setNAN();if(!m.isEqualPoint2D(l)){if(g<_){const e=this.newCluster_();let t=H,s=-1;for(let i=g;i<_;i++){s=h.read(i),this.m_shape.setUserIndex(s,this.m_clusterIndex,e);const r=this.m_clusterVertices.newElement();this.m_clusterVertices.setField(r,0,s),this.m_clusterVertices.setField(r,1,t),t=r;const n=this.m_shape.getPathFromVertex(s),a=this.m_shape.getGeometryFromPath(n),o=this.getGeometryID(a);this.setClusterParentage_(e,this.getClusterParentage(e)|o)}this.setClusterVertexIterator_(e,t),this.setClusterVertexIndex_(e,this.m_shape.getVertexIndex(s)),this.m_lastCluster!==H&&this.setNextCluster_(this.m_lastCluster,e),this.setPrevCluster_(e,this.m_lastCluster),this.m_lastCluster=e,this.m_firstCluster===H&&(this.m_firstCluster=e)}g=_,m.setCoordsPoint2D(l)}}if(this.m_shape.hasSegmentParentage()){-1===this.m_clusterBreakNodeIndex&&(this.m_clusterBreakNodeIndex=this.createUserIndexForClusters());for(let e=0;e<this.m_pointCount;e++){const t=h.read(e);if(this.m_shape.getSegmentParentageBreakVertex(t)){const e=this.getClusterFromVertex(t);this.setBreakNode(e,!0)}}}this.progress_(i,!0);{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==H;){for(let t=this.m_shape.getFirstPath(e);t!==H;t=this.m_shape.getNextPath(t)){if(this.m_shape.isStrongPathStart(t)){const e=this.m_shape.getFirstVertex(t),s=this.getClusterFromVertex(e);this.setStrongPathNode(s,!0)}if(this.m_shape.isStrongPathEnd(t)){const e=this.m_shape.isClosedPath(t)?this.m_shape.getFirstVertex(t):this.m_shape.getLastVertex(t),s=this.getClusterFromVertex(e);this.setStrongPathNode(s,!0)}}null!=s?(e=t<s.length?s[t]:H,t++):e=this.m_shape.getNextGeometry(e)}}if(t===Qe.enumInputModeBuildGraph&&(this.m_tmpHalfEdgeParentageIndex=this.createUserIndexForHalfEdges(),this.m_tmpHalfEdgeParentageIndexLeft=this.createUserIndexForHalfEdges()),t===Qe.enumInputModeSimplifyWinding&&(this.m_tmpHalfEdgeWindingNumberIndex=this.createUserIndexForHalfEdges()),t===Qe.enumInputModeSimplifyAlternate&&(this.m_tmpHalfEdgeOddEvenNumberIndex=this.createUserIndexForHalfEdges()),this.createHalfEdges_(t,h),this.dbgNavigate_(),this.sortHalfEdgesByAngle_(t),!Number.isNaN(this.m_checkDirtyPlanesweepTolerance)&&!this.checkStructureAfterDirtySweep_())return this.m_bDirtyCheckFailed=!0,void this.cleanSetEditShapeImpl_();this.buildChains_(t),-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),this.m_bBuildChains&&this.planeSweepParentage_(t,i),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),this.dbgChkChainParents_(),this.dbgDumpChains_(),this.mergeSegmentParentage_(),this.dbgNavigate_(),this.dbgDumpChains_(),this.cleanSetEditShapeImpl_()}setEditShapeImpl3D_(t,s,i,r,n){e(0)}cleanSetEditShapeImpl_(){-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),-1!==this.m_tmpHalfEdgeWindingNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeWindingNumberIndex),this.m_tmpHalfEdgeWindingNumberIndex=-1),-1!==this.m_tmpHalfEdgeOddEvenNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeOddEvenNumberIndex),this.m_tmpHalfEdgeOddEvenNumberIndex=-1)}cleanSetEditShapeImpl3D_(){e(0)}dbgNavigate_(){}dbgChkChainParents_(){}deleteEdgeImpl_(e){const t=this.getHalfEdgeNext(e),s=this.getHalfEdgePrev(e),i=this.getHalfEdgeTwin(e),r=this.getHalfEdgeNext(i),n=this.getHalfEdgePrev(i);t!==i&&(this.setHalfEdgeNext_(n,t),this.setHalfEdgePrev_(t,n)),s!==i&&(this.setHalfEdgeNext_(s,r),this.setHalfEdgePrev_(r,s));const h=this.getHalfEdgeOrigin(e);this.getClusterHalfEdge(h)===e&&(r!==e?this.setClusterHalfEdge_(h,r):this.setClusterHalfEdge_(h,H));const a=this.getHalfEdgeOrigin(i);this.getClusterHalfEdge(a)===i&&(t!==i?this.setClusterHalfEdge_(a,t):this.setClusterHalfEdge_(a,H)),this.m_halfEdgeData.deleteElement(e),this.m_halfEdgeData.deleteElement(i)}getLeftSkipPolylines_(e,t){let s=t;for(;;){if(s=e.getPrev(s),-1===s)return H;{const t=e.getElement(s);if(this.getHalfEdgeChain(t)!==this.getHalfEdgeChain(this.getHalfEdgeTwin(t)))return t}}}checkStructureAfterDirtySweep_(){const e=W(this.m_checkDirtyPlanesweepTolerance),t=new F,s=new F,i=new F,r=new F,n=new F;for(let h=this.getFirstCluster();h!==H;h=this.getNextCluster(h)){const a=this.getClusterHalfEdge(h);if(a!==H){let h=a;this.getHalfEdgeFromXY(h,t),this.getHalfEdgeToXY(h,s),i.setSub(s,t);let o=i.sqrLength();do{const a=h;if(h=this.getHalfEdgeNext(this.getHalfEdgeTwin(h)),h!==a){this.getHalfEdgeToXY(h,r),n.setSub(r,t);const a=n.sqrLength(),m=n.crossProduct(i),g=m*m/(a*o);if(Math.min(a,o)*g<=e){if(n.dotProduct(i)>=0)return!1}i.assign(n),o=a,s.assign(r)}}while(h!==a)}}return!0}extractPolygonPathFromChain_(t,s,i,r,n){e(0)}mergeSegmentParentage_(){if(!this.m_shape.hasSegmentParentage())return;e(-1!==this.m_clusterBreakNodeIndex),e(-1===this.m_segmentParentageIndex);for(let e=this.getFirstCluster();e!==H;e=this.getNextCluster(e)){let t=0;const s=this.getClusterHalfEdge(e);if(s!==H){let e=s;do{t++,e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(e!==s&&t<3)}2!==t&&this.setBreakNode(e,!0)}let t=[],s=[];this.m_segmentParentageIndex=this.createUserIndexForHalfEdges();const i=this.createUserIndexForHalfEdges();for(let e=this.getFirstCluster();e!==H;e=this.getNextCluster(e)){const r=this.getClusterHalfEdge(e);if(r!==H){let e=!1,n=r;do{let r=n;for(;-1===this.getHalfEdgeUserIndex(r,i);){const n=this.getHalfEdgeNext(r),h=this.getHalfEdgeTwin(r);Je(this,r,s);const a=s.at(-1).parentage;if(!e){const s=this.getHalfEdgeOrigin(r);if(!this.isBreakNode(s)){const s=this.getHalfEdgePrev(r);r!==s&&(Je(this,s,t),e=!0)}}if(e&&!Ke(s,t)){const e=this.getHalfEdgeOrigin(r);this.setBreakNode(e,!0)}t=q(s,s=t),e=!0;const o=this.getHalfEdgeOrigin(n);this.isBreakNode(o)&&(e=!1),this.setHalfEdgeUserIndex(r,this.m_segmentParentageIndex,a),this.setHalfEdgeUserIndex(h,this.m_segmentParentageIndex,a),this.setHalfEdgeUserIndex(r,i,1),this.setHalfEdgeUserIndex(h,i,1),r=n}n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(n!==r)}}this.deleteUserIndexForHalfEdges(i)}registerNewBitSet(t){return e(0),new Le}getLeftEdgeBitSet_(t){return e(0),new Le}getEdgeBitSet_(t){return e(0),new Le}setEdgeBitSet_(t,s){e(0)}setLeftEdgeBitSet_(t,s){e(0)}setChainBitSet_(t,s){e(0)}getEmptySet(){return e(0),new Le}deleteEdgeBitSets_(){-1!==this.m_edgeBitSetIndex&&(this.deleteUserIndexForHalfEdges(this.m_edgeBitSetIndex),this.m_edgeBitSetIndex=-1),-1!==this.m_edgeBitSetIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_edgeBitSetIndexLeft),this.m_edgeBitSetIndexLeft=-1),this.m_edgeBitSets.length=0,this.m_uniqueBitSets=null}deleteChainBitSets_(){-1!==this.m_chainBitSetIndex&&(this.deleteUserIndexForChains(this.m_chainBitSetIndex),this.m_chainBitSetIndex=-1,this.m_chainBitSets.length=0)}dbgPrintEdge_(t){e(0)}dbgVerifyEdgeSegment(t){e(0)}}$e.c_EdgeParentageMask=~(1<<31),$e.c_EdgeBitMask=1<<31;class et{freeNode_(e){this.m_listNodes.deleteElement(e)}newNode_(){return this.m_listNodes.newElement()}freeList_(e){this.m_lists.deleteElement(e)}newList_(){return this.m_lists.newElement()}Init_(t){e(0)}constructor(e){this.m_listNodes=new M(2),this.m_listOfLists=et.st_nullNode(),this.m_bAllowNavigationBetweenLists=!0,void 0===e&&(e=!0),this.m_bAllowNavigationBetweenLists=e,this.m_lists=new M(this.m_bAllowNavigationBetweenLists?4:2)}createList(){const e=this.newList_();return this.m_bAllowNavigationBetweenLists&&(this.m_lists.setField(e,3,this.m_listOfLists),this.m_listOfLists!==et.st_nullNode()&&this.m_lists.setField(this.m_listOfLists,2,e),this.m_listOfLists=e),e}deleteList(e){let t=this.getFirst(e);for(;t!==et.st_nullNode();){const e=t;t=this.getNext(t),this.freeNode_(e)}if(this.m_bAllowNavigationBetweenLists){const t=this.m_lists.getField(e,2),s=this.m_lists.getField(e,3);t!==et.st_nullNode()?this.m_lists.setField(t,3,s):this.m_listOfLists=s,s!==et.st_nullNode()&&this.m_lists.setField(s,2,t)}this.freeList_(e)}reserveLists(e){this.m_lists.setCapacity(e)}addElement(e,t){this.m_lists.getField(e,0);const s=this.m_lists.getField(e,1),i=this.newNode_();return s!==et.st_nullNode()?(this.m_listNodes.setField(s,1,i),this.m_lists.setField(e,1,i)):(this.m_lists.setField(e,0,i),this.m_lists.setField(e,1,i)),this.m_listNodes.setField(i,0,t),i}reserveNodes(e){this.m_listNodes.setCapacity(e)}deleteElementDirect(e,t,s){t!==et.st_nullNode()?(this.m_listNodes.setField(t,1,this.m_listNodes.getField(s,1)),this.m_lists.getField(e,1)===s&&this.m_lists.setField(e,1,t)):(this.m_lists.setField(e,0,this.m_listNodes.getField(s,1)),this.m_lists.getField(e,1)===s&&this.m_lists.setField(e,1,et.st_nullNode())),this.freeNode_(s)}deleteElementSearch(e,t){let s=-1,i=this.getFirst(e);for(;i!==t;)s=i,i=this.getNext(i);this.deleteElementDirect(e,s,t)}concatenateLists(e,t){const s=this.m_lists.getField(e,1),i=this.m_lists.getField(t,0);if(i!==et.st_nullNode()&&(s!==et.st_nullNode()?(this.m_listNodes.setField(s,1,i),this.m_lists.setField(e,1,this.m_lists.getField(t,1))):(this.m_lists.setField(e,0,i),this.m_lists.setField(e,1,this.m_lists.getField(t,1)))),this.m_bAllowNavigationBetweenLists){const e=this.m_lists.getField(t,2),s=this.m_lists.getField(t,3);e!==et.st_nullNode()?this.m_lists.setField(e,3,s):this.m_listOfLists=s,s!==et.st_nullNode()&&this.m_lists.setField(s,2,e)}return this.freeList_(t),e}getElement(e){return this.m_listNodes.getField(e,0)}getData(e){return this.getElement(e)}setElement(t,s){e(0)}getNext(e){return this.m_listNodes.getField(e,1)}getFirst(e){return this.m_lists.getField(e,0)}getFirstElement(e){const t=this.getFirst(e);return this.getElement(t)}static st_nullNode(){return-1}clear(){this.m_listNodes.deleteAll(!0),this.m_lists.deleteAll(!0),this.m_listOfLists=et.st_nullNode()}isEmpty(t){return e(0),!1}getNodeCount(){return this.m_listNodes.size()}getListCount(){return this.m_lists.size()}getFirstList(){return this.m_listOfLists}getNextList(e){return this.m_lists.getField(e,3)}}function tt(e=-1){return{m_value:e,m_line:new ge,m_segment:null,m_segmentInfo:new ye(-1),m_env:new le(0,0),m_dxdy:55555555,m_bHorizontal:!1,m_bCurve:!1}}const st=67;class it extends de{constructor(e,t,s){super(!0),this.m_bIntersectionDetected=!1,this.m_nonSimpleResult=new Xe,this.m_tempSimpleEdge1=tt(),this.m_tempSimpleEdge2=tt(),this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H,this.m_currentNode=-1,this.m_prevX1=Number.NaN,this.m_prevX2=Number.NaN,this.m_prevY=Number.NaN,this.m_prevX=0,this.m_sweepY=Number.NaN,this.m_sweepX=0,this.m_simpleEdgesCache=[],this.m_simpleEdgesRecycle=[],this.m_cOutstandingConstructedEdges=0,this.m_shape=e,this.m_bShapeHasSegments=this.m_shape.hasCurves(),this.m_tolerance=t,this.m_tolerance10=10*t,this.m_bIsSimple=s;const i=Math.trunc(Math.min(3*e.getTotalPointCount()/2,st)),r=Math.min(7,i);this.m_simpleEdgesCache.length=r}tryGetCachedEdge_(e){const t=this.m_simpleEdgesCache[(e&fe())%this.m_simpleEdgesCache.length];return t&&t.m_value===e?t:null}tryDeleteCachedEdge_(e){const t=(e&fe())%this.m_simpleEdgesCache.length,s=this.m_simpleEdgesCache[t];s&&s.m_value===e&&(this.m_simpleEdgesRecycle.push(s),this.m_simpleEdgesCache[t]=null)}tryCreateCachedEdge_(e){const t=(e&fe())%this.m_simpleEdgesCache.length;let s=this.m_simpleEdgesCache[t];return s?null:(0===this.m_simpleEdgesRecycle.length?(s=tt(),this.m_cOutstandingConstructedEdges++):s=this.m_simpleEdgesRecycle.pop(),s.m_value=e,this.m_simpleEdgesCache[t]=s,s)}initSimpleEdge_(e,t){this.m_bShapeHasSegments&&this.initSimpleEdgeHelper_(e,t)||e.m_bCurve||(this.m_shape.queryLineConnector(t,e.m_line,!0),e.m_segment=e.m_line,e.m_env.setCoordsNoNAN(e.m_line.getStartX(),e.m_line.getEndX()),e.m_env.vmax+=this.m_tolerance,e.m_line.orientBottomUp(),e.m_bHorizontal=e.m_line.getEndY()===e.m_line.getStartY(),e.m_bHorizontal||(e.m_dxdy=(e.m_line.getEndX()-e.m_line.getStartX())/(e.m_line.getEndY()-e.m_line.getStartY())))}initSimpleEdgeHelper_(e,t){if(e.m_segment=this.m_shape.getSegment(t),e.m_segmentInfo=this.m_shape.getOriginalSegmentInfo(t),e.m_bCurve=null!==e.m_segment,e.m_bCurve){const t=e.m_segment.clone();return t.orientBottomUp(),e.m_segment=t,e.m_env=e.m_segment.queryInterval(0,0),e.m_env.vmax+=this.m_tolerance,!0}return!1}compareTwoSegments_(e,t){const s=e.getStartXY(),i=e.getEndXY(),r=t.getStartXY(),n=t.getEndXY(),h=new F;if(h.setCoords(this.m_sweepX,this.m_sweepY),s.isEqualPoint2D(r)&&this.m_sweepY===s.y){h.assign(i.compare(n)<0?i:n);const s=e.intersectionOfYMonotonicWithAxisX(h.y,h.x),r=t.intersectionOfYMonotonicWithAxisX(h.y,h.x);if(Math.abs(s-r)>this.m_tolerance)return s<r?-1:1}const a=s.compare(r)<0?r:s,o=i.compare(n)<0?i:n;let m=0,g=0;for(let l=1;l<5;l++){xe(a,o,l/5,h);const s=e.intersectionOfYMonotonicWithAxisX(h.y,h.x),i=t.intersectionOfYMonotonicWithAxisX(h.y,h.x),r=Math.abs(s-i);r>m&&(m=r,g=s<i?-1:1)}return 0===g?this.errorCracking():g}compareNonHorizontal_(e,t){if(e.m_line.getStartY()===t.m_line.getStartY()&&e.m_line.getStartX()===t.m_line.getStartX())return e.m_line.getEndY()===t.m_line.getEndY()&&e.m_line.getEndX()===t.m_line.getEndX()?this.m_bIsSimple?this.errorCoincident():0:this.compareNonHorizontalUpperEnd_(e,t);if(e.m_line.getEndY()===t.m_line.getEndY()&&e.m_line.getEndX()===t.m_line.getEndX())return this.compareNonHorizontalLowerEnd_(e,t);const s=this.compareNonHorizontalLowerEnd_(e,t),i=this.compareNonHorizontalUpperEnd_(e,t);return s<0&&i<0?-1:s>0&&i>0?1:this.errorCracking()}compareHorizontal1Case1_(e,t){if(e.getEndX()>t.getEndX()){if(t.getEndX()>t.getStartX()&&t.getEndY()-t.getStartY()<2*this.m_tolerance&&e.isIntersectingPoint(t.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}else{if((t.getEndY()-t.getStartY())/(t.getEndX()-t.getStartX())*(e.getEndX()-e.getStartX())<this.m_tolerance10&&t.isIntersectingPoint(e.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}return 1}compareHorizontal1Case2_(e,t){if(e.getStartX()<t.getStartX()){if(t.getEndX()>t.getStartX()&&t.getEndY()-t.getStartY()<2*this.m_tolerance&&e.isIntersectingPoint(t.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}else{if((t.getEndY()-t.getStartY())/(t.getEndX()-t.getStartX())*(e.getStartX()-e.getEndX())<this.m_tolerance10&&t.isIntersectingPoint(e.getStartXY(),this.m_tolerance,!0))return this.errorCracking()}return-1}compareHorizontal1Case3_(e,t){const s=F.getNAN();s.setSub(t.getEndXY(),t.getStartXY()),s.rightPerpendicularThis(),s.normalize();const i=F.getNAN();i.setSub(e.getStartXY(),t.getStartXY());const r=F.getNAN();r.setSub(e.getEndXY(),t.getStartXY());const n=i.dotProduct(s),h=r.dotProduct(s),a=Math.abs(n),o=Math.abs(h);if(a<o){if(a<this.m_tolerance10&&t.isIntersectingPoint(e.getStartXY(),this.m_tolerance,!0))return this.errorCracking()}else if(o<this.m_tolerance10&&t.isIntersectingPoint(e.getEndXY(),this.m_tolerance,!0))return this.errorCracking();return n<0&&h<0?-1:n>0&&h>0?1:this.errorCracking()}compareHorizontal1_(e,t){return e.getStartY()===t.getStartY()&&e.getStartX()===t.getStartX()?this.compareHorizontal1Case1_(e,t):e.getEndY()===t.getEndY()&&e.getEndX()===t.getEndX()?this.compareHorizontal1Case2_(e,t):this.compareHorizontal1Case3_(e,t)}compareHorizontal2_(e,t){return e.getEndY()===t.getEndY()&&e.getEndX()===t.getEndX()&&e.getStartY()===t.getStartY()&&e.getStartX()===t.getStartX()?this.m_bIsSimple?this.errorCoincident():0:this.errorCracking()}compareNonHorizontalLowerEnd_(e,t){let s=1;if(e.m_line.getStartY()<t.m_line.getStartY()){s=-1;const i=e;e=t,t=i}const i=e.m_line,r=t.m_line,n=i.getStartX()-r.getStartX(),h=t.m_dxdy*(i.getStartY()-r.getStartY()),a=this.m_tolerance10;return n<h-a?-s:n>h+a?s:r.isIntersectingPoint(i.getStartXY(),this.m_tolerance,!0)?this.errorCracking():n<h?-s:s}compareNonHorizontalUpperEnd_(e,t){let s=1;if(t.m_line.getEndY()<e.m_line.getEndY()){s=-1;const i=e;e=t,t=i}const i=e.m_line,r=t.m_line,n=i.getEndX()-r.getStartX(),h=t.m_dxdy*(i.getEndY()-r.getStartY()),a=this.m_tolerance10;return n<h-a?-s:n>h+a?s:r.isIntersectingPoint(i.getEndXY(),this.m_tolerance,!0)?this.errorCracking():n<h?-s:s}errorCoincident(){this.m_bIntersectionDetected=!0;const e=7;return this.m_nonSimpleResult=new Xe(e,this.m_vertex1,this.m_vertex2),-1}errorCracking(){if(this.m_bIntersectionDetected=!0,this.m_bIsSimple){const e=6;this.m_nonSimpleResult=new Xe(e,this.m_vertex1,this.m_vertex2)}else this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H;return-1}compareSegments_(e,t,s,i){if(s.m_env.vmax<i.m_env.vmin)return-1;if(i.m_env.vmax<s.m_env.vmin)return 1;if(!s.m_bCurve&&!i.m_bCurve){let e=s.m_bHorizontal?1:0;return e|=i.m_bHorizontal?2:0,0===e?this.compareNonHorizontal_(s,i):1===e?this.compareHorizontal1_(s.m_line,i.m_line):2===e?-1*this.compareHorizontal1_(i.m_line,s.m_line):this.compareHorizontal2_(s.m_line,i.m_line)}if(this.m_bIntersectionDetected)return-1;const r=this.m_prevY===this.m_sweepY&&this.m_prevX===this.m_sweepX;let n,h;if(r&&e===this.m_prev1?n=this.m_prevX1:(n=Number.NaN,this.m_prev1=H),r&&t===this.m_prev2?h=this.m_prevX2:(h=Number.NaN,this.m_prev2=H),this.m_prevY=this.m_sweepY,this.m_prevX=this.m_sweepX,Number.isNaN(n)){this.m_prev1=e;const t=s.m_segment.intersectionOfYMonotonicWithAxisX(this.m_sweepY,this.m_sweepX);n=t,this.m_prevX1=t}if(Number.isNaN(h)){this.m_prev2=t;const e=i.m_segment.intersectionOfYMonotonicWithAxisX(this.m_sweepY,this.m_sweepX);h=e,this.m_prevX2=e}const a=K(!0,!0,s.m_segment,i.m_segment,this.m_tolerance,!0);return 0!==a?2===a?this.m_bIsSimple?this.errorCoincident():s.m_segmentInfo.equals(i.m_segmentInfo)?0:this.errorCracking():this.errorCracking():Math.abs(n-h)<=this.m_tolerance?this.compareTwoSegments_(s.m_segment,i.m_segment):n<h?-1:n>h?1:0}clearIntersectionDetectedFlag(){this.m_bIntersectionDetected=!1}intersectionDetected(){return this.m_bIntersectionDetected}getLastComparedNode(){return this.m_currentNode}getResult(){return this.m_nonSimpleResult}setSweepY(e,t){this.m_sweepY=e,this.m_sweepX=t,this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H}compare(e,t,s){if(this.m_bIntersectionDetected)return-1;const i=e.getElement(s),r=t;return this.m_currentNode=s,this.compareSegments(r,r,i,i)}compareSegments(e,t,s,i){let r=this.tryGetCachedEdge_(e);null===r?this.m_vertex1===t?r=this.m_tempSimpleEdge1:(this.m_vertex1=t,r=this.tryCreateCachedEdge_(e),null===r&&(r=this.m_tempSimpleEdge1,this.m_tempSimpleEdge1.m_value=e),this.initSimpleEdge_(r,t)):this.m_vertex1=t;let n=this.tryGetCachedEdge_(s);return null===n?this.m_vertex2===i?n=this.m_tempSimpleEdge2:(this.m_vertex2=i,n=this.tryCreateCachedEdge_(s),null===n&&(n=this.m_tempSimpleEdge2,this.m_tempSimpleEdge2.m_value=s),this.initSimpleEdge_(n,i)):this.m_vertex2=i,this.compareSegments_(t,i,r,n)}onDelete(e){this.tryDeleteCachedEdge_(e)}onSet(e){this.tryDeleteCachedEdge_(e)}onEndSearch(e){this.tryDeleteCachedEdge_(e)}onAddUniqueElementFailed(e){this.tryDeleteCachedEdge_(e)}}class rt{constructor(e,t){this.m_bIntersectionDetected=!1,this.m_pointOfInterest=F.getNAN(),this.m_line1=new ge,this.m_seg1=null,this.m_env=le.constructEmpty(),this.m_vertex1=-1,this.m_currentNode=-1,this.m_minDist=Number.MAX_VALUE,this.m_shape=e,this.m_tolerance=t}getCurrentNode(){return this.m_currentNode}clearIntersectionDetectedFlag(){this.m_bIntersectionDetected=!1,this.m_minDist=Number.MAX_VALUE}intersectionDetected(){return this.m_bIntersectionDetected}setPoint(e){this.m_pointOfInterest=e}compare(t,s){return e(0),0}compareVertex(e,t,s){let i,r=this.m_shape.getSegment(s),h=!0;if(null==r)this.m_shape.queryLineConnector(s,this.m_line1,!0),this.m_env.setCoordsNoNAN(this.m_line1.getStartX(),this.m_line1.getEndX()),r=this.m_line1,i=this.m_line1.getStartY()===this.m_line1.getEndY();else{const e=n.constructEmpty();r.queryLooseEnvelope(e),e.queryIntervalX(this.m_env),i=0===e.height(),h=!1}if(this.m_pointOfInterest.x+this.m_tolerance<this.m_env.vmin)return-1;if(this.m_pointOfInterest.x-this.m_tolerance>this.m_env.vmax)return 1;if(i)return this.m_currentNode=t,this.m_bIntersectionDetected=!0,0;let a=0;if(h){Ee(this.m_line1);const e=this.m_line1.getStartXY(),t=new F;t.setSub(this.m_line1.getEndXY(),e),t.rightPerpendicularThis();const s=new F;s.setSub(this.m_pointOfInterest,e),a=t.dotProduct(s),a/=t.length()}else{a=r.intersectionOfYMonotonicWithAxisX(this.m_pointOfInterest.y,this.m_pointOfInterest.x)-this.m_pointOfInterest.x}if(a<10*-this.m_tolerance)return-1;if(a>10*this.m_tolerance)return 1;if(r.isIntersectingPoint(this.m_pointOfInterest,this.m_tolerance)){Math.abs(a)<this.m_minDist&&(this.m_currentNode=t,this.m_minDist=a),this.m_bIntersectionDetected=!0}return a<0?-1:a>0?1:0}}class nt{constructor(e,t){this.m_lists=new et(!1),this.m_hash=t,this.m_hashBuckets=new Int32Array(e),this.m_hashBuckets.fill(nt.st_nullNode()),this.m_bitFilter=new Int32Array(10*e+31>>5)}reserveElements(e){this.m_lists.reserveLists(Math.min(this.m_hashBuckets.length,e)),this.m_lists.reserveNodes(e)}addElement(e,t){void 0===t&&(t=this.m_hash.getHash(e));const s=t%(this.m_bitFilter.length<<5);this.m_bitFilter[s>>5]|=1<<(31&s);const i=t%this.m_hashBuckets.length;let r=this.m_hashBuckets[i];r===et.st_nullNode()&&(r=this.m_lists.createList(),this.m_hashBuckets[i]=r);return this.m_lists.addElement(r,e)}deleteElement(e,t){void 0===t&&(t=this.m_hash.getHash(e));const i=t%this.m_hashBuckets.length,r=this.m_hashBuckets[i];r===et.st_nullNode()&&s("");let n=this.m_lists.getFirst(r),h=et.st_nullNode();for(;n!==et.st_nullNode();){const t=this.m_lists.getData(n),s=this.m_lists.getNext(n);t===e?(this.m_lists.deleteElementDirect(r,h,n),this.m_lists.getFirst(r)===et.st_nullNode()&&(this.m_lists.deleteList(r),this.m_hashBuckets[i]=et.st_nullNode())):h=n,n=s}}getFirstInBucket(e){const t=e%(this.m_bitFilter.length<<5);if(!(this.m_bitFilter[t>>5]&1<<(31&t)))return et.st_nullNode();const s=e%this.m_hashBuckets.length,i=this.m_hashBuckets[s];return i===et.st_nullNode()?et.st_nullNode():this.m_lists.getFirst(i)}getNextInBucket(e){return this.m_lists.getNext(e)}findNode(e){const t=this.m_hash.getHash(e);let s=this.getFirstInBucket(t);for(;s!==et.st_nullNode();){const t=this.m_lists.getData(s);if(this.m_hash.equal(t,e))return s;s=this.m_lists.getNext(s)}return et.st_nullNode()}getNextNode(t){return e(0),0}deleteNode(e){const t=this.getElement(e),i=this.m_hash.getHash(t)%this.m_hashBuckets.length,r=this.m_hashBuckets[i];r===et.st_nullNode()&&s(""),this.m_lists.deleteElementSearch(r,e),this.m_lists.getFirst(r)===et.st_nullNode()&&(this.m_lists.deleteList(r),this.m_hashBuckets[i]=et.st_nullNode())}getElement(e){return this.m_lists.getData(e)}static st_nullNode(){return et.st_nullNode()}clear(){e(0)}size(){return this.m_lists.getNodeCount()}dbgPrintBucketHistogram(){e(0)}}function ht(e,t,s,i,r){const n=new _t(r);return n.m_shape=e,n.m_sqrTolerance=t*t,n.m_cellSize=2*t,n.m_invCellSize=1/n.m_cellSize,n.m_geometry=s,n.m_bTrackChanges=i,n.m_bHasSegmentParentage=e.hasSegmentParentage(),n.clusterNonReciprocal()}function at(e,t,s,i,r){const n=e-s,h=t-i;return n*n+h*h<=r}function ot(){return{pt:new F,weight:0,rank:0,bMerged:!1}}function mt(e,t,s,i,r,n){const h=ot(),a=s+r;let o=!1,m=e.x;e.x!==t.x&&(i===n&&(m=(e.x*s+t.x*r)/a),o=!0);let g=e.y;return e.y!==t.y&&(i===n&&(g=(e.y*s+t.y*r)/a),o=!0),i!==n?i>n?(h.rank=i,h.weight=s,h.pt=e):(h.rank=n,h.weight=r,h.pt=t):(h.pt.setCoords(m,g),h.weight=a,h.rank=i),h.bMerged=o,h}function gt(e,t){const s=Ae(e);return Ge(s,t)}class lt{constructor(e,t,s,i,r){this.m_workPt=new F,this.m_shape=e,this.m_sqrTolerance=s,this.m_invCellSize=i,this.m_origin=t.clone(),this.m_hashValues=r}getHash(e){return this.m_shape.getUserIndex(e,this.m_hashValues)}calculateHash(t){return e(0),0}calculateHashFromVertex(e){this.m_shape.queryXY(e,this.m_workPt);const t=this.m_workPt.x-this.m_origin.x,s=Math.trunc(t*this.m_invCellSize+.5),i=this.m_workPt.y-this.m_origin.y;return gt(s,Math.trunc(i*this.m_invCellSize+.5))}dbgCalculateHashFromXy(t,s){return e(0),0}equal(t,s){return e(0),!1}}class _t{constructor(e){this.m_origin=F.getNAN(),this.m_sqrTolerance=0,this.m_cellSize=0,this.m_invCellSize=0,this.m_geometry=H,this.m_bucketArray=new Array(4),this.m_bucketHash=new Array(4),this.m_dbgCandidateCheckCount=0,this.m_nsr=new Xe,this.m_hashValues=-1,this.m_newClusters=-1,this.m_bTrackChanges=!1,this.m_bHasSegmentParentage=!1,this.m_shape=null,this.m_clusters=new et,this.m_hashFunction=null,this.m_hashTable=null,this.m_progressCounter=0,this.m_progressTracker=e}progress_(){}getNearestNeighbourCandidate(t,s,i,r,n){e(0)}findClusterCandidate(t,s){e(0)}collectClusterCandidates(e,t){const s=F.getNAN();this.m_shape.queryXY(e,s);const i=(s.x-this.m_origin.x)*this.m_invCellSize,r=(s.y-this.m_origin.y)*this.m_invCellSize,n=Math.trunc(i),h=Math.trunc(r);let a=0;for(let o=0;o<=1;o+=1)for(let e=0;e<=1;e+=1){const t=gt(n+o,h+e),s=this.m_hashTable.getFirstInBucket(t);s!==nt.st_nullNode()&&(this.m_bucketArray[a]=s,this.m_bucketHash[a]=t,a++)}for(let o=a-1;o>=1;o--){const e=this.m_bucketArray[o];for(let t=o-1;t>=0;t--)if(e===this.m_bucketArray[t]){this.m_bucketHash[t]=-1,a--,o!==a&&(this.m_bucketHash[o]=this.m_bucketHash[a],this.m_bucketArray[o]=this.m_bucketArray[a]);break}}for(let o=0;o<a;o++)this.collectNearestNeighbourCandidates(e,this.m_bucketHash[o],s,this.m_bucketArray[o],t)}collectNearestNeighbourCandidates(e,t,s,i,r){const n=F.getNAN();for(let h=i;h!==nt.st_nullNode();h=this.m_hashTable.getNextInBucket(h)){const i=this.m_hashTable.getElement(h);e===i||-1!==t&&this.m_shape.getUserIndex(i,this.m_hashValues)!==t||(this.m_shape.queryXY(i,n),at(s.x,s.y,n.x,n.y,this.m_sqrTolerance)&&r.push(h))}}mergeClusters(e,t,s){let i=this.m_shape.getUserIndex(e,this.m_newClusters);const r=this.m_shape.getUserIndex(t,this.m_newClusters);-1===i&&(i=this.m_clusters.createList(),this.m_clusters.addElement(i,e),this.m_shape.setUserIndex(e,this.m_newClusters,i)),-1===r?this.m_clusters.addElement(i,t):this.m_clusters.concatenateLists(i,r),this.m_shape.setUserIndex(t,this.m_newClusters,M.impossibleIndex2());const n=this.mergeVertices(e,t);if(s){const t=this.m_hashFunction.calculateHashFromVertex(e);this.m_shape.setUserIndex(e,this.m_hashValues,t)}return n}mergeVertices(e,t){const s=F.getNAN();this.m_shape.queryXY(e,s);const i=F.getNAN();this.m_shape.queryXY(t,i);const r=this.m_shape.getRank(e),n=this.m_shape.getRank(t),h=this.m_shape.getWeight(e),a=this.m_shape.getWeight(t);let o,m,g,l,_=!1;if(r===n?(o=r,m=h+a,g=s.x,s.x!==i.x&&(g=(s.x*h+i.x*a)/m,_=!0),l=s.y,s.y!==i.y&&(l=(s.y*h+i.y*a)/m,_=!0)):(r>n?(g=s.x,l=s.y,m=h,o=r):(g=i.x,l=i.y,m=a,o=n),_=!s.equals(i)),_&&(this.m_shape.setXYMonotonic(e,g,l),this.m_bTrackChanges&&this.m_shape.setGeometryModifiedWithVertex(e,!0),this.m_bHasSegmentParentage)){const s=this.m_shape.getSegmentParentageBreakVertex(e)||this.m_shape.getSegmentParentageBreakVertex(t);this.m_shape.setSegmentParentageBreakVertex(e,s),this.m_shape.setSegmentParentageBreakVertex(t,s)}return this.m_shape.setWeight(e,m),this.m_shape.setRank(e,o),_}clusterReciprocal(){return e(0),!1}needsClustering(){return e(0),!1}clusterNonReciprocal(){const e=this.m_shape.getSelectedCount(),t=this.m_shape.getEnvelope2D(this.m_progressTracker);this.m_origin=t.getLowerLeft();const s=Math.max(t.height(),t.width())/(Ne()-1);this.m_cellSize<s&&(this.m_cellSize=s,this.m_invCellSize=1/this.m_cellSize),this.m_clusters.clear(),this.m_clusters.reserveLists(Math.trunc(this.m_shape.getSelectedCount()/3+1)),this.m_clusters.reserveNodes(Math.trunc(this.m_shape.getSelectedCount()/3+1)),this.m_hashValues=this.m_shape.createUserIndex(),this.m_newClusters=this.m_shape.createUserIndex(),this.m_hashFunction=new lt(this.m_shape,this.m_origin,this.m_sqrTolerance,this.m_invCellSize,this.m_hashValues),this.m_hashTable=new nt(Math.trunc(4*e/3),this.m_hashFunction),this.m_hashTable.reserveElements(this.m_shape.getSelectedCount());let i=!1;{const e=this.m_shape.queryVertexIteratorOnSelection(this.m_geometry);for(let t=e.next();t!==H;t=e.next()){this.progress_();const e=this.m_hashFunction.calculateHashFromVertex(t);this.m_shape.setUserIndex(t,this.m_hashValues,e),this.m_hashTable.addElement(t,e)}}{const e=[],t=this.m_shape.queryVertexIteratorOnSelection(this.m_geometry);for(let s=t.next();s!==H;s=t.next()){if(this.m_shape.getUserIndex(s,this.m_newClusters)===M.impossibleIndex2())continue;let t=this.m_shape.getUserIndex(s,this.m_hashValues);this.m_hashTable.deleteElement(s,t);let r=!1;for(;this.collectClusterCandidates(s,e),0!==e.length;){let t=0;for(let i=0,r=e.length;i<r;i++){this.progress_();const n=e[i],h=this.m_hashTable.getElement(n);this.m_hashTable.deleteNode(n);const a=i+1===r;t|=this.mergeClusters(s,h,a)?1:0}if(r||=0!==t,i||=0!==t,e.length=0,!t)break}r&&(t=this.m_shape.getUserIndex(s,this.m_hashValues)),this.m_hashTable.addElement(s,t)}e.length=0}return i&&this.applyClusterPositions_(),this.m_hashTable=null,this.m_hashFunction=null,this.m_shape.removeUserIndex(this.m_hashValues),this.m_shape.removeUserIndex(this.m_newClusters),i}applyClusterPositions_(){const e=F.getNAN();for(let t=this.m_clusters.getFirstList();t!==et.st_nullNode();t=this.m_clusters.getNextList(t)){let s=this.m_clusters.getFirst(t);const i=this.m_clusters.getElement(s);this.m_shape.queryXY(i,e);const r=this.m_shape.getRank(i),n=this.m_shape.getWeight(i);for(s=this.m_clusters.getNext(s);s!==et.st_nullNode();s=this.m_clusters.getNext(s)){const t=this.m_clusters.getElement(s);if(this.m_bTrackChanges?this.m_shape.isEqualXYPoint2D(t,e)||(this.m_shape.setXYMonotonicPoint2D(t,e),this.m_shape.setGeometryModifiedWithVertex(t,!0)):this.m_shape.setXYMonotonicPoint2D(t,e),this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentageBreakVertex(i)||this.m_shape.getSegmentParentageBreakVertex(t);this.m_shape.setSegmentParentageBreakVertex(i,e),this.m_shape.setSegmentParentageBreakVertex(t,e)}this.m_shape.setWeight(t,n),this.m_shape.setRank(t,r)}}}}class dt{constructor(){this.m_inputParts=[],this.m_resultParts1=[],this.m_resultParts2=[],this.m_resultSegments=[],this.m_freeSegments=[],this.m_inputSegments=[],this.m_param1=[],this.m_param2=[],this.m_tolerance=0,this.m_point=new P,this.m_pointWeight=1,this.m_maxDensifyLimit=0,this.m_pointRank=0,this.m_changed1=!1,this.m_changed2=!1,this.m_adaptiveDensify=!1}clear(){this.freeAllResultSegments(),this.m_inputSegments.length=0,this.m_inputParts.length=0,this.m_resultParts1.length=0,this.m_resultParts2.length=0,this.m_param1.length=0,this.m_param2.length=0,this.m_adaptiveDensify=!1,this.m_changed1=!1,this.m_changed2=!1}newIntersectionPart_(e,t,s,i,r,n,h,a,o,m){return ut(e,t,s,i,r,n,h,a,o,m)}pushSegment(e,t,s,i,r,n,h,a,o,m){return this.m_inputParts.push(this.newIntersectionPart_(this.m_inputSegments.length,t,s,i,r,n,h,a,o,m)),this.m_inputSegments.push(e),this.m_inputParts.length-1}getResultSegmentCount(e){return this.m_adaptiveDensify?0===e?this.m_param1.length-1:this.m_param2.length-1:0===e?this.m_resultParts1.length:this.m_resultParts2.length}getResultPart_(e,t){return 0===e?this.m_resultParts1[t]:this.m_resultParts2[t]}getResultSegment(e,t){return this.m_resultSegments[this.getResultPart_(e,t).segmentIndex].get()}getSegmentChanged(e){return 0===e?this.m_changed1:this.m_changed2}getResultSegmentStartPointWeight(e,t){return this.getResultPart_(e,t).weightStart}getResultSegmentStartPointRank(e,t){return this.getResultPart_(e,t).rankStart}getResultSegmentSegmentParentage(e,t){return this.getResultPart_(e,t).segmentParentage}getResultSegmentStartPointIsBreak(e,t){return this.getResultPart_(e,t).u.bBreakStart}getResultSegmentEndPointWeight(e,t){return this.getResultPart_(e,t).weightEnd}getResultSegmentEndPointRank(e,t){return this.getResultPart_(e,t).rankEnd}getResultSegmentEndPointIsBreak(e,t){return this.getResultPart_(e,t).u.bBreakEnd}getResultSegmentInteriorRank(e,t){return this.getResultPart_(e,t).rankInterior}getResultSegmentInteriorWeight(e,t){return this.getResultPart_(e,t).weightInterior}getResultPoint(){return this.m_point}getResultPointWeight(){return this.m_pointWeight}getResultPointRank(){return this.m_pointRank}getResultPointChanged(){return this.m_changed2}intersectLines(e,t){2!==this.m_inputSegments.length&&o(""),this.m_changed1=!1,this.m_changed2=!1,this.m_tolerance=e;const s=W(e*dt.c_smallToleranceFactor);let i=!1;const r=this.m_inputParts[0],n=this.m_inputParts[1],h=this.m_inputSegments[r.segmentIndex],a=this.m_inputSegments[n.segmentIndex];if(t||5&S(!0,h,a,e,!0)){const t=Ie(!0,h,a,null,this.m_param1,this.m_param2,e);0===t&&o("");const m=new Array(t);for(let e=0;e<t;++e)m[e]=F.getNAN();const g=new Float64Array(t),l=new Int32Array(t),_=new Array(t),d=new Array(t);for(let e=0;e<t;++e)_[e]=ct(),d[e]=ct();for(let e=0;e<t;e++){const t=this.m_param1[e],o=this.m_param2[e];let p,u=r.rankInterior,c=r.weightInterior;0===t?(u=r.rankStart,c=r.weightStart,p=r.u.bBreakStart):1===t?(u=r.rankEnd,c=r.weightEnd,p=r.u.bBreakEnd):(this.m_changed1=!0,p=!1);let f,x=n.rankInterior,E=n.weightInterior;0===o?(x=n.rankStart,E=n.weightStart,f=n.u.bBreakStart):1===o?(x=n.rankEnd,E=n.weightEnd,f=n.u.bBreakEnd):(this.m_changed2=!0,f=!1);const I=u,S=x;let C=1,P=0,y=F.getNAN();if(I===S){const i=h.getCoord2D(t),r=a.getCoord2D(o);C=c+E;P=u,xe(i,r,E/C,y);const n=F.sqrDistance(y,i),m=F.sqrDistance(y,r);_[e].bBigMove=n>s,d[e].bBigMove=m>s,this.m_changed1||i.equals(y)||(this.m_changed1=!0),this.m_changed2||r.equals(y)||(this.m_changed2=!0)}else if(I>S){y=h.getCoord2D(t);const i=a.getCoord2D(o);C=c,P=u;const r=F.sqrDistance(y,i);_[e].bBigMove=!1,d[e].bBigMove=r>s,this.m_changed2||i.equals(y)||(this.m_changed2=!0)}else{y=a.getCoord2D(o),C=E,P=x;const i=h.getCoord2D(t),r=F.sqrDistance(y,i);_[e].bBigMove=r>s,d[e].bBigMove=!1,this.m_changed1||i.equals(y)||(this.m_changed1=!0)}m[e].assign(y),g[e]=C,l[e]=P,_[e].bIsBreak=p||f,d[e].bIsBreak=p||f,i||=_[e].bBigMove||d[e].bBigMove}const p=r.rankInterior,u=r.weightInterior;let c=0,f=-1;for(let s=0;s<=t;s++){const i=s<t?this.m_param1[s]:1;if(i!==c){const n=this.allocResultSegment(),a=this.m_resultSegments[n];let o,d,x,E;h.queryCut(c,i,a,!1),a.get().snapControlPoints(e*e);let I=!1,S=!1,C=!1,P=!1,y=!1,N=F.getNAN(),v=F.getNAN();-1!==f?(d=l[f],o=g[f],I=_[f].bBigMove,N.assign(m[f]),C=_[f].bIsBreak,y=!0):(o=r.weightStart,d=r.rankStart,N=a.get().getStartXY(),C=r.u.bBreakStart),s<t?(E=l[s],x=g[s],S=_[s].bBigMove,v.assign(m[s]),P=_[s].bIsBreak,y=!0):(x=r.weightEnd,E=r.rankEnd,v=a.get().getEndXY(),P=r.u.bBreakEnd),y&&a.get().setCoordsForIntersector(N,v,!0),this.m_resultParts1.push(this.newIntersectionPart_(n,o,d,x,E,u,p,C,P,r.segmentParentage));const b=this.m_resultParts1.at(-1);b.u.bBigMoveStart=I,b.u.bBigMoveEnd=S,c=i,f=s}else-1===f&&(f=s)}const x=new Array(t);for(let e=0;e<t;e++)x[e]=e;t>2?(x.sort(((e,t)=>this.m_param2[e]<this.m_param2[t]?-1:this.m_param2[e]>this.m_param2[t]?1:0)),J(this.m_param2)):2===t&&this.m_param2[0]>this.m_param2[1]&&(this.m_param2[1]=q(this.m_param2[0],this.m_param2[0]=this.m_param2[1]),x[1]=q(x[0],x[0]=x[1]));const E=n.rankInterior,I=n.weightInterior;c=0,f=-1;for(let s=0;s<=t;s++){const i=s<t?this.m_param2[s]:1;if(i!==c){const r=this.allocResultSegment(),h=this.m_resultSegments[r];let o,_,p,u;a.queryCut(c,i,h,!1),h.get().snapControlPoints(e*e);let S=F.getNAN(),C=F.getNAN(),P=!1,y=!1,N=!1,v=!1,b=!1;if(-1!==f){const e=x[f];o=g[e],_=l[e],S.assign(m[e]),N=d[e].bBigMove,P=d[e].bIsBreak,b=!0}else o=n.weightStart,_=n.rankStart,S=h.get().getStartXY(),P=n.u.bBreakStart;if(s!==t){const e=x[s];p=g[e],u=l[e],C.assign(m[e]),v=d[e].bBigMove,y=d[e].bIsBreak,b=!0}else p=n.weightEnd,u=n.rankEnd,C=h.get().getEndXY(),y=n.u.bBreakEnd;b&&h.get().setCoordsForIntersector(S,C,!0),this.m_resultParts2.push(this.newIntersectionPart_(r,o,_,p,u,I,E,P,y,n.segmentParentage));const w=this.m_resultParts2.at(-1);w.u.bBigMoveStart=N,w.u.bBigMoveEnd=v,c=i,f=s}else-1===f&&(f=s)}return i?3:2}return 0}intersect(e,t){const s=this.m_inputParts[0],r=this.m_inputParts[1],n=this.m_inputSegments[s.segmentIndex].getGeometryType(),h=this.m_inputSegments[r.segmentIndex].getGeometryType();if(n!==i.enumLine||h!==i.enumLine){return new It(this).intersectCurves(e,t)}return this.intersectLines(e,t)}intersectEx(e,t,s,i,r){this.m_point.assignCopy(t),1!==this.m_inputSegments.length&&o(""),this.m_tolerance=e,this.m_changed1=!1,this.m_changed2=!1;const n=W(e*dt.c_smallToleranceFactor);let h=!1;const a=this.m_inputParts[0],m=this.m_inputSegments[a.segmentIndex];if(r||m.isIntersectingPoint(t.getXY(),e,!0)){this.m_param1=Y(16,Number.NaN);const r=m.getClosestCoordinate(t.getXY(),!1);this.m_param1[0]=r;let o=a.rankInterior,g=a.weightInterior;0===r?(o=a.rankStart,g=a.weightStart):1===r?(o=a.rankEnd,g=a.weightEnd):this.m_changed1=!0;let l=o;const _=s,d=i;l===_&&m.isCurve()&&(l=_+1);let p=1,u=0;const c=new F;if(l===_){const e=m.getCoord2D(r),s=t.getXY();p=g+d,u=o;xe(e,s,d/p,c),this.m_changed1||e.equals(c)||(this.m_changed1=!0),this.m_changed2||s.equals(c)||(this.m_changed2=!0);h=F.sqrDistance(c,e)>n}else if(l>_)c.assign(m.getCoord2D(r)),p=g,u=o,this.m_changed2||c.equals(t.getXY())||(this.m_changed2=!0);else{c.assign(m.getCoord2D(r)),p=d,u=_,this.m_changed1||c.equals(t.getXY())||(this.m_changed1=!0);h=F.sqrDistance(c,t.getXY())>n}let f=0,x=-1;const E=1;for(let t=0;t<=E;t++){const s=t<E?this.m_param1[0]:1;if(s!==f){const i=this.allocResultSegment(),r=this.m_resultSegments[i];m.queryCut(f,s,r),r.get().snapControlPoints(e*e);let n=a.weightStart,h=a.weightEnd,o=a.rankStart,g=a.rankEnd;const l=a.rankInterior,_=a.weightInterior;let d=a.u.bBreakStart,I=a.u.bBreakEnd;-1!==x&&(n=p,o=u,d=!0,r.get().setCoordsForIntersector(c,r.get().getEndXY(),!0)),t!==E&&(h=p,g=u,I=!0,r.get().setCoordsForIntersector(r.get().getStartXY(),c,!0)),f=s,this.m_resultParts1.push(this.newIntersectionPart_(i,n,o,h,g,_,l,d,I,a.segmentParentage))}x=t}return this.m_point.setXY(c),this.m_pointWeight=p,this.m_pointRank=u,h?3:2}return 0}getTolerance(){return this.m_tolerance}freeAllResultSegments(){this.m_resultSegments.length=0,this.m_freeSegments.length=0}freeResultSegment(e){this.m_freeSegments.push(e)}allocResultSegment(){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const e=new G,t=this.m_resultSegments.length;return this.m_resultSegments.push(e),t}allocResultSegmentFromBuffer(e){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const t=new G({copy:e}),s=this.m_resultSegments.length;return this.m_resultSegments.push(t),s}allocResultSegmentFromSegment(e){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const t=new G({segment:e}),s=this.m_resultSegments.length;return this.m_resultSegments.push(t),s}}function pt(e,t){return{bBigMoveStart:!1,bBigMoveEnd:!1,bBreakStart:e,bBreakEnd:t}}function ut(e,t,s,i,r,n,h,a,o,m){return{segmentIndex:e,weightStart:t,rankStart:s,weightEnd:i,rankEnd:r,weightInterior:n,rankInterior:h,segmentParentage:m,u:pt(a,o)}}function ct(){return{bBigMove:!1,bIsBreak:!1}}dt.maxWeight=.1*Number.MAX_VALUE,dt.c_smallToleranceFactor=.01,dt.c_maxGeometryTypeToRankDelta=8;let ft=class{constructor(){this.start=null,this.end=null,this.equalEdge=null,this.segmentIndex=-1,this.segmentParentage=-1,this.weight=0,this.rank=0}hasSegment(){return this.segmentIndex>=0}transferAttributes(e,t,s){if(1===t.getDescription().getAttributeCount())return;const i=e.parent.m_resultSegments[this.segmentIndex].get().getStartXY(),r=e.parent.m_resultSegments[this.segmentIndex].get().getEndXY(),n=new P;t.queryStart(n),s?(n.setXY(i),e.parent.m_resultSegments[this.segmentIndex].get().setStart(n)):(n.setXY(r),e.parent.m_resultSegments[this.segmentIndex].get().setEnd(n)),t.queryEnd(n),s?(n.setXY(r),e.parent.m_resultSegments[this.segmentIndex].get().setEnd(n)):(n.setXY(i),e.parent.m_resultSegments[this.segmentIndex].get().setStart(n))}copyFromWhenOverlap(e,t,s){this.equalEdge=t,t.equalEdge=this,this.segmentIndex=e.parent.allocResultSegmentFromBuffer(e.parent.m_resultSegments[t.segmentIndex]),this.segmentParentage=t.segmentParentage,this.weight=t.weight,this.rank=t.rank,s?(this.start.copyFrom(t.start),this.end.copyFrom(t.end)):(this.start.copyFrom(t.end),this.end.copyFrom(t.start),e.parent.m_resultSegments[this.segmentIndex].get().reverse())}disconnect(t){e(0)}getEnvelope(){return e(0),{}}getEnd(){return e(0),{}}getNextInChain(){return this.end.nextInChain}getPrevInChain(){return this.start.prevInChain}};class xt{constructor(){this.hash=0,this.pt=new F,this.prevInChain=null,this.nextInChain=null,this.prevInHash=null,this.nextInHash=null,this.prevEqual=null,this.nextEqual=null,this.weight=0,this.rank=0,this.bBigMove=!1,this.bIsBreak=!1}copyFrom(e){this.pt.assign(e.pt),this.weight=e.weight,this.rank=e.rank,this.bBigMove=e.bBigMove,this.bIsBreak=e.bIsBreak}nextNode(){return e(0),{}}prevNode(){return e(0),{}}startingEdges(t,s){e(0)}terminatingEdges(t,s){e(0)}sameListSize(){return e(0),0}equalListHead(){let e=this;for(;null!==e.prevEqual;e=e.prevEqual);return e}}function Et(e,t,s,i){return{edge1:e,edge2:t,recursion:s,bIsIntersecting:i}}class It{constructor(e){this.m_pairs=[],this.m_chainOrigin1=null,this.m_chainOrigin2=null,this.m_newNodes=[],this.m_hashTableOfEquals=[],this.m_hashTableOfEqualsSize=0,this.m_origin=new F,this.m_cell=new F,this.parent=e}addSegment(t,s,i,r,n,h,a,o,m,g,l){const _=this.newNode(this.parent.m_resultSegments[t].get().getStartXY(),i,r,m),d=this.newNode(this.parent.m_resultSegments[t].get().getEndXY(),n,h,g);this.newEdge(_,d,t,a,o,l),null===this.m_chainOrigin1?this.m_chainOrigin1=_:null===this.m_chainOrigin2?this.m_chainOrigin2=_:e(0)}intersectCurvesHelper(t,s,r,n,h){const a=this.tryOverlapIntersectCurves(t,s,r,n);if(0!==a)return a;const m=W(.01*r);let g=!1;const l=this.getSegment(t).get(),_=this.getSegment(s).get();if(l.isDegenerate(0)||_.isDegenerate(0))return 0;let d=this.processSharpCorners(l,_,r,h>4);const p=d>0;if(!p){if(!(n||5&K(!0,!1,l,_,r,!0)))return 0;d=Ie(!0,l,_,null,this.parent.m_param1,this.parent.m_param2,r)}0===d&&o("");const u=l.getGeometryType(),c=_.getGeometryType(),f=he(F,d),x=he(F,d),E=new Array(d),I=new Array(d),S=new Array(d),C=new Array(d),P=ve(ct,d),y=ve(ct,d);let N=!1,v=!1;for(let e=0;e<d;e++){const i=this.parent.m_param1[e],n=this.parent.m_param2[e];let h=t.rank,a=t.weight,o=!0,d=!1;0===i?(h=t.start.rank,a=t.start.weight,d=t.start.bIsBreak):1===i?(h=t.end.rank,a=t.end.weight,d=t.end.bIsBreak):(N=!0,o=!1);let b=s.rank,w=s.weight,V=!1,H=!0;0===n?(b=s.start.rank,w=s.start.weight,V=s.start.bIsBreak):1===n?(b=s.end.rank,w=s.end.weight,V=s.end.bIsBreak):(v=!0,H=!1);let T=h,k=b;if(T===k&&(T*=dt.c_maxGeometryTypeToRankDelta,k*=dt.c_maxGeometryTypeToRankDelta,T+=St(u,l,!1),k+=St(c,_,!1)),o&&H&&k===T){const e=l.getCoord2D(i),t=_.getCoord2D(n);e.equals(t)&&(k=T-1)}let G=1,B=0,D=1,A=0;const U=new F,O=new F,Y=l.getCoord2D(i),X=_.getCoord2D(n);if(p&&F.distance(Y,X)>r)U.setCoordsPoint2D(Y),O.setCoordsPoint2D(X),G=a,D=w,B=h,A=b,P[e].bBigMove=!1,y[e].bBigMove=!1,d=!0,V=!0;else if(T===k){D=G=a+w,A=B=h;xe(Y,X,w/G,U),O.setCoordsPoint2D(U);const t=F.sqrDistance(U,Y),s=F.sqrDistance(U,X);P[e].bBigMove=t>m,y[e].bBigMove=s>m,N||Y.equals(U)||(N=!0),v||X.equals(O)||(v=!0)}else if(T>k){U.setCoordsPoint2D(Y),O.setCoordsPoint2D(U),D=G=a,A=B=h;const t=F.sqrDistance(U,X);P[e].bBigMove=!1,y[e].bBigMove=t>m,v||X.equals(O)||(v=!0)}else{O.setCoordsPoint2D(X),U.setCoordsPoint2D(O),D=G=w,A=B=b;const t=F.sqrDistance(U,Y);P[e].bBigMove=t>m,y[e].bBigMove=!1,N||Y.equals(U)||(N=!0)}f[e].assign(U),x[e].assign(O),E[e]=G,I[e]=D,S[e]=B,C[e]=A,P[e].bIsBreak=d||V,y[e].bIsBreak=d||V,g||=P[e].bBigMove||y[e].bBigMove,e>0&&(i!==this.parent.m_param1[e-1]&&n!==this.parent.m_param2[e-1]||(S[e]<=S[e-1]?(f[e].assign(x[e-1]),E[e]=I[e-1],S[e]=C[e-1],x[e].assign(x[e-1]),I[e]=I[e-1],C[e]=C[e-1],P[e].bBigMove||=P[e-1].bBigMove,y[e].bBigMove||=y[e-1].bBigMove,P[e].bIsBreak||=P[e-1].bIsBreak,y[e].bIsBreak||=y[e-1].bIsBreak):(f[e-1].assign(f[e]),E[e-1]=E[e],S[e-1]=S[e],x[e-1].assign(x[e]),I[e-1]=I[e],C[e-1]=C[e],P[e-1].bBigMove||=P[e].bBigMove,y[e-1].bBigMove||=y[e].bBigMove,P[e-1].bIsBreak||=P[e].bIsBreak,y[e-1].bIsBreak||=y[e].bIsBreak)))}if(!N&&!v&&2===d){if(u!==i.enumLine||c!==i.enumLine){if(this.processDoublyConnectedEdges(t,s,h+1,r))return this.parent.m_changed1=!0,this.parent.m_changed2=!0,2;e(0)}e(0)}this.parent.m_changed1||=N,this.parent.m_changed2||=v;let b=t,w=t.end.weight,V=t.end.rank,H=t.end.bBigMove,T=t.end.bIsBreak,k=0,G=-1;for(let e=0;e<=d;e++){const s=e<d?this.parent.m_param1[e]:1;if(s!==k){const i=this.parent.allocResultSegment(),n=this.parent.m_resultSegments[i];let h,a,o,m;l.queryCut(k,s,n,!1),n.get().snapControlPoints(r*r);let g=!1,_=!1,p=!1,u=!1;const c=new F,x=new F;-1!==G?(a=S[G],h=E[G],p=P[G].bBigMove,g=P[G].bIsBreak,c.assign(f[G])):(h=t.start.weight,a=t.start.rank,p=t.start.bBigMove,g=t.start.bIsBreak,c.assign(n.get().getStartXY())),e<d?(m=S[e],o=E[e],u=P[e].bBigMove,_=P[e].bIsBreak,x.assign(f[e])):(o=w,m=V,u=H,_=T,x.assign(n.get().getEndXY()));let I=b;s<1&&(this.splitEdgeInPlace(b),I=b.getNextInChain()),this.updateSegmentOnly(b,i),0===b.start.hash||b.start.pt.equals(c)||(this.m_newNodes.push(b.start),this.removeNodeFromHash(b.start),b.start.hash=0),0===b.end.hash||b.end.pt.equals(x)||(this.m_newNodes.push(b.end),this.removeNodeFromHash(b.end),b.end.hash=0),b.start.pt.assign(c),b.end.pt.assign(x),b.start.bBigMove||=p,b.end.bBigMove||=u,b.start.bIsBreak||=g,b.end.bIsBreak||=_,b.start.weight=h,b.start.rank=a,b.end.weight=o,b.end.rank=m,b=I,k=s,G=e}else-1===G&&(G=e)}const B=b.getNextInChain(),D=[];D.length=d;for(let e=0;e<d;e++)D[e]=e;d>2?(D.sort(((e,t)=>be(this.parent.m_param2[e],this.parent.m_param2[t]))),this.parent.m_param2.sort(be)):2===d&&this.parent.m_param2[0]>this.parent.m_param2[1]&&(this.parent.m_param2[1]=q(this.parent.m_param2[0],this.parent.m_param2[0]=this.parent.m_param2[1]),D[1]=q(D[0],D[0]=D[1])),b=s,w=s.end.weight,V=s.end.rank,H=s.end.bBigMove,T=s.end.bIsBreak,k=0,G=-1;for(let e=0;e<=d;e++){const t=e<d?this.parent.m_param2[e]:1;if(t!==k){const i=this.parent.allocResultSegment(),n=this.parent.m_resultSegments[i];let h,a,o,m;_.queryCut(k,t,n,!1),n.get().snapControlPoints(r*r);const g=new F,l=new F;let p=!1,u=!1,c=!1,f=!1;if(-1!==G){const e=D[G];h=I[e],a=C[e],g.assign(x[e]),c=y[e].bBigMove,p=y[e].bIsBreak}else h=s.start.weight,a=s.start.rank,c=s.start.bBigMove,p=s.start.bIsBreak,g.assign(n.get().getStartXY());if(e!==d){const t=D[e];o=I[t],m=C[t],l.assign(x[t]),f=y[t].bBigMove,u=y[t].bIsBreak}else o=w,m=V,f=H,u=T,l.assign(n.get().getEndXY());let E=b;t<1&&(this.splitEdgeInPlace(b),E=b.getNextInChain()),this.updateSegmentOnly(b,i),0===b.start.hash||b.start.pt.equals(g)||(this.m_newNodes.push(b.start),this.removeNodeFromHash(b.start),b.start.hash=0),0===b.end.hash||b.end.pt.equals(l)||(this.m_newNodes.push(b.end),this.removeNodeFromHash(b.end),b.end.hash=0),b.start.pt.assign(g),b.end.pt.assign(l),b.start.bBigMove||=c,b.end.bBigMove||=f,b.start.bIsBreak||=p,b.end.bIsBreak||=u,b.start.weight=h,b.start.rank=a,b.end.weight=o,b.end.rank=m,b=E,k=t,G=e}else-1===G&&(G=e)}const A=b.getNextInChain();return this.postProcessResultPartsForCurves(t,B,s,A,h+1),g?3:2}intersectCurves(t,s){2!==this.parent.m_inputSegments.length&&o(""),this.parent.m_changed1=!1,this.parent.m_changed2=!1,this.parent.m_tolerance=t,this.m_hashTableOfEqualsSize=0,this.m_hashTableOfEquals=we(16);const i=n.constructEmpty();for(let e=0;e<2;e++){const t=this.parent.allocResultSegmentFromSegment(this.parent.m_inputSegments[this.parent.m_inputParts[e].segmentIndex]),s=n.constructEmpty();this.parent.m_inputSegments[this.parent.m_inputParts[e].segmentIndex].queryLooseEnvelope(s),i.mergeEnvelope2D(s);const r=this.parent.m_inputParts[e];this.addSegment(t,0,r.weightStart,r.rankStart,r.weightEnd,r.rankEnd,r.weightInterior,r.rankInterior,r.u.bBreakStart,r.u.bBreakEnd,r.segmentParentage)}i.inflateCoords(100*t,100*t),this.m_origin.assign(i.getLowerLeft()),this.m_cell.setCoords(2*t,2*t),this.m_pairs.push(Et(this.m_chainOrigin1.nextInChain,this.m_chainOrigin2.nextInChain,0,s));let r=0,h=!0;for(;this.m_pairs.length;){const s=this.m_pairs.at(-1);this.m_pairs.pop(),e(s.recursion>=0),e(s.recursion<=256),this.clusterNodes(t);const i=this.intersectCurvesHelper(s.edge1,s.edge2,t,s.bIsIntersecting,s.recursion);h&&(h=!1,r=i)}for(let e=0;e<2;e++){const t=0===e?this.parent.m_resultParts1:this.parent.m_resultParts2;for(let s=(0===e?this.m_chainOrigin1:this.m_chainOrigin2).nextInChain;null!=s;s=s.getNextInChain())t.push(this.parent.newIntersectionPart_(s.segmentIndex,s.start.weight,s.start.rank,s.end.weight,s.end.rank,s.weight,s.rank,s.start.bIsBreak,s.end.bIsBreak,s.segmentParentage)),t.at(-1).u.bBigMoveStart=s.start.bBigMove,t.at(-1).u.bBigMoveEnd=s.end.bBigMove}return r}tryOverlapIntersectCurves(t,s,i,r){const n=this.parent.m_resultSegments[t.segmentIndex].get(),h=this.parent.m_resultSegments[s.segmentIndex].get(),a=n.getStartXY().equals(h.getStartXY())&&n.getEndXY().equals(h.getEndXY()),o=n.getStartXY().equals(h.getEndXY())&&n.getEndXY().equals(h.getStartXY());if(!a&&!o)return 0;const m=Ve(n,h,!0);if(0!==m&&He(n,h)&&t.segmentParentage===s.segmentParentage){let t=!1;if(m>0)t=n.equals(h);else{e(-1===m);const s=new G({segment:h});s.get().reverse(),t=n.equals(s.get())}if(t)return 1}const g=i*dt.c_smallToleranceFactor;let l=!1;if(0===m){const e=[.5,.25,.75,.125,.375,.625,.875,.5625,.3125];for(let t=0,s=e.length;t<s;++t){const s=e[t],r=new F;n.queryCoord2D(s,r);const a=h.getClosestCoordinate(r,!1),o=new F;h.queryCoord2D(a,o);const m=F.distance(r,o);if(m>i)return 0;l||=m>g}for(let t=0,s=e.length;t<s;++t){const s=e[t],r=new F;h.queryCoord2D(s,r);const a=n.getClosestCoordinate(r,!1),o=new F;n.queryCoord2D(a,o);const m=F.distance(r,o);if(m>i)return 0;l||=m>g}}let _=t.rank,d=s.rank;return _===d&&(_*=dt.c_maxGeometryTypeToRankDelta,d*=dt.c_maxGeometryTypeToRankDelta,_+=St(n.getGeometryType(),n,!0),d+=St(h.getGeometryType(),h,!0)),_>d?(s.copyFromWhenOverlap(this,t,a),s.transferAttributes(this,n,a)):d>_?(t.copyFromWhenOverlap(this,s,a),t.transferAttributes(this,h,a)):t.segmentParentage<=s.segmentParentage?(t.weight=t.weight+s.weight,s.copyFromWhenOverlap(this,t,a),s.transferAttributes(this,n,a)):(s.weight=t.weight+s.weight,t.copyFromWhenOverlap(this,s,a),t.transferAttributes(this,h,a)),l?3:2}postProcessResultPartsForCurves(e,t,s,i,r){r===Te()&&o("curve_helper");for(let n=e;n!==t;n=n.getNextInChain())this.updateSegmentToNodes(n);for(let n=s;n!==i;n=n.getNextInChain())this.updateSegmentToNodes(n);for(let n=e;n!==t;n=n.getNextInChain()){const e=n.end.pt.sub(n.start.pt);for(let t=s;t!==i;t=t.getNextInChain()){let s=0;if(n.start.pt.equals(t.start.pt)&&n.end.pt.equals(t.end.pt)?s=1:n.start.pt.equals(t.end.pt)&&n.end.pt.equals(t.start.pt)&&(s=-1),!s){let s=n.start.pt.equals(t.start.pt)?1:0;if(s||(s=n.end.pt.equals(t.end.pt)?2:0,s||(s=n.end.pt.equals(t.start.pt)?3:0,s||(s=n.start.pt.equals(t.end.pt)?4:0))),s){const i=t.end.pt.sub(t.start.pt),h=e.dotProduct(i);let a;switch(s){case 1:case 2:a=h>0;break;case 3:case 4:a=h<0;break;default:o("")}a&&this.m_pairs.push(Et(n,t,r,!1))}continue}const i=this.parent.m_resultSegments[n.segmentIndex],h=this.parent.m_resultSegments[t.segmentIndex],a=[.5,.25,.75];for(let e=0,t=a.length;e<t;++e){const t=a[e],r=new F;i.get().queryCoord2D(t,r);const n=h.get().getClosestCoordinate(r,!1),o=new F;h.get().queryCoord2D(n,o);if(F.distance(r,o)>this.parent.m_tolerance){s=0;break}}if(!s){this.m_pairs.push(Et(n,t,r,!1));continue}for(let e=0,t=a.length;e<t;++e){const t=a[e],r=new F;h.get().queryCoord2D(t,r);const n=i.get().getClosestCoordinate(r,!1),o=new F;i.get().queryCoord2D(n,o);if(F.distance(r,o)>this.parent.m_tolerance){s=0;break}}if(!s){this.m_pairs.push(Et(n,t,r,!1));continue}n.equalEdge=t,t.equalEdge=n;let m=n.rank,g=t.rank;m===g&&(m*=dt.c_maxGeometryTypeToRankDelta,g*=dt.c_maxGeometryTypeToRankDelta,m+=St(i.get().getGeometryType(),i.get(),!0),g+=St(h.get().getGeometryType(),h.get(),!0)),m>g||m===g&&n.segmentParentage<=t.segmentParentage?(i.copyTo(h,!1),t.segmentParentage=n.segmentParentage,-1===s&&h.get().reverse()):(h.copyTo(i,!1),n.segmentParentage=t.segmentParentage,-1===s&&i.get().reverse());break}}this.updateAttachedEdgesAfterNodeChange(e.start),t&&this.updateAttachedEdgesAfterNodeChange(t.start),this.updateAttachedEdgesAfterNodeChange(s.start),i&&this.updateAttachedEdgesAfterNodeChange(i.start)}processDoublyConnectedEdges(e,t,s,i){s===Te()&&o("curve_helper");const r=this.getSegment(e).get(),n=this.getSegment(t).get(),h=r.getStartXY().equals(n.getStartXY())&&r.getEndXY().equals(n.getEndXY())?1:r.getEndXY().equals(n.getStartXY())&&r.getStartXY().equals(n.getEndXY())?-1:0;if(0!==h){const a=new G;r.queryCut(0,.5,a),a.get().snapControlPoints(i*i);const o=new G;r.queryCut(.5,1,o),o.get().snapControlPoints(i*i),this.splitEdgeInPlace(e),e.end.pt=a.get().getEndXY(),e.segmentIndex=this.parent.allocResultSegmentFromBuffer(a),e.getNextInChain().segmentIndex=this.parent.allocResultSegmentFromBuffer(o);let m=n.getClosestCoordinate(e.end.pt,!1);return Math.abs(m-.5)>.2&&(m=.5),n.queryCut(0,m,a),a.get().snapControlPoints(i*i),n.queryCut(m,1,o),o.get().snapControlPoints(i*i),this.splitEdgeInPlace(t),t.end.pt=a.get().getEndXY(),t.segmentIndex=this.parent.allocResultSegmentFromBuffer(a),t.getNextInChain().segmentIndex=this.parent.allocResultSegmentFromBuffer(o),h>0?(this.m_pairs.push(Et(e,t,s,!1)),this.m_pairs.push(Et(e.getNextInChain(),t.getNextInChain(),s,!1))):(this.m_pairs.push(Et(e,t.getNextInChain(),s,!1)),this.m_pairs.push(Et(e.getNextInChain(),t,s,!1))),!0}return!1}getNext(t){return e(0),{}}newNode(e,t,s,i){const r=new xt;return this.m_newNodes.push(r),r.pt=e,r.rank=s,r.weight=t,r.bIsBreak=i,r}newEdge(e,t,s,i,r,n){const h=new ft;return h.start=e,h.end=t,e.nextInChain=h,t.prevInChain=h,h.segmentIndex=s,h.segmentParentage=n,h.rank=r,h.weight=i,h}splitEdgeInPlace(e){e.segmentIndex=-1;const t=new ft,s=new xt;this.m_newNodes.push(s),s.pt.setNAN(),s.nextInChain=t,s.prevInChain=e,s.prevInHash=null,s.nextInHash=null,s.prevEqual=null,s.nextEqual=null,s.weight=e.weight,s.rank=e.rank,s.bIsBreak=!1,s.bBigMove=!1,t.start=s,t.segmentIndex=-1,t.end=e.end,t.end.prevInChain=t,t.rank=e.rank,t.weight=e.weight,t.segmentParentage=e.segmentParentage,e.end=s,e.equalEdge&&(e.equalEdge.equalEdge=null),e.equalEdge=null}updateSegmentOnly(e,t){e.segmentIndex=t}updateAttachedEdgesAfterNodeChange(e){for(let t=e.equalListHead();null!==t;t=t.nextEqual)this.updateAttachedEdgesAfterNodeChangeImpl(t)}updateAttachedEdgesAfterNodeChangeImpl(e){const t=e.prevInChain;if(t&&t.hasSegment()){const s=this.getSegment(t).get();e.pt.equals(s.getEndXY())||(s.setCoordsForIntersector(t.start.pt,t.end.pt,!1),s.ensureXYMonotone())}const s=e.nextInChain;if(s&&s.hasSegment()){const t=this.getSegment(s).get();e.pt.equals(t.getStartXY())||(t.setCoordsForIntersector(s.start.pt,s.end.pt,!1),t.ensureXYMonotone())}}updateSegmentToNodes(e){const t=this.getSegment(e).get();e.start.pt.equals(t.getStartXY())&&e.end.pt.equals(t.getEndXY())||(t.setCoordsForIntersector(e.start.pt,e.end.pt,!1),t.ensureXYMonotone()),this.updateAttachedEdgesAfterNodeChange(e.start),this.updateAttachedEdgesAfterNodeChange(e.end)}getSegment(e){return this.parent.m_resultSegments[e.segmentIndex]}clusterNodes(e){let t=!1;const s=[],i=[],r=[];for(let n=0,h=this.m_newNodes.length;n<h;n++){const e=this.m_newNodes[n];if(null===e)continue;let t=e;for(let s=n+1;s<h;s++){const i=this.m_newNodes[s];null!==i&&(e.pt.equals(i.pt)&&(t.nextInHash=i,i.prevInHash=t,t=i,this.m_newNodes[s]=null))}}for(let n=0,h=this.m_newNodes.length;n<h;n++){const h=this.m_newNodes[n];if(null==h)continue;for(h.hash=this.calculateHash(h.pt);;){const n=we(4),a=this.hashTableBinsToCheck(h,n);for(let t=0;t<a;t++)if(null!==n[t])for(let a=n[t];null!==a;){const t=a.nextInHash;F.distance(h.pt,a.pt)<=e&&(s.push(a),this.removeNodeFromHash(a),a.hash=0,r.push(a),i.push(a)),a=t}let o=!1;for(const e of s)if(!h.pt.equals(e.pt)){const s=mt(h.pt,e.pt,h.weight,h.rank,e.weight,e.rank);h.pt.assign(s.pt),h.weight=s.weight,h.rank=s.rank,o=!0,t=!0}if(s.length=0,!o)break;h.hash=this.calculateHash(h.pt)}r.push(h),i.push(h);for(let e=h.nextInHash;null!==e;){e.prevInHash=null;const t=e.nextInHash;e.nextInHash=null,r.push(e),i.push(e),e=t}const a=h.hash;let o=null,m=null;for(const e of i)h!==e&&(e.hash=a,e.pt.assign(h.pt),e.rank=h.rank,e.weight=h.weight),e.prevInHash=o,o&&(o.nextInHash=e),e.prevEqual=m,e.nextEqual=null,m&&(m.nextEqual=e),m=e,o=e;const g=a%this.m_hashTableOfEquals.length;o.nextInHash=this.m_hashTableOfEquals[g],null!==this.m_hashTableOfEquals[g]&&(this.m_hashTableOfEquals[g].prevInHash=o),this.m_hashTableOfEquals[g]=i[0],this.m_hashTableOfEqualsSize+=i.length,i.length=0,this.rehashIfNeeded()}if(this.m_newNodes.length=0,t)for(const n of r)this.updateAttachedEdgesAfterNodeChange(n)}addNodeToHash(t){e(0)}rehashIfNeeded(){if(2*this.m_hashTableOfEqualsSize>this.m_hashTableOfEquals.length){const e=this.m_hashTableOfEquals;this.m_hashTableOfEquals=we(2*e.length),this.m_hashTableOfEqualsSize=0;for(const t of e){let e=t;for(;e;){const t=e.nextInHash;e.nextInHash=null,e.prevInHash=null,this.addNodeToHashImpl(e),e=t}}}}addNodeToHashImpl(e){const t=e.hash%this.m_hashTableOfEquals.length,s=this.m_hashTableOfEquals[t];e.nextInHash=s,null!==s&&(s.prevInHash=e),this.m_hashTableOfEquals[t]=e,this.m_hashTableOfEqualsSize++}removeNodeFromHash(e){const t=e.hash%this.m_hashTableOfEquals.length,s=e.prevInHash,i=e.nextInHash;s?s.nextInHash=i:this.m_hashTableOfEquals[t]=i,i&&(i.prevInHash=s),this.m_hashTableOfEqualsSize--,e.prevInHash=null,e.nextInHash=null}hashTableBinsToCheck(e,t){const s=(e.pt.x-this.m_origin.x)/this.m_cell.x,i=(e.pt.y-this.m_origin.y)/this.m_cell.y,r=Ne()-1,n=Math.round(De(s,-r,r)),h=Math.round(De(i,-r,r));let a=n|h<<32;a=Be(a),t[0]=this.m_hashTableOfEquals[a%this.m_hashTableOfEquals.length];let o=n+1|h<<32;o=Be(o);let m=1;t[1]=this.m_hashTableOfEquals[o%this.m_hashTableOfEquals.length],t[1]!==t[0]&&(m=2);let g=n+1|h+1<<32;g=Be(g),t[m]=this.m_hashTableOfEquals[g%this.m_hashTableOfEquals.length];for(let _=0;_<m;_++)if(t[m]===t[_]){m--;break}m++;let l=n|h+1<<32;l=Be(l),t[m]=this.m_hashTableOfEquals[l%this.m_hashTableOfEquals.length];for(let _=0;_<m;_++)if(t[m]===t[_]){m--;break}return m++,m}calculateHash(e){const t=(e.x-this.m_origin.x)/this.m_cell.x,s=(e.y-this.m_origin.y)/this.m_cell.y,i=Ne()-1;let r=Math.round(De(t,-i,i))|Math.round(De(s,-i,i))<<32;return r=Be(r),0===r&&(r=1),r}processSharpCorners(e,t,s,i){if(this.parent.m_param1.length=0,this.parent.m_param2.length=0,e.getStartXY().equals(t.getStartXY())){const r=[0,0],n=[0,0],h=ke(e,t,0,0,s,2,r,n,i);if(h){this.parent.m_param1.push(0),this.parent.m_param2.push(0);for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return h+1}}if(e.getEndXY().equals(t.getEndXY())){const r=[0,0],n=[0,0],h=ke(e,t,1,1,s,2,r,n,i);if(h){for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return this.parent.m_param1.push(1),this.parent.m_param2.push(1),h+1}}if(e.getStartXY().equals(t.getEndXY())){const r=[0,0],n=[0,0],h=ke(e,t,0,1,s,2,r,n,i);if(h){this.parent.m_param1.push(0),this.parent.m_param2.push(1);for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return h+1}}if(e.getEndXY().equals(t.getStartXY())){const r=[0,0],n=[0,0],h=ke(e,t,1,0,s,2,r,n,i);if(h){for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return this.parent.m_param1.push(1),this.parent.m_param2.push(0),h+1}}return 0}}function St(e,t,s){let r=0;switch(e){case i.enumLine:r=0;break;case i.enumBezier:r=2;break;case i.enumRationalBezier2:r=3;break;case i.enumBezier2:r=1;break;case i.enumEllipticArc:r=0===t.projectionBehavior()?5:4;break;default:o("")}return s?5-r:r}class Ct extends it{constructor(e){super(e.m_shape,e.m_tolerance,!1),this.m_parent=e}compare(e,t,s){if(this.m_bIntersectionDetected)return-1;const i=e.getElement(s),r=this.m_parent.getEdgeOriginVertices(t),n=this.m_parent.m_edgeVertices.getFirstElement(r),h=this.m_parent.getEdgeOriginVertices(i),a=this.m_parent.m_edgeVertices.getFirstElement(h);return this.m_currentNode=s,this.compareSegments(t,n,i,a)}}class Pt extends rt{constructor(e){super(e.m_shape,e.m_tolerance),this.m_parent=e}compare(e,t){if(this.m_bIntersectionDetected)return-1;const s=e.getElement(t),i=this.m_parent.getEdgeOriginVertices(s),r=this.m_parent.m_edgeVertices.getFirstElement(i);return this.m_currentNode=t,this.compareVertex(e,t,r)}}class yt extends de{constructor(e){super(),this.pt1=F.getNAN(),this.pt2=F.getNAN(),this.m_shape=e}compare(e,t,s){this.m_shape.queryXY(t,this.pt1);const i=e.getElement(s);return this.m_shape.queryXY(i,this.pt2),this.pt1.compare(this.pt2)}}class Nt{constructor(e){this.m_point=F.getNAN(),this.m_pt=F.getNAN(),this.m_shape=e}setPoint(e){this.m_point.setCoordsPoint2D(e)}compare(e,t){const s=e.getElement(t);return this.m_shape.queryXY(s,this.m_pt),this.m_point.compare(this.m_pt)}}class vt{constructor(e,t){this.m_shape=null,this.m_progressTracker=null,this.m_edges=new M(8),this.m_clusters=new M(5),this.m_clusterVertices=new et(!1),this.m_edgeVertices=new et(!1),this.m_helperPoint=new P,this.m_eventQ=new _,this.m_sweepStructure=new _,this.m_bComplications=!1,this.m_sweepComparator=null,this.m_tempEdgeBuffer=[],this.m_modifiedClusters=[],this.m_edgesToInsertInSweepStructure=[],this.m_prevNeighbour=-1,this.m_nextNeighbour=-1,this.m_bContinuingSegmentChainOptimization=!1,this.m_progressCounter=0,this.m_segmentIntersector=new dt,this.m_segBuf1=new G,this.m_segBuf2=new G,this.m_sweepPoint=new F(0,0),this.m_tolerance=0,this.m_toleranceSqr=0,this.m_sweepPointCluster=-1,this.m_vertexClusterIndex=-1,this.m_bCracked=!1,this.m_bSweepPointClusterWasModified=!1,this.m_progressTracker=e,this.m_bTrackChanges=t}hadComplications(){return this.m_bComplications}sweep(e,t){const s=new Q;s.setSwapCoordinates(),e.applyTransformation(s),this.setEditShape_(e),this.m_bCracked=!1,this.m_tolerance=t,this.m_toleranceSqr=t*t;let i=this.sweepImpl_();return e.applyTransformation(s),i||(this.fillEventQueuePass2(),i=this.sweepImpl_()||i),this.m_shape.removeUserIndex(this.m_vertexClusterIndex),this.m_shape=null,this.m_bCracked}sweepVertical(e,t){this.setEditShape_(e),this.m_bCracked=!1,this.m_tolerance=t,this.m_toleranceSqr=t*t,this.m_bComplications=!1;let s=this.sweepImpl_();if(!this.m_bComplications){const i=e.filterClosePoints(t,!0,!1,this.m_bTrackChanges,H);this.m_bComplications=1===i,s||=1===i}return-1!==this.m_vertexClusterIndex&&(this.m_shape.removeUserIndex(this.m_vertexClusterIndex),this.m_vertexClusterIndex=-1),this.m_shape=null,s}getEdgeCluster(e,t){return this.m_edges.getField(e,0+t)}setEdgeCluster_(e,t,s){this.m_edges.setField(e,0+t,s)}getEdgeOriginVertices(e){return this.m_edges.getField(e,2)}setEdgeOriginVertices_(e,t){this.m_edges.setField(e,2,t)}getNextEdgeEx(e,t){return this.m_edges.getField(e,3+t)}setNextEdgeEx_(e,t,s){this.m_edges.setField(e,3+t,s)}getEdgeSweepNode(e){return this.m_edges.getField(e,7)}setEdgeSweepNode_(e,t){this.m_edges.setField(e,7,t)}getNextEdge(e,t){const s=this.getEdgeEnd(e,t);return this.m_edges.getField(e,3+s)}setNextEdge_(e,t,s){const i=this.getEdgeEnd(e,t);this.m_edges.setField(e,3+i,s)}getPrevEdge(e,t){const s=this.getEdgeEnd(e,t);return this.m_edges.getField(e,5+s)}setPrevEdge_(e,t,s){const i=this.getEdgeEnd(e,t);this.m_edges.setField(e,5+i,s)}getClusterVertices(e){return this.m_clusters.getField(e,0)}setClusterVertices_(e,t){this.m_clusters.setField(e,0,t)}getClusterSweepEdgeList(e){return this.m_clusters.getField(e,2)}setClusterSweepEdgeList_(e,t){this.m_clusters.setField(e,2,t)}getClusterFirstEdge(e){return this.m_clusters.getField(e,1)}setClusterFirstEdge_(e,t){this.m_clusters.setField(e,1,t)}getClusterEventQNode(e){return this.m_clusters.getField(e,3)}setClusterEventQNode_(e,t){this.m_clusters.setField(e,3,t)}newCluster_(e){const t=this.m_clusters.newElement(),s=this.m_clusterVertices.createList();return this.setClusterVertices_(t,s),e!==H&&(this.m_clusterVertices.addElement(s,e),this.m_shape.setUserIndex(e,this.m_vertexClusterIndex,t)),t}deleteCluster_(e){this.m_clusters.deleteElement(e)}addVertexToCluster_(e,t){const s=this.getClusterVertices(e);this.m_clusterVertices.addElement(s,t),this.m_shape.setUserIndex(t,this.m_vertexClusterIndex,e)}newEdge_(e){const t=this.m_edges.newElement(),s=this.m_edgeVertices.createList();return this.setEdgeOriginVertices_(t,s),-1!==e&&this.m_edgeVertices.addElement(s,e),t}addVertexToEdge_(e,t){const s=this.getEdgeOriginVertices(e);this.m_edgeVertices.addElement(s,t)}deleteEdge_(e){this.m_edges.deleteElement(e);const t=this.m_edgesToInsertInSweepStructure.findIndex((t=>t===e));t>=0&&Z(this.m_edgesToInsertInSweepStructure,t)}addEdgeToCluster(e,t){-1===this.getEdgeCluster(e,0)?this.setEdgeCluster_(e,0,t):-1===this.getEdgeCluster(e,1)?this.setEdgeCluster_(e,1,t):o(""),this.addEdgeToClusterImpl_(e,t)}addEdgeToClusterImpl_(e,t){const s=this.getClusterFirstEdge(t);if(-1!==s){const i=this.getNextEdge(s,t);this.setPrevEdge_(i,t,e),this.setNextEdge_(e,t,i),this.setNextEdge_(s,t,e),this.setPrevEdge_(e,t,s)}else this.setPrevEdge_(e,t,e),this.setNextEdge_(e,t,e),this.setClusterFirstEdge_(t,e)}getEdgeEnd(e,t){return this.getEdgeCluster(e,0)===t?0:1}mergeClusters_(e,t){this.dbgCheckCluster_(e),this.dbgCheckCluster_(t);const s=this.getClusterEventQNode(t);-1!==s&&(this.m_eventQ.deleteNode(s),this.setClusterEventQNode_(t,-1));let i=this.getClusterFirstEdge(e),r=this.getClusterFirstEdge(t);if(-1!==r){let s=r,n=r,h=!1;do{this.dbgCheckEdge_(s),h=!1;const i=this.getEdgeEnd(s,t),a=this.getNextEdgeEx(s,i);if(this.getEdgeCluster(s,i+1&1)===e){this.disconnectEdge_(s);const e=this.getEdgeOriginVertices(s);if(this.m_edgeVertices.deleteList(e),this.deleteEdge_(s),s===a){r=-1;break}r===s&&(r=this.getClusterFirstEdge(t),n=a,h=!0)}s=a}while(s!==n||h);if(-1!==r){do{const i=this.getEdgeEnd(s,t),r=this.getNextEdgeEx(s,i);this.setEdgeCluster_(s,i,e),s=r}while(s!==n);if(i=this.getClusterFirstEdge(e),-1!==i){const t=this.getNextEdge(i,e),s=this.getNextEdge(r,e);t===i?(this.setClusterFirstEdge_(e,r),this.addEdgeToClusterImpl_(i,e),this.setClusterFirstEdge_(e,i)):s===r&&this.addEdgeToClusterImpl_(r,e),this.setNextEdge_(r,e,t),this.setPrevEdge_(t,e,r),this.setNextEdge_(i,e,s),this.setPrevEdge_(s,e,i)}else this.setClusterFirstEdge_(e,r)}}const n=this.getClusterVertices(e),h=this.getClusterVertices(t);for(let a=this.m_clusterVertices.getFirst(h);-1!==a;a=this.m_clusterVertices.getNext(a)){const t=this.m_clusterVertices.getElement(a);this.m_shape.setUserIndex(t,this.m_vertexClusterIndex,e)}this.m_clusterVertices.concatenateLists(n,h),this.deleteCluster_(t),this.dbgCheckCluster_(e)}mergeEdges_(e,t){this.dbgCheckEdge_(e),this.dbgCheckEdge_(t);const s=this.getEdgeCluster(e,0),i=this.getEdgeCluster(e,1),r=this.getEdgeCluster(t,0),n=this.getEdgeCluster(t,1),h=this.getEdgeOriginVertices(e),a=this.getEdgeOriginVertices(t);if(this.m_edgeVertices.concatenateLists(h,a),t===this.getClusterFirstEdge(s)&&this.setClusterFirstEdge_(s,e),t===this.getClusterFirstEdge(i)&&this.setClusterFirstEdge_(i,e),this.disconnectEdge_(t),this.deleteEdge_(t),!(s===r&&i===n||i===r&&s===n)){const e=this.getClusterXY(s),t=this.getClusterXY(r);e.isEqualPoint2D(t)?(s!==r&&this.mergeClusters_(s,r),i!==n&&this.mergeClusters_(i,n)):(i!==r&&this.mergeClusters_(i,r),s!==n&&this.mergeClusters_(s,n))}this.dbgCheckEdge_(e)}disconnectEdge_(e){const t=this.getEdgeCluster(e,0),s=this.getEdgeCluster(e,1);this.disconnectEdgeFromCluster_(e,t),this.disconnectEdgeFromCluster_(e,s)}disconnectEdgeFromCluster_(e,t){const s=this.getNextEdge(e,t),i=this.getPrevEdge(e,t),r=this.getClusterFirstEdge(t);s!==e?(this.setNextEdge_(i,t,s),this.setPrevEdge_(s,t,i),r===e&&this.setClusterFirstEdge_(t,s)):this.setClusterFirstEdge_(t,-1)}applyIntersectorToEditShape_(e,t,s){let i=this.m_edgeVertices.getFirst(e);const r=this.m_edgeVertices.getElement(i),n=this.getClusterFromVertex(r),h=this.m_shape.getNextVertex(r),a=this.getClusterFromVertex(h),o=this.m_shape.getXY(r),m=this.m_shape.getXY(h);let g=!1,l=!1;const _=t.getResultSegment(s,0).getStartXY(),d=t.getResultSegment(s,t.getResultSegmentCount(s)-1).getEndXY();o.equals(_)||(g=!0),m.equals(d)||(l=!0),this.m_shape.splitSegmentWithIntersector(r,t,s,!0,!0);const p=this.m_bTrackChanges&&t.getSegmentChanged(s);for(p&&this.m_shape.setGeometryModifiedWithVertex(r,!0),i=this.m_edgeVertices.getNext(i);-1!==i;i=this.m_edgeVertices.getNext(i)){const e=this.m_edgeVertices.getElement(i),r=this.getClusterFromVertex(e)===n;this.m_shape.splitSegmentWithIntersector(e,t,s,r,!0),p&&this.m_shape.setGeometryModifiedWithVertex(e,!0)}if(g&&this.updateClusterXY(!0,n,_,t.getResultSegmentStartPointWeight(s,0),t.getResultSegmentStartPointRank(s,0)),l){const e=t.getResultSegmentCount(s)-1;this.updateClusterXY(!0,a,d,t.getResultSegmentEndPointWeight(s,e),t.getResultSegmentEndPointRank(s,e))}}createEdgesAndClustersFromSplitEdge_(e,t,s){this.dbgCheckNewEdgesArray_();const i=this.getEdgeOriginVertices(e),r=this.getEdgeCluster(e,0),n=this.getEdgeCluster(e,1);let h=this.newEdge_(-1);this.m_edgesToInsertInSweepStructure.push(h);const a=M.impossibleIndex3();this.setEdgeSweepNode_(h,a),this.m_tempEdgeBuffer.push(h),this.addEdgeToCluster(h,r);const o=t.getResultSegmentCount(s);for(let m=1;m<o;m++){const e=this.newCluster_(-1);this.m_modifiedClusters.push(e),this.m_tempEdgeBuffer.push(e),this.addEdgeToCluster(h,e);const t=this.newEdge_(-1);this.m_edgesToInsertInSweepStructure.push(t),this.setEdgeSweepNode_(t,a),this.m_tempEdgeBuffer.push(t),this.addEdgeToCluster(t,e),h=t}this.addEdgeToCluster(h,n);for(let m=this.m_edgeVertices.getFirst(i);-1!==m;m=this.m_edgeVertices.getNext(m)){let e=this.m_edgeVertices.getElement(m);if(this.getClusterFromVertex(e)===r){let t=0;const s=this.m_tempEdgeBuffer.length;do{if(t>0){const s=this.m_tempEdgeBuffer[t-1];this.addVertexToCluster_(s,e)}const s=this.m_tempEdgeBuffer[t];t+=2,this.addVertexToEdge_(s,e),e=this.m_shape.getNextVertex(e)}while(t<s)}else{let t=this.m_tempEdgeBuffer.length-1;do{if(t<this.m_tempEdgeBuffer.length-2){const s=this.m_tempEdgeBuffer[t+1];this.addVertexToCluster_(s,e)}const s=this.m_tempEdgeBuffer[t];t-=2,this.addVertexToEdge_(s,e),e=this.m_shape.getNextVertex(e)}while(t>=0)}}this.m_tempEdgeBuffer.length=0,this.dbgCheckNewEdgesArray_()}getVertexFromClusterIndex(e){const t=this.getClusterVertices(e);return this.m_clusterVertices.getFirstElement(t)}getClusterFromVertex(e){return this.m_shape.getUserIndex(e,this.m_vertexClusterIndex)}processSplitHelper1_(e,t,s){const i=this.getEdgeCluster(t,0),r=this.getClusterXY(i),n=this.getEdgeCluster(t,1),h=this.getClusterXY(n),a=s.getResultSegmentCount(e);let o=s.getResultSegment(e,0);const m=o.getStartXY();if(!r.isEqualPoint2D(m)){if(!this.m_bComplications){r.compare(this.m_sweepPoint)*m.compare(this.m_sweepPoint)<0&&(this.m_bComplications=!0)}this.getAffectedEdges(i,this.m_tempEdgeBuffer),this.m_modifiedClusters.push(i)}if(!this.m_bComplications&&a>1){const e=r.compare(h),t=o.getEndXY();(r.compare(t)!==e||t.compare(h)!==e||t.compare(this.m_sweepPoint)<0)&&(this.m_bComplications=!0)}o=s.getResultSegment(e,a-1);const g=o.getEndXY();if(!h.isEqualPoint2D(g)){if(!this.m_bComplications){h.compare(this.m_sweepPoint)*g.compare(this.m_sweepPoint)<0&&(this.m_bComplications=!0)}this.getAffectedEdges(n,this.m_tempEdgeBuffer),this.m_modifiedClusters.push(n)}this.m_tempEdgeBuffer.push(t);for(let l=0,_=this.m_tempEdgeBuffer.length;l<_;l++){const e=this.m_tempEdgeBuffer[l],s=this.getEdgeSweepNode(e);M.isValidElement(s)&&(this.m_sweepStructure.deleteNode(s),this.setEdgeSweepNode_(e,-1));const i=M.impossibleIndex3();e!==t&&this.getEdgeSweepNode(e)!==i&&(this.m_edgesToInsertInSweepStructure.push(e),this.setEdgeSweepNode_(e,i))}this.m_tempEdgeBuffer.length=0}checkAndFixIntersection_(e,t){const s=this.m_sweepStructure.getElement(e);return this.m_sweepComparator.compare(this.m_sweepStructure,s,t),!!this.m_sweepComparator.intersectionDetected()&&(this.m_sweepComparator.clearIntersectionDetectedFlag(),this.fixIntersection_(e,t),!0)}fixIntersection_(t,s){this.m_bCracked=!0;const i=this.m_sweepStructure.getElement(t),r=this.m_sweepStructure.getElement(s);let n=null,h=null;const a=this.getEdgeOriginVertices(i),o=this.m_edgeVertices.getFirstElement(a),m=this.getEdgeOriginVertices(r),g=this.m_edgeVertices.getFirstElement(m),l=this.m_shape.querySegment(o,this.m_segBuf1,!1,!1);e(l),n=this.m_segBuf1.get();const _=this.m_shape.getNextVertex(o),d=this.m_shape.getWeight(o),p=this.m_shape.getSegmentParentageBreakVertex(o),u=this.m_shape.getWeight(_),c=this.m_shape.getSegmentParentageBreakVertex(_),f=this.m_shape.getSegmentWeight(o),x=this.m_shape.getRank(o),E=this.m_shape.getRank(_),I=this.m_shape.getSegmentRank(o),S=this.m_shape.getSegmentParentage(o),C=this.m_shape.querySegment(g,this.m_segBuf2,!1,!1);e(C),h=this.m_segBuf2.get();const P=this.m_shape.getNextVertex(g),y=this.m_shape.getWeight(g),N=this.m_shape.getSegmentParentageBreakVertex(g),v=this.m_shape.getWeight(P),b=this.m_shape.getSegmentParentageBreakVertex(P),w=this.m_shape.getSegmentWeight(g),V=this.m_shape.getRank(g),H=this.m_shape.getRank(P),T=this.m_shape.getSegmentRank(g),k=this.m_shape.getSegmentParentage(g);this.m_segmentIntersector.pushSegment(n,d,x,u,E,f,I,p,c,S),this.m_segmentIntersector.pushSegment(h,y,V,v,H,w,T,N,b,k),3===this.m_segmentIntersector.intersect(this.m_tolerance,!0)&&(this.m_bComplications=!0),this.splitEdge_(i,r,-1,this.m_segmentIntersector),this.m_segmentIntersector.clear()}fixIntersectionPointSegment_(t,s){e(0)}insertNewEdges_(){if(0===this.m_edgesToInsertInSweepStructure.length)return!0;this.dbgCheckNewEdgesArray_();let e=!0,t=0;const s=this.m_edgesToInsertInSweepStructure.length,i=Math.max(2*s+200,this.m_sweepStructure.size()+200);for(;this.m_edgesToInsertInSweepStructure.length;){if(this.m_edgesToInsertInSweepStructure.length>Math.max(100,this.m_shape.getTotalPointCount())||t>i){this.m_edgesToInsertInSweepStructure.length=0,this.m_bComplications=!0,e=!1;break}const s=this.m_edgesToInsertInSweepStructure.at(-1);this.m_edgesToInsertInSweepStructure.pop(),this.setEdgeSweepNode_(s,-1);const r=this.isEdgeOnSweepLine_(s);M.isValidElement(r)?(this.insertNewEdgeToSweepStructure_(s,r),t++):r!==M.impossibleIndex2()&&(e=!1),this.m_bContinuingSegmentChainOptimization=!1}return e}insertNewEdgeToSweepStructure_(e,t){let s;if(this.m_bContinuingSegmentChainOptimization?(s=this.m_sweepStructure.addElementAtPosition(this.m_prevNeighbour,this.m_nextNeighbour,e,!0,!0),this.m_bContinuingSegmentChainOptimization=!1):s=this.m_sweepStructure.addUniqueElement(e),-1===s){const t=this.m_sweepStructure.getDuplicateElement(),s=this.m_sweepStructure.getElement(t);return this.mergeEdges_(s,e),!1}if(this.setEdgeSweepNode_(e,s),this.m_sweepComparator.intersectionDetected()){this.m_sweepComparator.clearIntersectionDetectedFlag();const e=this.m_sweepComparator.getLastComparedNode();return this.m_prevNeighbour===e&&(this.m_prevNeighbour=-1),this.m_nextNeighbour===e&&(this.m_nextNeighbour=-1),this.fixIntersection_(e,s),!0}return!1}isEdgeOnSweepLine_(e){const t=this.getEdgeCluster(e,0),s=this.getEdgeCluster(e,1),i=this.getClusterXY(t),r=this.getClusterXY(s);if(F.sqrDistance(i,r)<=this.m_toleranceSqr)return this.m_bComplications=!0,-1;const n=i.compare(this.m_sweepPoint),h=r.compare(this.m_sweepPoint);return n<=0&&h>0?s:h<=0&&n>0?t:n>0&&h>0?M.impossibleIndex2():-1}fillEventQueue(){const e=new c(0),t=this.m_shape.queryVertexIteratorOnSelection();for(let r=t.next();r!==H;r=t.next())-1!==this.m_shape.getUserIndex(r,this.m_vertexClusterIndex)&&e.add(r);this.m_shape.sortVerticesSimpleByY(e,0,e.size()),this.progress_(!0),this.m_eventQ.clear(),this.m_eventQ.setCapacity(e.size()),this.m_eventQ.setComparator(new yt(this.m_shape));const s=F.getNAN();s.setNAN();let i=-1;for(let r=0,n=e.size();r<n;r++){const t=e.read(r);if(this.m_shape.getXY(t).isEqualPoint2D(s)){const e=this.m_shape.getUserIndex(t,this.m_vertexClusterIndex);this.mergeClusters_(i,e);continue}i=this.getClusterFromVertex(t),this.m_shape.queryXY(t,s);const n=this.m_eventQ.addBiggestElement(t);this.setClusterEventQNode_(i,n)}}fillEventQueuePass2(){const e=new c(0);for(let t=this.m_eventQ.getFirst();-1!==t;t=this.m_eventQ.getNext(t)){const s=this.m_eventQ.getElement(t);e.add(s)}this.m_eventQ.clear(),this.m_shape.sortVerticesSimpleByY(e,0,e.size()),this.progress_(!0);for(let t=0,s=e.size();t<s;t++){const s=e.read(t),i=this.getClusterFromVertex(s),r=this.m_eventQ.addBiggestElement(s);this.setClusterEventQNode_(i,r)}}getAffectedEdges(e,t){const s=this.getClusterFirstEdge(e);if(-1===s)return;let i=s;do{const s=this.getEdgeSweepNode(i);M.isValidElement(s)&&t.push(i),i=this.getNextEdge(i,e)}while(i!==s)}updateClusterXY(e,t,s,i,r){const n=this.getClusterVertices(t);for(let h=this.m_clusterVertices.getFirst(n);-1!==h;h=this.m_clusterVertices.getNext(h)){const t=this.m_clusterVertices.getElement(h);this.m_shape.setXYMonotonicPoint2D(t,s),this.m_shape.setWeight(t,i),this.m_shape.setRank(t,r),e&&this.m_bTrackChanges&&this.m_shape.setGeometryModifiedWithVertex(t,!0),this.m_shape.setSegmentParentageBreakVertex(t,!0)}}splitEdge_(e,t,s,i){this.dbgCheckEdge_(e),-1!==t&&this.dbgCheckEdge_(t),this.disconnectEdge_(e),-1!==t&&this.disconnectEdge_(t),this.processSplitHelper1_(0,e,i),-1!==t&&this.processSplitHelper1_(1,t,i),-1!==s&&i.getResultPointChanged()&&this.m_modifiedClusters.push(s);for(let h=0,a=this.m_modifiedClusters.length;h<a;h++){const e=this.m_modifiedClusters[h],t=this.getClusterEventQNode(e);-1!==t&&(this.m_eventQ.deleteNode(t),this.setClusterEventQNode_(e,-1))}const r=this.getEdgeOriginVertices(e),n=-1!==t?this.getEdgeOriginVertices(t):-1;if(this.applyIntersectorToEditShape_(r,i,0),-1!==n)this.applyIntersectorToEditShape_(n,i,1);else{const e=i.getResultPoint().getXY();this.updateClusterXY(i.getResultPointChanged(),s,e,i.getResultPointWeight(),i.getResultPointRank())}this.createEdgesAndClustersFromSplitEdge_(e,i,0),-1!==t&&this.createEdgesAndClustersFromSplitEdge_(t,i,1),this.m_edgeVertices.deleteList(r),this.deleteEdge_(e),-1!==t&&(this.m_edgeVertices.deleteList(n),this.deleteEdge_(t));for(let h=0,a=this.m_modifiedClusters.length;h<a;h++){const e=this.m_modifiedClusters[h];e===this.m_sweepPointCluster&&(this.m_bSweepPointClusterWasModified=!0);let t=this.getClusterEventQNode(e);if(-1===t){const s=this.getClusterFirstVertex(e);if(t=this.m_eventQ.addUniqueElement(s),-1===t){const t=this.m_eventQ.getDuplicateElement(),s=this.m_eventQ.getElement(t),i=this.getClusterFromVertex(s);this.mergeClusters_(i,e)}else this.setClusterEventQNode_(e,t)}}this.m_modifiedClusters.length=0}getClusterXY(e){const t=this.getClusterFirstVertex(e);return this.m_shape.getXY(t)}getClusterFirstVertex(e){const t=this.getClusterVertices(e);return this.m_clusterVertices.getFirstElement(t)}dbgCheckEdge_(e){}dbgCheckCluster_(e){}dbgCheckNewEdgesArray_(){}dbgSaveSweepStructure_(t){e(0)}sweepImpl_(){this.progress_(!0),this.m_bSweepPointClusterWasModified=!1,this.m_sweepPointCluster=-1,null===this.m_sweepComparator&&(this.m_sweepStructure.disableBalancing(),this.m_sweepComparator=new Ct(this),this.m_sweepStructure.setComparator(this.m_sweepComparator));const e=[];let t=null,s=null;this.m_prevNeighbour=-1,this.m_nextNeighbour=-1,this.m_bContinuingSegmentChainOptimization=!1;const i=M.impossibleIndex2(),r=M.impossibleIndex3();for(let n=this.m_eventQ.getFirst();-1!==n;){this.progress_(),this.dbgCheckSweepStructure_(),this.m_bContinuingSegmentChainOptimization=!1,this.m_prevNeighbour=-1,this.m_nextNeighbour=-1;const h=this.m_eventQ.getElement(n);this.m_sweepPointCluster=this.getClusterFromVertex(h),this.m_shape.queryXY(h,this.m_sweepPoint),this.m_sweepComparator.setSweepY(this.m_sweepPoint.y,this.m_sweepPoint.x);let a=!1;{const t=this.getClusterFirstEdge(this.m_sweepPointCluster);if(a=-1===t,!a){let s=t;do{const t=this.getEdgeSweepNode(s);-1===t?(this.m_edgesToInsertInSweepStructure.push(s),this.setEdgeSweepNode_(s,r)):t!==r&&e.push(t),s=this.getNextEdge(s,this.m_sweepPointCluster)}while(s!==t)}}if(!this.m_sweepStructure.isAutoBalancing()&&(this.m_sweepStructure.getMaxDepthEver()>4||this.m_edgesToInsertInSweepStructure.length>10)&&this.m_sweepStructure.enableBalancing(),e.length>0){this.m_bContinuingSegmentChainOptimization=1===e.length&&1===this.m_edgesToInsertInSweepStructure.length;for(let r=0,n=e.length;r<n;r++){const t=this.m_sweepStructure.getElement(e[r]);this.setEdgeSweepNode_(t,i)}let t=i,s=i;for(let r=0,n=e.length;r<n;r++){const n=e[r];if(t===i){const e=this.m_sweepStructure.getPrev(n);if(-1!==e){const s=this.m_sweepStructure.getElement(e);this.getEdgeSweepNode(s)!==i&&(t=e)}else t=-1}if(s===i){const e=this.m_sweepStructure.getNext(n);if(-1!==e){const t=this.m_sweepStructure.getElement(e);this.getEdgeSweepNode(t)!==i&&(s=e)}else s=-1}if(t!==i&&s!==i)break}for(let i=0,r=e.length;i<r;i++){const t=e[i],s=this.m_sweepStructure.getElement(t);this.m_sweepStructure.deleteNode(t),this.setEdgeSweepNode_(s,-1)}e.length=0,this.m_prevNeighbour=t,this.m_nextNeighbour=s,-1!==t&&-1!==s?this.m_bContinuingSegmentChainOptimization||this.checkAndFixIntersection_(t,s):-1===t&&-1===s&&(this.m_bContinuingSegmentChainOptimization=!1)}else a&&(null===t&&(t=new Pt(this)),t.setPoint(this.m_sweepPoint),this.m_sweepStructure.searchUpperBound(t),t.intersectionDetected()&&(t.clearIntersectionDetectedFlag(),this.fixIntersectionPointSegment_(this.m_sweepPointCluster,t.getCurrentNode())));const o=this.m_bContinuingSegmentChainOptimization;!this.insertNewEdges_()&&o&&-1!==this.m_prevNeighbour&&-1!==this.m_nextNeighbour&&this.checkAndFixIntersection_(this.m_prevNeighbour,this.m_nextNeighbour),this.m_bSweepPointClusterWasModified?(this.m_bSweepPointClusterWasModified=!1,null===s&&(s=new Nt(this.m_shape)),s.setPoint(this.m_sweepPoint),n=this.m_eventQ.searchUpperBound(s)):n=this.m_eventQ.getNext(n)}return this.m_bCracked}setEditShape_(e){this.m_shape=e,this.m_vertexClusterIndex=this.m_shape.createUserIndex(),this.m_edges.setCapacity(e.getSelectedCount()+32),this.m_clusters.setCapacity(e.getSelectedCount()),this.m_clusterVertices.reserveLists(e.getSelectedCount()),this.m_clusterVertices.reserveNodes(e.getSelectedCount()),this.m_edgeVertices.reserveLists(e.getSelectedCount()+32),this.m_edgeVertices.reserveNodes(e.getSelectedCount()+32);for(let t=this.m_shape.getFirstGeometry();t!==H;t=this.m_shape.getNextGeometry(t)){if(u(this.m_shape.getGeometryType(t)))for(let s=this.m_shape.getFirstPath(t);s!==H;s=this.m_shape.getNextPath(s)){const t=this.m_shape.getPathSize(s),i=this.m_shape.getFirstVertex(s);if(i===H)continue;let r=this.m_shape.getNextVertex(i);if(r===H||r===i)continue;let n=-1;e.selected(i)&&(n=this.newCluster_(i));let h=-1;-1!==n&&e.selected(r)&&(h=this.newEdge_(i),this.addEdgeToCluster(h,n));let a=h;for(let e=0,s=t-2;e<s;e++){const e=this.m_shape.getNextVertex(r);let t=-1;if(this.m_shape.selected(r)){const s=this.newCluster_(r);-1!==a&&this.addEdgeToCluster(a,s),this.m_shape.selected(e)&&(t=this.newEdge_(r),this.addEdgeToCluster(t,s))}a=t,r=e}if(this.m_shape.isClosedPath(s)){const e=this.m_shape.getNextVertex(r);if(this.m_shape.selected(r)){const t=this.newCluster_(r);if(-1!==a&&this.addEdgeToCluster(a,t),this.m_shape.selected(e)){const e=this.newEdge_(r);this.addEdgeToCluster(e,t),this.addEdgeToCluster(e,n)}}}else{let e=-1;this.m_shape.selected(r)&&(e=this.newCluster_(r),-1!==a&&this.addEdgeToCluster(a,e))}}else for(let e=this.m_shape.getFirstPath(t);e!==H;e=this.m_shape.getNextPath(e)){let t=this.m_shape.getFirstVertex(e);for(let s=0,i=this.m_shape.getPathSize(e);s<i;s++)this.m_shape.selected(t)&&this.newCluster_(t),t=this.m_shape.getNextVertex(t)}}this.fillEventQueue()}progress_(e=!1){}dbgCheckSweepStructure_(){}}class bt{constructor(e,t){this.m_monotoneParts=he(G,16),this.m_xOrds=Y(16,Number.NaN),this.m_inputPoint=F.getNAN(),this.m_miny=0,this.m_maxy=0,this.m_windnum=0,this.m_bAlternate=e,this.m_tolerance=t,this.m_toleranceSqr=t*t,this.m_bTestBorder=!!t,this.m_bBreak=!1}_DoOne(e){if(!this.m_bTestBorder&&(this.m_bAlternate&&this.m_inputPoint.equals(e.getStartXY())||this.m_inputPoint.equals(e.getEndXY())))return void(this.m_bBreak=!0);if(e.getStartY()===this.m_inputPoint.y&&e.getStartY()===e.getEndY()){if(this.m_bAlternate&&!this.m_bTestBorder){const t=Math.min(e.getStartX(),e.getEndX()),s=Math.max(e.getStartX(),e.getEndX());this.m_inputPoint.x>t&&this.m_inputPoint.x<s&&(this.m_bBreak=!0)}return}let t=!1;const s=Math.max(e.getStartX(),e.getEndX());if(this.m_inputPoint.x>s)t=!0;else if(this.m_inputPoint.x>=Math.min(e.getStartX(),e.getEndX())){const i=e.intersectionOfYMonotonicWithAxisX(this.m_inputPoint.y,s);t=!Number.isNaN(i)&&i<=this.m_inputPoint.x}if(t){if(this.m_inputPoint.y===e.getStartY()){if(this.m_inputPoint.y<e.getEndY())return}else if(this.m_inputPoint.y===e.getEndY()&&this.m_inputPoint.y<e.getStartY())return;this.m_bAlternate?this.m_windnum^=1:this.m_windnum+=e.getStartY()>e.getEndY()?1:-1}}_Result(){return!!this.m_windnum}testBorder(e){const t=e.getClosestCoordinate(this.m_inputPoint,!1),s=e.getCoord2D(t);return F.sqrDistance(s,this.m_inputPoint)<=this.m_toleranceSqr}SetInputPoint(e){this.m_inputPoint.setCoordsPoint2D(e),this.m_miny=e.y-this.m_tolerance,this.m_maxy=e.y+this.m_tolerance}processSegment(e){const t=e.queryInterval(0,1);if(t.vmin>this.m_maxy||t.vmax<this.m_miny)return!1;if(this.m_bTestBorder&&this.testBorder(e))return!0;if(t.vmin>this.m_inputPoint.y||t.vmax<this.m_inputPoint.y)return!1;const s=e.getMonotonicParts(this.m_monotoneParts,!0);if(s>0)for(let i=0;i<s;i++){const e=this.m_monotoneParts[i].get(),t=le.construct(e.getStartY(),e.getEndY());if(!(t.vmin>this.m_inputPoint.y||t.vmax<this.m_inputPoint.y)&&(this._DoOne(e),this.m_bBreak))return!0}else if(this._DoOne(e),this.m_bBreak)return!0;return!1}result(){return e(0),2}}function wt(e,t,s){const i=0===e.getFillRule(),r=new bt(i,s);r.SetInputPoint(t);const n=e.getImpl().querySegmentIterator();for(;n.nextPath();)for(;n.hasNextSegment();){const e=n.nextSegment();if(r.processSegment(e))return-1}return r._Result()?1:0}function Vt(e,t,s){return t.isEmpty()?0:Ht(e,t.getXY(),s)}function Ht(e,t,s){if(e.isEmpty())return 0;const i=n.constructEmpty();if(e.queryLooseEnvelope(i),i.inflateCoords(s,s),!i.contains(t))return 0;return e.getImpl().getAccelerators(),wt(e,t,s)}function Tt(e,t){const s=e.getPointCount();if(s<16)return!1;const i=1;return 2*s+1*(Math.log(s)/Math.log(2))*t<i*s*t}function kt(e){for(let t=e.getFirstGeometry();t!==H;t=e.getNextGeometry(t))if(u(e.getGeometryType(t)))return!0;return!1}function Ft(e,t,s,i){if(!kt(e))return!1;const r=new Bt(i);r.m_shape=e,r.m_tolerance=t,r.m_bTrackChanges=s;let n=!1;const h=e.hasCurves()?5:15;return n=e.getTotalPointCount()<h?r.crackBruteForce_():r.crackerPlaneSweep_(),n}function Gt(e,t,s,i,r){if(!kt(t))return!1;let n=new Bt(r);if(n.m_shape=t,n.m_tolerance=s,n.m_bAllowCoincident=e,n.m_bNeedsNonSimpleResult=null!==i,n.needsCrackingImpl_())return i&&i.assign(n.m_nonSimpleResult),!0;const h=new Q;h.setSwapCoordinates(),t.applyTransformation(h),n=new Bt(r),n.m_shape=t,n.m_tolerance=s,n.m_bAllowCoincident=e,n.m_bNeedsNonSimpleResult=null!==i;const a=n.needsCrackingImpl_();return t.applyTransformation(h),!!a&&(i&&i.assign(n.m_nonSimpleResult),!0)}class Bt{crackBruteForce_(){let e=this.crackBruteForceImpl_();if(!e&&this.m_shape.hasCurves()){const t=new Q;t.setSwapCoordinates(),this.m_shape.applyTransformation(t),e=this.crackBruteForceImpl_(),this.m_shape.applyTransformation(t)}return e}crackBruteForceImpl_(){let t=!1;const s=new G,i=new G,r=n.constructEmpty(),h=n.constructEmpty(),a=!1,o=new P,m=new dt,g=this.m_shape.getTotalPointCount(),l=g*g*2,_=this.m_shape.queryVertexIteratorOnSelection();for(let n=_.next();n!==H;n=_.next()){const g=this.m_shape.getGeometryType(_.currentGeometry());let d=1,p=1,u=1,c=0,f=0,x=0;const E=this.m_shape.getSegmentParentage(n);let I=!1,S=!1,C=null,P=!1;if(z(g))d=this.m_shape.getWeight(n),c=this.m_shape.getRank(n);else{if(C=this.getSegment_(n,s),null===C)continue;const e=this.m_shape.getVertexIndex(n);d=this.m_shape.getWeightWithIndex(e),c=this.m_shape.getRankWithIndex(e),u=this.m_shape.getSegmentWeightWithIndex(e),x=this.m_shape.getSegmentRankWithIndex(e),I=this.m_shape.getSegmentParentageBreakVertex(n);{const e=this.m_shape.getNextVertex(n);p=this.m_shape.getWeight(e),f=this.m_shape.getRank(e),S=this.m_shape.getSegmentParentageBreakVertex(e)}if(C.queryLooseEnvelope(r),r.inflateCoords(this.m_tolerance,this.m_tolerance),C.isDegenerate(this.m_tolerance)){if(!C.isDegenerate(0))continue;P=!0,C=null}}const y=new j({copy:_});let N=y.next();N!==H&&(N=y.next());let v=0;for(;N!==H;N=y.next()){if(0!==v){v--;continue}if(this.m_shape.getTotalPointCount()>l)return t;this.progress_();const g=this.m_shape.getGeometryType(y.currentGeometry());let b=null,w=!1,V=0,T=0,k=0,F=0,G=0,B=0,D=!1,A=!1;const U=this.m_shape.getSegmentParentage(N);if(z(g))V=this.m_shape.getWeight(N),F=this.m_shape.getRank(N);else{if(b=this.getSegment_(N,i),null===b)continue;const e=this.m_shape.getVertexIndex(N);V=this.m_shape.getWeightWithIndex(e),F=this.m_shape.getRankWithIndex(e),k=this.m_shape.getSegmentWeightWithIndex(e),B=this.m_shape.getSegmentRankWithIndex(e),D=this.m_shape.getSegmentParentageBreakVertex(N);{const e=this.m_shape.getNextVertex(N);T=this.m_shape.getWeight(e),G=this.m_shape.getRank(e),A=this.m_shape.getSegmentParentageBreakVertex(e)}if(b.queryLooseEnvelope(h),b.isDegenerate(this.m_tolerance)){if(!b.isDegenerate(0))continue;w=!0,b=null}}let O=0,Y=0;if(null!==C&&null!==b){if(r.isIntersectingNe(h)){0!==K(!0,!0,C,b,this.m_tolerance,!0)&&(m.pushSegment(C,d,c,p,f,u,x,I,S,E),m.pushSegment(b,V,F,T,G,k,B,D,A,U),m.intersect(this.m_tolerance,!0),t||=m.getSegmentChanged(0)||m.getSegmentChanged(1),O=m.getResultSegmentCount(0),Y=m.getResultSegmentCount(1),O+Y>0&&(this.m_shape.splitSegmentWithIntersector(n,m,0,!0,!0),this.m_shape.splitSegmentWithIntersector(N,m,1,!0,!0),this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(n,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(N,!0))),Y>1&&(v+=Y-1),m.clear())}}else if(null!==C){const e=this.m_shape.getXY(N);if(r.contains(e)){if(m.pushSegment(C,d,c,p,f,u,x,I,S,E),this.m_shape.queryPoint(N,o),m.intersectEx(this.m_tolerance,o,F,V,a),t||=m.getSegmentChanged(0)||m.getResultPointChanged(),O=m.getResultSegmentCount(0),O>0)if(this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(n,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(N,!0)),this.m_shape.splitSegmentWithIntersector(n,m,0,!0,!0),w){let e=H;for(let t=this.m_shape.getNextVertex(N);t!==H&&t!==N&&(b=this.getSegment_(t,i),e=t,null!=b&&b.isDegenerate(0));t=this.m_shape.getNextVertex(t));for(let t=N;t!==H&&(this.m_shape.setPoint(t,m.getResultPoint(),!0),t!==e);t=this.m_shape.getNextVertex(t));}else this.m_shape.setPoint(N,m.getResultPoint(),!0);m.clear()}}else{if(null===b)continue;{const e=this.m_shape.getXY(n);if(h.inflateCoords(this.m_tolerance,this.m_tolerance),h.contains(e)){if(m.pushSegment(b,V,F,T,G,k,B,D,A,U),this.m_shape.queryPoint(n,o),m.intersectEx(this.m_tolerance,o,c,d,a),t||=m.getSegmentChanged(0)||m.getResultPointChanged(),Y=m.getResultSegmentCount(0),Y>0)if(this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(N,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(n,!0)),this.m_shape.splitSegmentWithIntersector(N,m,0,!0,!0),v+=Y-1,P){let e=H;for(let t=this.m_shape.getNextVertex(n);t!==H&&t!==n&&(b=this.getSegment_(t,i),e=t,null!=b&&b.isDegenerate(0));t=this.m_shape.getNextVertex(t));for(let t=n;t!==H&&(this.m_shape.setPoint(t,m.getResultPoint(),!0),t!==e);t=this.m_shape.getNextVertex(t));}else this.m_shape.setPoint(n,m.getResultPoint(),!0);m.clear()}}}if(O+Y!==0&&0!==O){let t=!1;for(;C=this.getSegment_(n,s),null!=C&&(C.queryEnvelope(r),C.isDegenerate(this.m_tolerance));){if(!(O>1)){t=!0;break}n=_.next(),O--,e(n!==H)}if(t)break}}}return t}crackerPlaneSweep_(){return this.planesweep_()}planesweep_(){return new vt(this.m_progressTracker,this.m_bTrackChanges).sweep(this.m_shape,this.m_tolerance)}needsCrackingImpl_(){let t=!1;const s=new c(0),i=this.m_shape.queryVertexIteratorOnSelection();for(let e=i.next();e!==H;e=i.next())s.add(e);this.m_shape.sortVerticesSimpleByY(s,0,s.size()),s.add(H);const r=this.m_shape.createUserIndex(),n=this.m_shape.createUserIndex();this.m_sweepComparator=new it(this.m_shape,this.m_tolerance,!this.m_bAllowCoincident),this.m_sweepStructure.setComparator(this.m_sweepComparator);let h=null;const a=[],o=[];let m=0;for(let g=s.read(m++);g!==H;){const i=this.m_shape.getXY(g);let l=!1;do{this.progress_();let e=this.m_shape.getNextVertex(g),t=this.m_shape.getPrevVertex(g);l||=e!==H||t!==H,e===H||this.m_shape.selected(e)||(e=H),t===H||this.m_shape.selected(t)||(t=H),e!==H&&this.m_shape.compareVerticesSimpleY(g,e)<0&&(o.push(g),o.push(e)),t!==H&&this.m_shape.compareVerticesSimpleY(g,t)<0&&(o.push(t),o.push(t));const i=this.m_shape.getUserIndex(g,r);-1!==i&&(a.push(i),this.m_shape.setUserIndex(g,r,-1));const h=this.m_shape.getUserIndex(g,n);-1!==h&&(a.push(h),this.m_shape.setUserIndex(g,n,-1)),g=s.read(m++)}while(g!==H&&this.m_shape.isEqualXYPoint2D(g,i));if(!l&&(null===h&&(h=new rt(this.m_shape,this.m_tolerance)),h.setPoint(i),this.m_sweepStructure.searchUpperBound(h),h.intersectionDetected())){t=!0,this.m_bNeedsNonSimpleResult&&(e(0),this.m_nonSimpleResult=new Xe(6,-1,-1));break}let _=1===a.length&&2===o.length;const d=32;a.length>d&&J(a);let p=-1,u=-1;if(!_)for(let e=0,s=a.length;e<s;e++){const s=a[e],i=this.m_sweepStructure.getPrev(s);if(-1!==i&&-1===a.indexOf(i))if(-1===p)p=i;else{if(t=!0,!this.m_bNeedsNonSimpleResult)break;this.m_nonSimpleResult=new Xe(6,-1,-1)}const r=this.m_sweepStructure.getNext(s);if(-1!==r&&-1===a.indexOf(r))if(-1===u)u=r;else{if(t=!0,!this.m_bNeedsNonSimpleResult)break;this.m_nonSimpleResult=new Xe(6,-1,-1)}if(-1!==p&&-1!==u)break}if(t&&!this.m_bNeedsNonSimpleResult)break;if(this.m_sweepComparator.setSweepY(i.y,i.x),!_){for(let e=0,t=a.length;e<t;e++){const t=a[e];this.m_sweepStructure.deleteNode(t)}a.length=0}if(!_&&-1!==p&&-1!==u&&this.checkForIntersections_(p,u)){t=!0,this.m_bNeedsNonSimpleResult&&(this.m_nonSimpleResult=this.m_sweepComparator.getResult());break}for(let e=0,s=o.length;e<s;e+=2){const s=o[e],i=o[e+1];let h;if(_?(h=this.m_sweepStructure.replaceElementAtPosition(a[0],s,!0,!0),a.length=0,_=!1):h=this.m_sweepStructure.addElement(s),this.m_sweepComparator.intersectionDetected()){this.m_bNeedsNonSimpleResult&&(this.m_nonSimpleResult=this.m_sweepComparator.getResult()),t=!0;break}-1===this.m_shape.getUserIndex(i,r)?this.m_shape.setUserIndex(i,r,h):this.m_shape.setUserIndex(i,n,h)}if(t)break;o.length=0}return this.m_shape.removeUserIndex(r),this.m_shape.removeUserIndex(n),t}checkForIntersections_(e,t){const s=this.m_sweepStructure.getElement(e);this.m_sweepComparator.compare(this.m_sweepStructure,s,t);const i=this.m_sweepComparator.intersectionDetected();return this.m_sweepComparator.clearIntersectionDetectedFlag(),i}getSegment_(e,t){return Bt.st_getSegment(this.m_shape,e,t)}static st_getSegment(e,t,s){return e.querySegment(t,s,!1,!1)?s.get():null}dbgPrintSweepEdge(e){}dbgPrintSweepStructure(){}dbgSaveSweepStructure(e=null){}dbgCheckSweepStructure(){}progress_(e=!1){this.m_progressCounter++,!e&&4095&this.m_progressCounter||(this.m_progressCounter=0)}static st_quadTreeWillHelp_(t,s){return e(0),!1}crackAWithBMultiPath_(t,s,i){return e(0),t}constructor(e){this.m_shape=null,this.m_progressTracker=null,this.m_nonSimpleResult=new Xe,this.m_tolerance=0,this.m_sweepComparator=null,this.m_progressCounter=0,this.m_bTrackChanges=!1,this.m_bNeedsNonSimpleResult=!1,this.m_bAllowCoincident=!0,this.m_sweepStructure=new _,this.m_progressTracker=e}}function Dt(e,t,s,i,r){return new Ot(e,s,t,i,r).do_()}function At(t,s,i){if(!t.hasCurves())return!1;t.dbgVerifyCurves();const r=t.createUserIndexUninitialized(),n=new c(0),h=t.queryVertexIteratorOnSelection();for(let e=h.next();e!==H;e=h.next())n.add(e),t.setUserIndex(e,r,-1);if(0===n.size())return!1;n.add(H),t.sortVerticesSimpleByY(n,0,n.size()-1);let a=0;const o=t.getXY(n.read(a)),m=F.getNAN(),g=[];for(let e=1,l=n.size();e<l;++e){const s=n.read(e),i=s!==H?t.getXY(s):m;if(i.equals(o))continue;const h=[];for(let m=a;m<e;m++){const e=n.read(m),s=t.getPrevVertex(e);if(s!==H&&-1===t.getUserIndex(s,r)){const e=Yt(t.getXY(s),t.getSegment(s));0!==F.sqrDistance(o,e.otherPt)&&(e.vert=s,e.dir=-1,h.push(e)),t.setUserIndex(s,r,1)}const i=t.getNextVertex(e);if(i!==H&&-1===t.getUserIndex(e,r)){const s=Yt(t.getXY(i),t.getSegment(e));0!==F.sqrDistance(o,s.otherPt)&&(s.vert=e,s.dir=1,h.push(s)),t.setUserIndex(e,r,1)}}if(h.length>1){h.sort(Rt);const e=Yt(F.getNAN(),null);h.push(e);let t=0;for(let s=1,i=h.length;s<i;s++)if(!h[s].otherPt.equals(h[s-1].otherPt)){if(s-t>1&&null!==h[t].seg){let e=!1;const i=t;for(let r=t+1;r<s;r++)if(!Xt(h[i],h[r])){e=!0;break}if(e)for(let r=t;r<s&&null!==h[r].seg;r++)g.push(h[r].vert)}t=s}}a=e,o.setCoordsPoint2D(i)}for(const l of g){const i=t.getSegment(l);e(null!==i);const r=t.getXY(l),n=t.getXY(t.getNextVertex(l));if(F.distance(r,n)<3*s)t.setSegmentToIndex(t.getVertexIndex(l),null);else{const e=i.lengthToT(.5*i.calculateLength2D());t.splitSegment(l,[e],1)}}return t.removeUserIndex(r),g.length>0}function Ut(e){return d(e)}Bt.s_bForceBruteForce=!0;class Ot{constructor(e,t,s,i,r){this.m_shape=e,this.m_progressTracker=t,this.m_tolerance=s,this.m_bFilterDegenerateSegments=i,this.m_bTrackChanges=r,this.m_progressCounter=0}do_(){const e=new pe(this.m_tolerance.tolerance,this.m_tolerance.resolution),t=1e-5,s=1e-6,i=Ut(e);let r=p(e);const n=r*(1+t);r*=1+s;let h=!1;const a=this.m_shape.getTotalPointCount()+10>30?1e3:(this.m_shape.getTotalPointCount()+10)*(this.m_shape.getTotalPointCount()+10),m=this.m_shape.hasPointFeatures();for(let g=0;;g++){this.m_shape.dbgCheckSelection(),g>a&&o("crack_and_cluster_iteration_exceeded"),this.m_shape.dbgVerifyMonotone();let e=-1;0===g&&(e=this.firstCrack_(),h||=e>0);const t=this.cluster_(i);if(this.m_shape.dbgVerifyMonotone(),h||=t,this.m_bFilterDegenerateSegments){const e=0!==this.m_shape.filterClosePoints(i,!0,!1,this.m_bTrackChanges,H);h||=e,this.m_shape.dbgVerifyMonotone()}const s=this.m_shape.snapControlPointsOnSelection(n*n);h||=s,this.m_shape.dbgCheckSelection();let l=!1;if((0===g&&-1===e||m||Gt(!0,this.m_shape,r,null,this.m_progressTracker))&&(l=this.crack_(n),h||=l,this.m_shape.dbgVerifyMonotone()),!l&&!At(this.m_shape,i,this.m_progressTracker)){this.m_shape.dbgVerifyMonotone();break}}return h&&(ds(this.m_shape),_s(this.m_shape)),h}cluster_(e){return ht(this.m_shape,e,H,this.m_bTrackChanges,this.m_progressTracker)}crack_(e){return Ft(this.m_shape,e,this.m_bTrackChanges,this.m_progressTracker)}static fixCurveTwoPointLoops(t,s,i){return e(0),!1}firstCrack_(){const e=this.m_shape.getEnvelope2D(this.m_progressTracker),t=T(null,e,!0).total();if(4*t<this.m_tolerance.total()){let e=!1;const s=1.1*t,i=t,r=this.cluster_(s);e||=r;let n=0;this.m_bFilterDegenerateSegments&&(n=this.m_shape.filterClosePoints(0,!0,!1,this.m_bTrackChanges,H));const h=this.crack_(i);return e||=h,e?1:n?2:0}return-1}progress_(e=!1){this.m_progressCounter++,!e&&4095&this.m_progressCounter||(this.m_progressCounter=0)}}function Yt(e,t){return{otherPt:e,seg:t}}function Xt(e,t){if(null===e.seg)return null===t.seg;if(null===t.seg)return!1;const s=e.seg.getGeometryType();if(s!==t.seg.getGeometryType())return!1;if(s===i.enumBezier){const s=e.seg,i=t.seg;let r=s.getControlPoint1(),n=s.getControlPoint2();-1===e.dir&&(n=q(r,r=n));let h=i.getControlPoint1(),a=i.getControlPoint2();return-1===t.dir&&(a=q(h,h=a)),r.equals(h)&&n.equals(a)}if(s===i.enumRationalBezier2){const s=e.seg,i=t.seg,r=s.getControlPoint1(),n=i.getControlPoint1();if(!r.equals(n))return!1;const h=new Array(3);s.queryWeights(h),-1===e.dir&&(h[2]=q(h[0],h[0]=h[2]));const a=new Array(3);return i.queryWeights(a),-1===t.dir&&(a[2]=q(a[0],a[0]=a[2])),h[0]===a[0]&&h[1]===a[1]&&h[2]===a[2]}o("")}function qt(e,t){if(null===e.seg||null===t.seg)return null!==e.seg?-1:null!==t.seg?1:0;const s=e.seg.getGeometryType(),i=t.seg.getGeometryType();return s<i?-1:s>i?1:0}function Rt(e,t){const s=e.otherPt.compare(t.otherPt);return 0!==s?s:qt(e,t)}function Mt(e,t,s){if(null!=t){if("object"!=typeof t&&"function"!=typeof t)throw new TypeError("Object expected.");var i,r;if(void 0===i){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");i=t[Symbol.dispose]}if("function"!=typeof i)throw new TypeError("Object not disposable.");r&&(i=function(){try{r.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:t,dispose:i,async:s})}return t}var Lt="function"==typeof SuppressedError?SuppressedError:function(e,t,s){var i=new Error(s);return i.name="SuppressedError",i.error=e,i.suppressed=t,i};function zt(e){function t(t){e.error=e.hasError?new Lt(t,e.error,"An error was suppressed during disposal."):t,e.hasError=!0}function s(){for(;e.stack.length;){var i=e.stack.pop();try{var r=i.dispose&&i.dispose.call(i.value);if(i.async)return Promise.resolve(r).then(s,(function(e){return t(e),s()}))}catch(n){t(n)}}if(e.hasError)throw e.error}return s()}function Wt(e,t,s,i,r){const n=new Kt(r);return n.m_shape=e,n.m_geometry=t,n.m_sortedVertices=s,n.m_bFixSelfTangency=i,n.fixRingOrientation_()}class Qt{getDirection_(e){return this.m_shape.getNextVertex(this.getEnd1(e))===this.getEnd2(e)}getEnd_(e){const t=this.getEnd1(e),s=this.getEnd2(e);return this.m_shape.getNextVertex(t)===s?s:t}constructor(e){this.m_end1Nodes=[],this.m_end2Nodes=[],this.m_directions=[],this.m_shape=e,this.m_firstFree=-1}getSegment(e){return this.m_shape.getSegment(this.getStart(e))}isBottomUp(t){let s=this.getEnd1(t),i=this.getEnd2(t);this.m_shape.getPrevVertex(s)===i&&(i=q(s,s=i));const r=F.getNAN(),n=F.getNAN();return this.m_shape.queryXY(s,r),this.m_shape.queryXY(i,n),e(!r.equals(n)),r.y<n.y}getStart(e){const t=this.getEnd1(e),s=this.getEnd2(e);return this.m_shape.getNextVertex(t)===s?t:s}getEnd1(e){return this.m_end1Nodes[e]}getEnd2(e){return this.m_end2Nodes[e]}freeEdge(e){this.m_end1Nodes[e]=this.m_firstFree,this.m_firstFree=e}newEdge(e){if(-1!==this.m_firstFree){const t=this.m_firstFree;return this.m_firstFree=this.m_end1Nodes[t],this.m_end1Nodes[t]=e,this.m_end2Nodes[t]=this.m_shape.getNextVertex(e),t}const t=this.m_end1Nodes.length;return this.m_end1Nodes.push(e),this.m_end2Nodes.push(this.m_shape.getNextVertex(e)),t}getShape(){return this.m_shape}getPath(e){return this.m_shape.getPathFromVertex(this.getEnd1(e))}}let Zt=class extends de{constructor(e){super(),this.m_line1=new ge,this.m_line2=new ge,this.m_leftElm=-1,this.m_leftx=0,this.m_seg1=null,this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_edges;let n;if(this.m_leftElm===t)n=this.m_leftx;else{if(this.m_seg1=r.getSegment(t),this.m_seg1)n=this.m_seg1.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(t),this.m_line1,!0),this.m_seg1=this.m_line1,n=this.m_line1.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0)}this.m_leftx=n,this.m_leftElm=t}let h,a=r.getSegment(i);if(a)h=a.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(i),this.m_line2,!0),a=this.m_line2,h=this.m_line2.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0)}if(n===h){const e=r.isBottomUp(t),s=r.isBottomUp(i),o=e?this.m_seg1.getEndY():this.m_seg1.getStartY(),m=s?a.getEndY():a.getStartY(),g=Math.min(o,m);let l=.5*(g+this.m_helper.m_yScanline);l===this.m_helper.m_yScanline&&(l=g),n=this.m_seg1.intersectionOfYMonotonicWithAxisX(l,0),h=a.intersectionOfYMonotonicWithAxisX(l,0),n===h&&Se("")}return n<h?-1:n>h?1:0}reset(){this.m_leftElm=-1}};class jt{constructor(e){this.m_node=-1,this.m_index=0,this.m_sortedVertices=e.m_sortedVertices,this.m_sortedVerticesArray=e.m_sortedVerticesArray,this.m_sortedVertices&&(this.m_node=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList()))}next(){if(this.m_sortedVertices){const e=this.m_node;if(-1===e)return H;const t=this.m_sortedVertices.getData(e);return this.m_node=this.m_sortedVertices.getNext(e),t}if(this.m_index<this.m_sortedVerticesArray.size()){const e=this.m_sortedVerticesArray.read(this.m_index);return this.m_index++,e}return H}}class Kt{constructor(e){this.m_edges=null,this.m_shape=null,this.m_AET=new _,this.m_yScanline=0,this.m_geometry=H,this.m_unknownRingOrientationCount=-1,this.m_sortedVertices=null,this.m_sortedVerticesArray=null,this.m_unknownNodes=[],this.m_node1UserIndex=-1,this.m_node2UserIndex=-1,this.m_pathOrientationIndex=-1,this.m_pathParentageIndex=-1,this.m_pathParentsIndex=-1,this.m_progressCounter=0,this.m_bFixSelfTangency=!1,this.m_progressTracker=e,this.m_AET.disableBalancing(),this.m_sweepComparator=new Zt(this),this.m_AET.setComparator(this.m_sweepComparator)}fixRingOrientation_(){const e=this.fixRingOrientationImplMain_();return-1===this.m_pathOrientationIndex||this.fixRingOrientationImplSimplify_(),e}fixRingOrientationForMp2sp_(){return e(0),0}processBunchForRingOrientationTest_(e){return this.processBunchForRingOrientationTestOddEven_(e)}processBunchForRingOrientationTestOddEven_(t){let s=!1;if(this.m_edges||(this.m_edges=new Qt(this.m_shape)),this.m_unknownNodes.length=0,this.processBunchForRingOrientationRemoveEdges_(t),!this.m_AET.isAutoBalancing()){let e=0;for(let s=0,i=t.length;s<i;s++){-1!==t[s]&&e++}(e>10||this.m_AET.getMaxDepthEver()>4)&&this.m_AET.enableBalancing()}for(let e=0,i=t.length;e<i;e++){const s=t[e];s!==H&&this.insertEdge_(s,-1)}for(let i=0;i<this.m_unknownNodes.length&&this.m_unknownRingOrientationCount>0;i++){const t=this.m_unknownNodes[i],r=this.m_AET.getElement(t),n=this.m_edges.getPath(r),h=this.m_shape.getPathUserIndex(n,this.m_pathOrientationIndex);let a=H;if(0===h){let i=this.m_AET.getPrev(t),r=t,n=!1;for(;i!==_.st_nullNode();){const e=this.m_AET.getElement(i),t=this.m_edges.getPath(e);if(0!==this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){a=t;break}r=i,i=this.m_AET.getPrev(i)}if(i===_.st_nullNode())n=!0,i=r;else{const e=this.m_AET.getElement(i);n=this.m_edges.isBottomUp(e),i=this.m_AET.getNext(i),n=!n}do{const t=this.m_AET.getElement(i),h=this.m_edges.getPath(t);if(0===this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex)){if(n!==this.m_edges.isBottomUp(t)){const e=this.m_shape.getFirstVertex(h);this.m_shape.reverseRingInternal(e),this.m_shape.setLastVertex(h,this.m_shape.getPrevVertex(e)),s=!0}if(this.m_shape.setPathUserIndex(h,this.m_pathOrientationIndex,n?3:2),!n){let t=this.m_shape.getPathUserIndex(a,this.m_pathOrientationIndex);2===t?(a=this.m_shape.getPathUserIndex(a,this.m_pathParentsIndex),t=this.m_shape.getPathUserIndex(a,this.m_pathOrientationIndex),e(3===t)):e(3===t);const s=this.m_shape.getPathUserIndex(a,this.m_pathParentageIndex);this.m_shape.setPathUserIndex(a,this.m_pathParentageIndex,h),this.m_shape.setPathUserIndex(h,this.m_pathParentageIndex,s),this.m_shape.setPathUserIndex(h,this.m_pathParentsIndex,a)}if(this.m_unknownRingOrientationCount--,!this.m_unknownRingOrientationCount)return s}a=h,r=i,i=this.m_AET.getNext(i),n=!n}while(r!==t)}}return s}processBunchForRingOrientationRemoveEdges_(e){for(let t=0,s=e.length;t<s;t++){const s=e[t],i=this.m_shape.getUserIndex(s,this.m_node1UserIndex),r=this.m_shape.getUserIndex(s,this.m_node2UserIndex);if(-1!==i){const e=this.m_AET.getElement(i);this.m_edges.freeEdge(e),this.m_shape.setUserIndex(s,this.m_node1UserIndex,-1)}if(-1!==r){const e=this.m_AET.getElement(r);this.m_edges.freeEdge(e),this.m_shape.setUserIndex(s,this.m_node2UserIndex,-1)}let n=-1;-1!==i&&-1!==r?(this.m_AET.deleteNode(i),this.m_AET.deleteNode(r),e[t]=H):n=-1!==i?i:r,-1!==n&&(this.insertEdge_(s,n)||this.m_AET.deleteNode(n),e[t]=H)}}dbgVerifyRingOrientation_(){}insertEdge_(e,t){const s=F.getNAN(),i=F.getNAN();this.m_shape.queryXY(e,s);const r=this.m_shape.getNextVertex(e);this.m_shape.queryXY(r,i);let n=!1;if(s.y<i.y){n=!0;const s=this.m_edges.newEdge(e);let i;-1===t?i=this.m_AET.addElement(s):(i=t,this.m_AET.setElement(i,s));-1===this.m_shape.getUserIndex(r,this.m_node1UserIndex)?this.m_shape.setUserIndex(r,this.m_node1UserIndex,i):this.m_shape.setUserIndex(r,this.m_node2UserIndex,i);const h=this.m_shape.getPathFromVertex(e);0===this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex)&&this.m_unknownNodes.push(i)}const h=this.m_shape.getPrevVertex(e);if(this.m_shape.queryXY(h,i),s.y<i.y){n=!0;const s=this.m_edges.newEdge(h);let i;-1===t?i=this.m_AET.addElement(s):(i=t,this.m_AET.setElement(i,s));-1===this.m_shape.getUserIndex(h,this.m_node1UserIndex)?this.m_shape.setUserIndex(h,this.m_node1UserIndex,i):this.m_shape.setUserIndex(h,this.m_node2UserIndex,i);const r=this.m_shape.getPathFromVertex(e);0===this.m_shape.getPathUserIndex(r,this.m_pathOrientationIndex)&&this.m_unknownNodes.push(i)}return n}fixRingSelfTangency_(){return e(0),!1}progress_(e=!1){}fixRingOrientationImplMain_(){const e={stack:[],error:void 0,hasError:!1};try{let t,s=!1;const i=Mt(e,Fe((()=>{this.m_sortedVerticesArray=null})),!1);if(null===this.m_sortedVertices){const e=this.m_shape.getPointCount(this.m_geometry);t=new c(0);for(let s=this.m_shape.getFirstPath(this.m_geometry);s!==H;s=this.m_shape.getNextPath(s)){let e=this.m_shape.getFirstVertex(s);for(let i=0,r=this.m_shape.getPathSize(s);i<r;i++)t.add(e),e=this.m_shape.getNextVertex(e)}this.m_shape.sortVerticesSimpleByY(t,0,e),this.progress_(!0),this.m_sortedVerticesArray=t}else i.bForget=!0;if(this.m_bFixSelfTangency&&(s=this.fixRingSelfTangency_()),1===this.m_shape.getPathCount(this.m_geometry)){const e=this.m_shape.getFirstPath(this.m_geometry),t=this.m_shape.getRingArea(e);if(this.m_shape.setExterior(e,!0),t<0){const t=this.m_shape.getFirstVertex(e);return _s(this.m_shape),this.m_shape.reverseRingInternal(t),_s(this.m_shape),this.m_shape.setLastVertex(e,this.m_shape.getPrevVertex(t)),!0}return!1}this.m_shape.dbgVerifyCurves(),this.m_pathOrientationIndex=this.m_shape.createPathUserIndex(),this.m_pathParentageIndex=this.m_shape.createPathUserIndex(),this.m_pathParentsIndex=this.m_shape.createPathUserIndex();for(let e=this.m_shape.getFirstPath(this.m_geometry);e!==H;e=this.m_shape.getNextPath(e))this.m_shape.setPathUserIndex(e,this.m_pathOrientationIndex,0),this.m_shape.setPathUserIndex(e,this.m_pathParentageIndex,-1),this.m_shape.setPathUserIndex(e,this.m_pathParentsIndex,-1);const r=[];this.m_yScanline=Number.NaN;const n=F.getNAN();this.m_unknownRingOrientationCount=this.m_shape.getPathCount(this.m_geometry),this.m_node1UserIndex=this.m_shape.createUserIndexUninitialized(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,this.m_node1UserIndex,-1),this.m_node2UserIndex=this.m_shape.createUserIndexUninitialized(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,this.m_node2UserIndex,-1);const h=new jt(this);for(let e=h.next();e!==H&&(this.progress_(),this.m_shape.queryXY(e,n),n.y!==this.m_yScanline&&r.length&&(s=this.processBunchForRingOrientationTest_(r)||s,this.m_sweepComparator.reset(),r.length=0),r.push(e),this.m_yScanline=n.y,0!==this.m_unknownRingOrientationCount);e=h.next());return this.m_unknownRingOrientationCount>0&&(s=this.processBunchForRingOrientationTest_(r)||s,r.length=0),this.m_shape.removeUserIndex(this.m_node1UserIndex),this.m_shape.removeUserIndex(this.m_node2UserIndex),this.dbgVerifyRingOrientation_(),s}catch(t){e.error=t,e.hasError=!0}finally{zt(e)}}fixRingOrientationImplSimplify_(){const e=[];for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==H;)if(this.progress_(),3===this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){this.m_shape.setExterior(t,!0);for(let r=this.m_shape.getPathUserIndex(t,this.m_pathParentageIndex);r!==H;){const s=this.m_shape.getPathUserIndex(r,this.m_pathParentageIndex);e.push(r),this.m_shape.setExterior(r,!1),this.m_shape.setPathUserIndex(r,this.m_pathParentageIndex,t),r=s}let s=t,i=e.length;for(let e=this.m_shape.getNextPath(t);i>0&&e!==H;e=this.m_shape.getNextPath(e),--i){if(this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex)!==t){s=H;break}s=e}if(0!==i){s=t;for(let t=0,i=e.length;t<i;t++){const i=e[t];this.m_shape.setPathUserIndex(i,this.m_pathParentageIndex,Ce),this.m_shape.movePath(this.m_geometry,this.m_shape.getNextPath(s),i),s=i}}e.length=0,t=this.m_shape.getNextPath(s)}else t=this.m_shape.getNextPath(t);this.m_shape.removePathUserIndex(this.m_pathOrientationIndex),this.m_shape.removePathUserIndex(this.m_pathParentageIndex),this.m_shape.removePathUserIndex(this.m_pathParentsIndex)}fixRingOrientationImplMp2sp_(){return e(0),0}}function Jt(e,t,s,i,r,n){const h=new $t(n);return h.m_shape=e,h.m_geometry=t,h.m_knownSimpleResult=s,h.m_bFixSelfTangency=i,h.m_polylineDegeneracies=r,h.m_bHasSegmentParentage=e.hasSegmentParentage(),h.m_bHasSegments=e.hasCurves(),h.simplify_()}class $t{constructor(e){this.m_shape=null,this.m_geometry=H,this.m_sortedVertices=new l,this.m_bunchEdgeEndPoints=[],this.m_bunchEdgeCenterPoints=[],this.m_bunchEdgeIndices=[],this.m_knownSimpleResult=-1,this.m_sortedVerticesListIndex=-1,this.m_polylineDegeneracies=H,this.m_userIndexSortedIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=-1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=-1,this.m_progressCounter=0,this.m_bFixSelfTangency=!1,this.m_bHasSegmentParentage=!1,this.m_bHasSegments=!1,this.m_progressTracker=e}compareAngles_(e,t){if(this.m_bHasSegments)return this.compareAnglesCurves_(e,t);const s=this.m_bunchEdgeEndPoints[e],i=new F;this.m_shape.queryXY(s,i);const r=new F,n=this.m_bunchEdgeEndPoints[t];if(this.m_shape.queryXY(n,r),i.equals(r))return 0;const h=this.m_bunchEdgeCenterPoints[e],a=new F;this.m_shape.queryXY(h,a);const o=this.m_bunchEdgeCenterPoints[t],m=new F;this.m_shape.queryXY(o,m);const g=new F;g.setSub(i,a);const l=new F;l.setSub(r,m),(g.isZero()||l.isZero())&&Se("");return F.compareVectors(g,l)}compareAnglesCurves_(e,t){const s=this.m_bunchEdgeEndPoints[e],i=this.m_bunchEdgeEndPoints[t],r=this.m_bunchEdgeCenterPoints[e],n=this.m_bunchEdgeCenterPoints[t],h=this.m_shape.getNextVertex(r)===s,a=this.m_shape.getNextVertex(n)===i,o=new G,m=new F;h?(this.m_shape.querySegment(r,o,!1,!0),m.assign(o.get().getTangent(0))):(this.m_shape.querySegment(s,o,!1,!0),m.assign(o.get().getTangent(1)),m.negateThis());const g=new F;a?(this.m_shape.querySegment(n,o,!1,!0),g.assign(o.get().getTangent(0))):(this.m_shape.querySegment(i,o,!1,!0),g.assign(o.get().getTangent(1)),g.negateThis()),(m.isZero()||g.isZero())&&Se("");return F.compareVectors(m,g)}beforeRemoveVertex_(e,t){const s=this.m_shape.getUserIndex(e,this.m_userIndexSortedIndexToVertex);if(this.m_nextVertexToProcess===s&&(this.m_nextVertexToProcess=this.m_sortedVertices.getNext(this.m_nextVertexToProcess)),this.m_firstCoincidentVertex===s&&(this.m_firstCoincidentVertex=this.m_sortedVertices.getNext(this.m_firstCoincidentVertex)),this.m_sortedVertices.deleteElement(this.m_sortedVerticesListIndex,s),this.removeAngleSortInfo_(e),t){const t=this.m_shape.getPathFromVertex(e);if(t!==H){if(this.m_shape.getFirstVertex(t)===e){const s=this.m_shape.getNextVertex(e);if(s!==e){if(this.m_shape.getPathFromVertex(s)===t)return void this.m_shape.setFirstVertex(t,s);{const s=this.m_shape.getPrevVertex(e);if(s!==e){if(this.m_shape.getPathFromVertex(s)===t)return void this.m_shape.setFirstVertex(t,s)}}}this.m_shape.setFirstVertex(t,H),this.m_shape.setLastVertex(t,H)}}}}processBunch_(){let e=!1;const t=new F(0,0);for(;;){this.m_bunchEdgeEndPoints.length=0,this.m_bunchEdgeCenterPoints.length=0,this.m_bunchEdgeIndices.length=0;let s=this.m_firstCoincidentVertex,i=0,r=!0;for(;s!==this.m_nextVertexToProcess;){const e=this.m_sortedVertices.getData(s);r&&(this.m_shape.queryXY(e,t),r=!1);const n=this.m_shape.getPrevVertex(e),h=this.m_shape.getNextVertex(e);this.m_shape.getUserIndex(n,this.m_userIndexSortedAngleIndexToVertex)!==Ce&&(this.m_bunchEdgeEndPoints.push(n),this.m_shape.setUserIndex(n,this.m_userIndexSortedAngleIndexToVertex,Ce),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++));this.m_shape.getUserIndex(h,this.m_userIndexSortedAngleIndexToVertex)!==Ce&&(this.m_bunchEdgeEndPoints.push(h),this.m_shape.setUserIndex(h,this.m_userIndexSortedAngleIndexToVertex,Ce),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++)),s=this.m_sortedVertices.getNext(s)}if(this.m_bunchEdgeEndPoints.length<2){1===this.m_bunchEdgeEndPoints.length&&this.m_shape.setUserIndex(this.m_bunchEdgeEndPoints[0],this.m_userIndexSortedAngleIndexToVertex,-1);break}this.m_bunchEdgeIndices.sort(((e,t)=>this.compareAngles_(e,t)));for(let e=0,t=this.m_bunchEdgeIndices.length;e<t;e++){const t=this.m_bunchEdgeIndices[e],s=this.m_bunchEdgeEndPoints[t];this.m_shape.setUserIndex(s,this.m_userIndexSortedAngleIndexToVertex,e)}const n=this.processCrossOvers_(t);for(let e=0,t=this.m_bunchEdgeIndices.length;e<t;e++){const t=this.m_bunchEdgeIndices[e];if(-1===t)continue;const s=this.m_bunchEdgeEndPoints[t];this.m_shape.setUserIndex(s,this.m_userIndexSortedAngleIndexToVertex,-1)}if(!n)break;e=!0}return e}processCrossOvers_(e){let t=!1,s=!0;for(;s;){s=!1;let i=0;-1===this.m_bunchEdgeIndices[i]&&(i=this.getNextEdgeIndex_(i));let r=this.getNextEdgeIndex_(i);for(let n=0,h=this.m_bunchEdgeIndices.length;n<h&&-1!==i&&-1!==r&&i!==r;n++){const n=this.m_bunchEdgeIndices[i],h=this.m_bunchEdgeIndices[r],a=this.m_bunchEdgeEndPoints[n],o=this.m_bunchEdgeEndPoints[h];let m=this.m_shape.getNextVertex(a),g=!1;this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(a),g=!0);let l=this.m_shape.getNextVertex(o),_=!1;this.m_shape.isEqualXYPoint2D(l,e)||(l=this.m_shape.getPrevVertex(o),_=!0);const d=g?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=_?this.m_shape.getPrevVertex(l):this.m_shape.getNextVertex(l);let u=!1;(this.removeSpike_(m)||this.removeSpike_(l)||this.removeSpike_(a)||this.removeSpike_(o)||this.removeSpike_(d)||this.removeSpike_(p))&&(u=!0),m!==l&&(!u&&this.m_shape.isEqualXY(a,o)&&(u=this.resolveOverlap_(g,_,m,a,l,o)),!u&&this.m_shape.isEqualXY(d,p)&&(u=this.resolveOverlap_(!g,!_,m,d,l,p)),!u&&this.m_shape.isEqualXY(a,p)&&(u=this.resolveOverlap_(g,!_,m,a,l,p)),!u&&this.m_shape.isEqualXY(d,o)&&(u=this.resolveOverlap_(!g,_,m,d,l,o))),u&&(t=!0),s||=u,i=u?this.getNextEdgeIndex_(i):r,r=this.getNextEdgeIndex_(i)}}if(!t){let s=0;-1===this.m_bunchEdgeIndices[s]&&(s=this.getNextEdgeIndex_(s));let i=this.getNextEdgeIndex_(s);for(let r=0,n=this.m_bunchEdgeIndices.length;r<n&&-1!==s&&-1!==i&&s!==i;r++){const r=this.m_bunchEdgeIndices[s],n=this.m_bunchEdgeIndices[i],h=this.m_bunchEdgeEndPoints[r],a=this.m_bunchEdgeEndPoints[n];let o=this.m_shape.getNextVertex(h);this.m_shape.isEqualXYPoint2D(o,e)||(o=this.m_shape.getPrevVertex(h));let m=this.m_shape.getNextVertex(a);this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(a));const g=this.getDirection_(o,h),l=this.getDirection_(m,a),_=g?this.m_shape.getPrevVertex(o):this.m_shape.getNextVertex(o),d=l?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=this.detectAndResolveCrossOver_(g,l,h,o,_,a,m,d);1!==p?0===p?(s=this.getNextEdgeIndex_(s),i=this.getNextEdgeIndex_(s)):(s=this.getPrevEdgeIndex_(s),i=this.getNextEdgeIndex_(s)):t=!0}}return t}simplify_(){if(this.m_shape.getGeometryType(this.m_geometry)===i.enumPolygon&&1===this.m_shape.getFillRule(this.m_geometry)){new Qs(this.m_progressTracker).planarSimplifyNoCrackingAndCluster(this.m_bFixSelfTangency,this.m_shape,this.m_geometry,0)}let e=!1;this.m_userIndexSortedIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=this.m_shape.createUserIndexUninitialized();const t=this.m_shape.getPointCount(this.m_geometry),s=new c(0);this.m_shape.dbgVerifyMonotone();for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==H;i=this.m_shape.getNextPath(i)){let e=this.m_shape.getFirstVertex(i);for(let t=0,r=this.m_shape.getPathSize(i);t<r;t++)this.m_shape.setUserIndex(e,this.m_userIndexSortedAngleIndexToVertex,-1),s.add(e),e=this.m_shape.getNextVertex(e)}this.m_shape.sortVerticesSimpleByY(s,0,t),this.progress_(!0),this.m_userIndexSortedIndexToVertex=this.m_shape.createUserIndexUninitialized(),this.m_sortedVertices.reserveNodes(t),this.m_sortedVerticesListIndex=this.m_sortedVertices.createList(0);for(let i=0;i<t;i++){const e=s.read(i),t=this.m_sortedVertices.addElement(this.m_sortedVerticesListIndex,e);this.m_shape.setUserIndex(e,this.m_userIndexSortedIndexToVertex,t)}this.m_nextVertexToProcess=-1,this.cleanupSpikes_()&&(e=!0);let r=0,n=!1;do{n=!1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=this.m_sortedVertices.getFirst(this.m_sortedVerticesListIndex);const t=new F(0,0);this.m_firstCoincidentVertex!==l.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(this.m_firstCoincidentVertex),t);let s=0,i=this.m_firstCoincidentVertex;for(;i!==l.st_nullNode()&&(i=this.m_sortedVertices.getNext(i),i!==l.st_nullNode());){this.progress_();const e=this.m_sortedVertices.getData(i),r=F.getNAN();if(this.m_shape.queryXY(e,r),t.equals(r))s++;else{if(s>0){this.m_nextVertexToProcess=i;const e=this.processBunch_();i=this.m_nextVertexToProcess,i!==l.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(i),r),e&&(n=!0)}t.setCoordsPoint2D(r),this.m_firstCoincidentVertex=i,s=0}}if(this.m_nextVertexToProcess=-1,s>0){this.processBunch_()&&(n=!0)}r++>10&&o(""),n&&this.fixOrphanVertices_(),this.cleanupSpikes_()&&(n=!0),e||=n}while(n);return this.m_shape.dbgVerifyMonotone(),this.m_shape.dbgVerifyCurves(),this.m_shape.removeUserIndex(this.m_userIndexSortedIndexToVertex),this.m_shape.removeUserIndex(this.m_userIndexSortedAngleIndexToVertex),_s(this.m_shape),e=Wt(this.m_shape,this.m_geometry,this.m_sortedVertices,this.m_bFixSelfTangency,this.m_progressTracker)||e,this.m_shape.dbgVerifyCurves(),_s(this.m_shape),e}getDirection_(e,t){return this.m_shape.getNextVertex(t)!==e}detectAndResolveCrossOver_(e,t,s,i,r,n,h,a){if(i===h)return this.removeAngleSortInfo_(s),this.removeAngleSortInfo_(n),-1;const o=this.m_shape.getUserIndex(s,this.m_userIndexSortedAngleIndexToVertex),m=this.m_shape.getUserIndex(r,this.m_userIndexSortedAngleIndexToVertex),g=this.m_shape.getUserIndex(n,this.m_userIndexSortedAngleIndexToVertex),l=this.m_shape.getUserIndex(a,this.m_userIndexSortedAngleIndexToVertex),_=new Array(8),d=new Array(4);_[0]=0,d[0]=o,_[1]=0,d[1]=m,_[2]=1,d[2]=g,_[3]=1,d[3]=l;for(let u=1;u<4;u++){const e=d[u],t=_[u];let s=u-1;for(;s>=0&&d[s]>e;)d[s+1]=d[s],_[s+1]=_[s],s--;d[s+1]=e,_[s+1]=t}let p=0;if(_[0]&&(p|=1),_[1]&&(p|=2),_[2]&&(p|=4),_[3]&&(p|=8),5!==p&&10!==p)return 0;if(e!==t&&(a=q(n,n=a)),e)this.m_shape.setNextVertex(a,i),this.m_shape.setPrevVertex(i,a),this.m_shape.setNextVertex(r,h),this.m_shape.setPrevVertex(h,r),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(h,!0));else{if(this.m_shape.setPrevVertex(a,i),this.m_shape.setNextVertex(i,a),this.m_shape.setPrevVertex(r,h),this.m_shape.setNextVertex(h,r),this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(i),t=this.m_shape.getSegmentParentage(h);this.m_shape.setSegmentParentageAndBreak(i,t,!0),this.m_shape.setSegmentParentageAndBreak(h,e,!0)}if(this.m_bHasSegments){const e=this.m_shape.getVertexIndex(i),t=this.m_shape.getVertexIndex(h),s=this.m_shape.getSegmentFromIndex(e);this.m_shape.setSegmentToIndex(e,null);const r=this.m_shape.getSegmentFromIndex(t);this.m_shape.setSegmentToIndex(t,null),this.m_shape.setSegmentToIndex(e,r),this.m_shape.setSegmentToIndex(t,s)}}return 1}resolveOverlap_(e,t,s,i,r,n){return this.resolveOverlapOddEven_(e,t,s,i,r,n)}resolveOverlapOddEven_(e,t,s,i,r,n){if(e!==t){e||(r=q(s,s=r),n=q(i,i=n));const t=this.m_shape.getNextVertex(r),h=this.m_shape.getNextVertex(s);if(this.m_shape.setNextVertex(s,t),this.m_shape.setPrevVertex(t,s),this.m_shape.setNextVertex(r,h),this.m_shape.setPrevVertex(h,r),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(s),t=this.m_shape.getVertexIndex(r),i=this.m_shape.getSegmentFromIndex(e);this.m_shape.setSegmentToIndex(e,null);const n=this.m_shape.getSegmentFromIndex(t);this.m_shape.setSegmentToIndex(t,null),this.m_shape.setSegmentToIndex(e,n),this.m_shape.setSegmentToIndex(t,i)}if(this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(s),t=this.m_shape.getSegmentParentage(r);this.m_shape.setSegmentParentageAndBreak(s,t,!0),this.m_shape.setSegmentParentageAndBreak(r,e,!0),this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(n,!0)}this.removeSpike_(r)}else{const h=e?s:i,a=t?r:n,o=e?i:s,m=t?n:r;let g=null;if(this.m_bHasSegments){const e=this.m_shape.getVertexIndex(m);g=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null);const t=this.m_shape.getVertexIndex(a);this.m_shape.setSegmentToIndex(t,null);const s=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(s,null)}let l=-1;this.m_bHasSegmentParentage&&(l=this.m_shape.getSegmentParentage(m));let _=!1;this.m_shape.setNextVertex(h,a),this.m_shape.setNextVertex(a,h),this.m_shape.setPrevVertex(o,m),this.m_shape.setPrevVertex(m,o);let d=m;for(;d!==a;){const e=this.m_shape.getPrevVertex(d),t=this.m_shape.getNextVertex(d);if(this.m_shape.setPrevVertex(d,t),this.m_shape.setNextVertex(d,e),_||=d===h,this.m_bHasSegments&&d!==h){const e=this.m_shape.getVertexIndex(t),s=g;g=this.m_shape.getSegmentFromIndex(e),null!==s&&s.reverse(),this.m_shape.setSegmentToIndex(e,s)}if(this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(t);this.m_shape.setSegmentParentagePreserveBreak(t,l),l=e}d=t}let p=null;if(!_){const e=this.m_shape.getPrevVertex(a),t=this.m_shape.getNextVertex(a);if(this.m_shape.setPrevVertex(a,t),this.m_shape.setNextVertex(a,e),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(a);p=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null)}}let u=-1,c=-1;if(this.m_bHasSegmentParentage&&(u=_?this.m_shape.getSegmentParentage(h):this.m_shape.getSegmentParentage(a),c=this.m_shape.getSegmentParentage(o)),this.transferVertexData_(a,h),this.beforeRemoveVertex_(a,!0),this.m_shape.removeVertexInternal(a,!0),this.removeAngleSortInfo_(h),this.transferVertexData_(m,o),this.beforeRemoveVertex_(m,!0),this.m_shape.removeVertexInternal(m,!0),this.removeAngleSortInfo_(o),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageAndBreak(h,u,!0),this.m_shape.setSegmentParentageAndBreak(o,c,!0)),p){const e=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(e,p)}}return!0}cleanupSpikes_(){_s(this.m_shape);let e=!1;for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==H;){const s=this.m_shape.getNextPath(t);let i=this.m_shape.getFirstVertex(t);for(let r=0,n=this.m_shape.getPathSize(t);r<n&&n>1;){this.progress_();const{v:s,bModified:h}=this.checkAndCleanupSpike_(t,i);if(s===H)break;h?(e=!0,i=s,r=0,n=this.m_shape.getPathSize(t)):(i=s,r++)}t=s}return _s(this.m_shape),e}checkAndCleanupSpike_(e,t){const s={v:H,bModified:!1};let i=this.m_shape.getPrevVertex(t),r=this.m_shape.getNextVertex(t),n=H,h=H;for(;this.m_shape.isEqualXY(i,r)&&(n=i,h=r,r!==t);)i=this.m_shape.getPrevVertex(i),r=this.m_shape.getNextVertex(r);if(n===H)return s.v=r,s;s.bModified=!0;for(let a=this.m_shape.getNextVertex(n);this.beforeRemoveVertex_(a,!1),a!==h;a=this.m_shape.getNextVertex(a));if(n===t)return this.m_polylineDegeneracies!==H?this.m_shape.movePath(this.m_polylineDegeneracies,H,e):this.m_shape.removePath(e),s.v=H,s;{const e=this.m_shape.peelALoopIntoAPath(n,h);this.m_polylineDegeneracies!==H?this.m_shape.movePath(this.m_polylineDegeneracies,H,e):this.m_shape.removePath(e)}return s.v=n,s}removeSpike_(e){let t=this.m_shape.getPrevVertex(e),s=this.m_shape.getNextVertex(e),i=H,r=H;for(;this.m_shape.isEqualXY(t,s)&&(i=t,r=s,s!==e);)t=this.m_shape.getPrevVertex(t),s=this.m_shape.getNextVertex(s);if(i===H)return!1;if(this.m_shape.peelALoop(i,r),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(r,!0)),this.removeAngleSortInfo_(i),this.m_polylineDegeneracies===H)for(let n=this.m_shape.getNextVertex(r);;){const e=this.m_shape.getNextVertex(n);if(this.removeAngleSortInfo_(n),this.beforeRemoveVertex_(n,!0),this.m_shape.setSegmentToIndex(this.m_shape.getVertexIndex(n),null),this.m_shape.removeVertexInternal(n,!1),n===r)break;n=e}else{for(let t=r;;){const e=this.m_shape.getNextVertex(t);if(this.removeAngleSortInfo_(t),this.beforeRemoveVertex_(t,!1),t=e,t===r)break}const e=[!1];this.m_shape.insertClosedPath(this.m_polylineDegeneracies,H,r,r,e)}return!0}fixOrphanVertices_(){let e=0;for(let i=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList());-1!==i;i=this.m_sortedVertices.getNext(i)){const e=this.m_sortedVertices.getData(i);this.m_shape.setPathToVertex(e,H)}let t=0;for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==H;){const s=this.m_shape.getFirstVertex(i);if(s===H||this.m_shape.getPathFromVertex(s)!==H){const e=i;i=this.m_shape.getNextPath(i),this.m_shape.removePathOnly(e);continue}this.m_shape.setPathToVertex(s,i);let r=1;for(let e=this.m_shape.getNextVertex(s);e!==s;e=this.m_shape.getNextVertex(e))this.m_shape.setPathToVertex(e,i),r++;this.m_shape.setRingAreaValid(i,!1),this.m_shape.setPathSize(i,r),this.m_shape.setLastVertex(i,this.m_shape.getPrevVertex(s)),t+=r,e++,i=this.m_shape.getNextPath(i)}for(let i=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList());-1!==i;i=this.m_sortedVertices.getNext(i)){const s=this.m_sortedVertices.getData(i);if(this.m_shape.getPathFromVertex(s)!==H)continue;const r=[!1],n=this.m_shape.insertClosedPath(this.m_geometry,H,s,s,r);t+=this.m_shape.getPathSize(n),e++}this.m_shape.setGeometryPathCount(this.m_geometry,e),this.m_shape.setGeometryVertexCount(this.m_geometry,t);let s=0;for(let i=this.m_shape.getFirstGeometry();i!==H;i=this.m_shape.getNextGeometry(i))s+=this.m_shape.getPointCount(i);this.m_shape.setTotalPointCount(s)}getNextEdgeIndex_(e){if(-1===e)return-1;for(let t=0,s=this.m_bunchEdgeIndices.length-1;t<s;t++)if(e=(e+1)%this.m_bunchEdgeIndices.length,-1!==this.m_bunchEdgeIndices[e])return e;return-1}getPrevEdgeIndex_(e){if(-1===e)return-1;for(let t=0,s=this.m_bunchEdgeIndices.length-1;t<s;t++)if(e=(this.m_bunchEdgeIndices.length+e-1)%this.m_bunchEdgeIndices.length,-1!==this.m_bunchEdgeIndices[e])return e;return-1}transferVertexData_(e,t){const s=this.m_shape.getUserIndex(t,this.m_userIndexSortedIndexToVertex),i=this.m_shape.getUserIndex(t,this.m_userIndexSortedAngleIndexToVertex);this.m_shape.transferAllDataToTheVertex(e,t),this.m_shape.setUserIndex(t,this.m_userIndexSortedIndexToVertex,s),this.m_shape.setUserIndex(t,this.m_userIndexSortedAngleIndexToVertex,i)}removeAngleSortInfo_(e){const t=this.m_shape.getUserIndex(e,this.m_userIndexSortedAngleIndexToVertex);-1!==t&&(this.m_bunchEdgeIndices[t]=-1,this.m_shape.setUserIndex(e,this.m_userIndexSortedAngleIndexToVertex,-1))}progress_(e=!1){}}function es(e,t,s){const i=Vt(e,t,s);return i?1===i?1:2:0}function ts(e,t,s){const i=Ht(e,t,s);return i?1===i?1:2:0}function ss(e,t,s,i,r){for(let n=0;n<s;n++)r[n]=ts(e,t[n],i)}function is(e,t,s,r,h){if(e.getGeometryType()===i.enumPolygon)ss(e,t,s,r,h);else if(e.getGeometryType()===i.enumEnvelope){const t=n.constructEmpty();e.queryEnvelope(t),ns()}else Pe("")}function rs(e,t,s,r,n){const a=e.getGeometryType();a===i.enumPolyline?os():h(a)?as():Pe("")}function ns(t,s,i,r,n){e(0)}function hs(e,t,s){if(s.reset(),t<3)return;const i=e[0].clone(),r=i.x,n=i.y,h=e[1].clone(),a=new F;for(let o=2;o<t;o++)a.assign(e[o]),s.pe((a.x-i.x)*(h.y-n)),i.assign(h),h.assign(a);s.pe((r-i.x)*(h.y-n))}function as(t,s,i,r,n){e(0)}function os(t,s,i,r,n){e(0)}function ms(e,t,s,i,r,n,h){gs(e,t,s,r,n,h)}function gs(e,t,s,i,r,n){e.hasCurves()?(e.setCurveStitcherPointer(i),i.m_impl=new Es(n,!1,null),i.m_impl.buildMonotonicCurveParentage(e,t,s,r)):i.m_impl=null}function ls(e,t,s,i,r,n,h,a){e.hasCurves()?(e.setCurveStitcherPointer(n),n.m_impl=new Es(a,!0,r),n.m_impl.buildMonotonicCurveParentage(e,t,s,h),At(e,s)):n.m_impl=null}function _s(e){}function ds(e){if(!e.hasSegmentParentage())return;const t=new c(0),s=e.queryVertexIteratorOnSelection();for(let h=s.next();h!==H;h=s.next())t.add(h);if(0===t.size())return;e.sortVerticesSimpleByY(t,0,t.size()),t.add(H);const i=F.getNAN();e.queryXY(t.read(0),i);let r=0;const n=F.getNAN();for(let h=1,a=t.size();h<a;h++){{const s=t.read(h);s!==H?e.queryXY(s,n):n.setNAN()}if(!n.isEqualPoint2D(i)){let s=!1,a=-2;for(let i=r;i<h;++i){const r=t.read(i);if(e.getSegmentParentageBreakVertex(r)){s=!0;break}let n=e.getSegmentParentage(r);const h=e.getPrevVertex(r);if(h!==H){let t=e.getSegmentParentage(h);if(-1===n&&(n=t),-1===t&&(t=n),n!==t){s=!0;break}}if(-2!==a&&n!==a){s=!0;break}a=n}if(s)for(let i=r;i<h;++i)e.setSegmentParentageBreakVertex(t.read(i),!0);i.setCoordsPoint2D(n),r=h}}}function ps(e,t){let s=t.isEmpty()?e:T(null,t,!0).total();return s>e&&(s=e),.125*s}function us(e,t){return t||(t=n.constructEmpty()),ps(e,t)}function cs(e,t){return.125*e}function fs(e,t){return 3*e+3*t}class xs{constructor(){this.m_impl=null}stitchCurves(e,t,s,i){this.m_impl&&(this.m_impl.stitchCurves(e,t,s),i&&this.clearStitcher(e))}clearStitcher(e){this.m_impl&&(this.m_impl.clearStitcher(e),this.m_impl=null)}getOriginalVertexIndex(e,t){return this.m_impl.getOriginalVertexIndex(e,t)}getOriginalSegmentTypeInfo(e){return this.m_impl.getOriginalSegmentTypeInfo(e)}}class Es{constructor(e,t,s){this.m_originalPlanarSegments=[],this.m_progressTracker=null,this.m_nsr=null,this.m_progressTracker=e,this.m_nsr=s,this.m_tolerance=0,this.m_originalVertexIndex=-1,this.m_type=0,this.m_progressCounter=0,this.m_bIsSimple=t}buildSegmentParentage(t,s,i,r,n){e(0)}static processCurves(t,s,i,r){return e(0),t}buildMonotonicCurveParentage(t,s,r,n){const h=!1;if(!t.hasCurves())return;e(!t.hasSegmentParentage()),this.m_type=1,this.m_originalPlanarSegments.length=0,this.m_bIsSimple&&(this.m_originalVertexIndex=t.createUserIndex()),this.m_tolerance=r;const a=new P,o=new G,m=[],g=[],l=[];for(let _=t.getFirstGeometry();_!==H;_=t.getNextGeometry(_))for(let n=t.getFirstPath(_);n!==H;n=t.getNextPath(n)){let _=t.getPathSize(n),d=t.getFirstVertex(n),p=0,u=-1;for(let c=0;c<_;c++){let f=t.getNextVertex(d);if(!t.querySegment(d,o,!0,!1)){d=f;continue}if(0===p){u=t.getVertexIndex(d);const s=Es.regularizeCurve(t,o.get(),d,r);if(s>=0){this.m_nsr&&0===this.m_nsr.m_reason&&this.m_nsr.assign(new Xe(13,u,-1)),p=s,_=t.getPathSize(n),f=t.getNextVertex(d);const i=t.querySegment(d,o,!0,!1);e(i)}}else p--;const x=t.getVertexIndex(d);let E;-1!==this.m_originalVertexIndex&&t.setUserIndex(d,this.m_originalVertexIndex,u),t.setSegmentToIndex(x,null);let I=!1;switch(o.get().getGeometryType()){case i.enumEllipticArc:case i.enumRationalBezier2:E=Ye(o.get(),s,r,h,g,l,m,this.m_progressTracker),I=!0;break;default:{const e=!this.m_bIsSimple||!o.get().isMonotoneQuickAndDirty();E=Oe(o.get(),s,r,e,h,g,m,this.m_progressTracker)}}const S=this.m_originalPlanarSegments.length;if(t.setSegmentParentageAndBreak(d,S,!0),!g[1].isNAN()){let e=null;I?(ee(g),ee(l),e=new te({points:g,weights:l})):e=new $({cp:g}),e.snapControlPoints(r*r),t.setSegmentToIndex(x,e)}const C=I?2:3;for(let e=1,s=E,i=C;e<s;++e,i+=C){o.get().queryCoord(m[e],a);const s=t.insertVertex(n,f,a);if(-1!==this.m_originalVertexIndex&&t.setUserIndex(s,this.m_originalVertexIndex,u),!g[i+1].isNAN())if(I){const e=new te({points:g.slice(i),weights:l.slice(i)});e.snapControlPoints(r*r),t.setSegmentToIndex(t.getVertexIndex(s),e)}else{const e=new $({cp:g.slice(i)});e.snapControlPoints(r*r),t.setSegmentToIndex(t.getVertexIndex(s),e)}t.setSegmentParentageAndBreak(s,S,!1)}E>1&&(c+=E-1,_=t.getPathSize(n)),this.m_originalPlanarSegments.push(o.releaseSegment()),d=f}}}stitchCurves(e,t,s){Es.st_stitchCurvesImpl(this,e,t,s,!1)}clearStitcher(e){this.m_originalPlanarSegments.length=0,-1!==this.m_originalVertexIndex&&(e.removeUserIndex(this.m_originalVertexIndex),this.m_originalVertexIndex=-1),e.deleteSegmentParentage()}static st_verifyParentage(e){Es.st_stitchCurvesImpl(null,e,H,0,!0)}getOriginalVertexIndex(e,t){return-1!==this.m_originalVertexIndex&&t!==H?e.getUserIndex(t,this.m_originalVertexIndex):-1}getOriginalSegmentTypeInfo(e){if(-1!==e){const t=this.m_originalPlanarSegments[e];switch(t.getGeometryType()){case i.enumEllipticArc:return 0===t.projectionBehavior()?0:1;case i.enumBezier:return 2;case i.enumBezier2:return 3;case i.enumLine:return-1;case i.enumRationalBezier2:return 4;default:se("")}}return-1}static st_curveRequiresRegularization(t,s){return e(0),!1}progress_(e=!1){this.m_progressCounter++,e||this.m_progressCounter}processSpan_(t,s,i,r,n,h,a){if(s===i&&0===r)return e(t.getNextVertex(s)===H),t.setSegmentToIndex(t.getVertexIndex(s),null),void t.setSegmentParentageAndBreak(s,-1);const o=t.getNextVertex(s);{let s=2;for(let e=o;e!==i;e=t.getNextVertex(e))s++;e(s===r)}if(null===n){t.setSegmentToIndex(t.getVertexIndex(s),null);for(let e=o;e!==i;)e=t.removeVertex(e,!0);return}const m=t.getXY(s),g=t.getXY(i);if(n.isClosed()){if(m.isEqualPoint2D(g)&&m.isEqualPoint2D(n.getStartXY())){let e;if(e=this.verifySegmentFitness(t,s,i,r,n,h,a)){const r=n.clone();return r.dropAllAttributes(),e<0&&r.reverse(),this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),r)}}}else if(m.isEqualPoint2D(n.getStartXY())){if(g.isEqualPoint2D(n.getEndXY())){const e=n.clone();if(e.dropAllAttributes(),this.verifySegmentFitness(t,s,i,r,e,h,a))return this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),e)}}else if(g.isEqualPoint2D(n.getStartXY())&&m.isEqualPoint2D(n.getEndXY())){const e=n.getReversed();if(e.dropAllAttributes(),this.verifySegmentFitness(t,s,i,r,e,h,a))return this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),e)}this.processSpanSplitSegment(t,s,i,r,n,h,a)}processSpanSplitSegment(e,t,s,i,r,n,h){if(r.isLine())return;if(this.fitSegmentToSpan(e,t,s,i,r,n,h))return;const a=h*h;let o=i,m=t;const g=e.getXY(t);let l=r.getClosestCoordinate(g,!1);const _=r.getCoord2D(l);let d=!1;const p=F.sqrDistance(g,_);if(p>a){const i=e.getNextVertex(t);if(this.approximateSpanSection(e,t,r,n,h),i===s)return;m=i,d=!0,o-=1}let u=s;const c=e.getXY(s);l=r.getClosestCoordinate(c,!1);const f=r.getCoord2D(l);let x=!1;const E=F.sqrDistance(c,f);if(E>a){const t=e.getPrevVertex(s);if(this.approximateSpanSection(e,t,r,n,h),t===m)return;u=t,x=!0,o-=1}if((d||x)&&this.fitSegmentToSpan(e,m,u,o,r,n,h))return;let I=!1;if(!d&&p>0){const s=e.getNextVertex(t);if(this.approximateSpanSection(e,t,r,n,h),s===u)return;m=s,d=!0,I=!0,o-=1}if(!x&&E>0){const t=e.getPrevVertex(s);if(this.approximateSpanSection(e,t,r,n,h),t===m)return;u=t,x=!0,I=!0,o-=1}if(I&&this.fitSegmentToSpan(e,m,u,o,r,n,h))return;let S=m;for(;;){const t=e.getNextVertex(S);if(this.approximateSpanSection(e,S,r,n,h),S=t,S===u)return}}fitSegmentToSpan(t,s,i,r,n,h,a){const o=0===this.m_type,m=[];if(m.push(t.getXY(s)),o){let n=s;const h=32;if(r>h){const s=BigInt(r-1),a=BigInt(h-1);let o=a,g=0n;for(let e=1;e<r;e++,o+=a)if(n=t.getNextVertex(n),o>=g+s){g+=s;const e=t.getXY(n);m.push(e)}e(n===i)}else{for(let e=1;e<r;e++){n=t.getNextVertex(n);const e=t.getXY(n);m.push(e)}e(n===i)}}else{let e=s;const n=new G;for(;;){t.querySegment(e,n,!1,!0);const s=[.1,.25,.4,.5,.6,.75,.9,1];let h=0;for(const e of s){(2===r||1&h)&&m.push(n.get().getCoord2D(e)),h++}if(e=t.getNextVertex(e),e===i)break}}const g=(()=>{let e=m[0].compare(m.at(-1));if(0===e){const t=new ce(0);hs(m,m.length,t),e=t.getResult()>=0?-1:1}return e>0})();g&&m.reverse();const l=n.clone();if(l.dropAllAttributes(),l.setSegmentFromCoords(m,m.length),g&&l.reverse(),l.snapControlPoints(this.m_tolerance*this.m_tolerance),this.verifySegmentFitness(t,s,i,r,l,h,a)){this.removeSpan(t,s,i);const e=t.getVertexIndex(s);return t.setSegmentToIndex(e,l),!0}return!1}approximateSpanSection(e,t,s,r,n){const h=new G;if(!e.querySegment(t,h,!0,!1))return;const a=s.getGeometryType();if(a!==h.get().getGeometryType()){if(a===i.enumEllipticArc){if(h.get().getGeometryType()!==i.enumRationalBezier2)return;if(0===s.projectionBehavior()){const s=[];ie(!1,h.get(),n,s,this.m_progressTracker);const i=e.getNextVertex(t),r=e.getPathFromVertex(t),a=new P;let o=t;for(let t=1,n=s.length;t<n;t++){const n=s[t],m=h.get().getCoord2D(s[t-1]),g=h.get().getCoord2D(re(s[t-1],n,.5));h.get().queryCoord(n,a);const l=a.getXY(),_=new ne;_.constructCircularArcThreePoint(m,l,g);let d=H;n<1&&(d=e.insertVertex(r,i,a)),e.setSegmentToIndex(e.getVertexIndex(o),_),o=d}return}{const s=he(F,3);h.get().queryControlPoints(s);const i=[0,0,0];h.get().queryWeights(i);const r=ae(i),n=new ne;return oe(s,r*r,null,!1,n),void e.setSegmentToIndex(e.getVertexIndex(t),n)}}o("approximate_span_section_")}}verifySegmentFitness(e,t,s,i,r,n,h){return 0===this.m_type?this.verifySegmentFitnessLines(e,t,s,i,r,n,h):this.verifySegmentFitnessCurves(e,t,s,i,r,n,h)}verifySegmentFitnessCurves(e,t,s,i,r,n,h){const a=e.getXY(t),o=e.getXY(s);if(!a.isEqualPoint2D(r.getStartXY())||!o.isEqualPoint2D(r.getEndXY()))return 0;let m=0;if(r.isClosed()){const e=r.getCoord2D(.1).sub(a);m=r.getCoord2D(.7).sub(a).crossProduct(e)>=0?1:-1}const g=new Array(me.s_maxMonotonicPartParams);let l=r.getMonotonicPartParams(g.length,g);l--;const _=new ge,d=[1,.5,.75,.25];let p=0,u=t;const c=a.clone();for(;;){const t=e.getNextVertex(u);let i=e.getSegment(u);null===i&&(e.queryLineConnector(u,_,!0),i=_);for(let e=t===s?1:0;e<d.length;e++){const t=i.getCoord2D(d[e]);if(!r.isCloserThanDistance(t,le.unit(),h))return 0}if(l>1)for(let e=1;e<l;){const t=r.getCoord2D(g[e]);i.isCloserThanDistance(t,le.unit(),h)?(g[l-1]=q(g[e],g[e]=g[l-1]),l--):e++}if(m){const e=i.getCoord2D(.25);p+=e.sub(a).crossProduct(c.sub(a)),c.assign(e),e.assign(i.getCoord2D(.75)),p+=e.sub(a).crossProduct(c.sub(a)),c.assign(e)}if(u=t,u===s)return l>1?0:m?p<0?-m:m:1}}verifySegmentFitnessLines(t,s,i,r,n,h,a){return e(0),0}removeSpan(e,t,s){e.setSegmentToIndex(e.getVertexIndex(t),null);const i=e.getNextVertex(t);i!==s&&e.removeVertices(i,s)}static st_stitchCurvesImpl(e,t,s,i,r){if(t.hasSegmentParentage())return t.hasCurves()?Es.st_stitchCurvesFromCurvesImpl(e,t,s,i,r):Es.st_stitchCurvesFromLinesImpl(e,t,s,i,r)}static st_stitchCurvesFromLinesImpl(t,s,i,r,n){let h=i===H?s.getFirstGeometry():i;for(;h!==H;){for(let i=s.getFirstPath(h);i!==H;i=s.getNextPath(i)){let h=s.getPathSize(i);s.isClosedPath(i)&&(h+=1);let a=!0,o=!1;const m=s.getFirstVertex(i);let g=m;for(let i=0;i<h&&g!==H;){let l=s.getSegmentParentage(g);if(-1===l||a){a=!1,i++,g=s.getNextVertex(g),o=!0;continue}let _,d,p=0;if(o?(_=s.getPrevVertex(g),d=g,e(_!==H),e(d!==_),e(-1===s.getSegmentParentage(_)||m===_)):(_=g,d=s.getNextVertex(_),i++,e(d!==H),e(d!==_),l=s.getSegmentParentage(d)),p=2,o=!1,-1===l||s.getSegmentParentageBreakVertex(d)){g=d;continue}let u=s.getNextVertex(d);for(i++;i<h&&u!==H;){d=u,p++;const t=s.getSegmentParentage(u);if(-1===t||s.getSegmentParentageBreakVertex(u))break;e(t===l),i++,u=s.getNextVertex(u)}if(!n){const e=t.m_originalPlanarSegments[l];t.processSpan_(s,_,d,p,e,l,r)}g=d}}if(i!==H)break;h=s.getNextGeometry(h)}}static st_stitchCurvesFromCurvesImpl(t,s,i,r,n){let h=i===H?s.getFirstGeometry():i;for(;h!==H;)if(_e(s.getGeometryType(h))){for(let i=s.getFirstPath(h);i!==H;i=s.getNextPath(i)){let h=s.getPathSize(i);const a=s.isClosedPath(i);a&&(h+=1);let o=s.getFirstVertex(i);if(a){if(-1!==s.getSegmentParentage(o)){let e=o;for(let t=0;!s.getSegmentParentageBreakVertex(e);t++){if(t===h){o=s.getFirstVertex(i),s.setSegmentParentageBreakVertex(e,!0);break}e=s.getPrevVertex(e)}}}else e(-1===s.getSegmentParentage(o)||s.getSegmentParentageBreakVertex(o));let m=o;for(let i=0;i<h&&m!==H;){const a=s.getSegmentParentage(m);if(-1===a){i++,m=s.getNextVertex(m);continue}let o=0,g=H;const l=m;o=1;let _=s.getNextVertex(l);for(;i<h&&_!==H;){i++,g=_,o++;const t=s.getSegmentParentage(_);if(-1===t||s.getSegmentParentageBreakVertex(_))break;e(t===a),_=s.getNextVertex(_)}if(g===H)break;if(!n){const e=t.m_originalPlanarSegments[a];t.processSpan_(s,l,g,o,e,a,r)}m=g}}if(i!==H)break;h=s.getNextGeometry(h)}else h=i===H?s.getNextGeometry(h):H}static regularizeCurve(e,t,s,i){let r=t.snapControlPoints(i*i);if(r){const i=e.getVertexIndex(s),r=t.clone();e.setSegmentToIndex(i,r)}if(t.getGeometryType()===$.type){const n=[],h=t.calculateSpecialPointsForCracking(i,n);if(h>0){e.splitSegment(s,n,h),r=e.snapControlPoints(s,h+1,i*i)||r;for(let t=0;t<h;t++)s=e.getNextVertex(s),e.setSegmentParentageBreakVertex(s,!0);return h}}return r?0:-1}}function Is(e,t,s,m,g){if(m&&(m.m_reason=0,m.m_vertexIndex1=-1,m.m_vertexIndex2=-1),e.isEmpty())return 5;const l=e.getGeometryType();if(l===i.enumPoint)return Cs(e,m);const _=r(t,e,!1).total();if(l===i.enumEnvelope){const t=e,s=n.constructEmpty();return t.queryEnvelope(s),s.isDegenerate(_)?(m&&(m.m_reason=4,m.m_vertexIndex1=-1,m.m_vertexIndex2=-1),0):5}if(h(l)){const i=e,r=new a({vd:i.getDescription()});return r.addSegment(i,!0),Is(r,t,s,m,g)}const d=[0],p=e.getImpl().getIsSimple(_,d);let u=s?-1:p;if(-1!==u)return u;const c=new vs(e,t,u,g,!1);return l===i.enumMultiPoint?u=c.multipointIsSimpleAsFeature():l===i.enumPolyline?u=c.polylineIsSimpleAsFeature():l===i.enumPolygon?u=c.polygonIsSimpleAsFeature():o(""),e.getImpl().setIsSimple(u,_),m&&m.assign(c.m_nonSimpleResult),u}function Ss(e,t,s,l){if(e.isEmpty())return e;const _=e.getGeometryType();if(_===i.enumPoint){const t=new Xe;if(Cs(e,t),3===t.m_reason){const t=e.clone();return t.replaceNaNs(1,0),t}return 2===t.m_reason?e.createInstance():e}if(_===i.enumEnvelope){const s=r(t,e,!0).total(),i=e,h=n.constructEmpty();return i.queryEnvelope(h),h.isDegenerate(s)?i.createInstance():e}if(h(_)){const i=e,r=new a({vd:i.getDescription()});return r.addSegment(i,!0),Ss(r,t,s,l)}m(_);const d=r(t,e,!1).total(),p=[0],u=e.getImpl().getIsSimple(d,p),c=s?-1:u;if(g(c)){if(_===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}if((_===i.enumMultiPoint||_===i.enumPolyline)&&c>=1)return e;const f=new vs(e,t,c,l,!1);let x;return _===i.enumMultiPoint?x=f.multipointSimplifyAsFeature():_===i.enumPolyline?x=f.polylineSimplifyAsFeature():_===i.enumPolygon?x=f.polygonSimplifyAsFeature():o(""),x}function Cs(e,t){const s=e.getX(),i=e.getY();if(!Number.isFinite(s)||!Number.isFinite(i))return t&&(t.m_reason=2,t.m_vertexIndex1=-1,t.m_vertexIndex2=-1),0;if(e.hasAttribute(1)){const s=e.getZ();if(!Number.isFinite(s))return t&&(t.m_reason=Number.isNaN(s)?3:2,t.m_vertexIndex1=-1,t.m_vertexIndex2=-1),0}return 5}class Ps{constructor(){this.m_segment=null,this.m_vertexIndex=-1,this.m_pathIndex=-1,this.m_flags=0}setReversed(e){this.m_flags&=-2,this.m_flags=this.m_flags|(e?1:0)}getReversed(){return!!(1&this.m_flags)}getRightSide(){return this.getReversed()?0:1}}class ys extends de{constructor(e){super(),this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_xy.read(2*t)-this.m_helper.m_xy.read(2*i);return r<0?-1:r>0?1:0}}class Ns extends de{constructor(e){super(),this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_edges[t],n=this.m_helper.m_edges[i],h=r.getReversed(),a=n.getReversed();let o=r.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);if(o===m){const e=h?r.m_segment.getStartY():r.m_segment.getEndY(),t=a?n.m_segment.getStartY():n.m_segment.getEndY(),s=Math.min(e,t);let i=.5*(s-this.m_helper.m_yScanline)+this.m_helper.m_yScanline;i===this.m_helper.m_yScanline&&(i=s),o=r.m_segment.intersectionOfYMonotonicWithAxisX(i,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(i,0)}return o<m?-1:o>m?1:0}}class vs{constructor(e,t,s,i,n){this.m_multiVertexGeom=null,this.m_edges=[],this.m_freeEdges=[],this.m_lineEdgesRecycle=[],this.m_newEdges=[],this.m_recycledSegIter=null,this.m_crossOverHelperList=new l,this.m_progressTracker=null,this.m_progressCounter=0,this.m_AET=new _,this.m_xyToNode1=null,this.m_xyToNode2=null,this.m_pathOrientations=null,this.m_pathParentage=null,this.m_xy=null,this.m_pairs=[],this.m_pairIndices=null,this.m_pathsForOGCTests=[],this.m_curveStitcher=null,this.m_editShape=null,this.m_multiPathStitcher=null,this.m_nonSimpleResult=new Xe,this.m_progressCounter=0,this.m_progressTracker=i,this.m_geometry=e,this.m_knownSimpleResult=s,this.m_sr=t;const h=r(t,e,!1);this.m_toleranceIsSimple=h,this.m_toleranceIsSimpleClustering=d(h),this.m_toleranceIsSimpleCracking=p(h),this.m_toleranceSimplify=r(t,e,!0),this.m_description=this.m_geometry.getDescription(),this.m_attributeCount=this.m_description.getAttributeCount(),this.m_bOGCRestrictions=n,this.m_bPlanarSimplify=this.m_bOGCRestrictions,this.m_unknownOrientationPathCount=-1,this.m_yScanline=0,this.m_progressCounter=0}isSimplePlanarImpl(){if(this.m_bPlanarSimplify=!0,!this.checkStructure())return 0;const e=this.m_geometry.getGeometryType();return u(e)&&!this.checkDegenerateSegments(!1)?0:this._CheckClustering()?u(e)?this._CheckCracking()?this.m_geometry.getGeometryType()===i.enumPolyline?this.checkSelfIntersectionsPolylinePlanar()?4:0:this._CheckSelfIntersections()?this._CheckValidRingOrientation():0:0:5:0}isSimplePlanarImpl3D(){return e(0),7}generateSortedPairs(e){let t=null;u(e.getGeometryType())&&(t=e);const s=(this.m_bPlanarSimplify||this.m_bOGCRestrictions)&&null!==t,i=e.getPointCount();this.m_xy=e.getAttributeStreamRef(0),this.m_pairs.length=0,this.m_pairIndices=new c(0),s&&(this.m_pathsForOGCTests.length=0);let r=0;for(let a=0;a<i;a++)if(this.m_pairs.push(2*a),this.m_pairs.push(2*a+1),this.m_pairIndices.add(2*a),this.m_pairIndices.add(2*a+1),s){for(;a>=t.getPathEnd(r);)r++;this.m_pathsForOGCTests.push(r)}const n=new f,h={parent:this,workPt:new F,userSort(e,t,i){i.sort(e,t,((e,t)=>this.parent.compareVerticesForPlanarClustering(e,t,s)))},getValue(e){const t=this.parent.m_pairs[e],s=t>>1;this.parent.m_xy.queryPoint2D(2*s,this.workPt);return this.workPt.y+(1&t?this.parent.m_toleranceIsSimpleClustering:-this.parent.m_toleranceIsSimpleClustering)}};n.sort(this.m_pairIndices,0,2*i,h)}_TestToleranceDistancePlanar(e,t){const s=this.m_xy.read(2*e),i=this.m_xy.read(2*e+1),r=this.m_xy.read(2*t),n=this.m_xy.read(2*t+1);if(!!at(s,i,r,n,this.m_toleranceIsSimpleClustering*this.m_toleranceIsSimpleClustering)){if(0===this.m_geometry.getDimension())return!1;return s===r&&i===n}return!0}checkStructure(){const e=this.m_geometry.getGeometryType();if(u(e)){const e=this.m_geometry.getImpl(),t=this.m_geometry.getGeometryType()===i.enumPolygon?3:2;for(let s=0,i=e.getPathCount();s<i;s++)if(e.getPathSize(s)<t){if(e.hasNonLinearSegments()&&e.hasNonLinearSegmentsPath(s)&&e.getPathSize(s)>0)continue;return this.m_nonSimpleResult=new Xe(1,s,0),!1}}if(x(e)){const e=this.m_geometry.getImpl(),t=e.getAttributeStreamRef(0);for(let s=0,i=e.getPointCount();s<i;s++){if(!t.readPoint2D(2*s).isFinite())return this.m_nonSimpleResult=new Xe(2,s,0),!1}if(this.m_geometry.hasAttribute(1)){const t=e.getAttributeStreamRef(1);for(let s=0,i=e.getPointCount();s<i;s++){const e=t.read(s);if(!Number.isFinite(e))return Number.isNaN(e)?this.m_nonSimpleResult=new Xe(3,s,0):this.m_nonSimpleResult=new Xe(2,s,0),!1}}}return!0}checkDegenerateSegments(e){const t=this.m_geometry.getImpl(),s=t.querySegmentIterator(),i=t.hasAttribute(1),r=i?E(this.m_sr,t,!1).total():0,n=t.hasNonLinearSegments(),h=this.m_toleranceIsSimple.total();for(;s.nextPath();)for(;s.hasNextSegment();){const t=s.nextSegment();let a=t.calculateLowerLength2D();if(!(a>h)&&!(n&&t.isCurve()&&(a=t.calculateLength2D(),a>h))){if(e&&i){const e=t.getStartAttributeAsDbl(1,0),s=t.getEndAttributeAsDbl(1,0);if(Math.abs(s-e)>r)continue}return this.m_nonSimpleResult=new Xe(4,s.getStartPointIndex(),-1),!1}}return!0}checkDegenerateSegments3D(){return e(0),!1}_CheckClustering(){const e=this.m_geometry.getImpl();this.generateSortedPairs(e);const t=e.getPointCount();this.m_AET.clear(),this.m_AET.setComparator(new ys(this)),this.m_AET.setCapacity(t);for(let s=0,i=2*t;s<i;s++){this.progress_();const e=this.m_pairIndices.read(s),t=this.m_pairs[e],i=t>>1;if(1&t){const e=this.m_AET.search(i),t=this.m_AET.getPrev(e),s=this.m_AET.getNext(e);if(this.m_AET.deleteNode(e),t!==_.st_nullNode()&&s!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),this.m_AET.getElement(s)))return this.m_nonSimpleResult=new Xe(5,this.m_AET.getElement(t),this.m_AET.getElement(s)),!1}else{const e=this.m_AET.addElement(i),t=this.m_AET.getPrev(e);if(t!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),i))return this.m_nonSimpleResult=new Xe(5,i,this.m_AET.getElement(t)),!1;const s=this.m_AET.getNext(e);if(s!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(s),i))return this.m_nonSimpleResult=new Xe(5,i,this.m_AET.getElement(s)),!1}}return!0}_CheckCracking(){const e=this.m_geometry.getImpl(),t=e.getPointCount();return!e.hasNonLinearSegments()&&t<10?this._CheckCrackingBrute():this._CheckCrackingPlanesweep()}_CheckCrackingPlanesweep(){if(this.m_editShape=new I,this.m_editShape.addGeometry(this.m_geometry),this.m_editShape.hasCurves()){this.m_curveStitcher=new xs;const e=n.constructEmpty();this.m_geometry.queryEnvelope(e);const t=us(this.m_toleranceSimplify.total(),e),s=new Xe;if(ls(this.m_editShape,t,this.m_toleranceSimplify.total(),12e3,s,this.m_curveStitcher,null,this.m_progressTracker),0!==s.m_reason)return this.m_editShape=null,this.m_nonSimpleResult.assign(s),!1}const e=new Xe;return Gt(!1,this.m_editShape,this.m_toleranceIsSimpleCracking,e,this.m_progressTracker)?(null!=this.m_curveStitcher?(e.m_vertexIndex1=this.m_curveStitcher.getOriginalVertexIndex(this.m_editShape,e.m_vertexIndex1),e.m_vertexIndex2=this.m_curveStitcher.getOriginalVertexIndex(this.m_editShape,e.m_vertexIndex2),this.m_curveStitcher=null):(e.m_vertexIndex1=this.m_editShape.getVertexIndex(e.m_vertexIndex1),e.m_vertexIndex2=this.m_editShape.getVertexIndex(e.m_vertexIndex2)),this.m_editShape=null,this.m_nonSimpleResult.assign(e),!1):(null==this.m_curveStitcher&&(this.m_editShape=null),!0)}_CheckCrackingBrute(){const e=this.m_geometry.getImpl(),t=e.querySegmentIterator(),s=e.querySegmentIterator();for(;t.nextPath();)for(;t.hasNextSegment();){const e=t.nextSegment();if(!t.isLastSegmentInPath()||!t.isLastPath()){s.resetTo(t);do{for(;s.hasNextSegment();){const i=s.nextSegment(),r=S(!0,e,i,this.m_toleranceIsSimpleCracking,!0);if(r){const e=2===r?7:6;return this.m_nonSimpleResult=new Xe(e,t.getStartPointIndex(),s.getStartPointIndex()),!1}}}while(s.nextPath())}}return!0}_CheckSelfIntersections(){let e=this.m_geometry.getImpl();null!==this.m_curveStitcher&&(this.m_multiPathStitcher=this.m_editShape.getGeometry(this.m_editShape.getFirstGeometry()),e=this.m_multiPathStitcher.getImpl(),this.generateSortedPairs(e)),this.m_edges.length=0,this.m_lineEdgesRecycle.length=0,this.m_recycledSegIter=e.querySegmentIterator(),this.m_recycledSegIter.setCirculator(!0);const t=new Array(0),s=e.getPointCount();let i=Number.NaN,r=0;for(let n=0,h=2*s;n<h;n++){this.progress_();const e=this.m_pairIndices.read(n),s=this.m_pairs[e];if(1&s)continue;const h=s>>1,a=this.m_xy.read(2*h),o=this.m_xy.read(2*h+1);if(t.length&&(a!==i||o!==r)){if(!this.processBunchForSelfIntersectionTest(t))return!1;t.length=0}t.push(h),i=a,r=o}return!!this.processBunchForSelfIntersectionTest(t)}checkSelfIntersectionsPolylinePlanar(){return e(0),!1}checkSelfIntersectionsPolylinePlanar3D(t){return e(0),!1}checkSelfIntersectionsPolygonsOGC(){return e(0),!1}_CheckValidRingOrientation(){const e=null!==this.m_multiPathStitcher?this.m_multiPathStitcher.getImpl():this.m_geometry.getImpl();if(e.calculateArea2D()<=0)return this.m_nonSimpleResult=new Xe(8,1===e.getPathCount()?1:-1,-1),0;if(1===e.getPathCount())return this.m_bOGCRestrictions&&!this.checkSelfIntersectionsPolygonsOGC()?0:4;this.m_pathOrientations=new C(e.getPathCount(),0),this.m_pathParentage=new c(e.getPathCount(),-1);let t=-1,s=0;for(let n=0,h=e.getPathCount();n<h;n++){const i=e.calculateRingArea2D(n);if(this.m_pathOrientations.write(n,i<0?0:8),i>0)t=n,s=i;else{if(0===i)return this.m_nonSimpleResult=new Xe(8,n,-1),0;if((t<0||s<Math.abs(i))&&(this.m_nonSimpleResult=new Xe(9,n,-1),this.m_bOGCRestrictions))return 0;this.m_pathParentage.write(n,t)}}this.m_unknownOrientationPathCount=e.getPathCount(),this.m_newEdges.length=0;const i=e.getPointCount();this.m_yScanline=Number.NaN;const r=[];this.m_xyToNode1=new c(i,_.st_nullNode()),this.m_xyToNode2=new c(i,_.st_nullNode()),this.m_freeEdges.length=0,this.m_AET.clear(),this.m_AET.setComparator(new Ns(this));for(let n=0,h=2*i;this.m_unknownOrientationPathCount>0&&n<h;n++){const e=this.m_pairIndices.read(n),t=this.m_pairs[e];if(1&t)continue;const s=t>>1,i=this.m_xy.read(2*s+1);if(i!==this.m_yScanline&&r.length){if(!this.processBunchForRingOrientationTest(r))return 0;r.length=0}r.push(s),this.m_yScanline=i}return this.m_unknownOrientationPathCount>0&&!this.processBunchForRingOrientationTest(r)?0:this.m_bOGCRestrictions?0!==this.m_nonSimpleResult.m_reason?0:this.checkSelfIntersectionsPolygonsOGC()?5:0:0===this.m_nonSimpleResult.m_reason?4:3}processBunchForSelfIntersectionTest(e){if(1===e.length)return!0;for(let h=0,a=e.length;h<a;h++){const t=e[h];this.m_recycledSegIter.resetToVertex(t,-1);const s=this.m_recycledSegIter.previousSegment();this.m_edges.push(this.createEdge(s,t,this.m_recycledSegIter.getPathIndex(),!0)),this.m_recycledSegIter.nextSegment();const i=this.m_recycledSegIter.nextSegment();this.m_edges.push(this.createEdge(i,t,this.m_recycledSegIter.getPathIndex(),!1))}this.m_edges.sort(((e,t)=>this.edgeAngleCompare(e,t)));let t=this.m_crossOverHelperList.getFirstList();-1===t&&(t=this.m_crossOverHelperList.createList(0)),this.m_crossOverHelperList.reserveNodes(this.m_edges.length);for(let h=0,a=this.m_edges.length;h<a;h++)this.m_crossOverHelperList.addElement(t,h);let s=!0,i=-1,r=-1;for(;s;){s=!1;let e=this.m_crossOverHelperList.getFirst(t);if(-1===e)break;let n=this.m_crossOverHelperList.getNext(e);for(;-1!==n;){const h=this.m_crossOverHelperList.getData(e),a=this.m_crossOverHelperList.getData(n);if(i=this.m_edges[h].m_vertexIndex,r=this.m_edges[a].m_vertexIndex,i!==r)e=n,n=this.m_crossOverHelperList.getNext(e);else if(s=!0,this.m_crossOverHelperList.deleteElement(t,e),e=this.m_crossOverHelperList.getPrev(n),n=this.m_crossOverHelperList.deleteElement(t,n),-1===n||-1===e)break}}const n=this.m_crossOverHelperList.getListSize(t);if(this.m_crossOverHelperList.clear(t),n>0)return this.m_nonSimpleResult=new Xe(7,i,r),!1;for(let h=0,a=e.length;h<a;h++)this.recycleEdge(this.m_edges[h]);return this.m_edges.length=0,!0}processBunchForRingOrientationTest(e){for(let t=0,s=e.length;t<s;t++){const s=e[t];let i=this.m_xyToNode1.read(s);if(i!==_.st_nullNode()){const e=this.m_AET.getElement(i);this.m_freeEdges.push(e),this.m_AET.deleteNode(i),this.recycleEdge(this.m_edges[e]),this.m_edges[e]=null,this.m_xyToNode1.write(s,_.st_nullNode())}if(i=this.m_xyToNode2.read(s),i!==_.st_nullNode()){const e=this.m_AET.getElement(i);this.m_freeEdges.push(e),this.m_AET.deleteNode(i),this.recycleEdge(this.m_edges[e]),this.m_edges[e]=null,this.m_xyToNode2.write(s,_.st_nullNode())}}for(let t=0,s=e.length;t<s;t++){const s=e[t];this.m_recycledSegIter.resetToVertex(s,-1);const i=this.m_recycledSegIter.previousSegment();if(i.getStartY()>i.getEndY()){const e=this.m_recycledSegIter.getStartPointIndex(),t=this.createEdge(i,s,this.m_recycledSegIter.getPathIndex(),!0);let r;this.m_freeEdges.length>0?(r=this.m_freeEdges.at(-1),this.m_freeEdges.pop(),this.m_edges[r]=t):(r=this.m_edges.length,this.m_edges.push(t));const n=this.m_AET.addElement(r);this.m_xyToNode1.read(e)===_.st_nullNode()?this.m_xyToNode1.write(e,n):this.m_xyToNode2.write(e,n),3&this.m_pathOrientations.read(this.m_recycledSegIter.getPathIndex())||this.m_newEdges.push(n)}this.m_recycledSegIter.nextSegment();const r=this.m_recycledSegIter.nextSegment();if(r.getStartY()<r.getEndY()){const e=this.m_recycledSegIter.getEndPointIndex(),t=this.createEdge(r,s,this.m_recycledSegIter.getPathIndex(),!1);let i;this.m_freeEdges.length>0?(i=this.m_freeEdges.at(-1),this.m_freeEdges.pop(),this.m_edges[i]=t):(i=this.m_edges.length,this.m_edges.push(t));const n=this.m_AET.addElement(i);this.m_xyToNode1.read(e)===_.st_nullNode()?this.m_xyToNode1.write(e,n):this.m_xyToNode2.write(e,n),3&this.m_pathOrientations.read(this.m_recycledSegIter.getPathIndex())||this.m_newEdges.push(n)}}for(let t=0,s=this.m_newEdges.length;t<s&&this.m_unknownOrientationPathCount>0;t++){const e=this.m_newEdges[t],s=this.m_AET.getElement(e),i=this.m_edges[s].m_pathIndex;if(!(3&this.m_pathOrientations.read(i))){let t=-1,s=this.m_AET.getPrev(e),i=e,r=0;{let e=-1,n=null,h=-1,a=0;for(;s!==_.st_nullNode()&&(e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex,a=this.m_pathOrientations.read(h),!(3&a));)i=s,s=this.m_AET.getPrev(s);s===_.st_nullNode()?(r=1,s=i):(t=1==(3&a)?h:this.m_pathParentage.read(h),r=n.getRightSide()?0:1,s=this.m_AET.getNext(s))}do{const e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex;let a=this.m_pathOrientations.read(h);if(!(3&a)){if(r!==n.getRightSide())return this.m_nonSimpleResult=new Xe(8,h,-1),!1;const e=r&&!n.getReversed()?1:2;if(a=-4&a|e,this.m_pathOrientations.write(h,a),2===e&&0===this.m_nonSimpleResult.m_reason){const e=this.m_pathParentage.read(h);if(e!==t&&(this.m_nonSimpleResult=new Xe(9,h,e),this.m_bOGCRestrictions))return!1}if(this.m_unknownOrientationPathCount--,!this.m_unknownOrientationPathCount)return!0}t=1==(3&a)?h:this.m_pathParentage.read(h),i=s,s=this.m_AET.getNext(s),r=r?0:1}while(i!==e)}}return this.m_newEdges.length=0,!0}createEdge(e,t,s,r){let n;return e.getGeometryType()===i.enumLine?n=this.createEdgeLine(e):(n=new Ps,n.m_segment=e.clone()),n.m_vertexIndex=t,n.m_pathIndex=s,n.m_flags=0,n.setReversed(r),n}createEdgeLine(e){let t;return this.m_lineEdgesRecycle.length>0?(t=this.m_lineEdgesRecycle.at(-1),this.m_lineEdgesRecycle.pop(),e.copyTo(t.m_segment)):(t=new Ps,t.m_segment=e.clone()),t}recycleEdge(e){e.m_segment.getGeometryType()===i.enumLine&&this.m_lineEdgesRecycle.push(e)}static isShortSegment(e,t,s,i){let r=e.calculateLowerLength2D();if(r<=s){let n=!0;if(e.isCurve()&&(r=e.calculateLength2D(),n=r<=s),n){if(t){let t=e.getEndAttributeAsDbl(1,0);Number.isNaN(t)&&(t=0);let s=e.getStartAttributeAsDbl(1,0);return Number.isNaN(s)&&(s=0),Math.abs(s-t)<=i}return!0}return!1}return!1}static isShortSegmentPoints(t,s,i,r,n){return e(0),!1}removeDegenerateSegmentsFromCurvedPath(t,s,i,r){const n=t.hasAttribute(1),h=t.querySegmentIterator();h.resetToPath(s),e(h.nextPath());const a=this.m_toleranceSimplify.total();let o=!1,m=!0;const g=new P,l=new P,_=new F;for(;h.hasNextSegment();){this.progress_();const e=h.nextSegment();if(vs.isShortSegment(e,n,a,i))o?(e.queryEnd(l),vs.isShortSegmentPoints(g,l,n,a,i),m&&(r.startPathPoint(g),m=!1),e.queryEnd(g),r.lineToPoint(g),o=!1):(_.assign(e.getStartXY()),e.queryStart(g),o=!0);else if(o)if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(_,e.getEndXY(),!1),t.setStart(g),vs.isShortSegment(t,n,a,i))continue;r.addSegment(t,m),m=!1,o=!1}else e.queryEnd(l),vs.isShortSegmentPoints(g,l,n,a,i)||(m&&(r.startPathPoint(g),m=!1),r.lineToPoint(l),o=!1);else r.addSegment(e,m),m=!1}if(m)return;if(!o)return;t.isClosedPath(s)?t.getPointByVal(t.getPathStart(s),g):t.getPointByVal(t.getPathEnd(s)-1,g);const d=r.querySegmentIterator();d.resetToLastPath(),d.resetToLastSegment();const p=r.getDescription().getAttributeCount()>1;for(e(d.previousPath());d.hasPreviousSegment();){const e=d.previousSegment();if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(e.getStartXY(),g.getXY(),!1),!vs.isShortSegment(t,n,a,i)){p&&t.setEnd(g);const e=d.getEndPointIndex();for(let t=r.getPointCount()-1;t>=e;t--)r.removePoint(t);return void r.addSegment(t,!1)}}else if(e.queryStart(l),!vs.isShortSegmentPoints(l,g,n,a,i)){const e=d.getEndPointIndex();for(let t=r.getPointCount()-1;t>=e;t--)r.removePoint(t);return void r.lineToPoint(g)}}r.removePath(r.getPathCount()-1)}multipointIsSimpleAsFeature(){if(!this.checkStructure())return 0;const e=this.m_geometry.getImpl();this.m_multiVertexGeom=e;const t=e.getPointCount(),s=new Array(t);for(let i=0;i<t;i++)s[i]=i;s.sort(((e,t)=>this.compareVerticesMultiPoint(e,t)));for(let i=1;i<t;i++)if(0===this.compareVerticesMultiPoint(s[i-1],s[i]))return this.m_nonSimpleResult=new Xe(5,s[i-1],s[i]),0;return 1}polylineIsSimpleAsFeature(){return this.checkStructure()&&this.checkDegenerateSegments(!0)?1:0}polygonIsSimpleAsFeature(){return this.isSimplePlanarImpl()}multipointSimplifyAsFeature(){let e=this.m_geometry.getImpl();const t=vs.hasNanZs(e);let s,i=this.m_geometry;t&&(s=this.m_geometry.clone(),e=s.getImpl(),s.replaceNaNs(1,y.getDefaultValue(1)),i=s),this.m_multiVertexGeom=e;const r=e.getPointCount(),n=new Array(r);for(let l=0;l<r;l++)n[l]=l;n.sort(((e,t)=>this.compareVerticesMultiPoint(e,t)));const h=new Array(r);h.fill(!1);let a=-1;for(let l=0;l<r;l++){const t=n[l];e.getXY(t).isFinite()&&((a<0||0!==this.compareVerticesMultiPoint(a,t))&&(h[t]=!0),a=t)}const o=this.m_geometry.createInstance();let m=0,g=0;for(let l=0;l<r;l++)h[l]?g=l+1:(m<g&&o.addPoints(i,m,g),m=l+1);return m<g&&o.addPoints(i,m,g),o.getImpl().setIsSimple(1,this.m_toleranceSimplify.total()),o}polylineSimplifyAsFeature(){const e=this.m_geometry.getImpl(),t=e.querySegmentIterator(),s=e.querySegmentIterator(),i=this.m_geometry.createInstance(),r=this.m_geometry,n=e.hasAttribute(1),h=n?E(this.m_sr,e,!0).total():0,a=[],o=[];let m=null;n&&(m=e.getAttributeStreamRef(1));const g=new P,l=e.hasNonLinearSegments(),_=this.m_toleranceSimplify.total();for(;t.nextPath();){if(s.nextPath(),e.getPathSize(t.getPathIndex())<2)continue;if(l&&e.hasNonLinearSegmentsPath(t.getPathIndex())){this.removeDegenerateSegmentsFromCurvedPath(e,t.getPathIndex(),h,i);continue}s.resetToLastSegment();let d=0,p=0,u=!0,c=!0;for(;t.hasNextSegment();){this.progress_();const i=t.nextSegment(),r=s.previousSegment();if(t.getStartPointIndex()>s.getStartPointIndex())break;if(u){const s=t.getStartPointIndex();e.getXY(s).isNAN()||(u=!1,a.push(s))}if(c){const t=s.getEndPointIndex();e.getXY(t).isNAN()||(o.push(t),c=!1)}if(!u){const s=a.at(-1),r=t.getEndPointIndex();if(r-s>1){const t=new F;t.setSub(e.getXY(s),e.getXY(r)),d=t.length()}else d=i.calculateLength2D();if(d>_)a.push(r),d=0;else if(n){let e=m.read(s);Number.isNaN(e)&&(e=0);let t=m.read(r);Number.isNaN(t)&&(t=0),Math.abs(t-e)>h&&(a.push(r),d=0)}}if(!c){const t=o.at(-1),i=s.getStartPointIndex();if(i-t>1){const s=new F;s.setSub(e.getXY(t),e.getXY(i)),p=s.length()}else p=r.calculateLength2D();if(p>_)o.push(i),p=0;else if(n){let e=m.read(t);Number.isNaN(e)&&(e=0);let s=m.read(i);Number.isNaN(s)&&(s=0),Math.abs(s-e)>h&&(o.push(i),p=0)}}}if(a.length>0&&o.length>0&&(a.at(-1)<o.at(-1)?a.length>o.length?a.pop():o.pop():(a.at(-1)===o.at(-1)||o.pop(),o.pop())),o.length+a.length>=2){let e=!1;for(let t=0,s=a.length;t<s;t++)r.getPointByVal(a[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);for(let t=o.length-1;t>0;t--)r.getPointByVal(o[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);r.isClosedPath(t.getPathIndex())?i.closePathWithLine():o.length>0&&(r.getPointByVal(o[0],g),i.lineToPoint(g))}a.length=0,o.length=0}return n&&i.replaceNaNs(1,0),i.getImpl().setIsSimple(1,_),i}polygonSimplifyAsFeature(){return this.simplifyPlanar()}simplifyPlanar(){if(1===this.m_geometry.getFillRule()&&!N(this.m_knownSimpleResult))return Us(this.m_geometry,this.m_toleranceSimplify,!0,!1,this.m_knownSimpleResult,this.m_progressTracker,0,!0);const e=new I;if(e.addGeometry(this.m_geometry),this.m_geometry.hasAttribute(1)&&e.replaceNaNs(1,0),e.removeNaNVertices(),0!==e.getTotalPointCount()){let t=null,s=0,r=0;if(e.hasCurves()){t=new xs;const i=n.constructEmpty();this.m_geometry.queryEnvelope(i);const h=us(this.m_toleranceSimplify.total(),i);s=cs(this.m_toleranceSimplify.total()),r=fs(h,s),ms(e,h,this.m_toleranceSimplify.total(),12e3,t,null,this.m_progressTracker)}if(!N(this.m_knownSimpleResult)){Dt(e,this.m_toleranceSimplify.add(r),this.m_progressTracker,!0,!1)}this.m_geometry.getGeometryType()===i.enumPolygon&&Jt(e,e.getFirstGeometry(),this.m_knownSimpleResult,!1,-1,this.m_progressTracker),null!==t&&t.stitchCurves(e,e.getFirstGeometry(),s,!0)}const t=e.getGeometry(e.getFirstGeometry());return t.getGeometryType()===i.enumPolygon&&(t.getImpl().updateOGCFlagsProtected(),t.setFillRule(0)),t.getImpl().setIsSimple(4,this.m_toleranceSimplify.total()),t}progress_(){}static hasNanZs(e){if(e.hasAttribute(1)){const t=e.getAttributeStreamRef(1);for(let s=0,i=e.getPointCount();s<i;s++){const e=t.read(s);if(Number.isNaN(e))return!0}}return!1}compareVerticesForPlanarClustering(e,t,s){if(e===t)return 0;const i=this.m_pairs[e],r=this.m_pairs[t],n=i>>1,h=r>>1,a=this.m_xy.readPoint2D(2*n);a.y+=1&i?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const o=this.m_xy.readPoint2D(2*h);o.y+=1&r?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const m=a.compare(o);if(0===m&&s){const e=this.m_pathsForOGCTests[n]-this.m_pathsForOGCTests[h];return v(e)}return m}compareVerticesMultiPoint(e,t){if(e===t)return 0;const s=this.m_multiVertexGeom.getXY(e),i=this.m_multiVertexGeom.getXY(t),r=!s.isFinite(),n=!i.isFinite();if(r||n)return r<n?-1:r>n?1:0;if(s.y<i.y)return-1;if(s.y>i.y)return 1;if(s.x<i.x)return-1;if(s.x>i.x)return 1;for(let h=1;h<this.m_attributeCount;h++){const s=this.m_description.getSemantics(h),i=y.getComponentCount(s);for(let r=0;r<i;r++){const i=this.m_multiVertexGeom.getAttributeAsDbl(s,e,r),n=this.m_multiVertexGeom.getAttributeAsDbl(s,t,r),h=b(i,n);if(0!==h)return h}}return 0}edgeAngleCompare(e,t){if(e===t)return 0;const s=e.m_segment.getTangent(e.getReversed()?1:0);e.getReversed()&&s.negateThis();const i=t.m_segment.getTangent(t.getReversed()?1:0);t.getReversed()&&i.negateThis();const r=s.getQuarter(),n=i.getQuarter();if(n===r){const e=s.crossProduct(i);return e<0?1:e>0?-1:0}return r<n?-1:1}}class bs{getOperatorType(){return 10103}accelerateGeometry(e,t,s){return!1}canAccelerateGeometry(e){return!1}supportsCurves(){return!1}isSimpleAsFeature(e,s,i,r,n){const h=Is(e,s,i,r,n);return t(e.getGeometryType(),h)}executeMany(e,t,s,i){return new ws(e,t,s,i)}execute(e,t,s,i){const r=new Ue([e]);return this.executeMany(r,t,s,i).next()}}class ws{constructor(e,t,i,r){this.m_progressTracker=r,this.m_bForceSimplify=i,this.m_index=-1,e||s(""),this.m_inputGeometryCursor=e,this.m_spatialReference=t}next(){const e=this.m_inputGeometryCursor.next();return e?(this.m_index=this.m_inputGeometryCursor.getGeometryID(),this.simplify(e)):null}getGeometryID(){return this.m_index}tock(){return!1}getRank(){return 1}simplify(e){if(e||s(""),e.getGeometryType()===i.enumGeometryCollection){const t=w.generateGeometryCursor(e,-1),s=(new bs).executeMany(t,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker),i=e.createInstance();for(let e=s.next();null!=e;e=s.next())i.addGeometry(e);return i}return Ss(e,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker)}}function Vs(e,t,s,i){s>0&&ht(e,s,t,!1,i);new Ts(i).executeImpl_(e,t)}function Hs(e,t,s){return{vertex0:e,vertex1:t,dir:s}}class Ts{constructor(e){this.m_shape=null,this.m_spikes=[],this.m_points=new c(0),this.m_pointsIndex=-1,this.m_dissolvedEdges=0,this.m_progressTracker=e}executeImpl_(t,s){if(this.m_shape=t,t.getPathCount(s)<2&&t.getPointCount(s)<6)return;this.m_points.resize(0);for(let e=t.getFirstPath(s);e!==H;e=t.getNextPath(e)){let s=t.getFirstVertex(e);for(let i=0,r=t.getPathSize(e);i<r;i++,s=t.getNextVertex(s))this.m_points.add(s)}this.m_pointsIndex=t.createUserIndex();for(let e=0,l=this.m_points.size();e<l;++e)t.setUserIndex(this.m_points.read(e),this.m_pointsIndex,e);t.sortVerticesSimpleByY(this.m_points,0,this.m_points.size());let i=this.m_points.read(0);const r=t.getXY(i);let n=1,h=0;const a=[];for(let e=1;e<this.m_points.size();e++){const s=this.m_points.read(e);if(s===H)continue;if(-1===t.getUserIndex(s,this.m_pointsIndex))continue;const o=t.getXY(s);if(o.isEqualPoint2D(r))n++;else{if(n>1){for(let s=h;s<e;s++){const e=this.m_points.read(s);if(-1===t.getUserIndex(e,this.m_pointsIndex))continue;const i=t.getNextVertex(e),n=t.getPrevVertex(e);if(e!==i&&!t.isEqualXYPoint2D(i,r)){const t=Hs(e,i,1);a.push(t)}if(e!==n&&n!==i&&!t.isEqualXYPoint2D(n,r)){const t=Hs(e,n,-1);a.push(t)}}a.length>0&&this.processBunch_(a,r)}i=s,r.assign(o),n=1,h=e}}if(0===this.m_dissolvedEdges)return t.removeUserIndex(this.m_pointsIndex),void(this.m_pointsIndex=-1);let o=t.getPointCount(s);for(let e=0;e<this.m_points.size();e++){const s=this.m_points.read(e);if(s===H)continue;if(-1!==t.getUserIndex(s,this.m_pointsIndex)){t.setUserIndex(s,this.m_pointsIndex,-1);continue}const i=t.getPathFromVertex(s);t.getFirstVertex(i)===s&&t.setFirstVertex(i,H),t.freeVertex(s),this.m_points.write(e,H),o--}const m=t.createPathUserIndex();let g=t.getPathCount(s);for(let l=0,_=this.m_points.size();l<_;++l){if(this.m_points.read(l)===H)continue;let i=this.m_points.read(l);if(-1!==t.getUserIndex(i,this.m_pointsIndex))continue;let r=t.getPathFromVertex(i),n=-1;if(2===t.getPathUserIndex(r,m)){r=H;for(let e=t.getNextVertex(i);e!==i;e=t.getNextVertex(e)){const s=t.getPathFromVertex(e);if(2!==t.getPathUserIndex(s,m)){r=s,i=e;break}}r===H&&(r=t.insertPath(s,H),t.setClosedPath(r,!0),g++),e(r!==H)}t.setPathUserIndex(r,m,2),n=t.getFirstVertex(r);let h=0,a=!1,o=i;do{n===o&&(a=!0),t.setUserIndex(o,this.m_pointsIndex,1);const e=t.getPathFromVertex(o);e!==r&&(2!==t.getPathUserIndex(e,m)&&(t.setPathUserIndex(e,m,1),t.setFirstVertex(e,H)),t.setPathToVertex(o,r)),h++,o=t.getNextVertex(o)}while(o!==i);a||t.setFirstVertex(r,i),t.setPathSize(r,h)}for(let e=t.getFirstPath(s);e!==H;){const s=t.getNextPath(e);1!==t.getPathUserIndex(e,m)&&t.getFirstVertex(e)!==H||(t.removePathOnly(e),g--),e=s}t.setGeometryVertexCount(s,o),t.setGeometryPathCount(s,g),t.removePathUserIndex(m),t.removeUserIndex(this.m_pointsIndex),this.m_pointsIndex=-1,t.dbgVerifyVertexCounts(),t.filterClosePoints(0,!0,!1,!1,s)}processBunch_(e,t){e.sort(((e,s)=>{const i=this.m_shape.getXY(e.vertex1).sub(t),r=this.m_shape.getXY(s.vertex1).sub(t),n=F.compareVectors(i,r);return 0===n?e.dir<s.dir?-1:1:n}));let s=0;const i=this.m_shape.getXY(e[0].vertex1);let r=1;const n=this.m_shape.hasCurves();for(let h=1,a=e.length;h<a;h++){const t=this.m_shape.getXY(e[h].vertex1);if(!(t.isEqualPoint2D(i)&&(r++,h+1<a))){if(2===r){const t=e[s],i=e[s+1],r=t.dir;if(r!==i.dir){let e=!0;if(n&&(e=!this.m_shape.isCurve(1===t.dir?t.vertex0:t.vertex1)&&!this.m_shape.isCurve(1===i.dir?i.vertex0:i.vertex1)),e){if(1===r){const e=t.vertex0,s=i.vertex0;this.m_shape.setNextVertex(e,s),this.m_shape.setPrevVertex(s,e),this.m_shape.getPrevVertex(e)===s&&(this.m_shape.setUserIndex(e,this.m_pointsIndex,-1),this.m_shape.setUserIndex(s,this.m_pointsIndex,-1));const r=t.vertex1,n=i.vertex1;this.m_shape.setPrevVertex(r,n),this.m_shape.setNextVertex(n,r),this.m_shape.getNextVertex(r)===n&&(this.m_shape.setUserIndex(r,this.m_pointsIndex,-1),this.m_shape.setUserIndex(n,this.m_pointsIndex,-1))}else{const e=t.vertex0,s=i.vertex0;this.m_shape.setPrevVertex(e,s),this.m_shape.setNextVertex(s,e),this.m_shape.getNextVertex(e)===s&&(this.m_shape.setUserIndex(e,this.m_pointsIndex,-1),this.m_shape.setUserIndex(s,this.m_pointsIndex,-1));const r=t.vertex1,n=i.vertex1;this.m_shape.setNextVertex(r,n),this.m_shape.setPrevVertex(n,r),this.m_shape.getPrevVertex(r)===n&&(this.m_shape.setUserIndex(r,this.m_pointsIndex,-1),this.m_shape.setUserIndex(n,this.m_pointsIndex,-1))}this.m_dissolvedEdges+=2}}}i.assign(t),s=h,r=1}}e.length=0}}var ks=u,Fs=h,Gs=B;function Bs(t){switch(t){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 0:return 0;default:e(0,"unrecognized cut side")}return 3}function Ds(){return{unsplitBehavior:0,allCrossRoadsImpassable:!1,ogcRule:!1}}function As(t,s,i,r,n,h,a){return e(0),{}}function Us(e,t,s,i,r,n,h,a){return new Qs(n).planarSimplifyImpl_(e,t,s,i,r,n,h,a)}function Os(t,s,i,r){return e(0),{}}function Ys(t,s,i,r,n,h,a){return e(0),{}}function Xs(t,s,i,r){return e(0),{}}function qs(e,t,s){return Zs(e,t,s)}function Rs(t,s,i){return e(0),{}}function Ms(e,t,s,r){const h=n.constructEmpty();e.queryEnvelope(h);const a=n.constructEmpty();t.queryEnvelope(a);const o=n.constructEmpty();o.setCoords({env2D:h}),o.mergeEnvelope2D(a);const m=T(s,o,!0),g=new n(a),l=d(m);if(g.inflateCoords(l,l),!h.isIntersecting(g)){if(e.getDimension()<=t.getDimension())return js(Ks(e.createInstance()),e,t,"&");if(e.getDimension()>t.getDimension())return js(Ks(t.createInstance()),e,t,"&")}const _=new Qs(r),p=new I,u=p.addGeometry(Ks(e)),c=p.addGeometry(Ks(t));let f=0,x=0,E=null;if(p.hasCurves()){E=new xs;const e=p.getEnvelope2D(r);x=cs(m.total());const t=us(m.total(),e);f=fs(t,x),ms(p,t,m.total(),12e3,E,null,r)}_.setEditShapeCrackAndCluster(p,m.add(f));const S=_.intersection(u,c);null!==E&&E.stitchCurves(p,S,x,!0);const C=js(p.getGeometry(S),e,t,"&");return ks(C.getGeometryType())&&(C.getImpl().setIsSimple(4,m.total()),C.getGeometryType()===i.enumPolygon&&C.getImpl().updateOGCFlagsProtected()),C}function Ls(e,t,s,r){const h=new Array(3),a=n.constructEmpty();e.queryEnvelope(a);const o=n.constructEmpty();t.queryEnvelope(o);const m=n.constructEmpty();m.setCoords({env2D:a}),m.mergeEnvelope2D(o);const g=T(s,m,!0),l=new n(o),_=d(g);if(l.inflateCoords(_,_),!a.isIntersecting(l)){if(e.getDimension()<=t.getDimension()){const s=js(Ks(e.createInstance()),e,t,"&");return h[s.getDimension()]=s,h}if(e.getDimension()>t.getDimension()){const s=js(Ks(t.createInstance()),e,t,"&");return h[s.getDimension()]=s,h}}const p=new Qs(r),u=new I,c=u.addGeometry(Ks(e)),f=u.addGeometry(Ks(t));let x=0,E=0,S=null;if(u.hasCurves()){S=new xs;const e=u.getEnvelope2D(r);E=cs(g.total());const t=us(g.total(),e);x=fs(t,E),ms(u,t,g.total(),12e3,S,null,r)}p.setEditShapeCrackAndCluster(u,g.add(x)),u.dbgVerifyCurves();const C=p.intersectionEx(c,f);for(const n of C){null!==S&&S.stitchCurves(u,n,E,!1);const s=js(u.getGeometry(n),e,t,"&");ks(s.getGeometryType())&&(s.getImpl().setIsSimple(4,g.total()),s.getGeometryType()===i.enumPolygon&&s.getImpl().updateOGCFlagsProtected()),h[s.getDimension()]=s}return null!==S&&S.clearStitcher(u),h}function zs(e,t,i,r,n,h=!1){0===t&&s("not enough geometries to dissolve");let a=0;for(let s=0,u=t;s<u;s++)a=Math.max(e[s].getDimension(),a);if(2===a||1===a)return new Qs(r).dissolveMultiPaths_(a,!1,e,t,i,n,h);let o=0,m=-1;for(let s=0,u=t;s<u;s++)e[s].getDimension()===a&&(-1===m&&(m=s),e[s].isEmpty()||(m=s,o++));if(o<2)return Ks(e[m]);const g=V.constructEmpty(),l=new I;let _=H;for(let s=0,u=t;s<u;s++)if(e[s].getDimension()===a&&!e[s].isEmpty()){_===H?_=l.addGeometry(Ks(e[s])):l.appendGeometry(_,Ks(e[s]));const t=V.constructEmpty();e[s].queryLooseEnvelope(t),g.mergeEnv3D(t)}const d=T(i,g.getEnvelope2D(),!0),p=new Qs(r);if(h){const e=k(i,g.getEnvelopeZs(),!0);return p.planarSimplify3DImpl_(l,d,e,0,!0)}return p.m_bOGCOutput=!0,p.planarSimplifyMultiPoints(l,d,!1,-1)}function Ws(e,t,i,r,n,h=!1){t<2&&s("not enough geometries to dissolve");let a=0;for(let s=0,c=t;s<c;s++)a=Math.max(e[s].getDimension(),a);if(2===a||1===a)return new Qs(r).dissolveMultiPaths_(a,!0,e,t,i,n,h);const o=V.constructEmpty(),m=new I;let g=H,l=0,_=-1;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===a&&(-1===_&&(_=s),!e[s].isEmpty())){_=s,g===H?g=m.addGeometry(Ks(e[s])):m.appendGeometry(g,Ks(e[s]));const t=V.constructEmpty();e[s].queryLooseEnvelope(t),o.mergeEnv3D(t),l++}if(l<2)return Ks(e[_]);const d=0===a?i:null,p=T(d,o.getEnvelope2D(),!0),u=new Qs(r);if(h){const e=k(d,o.getEnvelopeZs(),!0);return u.m_bOGCOutput=!0,u.planarSimplify3DImpl_(m,p,e,0,!0)}return u.planarSimplifyMultiPoints(m,p,!0,-1)}class Qs{constructor(e){this.m_topoGraph=null,this.m_maskLookup=[],this.m_dummyPt1=F.getNAN(),this.m_dummyPt2=F.getNAN(),this.m_fromEdgeForPolylines=H,this.m_progressCounter=0,this.m_bOGCOutput=!1,this.m_progressTracker=e}setEditShape(e,t=!1){null===this.m_topoGraph&&(this.m_topoGraph=new $e),this.m_topoGraph.setEditShape(e,this.m_progressTracker,!0,t)}setEditShapeCrackAndCluster(e,t){Dt(e,t,this.m_progressTracker,!0,!1);for(let s=e.getFirstGeometry();s!==H;s=e.getNextGeometry(s))e.getGeometryType(s)===i.enumPolygon&&Jt(e,s,-1,this.m_bOGCOutput,H,this.m_progressTracker);this.setEditShape(e)}setHalfEdgeOrientations_(e,t){const s=this.m_topoGraph.getShape();for(let i=s.getFirstGeometry();i!==H;i=s.getNextGeometry(i))if(i===t)for(let t=s.getFirstPath(i);t!==H;t=s.getNextPath(t)){let i=s.getFirstVertex(t);if(i===H)continue;let r=s.getNextVertex(i);for(;r!==H;){const t=this.m_topoGraph.getClusterFromVertex(i),n=this.m_topoGraph.getClusterFromVertex(r),h=this.m_topoGraph.getHalfEdgeConnector(t,n);if(h!==H){const t=this.m_topoGraph.getHalfEdgeTwin(h);this.m_topoGraph.setHalfEdgeUserIndex(h,e,1),this.m_topoGraph.setHalfEdgeUserIndex(t,e,2)}i=r,r=s.getNextVertex(i)}}}flushVertices_(e,t){const s=this.m_topoGraph.getShape(),i=s.hasSegmentParentage(),r=new G,n=s.insertPath(e,H);t.push(t[0]);const h=t.length;let a=H;for(let o=0;o<h;o++){const e=t[o];if(a=s.addVertex(n,e),!i)continue;const m=this.m_topoGraph.getClusterFromVertex(e);if(o>0&&this.m_topoGraph.isBreakNode(m)&&s.setSegmentParentageBreakVertex(a,!0),o<h-1){const e=this.m_topoGraph.getHalfEdgeConnector(m,this.m_topoGraph.getClusterFromVertex(t[o+1])),i=this.m_topoGraph.getSegmentParentage(e);s.setSegmentParentageAndBreak(a,i,o>0||this.m_topoGraph.isBreakNode(m)),this.m_topoGraph.isHalfEdgeCurve(e)&&(this.m_topoGraph.querySegmentXY(e,r),s.setSegmentToIndex(s.getVertexIndex(a),r.get().clone()))}}if(i){const e=this.m_topoGraph.getClusterFromVertex(t[h-1]);this.m_topoGraph.isBreakNode(e)&&s.setSegmentParentageBreakVertex(a,!0)}s.setClosedPath(n,!0)}processPolygonCuts_(e,t,s,r){const n=this.m_topoGraph.getGeometryID(s),h=this.m_topoGraph.getGeometryID(r),a=[],o=this.m_topoGraph.getShape(),m=this.m_topoGraph.createUserIndexForHalfEdges();for(let g=this.m_topoGraph.getFirstCluster();g!==H;g=this.m_topoGraph.getNextCluster(g)){const s=this.m_topoGraph.getClusterHalfEdge(g);if(s===H)continue;let r=s;do{if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,m)){let s=r,g=r,l=!1,_=0;do{if(this.m_topoGraph.setHalfEdgeUserIndex(s,m,1),!l){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){this.m_topoGraph.getHalfEdgeFaceParentage(s)&n&&(g=s,l=!0)}}if(l){const t=this.m_topoGraph.getHalfEdgeOrigin(s),i=this.m_topoGraph.getClusterVertexIterator(t),r=this.m_topoGraph.getVertexFromVertexIterator(i);if(a.push(r),-1!==e){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){_|=this.m_topoGraph.getHalfEdgeUserIndex(s,e)}}}s=this.m_topoGraph.getHalfEdgeNext(s)}while(s!==g);if(l&&this.m_topoGraph.getChainArea(this.m_topoGraph.getHalfEdgeChain(g))>0){const e=o.createGeometry(i.enumPolygon);this.flushVertices_(e,a),-1!==t&&o.setGeometryUserIndex(e,t,_)}a.length=0}r=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(r))}while(r!==s)}this.m_topoGraph.deleteUserIndexForHalfEdges(m)}cutPolygonPolyline_(e,t,s,i){this.m_topoGraph.removeSpikes_();let r=-1;-1!==e&&(r=this.m_topoGraph.createUserIndexForHalfEdges(),this.setHalfEdgeOrientations_(r,s)),this.processPolygonCuts_(r,e,t,s),-1!==r&&(this.m_topoGraph.deleteUserIndexForHalfEdges(r),r=-1);const n=this.m_topoGraph.getShape();for(let h=n.getFirstGeometry();h!==H;h=n.getNextGeometry(h))h!==t&&h!==s&&i.push(h);i.sort(((e,t)=>{const s=n.getFirstPath(e),i=n.getRingArea(s),r=n.getFirstPath(t),h=n.getRingArea(r);return i<h?-1:i>h?1:0}))}cut(e,t,s,i,r){const n=this.m_topoGraph.getShape().getGeometryType(s),h=this.m_topoGraph.getShape().getGeometryType(i),a=B(n),m=B(h);if(2!==a||1!==m)if(1!==a||1!==m)o("");else{new $s(this,e,t,s,i,r).Do()}else this.cutPolygonPolyline_(t,s,i,r)}progress_(e=!1){}isGoodParentage(e){return e>=0&&e<this.m_maskLookup.length&&this.m_maskLookup[e]}normalizeInputGeometry(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(h(t)){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}return t!==i.enumMultiPoint&&t!==i.enumPolyline&&t!==i.enumPolygon&&s("Unexpected geometry type"),e}dissolveNonSimplePolygons(t,s,i,r){e(s>0);const n=new I;let h=0,a=-1;for(let e=0,o=s;e<o;e++)2===t[e].getDimension()&&(-1===a&&(a=e),t[e].isEmpty()||(h++,n.addGeometry(t[e])));return 0===h?(e(a>=0),this.normalizeInputGeometry(t[a])):this.planarSimplifyPolygons(n,i,!0,!1,-1,!0)}dissolveMultiPaths_(t,s,r,o,m,l,_){e(t>=1&&t<=2),e(o>0);const p=8&l?1:2,c=V.constructEmpty();let f=0,x=-1,E=!0;for(let e=0,n=o;e<n;e++)if(r[e].getDimension()===t&&(-1===x&&(x=e),!r[e].isEmpty())){x=e,f++;const s=V.constructEmpty();if(r[e].queryLooseEnvelope(s),c.mergeEnv3D(s),2===t&&E&&r[e].getGeometryType()===i.enumPolygon)if(16&l){const t=[0],s=r[e].getImpl().getIsSimple(0,t),i=this.m_bOGCOutput?5===s:g(s);E&&=i}else{const t=U(r[e],0);E&&=t}}if(f<2&&(e(x>=0),0===f||!(16&l)))return this.normalizeInputGeometry(r[x]);if(!E){const e=T(s?null:m,c.getEnvelope2D(),!0);return this.dissolveNonSimplePolygons(r,o,e,l)}const S=r.slice(0,o),C=T(m,c.getEnvelope2D(),!0),P=10*d(C);let y=new pe(0,0);if(_&&(y=k(m,c.getEnvelopeZs(),!0)),1===f&&1===t&&2===p&&!s)return _?Ys(r[0],C,y,this.m_progressTracker,p,!0,this.m_bOGCOutput):this.m_bOGCOutput?As(S[x],C,!1,-1,this.m_progressTracker):Us(S[x],C,!1,!1,-1,this.m_progressTracker,p,!1);const v=new O;v.startConstruction();let b=2===t?3:4,w=0;for(let a=0,d=o;a<d;a++){if(S[a].getDimension()!==t||S[a].isEmpty())continue;let r=S[a].getGeometryType();if(r!==i.enumEnvelope){if(h(r)?(S[a]=this.normalizeInputGeometry(S[a]),r=i.enumPolyline):e(u(r)),1===t){e(r===i.enumPolyline);let t=-1;if(_)e(0,"3d not implemented yet");else{const e=[0];t=S[a].getImpl().getIsSimple(C.total(),e)}if(this.m_bOGCOutput?5!==t:!g(t))if(s)b=-1;else{_?e(0,"3d not implemented yet"):this.m_bOGCOutput?S[a]=As(S[a],C,!1,-1,this.m_progressTracker):S[a]=Us(S[a],C,!1,!1,-1,this.m_progressTracker,p,!1);const t=[0];e(g(S[a].getImpl().getIsSimple(C.total(),t)))}}else{e(r===i.enumPolygon);const t=[0],s=S[a].getImpl().getIsSimple(0,t);e(N(s))}const o=S[a].getImpl();for(let e=0,t=o.getPathCount();e<t;e++){const t=n.constructEmpty();o.queryLoosePathEnvelope(e,t),t.inflateCoords(P,P),v.addEnvelope(w,t),w++}}else{e(r===i.enumEnvelope);const t=n.constructEmpty();S[a].queryLooseEnvelope(t),t.inflateCoords(P,P),v.addEnvelope(w,t),w++,b=-1}}v.endConstruction();const F=w,G=Y(F,-2147483647),B=Y(F,-1);let A=0;x=-1,w=0;for(let n=0,h=o;n<h;n++){if(S[n].getDimension()!==t)continue;if(-1===x&&(x=n),S[n].isEmpty())continue;x=n,A++;const s=S[n].getGeometryType();if(u(s)){for(let e=0,t=S[n].getPathCount();e<t;e++)B[w]=n,G[w]=-e-1,w++}else e(s===i.enumEnvelope),B[w]=n,G[w]=-1,w++}if(A<2&&2===t)return e(x>=0),this.normalizeInputGeometry(S[x]);let q=F;for(;v.next()&&q>0;){this.progress_();const e=v.getHandleA(),t=v.getHandleB(),s=v.getElement(e),i=v.getElement(t);B[s]!==B[i]&&(G[s]<0&&(q--,G[s]=-(G[s]+1)),G[i]<0&&(q--,G[i]=-(G[i]+1)))}const R=new I;let M=!1,L=0;for(let n=0,h=o;n<h;n++){if(S[n].getDimension()!==t||S[n].isEmpty())continue;const s=S[n].getGeometryType(),r=L;let h=0,o=0;const m=u(s)?S[n]:null;for(let e=r,t=G.length;e<t&&B[e]===n;e++)G[e]>=0&&(h++,o+=m?m.getPathSize(G[e]):X(S[n])),L++;if(o>.95*X(S[n])){R.addGeometry(this.normalizeInputGeometry(S[n]));for(let e=r;e<L;e++)G[e]<0&&(G[e]=-(G[e]+1))}else{if(0===h){M=!0;continue}{M=!0,e(u(s)),e(null!=m);const t=new D({vd:S[n].getDescription()}),h=new a({vd:S[n].getDescription()}),o=s===i.enumPolygon?t:h;for(let e=r;e<L;e++)G[e]>=0&&o.addPath(m,G[e],!0);R.addGeometry(o)}}}let z;if(R.getFirstGeometry()!==H){const e=2===t,i=s?T(null,c.getEnvelope2D(),!0):C;let r=new pe(0,0);if(_&&(r=s?k(null,c.getEnvelopeZs(),!0):y),2===t&&!(2&l)){R.collapseAllGeometriesToFirst();let e=0,t=null;if(R.hasCurves()&&!R.hasSegmentParentage()){t=new xs;const s=R.getEnvelope2D(this.m_progressTracker);e=cs(i.total());ms(R,us(i.total(),s),i.total(),12e3,t,null,this.m_progressTracker)}Vs(R,R.getFirstGeometry(),i.total(),this.m_progressTracker),null!==t&&t.stitchCurves(R,H,e,!0)}if(_)z=this.planarSimplify3DImpl_(R,i,r,p,!0);else if(2===t)z=this.planarSimplifyPolygons(R,i,e,s,-1,!1);else{const e=Ds();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=p,z=this.planarSimplifyPolylines(R,i,s,e,-1)}if(!M){const e=[0];b=z.getImpl().getIsSimple(i.total(),e)}}else e(M),e(x>=0),z=2===t?new D({vd:S[x].getDescription()}):new a({vd:S[x].getDescription()});if(M){let t=0;for(let e=0,s=G.length;e<s;e++){const s=B[e];if(!(s<0)&&G[e]<0){const i=S[s].getGeometryType(),r=u(i)?S[s]:null;if(r){const s=-(G[e]+1);t+=r.getPathSize(s)}else t+=4}}z.reserve(z.getPointCount()+t);for(let s=0,r=G.length;s<r;s++){const t=B[s];if(!(t<0)&&G[s]<0){const r=S[t].getGeometryType(),n=u(r)?S[t]:null;if(n){const e=-(G[s]+1);z.addPath(n,e,!0)}else r===i.enumEnvelope?z.addEnvelope(S[t],!1):(e(h(r)),z.addSegment(S[t],!0))}}}let W=0;if(2===t?-1!==b&&(b=3,W=s?0:C.total()):(e(1===t),s||-1===b||(W=C.total())),_||z.getImpl().setIsSimple(b,W),!s&&M)if(2===t){if(!_)return(new bs).execute(z,m,!1,this.m_progressTracker);e(0,"3d not yet implemented")}else 1===t&&1!==p&&(z=_?Xs(this.m_bOGCOutput,z,p,this.m_progressTracker):Os(this.m_bOGCOutput,z,p,this.m_progressTracker),z.getImpl().setIsSimple(b,W));return z}dissolveTopoGraphCommonEdges_(){const e=this.m_topoGraph.createUserIndexForHalfEdges(),t=[];for(let s=this.m_topoGraph.getFirstCluster();s!==H;s=this.m_topoGraph.getNextCluster(s)){const i=this.m_topoGraph.getClusterHalfEdge(s);let r=i;if(i!==H)do{this.progress_();if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,e)){const s=this.m_topoGraph.getHalfEdgeTwin(r);this.m_topoGraph.setHalfEdgeUserIndex(s,e,1),this.m_topoGraph.setHalfEdgeUserIndex(r,e,1);const i=this.m_topoGraph.getHalfEdgeFaceParentage(r);if(this.isGoodParentage(i)){const e=this.m_topoGraph.getHalfEdgeFaceParentage(s);this.isGoodParentage(e)&&t.push(r)}}r=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(r))}while(r!==i)}this.m_topoGraph.deleteUserIndexForHalfEdges(e),this.m_topoGraph.deleteEdgesBreakFaces_(t)}chooseVertexByOrder(t,s,i,r){let n=fe(),h=H;for(let e=this.m_topoGraph.getClusterVertexIterator(t);e!==H;e=this.m_topoGraph.incrementVertexIterator(e)){const t=this.m_topoGraph.getVertexFromVertexIterator(e),r=s.getUserIndex(t,i);r>=0&&r<n&&(n=r,h=t)}e(h!==H);let a=s.getUserIndex(h,r);return a>0&&(s.setUserIndex(h,r,--a),0===a&&s.setUserIndex(h,i,-1)),h}chooseVertexFromCluster_(e,t){return this.m_topoGraph.getVertexDominantFromCluster(e,t)}chooseVertexFromVertexCluster_(e,t){return this.m_topoGraph.getVertexDominant(e,t)}collectPolygonPathsPreservingFrom_(e,t,s,r,n){const h=this.m_topoGraph.getShape();if(h.getGeometryType(e)!==i.enumPolygon)return;const a=h.hasSegmentParentage(),o=new G;for(let i=h.getFirstPath(e);i!==H;i=h.getNextPath(i)){const e=h.getFirstVertex(i);this.m_topoGraph.getClusterFromVertex(e);const m=this.m_topoGraph.getHalfEdgeFromVertex(e);if(m===H)continue;const g=this.m_topoGraph.getHalfEdgeUserIndex(m,s);if(1===g||2===g)continue;const l=this.m_topoGraph.getHalfEdgeFaceParentage(m);if(!this.isGoodParentage(l)){this.m_topoGraph.setHalfEdgeUserIndex(m,s,2);continue}this.m_topoGraph.setHalfEdgeUserIndex(m,s,1);const _=h.insertPath(t,H);h.setClosedPath(_,!0);let d=m,p=e,u=this.m_topoGraph.getClusterFromVertex(p),c=1;do{this.progress_();const e=this.chooseVertexFromVertexCluster_(p,n),t=h.addVertex(_,e);if(this.m_topoGraph.isHalfEdgeCurve(d)&&(this.m_topoGraph.querySegmentXY(d,o),h.setSegmentToIndex(h.getVertexIndex(t),o.get().clone())),a){const e=this.m_topoGraph.getSegmentParentage(d);h.setSegmentParentageAndBreak(t,e,this.m_topoGraph.isBreakNode(u))}let i,m;-1!==r&&this.m_topoGraph.setClusterUserIndex(u,r,1),this.m_topoGraph.setHalfEdgeUserIndex(d,s,1),d=this.m_topoGraph.getHalfEdgeNext(d);do{i=1===c?h.getNextVertex(p):h.getPrevVertex(p),m=i!==H?this.m_topoGraph.getClusterFromVertex(i):H}while(m===u);const g=this.m_topoGraph.getHalfEdgeOrigin(d);if(g!==m){do{i=1===c?h.getPrevVertex(p):h.getNextVertex(p),m=i!==H?this.m_topoGraph.getClusterFromVertex(i):H}while(m===u);if(g!==m){m=g;const e=this.m_topoGraph.getClusterVertexIterator(m);i=this.m_topoGraph.getVertexFromVertexIterator(e)}else c=-c}u=m,p=i}while(d!==m)}}topoOperationPolygonPolygonHelper_(e,t,s,i,r,n){this.progress_(!0),e!==H&&this.collectPolygonPathsPreservingFrom_(e,s,r,n,i),t!==H&&this.collectPolygonPathsPreservingFrom_(t,s,r,n,i);const h=new G,a=this.m_topoGraph.getShape();a.dbgVerifyCurves();const o=a.hasSegmentParentage();for(let m=this.m_topoGraph.getFirstCluster();m!==H;m=this.m_topoGraph.getNextCluster(m)){const e=this.m_topoGraph.getClusterHalfEdge(m);if(e===H)continue;let t=e;do{this.progress_();const e=this.m_topoGraph.getHalfEdgeUserIndex(t,r);if(1!==e&&2!==e){const e=this.m_topoGraph.getHalfEdgeFaceParentage(t);if(this.isGoodParentage(e)){const e=a.insertPath(s,H);a.setClosedPath(e,!0);let m=t;do{const t=this.m_topoGraph.getHalfEdgeVertexIterator(m);let s=H;if(t!==H)s=this.m_topoGraph.getVertexFromVertexIterator(t);else{const e=this.m_topoGraph.getHalfEdgeVertexIterator(this.m_topoGraph.getHalfEdgeTwin(m));s=this.m_topoGraph.getVertexFromVertexIterator(e),s=a.getNextVertex(s)}const g=this.chooseVertexFromVertexCluster_(s,i),l=a.addVertex(e,g);if(o){const e=this.m_topoGraph.getSegmentParentage(m),t=this.m_topoGraph.getHalfEdgeOrigin(m);a.setSegmentParentageAndBreak(l,e,this.m_topoGraph.isBreakNode(t))}if(this.m_topoGraph.isHalfEdgeCurve(m)&&(this.m_topoGraph.querySegmentXY(m,h),a.setSegmentToIndex(a.getVertexIndex(l),h.get().clone())),this.m_topoGraph.setHalfEdgeUserIndex(m,r,1),-1!==n){const e=this.m_topoGraph.getClusterFromVertex(g);this.m_topoGraph.setClusterUserIndex(e,n,1)}m=this.m_topoGraph.getHalfEdgeNext(m)}while(m!==t)}else this.m_topoGraph.setHalfEdgeUserIndex(t,r,2)}t=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(t))}while(t!==e)}}topoOperationPolygonPolygon_(e,t,s,r=!1){this.dissolveTopoGraphCommonEdges_();const n=this.m_topoGraph.getShape(),h=n.createGeometry(i.enumPolygon),a=this.m_topoGraph.createUserIndexForHalfEdges();return this.topoOperationPolygonPolygonHelper_(e,t,h,s,a,-1),this.m_topoGraph.deleteUserIndexForHalfEdges(a),r||Jt(n,h,3,this.m_bOGCOutput,H,this.m_progressTracker),h}topoOperationPolyline_(e,t){const s=Ds();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(H,e,!1,s).first}topoOperationMultiPoint_(){return e(0),0}intersection(t,s){const i=this.m_topoGraph.getShape().getGeometryType(t),r=this.m_topoGraph.getShape().getGeometryType(s),n=B(i),h=B(r),a=this.m_topoGraph.getGeometryID(t),m=this.m_topoGraph.getGeometryID(s);e(a>=0),e(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=H;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=t),2===n&&2===h?this.topoOperationPolygonPolygon_(t,s,g):1===n&&h>0||1===h&&n>0?this.topoOperationPolyline_(g,this.m_bOGCOutput):0===n||0===h?this.topoOperationMultiPoint_():void o("")}topoOperationPolygonPolygonEx(e,t,s){const r=this.m_topoGraph.getShape(),n=r.createGeometry(i.enumPolygon),h=r.createGeometry(i.enumPolyline),a=r.createGeometry(i.enumMultiPoint);this.dissolveTopoGraphCommonEdges_();let o=H;const m=this.m_topoGraph.createUserIndexForHalfEdges(),g=this.m_topoGraph.createUserIndexForClusters();r.dbgVerifyCurves(),this.topoOperationPolygonPolygonHelper_(e,t,n,s,m,g),r.dbgVerifyCurves();const l=r.hasSegmentParentage(),_=new G;for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){const e=this.m_topoGraph.getClusterHalfEdge(i);if(e===H)continue;let t=e;do{let e=this.m_topoGraph.getHalfEdgeUserIndex(t,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m),a=e|n;if(2===a){let o=this.m_topoGraph.getHalfEdgeParentage(t);if(this.isGoodParentage(o)){const d=r.insertPath(h,H);let p=t;const u=this.chooseVertexFromCluster_(i,s);let c=r.addVertex(d,u);if(l){const e=this.m_topoGraph.getSegmentParentage(t),s=this.m_topoGraph.getHalfEdgeOrigin(t);r.setSegmentParentageAndBreak(c,e,this.m_topoGraph.isBreakNode(s))}this.m_topoGraph.isHalfEdgeCurve(t)&&(this.m_topoGraph.querySegmentXY(t,_),r.setSegmentToIndex(r.getVertexIndex(c),_.get().clone())),this.m_topoGraph.setClusterUserIndex(i,g,1);do{this.progress_();const i=this.m_topoGraph.getHalfEdgeTo(p),h=this.chooseVertexFromCluster_(i,s);if(c=r.addVertex(d,h),l){const e=this.m_topoGraph.getSegmentParentage(t),s=this.m_topoGraph.getHalfEdgeOrigin(t);r.setSegmentParentageAndBreak(c,e,this.m_topoGraph.isBreakNode(s))}if(this.m_topoGraph.setHalfEdgeUserIndex(p,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m,1),this.m_topoGraph.setClusterUserIndex(i,g,1),p=this.m_topoGraph.getHalfEdgeNext(p),e=this.m_topoGraph.getHalfEdgeUserIndex(p,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m),a=e|n,2!==a)break;if(o=this.m_topoGraph.getHalfEdgeParentage(p),!this.isGoodParentage(o)){this.m_topoGraph.setHalfEdgeUserIndex(p,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m,1);break}this.m_topoGraph.isHalfEdgeCurve(t)&&p!==t&&(this.m_topoGraph.querySegmentXY(t,_),r.setSegmentToIndex(r.getVertexIndex(c),_.get().clone()))}while(p!==t)}else this.m_topoGraph.setHalfEdgeUserIndex(t,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m,1)}t=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(t))}while(t!==e)}for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){this.progress_();if(1===this.m_topoGraph.getClusterUserIndex(i,g))continue;const e=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(e)){o===H&&(o=r.insertPath(a,H));const e=this.m_topoGraph.getClusterVertexIterator(i);let t=H;if(e!==H){t=this.m_topoGraph.getVertexFromVertexIterator(e);const i=this.chooseVertexFromVertexCluster_(t,s);r.addVertex(o,i)}}}this.m_topoGraph.deleteUserIndexForClusters(g),this.m_topoGraph.deleteUserIndexForHalfEdges(m),r.dbgVerifyCurves(),Jt(r,n,3,this.m_bOGCOutput,H,this.m_progressTracker);const d=[H,H,H];return d[0]=a,d[1]=h,d[2]=n,d}topoOperationPolylinePolylineOrPolygonEx(e,t){const s=Ds();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(H,e,!0,s)}topoOperationMultiPoint(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,H);for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=H;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==H;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===H&&(t=i);const r=e.getGeometryFromPath(e.getPathFromVertex(i)),n=this.m_topoGraph.getGeometryID(r);if(this.isGoodParentage(n)){t=i;break}}e.addVertex(s,t)}}return t}intersectionEx(t,s){const i=this.m_topoGraph.getShape().getGeometryType(t),r=this.m_topoGraph.getShape().getGeometryType(s),n=Gs(i),h=Gs(r),a=this.m_topoGraph.getGeometryID(t),m=this.m_topoGraph.getGeometryID(s);e(a>=0),e(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=H;if(this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=t),2===n&&2===h)return this.topoOperationPolygonPolygonEx(t,s,g);if(1===n&&h>0||1===h&&n>0){const{first:e,second:t}=this.topoOperationPolylinePolylineOrPolygonEx(g,this.m_bOGCOutput);return[t,e]}if(0===n||0===h){const e=[];return e.push(this.topoOperationMultiPoint()),e}o("")}getCombinedHalfEdgeParentage(e){return this.m_topoGraph.getHalfEdgeParentage(e)|this.m_topoGraph.getHalfEdgeFaceParentage(e)|this.m_topoGraph.getHalfEdgeFaceParentage(this.m_topoGraph.getHalfEdgeTwin(e))}prevailingDirection(e,t){const s=this.getCombinedHalfEdgeParentage(t),i=this.m_topoGraph.getHalfEdgeOrigin(t),r=this.m_topoGraph.getHalfEdgeTo(t);let n=0,h=0;for(let a=this.m_topoGraph.getClusterVertexIterator(i);a!==H;a=this.m_topoGraph.incrementVertexIterator(a)){const i=this.m_topoGraph.getVertexFromVertexIterator(a),o=e.getPathFromVertex(i),m=e.getGeometryFromPath(o),g=this.m_topoGraph.getGeometryID(m),l=e.getFirstVertex(o),_=!!(g&s);_&&l===i&&(this.m_fromEdgeForPolylines=t);const d=e.getNextVertex(i);if(d!==H&&this.m_topoGraph.getClusterFromVertex(d)===r){if(n++,_){if(this.m_fromEdgeForPolylines===H&&l===d){const e=this.m_topoGraph.getHalfEdgeNext(t);this.isGoodParentage(this.getCombinedHalfEdgeParentage(e))&&(this.m_fromEdgeForPolylines=e)}h++}}else{const s=e.getPrevVertex(i);if(s!==H&&this.m_topoGraph.getClusterFromVertex(s)===r&&(n--,_)){if(this.m_fromEdgeForPolylines===H&&l===s){const e=this.m_topoGraph.getHalfEdgeNext(t);this.isGoodParentage(this.getCombinedHalfEdgeParentage(e))&&(this.m_fromEdgeForPolylines=e)}h--}}}this.m_topoGraph.queryXY(i,this.m_dummyPt1),this.m_topoGraph.queryXY(r,this.m_dummyPt2);return(0!==h?h:n)*F.distance(this.m_dummyPt1,this.m_dummyPt2)}tryMoveThroughCrossroadBackwards(e,t){const s=this.m_topoGraph.getHalfEdgePrev(e),i=this.m_topoGraph.getHalfEdgeTwin(s);if(!t){if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e)))return H;const t=this.m_topoGraph.getHalfEdgeTwin(e);if(i===this.m_topoGraph.getHalfEdgeNext(t))return s}let r=i,n=H;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==H)return H;n=this.m_topoGraph.getHalfEdgeTwin(r)}r=this.m_topoGraph.getHalfEdgeTwin(this.m_topoGraph.getHalfEdgePrev(r))}return n}tryMoveThroughCrossroadForward(e,t){const s=this.m_topoGraph.getHalfEdgeNext(e),i=this.m_topoGraph.getHalfEdgeTwin(s);if(!t){const t=this.m_topoGraph.getHalfEdgeTwin(e);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(t)))return H;if(i===this.m_topoGraph.getHalfEdgePrev(t))return s}let r=i,n=H;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==H)return H;n=this.m_topoGraph.getHalfEdgeTwin(r)}r=this.m_topoGraph.getHalfEdgeTwin(this.m_topoGraph.getHalfEdgeNext(r))}return n}isOnALoop(e,t){let s=e;const i=2*this.m_topoGraph.getShape().getTotalPointCount()+10;for(let r=0;r<i;r++){if(1===this.m_topoGraph.getHalfEdgeUserIndex(s,t))return!1;const i=this.m_topoGraph.getHalfEdgeNext(s);if(i===this.m_topoGraph.getHalfEdgeTwin(s))return!1;if(s=i,s===e)return!0}o("is_on_a_loop_")}restorePolylineParts(t,s,i,r,n,h,a,o,m,g){e(n===H&&h>=0&&a>=0||-1===h&&-1===a),e(-1===o&&1!==g.unsplitBehavior||-1!==o&&1===g.unsplitBehavior);const l=g.ogcRule,_=g.allCrossRoadsImpassable,d=1===g.unsplitBehavior,p=0===g.unsplitBehavior;g.unsplitBehavior;const u=this.m_topoGraph.getShape(),c=u.hasSegmentParentage();let f=t,x=this.m_topoGraph.getHalfEdgeTwin(f);const E=new G;this.m_fromEdgeForPolylines=H;let I=this.prevailingDirection(u,f),S=f,C=H,P=!1,y=!1,N=!1;if(!d)for(;;){const e=this.m_topoGraph.getHalfEdgePrev(f);if(e===x){N=!0;break}const s=this.m_topoGraph.getHalfEdgeNext(x);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(s))){P=!0;break}if(this.m_topoGraph.getHalfEdgeTwin(e)!==s){if(_){P=!0;break}if(f=this.tryMoveThroughCrossroadBackwards(f,!0),f===H){P=!0;break}x=this.m_topoGraph.getHalfEdgeTwin(f)}else f=e,x=s;if(1===this.m_topoGraph.getHalfEdgeUserIndex(f,i)){N=!0;break}if(f===t){C=t,y=!0;break}const r=this.getCombinedHalfEdgeParentage(f);if(!this.isGoodParentage(r))break;S=f,I+=this.prevailingDirection(u,f)}if(C===H){for(f=t,x=this.m_topoGraph.getHalfEdgeTwin(f),C=f;;){const e=this.m_topoGraph.getHalfEdgeNext(f),t=this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e));if(t){P=!0;break}if(e===x){N=!0;break}if(-1!==o){const e=this.m_topoGraph.getHalfEdgeOrigin(x);if(1===this.m_topoGraph.getClusterUserIndex(e,o)){P=!0;break}}const s=this.m_topoGraph.getHalfEdgePrev(x);if(this.m_topoGraph.getHalfEdgeTwin(e)!==s){if(t||_){P=!0;break}if(f=this.tryMoveThroughCrossroadForward(f,!0),f===H){P=!0;break}x=this.m_topoGraph.getHalfEdgeTwin(f)}else f=e,x=s;if(1===this.m_topoGraph.getHalfEdgeUserIndex(f,i)){N=!0;break}const r=this.getCombinedHalfEdgeParentage(f);if(!this.isGoodParentage(r))break;C=f,I+=this.prevailingDirection(u,f)}const e=this.m_topoGraph.getHalfEdgeOrigin(S);y=this.m_topoGraph.getHalfEdgeTo(C)===e}else if(this.m_fromEdgeForPolylines!==H){S=t,C=this.tryMoveThroughCrossroadBackwards(S,!1),e(C!==H);const s=this.m_topoGraph.getHalfEdgeTwin(S);this.m_topoGraph.getHalfEdgeNext(s)}let v=y;y||N||m&&(v=this.isOnALoop(t,i),v||(v=this.isOnALoop(x,i)));const b=I>=0;let w=!1;v&&P&&(y?(w=l,b&&(w||d||p)&&S!==t&&(e(!d),S=t,w=!1)):(d||b&&p)&&(S=t));let V=0;for(f=S;x=this.m_topoGraph.getHalfEdgeTwin(f),this.m_topoGraph.setHalfEdgeUserIndex(f,i,1),this.m_topoGraph.setHalfEdgeUserIndex(x,i,1),V++,f!==C;)f=_?this.m_topoGraph.getHalfEdgeNext(f):this.tryMoveThroughCrossroadForward(f,!1);b||(C=q(S,S=C),C=this.m_topoGraph.getHalfEdgeTwin(C),S=this.m_topoGraph.getHalfEdgeTwin(S));let T=u.insertPath(s,H);f=S;const k=this.m_topoGraph.getHalfEdgeOrigin(S);let F;F=-1!==h?this.chooseVertexByOrder(k,u,h,a):this.chooseVertexFromCluster_(k,n),this.m_topoGraph.isStrongPathNode(k)&&u.setStrongPathStart(T,!0);let B=u.addVertex(T,F),D=B;-1!==r&&this.m_topoGraph.setClusterUserIndex(k,r,1);let A=0;const U=w?(V+1)/2:-1;let O=H,Y=!0,X=H;for(;;){if(c){const e=this.m_topoGraph.getSegmentParentage(f),t=this.m_topoGraph.getHalfEdgeOrigin(f);u.setSegmentParentageAndBreak(D,e,Y||this.m_topoGraph.isBreakNode(t))}Y=!1,this.m_topoGraph.isHalfEdgeCurve(f)&&(this.m_topoGraph.querySegmentXY(f,E),u.setSegmentToIndex(u.getVertexIndex(D),E.get().clone())),O!==H&&-1!==a&&u.addToUserIndex(O,a,-1);const e=_?this.m_topoGraph.getHalfEdgeNext(f):this.tryMoveThroughCrossroadForward(f,!1),t=this.m_topoGraph.getHalfEdgeTo(f);let i;if(i=-1!==h?this.chooseVertexByOrder(t,u,h,a):this.chooseVertexFromCluster_(t,n),B=u.addVertex(T,i),X=t,-1!==r&&this.m_topoGraph.setClusterUserIndex(t,r,1),c&&this.m_topoGraph.isBreakNode(t)&&u.setSegmentParentageBreakVertex(B,!0),O=i,A++,w&&A===U&&(T=u.insertPath(s,H),B=u.addVertex(T,i),Y=!0,-1!==a&&u.addToUserIndex(i,a,-1),O=H),f===C)break;f=e,D=B}X!==H&&this.m_topoGraph.isStrongPathNode(X)&&u.setStrongPathEnd(T,!0)}topoOperationPolylineSimplify_(e,t){return this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}topoOperationPolylineSimplifyOrPolylineTopoHelper_(t,s,r,n){e(s===H||t===H);const h=this.m_topoGraph.getShape(),a=e=>e=t===H?e===H?h.getFirstGeometry():h.getNextGeometry(e):e===H?t:H,o=h.createGeometry(i.enumPolyline);let m=-1;r&&(m=this.m_topoGraph.createUserIndexForClusters());const g=this.m_topoGraph.createUserIndexForHalfEdges(),l=s===H?h.createUserIndex():-1,_=s===H?h.createUserIndex():-1;let d=-1;if(1===n.unsplitBehavior){d=this.m_topoGraph.createUserIndexForClusters();for(let e=a(H);e!==H;e=a(e))for(let t=h.getFirstPath(e);t!==H;t=h.getNextPath(t)){{const e=h.getFirstVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,d,1)}if(!h.isClosedPath(t)){const e=h.getLastVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,d,1)}}}if(s===H){let e=0;for(let t=a(H);t!==H;t=a(t))for(let s=h.getFirstPath(t);s!==H;s=h.getNextPath(s)){if(h.isClosedPath(s)){let t=h.getFirstVertex(s);for(let i=0,r=h.getPathSize(s);i<r;i++,t=h.getNextVertex(t))h.setUserIndex(t,l,e++),h.setUserIndex(t,_,2)}else{const t=h.getFirstVertex(s);h.setUserIndex(t,l,e++),h.setUserIndex(t,_,1);let i=h.getNextVertex(t);for(let r=1,n=h.getPathSize(s)-1;r<n;++r)h.setUserIndex(i,l,e++),h.setUserIndex(i,_,2),i=h.getNextVertex(i);h.setUserIndex(i,l,e++),h.setUserIndex(i,_,1)}}}for(let e=a(H);e!==H;e=a(e))for(let t=h.getFirstPath(e);t!==H;t=h.getNextPath(t)){let e=h.getFirstVertex(t);for(let i=0,r=h.getPathSize(t);i<r;i++,e=h.getNextVertex(e)){const t=this.m_topoGraph.getHalfEdgeFromVertex(e);if(t===H)continue;if(1===this.m_topoGraph.getHalfEdgeUserIndex(t,g))continue;const r=this.getCombinedHalfEdgeParentage(t);if(this.isGoodParentage(r)){const e=0===i;this.restorePolylineParts(t,o,g,m,s,l,_,d,e,n)}}}let p=H;if(r){p=h.createGeometry(i.enumMultiPoint);let e=H;for(let t=this.m_topoGraph.getFirstCluster();t!==H;t=this.m_topoGraph.getNextCluster(t)){this.progress_();if(1!==this.m_topoGraph.getClusterUserIndex(t,m)){const i=this.m_topoGraph.getClusterParentage(t);if(this.isGoodParentage(i)){e===H&&(e=h.insertPath(p,H));const i=this.m_topoGraph.getClusterVertexIterator(t);if(i!==H){let r;this.m_topoGraph.getVertexFromVertexIterator(i),r=-1!==l?this.chooseVertexByOrder(t,h,l,_):this.chooseVertexFromCluster_(t,s),h.addVertex(e,r)}}}}}return-1!==_&&h.removeUserIndex(_),-1!==l&&h.removeUserIndex(l),-1!==m&&h.removeUserIndex(m),this.m_topoGraph.deleteUserIndexForHalfEdges(g),R(o,p)}difference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=B(s),n=B(i);if(r>n)return e;const h=this.m_topoGraph.getGeometryID(e),a=this.m_topoGraph.getGeometryID(t);if(this.m_maskLookup.length=0,this.m_maskLookup.length=1+(h|a),this.m_maskLookup[h]=!0,2===r&&2===n){let s=H;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(s=e),this.topoOperationPolygonPolygon_(e,t,s)}if(1===r&&2===n){const t=Ds();return t.allCrossRoadsImpassable=!1,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}if(1===r&&1===n){const t=Ds();return t.allCrossRoadsImpassable=!0,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}if(0===r)return this.topoOperationMultiPoint_();o("")}planarSimplifyNoCrackingAndCluster(t,s,i,r){return e(0),!1}unsplitPolylineExact(t){return e(0),new a}planarSimplifyPolylines(t,s,r,n,h){for(let p=t.getFirstGeometry();p!==H;p=t.getNextGeometry(p)){const s=t.getGeometryType(p);e(s===i.enumPolyline)}let a=0,o=0,m=null;if(t.hasCurves()&&!t.hasSegmentParentage()){m=new xs;const e=t.getEnvelope2D(this.m_progressTracker);o=cs(s.total());const i=us(s.total(),e);a=fs(i,o),ms(t,i,s.total(),12e3,m,null,this.m_progressTracker)}{const e=Ut(s.add(a));t.filterClosePoints(e,!1,!1,!1,H)}if(this.m_topoGraph=new $e,4!==h&&5!==h)if(null===m&&r){const e=new vt(this.m_progressTracker,!1);e.sweepVertical(t,s.total()),e.hadComplications()?(Dt(t,s,this.m_progressTracker,!0,!1),r=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(s.total())}else Dt(t,s.add(a),this.m_progressTracker,!0,!1),r=!1;else r=!1;t.removeSelection(),t.collapseAllGeometriesToFirst();const g=t.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,g,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(r&&null===m),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolylines(t,s,!1,n,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const l=this.m_topoGraph.getGeometryID(g);e(l>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=l+1,this.m_maskLookup[l]=!0;const _=this.topoOperationPolylineSimplify_(t.getFirstGeometry(),n);null!==m&&m.stitchCurves(t,_,o,!0);const d=t.getGeometry(_);return r||d.getImpl().setIsSimple(4,s.total()),d}planarSimplifyMultiPoints(t,s,r,n){for(let g=t.getFirstGeometry();g!==H;g=t.getNextGeometry(g)){const s=t.getGeometryType(g);e(s===i.enumMultiPoint)}this.m_topoGraph=new $e,4!==n&&5!==n?(Dt(t,s,this.m_progressTracker,!0,!1),r=!1):r=!1,t.removeSelection(),t.collapseAllGeometriesToFirst();const h=t.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,h,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(r),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyMultiPoints(t,s,!1,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const a=this.m_topoGraph.getGeometryID(h);e(a>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=a+1,this.m_maskLookup[a]=!0;const o=this.topoOperationMultiPoint(),m=t.getGeometry(o);return r||m.getImpl().setIsSimple(4,s.total()),m}planarSimplifyPolygons(t,s,r,n,h,a){for(let f=t.getFirstGeometry();f!==H;f=t.getNextGeometry(f)){const s=t.getGeometryType(f);e(s===i.enumPolygon||s===i.enumPolyline&&r)}let o=0,m=0,g=null;if(t.hasCurves()&&!t.hasSegmentParentage()){g=new xs;const e=t.getEnvelope2D(this.m_progressTracker);m=cs(s.total());const i=us(s.total(),e);o=fs(i,m),ms(t,i,s.total(),12e3,g,null,this.m_progressTracker)}if(a){Dt(t,s.add(o),this.m_progressTracker,!0,!1);for(let e=t.getFirstGeometry();e!==H;e=t.getNextGeometry(e))t.getGeometryType(e)===i.enumPolygon&&Jt(t,e,-1,!1,H,this.m_progressTracker)}if(this.m_topoGraph=new $e,a||4===h||5===h)n=!1;else if(null===g&&n){const e=new vt(this.m_progressTracker,!1);e.sweepVertical(t,s.total()),e.hadComplications()?(Dt(t,s,this.m_progressTracker,!0,!1),n=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(s.total())}else Dt(t,s.add(o),this.m_progressTracker,!0,!1),n=!1;t.removeSelection(),t.collapseAllGeometriesToFirst();const l=t.getFirstGeometry();if(r?this.m_topoGraph.setAndSimplifyEditShapeWinding(t,l,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,l,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(n&&null===g),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolygons(t,s,r,!1,-1,!1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const _=this.m_topoGraph.getGeometryID(l);e(_>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=_+1,this.m_maskLookup[_]=!0,t.setFillRule(l,0);const d=this.m_bOGCOutput&&r,p=d;let u=this.topoOperationPolygonPolygon_(l,H,H,p);if(d){this.m_topoGraph.removeShape(),this.m_topoGraph=null,t.removeGeometry(l),this.m_topoGraph=new $e,this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,u,this.m_progressTracker);u=this.topoOperationPolygonPolygon_(u,H,H,!1)}null!==g&&g.stitchCurves(t,u,m,!0);const c=t.getGeometry(u);return c.setFillRule(0),n?c.getImpl().setIsSimple(3,0):(c.getImpl().setIsSimple(4,s.total()),c.getImpl().updateOGCFlagsProtected()),c}planarSimplify3DImpl_(t,s,i,r,n){return e(0),{}}planarSimplifyImpl_(e,t,s,r,n,h,m,g){if(e.isEmpty())return e.clone();const l=e.getGeometryType(),_=new I,d=_.addGeometry(e);if(N(n)&&l===i.enumPolygon&&(s=!1,_.setFillRule(d,0)),g&&(e.hasAttribute(1)&&_.replaceNaNs(1,0),_.removeNaNVertices()),l===i.enumPolygon||l===i.enumPolyline&&s)return this.planarSimplifyPolygons(_,t,s,r,n,!1);if(l===a.type){const e=Ds();return e.allCrossRoadsImpassable=!0,e.ogcRule=this.m_bOGCOutput,e.unsplitBehavior=m,this.planarSimplifyPolylines(_,t,r,e,n)}if(l===i.enumMultiPoint)return this.planarSimplifyMultiPoints(_,t,r,n);o("what else?")}}function Zs(e,t,s,i){const r=e.createInstance(),n=he(F,100),h=new Array(100),a=e.getPointCount();let m=!0;const g=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&o("");for(let o=0;o<a;){const i=e.queryCoordinates(n,n.length,o,-1)-o;g?is(t,n,i,s.total(),h):rs(t,n,i,s.total());let a=0;for(let t=0;t<i;t++){0===h[t]&&(m&&(m=!1,r.addPoints(e,0,o)),a!==t&&r.addPoints(e,o+a,o+t),a=t+1)}m||a===i||r.addPoints(e,o+a,o+i),o+=i}return m?e:r}function js(e,t,s,r){const n=e.getGeometryType();if(n===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(n===i.enumPoint&&"^"===r){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(n===i.enumLine){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}if(n===i.enumMultiPoint&&"-"===r&&t.getGeometryType()===i.enumPoint){const t=new P({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}if(n===i.enumMultiPoint&&"&"===r&&t.getGeometryType()===i.enumPoint){const t=new P({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}return e}function Ks(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(Fs(t)){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}return t!==i.enumMultiPoint&&t!==i.enumPolyline&&t!==i.enumPolygon&&s("Unexpected geometry type"),e}function Js(t,s,i,r){const n=i===H?t.getClusterHalfEdge(s):i;let h=n;e(t.getHalfEdgeOrigin(n)===s);do{r(h),h=t.getHalfEdgeNext(t.getHalfEdgeTwin(h))}while(h!==n)}class $s{constructor(e,t,s,i,r,n){this.m_rParent=e,this.m_rTopoGraph=e.m_topoGraph,this.m_rShape=this.m_rTopoGraph.getShape(),this.m_IDCuttee=this.m_rTopoGraph.getGeometryID(i),this.m_IDCutter=this.m_rTopoGraph.getGeometryID(r),this.m_IDBoth=this.m_IDCuttee|this.m_IDCutter,this.m_bConsiderTouch=t,this.m_sideIndex=s,this.m_cuttee=i,this.m_cutter=r,this.m_rCutHandles=n,this.m_cutteeBreadcrumbsIndex=this.m_rShape.createUserIndexUninitialized(),this.m_clusterParentageIndex=this.m_rShape.createUserIndexUninitialized();for(let h=this.m_rShape.getFirstPath(this.m_cuttee);h!==H;h=this.m_rShape.getNextPath(h)){let e=0;const t=this.m_rShape.getPathSize(h);for(let s=this.m_rShape.getFirstVertex(h);e<t;e++,s=this.m_rShape.getNextVertex(s))this.m_rShape.setUserIndex(s,this.m_clusterParentageIndex,this.m_rTopoGraph.getClusterParentage(this.m_rTopoGraph.getClusterFromVertex(s)))}}Do(){this.cutPolylinePolyline_(),this.m_rShape.removeUserIndex(this.m_cutteeBreadcrumbsIndex),this.m_rShape.removeUserIndex(this.m_clusterParentageIndex)}setTbd(e){return 8|e}classifyStandardCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),a=n===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),o=this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));let g=1,l=32,_=32;if(Js(this.m_rTopoGraph,t,m,(e=>{e===o&&(g=2),e===h&&(l=g),e===a&&(_=g)})),this.m_bConsiderTouch)32!==l&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),32!==_&&this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|_);else{if(32===l||32===_)return 1;if(l===_&&!(h===o||h===m||a===o||a===m))return 1;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|_)}return 0}classifyTouchCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),a=n===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),o=s===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=i===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));if(!this.m_bConsiderTouch){let t;return(t=o===h||m===h)?this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))):(t=o===a||m===a)&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),t?0:1}if(h===H)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===H)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;if(h===a)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(m!==H){if(h===m)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===m)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=1;Js(this.m_rTopoGraph,t,m,(t=>{if(t===h){const e=this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,e),s=2}else if(t===a){const t=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,t),s=2}}))}else{if(h===o)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===o)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=2;Js(this.m_rTopoGraph,t,o,(t=>{if(t===h){const e=this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,e),s=1}else if(t===a){const t=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,t),s=1}}))}return 0}classifyCutVertex(e,t){let s=0,i=0;for(let r=this.m_rTopoGraph.getClusterVertexIterator(t);r!==H;r=this.m_rTopoGraph.incrementVertexIterator(r)){const n=this.m_rTopoGraph.getVertexFromVertexIterator(r);if(this.m_rShape.getGeometryFromVertex(n)===this.m_cutter){i++;const r=this.m_rShape.getPrevVertex(n),h=this.m_rShape.getNextVertex(n);s+=r===H||h===H?this.classifyTouchCut(e,t,r,h):this.classifyStandardCut(e,t,r,h)}}i&&s===i&&!this.m_bConsiderTouch&&this.m_rShape.setUserIndex(e,this.m_clusterParentageIndex,this.m_IDCuttee)}cutPolylinePolyline_(){this.m_rShape.getGeometryType(this.m_cuttee),this.m_rShape.getGeometryType(this.m_cutter),this.m_rParent.m_maskLookup.length=0,this.m_rParent.m_maskLookup.length=this.m_IDBoth+1,this.m_rParent.m_maskLookup[this.m_IDBoth]=!0;for(let i=this.m_rShape.getFirstPath(this.m_cuttee);i!==H;i=this.m_rShape.getNextPath(i)){const e=this.m_rShape.getPathSize(i);let t=this.m_rShape.getFirstVertex(i);for(let s=0;s<e;++s,t=this.m_rShape.getNextVertex(t))this.m_rShape.setUserIndex(t,this.m_cutteeBreadcrumbsIndex,0);t=this.m_rShape.getFirstVertex(i);for(let s=0;s<e;++s,t=this.m_rShape.getNextVertex(t)){const e=this.m_rTopoGraph.getClusterFromVertex(t);this.m_rTopoGraph.getClusterParentage(e)===this.m_IDBoth&&this.classifyCutVertex(t,e)}}const e=(e,t)=>{let s=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex);const i=this.m_rTopoGraph.getHalfEdgeConnector(this.m_rTopoGraph.getClusterFromVertex(e),this.m_rTopoGraph.getClusterFromVertex(t));return(this.m_rTopoGraph.getHalfEdgeParentage(i)&this.m_IDBoth)===this.m_IDBoth&&(s|=4),s};for(let i=this.m_rShape.getFirstPath(this.m_cuttee);i!==H;i=this.m_rShape.getNextPath(i)){let t=this.m_rShape.getFirstVertex(i);const s=this.m_rShape.isClosedPath(i),r=this.m_rShape.getPathSize(i)+(s?1:0);let n=1,h=32;for(let i=this.m_rShape.getNextVertex(t);n<r;++n,t=i,i=this.m_rShape.getNextVertex(i)){const s=e(t,i);this.m_rShape.getUserIndex(t,this.m_clusterParentageIndex)===this.m_IDBoth&&(h=s),32!==h&&this.m_rShape.setUserIndex(t,this.m_cutteeBreadcrumbsIndex,h|s)}t=this.m_rShape.getLastVertex(i);let a=32;n=1;for(let i=this.m_rShape.getPrevVertex(t);n<r;++n,t=i,i=this.m_rShape.getPrevVertex(i)){const s=e(i,t);this.m_rShape.getUserIndex(t,this.m_clusterParentageIndex)===this.m_IDBoth&&(a=s),32!==a&&this.m_rShape.setUserIndex(i,this.m_cutteeBreadcrumbsIndex,a|s)}}let t=H,s=H,r=32;const n=this.m_rShape.hasSegmentParentage(),h=new G;for(let a=this.m_rShape.getFirstPath(this.m_cuttee);a!==H;a=this.m_rShape.getNextPath(a)){const e=this.m_rShape.isClosedPath(a),o=this.m_rShape.getPathSize(a)+(e?1:0);let m=1,g=this.m_rShape.getFirstVertex(a),l=H,_=!0;for(let a=this.m_rShape.getNextVertex(g);m<o;++m,a=this.m_rShape.getNextVertex(a)){let e=this.m_rShape.getUserIndex(g,this.m_cutteeBreadcrumbsIndex);8===e?e=3:(e&=-9,4&e?e=4:3&~e||(e=3)),e!==r?(t!==H&&(l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),this.m_rCutHandles.push(t),this.m_rShape.setGeometryUserIndex(t,this.m_sideIndex,r)),t=this.m_rShape.createGeometry(i.enumPolyline),s=this.m_rShape.insertPath(t,H),r=e,_=!0):this.m_rShape.getUserIndex(g,this.m_clusterParentageIndex)===this.m_IDBoth&&4!==e&&(l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),s=this.m_rShape.insertPath(t,H),_=!0),l=this.m_rShape.addVertex(s,g);const o=this.m_rTopoGraph.getClusterFromVertex(g);!_&&n&&this.m_rTopoGraph.isBreakNode(o)&&this.m_rShape.setSegmentParentageBreakVertex(l,!0);const m=this.m_rTopoGraph.getHalfEdgeFromVertex(g);if(n){const e=this.m_rTopoGraph.getSegmentParentage(m);this.m_rShape.setSegmentParentageAndBreak(l,e,_||this.m_rTopoGraph.isBreakNode(o))}this.m_rTopoGraph.isHalfEdgeCurve(m)&&(this.m_rTopoGraph.querySegmentXY(m,h),this.m_rShape.setSegmentToIndex(this.m_rShape.getVertexIndex(l),h.get().clone())),g=a,_=!1}l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),this.m_rCutHandles.push(t),this.m_rShape.setGeometryUserIndex(t,this.m_sideIndex,r),t=H,s=H,r=32}}}export{xs as C,bs as O,Qs as T,Bs as a,ms as b,Ls as c,us as d,qs as e,Rs as f,zs as g,Ws as h,Ms as i,es as j,ts as k,Dt as l,Jt as m,$e as n,Ht as o,fs as p,Tt as q,cs as s};
5
+ import{h as e,a3 as t,t as s,G as i,a4 as r,e as n,o as h,b as a,r as o,a5 as m,a6 as g,a7 as l,a8 as _,a9 as d,aa as p,k as u,ab as c,ac as f,q as x,ad as E,g as I,ae as S,af as C,P,ag as y,v as N,ah as v,ai as b,aj as w,ak as V,n as H,D as T,al as k,j as F,H as G,am as B,a as D,M as A,an as U,ao as O,m as Y,ap as X,aq as q,ar as R,as as M,at as L,au as z,av as W,a1 as Q,aw as Z,ax as j,ay as J,az as K,N as $,aA as ee,Q as te,U as se,aB as ie,aC as re,T as ne,F as he,aD as ae,aE as oe,aF as me,L as ge,O as le,aG as _e,aH as de,C as pe,aI as ue,aJ as ce,aK as fe,X as xe,aL as Ee,aM as Ie,aN as Se,aO as Ce,x as Pe,aP as ye,I as Ne,aQ as ve,aR as be,aS as we,aT as Ve,aU as He,aV as Te,aW as ke,aX as Fe,aY as Ge,aZ as Be,a_ as De,a$ as Ae}from"./Polyline.js";import{S as Ue}from"./SimpleGeometryCursor.js";import{a as Oe,b as Ye}from"./Densificator-DB2izaQs.js";class Xe{assign(e){this.m_reason=e.m_reason,this.m_vertexIndex1=e.m_vertexIndex1,this.m_vertexIndex2=e.m_vertexIndex2}constructor(e,t,s){void 0!==e?(this.m_reason=e,this.m_vertexIndex1=t,this.m_vertexIndex2=s):(this.m_reason=0,this.m_vertexIndex1=-1,this.m_vertexIndex2=-2)}clear(){e(0)}}class qe{constructor(e){this.m_currentShift=63n,this.m_currentElt=0n,this.m_iCurrentElt=-1,this.m_parent=e,this.m_aiSetElts=e.getSetIndexes_()}next(){if(this.m_currentShift++,64n===this.m_currentShift){if(this.m_iCurrentElt++,this.m_iCurrentElt===this.m_aiSetElts.length)return qe.npos();this.m_currentShift=0n,this.m_currentElt=this.m_parent.m_bits[this.m_aiSetElts[this.m_iCurrentElt]]}for(;this.m_currentShift<63n&&!(this.m_currentElt&1n<<this.m_currentShift);)this.m_currentShift++;return this.m_currentElt&1n<<this.m_currentShift?64*this.m_aiSetElts[this.m_iCurrentElt]+Number(this.m_currentShift):this.next()}static npos(){return Number.MAX_SAFE_INTEGER}}function Re(e){return 1n<<(0x3fn&BigInt(e))}function Me(e){return e>>6}class Le{constructor(e){this.m_bits=[]}assignMove(){return this}assignCopy(){return this}getSetElts_(){const e=[];return this.m_bits.map((t=>{t&&e.push(t)})),e}getSetIndexes_(){const e=[];return this.m_bits.map(((t,s)=>{t&&e.push(s)})),e}hasBit(e){const t=Re(e),s=Me(e);return void 0!==this.m_bits[s]&&!!(this.m_bits[s]&t)}setBit(e){const t=Re(e),s=Me(e);void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]|=t}clearBit(e){}flipBit(e){const t=Re(e),s=Me(e);return void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]^=t,0n!==(this.m_bits[s]&t)}clear(){this.m_bits.length=0}isZero(){return!1}equals(e){const t=this.getSetElts_(),s=e.getSetElts_();if(t.length!==s.length)return!1;for(let i=0;i<t.length;++i)if(t[i]!==s[i])return!1;return!0}notEquals(e){return!this.equals(e)}assignOr(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]|=e.m_bits[s];return this}assignSubtract(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]&=~e.m_bits[s];return this}assignAnd(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]&=e.m_bits[s];return this}assignXor(e){const t=e.getSetIndexes_();for(const s of t)this.m_bits[s]^=e.m_bits[s];return this}getHashCode(){return this.getSetElts_().reduce(((e,t)=>ue(e,t)),0)}getUnorderedBitIterator(){return new qe(this)}}class ze extends de{constructor(e){super(),this.m_bufferLeft=new G,this.m_bufferRight=new G,this.m_intervalLeft=le.constructEmpty(),this.m_intervalRight=le.constructEmpty(),this.m_yScanline=Number.NaN,this.m_helper=e}compare(e,t,s){const i=t,r=e.getElement(s);this.m_helper.querySegmentXY(i,this.m_bufferLeft),this.m_helper.querySegmentXY(r,this.m_bufferRight);const n=this.m_bufferLeft.get(),h=this.m_bufferRight.get();if(this.m_intervalLeft.setCoords(n.getStartX(),n.getEndX()),this.m_intervalRight.setCoords(h.getStartX(),h.getEndX()),this.m_intervalLeft.vmax<this.m_intervalRight.vmin)return-1;if(this.m_intervalLeft.vmin>this.m_intervalRight.vmax)return 1;const a=n.getStartY()===n.getEndY(),o=h.getStartY()===h.getEndY();if(a||o){if(a&&o)return 0;if(n.getStartY()===h.getStartY()&&n.getStartX()===h.getStartX())return a?1:-1;if(n.getEndY()===h.getEndY()&&n.getEndX()===h.getEndX())return a?-1:1}let m=n.intersectionOfYMonotonicWithAxisX(this.m_yScanline,this.m_intervalLeft.vmin),g=h.intersectionOfYMonotonicWithAxisX(this.m_yScanline,this.m_intervalRight.vmin);if(m===g){const e=n.getEndY(),t=h.getEndY(),s=Math.min(e,t);let i=.5*(s+this.m_yScanline);i===this.m_yScanline&&(i=s),m=n.intersectionOfYMonotonicWithAxisX(i,this.m_intervalLeft.vmin),g=h.intersectionOfYMonotonicWithAxisX(i,this.m_intervalRight.vmin)}return m<g?-1:m>g?1:0}setY(e){this.m_yScanline=e}}class We{constructor(e){this.m_segmentBuffer=new G,this.m_point=F.getNAN(),this.m_parent=e}setPointXY(e){this.m_point.assign(e)}compare(e,t){const s=e.getElement(t);this.m_parent.querySegmentXY(s,this.m_segmentBuffer);const i=this.m_segmentBuffer.get(),r=new le;if(r.setCoords(i.getStartX(),i.getEndX()),this.m_point.x<r.vmin)return-1;if(this.m_point.x>r.vmax)return 1;const n=i.intersectionOfYMonotonicWithAxisX(this.m_point.y,this.m_point.x);return this.m_point.x<n?-1:this.m_point.x>n?1:0}}var Qe,Ze;function je(e,t){return{parentage:e,rank:t}}function Je(e,t){const s=e.length;if(s!==t.length)return!1;const i=e[0].parentage;if(i!==t[0].parentage)return!1;if(-1===i)return!0;for(let r=1;r<s;++r)if(e[r].parentage!==t[r].parentage)return!1;return!0}function Ke(e,t,s){s.length=0;let i=!1;{let r=e.getHalfEdgeVertexIterator(t);for(;r!==H;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(je(h,n)),r=e.incrementVertexIterator(r)}}{let r=e.getHalfEdgeVertexIterator(e.getHalfEdgeTwin(t));for(;r!==H;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(je(h,n)),r=e.incrementVertexIterator(r)}}i&&s.sort(((e,t)=>e.rank>t.rank?-1:e.rank<t.rank?1:e.parentage<t.parentage?-1:e.parentage>t.parentage?1:0)),-1===s[0].parentage&&(s.length=1)}!function(e){e[e.enumInputModeBuildGraph=0]="enumInputModeBuildGraph",e[e.enumInputModeSimplifyAlternate=1]="enumInputModeSimplifyAlternate",e[e.enumInputModeSimplifyWinding=2]="enumInputModeSimplifyWinding"}(Qe||(Qe={})),function(e){e[e.enumSegmentParentageBreakNode=1]="enumSegmentParentageBreakNode",e[e.enumPathBreakNode=2]="enumPathBreakNode"}(Ze||(Ze={}));class $e{constructor(){this.m_shape=null,this.m_clusterData=new M(8),this.m_clusterVertices=new M(2),this.m_firstCluster=H,this.m_lastCluster=H,this.m_halfEdgeData=new M(8),this.m_chainData=new M(8),this.m_chainAreas=null,this.m_chainPerimeters=null,this.m_universeChain=-1,this.m_simplifiedGeometry=-1,this.m_edgeIndices=[],this.m_clusterIndices=[],this.m_chainIndices=[],this.m_bBuildGeometryParentageSets=!1,this.m_chainBitSetIndex=-1,this.m_edgeBitSetIndex=-1,this.m_edgeBitSetIndexLeft=-1,this.m_emptyBitSet=null,this.m_geometryMapID=null,this.m_uniqueBitSets=null,this.m_chainBitSets=[],this.m_edgeBitSets=[],this.m_checkDirtyPlanesweepTolerance=Number.NaN,this.m_geometryIDIndex=-1,this.m_clusterIndex=-1,this.m_halfEdgeIndex=-1,this.m_tmpHalfEdgeParentageIndex=-1,this.m_tmpHalfEdgeParentageIndexLeft=-1,this.m_tmpHalfEdgeWindingNumberIndex=-1,this.m_tmpHalfEdgeOddEvenNumberIndex=-1,this.m_segmentParentageIndex=-1,this.m_segmentIndexHe=-1,this.m_clusterBreakNodeIndex=-1,this.m_universeGeomID=-1,this.m_pointCount=0,this.m_progressCounter=0,this.m_bBuildChains=!0,this.m_bDirtyCheckFailed=!1}setCheckDirtyPlanesweepTolerance(e){this.m_checkDirtyPlanesweepTolerance=e}dirtyCheckFailed(){return this.m_bDirtyCheckFailed}getShape(){return this.m_shape}setEditShape(e,t,s=!0,i=!1){i?this.setEditShapeImpl3D_(e,Qe.enumInputModeBuildGraph,null,t,!1):this.setEditShapeImpl_(e,Qe.enumInputModeBuildGraph,null,t,s)}setAndSimplifyEditShapeAlternate(e,t,s=null,r=!1){const n=[];n.push(t),this.m_simplifiedGeometry=t,r?this.setEditShapeImpl3D_(e,Qe.enumInputModeSimplifyAlternate,n,s,!1):this.setEditShapeImpl_(e,Qe.enumInputModeSimplifyAlternate,n,s,e.getGeometryType(t)===i.enumPolygon)}setAndSimplifyEditShapeWinding(e,t,s=null){const i=[];i.push(t),this.m_simplifiedGeometry=t,this.setEditShapeImpl_(e,Qe.enumInputModeSimplifyWinding,i,s,!0)}removeShape(){null!==this.m_shape&&(-1!==this.m_geometryIDIndex&&(this.m_shape.removeGeometryUserIndex(this.m_geometryIDIndex),this.m_geometryIDIndex=-1),-1!==this.m_clusterIndex&&(this.m_shape.removeUserIndex(this.m_clusterIndex),this.m_clusterIndex=-1),-1!==this.m_halfEdgeIndex&&(this.m_shape.removeUserIndex(this.m_halfEdgeIndex),this.m_halfEdgeIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),-1!==this.m_tmpHalfEdgeWindingNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeWindingNumberIndex),this.m_tmpHalfEdgeWindingNumberIndex=-1),-1!==this.m_tmpHalfEdgeOddEvenNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeOddEvenNumberIndex),this.m_tmpHalfEdgeOddEvenNumberIndex=-1),-1!==this.m_segmentParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_segmentParentageIndex),this.m_segmentParentageIndex=-1),-1!==this.m_segmentIndexHe&&(this.deleteUserIndexForHalfEdges(this.m_segmentIndexHe),this.m_segmentIndexHe=-1),-1!==this.m_clusterBreakNodeIndex&&(this.deleteUserIndexForClusters(this.m_clusterBreakNodeIndex),this.m_clusterBreakNodeIndex=-1),this.deleteEdgeBitSets_(),this.deleteChainBitSets_(),this.m_emptyBitSet=null,this.m_geometryMapID=null,this.m_shape=null,this.m_clusterData.deleteAll(!0),this.m_clusterVertices.deleteAll(!0),this.m_firstCluster=H,this.m_lastCluster=H,this.m_halfEdgeData.deleteAll(!0),this.m_edgeIndices.length=0,this.m_clusterIndices.length=0,this.m_chainIndices.length=0,this.m_chainData.deleteAll(!0),this.m_universeChain=H,this.m_chainAreas=null)}getClusterHalfEdge(e){return this.m_clusterData.getField(e,2)}queryXY(e,t){const s=this.getClusterVertexIndex_(e);t.assign(this.m_shape.getXYWithIndex(s))}queryXYZ(t,s){e(0)}getClusterParentage(e){return this.m_clusterData.getField(e,1)}getFirstCluster(){return this.m_firstCluster}getPrevCluster(e){return this.m_clusterData.getField(e,3)}getNextCluster(e){return this.m_clusterData.getField(e,4)}getClusterChain(e){return this.m_clusterData.getField(e,6)}getClusterVertexIterator(e){return this.m_clusterData.getField(e,7)}incrementVertexIterator(e){return this.m_clusterVertices.getField(e,1)}getVertexFromVertexIterator(e){return this.m_clusterVertices.getField(e,0)}getClusterUserIndex(e,t){const s=this.getClusterIndex_(e),i=this.m_clusterIndices[t];return i.size()<=s?-1:i.read(s)}setClusterUserIndex(e,t,s){const i=this.getClusterIndex_(e),r=this.m_clusterIndices[t];r.size()<=i&&r.resize(this.m_clusterData.size(),-1),r.write(i,s)}hasClusterUserIndexFlags(e,t,s){if(-1===t)return!1;const i=this.getClusterUserIndex(e,t);return-1!==i&&!!(s&i)}setClusterUserIndexFlags(e,t,s){const i=this.getClusterIndex_(e),r=this.m_clusterIndices[t];r.size()<=i&&r.resize(this.m_clusterData.size(),-1);let n=r.read(i);-1===n&&(n=0),r.write(i,s|n)}clearClusterUserIndexFlags(t,s,i){e(0)}createUserIndexForClusters(e=-1){const t=new c(this.m_clusterData.capacity(),e);for(let s=0,i=this.m_clusterIndices.length;s<i;s++)if(null===this.m_clusterIndices[s])return this.m_clusterIndices[s]=t,s;this.m_clusterIndices.push(t);return this.m_clusterIndices.length-1}deleteUserIndexForClusters(e){this.m_clusterIndices[e]=null}getHalfEdgeOrigin(e){return this.m_halfEdgeData.getField(e,1)}getHalfEdgeTo(e){return this.getHalfEdgeOrigin(this.getHalfEdgeTwin(e))}getHalfEdgeTwin(e){return this.m_halfEdgeData.getField(e,4)}getHalfEdgePrev(e){return this.m_halfEdgeData.getField(e,5)}getHalfEdgeNext(e){return this.m_halfEdgeData.getField(e,6)}getHalfEdgeChain(e){return this.m_halfEdgeData.getField(e,2)}getHalfEdgeFaceParentage(e){return this.getChainParentage(this.getHalfEdgeChain(e))}getHalfEdgeVertexIterator(e){return this.m_halfEdgeData.getField(e,7)}getHalfEdgeFromXY(e,t){this.queryXY(this.getHalfEdgeOrigin(e),t)}getHalfEdgeToXY(e,t){this.queryXY(this.getHalfEdgeTo(e),t)}isHalfEdgeCurve(e){if(-1!==this.m_segmentIndexHe){return-1!==this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe)}return!1}getHalfEdgeFromXYZ(t,s){e(0)}getHalfEdgeToXYZ(t,s){e(0)}getHalfEdgeParentage(e){return this.m_halfEdgeData.getField(e,3)&$e.c_EdgeParentageMask}getHalfEdgeUserIndex(e,t){const s=this.getHalfEdgeIndex_(e),i=this.m_edgeIndices[t];return i.size()<=s?-1:i.read(s)}setHalfEdgeUserIndex(e,t,s){const i=this.getHalfEdgeIndex_(e),r=this.m_edgeIndices[t];r.size()<=i&&r.resize(this.m_halfEdgeData.size(),-1),r.write(i,s)}createUserIndexForHalfEdges(t){void 0===t&&(t=-1);const s=new c(this.m_halfEdgeData.capacity(),t);for(let e=0,r=this.m_edgeIndices.length;e<r;e++)if(null===this.m_edgeIndices[e])return this.m_edgeIndices[e]=s,e;this.m_edgeIndices.push(s);const i=this.m_edgeIndices.length-1;return e(i>=0&&i<=Number.MAX_SAFE_INTEGER),i}deleteUserIndexForHalfEdges(e){this.m_edgeIndices[e]=null}deleteEdgesBreakFaces_(e){for(let t=0,s=e.length;t<s;t++){const s=e[t],i=this.getHalfEdgeChain(s),r=this.getHalfEdgeTwin(s),n=this.getHalfEdgeChain(r);this.setChainHalfEdge_(i,H),this.setChainHalfEdge_(n,H),this.updateVertexToHalfEdgeConnection_(s,!0),this.deleteEdgeImpl_(s)}}doesHalfEdgeBelongToAPolygonInterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolygonExterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolygonBoundary(t,s){return e(0),!1}doesHalfEdgeBelongToAPolylineInterior(t,s){return e(0),!1}doesHalfEdgeBelongToAPolylineExterior(t,s){return e(0),!1}doesClusterBelongToAPolygonInterior(t,s){return e(0),!1}doesClusterBelongToAPolygonExterior(t,s){return e(0),!1}doesClusterBelongToAPolygonBoundary(t,s){return e(0),!1}getFirstChain(){return this.m_universeChain}getChainHalfEdge(e){return this.m_chainData.getField(e,1)}getChainParentage(e){return this.m_chainData.getField(e,2)}getChainParent(e){return this.m_chainData.getField(e,3)}getChainFirstIsland(e){return this.m_chainData.getField(e,4)}getChainNextInParent(e){return this.m_chainData.getField(e,5)}getChainNext(e){return this.m_chainData.getField(e,7)}getChainArea(e){const t=this.getChainIndex_(e);let s=this.m_chainAreas.read(t);return Number.isNaN(s)&&(this.updateChainAreaAndPerimeter_(e),s=this.m_chainAreas.read(t)),s}getChainPerimeter(t){return e(0),0}getChainUserIndex(t,s){return e(0),0}setChainUserIndex(t,s,i){e(0)}createUserIndexForChains(){return e(0),0}deleteUserIndexForChains(t){e(0)}extractPolygonFromChainAndIslands(t,s,i,r){return e(0),0}getGeometryID(t){const s=this.m_shape.getGeometryUserIndex(t,this.m_geometryIDIndex);return e(s>=0),1<<Math.min(s,31)}getClusterFromVertex(e){return this.m_shape.getUserIndex(e,this.m_clusterIndex)}getHalfEdgeFromVertex(e){return this.m_shape.getUserIndex(e,this.m_halfEdgeIndex)}buildGeometryParentageSets(){this.m_bBuildGeometryParentageSets=!0}getChainBitSet(t){return e(0),new Le}getChainBoundaryBitSet(t){return e(0),new Le}getChainPolygons(t){return e(0),[]}getGeometriesFromBits(t){return e(0),[]}getVertexDominant(e,t){if(t===H)return e;const s=this.getClusterFromVertex(e);return this.getVertexDominantFromCluster(s,t)}getVertexDominantFromCluster(e,t){if(t!==H){let s=H;for(let i=this.getClusterVertexIterator(e);i!==H;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);s===H&&(s=e);const r=this.m_shape.getPathFromVertex(e);if(this.m_shape.getGeometryFromPath(r)===t){s=e;break}}return s}{const t=this.getClusterVertexIterator(e);if(t!==H){return this.getVertexFromVertexIterator(t)}return H}}isBreakNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode)}setBreakNode(t,s){e(-1!==this.m_clusterBreakNodeIndex),s?this.setClusterUserIndexFlags(t,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode):this.clearClusterUserIndexFlags(t,this.m_clusterBreakNodeIndex,Ze.enumSegmentParentageBreakNode)}isStrongPathNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode)}setStrongPathNode(e,t){if(-1===this.m_clusterBreakNodeIndex){if(!t)return;this.m_clusterBreakNodeIndex=this.createUserIndexForClusters()}t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Ze.enumPathBreakNode)}getSegmentParentage(e){if(-1===this.m_segmentParentageIndex)return-1;const t=this.getHalfEdgeUserIndex(e,this.m_segmentParentageIndex);return t>=0?t:-1}isCrossroadAhead(e){const t=this.getHalfEdgeNext(e);if(this.isStrongPathNode(this.getHalfEdgeOrigin(t)))return!0;const s=this.getHalfEdgeTwin(t),i=this.getHalfEdgeNext(s);return e!==this.getHalfEdgeTwin(i)}isCrossroadBehind(t){return e(0),!1}getHalfEdgeConnector(e,t){const s=this.getClusterHalfEdge(e);if(s===H)return H;let i=s,r=H,n=H;do{if(this.getHalfEdgeTo(i)===t)return i;if(r===H){if(r=this.getClusterHalfEdge(t),r===H)return H;n=r}if(this.getHalfEdgeTo(n)===e)return i=this.getHalfEdgeTwin(n),i;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(i)),n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(i!==s&&n!==r);return H}querySegmentXY(e,t){if(-1!==this.m_segmentIndexHe){let s=this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe);if(-1!==s){if(-2!==s){const e=this.m_shape.getSegmentFromIndex(s);t.copyFrom(e,!0)}else{s=this.getHalfEdgeUserIndex(this.getHalfEdgeTwin(e),this.m_segmentIndexHe);const i=this.m_shape.getSegmentFromIndex(s);t.copyFrom(i,!0),t.get().reverse()}return}}t.createLine();const s=t.get(),i=F.getNAN();this.getHalfEdgeFromXY(e,i),s.setStartXY(i),this.getHalfEdgeToXY(e,i),s.setEndXY(i)}isCurveEdge(e){if(-1!==this.m_segmentIndexHe){return-1!==this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe)}return!1}compareEdgeAnglesCurveHelper_(t,s,i){const r=new G,n=new G;this.querySegmentXY(t,r),this.querySegmentXY(s,n);const h=r.get(),a=n.get();if(h.equals(a))return 0;const o=new F;this.getHalfEdgeFromXY(t,o);const m=new F;this.getHalfEdgeToXY(t,m);const g=new F;this.getHalfEdgeToXY(s,g),e(!m.isEqualPoint2D(g));const l=h.getTangent(0),_=a.getTangent(0);return F.compareVectors(l,_)}compareEdgeAnglesHelper_(e,t,s){if(e===t)return 0;if(this.isHalfEdgeCurve(e)||this.isHalfEdgeCurve(t))return this.compareEdgeAnglesCurveHelper_(e,t,s);const i=F.getNAN();this.getHalfEdgeToXY(e,i);const r=F.getNAN();if(this.getHalfEdgeToXY(t,r),i.isEqualPoint2D(r))return 0;const n=F.getNAN();this.getHalfEdgeFromXY(e,n);const h=F.getNAN();h.setSub(i,n);const a=F.getNAN();if(a.setSub(r,n),!s||a.y>=0&&h.y>0){return F.compareVectors(h,a)}return 0}compareEdgeAngles_(e,t){return this.compareEdgeAnglesHelper_(e,t,!1)}compareEdgeAnglesForPair_(e,t){return this.compareEdgeAnglesHelper_(e,t,!0)}compareEdgeAngles3D_(t,s){return e(0),0}compareEdgeAnglesForPair3D_(t,s){return e(0),0}dbgDumpChains_(){}dbgDumpChainToPolygon_(t,s){e(0)}deleteEdgeInternal_(t){const s=this.getHalfEdgeChain(t),i=this.getHalfEdgeTwin(t),r=this.getHalfEdgeChain(i);e(r===s),e(t===this.getHalfEdgeNext(i)||i===this.getHalfEdgeNext(t));let n=this.getHalfEdgeNext(t);n===i&&(n=this.getHalfEdgeNext(n),n===t&&(n=H));const h=this.getChainIndex_(s),a=this.m_chainAreas.read(h);Number.isNaN(a)||(this.setChainArea_(s,Number.NaN),this.setChainPerimeter_(s,Number.NaN));const o=this.getChainHalfEdge(s);o!==t&&o!==i||this.setChainHalfEdge_(s,n),this.updateVertexToHalfEdgeConnection_(t,!0),this.deleteEdgeImpl_(t)}getFirstUnvisitedHalfEdgeOnCluster_(e,t,s){let i=t!==H?t:this.getClusterHalfEdge(e);if(i===H)return H;const r=i;for(;;){if(1!==this.getHalfEdgeUserIndex(i,s))return i;const e=this.getHalfEdgeNext(this.getHalfEdgeTwin(i));if(e===r)return H;i=e}}removeSpikes_(){let e=!1;const t=this.createUserIndexForHalfEdges();for(let s=this.getFirstCluster();s!==H;s=this.getNextCluster(s)){let i=H;for(;;){let r=this.getFirstUnvisitedHalfEdgeOnCluster_(s,i,t);if(r===H)break;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(r));let n=r;for(;;){const s=this.getHalfEdgeNext(n),h=this.getHalfEdgePrev(n),a=this.getHalfEdgeTwin(n);if(h===a){if(this.deleteEdgeInternal_(n),e=!0,i!==n&&i!==a||(i=H),n===r||h===r){if(r=s,n===r||h===r)break;n=s;continue}}else this.setHalfEdgeUserIndex(n,t,1);if(n=s,n===r)break}}}return this.deleteUserIndexForHalfEdges(t),e}progress_(e,t=!1){}newCluster_(){const e=this.m_clusterData.newElement();return this.m_clusterData.setField(e,1,0),e}newHalfEdgePair_(){const e=this.m_halfEdgeData.newElement();this.m_halfEdgeData.setField(e,2,0),this.m_halfEdgeData.setField(e,3,0);const t=this.m_halfEdgeData.newElement();return this.m_halfEdgeData.setField(t,2,0),this.m_halfEdgeData.setField(t,3,0),this.setHalfEdgeTwin_(e,t),this.setHalfEdgeTwin_(t,e),e}newChain_(){const e=this.m_chainData.newElement();return this.m_chainData.setField(e,2,0),e}deleteChain_(t){return e(0),0}getClusterIndex_(e){return this.m_clusterData.elementToIndex(e)}setClusterVertexIterator_(e,t){this.m_clusterData.setField(e,7,t)}setClusterHalfEdge_(e,t){this.m_clusterData.setField(e,2,t)}setClusterParentage_(e,t){this.m_clusterData.setField(e,1,t)}setPrevCluster_(e,t){this.m_clusterData.setField(e,3,t)}setNextCluster_(e,t){this.m_clusterData.setField(e,4,t)}setClusterVertexIndex_(e,t){this.m_clusterData.setField(e,5,t)}getClusterVertexIndex_(e){return this.m_clusterData.getField(e,5)}setClusterChain_(e,t){this.m_clusterData.setField(e,6,t)}addClusterToExteriorChain_(e,t){this.setClusterChain_(t,e)}getHalfEdgeIndex_(e){return this.m_halfEdgeData.elementToIndex(e)}setHalfEdgeOrigin_(e,t){this.m_halfEdgeData.setField(e,1,t)}setHalfEdgeTwin_(e,t){this.m_halfEdgeData.setField(e,4,t)}setHalfEdgePrev_(e,t){this.m_halfEdgeData.setField(e,5,t)}setHalfEdgeNext_(e,t){this.m_halfEdgeData.setField(e,6,t)}setHalfEdgeChain_(e,t){this.m_halfEdgeData.setField(e,2,t)}setHalfEdgeParentage_(e,t){this.m_halfEdgeData.setField(e,3,t)}getHalfEdgeParentageMask_(e){return this.m_halfEdgeData.getField(e,3)}setHalfEdgeVertexIterator_(e,t){this.m_halfEdgeData.setField(e,7,t)}updateVertexToHalfEdgeConnectionHelper_(e,t){const s=t?H:e;for(let i=this.getHalfEdgeVertexIterator(e);i!==H;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);this.m_shape.setUserIndex(e,this.m_halfEdgeIndex,s)}}updateVertexToHalfEdgeConnection_(e,t){e!==H&&(this.updateVertexToHalfEdgeConnectionHelper_(e,t),this.updateVertexToHalfEdgeConnectionHelper_(this.getHalfEdgeTwin(e),t))}getChainIndex_(e){return this.m_chainData.elementToIndex(e)}setChainHalfEdge_(e,t){this.m_chainData.setField(e,1,t)}setChainParentage_(e,t){this.m_chainData.setField(e,2,t)}setChainParent_(e,t){this.m_chainData.setField(e,3,t);const s=this.getChainFirstIsland(t);this.setChainNextInParent_(e,s),this.setChainFirstIsland_(t,e)}setChainFirstIsland_(e,t){this.m_chainData.setField(e,4,t)}setChainNextInParent_(e,t){this.m_chainData.setField(e,5,t)}setChainPrev_(e,t){this.m_chainData.setField(e,6,t)}setChainNext_(e,t){this.m_chainData.setField(e,7,t)}setChainArea_(e,t){const s=this.getChainIndex_(e);this.m_chainAreas.write(s,t)}setChainPerimeter_(e,t){const s=this.getChainIndex_(e);this.m_chainPerimeters.write(s,t)}updateChainAreaAndPerimeter_(e){const t=this.m_shape.hasCurves(),s=new ce(0),i=new ce(0),r=this.getChainHalfEdge(e),n=F.getNAN(),h=F.getNAN(),a=F.getNAN();this.getHalfEdgeFromXY(r,n),h.setCoordsPoint2D(n);let o=r;do{this.getHalfEdgeToXY(o,a),t&&this.isCurveEdge(o)||i.pe(F.distance(h,a));this.getHalfEdgeChain(this.getHalfEdgeTwin(o))!==e&&s.pe((a.x-n.x-(h.x-n.x))*(a.y-n.y+(h.y-n.y))*.5),h.setCoordsPoint2D(a),o=this.getHalfEdgeNext(o)}while(o!==r);if(t){const t=new G;o=r;do{this.getHalfEdgeToXY(o,a);const r=this.isCurveEdge(o);r&&(this.querySegmentXY(o,t),i.pe(t.get().calculateLength2D()));if(this.getHalfEdgeChain(this.getHalfEdgeTwin(o))!==e&&r){const e=t.get().calculateArea2DHelper();s.pe(e)}o=this.getHalfEdgeNext(o)}while(o!==r)}const m=this.getChainIndex_(e);this.m_chainAreas.write(m,s.getResult()),this.m_chainPerimeters.write(m,i.getResult())}getChainTopmostEdge_(t){return e(0),0}planeSweepParentage_(e,t){const s=new ze(this),i=new _;i.setCapacity(this.m_pointCount/2),i.setComparator(s);const r=[],n=this.createUserIndexForHalfEdges();let h=null;const a=F.getNAN();for(let o=this.getFirstCluster();o!==H;o=this.getNextCluster(o)){this.progress_(t);const m=this.getClusterHalfEdge(o);if(m!==H){if(r.length=0,!this.tryOptimizedInsertion_(i,n,r,o,m)){this.queryXY(o,a),s.setY(a.y);let e=m;do{const t=this.getHalfEdgeUserIndex(e,n);-1!==t&&(i.deleteNode(t),this.setHalfEdgeUserIndex(e,n,M.impossibleIndex2())),e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(m!==e);e=m;do{if(-1===this.getHalfEdgeUserIndex(e,n)){const t=i.addElement(e);r.push(t)}e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(m!==e)}for(let t=r.length-1;t>=0;t--){const s=r[t],h=i.getElement(s),a=this.getHalfEdgeTwin(h);this.setHalfEdgeUserIndex(a,n,s),this.planeSweepParentagePropagateParentage_(i,s,e)}}else if(this.getClusterChain(o)===H){null===h&&(h=new We(this)),this.queryXY(o,a),h.setPointXY(a);const e=i.searchLowerBound(h);let t=this.m_universeChain;if(-1!==e){let s=i.getElement(e);this.getHalfEdgeChain(s)===this.getHalfEdgeChain(this.getHalfEdgeTwin(s))&&(s=this.getLeftSkipPolylines_(i,e)),s!==H&&(t=this.getHalfEdgeChain(s))}this.addClusterToExteriorChain_(t,o)}}this.deleteUserIndexForHalfEdges(n)}planeSweepParentagePropagateParentage_(t,s,i){const r=t.getElement(s),n=this.getHalfEdgeChain(r);if(this.getChainParent(n)!==H)return;const h=this.getLeftSkipPolylines_(t,s),a=this.getHalfEdgeTwin(r),o=this.getHalfEdgeChain(a);let m=this.getChainParent(n),g=this.getChainParent(o);if(h===H)m===H&&(o===n?(this.setChainParent_(o,this.m_universeChain),g=this.m_universeChain,m=g):(g===H&&(this.setChainParent_(o,this.m_universeChain),g=this.m_universeChain),this.setChainParent_(n,o),m=o));else{const e=this.getHalfEdgeChain(h);if(g===H){if(this.getChainArea(e)<=0){const t=this.getChainParent(e);this.setChainParent_(o,t),g=t}else this.setChainParent_(o,e),g=e;o===n&&(m=g)}}m===H&&(this.trySetChainParentFromTwin_(n,o),m=this.getChainParent(n)),e(m!==H),i===Qe.enumInputModeBuildGraph?this.propagateParentageBuildGraph_(t,s,r,h):i===Qe.enumInputModeSimplifyWinding?this.propagateParentageWinding_(t,s,r,h,a,n,o):i===Qe.enumInputModeSimplifyAlternate&&this.propagateParentageAlternate_(t,s,r,h,a,n,o)}propagateParentageBuildGraph_(e,t,s,i){let r,n=t;i===H?(n=e.getNext(n),r=this.getHalfEdgeChain(s)):r=this.getHalfEdgeChain(i);let h=null,a=this.getChainParentage(r);for(this.m_bBuildGeometryParentageSets&&(h=this.getChainBitSet(r));-1!==n;n=e.getNext(n)){const t=e.getElement(n),s=this.getHalfEdgeTwin(t);r=this.getHalfEdgeChain(t);const i=this.getHalfEdgeChain(s);if(this.m_bBuildGeometryParentageSets){let e=this.getChainBitSet(i);e=new Le({copy:e}),e.assignOr(h),this.setChainBitSet_(i,e);let s=this.getChainBitSet(r);const n=this.getLeftEdgeBitSet_(t),a=new Le({copy:h});if(a.assignSubtract(n),a.isZero())break;s=new Le({copy:s}),s.assignOr(a),this.setChainBitSet_(r,s),h=s}const o=this.getChainParentage(i),m=o|a;m!==o&&this.setChainParentage_(i,m);let g=this.getChainParentage(r);const l=a&~this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeParentageIndexLeft);if(l&&(g|=l,this.setChainParentage_(r,g)),0===l)break;a=g}}propagateParentageWinding_(t,s,i,r,n,h,a){if(h===a)return;let o=this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex);o+=this.getHalfEdgeUserIndex(n,this.m_tmpHalfEdgeWindingNumberIndex);let m=0;const g=[],l=[];l.push(0);for(let _=t.getFirst();_!==s;_=t.getNext(_)){const s=t.getElement(_),i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeChain(s),n=this.getHalfEdgeChain(i);if(r!==n){let t=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex);t+=this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),m+=t;let h=!1;0!==g.length&&g.at(-1)===n&&(l.pop(),g.pop(),h=!0),e(this.getChainParent(n)!==H),h&&this.getChainParent(n)===r||(l.push(m),g.push(r))}}if(m+=o,0!==g.length&&g.at(-1)===a&&(l.pop(),g.pop()),0!==m){if(0===l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(h,t)}}else if(0!==l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(h,t)}}propagateParentageAlternate_(t,s,i,r,n,h,a){e(0)}tryOptimizedInsertion_(e,t,s,i,r){let n=r,h=-1,a=H,o=0;do{if(2===o)return!1;const e=this.getHalfEdgeUserIndex(n,t);if(-1!==e){if(-1!==h)return!1;h=e}else{if(a!==H)return!1;a=n}o++,n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(r!==n);return a!==H&&-1!==h&&(this.setHalfEdgeUserIndex(e.getElement(h),t,M.impossibleIndex2()),e.setElement(h,a),s.push(h),!0)}trySetChainParentFromTwin_(e,t){const s=this.getChainArea(e);if(0===s)return!1;const i=this.getChainArea(t);if(s>0&&i<0||s<0&&i>0)return this.setChainParent_(e,t),!0;{const s=this.getChainParent(t);if(s!==H)return this.setChainParent_(e,s),!0}return!1}createHalfEdges_(e,t){this.m_halfEdgeIndex=this.m_shape.createUserIndex();for(let s=0,r=t.size();s<r;s++){const r=t.read(s),n=this.m_shape.getUserIndex(r,this.m_clusterIndex),h=this.m_shape.getPathFromVertex(r),a=this.m_shape.getGeometryFromPath(h),o=this.m_shape.getGeometryType(a);if(u(o)){const t=this.m_shape.getNextVertex(r);if(t===H)continue;const s=this.m_shape.getUserIndex(t,this.m_clusterIndex);if(n===s)continue;const h=this.newHalfEdgePair_(),m=this.getHalfEdgeTwin(h),g=this.m_clusterVertices.newElement();this.m_clusterVertices.setField(g,0,r),this.m_clusterVertices.setField(g,1,-1),this.setHalfEdgeVertexIterator_(h,g),this.m_shape.setUserIndex(r,this.m_halfEdgeIndex,h),this.setHalfEdgeOrigin_(h,n);const l=this.getClusterHalfEdge(n);if(l===H)this.setClusterHalfEdge_(n,h),this.setHalfEdgePrev_(h,m),this.setHalfEdgeNext_(m,h);else{const e=this.getHalfEdgePrev(l);this.setHalfEdgePrev_(l,m),this.setHalfEdgeNext_(m,l),this.setHalfEdgeNext_(e,h),this.setHalfEdgePrev_(h,e)}this.setHalfEdgeOrigin_(m,s);const _=this.getClusterHalfEdge(s);if(_===H)this.setClusterHalfEdge_(s,m),this.setHalfEdgeNext_(h,m),this.setHalfEdgePrev_(m,h);else{const e=this.getHalfEdgePrev(_);this.setHalfEdgePrev_(_,h),this.setHalfEdgeNext_(h,_),this.setHalfEdgeNext_(e,m),this.setHalfEdgePrev_(m,e)}const d=this.getGeometryID(a);if(e===Qe.enumInputModeBuildGraph){const e=o===i.enumPolygon?d:0;if(this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeParentageIndex,0),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,e),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeParentageIndexLeft,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,0),this.m_bBuildGeometryParentageSets){const e=new Le,t=this.m_shape.getGeometryUserIndex(a,this.m_geometryIDIndex);e.setBit(t),this.setEdgeBitSet_(h,e),this.setEdgeBitSet_(m,null),this.setLeftEdgeBitSet_(m,e),this.setLeftEdgeBitSet_(h,null)}}else if(e===Qe.enumInputModeSimplifyWinding){const e=this.m_shape.getXY(r),s=this.m_shape.getXY(t);let i=0,n=0;e.compare(s)<0?i=1:n=-1,this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,i),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeWindingNumberIndex,n)}else e===Qe.enumInputModeSimplifyAlternate&&(this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,1),this.setHalfEdgeUserIndex(m,this.m_tmpHalfEdgeOddEvenNumberIndex,1));const p=o===i.enumPolygon?$e.c_EdgeBitMask:0;this.setHalfEdgeParentage_(h,d|p),this.setHalfEdgeParentage_(m,d|p)}}if(this.m_shape.hasCurves()){this.m_segmentIndexHe=this.createUserIndexForHalfEdges();for(let e=0,s=t.size();e<s;e++){const s=t.read(e);if(this.m_shape.getSegment(s)){const e=this.m_shape.getUserIndex(s,this.m_halfEdgeIndex);e!==H&&(this.setHalfEdgeUserIndex(e,this.m_segmentIndexHe,this.m_shape.getVertexIndex(s)),this.setHalfEdgeUserIndex(this.getHalfEdgeTwin(e),this.m_segmentIndexHe,-2))}}}}mergeVertexListsOfEdges_(e,t){{const s=this.getHalfEdgeVertexIterator(t);if(s!==H){const i=this.getHalfEdgeVertexIterator(e);this.m_clusterVertices.setField(s,1,i),this.setHalfEdgeVertexIterator_(e,s),this.setHalfEdgeVertexIterator_(t,H)}}const s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeTwin(t);{const e=this.getHalfEdgeVertexIterator(i);if(e!==H){const t=this.getHalfEdgeVertexIterator(s);this.m_clusterVertices.setField(e,1,t),this.setHalfEdgeVertexIterator_(s,e),this.setHalfEdgeVertexIterator_(i,H)}}if(-1!==this.m_segmentIndexHe){let r=this.getHalfEdgeUserIndex(e,this.m_segmentIndexHe);if(-1!==r){if(-2===r){const s=this.getHalfEdgeUserIndex(t,this.m_segmentIndexHe);this.setHalfEdgeUserIndex(e,this.m_segmentIndexHe,s)}if(r=this.getHalfEdgeUserIndex(s,this.m_segmentIndexHe),-2===r){const e=this.getHalfEdgeUserIndex(i,this.m_segmentIndexHe);this.setHalfEdgeUserIndex(s,this.m_segmentIndexHe,e)}}}}sortHalfEdgesByAngle_(e){const t=[];for(let s=this.getFirstCluster();s!==H;s=this.getNextCluster(s)){t.length=0;const i=this.getClusterHalfEdge(s);if(i!==H){let r=i;do{t.push(r),r=this.getHalfEdgeNext(this.getHalfEdgeTwin(r))}while(r!==i);if(t.length>1){let r=!0;t.length>2?(t.sort(((e,t)=>this.compareEdgeAngles_(e,t))),t.push(t[0])):this.compareEdgeAnglesForPair_(t[0],t[1])>0?t[1]=q(t[0],t[0]=t[1]):r=!1;let n=t[0],h=n,a=this.getHalfEdgeTo(h),o=this.getHalfEdgeTwin(h),m=H;for(let s=1,i=t.length;s<i;s++){const i=t[s],r=this.getHalfEdgeTwin(i),g=this.getHalfEdgeOrigin(r);if(g!==a||i===h)this.updateVertexToHalfEdgeConnection_(m,!1),m=H,h=i,a=g,o=r;else{if(e===Qe.enumInputModeBuildGraph){const e=this.getHalfEdgeParentageMask_(h)|this.getHalfEdgeParentageMask_(i);if(this.setHalfEdgeParentage_(h,e),this.setHalfEdgeParentage_(o,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndexLeft)),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeParentageIndexLeft)|this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeParentageIndexLeft)),this.m_bBuildGeometryParentageSets){let e,t,s;e=this.getEdgeBitSet_(h),t=this.getEdgeBitSet_(i),s=new Le({copy:e}),s.assignOr(t),this.setEdgeBitSet_(h,s),e=this.getEdgeBitSet_(o),t=this.getEdgeBitSet_(r),s=new Le({copy:e}),s.assignOr(t),this.setEdgeBitSet_(o,s),e=this.getLeftEdgeBitSet_(h),t=this.getLeftEdgeBitSet_(i),s=new Le({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(h,s),e=this.getLeftEdgeBitSet_(o),t=this.getLeftEdgeBitSet_(r),s=new Le({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(o,s)}}else if(-1!==this.m_tmpHalfEdgeWindingNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),t=this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,e),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeWindingNumberIndex,t)}else if(-1!==this.m_tmpHalfEdgeOddEvenNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeOddEvenNumberIndex),t=this.getHalfEdgeUserIndex(o,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeOddEvenNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,e),this.setHalfEdgeUserIndex(o,this.m_tmpHalfEdgeOddEvenNumberIndex,t)}this.mergeVertexListsOfEdges_(h,i),this.deleteEdgeImpl_(i),m=h,t[s]=H,i===n&&(t[0]=H,n=H)}}if(this.updateVertexToHalfEdgeConnection_(m,!1),m=H,!r){n=H;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s!==H){n=s;break}}i!==n&&this.setClusterHalfEdge_(s,n);continue}n=H;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s===H)continue;if(n===H){n=s,h=n,a=this.getHalfEdgeTo(h),o=this.getHalfEdgeTwin(h);continue}if(s===h)continue;const i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeOrigin(i);this.setHalfEdgeNext_(o,s),this.setHalfEdgePrev_(s,o),h=s,a=r,o=i}this.setClusterHalfEdge_(s,n)}}}}sortHalfEdgesByAngleHelper_(t){e(0)}sortHalfEdgesByAngle3D_(t){e(0)}buildChains_(e){this.m_universeChain=this.newChain_(),this.setChainHalfEdge_(this.m_universeChain,H);let t=this.m_universeChain;const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==H;i=this.getNextCluster(i)){const e=this.getClusterHalfEdge(i);if(e!==H){let i=e;do{if(1!==this.getHalfEdgeUserIndex(i,s)){const e=this.newChain_();let r;this.setChainHalfEdge_(e,i),this.setChainPrev_(e,t),this.setChainNext_(t,e),this.m_bBuildGeometryParentageSets&&(r=new Le),t=e;let n=0,h=i;do{-1!==this.m_tmpHalfEdgeParentageIndex&&(n|=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)),this.m_bBuildGeometryParentageSets&&r.assignOr(this.getEdgeBitSet_(h)),this.setHalfEdgeChain_(h,e),this.setHalfEdgeUserIndex(h,s,1),h=this.getHalfEdgeNext(h)}while(h!==i);this.m_bBuildGeometryParentageSets&&this.setChainBitSet_(e,r),this.setChainParentage_(e,n)}i=this.getHalfEdgeNext(this.getHalfEdgeTwin(i))}while(i!==e)}}this.m_chainAreas=new L(this.m_chainData.size(),Number.NaN),this.m_chainPerimeters=new L(this.m_chainData.size(),Number.NaN),this.setChainArea_(this.m_universeChain,Number.POSITIVE_INFINITY),this.setChainPerimeter_(this.m_universeChain,Number.POSITIVE_INFINITY),this.deleteUserIndexForHalfEdges(s)}simplify_(t){e(0)}simplifyAlternate_(){e(0)}simplifyWinding_(){e(0)}setEditShapeImpl_(e,t,s,i,r){this.removeShape(),this.m_bBuildChains=r,this.m_shape=e,this.m_geometryIDIndex=this.m_shape.createGeometryUserIndex();let n=this.m_shape.getTotalPointCount();if(s){n=0;for(let e=0,t=s.length;e<t;e++)n+=this.m_shape.getPointCount(s[e])}const h=new c(0);let a=0,o=0;{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==H;){this.m_shape.setGeometryUserIndex(e,this.m_geometryIDIndex,o++);for(let t=this.m_shape.getFirstPath(e);t!==H;t=this.m_shape.getNextPath(t)){let e=this.m_shape.getFirstVertex(t);for(let s=0,i=this.m_shape.getPathSize(t);s<i;s++)h.add(e),e=this.m_shape.getNextVertex(e)}z(this.m_shape.getGeometryType(e))||(a+=this.m_shape.getPathCount(e)),null!=s?(e=t<s.length?s[t]:H,t++):e=this.m_shape.getNextGeometry(e)}}this.m_universeGeomID=1<<Math.min(o,31),this.m_pointCount=h.size(),this.m_shape.sortVerticesSimpleByY(h,0,this.m_pointCount),this.m_clusterVertices.setCapacity(this.m_pointCount),this.progress_(i,!0),this.m_clusterData.setCapacity(this.m_pointCount+10),this.m_halfEdgeData.setCapacity(2*this.m_pointCount+32),this.m_chainData.setCapacity(Math.max(32,a)),this.m_clusterIndex=this.m_shape.createUserIndex();const m=F.getNAN();let g=0;const l=F.getNAN();for(let _=0;_<=this.m_pointCount;_++){if(_<this.m_pointCount){const e=h.read(_);this.m_shape.queryXY(e,l)}else l.setNAN();if(!m.isEqualPoint2D(l)){if(g<_){const e=this.newCluster_();let t=H,s=-1;for(let i=g;i<_;i++){s=h.read(i),this.m_shape.setUserIndex(s,this.m_clusterIndex,e);const r=this.m_clusterVertices.newElement();this.m_clusterVertices.setField(r,0,s),this.m_clusterVertices.setField(r,1,t),t=r;const n=this.m_shape.getPathFromVertex(s),a=this.m_shape.getGeometryFromPath(n),o=this.getGeometryID(a);this.setClusterParentage_(e,this.getClusterParentage(e)|o)}this.setClusterVertexIterator_(e,t),this.setClusterVertexIndex_(e,this.m_shape.getVertexIndex(s)),this.m_lastCluster!==H&&this.setNextCluster_(this.m_lastCluster,e),this.setPrevCluster_(e,this.m_lastCluster),this.m_lastCluster=e,this.m_firstCluster===H&&(this.m_firstCluster=e)}g=_,m.setCoordsPoint2D(l)}}if(this.m_shape.hasSegmentParentage()){-1===this.m_clusterBreakNodeIndex&&(this.m_clusterBreakNodeIndex=this.createUserIndexForClusters());for(let e=0;e<this.m_pointCount;e++){const t=h.read(e);if(this.m_shape.getSegmentParentageBreakVertex(t)){const e=this.getClusterFromVertex(t);this.setBreakNode(e,!0)}}}this.progress_(i,!0);{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==H;){for(let t=this.m_shape.getFirstPath(e);t!==H;t=this.m_shape.getNextPath(t)){if(this.m_shape.isStrongPathStart(t)){const e=this.m_shape.getFirstVertex(t),s=this.getClusterFromVertex(e);this.setStrongPathNode(s,!0)}if(this.m_shape.isStrongPathEnd(t)){const e=this.m_shape.isClosedPath(t)?this.m_shape.getFirstVertex(t):this.m_shape.getLastVertex(t),s=this.getClusterFromVertex(e);this.setStrongPathNode(s,!0)}}null!=s?(e=t<s.length?s[t]:H,t++):e=this.m_shape.getNextGeometry(e)}}if(t===Qe.enumInputModeBuildGraph&&(this.m_tmpHalfEdgeParentageIndex=this.createUserIndexForHalfEdges(),this.m_tmpHalfEdgeParentageIndexLeft=this.createUserIndexForHalfEdges()),t===Qe.enumInputModeSimplifyWinding&&(this.m_tmpHalfEdgeWindingNumberIndex=this.createUserIndexForHalfEdges()),t===Qe.enumInputModeSimplifyAlternate&&(this.m_tmpHalfEdgeOddEvenNumberIndex=this.createUserIndexForHalfEdges()),this.createHalfEdges_(t,h),this.dbgNavigate_(),this.sortHalfEdgesByAngle_(t),!Number.isNaN(this.m_checkDirtyPlanesweepTolerance)&&!this.checkStructureAfterDirtySweep_())return this.m_bDirtyCheckFailed=!0,void this.cleanSetEditShapeImpl_();this.buildChains_(t),-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),this.m_bBuildChains&&this.planeSweepParentage_(t,i),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),this.dbgChkChainParents_(),this.dbgDumpChains_(),this.mergeSegmentParentage_(),this.dbgNavigate_(),this.dbgDumpChains_(),this.cleanSetEditShapeImpl_()}setEditShapeImpl3D_(t,s,i,r,n){e(0)}cleanSetEditShapeImpl_(){-1!==this.m_tmpHalfEdgeParentageIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndex),this.m_tmpHalfEdgeParentageIndex=-1),-1!==this.m_tmpHalfEdgeParentageIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeParentageIndexLeft),this.m_tmpHalfEdgeParentageIndexLeft=-1),-1!==this.m_tmpHalfEdgeWindingNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeWindingNumberIndex),this.m_tmpHalfEdgeWindingNumberIndex=-1),-1!==this.m_tmpHalfEdgeOddEvenNumberIndex&&(this.deleteUserIndexForHalfEdges(this.m_tmpHalfEdgeOddEvenNumberIndex),this.m_tmpHalfEdgeOddEvenNumberIndex=-1)}cleanSetEditShapeImpl3D_(){e(0)}dbgNavigate_(){}dbgChkChainParents_(){}deleteEdgeImpl_(e){const t=this.getHalfEdgeNext(e),s=this.getHalfEdgePrev(e),i=this.getHalfEdgeTwin(e),r=this.getHalfEdgeNext(i),n=this.getHalfEdgePrev(i);t!==i&&(this.setHalfEdgeNext_(n,t),this.setHalfEdgePrev_(t,n)),s!==i&&(this.setHalfEdgeNext_(s,r),this.setHalfEdgePrev_(r,s));const h=this.getHalfEdgeOrigin(e);this.getClusterHalfEdge(h)===e&&(r!==e?this.setClusterHalfEdge_(h,r):this.setClusterHalfEdge_(h,H));const a=this.getHalfEdgeOrigin(i);this.getClusterHalfEdge(a)===i&&(t!==i?this.setClusterHalfEdge_(a,t):this.setClusterHalfEdge_(a,H)),this.m_halfEdgeData.deleteElement(e),this.m_halfEdgeData.deleteElement(i)}getLeftSkipPolylines_(e,t){let s=t;for(;;){if(s=e.getPrev(s),-1===s)return H;{const t=e.getElement(s);if(this.getHalfEdgeChain(t)!==this.getHalfEdgeChain(this.getHalfEdgeTwin(t)))return t}}}checkStructureAfterDirtySweep_(){const e=W(this.m_checkDirtyPlanesweepTolerance),t=new F,s=new F,i=new F,r=new F,n=new F;for(let h=this.getFirstCluster();h!==H;h=this.getNextCluster(h)){const a=this.getClusterHalfEdge(h);if(a!==H){let h=a;this.getHalfEdgeFromXY(h,t),this.getHalfEdgeToXY(h,s),i.setSub(s,t);let o=i.sqrLength();do{const a=h;if(h=this.getHalfEdgeNext(this.getHalfEdgeTwin(h)),h!==a){this.getHalfEdgeToXY(h,r),n.setSub(r,t);const a=n.sqrLength(),m=n.crossProduct(i),g=m*m/(a*o);if(Math.min(a,o)*g<=e){if(n.dotProduct(i)>=0)return!1}i.assign(n),o=a,s.assign(r)}}while(h!==a)}}return!0}extractPolygonPathFromChain_(t,s,i,r,n){e(0)}mergeSegmentParentage_(){if(!this.m_shape.hasSegmentParentage())return;e(-1!==this.m_clusterBreakNodeIndex),e(-1===this.m_segmentParentageIndex);for(let e=this.getFirstCluster();e!==H;e=this.getNextCluster(e)){let t=0;const s=this.getClusterHalfEdge(e);if(s!==H){let e=s;do{t++,e=this.getHalfEdgeNext(this.getHalfEdgeTwin(e))}while(e!==s&&t<3)}2!==t&&this.setBreakNode(e,!0)}let t=[],s=[];this.m_segmentParentageIndex=this.createUserIndexForHalfEdges();const i=this.createUserIndexForHalfEdges();for(let e=this.getFirstCluster();e!==H;e=this.getNextCluster(e)){const r=this.getClusterHalfEdge(e);if(r!==H){let e=!1,n=r;do{let r=n;for(;-1===this.getHalfEdgeUserIndex(r,i);){const n=this.getHalfEdgeNext(r),h=this.getHalfEdgeTwin(r);Ke(this,r,s);const a=s.at(-1).parentage;if(!e){const s=this.getHalfEdgeOrigin(r);if(!this.isBreakNode(s)){const s=this.getHalfEdgePrev(r);r!==s&&(Ke(this,s,t),e=!0)}}if(e&&!Je(s,t)){const e=this.getHalfEdgeOrigin(r);this.setBreakNode(e,!0)}t=q(s,s=t),e=!0;const o=this.getHalfEdgeOrigin(n);this.isBreakNode(o)&&(e=!1),this.setHalfEdgeUserIndex(r,this.m_segmentParentageIndex,a),this.setHalfEdgeUserIndex(h,this.m_segmentParentageIndex,a),this.setHalfEdgeUserIndex(r,i,1),this.setHalfEdgeUserIndex(h,i,1),r=n}n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(n!==r)}}this.deleteUserIndexForHalfEdges(i)}registerNewBitSet(t){return e(0),new Le}getLeftEdgeBitSet_(t){return e(0),new Le}getEdgeBitSet_(t){return e(0),new Le}setEdgeBitSet_(t,s){e(0)}setLeftEdgeBitSet_(t,s){e(0)}setChainBitSet_(t,s){e(0)}getEmptySet(){return e(0),new Le}deleteEdgeBitSets_(){-1!==this.m_edgeBitSetIndex&&(this.deleteUserIndexForHalfEdges(this.m_edgeBitSetIndex),this.m_edgeBitSetIndex=-1),-1!==this.m_edgeBitSetIndexLeft&&(this.deleteUserIndexForHalfEdges(this.m_edgeBitSetIndexLeft),this.m_edgeBitSetIndexLeft=-1),this.m_edgeBitSets.length=0,this.m_uniqueBitSets=null}deleteChainBitSets_(){-1!==this.m_chainBitSetIndex&&(this.deleteUserIndexForChains(this.m_chainBitSetIndex),this.m_chainBitSetIndex=-1,this.m_chainBitSets.length=0)}dbgPrintEdge_(t){e(0)}dbgVerifyEdgeSegment(t){e(0)}}$e.c_EdgeParentageMask=~(1<<31),$e.c_EdgeBitMask=1<<31;class et{freeNode_(e){this.m_listNodes.deleteElement(e)}newNode_(){return this.m_listNodes.newElement()}freeList_(e){this.m_lists.deleteElement(e)}newList_(){return this.m_lists.newElement()}Init_(t){e(0)}constructor(e){this.m_listNodes=new M(2),this.m_listOfLists=et.st_nullNode(),this.m_bAllowNavigationBetweenLists=!0,void 0===e&&(e=!0),this.m_bAllowNavigationBetweenLists=e,this.m_lists=new M(this.m_bAllowNavigationBetweenLists?4:2)}createList(){const e=this.newList_();return this.m_bAllowNavigationBetweenLists&&(this.m_lists.setField(e,3,this.m_listOfLists),this.m_listOfLists!==et.st_nullNode()&&this.m_lists.setField(this.m_listOfLists,2,e),this.m_listOfLists=e),e}deleteList(e){let t=this.getFirst(e);for(;t!==et.st_nullNode();){const e=t;t=this.getNext(t),this.freeNode_(e)}if(this.m_bAllowNavigationBetweenLists){const t=this.m_lists.getField(e,2),s=this.m_lists.getField(e,3);t!==et.st_nullNode()?this.m_lists.setField(t,3,s):this.m_listOfLists=s,s!==et.st_nullNode()&&this.m_lists.setField(s,2,t)}this.freeList_(e)}reserveLists(e){this.m_lists.setCapacity(e)}addElement(e,t){this.m_lists.getField(e,0);const s=this.m_lists.getField(e,1),i=this.newNode_();return s!==et.st_nullNode()?(this.m_listNodes.setField(s,1,i),this.m_lists.setField(e,1,i)):(this.m_lists.setField(e,0,i),this.m_lists.setField(e,1,i)),this.m_listNodes.setField(i,0,t),i}reserveNodes(e){this.m_listNodes.setCapacity(e)}deleteElementDirect(e,t,s){t!==et.st_nullNode()?(this.m_listNodes.setField(t,1,this.m_listNodes.getField(s,1)),this.m_lists.getField(e,1)===s&&this.m_lists.setField(e,1,t)):(this.m_lists.setField(e,0,this.m_listNodes.getField(s,1)),this.m_lists.getField(e,1)===s&&this.m_lists.setField(e,1,et.st_nullNode())),this.freeNode_(s)}deleteElementSearch(e,t){let s=-1,i=this.getFirst(e);for(;i!==t;)s=i,i=this.getNext(i);this.deleteElementDirect(e,s,t)}concatenateLists(e,t){const s=this.m_lists.getField(e,1),i=this.m_lists.getField(t,0);if(i!==et.st_nullNode()&&(s!==et.st_nullNode()?(this.m_listNodes.setField(s,1,i),this.m_lists.setField(e,1,this.m_lists.getField(t,1))):(this.m_lists.setField(e,0,i),this.m_lists.setField(e,1,this.m_lists.getField(t,1)))),this.m_bAllowNavigationBetweenLists){const e=this.m_lists.getField(t,2),s=this.m_lists.getField(t,3);e!==et.st_nullNode()?this.m_lists.setField(e,3,s):this.m_listOfLists=s,s!==et.st_nullNode()&&this.m_lists.setField(s,2,e)}return this.freeList_(t),e}getElement(e){return this.m_listNodes.getField(e,0)}getData(e){return this.getElement(e)}setElement(t,s){e(0)}getNext(e){return this.m_listNodes.getField(e,1)}getFirst(e){return this.m_lists.getField(e,0)}getFirstElement(e){const t=this.getFirst(e);return this.getElement(t)}static st_nullNode(){return-1}clear(){this.m_listNodes.deleteAll(!0),this.m_lists.deleteAll(!0),this.m_listOfLists=et.st_nullNode()}isEmpty(t){return e(0),!1}getNodeCount(){return this.m_listNodes.size()}getListCount(){return this.m_lists.size()}getFirstList(){return this.m_listOfLists}getNextList(e){return this.m_lists.getField(e,3)}}function tt(e=-1){return{m_value:e,m_line:new ge,m_segment:null,m_segmentInfo:new ye(-1),m_env:new le(0,0),m_dxdy:55555555,m_bHorizontal:!1,m_bCurve:!1}}const st=67;class it extends de{constructor(e,t,s){super(!0),this.m_bIntersectionDetected=!1,this.m_nonSimpleResult=new Xe,this.m_tempSimpleEdge1=tt(),this.m_tempSimpleEdge2=tt(),this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H,this.m_currentNode=-1,this.m_prevX1=Number.NaN,this.m_prevX2=Number.NaN,this.m_prevY=Number.NaN,this.m_prevX=0,this.m_sweepY=Number.NaN,this.m_sweepX=0,this.m_simpleEdgesCache=[],this.m_simpleEdgesRecycle=[],this.m_cOutstandingConstructedEdges=0,this.m_shape=e,this.m_bShapeHasSegments=this.m_shape.hasCurves(),this.m_tolerance=t,this.m_tolerance10=10*t,this.m_bIsSimple=s;const i=Math.trunc(Math.min(3*e.getTotalPointCount()/2,st)),r=Math.min(7,i);this.m_simpleEdgesCache.length=r}tryGetCachedEdge_(e){const t=this.m_simpleEdgesCache[(e&fe())%this.m_simpleEdgesCache.length];return t&&t.m_value===e?t:null}tryDeleteCachedEdge_(e){const t=(e&fe())%this.m_simpleEdgesCache.length,s=this.m_simpleEdgesCache[t];s&&s.m_value===e&&(this.m_simpleEdgesRecycle.push(s),this.m_simpleEdgesCache[t]=null)}tryCreateCachedEdge_(e){const t=(e&fe())%this.m_simpleEdgesCache.length;let s=this.m_simpleEdgesCache[t];return s?null:(0===this.m_simpleEdgesRecycle.length?(s=tt(),this.m_cOutstandingConstructedEdges++):s=this.m_simpleEdgesRecycle.pop(),s.m_value=e,this.m_simpleEdgesCache[t]=s,s)}initSimpleEdge_(e,t){this.m_bShapeHasSegments&&this.initSimpleEdgeHelper_(e,t)||e.m_bCurve||(this.m_shape.queryLineConnector(t,e.m_line,!0),e.m_segment=e.m_line,e.m_env.setCoordsNoNAN(e.m_line.getStartX(),e.m_line.getEndX()),e.m_env.vmax+=this.m_tolerance,e.m_line.orientBottomUp(),e.m_bHorizontal=e.m_line.getEndY()===e.m_line.getStartY(),e.m_bHorizontal||(e.m_dxdy=(e.m_line.getEndX()-e.m_line.getStartX())/(e.m_line.getEndY()-e.m_line.getStartY())))}initSimpleEdgeHelper_(e,t){if(e.m_segment=this.m_shape.getSegment(t),e.m_segmentInfo=this.m_shape.getOriginalSegmentInfo(t),e.m_bCurve=null!==e.m_segment,e.m_bCurve){const t=e.m_segment.clone();return t.orientBottomUp(),e.m_segment=t,e.m_env=e.m_segment.queryInterval(0,0),e.m_env.vmax+=this.m_tolerance,!0}return!1}compareTwoSegments_(e,t){const s=e.getStartXY(),i=e.getEndXY(),r=t.getStartXY(),n=t.getEndXY(),h=new F;if(h.setCoords(this.m_sweepX,this.m_sweepY),s.isEqualPoint2D(r)&&this.m_sweepY===s.y){h.assign(i.compare(n)<0?i:n);const s=e.intersectionOfYMonotonicWithAxisX(h.y,h.x),r=t.intersectionOfYMonotonicWithAxisX(h.y,h.x);if(Math.abs(s-r)>this.m_tolerance)return s<r?-1:1}const a=s.compare(r)<0?r:s,o=i.compare(n)<0?i:n;let m=0,g=0;for(let l=1;l<5;l++){xe(a,o,l/5,h);const s=e.intersectionOfYMonotonicWithAxisX(h.y,h.x),i=t.intersectionOfYMonotonicWithAxisX(h.y,h.x),r=Math.abs(s-i);r>m&&(m=r,g=s<i?-1:1)}return 0===g?this.errorCracking():g}compareNonHorizontal_(e,t){if(e.m_line.getStartY()===t.m_line.getStartY()&&e.m_line.getStartX()===t.m_line.getStartX())return e.m_line.getEndY()===t.m_line.getEndY()&&e.m_line.getEndX()===t.m_line.getEndX()?this.m_bIsSimple?this.errorCoincident():0:this.compareNonHorizontalUpperEnd_(e,t);if(e.m_line.getEndY()===t.m_line.getEndY()&&e.m_line.getEndX()===t.m_line.getEndX())return this.compareNonHorizontalLowerEnd_(e,t);const s=this.compareNonHorizontalLowerEnd_(e,t),i=this.compareNonHorizontalUpperEnd_(e,t);return s<0&&i<0?-1:s>0&&i>0?1:this.errorCracking()}compareHorizontal1Case1_(e,t){if(e.getEndX()>t.getEndX()){if(t.getEndX()>t.getStartX()&&t.getEndY()-t.getStartY()<2*this.m_tolerance&&e.isIntersectingPoint(t.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}else{if((t.getEndY()-t.getStartY())/(t.getEndX()-t.getStartX())*(e.getEndX()-e.getStartX())<this.m_tolerance10&&t.isIntersectingPoint(e.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}return 1}compareHorizontal1Case2_(e,t){if(e.getStartX()<t.getStartX()){if(t.getEndX()>t.getStartX()&&t.getEndY()-t.getStartY()<2*this.m_tolerance&&e.isIntersectingPoint(t.getEndXY(),this.m_tolerance,!0))return this.errorCracking()}else{if((t.getEndY()-t.getStartY())/(t.getEndX()-t.getStartX())*(e.getStartX()-e.getEndX())<this.m_tolerance10&&t.isIntersectingPoint(e.getStartXY(),this.m_tolerance,!0))return this.errorCracking()}return-1}compareHorizontal1Case3_(e,t){const s=F.getNAN();s.setSub(t.getEndXY(),t.getStartXY()),s.rightPerpendicularThis(),s.normalize();const i=F.getNAN();i.setSub(e.getStartXY(),t.getStartXY());const r=F.getNAN();r.setSub(e.getEndXY(),t.getStartXY());const n=i.dotProduct(s),h=r.dotProduct(s),a=Math.abs(n),o=Math.abs(h);if(a<o){if(a<this.m_tolerance10&&t.isIntersectingPoint(e.getStartXY(),this.m_tolerance,!0))return this.errorCracking()}else if(o<this.m_tolerance10&&t.isIntersectingPoint(e.getEndXY(),this.m_tolerance,!0))return this.errorCracking();return n<0&&h<0?-1:n>0&&h>0?1:this.errorCracking()}compareHorizontal1_(e,t){return e.getStartY()===t.getStartY()&&e.getStartX()===t.getStartX()?this.compareHorizontal1Case1_(e,t):e.getEndY()===t.getEndY()&&e.getEndX()===t.getEndX()?this.compareHorizontal1Case2_(e,t):this.compareHorizontal1Case3_(e,t)}compareHorizontal2_(e,t){return e.getEndY()===t.getEndY()&&e.getEndX()===t.getEndX()&&e.getStartY()===t.getStartY()&&e.getStartX()===t.getStartX()?this.m_bIsSimple?this.errorCoincident():0:this.errorCracking()}compareNonHorizontalLowerEnd_(e,t){let s=1;if(e.m_line.getStartY()<t.m_line.getStartY()){s=-1;const i=e;e=t,t=i}const i=e.m_line,r=t.m_line,n=i.getStartX()-r.getStartX(),h=t.m_dxdy*(i.getStartY()-r.getStartY()),a=this.m_tolerance10;return n<h-a?-s:n>h+a?s:r.isIntersectingPoint(i.getStartXY(),this.m_tolerance,!0)?this.errorCracking():n<h?-s:s}compareNonHorizontalUpperEnd_(e,t){let s=1;if(t.m_line.getEndY()<e.m_line.getEndY()){s=-1;const i=e;e=t,t=i}const i=e.m_line,r=t.m_line,n=i.getEndX()-r.getStartX(),h=t.m_dxdy*(i.getEndY()-r.getStartY()),a=this.m_tolerance10;return n<h-a?-s:n>h+a?s:r.isIntersectingPoint(i.getEndXY(),this.m_tolerance,!0)?this.errorCracking():n<h?-s:s}errorCoincident(){this.m_bIntersectionDetected=!0;const e=7;return this.m_nonSimpleResult=new Xe(e,this.m_vertex1,this.m_vertex2),-1}errorCracking(){if(this.m_bIntersectionDetected=!0,this.m_bIsSimple){const e=6;this.m_nonSimpleResult=new Xe(e,this.m_vertex1,this.m_vertex2)}else this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H;return-1}compareSegments_(e,t,s,i){if(s.m_env.vmax<i.m_env.vmin)return-1;if(i.m_env.vmax<s.m_env.vmin)return 1;if(!s.m_bCurve&&!i.m_bCurve){let e=s.m_bHorizontal?1:0;return e|=i.m_bHorizontal?2:0,0===e?this.compareNonHorizontal_(s,i):1===e?this.compareHorizontal1_(s.m_line,i.m_line):2===e?-1*this.compareHorizontal1_(i.m_line,s.m_line):this.compareHorizontal2_(s.m_line,i.m_line)}if(this.m_bIntersectionDetected)return-1;const r=this.m_prevY===this.m_sweepY&&this.m_prevX===this.m_sweepX;let n,h;if(r&&e===this.m_prev1?n=this.m_prevX1:(n=Number.NaN,this.m_prev1=H),r&&t===this.m_prev2?h=this.m_prevX2:(h=Number.NaN,this.m_prev2=H),this.m_prevY=this.m_sweepY,this.m_prevX=this.m_sweepX,Number.isNaN(n)){this.m_prev1=e;const t=s.m_segment.intersectionOfYMonotonicWithAxisX(this.m_sweepY,this.m_sweepX);n=t,this.m_prevX1=t}if(Number.isNaN(h)){this.m_prev2=t;const e=i.m_segment.intersectionOfYMonotonicWithAxisX(this.m_sweepY,this.m_sweepX);h=e,this.m_prevX2=e}const a=J(!0,!0,s.m_segment,i.m_segment,this.m_tolerance,!0);return 0!==a?2===a?this.m_bIsSimple?this.errorCoincident():s.m_segmentInfo.equals(i.m_segmentInfo)?0:this.errorCracking():this.errorCracking():Math.abs(n-h)<=this.m_tolerance?this.compareTwoSegments_(s.m_segment,i.m_segment):n<h?-1:n>h?1:0}clearIntersectionDetectedFlag(){this.m_bIntersectionDetected=!1}intersectionDetected(){return this.m_bIntersectionDetected}getLastComparedNode(){return this.m_currentNode}getResult(){return this.m_nonSimpleResult}setSweepY(e,t){this.m_sweepY=e,this.m_sweepX=t,this.m_prev1=H,this.m_prev2=H,this.m_vertex1=H,this.m_vertex2=H}compare(e,t,s){if(this.m_bIntersectionDetected)return-1;const i=e.getElement(s),r=t;return this.m_currentNode=s,this.compareSegments(r,r,i,i)}compareSegments(e,t,s,i){let r=this.tryGetCachedEdge_(e);null===r?this.m_vertex1===t?r=this.m_tempSimpleEdge1:(this.m_vertex1=t,r=this.tryCreateCachedEdge_(e),null===r&&(r=this.m_tempSimpleEdge1,this.m_tempSimpleEdge1.m_value=e),this.initSimpleEdge_(r,t)):this.m_vertex1=t;let n=this.tryGetCachedEdge_(s);return null===n?this.m_vertex2===i?n=this.m_tempSimpleEdge2:(this.m_vertex2=i,n=this.tryCreateCachedEdge_(s),null===n&&(n=this.m_tempSimpleEdge2,this.m_tempSimpleEdge2.m_value=s),this.initSimpleEdge_(n,i)):this.m_vertex2=i,this.compareSegments_(t,i,r,n)}onDelete(e){this.tryDeleteCachedEdge_(e)}onSet(e){this.tryDeleteCachedEdge_(e)}onEndSearch(e){this.tryDeleteCachedEdge_(e)}onAddUniqueElementFailed(e){this.tryDeleteCachedEdge_(e)}}class rt{constructor(e,t){this.m_bIntersectionDetected=!1,this.m_pointOfInterest=F.getNAN(),this.m_line1=new ge,this.m_seg1=null,this.m_env=le.constructEmpty(),this.m_vertex1=-1,this.m_currentNode=-1,this.m_minDist=Number.MAX_VALUE,this.m_shape=e,this.m_tolerance=t}getCurrentNode(){return this.m_currentNode}clearIntersectionDetectedFlag(){this.m_bIntersectionDetected=!1,this.m_minDist=Number.MAX_VALUE}intersectionDetected(){return this.m_bIntersectionDetected}setPoint(e){this.m_pointOfInterest=e}compare(t,s){return e(0),0}compareVertex(e,t,s){let i,r=this.m_shape.getSegment(s),h=!0;if(null==r)this.m_shape.queryLineConnector(s,this.m_line1,!0),this.m_env.setCoordsNoNAN(this.m_line1.getStartX(),this.m_line1.getEndX()),r=this.m_line1,i=this.m_line1.getStartY()===this.m_line1.getEndY();else{const e=n.constructEmpty();r.queryLooseEnvelope(e),e.queryIntervalX(this.m_env),i=0===e.height(),h=!1}if(this.m_pointOfInterest.x+this.m_tolerance<this.m_env.vmin)return-1;if(this.m_pointOfInterest.x-this.m_tolerance>this.m_env.vmax)return 1;if(i)return this.m_currentNode=t,this.m_bIntersectionDetected=!0,0;let a=0;if(h){Ee(this.m_line1);const e=this.m_line1.getStartXY(),t=new F;t.setSub(this.m_line1.getEndXY(),e),t.rightPerpendicularThis();const s=new F;s.setSub(this.m_pointOfInterest,e),a=t.dotProduct(s),a/=t.length()}else{a=r.intersectionOfYMonotonicWithAxisX(this.m_pointOfInterest.y,this.m_pointOfInterest.x)-this.m_pointOfInterest.x}if(a<10*-this.m_tolerance)return-1;if(a>10*this.m_tolerance)return 1;if(r.isIntersectingPoint(this.m_pointOfInterest,this.m_tolerance)){Math.abs(a)<this.m_minDist&&(this.m_currentNode=t,this.m_minDist=a),this.m_bIntersectionDetected=!0}return a<0?-1:a>0?1:0}}class nt{constructor(e,t){this.m_lists=new et(!1),this.m_hash=t,this.m_hashBuckets=new Int32Array(e),this.m_hashBuckets.fill(nt.st_nullNode()),this.m_bitFilter=new Int32Array(10*e+31>>5)}reserveElements(e){this.m_lists.reserveLists(Math.min(this.m_hashBuckets.length,e)),this.m_lists.reserveNodes(e)}addElement(e,t){void 0===t&&(t=this.m_hash.getHash(e));const s=t%(this.m_bitFilter.length<<5);this.m_bitFilter[s>>5]|=1<<(31&s);const i=t%this.m_hashBuckets.length;let r=this.m_hashBuckets[i];r===et.st_nullNode()&&(r=this.m_lists.createList(),this.m_hashBuckets[i]=r);return this.m_lists.addElement(r,e)}deleteElement(e,t){void 0===t&&(t=this.m_hash.getHash(e));const i=t%this.m_hashBuckets.length,r=this.m_hashBuckets[i];r===et.st_nullNode()&&s("");let n=this.m_lists.getFirst(r),h=et.st_nullNode();for(;n!==et.st_nullNode();){const t=this.m_lists.getData(n),s=this.m_lists.getNext(n);t===e?(this.m_lists.deleteElementDirect(r,h,n),this.m_lists.getFirst(r)===et.st_nullNode()&&(this.m_lists.deleteList(r),this.m_hashBuckets[i]=et.st_nullNode())):h=n,n=s}}getFirstInBucket(e){const t=e%(this.m_bitFilter.length<<5);if(!(this.m_bitFilter[t>>5]&1<<(31&t)))return et.st_nullNode();const s=e%this.m_hashBuckets.length,i=this.m_hashBuckets[s];return i===et.st_nullNode()?et.st_nullNode():this.m_lists.getFirst(i)}getNextInBucket(e){return this.m_lists.getNext(e)}findNode(e){const t=this.m_hash.getHash(e);let s=this.getFirstInBucket(t);for(;s!==et.st_nullNode();){const t=this.m_lists.getData(s);if(this.m_hash.equal(t,e))return s;s=this.m_lists.getNext(s)}return et.st_nullNode()}getNextNode(t){return e(0),0}deleteNode(e){const t=this.getElement(e),i=this.m_hash.getHash(t)%this.m_hashBuckets.length,r=this.m_hashBuckets[i];r===et.st_nullNode()&&s(""),this.m_lists.deleteElementSearch(r,e),this.m_lists.getFirst(r)===et.st_nullNode()&&(this.m_lists.deleteList(r),this.m_hashBuckets[i]=et.st_nullNode())}getElement(e){return this.m_lists.getData(e)}static st_nullNode(){return et.st_nullNode()}clear(){e(0)}size(){return this.m_lists.getNodeCount()}dbgPrintBucketHistogram(){e(0)}}function ht(e,t,s,i,r){const n=new _t(r);return n.m_shape=e,n.m_sqrTolerance=t*t,n.m_cellSize=2*t,n.m_invCellSize=1/n.m_cellSize,n.m_geometry=s,n.m_bTrackChanges=i,n.m_bHasSegmentParentage=e.hasSegmentParentage(),n.clusterNonReciprocal()}function at(e,t,s,i,r){const n=e-s,h=t-i;return n*n+h*h<=r}function ot(){return{pt:new F,weight:0,rank:0,bMerged:!1}}function mt(e,t,s,i,r,n){const h=ot(),a=s+r;let o=!1,m=e.x;e.x!==t.x&&(i===n&&(m=(e.x*s+t.x*r)/a),o=!0);let g=e.y;return e.y!==t.y&&(i===n&&(g=(e.y*s+t.y*r)/a),o=!0),i!==n?i>n?(h.rank=i,h.weight=s,h.pt=e):(h.rank=n,h.weight=r,h.pt=t):(h.pt.setCoords(m,g),h.weight=a,h.rank=i),h.bMerged=o,h}function gt(e,t){const s=Ae(e);return Ge(s,t)}class lt{constructor(e,t,s,i,r){this.m_workPt=new F,this.m_shape=e,this.m_sqrTolerance=s,this.m_invCellSize=i,this.m_origin=t.clone(),this.m_hashValues=r}getHash(e){return this.m_shape.getUserIndex(e,this.m_hashValues)}calculateHash(t){return e(0),0}calculateHashFromVertex(e){this.m_shape.queryXY(e,this.m_workPt);const t=this.m_workPt.x-this.m_origin.x,s=Math.trunc(t*this.m_invCellSize+.5),i=this.m_workPt.y-this.m_origin.y;return gt(s,Math.trunc(i*this.m_invCellSize+.5))}dbgCalculateHashFromXy(t,s){return e(0),0}equal(t,s){return e(0),!1}}class _t{constructor(e){this.m_origin=F.getNAN(),this.m_sqrTolerance=0,this.m_cellSize=0,this.m_invCellSize=0,this.m_geometry=H,this.m_bucketArray=new Array(4),this.m_bucketHash=new Array(4),this.m_dbgCandidateCheckCount=0,this.m_nsr=new Xe,this.m_hashValues=-1,this.m_newClusters=-1,this.m_bTrackChanges=!1,this.m_bHasSegmentParentage=!1,this.m_shape=null,this.m_clusters=new et,this.m_hashFunction=null,this.m_hashTable=null,this.m_progressCounter=0,this.m_progressTracker=e}progress_(){}getNearestNeighbourCandidate(t,s,i,r,n){e(0)}findClusterCandidate(t,s){e(0)}collectClusterCandidates(e,t){const s=F.getNAN();this.m_shape.queryXY(e,s);const i=(s.x-this.m_origin.x)*this.m_invCellSize,r=(s.y-this.m_origin.y)*this.m_invCellSize,n=Math.trunc(i),h=Math.trunc(r);let a=0;for(let o=0;o<=1;o+=1)for(let e=0;e<=1;e+=1){const t=gt(n+o,h+e),s=this.m_hashTable.getFirstInBucket(t);s!==nt.st_nullNode()&&(this.m_bucketArray[a]=s,this.m_bucketHash[a]=t,a++)}for(let o=a-1;o>=1;o--){const e=this.m_bucketArray[o];for(let t=o-1;t>=0;t--)if(e===this.m_bucketArray[t]){this.m_bucketHash[t]=-1,a--,o!==a&&(this.m_bucketHash[o]=this.m_bucketHash[a],this.m_bucketArray[o]=this.m_bucketArray[a]);break}}for(let o=0;o<a;o++)this.collectNearestNeighbourCandidates(e,this.m_bucketHash[o],s,this.m_bucketArray[o],t)}collectNearestNeighbourCandidates(e,t,s,i,r){const n=F.getNAN();for(let h=i;h!==nt.st_nullNode();h=this.m_hashTable.getNextInBucket(h)){const i=this.m_hashTable.getElement(h);e===i||-1!==t&&this.m_shape.getUserIndex(i,this.m_hashValues)!==t||(this.m_shape.queryXY(i,n),at(s.x,s.y,n.x,n.y,this.m_sqrTolerance)&&r.push(h))}}mergeClusters(e,t,s){let i=this.m_shape.getUserIndex(e,this.m_newClusters);const r=this.m_shape.getUserIndex(t,this.m_newClusters);-1===i&&(i=this.m_clusters.createList(),this.m_clusters.addElement(i,e),this.m_shape.setUserIndex(e,this.m_newClusters,i)),-1===r?this.m_clusters.addElement(i,t):this.m_clusters.concatenateLists(i,r),this.m_shape.setUserIndex(t,this.m_newClusters,M.impossibleIndex2());const n=this.mergeVertices(e,t);if(s){const t=this.m_hashFunction.calculateHashFromVertex(e);this.m_shape.setUserIndex(e,this.m_hashValues,t)}return n}mergeVertices(e,t){const s=F.getNAN();this.m_shape.queryXY(e,s);const i=F.getNAN();this.m_shape.queryXY(t,i);const r=this.m_shape.getRank(e),n=this.m_shape.getRank(t),h=this.m_shape.getWeight(e),a=this.m_shape.getWeight(t);let o,m,g,l,_=!1;if(r===n?(o=r,m=h+a,g=s.x,s.x!==i.x&&(g=(s.x*h+i.x*a)/m,_=!0),l=s.y,s.y!==i.y&&(l=(s.y*h+i.y*a)/m,_=!0)):(r>n?(g=s.x,l=s.y,m=h,o=r):(g=i.x,l=i.y,m=a,o=n),_=!s.equals(i)),_&&(this.m_shape.setXYMonotonic(e,g,l),this.m_bTrackChanges&&this.m_shape.setGeometryModifiedWithVertex(e,!0),this.m_bHasSegmentParentage)){const s=this.m_shape.getSegmentParentageBreakVertex(e)||this.m_shape.getSegmentParentageBreakVertex(t);this.m_shape.setSegmentParentageBreakVertex(e,s),this.m_shape.setSegmentParentageBreakVertex(t,s)}return this.m_shape.setWeight(e,m),this.m_shape.setRank(e,o),_}clusterReciprocal(){return e(0),!1}needsClustering(){return e(0),!1}clusterNonReciprocal(){const e=this.m_shape.getSelectedCount(),t=this.m_shape.getEnvelope2D(this.m_progressTracker);this.m_origin=t.getLowerLeft();const s=Math.max(t.height(),t.width())/(Ne()-1);this.m_cellSize<s&&(this.m_cellSize=s,this.m_invCellSize=1/this.m_cellSize),this.m_clusters.clear(),this.m_clusters.reserveLists(Math.trunc(this.m_shape.getSelectedCount()/3+1)),this.m_clusters.reserveNodes(Math.trunc(this.m_shape.getSelectedCount()/3+1)),this.m_hashValues=this.m_shape.createUserIndex(),this.m_newClusters=this.m_shape.createUserIndex(),this.m_hashFunction=new lt(this.m_shape,this.m_origin,this.m_sqrTolerance,this.m_invCellSize,this.m_hashValues),this.m_hashTable=new nt(Math.trunc(4*e/3),this.m_hashFunction),this.m_hashTable.reserveElements(this.m_shape.getSelectedCount());let i=!1;{const e=this.m_shape.queryVertexIteratorOnSelection(this.m_geometry);for(let t=e.next();t!==H;t=e.next()){this.progress_();const e=this.m_hashFunction.calculateHashFromVertex(t);this.m_shape.setUserIndex(t,this.m_hashValues,e),this.m_hashTable.addElement(t,e)}}{const e=[],t=this.m_shape.queryVertexIteratorOnSelection(this.m_geometry);for(let s=t.next();s!==H;s=t.next()){if(this.m_shape.getUserIndex(s,this.m_newClusters)===M.impossibleIndex2())continue;let t=this.m_shape.getUserIndex(s,this.m_hashValues);this.m_hashTable.deleteElement(s,t);let r=!1;for(;this.collectClusterCandidates(s,e),0!==e.length;){let t=0;for(let i=0,r=e.length;i<r;i++){this.progress_();const n=e[i],h=this.m_hashTable.getElement(n);this.m_hashTable.deleteNode(n);const a=i+1===r;t|=this.mergeClusters(s,h,a)?1:0}if(r||=0!==t,i||=0!==t,e.length=0,!t)break}r&&(t=this.m_shape.getUserIndex(s,this.m_hashValues)),this.m_hashTable.addElement(s,t)}e.length=0}return i&&this.applyClusterPositions_(),this.m_hashTable=null,this.m_hashFunction=null,this.m_shape.removeUserIndex(this.m_hashValues),this.m_shape.removeUserIndex(this.m_newClusters),i}applyClusterPositions_(){const e=F.getNAN();for(let t=this.m_clusters.getFirstList();t!==et.st_nullNode();t=this.m_clusters.getNextList(t)){let s=this.m_clusters.getFirst(t);const i=this.m_clusters.getElement(s);this.m_shape.queryXY(i,e);const r=this.m_shape.getRank(i),n=this.m_shape.getWeight(i);for(s=this.m_clusters.getNext(s);s!==et.st_nullNode();s=this.m_clusters.getNext(s)){const t=this.m_clusters.getElement(s);if(this.m_bTrackChanges?this.m_shape.isEqualXYPoint2D(t,e)||(this.m_shape.setXYMonotonicPoint2D(t,e),this.m_shape.setGeometryModifiedWithVertex(t,!0)):this.m_shape.setXYMonotonicPoint2D(t,e),this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentageBreakVertex(i)||this.m_shape.getSegmentParentageBreakVertex(t);this.m_shape.setSegmentParentageBreakVertex(i,e),this.m_shape.setSegmentParentageBreakVertex(t,e)}this.m_shape.setWeight(t,n),this.m_shape.setRank(t,r)}}}}class dt{constructor(){this.m_inputParts=[],this.m_resultParts1=[],this.m_resultParts2=[],this.m_resultSegments=[],this.m_freeSegments=[],this.m_inputSegments=[],this.m_param1=[],this.m_param2=[],this.m_tolerance=0,this.m_point=new P,this.m_pointWeight=1,this.m_maxDensifyLimit=0,this.m_pointRank=0,this.m_changed1=!1,this.m_changed2=!1,this.m_adaptiveDensify=!1}clear(){this.freeAllResultSegments(),this.m_inputSegments.length=0,this.m_inputParts.length=0,this.m_resultParts1.length=0,this.m_resultParts2.length=0,this.m_param1.length=0,this.m_param2.length=0,this.m_adaptiveDensify=!1,this.m_changed1=!1,this.m_changed2=!1}newIntersectionPart_(e,t,s,i,r,n,h,a,o,m){return ut(e,t,s,i,r,n,h,a,o,m)}pushSegment(e,t,s,i,r,n,h,a,o,m){return this.m_inputParts.push(this.newIntersectionPart_(this.m_inputSegments.length,t,s,i,r,n,h,a,o,m)),this.m_inputSegments.push(e),this.m_inputParts.length-1}getResultSegmentCount(e){return this.m_adaptiveDensify?0===e?this.m_param1.length-1:this.m_param2.length-1:0===e?this.m_resultParts1.length:this.m_resultParts2.length}getResultPart_(e,t){return 0===e?this.m_resultParts1[t]:this.m_resultParts2[t]}getResultSegment(e,t){return this.m_resultSegments[this.getResultPart_(e,t).segmentIndex].get()}getSegmentChanged(e){return 0===e?this.m_changed1:this.m_changed2}getResultSegmentStartPointWeight(e,t){return this.getResultPart_(e,t).weightStart}getResultSegmentStartPointRank(e,t){return this.getResultPart_(e,t).rankStart}getResultSegmentSegmentParentage(e,t){return this.getResultPart_(e,t).segmentParentage}getResultSegmentStartPointIsBreak(e,t){return this.getResultPart_(e,t).u.bBreakStart}getResultSegmentEndPointWeight(e,t){return this.getResultPart_(e,t).weightEnd}getResultSegmentEndPointRank(e,t){return this.getResultPart_(e,t).rankEnd}getResultSegmentEndPointIsBreak(e,t){return this.getResultPart_(e,t).u.bBreakEnd}getResultSegmentInteriorRank(e,t){return this.getResultPart_(e,t).rankInterior}getResultSegmentInteriorWeight(e,t){return this.getResultPart_(e,t).weightInterior}getResultPoint(){return this.m_point}getResultPointWeight(){return this.m_pointWeight}getResultPointRank(){return this.m_pointRank}getResultPointChanged(){return this.m_changed2}intersectLines(e,t){2!==this.m_inputSegments.length&&o(""),this.m_changed1=!1,this.m_changed2=!1,this.m_tolerance=e;const s=W(e*dt.c_smallToleranceFactor);let i=!1;const r=this.m_inputParts[0],n=this.m_inputParts[1],h=this.m_inputSegments[r.segmentIndex],a=this.m_inputSegments[n.segmentIndex];if(t||5&S(!0,h,a,e,!0)){const t=Ie(!0,h,a,null,this.m_param1,this.m_param2,e);0===t&&o("");const m=new Array(t);for(let e=0;e<t;++e)m[e]=F.getNAN();const g=new Float64Array(t),l=new Int32Array(t),_=new Array(t),d=new Array(t);for(let e=0;e<t;++e)_[e]=ct(),d[e]=ct();for(let e=0;e<t;e++){const t=this.m_param1[e],o=this.m_param2[e];let p,u=r.rankInterior,c=r.weightInterior;0===t?(u=r.rankStart,c=r.weightStart,p=r.u.bBreakStart):1===t?(u=r.rankEnd,c=r.weightEnd,p=r.u.bBreakEnd):(this.m_changed1=!0,p=!1);let f,x=n.rankInterior,E=n.weightInterior;0===o?(x=n.rankStart,E=n.weightStart,f=n.u.bBreakStart):1===o?(x=n.rankEnd,E=n.weightEnd,f=n.u.bBreakEnd):(this.m_changed2=!0,f=!1);const I=u,S=x;let C=1,P=0,y=F.getNAN();if(I===S){const i=h.getCoord2D(t),r=a.getCoord2D(o);C=c+E;P=u,xe(i,r,E/C,y);const n=F.sqrDistance(y,i),m=F.sqrDistance(y,r);_[e].bBigMove=n>s,d[e].bBigMove=m>s,this.m_changed1||i.equals(y)||(this.m_changed1=!0),this.m_changed2||r.equals(y)||(this.m_changed2=!0)}else if(I>S){y=h.getCoord2D(t);const i=a.getCoord2D(o);C=c,P=u;const r=F.sqrDistance(y,i);_[e].bBigMove=!1,d[e].bBigMove=r>s,this.m_changed2||i.equals(y)||(this.m_changed2=!0)}else{y=a.getCoord2D(o),C=E,P=x;const i=h.getCoord2D(t),r=F.sqrDistance(y,i);_[e].bBigMove=r>s,d[e].bBigMove=!1,this.m_changed1||i.equals(y)||(this.m_changed1=!0)}m[e].assign(y),g[e]=C,l[e]=P,_[e].bIsBreak=p||f,d[e].bIsBreak=p||f,i||=_[e].bBigMove||d[e].bBigMove}const p=r.rankInterior,u=r.weightInterior;let c=0,f=-1;for(let s=0;s<=t;s++){const i=s<t?this.m_param1[s]:1;if(i!==c){const n=this.allocResultSegment(),a=this.m_resultSegments[n];let o,d,x,E;h.queryCut(c,i,a,!1),a.get().snapControlPoints(e*e);let I=!1,S=!1,C=!1,P=!1,y=!1,N=F.getNAN(),v=F.getNAN();-1!==f?(d=l[f],o=g[f],I=_[f].bBigMove,N.assign(m[f]),C=_[f].bIsBreak,y=!0):(o=r.weightStart,d=r.rankStart,N=a.get().getStartXY(),C=r.u.bBreakStart),s<t?(E=l[s],x=g[s],S=_[s].bBigMove,v.assign(m[s]),P=_[s].bIsBreak,y=!0):(x=r.weightEnd,E=r.rankEnd,v=a.get().getEndXY(),P=r.u.bBreakEnd),y&&a.get().setCoordsForIntersector(N,v,!0),this.m_resultParts1.push(this.newIntersectionPart_(n,o,d,x,E,u,p,C,P,r.segmentParentage));const b=this.m_resultParts1.at(-1);b.u.bBigMoveStart=I,b.u.bBigMoveEnd=S,c=i,f=s}else-1===f&&(f=s)}const x=new Array(t);for(let e=0;e<t;e++)x[e]=e;t>2?(x.sort(((e,t)=>this.m_param2[e]<this.m_param2[t]?-1:this.m_param2[e]>this.m_param2[t]?1:0)),K(this.m_param2)):2===t&&this.m_param2[0]>this.m_param2[1]&&(this.m_param2[1]=q(this.m_param2[0],this.m_param2[0]=this.m_param2[1]),x[1]=q(x[0],x[0]=x[1]));const E=n.rankInterior,I=n.weightInterior;c=0,f=-1;for(let s=0;s<=t;s++){const i=s<t?this.m_param2[s]:1;if(i!==c){const r=this.allocResultSegment(),h=this.m_resultSegments[r];let o,_,p,u;a.queryCut(c,i,h,!1),h.get().snapControlPoints(e*e);let S=F.getNAN(),C=F.getNAN(),P=!1,y=!1,N=!1,v=!1,b=!1;if(-1!==f){const e=x[f];o=g[e],_=l[e],S.assign(m[e]),N=d[e].bBigMove,P=d[e].bIsBreak,b=!0}else o=n.weightStart,_=n.rankStart,S=h.get().getStartXY(),P=n.u.bBreakStart;if(s!==t){const e=x[s];p=g[e],u=l[e],C.assign(m[e]),v=d[e].bBigMove,y=d[e].bIsBreak,b=!0}else p=n.weightEnd,u=n.rankEnd,C=h.get().getEndXY(),y=n.u.bBreakEnd;b&&h.get().setCoordsForIntersector(S,C,!0),this.m_resultParts2.push(this.newIntersectionPart_(r,o,_,p,u,I,E,P,y,n.segmentParentage));const w=this.m_resultParts2.at(-1);w.u.bBigMoveStart=N,w.u.bBigMoveEnd=v,c=i,f=s}else-1===f&&(f=s)}return i?3:2}return 0}intersect(e,t){const s=this.m_inputParts[0],r=this.m_inputParts[1],n=this.m_inputSegments[s.segmentIndex].getGeometryType(),h=this.m_inputSegments[r.segmentIndex].getGeometryType();if(n!==i.enumLine||h!==i.enumLine){return new It(this).intersectCurves(e,t)}return this.intersectLines(e,t)}intersectEx(e,t,s,i,r){this.m_point.assignCopy(t),1!==this.m_inputSegments.length&&o(""),this.m_tolerance=e,this.m_changed1=!1,this.m_changed2=!1;const n=W(e*dt.c_smallToleranceFactor);let h=!1;const a=this.m_inputParts[0],m=this.m_inputSegments[a.segmentIndex];if(r||m.isIntersectingPoint(t.getXY(),e,!0)){this.m_param1=Y(16,Number.NaN);const r=m.getClosestCoordinate(t.getXY(),!1);this.m_param1[0]=r;let o=a.rankInterior,g=a.weightInterior;0===r?(o=a.rankStart,g=a.weightStart):1===r?(o=a.rankEnd,g=a.weightEnd):this.m_changed1=!0;let l=o;const _=s,d=i;l===_&&m.isCurve()&&(l=_+1);let p=1,u=0;const c=new F;if(l===_){const e=m.getCoord2D(r),s=t.getXY();p=g+d,u=o;xe(e,s,d/p,c),this.m_changed1||e.equals(c)||(this.m_changed1=!0),this.m_changed2||s.equals(c)||(this.m_changed2=!0);h=F.sqrDistance(c,e)>n}else if(l>_)c.assign(m.getCoord2D(r)),p=g,u=o,this.m_changed2||c.equals(t.getXY())||(this.m_changed2=!0);else{c.assign(m.getCoord2D(r)),p=d,u=_,this.m_changed1||c.equals(t.getXY())||(this.m_changed1=!0);h=F.sqrDistance(c,t.getXY())>n}let f=0,x=-1;const E=1;for(let t=0;t<=E;t++){const s=t<E?this.m_param1[0]:1;if(s!==f){const i=this.allocResultSegment(),r=this.m_resultSegments[i];m.queryCut(f,s,r),r.get().snapControlPoints(e*e);let n=a.weightStart,h=a.weightEnd,o=a.rankStart,g=a.rankEnd;const l=a.rankInterior,_=a.weightInterior;let d=a.u.bBreakStart,I=a.u.bBreakEnd;-1!==x&&(n=p,o=u,d=!0,r.get().setCoordsForIntersector(c,r.get().getEndXY(),!0)),t!==E&&(h=p,g=u,I=!0,r.get().setCoordsForIntersector(r.get().getStartXY(),c,!0)),f=s,this.m_resultParts1.push(this.newIntersectionPart_(i,n,o,h,g,_,l,d,I,a.segmentParentage))}x=t}return this.m_point.setXY(c),this.m_pointWeight=p,this.m_pointRank=u,h?3:2}return 0}getTolerance(){return this.m_tolerance}freeAllResultSegments(){this.m_resultSegments.length=0,this.m_freeSegments.length=0}freeResultSegment(e){this.m_freeSegments.push(e)}allocResultSegment(){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const e=new G,t=this.m_resultSegments.length;return this.m_resultSegments.push(e),t}allocResultSegmentFromBuffer(e){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const t=new G({copy:e}),s=this.m_resultSegments.length;return this.m_resultSegments.push(t),s}allocResultSegmentFromSegment(e){if(this.m_freeSegments.length){return this.m_freeSegments.pop()}const t=new G({segment:e}),s=this.m_resultSegments.length;return this.m_resultSegments.push(t),s}}function pt(e,t){return{bBigMoveStart:!1,bBigMoveEnd:!1,bBreakStart:e,bBreakEnd:t}}function ut(e,t,s,i,r,n,h,a,o,m){return{segmentIndex:e,weightStart:t,rankStart:s,weightEnd:i,rankEnd:r,weightInterior:n,rankInterior:h,segmentParentage:m,u:pt(a,o)}}function ct(){return{bBigMove:!1,bIsBreak:!1}}dt.maxWeight=.1*Number.MAX_VALUE,dt.c_smallToleranceFactor=.01,dt.c_maxGeometryTypeToRankDelta=8;let ft=class{constructor(){this.start=null,this.end=null,this.equalEdge=null,this.segmentIndex=-1,this.segmentParentage=-1,this.weight=0,this.rank=0}hasSegment(){return this.segmentIndex>=0}transferAttributes(e,t,s){if(1===t.getDescription().getAttributeCount())return;const i=e.parent.m_resultSegments[this.segmentIndex].get().getStartXY(),r=e.parent.m_resultSegments[this.segmentIndex].get().getEndXY(),n=new P;t.queryStart(n),s?(n.setXY(i),e.parent.m_resultSegments[this.segmentIndex].get().setStart(n)):(n.setXY(r),e.parent.m_resultSegments[this.segmentIndex].get().setEnd(n)),t.queryEnd(n),s?(n.setXY(r),e.parent.m_resultSegments[this.segmentIndex].get().setEnd(n)):(n.setXY(i),e.parent.m_resultSegments[this.segmentIndex].get().setStart(n))}copyFromWhenOverlap(e,t,s){this.equalEdge=t,t.equalEdge=this,this.segmentIndex=e.parent.allocResultSegmentFromBuffer(e.parent.m_resultSegments[t.segmentIndex]),this.segmentParentage=t.segmentParentage,this.weight=t.weight,this.rank=t.rank,s?(this.start.copyFrom(t.start),this.end.copyFrom(t.end)):(this.start.copyFrom(t.end),this.end.copyFrom(t.start),e.parent.m_resultSegments[this.segmentIndex].get().reverse())}disconnect(t){e(0)}getEnvelope(){return e(0),{}}getEnd(){return e(0),{}}getNextInChain(){return this.end.nextInChain}getPrevInChain(){return this.start.prevInChain}};class xt{constructor(){this.hash=0,this.pt=new F,this.prevInChain=null,this.nextInChain=null,this.prevInHash=null,this.nextInHash=null,this.prevEqual=null,this.nextEqual=null,this.weight=0,this.rank=0,this.bBigMove=!1,this.bIsBreak=!1}copyFrom(e){this.pt.assign(e.pt),this.weight=e.weight,this.rank=e.rank,this.bBigMove=e.bBigMove,this.bIsBreak=e.bIsBreak}nextNode(){return e(0),{}}prevNode(){return e(0),{}}startingEdges(t,s){e(0)}terminatingEdges(t,s){e(0)}sameListSize(){return e(0),0}equalListHead(){let e=this;for(;null!==e.prevEqual;e=e.prevEqual);return e}}function Et(e,t,s,i){return{edge1:e,edge2:t,recursion:s,bIsIntersecting:i}}class It{constructor(e){this.m_pairs=[],this.m_chainOrigin1=null,this.m_chainOrigin2=null,this.m_newNodes=[],this.m_hashTableOfEquals=[],this.m_hashTableOfEqualsSize=0,this.m_origin=new F,this.m_cell=new F,this.parent=e}addSegment(t,s,i,r,n,h,a,o,m,g,l){const _=this.newNode(this.parent.m_resultSegments[t].get().getStartXY(),i,r,m),d=this.newNode(this.parent.m_resultSegments[t].get().getEndXY(),n,h,g);this.newEdge(_,d,t,a,o,l),null===this.m_chainOrigin1?this.m_chainOrigin1=_:null===this.m_chainOrigin2?this.m_chainOrigin2=_:e(0)}intersectCurvesHelper(t,s,r,n,h){const a=this.tryOverlapIntersectCurves(t,s,r,n);if(0!==a)return a;const m=W(.01*r);let g=!1;const l=this.getSegment(t).get(),_=this.getSegment(s).get();if(l.isDegenerate(0)||_.isDegenerate(0))return 0;let d=this.processSharpCorners(l,_,r,h>4);const p=d>0;if(!p){if(!(n||5&J(!0,!1,l,_,r,!0)))return 0;d=Ie(!0,l,_,null,this.parent.m_param1,this.parent.m_param2,r)}0===d&&o("");const u=l.getGeometryType(),c=_.getGeometryType(),f=he(F,d),x=he(F,d),E=new Array(d),I=new Array(d),S=new Array(d),C=new Array(d),P=ve(ct,d),y=ve(ct,d);let N=!1,v=!1;for(let e=0;e<d;e++){const i=this.parent.m_param1[e],n=this.parent.m_param2[e];let h=t.rank,a=t.weight,o=!0,d=!1;0===i?(h=t.start.rank,a=t.start.weight,d=t.start.bIsBreak):1===i?(h=t.end.rank,a=t.end.weight,d=t.end.bIsBreak):(N=!0,o=!1);let b=s.rank,w=s.weight,V=!1,H=!0;0===n?(b=s.start.rank,w=s.start.weight,V=s.start.bIsBreak):1===n?(b=s.end.rank,w=s.end.weight,V=s.end.bIsBreak):(v=!0,H=!1);let T=h,k=b;if(T===k&&(T*=dt.c_maxGeometryTypeToRankDelta,k*=dt.c_maxGeometryTypeToRankDelta,T+=St(u,l,!1),k+=St(c,_,!1)),o&&H&&k===T){const e=l.getCoord2D(i),t=_.getCoord2D(n);e.equals(t)&&(k=T-1)}let G=1,B=0,D=1,A=0;const U=new F,O=new F,Y=l.getCoord2D(i),X=_.getCoord2D(n);if(p&&F.distance(Y,X)>r)U.setCoordsPoint2D(Y),O.setCoordsPoint2D(X),G=a,D=w,B=h,A=b,P[e].bBigMove=!1,y[e].bBigMove=!1,d=!0,V=!0;else if(T===k){D=G=a+w,A=B=h;xe(Y,X,w/G,U),O.setCoordsPoint2D(U);const t=F.sqrDistance(U,Y),s=F.sqrDistance(U,X);P[e].bBigMove=t>m,y[e].bBigMove=s>m,N||Y.equals(U)||(N=!0),v||X.equals(O)||(v=!0)}else if(T>k){U.setCoordsPoint2D(Y),O.setCoordsPoint2D(U),D=G=a,A=B=h;const t=F.sqrDistance(U,X);P[e].bBigMove=!1,y[e].bBigMove=t>m,v||X.equals(O)||(v=!0)}else{O.setCoordsPoint2D(X),U.setCoordsPoint2D(O),D=G=w,A=B=b;const t=F.sqrDistance(U,Y);P[e].bBigMove=t>m,y[e].bBigMove=!1,N||Y.equals(U)||(N=!0)}f[e].assign(U),x[e].assign(O),E[e]=G,I[e]=D,S[e]=B,C[e]=A,P[e].bIsBreak=d||V,y[e].bIsBreak=d||V,g||=P[e].bBigMove||y[e].bBigMove,e>0&&(i!==this.parent.m_param1[e-1]&&n!==this.parent.m_param2[e-1]||(S[e]<=S[e-1]?(f[e].assign(x[e-1]),E[e]=I[e-1],S[e]=C[e-1],x[e].assign(x[e-1]),I[e]=I[e-1],C[e]=C[e-1],P[e].bBigMove||=P[e-1].bBigMove,y[e].bBigMove||=y[e-1].bBigMove,P[e].bIsBreak||=P[e-1].bIsBreak,y[e].bIsBreak||=y[e-1].bIsBreak):(f[e-1].assign(f[e]),E[e-1]=E[e],S[e-1]=S[e],x[e-1].assign(x[e]),I[e-1]=I[e],C[e-1]=C[e],P[e-1].bBigMove||=P[e].bBigMove,y[e-1].bBigMove||=y[e].bBigMove,P[e-1].bIsBreak||=P[e].bIsBreak,y[e-1].bIsBreak||=y[e].bIsBreak)))}if(!N&&!v&&2===d){if(u!==i.enumLine||c!==i.enumLine){if(this.processDoublyConnectedEdges(t,s,h+1,r))return this.parent.m_changed1=!0,this.parent.m_changed2=!0,2;e(0)}e(0)}this.parent.m_changed1||=N,this.parent.m_changed2||=v;let b=t,w=t.end.weight,V=t.end.rank,H=t.end.bBigMove,T=t.end.bIsBreak,k=0,G=-1;for(let e=0;e<=d;e++){const s=e<d?this.parent.m_param1[e]:1;if(s!==k){const i=this.parent.allocResultSegment(),n=this.parent.m_resultSegments[i];let h,a,o,m;l.queryCut(k,s,n,!1),n.get().snapControlPoints(r*r);let g=!1,_=!1,p=!1,u=!1;const c=new F,x=new F;-1!==G?(a=S[G],h=E[G],p=P[G].bBigMove,g=P[G].bIsBreak,c.assign(f[G])):(h=t.start.weight,a=t.start.rank,p=t.start.bBigMove,g=t.start.bIsBreak,c.assign(n.get().getStartXY())),e<d?(m=S[e],o=E[e],u=P[e].bBigMove,_=P[e].bIsBreak,x.assign(f[e])):(o=w,m=V,u=H,_=T,x.assign(n.get().getEndXY()));let I=b;s<1&&(this.splitEdgeInPlace(b),I=b.getNextInChain()),this.updateSegmentOnly(b,i),0===b.start.hash||b.start.pt.equals(c)||(this.m_newNodes.push(b.start),this.removeNodeFromHash(b.start),b.start.hash=0),0===b.end.hash||b.end.pt.equals(x)||(this.m_newNodes.push(b.end),this.removeNodeFromHash(b.end),b.end.hash=0),b.start.pt.assign(c),b.end.pt.assign(x),b.start.bBigMove||=p,b.end.bBigMove||=u,b.start.bIsBreak||=g,b.end.bIsBreak||=_,b.start.weight=h,b.start.rank=a,b.end.weight=o,b.end.rank=m,b=I,k=s,G=e}else-1===G&&(G=e)}const B=b.getNextInChain(),D=[];D.length=d;for(let e=0;e<d;e++)D[e]=e;d>2?(D.sort(((e,t)=>be(this.parent.m_param2[e],this.parent.m_param2[t]))),this.parent.m_param2.sort(be)):2===d&&this.parent.m_param2[0]>this.parent.m_param2[1]&&(this.parent.m_param2[1]=q(this.parent.m_param2[0],this.parent.m_param2[0]=this.parent.m_param2[1]),D[1]=q(D[0],D[0]=D[1])),b=s,w=s.end.weight,V=s.end.rank,H=s.end.bBigMove,T=s.end.bIsBreak,k=0,G=-1;for(let e=0;e<=d;e++){const t=e<d?this.parent.m_param2[e]:1;if(t!==k){const i=this.parent.allocResultSegment(),n=this.parent.m_resultSegments[i];let h,a,o,m;_.queryCut(k,t,n,!1),n.get().snapControlPoints(r*r);const g=new F,l=new F;let p=!1,u=!1,c=!1,f=!1;if(-1!==G){const e=D[G];h=I[e],a=C[e],g.assign(x[e]),c=y[e].bBigMove,p=y[e].bIsBreak}else h=s.start.weight,a=s.start.rank,c=s.start.bBigMove,p=s.start.bIsBreak,g.assign(n.get().getStartXY());if(e!==d){const t=D[e];o=I[t],m=C[t],l.assign(x[t]),f=y[t].bBigMove,u=y[t].bIsBreak}else o=w,m=V,f=H,u=T,l.assign(n.get().getEndXY());let E=b;t<1&&(this.splitEdgeInPlace(b),E=b.getNextInChain()),this.updateSegmentOnly(b,i),0===b.start.hash||b.start.pt.equals(g)||(this.m_newNodes.push(b.start),this.removeNodeFromHash(b.start),b.start.hash=0),0===b.end.hash||b.end.pt.equals(l)||(this.m_newNodes.push(b.end),this.removeNodeFromHash(b.end),b.end.hash=0),b.start.pt.assign(g),b.end.pt.assign(l),b.start.bBigMove||=c,b.end.bBigMove||=f,b.start.bIsBreak||=p,b.end.bIsBreak||=u,b.start.weight=h,b.start.rank=a,b.end.weight=o,b.end.rank=m,b=E,k=t,G=e}else-1===G&&(G=e)}const A=b.getNextInChain();return this.postProcessResultPartsForCurves(t,B,s,A,h+1),g?3:2}intersectCurves(t,s){2!==this.parent.m_inputSegments.length&&o(""),this.parent.m_changed1=!1,this.parent.m_changed2=!1,this.parent.m_tolerance=t,this.m_hashTableOfEqualsSize=0,this.m_hashTableOfEquals=we(16);const i=n.constructEmpty();for(let e=0;e<2;e++){const t=this.parent.allocResultSegmentFromSegment(this.parent.m_inputSegments[this.parent.m_inputParts[e].segmentIndex]),s=n.constructEmpty();this.parent.m_inputSegments[this.parent.m_inputParts[e].segmentIndex].queryLooseEnvelope(s),i.mergeEnvelope2D(s);const r=this.parent.m_inputParts[e];this.addSegment(t,0,r.weightStart,r.rankStart,r.weightEnd,r.rankEnd,r.weightInterior,r.rankInterior,r.u.bBreakStart,r.u.bBreakEnd,r.segmentParentage)}i.inflateCoords(100*t,100*t),this.m_origin.assign(i.getLowerLeft()),this.m_cell.setCoords(2*t,2*t),this.m_pairs.push(Et(this.m_chainOrigin1.nextInChain,this.m_chainOrigin2.nextInChain,0,s));let r=0,h=!0;for(;this.m_pairs.length;){const s=this.m_pairs.at(-1);this.m_pairs.pop(),e(s.recursion>=0),e(s.recursion<=256),this.clusterNodes(t);const i=this.intersectCurvesHelper(s.edge1,s.edge2,t,s.bIsIntersecting,s.recursion);h&&(h=!1,r=i)}for(let e=0;e<2;e++){const t=0===e?this.parent.m_resultParts1:this.parent.m_resultParts2;for(let s=(0===e?this.m_chainOrigin1:this.m_chainOrigin2).nextInChain;null!=s;s=s.getNextInChain())t.push(this.parent.newIntersectionPart_(s.segmentIndex,s.start.weight,s.start.rank,s.end.weight,s.end.rank,s.weight,s.rank,s.start.bIsBreak,s.end.bIsBreak,s.segmentParentage)),t.at(-1).u.bBigMoveStart=s.start.bBigMove,t.at(-1).u.bBigMoveEnd=s.end.bBigMove}return r}tryOverlapIntersectCurves(t,s,i,r){const n=this.parent.m_resultSegments[t.segmentIndex].get(),h=this.parent.m_resultSegments[s.segmentIndex].get(),a=n.getStartXY().equals(h.getStartXY())&&n.getEndXY().equals(h.getEndXY()),o=n.getStartXY().equals(h.getEndXY())&&n.getEndXY().equals(h.getStartXY());if(!a&&!o)return 0;const m=Ve(n,h,!0);if(0!==m&&He(n,h)&&t.segmentParentage===s.segmentParentage){let t=!1;if(m>0)t=n.equals(h);else{e(-1===m);const s=new G({segment:h});s.get().reverse(),t=n.equals(s.get())}if(t)return 1}const g=i*dt.c_smallToleranceFactor;let l=!1;if(0===m){const e=[.5,.25,.75,.125,.375,.625,.875,.5625,.3125];for(let t=0,s=e.length;t<s;++t){const s=e[t],r=new F;n.queryCoord2D(s,r);const a=h.getClosestCoordinate(r,!1),o=new F;h.queryCoord2D(a,o);const m=F.distance(r,o);if(m>i)return 0;l||=m>g}for(let t=0,s=e.length;t<s;++t){const s=e[t],r=new F;h.queryCoord2D(s,r);const a=n.getClosestCoordinate(r,!1),o=new F;n.queryCoord2D(a,o);const m=F.distance(r,o);if(m>i)return 0;l||=m>g}}let _=t.rank,d=s.rank;return _===d&&(_*=dt.c_maxGeometryTypeToRankDelta,d*=dt.c_maxGeometryTypeToRankDelta,_+=St(n.getGeometryType(),n,!0),d+=St(h.getGeometryType(),h,!0)),_>d?(s.copyFromWhenOverlap(this,t,a),s.transferAttributes(this,n,a)):d>_?(t.copyFromWhenOverlap(this,s,a),t.transferAttributes(this,h,a)):t.segmentParentage<=s.segmentParentage?(t.weight=t.weight+s.weight,s.copyFromWhenOverlap(this,t,a),s.transferAttributes(this,n,a)):(s.weight=t.weight+s.weight,t.copyFromWhenOverlap(this,s,a),t.transferAttributes(this,h,a)),l?3:2}postProcessResultPartsForCurves(e,t,s,i,r){r===Te()&&o("curve_helper");for(let n=e;n!==t;n=n.getNextInChain())this.updateSegmentToNodes(n);for(let n=s;n!==i;n=n.getNextInChain())this.updateSegmentToNodes(n);for(let n=e;n!==t;n=n.getNextInChain()){const e=n.end.pt.sub(n.start.pt);for(let t=s;t!==i;t=t.getNextInChain()){let s=0;if(n.start.pt.equals(t.start.pt)&&n.end.pt.equals(t.end.pt)?s=1:n.start.pt.equals(t.end.pt)&&n.end.pt.equals(t.start.pt)&&(s=-1),!s){let s=n.start.pt.equals(t.start.pt)?1:0;if(s||(s=n.end.pt.equals(t.end.pt)?2:0,s||(s=n.end.pt.equals(t.start.pt)?3:0,s||(s=n.start.pt.equals(t.end.pt)?4:0))),s){const i=t.end.pt.sub(t.start.pt),h=e.dotProduct(i);let a;switch(s){case 1:case 2:a=h>0;break;case 3:case 4:a=h<0;break;default:o("")}a&&this.m_pairs.push(Et(n,t,r,!1))}continue}const i=this.parent.m_resultSegments[n.segmentIndex],h=this.parent.m_resultSegments[t.segmentIndex],a=[.5,.25,.75];for(let e=0,t=a.length;e<t;++e){const t=a[e],r=new F;i.get().queryCoord2D(t,r);const n=h.get().getClosestCoordinate(r,!1),o=new F;h.get().queryCoord2D(n,o);if(F.distance(r,o)>this.parent.m_tolerance){s=0;break}}if(!s){this.m_pairs.push(Et(n,t,r,!1));continue}for(let e=0,t=a.length;e<t;++e){const t=a[e],r=new F;h.get().queryCoord2D(t,r);const n=i.get().getClosestCoordinate(r,!1),o=new F;i.get().queryCoord2D(n,o);if(F.distance(r,o)>this.parent.m_tolerance){s=0;break}}if(!s){this.m_pairs.push(Et(n,t,r,!1));continue}n.equalEdge=t,t.equalEdge=n;let m=n.rank,g=t.rank;m===g&&(m*=dt.c_maxGeometryTypeToRankDelta,g*=dt.c_maxGeometryTypeToRankDelta,m+=St(i.get().getGeometryType(),i.get(),!0),g+=St(h.get().getGeometryType(),h.get(),!0)),m>g||m===g&&n.segmentParentage<=t.segmentParentage?(i.copyTo(h,!1),t.segmentParentage=n.segmentParentage,-1===s&&h.get().reverse()):(h.copyTo(i,!1),n.segmentParentage=t.segmentParentage,-1===s&&i.get().reverse());break}}this.updateAttachedEdgesAfterNodeChange(e.start),t&&this.updateAttachedEdgesAfterNodeChange(t.start),this.updateAttachedEdgesAfterNodeChange(s.start),i&&this.updateAttachedEdgesAfterNodeChange(i.start)}processDoublyConnectedEdges(e,t,s,i){s===Te()&&o("curve_helper");const r=this.getSegment(e).get(),n=this.getSegment(t).get(),h=r.getStartXY().equals(n.getStartXY())&&r.getEndXY().equals(n.getEndXY())?1:r.getEndXY().equals(n.getStartXY())&&r.getStartXY().equals(n.getEndXY())?-1:0;if(0!==h){const a=new G;r.queryCut(0,.5,a),a.get().snapControlPoints(i*i);const o=new G;r.queryCut(.5,1,o),o.get().snapControlPoints(i*i),this.splitEdgeInPlace(e),e.end.pt=a.get().getEndXY(),e.segmentIndex=this.parent.allocResultSegmentFromBuffer(a),e.getNextInChain().segmentIndex=this.parent.allocResultSegmentFromBuffer(o);let m=n.getClosestCoordinate(e.end.pt,!1);return Math.abs(m-.5)>.2&&(m=.5),n.queryCut(0,m,a),a.get().snapControlPoints(i*i),n.queryCut(m,1,o),o.get().snapControlPoints(i*i),this.splitEdgeInPlace(t),t.end.pt=a.get().getEndXY(),t.segmentIndex=this.parent.allocResultSegmentFromBuffer(a),t.getNextInChain().segmentIndex=this.parent.allocResultSegmentFromBuffer(o),h>0?(this.m_pairs.push(Et(e,t,s,!1)),this.m_pairs.push(Et(e.getNextInChain(),t.getNextInChain(),s,!1))):(this.m_pairs.push(Et(e,t.getNextInChain(),s,!1)),this.m_pairs.push(Et(e.getNextInChain(),t,s,!1))),!0}return!1}getNext(t){return e(0),{}}newNode(e,t,s,i){const r=new xt;return this.m_newNodes.push(r),r.pt=e,r.rank=s,r.weight=t,r.bIsBreak=i,r}newEdge(e,t,s,i,r,n){const h=new ft;return h.start=e,h.end=t,e.nextInChain=h,t.prevInChain=h,h.segmentIndex=s,h.segmentParentage=n,h.rank=r,h.weight=i,h}splitEdgeInPlace(e){e.segmentIndex=-1;const t=new ft,s=new xt;this.m_newNodes.push(s),s.pt.setNAN(),s.nextInChain=t,s.prevInChain=e,s.prevInHash=null,s.nextInHash=null,s.prevEqual=null,s.nextEqual=null,s.weight=e.weight,s.rank=e.rank,s.bIsBreak=!1,s.bBigMove=!1,t.start=s,t.segmentIndex=-1,t.end=e.end,t.end.prevInChain=t,t.rank=e.rank,t.weight=e.weight,t.segmentParentage=e.segmentParentage,e.end=s,e.equalEdge&&(e.equalEdge.equalEdge=null),e.equalEdge=null}updateSegmentOnly(e,t){e.segmentIndex=t}updateAttachedEdgesAfterNodeChange(e){for(let t=e.equalListHead();null!==t;t=t.nextEqual)this.updateAttachedEdgesAfterNodeChangeImpl(t)}updateAttachedEdgesAfterNodeChangeImpl(e){const t=e.prevInChain;if(t&&t.hasSegment()){const s=this.getSegment(t).get();e.pt.equals(s.getEndXY())||(s.setCoordsForIntersector(t.start.pt,t.end.pt,!1),s.ensureXYMonotone())}const s=e.nextInChain;if(s&&s.hasSegment()){const t=this.getSegment(s).get();e.pt.equals(t.getStartXY())||(t.setCoordsForIntersector(s.start.pt,s.end.pt,!1),t.ensureXYMonotone())}}updateSegmentToNodes(e){const t=this.getSegment(e).get();e.start.pt.equals(t.getStartXY())&&e.end.pt.equals(t.getEndXY())||(t.setCoordsForIntersector(e.start.pt,e.end.pt,!1),t.ensureXYMonotone()),this.updateAttachedEdgesAfterNodeChange(e.start),this.updateAttachedEdgesAfterNodeChange(e.end)}getSegment(e){return this.parent.m_resultSegments[e.segmentIndex]}clusterNodes(e){let t=!1;const s=[],i=[],r=[];for(let n=0,h=this.m_newNodes.length;n<h;n++){const e=this.m_newNodes[n];if(null===e)continue;let t=e;for(let s=n+1;s<h;s++){const i=this.m_newNodes[s];null!==i&&(e.pt.equals(i.pt)&&(t.nextInHash=i,i.prevInHash=t,t=i,this.m_newNodes[s]=null))}}for(let n=0,h=this.m_newNodes.length;n<h;n++){const h=this.m_newNodes[n];if(null==h)continue;for(h.hash=this.calculateHash(h.pt);;){const n=we(4),a=this.hashTableBinsToCheck(h,n);for(let t=0;t<a;t++)if(null!==n[t])for(let a=n[t];null!==a;){const t=a.nextInHash;F.distance(h.pt,a.pt)<=e&&(s.push(a),this.removeNodeFromHash(a),a.hash=0,r.push(a),i.push(a)),a=t}let o=!1;for(const e of s)if(!h.pt.equals(e.pt)){const s=mt(h.pt,e.pt,h.weight,h.rank,e.weight,e.rank);h.pt.assign(s.pt),h.weight=s.weight,h.rank=s.rank,o=!0,t=!0}if(s.length=0,!o)break;h.hash=this.calculateHash(h.pt)}r.push(h),i.push(h);for(let e=h.nextInHash;null!==e;){e.prevInHash=null;const t=e.nextInHash;e.nextInHash=null,r.push(e),i.push(e),e=t}const a=h.hash;let o=null,m=null;for(const e of i)h!==e&&(e.hash=a,e.pt.assign(h.pt),e.rank=h.rank,e.weight=h.weight),e.prevInHash=o,o&&(o.nextInHash=e),e.prevEqual=m,e.nextEqual=null,m&&(m.nextEqual=e),m=e,o=e;const g=a%this.m_hashTableOfEquals.length;o.nextInHash=this.m_hashTableOfEquals[g],null!==this.m_hashTableOfEquals[g]&&(this.m_hashTableOfEquals[g].prevInHash=o),this.m_hashTableOfEquals[g]=i[0],this.m_hashTableOfEqualsSize+=i.length,i.length=0,this.rehashIfNeeded()}if(this.m_newNodes.length=0,t)for(const n of r)this.updateAttachedEdgesAfterNodeChange(n)}addNodeToHash(t){e(0)}rehashIfNeeded(){if(2*this.m_hashTableOfEqualsSize>this.m_hashTableOfEquals.length){const e=this.m_hashTableOfEquals;this.m_hashTableOfEquals=we(2*e.length),this.m_hashTableOfEqualsSize=0;for(const t of e){let e=t;for(;e;){const t=e.nextInHash;e.nextInHash=null,e.prevInHash=null,this.addNodeToHashImpl(e),e=t}}}}addNodeToHashImpl(e){const t=e.hash%this.m_hashTableOfEquals.length,s=this.m_hashTableOfEquals[t];e.nextInHash=s,null!==s&&(s.prevInHash=e),this.m_hashTableOfEquals[t]=e,this.m_hashTableOfEqualsSize++}removeNodeFromHash(e){const t=e.hash%this.m_hashTableOfEquals.length,s=e.prevInHash,i=e.nextInHash;s?s.nextInHash=i:this.m_hashTableOfEquals[t]=i,i&&(i.prevInHash=s),this.m_hashTableOfEqualsSize--,e.prevInHash=null,e.nextInHash=null}hashTableBinsToCheck(e,t){const s=(e.pt.x-this.m_origin.x)/this.m_cell.x,i=(e.pt.y-this.m_origin.y)/this.m_cell.y,r=Ne()-1,n=Math.round(De(s,-r,r)),h=Math.round(De(i,-r,r));let a=n|h<<32;a=Be(a),t[0]=this.m_hashTableOfEquals[a%this.m_hashTableOfEquals.length];let o=n+1|h<<32;o=Be(o);let m=1;t[1]=this.m_hashTableOfEquals[o%this.m_hashTableOfEquals.length],t[1]!==t[0]&&(m=2);let g=n+1|h+1<<32;g=Be(g),t[m]=this.m_hashTableOfEquals[g%this.m_hashTableOfEquals.length];for(let _=0;_<m;_++)if(t[m]===t[_]){m--;break}m++;let l=n|h+1<<32;l=Be(l),t[m]=this.m_hashTableOfEquals[l%this.m_hashTableOfEquals.length];for(let _=0;_<m;_++)if(t[m]===t[_]){m--;break}return m++,m}calculateHash(e){const t=(e.x-this.m_origin.x)/this.m_cell.x,s=(e.y-this.m_origin.y)/this.m_cell.y,i=Ne()-1;let r=Math.round(De(t,-i,i))|Math.round(De(s,-i,i))<<32;return r=Be(r),0===r&&(r=1),r}processSharpCorners(e,t,s,i){if(this.parent.m_param1.length=0,this.parent.m_param2.length=0,e.getStartXY().equals(t.getStartXY())){const r=[0,0],n=[0,0],h=ke(e,t,0,0,s,2,r,n,i);if(h){this.parent.m_param1.push(0),this.parent.m_param2.push(0);for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return h+1}}if(e.getEndXY().equals(t.getEndXY())){const r=[0,0],n=[0,0],h=ke(e,t,1,1,s,2,r,n,i);if(h){for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return this.parent.m_param1.push(1),this.parent.m_param2.push(1),h+1}}if(e.getStartXY().equals(t.getEndXY())){const r=[0,0],n=[0,0],h=ke(e,t,0,1,s,2,r,n,i);if(h){this.parent.m_param1.push(0),this.parent.m_param2.push(1);for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return h+1}}if(e.getEndXY().equals(t.getStartXY())){const r=[0,0],n=[0,0],h=ke(e,t,1,0,s,2,r,n,i);if(h){for(let e=0;e<h;e++)this.parent.m_param1.push(r[e]),this.parent.m_param2.push(n[e]);return this.parent.m_param1.push(1),this.parent.m_param2.push(0),h+1}}return 0}}function St(e,t,s){let r=0;switch(e){case i.enumLine:r=0;break;case i.enumBezier:r=2;break;case i.enumRationalBezier2:r=3;break;case i.enumBezier2:r=1;break;case i.enumEllipticArc:r=0===t.projectionBehavior()?5:4;break;default:o("")}return s?5-r:r}class Ct extends it{constructor(e){super(e.m_shape,e.m_tolerance,!1),this.m_parent=e}compare(e,t,s){if(this.m_bIntersectionDetected)return-1;const i=e.getElement(s),r=this.m_parent.getEdgeOriginVertices(t),n=this.m_parent.m_edgeVertices.getFirstElement(r),h=this.m_parent.getEdgeOriginVertices(i),a=this.m_parent.m_edgeVertices.getFirstElement(h);return this.m_currentNode=s,this.compareSegments(t,n,i,a)}}class Pt extends rt{constructor(e){super(e.m_shape,e.m_tolerance),this.m_parent=e}compare(e,t){if(this.m_bIntersectionDetected)return-1;const s=e.getElement(t),i=this.m_parent.getEdgeOriginVertices(s),r=this.m_parent.m_edgeVertices.getFirstElement(i);return this.m_currentNode=t,this.compareVertex(e,t,r)}}class yt extends de{constructor(e){super(),this.pt1=F.getNAN(),this.pt2=F.getNAN(),this.m_shape=e}compare(e,t,s){this.m_shape.queryXY(t,this.pt1);const i=e.getElement(s);return this.m_shape.queryXY(i,this.pt2),this.pt1.compare(this.pt2)}}class Nt{constructor(e){this.m_point=F.getNAN(),this.m_pt=F.getNAN(),this.m_shape=e}setPoint(e){this.m_point.setCoordsPoint2D(e)}compare(e,t){const s=e.getElement(t);return this.m_shape.queryXY(s,this.m_pt),this.m_point.compare(this.m_pt)}}class vt{constructor(e,t){this.m_shape=null,this.m_progressTracker=null,this.m_edges=new M(8),this.m_clusters=new M(5),this.m_clusterVertices=new et(!1),this.m_edgeVertices=new et(!1),this.m_helperPoint=new P,this.m_eventQ=new _,this.m_sweepStructure=new _,this.m_bComplications=!1,this.m_sweepComparator=null,this.m_tempEdgeBuffer=[],this.m_modifiedClusters=[],this.m_edgesToInsertInSweepStructure=[],this.m_prevNeighbour=-1,this.m_nextNeighbour=-1,this.m_bContinuingSegmentChainOptimization=!1,this.m_progressCounter=0,this.m_segmentIntersector=new dt,this.m_segBuf1=new G,this.m_segBuf2=new G,this.m_sweepPoint=new F(0,0),this.m_tolerance=0,this.m_toleranceSqr=0,this.m_sweepPointCluster=-1,this.m_vertexClusterIndex=-1,this.m_bCracked=!1,this.m_bSweepPointClusterWasModified=!1,this.m_progressTracker=e,this.m_bTrackChanges=t}hadComplications(){return this.m_bComplications}sweep(e,t){const s=new Q;s.setSwapCoordinates(),e.applyTransformation(s),this.setEditShape_(e),this.m_bCracked=!1,this.m_tolerance=t,this.m_toleranceSqr=t*t;let i=this.sweepImpl_();return e.applyTransformation(s),i||(this.fillEventQueuePass2(),i=this.sweepImpl_()||i),this.m_shape.removeUserIndex(this.m_vertexClusterIndex),this.m_shape=null,this.m_bCracked}sweepVertical(e,t){this.setEditShape_(e),this.m_bCracked=!1,this.m_tolerance=t,this.m_toleranceSqr=t*t,this.m_bComplications=!1;let s=this.sweepImpl_();if(!this.m_bComplications){const i=e.filterClosePoints(t,!0,!1,this.m_bTrackChanges,H);this.m_bComplications=1===i,s||=1===i}return-1!==this.m_vertexClusterIndex&&(this.m_shape.removeUserIndex(this.m_vertexClusterIndex),this.m_vertexClusterIndex=-1),this.m_shape=null,s}getEdgeCluster(e,t){return this.m_edges.getField(e,0+t)}setEdgeCluster_(e,t,s){this.m_edges.setField(e,0+t,s)}getEdgeOriginVertices(e){return this.m_edges.getField(e,2)}setEdgeOriginVertices_(e,t){this.m_edges.setField(e,2,t)}getNextEdgeEx(e,t){return this.m_edges.getField(e,3+t)}setNextEdgeEx_(e,t,s){this.m_edges.setField(e,3+t,s)}getEdgeSweepNode(e){return this.m_edges.getField(e,7)}setEdgeSweepNode_(e,t){this.m_edges.setField(e,7,t)}getNextEdge(e,t){const s=this.getEdgeEnd(e,t);return this.m_edges.getField(e,3+s)}setNextEdge_(e,t,s){const i=this.getEdgeEnd(e,t);this.m_edges.setField(e,3+i,s)}getPrevEdge(e,t){const s=this.getEdgeEnd(e,t);return this.m_edges.getField(e,5+s)}setPrevEdge_(e,t,s){const i=this.getEdgeEnd(e,t);this.m_edges.setField(e,5+i,s)}getClusterVertices(e){return this.m_clusters.getField(e,0)}setClusterVertices_(e,t){this.m_clusters.setField(e,0,t)}getClusterSweepEdgeList(e){return this.m_clusters.getField(e,2)}setClusterSweepEdgeList_(e,t){this.m_clusters.setField(e,2,t)}getClusterFirstEdge(e){return this.m_clusters.getField(e,1)}setClusterFirstEdge_(e,t){this.m_clusters.setField(e,1,t)}getClusterEventQNode(e){return this.m_clusters.getField(e,3)}setClusterEventQNode_(e,t){this.m_clusters.setField(e,3,t)}newCluster_(e){const t=this.m_clusters.newElement(),s=this.m_clusterVertices.createList();return this.setClusterVertices_(t,s),e!==H&&(this.m_clusterVertices.addElement(s,e),this.m_shape.setUserIndex(e,this.m_vertexClusterIndex,t)),t}deleteCluster_(e){this.m_clusters.deleteElement(e)}addVertexToCluster_(e,t){const s=this.getClusterVertices(e);this.m_clusterVertices.addElement(s,t),this.m_shape.setUserIndex(t,this.m_vertexClusterIndex,e)}newEdge_(e){const t=this.m_edges.newElement(),s=this.m_edgeVertices.createList();return this.setEdgeOriginVertices_(t,s),-1!==e&&this.m_edgeVertices.addElement(s,e),t}addVertexToEdge_(e,t){const s=this.getEdgeOriginVertices(e);this.m_edgeVertices.addElement(s,t)}deleteEdge_(e){this.m_edges.deleteElement(e);const t=this.m_edgesToInsertInSweepStructure.findIndex((t=>t===e));t>=0&&Z(this.m_edgesToInsertInSweepStructure,t)}addEdgeToCluster(e,t){-1===this.getEdgeCluster(e,0)?this.setEdgeCluster_(e,0,t):-1===this.getEdgeCluster(e,1)?this.setEdgeCluster_(e,1,t):o(""),this.addEdgeToClusterImpl_(e,t)}addEdgeToClusterImpl_(e,t){const s=this.getClusterFirstEdge(t);if(-1!==s){const i=this.getNextEdge(s,t);this.setPrevEdge_(i,t,e),this.setNextEdge_(e,t,i),this.setNextEdge_(s,t,e),this.setPrevEdge_(e,t,s)}else this.setPrevEdge_(e,t,e),this.setNextEdge_(e,t,e),this.setClusterFirstEdge_(t,e)}getEdgeEnd(e,t){return this.getEdgeCluster(e,0)===t?0:1}mergeClusters_(e,t){this.dbgCheckCluster_(e),this.dbgCheckCluster_(t);const s=this.getClusterEventQNode(t);-1!==s&&(this.m_eventQ.deleteNode(s),this.setClusterEventQNode_(t,-1));let i=this.getClusterFirstEdge(e),r=this.getClusterFirstEdge(t);if(-1!==r){let s=r,n=r,h=!1;do{this.dbgCheckEdge_(s),h=!1;const i=this.getEdgeEnd(s,t),a=this.getNextEdgeEx(s,i);if(this.getEdgeCluster(s,i+1&1)===e){this.disconnectEdge_(s);const e=this.getEdgeOriginVertices(s);if(this.m_edgeVertices.deleteList(e),this.deleteEdge_(s),s===a){r=-1;break}r===s&&(r=this.getClusterFirstEdge(t),n=a,h=!0)}s=a}while(s!==n||h);if(-1!==r){do{const i=this.getEdgeEnd(s,t),r=this.getNextEdgeEx(s,i);this.setEdgeCluster_(s,i,e),s=r}while(s!==n);if(i=this.getClusterFirstEdge(e),-1!==i){const t=this.getNextEdge(i,e),s=this.getNextEdge(r,e);t===i?(this.setClusterFirstEdge_(e,r),this.addEdgeToClusterImpl_(i,e),this.setClusterFirstEdge_(e,i)):s===r&&this.addEdgeToClusterImpl_(r,e),this.setNextEdge_(r,e,t),this.setPrevEdge_(t,e,r),this.setNextEdge_(i,e,s),this.setPrevEdge_(s,e,i)}else this.setClusterFirstEdge_(e,r)}}const n=this.getClusterVertices(e),h=this.getClusterVertices(t);for(let a=this.m_clusterVertices.getFirst(h);-1!==a;a=this.m_clusterVertices.getNext(a)){const t=this.m_clusterVertices.getElement(a);this.m_shape.setUserIndex(t,this.m_vertexClusterIndex,e)}this.m_clusterVertices.concatenateLists(n,h),this.deleteCluster_(t),this.dbgCheckCluster_(e)}mergeEdges_(e,t){this.dbgCheckEdge_(e),this.dbgCheckEdge_(t);const s=this.getEdgeCluster(e,0),i=this.getEdgeCluster(e,1),r=this.getEdgeCluster(t,0),n=this.getEdgeCluster(t,1),h=this.getEdgeOriginVertices(e),a=this.getEdgeOriginVertices(t);if(this.m_edgeVertices.concatenateLists(h,a),t===this.getClusterFirstEdge(s)&&this.setClusterFirstEdge_(s,e),t===this.getClusterFirstEdge(i)&&this.setClusterFirstEdge_(i,e),this.disconnectEdge_(t),this.deleteEdge_(t),!(s===r&&i===n||i===r&&s===n)){const e=this.getClusterXY(s),t=this.getClusterXY(r);e.isEqualPoint2D(t)?(s!==r&&this.mergeClusters_(s,r),i!==n&&this.mergeClusters_(i,n)):(i!==r&&this.mergeClusters_(i,r),s!==n&&this.mergeClusters_(s,n))}this.dbgCheckEdge_(e)}disconnectEdge_(e){const t=this.getEdgeCluster(e,0),s=this.getEdgeCluster(e,1);this.disconnectEdgeFromCluster_(e,t),this.disconnectEdgeFromCluster_(e,s)}disconnectEdgeFromCluster_(e,t){const s=this.getNextEdge(e,t),i=this.getPrevEdge(e,t),r=this.getClusterFirstEdge(t);s!==e?(this.setNextEdge_(i,t,s),this.setPrevEdge_(s,t,i),r===e&&this.setClusterFirstEdge_(t,s)):this.setClusterFirstEdge_(t,-1)}applyIntersectorToEditShape_(e,t,s){let i=this.m_edgeVertices.getFirst(e);const r=this.m_edgeVertices.getElement(i),n=this.getClusterFromVertex(r),h=this.m_shape.getNextVertex(r),a=this.getClusterFromVertex(h),o=this.m_shape.getXY(r),m=this.m_shape.getXY(h);let g=!1,l=!1;const _=t.getResultSegment(s,0).getStartXY(),d=t.getResultSegment(s,t.getResultSegmentCount(s)-1).getEndXY();o.equals(_)||(g=!0),m.equals(d)||(l=!0),this.m_shape.splitSegmentWithIntersector(r,t,s,!0,!0);const p=this.m_bTrackChanges&&t.getSegmentChanged(s);for(p&&this.m_shape.setGeometryModifiedWithVertex(r,!0),i=this.m_edgeVertices.getNext(i);-1!==i;i=this.m_edgeVertices.getNext(i)){const e=this.m_edgeVertices.getElement(i),r=this.getClusterFromVertex(e)===n;this.m_shape.splitSegmentWithIntersector(e,t,s,r,!0),p&&this.m_shape.setGeometryModifiedWithVertex(e,!0)}if(g&&this.updateClusterXY(!0,n,_,t.getResultSegmentStartPointWeight(s,0),t.getResultSegmentStartPointRank(s,0)),l){const e=t.getResultSegmentCount(s)-1;this.updateClusterXY(!0,a,d,t.getResultSegmentEndPointWeight(s,e),t.getResultSegmentEndPointRank(s,e))}}createEdgesAndClustersFromSplitEdge_(e,t,s){this.dbgCheckNewEdgesArray_();const i=this.getEdgeOriginVertices(e),r=this.getEdgeCluster(e,0),n=this.getEdgeCluster(e,1);let h=this.newEdge_(-1);this.m_edgesToInsertInSweepStructure.push(h);const a=M.impossibleIndex3();this.setEdgeSweepNode_(h,a),this.m_tempEdgeBuffer.push(h),this.addEdgeToCluster(h,r);const o=t.getResultSegmentCount(s);for(let m=1;m<o;m++){const e=this.newCluster_(-1);this.m_modifiedClusters.push(e),this.m_tempEdgeBuffer.push(e),this.addEdgeToCluster(h,e);const t=this.newEdge_(-1);this.m_edgesToInsertInSweepStructure.push(t),this.setEdgeSweepNode_(t,a),this.m_tempEdgeBuffer.push(t),this.addEdgeToCluster(t,e),h=t}this.addEdgeToCluster(h,n);for(let m=this.m_edgeVertices.getFirst(i);-1!==m;m=this.m_edgeVertices.getNext(m)){let e=this.m_edgeVertices.getElement(m);if(this.getClusterFromVertex(e)===r){let t=0;const s=this.m_tempEdgeBuffer.length;do{if(t>0){const s=this.m_tempEdgeBuffer[t-1];this.addVertexToCluster_(s,e)}const s=this.m_tempEdgeBuffer[t];t+=2,this.addVertexToEdge_(s,e),e=this.m_shape.getNextVertex(e)}while(t<s)}else{let t=this.m_tempEdgeBuffer.length-1;do{if(t<this.m_tempEdgeBuffer.length-2){const s=this.m_tempEdgeBuffer[t+1];this.addVertexToCluster_(s,e)}const s=this.m_tempEdgeBuffer[t];t-=2,this.addVertexToEdge_(s,e),e=this.m_shape.getNextVertex(e)}while(t>=0)}}this.m_tempEdgeBuffer.length=0,this.dbgCheckNewEdgesArray_()}getVertexFromClusterIndex(e){const t=this.getClusterVertices(e);return this.m_clusterVertices.getFirstElement(t)}getClusterFromVertex(e){return this.m_shape.getUserIndex(e,this.m_vertexClusterIndex)}processSplitHelper1_(e,t,s){const i=this.getEdgeCluster(t,0),r=this.getClusterXY(i),n=this.getEdgeCluster(t,1),h=this.getClusterXY(n),a=s.getResultSegmentCount(e);let o=s.getResultSegment(e,0);const m=o.getStartXY();if(!r.isEqualPoint2D(m)){if(!this.m_bComplications){r.compare(this.m_sweepPoint)*m.compare(this.m_sweepPoint)<0&&(this.m_bComplications=!0)}this.getAffectedEdges(i,this.m_tempEdgeBuffer),this.m_modifiedClusters.push(i)}if(!this.m_bComplications&&a>1){const e=r.compare(h),t=o.getEndXY();(r.compare(t)!==e||t.compare(h)!==e||t.compare(this.m_sweepPoint)<0)&&(this.m_bComplications=!0)}o=s.getResultSegment(e,a-1);const g=o.getEndXY();if(!h.isEqualPoint2D(g)){if(!this.m_bComplications){h.compare(this.m_sweepPoint)*g.compare(this.m_sweepPoint)<0&&(this.m_bComplications=!0)}this.getAffectedEdges(n,this.m_tempEdgeBuffer),this.m_modifiedClusters.push(n)}this.m_tempEdgeBuffer.push(t);for(let l=0,_=this.m_tempEdgeBuffer.length;l<_;l++){const e=this.m_tempEdgeBuffer[l],s=this.getEdgeSweepNode(e);M.isValidElement(s)&&(this.m_sweepStructure.deleteNode(s),this.setEdgeSweepNode_(e,-1));const i=M.impossibleIndex3();e!==t&&this.getEdgeSweepNode(e)!==i&&(this.m_edgesToInsertInSweepStructure.push(e),this.setEdgeSweepNode_(e,i))}this.m_tempEdgeBuffer.length=0}checkAndFixIntersection_(e,t){const s=this.m_sweepStructure.getElement(e);return this.m_sweepComparator.compare(this.m_sweepStructure,s,t),!!this.m_sweepComparator.intersectionDetected()&&(this.m_sweepComparator.clearIntersectionDetectedFlag(),this.fixIntersection_(e,t),!0)}fixIntersection_(t,s){this.m_bCracked=!0;const i=this.m_sweepStructure.getElement(t),r=this.m_sweepStructure.getElement(s);let n=null,h=null;const a=this.getEdgeOriginVertices(i),o=this.m_edgeVertices.getFirstElement(a),m=this.getEdgeOriginVertices(r),g=this.m_edgeVertices.getFirstElement(m),l=this.m_shape.querySegment(o,this.m_segBuf1,!1,!1);e(l),n=this.m_segBuf1.get();const _=this.m_shape.getNextVertex(o),d=this.m_shape.getWeight(o),p=this.m_shape.getSegmentParentageBreakVertex(o),u=this.m_shape.getWeight(_),c=this.m_shape.getSegmentParentageBreakVertex(_),f=this.m_shape.getSegmentWeight(o),x=this.m_shape.getRank(o),E=this.m_shape.getRank(_),I=this.m_shape.getSegmentRank(o),S=this.m_shape.getSegmentParentage(o),C=this.m_shape.querySegment(g,this.m_segBuf2,!1,!1);e(C),h=this.m_segBuf2.get();const P=this.m_shape.getNextVertex(g),y=this.m_shape.getWeight(g),N=this.m_shape.getSegmentParentageBreakVertex(g),v=this.m_shape.getWeight(P),b=this.m_shape.getSegmentParentageBreakVertex(P),w=this.m_shape.getSegmentWeight(g),V=this.m_shape.getRank(g),H=this.m_shape.getRank(P),T=this.m_shape.getSegmentRank(g),k=this.m_shape.getSegmentParentage(g);this.m_segmentIntersector.pushSegment(n,d,x,u,E,f,I,p,c,S),this.m_segmentIntersector.pushSegment(h,y,V,v,H,w,T,N,b,k),3===this.m_segmentIntersector.intersect(this.m_tolerance,!0)&&(this.m_bComplications=!0),this.splitEdge_(i,r,-1,this.m_segmentIntersector),this.m_segmentIntersector.clear()}fixIntersectionPointSegment_(t,s){e(0)}insertNewEdges_(){if(0===this.m_edgesToInsertInSweepStructure.length)return!0;this.dbgCheckNewEdgesArray_();let e=!0,t=0;const s=this.m_edgesToInsertInSweepStructure.length,i=Math.max(2*s+200,this.m_sweepStructure.size()+200);for(;this.m_edgesToInsertInSweepStructure.length;){if(this.m_edgesToInsertInSweepStructure.length>Math.max(100,this.m_shape.getTotalPointCount())||t>i){this.m_edgesToInsertInSweepStructure.length=0,this.m_bComplications=!0,e=!1;break}const s=this.m_edgesToInsertInSweepStructure.at(-1);this.m_edgesToInsertInSweepStructure.pop(),this.setEdgeSweepNode_(s,-1);const r=this.isEdgeOnSweepLine_(s);M.isValidElement(r)?(this.insertNewEdgeToSweepStructure_(s,r),t++):r!==M.impossibleIndex2()&&(e=!1),this.m_bContinuingSegmentChainOptimization=!1}return e}insertNewEdgeToSweepStructure_(e,t){let s;if(this.m_bContinuingSegmentChainOptimization?(s=this.m_sweepStructure.addElementAtPosition(this.m_prevNeighbour,this.m_nextNeighbour,e,!0,!0),this.m_bContinuingSegmentChainOptimization=!1):s=this.m_sweepStructure.addUniqueElement(e),-1===s){const t=this.m_sweepStructure.getDuplicateElement(),s=this.m_sweepStructure.getElement(t);return this.mergeEdges_(s,e),!1}if(this.setEdgeSweepNode_(e,s),this.m_sweepComparator.intersectionDetected()){this.m_sweepComparator.clearIntersectionDetectedFlag();const e=this.m_sweepComparator.getLastComparedNode();return this.m_prevNeighbour===e&&(this.m_prevNeighbour=-1),this.m_nextNeighbour===e&&(this.m_nextNeighbour=-1),this.fixIntersection_(e,s),!0}return!1}isEdgeOnSweepLine_(e){const t=this.getEdgeCluster(e,0),s=this.getEdgeCluster(e,1),i=this.getClusterXY(t),r=this.getClusterXY(s);if(F.sqrDistance(i,r)<=this.m_toleranceSqr)return this.m_bComplications=!0,-1;const n=i.compare(this.m_sweepPoint),h=r.compare(this.m_sweepPoint);return n<=0&&h>0?s:h<=0&&n>0?t:n>0&&h>0?M.impossibleIndex2():-1}fillEventQueue(){const e=new c(0),t=this.m_shape.queryVertexIteratorOnSelection();for(let r=t.next();r!==H;r=t.next())-1!==this.m_shape.getUserIndex(r,this.m_vertexClusterIndex)&&e.add(r);this.m_shape.sortVerticesSimpleByY(e,0,e.size()),this.progress_(!0),this.m_eventQ.clear(),this.m_eventQ.setCapacity(e.size()),this.m_eventQ.setComparator(new yt(this.m_shape));const s=F.getNAN();s.setNAN();let i=-1;for(let r=0,n=e.size();r<n;r++){const t=e.read(r);if(this.m_shape.getXY(t).isEqualPoint2D(s)){const e=this.m_shape.getUserIndex(t,this.m_vertexClusterIndex);this.mergeClusters_(i,e);continue}i=this.getClusterFromVertex(t),this.m_shape.queryXY(t,s);const n=this.m_eventQ.addBiggestElement(t);this.setClusterEventQNode_(i,n)}}fillEventQueuePass2(){const e=new c(0);for(let t=this.m_eventQ.getFirst();-1!==t;t=this.m_eventQ.getNext(t)){const s=this.m_eventQ.getElement(t);e.add(s)}this.m_eventQ.clear(),this.m_shape.sortVerticesSimpleByY(e,0,e.size()),this.progress_(!0);for(let t=0,s=e.size();t<s;t++){const s=e.read(t),i=this.getClusterFromVertex(s),r=this.m_eventQ.addBiggestElement(s);this.setClusterEventQNode_(i,r)}}getAffectedEdges(e,t){const s=this.getClusterFirstEdge(e);if(-1===s)return;let i=s;do{const s=this.getEdgeSweepNode(i);M.isValidElement(s)&&t.push(i),i=this.getNextEdge(i,e)}while(i!==s)}updateClusterXY(e,t,s,i,r){const n=this.getClusterVertices(t);for(let h=this.m_clusterVertices.getFirst(n);-1!==h;h=this.m_clusterVertices.getNext(h)){const t=this.m_clusterVertices.getElement(h);this.m_shape.setXYMonotonicPoint2D(t,s),this.m_shape.setWeight(t,i),this.m_shape.setRank(t,r),e&&this.m_bTrackChanges&&this.m_shape.setGeometryModifiedWithVertex(t,!0),this.m_shape.setSegmentParentageBreakVertex(t,!0)}}splitEdge_(e,t,s,i){this.dbgCheckEdge_(e),-1!==t&&this.dbgCheckEdge_(t),this.disconnectEdge_(e),-1!==t&&this.disconnectEdge_(t),this.processSplitHelper1_(0,e,i),-1!==t&&this.processSplitHelper1_(1,t,i),-1!==s&&i.getResultPointChanged()&&this.m_modifiedClusters.push(s);for(let h=0,a=this.m_modifiedClusters.length;h<a;h++){const e=this.m_modifiedClusters[h],t=this.getClusterEventQNode(e);-1!==t&&(this.m_eventQ.deleteNode(t),this.setClusterEventQNode_(e,-1))}const r=this.getEdgeOriginVertices(e),n=-1!==t?this.getEdgeOriginVertices(t):-1;if(this.applyIntersectorToEditShape_(r,i,0),-1!==n)this.applyIntersectorToEditShape_(n,i,1);else{const e=i.getResultPoint().getXY();this.updateClusterXY(i.getResultPointChanged(),s,e,i.getResultPointWeight(),i.getResultPointRank())}this.createEdgesAndClustersFromSplitEdge_(e,i,0),-1!==t&&this.createEdgesAndClustersFromSplitEdge_(t,i,1),this.m_edgeVertices.deleteList(r),this.deleteEdge_(e),-1!==t&&(this.m_edgeVertices.deleteList(n),this.deleteEdge_(t));for(let h=0,a=this.m_modifiedClusters.length;h<a;h++){const e=this.m_modifiedClusters[h];e===this.m_sweepPointCluster&&(this.m_bSweepPointClusterWasModified=!0);let t=this.getClusterEventQNode(e);if(-1===t){const s=this.getClusterFirstVertex(e);if(t=this.m_eventQ.addUniqueElement(s),-1===t){const t=this.m_eventQ.getDuplicateElement(),s=this.m_eventQ.getElement(t),i=this.getClusterFromVertex(s);this.mergeClusters_(i,e)}else this.setClusterEventQNode_(e,t)}}this.m_modifiedClusters.length=0}getClusterXY(e){const t=this.getClusterFirstVertex(e);return this.m_shape.getXY(t)}getClusterFirstVertex(e){const t=this.getClusterVertices(e);return this.m_clusterVertices.getFirstElement(t)}dbgCheckEdge_(e){}dbgCheckCluster_(e){}dbgCheckNewEdgesArray_(){}dbgSaveSweepStructure_(t){e(0)}sweepImpl_(){this.progress_(!0),this.m_bSweepPointClusterWasModified=!1,this.m_sweepPointCluster=-1,null===this.m_sweepComparator&&(this.m_sweepStructure.disableBalancing(),this.m_sweepComparator=new Ct(this),this.m_sweepStructure.setComparator(this.m_sweepComparator));const e=[];let t=null,s=null;this.m_prevNeighbour=-1,this.m_nextNeighbour=-1,this.m_bContinuingSegmentChainOptimization=!1;const i=M.impossibleIndex2(),r=M.impossibleIndex3();for(let n=this.m_eventQ.getFirst();-1!==n;){this.progress_(),this.dbgCheckSweepStructure_(),this.m_bContinuingSegmentChainOptimization=!1,this.m_prevNeighbour=-1,this.m_nextNeighbour=-1;const h=this.m_eventQ.getElement(n);this.m_sweepPointCluster=this.getClusterFromVertex(h),this.m_shape.queryXY(h,this.m_sweepPoint),this.m_sweepComparator.setSweepY(this.m_sweepPoint.y,this.m_sweepPoint.x);let a=!1;{const t=this.getClusterFirstEdge(this.m_sweepPointCluster);if(a=-1===t,!a){let s=t;do{const t=this.getEdgeSweepNode(s);-1===t?(this.m_edgesToInsertInSweepStructure.push(s),this.setEdgeSweepNode_(s,r)):t!==r&&e.push(t),s=this.getNextEdge(s,this.m_sweepPointCluster)}while(s!==t)}}if(!this.m_sweepStructure.isAutoBalancing()&&(this.m_sweepStructure.getMaxDepthEver()>4||this.m_edgesToInsertInSweepStructure.length>10)&&this.m_sweepStructure.enableBalancing(),e.length>0){this.m_bContinuingSegmentChainOptimization=1===e.length&&1===this.m_edgesToInsertInSweepStructure.length;for(let r=0,n=e.length;r<n;r++){const t=this.m_sweepStructure.getElement(e[r]);this.setEdgeSweepNode_(t,i)}let t=i,s=i;for(let r=0,n=e.length;r<n;r++){const n=e[r];if(t===i){const e=this.m_sweepStructure.getPrev(n);if(-1!==e){const s=this.m_sweepStructure.getElement(e);this.getEdgeSweepNode(s)!==i&&(t=e)}else t=-1}if(s===i){const e=this.m_sweepStructure.getNext(n);if(-1!==e){const t=this.m_sweepStructure.getElement(e);this.getEdgeSweepNode(t)!==i&&(s=e)}else s=-1}if(t!==i&&s!==i)break}for(let i=0,r=e.length;i<r;i++){const t=e[i],s=this.m_sweepStructure.getElement(t);this.m_sweepStructure.deleteNode(t),this.setEdgeSweepNode_(s,-1)}e.length=0,this.m_prevNeighbour=t,this.m_nextNeighbour=s,-1!==t&&-1!==s?this.m_bContinuingSegmentChainOptimization||this.checkAndFixIntersection_(t,s):-1===t&&-1===s&&(this.m_bContinuingSegmentChainOptimization=!1)}else a&&(null===t&&(t=new Pt(this)),t.setPoint(this.m_sweepPoint),this.m_sweepStructure.searchUpperBound(t),t.intersectionDetected()&&(t.clearIntersectionDetectedFlag(),this.fixIntersectionPointSegment_(this.m_sweepPointCluster,t.getCurrentNode())));const o=this.m_bContinuingSegmentChainOptimization;!this.insertNewEdges_()&&o&&-1!==this.m_prevNeighbour&&-1!==this.m_nextNeighbour&&this.checkAndFixIntersection_(this.m_prevNeighbour,this.m_nextNeighbour),this.m_bSweepPointClusterWasModified?(this.m_bSweepPointClusterWasModified=!1,null===s&&(s=new Nt(this.m_shape)),s.setPoint(this.m_sweepPoint),n=this.m_eventQ.searchUpperBound(s)):n=this.m_eventQ.getNext(n)}return this.m_bCracked}setEditShape_(e){this.m_shape=e,this.m_vertexClusterIndex=this.m_shape.createUserIndex(),this.m_edges.setCapacity(e.getSelectedCount()+32),this.m_clusters.setCapacity(e.getSelectedCount()),this.m_clusterVertices.reserveLists(e.getSelectedCount()),this.m_clusterVertices.reserveNodes(e.getSelectedCount()),this.m_edgeVertices.reserveLists(e.getSelectedCount()+32),this.m_edgeVertices.reserveNodes(e.getSelectedCount()+32);for(let t=this.m_shape.getFirstGeometry();t!==H;t=this.m_shape.getNextGeometry(t)){if(u(this.m_shape.getGeometryType(t)))for(let s=this.m_shape.getFirstPath(t);s!==H;s=this.m_shape.getNextPath(s)){const t=this.m_shape.getPathSize(s),i=this.m_shape.getFirstVertex(s);if(i===H)continue;let r=this.m_shape.getNextVertex(i);if(r===H||r===i)continue;let n=-1;e.selected(i)&&(n=this.newCluster_(i));let h=-1;-1!==n&&e.selected(r)&&(h=this.newEdge_(i),this.addEdgeToCluster(h,n));let a=h;for(let e=0,s=t-2;e<s;e++){const e=this.m_shape.getNextVertex(r);let t=-1;if(this.m_shape.selected(r)){const s=this.newCluster_(r);-1!==a&&this.addEdgeToCluster(a,s),this.m_shape.selected(e)&&(t=this.newEdge_(r),this.addEdgeToCluster(t,s))}a=t,r=e}if(this.m_shape.isClosedPath(s)){const e=this.m_shape.getNextVertex(r);if(this.m_shape.selected(r)){const t=this.newCluster_(r);if(-1!==a&&this.addEdgeToCluster(a,t),this.m_shape.selected(e)){const e=this.newEdge_(r);this.addEdgeToCluster(e,t),this.addEdgeToCluster(e,n)}}}else{let e=-1;this.m_shape.selected(r)&&(e=this.newCluster_(r),-1!==a&&this.addEdgeToCluster(a,e))}}else for(let e=this.m_shape.getFirstPath(t);e!==H;e=this.m_shape.getNextPath(e)){let t=this.m_shape.getFirstVertex(e);for(let s=0,i=this.m_shape.getPathSize(e);s<i;s++)this.m_shape.selected(t)&&this.newCluster_(t),t=this.m_shape.getNextVertex(t)}}this.fillEventQueue()}progress_(e=!1){}dbgCheckSweepStructure_(){}}class bt{constructor(e,t){this.m_monotoneParts=he(G,16),this.m_xOrds=Y(16,Number.NaN),this.m_inputPoint=F.getNAN(),this.m_miny=0,this.m_maxy=0,this.m_windnum=0,this.m_bAlternate=e,this.m_tolerance=t,this.m_toleranceSqr=t*t,this.m_bTestBorder=!!t,this.m_bBreak=!1}_DoOne(e){if(!this.m_bTestBorder&&(this.m_bAlternate&&this.m_inputPoint.equals(e.getStartXY())||this.m_inputPoint.equals(e.getEndXY())))return void(this.m_bBreak=!0);if(e.getStartY()===this.m_inputPoint.y&&e.getStartY()===e.getEndY()){if(this.m_bAlternate&&!this.m_bTestBorder){const t=Math.min(e.getStartX(),e.getEndX()),s=Math.max(e.getStartX(),e.getEndX());this.m_inputPoint.x>t&&this.m_inputPoint.x<s&&(this.m_bBreak=!0)}return}let t=!1;const s=Math.max(e.getStartX(),e.getEndX());if(this.m_inputPoint.x>s)t=!0;else if(this.m_inputPoint.x>=Math.min(e.getStartX(),e.getEndX())){const i=e.intersectionOfYMonotonicWithAxisX(this.m_inputPoint.y,s);t=!Number.isNaN(i)&&i<=this.m_inputPoint.x}if(t){if(this.m_inputPoint.y===e.getStartY()){if(this.m_inputPoint.y<e.getEndY())return}else if(this.m_inputPoint.y===e.getEndY()&&this.m_inputPoint.y<e.getStartY())return;this.m_bAlternate?this.m_windnum^=1:this.m_windnum+=e.getStartY()>e.getEndY()?1:-1}}_Result(){return!!this.m_windnum}testBorder(e){const t=e.getClosestCoordinate(this.m_inputPoint,!1),s=e.getCoord2D(t);return F.sqrDistance(s,this.m_inputPoint)<=this.m_toleranceSqr}SetInputPoint(e){this.m_inputPoint.setCoordsPoint2D(e),this.m_miny=e.y-this.m_tolerance,this.m_maxy=e.y+this.m_tolerance}processSegment(e){const t=e.queryInterval(0,1);if(t.vmin>this.m_maxy||t.vmax<this.m_miny)return!1;if(this.m_bTestBorder&&this.testBorder(e))return!0;if(t.vmin>this.m_inputPoint.y||t.vmax<this.m_inputPoint.y)return!1;const s=e.getMonotonicParts(this.m_monotoneParts,!0);if(s>0)for(let i=0;i<s;i++){const e=this.m_monotoneParts[i].get(),t=le.construct(e.getStartY(),e.getEndY());if(!(t.vmin>this.m_inputPoint.y||t.vmax<this.m_inputPoint.y)&&(this._DoOne(e),this.m_bBreak))return!0}else if(this._DoOne(e),this.m_bBreak)return!0;return!1}result(){return e(0),2}}function wt(e,t,s){const i=0===e.getFillRule(),r=new bt(i,s);r.SetInputPoint(t);const n=e.getImpl().querySegmentIterator();for(;n.nextPath();)for(;n.hasNextSegment();){const e=n.nextSegment();if(r.processSegment(e))return-1}return r._Result()?1:0}function Vt(e,t,s){return t.isEmpty()?0:Ht(e,t.getXY(),s)}function Ht(e,t,s){if(e.isEmpty())return 0;const i=n.constructEmpty();if(e.queryLooseEnvelope(i),i.inflateCoords(s,s),!i.contains(t))return 0;return e.getImpl().getAccelerators(),wt(e,t,s)}function Tt(e,t){const s=e.getPointCount();if(s<16)return!1;const i=1;return 2*s+1*(Math.log(s)/Math.log(2))*t<i*s*t}function kt(e){for(let t=e.getFirstGeometry();t!==H;t=e.getNextGeometry(t))if(u(e.getGeometryType(t)))return!0;return!1}function Ft(e,t,s,i){if(!kt(e))return!1;const r=new Bt(i);r.m_shape=e,r.m_tolerance=t,r.m_bTrackChanges=s;let n=!1;const h=e.hasCurves()?5:15;return n=e.getTotalPointCount()<h?r.crackBruteForce_():r.crackerPlaneSweep_(),n}function Gt(e,t,s,i,r){if(!kt(t))return!1;let n=new Bt(r);if(n.m_shape=t,n.m_tolerance=s,n.m_bAllowCoincident=e,n.m_bNeedsNonSimpleResult=null!==i,n.needsCrackingImpl_())return i&&i.assign(n.m_nonSimpleResult),!0;const h=new Q;h.setSwapCoordinates(),t.applyTransformation(h),n=new Bt(r),n.m_shape=t,n.m_tolerance=s,n.m_bAllowCoincident=e,n.m_bNeedsNonSimpleResult=null!==i;const a=n.needsCrackingImpl_();return t.applyTransformation(h),!!a&&(i&&i.assign(n.m_nonSimpleResult),!0)}class Bt{crackBruteForce_(){let e=this.crackBruteForceImpl_();if(!e&&this.m_shape.hasCurves()){const t=new Q;t.setSwapCoordinates(),this.m_shape.applyTransformation(t),e=this.crackBruteForceImpl_(),this.m_shape.applyTransformation(t)}return e}crackBruteForceImpl_(){let t=!1;const s=new G,i=new G,r=n.constructEmpty(),h=n.constructEmpty(),a=!1,o=new P,m=new dt,g=this.m_shape.getTotalPointCount(),l=g*g*2,_=this.m_shape.queryVertexIteratorOnSelection();for(let n=_.next();n!==H;n=_.next()){const g=this.m_shape.getGeometryType(_.currentGeometry());let d=1,p=1,u=1,c=0,f=0,x=0;const E=this.m_shape.getSegmentParentage(n);let I=!1,S=!1,C=null,P=!1;if(z(g))d=this.m_shape.getWeight(n),c=this.m_shape.getRank(n);else{if(C=this.getSegment_(n,s),null===C)continue;const e=this.m_shape.getVertexIndex(n);d=this.m_shape.getWeightWithIndex(e),c=this.m_shape.getRankWithIndex(e),u=this.m_shape.getSegmentWeightWithIndex(e),x=this.m_shape.getSegmentRankWithIndex(e),I=this.m_shape.getSegmentParentageBreakVertex(n);{const e=this.m_shape.getNextVertex(n);p=this.m_shape.getWeight(e),f=this.m_shape.getRank(e),S=this.m_shape.getSegmentParentageBreakVertex(e)}if(C.queryLooseEnvelope(r),r.inflateCoords(this.m_tolerance,this.m_tolerance),C.isDegenerate(this.m_tolerance)){if(!C.isDegenerate(0))continue;P=!0,C=null}}const y=new j({copy:_});let N=y.next();N!==H&&(N=y.next());let v=0;for(;N!==H;N=y.next()){if(0!==v){v--;continue}if(this.m_shape.getTotalPointCount()>l)return t;this.progress_();const g=this.m_shape.getGeometryType(y.currentGeometry());let b=null,w=!1,V=0,T=0,k=0,F=0,G=0,B=0,D=!1,A=!1;const U=this.m_shape.getSegmentParentage(N);if(z(g))V=this.m_shape.getWeight(N),F=this.m_shape.getRank(N);else{if(b=this.getSegment_(N,i),null===b)continue;const e=this.m_shape.getVertexIndex(N);V=this.m_shape.getWeightWithIndex(e),F=this.m_shape.getRankWithIndex(e),k=this.m_shape.getSegmentWeightWithIndex(e),B=this.m_shape.getSegmentRankWithIndex(e),D=this.m_shape.getSegmentParentageBreakVertex(N);{const e=this.m_shape.getNextVertex(N);T=this.m_shape.getWeight(e),G=this.m_shape.getRank(e),A=this.m_shape.getSegmentParentageBreakVertex(e)}if(b.queryLooseEnvelope(h),b.isDegenerate(this.m_tolerance)){if(!b.isDegenerate(0))continue;w=!0,b=null}}let O=0,Y=0;if(null!==C&&null!==b){if(r.isIntersectingNe(h)){0!==J(!0,!0,C,b,this.m_tolerance,!0)&&(m.pushSegment(C,d,c,p,f,u,x,I,S,E),m.pushSegment(b,V,F,T,G,k,B,D,A,U),m.intersect(this.m_tolerance,!0),t||=m.getSegmentChanged(0)||m.getSegmentChanged(1),O=m.getResultSegmentCount(0),Y=m.getResultSegmentCount(1),O+Y>0&&(this.m_shape.splitSegmentWithIntersector(n,m,0,!0,!0),this.m_shape.splitSegmentWithIntersector(N,m,1,!0,!0),this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(n,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(N,!0))),Y>1&&(v+=Y-1),m.clear())}}else if(null!==C){const e=this.m_shape.getXY(N);if(r.contains(e)){if(m.pushSegment(C,d,c,p,f,u,x,I,S,E),this.m_shape.queryPoint(N,o),m.intersectEx(this.m_tolerance,o,F,V,a),t||=m.getSegmentChanged(0)||m.getResultPointChanged(),O=m.getResultSegmentCount(0),O>0)if(this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(n,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(N,!0)),this.m_shape.splitSegmentWithIntersector(n,m,0,!0,!0),w){let e=H;for(let t=this.m_shape.getNextVertex(N);t!==H&&t!==N&&(b=this.getSegment_(t,i),e=t,null!=b&&b.isDegenerate(0));t=this.m_shape.getNextVertex(t));for(let t=N;t!==H&&(this.m_shape.setPoint(t,m.getResultPoint(),!0),t!==e);t=this.m_shape.getNextVertex(t));}else this.m_shape.setPoint(N,m.getResultPoint(),!0);m.clear()}}else{if(null===b)continue;{const e=this.m_shape.getXY(n);if(h.inflateCoords(this.m_tolerance,this.m_tolerance),h.contains(e)){if(m.pushSegment(b,V,F,T,G,k,B,D,A,U),this.m_shape.queryPoint(n,o),m.intersectEx(this.m_tolerance,o,c,d,a),t||=m.getSegmentChanged(0)||m.getResultPointChanged(),Y=m.getResultSegmentCount(0),Y>0)if(this.m_bTrackChanges&&(m.getSegmentChanged(0)&&this.m_shape.setGeometryModifiedWithVertex(N,!0),m.getSegmentChanged(1)&&this.m_shape.setGeometryModifiedWithVertex(n,!0)),this.m_shape.splitSegmentWithIntersector(N,m,0,!0,!0),v+=Y-1,P){let e=H;for(let t=this.m_shape.getNextVertex(n);t!==H&&t!==n&&(b=this.getSegment_(t,i),e=t,null!=b&&b.isDegenerate(0));t=this.m_shape.getNextVertex(t));for(let t=n;t!==H&&(this.m_shape.setPoint(t,m.getResultPoint(),!0),t!==e);t=this.m_shape.getNextVertex(t));}else this.m_shape.setPoint(n,m.getResultPoint(),!0);m.clear()}}}if(O+Y!==0&&0!==O){let t=!1;for(;C=this.getSegment_(n,s),null!=C&&(C.queryEnvelope(r),C.isDegenerate(this.m_tolerance));){if(!(O>1)){t=!0;break}n=_.next(),O--,e(n!==H)}if(t)break}}}return t}crackerPlaneSweep_(){return this.planesweep_()}planesweep_(){return new vt(this.m_progressTracker,this.m_bTrackChanges).sweep(this.m_shape,this.m_tolerance)}needsCrackingImpl_(){let t=!1;const s=new c(0),i=this.m_shape.queryVertexIteratorOnSelection();for(let e=i.next();e!==H;e=i.next())s.add(e);this.m_shape.sortVerticesSimpleByY(s,0,s.size()),s.add(H);const r=this.m_shape.createUserIndex(),n=this.m_shape.createUserIndex();this.m_sweepComparator=new it(this.m_shape,this.m_tolerance,!this.m_bAllowCoincident),this.m_sweepStructure.setComparator(this.m_sweepComparator);let h=null;const a=[],o=[];let m=0;for(let g=s.read(m++);g!==H;){const i=this.m_shape.getXY(g);let l=!1;do{this.progress_();let e=this.m_shape.getNextVertex(g),t=this.m_shape.getPrevVertex(g);l||=e!==H||t!==H,e===H||this.m_shape.selected(e)||(e=H),t===H||this.m_shape.selected(t)||(t=H),e!==H&&this.m_shape.compareVerticesSimpleY(g,e)<0&&(o.push(g),o.push(e)),t!==H&&this.m_shape.compareVerticesSimpleY(g,t)<0&&(o.push(t),o.push(t));const i=this.m_shape.getUserIndex(g,r);-1!==i&&(a.push(i),this.m_shape.setUserIndex(g,r,-1));const h=this.m_shape.getUserIndex(g,n);-1!==h&&(a.push(h),this.m_shape.setUserIndex(g,n,-1)),g=s.read(m++)}while(g!==H&&this.m_shape.isEqualXYPoint2D(g,i));if(!l&&(null===h&&(h=new rt(this.m_shape,this.m_tolerance)),h.setPoint(i),this.m_sweepStructure.searchUpperBound(h),h.intersectionDetected())){t=!0,this.m_bNeedsNonSimpleResult&&(e(0),this.m_nonSimpleResult=new Xe(6,-1,-1));break}let _=1===a.length&&2===o.length;const d=32;a.length>d&&K(a);let p=-1,u=-1;if(!_)for(let e=0,s=a.length;e<s;e++){const s=a[e],i=this.m_sweepStructure.getPrev(s);if(-1!==i&&-1===a.indexOf(i))if(-1===p)p=i;else{if(t=!0,!this.m_bNeedsNonSimpleResult)break;this.m_nonSimpleResult=new Xe(6,-1,-1)}const r=this.m_sweepStructure.getNext(s);if(-1!==r&&-1===a.indexOf(r))if(-1===u)u=r;else{if(t=!0,!this.m_bNeedsNonSimpleResult)break;this.m_nonSimpleResult=new Xe(6,-1,-1)}if(-1!==p&&-1!==u)break}if(t&&!this.m_bNeedsNonSimpleResult)break;if(this.m_sweepComparator.setSweepY(i.y,i.x),!_){for(let e=0,t=a.length;e<t;e++){const t=a[e];this.m_sweepStructure.deleteNode(t)}a.length=0}if(!_&&-1!==p&&-1!==u&&this.checkForIntersections_(p,u)){t=!0,this.m_bNeedsNonSimpleResult&&(this.m_nonSimpleResult=this.m_sweepComparator.getResult());break}for(let e=0,s=o.length;e<s;e+=2){const s=o[e],i=o[e+1];let h;if(_?(h=this.m_sweepStructure.replaceElementAtPosition(a[0],s,!0,!0),a.length=0,_=!1):h=this.m_sweepStructure.addElement(s),this.m_sweepComparator.intersectionDetected()){this.m_bNeedsNonSimpleResult&&(this.m_nonSimpleResult=this.m_sweepComparator.getResult()),t=!0;break}-1===this.m_shape.getUserIndex(i,r)?this.m_shape.setUserIndex(i,r,h):this.m_shape.setUserIndex(i,n,h)}if(t)break;o.length=0}return this.m_shape.removeUserIndex(r),this.m_shape.removeUserIndex(n),t}checkForIntersections_(e,t){const s=this.m_sweepStructure.getElement(e);this.m_sweepComparator.compare(this.m_sweepStructure,s,t);const i=this.m_sweepComparator.intersectionDetected();return this.m_sweepComparator.clearIntersectionDetectedFlag(),i}getSegment_(e,t){return Bt.st_getSegment(this.m_shape,e,t)}static st_getSegment(e,t,s){return e.querySegment(t,s,!1,!1)?s.get():null}dbgPrintSweepEdge(e){}dbgPrintSweepStructure(){}dbgSaveSweepStructure(e=null){}dbgCheckSweepStructure(){}progress_(e=!1){this.m_progressCounter++,!e&&4095&this.m_progressCounter||(this.m_progressCounter=0)}static st_quadTreeWillHelp_(t,s){return e(0),!1}crackAWithBMultiPath_(t,s,i){return e(0),t}constructor(e){this.m_shape=null,this.m_progressTracker=null,this.m_nonSimpleResult=new Xe,this.m_tolerance=0,this.m_sweepComparator=null,this.m_progressCounter=0,this.m_bTrackChanges=!1,this.m_bNeedsNonSimpleResult=!1,this.m_bAllowCoincident=!0,this.m_sweepStructure=new _,this.m_progressTracker=e}}function Dt(e,t,s,i,r){return new Ot(e,s,t,i,r).do_()}function At(t,s,i){if(!t.hasCurves())return!1;t.dbgVerifyCurves();const r=t.createUserIndexUninitialized(),n=new c(0),h=t.queryVertexIteratorOnSelection();for(let e=h.next();e!==H;e=h.next())n.add(e),t.setUserIndex(e,r,-1);if(0===n.size())return!1;n.add(H),t.sortVerticesSimpleByY(n,0,n.size()-1);let a=0;const o=t.getXY(n.read(a)),m=F.getNAN(),g=[];for(let e=1,l=n.size();e<l;++e){const s=n.read(e),i=s!==H?t.getXY(s):m;if(i.equals(o))continue;const h=[];for(let m=a;m<e;m++){const e=n.read(m),s=t.getPrevVertex(e);if(s!==H&&-1===t.getUserIndex(s,r)){const e=Yt(t.getXY(s),t.getSegment(s));0!==F.sqrDistance(o,e.otherPt)&&(e.vert=s,e.dir=-1,h.push(e)),t.setUserIndex(s,r,1)}const i=t.getNextVertex(e);if(i!==H&&-1===t.getUserIndex(e,r)){const s=Yt(t.getXY(i),t.getSegment(e));0!==F.sqrDistance(o,s.otherPt)&&(s.vert=e,s.dir=1,h.push(s)),t.setUserIndex(e,r,1)}}if(h.length>1){h.sort(Rt);const e=Yt(F.getNAN(),null);h.push(e);let t=0;for(let s=1,i=h.length;s<i;s++)if(!h[s].otherPt.equals(h[s-1].otherPt)){if(s-t>1&&null!==h[t].seg){let e=!1;const i=t;for(let r=t+1;r<s;r++)if(!Xt(h[i],h[r])){e=!0;break}if(e)for(let r=t;r<s&&null!==h[r].seg;r++)g.push(h[r].vert)}t=s}}a=e,o.setCoordsPoint2D(i)}for(const l of g){const i=t.getSegment(l);e(null!==i);const r=t.getXY(l),n=t.getXY(t.getNextVertex(l));if(F.distance(r,n)<3*s)t.setSegmentToIndex(t.getVertexIndex(l),null);else{const e=i.lengthToT(.5*i.calculateLength2D());t.splitSegment(l,[e],1)}}return t.removeUserIndex(r),g.length>0}function Ut(e){return d(e)}Bt.s_bForceBruteForce=!0;class Ot{constructor(e,t,s,i,r){this.m_shape=e,this.m_progressTracker=t,this.m_tolerance=s,this.m_bFilterDegenerateSegments=i,this.m_bTrackChanges=r,this.m_progressCounter=0}do_(){const e=new pe(this.m_tolerance.tolerance,this.m_tolerance.resolution),t=1e-5,s=1e-6,i=Ut(e);let r=p(e);const n=r*(1+t);r*=1+s;let h=!1;const a=this.m_shape.getTotalPointCount()+10>30?1e3:(this.m_shape.getTotalPointCount()+10)*(this.m_shape.getTotalPointCount()+10),m=this.m_shape.hasPointFeatures();for(let g=0;;g++){this.m_shape.dbgCheckSelection(),g>a&&o("crack_and_cluster_iteration_exceeded"),this.m_shape.dbgVerifyMonotone();let e=-1;0===g&&(e=this.firstCrack_(),h||=e>0);const t=this.cluster_(i);if(this.m_shape.dbgVerifyMonotone(),h||=t,this.m_bFilterDegenerateSegments){const e=0!==this.m_shape.filterClosePoints(i,!0,!1,this.m_bTrackChanges,H);h||=e,this.m_shape.dbgVerifyMonotone()}const s=this.m_shape.snapControlPointsOnSelection(n*n);h||=s,this.m_shape.dbgCheckSelection();let l=!1;if((0===g&&-1===e||m||Gt(!0,this.m_shape,r,null,this.m_progressTracker))&&(l=this.crack_(n),h||=l,this.m_shape.dbgVerifyMonotone()),!l&&!At(this.m_shape,i,this.m_progressTracker)){this.m_shape.dbgVerifyMonotone();break}}return h&&(ds(this.m_shape),_s(this.m_shape)),h}cluster_(e){return ht(this.m_shape,e,H,this.m_bTrackChanges,this.m_progressTracker)}crack_(e){return Ft(this.m_shape,e,this.m_bTrackChanges,this.m_progressTracker)}static fixCurveTwoPointLoops(t,s,i){return e(0),!1}firstCrack_(){const e=this.m_shape.getEnvelope2D(this.m_progressTracker),t=T(null,e,!0).total();if(4*t<this.m_tolerance.total()){let e=!1;const s=1.1*t,i=t,r=this.cluster_(s);e||=r;let n=0;this.m_bFilterDegenerateSegments&&(n=this.m_shape.filterClosePoints(0,!0,!1,this.m_bTrackChanges,H));const h=this.crack_(i);return e||=h,e?1:n?2:0}return-1}progress_(e=!1){this.m_progressCounter++,!e&&4095&this.m_progressCounter||(this.m_progressCounter=0)}}function Yt(e,t){return{otherPt:e,seg:t}}function Xt(e,t){if(null===e.seg)return null===t.seg;if(null===t.seg)return!1;const s=e.seg.getGeometryType();if(s!==t.seg.getGeometryType())return!1;if(s===i.enumBezier){const s=e.seg,i=t.seg;let r=s.getControlPoint1(),n=s.getControlPoint2();-1===e.dir&&(n=q(r,r=n));let h=i.getControlPoint1(),a=i.getControlPoint2();return-1===t.dir&&(a=q(h,h=a)),r.equals(h)&&n.equals(a)}if(s===i.enumRationalBezier2){const s=e.seg,i=t.seg,r=s.getControlPoint1(),n=i.getControlPoint1();if(!r.equals(n))return!1;const h=new Array(3);s.queryWeights(h),-1===e.dir&&(h[2]=q(h[0],h[0]=h[2]));const a=new Array(3);return i.queryWeights(a),-1===t.dir&&(a[2]=q(a[0],a[0]=a[2])),h[0]===a[0]&&h[1]===a[1]&&h[2]===a[2]}o("")}function qt(e,t){if(null===e.seg||null===t.seg)return null!==e.seg?-1:null!==t.seg?1:0;const s=e.seg.getGeometryType(),i=t.seg.getGeometryType();return s<i?-1:s>i?1:0}function Rt(e,t){const s=e.otherPt.compare(t.otherPt);return 0!==s?s:qt(e,t)}function Mt(e,t,s){if(null!=t){if("object"!=typeof t&&"function"!=typeof t)throw new TypeError("Object expected.");var i,r;if(void 0===i){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");i=t[Symbol.dispose]}if("function"!=typeof i)throw new TypeError("Object not disposable.");r&&(i=function(){try{r.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:t,dispose:i,async:s})}return t}var Lt="function"==typeof SuppressedError?SuppressedError:function(e,t,s){var i=new Error(s);return i.name="SuppressedError",i.error=e,i.suppressed=t,i};function zt(e){function t(t){e.error=e.hasError?new Lt(t,e.error,"An error was suppressed during disposal."):t,e.hasError=!0}function s(){for(;e.stack.length;){var i=e.stack.pop();try{var r=i.dispose&&i.dispose.call(i.value);if(i.async)return Promise.resolve(r).then(s,(function(e){return t(e),s()}))}catch(n){t(n)}}if(e.hasError)throw e.error}return s()}function Wt(e,t,s,i,r){const n=new Jt(r);return n.m_shape=e,n.m_geometry=t,n.m_sortedVertices=s,n.m_bFixSelfTangency=i,n.fixRingOrientation_()}class Qt{getDirection_(e){return this.m_shape.getNextVertex(this.getEnd1(e))===this.getEnd2(e)}getEnd_(e){const t=this.getEnd1(e),s=this.getEnd2(e);return this.m_shape.getNextVertex(t)===s?s:t}constructor(e){this.m_end1Nodes=[],this.m_end2Nodes=[],this.m_directions=[],this.m_shape=e,this.m_firstFree=-1}getSegment(e){return this.m_shape.getSegment(this.getStart(e))}isBottomUp(t){let s=this.getEnd1(t),i=this.getEnd2(t);this.m_shape.getPrevVertex(s)===i&&(i=q(s,s=i));const r=F.getNAN(),n=F.getNAN();return this.m_shape.queryXY(s,r),this.m_shape.queryXY(i,n),e(!r.equals(n)),r.y<n.y}getStart(e){const t=this.getEnd1(e),s=this.getEnd2(e);return this.m_shape.getNextVertex(t)===s?t:s}getEnd1(e){return this.m_end1Nodes[e]}getEnd2(e){return this.m_end2Nodes[e]}freeEdge(e){this.m_end1Nodes[e]=this.m_firstFree,this.m_firstFree=e}newEdge(e){if(-1!==this.m_firstFree){const t=this.m_firstFree;return this.m_firstFree=this.m_end1Nodes[t],this.m_end1Nodes[t]=e,this.m_end2Nodes[t]=this.m_shape.getNextVertex(e),t}const t=this.m_end1Nodes.length;return this.m_end1Nodes.push(e),this.m_end2Nodes.push(this.m_shape.getNextVertex(e)),t}getShape(){return this.m_shape}getPath(e){return this.m_shape.getPathFromVertex(this.getEnd1(e))}}let Zt=class extends de{constructor(e){super(),this.m_line1=new ge,this.m_line2=new ge,this.m_leftElm=-1,this.m_leftx=0,this.m_seg1=null,this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_edges;let n;if(this.m_leftElm===t)n=this.m_leftx;else{if(this.m_seg1=r.getSegment(t),this.m_seg1)n=this.m_seg1.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(t),this.m_line1,!0),this.m_seg1=this.m_line1,n=this.m_line1.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0)}this.m_leftx=n,this.m_leftElm=t}let h,a=r.getSegment(i);if(a)h=a.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(i),this.m_line2,!0),a=this.m_line2,h=this.m_line2.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0)}if(n===h){const e=r.isBottomUp(t),s=r.isBottomUp(i),o=e?this.m_seg1.getEndY():this.m_seg1.getStartY(),m=s?a.getEndY():a.getStartY(),g=Math.min(o,m);let l=.5*(g+this.m_helper.m_yScanline);l===this.m_helper.m_yScanline&&(l=g),n=this.m_seg1.intersectionOfYMonotonicWithAxisX(l,0),h=a.intersectionOfYMonotonicWithAxisX(l,0),n===h&&Se("")}return n<h?-1:n>h?1:0}reset(){this.m_leftElm=-1}};class jt{constructor(e){this.m_node=-1,this.m_index=0,this.m_sortedVertices=e.m_sortedVertices,this.m_sortedVerticesArray=e.m_sortedVerticesArray,this.m_sortedVertices&&(this.m_node=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList()))}next(){if(this.m_sortedVertices){const e=this.m_node;if(-1===e)return H;const t=this.m_sortedVertices.getData(e);return this.m_node=this.m_sortedVertices.getNext(e),t}if(this.m_index<this.m_sortedVerticesArray.size()){const e=this.m_sortedVerticesArray.read(this.m_index);return this.m_index++,e}return H}}class Jt{constructor(e){this.m_edges=null,this.m_shape=null,this.m_AET=new _,this.m_yScanline=0,this.m_geometry=H,this.m_unknownRingOrientationCount=-1,this.m_sortedVertices=null,this.m_sortedVerticesArray=null,this.m_unknownNodes=[],this.m_node1UserIndex=-1,this.m_node2UserIndex=-1,this.m_pathOrientationIndex=-1,this.m_pathParentageIndex=-1,this.m_pathParentsIndex=-1,this.m_progressCounter=0,this.m_bFixSelfTangency=!1,this.m_progressTracker=e,this.m_AET.disableBalancing(),this.m_sweepComparator=new Zt(this),this.m_AET.setComparator(this.m_sweepComparator)}fixRingOrientation_(){const e=this.fixRingOrientationImplMain_();return-1===this.m_pathOrientationIndex||this.fixRingOrientationImplSimplify_(),e}fixRingOrientationForMp2sp_(){return e(0),0}processBunchForRingOrientationTest_(e){return this.processBunchForRingOrientationTestOddEven_(e)}processBunchForRingOrientationTestOddEven_(t){let s=!1;if(this.m_edges||(this.m_edges=new Qt(this.m_shape)),this.m_unknownNodes.length=0,this.processBunchForRingOrientationRemoveEdges_(t),!this.m_AET.isAutoBalancing()){let e=0;for(let s=0,i=t.length;s<i;s++){-1!==t[s]&&e++}(e>10||this.m_AET.getMaxDepthEver()>4)&&this.m_AET.enableBalancing()}for(let e=0,i=t.length;e<i;e++){const s=t[e];s!==H&&this.insertEdge_(s,-1)}for(let i=0;i<this.m_unknownNodes.length&&this.m_unknownRingOrientationCount>0;i++){const t=this.m_unknownNodes[i],r=this.m_AET.getElement(t),n=this.m_edges.getPath(r),h=this.m_shape.getPathUserIndex(n,this.m_pathOrientationIndex);let a=H;if(0===h){let i=this.m_AET.getPrev(t),r=t,n=!1;for(;i!==_.st_nullNode();){const e=this.m_AET.getElement(i),t=this.m_edges.getPath(e);if(0!==this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){a=t;break}r=i,i=this.m_AET.getPrev(i)}if(i===_.st_nullNode())n=!0,i=r;else{const e=this.m_AET.getElement(i);n=this.m_edges.isBottomUp(e),i=this.m_AET.getNext(i),n=!n}do{const t=this.m_AET.getElement(i),h=this.m_edges.getPath(t);if(0===this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex)){if(n!==this.m_edges.isBottomUp(t)){const e=this.m_shape.getFirstVertex(h);this.m_shape.reverseRingInternal(e),this.m_shape.setLastVertex(h,this.m_shape.getPrevVertex(e)),s=!0}if(this.m_shape.setPathUserIndex(h,this.m_pathOrientationIndex,n?3:2),!n){let t=this.m_shape.getPathUserIndex(a,this.m_pathOrientationIndex);2===t?(a=this.m_shape.getPathUserIndex(a,this.m_pathParentsIndex),t=this.m_shape.getPathUserIndex(a,this.m_pathOrientationIndex),e(3===t)):e(3===t);const s=this.m_shape.getPathUserIndex(a,this.m_pathParentageIndex);this.m_shape.setPathUserIndex(a,this.m_pathParentageIndex,h),this.m_shape.setPathUserIndex(h,this.m_pathParentageIndex,s),this.m_shape.setPathUserIndex(h,this.m_pathParentsIndex,a)}if(this.m_unknownRingOrientationCount--,!this.m_unknownRingOrientationCount)return s}a=h,r=i,i=this.m_AET.getNext(i),n=!n}while(r!==t)}}return s}processBunchForRingOrientationRemoveEdges_(e){for(let t=0,s=e.length;t<s;t++){const s=e[t],i=this.m_shape.getUserIndex(s,this.m_node1UserIndex),r=this.m_shape.getUserIndex(s,this.m_node2UserIndex);if(-1!==i){const e=this.m_AET.getElement(i);this.m_edges.freeEdge(e),this.m_shape.setUserIndex(s,this.m_node1UserIndex,-1)}if(-1!==r){const e=this.m_AET.getElement(r);this.m_edges.freeEdge(e),this.m_shape.setUserIndex(s,this.m_node2UserIndex,-1)}let n=-1;-1!==i&&-1!==r?(this.m_AET.deleteNode(i),this.m_AET.deleteNode(r),e[t]=H):n=-1!==i?i:r,-1!==n&&(this.insertEdge_(s,n)||this.m_AET.deleteNode(n),e[t]=H)}}dbgVerifyRingOrientation_(){}insertEdge_(e,t){const s=F.getNAN(),i=F.getNAN();this.m_shape.queryXY(e,s);const r=this.m_shape.getNextVertex(e);this.m_shape.queryXY(r,i);let n=!1;if(s.y<i.y){n=!0;const s=this.m_edges.newEdge(e);let i;-1===t?i=this.m_AET.addElement(s):(i=t,this.m_AET.setElement(i,s));-1===this.m_shape.getUserIndex(r,this.m_node1UserIndex)?this.m_shape.setUserIndex(r,this.m_node1UserIndex,i):this.m_shape.setUserIndex(r,this.m_node2UserIndex,i);const h=this.m_shape.getPathFromVertex(e);0===this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex)&&this.m_unknownNodes.push(i)}const h=this.m_shape.getPrevVertex(e);if(this.m_shape.queryXY(h,i),s.y<i.y){n=!0;const s=this.m_edges.newEdge(h);let i;-1===t?i=this.m_AET.addElement(s):(i=t,this.m_AET.setElement(i,s));-1===this.m_shape.getUserIndex(h,this.m_node1UserIndex)?this.m_shape.setUserIndex(h,this.m_node1UserIndex,i):this.m_shape.setUserIndex(h,this.m_node2UserIndex,i);const r=this.m_shape.getPathFromVertex(e);0===this.m_shape.getPathUserIndex(r,this.m_pathOrientationIndex)&&this.m_unknownNodes.push(i)}return n}fixRingSelfTangency_(){return e(0),!1}progress_(e=!1){}fixRingOrientationImplMain_(){const e={stack:[],error:void 0,hasError:!1};try{let t,s=!1;const i=Mt(e,Fe((()=>{this.m_sortedVerticesArray=null})),!1);if(null===this.m_sortedVertices){const e=this.m_shape.getPointCount(this.m_geometry);t=new c(0);for(let s=this.m_shape.getFirstPath(this.m_geometry);s!==H;s=this.m_shape.getNextPath(s)){let e=this.m_shape.getFirstVertex(s);for(let i=0,r=this.m_shape.getPathSize(s);i<r;i++)t.add(e),e=this.m_shape.getNextVertex(e)}this.m_shape.sortVerticesSimpleByY(t,0,e),this.progress_(!0),this.m_sortedVerticesArray=t}else i.bForget=!0;if(this.m_bFixSelfTangency&&(s=this.fixRingSelfTangency_()),1===this.m_shape.getPathCount(this.m_geometry)){const e=this.m_shape.getFirstPath(this.m_geometry),t=this.m_shape.getRingArea(e);if(this.m_shape.setExterior(e,!0),t<0){const t=this.m_shape.getFirstVertex(e);return _s(this.m_shape),this.m_shape.reverseRingInternal(t),_s(this.m_shape),this.m_shape.setLastVertex(e,this.m_shape.getPrevVertex(t)),!0}return!1}this.m_shape.dbgVerifyCurves(),this.m_pathOrientationIndex=this.m_shape.createPathUserIndex(),this.m_pathParentageIndex=this.m_shape.createPathUserIndex(),this.m_pathParentsIndex=this.m_shape.createPathUserIndex();for(let e=this.m_shape.getFirstPath(this.m_geometry);e!==H;e=this.m_shape.getNextPath(e))this.m_shape.setPathUserIndex(e,this.m_pathOrientationIndex,0),this.m_shape.setPathUserIndex(e,this.m_pathParentageIndex,-1),this.m_shape.setPathUserIndex(e,this.m_pathParentsIndex,-1);const r=[];this.m_yScanline=Number.NaN;const n=F.getNAN();this.m_unknownRingOrientationCount=this.m_shape.getPathCount(this.m_geometry),this.m_node1UserIndex=this.m_shape.createUserIndexUninitialized(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,this.m_node1UserIndex,-1),this.m_node2UserIndex=this.m_shape.createUserIndexUninitialized(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,this.m_node2UserIndex,-1);const h=new jt(this);for(let e=h.next();e!==H&&(this.progress_(),this.m_shape.queryXY(e,n),n.y!==this.m_yScanline&&r.length&&(s=this.processBunchForRingOrientationTest_(r)||s,this.m_sweepComparator.reset(),r.length=0),r.push(e),this.m_yScanline=n.y,0!==this.m_unknownRingOrientationCount);e=h.next());return this.m_unknownRingOrientationCount>0&&(s=this.processBunchForRingOrientationTest_(r)||s,r.length=0),this.m_shape.removeUserIndex(this.m_node1UserIndex),this.m_shape.removeUserIndex(this.m_node2UserIndex),this.dbgVerifyRingOrientation_(),s}catch(t){e.error=t,e.hasError=!0}finally{zt(e)}}fixRingOrientationImplSimplify_(){const e=[];for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==H;)if(this.progress_(),3===this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){this.m_shape.setExterior(t,!0);for(let r=this.m_shape.getPathUserIndex(t,this.m_pathParentageIndex);r!==H;){const s=this.m_shape.getPathUserIndex(r,this.m_pathParentageIndex);e.push(r),this.m_shape.setExterior(r,!1),this.m_shape.setPathUserIndex(r,this.m_pathParentageIndex,t),r=s}let s=t,i=e.length;for(let e=this.m_shape.getNextPath(t);i>0&&e!==H;e=this.m_shape.getNextPath(e),--i){if(this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex)!==t){s=H;break}s=e}if(0!==i){s=t;for(let t=0,i=e.length;t<i;t++){const i=e[t];this.m_shape.setPathUserIndex(i,this.m_pathParentageIndex,Ce),this.m_shape.movePath(this.m_geometry,this.m_shape.getNextPath(s),i),s=i}}e.length=0,t=this.m_shape.getNextPath(s)}else t=this.m_shape.getNextPath(t);this.m_shape.removePathUserIndex(this.m_pathOrientationIndex),this.m_shape.removePathUserIndex(this.m_pathParentageIndex),this.m_shape.removePathUserIndex(this.m_pathParentsIndex)}fixRingOrientationImplMp2sp_(){return e(0),0}}function Kt(e,t,s,i,r,n){const h=new $t(n);return h.m_shape=e,h.m_geometry=t,h.m_knownSimpleResult=s,h.m_bFixSelfTangency=i,h.m_polylineDegeneracies=r,h.m_bHasSegmentParentage=e.hasSegmentParentage(),h.m_bHasSegments=e.hasCurves(),h.simplify_()}class $t{constructor(e){this.m_shape=null,this.m_geometry=H,this.m_sortedVertices=new l,this.m_bunchEdgeEndPoints=[],this.m_bunchEdgeCenterPoints=[],this.m_bunchEdgeIndices=[],this.m_knownSimpleResult=-1,this.m_sortedVerticesListIndex=-1,this.m_polylineDegeneracies=H,this.m_userIndexSortedIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=-1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=-1,this.m_progressCounter=0,this.m_bFixSelfTangency=!1,this.m_bHasSegmentParentage=!1,this.m_bHasSegments=!1,this.m_progressTracker=e}compareAngles_(e,t){if(this.m_bHasSegments)return this.compareAnglesCurves_(e,t);const s=this.m_bunchEdgeEndPoints[e],i=new F;this.m_shape.queryXY(s,i);const r=new F,n=this.m_bunchEdgeEndPoints[t];if(this.m_shape.queryXY(n,r),i.equals(r))return 0;const h=this.m_bunchEdgeCenterPoints[e],a=new F;this.m_shape.queryXY(h,a);const o=this.m_bunchEdgeCenterPoints[t],m=new F;this.m_shape.queryXY(o,m);const g=new F;g.setSub(i,a);const l=new F;l.setSub(r,m),(g.isZero()||l.isZero())&&Se("");return F.compareVectors(g,l)}compareAnglesCurves_(e,t){const s=this.m_bunchEdgeEndPoints[e],i=this.m_bunchEdgeEndPoints[t],r=this.m_bunchEdgeCenterPoints[e],n=this.m_bunchEdgeCenterPoints[t],h=this.m_shape.getNextVertex(r)===s,a=this.m_shape.getNextVertex(n)===i,o=new G,m=new F;h?(this.m_shape.querySegment(r,o,!1,!0),m.assign(o.get().getTangent(0))):(this.m_shape.querySegment(s,o,!1,!0),m.assign(o.get().getTangent(1)),m.negateThis());const g=new F;a?(this.m_shape.querySegment(n,o,!1,!0),g.assign(o.get().getTangent(0))):(this.m_shape.querySegment(i,o,!1,!0),g.assign(o.get().getTangent(1)),g.negateThis()),(m.isZero()||g.isZero())&&Se("");return F.compareVectors(m,g)}beforeRemoveVertex_(e,t){const s=this.m_shape.getUserIndex(e,this.m_userIndexSortedIndexToVertex);if(this.m_nextVertexToProcess===s&&(this.m_nextVertexToProcess=this.m_sortedVertices.getNext(this.m_nextVertexToProcess)),this.m_firstCoincidentVertex===s&&(this.m_firstCoincidentVertex=this.m_sortedVertices.getNext(this.m_firstCoincidentVertex)),this.m_sortedVertices.deleteElement(this.m_sortedVerticesListIndex,s),this.removeAngleSortInfo_(e),t){const t=this.m_shape.getPathFromVertex(e);if(t!==H){if(this.m_shape.getFirstVertex(t)===e){const s=this.m_shape.getNextVertex(e);if(s!==e){if(this.m_shape.getPathFromVertex(s)===t)return void this.m_shape.setFirstVertex(t,s);{const s=this.m_shape.getPrevVertex(e);if(s!==e){if(this.m_shape.getPathFromVertex(s)===t)return void this.m_shape.setFirstVertex(t,s)}}}this.m_shape.setFirstVertex(t,H),this.m_shape.setLastVertex(t,H)}}}}processBunch_(){let e=!1;const t=new F(0,0);for(;;){this.m_bunchEdgeEndPoints.length=0,this.m_bunchEdgeCenterPoints.length=0,this.m_bunchEdgeIndices.length=0;let s=this.m_firstCoincidentVertex,i=0,r=!0;for(;s!==this.m_nextVertexToProcess;){const e=this.m_sortedVertices.getData(s);r&&(this.m_shape.queryXY(e,t),r=!1);const n=this.m_shape.getPrevVertex(e),h=this.m_shape.getNextVertex(e);this.m_shape.getUserIndex(n,this.m_userIndexSortedAngleIndexToVertex)!==Ce&&(this.m_bunchEdgeEndPoints.push(n),this.m_shape.setUserIndex(n,this.m_userIndexSortedAngleIndexToVertex,Ce),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++));this.m_shape.getUserIndex(h,this.m_userIndexSortedAngleIndexToVertex)!==Ce&&(this.m_bunchEdgeEndPoints.push(h),this.m_shape.setUserIndex(h,this.m_userIndexSortedAngleIndexToVertex,Ce),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++)),s=this.m_sortedVertices.getNext(s)}if(this.m_bunchEdgeEndPoints.length<2){1===this.m_bunchEdgeEndPoints.length&&this.m_shape.setUserIndex(this.m_bunchEdgeEndPoints[0],this.m_userIndexSortedAngleIndexToVertex,-1);break}this.m_bunchEdgeIndices.sort(((e,t)=>this.compareAngles_(e,t)));for(let e=0,t=this.m_bunchEdgeIndices.length;e<t;e++){const t=this.m_bunchEdgeIndices[e],s=this.m_bunchEdgeEndPoints[t];this.m_shape.setUserIndex(s,this.m_userIndexSortedAngleIndexToVertex,e)}const n=this.processCrossOvers_(t);for(let e=0,t=this.m_bunchEdgeIndices.length;e<t;e++){const t=this.m_bunchEdgeIndices[e];if(-1===t)continue;const s=this.m_bunchEdgeEndPoints[t];this.m_shape.setUserIndex(s,this.m_userIndexSortedAngleIndexToVertex,-1)}if(!n)break;e=!0}return e}processCrossOvers_(e){let t=!1,s=!0;for(;s;){s=!1;let i=0;-1===this.m_bunchEdgeIndices[i]&&(i=this.getNextEdgeIndex_(i));let r=this.getNextEdgeIndex_(i);for(let n=0,h=this.m_bunchEdgeIndices.length;n<h&&-1!==i&&-1!==r&&i!==r;n++){const n=this.m_bunchEdgeIndices[i],h=this.m_bunchEdgeIndices[r],a=this.m_bunchEdgeEndPoints[n],o=this.m_bunchEdgeEndPoints[h];let m=this.m_shape.getNextVertex(a),g=!1;this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(a),g=!0);let l=this.m_shape.getNextVertex(o),_=!1;this.m_shape.isEqualXYPoint2D(l,e)||(l=this.m_shape.getPrevVertex(o),_=!0);const d=g?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=_?this.m_shape.getPrevVertex(l):this.m_shape.getNextVertex(l);let u=!1;(this.removeSpike_(m)||this.removeSpike_(l)||this.removeSpike_(a)||this.removeSpike_(o)||this.removeSpike_(d)||this.removeSpike_(p))&&(u=!0),m!==l&&(!u&&this.m_shape.isEqualXY(a,o)&&(u=this.resolveOverlap_(g,_,m,a,l,o)),!u&&this.m_shape.isEqualXY(d,p)&&(u=this.resolveOverlap_(!g,!_,m,d,l,p)),!u&&this.m_shape.isEqualXY(a,p)&&(u=this.resolveOverlap_(g,!_,m,a,l,p)),!u&&this.m_shape.isEqualXY(d,o)&&(u=this.resolveOverlap_(!g,_,m,d,l,o))),u&&(t=!0),s||=u,i=u?this.getNextEdgeIndex_(i):r,r=this.getNextEdgeIndex_(i)}}if(!t){let s=0;-1===this.m_bunchEdgeIndices[s]&&(s=this.getNextEdgeIndex_(s));let i=this.getNextEdgeIndex_(s);for(let r=0,n=this.m_bunchEdgeIndices.length;r<n&&-1!==s&&-1!==i&&s!==i;r++){const r=this.m_bunchEdgeIndices[s],n=this.m_bunchEdgeIndices[i],h=this.m_bunchEdgeEndPoints[r],a=this.m_bunchEdgeEndPoints[n];let o=this.m_shape.getNextVertex(h);this.m_shape.isEqualXYPoint2D(o,e)||(o=this.m_shape.getPrevVertex(h));let m=this.m_shape.getNextVertex(a);this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(a));const g=this.getDirection_(o,h),l=this.getDirection_(m,a),_=g?this.m_shape.getPrevVertex(o):this.m_shape.getNextVertex(o),d=l?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=this.detectAndResolveCrossOver_(g,l,h,o,_,a,m,d);1!==p?0===p?(s=this.getNextEdgeIndex_(s),i=this.getNextEdgeIndex_(s)):(s=this.getPrevEdgeIndex_(s),i=this.getNextEdgeIndex_(s)):t=!0}}return t}simplify_(){if(this.m_shape.getGeometryType(this.m_geometry)===i.enumPolygon&&1===this.m_shape.getFillRule(this.m_geometry)){new Qs(this.m_progressTracker).planarSimplifyNoCrackingAndCluster(this.m_bFixSelfTangency,this.m_shape,this.m_geometry,0)}let e=!1;this.m_userIndexSortedIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=-1,this.m_userIndexSortedAngleIndexToVertex=this.m_shape.createUserIndexUninitialized();const t=this.m_shape.getPointCount(this.m_geometry),s=new c(0);this.m_shape.dbgVerifyMonotone();for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==H;i=this.m_shape.getNextPath(i)){let e=this.m_shape.getFirstVertex(i);for(let t=0,r=this.m_shape.getPathSize(i);t<r;t++)this.m_shape.setUserIndex(e,this.m_userIndexSortedAngleIndexToVertex,-1),s.add(e),e=this.m_shape.getNextVertex(e)}this.m_shape.sortVerticesSimpleByY(s,0,t),this.progress_(!0),this.m_userIndexSortedIndexToVertex=this.m_shape.createUserIndexUninitialized(),this.m_sortedVertices.reserveNodes(t),this.m_sortedVerticesListIndex=this.m_sortedVertices.createList(0);for(let i=0;i<t;i++){const e=s.read(i),t=this.m_sortedVertices.addElement(this.m_sortedVerticesListIndex,e);this.m_shape.setUserIndex(e,this.m_userIndexSortedIndexToVertex,t)}this.m_nextVertexToProcess=-1,this.cleanupSpikes_()&&(e=!0);let r=0,n=!1;do{n=!1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=this.m_sortedVertices.getFirst(this.m_sortedVerticesListIndex);const t=new F(0,0);this.m_firstCoincidentVertex!==l.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(this.m_firstCoincidentVertex),t);let s=0,i=this.m_firstCoincidentVertex;for(;i!==l.st_nullNode()&&(i=this.m_sortedVertices.getNext(i),i!==l.st_nullNode());){this.progress_();const e=this.m_sortedVertices.getData(i),r=F.getNAN();if(this.m_shape.queryXY(e,r),t.equals(r))s++;else{if(s>0){this.m_nextVertexToProcess=i;const e=this.processBunch_();i=this.m_nextVertexToProcess,i!==l.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(i),r),e&&(n=!0)}t.setCoordsPoint2D(r),this.m_firstCoincidentVertex=i,s=0}}if(this.m_nextVertexToProcess=-1,s>0){this.processBunch_()&&(n=!0)}r++>10&&o(""),n&&this.fixOrphanVertices_(),this.cleanupSpikes_()&&(n=!0),e||=n}while(n);return this.m_shape.dbgVerifyMonotone(),this.m_shape.dbgVerifyCurves(),this.m_shape.removeUserIndex(this.m_userIndexSortedIndexToVertex),this.m_shape.removeUserIndex(this.m_userIndexSortedAngleIndexToVertex),_s(this.m_shape),e=Wt(this.m_shape,this.m_geometry,this.m_sortedVertices,this.m_bFixSelfTangency,this.m_progressTracker)||e,this.m_shape.dbgVerifyCurves(),_s(this.m_shape),e}getDirection_(e,t){return this.m_shape.getNextVertex(t)!==e}detectAndResolveCrossOver_(e,t,s,i,r,n,h,a){if(i===h)return this.removeAngleSortInfo_(s),this.removeAngleSortInfo_(n),-1;const o=this.m_shape.getUserIndex(s,this.m_userIndexSortedAngleIndexToVertex),m=this.m_shape.getUserIndex(r,this.m_userIndexSortedAngleIndexToVertex),g=this.m_shape.getUserIndex(n,this.m_userIndexSortedAngleIndexToVertex),l=this.m_shape.getUserIndex(a,this.m_userIndexSortedAngleIndexToVertex),_=new Array(8),d=new Array(4);_[0]=0,d[0]=o,_[1]=0,d[1]=m,_[2]=1,d[2]=g,_[3]=1,d[3]=l;for(let u=1;u<4;u++){const e=d[u],t=_[u];let s=u-1;for(;s>=0&&d[s]>e;)d[s+1]=d[s],_[s+1]=_[s],s--;d[s+1]=e,_[s+1]=t}let p=0;if(_[0]&&(p|=1),_[1]&&(p|=2),_[2]&&(p|=4),_[3]&&(p|=8),5!==p&&10!==p)return 0;if(e!==t&&(a=q(n,n=a)),e)this.m_shape.setNextVertex(a,i),this.m_shape.setPrevVertex(i,a),this.m_shape.setNextVertex(r,h),this.m_shape.setPrevVertex(h,r),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(h,!0));else{if(this.m_shape.setPrevVertex(a,i),this.m_shape.setNextVertex(i,a),this.m_shape.setPrevVertex(r,h),this.m_shape.setNextVertex(h,r),this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(i),t=this.m_shape.getSegmentParentage(h);this.m_shape.setSegmentParentageAndBreak(i,t,!0),this.m_shape.setSegmentParentageAndBreak(h,e,!0)}if(this.m_bHasSegments){const e=this.m_shape.getVertexIndex(i),t=this.m_shape.getVertexIndex(h),s=this.m_shape.getSegmentFromIndex(e);this.m_shape.setSegmentToIndex(e,null);const r=this.m_shape.getSegmentFromIndex(t);this.m_shape.setSegmentToIndex(t,null),this.m_shape.setSegmentToIndex(e,r),this.m_shape.setSegmentToIndex(t,s)}}return 1}resolveOverlap_(e,t,s,i,r,n){return this.resolveOverlapOddEven_(e,t,s,i,r,n)}resolveOverlapOddEven_(e,t,s,i,r,n){if(e!==t){e||(r=q(s,s=r),n=q(i,i=n));const t=this.m_shape.getNextVertex(r),h=this.m_shape.getNextVertex(s);if(this.m_shape.setNextVertex(s,t),this.m_shape.setPrevVertex(t,s),this.m_shape.setNextVertex(r,h),this.m_shape.setPrevVertex(h,r),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(s),t=this.m_shape.getVertexIndex(r),i=this.m_shape.getSegmentFromIndex(e);this.m_shape.setSegmentToIndex(e,null);const n=this.m_shape.getSegmentFromIndex(t);this.m_shape.setSegmentToIndex(t,null),this.m_shape.setSegmentToIndex(e,n),this.m_shape.setSegmentToIndex(t,i)}if(this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(s),t=this.m_shape.getSegmentParentage(r);this.m_shape.setSegmentParentageAndBreak(s,t,!0),this.m_shape.setSegmentParentageAndBreak(r,e,!0),this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(n,!0)}this.removeSpike_(r)}else{const h=e?s:i,a=t?r:n,o=e?i:s,m=t?n:r;let g=null;if(this.m_bHasSegments){const e=this.m_shape.getVertexIndex(m);g=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null);const t=this.m_shape.getVertexIndex(a);this.m_shape.setSegmentToIndex(t,null);const s=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(s,null)}let l=-1;this.m_bHasSegmentParentage&&(l=this.m_shape.getSegmentParentage(m));let _=!1;this.m_shape.setNextVertex(h,a),this.m_shape.setNextVertex(a,h),this.m_shape.setPrevVertex(o,m),this.m_shape.setPrevVertex(m,o);let d=m;for(;d!==a;){const e=this.m_shape.getPrevVertex(d),t=this.m_shape.getNextVertex(d);if(this.m_shape.setPrevVertex(d,t),this.m_shape.setNextVertex(d,e),_||=d===h,this.m_bHasSegments&&d!==h){const e=this.m_shape.getVertexIndex(t),s=g;g=this.m_shape.getSegmentFromIndex(e),null!==s&&s.reverse(),this.m_shape.setSegmentToIndex(e,s)}if(this.m_bHasSegmentParentage){const e=this.m_shape.getSegmentParentage(t);this.m_shape.setSegmentParentagePreserveBreak(t,l),l=e}d=t}let p=null;if(!_){const e=this.m_shape.getPrevVertex(a),t=this.m_shape.getNextVertex(a);if(this.m_shape.setPrevVertex(a,t),this.m_shape.setNextVertex(a,e),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(a);p=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null)}}let u=-1,c=-1;if(this.m_bHasSegmentParentage&&(u=_?this.m_shape.getSegmentParentage(h):this.m_shape.getSegmentParentage(a),c=this.m_shape.getSegmentParentage(o)),this.transferVertexData_(a,h),this.beforeRemoveVertex_(a,!0),this.m_shape.removeVertexInternal(a,!0),this.removeAngleSortInfo_(h),this.transferVertexData_(m,o),this.beforeRemoveVertex_(m,!0),this.m_shape.removeVertexInternal(m,!0),this.removeAngleSortInfo_(o),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageAndBreak(h,u,!0),this.m_shape.setSegmentParentageAndBreak(o,c,!0)),p){const e=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(e,p)}}return!0}cleanupSpikes_(){_s(this.m_shape);let e=!1;for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==H;){const s=this.m_shape.getNextPath(t);let i=this.m_shape.getFirstVertex(t);for(let r=0,n=this.m_shape.getPathSize(t);r<n&&n>1;){this.progress_();const{v:s,bModified:h}=this.checkAndCleanupSpike_(t,i);if(s===H)break;h?(e=!0,i=s,r=0,n=this.m_shape.getPathSize(t)):(i=s,r++)}t=s}return _s(this.m_shape),e}checkAndCleanupSpike_(e,t){const s={v:H,bModified:!1};let i=this.m_shape.getPrevVertex(t),r=this.m_shape.getNextVertex(t),n=H,h=H;for(;this.m_shape.isEqualXY(i,r)&&(n=i,h=r,r!==t);)i=this.m_shape.getPrevVertex(i),r=this.m_shape.getNextVertex(r);if(n===H)return s.v=r,s;s.bModified=!0;for(let a=this.m_shape.getNextVertex(n);this.beforeRemoveVertex_(a,!1),a!==h;a=this.m_shape.getNextVertex(a));if(n===t)return this.m_polylineDegeneracies!==H?this.m_shape.movePath(this.m_polylineDegeneracies,H,e):this.m_shape.removePath(e),s.v=H,s;{const e=this.m_shape.peelALoopIntoAPath(n,h);this.m_polylineDegeneracies!==H?this.m_shape.movePath(this.m_polylineDegeneracies,H,e):this.m_shape.removePath(e)}return s.v=n,s}removeSpike_(e){let t=this.m_shape.getPrevVertex(e),s=this.m_shape.getNextVertex(e),i=H,r=H;for(;this.m_shape.isEqualXY(t,s)&&(i=t,r=s,s!==e);)t=this.m_shape.getPrevVertex(t),s=this.m_shape.getNextVertex(s);if(i===H)return!1;if(this.m_shape.peelALoop(i,r),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageBreakVertex(i,!0),this.m_shape.setSegmentParentageBreakVertex(r,!0)),this.removeAngleSortInfo_(i),this.m_polylineDegeneracies===H)for(let n=this.m_shape.getNextVertex(r);;){const e=this.m_shape.getNextVertex(n);if(this.removeAngleSortInfo_(n),this.beforeRemoveVertex_(n,!0),this.m_shape.setSegmentToIndex(this.m_shape.getVertexIndex(n),null),this.m_shape.removeVertexInternal(n,!1),n===r)break;n=e}else{for(let t=r;;){const e=this.m_shape.getNextVertex(t);if(this.removeAngleSortInfo_(t),this.beforeRemoveVertex_(t,!1),t=e,t===r)break}const e=[!1];this.m_shape.insertClosedPath(this.m_polylineDegeneracies,H,r,r,e)}return!0}fixOrphanVertices_(){let e=0;for(let i=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList());-1!==i;i=this.m_sortedVertices.getNext(i)){const e=this.m_sortedVertices.getData(i);this.m_shape.setPathToVertex(e,H)}let t=0;for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==H;){const s=this.m_shape.getFirstVertex(i);if(s===H||this.m_shape.getPathFromVertex(s)!==H){const e=i;i=this.m_shape.getNextPath(i),this.m_shape.removePathOnly(e);continue}this.m_shape.setPathToVertex(s,i);let r=1;for(let e=this.m_shape.getNextVertex(s);e!==s;e=this.m_shape.getNextVertex(e))this.m_shape.setPathToVertex(e,i),r++;this.m_shape.setRingAreaValid(i,!1),this.m_shape.setPathSize(i,r),this.m_shape.setLastVertex(i,this.m_shape.getPrevVertex(s)),t+=r,e++,i=this.m_shape.getNextPath(i)}for(let i=this.m_sortedVertices.getFirst(this.m_sortedVertices.getFirstList());-1!==i;i=this.m_sortedVertices.getNext(i)){const s=this.m_sortedVertices.getData(i);if(this.m_shape.getPathFromVertex(s)!==H)continue;const r=[!1],n=this.m_shape.insertClosedPath(this.m_geometry,H,s,s,r);t+=this.m_shape.getPathSize(n),e++}this.m_shape.setGeometryPathCount(this.m_geometry,e),this.m_shape.setGeometryVertexCount(this.m_geometry,t);let s=0;for(let i=this.m_shape.getFirstGeometry();i!==H;i=this.m_shape.getNextGeometry(i))s+=this.m_shape.getPointCount(i);this.m_shape.setTotalPointCount(s)}getNextEdgeIndex_(e){if(-1===e)return-1;for(let t=0,s=this.m_bunchEdgeIndices.length-1;t<s;t++)if(e=(e+1)%this.m_bunchEdgeIndices.length,-1!==this.m_bunchEdgeIndices[e])return e;return-1}getPrevEdgeIndex_(e){if(-1===e)return-1;for(let t=0,s=this.m_bunchEdgeIndices.length-1;t<s;t++)if(e=(this.m_bunchEdgeIndices.length+e-1)%this.m_bunchEdgeIndices.length,-1!==this.m_bunchEdgeIndices[e])return e;return-1}transferVertexData_(e,t){const s=this.m_shape.getUserIndex(t,this.m_userIndexSortedIndexToVertex),i=this.m_shape.getUserIndex(t,this.m_userIndexSortedAngleIndexToVertex);this.m_shape.transferAllDataToTheVertex(e,t),this.m_shape.setUserIndex(t,this.m_userIndexSortedIndexToVertex,s),this.m_shape.setUserIndex(t,this.m_userIndexSortedAngleIndexToVertex,i)}removeAngleSortInfo_(e){const t=this.m_shape.getUserIndex(e,this.m_userIndexSortedAngleIndexToVertex);-1!==t&&(this.m_bunchEdgeIndices[t]=-1,this.m_shape.setUserIndex(e,this.m_userIndexSortedAngleIndexToVertex,-1))}progress_(e=!1){}}function es(e,t,s){const i=Vt(e,t,s);return i?1===i?1:2:0}function ts(e,t,s){const i=Ht(e,t,s);return i?1===i?1:2:0}function ss(e,t,s,i,r){for(let n=0;n<s;n++)r[n]=ts(e,t[n],i)}function is(e,t,s,r,h){if(e.getGeometryType()===i.enumPolygon)ss(e,t,s,r,h);else if(e.getGeometryType()===i.enumEnvelope){const t=n.constructEmpty();e.queryEnvelope(t),ns()}else Pe("")}function rs(e,t,s,r,n){const a=e.getGeometryType();a===i.enumPolyline?os():h(a)?as():Pe("")}function ns(t,s,i,r,n){e(0)}function hs(e,t,s){if(s.reset(),t<3)return;const i=e[0].clone(),r=i.x,n=i.y,h=e[1].clone(),a=new F;for(let o=2;o<t;o++)a.assign(e[o]),s.pe((a.x-i.x)*(h.y-n)),i.assign(h),h.assign(a);s.pe((r-i.x)*(h.y-n))}function as(t,s,i,r,n){e(0)}function os(t,s,i,r,n){e(0)}function ms(e,t,s,i,r,n,h){gs(e,t,s,r,n,h)}function gs(e,t,s,i,r,n){e.hasCurves()?(e.setCurveStitcherPointer(i),i.m_impl=new Es(n,!1,null),i.m_impl.buildMonotonicCurveParentage(e,t,s,r)):i.m_impl=null}function ls(e,t,s,i,r,n,h,a){e.hasCurves()?(e.setCurveStitcherPointer(n),n.m_impl=new Es(a,!0,r),n.m_impl.buildMonotonicCurveParentage(e,t,s,h),At(e,s)):n.m_impl=null}function _s(e){}function ds(e){if(!e.hasSegmentParentage())return;const t=new c(0),s=e.queryVertexIteratorOnSelection();for(let h=s.next();h!==H;h=s.next())t.add(h);if(0===t.size())return;e.sortVerticesSimpleByY(t,0,t.size()),t.add(H);const i=F.getNAN();e.queryXY(t.read(0),i);let r=0;const n=F.getNAN();for(let h=1,a=t.size();h<a;h++){{const s=t.read(h);s!==H?e.queryXY(s,n):n.setNAN()}if(!n.isEqualPoint2D(i)){let s=!1,a=-2;for(let i=r;i<h;++i){const r=t.read(i);if(e.getSegmentParentageBreakVertex(r)){s=!0;break}let n=e.getSegmentParentage(r);const h=e.getPrevVertex(r);if(h!==H){let t=e.getSegmentParentage(h);if(-1===n&&(n=t),-1===t&&(t=n),n!==t){s=!0;break}}if(-2!==a&&n!==a){s=!0;break}a=n}if(s)for(let i=r;i<h;++i)e.setSegmentParentageBreakVertex(t.read(i),!0);i.setCoordsPoint2D(n),r=h}}}function ps(e,t){let s=t.isEmpty()?e:T(null,t,!0).total();return s>e&&(s=e),.125*s}function us(e,t){return t||(t=n.constructEmpty()),ps(e,t)}function cs(e,t){return.125*e}function fs(e,t){return 3*e+3*t}class xs{constructor(){this.m_impl=null}stitchCurves(e,t,s,i){this.m_impl&&(this.m_impl.stitchCurves(e,t,s),i&&this.clearStitcher(e))}clearStitcher(e){this.m_impl&&(this.m_impl.clearStitcher(e),this.m_impl=null)}getOriginalVertexIndex(e,t){return this.m_impl.getOriginalVertexIndex(e,t)}getOriginalSegmentTypeInfo(e){return this.m_impl.getOriginalSegmentTypeInfo(e)}}class Es{constructor(e,t,s){this.m_originalPlanarSegments=[],this.m_progressTracker=null,this.m_nsr=null,this.m_progressTracker=e,this.m_nsr=s,this.m_tolerance=0,this.m_originalVertexIndex=-1,this.m_type=0,this.m_progressCounter=0,this.m_bIsSimple=t}buildSegmentParentage(t,s,i,r,n){e(0)}static processCurves(t,s,i,r){return e(0),t}buildMonotonicCurveParentage(t,s,r,n){const h=!1;if(!t.hasCurves())return;e(!t.hasSegmentParentage()),this.m_type=1,this.m_originalPlanarSegments.length=0,this.m_bIsSimple&&(this.m_originalVertexIndex=t.createUserIndex()),this.m_tolerance=r;const a=new P,o=new G,m=[],g=[],l=[];for(let _=t.getFirstGeometry();_!==H;_=t.getNextGeometry(_))for(let n=t.getFirstPath(_);n!==H;n=t.getNextPath(n)){let _=t.getPathSize(n),d=t.getFirstVertex(n),p=0,u=-1;for(let c=0;c<_;c++){let f=t.getNextVertex(d);if(!t.querySegment(d,o,!0,!1)){d=f;continue}if(0===p){u=t.getVertexIndex(d);const s=Es.regularizeCurve(t,o.get(),d,r);if(s>=0){this.m_nsr&&0===this.m_nsr.m_reason&&this.m_nsr.assign(new Xe(13,u,-1)),p=s,_=t.getPathSize(n),f=t.getNextVertex(d);const i=t.querySegment(d,o,!0,!1);e(i)}}else p--;const x=t.getVertexIndex(d);let E;-1!==this.m_originalVertexIndex&&t.setUserIndex(d,this.m_originalVertexIndex,u),t.setSegmentToIndex(x,null);let I=!1;switch(o.get().getGeometryType()){case i.enumEllipticArc:case i.enumRationalBezier2:E=Ye(o.get(),s,r,h,g,l,m,this.m_progressTracker),I=!0;break;default:{const e=!this.m_bIsSimple||!o.get().isMonotoneQuickAndDirty();E=Oe(o.get(),s,r,e,h,g,m,this.m_progressTracker)}}const S=this.m_originalPlanarSegments.length;if(t.setSegmentParentageAndBreak(d,S,!0),!g[1].isNAN()){let e=null;I?(ee(g),ee(l),e=new te({points:g,weights:l})):e=new $({cp:g}),e.snapControlPoints(r*r),t.setSegmentToIndex(x,e)}const C=I?2:3;for(let e=1,s=E,i=C;e<s;++e,i+=C){o.get().queryCoord(m[e],a);const s=t.insertVertex(n,f,a);if(-1!==this.m_originalVertexIndex&&t.setUserIndex(s,this.m_originalVertexIndex,u),!g[i+1].isNAN())if(I){const e=new te({points:g.slice(i),weights:l.slice(i)});e.snapControlPoints(r*r),t.setSegmentToIndex(t.getVertexIndex(s),e)}else{const e=new $({cp:g.slice(i)});e.snapControlPoints(r*r),t.setSegmentToIndex(t.getVertexIndex(s),e)}t.setSegmentParentageAndBreak(s,S,!1)}E>1&&(c+=E-1,_=t.getPathSize(n)),this.m_originalPlanarSegments.push(o.releaseSegment()),d=f}}}stitchCurves(e,t,s){Es.st_stitchCurvesImpl(this,e,t,s,!1)}clearStitcher(e){this.m_originalPlanarSegments.length=0,-1!==this.m_originalVertexIndex&&(e.removeUserIndex(this.m_originalVertexIndex),this.m_originalVertexIndex=-1),e.deleteSegmentParentage()}static st_verifyParentage(e){Es.st_stitchCurvesImpl(null,e,H,0,!0)}getOriginalVertexIndex(e,t){return-1!==this.m_originalVertexIndex&&t!==H?e.getUserIndex(t,this.m_originalVertexIndex):-1}getOriginalSegmentTypeInfo(e){if(-1!==e){const t=this.m_originalPlanarSegments[e];switch(t.getGeometryType()){case i.enumEllipticArc:return 0===t.projectionBehavior()?0:1;case i.enumBezier:return 2;case i.enumBezier2:return 3;case i.enumLine:return-1;case i.enumRationalBezier2:return 4;default:se("")}}return-1}static st_curveRequiresRegularization(t,s){return e(0),!1}progress_(e=!1){this.m_progressCounter++,e||this.m_progressCounter}processSpan_(t,s,i,r,n,h,a){if(s===i&&0===r)return e(t.getNextVertex(s)===H),t.setSegmentToIndex(t.getVertexIndex(s),null),void t.setSegmentParentageAndBreak(s,-1);const o=t.getNextVertex(s);{let s=2;for(let e=o;e!==i;e=t.getNextVertex(e))s++;e(s===r)}if(null===n){t.setSegmentToIndex(t.getVertexIndex(s),null);for(let e=o;e!==i;)e=t.removeVertex(e,!0);return}const m=t.getXY(s),g=t.getXY(i);if(n.isClosed()){if(m.isEqualPoint2D(g)&&m.isEqualPoint2D(n.getStartXY())){let e;if(e=this.verifySegmentFitness(t,s,i,r,n,h,a)){const r=n.clone();return r.dropAllAttributes(),e<0&&r.reverse(),this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),r)}}}else if(m.isEqualPoint2D(n.getStartXY())){if(g.isEqualPoint2D(n.getEndXY())){const e=n.clone();if(e.dropAllAttributes(),this.verifySegmentFitness(t,s,i,r,e,h,a))return this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),e)}}else if(g.isEqualPoint2D(n.getStartXY())&&m.isEqualPoint2D(n.getEndXY())){const e=n.getReversed();if(e.dropAllAttributes(),this.verifySegmentFitness(t,s,i,r,e,h,a))return this.removeSpan(t,s,i),void t.setSegmentToIndex(t.getVertexIndex(s),e)}this.processSpanSplitSegment(t,s,i,r,n,h,a)}processSpanSplitSegment(e,t,s,i,r,n,h){if(r.isLine())return;if(this.fitSegmentToSpan(e,t,s,i,r,n,h))return;const a=h*h;let o=i,m=t;const g=e.getXY(t);let l=r.getClosestCoordinate(g,!1);const _=r.getCoord2D(l);let d=!1;const p=F.sqrDistance(g,_);if(p>a){const i=e.getNextVertex(t);if(this.approximateSpanSection(e,t,r,n,h),i===s)return;m=i,d=!0,o-=1}let u=s;const c=e.getXY(s);l=r.getClosestCoordinate(c,!1);const f=r.getCoord2D(l);let x=!1;const E=F.sqrDistance(c,f);if(E>a){const t=e.getPrevVertex(s);if(this.approximateSpanSection(e,t,r,n,h),t===m)return;u=t,x=!0,o-=1}if((d||x)&&this.fitSegmentToSpan(e,m,u,o,r,n,h))return;let I=!1;if(!d&&p>0){const s=e.getNextVertex(t);if(this.approximateSpanSection(e,t,r,n,h),s===u)return;m=s,d=!0,I=!0,o-=1}if(!x&&E>0){const t=e.getPrevVertex(s);if(this.approximateSpanSection(e,t,r,n,h),t===m)return;u=t,x=!0,I=!0,o-=1}if(I&&this.fitSegmentToSpan(e,m,u,o,r,n,h))return;let S=m;for(;;){const t=e.getNextVertex(S);if(this.approximateSpanSection(e,S,r,n,h),S=t,S===u)return}}fitSegmentToSpan(t,s,i,r,n,h,a){const o=0===this.m_type,m=[];if(m.push(t.getXY(s)),o){let n=s;const h=32;if(r>h){const s=BigInt(r-1),a=BigInt(h-1);let o=a,g=0n;for(let e=1;e<r;e++,o+=a)if(n=t.getNextVertex(n),o>=g+s){g+=s;const e=t.getXY(n);m.push(e)}e(n===i)}else{for(let e=1;e<r;e++){n=t.getNextVertex(n);const e=t.getXY(n);m.push(e)}e(n===i)}}else{let e=s;const n=new G;for(;;){t.querySegment(e,n,!1,!0);const s=[.1,.25,.4,.5,.6,.75,.9,1];let h=0;for(const e of s){(2===r||1&h)&&m.push(n.get().getCoord2D(e)),h++}if(e=t.getNextVertex(e),e===i)break}}const g=(()=>{let e=m[0].compare(m.at(-1));if(0===e){const t=new ce(0);hs(m,m.length,t),e=t.getResult()>=0?-1:1}return e>0})();g&&m.reverse();const l=n.clone();if(l.dropAllAttributes(),l.setSegmentFromCoords(m,m.length),g&&l.reverse(),l.snapControlPoints(this.m_tolerance*this.m_tolerance),this.verifySegmentFitness(t,s,i,r,l,h,a)){this.removeSpan(t,s,i);const e=t.getVertexIndex(s);return t.setSegmentToIndex(e,l),!0}return!1}approximateSpanSection(e,t,s,r,n){const h=new G;if(!e.querySegment(t,h,!0,!1))return;const a=s.getGeometryType();if(a!==h.get().getGeometryType()){if(a===i.enumEllipticArc){if(h.get().getGeometryType()!==i.enumRationalBezier2)return;if(0===s.projectionBehavior()){const s=[];ie(!1,h.get(),n,s,this.m_progressTracker);const i=e.getNextVertex(t),r=e.getPathFromVertex(t),a=new P;let o=t;for(let t=1,n=s.length;t<n;t++){const n=s[t],m=h.get().getCoord2D(s[t-1]),g=h.get().getCoord2D(re(s[t-1],n,.5));h.get().queryCoord(n,a);const l=a.getXY(),_=new ne;_.constructCircularArcThreePoint(m,l,g);let d=H;n<1&&(d=e.insertVertex(r,i,a)),e.setSegmentToIndex(e.getVertexIndex(o),_),o=d}return}{const s=he(F,3);h.get().queryControlPoints(s);const i=[0,0,0];h.get().queryWeights(i);const r=ae(i),n=new ne;return oe(s,r*r,null,!1,n),void e.setSegmentToIndex(e.getVertexIndex(t),n)}}o("approximate_span_section_")}}verifySegmentFitness(e,t,s,i,r,n,h){return 0===this.m_type?this.verifySegmentFitnessLines(e,t,s,i,r,n,h):this.verifySegmentFitnessCurves(e,t,s,i,r,n,h)}verifySegmentFitnessCurves(e,t,s,i,r,n,h){const a=e.getXY(t),o=e.getXY(s);if(!a.isEqualPoint2D(r.getStartXY())||!o.isEqualPoint2D(r.getEndXY()))return 0;let m=0;if(r.isClosed()){const e=r.getCoord2D(.1).sub(a);m=r.getCoord2D(.7).sub(a).crossProduct(e)>=0?1:-1}const g=new Array(me.s_maxMonotonicPartParams);let l=r.getMonotonicPartParams(g.length,g);l--;const _=new ge,d=[1,.5,.75,.25];let p=0,u=t;const c=a.clone();for(;;){const t=e.getNextVertex(u);let i=e.getSegment(u);null===i&&(e.queryLineConnector(u,_,!0),i=_);for(let e=t===s?1:0;e<d.length;e++){const t=i.getCoord2D(d[e]);if(!r.isCloserThanDistance(t,le.unit(),h))return 0}if(l>1)for(let e=1;e<l;){const t=r.getCoord2D(g[e]);i.isCloserThanDistance(t,le.unit(),h)?(g[l-1]=q(g[e],g[e]=g[l-1]),l--):e++}if(m){const e=i.getCoord2D(.25);p+=e.sub(a).crossProduct(c.sub(a)),c.assign(e),e.assign(i.getCoord2D(.75)),p+=e.sub(a).crossProduct(c.sub(a)),c.assign(e)}if(u=t,u===s)return l>1?0:m?p<0?-m:m:1}}verifySegmentFitnessLines(t,s,i,r,n,h,a){return e(0),0}removeSpan(e,t,s){e.setSegmentToIndex(e.getVertexIndex(t),null);const i=e.getNextVertex(t);i!==s&&e.removeVertices(i,s)}static st_stitchCurvesImpl(e,t,s,i,r){if(t.hasSegmentParentage())return t.hasCurves()?Es.st_stitchCurvesFromCurvesImpl(e,t,s,i,r):Es.st_stitchCurvesFromLinesImpl(e,t,s,i,r)}static st_stitchCurvesFromLinesImpl(t,s,i,r,n){let h=i===H?s.getFirstGeometry():i;for(;h!==H;){for(let i=s.getFirstPath(h);i!==H;i=s.getNextPath(i)){let h=s.getPathSize(i);s.isClosedPath(i)&&(h+=1);let a=!0,o=!1;const m=s.getFirstVertex(i);let g=m;for(let i=0;i<h&&g!==H;){let l=s.getSegmentParentage(g);if(-1===l||a){a=!1,i++,g=s.getNextVertex(g),o=!0;continue}let _,d,p=0;if(o?(_=s.getPrevVertex(g),d=g,e(_!==H),e(d!==_),e(-1===s.getSegmentParentage(_)||m===_)):(_=g,d=s.getNextVertex(_),i++,e(d!==H),e(d!==_),l=s.getSegmentParentage(d)),p=2,o=!1,-1===l||s.getSegmentParentageBreakVertex(d)){g=d;continue}let u=s.getNextVertex(d);for(i++;i<h&&u!==H;){d=u,p++;const t=s.getSegmentParentage(u);if(-1===t||s.getSegmentParentageBreakVertex(u))break;e(t===l),i++,u=s.getNextVertex(u)}if(!n){const e=t.m_originalPlanarSegments[l];t.processSpan_(s,_,d,p,e,l,r)}g=d}}if(i!==H)break;h=s.getNextGeometry(h)}}static st_stitchCurvesFromCurvesImpl(t,s,i,r,n){let h=i===H?s.getFirstGeometry():i;for(;h!==H;)if(_e(s.getGeometryType(h))){for(let i=s.getFirstPath(h);i!==H;i=s.getNextPath(i)){let h=s.getPathSize(i);const a=s.isClosedPath(i);a&&(h+=1);let o=s.getFirstVertex(i);if(a){if(-1!==s.getSegmentParentage(o)){let e=o;for(let t=0;!s.getSegmentParentageBreakVertex(e);t++){if(t===h){o=s.getFirstVertex(i),s.setSegmentParentageBreakVertex(e,!0);break}e=s.getPrevVertex(e)}}}else e(-1===s.getSegmentParentage(o)||s.getSegmentParentageBreakVertex(o));let m=o;for(let i=0;i<h&&m!==H;){const a=s.getSegmentParentage(m);if(-1===a){i++,m=s.getNextVertex(m);continue}let o=0,g=H;const l=m;o=1;let _=s.getNextVertex(l);for(;i<h&&_!==H;){i++,g=_,o++;const t=s.getSegmentParentage(_);if(-1===t||s.getSegmentParentageBreakVertex(_))break;e(t===a),_=s.getNextVertex(_)}if(g===H)break;if(!n){const e=t.m_originalPlanarSegments[a];t.processSpan_(s,l,g,o,e,a,r)}m=g}}if(i!==H)break;h=s.getNextGeometry(h)}else h=i===H?s.getNextGeometry(h):H}static regularizeCurve(e,t,s,i){let r=t.snapControlPoints(i*i);if(r){const i=e.getVertexIndex(s),r=t.clone();e.setSegmentToIndex(i,r)}if(t.getGeometryType()===$.type){const n=[],h=t.calculateSpecialPointsForCracking(i,n);if(h>0){e.splitSegment(s,n,h),r=e.snapControlPoints(s,h+1,i*i)||r;for(let t=0;t<h;t++)s=e.getNextVertex(s),e.setSegmentParentageBreakVertex(s,!0);return h}}return r?0:-1}}function Is(e,t,s,m,g){if(m&&(m.m_reason=0,m.m_vertexIndex1=-1,m.m_vertexIndex2=-1),e.isEmpty())return 5;const l=e.getGeometryType();if(l===i.enumPoint)return Cs(e,m);const _=r(t,e,!1).total();if(l===i.enumEnvelope){const t=e,s=n.constructEmpty();return t.queryEnvelope(s),s.isDegenerate(_)?(m&&(m.m_reason=4,m.m_vertexIndex1=-1,m.m_vertexIndex2=-1),0):5}if(h(l)){const i=e,r=new a({vd:i.getDescription()});return r.addSegment(i,!0),Is(r,t,s,m,g)}const d=[0],p=e.getImpl().getIsSimple(_,d);let u=s?-1:p;if(-1!==u)return u;const c=new vs(e,t,u,g,!1);return l===i.enumMultiPoint?u=c.multipointIsSimpleAsFeature():l===i.enumPolyline?u=c.polylineIsSimpleAsFeature():l===i.enumPolygon?u=c.polygonIsSimpleAsFeature():o(""),e.getImpl().setIsSimple(u,_),m&&m.assign(c.m_nonSimpleResult),u}function Ss(e,t,s,l){if(e.isEmpty())return e;const _=e.getGeometryType();if(_===i.enumPoint){const t=new Xe;if(Cs(e,t),3===t.m_reason){const t=e.clone();return t.replaceNaNs(1,0),t}return 2===t.m_reason?e.createInstance():e}if(_===i.enumEnvelope){const s=r(t,e,!0).total(),i=e,h=n.constructEmpty();return i.queryEnvelope(h),h.isDegenerate(s)?i.createInstance():e}if(h(_)){const i=e,r=new a({vd:i.getDescription()});return r.addSegment(i,!0),Ss(r,t,s,l)}m(_);const d=r(t,e,!1).total(),p=[0],u=e.getImpl().getIsSimple(d,p),c=s?-1:u;if(g(c)){if(_===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}if((_===i.enumMultiPoint||_===i.enumPolyline)&&c>=1)return e;const f=new vs(e,t,c,l,!1);let x;return _===i.enumMultiPoint?x=f.multipointSimplifyAsFeature():_===i.enumPolyline?x=f.polylineSimplifyAsFeature():_===i.enumPolygon?x=f.polygonSimplifyAsFeature():o(""),x}function Cs(e,t){const s=e.getX(),i=e.getY();if(!Number.isFinite(s)||!Number.isFinite(i))return t&&(t.m_reason=2,t.m_vertexIndex1=-1,t.m_vertexIndex2=-1),0;if(e.hasAttribute(1)){const s=e.getZ();if(!Number.isFinite(s))return t&&(t.m_reason=Number.isNaN(s)?3:2,t.m_vertexIndex1=-1,t.m_vertexIndex2=-1),0}return 5}class Ps{constructor(){this.m_segment=null,this.m_vertexIndex=-1,this.m_pathIndex=-1,this.m_flags=0}setReversed(e){this.m_flags&=-2,this.m_flags=this.m_flags|(e?1:0)}getReversed(){return!!(1&this.m_flags)}getRightSide(){return this.getReversed()?0:1}}class ys extends de{constructor(e){super(),this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_xy.read(2*t)-this.m_helper.m_xy.read(2*i);return r<0?-1:r>0?1:0}}class Ns extends de{constructor(e){super(),this.m_helper=e}compare(e,t,s){const i=e.getElement(s),r=this.m_helper.m_edges[t],n=this.m_helper.m_edges[i],h=r.getReversed(),a=n.getReversed();let o=r.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);if(o===m){const e=h?r.m_segment.getStartY():r.m_segment.getEndY(),t=a?n.m_segment.getStartY():n.m_segment.getEndY(),s=Math.min(e,t);let i=.5*(s-this.m_helper.m_yScanline)+this.m_helper.m_yScanline;i===this.m_helper.m_yScanline&&(i=s),o=r.m_segment.intersectionOfYMonotonicWithAxisX(i,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(i,0)}return o<m?-1:o>m?1:0}}class vs{constructor(e,t,s,i,n){this.m_multiVertexGeom=null,this.m_edges=[],this.m_freeEdges=[],this.m_lineEdgesRecycle=[],this.m_newEdges=[],this.m_recycledSegIter=null,this.m_crossOverHelperList=new l,this.m_progressTracker=null,this.m_progressCounter=0,this.m_AET=new _,this.m_xyToNode1=null,this.m_xyToNode2=null,this.m_pathOrientations=null,this.m_pathParentage=null,this.m_xy=null,this.m_pairs=[],this.m_pairIndices=null,this.m_pathsForOGCTests=[],this.m_curveStitcher=null,this.m_editShape=null,this.m_multiPathStitcher=null,this.m_nonSimpleResult=new Xe,this.m_progressCounter=0,this.m_progressTracker=i,this.m_geometry=e,this.m_knownSimpleResult=s,this.m_sr=t;const h=r(t,e,!1);this.m_toleranceIsSimple=h,this.m_toleranceIsSimpleClustering=d(h),this.m_toleranceIsSimpleCracking=p(h),this.m_toleranceSimplify=r(t,e,!0),this.m_description=this.m_geometry.getDescription(),this.m_attributeCount=this.m_description.getAttributeCount(),this.m_bOGCRestrictions=n,this.m_bPlanarSimplify=this.m_bOGCRestrictions,this.m_unknownOrientationPathCount=-1,this.m_yScanline=0,this.m_progressCounter=0}isSimplePlanarImpl(){if(this.m_bPlanarSimplify=!0,!this.checkStructure())return 0;const e=this.m_geometry.getGeometryType();return u(e)&&!this.checkDegenerateSegments(!1)?0:this._CheckClustering()?u(e)?this._CheckCracking()?this.m_geometry.getGeometryType()===i.enumPolyline?this.checkSelfIntersectionsPolylinePlanar()?4:0:this._CheckSelfIntersections()?this._CheckValidRingOrientation():0:0:5:0}isSimplePlanarImpl3D(){return e(0),7}generateSortedPairs(e){let t=null;u(e.getGeometryType())&&(t=e);const s=(this.m_bPlanarSimplify||this.m_bOGCRestrictions)&&null!==t,i=e.getPointCount();this.m_xy=e.getAttributeStreamRef(0),this.m_pairs.length=0,this.m_pairIndices=new c(0),s&&(this.m_pathsForOGCTests.length=0);let r=0;for(let a=0;a<i;a++)if(this.m_pairs.push(2*a),this.m_pairs.push(2*a+1),this.m_pairIndices.add(2*a),this.m_pairIndices.add(2*a+1),s){for(;a>=t.getPathEnd(r);)r++;this.m_pathsForOGCTests.push(r)}const n=new f,h={parent:this,workPt:new F,userSort(e,t,i){i.sort(e,t,((e,t)=>this.parent.compareVerticesForPlanarClustering(e,t,s)))},getValue(e){const t=this.parent.m_pairs[e],s=t>>1;this.parent.m_xy.queryPoint2D(2*s,this.workPt);return this.workPt.y+(1&t?this.parent.m_toleranceIsSimpleClustering:-this.parent.m_toleranceIsSimpleClustering)}};n.sort(this.m_pairIndices,0,2*i,h)}_TestToleranceDistancePlanar(e,t){const s=this.m_xy.read(2*e),i=this.m_xy.read(2*e+1),r=this.m_xy.read(2*t),n=this.m_xy.read(2*t+1);if(!!at(s,i,r,n,this.m_toleranceIsSimpleClustering*this.m_toleranceIsSimpleClustering)){if(0===this.m_geometry.getDimension())return!1;return s===r&&i===n}return!0}checkStructure(){const e=this.m_geometry.getGeometryType();if(u(e)){const e=this.m_geometry.getImpl(),t=this.m_geometry.getGeometryType()===i.enumPolygon?3:2;for(let s=0,i=e.getPathCount();s<i;s++)if(e.getPathSize(s)<t){if(e.hasNonLinearSegments()&&e.hasNonLinearSegmentsPath(s)&&e.getPathSize(s)>0)continue;return this.m_nonSimpleResult=new Xe(1,s,0),!1}}if(x(e)){const e=this.m_geometry.getImpl(),t=e.getAttributeStreamRef(0);for(let s=0,i=e.getPointCount();s<i;s++){if(!t.readPoint2D(2*s).isFinite())return this.m_nonSimpleResult=new Xe(2,s,0),!1}if(this.m_geometry.hasAttribute(1)){const t=e.getAttributeStreamRef(1);for(let s=0,i=e.getPointCount();s<i;s++){const e=t.read(s);if(!Number.isFinite(e))return Number.isNaN(e)?this.m_nonSimpleResult=new Xe(3,s,0):this.m_nonSimpleResult=new Xe(2,s,0),!1}}}return!0}checkDegenerateSegments(e){const t=this.m_geometry.getImpl(),s=t.querySegmentIterator(),i=t.hasAttribute(1),r=i?E(this.m_sr,t,!1).total():0,n=t.hasNonLinearSegments(),h=this.m_toleranceIsSimple.total();for(;s.nextPath();)for(;s.hasNextSegment();){const t=s.nextSegment();let a=t.calculateLowerLength2D();if(!(a>h)&&!(n&&t.isCurve()&&(a=t.calculateLength2D(),a>h))){if(e&&i){const e=t.getStartAttributeAsDbl(1,0),s=t.getEndAttributeAsDbl(1,0);if(Math.abs(s-e)>r)continue}return this.m_nonSimpleResult=new Xe(4,s.getStartPointIndex(),-1),!1}}return!0}checkDegenerateSegments3D(){return e(0),!1}_CheckClustering(){const e=this.m_geometry.getImpl();this.generateSortedPairs(e);const t=e.getPointCount();this.m_AET.clear(),this.m_AET.setComparator(new ys(this)),this.m_AET.setCapacity(t);for(let s=0,i=2*t;s<i;s++){this.progress_();const e=this.m_pairIndices.read(s),t=this.m_pairs[e],i=t>>1;if(1&t){const e=this.m_AET.search(i),t=this.m_AET.getPrev(e),s=this.m_AET.getNext(e);if(this.m_AET.deleteNode(e),t!==_.st_nullNode()&&s!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),this.m_AET.getElement(s)))return this.m_nonSimpleResult=new Xe(5,this.m_AET.getElement(t),this.m_AET.getElement(s)),!1}else{const e=this.m_AET.addElement(i),t=this.m_AET.getPrev(e);if(t!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),i))return this.m_nonSimpleResult=new Xe(5,i,this.m_AET.getElement(t)),!1;const s=this.m_AET.getNext(e);if(s!==_.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(s),i))return this.m_nonSimpleResult=new Xe(5,i,this.m_AET.getElement(s)),!1}}return!0}_CheckCracking(){const e=this.m_geometry.getImpl(),t=e.getPointCount();return!e.hasNonLinearSegments()&&t<10?this._CheckCrackingBrute():this._CheckCrackingPlanesweep()}_CheckCrackingPlanesweep(){if(this.m_editShape=new I,this.m_editShape.addGeometry(this.m_geometry),this.m_editShape.hasCurves()){this.m_curveStitcher=new xs;const e=n.constructEmpty();this.m_geometry.queryEnvelope(e);const t=us(this.m_toleranceSimplify.total(),e),s=new Xe;if(ls(this.m_editShape,t,this.m_toleranceSimplify.total(),12e3,s,this.m_curveStitcher,null,this.m_progressTracker),0!==s.m_reason)return this.m_editShape=null,this.m_nonSimpleResult.assign(s),!1}const e=new Xe;return Gt(!1,this.m_editShape,this.m_toleranceIsSimpleCracking,e,this.m_progressTracker)?(null!=this.m_curveStitcher?(e.m_vertexIndex1=this.m_curveStitcher.getOriginalVertexIndex(this.m_editShape,e.m_vertexIndex1),e.m_vertexIndex2=this.m_curveStitcher.getOriginalVertexIndex(this.m_editShape,e.m_vertexIndex2),this.m_curveStitcher=null):(e.m_vertexIndex1=this.m_editShape.getVertexIndex(e.m_vertexIndex1),e.m_vertexIndex2=this.m_editShape.getVertexIndex(e.m_vertexIndex2)),this.m_editShape=null,this.m_nonSimpleResult.assign(e),!1):(null==this.m_curveStitcher&&(this.m_editShape=null),!0)}_CheckCrackingBrute(){const e=this.m_geometry.getImpl(),t=e.querySegmentIterator(),s=e.querySegmentIterator();for(;t.nextPath();)for(;t.hasNextSegment();){const e=t.nextSegment();if(!t.isLastSegmentInPath()||!t.isLastPath()){s.resetTo(t);do{for(;s.hasNextSegment();){const i=s.nextSegment(),r=S(!0,e,i,this.m_toleranceIsSimpleCracking,!0);if(r){const e=2===r?7:6;return this.m_nonSimpleResult=new Xe(e,t.getStartPointIndex(),s.getStartPointIndex()),!1}}}while(s.nextPath())}}return!0}_CheckSelfIntersections(){let e=this.m_geometry.getImpl();null!==this.m_curveStitcher&&(this.m_multiPathStitcher=this.m_editShape.getGeometry(this.m_editShape.getFirstGeometry()),e=this.m_multiPathStitcher.getImpl(),this.generateSortedPairs(e)),this.m_edges.length=0,this.m_lineEdgesRecycle.length=0,this.m_recycledSegIter=e.querySegmentIterator(),this.m_recycledSegIter.setCirculator(!0);const t=new Array(0),s=e.getPointCount();let i=Number.NaN,r=0;for(let n=0,h=2*s;n<h;n++){this.progress_();const e=this.m_pairIndices.read(n),s=this.m_pairs[e];if(1&s)continue;const h=s>>1,a=this.m_xy.read(2*h),o=this.m_xy.read(2*h+1);if(t.length&&(a!==i||o!==r)){if(!this.processBunchForSelfIntersectionTest(t))return!1;t.length=0}t.push(h),i=a,r=o}return!!this.processBunchForSelfIntersectionTest(t)}checkSelfIntersectionsPolylinePlanar(){return e(0),!1}checkSelfIntersectionsPolylinePlanar3D(t){return e(0),!1}checkSelfIntersectionsPolygonsOGC(){return e(0),!1}_CheckValidRingOrientation(){const e=null!==this.m_multiPathStitcher?this.m_multiPathStitcher.getImpl():this.m_geometry.getImpl();if(e.calculateArea2D()<=0)return this.m_nonSimpleResult=new Xe(8,1===e.getPathCount()?1:-1,-1),0;if(1===e.getPathCount())return this.m_bOGCRestrictions&&!this.checkSelfIntersectionsPolygonsOGC()?0:4;this.m_pathOrientations=new C(e.getPathCount(),0),this.m_pathParentage=new c(e.getPathCount(),-1);let t=-1,s=0;for(let n=0,h=e.getPathCount();n<h;n++){const i=e.calculateRingArea2D(n);if(this.m_pathOrientations.write(n,i<0?0:8),i>0)t=n,s=i;else{if(0===i)return this.m_nonSimpleResult=new Xe(8,n,-1),0;if((t<0||s<Math.abs(i))&&(this.m_nonSimpleResult=new Xe(9,n,-1),this.m_bOGCRestrictions))return 0;this.m_pathParentage.write(n,t)}}this.m_unknownOrientationPathCount=e.getPathCount(),this.m_newEdges.length=0;const i=e.getPointCount();this.m_yScanline=Number.NaN;const r=[];this.m_xyToNode1=new c(i,_.st_nullNode()),this.m_xyToNode2=new c(i,_.st_nullNode()),this.m_freeEdges.length=0,this.m_AET.clear(),this.m_AET.setComparator(new Ns(this));for(let n=0,h=2*i;this.m_unknownOrientationPathCount>0&&n<h;n++){const e=this.m_pairIndices.read(n),t=this.m_pairs[e];if(1&t)continue;const s=t>>1,i=this.m_xy.read(2*s+1);if(i!==this.m_yScanline&&r.length){if(!this.processBunchForRingOrientationTest(r))return 0;r.length=0}r.push(s),this.m_yScanline=i}return this.m_unknownOrientationPathCount>0&&!this.processBunchForRingOrientationTest(r)?0:this.m_bOGCRestrictions?0!==this.m_nonSimpleResult.m_reason?0:this.checkSelfIntersectionsPolygonsOGC()?5:0:0===this.m_nonSimpleResult.m_reason?4:3}processBunchForSelfIntersectionTest(e){if(1===e.length)return!0;for(let h=0,a=e.length;h<a;h++){const t=e[h];this.m_recycledSegIter.resetToVertex(t,-1);const s=this.m_recycledSegIter.previousSegment();this.m_edges.push(this.createEdge(s,t,this.m_recycledSegIter.getPathIndex(),!0)),this.m_recycledSegIter.nextSegment();const i=this.m_recycledSegIter.nextSegment();this.m_edges.push(this.createEdge(i,t,this.m_recycledSegIter.getPathIndex(),!1))}this.m_edges.sort(((e,t)=>this.edgeAngleCompare(e,t)));let t=this.m_crossOverHelperList.getFirstList();-1===t&&(t=this.m_crossOverHelperList.createList(0)),this.m_crossOverHelperList.reserveNodes(this.m_edges.length);for(let h=0,a=this.m_edges.length;h<a;h++)this.m_crossOverHelperList.addElement(t,h);let s=!0,i=-1,r=-1;for(;s;){s=!1;let e=this.m_crossOverHelperList.getFirst(t);if(-1===e)break;let n=this.m_crossOverHelperList.getNext(e);for(;-1!==n;){const h=this.m_crossOverHelperList.getData(e),a=this.m_crossOverHelperList.getData(n);if(i=this.m_edges[h].m_vertexIndex,r=this.m_edges[a].m_vertexIndex,i!==r)e=n,n=this.m_crossOverHelperList.getNext(e);else if(s=!0,this.m_crossOverHelperList.deleteElement(t,e),e=this.m_crossOverHelperList.getPrev(n),n=this.m_crossOverHelperList.deleteElement(t,n),-1===n||-1===e)break}}const n=this.m_crossOverHelperList.getListSize(t);if(this.m_crossOverHelperList.clear(t),n>0)return this.m_nonSimpleResult=new Xe(7,i,r),!1;for(let h=0,a=e.length;h<a;h++)this.recycleEdge(this.m_edges[h]);return this.m_edges.length=0,!0}processBunchForRingOrientationTest(e){for(let t=0,s=e.length;t<s;t++){const s=e[t];let i=this.m_xyToNode1.read(s);if(i!==_.st_nullNode()){const e=this.m_AET.getElement(i);this.m_freeEdges.push(e),this.m_AET.deleteNode(i),this.recycleEdge(this.m_edges[e]),this.m_edges[e]=null,this.m_xyToNode1.write(s,_.st_nullNode())}if(i=this.m_xyToNode2.read(s),i!==_.st_nullNode()){const e=this.m_AET.getElement(i);this.m_freeEdges.push(e),this.m_AET.deleteNode(i),this.recycleEdge(this.m_edges[e]),this.m_edges[e]=null,this.m_xyToNode2.write(s,_.st_nullNode())}}for(let t=0,s=e.length;t<s;t++){const s=e[t];this.m_recycledSegIter.resetToVertex(s,-1);const i=this.m_recycledSegIter.previousSegment();if(i.getStartY()>i.getEndY()){const e=this.m_recycledSegIter.getStartPointIndex(),t=this.createEdge(i,s,this.m_recycledSegIter.getPathIndex(),!0);let r;this.m_freeEdges.length>0?(r=this.m_freeEdges.at(-1),this.m_freeEdges.pop(),this.m_edges[r]=t):(r=this.m_edges.length,this.m_edges.push(t));const n=this.m_AET.addElement(r);this.m_xyToNode1.read(e)===_.st_nullNode()?this.m_xyToNode1.write(e,n):this.m_xyToNode2.write(e,n),3&this.m_pathOrientations.read(this.m_recycledSegIter.getPathIndex())||this.m_newEdges.push(n)}this.m_recycledSegIter.nextSegment();const r=this.m_recycledSegIter.nextSegment();if(r.getStartY()<r.getEndY()){const e=this.m_recycledSegIter.getEndPointIndex(),t=this.createEdge(r,s,this.m_recycledSegIter.getPathIndex(),!1);let i;this.m_freeEdges.length>0?(i=this.m_freeEdges.at(-1),this.m_freeEdges.pop(),this.m_edges[i]=t):(i=this.m_edges.length,this.m_edges.push(t));const n=this.m_AET.addElement(i);this.m_xyToNode1.read(e)===_.st_nullNode()?this.m_xyToNode1.write(e,n):this.m_xyToNode2.write(e,n),3&this.m_pathOrientations.read(this.m_recycledSegIter.getPathIndex())||this.m_newEdges.push(n)}}for(let t=0,s=this.m_newEdges.length;t<s&&this.m_unknownOrientationPathCount>0;t++){const e=this.m_newEdges[t],s=this.m_AET.getElement(e),i=this.m_edges[s].m_pathIndex;if(!(3&this.m_pathOrientations.read(i))){let t=-1,s=this.m_AET.getPrev(e),i=e,r=0;{let e=-1,n=null,h=-1,a=0;for(;s!==_.st_nullNode()&&(e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex,a=this.m_pathOrientations.read(h),!(3&a));)i=s,s=this.m_AET.getPrev(s);s===_.st_nullNode()?(r=1,s=i):(t=1==(3&a)?h:this.m_pathParentage.read(h),r=n.getRightSide()?0:1,s=this.m_AET.getNext(s))}do{const e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex;let a=this.m_pathOrientations.read(h);if(!(3&a)){if(r!==n.getRightSide())return this.m_nonSimpleResult=new Xe(8,h,-1),!1;const e=r&&!n.getReversed()?1:2;if(a=-4&a|e,this.m_pathOrientations.write(h,a),2===e&&0===this.m_nonSimpleResult.m_reason){const e=this.m_pathParentage.read(h);if(e!==t&&(this.m_nonSimpleResult=new Xe(9,h,e),this.m_bOGCRestrictions))return!1}if(this.m_unknownOrientationPathCount--,!this.m_unknownOrientationPathCount)return!0}t=1==(3&a)?h:this.m_pathParentage.read(h),i=s,s=this.m_AET.getNext(s),r=r?0:1}while(i!==e)}}return this.m_newEdges.length=0,!0}createEdge(e,t,s,r){let n;return e.getGeometryType()===i.enumLine?n=this.createEdgeLine(e):(n=new Ps,n.m_segment=e.clone()),n.m_vertexIndex=t,n.m_pathIndex=s,n.m_flags=0,n.setReversed(r),n}createEdgeLine(e){let t;return this.m_lineEdgesRecycle.length>0?(t=this.m_lineEdgesRecycle.at(-1),this.m_lineEdgesRecycle.pop(),e.copyTo(t.m_segment)):(t=new Ps,t.m_segment=e.clone()),t}recycleEdge(e){e.m_segment.getGeometryType()===i.enumLine&&this.m_lineEdgesRecycle.push(e)}static isShortSegment(e,t,s,i){let r=e.calculateLowerLength2D();if(r<=s){let n=!0;if(e.isCurve()&&(r=e.calculateLength2D(),n=r<=s),n){if(t){let t=e.getEndAttributeAsDbl(1,0);Number.isNaN(t)&&(t=0);let s=e.getStartAttributeAsDbl(1,0);return Number.isNaN(s)&&(s=0),Math.abs(s-t)<=i}return!0}return!1}return!1}static isShortSegmentPoints(t,s,i,r,n){return e(0),!1}removeDegenerateSegmentsFromCurvedPath(t,s,i,r){const n=t.hasAttribute(1),h=t.querySegmentIterator();h.resetToPath(s),e(h.nextPath());const a=this.m_toleranceSimplify.total();let o=!1,m=!0;const g=new P,l=new P,_=new F;for(;h.hasNextSegment();){this.progress_();const e=h.nextSegment();if(vs.isShortSegment(e,n,a,i))o?(e.queryEnd(l),vs.isShortSegmentPoints(g,l,n,a,i),m&&(r.startPathPoint(g),m=!1),e.queryEnd(g),r.lineToPoint(g),o=!1):(_.assign(e.getStartXY()),e.queryStart(g),o=!0);else if(o)if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(_,e.getEndXY(),!1),t.setStart(g),vs.isShortSegment(t,n,a,i))continue;r.addSegment(t,m),m=!1,o=!1}else e.queryEnd(l),vs.isShortSegmentPoints(g,l,n,a,i)||(m&&(r.startPathPoint(g),m=!1),r.lineToPoint(l),o=!1);else r.addSegment(e,m),m=!1}if(m)return;if(!o)return;t.isClosedPath(s)?t.getPointByVal(t.getPathStart(s),g):t.getPointByVal(t.getPathEnd(s)-1,g);const d=r.querySegmentIterator();d.resetToLastPath(),d.resetToLastSegment();const p=r.getDescription().getAttributeCount()>1;for(e(d.previousPath());d.hasPreviousSegment();){const e=d.previousSegment();if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(e.getStartXY(),g.getXY(),!1),!vs.isShortSegment(t,n,a,i)){p&&t.setEnd(g);const e=d.getEndPointIndex();for(let t=r.getPointCount()-1;t>=e;t--)r.removePoint(t);return void r.addSegment(t,!1)}}else if(e.queryStart(l),!vs.isShortSegmentPoints(l,g,n,a,i)){const e=d.getEndPointIndex();for(let t=r.getPointCount()-1;t>=e;t--)r.removePoint(t);return void r.lineToPoint(g)}}r.removePath(r.getPathCount()-1)}multipointIsSimpleAsFeature(){if(!this.checkStructure())return 0;const e=this.m_geometry.getImpl();this.m_multiVertexGeom=e;const t=e.getPointCount(),s=new Array(t);for(let i=0;i<t;i++)s[i]=i;s.sort(((e,t)=>this.compareVerticesMultiPoint(e,t)));for(let i=1;i<t;i++)if(0===this.compareVerticesMultiPoint(s[i-1],s[i]))return this.m_nonSimpleResult=new Xe(5,s[i-1],s[i]),0;return 1}polylineIsSimpleAsFeature(){return this.checkStructure()&&this.checkDegenerateSegments(!0)?1:0}polygonIsSimpleAsFeature(){return this.isSimplePlanarImpl()}multipointSimplifyAsFeature(){let e=this.m_geometry.getImpl();const t=vs.hasNanZs(e);let s,i=this.m_geometry;t&&(s=this.m_geometry.clone(),e=s.getImpl(),s.replaceNaNs(1,y.getDefaultValue(1)),i=s),this.m_multiVertexGeom=e;const r=e.getPointCount(),n=new Array(r);for(let l=0;l<r;l++)n[l]=l;n.sort(((e,t)=>this.compareVerticesMultiPoint(e,t)));const h=new Array(r);h.fill(!1);let a=-1;for(let l=0;l<r;l++){const t=n[l];e.getXY(t).isFinite()&&((a<0||0!==this.compareVerticesMultiPoint(a,t))&&(h[t]=!0),a=t)}const o=this.m_geometry.createInstance();let m=0,g=0;for(let l=0;l<r;l++)h[l]?g=l+1:(m<g&&o.addPoints(i,m,g),m=l+1);return m<g&&o.addPoints(i,m,g),o.getImpl().setIsSimple(1,this.m_toleranceSimplify.total()),o}polylineSimplifyAsFeature(){const e=this.m_geometry.getImpl(),t=e.querySegmentIterator(),s=e.querySegmentIterator(),i=this.m_geometry.createInstance(),r=this.m_geometry,n=e.hasAttribute(1),h=n?E(this.m_sr,e,!0).total():0,a=[],o=[];let m=null;n&&(m=e.getAttributeStreamRef(1));const g=new P,l=e.hasNonLinearSegments(),_=this.m_toleranceSimplify.total();for(;t.nextPath();){if(s.nextPath(),e.getPathSize(t.getPathIndex())<2)continue;if(l&&e.hasNonLinearSegmentsPath(t.getPathIndex())){this.removeDegenerateSegmentsFromCurvedPath(e,t.getPathIndex(),h,i);continue}s.resetToLastSegment();let d=0,p=0,u=!0,c=!0;for(;t.hasNextSegment();){this.progress_();const i=t.nextSegment(),r=s.previousSegment();if(t.getStartPointIndex()>s.getStartPointIndex())break;if(u){const s=t.getStartPointIndex();e.getXY(s).isNAN()||(u=!1,a.push(s))}if(c){const t=s.getEndPointIndex();e.getXY(t).isNAN()||(o.push(t),c=!1)}if(!u){const s=a.at(-1),r=t.getEndPointIndex();if(r-s>1){const t=new F;t.setSub(e.getXY(s),e.getXY(r)),d=t.length()}else d=i.calculateLength2D();if(d>_)a.push(r),d=0;else if(n){let e=m.read(s);Number.isNaN(e)&&(e=0);let t=m.read(r);Number.isNaN(t)&&(t=0),Math.abs(t-e)>h&&(a.push(r),d=0)}}if(!c){const t=o.at(-1),i=s.getStartPointIndex();if(i-t>1){const s=new F;s.setSub(e.getXY(t),e.getXY(i)),p=s.length()}else p=r.calculateLength2D();if(p>_)o.push(i),p=0;else if(n){let e=m.read(t);Number.isNaN(e)&&(e=0);let s=m.read(i);Number.isNaN(s)&&(s=0),Math.abs(s-e)>h&&(o.push(i),p=0)}}}if(a.length>0&&o.length>0&&(a.at(-1)<o.at(-1)?a.length>o.length?a.pop():o.pop():(a.at(-1)===o.at(-1)||o.pop(),o.pop())),o.length+a.length>=2){let e=!1;for(let t=0,s=a.length;t<s;t++)r.getPointByVal(a[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);for(let t=o.length-1;t>0;t--)r.getPointByVal(o[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);r.isClosedPath(t.getPathIndex())?i.closePathWithLine():o.length>0&&(r.getPointByVal(o[0],g),i.lineToPoint(g))}a.length=0,o.length=0}return n&&i.replaceNaNs(1,0),i.getImpl().setIsSimple(1,_),i}polygonSimplifyAsFeature(){return this.simplifyPlanar()}simplifyPlanar(){if(1===this.m_geometry.getFillRule()&&!N(this.m_knownSimpleResult))return Us(this.m_geometry,this.m_toleranceSimplify,!0,!1,this.m_knownSimpleResult,this.m_progressTracker,0,!0);const e=new I;if(e.addGeometry(this.m_geometry),this.m_geometry.hasAttribute(1)&&e.replaceNaNs(1,0),e.removeNaNVertices(),0!==e.getTotalPointCount()){let t=null,s=0,r=0;if(e.hasCurves()){t=new xs;const i=n.constructEmpty();this.m_geometry.queryEnvelope(i);const h=us(this.m_toleranceSimplify.total(),i);s=cs(this.m_toleranceSimplify.total()),r=fs(h,s),ms(e,h,this.m_toleranceSimplify.total(),12e3,t,null,this.m_progressTracker)}if(!N(this.m_knownSimpleResult)){Dt(e,this.m_toleranceSimplify.add(r),this.m_progressTracker,!0,!1)}this.m_geometry.getGeometryType()===i.enumPolygon&&Kt(e,e.getFirstGeometry(),this.m_knownSimpleResult,!1,-1,this.m_progressTracker),null!==t&&t.stitchCurves(e,e.getFirstGeometry(),s,!0)}const t=e.getGeometry(e.getFirstGeometry());return t.getGeometryType()===i.enumPolygon&&(t.getImpl().updateOGCFlagsProtected(),t.setFillRule(0)),t.getImpl().setIsSimple(4,this.m_toleranceSimplify.total()),t}progress_(){}static hasNanZs(e){if(e.hasAttribute(1)){const t=e.getAttributeStreamRef(1);for(let s=0,i=e.getPointCount();s<i;s++){const e=t.read(s);if(Number.isNaN(e))return!0}}return!1}compareVerticesForPlanarClustering(e,t,s){if(e===t)return 0;const i=this.m_pairs[e],r=this.m_pairs[t],n=i>>1,h=r>>1,a=this.m_xy.readPoint2D(2*n);a.y+=1&i?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const o=this.m_xy.readPoint2D(2*h);o.y+=1&r?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const m=a.compare(o);if(0===m&&s){const e=this.m_pathsForOGCTests[n]-this.m_pathsForOGCTests[h];return v(e)}return m}compareVerticesMultiPoint(e,t){if(e===t)return 0;const s=this.m_multiVertexGeom.getXY(e),i=this.m_multiVertexGeom.getXY(t),r=!s.isFinite(),n=!i.isFinite();if(r||n)return r<n?-1:r>n?1:0;if(s.y<i.y)return-1;if(s.y>i.y)return 1;if(s.x<i.x)return-1;if(s.x>i.x)return 1;for(let h=1;h<this.m_attributeCount;h++){const s=this.m_description.getSemantics(h),i=y.getComponentCount(s);for(let r=0;r<i;r++){const i=this.m_multiVertexGeom.getAttributeAsDbl(s,e,r),n=this.m_multiVertexGeom.getAttributeAsDbl(s,t,r),h=b(i,n);if(0!==h)return h}}return 0}edgeAngleCompare(e,t){if(e===t)return 0;const s=e.m_segment.getTangent(e.getReversed()?1:0);e.getReversed()&&s.negateThis();const i=t.m_segment.getTangent(t.getReversed()?1:0);t.getReversed()&&i.negateThis();const r=s.getQuarter(),n=i.getQuarter();if(n===r){const e=s.crossProduct(i);return e<0?1:e>0?-1:0}return r<n?-1:1}}class bs{getOperatorType(){return 10103}accelerateGeometry(e,t,s){return!1}canAccelerateGeometry(e){return!1}supportsCurves(){return!1}isSimpleAsFeature(e,s,i,r,n){const h=Is(e,s,i,r,n);return t(e.getGeometryType(),h)}executeMany(e,t,s,i){return new ws(e,t,s,i)}execute(e,t,s,i){const r=new Ue([e]);return this.executeMany(r,t,s,i).next()}}class ws{constructor(e,t,i,r){this.m_progressTracker=r,this.m_bForceSimplify=i,this.m_index=-1,e||s(""),this.m_inputGeometryCursor=e,this.m_spatialReference=t}next(){const e=this.m_inputGeometryCursor.next();return e?(this.m_index=this.m_inputGeometryCursor.getGeometryID(),this.simplify(e)):null}getGeometryID(){return this.m_index}tock(){return!1}getRank(){return 1}simplify(e){if(e||s(""),e.getGeometryType()===i.enumGeometryCollection){const t=w.generateGeometryCursor(e,-1),s=(new bs).executeMany(t,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker),i=e.createInstance();for(let e=s.next();null!=e;e=s.next())i.addGeometry(e);return i}return Ss(e,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker)}}function Vs(e,t,s,i){s>0&&ht(e,s,t,!1,i);new Ts(i).executeImpl_(e,t)}function Hs(e,t,s){return{vertex0:e,vertex1:t,dir:s}}class Ts{constructor(e){this.m_shape=null,this.m_spikes=[],this.m_points=new c(0),this.m_pointsIndex=-1,this.m_dissolvedEdges=0,this.m_progressTracker=e}executeImpl_(t,s){if(this.m_shape=t,t.getPathCount(s)<2&&t.getPointCount(s)<6)return;this.m_points.resize(0);for(let e=t.getFirstPath(s);e!==H;e=t.getNextPath(e)){let s=t.getFirstVertex(e);for(let i=0,r=t.getPathSize(e);i<r;i++,s=t.getNextVertex(s))this.m_points.add(s)}this.m_pointsIndex=t.createUserIndex();for(let e=0,l=this.m_points.size();e<l;++e)t.setUserIndex(this.m_points.read(e),this.m_pointsIndex,e);t.sortVerticesSimpleByY(this.m_points,0,this.m_points.size());let i=this.m_points.read(0);const r=t.getXY(i);let n=1,h=0;const a=[];for(let e=1;e<this.m_points.size();e++){const s=this.m_points.read(e);if(s===H)continue;if(-1===t.getUserIndex(s,this.m_pointsIndex))continue;const o=t.getXY(s);if(o.isEqualPoint2D(r))n++;else{if(n>1){for(let s=h;s<e;s++){const e=this.m_points.read(s);if(-1===t.getUserIndex(e,this.m_pointsIndex))continue;const i=t.getNextVertex(e),n=t.getPrevVertex(e);if(e!==i&&!t.isEqualXYPoint2D(i,r)){const t=Hs(e,i,1);a.push(t)}if(e!==n&&n!==i&&!t.isEqualXYPoint2D(n,r)){const t=Hs(e,n,-1);a.push(t)}}a.length>0&&this.processBunch_(a,r)}i=s,r.assign(o),n=1,h=e}}if(0===this.m_dissolvedEdges)return t.removeUserIndex(this.m_pointsIndex),void(this.m_pointsIndex=-1);let o=t.getPointCount(s);for(let e=0;e<this.m_points.size();e++){const s=this.m_points.read(e);if(s===H)continue;if(-1!==t.getUserIndex(s,this.m_pointsIndex)){t.setUserIndex(s,this.m_pointsIndex,-1);continue}const i=t.getPathFromVertex(s);t.getFirstVertex(i)===s&&t.setFirstVertex(i,H),t.freeVertex(s),this.m_points.write(e,H),o--}const m=t.createPathUserIndex();let g=t.getPathCount(s);for(let l=0,_=this.m_points.size();l<_;++l){if(this.m_points.read(l)===H)continue;let i=this.m_points.read(l);if(-1!==t.getUserIndex(i,this.m_pointsIndex))continue;let r=t.getPathFromVertex(i),n=-1;if(2===t.getPathUserIndex(r,m)){r=H;for(let e=t.getNextVertex(i);e!==i;e=t.getNextVertex(e)){const s=t.getPathFromVertex(e);if(2!==t.getPathUserIndex(s,m)){r=s,i=e;break}}r===H&&(r=t.insertPath(s,H),t.setClosedPath(r,!0),g++),e(r!==H)}t.setPathUserIndex(r,m,2),n=t.getFirstVertex(r);let h=0,a=!1,o=i;do{n===o&&(a=!0),t.setUserIndex(o,this.m_pointsIndex,1);const e=t.getPathFromVertex(o);e!==r&&(2!==t.getPathUserIndex(e,m)&&(t.setPathUserIndex(e,m,1),t.setFirstVertex(e,H)),t.setPathToVertex(o,r)),h++,o=t.getNextVertex(o)}while(o!==i);a||t.setFirstVertex(r,i),t.setPathSize(r,h)}for(let e=t.getFirstPath(s);e!==H;){const s=t.getNextPath(e);1!==t.getPathUserIndex(e,m)&&t.getFirstVertex(e)!==H||(t.removePathOnly(e),g--),e=s}t.setGeometryVertexCount(s,o),t.setGeometryPathCount(s,g),t.removePathUserIndex(m),t.removeUserIndex(this.m_pointsIndex),this.m_pointsIndex=-1,t.dbgVerifyVertexCounts(),t.filterClosePoints(0,!0,!1,!1,s)}processBunch_(e,t){e.sort(((e,s)=>{const i=this.m_shape.getXY(e.vertex1).sub(t),r=this.m_shape.getXY(s.vertex1).sub(t),n=F.compareVectors(i,r);return 0===n?e.dir<s.dir?-1:1:n}));let s=0;const i=this.m_shape.getXY(e[0].vertex1);let r=1;const n=this.m_shape.hasCurves();for(let h=1,a=e.length;h<a;h++){const t=this.m_shape.getXY(e[h].vertex1);if(!(t.isEqualPoint2D(i)&&(r++,h+1<a))){if(2===r){const t=e[s],i=e[s+1],r=t.dir;if(r!==i.dir){let e=!0;if(n&&(e=!this.m_shape.isCurve(1===t.dir?t.vertex0:t.vertex1)&&!this.m_shape.isCurve(1===i.dir?i.vertex0:i.vertex1)),e){if(1===r){const e=t.vertex0,s=i.vertex0;this.m_shape.setNextVertex(e,s),this.m_shape.setPrevVertex(s,e),this.m_shape.getPrevVertex(e)===s&&(this.m_shape.setUserIndex(e,this.m_pointsIndex,-1),this.m_shape.setUserIndex(s,this.m_pointsIndex,-1));const r=t.vertex1,n=i.vertex1;this.m_shape.setPrevVertex(r,n),this.m_shape.setNextVertex(n,r),this.m_shape.getNextVertex(r)===n&&(this.m_shape.setUserIndex(r,this.m_pointsIndex,-1),this.m_shape.setUserIndex(n,this.m_pointsIndex,-1))}else{const e=t.vertex0,s=i.vertex0;this.m_shape.setPrevVertex(e,s),this.m_shape.setNextVertex(s,e),this.m_shape.getNextVertex(e)===s&&(this.m_shape.setUserIndex(e,this.m_pointsIndex,-1),this.m_shape.setUserIndex(s,this.m_pointsIndex,-1));const r=t.vertex1,n=i.vertex1;this.m_shape.setNextVertex(r,n),this.m_shape.setPrevVertex(n,r),this.m_shape.getPrevVertex(r)===n&&(this.m_shape.setUserIndex(r,this.m_pointsIndex,-1),this.m_shape.setUserIndex(n,this.m_pointsIndex,-1))}this.m_dissolvedEdges+=2}}}i.assign(t),s=h,r=1}}e.length=0}}var ks=u,Fs=h,Gs=B;function Bs(t){switch(t){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 0:return 0;default:e(0,"unrecognized cut side")}return 3}function Ds(){return{unsplitBehavior:0,allCrossRoadsImpassable:!1,ogcRule:!1}}function As(t,s,i,r,n,h,a){return e(0),{}}function Us(e,t,s,i,r,n,h,a){return new Qs(n).planarSimplifyImpl_(e,t,s,i,r,n,h,a)}function Os(t,s,i,r){return e(0),{}}function Ys(t,s,i,r,n,h,a){return e(0),{}}function Xs(t,s,i,r){return e(0),{}}function qs(e,t,s){return Zs(e,t,s)}function Rs(t,s,i){return e(0),{}}function Ms(e,t,s,r){const h=n.constructEmpty();e.queryEnvelope(h);const a=n.constructEmpty();t.queryEnvelope(a);const o=n.constructEmpty();o.setCoords({env2D:h}),o.mergeEnvelope2D(a);const m=T(s,o,!0),g=new n(a),l=d(m);if(g.inflateCoords(l,l),!h.isIntersecting(g)){if(e.getDimension()<=t.getDimension())return js(Js(e.createInstance()),e,t,"&");if(e.getDimension()>t.getDimension())return js(Js(t.createInstance()),e,t,"&")}const _=new Qs(r),p=new I,u=p.addGeometry(Js(e)),c=p.addGeometry(Js(t));let f=0,x=0,E=null;if(p.hasCurves()){E=new xs;const e=p.getEnvelope2D(r);x=cs(m.total());const t=us(m.total(),e);f=fs(t,x),ms(p,t,m.total(),12e3,E,null,r)}_.setEditShapeCrackAndCluster(p,m.add(f));const S=_.intersection(u,c);null!==E&&E.stitchCurves(p,S,x,!0);const C=js(p.getGeometry(S),e,t,"&");return ks(C.getGeometryType())&&(C.getImpl().setIsSimple(4,m.total()),C.getGeometryType()===i.enumPolygon&&C.getImpl().updateOGCFlagsProtected()),C}function Ls(e,t,s,r){const h=new Array(3),a=n.constructEmpty();e.queryEnvelope(a);const o=n.constructEmpty();t.queryEnvelope(o);const m=n.constructEmpty();m.setCoords({env2D:a}),m.mergeEnvelope2D(o);const g=T(s,m,!0),l=new n(o),_=d(g);if(l.inflateCoords(_,_),!a.isIntersecting(l)){if(e.getDimension()<=t.getDimension()){const s=js(Js(e.createInstance()),e,t,"&");return h[s.getDimension()]=s,h}if(e.getDimension()>t.getDimension()){const s=js(Js(t.createInstance()),e,t,"&");return h[s.getDimension()]=s,h}}const p=new Qs(r),u=new I,c=u.addGeometry(Js(e)),f=u.addGeometry(Js(t));let x=0,E=0,S=null;if(u.hasCurves()){S=new xs;const e=u.getEnvelope2D(r);E=cs(g.total());const t=us(g.total(),e);x=fs(t,E),ms(u,t,g.total(),12e3,S,null,r)}p.setEditShapeCrackAndCluster(u,g.add(x)),u.dbgVerifyCurves();const C=p.intersectionEx(c,f);for(const n of C){null!==S&&S.stitchCurves(u,n,E,!1);const s=js(u.getGeometry(n),e,t,"&");ks(s.getGeometryType())&&(s.getImpl().setIsSimple(4,g.total()),s.getGeometryType()===i.enumPolygon&&s.getImpl().updateOGCFlagsProtected()),h[s.getDimension()]=s}return null!==S&&S.clearStitcher(u),h}function zs(e,t,i,r,n,h=!1){0===t&&s("not enough geometries to dissolve");let a=0;for(let s=0,u=t;s<u;s++)a=Math.max(e[s].getDimension(),a);if(2===a||1===a)return new Qs(r).dissolveMultiPaths_(a,!1,e,t,i,n,h);let o=0,m=-1;for(let s=0,u=t;s<u;s++)e[s].getDimension()===a&&(-1===m&&(m=s),e[s].isEmpty()||(m=s,o++));if(o<2)return Js(e[m]);const g=V.constructEmpty(),l=new I;let _=H;for(let s=0,u=t;s<u;s++)if(e[s].getDimension()===a&&!e[s].isEmpty()){_===H?_=l.addGeometry(Js(e[s])):l.appendGeometry(_,Js(e[s]));const t=V.constructEmpty();e[s].queryLooseEnvelope(t),g.mergeEnv3D(t)}const d=T(i,g.getEnvelope2D(),!0),p=new Qs(r);if(h){const e=k(i,g.getEnvelopeZs(),!0);return p.planarSimplify3DImpl_(l,d,e,0,!0)}return p.m_bOGCOutput=!0,p.planarSimplifyMultiPoints(l,d,!1,-1)}function Ws(e,t,i,r,n,h=!1){t<2&&s("not enough geometries to dissolve");let a=0;for(let s=0,c=t;s<c;s++)a=Math.max(e[s].getDimension(),a);if(2===a||1===a)return new Qs(r).dissolveMultiPaths_(a,!0,e,t,i,n,h);const o=V.constructEmpty(),m=new I;let g=H,l=0,_=-1;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===a&&(-1===_&&(_=s),!e[s].isEmpty())){_=s,g===H?g=m.addGeometry(Js(e[s])):m.appendGeometry(g,Js(e[s]));const t=V.constructEmpty();e[s].queryLooseEnvelope(t),o.mergeEnv3D(t),l++}if(l<2)return Js(e[_]);const d=0===a?i:null,p=T(d,o.getEnvelope2D(),!0),u=new Qs(r);if(h){const e=k(d,o.getEnvelopeZs(),!0);return u.m_bOGCOutput=!0,u.planarSimplify3DImpl_(m,p,e,0,!0)}return u.planarSimplifyMultiPoints(m,p,!0,-1)}class Qs{constructor(e){this.m_topoGraph=null,this.m_maskLookup=[],this.m_dummyPt1=F.getNAN(),this.m_dummyPt2=F.getNAN(),this.m_fromEdgeForPolylines=H,this.m_progressCounter=0,this.m_bOGCOutput=!1,this.m_progressTracker=e}setEditShape(e,t=!1){null===this.m_topoGraph&&(this.m_topoGraph=new $e),this.m_topoGraph.setEditShape(e,this.m_progressTracker,!0,t)}setEditShapeCrackAndCluster(e,t){Dt(e,t,this.m_progressTracker,!0,!1);for(let s=e.getFirstGeometry();s!==H;s=e.getNextGeometry(s))e.getGeometryType(s)===i.enumPolygon&&Kt(e,s,-1,this.m_bOGCOutput,H,this.m_progressTracker);this.setEditShape(e)}setHalfEdgeOrientations_(e,t){const s=this.m_topoGraph.getShape();for(let i=s.getFirstGeometry();i!==H;i=s.getNextGeometry(i))if(i===t)for(let t=s.getFirstPath(i);t!==H;t=s.getNextPath(t)){let i=s.getFirstVertex(t);if(i===H)continue;let r=s.getNextVertex(i);for(;r!==H;){const t=this.m_topoGraph.getClusterFromVertex(i),n=this.m_topoGraph.getClusterFromVertex(r),h=this.m_topoGraph.getHalfEdgeConnector(t,n);if(h!==H){const t=this.m_topoGraph.getHalfEdgeTwin(h);this.m_topoGraph.setHalfEdgeUserIndex(h,e,1),this.m_topoGraph.setHalfEdgeUserIndex(t,e,2)}i=r,r=s.getNextVertex(i)}}}flushVertices_(e,t){const s=this.m_topoGraph.getShape(),i=s.hasSegmentParentage(),r=new G,n=s.insertPath(e,H);t.push(t[0]);const h=t.length;let a=H;for(let o=0;o<h;o++){const e=t[o];if(a=s.addVertex(n,e),!i)continue;const m=this.m_topoGraph.getClusterFromVertex(e);if(o>0&&this.m_topoGraph.isBreakNode(m)&&s.setSegmentParentageBreakVertex(a,!0),o<h-1){const e=this.m_topoGraph.getHalfEdgeConnector(m,this.m_topoGraph.getClusterFromVertex(t[o+1])),i=this.m_topoGraph.getSegmentParentage(e);s.setSegmentParentageAndBreak(a,i,o>0||this.m_topoGraph.isBreakNode(m)),this.m_topoGraph.isHalfEdgeCurve(e)&&(this.m_topoGraph.querySegmentXY(e,r),s.setSegmentToIndex(s.getVertexIndex(a),r.get().clone()))}}if(i){const e=this.m_topoGraph.getClusterFromVertex(t[h-1]);this.m_topoGraph.isBreakNode(e)&&s.setSegmentParentageBreakVertex(a,!0)}s.setClosedPath(n,!0)}processPolygonCuts_(e,t,s,r){const n=this.m_topoGraph.getGeometryID(s),h=this.m_topoGraph.getGeometryID(r),a=[],o=this.m_topoGraph.getShape(),m=this.m_topoGraph.createUserIndexForHalfEdges();for(let g=this.m_topoGraph.getFirstCluster();g!==H;g=this.m_topoGraph.getNextCluster(g)){const s=this.m_topoGraph.getClusterHalfEdge(g);if(s===H)continue;let r=s;do{if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,m)){let s=r,g=r,l=!1,_=0;do{if(this.m_topoGraph.setHalfEdgeUserIndex(s,m,1),!l){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){this.m_topoGraph.getHalfEdgeFaceParentage(s)&n&&(g=s,l=!0)}}if(l){const t=this.m_topoGraph.getHalfEdgeOrigin(s),i=this.m_topoGraph.getClusterVertexIterator(t),r=this.m_topoGraph.getVertexFromVertexIterator(i);if(a.push(r),-1!==e){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){_|=this.m_topoGraph.getHalfEdgeUserIndex(s,e)}}}s=this.m_topoGraph.getHalfEdgeNext(s)}while(s!==g);if(l&&this.m_topoGraph.getChainArea(this.m_topoGraph.getHalfEdgeChain(g))>0){const e=o.createGeometry(i.enumPolygon);this.flushVertices_(e,a),-1!==t&&o.setGeometryUserIndex(e,t,_)}a.length=0}r=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(r))}while(r!==s)}this.m_topoGraph.deleteUserIndexForHalfEdges(m)}cutPolygonPolyline_(e,t,s,i){this.m_topoGraph.removeSpikes_();let r=-1;-1!==e&&(r=this.m_topoGraph.createUserIndexForHalfEdges(),this.setHalfEdgeOrientations_(r,s)),this.processPolygonCuts_(r,e,t,s),-1!==r&&(this.m_topoGraph.deleteUserIndexForHalfEdges(r),r=-1);const n=this.m_topoGraph.getShape();for(let h=n.getFirstGeometry();h!==H;h=n.getNextGeometry(h))h!==t&&h!==s&&i.push(h);i.sort(((e,t)=>{const s=n.getFirstPath(e),i=n.getRingArea(s),r=n.getFirstPath(t),h=n.getRingArea(r);return i<h?-1:i>h?1:0}))}cut(e,t,s,i,r){const n=this.m_topoGraph.getShape().getGeometryType(s),h=this.m_topoGraph.getShape().getGeometryType(i),a=B(n),m=B(h);if(2!==a||1!==m)if(1!==a||1!==m)o("");else{new $s(this,e,t,s,i,r).Do()}else this.cutPolygonPolyline_(t,s,i,r)}progress_(e=!1){}isGoodParentage(e){return e>=0&&e<this.m_maskLookup.length&&this.m_maskLookup[e]}normalizeInputGeometry(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(h(t)){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}return t!==i.enumMultiPoint&&t!==i.enumPolyline&&t!==i.enumPolygon&&s("Unexpected geometry type"),e}dissolveNonSimplePolygons(t,s,i,r){e(s>0);const n=new I;let h=0,a=-1;for(let e=0,o=s;e<o;e++)2===t[e].getDimension()&&(-1===a&&(a=e),t[e].isEmpty()||(h++,n.addGeometry(t[e])));return 0===h?(e(a>=0),this.normalizeInputGeometry(t[a])):this.planarSimplifyPolygons(n,i,!0,!1,-1,!0)}dissolveMultiPaths_(t,s,r,o,m,l,_){e(t>=1&&t<=2),e(o>0);const p=8&l?1:2,c=V.constructEmpty();let f=0,x=-1,E=!0;for(let e=0,n=o;e<n;e++)if(r[e].getDimension()===t&&(-1===x&&(x=e),!r[e].isEmpty())){x=e,f++;const s=V.constructEmpty();if(r[e].queryLooseEnvelope(s),c.mergeEnv3D(s),2===t&&E&&r[e].getGeometryType()===i.enumPolygon)if(16&l){const t=[0],s=r[e].getImpl().getIsSimple(0,t),i=this.m_bOGCOutput?5===s:g(s);E&&=i}else{const t=U(r[e],0);E&&=t}}if(f<2&&(e(x>=0),0===f||!(16&l)))return this.normalizeInputGeometry(r[x]);if(!E){const e=T(s?null:m,c.getEnvelope2D(),!0);return this.dissolveNonSimplePolygons(r,o,e,l)}const S=r.slice(0,o),C=T(m,c.getEnvelope2D(),!0),P=10*d(C);let y=new pe(0,0);if(_&&(y=k(m,c.getEnvelopeZs(),!0)),1===f&&1===t&&2===p&&!s)return _?Ys(r[0],C,y,this.m_progressTracker,p,!0,this.m_bOGCOutput):this.m_bOGCOutput?As(S[x],C,!1,-1,this.m_progressTracker):Us(S[x],C,!1,!1,-1,this.m_progressTracker,p,!1);const v=new O;v.startConstruction();let b=2===t?3:4,w=0;for(let a=0,d=o;a<d;a++){if(S[a].getDimension()!==t||S[a].isEmpty())continue;let r=S[a].getGeometryType();if(r!==i.enumEnvelope){if(h(r)?(S[a]=this.normalizeInputGeometry(S[a]),r=i.enumPolyline):e(u(r)),1===t){e(r===i.enumPolyline);let t=-1;if(_)e(0,"3d not implemented yet");else{const e=[0];t=S[a].getImpl().getIsSimple(C.total(),e)}if(this.m_bOGCOutput?5!==t:!g(t))if(s)b=-1;else{_?e(0,"3d not implemented yet"):this.m_bOGCOutput?S[a]=As(S[a],C,!1,-1,this.m_progressTracker):S[a]=Us(S[a],C,!1,!1,-1,this.m_progressTracker,p,!1);const t=[0];e(g(S[a].getImpl().getIsSimple(C.total(),t)))}}else{e(r===i.enumPolygon);const t=[0],s=S[a].getImpl().getIsSimple(0,t);e(N(s))}const o=S[a].getImpl();for(let e=0,t=o.getPathCount();e<t;e++){const t=n.constructEmpty();o.queryLoosePathEnvelope(e,t),t.inflateCoords(P,P),v.addEnvelope(w,t),w++}}else{e(r===i.enumEnvelope);const t=n.constructEmpty();S[a].queryLooseEnvelope(t),t.inflateCoords(P,P),v.addEnvelope(w,t),w++,b=-1}}v.endConstruction();const F=w,G=Y(F,-2147483647),B=Y(F,-1);let A=0;x=-1,w=0;for(let n=0,h=o;n<h;n++){if(S[n].getDimension()!==t)continue;if(-1===x&&(x=n),S[n].isEmpty())continue;x=n,A++;const s=S[n].getGeometryType();if(u(s)){for(let e=0,t=S[n].getPathCount();e<t;e++)B[w]=n,G[w]=-e-1,w++}else e(s===i.enumEnvelope),B[w]=n,G[w]=-1,w++}if(A<2&&2===t)return e(x>=0),this.normalizeInputGeometry(S[x]);let q=F;for(;v.next()&&q>0;){this.progress_();const e=v.getHandleA(),t=v.getHandleB(),s=v.getElement(e),i=v.getElement(t);B[s]!==B[i]&&(G[s]<0&&(q--,G[s]=-(G[s]+1)),G[i]<0&&(q--,G[i]=-(G[i]+1)))}const R=new I;let M=!1,L=0;for(let n=0,h=o;n<h;n++){if(S[n].getDimension()!==t||S[n].isEmpty())continue;const s=S[n].getGeometryType(),r=L;let h=0,o=0;const m=u(s)?S[n]:null;for(let e=r,t=G.length;e<t&&B[e]===n;e++)G[e]>=0&&(h++,o+=m?m.getPathSize(G[e]):X(S[n])),L++;if(o>.95*X(S[n])){R.addGeometry(this.normalizeInputGeometry(S[n]));for(let e=r;e<L;e++)G[e]<0&&(G[e]=-(G[e]+1))}else{if(0===h){M=!0;continue}{M=!0,e(u(s)),e(null!=m);const t=new D({vd:S[n].getDescription()}),h=new a({vd:S[n].getDescription()}),o=s===i.enumPolygon?t:h;for(let e=r;e<L;e++)G[e]>=0&&o.addPath(m,G[e],!0);R.addGeometry(o)}}}let z;if(R.getFirstGeometry()!==H){const e=2===t,i=s?T(null,c.getEnvelope2D(),!0):C;let r=new pe(0,0);if(_&&(r=s?k(null,c.getEnvelopeZs(),!0):y),2===t&&!(2&l)){R.collapseAllGeometriesToFirst();let e=0,t=null;if(R.hasCurves()&&!R.hasSegmentParentage()){t=new xs;const s=R.getEnvelope2D(this.m_progressTracker);e=cs(i.total());ms(R,us(i.total(),s),i.total(),12e3,t,null,this.m_progressTracker)}Vs(R,R.getFirstGeometry(),i.total(),this.m_progressTracker),null!==t&&t.stitchCurves(R,H,e,!0)}if(_)z=this.planarSimplify3DImpl_(R,i,r,p,!0);else if(2===t)z=this.planarSimplifyPolygons(R,i,e,s,-1,!1);else{const e=Ds();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=p,z=this.planarSimplifyPolylines(R,i,s,e,-1)}if(!M){const e=[0];b=z.getImpl().getIsSimple(i.total(),e)}}else e(M),e(x>=0),z=2===t?new D({vd:S[x].getDescription()}):new a({vd:S[x].getDescription()});if(M){let t=0;for(let e=0,s=G.length;e<s;e++){const s=B[e];if(!(s<0)&&G[e]<0){const i=S[s].getGeometryType(),r=u(i)?S[s]:null;if(r){const s=-(G[e]+1);t+=r.getPathSize(s)}else t+=4}}z.reserve(z.getPointCount()+t);for(let s=0,r=G.length;s<r;s++){const t=B[s];if(!(t<0)&&G[s]<0){const r=S[t].getGeometryType(),n=u(r)?S[t]:null;if(n){const e=-(G[s]+1);z.addPath(n,e,!0)}else r===i.enumEnvelope?z.addEnvelope(S[t],!1):(e(h(r)),z.addSegment(S[t],!0))}}}let W=0;if(2===t?-1!==b&&(b=3,W=s?0:C.total()):(e(1===t),s||-1===b||(W=C.total())),_||z.getImpl().setIsSimple(b,W),!s&&M)if(2===t){if(!_)return(new bs).execute(z,m,!1,this.m_progressTracker);e(0,"3d not yet implemented")}else 1===t&&1!==p&&(z=_?Xs(this.m_bOGCOutput,z,p,this.m_progressTracker):Os(this.m_bOGCOutput,z,p,this.m_progressTracker),z.getImpl().setIsSimple(b,W));return z}dissolveTopoGraphCommonEdges_(){const e=this.m_topoGraph.createUserIndexForHalfEdges(),t=[];for(let s=this.m_topoGraph.getFirstCluster();s!==H;s=this.m_topoGraph.getNextCluster(s)){const i=this.m_topoGraph.getClusterHalfEdge(s);let r=i;if(i!==H)do{this.progress_();if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,e)){const s=this.m_topoGraph.getHalfEdgeTwin(r);this.m_topoGraph.setHalfEdgeUserIndex(s,e,1),this.m_topoGraph.setHalfEdgeUserIndex(r,e,1);const i=this.m_topoGraph.getHalfEdgeFaceParentage(r);if(this.isGoodParentage(i)){const e=this.m_topoGraph.getHalfEdgeFaceParentage(s);this.isGoodParentage(e)&&t.push(r)}}r=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(r))}while(r!==i)}this.m_topoGraph.deleteUserIndexForHalfEdges(e),this.m_topoGraph.deleteEdgesBreakFaces_(t)}chooseVertexByOrder(t,s,i,r){let n=fe(),h=H;for(let e=this.m_topoGraph.getClusterVertexIterator(t);e!==H;e=this.m_topoGraph.incrementVertexIterator(e)){const t=this.m_topoGraph.getVertexFromVertexIterator(e),r=s.getUserIndex(t,i);r>=0&&r<n&&(n=r,h=t)}e(h!==H);let a=s.getUserIndex(h,r);return a>0&&(s.setUserIndex(h,r,--a),0===a&&s.setUserIndex(h,i,-1)),h}chooseVertexFromCluster_(e,t){return this.m_topoGraph.getVertexDominantFromCluster(e,t)}chooseVertexFromVertexCluster_(e,t){return this.m_topoGraph.getVertexDominant(e,t)}collectPolygonPathsPreservingFrom_(e,t,s,r,n){const h=this.m_topoGraph.getShape();if(h.getGeometryType(e)!==i.enumPolygon)return;const a=h.hasSegmentParentage(),o=new G;for(let i=h.getFirstPath(e);i!==H;i=h.getNextPath(i)){const e=h.getFirstVertex(i);this.m_topoGraph.getClusterFromVertex(e);const m=this.m_topoGraph.getHalfEdgeFromVertex(e);if(m===H)continue;const g=this.m_topoGraph.getHalfEdgeUserIndex(m,s);if(1===g||2===g)continue;const l=this.m_topoGraph.getHalfEdgeFaceParentage(m);if(!this.isGoodParentage(l)){this.m_topoGraph.setHalfEdgeUserIndex(m,s,2);continue}this.m_topoGraph.setHalfEdgeUserIndex(m,s,1);const _=h.insertPath(t,H);h.setClosedPath(_,!0);let d=m,p=e,u=this.m_topoGraph.getClusterFromVertex(p),c=1;do{this.progress_();const e=this.chooseVertexFromVertexCluster_(p,n),t=h.addVertex(_,e);if(this.m_topoGraph.isHalfEdgeCurve(d)&&(this.m_topoGraph.querySegmentXY(d,o),h.setSegmentToIndex(h.getVertexIndex(t),o.get().clone())),a){const e=this.m_topoGraph.getSegmentParentage(d);h.setSegmentParentageAndBreak(t,e,this.m_topoGraph.isBreakNode(u))}let i,m;-1!==r&&this.m_topoGraph.setClusterUserIndex(u,r,1),this.m_topoGraph.setHalfEdgeUserIndex(d,s,1),d=this.m_topoGraph.getHalfEdgeNext(d);do{i=1===c?h.getNextVertex(p):h.getPrevVertex(p),m=i!==H?this.m_topoGraph.getClusterFromVertex(i):H}while(m===u);const g=this.m_topoGraph.getHalfEdgeOrigin(d);if(g!==m){do{i=1===c?h.getPrevVertex(p):h.getNextVertex(p),m=i!==H?this.m_topoGraph.getClusterFromVertex(i):H}while(m===u);if(g!==m){m=g;const e=this.m_topoGraph.getClusterVertexIterator(m);i=this.m_topoGraph.getVertexFromVertexIterator(e)}else c=-c}u=m,p=i}while(d!==m)}}topoOperationPolygonPolygonHelper_(e,t,s,i,r,n){this.progress_(!0),e!==H&&this.collectPolygonPathsPreservingFrom_(e,s,r,n,i),t!==H&&this.collectPolygonPathsPreservingFrom_(t,s,r,n,i);const h=new G,a=this.m_topoGraph.getShape();a.dbgVerifyCurves();const o=a.hasSegmentParentage();for(let m=this.m_topoGraph.getFirstCluster();m!==H;m=this.m_topoGraph.getNextCluster(m)){const e=this.m_topoGraph.getClusterHalfEdge(m);if(e===H)continue;let t=e;do{this.progress_();const e=this.m_topoGraph.getHalfEdgeUserIndex(t,r);if(1!==e&&2!==e){const e=this.m_topoGraph.getHalfEdgeFaceParentage(t);if(this.isGoodParentage(e)){const e=a.insertPath(s,H);a.setClosedPath(e,!0);let m=t;do{const t=this.m_topoGraph.getHalfEdgeVertexIterator(m);let s=H;if(t!==H)s=this.m_topoGraph.getVertexFromVertexIterator(t);else{const e=this.m_topoGraph.getHalfEdgeVertexIterator(this.m_topoGraph.getHalfEdgeTwin(m));s=this.m_topoGraph.getVertexFromVertexIterator(e),s=a.getNextVertex(s)}const g=this.chooseVertexFromVertexCluster_(s,i),l=a.addVertex(e,g);if(o){const e=this.m_topoGraph.getSegmentParentage(m),t=this.m_topoGraph.getHalfEdgeOrigin(m);a.setSegmentParentageAndBreak(l,e,this.m_topoGraph.isBreakNode(t))}if(this.m_topoGraph.isHalfEdgeCurve(m)&&(this.m_topoGraph.querySegmentXY(m,h),a.setSegmentToIndex(a.getVertexIndex(l),h.get().clone())),this.m_topoGraph.setHalfEdgeUserIndex(m,r,1),-1!==n){const e=this.m_topoGraph.getClusterFromVertex(g);this.m_topoGraph.setClusterUserIndex(e,n,1)}m=this.m_topoGraph.getHalfEdgeNext(m)}while(m!==t)}else this.m_topoGraph.setHalfEdgeUserIndex(t,r,2)}t=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(t))}while(t!==e)}}topoOperationPolygonPolygon_(e,t,s,r=!1){this.dissolveTopoGraphCommonEdges_();const n=this.m_topoGraph.getShape(),h=n.createGeometry(i.enumPolygon),a=this.m_topoGraph.createUserIndexForHalfEdges();return this.topoOperationPolygonPolygonHelper_(e,t,h,s,a,-1),this.m_topoGraph.deleteUserIndexForHalfEdges(a),r||Kt(n,h,3,this.m_bOGCOutput,H,this.m_progressTracker),h}topoOperationPolyline_(e,t){const s=Ds();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(H,e,!1,s).first}topoOperationMultiPoint_(){return e(0),0}intersection(t,s){const i=this.m_topoGraph.getShape().getGeometryType(t),r=this.m_topoGraph.getShape().getGeometryType(s),n=B(i),h=B(r),a=this.m_topoGraph.getGeometryID(t),m=this.m_topoGraph.getGeometryID(s);e(a>=0),e(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=H;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=t),2===n&&2===h?this.topoOperationPolygonPolygon_(t,s,g):1===n&&h>0||1===h&&n>0?this.topoOperationPolyline_(g,this.m_bOGCOutput):0===n||0===h?this.topoOperationMultiPoint_():void o("")}topoOperationPolygonPolygonEx(e,t,s){const r=this.m_topoGraph.getShape(),n=r.createGeometry(i.enumPolygon),h=r.createGeometry(i.enumPolyline),a=r.createGeometry(i.enumMultiPoint);this.dissolveTopoGraphCommonEdges_();let o=H;const m=this.m_topoGraph.createUserIndexForHalfEdges(),g=this.m_topoGraph.createUserIndexForClusters();r.dbgVerifyCurves(),this.topoOperationPolygonPolygonHelper_(e,t,n,s,m,g),r.dbgVerifyCurves();const l=r.hasSegmentParentage(),_=new G;for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){const e=this.m_topoGraph.getClusterHalfEdge(i);if(e===H)continue;let t=e;do{let e=this.m_topoGraph.getHalfEdgeUserIndex(t,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m),a=e|n;if(2===a){let o=this.m_topoGraph.getHalfEdgeParentage(t);if(this.isGoodParentage(o)){const d=r.insertPath(h,H);let p=t;const u=this.chooseVertexFromCluster_(i,s);let c=r.addVertex(d,u);if(l){const e=this.m_topoGraph.getSegmentParentage(t),s=this.m_topoGraph.getHalfEdgeOrigin(t);r.setSegmentParentageAndBreak(c,e,this.m_topoGraph.isBreakNode(s))}this.m_topoGraph.isHalfEdgeCurve(t)&&(this.m_topoGraph.querySegmentXY(t,_),r.setSegmentToIndex(r.getVertexIndex(c),_.get().clone())),this.m_topoGraph.setClusterUserIndex(i,g,1);do{this.progress_();const i=this.m_topoGraph.getHalfEdgeTo(p),h=this.chooseVertexFromCluster_(i,s);if(c=r.addVertex(d,h),l){const e=this.m_topoGraph.getSegmentParentage(t),s=this.m_topoGraph.getHalfEdgeOrigin(t);r.setSegmentParentageAndBreak(c,e,this.m_topoGraph.isBreakNode(s))}if(this.m_topoGraph.setHalfEdgeUserIndex(p,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m,1),this.m_topoGraph.setClusterUserIndex(i,g,1),p=this.m_topoGraph.getHalfEdgeNext(p),e=this.m_topoGraph.getHalfEdgeUserIndex(p,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m),a=e|n,2!==a)break;if(o=this.m_topoGraph.getHalfEdgeParentage(p),!this.isGoodParentage(o)){this.m_topoGraph.setHalfEdgeUserIndex(p,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(p),m,1);break}this.m_topoGraph.isHalfEdgeCurve(t)&&p!==t&&(this.m_topoGraph.querySegmentXY(t,_),r.setSegmentToIndex(r.getVertexIndex(c),_.get().clone()))}while(p!==t)}else this.m_topoGraph.setHalfEdgeUserIndex(t,m,1),this.m_topoGraph.setHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m,1)}t=this.m_topoGraph.getHalfEdgeNext(this.m_topoGraph.getHalfEdgeTwin(t))}while(t!==e)}for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){this.progress_();if(1===this.m_topoGraph.getClusterUserIndex(i,g))continue;const e=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(e)){o===H&&(o=r.insertPath(a,H));const e=this.m_topoGraph.getClusterVertexIterator(i);let t=H;if(e!==H){t=this.m_topoGraph.getVertexFromVertexIterator(e);const i=this.chooseVertexFromVertexCluster_(t,s);r.addVertex(o,i)}}}this.m_topoGraph.deleteUserIndexForClusters(g),this.m_topoGraph.deleteUserIndexForHalfEdges(m),r.dbgVerifyCurves(),Kt(r,n,3,this.m_bOGCOutput,H,this.m_progressTracker);const d=[H,H,H];return d[0]=a,d[1]=h,d[2]=n,d}topoOperationPolylinePolylineOrPolygonEx(e,t){const s=Ds();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(H,e,!0,s)}topoOperationMultiPoint(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,H);for(let i=this.m_topoGraph.getFirstCluster();i!==H;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=H;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==H;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===H&&(t=i);const r=e.getGeometryFromPath(e.getPathFromVertex(i)),n=this.m_topoGraph.getGeometryID(r);if(this.isGoodParentage(n)){t=i;break}}e.addVertex(s,t)}}return t}intersectionEx(t,s){const i=this.m_topoGraph.getShape().getGeometryType(t),r=this.m_topoGraph.getShape().getGeometryType(s),n=Gs(i),h=Gs(r),a=this.m_topoGraph.getGeometryID(t),m=this.m_topoGraph.getGeometryID(s);e(a>=0),e(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=H;if(this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=t),2===n&&2===h)return this.topoOperationPolygonPolygonEx(t,s,g);if(1===n&&h>0||1===h&&n>0){const{first:e,second:t}=this.topoOperationPolylinePolylineOrPolygonEx(g,this.m_bOGCOutput);return[t,e]}if(0===n||0===h){const e=[];return e.push(this.topoOperationMultiPoint()),e}o("")}getCombinedHalfEdgeParentage(e){return this.m_topoGraph.getHalfEdgeParentage(e)|this.m_topoGraph.getHalfEdgeFaceParentage(e)|this.m_topoGraph.getHalfEdgeFaceParentage(this.m_topoGraph.getHalfEdgeTwin(e))}prevailingDirection(e,t){const s=this.getCombinedHalfEdgeParentage(t),i=this.m_topoGraph.getHalfEdgeOrigin(t),r=this.m_topoGraph.getHalfEdgeTo(t);let n=0,h=0;for(let a=this.m_topoGraph.getClusterVertexIterator(i);a!==H;a=this.m_topoGraph.incrementVertexIterator(a)){const i=this.m_topoGraph.getVertexFromVertexIterator(a),o=e.getPathFromVertex(i),m=e.getGeometryFromPath(o),g=this.m_topoGraph.getGeometryID(m),l=e.getFirstVertex(o),_=!!(g&s);_&&l===i&&(this.m_fromEdgeForPolylines=t);const d=e.getNextVertex(i);if(d!==H&&this.m_topoGraph.getClusterFromVertex(d)===r){if(n++,_){if(this.m_fromEdgeForPolylines===H&&l===d){const e=this.m_topoGraph.getHalfEdgeNext(t);this.isGoodParentage(this.getCombinedHalfEdgeParentage(e))&&(this.m_fromEdgeForPolylines=e)}h++}}else{const s=e.getPrevVertex(i);if(s!==H&&this.m_topoGraph.getClusterFromVertex(s)===r&&(n--,_)){if(this.m_fromEdgeForPolylines===H&&l===s){const e=this.m_topoGraph.getHalfEdgeNext(t);this.isGoodParentage(this.getCombinedHalfEdgeParentage(e))&&(this.m_fromEdgeForPolylines=e)}h--}}}this.m_topoGraph.queryXY(i,this.m_dummyPt1),this.m_topoGraph.queryXY(r,this.m_dummyPt2);return(0!==h?h:n)*F.distance(this.m_dummyPt1,this.m_dummyPt2)}tryMoveThroughCrossroadBackwards(e,t){const s=this.m_topoGraph.getHalfEdgePrev(e),i=this.m_topoGraph.getHalfEdgeTwin(s);if(!t){if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e)))return H;const t=this.m_topoGraph.getHalfEdgeTwin(e);if(i===this.m_topoGraph.getHalfEdgeNext(t))return s}let r=i,n=H;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==H)return H;n=this.m_topoGraph.getHalfEdgeTwin(r)}r=this.m_topoGraph.getHalfEdgeTwin(this.m_topoGraph.getHalfEdgePrev(r))}return n}tryMoveThroughCrossroadForward(e,t){const s=this.m_topoGraph.getHalfEdgeNext(e),i=this.m_topoGraph.getHalfEdgeTwin(s);if(!t){const t=this.m_topoGraph.getHalfEdgeTwin(e);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(t)))return H;if(i===this.m_topoGraph.getHalfEdgePrev(t))return s}let r=i,n=H;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==H)return H;n=this.m_topoGraph.getHalfEdgeTwin(r)}r=this.m_topoGraph.getHalfEdgeTwin(this.m_topoGraph.getHalfEdgeNext(r))}return n}isOnALoop(e,t){let s=e;const i=2*this.m_topoGraph.getShape().getTotalPointCount()+10;for(let r=0;r<i;r++){if(1===this.m_topoGraph.getHalfEdgeUserIndex(s,t))return!1;const i=this.m_topoGraph.getHalfEdgeNext(s);if(i===this.m_topoGraph.getHalfEdgeTwin(s))return!1;if(s=i,s===e)return!0}o("is_on_a_loop_")}restorePolylineParts(t,s,i,r,n,h,a,o,m,g){e(n===H&&h>=0&&a>=0||-1===h&&-1===a),e(-1===o&&1!==g.unsplitBehavior||-1!==o&&1===g.unsplitBehavior);const l=g.ogcRule,_=g.allCrossRoadsImpassable,d=1===g.unsplitBehavior,p=0===g.unsplitBehavior;g.unsplitBehavior;const u=this.m_topoGraph.getShape(),c=u.hasSegmentParentage();let f=t,x=this.m_topoGraph.getHalfEdgeTwin(f);const E=new G;this.m_fromEdgeForPolylines=H;let I=this.prevailingDirection(u,f),S=f,C=H,P=!1,y=!1,N=!1;if(!d)for(;;){const e=this.m_topoGraph.getHalfEdgePrev(f);if(e===x){N=!0;break}const s=this.m_topoGraph.getHalfEdgeNext(x);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(s))){P=!0;break}if(this.m_topoGraph.getHalfEdgeTwin(e)!==s){if(_){P=!0;break}if(f=this.tryMoveThroughCrossroadBackwards(f,!0),f===H){P=!0;break}x=this.m_topoGraph.getHalfEdgeTwin(f)}else f=e,x=s;if(1===this.m_topoGraph.getHalfEdgeUserIndex(f,i)){N=!0;break}if(f===t){C=t,y=!0;break}const r=this.getCombinedHalfEdgeParentage(f);if(!this.isGoodParentage(r))break;S=f,I+=this.prevailingDirection(u,f)}if(C===H){for(f=t,x=this.m_topoGraph.getHalfEdgeTwin(f),C=f;;){const e=this.m_topoGraph.getHalfEdgeNext(f),t=this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e));if(t){P=!0;break}if(e===x){N=!0;break}if(-1!==o){const e=this.m_topoGraph.getHalfEdgeOrigin(x);if(1===this.m_topoGraph.getClusterUserIndex(e,o)){P=!0;break}}const s=this.m_topoGraph.getHalfEdgePrev(x);if(this.m_topoGraph.getHalfEdgeTwin(e)!==s){if(t||_){P=!0;break}if(f=this.tryMoveThroughCrossroadForward(f,!0),f===H){P=!0;break}x=this.m_topoGraph.getHalfEdgeTwin(f)}else f=e,x=s;if(1===this.m_topoGraph.getHalfEdgeUserIndex(f,i)){N=!0;break}const r=this.getCombinedHalfEdgeParentage(f);if(!this.isGoodParentage(r))break;C=f,I+=this.prevailingDirection(u,f)}const e=this.m_topoGraph.getHalfEdgeOrigin(S);y=this.m_topoGraph.getHalfEdgeTo(C)===e}else if(this.m_fromEdgeForPolylines!==H){S=t,C=this.tryMoveThroughCrossroadBackwards(S,!1),e(C!==H);const s=this.m_topoGraph.getHalfEdgeTwin(S);this.m_topoGraph.getHalfEdgeNext(s)}let v=y;y||N||m&&(v=this.isOnALoop(t,i),v||(v=this.isOnALoop(x,i)));const b=I>=0;let w=!1;v&&P&&(y?(w=l,b&&(w||d||p)&&S!==t&&(e(!d),S=t,w=!1)):(d||b&&p)&&(S=t));let V=0;for(f=S;x=this.m_topoGraph.getHalfEdgeTwin(f),this.m_topoGraph.setHalfEdgeUserIndex(f,i,1),this.m_topoGraph.setHalfEdgeUserIndex(x,i,1),V++,f!==C;)f=_?this.m_topoGraph.getHalfEdgeNext(f):this.tryMoveThroughCrossroadForward(f,!1);b||(C=q(S,S=C),C=this.m_topoGraph.getHalfEdgeTwin(C),S=this.m_topoGraph.getHalfEdgeTwin(S));let T=u.insertPath(s,H);f=S;const k=this.m_topoGraph.getHalfEdgeOrigin(S);let F;F=-1!==h?this.chooseVertexByOrder(k,u,h,a):this.chooseVertexFromCluster_(k,n),this.m_topoGraph.isStrongPathNode(k)&&u.setStrongPathStart(T,!0);let B=u.addVertex(T,F),D=B;-1!==r&&this.m_topoGraph.setClusterUserIndex(k,r,1);let A=0;const U=w?(V+1)/2:-1;let O=H,Y=!0,X=H;for(;;){if(c){const e=this.m_topoGraph.getSegmentParentage(f),t=this.m_topoGraph.getHalfEdgeOrigin(f);u.setSegmentParentageAndBreak(D,e,Y||this.m_topoGraph.isBreakNode(t))}Y=!1,this.m_topoGraph.isHalfEdgeCurve(f)&&(this.m_topoGraph.querySegmentXY(f,E),u.setSegmentToIndex(u.getVertexIndex(D),E.get().clone())),O!==H&&-1!==a&&u.addToUserIndex(O,a,-1);const e=_?this.m_topoGraph.getHalfEdgeNext(f):this.tryMoveThroughCrossroadForward(f,!1),t=this.m_topoGraph.getHalfEdgeTo(f);let i;if(i=-1!==h?this.chooseVertexByOrder(t,u,h,a):this.chooseVertexFromCluster_(t,n),B=u.addVertex(T,i),X=t,-1!==r&&this.m_topoGraph.setClusterUserIndex(t,r,1),c&&this.m_topoGraph.isBreakNode(t)&&u.setSegmentParentageBreakVertex(B,!0),O=i,A++,w&&A===U&&(T=u.insertPath(s,H),B=u.addVertex(T,i),Y=!0,-1!==a&&u.addToUserIndex(i,a,-1),O=H),f===C)break;f=e,D=B}X!==H&&this.m_topoGraph.isStrongPathNode(X)&&u.setStrongPathEnd(T,!0)}topoOperationPolylineSimplify_(e,t){return this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}topoOperationPolylineSimplifyOrPolylineTopoHelper_(t,s,r,n){e(s===H||t===H);const h=this.m_topoGraph.getShape(),a=e=>e=t===H?e===H?h.getFirstGeometry():h.getNextGeometry(e):e===H?t:H,o=h.createGeometry(i.enumPolyline);let m=-1;r&&(m=this.m_topoGraph.createUserIndexForClusters());const g=this.m_topoGraph.createUserIndexForHalfEdges(),l=s===H?h.createUserIndex():-1,_=s===H?h.createUserIndex():-1;let d=-1;if(1===n.unsplitBehavior){d=this.m_topoGraph.createUserIndexForClusters();for(let e=a(H);e!==H;e=a(e))for(let t=h.getFirstPath(e);t!==H;t=h.getNextPath(t)){{const e=h.getFirstVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,d,1)}if(!h.isClosedPath(t)){const e=h.getLastVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,d,1)}}}if(s===H){let e=0;for(let t=a(H);t!==H;t=a(t))for(let s=h.getFirstPath(t);s!==H;s=h.getNextPath(s)){if(h.isClosedPath(s)){let t=h.getFirstVertex(s);for(let i=0,r=h.getPathSize(s);i<r;i++,t=h.getNextVertex(t))h.setUserIndex(t,l,e++),h.setUserIndex(t,_,2)}else{const t=h.getFirstVertex(s);h.setUserIndex(t,l,e++),h.setUserIndex(t,_,1);let i=h.getNextVertex(t);for(let r=1,n=h.getPathSize(s)-1;r<n;++r)h.setUserIndex(i,l,e++),h.setUserIndex(i,_,2),i=h.getNextVertex(i);h.setUserIndex(i,l,e++),h.setUserIndex(i,_,1)}}}for(let e=a(H);e!==H;e=a(e))for(let t=h.getFirstPath(e);t!==H;t=h.getNextPath(t)){let e=h.getFirstVertex(t);for(let i=0,r=h.getPathSize(t);i<r;i++,e=h.getNextVertex(e)){const t=this.m_topoGraph.getHalfEdgeFromVertex(e);if(t===H)continue;if(1===this.m_topoGraph.getHalfEdgeUserIndex(t,g))continue;const r=this.getCombinedHalfEdgeParentage(t);if(this.isGoodParentage(r)){const e=0===i;this.restorePolylineParts(t,o,g,m,s,l,_,d,e,n)}}}let p=H;if(r){p=h.createGeometry(i.enumMultiPoint);let e=H;for(let t=this.m_topoGraph.getFirstCluster();t!==H;t=this.m_topoGraph.getNextCluster(t)){this.progress_();if(1!==this.m_topoGraph.getClusterUserIndex(t,m)){const i=this.m_topoGraph.getClusterParentage(t);if(this.isGoodParentage(i)){e===H&&(e=h.insertPath(p,H));const i=this.m_topoGraph.getClusterVertexIterator(t);if(i!==H){let r;this.m_topoGraph.getVertexFromVertexIterator(i),r=-1!==l?this.chooseVertexByOrder(t,h,l,_):this.chooseVertexFromCluster_(t,s),h.addVertex(e,r)}}}}}return-1!==_&&h.removeUserIndex(_),-1!==l&&h.removeUserIndex(l),-1!==m&&h.removeUserIndex(m),this.m_topoGraph.deleteUserIndexForHalfEdges(g),R(o,p)}difference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=B(s),n=B(i);if(r>n)return e;const h=this.m_topoGraph.getGeometryID(e),a=this.m_topoGraph.getGeometryID(t);if(this.m_maskLookup.length=0,this.m_maskLookup.length=1+(h|a),this.m_maskLookup[h]=!0,2===r&&2===n){let s=H;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(s=e),this.topoOperationPolygonPolygon_(e,t,s)}if(1===r&&2===n){const t=Ds();return t.allCrossRoadsImpassable=!1,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}if(1===r&&1===n){const t=Ds();return t.allCrossRoadsImpassable=!0,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,H,!1,t).first}if(0===r)return this.topoOperationMultiPoint_();o("")}planarSimplifyNoCrackingAndCluster(t,s,i,r){return e(0),!1}unsplitPolylineExact(t){return e(0),new a}planarSimplifyPolylines(t,s,r,n,h){for(let p=t.getFirstGeometry();p!==H;p=t.getNextGeometry(p)){const s=t.getGeometryType(p);e(s===i.enumPolyline)}let a=0,o=0,m=null;if(t.hasCurves()&&!t.hasSegmentParentage()){m=new xs;const e=t.getEnvelope2D(this.m_progressTracker);o=cs(s.total());const i=us(s.total(),e);a=fs(i,o),ms(t,i,s.total(),12e3,m,null,this.m_progressTracker)}{const e=Ut(s.add(a));t.filterClosePoints(e,!1,!1,!1,H)}if(this.m_topoGraph=new $e,4!==h&&5!==h)if(null===m&&r){const e=new vt(this.m_progressTracker,!1);e.sweepVertical(t,s.total()),e.hadComplications()?(Dt(t,s,this.m_progressTracker,!0,!1),r=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(s.total())}else Dt(t,s.add(a),this.m_progressTracker,!0,!1),r=!1;else r=!1;t.removeSelection(),t.collapseAllGeometriesToFirst();const g=t.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,g,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(r&&null===m),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolylines(t,s,!1,n,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const l=this.m_topoGraph.getGeometryID(g);e(l>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=l+1,this.m_maskLookup[l]=!0;const _=this.topoOperationPolylineSimplify_(t.getFirstGeometry(),n);null!==m&&m.stitchCurves(t,_,o,!0);const d=t.getGeometry(_);return r||d.getImpl().setIsSimple(4,s.total()),d}planarSimplifyMultiPoints(t,s,r,n){for(let g=t.getFirstGeometry();g!==H;g=t.getNextGeometry(g)){const s=t.getGeometryType(g);e(s===i.enumMultiPoint)}this.m_topoGraph=new $e,4!==n&&5!==n?(Dt(t,s,this.m_progressTracker,!0,!1),r=!1):r=!1,t.removeSelection(),t.collapseAllGeometriesToFirst();const h=t.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,h,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(r),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyMultiPoints(t,s,!1,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const a=this.m_topoGraph.getGeometryID(h);e(a>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=a+1,this.m_maskLookup[a]=!0;const o=this.topoOperationMultiPoint(),m=t.getGeometry(o);return r||m.getImpl().setIsSimple(4,s.total()),m}planarSimplifyPolygons(t,s,r,n,h,a){for(let f=t.getFirstGeometry();f!==H;f=t.getNextGeometry(f)){const s=t.getGeometryType(f);e(s===i.enumPolygon||s===i.enumPolyline&&r)}let o=0,m=0,g=null;if(t.hasCurves()&&!t.hasSegmentParentage()){g=new xs;const e=t.getEnvelope2D(this.m_progressTracker);m=cs(s.total());const i=us(s.total(),e);o=fs(i,m),ms(t,i,s.total(),12e3,g,null,this.m_progressTracker)}if(a){Dt(t,s.add(o),this.m_progressTracker,!0,!1);for(let e=t.getFirstGeometry();e!==H;e=t.getNextGeometry(e))t.getGeometryType(e)===i.enumPolygon&&Kt(t,e,-1,!1,H,this.m_progressTracker)}if(this.m_topoGraph=new $e,a||4===h||5===h)n=!1;else if(null===g&&n){const e=new vt(this.m_progressTracker,!1);e.sweepVertical(t,s.total()),e.hadComplications()?(Dt(t,s,this.m_progressTracker,!0,!1),n=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(s.total())}else Dt(t,s.add(o),this.m_progressTracker,!0,!1),n=!1;t.removeSelection(),t.collapseAllGeometriesToFirst();const l=t.getFirstGeometry();if(r?this.m_topoGraph.setAndSimplifyEditShapeWinding(t,l,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,l,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return e(n&&null===g),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolygons(t,s,r,!1,-1,!1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const _=this.m_topoGraph.getGeometryID(l);e(_>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=_+1,this.m_maskLookup[_]=!0,t.setFillRule(l,0);const d=this.m_bOGCOutput&&r,p=d;let u=this.topoOperationPolygonPolygon_(l,H,H,p);if(d){this.m_topoGraph.removeShape(),this.m_topoGraph=null,t.removeGeometry(l),this.m_topoGraph=new $e,this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,u,this.m_progressTracker);u=this.topoOperationPolygonPolygon_(u,H,H,!1)}null!==g&&g.stitchCurves(t,u,m,!0);const c=t.getGeometry(u);return c.setFillRule(0),n?c.getImpl().setIsSimple(3,0):(c.getImpl().setIsSimple(4,s.total()),c.getImpl().updateOGCFlagsProtected()),c}planarSimplify3DImpl_(t,s,i,r,n){return e(0),{}}planarSimplifyImpl_(e,t,s,r,n,h,m,g){if(e.isEmpty())return e.clone();const l=e.getGeometryType(),_=new I,d=_.addGeometry(e);if(N(n)&&l===i.enumPolygon&&(s=!1,_.setFillRule(d,0)),g&&(e.hasAttribute(1)&&_.replaceNaNs(1,0),_.removeNaNVertices()),l===i.enumPolygon||l===i.enumPolyline&&s)return this.planarSimplifyPolygons(_,t,s,r,n,!1);if(l===a.type){const e=Ds();return e.allCrossRoadsImpassable=!0,e.ogcRule=this.m_bOGCOutput,e.unsplitBehavior=m,this.planarSimplifyPolylines(_,t,r,e,n)}if(l===i.enumMultiPoint)return this.planarSimplifyMultiPoints(_,t,r,n);o("what else?")}}function Zs(e,t,s,i){const r=e.createInstance(),n=he(F,100),h=new Array(100),a=e.getPointCount();let m=!0;const g=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&o("");for(let o=0;o<a;){const i=e.queryCoordinates(n,n.length,o,-1)-o;g?is(t,n,i,s.total(),h):rs(t,n,i,s.total());let a=0;for(let t=0;t<i;t++){0===h[t]&&(m&&(m=!1,r.addPoints(e,0,o)),a!==t&&r.addPoints(e,o+a,o+t),a=t+1)}m||a===i||r.addPoints(e,o+a,o+i),o+=i}return m?e:r}function js(e,t,s,r){const n=e.getGeometryType();if(n===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(n===i.enumPoint&&"^"===r){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(n===i.enumLine){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}if(n===i.enumMultiPoint&&"-"===r&&t.getGeometryType()===i.enumPoint){const t=new P({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}if(n===i.enumMultiPoint&&"&"===r&&t.getGeometryType()===i.enumPoint){const t=new P({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}return e}function Js(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new D({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new A({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(Fs(t)){const t=new a({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}return t!==i.enumMultiPoint&&t!==i.enumPolyline&&t!==i.enumPolygon&&s("Unexpected geometry type"),e}function Ks(t,s,i,r){const n=i===H?t.getClusterHalfEdge(s):i;let h=n;e(t.getHalfEdgeOrigin(n)===s);do{r(h),h=t.getHalfEdgeNext(t.getHalfEdgeTwin(h))}while(h!==n)}class $s{constructor(e,t,s,i,r,n){this.m_rParent=e,this.m_rTopoGraph=e.m_topoGraph,this.m_rShape=this.m_rTopoGraph.getShape(),this.m_IDCuttee=this.m_rTopoGraph.getGeometryID(i),this.m_IDCutter=this.m_rTopoGraph.getGeometryID(r),this.m_IDBoth=this.m_IDCuttee|this.m_IDCutter,this.m_bConsiderTouch=t,this.m_sideIndex=s,this.m_cuttee=i,this.m_cutter=r,this.m_rCutHandles=n,this.m_cutteeBreadcrumbsIndex=this.m_rShape.createUserIndexUninitialized(),this.m_clusterParentageIndex=this.m_rShape.createUserIndexUninitialized();for(let h=this.m_rShape.getFirstPath(this.m_cuttee);h!==H;h=this.m_rShape.getNextPath(h)){let e=0;const t=this.m_rShape.getPathSize(h);for(let s=this.m_rShape.getFirstVertex(h);e<t;e++,s=this.m_rShape.getNextVertex(s))this.m_rShape.setUserIndex(s,this.m_clusterParentageIndex,this.m_rTopoGraph.getClusterParentage(this.m_rTopoGraph.getClusterFromVertex(s)))}}Do(){this.cutPolylinePolyline_(),this.m_rShape.removeUserIndex(this.m_cutteeBreadcrumbsIndex),this.m_rShape.removeUserIndex(this.m_clusterParentageIndex)}setTbd(e){return 8|e}classifyStandardCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),a=n===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),o=this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));let g=1,l=32,_=32;if(Ks(this.m_rTopoGraph,t,m,(e=>{e===o&&(g=2),e===h&&(l=g),e===a&&(_=g)})),this.m_bConsiderTouch)32!==l&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),32!==_&&this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|_);else{if(32===l||32===_)return 1;if(l===_&&!(h===o||h===m||a===o||a===m))return 1;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|_)}return 0}classifyTouchCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),a=n===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),o=s===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=i===H?H:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));if(!this.m_bConsiderTouch){let t;return(t=o===h||m===h)?this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))):(t=o===a||m===a)&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),t?0:1}if(h===H)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===H)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;if(h===a)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(m!==H){if(h===m)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===m)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=1;Ks(this.m_rTopoGraph,t,m,(t=>{if(t===h){const e=this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,e),s=2}else if(t===a){const t=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,t),s=2}}))}else{if(h===o)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(a===o)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=2;Ks(this.m_rTopoGraph,t,o,(t=>{if(t===h){const e=this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,e),s=1}else if(t===a){const t=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|s;this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,t),s=1}}))}return 0}classifyCutVertex(e,t){let s=0,i=0;for(let r=this.m_rTopoGraph.getClusterVertexIterator(t);r!==H;r=this.m_rTopoGraph.incrementVertexIterator(r)){const n=this.m_rTopoGraph.getVertexFromVertexIterator(r);if(this.m_rShape.getGeometryFromVertex(n)===this.m_cutter){i++;const r=this.m_rShape.getPrevVertex(n),h=this.m_rShape.getNextVertex(n);s+=r===H||h===H?this.classifyTouchCut(e,t,r,h):this.classifyStandardCut(e,t,r,h)}}i&&s===i&&!this.m_bConsiderTouch&&this.m_rShape.setUserIndex(e,this.m_clusterParentageIndex,this.m_IDCuttee)}cutPolylinePolyline_(){this.m_rShape.getGeometryType(this.m_cuttee),this.m_rShape.getGeometryType(this.m_cutter),this.m_rParent.m_maskLookup.length=0,this.m_rParent.m_maskLookup.length=this.m_IDBoth+1,this.m_rParent.m_maskLookup[this.m_IDBoth]=!0;for(let i=this.m_rShape.getFirstPath(this.m_cuttee);i!==H;i=this.m_rShape.getNextPath(i)){const e=this.m_rShape.getPathSize(i);let t=this.m_rShape.getFirstVertex(i);for(let s=0;s<e;++s,t=this.m_rShape.getNextVertex(t))this.m_rShape.setUserIndex(t,this.m_cutteeBreadcrumbsIndex,0);t=this.m_rShape.getFirstVertex(i);for(let s=0;s<e;++s,t=this.m_rShape.getNextVertex(t)){const e=this.m_rTopoGraph.getClusterFromVertex(t);this.m_rTopoGraph.getClusterParentage(e)===this.m_IDBoth&&this.classifyCutVertex(t,e)}}const e=(e,t)=>{let s=this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex);const i=this.m_rTopoGraph.getHalfEdgeConnector(this.m_rTopoGraph.getClusterFromVertex(e),this.m_rTopoGraph.getClusterFromVertex(t));return(this.m_rTopoGraph.getHalfEdgeParentage(i)&this.m_IDBoth)===this.m_IDBoth&&(s|=4),s};for(let i=this.m_rShape.getFirstPath(this.m_cuttee);i!==H;i=this.m_rShape.getNextPath(i)){let t=this.m_rShape.getFirstVertex(i);const s=this.m_rShape.isClosedPath(i),r=this.m_rShape.getPathSize(i)+(s?1:0);let n=1,h=32;for(let i=this.m_rShape.getNextVertex(t);n<r;++n,t=i,i=this.m_rShape.getNextVertex(i)){const s=e(t,i);this.m_rShape.getUserIndex(t,this.m_clusterParentageIndex)===this.m_IDBoth&&(h=s),32!==h&&this.m_rShape.setUserIndex(t,this.m_cutteeBreadcrumbsIndex,h|s)}t=this.m_rShape.getLastVertex(i);let a=32;n=1;for(let i=this.m_rShape.getPrevVertex(t);n<r;++n,t=i,i=this.m_rShape.getPrevVertex(i)){const s=e(i,t);this.m_rShape.getUserIndex(t,this.m_clusterParentageIndex)===this.m_IDBoth&&(a=s),32!==a&&this.m_rShape.setUserIndex(i,this.m_cutteeBreadcrumbsIndex,a|s)}}let t=H,s=H,r=32;const n=this.m_rShape.hasSegmentParentage(),h=new G;for(let a=this.m_rShape.getFirstPath(this.m_cuttee);a!==H;a=this.m_rShape.getNextPath(a)){const e=this.m_rShape.isClosedPath(a),o=this.m_rShape.getPathSize(a)+(e?1:0);let m=1,g=this.m_rShape.getFirstVertex(a),l=H,_=!0;for(let a=this.m_rShape.getNextVertex(g);m<o;++m,a=this.m_rShape.getNextVertex(a)){let e=this.m_rShape.getUserIndex(g,this.m_cutteeBreadcrumbsIndex);8===e?e=3:(e&=-9,4&e?e=4:3&~e||(e=3)),e!==r?(t!==H&&(l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),this.m_rCutHandles.push(t),this.m_rShape.setGeometryUserIndex(t,this.m_sideIndex,r)),t=this.m_rShape.createGeometry(i.enumPolyline),s=this.m_rShape.insertPath(t,H),r=e,_=!0):this.m_rShape.getUserIndex(g,this.m_clusterParentageIndex)===this.m_IDBoth&&4!==e&&(l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),s=this.m_rShape.insertPath(t,H),_=!0),l=this.m_rShape.addVertex(s,g);const o=this.m_rTopoGraph.getClusterFromVertex(g);!_&&n&&this.m_rTopoGraph.isBreakNode(o)&&this.m_rShape.setSegmentParentageBreakVertex(l,!0);const m=this.m_rTopoGraph.getHalfEdgeFromVertex(g);if(n){const e=this.m_rTopoGraph.getSegmentParentage(m);this.m_rShape.setSegmentParentageAndBreak(l,e,_||this.m_rTopoGraph.isBreakNode(o))}this.m_rTopoGraph.isHalfEdgeCurve(m)&&(this.m_rTopoGraph.querySegmentXY(m,h),this.m_rShape.setSegmentToIndex(this.m_rShape.getVertexIndex(l),h.get().clone())),g=a,_=!1}l=this.m_rShape.addVertex(s,g),n&&this.m_rTopoGraph.isBreakNode(this.m_rTopoGraph.getClusterFromVertex(g))&&this.m_rShape.setSegmentParentageBreakVertex(l,!0),this.m_rCutHandles.push(t),this.m_rShape.setGeometryUserIndex(t,this.m_sideIndex,r),t=H,s=H,r=32}}}export{xs as C,bs as O,$e as T,Kt as a,ms as b,es as c,us as d,Dt as e,fs as f,Ht as g,Bs as h,ts as i,Qs as j,Ms as k,Ls as l,qs as m,Rs as n,zs as o,Ws as p,Tt as q,cs as s};