@arcgis/core 4.32.0-next.20250102 → 4.32.0-next.20250103

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 (261) hide show
  1. package/Color.js +1 -1
  2. package/PopupTemplate.js +1 -1
  3. package/arcade/functions/date.js +1 -1
  4. package/arcade/functions/featuresetbase.js +1 -1
  5. package/arcade/functions/featuresetstats.js +1 -1
  6. package/arcade/functions/featuresetstring.js +1 -1
  7. package/arcade/functions/geomasync.js +1 -1
  8. package/arcade/functions/geometry.js +1 -1
  9. package/arcade/functions/geomsync.js +1 -1
  10. package/arcade/functions/knowledgegraph.js +1 -1
  11. package/arcade/functions/string.js +1 -1
  12. package/arcade/geometry/extendedUnitData.js +5 -0
  13. package/arcade/geometry/functions.js +5 -0
  14. package/arcade/geometry/operators.js +5 -0
  15. package/arcade/geometry/unitConversion.js +5 -0
  16. package/arcade/geometry/wkt.js +5 -0
  17. package/arcade/languageUtils.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/{e371f4f0eb3c22f222df.js → 005727711cca0614c2ab.js} +2 -2
  20. package/assets/esri/core/workers/chunks/{e371f4f0eb3c22f222df.js.LICENSE.txt → 005727711cca0614c2ab.js.LICENSE.txt} +1 -1
  21. package/assets/esri/core/workers/chunks/{2d908c115ea18e813b95.js → 00c0fbe19c12691cf2c3.js} +1 -1
  22. package/assets/esri/core/workers/chunks/08e28328385066c519c2.js +1 -0
  23. package/assets/esri/core/workers/chunks/{0e735d01296d340b393e.js → 0b95ec12218f3c04df18.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{59bf879b4802a5ba431e.js → 0ee669947c23f469e357.js} +1 -1
  25. package/assets/esri/core/workers/chunks/116103ecec27cce47a2f.js +1 -0
  26. package/assets/esri/core/workers/chunks/11f00218905f0db447ff.js +1 -0
  27. package/assets/esri/core/workers/chunks/14b87f3dd9942e6b19d0.js +1 -0
  28. package/assets/esri/core/workers/chunks/16d7c07e1c11b88dae84.js +1 -0
  29. package/assets/esri/core/workers/chunks/1d04fe800cb98e4d6bc4.js +1 -0
  30. package/assets/esri/core/workers/chunks/{71f6e5742cf0c482066b.js → 1dc6b5b177022b80c473.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{59455e2dd44b4c01cc76.js → 2586741c359057b3f626.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{250a810dd4e1ff293564.js → 318a39b56851e707edad.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{b1e4813f0c73fc2a483c.js → 370b230fd2d7703d0698.js} +2 -2
  34. package/assets/esri/core/workers/chunks/{b1e4813f0c73fc2a483c.js.LICENSE.txt → 370b230fd2d7703d0698.js.LICENSE.txt} +1 -1
  35. package/assets/esri/core/workers/chunks/38d03fe352057fb375b5.js +1 -0
  36. package/assets/esri/core/workers/chunks/{ebf9caf2dc8af89afec2.js → 42aa697b4718b75b8cb2.js} +2 -2
  37. package/assets/esri/core/workers/chunks/{ebf9caf2dc8af89afec2.js.LICENSE.txt → 42aa697b4718b75b8cb2.js.LICENSE.txt} +1 -1
  38. package/assets/esri/core/workers/chunks/{801dbea20966806db1c9.js → 53cd990b2c988518de6d.js} +1 -1
  39. package/assets/esri/core/workers/chunks/5a1eb0d1e25ff5574c43.js +1 -0
  40. package/assets/esri/core/workers/chunks/6157c49e7431f5868c77.js +1 -0
  41. package/assets/esri/core/workers/chunks/{eef2d94a73064f9bc085.js → 61d64f163840563017d5.js} +1 -1
  42. package/assets/esri/core/workers/chunks/6d218fb5e0f0a04d72c5.js +2 -0
  43. package/assets/esri/core/workers/chunks/{d82b3e2905cab511ff3a.js.LICENSE.txt → 6d218fb5e0f0a04d72c5.js.LICENSE.txt} +1 -1
  44. package/assets/esri/core/workers/chunks/6ed57d01be6bc054c7cd.js +1 -0
  45. package/assets/esri/core/workers/chunks/7254956381e823219db0.js +1 -0
  46. package/assets/esri/core/workers/chunks/740e6bdb3b76f2ea6d61.js +1 -0
  47. package/assets/esri/core/workers/chunks/756c2f7c8659deab6c96.js.LICENSE.txt +1 -1
  48. package/assets/esri/core/workers/chunks/{56fc353421252f2d0a99.js → 75e8ba7e02647b7216ae.js} +1 -1
  49. package/assets/esri/core/workers/chunks/89d7eec47e5b29935d92.js +1 -0
  50. package/assets/esri/core/workers/chunks/8cd2c9ec1e541836b81c.js +1 -0
  51. package/assets/esri/core/workers/chunks/{0b3e1e903120da297641.js → 932375de79e3d33bc4d7.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{263adfd1c2641ef5c0f5.js → 95f23bd17ce9e07fc8ef.js} +1 -1
  53. package/assets/esri/core/workers/chunks/{7de9c01849c4aa1940e7.js → 986889cea53c4a470347.js} +1 -1
  54. package/assets/esri/core/workers/chunks/{cc6160e8ab3cea4040c2.js → 9e9b2fd958e816b1b5f6.js} +1 -1
  55. package/assets/esri/core/workers/chunks/a57cead317eb2fc9afd8.js +1 -0
  56. package/assets/esri/core/workers/chunks/acec58a7f23b2cc938ee.js +1 -0
  57. package/assets/esri/core/workers/chunks/b0f4254d8a32dd713009.js +1 -0
  58. package/assets/esri/core/workers/chunks/b277b8c2f556918e4f9a.js +1 -0
  59. package/assets/esri/core/workers/chunks/{deffd56e39ce725ce377.js → b30046a40bcfbec8abe4.js} +1 -1
  60. package/assets/esri/core/workers/chunks/{5c11e2e65b97565e5003.js → b7db64b07edb0b37ece1.js} +1 -1
  61. package/assets/esri/core/workers/chunks/bd1fb82e8bac439d05ea.js +1 -0
  62. package/assets/esri/core/workers/chunks/bf0a0ca7fdac98f06a89.js.LICENSE.txt +1 -1
  63. package/assets/esri/core/workers/chunks/c44ce0302dc82fb66ada.js +1 -0
  64. package/assets/esri/core/workers/chunks/c52872a50a5989121388.js +1 -0
  65. package/assets/esri/core/workers/chunks/c8cd6ba5600d8ff8db0b.js +2 -0
  66. package/assets/esri/core/workers/chunks/{a100fb789d72410f8d4f.js.LICENSE.txt → c8cd6ba5600d8ff8db0b.js.LICENSE.txt} +1 -1
  67. package/assets/esri/core/workers/chunks/{57c1370b310768c0790a.js → ca1e186f136abb23ae4b.js} +1 -1
  68. package/assets/esri/core/workers/chunks/{d14e4fc82ad772899336.js → ca4a37bdc0f7fb705146.js} +1 -1
  69. package/assets/esri/core/workers/chunks/cb94fc9b0f613ad50b3f.js +1 -0
  70. package/assets/esri/core/workers/chunks/d20764cc99fcabcb7cbf.js +1 -0
  71. package/assets/esri/core/workers/chunks/df18a72e3625cbe31935.js +1 -0
  72. package/assets/esri/core/workers/chunks/eff8fcb6393cd1193cbc.js +1 -0
  73. package/assets/esri/core/workers/chunks/f19d3c855f6e93544918.js +1 -0
  74. package/assets/esri/core/workers/chunks/{60b40b2319d1651dd150.js → f7e50a8284d12da21355.js} +1 -1
  75. package/assets/esri/core/workers/chunks/f9c0d571f62e611ffe2b.js +1 -0
  76. package/assets/esri/core/workers/chunks/fdfe8e0d942b78f08191.js +1 -0
  77. package/assets/esri/core/workers/chunks/ff21207f46a354786eed.js +1 -0
  78. package/chunks/Bufferer-BiY2mtjI.js +1 -1
  79. package/chunks/Centroid-DZi-eb9F.js +1 -1
  80. package/chunks/Clipper-a9xfvRaw.js +1 -1
  81. package/chunks/CrackAndCluster-CfzXpEle.js +1 -1
  82. package/chunks/Distance2DCalculator-eS0piaux.js +1 -1
  83. package/chunks/GeodeticDistanceCalculator-bNilDneE.js +1 -1
  84. package/chunks/Geometry.js +1 -1
  85. package/chunks/GeometryCleaner-DVgW95-D.js +1 -1
  86. package/chunks/Intersector-K1VmdfQW.js +1 -1
  87. package/chunks/LineSeries.js +1 -1
  88. package/chunks/OperatorClip.js +1 -1
  89. package/chunks/OperatorCrosses.js +1 -1
  90. package/chunks/OperatorCut.js +1 -1
  91. package/chunks/OperatorDensify.js +1 -1
  92. package/chunks/OperatorDifference.js +1 -1
  93. package/chunks/OperatorGeneralize.js +1 -1
  94. package/chunks/OperatorGeodesicBuffer.js +1 -1
  95. package/chunks/OperatorGeodeticArea.js +1 -1
  96. package/chunks/OperatorGeodeticDensifyByLength.js +1 -1
  97. package/chunks/OperatorGeodeticDistance.js +1 -1
  98. package/chunks/OperatorGeodeticLength.js +1 -1
  99. package/chunks/OperatorIntersection.js +1 -1
  100. package/chunks/OperatorIntersects.js +1 -1
  101. package/chunks/OperatorMultiPartToSinglePart.js +1 -1
  102. package/chunks/OperatorOverlaps.js +1 -1
  103. package/chunks/OperatorProject.js +1 -1
  104. package/chunks/OperatorProximity.js +1 -1
  105. package/chunks/OperatorProximityGeodesic.js +1 -1
  106. package/chunks/OperatorShapePreservingDensify.js +1 -1
  107. package/chunks/OperatorShapePreservingLength.js +1 -1
  108. package/chunks/OperatorSimplify.js +1 -1
  109. package/chunks/OperatorTouches.js +1 -1
  110. package/chunks/OperatorUnion.js +1 -1
  111. package/chunks/OperatorWithin.js +1 -1
  112. package/chunks/QuadraticBezier.js +1 -1
  113. package/chunks/SideCalculator2D-Bf4QCxCR.js +1 -1
  114. package/chunks/Theme.js +1 -1
  115. package/chunks/Tick.js +1 -1
  116. package/chunks/Transformation2D.js +1 -1
  117. package/chunks/arcade.js +1 -1
  118. package/chunks/areaOperator.js +5 -0
  119. package/chunks/array.js +1 -1
  120. package/chunks/bufferOperator.js +5 -0
  121. package/chunks/centroidOperator.js +5 -0
  122. package/chunks/chartUtilsAm5.js +1 -1
  123. package/chunks/clipOperator.js +5 -0
  124. package/chunks/containsOperator.js +5 -0
  125. package/chunks/convexHullOperator.js +5 -0
  126. package/chunks/crossesOperator.js +5 -0
  127. package/chunks/cutOperator.js +5 -0
  128. package/chunks/densifyOperator.js +5 -0
  129. package/chunks/differenceOperator.js +5 -0
  130. package/chunks/disjointOperator.js +5 -0
  131. package/chunks/distanceOperator.js +5 -0
  132. package/chunks/equalsOperator.js +5 -0
  133. package/chunks/generalizeOperator.js +5 -0
  134. package/chunks/geodesicBufferOperator.js +5 -0
  135. package/chunks/geodeticAreaOperator.js +5 -0
  136. package/chunks/geodeticDensifyOperator.js +5 -0
  137. package/chunks/geodeticLengthOperator.js +5 -0
  138. package/chunks/i3s.js +1 -1
  139. package/chunks/intersectionOperator.js +5 -0
  140. package/chunks/intersectsOperator.js +5 -0
  141. package/chunks/languageUtils.js +1 -1
  142. package/chunks/lclayout.js +1 -1
  143. package/chunks/lengthOperator.js +5 -0
  144. package/chunks/lyr3DMain.js +1 -1
  145. package/chunks/lyr3DWorker.js +1 -1
  146. package/chunks/offsetOperator.js +5 -0
  147. package/chunks/overlapsOperator.js +5 -0
  148. package/chunks/pe-wasm.js +1 -1
  149. package/chunks/proximityOperator.js +5 -0
  150. package/chunks/relateOperator.js +5 -0
  151. package/chunks/simplifyOperator.js +5 -0
  152. package/chunks/symmetricDifferenceOperator.js +5 -0
  153. package/chunks/touchesOperator.js +5 -0
  154. package/chunks/unionOperator.js +5 -0
  155. package/chunks/vxlLayer.js +1 -1
  156. package/chunks/withinOperator.js +5 -0
  157. package/copyright.txt +2 -2
  158. package/core/Evented.js +1 -1
  159. package/geometry/operators/areaOperator.js +1 -1
  160. package/geometry/operators/bufferOperator.js +1 -1
  161. package/geometry/operators/centroidOperator.js +1 -1
  162. package/geometry/operators/clipOperator.js +1 -1
  163. package/geometry/operators/containsOperator.js +1 -1
  164. package/geometry/operators/convexHullOperator.js +1 -1
  165. package/geometry/operators/crossesOperator.js +1 -1
  166. package/geometry/operators/cutOperator.js +1 -1
  167. package/geometry/operators/densifyOperator.js +1 -1
  168. package/geometry/operators/differenceOperator.js +1 -1
  169. package/geometry/operators/disjointOperator.js +1 -1
  170. package/geometry/operators/distanceOperator.js +1 -1
  171. package/geometry/operators/equalsOperator.js +1 -1
  172. package/geometry/operators/extendOperator.js +1 -1
  173. package/geometry/operators/generalizeOperator.js +1 -1
  174. package/geometry/operators/geodesicBufferOperator.js +1 -1
  175. package/geometry/operators/geodeticAreaOperator.js +1 -1
  176. package/geometry/operators/geodeticDensifyOperator.js +1 -1
  177. package/geometry/operators/geodeticLengthOperator.js +1 -1
  178. package/geometry/operators/gx/operatorAffineTransform.js +1 -1
  179. package/geometry/operators/gx/operatorAlphaShape.js +1 -1
  180. package/geometry/operators/gx/operatorAutoComplete.js +1 -1
  181. package/geometry/operators/gx/operatorBoundary.js +1 -1
  182. package/geometry/operators/gx/operatorBuffer.js +1 -1
  183. package/geometry/operators/gx/operatorConvexHull.js +1 -1
  184. package/geometry/operators/gx/operatorGraphicBuffer.js +1 -1
  185. package/geometry/operators/gx/operatorIntegrate.js +1 -1
  186. package/geometry/operators/gx/operatorLabelPoint.js +1 -1
  187. package/geometry/operators/gx/operatorLinesToPolygons.js +1 -1
  188. package/geometry/operators/gx/operatorLocateBetween.js +1 -1
  189. package/geometry/operators/gx/operatorMinimumBoundingCircle.js +1 -1
  190. package/geometry/operators/gx/operatorOffset.js +1 -1
  191. package/geometry/operators/gx/operatorPolygonOverlay.js +1 -1
  192. package/geometry/operators/gx/operatorPolygonSlicer.js +1 -1
  193. package/geometry/operators/gx/operatorSinglePartToMultiPart.js +1 -1
  194. package/geometry/operators/gx/operatorSymmetricDifference.js +1 -1
  195. package/geometry/operators/intersectionOperator.js +1 -1
  196. package/geometry/operators/intersectsOperator.js +1 -1
  197. package/geometry/operators/isNearOperator.js +1 -1
  198. package/geometry/operators/json/disjointOperator.js +1 -1
  199. package/geometry/operators/lengthOperator.js +1 -1
  200. package/geometry/operators/offsetOperator.js +1 -1
  201. package/geometry/operators/overlapsOperator.js +1 -1
  202. package/geometry/operators/proximityOperator.js +1 -1
  203. package/geometry/operators/relateOperator.js +1 -1
  204. package/geometry/operators/reshapeOperator.js +1 -1
  205. package/geometry/operators/simplifyOperator.js +1 -1
  206. package/geometry/operators/support/apiConverter.js +1 -1
  207. package/geometry/operators/support/jsonConverter.js +1 -1
  208. package/geometry/operators/symmetricDifferenceOperator.js +1 -1
  209. package/geometry/operators/touchesOperator.js +1 -1
  210. package/geometry/operators/unionOperator.js +1 -1
  211. package/geometry/operators/withinOperator.js +1 -1
  212. package/geometry/support/contains.js +1 -1
  213. package/kernel.js +1 -1
  214. package/layers/KMLLayer.js +1 -1
  215. package/layers/WCSLayer.js +1 -1
  216. package/layers/support/rasterDatasets/WCSRaster.js +1 -1
  217. package/layers/support/rasterFormats/RasterCodec.js +1 -1
  218. package/layers/support/rasterFormats/TiffDecoder.js +1 -1
  219. package/layers/support/wmtsUtils.js +1 -1
  220. package/package.json +3 -3
  221. package/smartMapping/renderers/support/utils.js +1 -1
  222. package/smartMapping/symbology/support/Theme.js +1 -1
  223. package/support/revision.js +1 -1
  224. package/views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DView.js +1 -1
  225. package/views/3d/support/DisplayQualityProfile.js +1 -1
  226. package/views/3d/webgl-engine/core/shaderModules/interfaces.js +1 -1
  227. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  228. package/views/SelectionManager.js +1 -1
  229. package/widgets/BatchAttributeForm.js +1 -1
  230. package/widgets/Feature/support/featureUtils.js +1 -1
  231. package/widgets/Legend/support/heatmapRampUtils.js +1 -1
  232. package/widgets/OrientedImageryViewer/OrientedImageryViewerVisibleElements.js +1 -1
  233. package/widgets/OrientedImageryViewer.js +1 -1
  234. package/assets/esri/core/workers/chunks/015285436ca965f94e17.js +0 -1
  235. package/assets/esri/core/workers/chunks/048d296efa26ccd79056.js +0 -1
  236. package/assets/esri/core/workers/chunks/0e0b978459d70b15acb5.js +0 -1
  237. package/assets/esri/core/workers/chunks/10fa211987b16fd71a1a.js +0 -1
  238. package/assets/esri/core/workers/chunks/200a5f1864c2c2f7536c.js +0 -1
  239. package/assets/esri/core/workers/chunks/23a697d48f6e45cc033e.js +0 -1
  240. package/assets/esri/core/workers/chunks/29b610ff44708e044cbd.js +0 -1
  241. package/assets/esri/core/workers/chunks/3600125c58d5d04c515a.js +0 -1
  242. package/assets/esri/core/workers/chunks/457d4abc938d14f28e31.js +0 -1
  243. package/assets/esri/core/workers/chunks/4b5dbdcad438cb2dd4bf.js +0 -1
  244. package/assets/esri/core/workers/chunks/69efc716991a407c3d23.js +0 -1
  245. package/assets/esri/core/workers/chunks/6e254e846e284223ef63.js +0 -1
  246. package/assets/esri/core/workers/chunks/785610aa615198fd3815.js +0 -1
  247. package/assets/esri/core/workers/chunks/7bf7aace72f81f5de4e4.js +0 -1
  248. package/assets/esri/core/workers/chunks/7ea3d652536e1d79dfc6.js +0 -1
  249. package/assets/esri/core/workers/chunks/816c9c81352cd0ca8ce8.js +0 -1
  250. package/assets/esri/core/workers/chunks/9291508232b23f030178.js +0 -1
  251. package/assets/esri/core/workers/chunks/9fc49968dea8e2b64f3e.js +0 -1
  252. package/assets/esri/core/workers/chunks/a0b3d70a1b0360084593.js +0 -1
  253. package/assets/esri/core/workers/chunks/a100fb789d72410f8d4f.js +0 -2
  254. package/assets/esri/core/workers/chunks/b4d76d46661aba356ea3.js +0 -1
  255. package/assets/esri/core/workers/chunks/cb3af81e1fe6405c4885.js +0 -1
  256. package/assets/esri/core/workers/chunks/cbf57abb537e86c1dd7f.js +0 -1
  257. package/assets/esri/core/workers/chunks/cebdf2f88c4d2ad8baab.js +0 -1
  258. package/assets/esri/core/workers/chunks/d56d77125798beb7e493.js +0 -1
  259. package/assets/esri/core/workers/chunks/d82b3e2905cab511ff3a.js +0 -2
  260. package/assets/esri/core/workers/chunks/e2f91098793b8742fae6.js +0 -1
  261. package/assets/esri/core/workers/chunks/f25c04cf1a4bc1d2636a.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.32/esri/copyright.txt for details.
4
4
  */
5
- import{S as e,G as t}from"./SimpleGeometryCursor.js";import{t as s,G as i,c as r,a as n,d as h,g as o,e as a,v as m,f as g,h as l,i as d,j as _,k as p}from"./Geometry.js";import{e as u,b as c,n as f,c as x,f as I,S as E,g as P,M as y,h as S,i as C,j as G,k as H,l as V,m as v,a as N,o as T,p as F,q as b,A as w,r as U,P as k,T as D,s as B,C as A,t as O,I as R,u as L,B as Y,v as M,w as X,x as q,y as z,V as W,z as Z,L as j}from"./QuadraticBezier.js";import{s as Q,d as K,b as J,e as $,c as ee,P as te,a as se,C as ie,f as re,N as ne,i as he,g as oe,n as ae,h as me,j as ge,t as le,k as de}from"./CrackAndCluster-CfzXpEle.js";import{P as _e,a as pe,b as ue,d as ce,e as fe,f as xe,s as Ie,g as Ee,h as Pe,i as ye,E as Se,K as Ce,j as Ge,m as He}from"./Transformation2D.js";import{b as Ve,c as ve}from"./tslib.es6.js";class Ne{constructor(e){this.m_currentShift=63n,this.m_currentElt=0n,this.m_iCurrentElt=-1,this.m_parent=e,this.m_aiSetElts=e.m_bits.flatMap(((e,t)=>t))}next(){if(this.m_currentShift++,64n===this.m_currentShift){if(this.m_iCurrentElt++,this.m_iCurrentElt===this.m_aiSetElts.length)return Ne.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 Te(e){return 1n<<(0x3fn&BigInt(e))}function Fe(e){return e>>6}class be{constructor(e){this.m_bits=[],void 0!==e&&e.copy&&(this.m_bits=e.copy.m_bits.slice())}assignMove(){return this}assignCopy(){return this}hasBit(e){const t=Te(e),s=Fe(e);return void 0!==this.m_bits[s]&&!!(this.m_bits[s]&t)}setBit(e){const t=Te(e),s=Fe(e);void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]|=t}clearBit(e){}flipBit(e){const t=Te(e),s=Fe(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(){let e=0;return this.m_bits.forEach((t=>{e|=t?2:1})),!(2&e)}equals(e){if(this===e)return!0;if(this.m_bits.length!==e.m_bits.length)return!1;let t=0;return this.m_bits.forEach(((s,i)=>{t|=s===e.m_bits[i]?2:1})),!(1&t)&&(e.m_bits.forEach(((e,s)=>{t|=e===this.m_bits[s]?2:1})),!(1&t))}notEquals(e){return!this.equals(e)}assignOr(e){return e.m_bits.forEach(((e,t)=>{void 0===this.m_bits[t]?this.m_bits[t]=e:this.m_bits[t]|=e})),this}assignSubtract(e){return e.m_bits.forEach(((e,t)=>{void 0!==this.m_bits[t]&&(this.m_bits[t]&=~e)})),this}assignAnd(e){return e.m_bits.forEach(((e,t)=>{void 0!==this.m_bits[t]&&(this.m_bits[t]&=e)})),this}assignXor(e){return e.m_bits.forEach(((e,t)=>{void 0===this.m_bits[t]?this.m_bits[t]=e:this.m_bits[t]^=e})),this}getHashCode(){return this.m_bits.reduce(((e,t)=>Pe(e,t)),ye(0))}getUnorderedBitIterator(){return new Ne(this)}}class we{constructor(e,t){this.m_map=new Map,this.m_hf=e,this.m_ef=t}add(e){const t=this.m_hf(e);if(!this.m_map.has(t))return this.m_map.set(t,e),this;const s=this.m_map.get(t);return s instanceof Array?s.find((t=>this.m_ef(t,e)))||s.push(e):this.m_ef(s,e)||this.m_map.set(t,[s,e]),this}clear(){this.m_map.clear()}delete(e){return!1}has(e){const t=this.m_hf(e);if(!this.m_map.has(t))return!1;const s=this.m_map.get(t);return s instanceof Array?void 0!==s.find((t=>this.m_ef(t,e))):this.m_ef(s,e)}get(e){const t=this.m_hf(e),s=this.m_map.get(t);if(void 0!==s)return s instanceof Array?s.find((t=>this.m_ef(t,e))):s}get size(){let e=0;for(const t of this.m_map.values())e+=t instanceof Array?t.length:1;return e}forEach(e,t){}[Symbol.iterator](){return(new Set)[Symbol.iterator]()}entries(){return(new Set).entries()}keys(){return(new Set).keys()}values(){return(new Set).values()}get[Symbol.toStringTag](){return"ValueSet"}}class Ue extends Z{constructor(e){super(),this.m_bufferLeft=new E,this.m_bufferRight=new E,this.m_intervalLeft=Se.constructEmpty(),this.m_intervalRight=Se.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 o=n.getStartY()===n.getEndY(),a=h.getStartY()===h.getEndY();if(o||a){if(o&&a)return 0;if(n.getStartY()===h.getStartY()&&n.getStartX()===h.getStartX())return o?1:-1;if(n.getEndY()===h.getEndY()&&n.getEndX()===h.getEndX())return o?-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 ke{constructor(e){this.m_segmentBuffer=new E,this.m_point=_e.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 Se;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 De,Be;function Ae(e,t){return{parentage:e,rank:t}}function Oe(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 Re(e,t,s){s.length=0;let i=!1;{let r=e.getHalfEdgeVertexIterator(t);for(;r!==f;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(Ae(h,n)),r=e.incrementVertexIterator(r)}}{let r=e.getHalfEdgeVertexIterator(e.getHalfEdgeTwin(t));for(;r!==f;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(Ae(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 Le(){return new we((e=>e.getHashCode()),((e,t)=>e.equals(t)))}!function(e){e[e.enumInputModeBuildGraph=0]="enumInputModeBuildGraph",e[e.enumInputModeSimplifyAlternate=1]="enumInputModeSimplifyAlternate",e[e.enumInputModeSimplifyWinding=2]="enumInputModeSimplifyWinding"}(De||(De={})),function(e){e[e.enumSegmentParentageBreakNode=1]="enumSegmentParentageBreakNode",e[e.enumPathBreakNode=2]="enumPathBreakNode"}(Be||(Be={}));class Ye{constructor(){this.m_shape=null,this.m_clusterData=new b(8),this.m_clusterVertices=new b(2),this.m_firstCluster=f,this.m_lastCluster=f,this.m_halfEdgeData=new b(8),this.m_chainData=new b(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,De.enumInputModeBuildGraph,null,t,!1):this.setEditShapeImpl_(e,De.enumInputModeBuildGraph,null,t,s)}setAndSimplifyEditShapeAlternate(e,t,s=null,r=!1){const n=[];n.push(t),this.m_simplifiedGeometry=t,r?this.setEditShapeImpl3D_(e,De.enumInputModeSimplifyAlternate,n,s,!1):this.setEditShapeImpl_(e,De.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,De.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=f,this.m_lastCluster=f,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=f,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(e,t){o(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(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)}createUserIndexForClusters(e=-1){const t=new w(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(e,t){o(0)}getHalfEdgeToXYZ(e,t){o(0)}getHalfEdgeParentage(e){return this.m_halfEdgeData.getField(e,3)&Ye.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(e){void 0===e&&(e=-1);const t=new w(this.m_halfEdgeData.capacity(),e);for(let i=0,r=this.m_edgeIndices.length;i<r;i++)if(null===this.m_edgeIndices[i])return this.m_edgeIndices[i]=t,i;this.m_edgeIndices.push(t);const s=this.m_edgeIndices.length-1;return o(s>=0&&s<=Number.MAX_SAFE_INTEGER),s}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,f),this.setChainHalfEdge_(n,f),this.updateVertexToHalfEdgeConnection_(s,!0),this.deleteEdgeImpl_(s)}}doesHalfEdgeBelongToAPolygonInterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolygonExterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolygonBoundary(e,t){return o(0),!1}doesHalfEdgeBelongToAPolylineInterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolylineExterior(e,t){return o(0),!1}doesClusterBelongToAPolygonInterior(e,t){return o(0),!1}doesClusterBelongToAPolygonExterior(e,t){return o(0),!1}doesClusterBelongToAPolygonBoundary(e,t){return o(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(e){return o(0),0}getChainUserIndex(e,t){const s=this.getChainIndex_(e),i=this.m_chainIndices[t];return i.size()<=s?-1:i.read(s)}setChainUserIndex(e,t,s){const i=this.getChainIndex_(e),r=this.m_chainIndices[t];r.size()<=i&&r.resize(this.m_chainData.size(),-1),r.write(i,s)}createUserIndexForChains(){const e=new w(this.m_chainData.capacity(),-1);for(let t=0,s=this.m_chainIndices.length;t<s;t++)if(null===this.m_chainIndices[t])return this.m_chainIndices[t]=e,t;this.m_chainIndices.push(e);return this.m_chainIndices.length-1}deleteUserIndexForChains(e){this.m_chainIndices[e]=null}extractPolygonFromChainAndIslands(e,t,s,r){const n=t===f?e.createGeometry(i.enumPolygon):t,h=new E;this.extractPolygonPathFromChain_(e,n,s,r,h);for(let i=this.getChainFirstIsland(s);i!==f;i=this.getChainNextInParent(i))this.extractPolygonPathFromChain_(e,n,i,r,h);return n}getGeometryID(e){const t=this.m_shape.getGeometryUserIndex(e,this.m_geometryIDIndex);return o(t>=0),1<<Math.min(t,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(e){if(o(this.m_bBuildGeometryParentageSets),-1===this.m_chainBitSetIndex)return this.getEmptySet();const t=this.getChainUserIndex(e,this.m_chainBitSetIndex);o(t>=0);let s=this.m_chainBitSets.at(t);return s||(s=this.getEmptySet()),s}getChainBoundaryBitSet(e){o(this.m_bBuildGeometryParentageSets);const t=new be,s=e=>{const s=this.getChainHalfEdge(e);let i=s;do{const e=this.getEdgeBitSet_(i);null!==e&&t.assignOr(e);const s=this.getEdgeBitSet_(this.getHalfEdgeTwin(i));null!==s&&t.assignOr(s),i=this.getHalfEdgeNext(i)}while(i!==s)};s(e);for(let i=this.getChainFirstIsland(e);i!==f;i=this.getChainNextInParent(i))s(e);return t}getChainPolygons(e){return o(0),[]}getGeometriesFromBits(e){if(!this.m_bBuildGeometryParentageSets||null===e)return[];if(null===this.m_geometryMapID){this.m_geometryMapID=new Map;for(let e=this.m_shape.getFirstGeometry();e!==f;e=this.m_shape.getNextGeometry(e))this.m_geometryMapID.set(this.m_shape.getGeometryUserIndex(e,this.m_geometryIDIndex),e)}const t=[],s=e.getUnorderedBitIterator();for(let i=s.next();i!==Ne.npos();i=s.next())o(this.m_geometryMapID.has(i)),t.push(this.m_geometryMapID.get(i));return t}getVertexDominant(e,t){if(t===f)return e;const s=this.getClusterFromVertex(e);return this.getVertexDominantFromCluster(s,t)}getVertexDominantFromCluster(e,t){if(t!==f){let s=f;for(let i=this.getClusterVertexIterator(e);i!==f;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);s===f&&(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!==f){return this.getVertexFromVertexIterator(t)}return f}}isBreakNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode)}setBreakNode(e,t){o(-1!==this.m_clusterBreakNodeIndex),t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode)}isStrongPathNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumPathBreakNode)}setStrongPathNode(e,t){if(-1===this.m_clusterBreakNodeIndex){if(!t)return;this.m_clusterBreakNodeIndex=this.createUserIndexForClusters()}t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumPathBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.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(e){return o(0),!1}getHalfEdgeConnector(e,t){const s=this.getClusterHalfEdge(e);if(s===f)return f;let i=s,r=f,n=f;do{if(this.getHalfEdgeTo(i)===t)return i;if(r===f){if(r=this.getClusterHalfEdge(t),r===f)return f;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 f}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=_e.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_(e,t,s){const i=new E,r=new E;this.querySegmentXY(e,i),this.querySegmentXY(t,r);const n=i.get(),h=r.get();if(n.equals(h))return 0;const a=new _e;this.getHalfEdgeFromXY(e,a);const m=new _e;this.getHalfEdgeToXY(e,m);const g=new _e;this.getHalfEdgeToXY(t,g),o(!m.isEqualPoint2D(g));const l=n.getTangent(0),d=h.getTangent(0);return _e.compareVectors(l,d)}compareEdgeAnglesHelper_(e,t,s){if(e===t)return 0;if(this.isHalfEdgeCurve(e)||this.isHalfEdgeCurve(t))return this.compareEdgeAnglesCurveHelper_(e,t,s);const i=_e.getNAN();this.getHalfEdgeToXY(e,i);const r=_e.getNAN();if(this.getHalfEdgeToXY(t,r),i.isEqualPoint2D(r))return 0;const n=_e.getNAN();this.getHalfEdgeFromXY(e,n);const h=_e.getNAN();h.setSub(i,n);const o=_e.getNAN();if(o.setSub(r,n),!s||o.y>=0&&h.y>0){return _e.compareVectors(h,o)}return 0}compareEdgeAngles_(e,t){return this.compareEdgeAnglesHelper_(e,t,!1)}compareEdgeAnglesForPair_(e,t){return this.compareEdgeAnglesHelper_(e,t,!0)}compareEdgeAngles3D_(e,t){return o(0),0}compareEdgeAnglesForPair3D_(e,t){return o(0),0}dbgDumpChains_(){}dbgDumpChainToPolygon_(e,t){}deleteEdgeInternal_(e){const t=this.getHalfEdgeChain(e),s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeChain(s);o(i===t),o(e===this.getHalfEdgeNext(s)||s===this.getHalfEdgeNext(e));let r=this.getHalfEdgeNext(e);r===s&&(r=this.getHalfEdgeNext(r),r===e&&(r=f));const n=this.getChainIndex_(t),h=this.m_chainAreas.read(n);Number.isNaN(h)||(this.setChainArea_(t,Number.NaN),this.setChainPerimeter_(t,Number.NaN));const a=this.getChainHalfEdge(t);a!==e&&a!==s||this.setChainHalfEdge_(t,r),this.updateVertexToHalfEdgeConnection_(e,!0),this.deleteEdgeImpl_(e)}getFirstUnvisitedHalfEdgeOnCluster_(e,t,s){let i=t!==f?t:this.getClusterHalfEdge(e);if(i===f)return f;const r=i;for(;;){if(1!==this.getHalfEdgeUserIndex(i,s))return i;const e=this.getHalfEdgeNext(this.getHalfEdgeTwin(i));if(e===r)return f;i=e}}removeSpikes_(){let e=!1;const t=this.createUserIndexForHalfEdges();for(let s=this.getFirstCluster();s!==f;s=this.getNextCluster(s)){let i=f;for(;;){let r=this.getFirstUnvisitedHalfEdgeOnCluster_(s,i,t);if(r===f)break;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(r));let n=r;for(;;){const s=this.getHalfEdgeNext(n),h=this.getHalfEdgePrev(n),o=this.getHalfEdgeTwin(n);if(h===o){if(this.deleteEdgeInternal_(n),e=!0,i!==n&&i!==o||(i=f),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_(e){return o(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?f:e;for(let i=this.getHalfEdgeVertexIterator(e);i!==f;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);this.m_shape.setUserIndex(e,this.m_halfEdgeIndex,s)}}updateVertexToHalfEdgeConnection_(e,t){e!==f&&(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=_e.getNAN(),h=_e.getNAN(),o=_e.getNAN();this.getHalfEdgeFromXY(r,n),h.setCoordsPoint2D(n);let a=r;do{this.getHalfEdgeToXY(a,o),t&&this.isCurveEdge(a)||i.pe(_e.distance(h,o));this.getHalfEdgeChain(this.getHalfEdgeTwin(a))!==e&&s.pe((o.x-n.x-(h.x-n.x))*(o.y-n.y+(h.y-n.y))*.5),h.setCoordsPoint2D(o),a=this.getHalfEdgeNext(a)}while(a!==r);if(t){const t=new E;a=r;do{this.getHalfEdgeToXY(a,o);const r=this.isCurveEdge(a);r&&(this.querySegmentXY(a,t),i.pe(t.get().calculateLength2D()));if(this.getHalfEdgeChain(this.getHalfEdgeTwin(a))!==e&&r){const e=t.get().calculateArea2DHelper();s.pe(e)}a=this.getHalfEdgeNext(a)}while(a!==r)}const m=this.getChainIndex_(e);this.m_chainAreas.write(m,s.getResult()),this.m_chainPerimeters.write(m,i.getResult())}getChainTopmostEdge_(e){return o(0),0}planeSweepParentage_(e,t){const s=new Ue(this),i=new D;i.setCapacity(Math.trunc(this.m_pointCount/2)),i.setComparator(s);const r=[],n=this.createUserIndexForHalfEdges();let h=null;const o=_e.getNAN();for(let a=this.getFirstCluster();a!==f;a=this.getNextCluster(a)){this.progress_(t);const m=this.getClusterHalfEdge(a);if(m!==f){if(r.length=0,!this.tryOptimizedInsertion_(i,n,r,a,m)){this.queryXY(a,o),s.setY(o.y);let e=m;do{const t=this.getHalfEdgeUserIndex(e,n);-1!==t&&(i.deleteNode(t),this.setHalfEdgeUserIndex(e,n,b.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),o=this.getHalfEdgeTwin(h);this.setHalfEdgeUserIndex(o,n,s),this.planeSweepParentagePropagateParentage_(i,s,e)}}else if(this.getClusterChain(a)===f){null===h&&(h=new ke(this)),this.queryXY(a,o),h.setPointXY(o);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!==f&&(t=this.getHalfEdgeChain(s))}this.addClusterToExteriorChain_(t,a)}}this.deleteUserIndexForHalfEdges(n)}planeSweepParentagePropagateParentage_(e,t,s){const i=e.getElement(t),r=this.getHalfEdgeChain(i);if(this.getChainParent(r)!==f)return;const n=this.getLeftSkipPolylines_(e,t),h=this.getHalfEdgeTwin(i),a=this.getHalfEdgeChain(h);let m=this.getChainParent(r),g=this.getChainParent(a);if(n===f)m===f&&(a===r?(this.setChainParent_(a,this.m_universeChain),g=this.m_universeChain,m=g):(g===f&&(this.setChainParent_(a,this.m_universeChain),g=this.m_universeChain),this.setChainParent_(r,a),m=a));else{const e=this.getHalfEdgeChain(n);if(g===f){if(this.getChainArea(e)<=0){const t=this.getChainParent(e);this.setChainParent_(a,t),g=t}else this.setChainParent_(a,e),g=e;a===r&&(m=g)}}m===f&&(this.trySetChainParentFromTwin_(r,a),m=this.getChainParent(r)),o(m!==f),s===De.enumInputModeBuildGraph?this.propagateParentageBuildGraph_(e,t,i,n):s===De.enumInputModeSimplifyWinding?this.propagateParentageWinding_(e,t,i,n,h,r,a):s===De.enumInputModeSimplifyAlternate&&this.propagateParentageAlternate_(e,t,i,n,h,r,a)}propagateParentageBuildGraph_(e,t,s,i){let r,n=t;i===f?(n=e.getNext(n),r=this.getHalfEdgeChain(s)):r=this.getHalfEdgeChain(i);let h=null,o=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 be({copy:e}),e.assignOr(h),this.setChainBitSet_(i,e);let s=this.getChainBitSet(r);const n=this.getLeftEdgeBitSet_(t),o=new be({copy:h});if(o.assignSubtract(n),o.isZero())break;s=new be({copy:s}),s.assignOr(o),this.setChainBitSet_(r,s),h=s}const a=this.getChainParentage(i),m=a|o;m!==a&&this.setChainParentage_(i,m);let g=this.getChainParentage(r);const l=o&~this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeParentageIndexLeft);if(l&&(g|=l,this.setChainParentage_(r,g)),0===l)break;o=g}}propagateParentageWinding_(e,t,s,i,r,n,h){if(n===h)return;let a=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex);a+=this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);let m=0;const g=[],l=[];l.push(0);for(let d=e.getFirst();d!==t;d=e.getNext(d)){const t=e.getElement(d),s=this.getHalfEdgeTwin(t),i=this.getHalfEdgeChain(t),r=this.getHalfEdgeChain(s);if(i!==r){let e=this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeWindingNumberIndex);e+=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex),m+=e;let n=!1;0!==g.length&&g.at(-1)===r&&(l.pop(),g.pop(),n=!0),o(this.getChainParent(r)!==f),n&&this.getChainParent(r)===i||(l.push(m),g.push(i))}}if(m+=a,0!==g.length&&g.at(-1)===h&&(l.pop(),g.pop()),0!==m){if(0===l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(n,t)}}else if(0!==l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(n,t)}}propagateParentageAlternate_(e,t,s,i,r,n,h){const o=this.m_simplifiedGeometry,a=this.getGeometryID(o);if(i===f){this.setChainParentage_(h,this.m_universeGeomID);1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,a):this.setChainParentage_(n,this.m_universeGeomID)}else{const e=this.getChainParentage(h);if(0===e){const e=this.getHalfEdgeChain(i),t=this.getChainParentage(e);this.setChainParentage_(h,t);1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,t===a?this.m_universeGeomID:a):this.setChainParentage_(n,t)}else{1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,e===a?this.m_universeGeomID:a):this.setChainParentage_(n,e)}}}tryOptimizedInsertion_(e,t,s,i,r){let n=r,h=-1,o=f,a=0;do{if(2===a)return!1;const e=this.getHalfEdgeUserIndex(n,t);if(-1!==e){if(-1!==h)return!1;h=e}else{if(o!==f)return!1;o=n}a++,n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(r!==n);return o!==f&&-1!==h&&(this.setHalfEdgeUserIndex(e.getElement(h),t,b.impossibleIndex2()),e.setElement(h,o),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!==f)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),o=this.m_shape.getGeometryFromPath(h),m=this.m_shape.getGeometryType(o);if(a(m)){const t=this.m_shape.getNextVertex(r);if(t===f)continue;const s=this.m_shape.getUserIndex(t,this.m_clusterIndex);if(n===s)continue;const h=this.newHalfEdgePair_(),a=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===f)this.setClusterHalfEdge_(n,h),this.setHalfEdgePrev_(h,a),this.setHalfEdgeNext_(a,h);else{const e=this.getHalfEdgePrev(l);this.setHalfEdgePrev_(l,a),this.setHalfEdgeNext_(a,l),this.setHalfEdgeNext_(e,h),this.setHalfEdgePrev_(h,e)}this.setHalfEdgeOrigin_(a,s);const d=this.getClusterHalfEdge(s);if(d===f)this.setClusterHalfEdge_(s,a),this.setHalfEdgeNext_(h,a),this.setHalfEdgePrev_(a,h);else{const e=this.getHalfEdgePrev(d);this.setHalfEdgePrev_(d,h),this.setHalfEdgeNext_(h,d),this.setHalfEdgeNext_(e,a),this.setHalfEdgePrev_(a,e)}const _=this.getGeometryID(o);if(e===De.enumInputModeBuildGraph){const e=m===i.enumPolygon?_:0;if(this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndex,0),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,e),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndexLeft,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,0),this.m_bBuildGeometryParentageSets){const e=new be,t=this.m_shape.getGeometryUserIndex(o,this.m_geometryIDIndex);e.setBit(t),this.setEdgeBitSet_(h,e),this.setEdgeBitSet_(a,null),this.setLeftEdgeBitSet_(a,e),this.setLeftEdgeBitSet_(h,null)}}else if(e===De.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(a,this.m_tmpHalfEdgeWindingNumberIndex,n)}else e===De.enumInputModeSimplifyAlternate&&(this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,1),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeOddEvenNumberIndex,1));const p=m===i.enumPolygon?Ye.c_EdgeBitMask:0;this.setHalfEdgeParentage_(h,_|p),this.setHalfEdgeParentage_(a,_|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!==f&&(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!==f){const i=this.getHalfEdgeVertexIterator(e);this.m_clusterVertices.setField(s,1,i),this.setHalfEdgeVertexIterator_(e,s),this.setHalfEdgeVertexIterator_(t,f)}}const s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeTwin(t);{const e=this.getHalfEdgeVertexIterator(i);if(e!==f){const t=this.getHalfEdgeVertexIterator(s);this.m_clusterVertices.setField(e,1,t),this.setHalfEdgeVertexIterator_(s,e),this.setHalfEdgeVertexIterator_(i,f)}}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!==f;s=this.getNextCluster(s)){t.length=0;const i=this.getClusterHalfEdge(s);if(i!==f){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]=ue(t[0],t[0]=t[1]):r=!1;let n=t[0],h=n,o=this.getHalfEdgeTo(h),a=this.getHalfEdgeTwin(h),m=f;for(let s=1,i=t.length;s<i;s++){const i=t[s],r=this.getHalfEdgeTwin(i),g=this.getHalfEdgeOrigin(r);if(g!==o||i===h)this.updateVertexToHalfEdgeConnection_(m,!1),m=f,h=i,o=g,a=r;else{if(e===De.enumInputModeBuildGraph){const e=this.getHalfEdgeParentageMask_(h)|this.getHalfEdgeParentageMask_(i);if(this.setHalfEdgeParentage_(h,e),this.setHalfEdgeParentage_(a,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(a,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(a,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(a,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 be({copy:e}),s.assignOr(t),this.setEdgeBitSet_(h,s),e=this.getEdgeBitSet_(a),t=this.getEdgeBitSet_(r),s=new be({copy:e}),s.assignOr(t),this.setEdgeBitSet_(a,s),e=this.getLeftEdgeBitSet_(h),t=this.getLeftEdgeBitSet_(i),s=new be({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(h,s),e=this.getLeftEdgeBitSet_(a),t=this.getLeftEdgeBitSet_(r),s=new be({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(a,s)}}else if(-1!==this.m_tmpHalfEdgeWindingNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),t=this.getHalfEdgeUserIndex(a,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,e),this.setHalfEdgeUserIndex(a,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(a,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeOddEvenNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,e),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeOddEvenNumberIndex,t)}this.mergeVertexListsOfEdges_(h,i),this.deleteEdgeImpl_(i),m=h,t[s]=f,i===n&&(t[0]=f,n=f)}}if(this.updateVertexToHalfEdgeConnection_(m,!1),m=f,!r){n=f;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s!==f){n=s;break}}i!==n&&this.setClusterHalfEdge_(s,n);continue}n=f;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s===f)continue;if(n===f){n=s,h=n,o=this.getHalfEdgeTo(h),a=this.getHalfEdgeTwin(h);continue}if(s===h)continue;const i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeOrigin(i);this.setHalfEdgeNext_(a,s),this.setHalfEdgePrev_(s,a),h=s,o=r,a=i}this.setClusterHalfEdge_(s,n)}}}}sortHalfEdgesByAngle3D_(e){o(0)}buildChains_(e){this.m_universeChain=this.newChain_(),this.setChainHalfEdge_(this.m_universeChain,f);let t=this.m_universeChain;const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){const e=this.getClusterHalfEdge(i);if(e!==f){let i=e;do{if(1!==this.getHalfEdgeUserIndex(i,s)){const e=this.newChain_();this.setChainHalfEdge_(e,i),this.setChainPrev_(e,t),this.setChainNext_(t,e);let r=null;this.m_bBuildGeometryParentageSets&&(r=new be),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 U(this.m_chainData.size(),Number.NaN),this.m_chainPerimeters=new U(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_(e){o(0)}simplifyAlternate_(){o(0)}simplifyWinding_(){o(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 w(0);let o=0,a=0;{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==f;){this.m_shape.setGeometryUserIndex(e,this.m_geometryIDIndex,a++);for(let t=this.m_shape.getFirstPath(e);t!==f;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)}g(this.m_shape.getGeometryType(e))||(o+=this.m_shape.getPathCount(e)),null!=s?(e=t<s.length?s[t]:f,t++):e=this.m_shape.getNextGeometry(e)}}this.m_universeGeomID=1<<Math.min(a,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,o)),this.m_clusterIndex=this.m_shape.createUserIndex();const m=_e.getNAN();let l=0;const d=_e.getNAN();for(let g=0;g<=this.m_pointCount;g++){if(g<this.m_pointCount){const e=h.read(g);this.m_shape.queryXY(e,d)}else d.setNAN();if(!m.isEqualPoint2D(d)){if(l<g){const e=this.newCluster_();let t=f,s=-1;for(let i=l;i<g;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),o=this.m_shape.getGeometryFromPath(n),a=this.getGeometryID(o);this.setClusterParentage_(e,this.getClusterParentage(e)|a)}this.setClusterVertexIterator_(e,t),this.setClusterVertexIndex_(e,this.m_shape.getVertexIndex(s)),this.m_lastCluster!==f&&this.setNextCluster_(this.m_lastCluster,e),this.setPrevCluster_(e,this.m_lastCluster),this.m_lastCluster=e,this.m_firstCluster===f&&(this.m_firstCluster=e)}l=g,m.setCoordsPoint2D(d)}}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!==f;){for(let t=this.m_shape.getFirstPath(e);t!==f;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]:f,t++):e=this.m_shape.getNextGeometry(e)}}if(t===De.enumInputModeBuildGraph&&(this.m_tmpHalfEdgeParentageIndex=this.createUserIndexForHalfEdges(),this.m_tmpHalfEdgeParentageIndexLeft=this.createUserIndexForHalfEdges()),t===De.enumInputModeSimplifyWinding&&(this.m_tmpHalfEdgeWindingNumberIndex=this.createUserIndexForHalfEdges()),t===De.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_(e,t,s,i,r){o(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_(){o(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,f));const o=this.getHalfEdgeOrigin(i);this.getClusterHalfEdge(o)===i&&(t!==i?this.setClusterHalfEdge_(o,t):this.setClusterHalfEdge_(o,f)),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 f;{const t=e.getElement(s);if(this.getHalfEdgeChain(t)!==this.getHalfEdgeChain(this.getHalfEdgeTwin(t)))return t}}}checkStructureAfterDirtySweep_(){const e=fe(this.m_checkDirtyPlanesweepTolerance),t=new _e,s=new _e,i=new _e,r=new _e,n=new _e;for(let h=this.getFirstCluster();h!==f;h=this.getNextCluster(h)){const o=this.getClusterHalfEdge(h);if(o!==f){let h=o;this.getHalfEdgeFromXY(h,t),this.getHalfEdgeToXY(h,s),i.setSub(s,t);let a=i.sqrLength();do{const o=h;if(h=this.getHalfEdgeNext(this.getHalfEdgeTwin(h)),h!==o){this.getHalfEdgeToXY(h,r),n.setSub(r,t);const o=n.sqrLength(),m=n.crossProduct(i),g=m*m/(o*a);if(Math.min(o,a)*g<=e){if(n.dotProduct(i)>=0)return!1}i.assign(n),a=o,s.assign(r)}}while(h!==o)}}return!0}extractPolygonPathFromChain_(e,t,s,i,r){const n=this.m_shape.hasSegmentParentage(),h=this.getChainHalfEdge(s);let o=h,a=f;const m=new k;do{const h=this.getHalfEdgeTwin(o);if(this.getHalfEdgeChain(h)!==s){let s=f;const h=this.getHalfEdgeOrigin(o);if(i===f){const e=this.getClusterVertexIterator(h);s=this.getVertexFromVertexIterator(e)}else for(let e=this.getClusterVertexIterator(h);e!==f;e=this.incrementVertexIterator(e)){const t=this.getVertexFromVertexIterator(e);s===f&&(s=t);const r=this.m_shape.getPathFromVertex(t);if(this.m_shape.getGeometryFromPath(r)===i){s=t;break}}let g;if(a===f&&(a=e.insertPath(t,f),e.setClosedPath(a,!0)),this.m_shape===e?g=e.addVertex(a,s):(this.m_shape.queryPoint(s,m),g=e.addPoint(a,m)),this.isHalfEdgeCurve(o)&&(this.querySegmentXY(o,r),e.setSegmentToIndex(e.getVertexIndex(g),r.get().clone())),n){const t=this.getSegmentParentage(o);e.setSegmentParentageAndBreak(g,t,this.isBreakNode(h))}}o=this.getHalfEdgeNext(o)}while(o!==h)}mergeSegmentParentage_(){if(!this.m_shape.hasSegmentParentage())return;o(-1!==this.m_clusterBreakNodeIndex),o(-1===this.m_segmentParentageIndex);for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){let e=0;const t=this.getClusterHalfEdge(i);if(t!==f){let s=t;do{e++,s=this.getHalfEdgeNext(this.getHalfEdgeTwin(s))}while(s!==t&&e<3)}2!==e&&this.setBreakNode(i,!0)}let e=[],t=[];this.m_segmentParentageIndex=this.createUserIndexForHalfEdges();const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){const r=this.getClusterHalfEdge(i);if(r!==f){let i=!1,n=r;do{let r=n;for(;-1===this.getHalfEdgeUserIndex(r,s);){const n=this.getHalfEdgeNext(r),h=this.getHalfEdgeTwin(r);Re(this,r,t);const o=t.at(-1).parentage;if(!i){const t=this.getHalfEdgeOrigin(r);if(!this.isBreakNode(t)){const t=this.getHalfEdgePrev(r);r!==t&&(Re(this,t,e),i=!0)}}if(i&&!Oe(t,e)){const e=this.getHalfEdgeOrigin(r);this.setBreakNode(e,!0)}e=ue(t,t=e),i=!0;const a=this.getHalfEdgeOrigin(n);this.isBreakNode(a)&&(i=!1),this.setHalfEdgeUserIndex(r,this.m_segmentParentageIndex,o),this.setHalfEdgeUserIndex(h,this.m_segmentParentageIndex,o),this.setHalfEdgeUserIndex(r,s,1),this.setHalfEdgeUserIndex(h,s,1),r=n}n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(n!==r)}}this.deleteUserIndexForHalfEdges(s)}registerNewBitSet(e){if(null===this.m_uniqueBitSets&&(this.m_uniqueBitSets=Le(),this.m_uniqueBitSets.add(this.getEmptySet())),null===e)return this.getEmptySet();return this.m_uniqueBitSets.has(e)?this.m_uniqueBitSets.get(e):(this.m_uniqueBitSets.add(e),e)}getLeftEdgeBitSet_(e){const t=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft);return o(t>=0),o(this.m_edgeBitSets.at(t)),this.m_edgeBitSets.at(t)}getEdgeBitSet_(e){const t=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndex);return o(t>=0),this.m_edgeBitSets.at(t)}setEdgeBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_edgeBitSetIndex&&(this.m_edgeBitSetIndex=this.createUserIndexForHalfEdges());const s=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndex);-1!==s?this.m_edgeBitSets[s]=t:(this.setHalfEdgeUserIndex(e,this.m_edgeBitSetIndex,this.m_edgeBitSets.length),this.m_edgeBitSets.push(t))}setLeftEdgeBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_edgeBitSetIndexLeft&&(this.m_edgeBitSetIndexLeft=this.createUserIndexForHalfEdges());const s=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft);-1!==s?this.m_edgeBitSets[s]=t:(this.setHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft,this.m_edgeBitSets.length),this.m_edgeBitSets.push(t))}setChainBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_chainBitSetIndex&&(this.m_chainBitSetIndex=this.createUserIndexForChains());const s=this.getChainUserIndex(e,this.m_chainBitSetIndex);-1!==s?this.m_chainBitSets[s]=t:(this.setChainUserIndex(e,this.m_chainBitSetIndex,this.m_chainBitSets.length),this.m_chainBitSets.push(t))}getEmptySet(){return this.m_emptyBitSet||(this.m_emptyBitSet=new be),this.m_emptyBitSet}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_(e){}dbgVerifyEdgeSegment(e){}}function Me(e,t,s,i){s>0&&se(e,s,t,!1,i);new qe(i).executeImpl_(e,t)}function Xe(e,t,s){return{vertex0:e,vertex1:t,dir:s}}Ye.c_EdgeParentageMask=~(1<<31),Ye.c_EdgeBitMask=1<<31;class qe{constructor(e){this.m_shape=null,this.m_spikes=[],this.m_points=new w(0),this.m_pointsIndex=-1,this.m_dissolvedEdges=0,this.m_progressTracker=e}executeImpl_(e,t){if(this.m_shape=e,e.getPathCount(t)<2&&e.getPointCount(t)<6)return;this.m_points.resize(0);for(let o=e.getFirstPath(t);o!==f;o=e.getNextPath(o)){let t=e.getFirstVertex(o);for(let s=0,i=e.getPathSize(o);s<i;s++,t=e.getNextVertex(t))this.m_points.add(t)}this.m_pointsIndex=e.createUserIndex();for(let o=0,l=this.m_points.size();o<l;++o)e.setUserIndex(this.m_points.read(o),this.m_pointsIndex,o);e.sortVerticesSimpleByY(this.m_points,0,this.m_points.size());let s=this.m_points.read(0);const i=e.getXY(s);let r=1,n=0;const h=[];for(let o=1;o<this.m_points.size();o++){const t=this.m_points.read(o);if(t===f)continue;if(-1===e.getUserIndex(t,this.m_pointsIndex))continue;const a=e.getXY(t);if(a.isEqualPoint2D(i))r++;else{if(r>1){for(let t=n;t<o;t++){const s=this.m_points.read(t);if(-1===e.getUserIndex(s,this.m_pointsIndex))continue;const r=e.getNextVertex(s),n=e.getPrevVertex(s);if(s!==r&&!e.isEqualXYPoint2D(r,i)){const e=Xe(s,r,1);h.push(e)}if(s!==n&&n!==r&&!e.isEqualXYPoint2D(n,i)){const e=Xe(s,n,-1);h.push(e)}}h.length>0&&this.processBunch_(h,i)}s=t,i.assign(a),r=1,n=o}}if(0===this.m_dissolvedEdges)return e.removeUserIndex(this.m_pointsIndex),void(this.m_pointsIndex=-1);let a=e.getPointCount(t);for(let o=0;o<this.m_points.size();o++){const t=this.m_points.read(o);if(t===f)continue;if(-1!==e.getUserIndex(t,this.m_pointsIndex)){e.setUserIndex(t,this.m_pointsIndex,-1);continue}const s=e.getPathFromVertex(t);e.getFirstVertex(s)===t&&e.setFirstVertex(s,f),e.freeVertex(t),this.m_points.write(o,f),a--}const m=e.createPathUserIndex();let g=e.getPathCount(t);for(let l=0,d=this.m_points.size();l<d;++l){if(this.m_points.read(l)===f)continue;let s=this.m_points.read(l);if(-1!==e.getUserIndex(s,this.m_pointsIndex))continue;let i=e.getPathFromVertex(s),r=-1;if(2===e.getPathUserIndex(i,m)){i=f;for(let t=e.getNextVertex(s);t!==s;t=e.getNextVertex(t)){const r=e.getPathFromVertex(t);if(2!==e.getPathUserIndex(r,m)){i=r,s=t;break}}i===f&&(i=e.insertPath(t,f),e.setClosedPath(i,!0),g++),o(i!==f)}e.setPathUserIndex(i,m,2),r=e.getFirstVertex(i);let n=0,h=!1,a=s;do{r===a&&(h=!0),e.setUserIndex(a,this.m_pointsIndex,1);const t=e.getPathFromVertex(a);t!==i&&(2!==e.getPathUserIndex(t,m)&&(e.setPathUserIndex(t,m,1),e.setFirstVertex(t,f)),e.setPathToVertex(a,i)),n++,a=e.getNextVertex(a)}while(a!==s);h||e.setFirstVertex(i,s),e.setPathSize(i,n)}for(let o=e.getFirstPath(t);o!==f;){const t=e.getNextPath(o);1!==e.getPathUserIndex(o,m)&&e.getFirstVertex(o)!==f||(e.removePathOnly(o),g--),o=t}e.setGeometryVertexCount(t,a),e.setGeometryPathCount(t,g),e.removePathUserIndex(m),e.removeUserIndex(this.m_pointsIndex),this.m_pointsIndex=-1,e.dbgVerifyVertexCounts(),e.filterClosePoints(0,!0,!1,!1,t)}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=_e.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,o=e.length;h<o;h++){const t=this.m_shape.getXY(e[h].vertex1);if(!(t.isEqualPoint2D(i)&&(r++,h+1<o))){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}}function ze(e,t,s,i,r){const n=new Ke(r);return n.m_shape=e,n.m_geometry=t,n.m_sortedVertices=s,n.m_bFixSelfTangency=i,n.fixRingOrientation_()}function We(e,t,s){const i=new Ke(s);return i.m_shape=e,i.m_geometry=t,i.m_sortedVertices=null,i.m_bFixSelfTangency=!1,i.fixRingOrientationForMp2sp_()}class Ze{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(e){let t=this.getEnd1(e),s=this.getEnd2(e);this.m_shape.getPrevVertex(t)===s&&(s=ue(t,t=s));const i=_e.getNAN(),r=_e.getNAN();return this.m_shape.queryXY(t,i),this.m_shape.queryXY(s,r),o(!i.equals(r)),i.y<r.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 je=class extends Z{constructor(e){super(),this.m_line1=new j,this.m_line2=new j,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,o=r.getSegment(i);if(o)h=o.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(i),this.m_line2,!0),o=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),a=e?this.m_seg1.getEndY():this.m_seg1.getStartY(),m=s?o.getEndY():o.getStartY(),g=Math.min(a,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=o.intersectionOfYMonotonicWithAxisX(l,0),n===h&&_("")}return n<h?-1:n>h?1:0}reset(){this.m_leftElm=-1}};class Qe{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 f;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 f}}class Ke{constructor(e){this.m_edges=null,this.m_shape=null,this.m_AET=new D,this.m_yScanline=0,this.m_geometry=f,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 je(this),this.m_AET.setComparator(this.m_sweepComparator)}fixRingOrientation_(){const e=this.fixRingOrientationImplMain_();return-1===this.m_pathOrientationIndex||this.fixRingOrientationImplSimplify_(),e}fixRingOrientationForMp2sp_(){return this.fixRingOrientationImplMain_(),-1===this.m_pathOrientationIndex?-1:this.fixRingOrientationImplMp2sp_()}processBunchForRingOrientationTest_(e){return this.processBunchForRingOrientationTestOddEven_(e)}processBunchForRingOrientationTestOddEven_(e){let t=!1;if(this.m_edges||(this.m_edges=new Ze(this.m_shape)),this.m_unknownNodes.length=0,this.processBunchForRingOrientationRemoveEdges_(e),!this.m_AET.isAutoBalancing()){let t=0;for(let s=0,i=e.length;s<i;s++){-1!==e[s]&&t++}(t>10||this.m_AET.getMaxDepthEver()>4)&&this.m_AET.enableBalancing()}for(let s=0,i=e.length;s<i;s++){const t=e[s];t!==f&&this.insertEdge_(t,-1)}for(let s=0;s<this.m_unknownNodes.length&&this.m_unknownRingOrientationCount>0;s++){const e=this.m_unknownNodes[s],i=this.m_AET.getElement(e),r=this.m_edges.getPath(i),n=this.m_shape.getPathUserIndex(r,this.m_pathOrientationIndex);let h=f;if(0===n){let s=this.m_AET.getPrev(e),i=e,r=!1;for(;s!==D.st_nullNode();){const e=this.m_AET.getElement(s),t=this.m_edges.getPath(e);if(0!==this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){h=t;break}i=s,s=this.m_AET.getPrev(s)}if(s===D.st_nullNode())r=!0,s=i;else{const e=this.m_AET.getElement(s);r=this.m_edges.isBottomUp(e),s=this.m_AET.getNext(s),r=!r}do{const e=this.m_AET.getElement(s),n=this.m_edges.getPath(e);if(0===this.m_shape.getPathUserIndex(n,this.m_pathOrientationIndex)){if(r!==this.m_edges.isBottomUp(e)){const e=this.m_shape.getFirstVertex(n);this.m_shape.reverseRingInternal(e),this.m_shape.setLastVertex(n,this.m_shape.getPrevVertex(e)),t=!0}if(this.m_shape.setPathUserIndex(n,this.m_pathOrientationIndex,r?3:2),!r){let e=this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex);2===e?(h=this.m_shape.getPathUserIndex(h,this.m_pathParentsIndex),e=this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex),o(3===e)):o(3===e);const t=this.m_shape.getPathUserIndex(h,this.m_pathParentageIndex);this.m_shape.setPathUserIndex(h,this.m_pathParentageIndex,n),this.m_shape.setPathUserIndex(n,this.m_pathParentageIndex,t),this.m_shape.setPathUserIndex(n,this.m_pathParentsIndex,h)}if(this.m_unknownRingOrientationCount--,!this.m_unknownRingOrientationCount)return t}h=n,i=s,s=this.m_AET.getNext(s),r=!r}while(i!==e)}}return t}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]=f):n=-1!==i?i:r,-1!==n&&(this.insertEdge_(s,n)||this.m_AET.deleteNode(n),e[t]=f)}}dbgVerifyRingOrientation_(){}insertEdge_(e,t){const s=_e.getNAN(),i=_e.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_(){const e=[],t=[];let s=-1,i=-1;const r=new _e;let n=f,h=f,a=-1;const m=new Qe(this);for(let o=m.next();o!==f;o=m.next()){const m=new _e;this.m_shape.queryXY(o,m);const g=this.m_shape.getPathFromVertex(o);if(r.equals(m)&&h===g){if(-1===i&&(s=this.m_shape.createPathUserIndex(),this.m_shape.fillPathUserIndexForGeometry(this.m_geometry,s,-1),i=this.m_shape.createUserIndex(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,i,-1)),-1===a){a=t.length,this.m_shape.setUserIndex(n,i,a),t.push(1);-1===this.m_shape.getPathUserIndex(g,s)&&(this.m_shape.setPathUserIndex(g,s,n),e.push(g))}this.m_shape.setUserIndex(o,i,a),t[t.length-1]++}else a=-1,r.assign(m);n=o,h=g}if(0===e.length)return!1;o(-1!==s);for(let o=0,g=e.length;o<g;o++){const r=e[o];let n=this.m_shape.getPathUserIndex(r,s);const h=this.m_shape.getUserIndex(n,i),a=[],m=[];a.push(n),m.push(h);for(let e=this.m_shape.getNextVertex(n);e!==n;e=this.m_shape.getNextVertex(e)){const s=e,r=this.m_shape.getUserIndex(s,i);if(-1!==r){if(0===m.length){m.push(r),a.push(s);continue}if(m.at(-1)===r){const h=a.at(-1);this.m_shape.peelALoopIntoAPath(h,s),this.m_shape.setUserIndex(e,i,-1),t[r]--,1===t[r]&&(t[r]=0,m.pop(),a.pop()),n=h,e=h}else a.push(e),m.push(r)}}}return this.m_shape.removePathUserIndex(s),this.m_shape.removeUserIndex(i),this.m_shape.dbgVerifyVertexCounts(),!0}progress_(e=!1){}fixRingOrientationImplMain_(){const e={stack:[],error:void 0,hasError:!1};try{let t,s=!1;const i=Ve(e,xe((()=>{this.m_sortedVerticesArray=null})),!1);if(null===this.m_sortedVertices){const e=this.m_shape.getPointCount(this.m_geometry);t=new w(0);for(let s=this.m_shape.getFirstPath(this.m_geometry);s!==f;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 this.m_shape.reverseRingInternal(t),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!==f;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=_e.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 Qe(this);for(let e=h.next();e!==f&&(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{ve(e)}}fixRingOrientationImplSimplify_(){const e=[];for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==f;)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!==f;){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!==f;e=this.m_shape.getNextPath(e),--i){if(this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex)!==t){s=f;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,B),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_(){const e=this.m_shape.createPathUserIndex();let t=0;const s=[];for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;)if(this.progress_(),3===this.m_shape.getPathUserIndex(i,this.m_pathOrientationIndex)){this.m_shape.setExterior(i,!0),this.m_shape.setPathUserIndex(i,e,t),t++;for(let e=this.m_shape.getPathUserIndex(i,this.m_pathParentageIndex);e!==f;){const t=this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex);s.push(e),this.m_shape.setExterior(e,!1),this.m_shape.setPathUserIndex(e,this.m_pathParentageIndex,i),e=t}let r=i,n=s.length,h=t;for(let t=this.m_shape.getNextPath(i);n>0&&t!==f;t=this.m_shape.getNextPath(t),--n){if(this.m_shape.getPathUserIndex(t,this.m_pathParentageIndex)!==i){r=f;break}r=t,this.m_shape.setPathUserIndex(t,e,-h),h++}if(0!==n){r=i,h=t;for(let t=0,i=s.length;t<i;t++){const i=s[t];this.m_shape.setPathUserIndex(i,e,-h),h++,this.m_shape.setPathUserIndex(i,this.m_pathParentageIndex,B)}r=i}t=h,s.length=0,i=this.m_shape.getNextPath(r)}else i=this.m_shape.getNextPath(i);return this.m_shape.removePathUserIndex(this.m_pathOrientationIndex),this.m_shape.removePathUserIndex(this.m_pathParentageIndex),this.m_shape.removePathUserIndex(this.m_pathParentsIndex),e}}function Je(e,t,s,i,r,n){const h=new $e(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 $e{constructor(e){this.m_shape=null,this.m_geometry=f,this.m_sortedVertices=new R,this.m_bunchEdgeEndPoints=[],this.m_bunchEdgeCenterPoints=[],this.m_bunchEdgeIndices=[],this.m_knownSimpleResult=-1,this.m_sortedVerticesListIndex=-1,this.m_polylineDegeneracies=f,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 _e;this.m_shape.queryXY(s,i);const r=new _e,n=this.m_bunchEdgeEndPoints[t];if(this.m_shape.queryXY(n,r),i.equals(r))return 0;const h=this.m_bunchEdgeCenterPoints[e],o=new _e;this.m_shape.queryXY(h,o);const a=this.m_bunchEdgeCenterPoints[t],m=new _e;this.m_shape.queryXY(a,m);const g=new _e;g.setSub(i,o);const l=new _e;l.setSub(r,m),(g.isZero()||l.isZero())&&_("");return _e.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,o=this.m_shape.getNextVertex(n)===i,a=new E,m=new _e;h?(this.m_shape.querySegment(r,a,!1,!0),m.assign(a.get().getTangent(0))):(this.m_shape.querySegment(s,a,!1,!0),m.assign(a.get().getTangent(1)),m.negateThis());const g=new _e;o?(this.m_shape.querySegment(n,a,!1,!0),g.assign(a.get().getTangent(0))):(this.m_shape.querySegment(i,a,!1,!0),g.assign(a.get().getTangent(1)),g.negateThis()),(m.isZero()||g.isZero())&&_("");return _e.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!==f){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,f),this.m_shape.setLastVertex(t,f)}}}}processBunch_(){let e=!1;const t=new _e(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)!==B&&(this.m_bunchEdgeEndPoints.push(n),this.m_shape.setUserIndex(n,this.m_userIndexSortedAngleIndexToVertex,B),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++));this.m_shape.getUserIndex(h,this.m_userIndexSortedAngleIndexToVertex)!==B&&(this.m_bunchEdgeEndPoints.push(h),this.m_shape.setUserIndex(h,this.m_userIndexSortedAngleIndexToVertex,B),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],o=this.m_bunchEdgeEndPoints[n],a=this.m_bunchEdgeEndPoints[h];let m=this.m_shape.getNextVertex(o),g=!1;this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(o),g=!0);let l=this.m_shape.getNextVertex(a),d=!1;this.m_shape.isEqualXYPoint2D(l,e)||(l=this.m_shape.getPrevVertex(a),d=!0);const _=g?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=d?this.m_shape.getPrevVertex(l):this.m_shape.getNextVertex(l);let u=!1;(this.removeSpike_(m)||this.removeSpike_(l)||this.removeSpike_(o)||this.removeSpike_(a)||this.removeSpike_(_)||this.removeSpike_(p))&&(u=!0),m!==l&&(!u&&this.m_shape.isEqualXY(o,a)&&(u=this.resolveOverlap_(g,d,m,o,l,a)),!u&&this.m_shape.isEqualXY(_,p)&&(u=this.resolveOverlap_(!g,!d,m,_,l,p)),!u&&this.m_shape.isEqualXY(o,p)&&(u=this.resolveOverlap_(g,!d,m,o,l,p)),!u&&this.m_shape.isEqualXY(_,a)&&(u=this.resolveOverlap_(!g,d,m,_,l,a))),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],o=this.m_bunchEdgeEndPoints[n];let a=this.m_shape.getNextVertex(h);this.m_shape.isEqualXYPoint2D(a,e)||(a=this.m_shape.getPrevVertex(h));let m=this.m_shape.getNextVertex(o);this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(o));const g=this.getDirection_(a,h),l=this.getDirection_(m,o),d=g?this.m_shape.getPrevVertex(a):this.m_shape.getNextVertex(a),_=l?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=this.detectAndResolveCrossOver_(g,l,h,a,d,o,m,_);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 Et(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 w(0);this.m_shape.dbgVerifyMonotone();for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;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,h=!1;do{h=!1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=this.m_sortedVertices.getFirst(this.m_sortedVerticesListIndex);const t=new _e(0,0);this.m_firstCoincidentVertex!==R.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(this.m_firstCoincidentVertex),t);let s=0,i=this.m_firstCoincidentVertex;for(;i!==R.st_nullNode()&&(i=this.m_sortedVertices.getNext(i),i!==R.st_nullNode());){this.progress_();const e=this.m_sortedVertices.getData(i),r=_e.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!==R.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(i),r),e&&(h=!0)}t.setCoordsPoint2D(r),this.m_firstCoincidentVertex=i,s=0}}if(this.m_nextVertexToProcess=-1,s>0){this.processBunch_()&&(h=!0)}r++>10&&n(""),h&&this.fixOrphanVertices_(),this.cleanupSpikes_()&&(h=!0),e||=h}while(h);return this.m_shape.dbgVerifyMonotone(),this.m_shape.dbgVerifyCurves(),this.m_shape.removeUserIndex(this.m_userIndexSortedIndexToVertex),this.m_shape.removeUserIndex(this.m_userIndexSortedAngleIndexToVertex),e=ze(this.m_shape,this.m_geometry,this.m_sortedVertices,this.m_bFixSelfTangency,this.m_progressTracker)||e,this.m_shape.dbgVerifyCurves(),e}getDirection_(e,t){return this.m_shape.getNextVertex(t)!==e}detectAndResolveCrossOver_(e,t,s,i,r,n,h,o){if(i===h)return this.removeAngleSortInfo_(s),this.removeAngleSortInfo_(n),-1;const a=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(o,this.m_userIndexSortedAngleIndexToVertex),d=new Array(8),_=new Array(4);d[0]=0,_[0]=a,d[1]=0,_[1]=m,d[2]=1,_[2]=g,d[3]=1,_[3]=l;for(let u=1;u<4;u++){const e=_[u],t=d[u];let s=u-1;for(;s>=0&&_[s]>e;)_[s+1]=_[s],d[s+1]=d[s],s--;_[s+1]=e,d[s+1]=t}let p=0;if(d[0]&&(p|=1),d[1]&&(p|=2),d[2]&&(p|=4),d[3]&&(p|=8),5!==p&&10!==p)return 0;if(e!==t&&(o=ue(n,n=o)),e)this.m_shape.setNextVertex(o,i),this.m_shape.setPrevVertex(i,o),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(o,i),this.m_shape.setNextVertex(i,o),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=ue(s,s=r),n=ue(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,o=t?r:n,a=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(o);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 d=!1;this.m_shape.setNextVertex(h,o),this.m_shape.setNextVertex(o,h),this.m_shape.setPrevVertex(a,m),this.m_shape.setPrevVertex(m,a);let _=m;for(;_!==o;){const e=this.m_shape.getPrevVertex(_),t=this.m_shape.getNextVertex(_);if(this.m_shape.setPrevVertex(_,t),this.m_shape.setNextVertex(_,e),d||=_===h,this.m_bHasSegments&&_!==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}_=t}let p=null;if(!d){const e=this.m_shape.getPrevVertex(o),t=this.m_shape.getNextVertex(o);if(this.m_shape.setPrevVertex(o,t),this.m_shape.setNextVertex(o,e),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(o);p=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null)}}let u=-1,c=-1;if(this.m_bHasSegmentParentage&&(u=d?this.m_shape.getSegmentParentage(h):this.m_shape.getSegmentParentage(o),c=this.m_shape.getSegmentParentage(a)),this.transferVertexData_(o,h),this.beforeRemoveVertex_(o,!0),this.m_shape.removeVertexInternal(o,!0),this.removeAngleSortInfo_(h),this.transferVertexData_(m,a),this.beforeRemoveVertex_(m,!0),this.m_shape.removeVertexInternal(m,!0),this.removeAngleSortInfo_(a),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageAndBreak(h,u,!0),this.m_shape.setSegmentParentageAndBreak(a,c,!0)),p){const e=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(e,p)}}return!0}cleanupSpikes_(){let e=!1;for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==f;){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===f)break;h?(e=!0,i=s,r=0,n=this.m_shape.getPathSize(t)):(i=s,r++)}t=s}return e}checkAndCleanupSpike_(e,t){const s={v:f,bModified:!1};let i=this.m_shape.getPrevVertex(t),r=this.m_shape.getNextVertex(t),n=f,h=f;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===f)return s.v=r,s;s.bModified=!0;for(let o=this.m_shape.getNextVertex(n);this.beforeRemoveVertex_(o,!1),o!==h;o=this.m_shape.getNextVertex(o));if(n===t)return this.m_polylineDegeneracies!==f?this.m_shape.movePath(this.m_polylineDegeneracies,f,e):this.m_shape.removePath(e),s.v=f,s;{const e=this.m_shape.peelALoopIntoAPath(n,h);this.m_polylineDegeneracies!==f?this.m_shape.movePath(this.m_polylineDegeneracies,f,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=f,r=f;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===f)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===f)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,f,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,f)}let t=0;for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;){const s=this.m_shape.getFirstVertex(i);if(s===f||this.m_shape.getPathFromVertex(s)!==f){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)!==f)continue;const r=[!1],n=this.m_shape.insertClosedPath(this.m_geometry,f,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!==f;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){}}var et=a,tt=h,st=r;function it(e){switch(e){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 0:return 0;default:o(0,"unrecognized cut side")}return 3}function rt(){return{unsplitBehavior:0,allCrossRoadsImpassable:!1,ogcRule:!1}}function nt(e,t,s,i){return new Et(i).autoCompleteImpl(e,t,s)}function ht(e,t,s,r,n,h,o){const a=new Et(n);a.m_bOGCOutput=!0;const m=e.getGeometryType()===i.enumPolygon&&1===e.getFillRule()&&!v(r);return a.planarSimplifyImpl_(e,t,m,s,r,n,h,o)}function ot(e,t,s,i,r,n,h,o){return new Et(n).planarSimplifyImpl_(e,t,s,i,r,n,h,o)}function at(e,t,s,i){const r=new Et(i),n=new c,h=n.addGeometry(t),a=r.planarSimplifyNoCrackingAndCluster(e,n,h,s);o(a,"planar_simplify_no_cracking_and_cluster");return n.getGeometry(h)}function mt(e,t,s,i,r,n,h){return o(0),{}}function gt(e,t,s,i){return o(0),{}}function lt(e,t,s){return yt(e,t,s)}function dt(e,t,s,r){if(e.isEmpty()||t.isEmpty()||e.getDimension()>t.getDimension())return St(Ct(e),e,t,"-");const n=new N;e.queryEnvelope(n);const h=new N;t.queryEnvelope(h);const o=new N;o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=h.clone(),g=H(a);if(m.inflateCoords(g,g),!n.isIntersecting(m))return St(Ct(e),e,t,"-");const l=new Et(r),d=new c,_=d.addGeometry(Ct(e)),p=d.addGeometry(Ct(t));let u=0,f=0,I=null;if(d.hasCurves()){I=new ie;const e=d.getEnvelope2D(r);f=Q(a.total());const t=K(a.total(),e);u=re(t,f),J(d,t,a.total(),12e3,I,null,r)}l.setEditShapeCrackAndCluster(d,a.add(u));const E=l.difference(_,p);null!==I&&I.stitchCurves(d,E,f,!0);const P=St(d.getGeometry(E),e,t,"-");return et(P.getGeometryType())&&(P.getImpl().setIsSimple(4,a.total()),P.getGeometryType()===i.enumPolygon&&P.getImpl().updateOGCFlagsProtected()),P}function _t(e,t,s,r){if(e.getDimension()>t.getDimension())return St(Ct(e),e,t,"^");if(e.getDimension()<t.getDimension())return St(Ct(t),e,t,"^");if(e.isEmpty())return St(Ct(t),e,t,"^");if(t.isEmpty())return St(Ct(e),e,t,"^");const n=new N;e.queryEnvelope(n);const h=new N;t.queryEnvelope(h);const o=new N;o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=new Et(r),g=new c,l=g.addGeometry(Ct(e)),d=g.addGeometry(Ct(t));let _=0,p=null;if(g.hasCurves()){p=new ie;const e=g.getEnvelope2D(r);_=Q(a.total());const t=K(a.total(),e);J(g,t,a.total(),12e3,p,null,r)}m.setEditShapeCrackAndCluster(g,a);const u=m.symmetricDifference(l,d);null!==p&&p.stitchCurves(g,u,_,!0);const f=St(g.getGeometry(u),e,t,"^");return et(f.getGeometryType())&&(f.getImpl().setIsSimple(4,a.total()),f.getGeometryType()===i.enumPolygon&&f.getImpl().updateOGCFlagsProtected()),f}function pt(e,t,s){return Pt(e,t,s,!0)}function ut(e,t,s){return e.isEmpty()||t.isEmpty()?e.createInstance():me(s,e,t)?new k({copy:ge(e,t)}):e.createInstance()}function ct(e,t,s,r){const n=N.constructEmpty();e.queryEnvelope(n);const h=N.constructEmpty();t.queryEnvelope(h);const o=N.constructEmpty();o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=new N(h),g=H(a);if(m.inflateCoords(g,g),!n.isIntersecting(m)){if(e.getDimension()<=t.getDimension())return St(Ct(e.createInstance()),e,t,"&");if(e.getDimension()>t.getDimension())return St(Ct(t.createInstance()),e,t,"&")}const l=new Et(r),d=new c,_=d.addGeometry(Ct(e)),p=d.addGeometry(Ct(t));let u=0,f=0,I=null;if(d.hasCurves()){I=new ie;const e=d.getEnvelope2D(r);f=Q(a.total());const t=K(a.total(),e);u=re(t,f),J(d,t,a.total(),12e3,I,null,r)}l.setEditShapeCrackAndCluster(d,a.add(u));const E=l.intersection(_,p);null!==I&&I.stitchCurves(d,E,f,!0);const P=St(d.getGeometry(E),e,t,"&");return et(P.getGeometryType())&&(P.getImpl().setIsSimple(4,a.total()),P.getGeometryType()===i.enumPolygon&&P.getImpl().updateOGCFlagsProtected()),P}function ft(e,t,s,r){const n=new Array(3),h=N.constructEmpty();e.queryEnvelope(h);const o=N.constructEmpty();t.queryEnvelope(o);const a=N.constructEmpty();a.setCoords({env2D:h}),a.mergeEnvelope2D(o);const m=x(s,a,!0),g=new N(o),l=H(m);if(g.inflateCoords(l,l),!h.isIntersecting(g)){if(e.getDimension()<=t.getDimension()){const s=St(Ct(e.createInstance()),e,t,"&");return n[s.getDimension()]=s,n}if(e.getDimension()>t.getDimension()){const s=St(Ct(t.createInstance()),e,t,"&");return n[s.getDimension()]=s,n}}const d=new Et(r),_=new c,p=_.addGeometry(Ct(e)),u=_.addGeometry(Ct(t));let f=0,I=0,E=null;if(_.hasCurves()){E=new ie;const e=_.getEnvelope2D(r);I=Q(m.total());const t=K(m.total(),e);f=re(t,I),J(_,t,m.total(),12e3,E,null,r)}d.setEditShapeCrackAndCluster(_,m.add(f)),_.dbgVerifyCurves();const P=d.intersectionEx(p,u);for(const c of P){null!==E&&E.stitchCurves(_,c,I,!1);const s=St(_.getGeometry(c),e,t,"&");et(s.getGeometryType())&&(s.getImpl().setIsSimple(4,m.total()),s.getGeometryType()===i.enumPolygon&&s.getImpl().updateOGCFlagsProtected()),n[s.getDimension()]=s}return null!==E&&E.clearStitcher(_),n}function xt(e,t,i,r,n,h=!1){0===t&&s("not enough geometries to dissolve");let o=0;for(let s=0,u=t;s<u;s++)o=Math.max(e[s].getDimension(),o);if(2===o||1===o)return new Et(r).dissolveMultiPaths_(o,!1,e,t,i,n,h);let a=0,m=-1;for(let s=0,u=t;s<u;s++)e[s].getDimension()===o&&(-1===m&&(m=s),e[s].isEmpty()||(m=s,a++));if(a<2)return Ct(e[m]);const g=u.constructEmpty(),l=new c;let d=f;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===o&&!e[s].isEmpty()){d===f?d=l.addGeometry(Ct(e[s])):l.appendGeometry(d,Ct(e[s]));const t=u.constructEmpty();e[s].queryLooseEnvelope(t),g.mergeEnv3D(t)}const _=x(i,g.getEnvelope2D(),!0),p=new Et(r);if(h){const e=I(i,g.getEnvelopeZs(),!0);return p.planarSimplify3DImpl_(l,_,e,0,!0)}return p.m_bOGCOutput=!0,p.planarSimplifyMultiPoints(l,_,!1,-1)}function It(e,t,i,r,n,h=!1){t<2&&s("not enough geometries to dissolve");let o=0;for(let s=0,u=t;s<u;s++)o=Math.max(e[s].getDimension(),o);if(2===o||1===o)return new Et(r).dissolveMultiPaths_(o,!0,e,t,i,n,h);const a=u.constructEmpty(),m=new c;let g=f,l=0,d=-1;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===o&&(-1===d&&(d=s),!e[s].isEmpty())){d=s,g===f?g=m.addGeometry(Ct(e[s])):m.appendGeometry(g,Ct(e[s]));const t=u.constructEmpty();e[s].queryLooseEnvelope(t),a.mergeEnv3D(t),l++}if(l<2)return Ct(e[d]);const _=0===o?i:null,p=x(_,a.getEnvelope2D(),!0),E=new Et(r);if(h){const e=I(_,a.getEnvelopeZs(),!0);return E.m_bOGCOutput=!0,E.planarSimplify3DImpl_(m,p,e,0,!0)}return E.planarSimplifyMultiPoints(m,p,!0,-1)}class Et{constructor(e){this.m_topoGraph=null,this.m_maskLookup=[],this.m_dummyPt1=_e.getNAN(),this.m_dummyPt2=_e.getNAN(),this.m_fromEdgeForPolylines=f,this.m_progressCounter=0,this.m_bOGCOutput=!1,this.m_progressTracker=e}linesToPolygonsImpl(t,s){let i=0,r=0,n=null;if(t.hasCurves()){n=new ie;const e=t.getEnvelope2D(this.m_progressTracker);r=Q(s.total());const h=K(s.total(),e);i=re(h,r),J(t,h,s.total(),12e3,n,null,this.m_progressTracker)}this.setEditShapeCrackAndCluster(t,s.add(i));const h=this.m_topoGraph.createUserIndexForChains(),o=this.m_topoGraph.getFirstChain();this.m_topoGraph.setChainUserIndex(o,h,1);for(let e=this.m_topoGraph.getChainFirstIsland(o);e!==f;e=this.m_topoGraph.getChainNextInParent(e))this.m_topoGraph.setChainUserIndex(e,h,1);const a=[];for(let e=this.m_topoGraph.getFirstChain();e!==f;e=this.m_topoGraph.getChainNext(e)){if(1===this.m_topoGraph.getChainUserIndex(e,h))continue;this.m_topoGraph.setChainUserIndex(e,h,1);for(let t=this.m_topoGraph.getChainFirstIsland(e);t!==f;t=this.m_topoGraph.getChainNextInParent(t))this.m_topoGraph.setChainUserIndex(t,h,1);if(0===this.m_topoGraph.getChainArea(e))continue;const s=this.m_topoGraph.extractPolygonFromChainAndIslands(t,f,e,f);null!=n&&n.stitchCurves(t,s,r,!1);const i=t.getGeometry(s);a.push(i)}return new e(a)}autoCompleteImpl(t,s,i){let r=0,n=0,h=null;if(t.hasCurves()){h=new ie;const e=t.getEnvelope2D(this.m_progressTracker);n=Q(i.total());const s=K(i.total(),e);r=re(s,n),J(t,s,i.total(),12e3,h,null,this.m_progressTracker)}this.setEditShapeCrackAndCluster(t,i.add(r));const o=this.m_topoGraph.getGeometryID(s),a=this.m_topoGraph.createUserIndexForChains(),m=this.m_topoGraph.getFirstChain();this.m_topoGraph.setChainUserIndex(m,a,1);for(let e=this.m_topoGraph.getChainFirstIsland(m);e!==f;e=this.m_topoGraph.getChainNextInParent(e))this.m_topoGraph.setChainUserIndex(e,a,1);const g=[];for(let e=this.m_topoGraph.getFirstChain();e!==f;e=this.m_topoGraph.getChainNext(e)){if(1===this.m_topoGraph.getChainUserIndex(e,a))continue;this.m_topoGraph.setChainUserIndex(e,a,1);for(let t=this.m_topoGraph.getChainFirstIsland(e);t!==f;t=this.m_topoGraph.getChainNextInParent(t))this.m_topoGraph.setChainUserIndex(t,a,1);if(0!==this.m_topoGraph.getChainParentage(e))continue;const s=this.m_topoGraph.getChainHalfEdge(e);let i=s,r=!1;do{const t=this.m_topoGraph.getHalfEdgeTwin(i);if(this.m_topoGraph.getHalfEdgeChain(t)!==e&&this.m_topoGraph.getHalfEdgeParentage(i)&o){r=!0;break}i=this.m_topoGraph.getHalfEdgeNext(i)}while(i!==s);if(!r)continue;if(0===this.m_topoGraph.getChainArea(e))continue;const m=this.m_topoGraph.extractPolygonFromChainAndIslands(t,f,e,f);null!==h&&h.stitchCurves(t,m,n,!1);const l=t.getGeometry(m);g.push(l)}return new e(g)}setEditShape(e,t=!1){null===this.m_topoGraph&&(this.m_topoGraph=new Ye),this.m_topoGraph.setEditShape(e,this.m_progressTracker,!0,t)}setEditShapeCrackAndCluster(e,t){$(e,t,this.m_progressTracker,!0,!1);for(let s=e.getFirstGeometry();s!==f;s=e.getNextGeometry(s))e.getGeometryType(s)===i.enumPolygon&&Je(e,s,-1,this.m_bOGCOutput,f,this.m_progressTracker);this.setEditShape(e)}setHalfEdgeOrientations_(e,t){const s=this.m_topoGraph.getShape();for(let i=s.getFirstGeometry();i!==f;i=s.getNextGeometry(i))if(i===t)for(let t=s.getFirstPath(i);t!==f;t=s.getNextPath(t)){let i=s.getFirstVertex(t);if(i===f)continue;let r=s.getNextVertex(i);for(;r!==f;){const t=this.m_topoGraph.getClusterFromVertex(i),n=this.m_topoGraph.getClusterFromVertex(r),h=this.m_topoGraph.getHalfEdgeConnector(t,n);if(h!==f){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 E,n=s.insertPath(e,f);t.push(t[0]);const h=t.length;let o=f;for(let a=0;a<h;a++){const e=t[a];if(o=s.addVertex(n,e),!i)continue;const m=this.m_topoGraph.getClusterFromVertex(e);if(a>0&&this.m_topoGraph.isBreakNode(m)&&s.setSegmentParentageBreakVertex(o,!0),a<h-1){const e=this.m_topoGraph.getHalfEdgeConnector(m,this.m_topoGraph.getClusterFromVertex(t[a+1])),i=this.m_topoGraph.getSegmentParentage(e);s.setSegmentParentageAndBreak(o,i,a>0||this.m_topoGraph.isBreakNode(m)),this.m_topoGraph.isHalfEdgeCurve(e)&&(this.m_topoGraph.querySegmentXY(e,r),s.setSegmentToIndex(s.getVertexIndex(o),r.get().clone()))}}if(i){const e=this.m_topoGraph.getClusterFromVertex(t[h-1]);this.m_topoGraph.isBreakNode(e)&&s.setSegmentParentageBreakVertex(o,!0)}s.setClosedPath(n,!0)}processPolygonCuts_(e,t,s,r){const n=this.m_topoGraph.getGeometryID(s),h=this.m_topoGraph.getGeometryID(r),o=[],a=this.m_topoGraph.getShape(),m=this.m_topoGraph.createUserIndexForHalfEdges();for(let g=this.m_topoGraph.getFirstCluster();g!==f;g=this.m_topoGraph.getNextCluster(g)){const s=this.m_topoGraph.getClusterHalfEdge(g);if(s===f)continue;let r=s;do{if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,m)){let s=r,g=r,l=!1,d=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(o.push(r),-1!==e){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){d|=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=a.createGeometry(i.enumPolygon);this.flushVertices_(e,o),-1!==t&&a.setGeometryUserIndex(e,t,d)}o.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!==f;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,h){const o=this.m_topoGraph.getShape().getGeometryType(s),a=this.m_topoGraph.getShape().getGeometryType(i),m=r(o),g=r(a);if(2!==m||1!==g)if(1!==m||1!==g)n("");else{new Ht(this,e,t,s,i,h).Do()}else this.cutPolygonPolyline_(t,s,i,h)}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 P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(h(t)){const t=new S({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(e,t,s,i){o(t>0);const r=new c;let n=0,h=-1;for(let o=0,a=t;o<a;o++)2===e[o].getDimension()&&(-1===h&&(h=o),e[o].isEmpty()||(n++,r.addGeometry(e[o])));return 0===n?(o(h>=0),this.normalizeInputGeometry(e[h])):this.planarSimplifyPolygons(r,s,!0,!1,-1,!0)}dissolveMultiPaths_(e,t,s,r,n,g,l){o(e>=1&&e<=2),o(r>0);const d=8&g?1:2,_=u.constructEmpty();let p=0,E=-1,y=!0;for(let h=0,o=r;h<o;h++)if(s[h].getDimension()===e&&(-1===E&&(E=h),!s[h].isEmpty())){E=h,p++;const t=u.constructEmpty();if(s[h].queryLooseEnvelope(t),_.mergeEnv3D(t),2===e&&y&&s[h].getGeometryType()===i.enumPolygon)if(16&g){const e=[0],t=s[h].getImpl().getIsSimple(0,e),i=this.m_bOGCOutput?5===t:G(t);y&&=i}else{const e=C(s[h],0);y&&=e}}if(p<2&&(o(E>=0),0===p||!(16&g)))return this.normalizeInputGeometry(s[E]);if(!y){const e=x(t?null:n,_.getEnvelope2D(),!0);return this.dissolveNonSimplePolygons(s,r,e,g)}const T=s.slice(0,r),F=x(n,_.getEnvelope2D(),!0),b=10*H(F);let w=new A(0,0);if(l&&(w=I(n,_.getEnvelopeZs(),!0)),1===p&&1===e&&2===d&&!t)return l?mt():this.m_bOGCOutput?ht(T[E],F,!1,-1,this.m_progressTracker,d,!1):ot(T[E],F,!1,!1,-1,this.m_progressTracker,d,!1);const U=new V;U.startConstruction();let k=2===e?3:4,D=0;for(let m=0,u=r;m<u;m++){if(T[m].getDimension()!==e||T[m].isEmpty())continue;let s=T[m].getGeometryType();if(s!==i.enumEnvelope){if(h(s)?(T[m]=this.normalizeInputGeometry(T[m]),s=i.enumPolyline):o(a(s)),1===e){o(s===i.enumPolyline);let e=-1;if(l)o(0,"3d not implemented yet");else{const t=[0];e=T[m].getImpl().getIsSimple(F.total(),t)}if(this.m_bOGCOutput?5!==e:!G(e))if(t)k=-1;else{l?o(0,"3d not implemented yet"):this.m_bOGCOutput?T[m]=ht(T[m],F,!1,-1,this.m_progressTracker,d,!1):T[m]=ot(T[m],F,!1,!1,-1,this.m_progressTracker,d,!1);const e=[0];o(G(T[m].getImpl().getIsSimple(F.total(),e)))}}else{o(s===i.enumPolygon);const e=[0],t=T[m].getImpl().getIsSimple(0,e);o(v(t))}const r=T[m].getImpl();for(let e=0,t=r.getPathCount();e<t;e++){const t=N.constructEmpty();r.queryLoosePathEnvelope(e,t),t.inflateCoords(b,b),U.addEnvelope(D,t),D++}}else{o(s===i.enumEnvelope);const e=N.constructEmpty();T[m].queryLooseEnvelope(e),e.inflateCoords(b,b),U.addEnvelope(D,e),D++,k=-1}}U.endConstruction();const B=D,O=pe(B,-2147483647),R=pe(B,-1);let L=0;E=-1,D=0;for(let h=0,m=r;h<m;h++){if(T[h].getDimension()!==e)continue;if(-1===E&&(E=h),T[h].isEmpty())continue;E=h,L++;const t=T[h].getGeometryType();if(a(t)){for(let e=0,t=T[h].getPathCount();e<t;e++)R[D]=h,O[D]=-e-1,D++}else o(t===i.enumEnvelope),R[D]=h,O[D]=-1,D++}if(L<2&&2===e)return o(E>=0),this.normalizeInputGeometry(T[E]);let Y=B;for(;U.next()&&Y>0;){this.progress_();const e=U.getHandleA(),t=U.getHandleB(),s=U.getElement(e),i=U.getElement(t);R[s]!==R[i]&&(O[s]<0&&(Y--,O[s]=-(O[s]+1)),O[i]<0&&(Y--,O[i]=-(O[i]+1)))}const M=new c;let X=!1,q=0;for(let h=0,u=r;h<u;h++){if(T[h].getDimension()!==e||T[h].isEmpty())continue;const t=T[h].getGeometryType(),s=q;let r=0,n=0;const g=a(t)?T[h]:null;for(let e=s,i=O.length;e<i&&R[e]===h;e++)O[e]>=0&&(r++,n+=g?g.getPathSize(O[e]):m(T[h])),q++;if(n>.95*m(T[h])){M.addGeometry(this.normalizeInputGeometry(T[h]));for(let e=s;e<q;e++)O[e]<0&&(O[e]=-(O[e]+1))}else{if(0===r){X=!0;continue}{X=!0,o(a(t)),o(null!=g);const e=new P({vd:T[h].getDescription()}),r=new S({vd:T[h].getDescription()}),n=t===i.enumPolygon?e:r;for(let t=s;t<q;t++)O[t]>=0&&n.addPath(g,O[t],!0);M.addGeometry(n)}}}let z;if(M.getFirstGeometry()!==f){const s=2===e,i=t?x(null,_.getEnvelope2D(),!0):F;let r=new A(0,0);if(l&&(r=t?I(null,_.getEnvelopeZs(),!0):w),2===e&&!(2&g)){M.collapseAllGeometriesToFirst();let e=0,t=null;if(M.hasCurves()&&!M.hasSegmentParentage()){t=new ie;const s=M.getEnvelope2D(this.m_progressTracker);e=Q(i.total());const r=K(i.total(),s);J(M,r,i.total(),12e3,t,null,this.m_progressTracker)}Me(M,M.getFirstGeometry(),i.total(),this.m_progressTracker),null!==t&&t.stitchCurves(M,f,e,!0)}if(l)z=this.planarSimplify3DImpl_(M,i,r,d,!0);else if(2===e)z=this.planarSimplifyPolygons(M,i,s,t,-1,!1);else{const e=rt();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=d,z=this.planarSimplifyPolylines(M,i,t,e,-1)}if(!X){const e=[0];k=z.getImpl().getIsSimple(i.total(),e)}}else o(X),o(E>=0),z=2===e?new P({vd:T[E].getDescription()}):new S({vd:T[E].getDescription()});if(X){let e=0;for(let t=0,s=O.length;t<s;t++){const s=R[t];if(!(s<0)&&O[t]<0){const i=T[s].getGeometryType(),r=a(i)?T[s]:null;if(r){const s=-(O[t]+1);e+=r.getPathSize(s)}else e+=4}}z.reserve(z.getPointCount()+e);for(let t=0,s=O.length;t<s;t++){const e=R[t];if(!(e<0)&&O[t]<0){const s=T[e].getGeometryType(),r=a(s)?T[e]:null;if(r){const e=-(O[t]+1);z.addPath(r,e,!0)}else s===i.enumEnvelope?z.addEnvelope(T[e],!1):(o(h(s)),z.addSegment(T[e],!0))}}}let W=0;if(2===e?-1!==k&&(k=3,W=t?0:F.total()):(o(1===e),t||-1===k||(W=F.total())),l||z.getImpl().setIsSimple(k,W),!t&&X)if(2===e){if(!l)return(new qt).execute(z,n,!1,this.m_progressTracker);o(0,"3d not yet implemented")}else 1===e&&1!==d&&(z=l?gt():at(this.m_bOGCOutput,z,d,this.m_progressTracker),z.getImpl().setIsSimple(k,W));return z}dissolveTopoGraphCommonEdges_(){const e=this.m_topoGraph.createUserIndexForHalfEdges(),t=[];for(let s=this.m_topoGraph.getFirstCluster();s!==f;s=this.m_topoGraph.getNextCluster(s)){const i=this.m_topoGraph.getClusterHalfEdge(s);let r=i;if(i!==f)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(e,t,s,i){let r=Ge(),n=f;for(let o=this.m_topoGraph.getClusterVertexIterator(e);o!==f;o=this.m_topoGraph.incrementVertexIterator(o)){const e=this.m_topoGraph.getVertexFromVertexIterator(o),i=t.getUserIndex(e,s);i>=0&&i<r&&(r=i,n=e)}o(n!==f);let h=t.getUserIndex(n,i);return h>0&&(t.setUserIndex(n,i,--h),0===h&&t.setUserIndex(n,s,-1)),n}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 o=h.hasSegmentParentage(),a=new E;for(let i=h.getFirstPath(e);i!==f;i=h.getNextPath(i)){const e=h.getFirstVertex(i);this.m_topoGraph.getClusterFromVertex(e);const m=this.m_topoGraph.getHalfEdgeFromVertex(e);if(m===f)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 d=h.insertPath(t,f);h.setClosedPath(d,!0);let _=m,p=e,u=this.m_topoGraph.getClusterFromVertex(p),c=1;do{this.progress_();const e=this.chooseVertexFromVertexCluster_(p,n),t=h.addVertex(d,e);if(this.m_topoGraph.isHalfEdgeCurve(_)&&(this.m_topoGraph.querySegmentXY(_,a),h.setSegmentToIndex(h.getVertexIndex(t),a.get().clone())),o){const e=this.m_topoGraph.getSegmentParentage(_);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(_,s,1),_=this.m_topoGraph.getHalfEdgeNext(_);do{i=1===c?h.getNextVertex(p):h.getPrevVertex(p),m=i!==f?this.m_topoGraph.getClusterFromVertex(i):f}while(m===u);const g=this.m_topoGraph.getHalfEdgeOrigin(_);if(g!==m){do{i=1===c?h.getPrevVertex(p):h.getNextVertex(p),m=i!==f?this.m_topoGraph.getClusterFromVertex(i):f}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(_!==m)}}topoOperationPolygonPolygonHelper_(e,t,s,i,r,n){this.progress_(!0),e!==f&&this.collectPolygonPathsPreservingFrom_(e,s,r,n,i),t!==f&&this.collectPolygonPathsPreservingFrom_(t,s,r,n,i);const h=new E,o=this.m_topoGraph.getShape();o.dbgVerifyCurves();const a=o.hasSegmentParentage();for(let m=this.m_topoGraph.getFirstCluster();m!==f;m=this.m_topoGraph.getNextCluster(m)){const e=this.m_topoGraph.getClusterHalfEdge(m);if(e===f)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=o.insertPath(s,f);o.setClosedPath(e,!0);let m=t;do{const t=this.m_topoGraph.getHalfEdgeVertexIterator(m);let s=f;if(t!==f)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=o.getNextVertex(s)}const g=this.chooseVertexFromVertexCluster_(s,i),l=o.addVertex(e,g);if(a){const e=this.m_topoGraph.getSegmentParentage(m),t=this.m_topoGraph.getHalfEdgeOrigin(m);o.setSegmentParentageAndBreak(l,e,this.m_topoGraph.isBreakNode(t))}if(this.m_topoGraph.isHalfEdgeCurve(m)&&(this.m_topoGraph.querySegmentXY(m,h),o.setSegmentToIndex(o.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),o=this.m_topoGraph.createUserIndexForHalfEdges();return this.topoOperationPolygonPolygonHelper_(e,t,h,s,o,-1),this.m_topoGraph.deleteUserIndexForHalfEdges(o),r||Je(n,h,3,this.m_bOGCOutput,f,this.m_progressTracker),h}topoOperationPolyline_(e,t){const s=rt();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(f,e,!1,s).first}topoOperationMultiPoint_(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,f);for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=f;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==f;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===f&&(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}intersection(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),h=r(s),a=r(i),m=this.m_topoGraph.getGeometryID(e),g=this.m_topoGraph.getGeometryID(t);o(m>=0),o(g>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(m|g),this.m_maskLookup[m|g]=!0;let l=f;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(l=e),2===h&&2===a?this.topoOperationPolygonPolygon_(e,t,l):1===h&&a>0||1===a&&h>0?this.topoOperationPolyline_(l,this.m_bOGCOutput):0===h||0===a?this.topoOperationMultiPoint_():void n("")}topoOperationPolygonPolygonEx(e,t,s){const r=this.m_topoGraph.getShape(),n=r.createGeometry(i.enumPolygon),h=r.createGeometry(i.enumPolyline),o=r.createGeometry(i.enumMultiPoint);this.dissolveTopoGraphCommonEdges_();let a=f;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(),d=new E;for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const e=this.m_topoGraph.getClusterHalfEdge(i);if(e===f)continue;let t=e;do{let e=this.m_topoGraph.getHalfEdgeUserIndex(t,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m),o=e|n;if(2===o){let a=this.m_topoGraph.getHalfEdgeParentage(t);if(this.isGoodParentage(a)){const _=r.insertPath(h,f);let p=t;const u=this.chooseVertexFromCluster_(i,s);let c=r.addVertex(_,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,d),r.setSegmentToIndex(r.getVertexIndex(c),d.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(_,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),o=e|n,2!==o)break;if(a=this.m_topoGraph.getHalfEdgeParentage(p),!this.isGoodParentage(a)){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,d),r.setSegmentToIndex(r.getVertexIndex(c),d.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!==f;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)){a===f&&(a=r.insertPath(o,f));const e=this.m_topoGraph.getClusterVertexIterator(i);let t=f;if(e!==f){t=this.m_topoGraph.getVertexFromVertexIterator(e);const i=this.chooseVertexFromVertexCluster_(t,s);r.addVertex(a,i)}}}this.m_topoGraph.deleteUserIndexForClusters(g),this.m_topoGraph.deleteUserIndexForHalfEdges(m),r.dbgVerifyCurves(),Je(r,n,3,this.m_bOGCOutput,f,this.m_progressTracker);const _=[f,f,f];return _[0]=o,_[1]=h,_[2]=n,_}topoOperationPolylinePolylineOrPolygonEx(e,t){const s=rt();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(f,e,!0,s)}topoOperationMultiPoint(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,f);for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=f;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==f;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===f&&(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(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=st(s),h=st(i),a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);o(a>=0),o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=f;if(this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=e),2===r&&2===h)return this.topoOperationPolygonPolygonEx(e,t,g);if(1===r&&h>0||1===h&&r>0){const{first:e,second:t}=this.topoOperationPolylinePolylineOrPolygonEx(g,this.m_bOGCOutput);return[t,e]}if(0===r||0===h){const e=[];return e.push(this.topoOperationMultiPoint()),e}n("")}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 o=this.m_topoGraph.getClusterVertexIterator(i);o!==f;o=this.m_topoGraph.incrementVertexIterator(o)){const i=this.m_topoGraph.getVertexFromVertexIterator(o),a=e.getPathFromVertex(i),m=e.getGeometryFromPath(a),g=this.m_topoGraph.getGeometryID(m),l=e.getFirstVertex(a),d=!!(g&s);d&&l===i&&(this.m_fromEdgeForPolylines=t);const _=e.getNextVertex(i);if(_!==f&&this.m_topoGraph.getClusterFromVertex(_)===r){if(n++,d){if(this.m_fromEdgeForPolylines===f&&l===_){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!==f&&this.m_topoGraph.getClusterFromVertex(s)===r&&(n--,d)){if(this.m_fromEdgeForPolylines===f&&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)*_e.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 f;const t=this.m_topoGraph.getHalfEdgeTwin(e);if(i===this.m_topoGraph.getHalfEdgeNext(t))return s}let r=i,n=f;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==f)return f;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 f;if(i===this.m_topoGraph.getHalfEdgePrev(t))return s}let r=i,n=f;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==f)return f;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}n("is_on_a_loop_")}restorePolylineParts(e,t,s,i,r,n,h,a,m,g){o(r===f&&n>=0&&h>=0||-1===n&&-1===h),o(-1===a&&1!==g.unsplitBehavior||-1!==a&&1===g.unsplitBehavior);const l=g.ogcRule,d=g.allCrossRoadsImpassable,_=1===g.unsplitBehavior,p=0===g.unsplitBehavior,u=this.m_topoGraph.getShape(),c=u.hasSegmentParentage();let x=e,I=this.m_topoGraph.getHalfEdgeTwin(x);const P=new E;this.m_fromEdgeForPolylines=f;let y=this.prevailingDirection(u,x),S=x,C=f,G=!1,H=!1,V=!1;if(!_)for(;;){const t=this.m_topoGraph.getHalfEdgePrev(x);if(t===I){V=!0;break}const i=this.m_topoGraph.getHalfEdgeNext(I);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(i))){G=!0;break}if(this.m_topoGraph.getHalfEdgeTwin(t)!==i){if(d){G=!0;break}if(x=this.tryMoveThroughCrossroadBackwards(x,!0),x===f){G=!0;break}I=this.m_topoGraph.getHalfEdgeTwin(x)}else x=t,I=i;if(1===this.m_topoGraph.getHalfEdgeUserIndex(x,s)){V=!0;break}if(x===e){C=e,H=!0;break}const r=this.getCombinedHalfEdgeParentage(x);if(!this.isGoodParentage(r))break;S=x,y+=this.prevailingDirection(u,x)}if(C===f){for(x=e,I=this.m_topoGraph.getHalfEdgeTwin(x),C=x;;){const e=this.m_topoGraph.getHalfEdgeNext(x),t=this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e));if(t){G=!0;break}if(e===I){V=!0;break}if(-1!==a){const e=this.m_topoGraph.getHalfEdgeOrigin(I);if(1===this.m_topoGraph.getClusterUserIndex(e,a)){G=!0;break}}const i=this.m_topoGraph.getHalfEdgePrev(I);if(this.m_topoGraph.getHalfEdgeTwin(e)!==i){if(t||d){G=!0;break}if(x=this.tryMoveThroughCrossroadForward(x,!0),x===f){G=!0;break}I=this.m_topoGraph.getHalfEdgeTwin(x)}else x=e,I=i;if(1===this.m_topoGraph.getHalfEdgeUserIndex(x,s)){V=!0;break}const r=this.getCombinedHalfEdgeParentage(x);if(!this.isGoodParentage(r))break;C=x,y+=this.prevailingDirection(u,x)}const t=this.m_topoGraph.getHalfEdgeOrigin(S);H=this.m_topoGraph.getHalfEdgeTo(C)===t}else if(this.m_fromEdgeForPolylines!==f){S=e,C=this.tryMoveThroughCrossroadBackwards(S,!1),o(C!==f);const t=this.m_topoGraph.getHalfEdgeTwin(S);this.m_topoGraph.getHalfEdgeNext(t)}let v=H;H||V||m&&(v=this.isOnALoop(e,s),v||(v=this.isOnALoop(I,s)));const N=y>=0;let T=!1;v&&G&&(H?(T=l,N&&(T||_||p)&&S!==e&&(o(!_),S=e,T=!1)):(_||N&&p)&&(S=e));let F=0;for(x=S;I=this.m_topoGraph.getHalfEdgeTwin(x),this.m_topoGraph.setHalfEdgeUserIndex(x,s,1),this.m_topoGraph.setHalfEdgeUserIndex(I,s,1),F++,x!==C;)x=d?this.m_topoGraph.getHalfEdgeNext(x):this.tryMoveThroughCrossroadForward(x,!1);N||(C=ue(S,S=C),C=this.m_topoGraph.getHalfEdgeTwin(C),S=this.m_topoGraph.getHalfEdgeTwin(S));let b=u.insertPath(t,f);x=S;const w=this.m_topoGraph.getHalfEdgeOrigin(S);let U;U=-1!==n?this.chooseVertexByOrder(w,u,n,h):this.chooseVertexFromCluster_(w,r),this.m_topoGraph.isStrongPathNode(w)&&u.setStrongPathStart(b,!0);let k=u.addVertex(b,U),D=k;-1!==i&&this.m_topoGraph.setClusterUserIndex(w,i,1);let B=0;const A=T?Math.trunc((F+1)/2):-1;let O=f,R=!0,L=f;for(;;){if(c){const e=this.m_topoGraph.getSegmentParentage(x),t=this.m_topoGraph.getHalfEdgeOrigin(x);u.setSegmentParentageAndBreak(D,e,R||this.m_topoGraph.isBreakNode(t))}R=!1,this.m_topoGraph.isHalfEdgeCurve(x)&&(this.m_topoGraph.querySegmentXY(x,P),u.setSegmentToIndex(u.getVertexIndex(D),P.get().clone())),O!==f&&-1!==h&&u.addToUserIndex(O,h,-1);const e=d?this.m_topoGraph.getHalfEdgeNext(x):this.tryMoveThroughCrossroadForward(x,!1),s=this.m_topoGraph.getHalfEdgeTo(x);let o;if(o=-1!==n?this.chooseVertexByOrder(s,u,n,h):this.chooseVertexFromCluster_(s,r),k=u.addVertex(b,o),L=s,-1!==i&&this.m_topoGraph.setClusterUserIndex(s,i,1),c&&this.m_topoGraph.isBreakNode(s)&&u.setSegmentParentageBreakVertex(k,!0),O=o,B++,T&&B===A&&(b=u.insertPath(t,f),k=u.addVertex(b,o),R=!0,-1!==h&&u.addToUserIndex(o,h,-1),O=f),x===C)break;x=e,D=k}L!==f&&this.m_topoGraph.isStrongPathNode(L)&&u.setStrongPathEnd(b,!0)}topoOperationPolylineSimplify_(e,t){return this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,t,s,r){o(t===f||e===f);const n=this.m_topoGraph.getShape(),h=t=>t=e===f?t===f?n.getFirstGeometry():n.getNextGeometry(t):t===f?e:f,a=n.createGeometry(i.enumPolyline);let m=-1;s&&(m=this.m_topoGraph.createUserIndexForClusters());const g=this.m_topoGraph.createUserIndexForHalfEdges(),l=t===f?n.createUserIndex():-1,d=t===f?n.createUserIndex():-1;let _=-1;if(1===r.unsplitBehavior){_=this.m_topoGraph.createUserIndexForClusters();for(let e=h(f);e!==f;e=h(e))for(let t=n.getFirstPath(e);t!==f;t=n.getNextPath(t)){{const e=n.getFirstVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,_,1)}if(!n.isClosedPath(t)){const e=n.getLastVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,_,1)}}}if(t===f){let e=0;for(let t=h(f);t!==f;t=h(t))for(let s=n.getFirstPath(t);s!==f;s=n.getNextPath(s)){if(n.isClosedPath(s)){let t=n.getFirstVertex(s);for(let i=0,r=n.getPathSize(s);i<r;i++,t=n.getNextVertex(t))n.setUserIndex(t,l,e++),n.setUserIndex(t,d,2)}else{const t=n.getFirstVertex(s);n.setUserIndex(t,l,e++),n.setUserIndex(t,d,1);let i=n.getNextVertex(t);for(let r=1,h=n.getPathSize(s)-1;r<h;++r)n.setUserIndex(i,l,e++),n.setUserIndex(i,d,2),i=n.getNextVertex(i);n.setUserIndex(i,l,e++),n.setUserIndex(i,d,1)}}}for(let i=h(f);i!==f;i=h(i))for(let e=n.getFirstPath(i);e!==f;e=n.getNextPath(e)){let s=n.getFirstVertex(e);for(let i=0,h=n.getPathSize(e);i<h;i++,s=n.getNextVertex(s)){const e=this.m_topoGraph.getHalfEdgeFromVertex(s);if(e===f)continue;if(1===this.m_topoGraph.getHalfEdgeUserIndex(e,g))continue;const n=this.getCombinedHalfEdgeParentage(e);if(this.isGoodParentage(n)){const s=0===i;this.restorePolylineParts(e,a,g,m,t,l,d,_,s,r)}}}let p=f;if(s){p=n.createGeometry(i.enumMultiPoint);let e=f;for(let s=this.m_topoGraph.getFirstCluster();s!==f;s=this.m_topoGraph.getNextCluster(s)){this.progress_();if(1!==this.m_topoGraph.getClusterUserIndex(s,m)){const i=this.m_topoGraph.getClusterParentage(s);if(this.isGoodParentage(i)){e===f&&(e=n.insertPath(p,f));const i=this.m_topoGraph.getClusterVertexIterator(s);if(i!==f){let r;this.m_topoGraph.getVertexFromVertexIterator(i),r=-1!==l?this.chooseVertexByOrder(s,n,l,d):this.chooseVertexFromCluster_(s,t),n.addVertex(e,r)}}}}}return-1!==d&&n.removeUserIndex(d),-1!==l&&n.removeUserIndex(l),-1!==m&&n.removeUserIndex(m),this.m_topoGraph.deleteUserIndexForHalfEdges(g),ce(a,p)}difference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),h=r(s),o=r(i);if(h>o)return e;const a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);if(this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a]=!0,2===h&&2===o){let s=f;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(s=e),this.topoOperationPolygonPolygon_(e,t,s)}if(1===h&&2===o){const t=rt();return t.allCrossRoadsImpassable=!1,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}if(1===h&&1===o){const t=rt();return t.allCrossRoadsImpassable=!0,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}if(0===h)return this.topoOperationMultiPoint_();n("")}symmetricDifference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=st(s),h=st(i),a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);return o(a>=0),o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a]=!0,this.m_maskLookup[a]=!0,this.m_maskLookup[m]=!0,2===r&&2===h?this.topoOperationPolygonPolygon_(e,t,f):1===r&&1===h?this.topoOperationPolyline_(f,this.m_bOGCOutput):0===r&&0===h?this.topoOperationMultiPoint():void n("")}planarSimplifyNoCrackingAndCluster(e,t,s,r){this.m_bOGCOutput=e,this.m_topoGraph=new Ye;const h=t.getFillRule(s),a=t.getGeometryType(s);if(1!==h||a===i.enumMultiPoint?this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,s,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeWinding(t,s,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return!1;this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const m=this.m_topoGraph.getGeometryID(s);if(o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=m+1,this.m_maskLookup[m]=!0,t.getGeometryType(s)===i.enumPolygon||1===h&&t.getGeometryType(s)!==i.enumMultiPoint){t.setFillRule(s,0);const i=this.topoOperationPolygonPolygon_(s,f,f);if(t.swapGeometry(i,s),t.removeGeometry(i),1===h&&this.m_bOGCOutput)return this.planarSimplifyNoCrackingAndCluster(e,t,s,r)}else if(t.getGeometryType(s)===i.enumPolyline){const e=rt();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=r;const i=this.topoOperationPolylineSimplify_(t.getFirstGeometry(),e);t.swapGeometry(i,s),t.removeGeometry(i)}else if(t.getGeometryType(s)===i.enumMultiPoint){const e=this.topoOperationMultiPoint_();t.swapGeometry(e,s),t.removeGeometry(e)}else n("");return!0}unsplitPolylineExact(e){return o(0),new S}planarSimplifyPolylines(e,t,s,r,n){for(let p=e.getFirstGeometry();p!==f;p=e.getNextGeometry(p)){const t=e.getGeometryType(p);o(t===i.enumPolyline)}let h=0,a=0,m=null;if(e.hasCurves()&&!e.hasSegmentParentage()){m=new ie;const s=e.getEnvelope2D(this.m_progressTracker);a=Q(t.total());const i=K(t.total(),s);h=re(i,a),J(e,i,t.total(),12e3,m,null,this.m_progressTracker)}{const s=ee(t.add(h));e.filterClosePoints(s,!1,!1,!1,f)}if(this.m_topoGraph=new Ye,4!==n&&5!==n)if(null===m&&s){const i=new te(this.m_progressTracker,!1);i.sweepVertical(e,t.total()),i.hadComplications()?($(e,t,this.m_progressTracker,!0,!1),s=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(t.total())}else $(e,t.add(h),this.m_progressTracker,!0,!1),s=!1;else s=!1;e.removeSelection(),e.collapseAllGeometriesToFirst();const g=e.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,g,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(s&&null===m),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolylines(e,t,!1,r,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const l=this.m_topoGraph.getGeometryID(g);o(l>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=l+1,this.m_maskLookup[l]=!0;const d=this.topoOperationPolylineSimplify_(e.getFirstGeometry(),r);null!==m&&m.stitchCurves(e,d,a,!0);const _=e.getGeometry(d);return s||_.getImpl().setIsSimple(4,t.total()),_}planarSimplifyMultiPoints(e,t,s,r){for(let g=e.getFirstGeometry();g!==f;g=e.getNextGeometry(g)){const t=e.getGeometryType(g);o(t===i.enumMultiPoint)}this.m_topoGraph=new Ye,4!==r&&5!==r?($(e,t,this.m_progressTracker,!0,!1),s=!1):s=!1,e.removeSelection(),e.collapseAllGeometriesToFirst();const n=e.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,n,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(s),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyMultiPoints(e,t,!1,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const h=this.m_topoGraph.getGeometryID(n);o(h>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=h+1,this.m_maskLookup[h]=!0;const a=this.topoOperationMultiPoint(),m=e.getGeometry(a);return s||m.getImpl().setIsSimple(4,t.total()),m}planarSimplifyPolygons(e,t,s,r,n,h){for(let x=e.getFirstGeometry();x!==f;x=e.getNextGeometry(x)){const t=e.getGeometryType(x);o(t===i.enumPolygon||t===i.enumPolyline&&s)}let a=0,m=0,g=null;if(e.hasCurves()&&!e.hasSegmentParentage()){g=new ie;const s=e.getEnvelope2D(this.m_progressTracker);m=Q(t.total());const i=K(t.total(),s);a=re(i,m),J(e,i,t.total(),12e3,g,null,this.m_progressTracker)}if(h){$(e,t.add(a),this.m_progressTracker,!0,!1);for(let t=e.getFirstGeometry();t!==f;t=e.getNextGeometry(t))e.getGeometryType(t)===i.enumPolygon&&Je(e,t,-1,!1,f,this.m_progressTracker)}if(this.m_topoGraph=new Ye,h||4===n||5===n)r=!1;else if(null===g&&r){const s=new te(this.m_progressTracker,!1);s.sweepVertical(e,t.total()),s.hadComplications()?($(e,t,this.m_progressTracker,!0,!1),r=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(t.total())}else $(e,t.add(a),this.m_progressTracker,!0,!1),r=!1;e.removeSelection(),e.collapseAllGeometriesToFirst();const l=e.getFirstGeometry();if(s?this.m_topoGraph.setAndSimplifyEditShapeWinding(e,l,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,l,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(r&&null===g),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolygons(e,t,s,!1,-1,!1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const d=this.m_topoGraph.getGeometryID(l);o(d>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=d+1,this.m_maskLookup[d]=!0,e.setFillRule(l,0);const _=this.m_bOGCOutput&&s,p=_;let u=this.topoOperationPolygonPolygon_(l,f,f,p);if(_){this.m_topoGraph.removeShape(),this.m_topoGraph=null,e.removeGeometry(l),this.m_topoGraph=new Ye,this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,u,this.m_progressTracker);u=this.topoOperationPolygonPolygon_(u,f,f,!1)}null!==g&&g.stitchCurves(e,u,m,!0);const c=e.getGeometry(u);return c.setFillRule(0),r?c.getImpl().setIsSimple(3,0):(c.getImpl().setIsSimple(4,t.total()),c.getImpl().updateOGCFlagsProtected()),c}planarSimplify3DImpl_(e,t,s,i,r){return o(0),{}}planarSimplifyImpl_(e,t,s,r,h,o,a,m){if(e.isEmpty())return e.clone();const g=e.getGeometryType(),l=new c,d=l.addGeometry(e);if(v(h)&&g===i.enumPolygon&&(s=!1,l.setFillRule(d,0)),m&&(e.hasAttribute(1)&&l.replaceNaNs(1,0),l.removeNaNVertices()),g===i.enumPolygon||g===i.enumPolyline&&s)return this.planarSimplifyPolygons(l,t,s,r,h,!1);if(g===S.type){const e=rt();return e.allCrossRoadsImpassable=!0,e.ogcRule=this.m_bOGCOutput,e.unsplitBehavior=a,this.planarSimplifyPolylines(l,t,r,e,h)}if(g===i.enumMultiPoint)return this.planarSimplifyMultiPoints(l,t,r,h);n("what else?")}}function Pt(e,t,s,i){if(e.isEmpty())return e.createInstance();if(t.isEmpty())return i?e.createInstance():new k({copy:e});const r=[new _e],h=[0],o=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&n(""),r[0]=e.getXY(),o?le(t,r,1,s.total(),h):de(t,r,1,s.total(),h);let a=0===h[0];return i||(a=!a),a?e.createInstance():e}function yt(e,t,s,i){const r=e.createInstance(),h=He(_e,100),o=new Array(100),a=e.getPointCount();let m=!0;const g=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&n("");for(let n=0;n<a;){const i=e.queryCoordinates(h,h.length,n,-1)-n;g?le(t,h,i,s.total(),o):de(t,h,i,s.total(),o);let a=0;for(let t=0;t<i;t++){0===o[t]&&(m&&(m=!1,r.addPoints(e,0,n)),a!==t&&r.addPoints(e,n+a,n+t),a=t+1)}m||a===i||r.addPoints(e,n+a,n+i),n+=i}return m?e:r}function St(e,t,s,r){const n=e.getGeometryType();if(n===i.enumEnvelope){const t=new P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(n===i.enumPoint&&("|"===r||"^"===r)){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(n===i.enumLine){const t=new S({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}if(n===i.enumMultiPoint&&"-"===r&&t.getGeometryType()===i.enumPoint){const t=new k({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}if(n===i.enumMultiPoint&&"&"===r&&t.getGeometryType()===i.enumPoint){const t=new k({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}return e}function Ct(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(tt(t)){const t=new S({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 Gt(e,t,s,i){const r=s===f?e.getClusterHalfEdge(t):s;let n=r;o(e.getHalfEdgeOrigin(r)===t);do{i(n),n=e.getHalfEdgeNext(e.getHalfEdgeTwin(n))}while(n!==r)}class Ht{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!==f;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===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),o=n===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),a=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,d=32;if(Gt(this.m_rTopoGraph,t,m,(e=>{e===a&&(g=2),e===h&&(l=g),e===o&&(d=g)})),this.m_bConsiderTouch)32!==l&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),32!==d&&this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|d);else{if(32===l||32===d)return 1;if(l===d&&!(h===a||h===m||o===a||o===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)|d)}return 0}classifyTouchCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),o=n===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),a=s===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=i===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));if(!this.m_bConsiderTouch){let t;return(t=a===h||m===h)?this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))):(t=a===o||m===o)&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),t?0:1}if(h===f)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===f)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;if(h===o)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!==f){if(h===m)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===m)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=1;Gt(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===o){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===a)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===a)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=2;Gt(this.m_rTopoGraph,t,a,(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===o){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!==f;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===f||h===f?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!==f;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!==f;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 o=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&&(o=s),32!==o&&this.m_rShape.setUserIndex(i,this.m_cutteeBreadcrumbsIndex,o|s)}}let t=f,s=f,r=32;const n=this.m_rShape.hasSegmentParentage(),h=new E;for(let o=this.m_rShape.getFirstPath(this.m_cuttee);o!==f;o=this.m_rShape.getNextPath(o)){const e=this.m_rShape.isClosedPath(o),a=this.m_rShape.getPathSize(o)+(e?1:0);let m=1,g=this.m_rShape.getFirstVertex(o),l=f,d=!0;for(let o=this.m_rShape.getNextVertex(g);m<a;++m,o=this.m_rShape.getNextVertex(o)){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!==f&&(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,f),r=e,d=!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,f),d=!0),l=this.m_rShape.addVertex(s,g);const a=this.m_rTopoGraph.getClusterFromVertex(g);!d&&n&&this.m_rTopoGraph.isBreakNode(a)&&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,d||this.m_rTopoGraph.isBreakNode(a))}this.m_rTopoGraph.isHalfEdgeCurve(m)&&(this.m_rTopoGraph.querySegmentXY(m,h),this.m_rShape.setSegmentToIndex(this.m_rShape.getVertexIndex(l),h.get().clone())),g=o,d=!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=f,s=f,r=32}}}function Vt(e,t,s){return new Et(s).linesToPolygonsImpl(e,t)}function vt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=new N;return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Tt(n,t,s,r,o)}const g=[0],l=e.getImpl().getIsSimple(m,g);let d=s?-1:l;if(G(d)||0===d)return d;const _=new Xt(e,t,d,o,!1);a===i.enumMultiPoint||a===i.enumPolyline||a===i.enumPolygon?d=_.isSimplePlanarImpl():n("");return e.getImpl().setIsSimple(d,m),r&&r.assign(_.m_nonSimpleResult),d}function Nt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=new N;return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Nt(n,t,s,r,o)}l(a),d(a)||p("OGC simplify is not implemented for this geometry type");const g=[0],_=e.getImpl().getIsSimple(m,g);let u=s?-1:_;if(5===u||0===u)return u;const c=new Xt(e,t,u,o,!0);a===i.enumMultiPoint||a===i.enumPolyline||a===i.enumPolygon?(u=c.isSimplePlanarImpl(),G(u)&&(u=5)):n("");return e.getImpl().setIsSimple(u,m),r&&r.assign(c.m_nonSimpleResult),u}function Tt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=N.constructEmpty();return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Tt(n,t,s,r,o)}const g=[0],l=e.getImpl().getIsSimple(m,g);let d=s?-1:l;if(-1!==d)return d;const _=new Xt(e,t,d,o,!1);return a===i.enumMultiPoint?d=_.multipointIsSimpleAsFeature():a===i.enumPolyline?d=_.polylineIsSimpleAsFeature():a===i.enumPolygon?d=_.polygonIsSimpleAsFeature():n(""),e.getImpl().setIsSimple(d,m),r&&r.assign(_.m_nonSimpleResult),d}function Ft(e,t,s,r){if(e.isEmpty())return e;const o=e.getGeometryType();if(o===i.enumPoint){const t=new ne;if(wt(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(o===i.enumEnvelope){const s=O(t,e,!0).total(),i=e,r=N.constructEmpty();return i.queryEnvelope(r),r.isDegenerate(s)?i.createInstance():e}if(h(o)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Ft(n,t,s,r)}l(o);const a=O(t,e,!1).total(),m=[0],g=e.getImpl().getIsSimple(a,m),d=s?-1:g;if(G(d)){if(o===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}if((o===i.enumMultiPoint||o===i.enumPolyline)&&d>=1)return e;const _=new Xt(e,t,d,r,!1);let p;return o===i.enumMultiPoint?p=_.multipointSimplifyAsFeature():o===i.enumPolyline?p=_.polylineSimplifyAsFeature():o===i.enumPolygon?p=_.polygonSimplifyAsFeature():n(""),p}function bt(e,t,s,r){if(e.isEmpty())return e;const n=e.getGeometryType();if(n===i.enumPoint){const t=new ne;if(wt(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(n===i.enumEnvelope){const s=e,i=new N;s.queryEnvelope(i);const r=O(t,e,!0).total();return i.isDegenerate(r)?s.createInstance():e}if(h(n)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),bt(n,t,s,r)}l(n),d(n)||p("OGC simplify is not implemented for this geometry type");const o=O(t,e,!1).total(),a=[0],m=e.getImpl().getIsSimple(o,a),g=s?-1:m;if(5===g){if(n===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}return ht(e,O(t,e,!0),!1,g,r,0,!0)}function wt(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 Ut{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}}function kt(){return{x:-1,y:-1,ipath:-1,ivertex:-1,ipolygon:-1}}function Dt(e,t,s,i,r){return{x:e,y:t,ipath:s,ivertex:i,ipolygon:r}}function Bt(e,t){return e.x===t.x&&e.y===t.y&&e.ipath===t.ipath&&e.ivertex===t.ivertex&&e.ipolygon===t.ipolygon}function At(e,t){e.x=t.x,e.y=t.y,e.ipath=t.ipath,e.ivertex=t.ivertex,e.ipolygon=t.ipolygon}function Ot(){return{x:-1,y:-1,ipath:-1,ivertex:-1,bBoundary:!1,bEndPoint:!1}}function Rt(e,t,s,i,r,n){return{x:e,y:t,ipath:s,ivertex:i,bBoundary:r,bEndPoint:n}}function Lt(e,t){e.x=t.x,e.y=t.y,e.ipath=t.ipath,e.ivertex=t.ivertex,e.bBoundary=t.bBoundary,e.bEndPoint=t.bEndPoint}class Yt extends Z{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 Mt extends Z{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(),o=n.getReversed();let a=r.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);if(a===m){const e=h?r.m_segment.getStartY():r.m_segment.getEndY(),t=o?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),a=r.m_segment.intersectionOfYMonotonicWithAxisX(i,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(i,0)}return a<m?-1:a>m?1:0}}class Xt{constructor(e,t,s,i,r){this.m_multiVertexGeom=null,this.m_edges=[],this.m_freeEdges=[],this.m_lineEdgesRecycle=[],this.m_newEdges=[],this.m_recycledSegIter=null,this.m_crossOverHelperList=new R,this.m_progressTracker=null,this.m_progressCounter=0,this.m_AET=new D,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 ne,this.m_progressCounter=0,this.m_progressTracker=i,this.m_geometry=e,this.m_knownSimpleResult=s,this.m_sr=t;const n=O(t,e,!1);this.m_toleranceIsSimple=n,this.m_toleranceIsSimpleClustering=H(n),this.m_toleranceIsSimpleCracking=L(n),this.m_toleranceSimplify=O(t,e,!0),this.m_description=this.m_geometry.getDescription(),this.m_attributeCount=this.m_description.getAttributeCount(),this.m_bOGCRestrictions=r,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 a(e)&&!this.checkDegenerateSegments(!1)?0:this._CheckClustering()?a(e)?this._CheckCracking()?this.m_geometry.getGeometryType()===i.enumPolyline?this.checkSelfIntersectionsPolylinePlanar()?4:0:this._CheckSelfIntersections()?this._CheckValidRingOrientation():0:0:5:0}isSimplePlanarImpl3D(){return o(0),7}generateSortedPairs(e){let t=null;a(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 w(0),s&&(this.m_pathsForOGCTests.length=0);let r=0;for(let o=0;o<i;o++)if(this.m_pairs.push(2*o),this.m_pairs.push(2*o+1),this.m_pairIndices.add(2*o),this.m_pairIndices.add(2*o+1),s){for(;o>=t.getPathEnd(r);)r++;this.m_pathsForOGCTests.push(r)}const n=new Y,h={parent:this,workPt:new _e,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(!!he(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(a(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 ne(1,s,0),!1}}if(d(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 ne(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 ne(3,s,0):this.m_nonSimpleResult=new ne(2,s,0),!1}}}return!0}checkDegenerateSegments(e){const t=this.m_geometry.getImpl(),s=t.querySegmentIterator(),i=t.hasAttribute(1),r=i?M(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 o=t.calculateLowerLength2D();if(!(o>h)&&!(n&&t.isCurve()&&(o=t.calculateLength2D(),o>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 ne(4,s.getStartPointIndex(),-1),!1}}return!0}checkDegenerateSegments3D(){return o(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 Yt(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!==D.st_nullNode()&&s!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),this.m_AET.getElement(s)))return this.m_nonSimpleResult=new ne(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!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),i))return this.m_nonSimpleResult=new ne(5,i,this.m_AET.getElement(t)),!1;const s=this.m_AET.getNext(e);if(s!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(s),i))return this.m_nonSimpleResult=new ne(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 c,this.m_editShape.addGeometry(this.m_geometry),this.m_editShape.hasCurves()){this.m_curveStitcher=new ie;const e=N.constructEmpty();this.m_geometry.queryEnvelope(e);const t=K(this.m_toleranceSimplify.total(),e),s=new ne;if(oe(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 ne;return ae(!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=X(!0,e,i,this.m_toleranceIsSimpleCracking,!0);if(r){const e=2===r?7:6;return this.m_nonSimpleResult=new ne(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,o=this.m_xy.read(2*h),a=this.m_xy.read(2*h+1);if(t.length&&(o!==i||a!==r)){if(!this.processBunchForSelfIntersectionTest(t))return!1;t.length=0}t.push(h),i=o,r=a}return!!this.processBunchForSelfIntersectionTest(t)}checkSelfIntersectionsPolylinePlanar(){const e=this.m_geometry.getImpl(),t=[];for(let h=0,o=e.getPathCount();h<o;h++)t.push(e.isClosedPathInXYPlane(h));const s=Ot();let i,r,n;{const h=this.m_pairIndices.read(0),o=this.m_pairs[h]>>1,a=this.m_xy.readPoint2D(2*o),m=this.m_pathsForOGCTests[o];i=t[m],r=e.getPathStart(m),n=e.getPathEnd(m)-1,s.bEndPoint=o===r||o===n,this.m_bOGCRestrictions?s.bBoundary=!i&&s.bEndPoint:s.bBoundary=s.bEndPoint,s.ipath=m,s.x=a.x,s.y=a.y,s.ivertex=o}for(let h=1,o=this.m_pairIndices.size();h<o;h++){const o=this.m_pairIndices.read(h),a=this.m_pairs[o];if(1&a)continue;const m=a>>1,g=this.m_xy.readPoint2D(2*m),l=this.m_pathsForOGCTests[m];let d;l!==s.ipath&&(i=t[l],r=e.getPathStart(l),n=e.getPathEnd(l)-1);const _=m===r||m===n;d=this.m_bOGCRestrictions?!i&&_:_;const p=Rt(g.x,g.y,l,m,d,_);if(p.x===s.x&&p.y===s.y)if(this.m_bOGCRestrictions){if(!(p.bBoundary&&s.bBoundary||p.ipath===s.ipath&&p.bEndPoint&&s.bEndPoint))return this.m_nonSimpleResult=new ne(10,p.ivertex,s.ivertex),!1}else if(!p.bEndPoint||!s.bEndPoint)return this.m_nonSimpleResult=new ne(7,p.ivertex,s.ivertex),!1;Lt(s,p)}return!0}checkSelfIntersectionsPolylinePlanar3D(e){return o(0),!1}checkSelfIntersectionsPolygonsOGC(){const e=this.m_geometry.getImpl(),t=[];let s=-1,i=!1;for(let g=0,l=e.getPathCount();g<l;g++)e.isExteriorRingOGC(g)&&(i=!1,s++,g<l-1&&(e.isExteriorRingOGC(g+1)||(i=!0))),t.push(i?s:-1);const r=kt();{const e=this.m_pairIndices.read(0),s=this.m_pairs[e]>>1,i=this.m_xy.readPoint2D(2*s),n=this.m_pathsForOGCTests[s];r.ipath=n,r.x=i.x,r.y=i.y,r.ivertex=s,r.ipolygon=t[n]}const n=[];for(let g=1,l=this.m_pairIndices.size();g<l;g++){const e=this.m_pairIndices.read(g),s=this.m_pairs[e];if(1&s)continue;const i=s>>1,h=this.m_xy.readPoint2D(2*i),o=this.m_pathsForOGCTests[i],a=Dt(h.x,h.y,o,i,t[o]);if(a.x===r.x&&a.y===r.y){if(a.ipath===r.ipath)return this.m_nonSimpleResult=new ne(11,a.ivertex,r.ivertex),!1;t[a.ipath]>=0&&t[a.ipath]===t[r.ipath]&&(0!==n.length&&Bt(n.at(-1),r)||n.push({...r}),n.push(a))}At(r,a)}if(0===n.length)return!0;const h=new R(!0);t.fill(-1);let o=-1;const a=new _e;for(let g=0,l=n.length;g<l;g++){const e=n[g];e.x===a.x&&e.y===a.y||(o=h.createList(0),a.x=e.x,a.y=e.y);let s=t[e.ipath];-1===s&&(s=h.createList(2),t[e.ipath]=s),h.addElement(s,o),h.addElement(o,s)}const m=[];for(let g=h.getFirstList();-1!==g;g=h.getNextList(g)){const e=h.getListData(g);if(1&e||!(2&e))continue;let s=-1;for(m.push(g),m.push(-1);m.length;){const e=m.at(-1);m.pop();const t=m.at(-1);m.pop();const i=h.getListData(t);if(1&i){s=2&i?t:e;break}h.setListData(t,1|i);for(let s=h.getFirst(t);-1!==s;s=h.getNext(s)){const i=h.getData(s);i!==e&&(m.push(i),m.push(t))}}if(-1!==s){const e=t.indexOf(s);return this.m_nonSimpleResult=new ne(12,e,-1),!1}}return!0}_CheckValidRingOrientation(){const e=null!==this.m_multiPathStitcher?this.m_multiPathStitcher.getImpl():this.m_geometry.getImpl();if(e.calculateArea2D()<=0)return this.m_nonSimpleResult=new ne(8,1===e.getPathCount()?1:-1,-1),0;if(1===e.getPathCount())return this.m_bOGCRestrictions&&!this.checkSelfIntersectionsPolygonsOGC()?0:4;this.m_pathOrientations=new q(e.getPathCount(),0),this.m_pathParentage=new w(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 ne(8,n,-1),0;if((t<0||s<Math.abs(i))&&(this.m_nonSimpleResult=new ne(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 w(i,D.st_nullNode()),this.m_xyToNode2=new w(i,D.st_nullNode()),this.m_freeEdges.length=0,this.m_AET.clear(),this.m_AET.setComparator(new Mt(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,o=e.length;h<o;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,o=this.m_edges.length;h<o;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),o=this.m_crossOverHelperList.getData(n);if(i=this.m_edges[h].m_vertexIndex,r=this.m_edges[o].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 ne(7,i,r),!1;for(let h=0,o=e.length;h<o;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!==D.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,D.st_nullNode())}if(i=this.m_xyToNode2.read(s),i!==D.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,D.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)===D.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)===D.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,o=0;for(;s!==D.st_nullNode()&&(e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex,o=this.m_pathOrientations.read(h),!(3&o));)i=s,s=this.m_AET.getPrev(s);s===D.st_nullNode()?(r=1,s=i):(t=1==(3&o)?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 o=this.m_pathOrientations.read(h);if(!(3&o)){if(r!==n.getRightSide())return this.m_nonSimpleResult=new ne(8,h,-1),!1;const e=r&&!n.getReversed()?1:2;if(o=-4&o|e,this.m_pathOrientations.write(h,o),2===e&&0===this.m_nonSimpleResult.m_reason){const e=this.m_pathParentage.read(h);if(e!==t&&(this.m_nonSimpleResult=new ne(9,h,e),this.m_bOGCRestrictions))return!1}if(this.m_unknownOrientationPathCount--,!this.m_unknownOrientationPathCount)return!0}t=1==(3&o)?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 Ut,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 Ut,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(e,t,s,i,r){if(s){const s=e.getXYZ(),n=t.getXYZ();return z(s,n,i,r)}{const s=e.getXY(),r=t.getXY();return _e.sqrDistance(s,r)<=i*i}}removeDegenerateSegmentsFromCurvedPath(e,t,s,i){const r=e.hasAttribute(1),n=e.querySegmentIterator();n.resetToPath(t),o(n.nextPath());const h=this.m_toleranceSimplify.total();let a=!1,m=!0;const g=new k,l=new k,d=new _e;for(;n.hasNextSegment();){this.progress_();const e=n.nextSegment();if(Xt.isShortSegment(e,r,h,s))if(a){if(e.queryEnd(l),Xt.isShortSegmentPoints(g,l,r,h,s))continue;m&&(i.startPathPoint(g),m=!1),e.queryEnd(g),i.lineToPoint(g),a=!1}else d.assign(e.getStartXY()),e.queryStart(g),a=!0;else if(a)if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(d,e.getEndXY(),!1),t.setStart(g),Xt.isShortSegment(t,r,h,s))continue;i.addSegment(t,m),m=!1,a=!1}else{if(e.queryEnd(l),Xt.isShortSegmentPoints(g,l,r,h,s))continue;m&&(i.startPathPoint(g),m=!1),i.lineToPoint(l),a=!1}else i.addSegment(e,m),m=!1}if(m)return;if(!a)return;e.isClosedPath(t)?e.getPointByVal(e.getPathStart(t),g):e.getPointByVal(e.getPathEnd(t)-1,g);const _=i.querySegmentIterator();_.resetToLastPath(),_.resetToLastSegment();const p=i.getDescription().getAttributeCount()>1;for(o(_.previousPath());_.hasPreviousSegment();){const e=_.previousSegment();if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(e.getStartXY(),g.getXY(),!1),!Xt.isShortSegment(t,r,h,s)){p&&t.setEnd(g);const e=_.getEndPointIndex();for(let t=i.getPointCount()-1;t>=e;t--)i.removePoint(t);return void i.addSegment(t,!1)}}else if(e.queryStart(l),!Xt.isShortSegmentPoints(l,g,r,h,s)){const e=_.getEndPointIndex();for(let t=i.getPointCount()-1;t>=e;t--)i.removePoint(t);return void i.lineToPoint(g)}}i.removePath(i.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 ne(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=Xt.hasNanZs(e);let s,i=this.m_geometry;t&&(s=this.m_geometry.clone(),e=s.getImpl(),s.replaceNaNs(1,W.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 o=-1;for(let l=0;l<r;l++){const t=n[l];e.getXY(t).isFinite()&&((o<0||0!==this.compareVerticesMultiPoint(o,t))&&(h[t]=!0),o=t)}const a=this.m_geometry.createInstance();let m=0,g=0;for(let l=0;l<r;l++)h[l]?g=l+1:(m<g&&a.addPoints(i,m,g),m=l+1);return m<g&&a.addPoints(i,m,g),a.getImpl().setIsSimple(1,this.m_toleranceSimplify.total()),a}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?M(this.m_sr,e,!0).total():0,o=[],a=[];let m=null;n&&(m=e.getAttributeStreamRef(1));const g=new k,l=e.hasNonLinearSegments(),d=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 _=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,o.push(s))}if(c){const t=s.getEndPointIndex();e.getXY(t).isNAN()||(a.push(t),c=!1)}if(!u){const s=o.at(-1),r=t.getEndPointIndex();if(r-s>1){const t=new _e;t.setSub(e.getXY(s),e.getXY(r)),_=t.length()}else _=i.calculateLength2D();if(_>d)o.push(r),_=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&&(o.push(r),_=0)}}if(!c){const t=a.at(-1),i=s.getStartPointIndex();if(i-t>1){const s=new _e;s.setSub(e.getXY(t),e.getXY(i)),p=s.length()}else p=r.calculateLength2D();if(p>d)a.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&&(a.push(i),p=0)}}}if(o.length>0&&a.length>0&&(o.at(-1)<a.at(-1)?o.length>a.length?o.pop():a.pop():(o.at(-1)===a.at(-1)||a.pop(),a.pop())),a.length+o.length>=2){let e=!1;for(let t=0,s=o.length;t<s;t++)r.getPointByVal(o[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);for(let t=a.length-1;t>0;t--)r.getPointByVal(a[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);r.isClosedPath(t.getPathIndex())?i.closePathWithLine():a.length>0&&(r.getPointByVal(a[0],g),i.lineToPoint(g))}o.length=0,a.length=0}return n&&i.replaceNaNs(1,0),i.getImpl().setIsSimple(1,d),i}polygonSimplifyAsFeature(){return this.simplifyPlanar()}simplifyPlanar(){if(1===this.m_geometry.getFillRule()&&!v(this.m_knownSimpleResult))return ot(this.m_geometry,this.m_toleranceSimplify,!0,!1,this.m_knownSimpleResult,this.m_progressTracker,0,!0);const e=new c;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 ie;const i=N.constructEmpty();this.m_geometry.queryEnvelope(i);const n=K(this.m_toleranceSimplify.total(),i);s=Q(this.m_toleranceSimplify.total()),r=re(n,s),J(e,n,this.m_toleranceSimplify.total(),12e3,t,null,this.m_progressTracker)}if(!v(this.m_knownSimpleResult)){const t=this.m_toleranceSimplify.add(r);$(e,t,this.m_progressTracker,!0,!1)}this.m_geometry.getGeometryType()===i.enumPolygon&&Je(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,o=this.m_xy.readPoint2D(2*n);o.y+=1&i?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const a=this.m_xy.readPoint2D(2*h);a.y+=1&r?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const m=o.compare(a);if(0===m&&s){const e=this.m_pathsForOGCTests[n]-this.m_pathsForOGCTests[h];return Ie(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=W.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=Ee(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 qt{getOperatorType(){return 10103}accelerateGeometry(e,t,s){return!1}canAccelerateGeometry(e){return!1}supportsCurves(){return!0}isSimpleAsFeature(e,t,s,i,r){const n=Tt(e,t,s,i,r);return T(e.getGeometryType(),n)}isSimplePlanarDONOTUSE(e,t,s,i,r){const n=vt(e,t,s,i,r);return G(n)}executeMany(e,t,s,i){return new zt(e,t,s,i)}execute(t,s,i,r){const h=new e([t]),o=this.executeMany(h,s,i,r).next();return o||n("null geometry"),o}}class zt extends t{constructor(e,t,s,i){super(),this.m_progressTracker=i,this.m_bForceSimplify=s,this.m_index=-1,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=F(e,-1),s=(new qt).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 Ft(e,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker)}}export{qt as O,Et as T,Ne as U,It as a,dt as b,ft as c,xt as d,ut as e,lt as f,pt as g,We as h,ct as i,nt as j,Nt as k,bt as l,Je as m,Vt as n,Ye as o,ot as p,_t as q,it as s};
5
+ import{S as e,G as t}from"./SimpleGeometryCursor.js";import{t as s,G as i,d as r,b as n,e as h,g as o,f as a,v as m,h as g,j as l,i as d,k as _,a as p}from"./Geometry.js";import{f as u,d as c,n as f,b as x,g as I,S as E,h as P,M as y,i as S,j as C,k as G,l as H,m as V,o as v,a as N,p as T,q as F,r as b,A as w,s as U,P as k,T as D,t as B,C as A,u as O,I as R,v as L,B as Y,w as M,x as X,y as q,z,V as W,F as Z,L as j}from"./QuadraticBezier.js";import{s as Q,d as K,b as J,e as $,c as ee,P as te,a as se,C as ie,f as re,N as ne,g as he,h as oe,n as ae,j as me,k as ge,t as le,l as de}from"./CrackAndCluster-CfzXpEle.js";import{P as _e,a as pe,b as ue,d as ce,e as fe,f as xe,s as Ie,g as Ee,h as Pe,i as ye,E as Se,K as Ce,j as Ge,m as He}from"./Transformation2D.js";import{b as Ve,c as ve}from"./tslib.es6.js";class Ne{constructor(e){this.m_currentShift=63n,this.m_currentElt=0n,this.m_iCurrentElt=-1,this.m_parent=e,this.m_aiSetElts=e.m_bits.flatMap(((e,t)=>t))}next(){if(this.m_currentShift++,64n===this.m_currentShift){if(this.m_iCurrentElt++,this.m_iCurrentElt===this.m_aiSetElts.length)return Ne.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 Te(e){return 1n<<(0x3fn&BigInt(e))}function Fe(e){return e>>6}class be{constructor(e){this.m_bits=[],void 0!==e&&e.copy&&(this.m_bits=e.copy.m_bits.slice())}assignMove(){return this}assignCopy(){return this}hasBit(e){const t=Te(e),s=Fe(e);return void 0!==this.m_bits[s]&&!!(this.m_bits[s]&t)}setBit(e){const t=Te(e),s=Fe(e);void 0===this.m_bits[s]&&(this.m_bits[s]=0n),this.m_bits[s]|=t}clearBit(e){}flipBit(e){const t=Te(e),s=Fe(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(){let e=0;return this.m_bits.forEach((t=>{e|=t?2:1})),!(2&e)}equals(e){if(this===e)return!0;if(this.m_bits.length!==e.m_bits.length)return!1;let t=0;return this.m_bits.forEach(((s,i)=>{t|=s===e.m_bits[i]?2:1})),!(1&t)&&(e.m_bits.forEach(((e,s)=>{t|=e===this.m_bits[s]?2:1})),!(1&t))}notEquals(e){return!this.equals(e)}assignOr(e){return e.m_bits.forEach(((e,t)=>{void 0===this.m_bits[t]?this.m_bits[t]=e:this.m_bits[t]|=e})),this}assignSubtract(e){return e.m_bits.forEach(((e,t)=>{void 0!==this.m_bits[t]&&(this.m_bits[t]&=~e)})),this}assignAnd(e){return e.m_bits.forEach(((e,t)=>{void 0!==this.m_bits[t]&&(this.m_bits[t]&=e)})),this}assignXor(e){return e.m_bits.forEach(((e,t)=>{void 0===this.m_bits[t]?this.m_bits[t]=e:this.m_bits[t]^=e})),this}getHashCode(){return this.m_bits.reduce(((e,t)=>Pe(e,t)),ye(0))}getUnorderedBitIterator(){return new Ne(this)}}class we{constructor(e,t){this.m_map=new Map,this.m_hf=e,this.m_ef=t}add(e){const t=this.m_hf(e);if(!this.m_map.has(t))return this.m_map.set(t,e),this;const s=this.m_map.get(t);return s instanceof Array?s.find((t=>this.m_ef(t,e)))||s.push(e):this.m_ef(s,e)||this.m_map.set(t,[s,e]),this}clear(){this.m_map.clear()}delete(e){return!1}has(e){const t=this.m_hf(e);if(!this.m_map.has(t))return!1;const s=this.m_map.get(t);return s instanceof Array?void 0!==s.find((t=>this.m_ef(t,e))):this.m_ef(s,e)}get(e){const t=this.m_hf(e),s=this.m_map.get(t);if(void 0!==s)return s instanceof Array?s.find((t=>this.m_ef(t,e))):s}get size(){let e=0;for(const t of this.m_map.values())e+=t instanceof Array?t.length:1;return e}forEach(e,t){}[Symbol.iterator](){return(new Set)[Symbol.iterator]()}entries(){return(new Set).entries()}keys(){return(new Set).keys()}values(){return(new Set).values()}get[Symbol.toStringTag](){return"ValueSet"}}class Ue extends Z{constructor(e){super(),this.m_bufferLeft=new E,this.m_bufferRight=new E,this.m_intervalLeft=Se.constructEmpty(),this.m_intervalRight=Se.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 o=n.getStartY()===n.getEndY(),a=h.getStartY()===h.getEndY();if(o||a){if(o&&a)return 0;if(n.getStartY()===h.getStartY()&&n.getStartX()===h.getStartX())return o?1:-1;if(n.getEndY()===h.getEndY()&&n.getEndX()===h.getEndX())return o?-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 ke{constructor(e){this.m_segmentBuffer=new E,this.m_point=_e.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 Se;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 De,Be;function Ae(e,t){return{parentage:e,rank:t}}function Oe(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 Re(e,t,s){s.length=0;let i=!1;{let r=e.getHalfEdgeVertexIterator(t);for(;r!==f;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(Ae(h,n)),r=e.incrementVertexIterator(r)}}{let r=e.getHalfEdgeVertexIterator(e.getHalfEdgeTwin(t));for(;r!==f;){const t=e.getVertexFromVertexIterator(r),n=e.getShape().getSegmentRank(t),h=e.getShape().getSegmentParentage(t);i||=h>=0,s.push(Ae(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 Le(){return new we((e=>e.getHashCode()),((e,t)=>e.equals(t)))}!function(e){e[e.enumInputModeBuildGraph=0]="enumInputModeBuildGraph",e[e.enumInputModeSimplifyAlternate=1]="enumInputModeSimplifyAlternate",e[e.enumInputModeSimplifyWinding=2]="enumInputModeSimplifyWinding"}(De||(De={})),function(e){e[e.enumSegmentParentageBreakNode=1]="enumSegmentParentageBreakNode",e[e.enumPathBreakNode=2]="enumPathBreakNode"}(Be||(Be={}));class Ye{constructor(){this.m_shape=null,this.m_clusterData=new b(8),this.m_clusterVertices=new b(2),this.m_firstCluster=f,this.m_lastCluster=f,this.m_halfEdgeData=new b(8),this.m_chainData=new b(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,De.enumInputModeBuildGraph,null,t,!1):this.setEditShapeImpl_(e,De.enumInputModeBuildGraph,null,t,s)}setAndSimplifyEditShapeAlternate(e,t,s=null,r=!1){const n=[];n.push(t),this.m_simplifiedGeometry=t,r?this.setEditShapeImpl3D_(e,De.enumInputModeSimplifyAlternate,n,s,!1):this.setEditShapeImpl_(e,De.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,De.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=f,this.m_lastCluster=f,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=f,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(e,t){o(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(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)}createUserIndexForClusters(e=-1){const t=new w(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(e,t){o(0)}getHalfEdgeToXYZ(e,t){o(0)}getHalfEdgeParentage(e){return this.m_halfEdgeData.getField(e,3)&Ye.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(e){void 0===e&&(e=-1);const t=new w(this.m_halfEdgeData.capacity(),e);for(let i=0,r=this.m_edgeIndices.length;i<r;i++)if(null===this.m_edgeIndices[i])return this.m_edgeIndices[i]=t,i;this.m_edgeIndices.push(t);const s=this.m_edgeIndices.length-1;return o(s>=0&&s<=Number.MAX_SAFE_INTEGER),s}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,f),this.setChainHalfEdge_(n,f),this.updateVertexToHalfEdgeConnection_(s,!0),this.deleteEdgeImpl_(s)}}doesHalfEdgeBelongToAPolygonInterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolygonExterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolygonBoundary(e,t){return o(0),!1}doesHalfEdgeBelongToAPolylineInterior(e,t){return o(0),!1}doesHalfEdgeBelongToAPolylineExterior(e,t){return o(0),!1}doesClusterBelongToAPolygonInterior(e,t){return o(0),!1}doesClusterBelongToAPolygonExterior(e,t){return o(0),!1}doesClusterBelongToAPolygonBoundary(e,t){return o(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(e){return o(0),0}getChainUserIndex(e,t){const s=this.getChainIndex_(e),i=this.m_chainIndices[t];return i.size()<=s?-1:i.read(s)}setChainUserIndex(e,t,s){const i=this.getChainIndex_(e),r=this.m_chainIndices[t];r.size()<=i&&r.resize(this.m_chainData.size(),-1),r.write(i,s)}createUserIndexForChains(){const e=new w(this.m_chainData.capacity(),-1);for(let t=0,s=this.m_chainIndices.length;t<s;t++)if(null===this.m_chainIndices[t])return this.m_chainIndices[t]=e,t;this.m_chainIndices.push(e);return this.m_chainIndices.length-1}deleteUserIndexForChains(e){this.m_chainIndices[e]=null}extractPolygonFromChainAndIslands(e,t,s,r){const n=t===f?e.createGeometry(i.enumPolygon):t,h=new E;this.extractPolygonPathFromChain_(e,n,s,r,h);for(let i=this.getChainFirstIsland(s);i!==f;i=this.getChainNextInParent(i))this.extractPolygonPathFromChain_(e,n,i,r,h);return n}getGeometryID(e){const t=this.m_shape.getGeometryUserIndex(e,this.m_geometryIDIndex);return o(t>=0),1<<Math.min(t,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(e){if(o(this.m_bBuildGeometryParentageSets),-1===this.m_chainBitSetIndex)return this.getEmptySet();const t=this.getChainUserIndex(e,this.m_chainBitSetIndex);o(t>=0);let s=this.m_chainBitSets.at(t);return s||(s=this.getEmptySet()),s}getChainBoundaryBitSet(e){o(this.m_bBuildGeometryParentageSets);const t=new be,s=e=>{const s=this.getChainHalfEdge(e);let i=s;do{const e=this.getEdgeBitSet_(i);null!==e&&t.assignOr(e);const s=this.getEdgeBitSet_(this.getHalfEdgeTwin(i));null!==s&&t.assignOr(s),i=this.getHalfEdgeNext(i)}while(i!==s)};s(e);for(let i=this.getChainFirstIsland(e);i!==f;i=this.getChainNextInParent(i))s(e);return t}getChainPolygons(e){return o(0),[]}getGeometriesFromBits(e){if(!this.m_bBuildGeometryParentageSets||null===e)return[];if(null===this.m_geometryMapID){this.m_geometryMapID=new Map;for(let e=this.m_shape.getFirstGeometry();e!==f;e=this.m_shape.getNextGeometry(e))this.m_geometryMapID.set(this.m_shape.getGeometryUserIndex(e,this.m_geometryIDIndex),e)}const t=[],s=e.getUnorderedBitIterator();for(let i=s.next();i!==Ne.npos();i=s.next())o(this.m_geometryMapID.has(i)),t.push(this.m_geometryMapID.get(i));return t}getVertexDominant(e,t){if(t===f)return e;const s=this.getClusterFromVertex(e);return this.getVertexDominantFromCluster(s,t)}getVertexDominantFromCluster(e,t){if(t!==f){let s=f;for(let i=this.getClusterVertexIterator(e);i!==f;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);s===f&&(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!==f){return this.getVertexFromVertexIterator(t)}return f}}isBreakNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode)}setBreakNode(e,t){o(-1!==this.m_clusterBreakNodeIndex),t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumSegmentParentageBreakNode)}isStrongPathNode(e){return this.hasClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumPathBreakNode)}setStrongPathNode(e,t){if(-1===this.m_clusterBreakNodeIndex){if(!t)return;this.m_clusterBreakNodeIndex=this.createUserIndexForClusters()}t?this.setClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.enumPathBreakNode):this.clearClusterUserIndexFlags(e,this.m_clusterBreakNodeIndex,Be.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(e){return o(0),!1}getHalfEdgeConnector(e,t){const s=this.getClusterHalfEdge(e);if(s===f)return f;let i=s,r=f,n=f;do{if(this.getHalfEdgeTo(i)===t)return i;if(r===f){if(r=this.getClusterHalfEdge(t),r===f)return f;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 f}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=_e.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_(e,t,s){const i=new E,r=new E;this.querySegmentXY(e,i),this.querySegmentXY(t,r);const n=i.get(),h=r.get();if(n.equals(h))return 0;const a=new _e;this.getHalfEdgeFromXY(e,a);const m=new _e;this.getHalfEdgeToXY(e,m);const g=new _e;this.getHalfEdgeToXY(t,g),o(!m.isEqualPoint2D(g));const l=n.getTangent(0),d=h.getTangent(0);return _e.compareVectors(l,d)}compareEdgeAnglesHelper_(e,t,s){if(e===t)return 0;if(this.isHalfEdgeCurve(e)||this.isHalfEdgeCurve(t))return this.compareEdgeAnglesCurveHelper_(e,t,s);const i=_e.getNAN();this.getHalfEdgeToXY(e,i);const r=_e.getNAN();if(this.getHalfEdgeToXY(t,r),i.isEqualPoint2D(r))return 0;const n=_e.getNAN();this.getHalfEdgeFromXY(e,n);const h=_e.getNAN();h.setSub(i,n);const o=_e.getNAN();if(o.setSub(r,n),!s||o.y>=0&&h.y>0){return _e.compareVectors(h,o)}return 0}compareEdgeAngles_(e,t){return this.compareEdgeAnglesHelper_(e,t,!1)}compareEdgeAnglesForPair_(e,t){return this.compareEdgeAnglesHelper_(e,t,!0)}compareEdgeAngles3D_(e,t){return o(0),0}compareEdgeAnglesForPair3D_(e,t){return o(0),0}dbgDumpChains_(){}dbgDumpChainToPolygon_(e,t){}deleteEdgeInternal_(e){const t=this.getHalfEdgeChain(e),s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeChain(s);o(i===t),o(e===this.getHalfEdgeNext(s)||s===this.getHalfEdgeNext(e));let r=this.getHalfEdgeNext(e);r===s&&(r=this.getHalfEdgeNext(r),r===e&&(r=f));const n=this.getChainIndex_(t),h=this.m_chainAreas.read(n);Number.isNaN(h)||(this.setChainArea_(t,Number.NaN),this.setChainPerimeter_(t,Number.NaN));const a=this.getChainHalfEdge(t);a!==e&&a!==s||this.setChainHalfEdge_(t,r),this.updateVertexToHalfEdgeConnection_(e,!0),this.deleteEdgeImpl_(e)}getFirstUnvisitedHalfEdgeOnCluster_(e,t,s){let i=t!==f?t:this.getClusterHalfEdge(e);if(i===f)return f;const r=i;for(;;){if(1!==this.getHalfEdgeUserIndex(i,s))return i;const e=this.getHalfEdgeNext(this.getHalfEdgeTwin(i));if(e===r)return f;i=e}}removeSpikes_(){let e=!1;const t=this.createUserIndexForHalfEdges();for(let s=this.getFirstCluster();s!==f;s=this.getNextCluster(s)){let i=f;for(;;){let r=this.getFirstUnvisitedHalfEdgeOnCluster_(s,i,t);if(r===f)break;i=this.getHalfEdgeNext(this.getHalfEdgeTwin(r));let n=r;for(;;){const s=this.getHalfEdgeNext(n),h=this.getHalfEdgePrev(n),o=this.getHalfEdgeTwin(n);if(h===o){if(this.deleteEdgeInternal_(n),e=!0,i!==n&&i!==o||(i=f),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_(e){return o(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?f:e;for(let i=this.getHalfEdgeVertexIterator(e);i!==f;i=this.incrementVertexIterator(i)){const e=this.getVertexFromVertexIterator(i);this.m_shape.setUserIndex(e,this.m_halfEdgeIndex,s)}}updateVertexToHalfEdgeConnection_(e,t){e!==f&&(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=_e.getNAN(),h=_e.getNAN(),o=_e.getNAN();this.getHalfEdgeFromXY(r,n),h.setCoordsPoint2D(n);let a=r;do{this.getHalfEdgeToXY(a,o),t&&this.isCurveEdge(a)||i.pe(_e.distance(h,o));this.getHalfEdgeChain(this.getHalfEdgeTwin(a))!==e&&s.pe((o.x-n.x-(h.x-n.x))*(o.y-n.y+(h.y-n.y))*.5),h.setCoordsPoint2D(o),a=this.getHalfEdgeNext(a)}while(a!==r);if(t){const t=new E;a=r;do{this.getHalfEdgeToXY(a,o);const r=this.isCurveEdge(a);r&&(this.querySegmentXY(a,t),i.pe(t.get().calculateLength2D()));if(this.getHalfEdgeChain(this.getHalfEdgeTwin(a))!==e&&r){const e=t.get().calculateArea2DHelper();s.pe(e)}a=this.getHalfEdgeNext(a)}while(a!==r)}const m=this.getChainIndex_(e);this.m_chainAreas.write(m,s.getResult()),this.m_chainPerimeters.write(m,i.getResult())}getChainTopmostEdge_(e){return o(0),0}planeSweepParentage_(e,t){const s=new Ue(this),i=new D;i.setCapacity(Math.trunc(this.m_pointCount/2)),i.setComparator(s);const r=[],n=this.createUserIndexForHalfEdges();let h=null;const o=_e.getNAN();for(let a=this.getFirstCluster();a!==f;a=this.getNextCluster(a)){this.progress_(t);const m=this.getClusterHalfEdge(a);if(m!==f){if(r.length=0,!this.tryOptimizedInsertion_(i,n,r,a,m)){this.queryXY(a,o),s.setY(o.y);let e=m;do{const t=this.getHalfEdgeUserIndex(e,n);-1!==t&&(i.deleteNode(t),this.setHalfEdgeUserIndex(e,n,b.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),o=this.getHalfEdgeTwin(h);this.setHalfEdgeUserIndex(o,n,s),this.planeSweepParentagePropagateParentage_(i,s,e)}}else if(this.getClusterChain(a)===f){null===h&&(h=new ke(this)),this.queryXY(a,o),h.setPointXY(o);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!==f&&(t=this.getHalfEdgeChain(s))}this.addClusterToExteriorChain_(t,a)}}this.deleteUserIndexForHalfEdges(n)}planeSweepParentagePropagateParentage_(e,t,s){const i=e.getElement(t),r=this.getHalfEdgeChain(i);if(this.getChainParent(r)!==f)return;const n=this.getLeftSkipPolylines_(e,t),h=this.getHalfEdgeTwin(i),a=this.getHalfEdgeChain(h);let m=this.getChainParent(r),g=this.getChainParent(a);if(n===f)m===f&&(a===r?(this.setChainParent_(a,this.m_universeChain),g=this.m_universeChain,m=g):(g===f&&(this.setChainParent_(a,this.m_universeChain),g=this.m_universeChain),this.setChainParent_(r,a),m=a));else{const e=this.getHalfEdgeChain(n);if(g===f){if(this.getChainArea(e)<=0){const t=this.getChainParent(e);this.setChainParent_(a,t),g=t}else this.setChainParent_(a,e),g=e;a===r&&(m=g)}}m===f&&(this.trySetChainParentFromTwin_(r,a),m=this.getChainParent(r)),o(m!==f),s===De.enumInputModeBuildGraph?this.propagateParentageBuildGraph_(e,t,i,n):s===De.enumInputModeSimplifyWinding?this.propagateParentageWinding_(e,t,i,n,h,r,a):s===De.enumInputModeSimplifyAlternate&&this.propagateParentageAlternate_(e,t,i,n,h,r,a)}propagateParentageBuildGraph_(e,t,s,i){let r,n=t;i===f?(n=e.getNext(n),r=this.getHalfEdgeChain(s)):r=this.getHalfEdgeChain(i);let h=null,o=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 be({copy:e}),e.assignOr(h),this.setChainBitSet_(i,e);let s=this.getChainBitSet(r);const n=this.getLeftEdgeBitSet_(t),o=new be({copy:h});if(o.assignSubtract(n),o.isZero())break;s=new be({copy:s}),s.assignOr(o),this.setChainBitSet_(r,s),h=s}const a=this.getChainParentage(i),m=a|o;m!==a&&this.setChainParentage_(i,m);let g=this.getChainParentage(r);const l=o&~this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeParentageIndexLeft);if(l&&(g|=l,this.setChainParentage_(r,g)),0===l)break;o=g}}propagateParentageWinding_(e,t,s,i,r,n,h){if(n===h)return;let a=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex);a+=this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);let m=0;const g=[],l=[];l.push(0);for(let d=e.getFirst();d!==t;d=e.getNext(d)){const t=e.getElement(d),s=this.getHalfEdgeTwin(t),i=this.getHalfEdgeChain(t),r=this.getHalfEdgeChain(s);if(i!==r){let e=this.getHalfEdgeUserIndex(t,this.m_tmpHalfEdgeWindingNumberIndex);e+=this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeWindingNumberIndex),m+=e;let n=!1;0!==g.length&&g.at(-1)===r&&(l.pop(),g.pop(),n=!0),o(this.getChainParent(r)!==f),n&&this.getChainParent(r)===i||(l.push(m),g.push(i))}}if(m+=a,0!==g.length&&g.at(-1)===h&&(l.pop(),g.pop()),0!==m){if(0===l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(n,t)}}else if(0!==l.at(-1)){const e=this.m_simplifiedGeometry,t=this.getGeometryID(e);this.setChainParentage_(n,t)}}propagateParentageAlternate_(e,t,s,i,r,n,h){const o=this.m_simplifiedGeometry,a=this.getGeometryID(o);if(i===f){this.setChainParentage_(h,this.m_universeGeomID);1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,a):this.setChainParentage_(n,this.m_universeGeomID)}else{const e=this.getChainParentage(h);if(0===e){const e=this.getHalfEdgeChain(i),t=this.getChainParentage(e);this.setChainParentage_(h,t);1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,t===a?this.m_universeGeomID:a):this.setChainParentage_(n,t)}else{1&this.getHalfEdgeUserIndex(s,this.m_tmpHalfEdgeOddEvenNumberIndex)?this.setChainParentage_(n,e===a?this.m_universeGeomID:a):this.setChainParentage_(n,e)}}}tryOptimizedInsertion_(e,t,s,i,r){let n=r,h=-1,o=f,a=0;do{if(2===a)return!1;const e=this.getHalfEdgeUserIndex(n,t);if(-1!==e){if(-1!==h)return!1;h=e}else{if(o!==f)return!1;o=n}a++,n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(r!==n);return o!==f&&-1!==h&&(this.setHalfEdgeUserIndex(e.getElement(h),t,b.impossibleIndex2()),e.setElement(h,o),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!==f)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),o=this.m_shape.getGeometryFromPath(h),m=this.m_shape.getGeometryType(o);if(a(m)){const t=this.m_shape.getNextVertex(r);if(t===f)continue;const s=this.m_shape.getUserIndex(t,this.m_clusterIndex);if(n===s)continue;const h=this.newHalfEdgePair_(),a=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===f)this.setClusterHalfEdge_(n,h),this.setHalfEdgePrev_(h,a),this.setHalfEdgeNext_(a,h);else{const e=this.getHalfEdgePrev(l);this.setHalfEdgePrev_(l,a),this.setHalfEdgeNext_(a,l),this.setHalfEdgeNext_(e,h),this.setHalfEdgePrev_(h,e)}this.setHalfEdgeOrigin_(a,s);const d=this.getClusterHalfEdge(s);if(d===f)this.setClusterHalfEdge_(s,a),this.setHalfEdgeNext_(h,a),this.setHalfEdgePrev_(a,h);else{const e=this.getHalfEdgePrev(d);this.setHalfEdgePrev_(d,h),this.setHalfEdgeNext_(h,d),this.setHalfEdgeNext_(e,a),this.setHalfEdgePrev_(a,e)}const _=this.getGeometryID(o);if(e===De.enumInputModeBuildGraph){const e=m===i.enumPolygon?_:0;if(this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndex,0),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,e),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndexLeft,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndexLeft,0),this.m_bBuildGeometryParentageSets){const e=new be,t=this.m_shape.getGeometryUserIndex(o,this.m_geometryIDIndex);e.setBit(t),this.setEdgeBitSet_(h,e),this.setEdgeBitSet_(a,null),this.setLeftEdgeBitSet_(a,e),this.setLeftEdgeBitSet_(h,null)}}else if(e===De.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(a,this.m_tmpHalfEdgeWindingNumberIndex,n)}else e===De.enumInputModeSimplifyAlternate&&(this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,1),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeOddEvenNumberIndex,1));const p=m===i.enumPolygon?Ye.c_EdgeBitMask:0;this.setHalfEdgeParentage_(h,_|p),this.setHalfEdgeParentage_(a,_|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!==f&&(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!==f){const i=this.getHalfEdgeVertexIterator(e);this.m_clusterVertices.setField(s,1,i),this.setHalfEdgeVertexIterator_(e,s),this.setHalfEdgeVertexIterator_(t,f)}}const s=this.getHalfEdgeTwin(e),i=this.getHalfEdgeTwin(t);{const e=this.getHalfEdgeVertexIterator(i);if(e!==f){const t=this.getHalfEdgeVertexIterator(s);this.m_clusterVertices.setField(e,1,t),this.setHalfEdgeVertexIterator_(s,e),this.setHalfEdgeVertexIterator_(i,f)}}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!==f;s=this.getNextCluster(s)){t.length=0;const i=this.getClusterHalfEdge(s);if(i!==f){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]=ue(t[0],t[0]=t[1]):r=!1;let n=t[0],h=n,o=this.getHalfEdgeTo(h),a=this.getHalfEdgeTwin(h),m=f;for(let s=1,i=t.length;s<i;s++){const i=t[s],r=this.getHalfEdgeTwin(i),g=this.getHalfEdgeOrigin(r);if(g!==o||i===h)this.updateVertexToHalfEdgeConnection_(m,!1),m=f,h=i,o=g,a=r;else{if(e===De.enumInputModeBuildGraph){const e=this.getHalfEdgeParentageMask_(h)|this.getHalfEdgeParentageMask_(i);if(this.setHalfEdgeParentage_(h,e),this.setHalfEdgeParentage_(a,e),this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeParentageIndex)|this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeParentageIndex)),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeParentageIndex,this.getHalfEdgeUserIndex(a,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(a,this.m_tmpHalfEdgeParentageIndexLeft,this.getHalfEdgeUserIndex(a,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 be({copy:e}),s.assignOr(t),this.setEdgeBitSet_(h,s),e=this.getEdgeBitSet_(a),t=this.getEdgeBitSet_(r),s=new be({copy:e}),s.assignOr(t),this.setEdgeBitSet_(a,s),e=this.getLeftEdgeBitSet_(h),t=this.getLeftEdgeBitSet_(i),s=new be({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(h,s),e=this.getLeftEdgeBitSet_(a),t=this.getLeftEdgeBitSet_(r),s=new be({copy:e}),s.assignOr(t),this.setLeftEdgeBitSet_(a,s)}}else if(-1!==this.m_tmpHalfEdgeWindingNumberIndex){const e=this.getHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(i,this.m_tmpHalfEdgeWindingNumberIndex),t=this.getHalfEdgeUserIndex(a,this.m_tmpHalfEdgeWindingNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeWindingNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeWindingNumberIndex,e),this.setHalfEdgeUserIndex(a,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(a,this.m_tmpHalfEdgeOddEvenNumberIndex)+this.getHalfEdgeUserIndex(r,this.m_tmpHalfEdgeOddEvenNumberIndex);this.setHalfEdgeUserIndex(h,this.m_tmpHalfEdgeOddEvenNumberIndex,e),this.setHalfEdgeUserIndex(a,this.m_tmpHalfEdgeOddEvenNumberIndex,t)}this.mergeVertexListsOfEdges_(h,i),this.deleteEdgeImpl_(i),m=h,t[s]=f,i===n&&(t[0]=f,n=f)}}if(this.updateVertexToHalfEdgeConnection_(m,!1),m=f,!r){n=f;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s!==f){n=s;break}}i!==n&&this.setClusterHalfEdge_(s,n);continue}n=f;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s===f)continue;if(n===f){n=s,h=n,o=this.getHalfEdgeTo(h),a=this.getHalfEdgeTwin(h);continue}if(s===h)continue;const i=this.getHalfEdgeTwin(s),r=this.getHalfEdgeOrigin(i);this.setHalfEdgeNext_(a,s),this.setHalfEdgePrev_(s,a),h=s,o=r,a=i}this.setClusterHalfEdge_(s,n)}}}}sortHalfEdgesByAngle3D_(e){o(0)}buildChains_(e){this.m_universeChain=this.newChain_(),this.setChainHalfEdge_(this.m_universeChain,f);let t=this.m_universeChain;const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){const e=this.getClusterHalfEdge(i);if(e!==f){let i=e;do{if(1!==this.getHalfEdgeUserIndex(i,s)){const e=this.newChain_();this.setChainHalfEdge_(e,i),this.setChainPrev_(e,t),this.setChainNext_(t,e);let r=null;this.m_bBuildGeometryParentageSets&&(r=new be),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 U(this.m_chainData.size(),Number.NaN),this.m_chainPerimeters=new U(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_(e){o(0)}simplifyAlternate_(){o(0)}simplifyWinding_(){o(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 w(0);let o=0,a=0;{let e=null!=s?s[0]:this.m_shape.getFirstGeometry(),t=1;for(;e!==f;){this.m_shape.setGeometryUserIndex(e,this.m_geometryIDIndex,a++);for(let t=this.m_shape.getFirstPath(e);t!==f;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)}g(this.m_shape.getGeometryType(e))||(o+=this.m_shape.getPathCount(e)),null!=s?(e=t<s.length?s[t]:f,t++):e=this.m_shape.getNextGeometry(e)}}this.m_universeGeomID=1<<Math.min(a,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,o)),this.m_clusterIndex=this.m_shape.createUserIndex();const m=_e.getNAN();let l=0;const d=_e.getNAN();for(let g=0;g<=this.m_pointCount;g++){if(g<this.m_pointCount){const e=h.read(g);this.m_shape.queryXY(e,d)}else d.setNAN();if(!m.isEqualPoint2D(d)){if(l<g){const e=this.newCluster_();let t=f,s=-1;for(let i=l;i<g;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),o=this.m_shape.getGeometryFromPath(n),a=this.getGeometryID(o);this.setClusterParentage_(e,this.getClusterParentage(e)|a)}this.setClusterVertexIterator_(e,t),this.setClusterVertexIndex_(e,this.m_shape.getVertexIndex(s)),this.m_lastCluster!==f&&this.setNextCluster_(this.m_lastCluster,e),this.setPrevCluster_(e,this.m_lastCluster),this.m_lastCluster=e,this.m_firstCluster===f&&(this.m_firstCluster=e)}l=g,m.setCoordsPoint2D(d)}}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!==f;){for(let t=this.m_shape.getFirstPath(e);t!==f;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]:f,t++):e=this.m_shape.getNextGeometry(e)}}if(t===De.enumInputModeBuildGraph&&(this.m_tmpHalfEdgeParentageIndex=this.createUserIndexForHalfEdges(),this.m_tmpHalfEdgeParentageIndexLeft=this.createUserIndexForHalfEdges()),t===De.enumInputModeSimplifyWinding&&(this.m_tmpHalfEdgeWindingNumberIndex=this.createUserIndexForHalfEdges()),t===De.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_(e,t,s,i,r){o(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_(){o(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,f));const o=this.getHalfEdgeOrigin(i);this.getClusterHalfEdge(o)===i&&(t!==i?this.setClusterHalfEdge_(o,t):this.setClusterHalfEdge_(o,f)),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 f;{const t=e.getElement(s);if(this.getHalfEdgeChain(t)!==this.getHalfEdgeChain(this.getHalfEdgeTwin(t)))return t}}}checkStructureAfterDirtySweep_(){const e=fe(this.m_checkDirtyPlanesweepTolerance),t=new _e,s=new _e,i=new _e,r=new _e,n=new _e;for(let h=this.getFirstCluster();h!==f;h=this.getNextCluster(h)){const o=this.getClusterHalfEdge(h);if(o!==f){let h=o;this.getHalfEdgeFromXY(h,t),this.getHalfEdgeToXY(h,s),i.setSub(s,t);let a=i.sqrLength();do{const o=h;if(h=this.getHalfEdgeNext(this.getHalfEdgeTwin(h)),h!==o){this.getHalfEdgeToXY(h,r),n.setSub(r,t);const o=n.sqrLength(),m=n.crossProduct(i),g=m*m/(o*a);if(Math.min(o,a)*g<=e){if(n.dotProduct(i)>=0)return!1}i.assign(n),a=o,s.assign(r)}}while(h!==o)}}return!0}extractPolygonPathFromChain_(e,t,s,i,r){const n=this.m_shape.hasSegmentParentage(),h=this.getChainHalfEdge(s);let o=h,a=f;const m=new k;do{const h=this.getHalfEdgeTwin(o);if(this.getHalfEdgeChain(h)!==s){let s=f;const h=this.getHalfEdgeOrigin(o);if(i===f){const e=this.getClusterVertexIterator(h);s=this.getVertexFromVertexIterator(e)}else for(let e=this.getClusterVertexIterator(h);e!==f;e=this.incrementVertexIterator(e)){const t=this.getVertexFromVertexIterator(e);s===f&&(s=t);const r=this.m_shape.getPathFromVertex(t);if(this.m_shape.getGeometryFromPath(r)===i){s=t;break}}let g;if(a===f&&(a=e.insertPath(t,f),e.setClosedPath(a,!0)),this.m_shape===e?g=e.addVertex(a,s):(this.m_shape.queryPoint(s,m),g=e.addPoint(a,m)),this.isHalfEdgeCurve(o)&&(this.querySegmentXY(o,r),e.setSegmentToIndex(e.getVertexIndex(g),r.get().clone())),n){const t=this.getSegmentParentage(o);e.setSegmentParentageAndBreak(g,t,this.isBreakNode(h))}}o=this.getHalfEdgeNext(o)}while(o!==h)}mergeSegmentParentage_(){if(!this.m_shape.hasSegmentParentage())return;o(-1!==this.m_clusterBreakNodeIndex),o(-1===this.m_segmentParentageIndex);for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){let e=0;const t=this.getClusterHalfEdge(i);if(t!==f){let s=t;do{e++,s=this.getHalfEdgeNext(this.getHalfEdgeTwin(s))}while(s!==t&&e<3)}2!==e&&this.setBreakNode(i,!0)}let e=[],t=[];this.m_segmentParentageIndex=this.createUserIndexForHalfEdges();const s=this.createUserIndexForHalfEdges();for(let i=this.getFirstCluster();i!==f;i=this.getNextCluster(i)){const r=this.getClusterHalfEdge(i);if(r!==f){let i=!1,n=r;do{let r=n;for(;-1===this.getHalfEdgeUserIndex(r,s);){const n=this.getHalfEdgeNext(r),h=this.getHalfEdgeTwin(r);Re(this,r,t);const o=t.at(-1).parentage;if(!i){const t=this.getHalfEdgeOrigin(r);if(!this.isBreakNode(t)){const t=this.getHalfEdgePrev(r);r!==t&&(Re(this,t,e),i=!0)}}if(i&&!Oe(t,e)){const e=this.getHalfEdgeOrigin(r);this.setBreakNode(e,!0)}e=ue(t,t=e),i=!0;const a=this.getHalfEdgeOrigin(n);this.isBreakNode(a)&&(i=!1),this.setHalfEdgeUserIndex(r,this.m_segmentParentageIndex,o),this.setHalfEdgeUserIndex(h,this.m_segmentParentageIndex,o),this.setHalfEdgeUserIndex(r,s,1),this.setHalfEdgeUserIndex(h,s,1),r=n}n=this.getHalfEdgeNext(this.getHalfEdgeTwin(n))}while(n!==r)}}this.deleteUserIndexForHalfEdges(s)}registerNewBitSet(e){if(null===this.m_uniqueBitSets&&(this.m_uniqueBitSets=Le(),this.m_uniqueBitSets.add(this.getEmptySet())),null===e)return this.getEmptySet();return this.m_uniqueBitSets.has(e)?this.m_uniqueBitSets.get(e):(this.m_uniqueBitSets.add(e),e)}getLeftEdgeBitSet_(e){const t=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft);return o(t>=0),o(this.m_edgeBitSets.at(t)),this.m_edgeBitSets.at(t)}getEdgeBitSet_(e){const t=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndex);return o(t>=0),this.m_edgeBitSets.at(t)}setEdgeBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_edgeBitSetIndex&&(this.m_edgeBitSetIndex=this.createUserIndexForHalfEdges());const s=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndex);-1!==s?this.m_edgeBitSets[s]=t:(this.setHalfEdgeUserIndex(e,this.m_edgeBitSetIndex,this.m_edgeBitSets.length),this.m_edgeBitSets.push(t))}setLeftEdgeBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_edgeBitSetIndexLeft&&(this.m_edgeBitSetIndexLeft=this.createUserIndexForHalfEdges());const s=this.getHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft);-1!==s?this.m_edgeBitSets[s]=t:(this.setHalfEdgeUserIndex(e,this.m_edgeBitSetIndexLeft,this.m_edgeBitSets.length),this.m_edgeBitSets.push(t))}setChainBitSet_(e,t){o(this.m_bBuildGeometryParentageSets),t=this.registerNewBitSet(t),-1===this.m_chainBitSetIndex&&(this.m_chainBitSetIndex=this.createUserIndexForChains());const s=this.getChainUserIndex(e,this.m_chainBitSetIndex);-1!==s?this.m_chainBitSets[s]=t:(this.setChainUserIndex(e,this.m_chainBitSetIndex,this.m_chainBitSets.length),this.m_chainBitSets.push(t))}getEmptySet(){return this.m_emptyBitSet||(this.m_emptyBitSet=new be),this.m_emptyBitSet}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_(e){}dbgVerifyEdgeSegment(e){}}function Me(e,t,s,i){s>0&&se(e,s,t,!1,i);new qe(i).executeImpl_(e,t)}function Xe(e,t,s){return{vertex0:e,vertex1:t,dir:s}}Ye.c_EdgeParentageMask=~(1<<31),Ye.c_EdgeBitMask=1<<31;class qe{constructor(e){this.m_shape=null,this.m_spikes=[],this.m_points=new w(0),this.m_pointsIndex=-1,this.m_dissolvedEdges=0,this.m_progressTracker=e}executeImpl_(e,t){if(this.m_shape=e,e.getPathCount(t)<2&&e.getPointCount(t)<6)return;this.m_points.resize(0);for(let o=e.getFirstPath(t);o!==f;o=e.getNextPath(o)){let t=e.getFirstVertex(o);for(let s=0,i=e.getPathSize(o);s<i;s++,t=e.getNextVertex(t))this.m_points.add(t)}this.m_pointsIndex=e.createUserIndex();for(let o=0,l=this.m_points.size();o<l;++o)e.setUserIndex(this.m_points.read(o),this.m_pointsIndex,o);e.sortVerticesSimpleByY(this.m_points,0,this.m_points.size());let s=this.m_points.read(0);const i=e.getXY(s);let r=1,n=0;const h=[];for(let o=1;o<this.m_points.size();o++){const t=this.m_points.read(o);if(t===f)continue;if(-1===e.getUserIndex(t,this.m_pointsIndex))continue;const a=e.getXY(t);if(a.isEqualPoint2D(i))r++;else{if(r>1){for(let t=n;t<o;t++){const s=this.m_points.read(t);if(-1===e.getUserIndex(s,this.m_pointsIndex))continue;const r=e.getNextVertex(s),n=e.getPrevVertex(s);if(s!==r&&!e.isEqualXYPoint2D(r,i)){const e=Xe(s,r,1);h.push(e)}if(s!==n&&n!==r&&!e.isEqualXYPoint2D(n,i)){const e=Xe(s,n,-1);h.push(e)}}h.length>0&&this.processBunch_(h,i)}s=t,i.assign(a),r=1,n=o}}if(0===this.m_dissolvedEdges)return e.removeUserIndex(this.m_pointsIndex),void(this.m_pointsIndex=-1);let a=e.getPointCount(t);for(let o=0;o<this.m_points.size();o++){const t=this.m_points.read(o);if(t===f)continue;if(-1!==e.getUserIndex(t,this.m_pointsIndex)){e.setUserIndex(t,this.m_pointsIndex,-1);continue}const s=e.getPathFromVertex(t);e.getFirstVertex(s)===t&&e.setFirstVertex(s,f),e.freeVertex(t),this.m_points.write(o,f),a--}const m=e.createPathUserIndex();let g=e.getPathCount(t);for(let l=0,d=this.m_points.size();l<d;++l){if(this.m_points.read(l)===f)continue;let s=this.m_points.read(l);if(-1!==e.getUserIndex(s,this.m_pointsIndex))continue;let i=e.getPathFromVertex(s),r=-1;if(2===e.getPathUserIndex(i,m)){i=f;for(let t=e.getNextVertex(s);t!==s;t=e.getNextVertex(t)){const r=e.getPathFromVertex(t);if(2!==e.getPathUserIndex(r,m)){i=r,s=t;break}}i===f&&(i=e.insertPath(t,f),e.setClosedPath(i,!0),g++),o(i!==f)}e.setPathUserIndex(i,m,2),r=e.getFirstVertex(i);let n=0,h=!1,a=s;do{r===a&&(h=!0),e.setUserIndex(a,this.m_pointsIndex,1);const t=e.getPathFromVertex(a);t!==i&&(2!==e.getPathUserIndex(t,m)&&(e.setPathUserIndex(t,m,1),e.setFirstVertex(t,f)),e.setPathToVertex(a,i)),n++,a=e.getNextVertex(a)}while(a!==s);h||e.setFirstVertex(i,s),e.setPathSize(i,n)}for(let o=e.getFirstPath(t);o!==f;){const t=e.getNextPath(o);1!==e.getPathUserIndex(o,m)&&e.getFirstVertex(o)!==f||(e.removePathOnly(o),g--),o=t}e.setGeometryVertexCount(t,a),e.setGeometryPathCount(t,g),e.removePathUserIndex(m),e.removeUserIndex(this.m_pointsIndex),this.m_pointsIndex=-1,e.dbgVerifyVertexCounts(),e.filterClosePoints(0,!0,!1,!1,t)}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=_e.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,o=e.length;h<o;h++){const t=this.m_shape.getXY(e[h].vertex1);if(!(t.isEqualPoint2D(i)&&(r++,h+1<o))){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}}function ze(e,t,s,i,r){const n=new Ke(r);return n.m_shape=e,n.m_geometry=t,n.m_sortedVertices=s,n.m_bFixSelfTangency=i,n.fixRingOrientation_()}function We(e,t,s){const i=new Ke(s);return i.m_shape=e,i.m_geometry=t,i.m_sortedVertices=null,i.m_bFixSelfTangency=!1,i.fixRingOrientationForMp2sp_()}class Ze{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(e){let t=this.getEnd1(e),s=this.getEnd2(e);this.m_shape.getPrevVertex(t)===s&&(s=ue(t,t=s));const i=_e.getNAN(),r=_e.getNAN();return this.m_shape.queryXY(t,i),this.m_shape.queryXY(s,r),o(!i.equals(r)),i.y<r.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 je=class extends Z{constructor(e){super(),this.m_line1=new j,this.m_line2=new j,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,o=r.getSegment(i);if(o)h=o.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);else{r.getShape().queryLineConnector(r.getStart(i),this.m_line2,!0),o=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),a=e?this.m_seg1.getEndY():this.m_seg1.getStartY(),m=s?o.getEndY():o.getStartY(),g=Math.min(a,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=o.intersectionOfYMonotonicWithAxisX(l,0),n===h&&_("")}return n<h?-1:n>h?1:0}reset(){this.m_leftElm=-1}};class Qe{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 f;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 f}}class Ke{constructor(e){this.m_edges=null,this.m_shape=null,this.m_AET=new D,this.m_yScanline=0,this.m_geometry=f,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 je(this),this.m_AET.setComparator(this.m_sweepComparator)}fixRingOrientation_(){const e=this.fixRingOrientationImplMain_();return-1===this.m_pathOrientationIndex||this.fixRingOrientationImplSimplify_(),e}fixRingOrientationForMp2sp_(){return this.fixRingOrientationImplMain_(),-1===this.m_pathOrientationIndex?-1:this.fixRingOrientationImplMp2sp_()}processBunchForRingOrientationTest_(e){return this.processBunchForRingOrientationTestOddEven_(e)}processBunchForRingOrientationTestOddEven_(e){let t=!1;if(this.m_edges||(this.m_edges=new Ze(this.m_shape)),this.m_unknownNodes.length=0,this.processBunchForRingOrientationRemoveEdges_(e),!this.m_AET.isAutoBalancing()){let t=0;for(let s=0,i=e.length;s<i;s++){-1!==e[s]&&t++}(t>10||this.m_AET.getMaxDepthEver()>4)&&this.m_AET.enableBalancing()}for(let s=0,i=e.length;s<i;s++){const t=e[s];t!==f&&this.insertEdge_(t,-1)}for(let s=0;s<this.m_unknownNodes.length&&this.m_unknownRingOrientationCount>0;s++){const e=this.m_unknownNodes[s],i=this.m_AET.getElement(e),r=this.m_edges.getPath(i),n=this.m_shape.getPathUserIndex(r,this.m_pathOrientationIndex);let h=f;if(0===n){let s=this.m_AET.getPrev(e),i=e,r=!1;for(;s!==D.st_nullNode();){const e=this.m_AET.getElement(s),t=this.m_edges.getPath(e);if(0!==this.m_shape.getPathUserIndex(t,this.m_pathOrientationIndex)){h=t;break}i=s,s=this.m_AET.getPrev(s)}if(s===D.st_nullNode())r=!0,s=i;else{const e=this.m_AET.getElement(s);r=this.m_edges.isBottomUp(e),s=this.m_AET.getNext(s),r=!r}do{const e=this.m_AET.getElement(s),n=this.m_edges.getPath(e);if(0===this.m_shape.getPathUserIndex(n,this.m_pathOrientationIndex)){if(r!==this.m_edges.isBottomUp(e)){const e=this.m_shape.getFirstVertex(n);this.m_shape.reverseRingInternal(e),this.m_shape.setLastVertex(n,this.m_shape.getPrevVertex(e)),t=!0}if(this.m_shape.setPathUserIndex(n,this.m_pathOrientationIndex,r?3:2),!r){let e=this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex);2===e?(h=this.m_shape.getPathUserIndex(h,this.m_pathParentsIndex),e=this.m_shape.getPathUserIndex(h,this.m_pathOrientationIndex),o(3===e)):o(3===e);const t=this.m_shape.getPathUserIndex(h,this.m_pathParentageIndex);this.m_shape.setPathUserIndex(h,this.m_pathParentageIndex,n),this.m_shape.setPathUserIndex(n,this.m_pathParentageIndex,t),this.m_shape.setPathUserIndex(n,this.m_pathParentsIndex,h)}if(this.m_unknownRingOrientationCount--,!this.m_unknownRingOrientationCount)return t}h=n,i=s,s=this.m_AET.getNext(s),r=!r}while(i!==e)}}return t}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]=f):n=-1!==i?i:r,-1!==n&&(this.insertEdge_(s,n)||this.m_AET.deleteNode(n),e[t]=f)}}dbgVerifyRingOrientation_(){}insertEdge_(e,t){const s=_e.getNAN(),i=_e.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_(){const e=[],t=[];let s=-1,i=-1;const r=new _e;let n=f,h=f,a=-1;const m=new Qe(this);for(let o=m.next();o!==f;o=m.next()){const m=new _e;this.m_shape.queryXY(o,m);const g=this.m_shape.getPathFromVertex(o);if(r.equals(m)&&h===g){if(-1===i&&(s=this.m_shape.createPathUserIndex(),this.m_shape.fillPathUserIndexForGeometry(this.m_geometry,s,-1),i=this.m_shape.createUserIndex(),this.m_shape.fillUserIndexForGeometry(this.m_geometry,i,-1)),-1===a){a=t.length,this.m_shape.setUserIndex(n,i,a),t.push(1);-1===this.m_shape.getPathUserIndex(g,s)&&(this.m_shape.setPathUserIndex(g,s,n),e.push(g))}this.m_shape.setUserIndex(o,i,a),t[t.length-1]++}else a=-1,r.assign(m);n=o,h=g}if(0===e.length)return!1;o(-1!==s);for(let o=0,g=e.length;o<g;o++){const r=e[o];let n=this.m_shape.getPathUserIndex(r,s);const h=this.m_shape.getUserIndex(n,i),a=[],m=[];a.push(n),m.push(h);for(let e=this.m_shape.getNextVertex(n);e!==n;e=this.m_shape.getNextVertex(e)){const s=e,r=this.m_shape.getUserIndex(s,i);if(-1!==r){if(0===m.length){m.push(r),a.push(s);continue}if(m.at(-1)===r){const h=a.at(-1);this.m_shape.peelALoopIntoAPath(h,s),this.m_shape.setUserIndex(e,i,-1),t[r]--,1===t[r]&&(t[r]=0,m.pop(),a.pop()),n=h,e=h}else a.push(e),m.push(r)}}}return this.m_shape.removePathUserIndex(s),this.m_shape.removeUserIndex(i),this.m_shape.dbgVerifyVertexCounts(),!0}progress_(e=!1){}fixRingOrientationImplMain_(){const e={stack:[],error:void 0,hasError:!1};try{let t,s=!1;const i=Ve(e,xe((()=>{this.m_sortedVerticesArray=null})),!1);if(null===this.m_sortedVertices){const e=this.m_shape.getPointCount(this.m_geometry);t=new w(0);for(let s=this.m_shape.getFirstPath(this.m_geometry);s!==f;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 this.m_shape.reverseRingInternal(t),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!==f;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=_e.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 Qe(this);for(let e=h.next();e!==f&&(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{ve(e)}}fixRingOrientationImplSimplify_(){const e=[];for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==f;)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!==f;){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!==f;e=this.m_shape.getNextPath(e),--i){if(this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex)!==t){s=f;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,B),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_(){const e=this.m_shape.createPathUserIndex();let t=0;const s=[];for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;)if(this.progress_(),3===this.m_shape.getPathUserIndex(i,this.m_pathOrientationIndex)){this.m_shape.setExterior(i,!0),this.m_shape.setPathUserIndex(i,e,t),t++;for(let e=this.m_shape.getPathUserIndex(i,this.m_pathParentageIndex);e!==f;){const t=this.m_shape.getPathUserIndex(e,this.m_pathParentageIndex);s.push(e),this.m_shape.setExterior(e,!1),this.m_shape.setPathUserIndex(e,this.m_pathParentageIndex,i),e=t}let r=i,n=s.length,h=t;for(let t=this.m_shape.getNextPath(i);n>0&&t!==f;t=this.m_shape.getNextPath(t),--n){if(this.m_shape.getPathUserIndex(t,this.m_pathParentageIndex)!==i){r=f;break}r=t,this.m_shape.setPathUserIndex(t,e,-h),h++}if(0!==n){r=i,h=t;for(let t=0,i=s.length;t<i;t++){const i=s[t];this.m_shape.setPathUserIndex(i,e,-h),h++,this.m_shape.setPathUserIndex(i,this.m_pathParentageIndex,B)}r=i}t=h,s.length=0,i=this.m_shape.getNextPath(r)}else i=this.m_shape.getNextPath(i);return this.m_shape.removePathUserIndex(this.m_pathOrientationIndex),this.m_shape.removePathUserIndex(this.m_pathParentageIndex),this.m_shape.removePathUserIndex(this.m_pathParentsIndex),e}}function Je(e,t,s,i,r,n){const h=new $e(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 $e{constructor(e){this.m_shape=null,this.m_geometry=f,this.m_sortedVertices=new R,this.m_bunchEdgeEndPoints=[],this.m_bunchEdgeCenterPoints=[],this.m_bunchEdgeIndices=[],this.m_knownSimpleResult=-1,this.m_sortedVerticesListIndex=-1,this.m_polylineDegeneracies=f,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 _e;this.m_shape.queryXY(s,i);const r=new _e,n=this.m_bunchEdgeEndPoints[t];if(this.m_shape.queryXY(n,r),i.equals(r))return 0;const h=this.m_bunchEdgeCenterPoints[e],o=new _e;this.m_shape.queryXY(h,o);const a=this.m_bunchEdgeCenterPoints[t],m=new _e;this.m_shape.queryXY(a,m);const g=new _e;g.setSub(i,o);const l=new _e;l.setSub(r,m),(g.isZero()||l.isZero())&&_("");return _e.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,o=this.m_shape.getNextVertex(n)===i,a=new E,m=new _e;h?(this.m_shape.querySegment(r,a,!1,!0),m.assign(a.get().getTangent(0))):(this.m_shape.querySegment(s,a,!1,!0),m.assign(a.get().getTangent(1)),m.negateThis());const g=new _e;o?(this.m_shape.querySegment(n,a,!1,!0),g.assign(a.get().getTangent(0))):(this.m_shape.querySegment(i,a,!1,!0),g.assign(a.get().getTangent(1)),g.negateThis()),(m.isZero()||g.isZero())&&_("");return _e.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!==f){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,f),this.m_shape.setLastVertex(t,f)}}}}processBunch_(){let e=!1;const t=new _e(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)!==B&&(this.m_bunchEdgeEndPoints.push(n),this.m_shape.setUserIndex(n,this.m_userIndexSortedAngleIndexToVertex,B),this.m_bunchEdgeCenterPoints.push(e),this.m_bunchEdgeIndices.push(i++));this.m_shape.getUserIndex(h,this.m_userIndexSortedAngleIndexToVertex)!==B&&(this.m_bunchEdgeEndPoints.push(h),this.m_shape.setUserIndex(h,this.m_userIndexSortedAngleIndexToVertex,B),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],o=this.m_bunchEdgeEndPoints[n],a=this.m_bunchEdgeEndPoints[h];let m=this.m_shape.getNextVertex(o),g=!1;this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(o),g=!0);let l=this.m_shape.getNextVertex(a),d=!1;this.m_shape.isEqualXYPoint2D(l,e)||(l=this.m_shape.getPrevVertex(a),d=!0);const _=g?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=d?this.m_shape.getPrevVertex(l):this.m_shape.getNextVertex(l);let u=!1;(this.removeSpike_(m)||this.removeSpike_(l)||this.removeSpike_(o)||this.removeSpike_(a)||this.removeSpike_(_)||this.removeSpike_(p))&&(u=!0),m!==l&&(!u&&this.m_shape.isEqualXY(o,a)&&(u=this.resolveOverlap_(g,d,m,o,l,a)),!u&&this.m_shape.isEqualXY(_,p)&&(u=this.resolveOverlap_(!g,!d,m,_,l,p)),!u&&this.m_shape.isEqualXY(o,p)&&(u=this.resolveOverlap_(g,!d,m,o,l,p)),!u&&this.m_shape.isEqualXY(_,a)&&(u=this.resolveOverlap_(!g,d,m,_,l,a))),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],o=this.m_bunchEdgeEndPoints[n];let a=this.m_shape.getNextVertex(h);this.m_shape.isEqualXYPoint2D(a,e)||(a=this.m_shape.getPrevVertex(h));let m=this.m_shape.getNextVertex(o);this.m_shape.isEqualXYPoint2D(m,e)||(m=this.m_shape.getPrevVertex(o));const g=this.getDirection_(a,h),l=this.getDirection_(m,o),d=g?this.m_shape.getPrevVertex(a):this.m_shape.getNextVertex(a),_=l?this.m_shape.getPrevVertex(m):this.m_shape.getNextVertex(m),p=this.detectAndResolveCrossOver_(g,l,h,a,d,o,m,_);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 Et(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 w(0);this.m_shape.dbgVerifyMonotone();for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;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,h=!1;do{h=!1,this.m_nextVertexToProcess=-1,this.m_firstCoincidentVertex=this.m_sortedVertices.getFirst(this.m_sortedVerticesListIndex);const t=new _e(0,0);this.m_firstCoincidentVertex!==R.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(this.m_firstCoincidentVertex),t);let s=0,i=this.m_firstCoincidentVertex;for(;i!==R.st_nullNode()&&(i=this.m_sortedVertices.getNext(i),i!==R.st_nullNode());){this.progress_();const e=this.m_sortedVertices.getData(i),r=_e.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!==R.st_nullNode()&&this.m_shape.queryXY(this.m_sortedVertices.getData(i),r),e&&(h=!0)}t.setCoordsPoint2D(r),this.m_firstCoincidentVertex=i,s=0}}if(this.m_nextVertexToProcess=-1,s>0){this.processBunch_()&&(h=!0)}r++>10&&n(""),h&&this.fixOrphanVertices_(),this.cleanupSpikes_()&&(h=!0),e||=h}while(h);return this.m_shape.dbgVerifyMonotone(),this.m_shape.dbgVerifyCurves(),this.m_shape.removeUserIndex(this.m_userIndexSortedIndexToVertex),this.m_shape.removeUserIndex(this.m_userIndexSortedAngleIndexToVertex),e=ze(this.m_shape,this.m_geometry,this.m_sortedVertices,this.m_bFixSelfTangency,this.m_progressTracker)||e,this.m_shape.dbgVerifyCurves(),e}getDirection_(e,t){return this.m_shape.getNextVertex(t)!==e}detectAndResolveCrossOver_(e,t,s,i,r,n,h,o){if(i===h)return this.removeAngleSortInfo_(s),this.removeAngleSortInfo_(n),-1;const a=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(o,this.m_userIndexSortedAngleIndexToVertex),d=new Array(8),_=new Array(4);d[0]=0,_[0]=a,d[1]=0,_[1]=m,d[2]=1,_[2]=g,d[3]=1,_[3]=l;for(let u=1;u<4;u++){const e=_[u],t=d[u];let s=u-1;for(;s>=0&&_[s]>e;)_[s+1]=_[s],d[s+1]=d[s],s--;_[s+1]=e,d[s+1]=t}let p=0;if(d[0]&&(p|=1),d[1]&&(p|=2),d[2]&&(p|=4),d[3]&&(p|=8),5!==p&&10!==p)return 0;if(e!==t&&(o=ue(n,n=o)),e)this.m_shape.setNextVertex(o,i),this.m_shape.setPrevVertex(i,o),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(o,i),this.m_shape.setNextVertex(i,o),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=ue(s,s=r),n=ue(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,o=t?r:n,a=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(o);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 d=!1;this.m_shape.setNextVertex(h,o),this.m_shape.setNextVertex(o,h),this.m_shape.setPrevVertex(a,m),this.m_shape.setPrevVertex(m,a);let _=m;for(;_!==o;){const e=this.m_shape.getPrevVertex(_),t=this.m_shape.getNextVertex(_);if(this.m_shape.setPrevVertex(_,t),this.m_shape.setNextVertex(_,e),d||=_===h,this.m_bHasSegments&&_!==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}_=t}let p=null;if(!d){const e=this.m_shape.getPrevVertex(o),t=this.m_shape.getNextVertex(o);if(this.m_shape.setPrevVertex(o,t),this.m_shape.setNextVertex(o,e),this.m_bHasSegments){const e=this.m_shape.getVertexIndex(o);p=this.m_shape.getSegmentFromIndex(e),this.m_shape.setSegmentToIndex(e,null)}}let u=-1,c=-1;if(this.m_bHasSegmentParentage&&(u=d?this.m_shape.getSegmentParentage(h):this.m_shape.getSegmentParentage(o),c=this.m_shape.getSegmentParentage(a)),this.transferVertexData_(o,h),this.beforeRemoveVertex_(o,!0),this.m_shape.removeVertexInternal(o,!0),this.removeAngleSortInfo_(h),this.transferVertexData_(m,a),this.beforeRemoveVertex_(m,!0),this.m_shape.removeVertexInternal(m,!0),this.removeAngleSortInfo_(a),this.m_bHasSegmentParentage&&(this.m_shape.setSegmentParentageAndBreak(h,u,!0),this.m_shape.setSegmentParentageAndBreak(a,c,!0)),p){const e=this.m_shape.getVertexIndex(h);this.m_shape.setSegmentToIndex(e,p)}}return!0}cleanupSpikes_(){let e=!1;for(let t=this.m_shape.getFirstPath(this.m_geometry);t!==f;){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===f)break;h?(e=!0,i=s,r=0,n=this.m_shape.getPathSize(t)):(i=s,r++)}t=s}return e}checkAndCleanupSpike_(e,t){const s={v:f,bModified:!1};let i=this.m_shape.getPrevVertex(t),r=this.m_shape.getNextVertex(t),n=f,h=f;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===f)return s.v=r,s;s.bModified=!0;for(let o=this.m_shape.getNextVertex(n);this.beforeRemoveVertex_(o,!1),o!==h;o=this.m_shape.getNextVertex(o));if(n===t)return this.m_polylineDegeneracies!==f?this.m_shape.movePath(this.m_polylineDegeneracies,f,e):this.m_shape.removePath(e),s.v=f,s;{const e=this.m_shape.peelALoopIntoAPath(n,h);this.m_polylineDegeneracies!==f?this.m_shape.movePath(this.m_polylineDegeneracies,f,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=f,r=f;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===f)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===f)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,f,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,f)}let t=0;for(let i=this.m_shape.getFirstPath(this.m_geometry);i!==f;){const s=this.m_shape.getFirstVertex(i);if(s===f||this.m_shape.getPathFromVertex(s)!==f){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)!==f)continue;const r=[!1],n=this.m_shape.insertClosedPath(this.m_geometry,f,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!==f;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){}}var et=a,tt=h,st=r;function it(e){switch(e){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 0:return 0;default:o(0,"unrecognized cut side")}return 3}function rt(){return{unsplitBehavior:0,allCrossRoadsImpassable:!1,ogcRule:!1}}function nt(e,t,s,i){return new Et(i).autoCompleteImpl(e,t,s)}function ht(e,t,s,r,n,h,o){const a=new Et(n);a.m_bOGCOutput=!0;const m=e.getGeometryType()===i.enumPolygon&&1===e.getFillRule()&&!v(r);return a.planarSimplifyImpl_(e,t,m,s,r,n,h,o)}function ot(e,t,s,i,r,n,h,o){return new Et(n).planarSimplifyImpl_(e,t,s,i,r,n,h,o)}function at(e,t,s,i){const r=new Et(i),n=new c,h=n.addGeometry(t),a=r.planarSimplifyNoCrackingAndCluster(e,n,h,s);o(a,"planar_simplify_no_cracking_and_cluster");return n.getGeometry(h)}function mt(e,t,s,i,r,n,h){return o(0),{}}function gt(e,t,s,i){return o(0),{}}function lt(e,t,s){return yt(e,t,s)}function dt(e,t,s,r){if(e.isEmpty()||t.isEmpty()||e.getDimension()>t.getDimension())return St(Ct(e),e,t,"-");const n=new N;e.queryEnvelope(n);const h=new N;t.queryEnvelope(h);const o=new N;o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=h.clone(),g=H(a);if(m.inflateCoords(g,g),!n.isIntersecting(m))return St(Ct(e),e,t,"-");const l=new Et(r),d=new c,_=d.addGeometry(Ct(e)),p=d.addGeometry(Ct(t));let u=0,f=0,I=null;if(d.hasCurves()){I=new ie;const e=d.getEnvelope2D(r);f=Q(a.total());const t=K(a.total(),e);u=re(t,f),J(d,t,a.total(),12e3,I,null,r)}l.setEditShapeCrackAndCluster(d,a.add(u));const E=l.difference(_,p);null!==I&&I.stitchCurves(d,E,f,!0);const P=St(d.getGeometry(E),e,t,"-");return et(P.getGeometryType())&&(P.getImpl().setIsSimple(4,a.total()),P.getGeometryType()===i.enumPolygon&&P.getImpl().updateOGCFlagsProtected()),P}function _t(e,t,s,r){if(e.getDimension()>t.getDimension())return St(Ct(e),e,t,"^");if(e.getDimension()<t.getDimension())return St(Ct(t),e,t,"^");if(e.isEmpty())return St(Ct(t),e,t,"^");if(t.isEmpty())return St(Ct(e),e,t,"^");const n=new N;e.queryEnvelope(n);const h=new N;t.queryEnvelope(h);const o=new N;o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=new Et(r),g=new c,l=g.addGeometry(Ct(e)),d=g.addGeometry(Ct(t));let _=0,p=null;if(g.hasCurves()){p=new ie;const e=g.getEnvelope2D(r);_=Q(a.total());const t=K(a.total(),e);J(g,t,a.total(),12e3,p,null,r)}m.setEditShapeCrackAndCluster(g,a);const u=m.symmetricDifference(l,d);null!==p&&p.stitchCurves(g,u,_,!0);const f=St(g.getGeometry(u),e,t,"^");return et(f.getGeometryType())&&(f.getImpl().setIsSimple(4,a.total()),f.getGeometryType()===i.enumPolygon&&f.getImpl().updateOGCFlagsProtected()),f}function pt(e,t,s){return Pt(e,t,s,!0)}function ut(e,t,s){return e.isEmpty()||t.isEmpty()?e.createInstance():me(s,e,t)?new k({copy:ge(e,t)}):e.createInstance()}function ct(e,t,s,r){const n=N.constructEmpty();e.queryEnvelope(n);const h=N.constructEmpty();t.queryEnvelope(h);const o=N.constructEmpty();o.setCoords({env2D:n}),o.mergeEnvelope2D(h);const a=x(s,o,!0),m=new N(h),g=H(a);if(m.inflateCoords(g,g),!n.isIntersecting(m)){if(e.getDimension()<=t.getDimension())return St(Ct(e.createInstance()),e,t,"&");if(e.getDimension()>t.getDimension())return St(Ct(t.createInstance()),e,t,"&")}const l=new Et(r),d=new c,_=d.addGeometry(Ct(e)),p=d.addGeometry(Ct(t));let u=0,f=0,I=null;if(d.hasCurves()){I=new ie;const e=d.getEnvelope2D(r);f=Q(a.total());const t=K(a.total(),e);u=re(t,f),J(d,t,a.total(),12e3,I,null,r)}l.setEditShapeCrackAndCluster(d,a.add(u));const E=l.intersection(_,p);null!==I&&I.stitchCurves(d,E,f,!0);const P=St(d.getGeometry(E),e,t,"&");return et(P.getGeometryType())&&(P.getImpl().setIsSimple(4,a.total()),P.getGeometryType()===i.enumPolygon&&P.getImpl().updateOGCFlagsProtected()),P}function ft(e,t,s,r){const n=new Array(3),h=N.constructEmpty();e.queryEnvelope(h);const o=N.constructEmpty();t.queryEnvelope(o);const a=N.constructEmpty();a.setCoords({env2D:h}),a.mergeEnvelope2D(o);const m=x(s,a,!0),g=new N(o),l=H(m);if(g.inflateCoords(l,l),!h.isIntersecting(g)){if(e.getDimension()<=t.getDimension()){const s=St(Ct(e.createInstance()),e,t,"&");return n[s.getDimension()]=s,n}if(e.getDimension()>t.getDimension()){const s=St(Ct(t.createInstance()),e,t,"&");return n[s.getDimension()]=s,n}}const d=new Et(r),_=new c,p=_.addGeometry(Ct(e)),u=_.addGeometry(Ct(t));let f=0,I=0,E=null;if(_.hasCurves()){E=new ie;const e=_.getEnvelope2D(r);I=Q(m.total());const t=K(m.total(),e);f=re(t,I),J(_,t,m.total(),12e3,E,null,r)}d.setEditShapeCrackAndCluster(_,m.add(f)),_.dbgVerifyCurves();const P=d.intersectionEx(p,u);for(const c of P){null!==E&&E.stitchCurves(_,c,I,!1);const s=St(_.getGeometry(c),e,t,"&");et(s.getGeometryType())&&(s.getImpl().setIsSimple(4,m.total()),s.getGeometryType()===i.enumPolygon&&s.getImpl().updateOGCFlagsProtected()),n[s.getDimension()]=s}return null!==E&&E.clearStitcher(_),n}function xt(e,t,i,r,n,h=!1){0===t&&s("not enough geometries to dissolve");let o=0;for(let s=0,u=t;s<u;s++)o=Math.max(e[s].getDimension(),o);if(2===o||1===o)return new Et(r).dissolveMultiPaths_(o,!1,e,t,i,n,h);let a=0,m=-1;for(let s=0,u=t;s<u;s++)e[s].getDimension()===o&&(-1===m&&(m=s),e[s].isEmpty()||(m=s,a++));if(a<2)return Ct(e[m]);const g=u.constructEmpty(),l=new c;let d=f;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===o&&!e[s].isEmpty()){d===f?d=l.addGeometry(Ct(e[s])):l.appendGeometry(d,Ct(e[s]));const t=u.constructEmpty();e[s].queryLooseEnvelope(t),g.mergeEnv3D(t)}const _=x(i,g.getEnvelope2D(),!0),p=new Et(r);if(h){const e=I(i,g.getEnvelopeZs(),!0);return p.planarSimplify3DImpl_(l,_,e,0,!0)}return p.m_bOGCOutput=!0,p.planarSimplifyMultiPoints(l,_,!1,-1)}function It(e,t,i,r,n,h=!1){t<2&&s("not enough geometries to dissolve");let o=0;for(let s=0,u=t;s<u;s++)o=Math.max(e[s].getDimension(),o);if(2===o||1===o)return new Et(r).dissolveMultiPaths_(o,!0,e,t,i,n,h);const a=u.constructEmpty(),m=new c;let g=f,l=0,d=-1;for(let s=0,c=t;s<c;s++)if(e[s].getDimension()===o&&(-1===d&&(d=s),!e[s].isEmpty())){d=s,g===f?g=m.addGeometry(Ct(e[s])):m.appendGeometry(g,Ct(e[s]));const t=u.constructEmpty();e[s].queryLooseEnvelope(t),a.mergeEnv3D(t),l++}if(l<2)return Ct(e[d]);const _=0===o?i:null,p=x(_,a.getEnvelope2D(),!0),E=new Et(r);if(h){const e=I(_,a.getEnvelopeZs(),!0);return E.m_bOGCOutput=!0,E.planarSimplify3DImpl_(m,p,e,0,!0)}return E.planarSimplifyMultiPoints(m,p,!0,-1)}class Et{constructor(e){this.m_topoGraph=null,this.m_maskLookup=[],this.m_dummyPt1=_e.getNAN(),this.m_dummyPt2=_e.getNAN(),this.m_fromEdgeForPolylines=f,this.m_progressCounter=0,this.m_bOGCOutput=!1,this.m_progressTracker=e}linesToPolygonsImpl(t,s){let i=0,r=0,n=null;if(t.hasCurves()){n=new ie;const e=t.getEnvelope2D(this.m_progressTracker);r=Q(s.total());const h=K(s.total(),e);i=re(h,r),J(t,h,s.total(),12e3,n,null,this.m_progressTracker)}this.setEditShapeCrackAndCluster(t,s.add(i));const h=this.m_topoGraph.createUserIndexForChains(),o=this.m_topoGraph.getFirstChain();this.m_topoGraph.setChainUserIndex(o,h,1);for(let e=this.m_topoGraph.getChainFirstIsland(o);e!==f;e=this.m_topoGraph.getChainNextInParent(e))this.m_topoGraph.setChainUserIndex(e,h,1);const a=[];for(let e=this.m_topoGraph.getFirstChain();e!==f;e=this.m_topoGraph.getChainNext(e)){if(1===this.m_topoGraph.getChainUserIndex(e,h))continue;this.m_topoGraph.setChainUserIndex(e,h,1);for(let t=this.m_topoGraph.getChainFirstIsland(e);t!==f;t=this.m_topoGraph.getChainNextInParent(t))this.m_topoGraph.setChainUserIndex(t,h,1);if(0===this.m_topoGraph.getChainArea(e))continue;const s=this.m_topoGraph.extractPolygonFromChainAndIslands(t,f,e,f);null!=n&&n.stitchCurves(t,s,r,!1);const i=t.getGeometry(s);a.push(i)}return new e(a)}autoCompleteImpl(t,s,i){let r=0,n=0,h=null;if(t.hasCurves()){h=new ie;const e=t.getEnvelope2D(this.m_progressTracker);n=Q(i.total());const s=K(i.total(),e);r=re(s,n),J(t,s,i.total(),12e3,h,null,this.m_progressTracker)}this.setEditShapeCrackAndCluster(t,i.add(r));const o=this.m_topoGraph.getGeometryID(s),a=this.m_topoGraph.createUserIndexForChains(),m=this.m_topoGraph.getFirstChain();this.m_topoGraph.setChainUserIndex(m,a,1);for(let e=this.m_topoGraph.getChainFirstIsland(m);e!==f;e=this.m_topoGraph.getChainNextInParent(e))this.m_topoGraph.setChainUserIndex(e,a,1);const g=[];for(let e=this.m_topoGraph.getFirstChain();e!==f;e=this.m_topoGraph.getChainNext(e)){if(1===this.m_topoGraph.getChainUserIndex(e,a))continue;this.m_topoGraph.setChainUserIndex(e,a,1);for(let t=this.m_topoGraph.getChainFirstIsland(e);t!==f;t=this.m_topoGraph.getChainNextInParent(t))this.m_topoGraph.setChainUserIndex(t,a,1);if(0!==this.m_topoGraph.getChainParentage(e))continue;const s=this.m_topoGraph.getChainHalfEdge(e);let i=s,r=!1;do{const t=this.m_topoGraph.getHalfEdgeTwin(i);if(this.m_topoGraph.getHalfEdgeChain(t)!==e&&this.m_topoGraph.getHalfEdgeParentage(i)&o){r=!0;break}i=this.m_topoGraph.getHalfEdgeNext(i)}while(i!==s);if(!r)continue;if(0===this.m_topoGraph.getChainArea(e))continue;const m=this.m_topoGraph.extractPolygonFromChainAndIslands(t,f,e,f);null!==h&&h.stitchCurves(t,m,n,!1);const l=t.getGeometry(m);g.push(l)}return new e(g)}setEditShape(e,t=!1){null===this.m_topoGraph&&(this.m_topoGraph=new Ye),this.m_topoGraph.setEditShape(e,this.m_progressTracker,!0,t)}setEditShapeCrackAndCluster(e,t){$(e,t,this.m_progressTracker,!0,!1);for(let s=e.getFirstGeometry();s!==f;s=e.getNextGeometry(s))e.getGeometryType(s)===i.enumPolygon&&Je(e,s,-1,this.m_bOGCOutput,f,this.m_progressTracker);this.setEditShape(e)}setHalfEdgeOrientations_(e,t){const s=this.m_topoGraph.getShape();for(let i=s.getFirstGeometry();i!==f;i=s.getNextGeometry(i))if(i===t)for(let t=s.getFirstPath(i);t!==f;t=s.getNextPath(t)){let i=s.getFirstVertex(t);if(i===f)continue;let r=s.getNextVertex(i);for(;r!==f;){const t=this.m_topoGraph.getClusterFromVertex(i),n=this.m_topoGraph.getClusterFromVertex(r),h=this.m_topoGraph.getHalfEdgeConnector(t,n);if(h!==f){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 E,n=s.insertPath(e,f);t.push(t[0]);const h=t.length;let o=f;for(let a=0;a<h;a++){const e=t[a];if(o=s.addVertex(n,e),!i)continue;const m=this.m_topoGraph.getClusterFromVertex(e);if(a>0&&this.m_topoGraph.isBreakNode(m)&&s.setSegmentParentageBreakVertex(o,!0),a<h-1){const e=this.m_topoGraph.getHalfEdgeConnector(m,this.m_topoGraph.getClusterFromVertex(t[a+1])),i=this.m_topoGraph.getSegmentParentage(e);s.setSegmentParentageAndBreak(o,i,a>0||this.m_topoGraph.isBreakNode(m)),this.m_topoGraph.isHalfEdgeCurve(e)&&(this.m_topoGraph.querySegmentXY(e,r),s.setSegmentToIndex(s.getVertexIndex(o),r.get().clone()))}}if(i){const e=this.m_topoGraph.getClusterFromVertex(t[h-1]);this.m_topoGraph.isBreakNode(e)&&s.setSegmentParentageBreakVertex(o,!0)}s.setClosedPath(n,!0)}processPolygonCuts_(e,t,s,r){const n=this.m_topoGraph.getGeometryID(s),h=this.m_topoGraph.getGeometryID(r),o=[],a=this.m_topoGraph.getShape(),m=this.m_topoGraph.createUserIndexForHalfEdges();for(let g=this.m_topoGraph.getFirstCluster();g!==f;g=this.m_topoGraph.getNextCluster(g)){const s=this.m_topoGraph.getClusterHalfEdge(g);if(s===f)continue;let r=s;do{if(1!==this.m_topoGraph.getHalfEdgeUserIndex(r,m)){let s=r,g=r,l=!1,d=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(o.push(r),-1!==e){if(this.m_topoGraph.getHalfEdgeParentage(s)&h){d|=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=a.createGeometry(i.enumPolygon);this.flushVertices_(e,o),-1!==t&&a.setGeometryUserIndex(e,t,d)}o.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!==f;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,h){const o=this.m_topoGraph.getShape().getGeometryType(s),a=this.m_topoGraph.getShape().getGeometryType(i),m=r(o),g=r(a);if(2!==m||1!==g)if(1!==m||1!==g)n("");else{new Ht(this,e,t,s,i,h).Do()}else this.cutPolygonPolyline_(t,s,i,h)}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 P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(h(t)){const t=new S({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(e,t,s,i){o(t>0);const r=new c;let n=0,h=-1;for(let o=0,a=t;o<a;o++)2===e[o].getDimension()&&(-1===h&&(h=o),e[o].isEmpty()||(n++,r.addGeometry(e[o])));return 0===n?(o(h>=0),this.normalizeInputGeometry(e[h])):this.planarSimplifyPolygons(r,s,!0,!1,-1,!0)}dissolveMultiPaths_(e,t,s,r,n,g,l){o(e>=1&&e<=2),o(r>0);const d=8&g?1:2,_=u.constructEmpty();let p=0,E=-1,y=!0;for(let h=0,o=r;h<o;h++)if(s[h].getDimension()===e&&(-1===E&&(E=h),!s[h].isEmpty())){E=h,p++;const t=u.constructEmpty();if(s[h].queryLooseEnvelope(t),_.mergeEnv3D(t),2===e&&y&&s[h].getGeometryType()===i.enumPolygon)if(16&g){const e=[0],t=s[h].getImpl().getIsSimple(0,e),i=this.m_bOGCOutput?5===t:G(t);y&&=i}else{const e=C(s[h],0);y&&=e}}if(p<2&&(o(E>=0),0===p||!(16&g)))return this.normalizeInputGeometry(s[E]);if(!y){const e=x(t?null:n,_.getEnvelope2D(),!0);return this.dissolveNonSimplePolygons(s,r,e,g)}const T=s.slice(0,r),F=x(n,_.getEnvelope2D(),!0),b=10*H(F);let w=new A(0,0);if(l&&(w=I(n,_.getEnvelopeZs(),!0)),1===p&&1===e&&2===d&&!t)return l?mt():this.m_bOGCOutput?ht(T[E],F,!1,-1,this.m_progressTracker,d,!1):ot(T[E],F,!1,!1,-1,this.m_progressTracker,d,!1);const U=new V;U.startConstruction();let k=2===e?3:4,D=0;for(let m=0,u=r;m<u;m++){if(T[m].getDimension()!==e||T[m].isEmpty())continue;let s=T[m].getGeometryType();if(s!==i.enumEnvelope){if(h(s)?(T[m]=this.normalizeInputGeometry(T[m]),s=i.enumPolyline):o(a(s)),1===e){o(s===i.enumPolyline);let e=-1;if(l)o(0,"3d not implemented yet");else{const t=[0];e=T[m].getImpl().getIsSimple(F.total(),t)}if(this.m_bOGCOutput?5!==e:!G(e))if(t)k=-1;else{l?o(0,"3d not implemented yet"):this.m_bOGCOutput?T[m]=ht(T[m],F,!1,-1,this.m_progressTracker,d,!1):T[m]=ot(T[m],F,!1,!1,-1,this.m_progressTracker,d,!1);const e=[0];o(G(T[m].getImpl().getIsSimple(F.total(),e)))}}else{o(s===i.enumPolygon);const e=[0],t=T[m].getImpl().getIsSimple(0,e);o(v(t))}const r=T[m].getImpl();for(let e=0,t=r.getPathCount();e<t;e++){const t=N.constructEmpty();r.queryLoosePathEnvelope(e,t),t.inflateCoords(b,b),U.addEnvelope(D,t),D++}}else{o(s===i.enumEnvelope);const e=N.constructEmpty();T[m].queryLooseEnvelope(e),e.inflateCoords(b,b),U.addEnvelope(D,e),D++,k=-1}}U.endConstruction();const B=D,O=pe(B,-2147483647),R=pe(B,-1);let L=0;E=-1,D=0;for(let h=0,m=r;h<m;h++){if(T[h].getDimension()!==e)continue;if(-1===E&&(E=h),T[h].isEmpty())continue;E=h,L++;const t=T[h].getGeometryType();if(a(t)){for(let e=0,t=T[h].getPathCount();e<t;e++)R[D]=h,O[D]=-e-1,D++}else o(t===i.enumEnvelope),R[D]=h,O[D]=-1,D++}if(L<2&&2===e)return o(E>=0),this.normalizeInputGeometry(T[E]);let Y=B;for(;U.next()&&Y>0;){this.progress_();const e=U.getHandleA(),t=U.getHandleB(),s=U.getElement(e),i=U.getElement(t);R[s]!==R[i]&&(O[s]<0&&(Y--,O[s]=-(O[s]+1)),O[i]<0&&(Y--,O[i]=-(O[i]+1)))}const M=new c;let X=!1,q=0;for(let h=0,u=r;h<u;h++){if(T[h].getDimension()!==e||T[h].isEmpty())continue;const t=T[h].getGeometryType(),s=q;let r=0,n=0;const g=a(t)?T[h]:null;for(let e=s,i=O.length;e<i&&R[e]===h;e++)O[e]>=0&&(r++,n+=g?g.getPathSize(O[e]):m(T[h])),q++;if(n>.95*m(T[h])){M.addGeometry(this.normalizeInputGeometry(T[h]));for(let e=s;e<q;e++)O[e]<0&&(O[e]=-(O[e]+1))}else{if(0===r){X=!0;continue}{X=!0,o(a(t)),o(null!=g);const e=new P({vd:T[h].getDescription()}),r=new S({vd:T[h].getDescription()}),n=t===i.enumPolygon?e:r;for(let t=s;t<q;t++)O[t]>=0&&n.addPath(g,O[t],!0);M.addGeometry(n)}}}let z;if(M.getFirstGeometry()!==f){const s=2===e,i=t?x(null,_.getEnvelope2D(),!0):F;let r=new A(0,0);if(l&&(r=t?I(null,_.getEnvelopeZs(),!0):w),2===e&&!(2&g)){M.collapseAllGeometriesToFirst();let e=0,t=null;if(M.hasCurves()&&!M.hasSegmentParentage()){t=new ie;const s=M.getEnvelope2D(this.m_progressTracker);e=Q(i.total());const r=K(i.total(),s);J(M,r,i.total(),12e3,t,null,this.m_progressTracker)}Me(M,M.getFirstGeometry(),i.total(),this.m_progressTracker),null!==t&&t.stitchCurves(M,f,e,!0)}if(l)z=this.planarSimplify3DImpl_(M,i,r,d,!0);else if(2===e)z=this.planarSimplifyPolygons(M,i,s,t,-1,!1);else{const e=rt();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=d,z=this.planarSimplifyPolylines(M,i,t,e,-1)}if(!X){const e=[0];k=z.getImpl().getIsSimple(i.total(),e)}}else o(X),o(E>=0),z=2===e?new P({vd:T[E].getDescription()}):new S({vd:T[E].getDescription()});if(X){let e=0;for(let t=0,s=O.length;t<s;t++){const s=R[t];if(!(s<0)&&O[t]<0){const i=T[s].getGeometryType(),r=a(i)?T[s]:null;if(r){const s=-(O[t]+1);e+=r.getPathSize(s)}else e+=4}}z.reserve(z.getPointCount()+e);for(let t=0,s=O.length;t<s;t++){const e=R[t];if(!(e<0)&&O[t]<0){const s=T[e].getGeometryType(),r=a(s)?T[e]:null;if(r){const e=-(O[t]+1);z.addPath(r,e,!0)}else s===i.enumEnvelope?z.addEnvelope(T[e],!1):(o(h(s)),z.addSegment(T[e],!0))}}}let W=0;if(2===e?-1!==k&&(k=3,W=t?0:F.total()):(o(1===e),t||-1===k||(W=F.total())),l||z.getImpl().setIsSimple(k,W),!t&&X)if(2===e){if(!l)return(new qt).execute(z,n,!1,this.m_progressTracker);o(0,"3d not yet implemented")}else 1===e&&1!==d&&(z=l?gt():at(this.m_bOGCOutput,z,d,this.m_progressTracker),z.getImpl().setIsSimple(k,W));return z}dissolveTopoGraphCommonEdges_(){const e=this.m_topoGraph.createUserIndexForHalfEdges(),t=[];for(let s=this.m_topoGraph.getFirstCluster();s!==f;s=this.m_topoGraph.getNextCluster(s)){const i=this.m_topoGraph.getClusterHalfEdge(s);let r=i;if(i!==f)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(e,t,s,i){let r=Ge(),n=f;for(let o=this.m_topoGraph.getClusterVertexIterator(e);o!==f;o=this.m_topoGraph.incrementVertexIterator(o)){const e=this.m_topoGraph.getVertexFromVertexIterator(o),i=t.getUserIndex(e,s);i>=0&&i<r&&(r=i,n=e)}o(n!==f);let h=t.getUserIndex(n,i);return h>0&&(t.setUserIndex(n,i,--h),0===h&&t.setUserIndex(n,s,-1)),n}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 o=h.hasSegmentParentage(),a=new E;for(let i=h.getFirstPath(e);i!==f;i=h.getNextPath(i)){const e=h.getFirstVertex(i);this.m_topoGraph.getClusterFromVertex(e);const m=this.m_topoGraph.getHalfEdgeFromVertex(e);if(m===f)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 d=h.insertPath(t,f);h.setClosedPath(d,!0);let _=m,p=e,u=this.m_topoGraph.getClusterFromVertex(p),c=1;do{this.progress_();const e=this.chooseVertexFromVertexCluster_(p,n),t=h.addVertex(d,e);if(this.m_topoGraph.isHalfEdgeCurve(_)&&(this.m_topoGraph.querySegmentXY(_,a),h.setSegmentToIndex(h.getVertexIndex(t),a.get().clone())),o){const e=this.m_topoGraph.getSegmentParentage(_);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(_,s,1),_=this.m_topoGraph.getHalfEdgeNext(_);do{i=1===c?h.getNextVertex(p):h.getPrevVertex(p),m=i!==f?this.m_topoGraph.getClusterFromVertex(i):f}while(m===u);const g=this.m_topoGraph.getHalfEdgeOrigin(_);if(g!==m){do{i=1===c?h.getPrevVertex(p):h.getNextVertex(p),m=i!==f?this.m_topoGraph.getClusterFromVertex(i):f}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(_!==m)}}topoOperationPolygonPolygonHelper_(e,t,s,i,r,n){this.progress_(!0),e!==f&&this.collectPolygonPathsPreservingFrom_(e,s,r,n,i),t!==f&&this.collectPolygonPathsPreservingFrom_(t,s,r,n,i);const h=new E,o=this.m_topoGraph.getShape();o.dbgVerifyCurves();const a=o.hasSegmentParentage();for(let m=this.m_topoGraph.getFirstCluster();m!==f;m=this.m_topoGraph.getNextCluster(m)){const e=this.m_topoGraph.getClusterHalfEdge(m);if(e===f)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=o.insertPath(s,f);o.setClosedPath(e,!0);let m=t;do{const t=this.m_topoGraph.getHalfEdgeVertexIterator(m);let s=f;if(t!==f)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=o.getNextVertex(s)}const g=this.chooseVertexFromVertexCluster_(s,i),l=o.addVertex(e,g);if(a){const e=this.m_topoGraph.getSegmentParentage(m),t=this.m_topoGraph.getHalfEdgeOrigin(m);o.setSegmentParentageAndBreak(l,e,this.m_topoGraph.isBreakNode(t))}if(this.m_topoGraph.isHalfEdgeCurve(m)&&(this.m_topoGraph.querySegmentXY(m,h),o.setSegmentToIndex(o.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),o=this.m_topoGraph.createUserIndexForHalfEdges();return this.topoOperationPolygonPolygonHelper_(e,t,h,s,o,-1),this.m_topoGraph.deleteUserIndexForHalfEdges(o),r||Je(n,h,3,this.m_bOGCOutput,f,this.m_progressTracker),h}topoOperationPolyline_(e,t){const s=rt();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(f,e,!1,s).first}topoOperationMultiPoint_(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,f);for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=f;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==f;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===f&&(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}intersection(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),h=r(s),a=r(i),m=this.m_topoGraph.getGeometryID(e),g=this.m_topoGraph.getGeometryID(t);o(m>=0),o(g>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(m|g),this.m_maskLookup[m|g]=!0;let l=f;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(l=e),2===h&&2===a?this.topoOperationPolygonPolygon_(e,t,l):1===h&&a>0||1===a&&h>0?this.topoOperationPolyline_(l,this.m_bOGCOutput):0===h||0===a?this.topoOperationMultiPoint_():void n("")}topoOperationPolygonPolygonEx(e,t,s){const r=this.m_topoGraph.getShape(),n=r.createGeometry(i.enumPolygon),h=r.createGeometry(i.enumPolyline),o=r.createGeometry(i.enumMultiPoint);this.dissolveTopoGraphCommonEdges_();let a=f;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(),d=new E;for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const e=this.m_topoGraph.getClusterHalfEdge(i);if(e===f)continue;let t=e;do{let e=this.m_topoGraph.getHalfEdgeUserIndex(t,m),n=this.m_topoGraph.getHalfEdgeUserIndex(this.m_topoGraph.getHalfEdgeTwin(t),m),o=e|n;if(2===o){let a=this.m_topoGraph.getHalfEdgeParentage(t);if(this.isGoodParentage(a)){const _=r.insertPath(h,f);let p=t;const u=this.chooseVertexFromCluster_(i,s);let c=r.addVertex(_,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,d),r.setSegmentToIndex(r.getVertexIndex(c),d.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(_,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),o=e|n,2!==o)break;if(a=this.m_topoGraph.getHalfEdgeParentage(p),!this.isGoodParentage(a)){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,d),r.setSegmentToIndex(r.getVertexIndex(c),d.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!==f;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)){a===f&&(a=r.insertPath(o,f));const e=this.m_topoGraph.getClusterVertexIterator(i);let t=f;if(e!==f){t=this.m_topoGraph.getVertexFromVertexIterator(e);const i=this.chooseVertexFromVertexCluster_(t,s);r.addVertex(a,i)}}}this.m_topoGraph.deleteUserIndexForClusters(g),this.m_topoGraph.deleteUserIndexForHalfEdges(m),r.dbgVerifyCurves(),Je(r,n,3,this.m_bOGCOutput,f,this.m_progressTracker);const _=[f,f,f];return _[0]=o,_[1]=h,_[2]=n,_}topoOperationPolylinePolylineOrPolygonEx(e,t){const s=rt();return s.allCrossRoadsImpassable=!1,s.ogcRule=t,s.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(f,e,!0,s)}topoOperationMultiPoint(){const e=this.m_topoGraph.getShape(),t=e.createGeometry(i.enumMultiPoint),s=e.insertPath(t,f);for(let i=this.m_topoGraph.getFirstCluster();i!==f;i=this.m_topoGraph.getNextCluster(i)){const t=this.m_topoGraph.getClusterParentage(i);if(this.isGoodParentage(t)){let t=f;for(let s=this.m_topoGraph.getClusterVertexIterator(i);s!==f;s=this.m_topoGraph.incrementVertexIterator(s)){const i=this.m_topoGraph.getVertexFromVertexIterator(s);t===f&&(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(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=st(s),h=st(i),a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);o(a>=0),o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a|m]=!0;let g=f;if(this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(g=e),2===r&&2===h)return this.topoOperationPolygonPolygonEx(e,t,g);if(1===r&&h>0||1===h&&r>0){const{first:e,second:t}=this.topoOperationPolylinePolylineOrPolygonEx(g,this.m_bOGCOutput);return[t,e]}if(0===r||0===h){const e=[];return e.push(this.topoOperationMultiPoint()),e}n("")}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 o=this.m_topoGraph.getClusterVertexIterator(i);o!==f;o=this.m_topoGraph.incrementVertexIterator(o)){const i=this.m_topoGraph.getVertexFromVertexIterator(o),a=e.getPathFromVertex(i),m=e.getGeometryFromPath(a),g=this.m_topoGraph.getGeometryID(m),l=e.getFirstVertex(a),d=!!(g&s);d&&l===i&&(this.m_fromEdgeForPolylines=t);const _=e.getNextVertex(i);if(_!==f&&this.m_topoGraph.getClusterFromVertex(_)===r){if(n++,d){if(this.m_fromEdgeForPolylines===f&&l===_){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!==f&&this.m_topoGraph.getClusterFromVertex(s)===r&&(n--,d)){if(this.m_fromEdgeForPolylines===f&&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)*_e.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 f;const t=this.m_topoGraph.getHalfEdgeTwin(e);if(i===this.m_topoGraph.getHalfEdgeNext(t))return s}let r=i,n=f;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==f)return f;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 f;if(i===this.m_topoGraph.getHalfEdgePrev(t))return s}let r=i,n=f;for(;r!==e;){const e=this.getCombinedHalfEdgeParentage(r);if(this.isGoodParentage(e)){if(n!==f)return f;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}n("is_on_a_loop_")}restorePolylineParts(e,t,s,i,r,n,h,a,m,g){o(r===f&&n>=0&&h>=0||-1===n&&-1===h),o(-1===a&&1!==g.unsplitBehavior||-1!==a&&1===g.unsplitBehavior);const l=g.ogcRule,d=g.allCrossRoadsImpassable,_=1===g.unsplitBehavior,p=0===g.unsplitBehavior,u=this.m_topoGraph.getShape(),c=u.hasSegmentParentage();let x=e,I=this.m_topoGraph.getHalfEdgeTwin(x);const P=new E;this.m_fromEdgeForPolylines=f;let y=this.prevailingDirection(u,x),S=x,C=f,G=!1,H=!1,V=!1;if(!_)for(;;){const t=this.m_topoGraph.getHalfEdgePrev(x);if(t===I){V=!0;break}const i=this.m_topoGraph.getHalfEdgeNext(I);if(this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(i))){G=!0;break}if(this.m_topoGraph.getHalfEdgeTwin(t)!==i){if(d){G=!0;break}if(x=this.tryMoveThroughCrossroadBackwards(x,!0),x===f){G=!0;break}I=this.m_topoGraph.getHalfEdgeTwin(x)}else x=t,I=i;if(1===this.m_topoGraph.getHalfEdgeUserIndex(x,s)){V=!0;break}if(x===e){C=e,H=!0;break}const r=this.getCombinedHalfEdgeParentage(x);if(!this.isGoodParentage(r))break;S=x,y+=this.prevailingDirection(u,x)}if(C===f){for(x=e,I=this.m_topoGraph.getHalfEdgeTwin(x),C=x;;){const e=this.m_topoGraph.getHalfEdgeNext(x),t=this.m_topoGraph.isStrongPathNode(this.m_topoGraph.getHalfEdgeOrigin(e));if(t){G=!0;break}if(e===I){V=!0;break}if(-1!==a){const e=this.m_topoGraph.getHalfEdgeOrigin(I);if(1===this.m_topoGraph.getClusterUserIndex(e,a)){G=!0;break}}const i=this.m_topoGraph.getHalfEdgePrev(I);if(this.m_topoGraph.getHalfEdgeTwin(e)!==i){if(t||d){G=!0;break}if(x=this.tryMoveThroughCrossroadForward(x,!0),x===f){G=!0;break}I=this.m_topoGraph.getHalfEdgeTwin(x)}else x=e,I=i;if(1===this.m_topoGraph.getHalfEdgeUserIndex(x,s)){V=!0;break}const r=this.getCombinedHalfEdgeParentage(x);if(!this.isGoodParentage(r))break;C=x,y+=this.prevailingDirection(u,x)}const t=this.m_topoGraph.getHalfEdgeOrigin(S);H=this.m_topoGraph.getHalfEdgeTo(C)===t}else if(this.m_fromEdgeForPolylines!==f){S=e,C=this.tryMoveThroughCrossroadBackwards(S,!1),o(C!==f);const t=this.m_topoGraph.getHalfEdgeTwin(S);this.m_topoGraph.getHalfEdgeNext(t)}let v=H;H||V||m&&(v=this.isOnALoop(e,s),v||(v=this.isOnALoop(I,s)));const N=y>=0;let T=!1;v&&G&&(H?(T=l,N&&(T||_||p)&&S!==e&&(o(!_),S=e,T=!1)):(_||N&&p)&&(S=e));let F=0;for(x=S;I=this.m_topoGraph.getHalfEdgeTwin(x),this.m_topoGraph.setHalfEdgeUserIndex(x,s,1),this.m_topoGraph.setHalfEdgeUserIndex(I,s,1),F++,x!==C;)x=d?this.m_topoGraph.getHalfEdgeNext(x):this.tryMoveThroughCrossroadForward(x,!1);N||(C=ue(S,S=C),C=this.m_topoGraph.getHalfEdgeTwin(C),S=this.m_topoGraph.getHalfEdgeTwin(S));let b=u.insertPath(t,f);x=S;const w=this.m_topoGraph.getHalfEdgeOrigin(S);let U;U=-1!==n?this.chooseVertexByOrder(w,u,n,h):this.chooseVertexFromCluster_(w,r),this.m_topoGraph.isStrongPathNode(w)&&u.setStrongPathStart(b,!0);let k=u.addVertex(b,U),D=k;-1!==i&&this.m_topoGraph.setClusterUserIndex(w,i,1);let B=0;const A=T?Math.trunc((F+1)/2):-1;let O=f,R=!0,L=f;for(;;){if(c){const e=this.m_topoGraph.getSegmentParentage(x),t=this.m_topoGraph.getHalfEdgeOrigin(x);u.setSegmentParentageAndBreak(D,e,R||this.m_topoGraph.isBreakNode(t))}R=!1,this.m_topoGraph.isHalfEdgeCurve(x)&&(this.m_topoGraph.querySegmentXY(x,P),u.setSegmentToIndex(u.getVertexIndex(D),P.get().clone())),O!==f&&-1!==h&&u.addToUserIndex(O,h,-1);const e=d?this.m_topoGraph.getHalfEdgeNext(x):this.tryMoveThroughCrossroadForward(x,!1),s=this.m_topoGraph.getHalfEdgeTo(x);let o;if(o=-1!==n?this.chooseVertexByOrder(s,u,n,h):this.chooseVertexFromCluster_(s,r),k=u.addVertex(b,o),L=s,-1!==i&&this.m_topoGraph.setClusterUserIndex(s,i,1),c&&this.m_topoGraph.isBreakNode(s)&&u.setSegmentParentageBreakVertex(k,!0),O=o,B++,T&&B===A&&(b=u.insertPath(t,f),k=u.addVertex(b,o),R=!0,-1!==h&&u.addToUserIndex(o,h,-1),O=f),x===C)break;x=e,D=k}L!==f&&this.m_topoGraph.isStrongPathNode(L)&&u.setStrongPathEnd(b,!0)}topoOperationPolylineSimplify_(e,t){return this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,t,s,r){o(t===f||e===f);const n=this.m_topoGraph.getShape(),h=t=>t=e===f?t===f?n.getFirstGeometry():n.getNextGeometry(t):t===f?e:f,a=n.createGeometry(i.enumPolyline);let m=-1;s&&(m=this.m_topoGraph.createUserIndexForClusters());const g=this.m_topoGraph.createUserIndexForHalfEdges(),l=t===f?n.createUserIndex():-1,d=t===f?n.createUserIndex():-1;let _=-1;if(1===r.unsplitBehavior){_=this.m_topoGraph.createUserIndexForClusters();for(let e=h(f);e!==f;e=h(e))for(let t=n.getFirstPath(e);t!==f;t=n.getNextPath(t)){{const e=n.getFirstVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,_,1)}if(!n.isClosedPath(t)){const e=n.getLastVertex(t),s=this.m_topoGraph.getClusterFromVertex(e);this.m_topoGraph.setClusterUserIndex(s,_,1)}}}if(t===f){let e=0;for(let t=h(f);t!==f;t=h(t))for(let s=n.getFirstPath(t);s!==f;s=n.getNextPath(s)){if(n.isClosedPath(s)){let t=n.getFirstVertex(s);for(let i=0,r=n.getPathSize(s);i<r;i++,t=n.getNextVertex(t))n.setUserIndex(t,l,e++),n.setUserIndex(t,d,2)}else{const t=n.getFirstVertex(s);n.setUserIndex(t,l,e++),n.setUserIndex(t,d,1);let i=n.getNextVertex(t);for(let r=1,h=n.getPathSize(s)-1;r<h;++r)n.setUserIndex(i,l,e++),n.setUserIndex(i,d,2),i=n.getNextVertex(i);n.setUserIndex(i,l,e++),n.setUserIndex(i,d,1)}}}for(let i=h(f);i!==f;i=h(i))for(let e=n.getFirstPath(i);e!==f;e=n.getNextPath(e)){let s=n.getFirstVertex(e);for(let i=0,h=n.getPathSize(e);i<h;i++,s=n.getNextVertex(s)){const e=this.m_topoGraph.getHalfEdgeFromVertex(s);if(e===f)continue;if(1===this.m_topoGraph.getHalfEdgeUserIndex(e,g))continue;const n=this.getCombinedHalfEdgeParentage(e);if(this.isGoodParentage(n)){const s=0===i;this.restorePolylineParts(e,a,g,m,t,l,d,_,s,r)}}}let p=f;if(s){p=n.createGeometry(i.enumMultiPoint);let e=f;for(let s=this.m_topoGraph.getFirstCluster();s!==f;s=this.m_topoGraph.getNextCluster(s)){this.progress_();if(1!==this.m_topoGraph.getClusterUserIndex(s,m)){const i=this.m_topoGraph.getClusterParentage(s);if(this.isGoodParentage(i)){e===f&&(e=n.insertPath(p,f));const i=this.m_topoGraph.getClusterVertexIterator(s);if(i!==f){let r;this.m_topoGraph.getVertexFromVertexIterator(i),r=-1!==l?this.chooseVertexByOrder(s,n,l,d):this.chooseVertexFromCluster_(s,t),n.addVertex(e,r)}}}}}return-1!==d&&n.removeUserIndex(d),-1!==l&&n.removeUserIndex(l),-1!==m&&n.removeUserIndex(m),this.m_topoGraph.deleteUserIndexForHalfEdges(g),ce(a,p)}difference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),h=r(s),o=r(i);if(h>o)return e;const a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);if(this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a]=!0,2===h&&2===o){let s=f;return this.m_topoGraph.getShape().getVertexDescription().getAttributeCount()>1&&(s=e),this.topoOperationPolygonPolygon_(e,t,s)}if(1===h&&2===o){const t=rt();return t.allCrossRoadsImpassable=!1,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}if(1===h&&1===o){const t=rt();return t.allCrossRoadsImpassable=!0,t.ogcRule=this.m_bOGCOutput,t.unsplitBehavior=0,this.topoOperationPolylineSimplifyOrPolylineTopoHelper_(e,f,!1,t).first}if(0===h)return this.topoOperationMultiPoint_();n("")}symmetricDifference(e,t){const s=this.m_topoGraph.getShape().getGeometryType(e),i=this.m_topoGraph.getShape().getGeometryType(t),r=st(s),h=st(i),a=this.m_topoGraph.getGeometryID(e),m=this.m_topoGraph.getGeometryID(t);return o(a>=0),o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=1+(a|m),this.m_maskLookup[a]=!0,this.m_maskLookup[a]=!0,this.m_maskLookup[m]=!0,2===r&&2===h?this.topoOperationPolygonPolygon_(e,t,f):1===r&&1===h?this.topoOperationPolyline_(f,this.m_bOGCOutput):0===r&&0===h?this.topoOperationMultiPoint():void n("")}planarSimplifyNoCrackingAndCluster(e,t,s,r){this.m_bOGCOutput=e,this.m_topoGraph=new Ye;const h=t.getFillRule(s),a=t.getGeometryType(s);if(1!==h||a===i.enumMultiPoint?this.m_topoGraph.setAndSimplifyEditShapeAlternate(t,s,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeWinding(t,s,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return!1;this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const m=this.m_topoGraph.getGeometryID(s);if(o(m>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=m+1,this.m_maskLookup[m]=!0,t.getGeometryType(s)===i.enumPolygon||1===h&&t.getGeometryType(s)!==i.enumMultiPoint){t.setFillRule(s,0);const i=this.topoOperationPolygonPolygon_(s,f,f);if(t.swapGeometry(i,s),t.removeGeometry(i),1===h&&this.m_bOGCOutput)return this.planarSimplifyNoCrackingAndCluster(e,t,s,r)}else if(t.getGeometryType(s)===i.enumPolyline){const e=rt();e.ogcRule=this.m_bOGCOutput,e.allCrossRoadsImpassable=!0,e.unsplitBehavior=r;const i=this.topoOperationPolylineSimplify_(t.getFirstGeometry(),e);t.swapGeometry(i,s),t.removeGeometry(i)}else if(t.getGeometryType(s)===i.enumMultiPoint){const e=this.topoOperationMultiPoint_();t.swapGeometry(e,s),t.removeGeometry(e)}else n("");return!0}unsplitPolylineExact(e){return o(0),new S}planarSimplifyPolylines(e,t,s,r,n){for(let p=e.getFirstGeometry();p!==f;p=e.getNextGeometry(p)){const t=e.getGeometryType(p);o(t===i.enumPolyline)}let h=0,a=0,m=null;if(e.hasCurves()&&!e.hasSegmentParentage()){m=new ie;const s=e.getEnvelope2D(this.m_progressTracker);a=Q(t.total());const i=K(t.total(),s);h=re(i,a),J(e,i,t.total(),12e3,m,null,this.m_progressTracker)}{const s=ee(t.add(h));e.filterClosePoints(s,!1,!1,!1,f)}if(this.m_topoGraph=new Ye,4!==n&&5!==n)if(null===m&&s){const i=new te(this.m_progressTracker,!1);i.sweepVertical(e,t.total()),i.hadComplications()?($(e,t,this.m_progressTracker,!0,!1),s=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(t.total())}else $(e,t.add(h),this.m_progressTracker,!0,!1),s=!1;else s=!1;e.removeSelection(),e.collapseAllGeometriesToFirst();const g=e.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,g,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(s&&null===m),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolylines(e,t,!1,r,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const l=this.m_topoGraph.getGeometryID(g);o(l>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=l+1,this.m_maskLookup[l]=!0;const d=this.topoOperationPolylineSimplify_(e.getFirstGeometry(),r);null!==m&&m.stitchCurves(e,d,a,!0);const _=e.getGeometry(d);return s||_.getImpl().setIsSimple(4,t.total()),_}planarSimplifyMultiPoints(e,t,s,r){for(let g=e.getFirstGeometry();g!==f;g=e.getNextGeometry(g)){const t=e.getGeometryType(g);o(t===i.enumMultiPoint)}this.m_topoGraph=new Ye,4!==r&&5!==r?($(e,t,this.m_progressTracker,!0,!1),s=!1):s=!1,e.removeSelection(),e.collapseAllGeometriesToFirst();const n=e.getFirstGeometry();if(this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,n,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(s),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyMultiPoints(e,t,!1,-1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const h=this.m_topoGraph.getGeometryID(n);o(h>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=h+1,this.m_maskLookup[h]=!0;const a=this.topoOperationMultiPoint(),m=e.getGeometry(a);return s||m.getImpl().setIsSimple(4,t.total()),m}planarSimplifyPolygons(e,t,s,r,n,h){for(let x=e.getFirstGeometry();x!==f;x=e.getNextGeometry(x)){const t=e.getGeometryType(x);o(t===i.enumPolygon||t===i.enumPolyline&&s)}let a=0,m=0,g=null;if(e.hasCurves()&&!e.hasSegmentParentage()){g=new ie;const s=e.getEnvelope2D(this.m_progressTracker);m=Q(t.total());const i=K(t.total(),s);a=re(i,m),J(e,i,t.total(),12e3,g,null,this.m_progressTracker)}if(h){$(e,t.add(a),this.m_progressTracker,!0,!1);for(let t=e.getFirstGeometry();t!==f;t=e.getNextGeometry(t))e.getGeometryType(t)===i.enumPolygon&&Je(e,t,-1,!1,f,this.m_progressTracker)}if(this.m_topoGraph=new Ye,h||4===n||5===n)r=!1;else if(null===g&&r){const s=new te(this.m_progressTracker,!1);s.sweepVertical(e,t.total()),s.hadComplications()?($(e,t,this.m_progressTracker,!0,!1),r=!1):this.m_topoGraph.setCheckDirtyPlanesweepTolerance(t.total())}else $(e,t.add(a),this.m_progressTracker,!0,!1),r=!1;e.removeSelection(),e.collapseAllGeometriesToFirst();const l=e.getFirstGeometry();if(s?this.m_topoGraph.setAndSimplifyEditShapeWinding(e,l,this.m_progressTracker):this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,l,this.m_progressTracker),this.m_topoGraph.dirtyCheckFailed())return o(r&&null===g),this.m_topoGraph.removeShape(),this.m_topoGraph=null,this.planarSimplifyPolygons(e,t,s,!1,-1,!1);this.m_topoGraph.setCheckDirtyPlanesweepTolerance(Number.NaN);const d=this.m_topoGraph.getGeometryID(l);o(d>=0),this.m_maskLookup.length=0,this.m_maskLookup.length=d+1,this.m_maskLookup[d]=!0,e.setFillRule(l,0);const _=this.m_bOGCOutput&&s,p=_;let u=this.topoOperationPolygonPolygon_(l,f,f,p);if(_){this.m_topoGraph.removeShape(),this.m_topoGraph=null,e.removeGeometry(l),this.m_topoGraph=new Ye,this.m_topoGraph.setAndSimplifyEditShapeAlternate(e,u,this.m_progressTracker);u=this.topoOperationPolygonPolygon_(u,f,f,!1)}null!==g&&g.stitchCurves(e,u,m,!0);const c=e.getGeometry(u);return c.setFillRule(0),r?c.getImpl().setIsSimple(3,0):(c.getImpl().setIsSimple(4,t.total()),c.getImpl().updateOGCFlagsProtected()),c}planarSimplify3DImpl_(e,t,s,i,r){return o(0),{}}planarSimplifyImpl_(e,t,s,r,h,o,a,m){if(e.isEmpty())return e.clone();const g=e.getGeometryType(),l=new c,d=l.addGeometry(e);if(v(h)&&g===i.enumPolygon&&(s=!1,l.setFillRule(d,0)),m&&(e.hasAttribute(1)&&l.replaceNaNs(1,0),l.removeNaNVertices()),g===i.enumPolygon||g===i.enumPolyline&&s)return this.planarSimplifyPolygons(l,t,s,r,h,!1);if(g===S.type){const e=rt();return e.allCrossRoadsImpassable=!0,e.ogcRule=this.m_bOGCOutput,e.unsplitBehavior=a,this.planarSimplifyPolylines(l,t,r,e,h)}if(g===i.enumMultiPoint)return this.planarSimplifyMultiPoints(l,t,r,h);n("what else?")}}function Pt(e,t,s,i){if(e.isEmpty())return e.createInstance();if(t.isEmpty())return i?e.createInstance():new k({copy:e});const r=[new _e],h=[0],o=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&n(""),r[0]=e.getXY(),o?le(t,r,1,s.total(),h):de(t,r,1,s.total(),h);let a=0===h[0];return i||(a=!a),a?e.createInstance():e}function yt(e,t,s,i){const r=e.createInstance(),h=He(_e,100),o=new Array(100),a=e.getPointCount();let m=!0;const g=2===t.getDimension();1!==t.getDimension()&&2!==t.getDimension()&&n("");for(let n=0;n<a;){const i=e.queryCoordinates(h,h.length,n,-1)-n;g?le(t,h,i,s.total(),o):de(t,h,i,s.total(),o);let a=0;for(let t=0;t<i;t++){0===o[t]&&(m&&(m=!1,r.addPoints(e,0,n)),a!==t&&r.addPoints(e,n+a,n+t),a=t+1)}m||a===i||r.addPoints(e,n+a,n+i),n+=i}return m?e:r}function St(e,t,s,r){const n=e.getGeometryType();if(n===i.enumEnvelope){const t=new P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(n===i.enumPoint&&("|"===r||"^"===r)){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(n===i.enumLine){const t=new S({vd:e.getDescription()});return e.isEmpty()||t.addSegment(e,!0),t}if(n===i.enumMultiPoint&&"-"===r&&t.getGeometryType()===i.enumPoint){const t=new k({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}if(n===i.enumMultiPoint&&"&"===r&&t.getGeometryType()===i.enumPoint){const t=new k({vd:e.getDescription()});return e.isEmpty()||e.getPointByVal(0,t),t}return e}function Ct(e){const t=e.getGeometryType();if(t===i.enumEnvelope){const t=new P({vd:e.getDescription()});return e.isEmpty()||t.addEnvelope(e,!1),t}if(t===i.enumPoint){const t=new y({vd:e.getDescription()});return e.isEmpty()||t.add(e),t}if(tt(t)){const t=new S({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 Gt(e,t,s,i){const r=s===f?e.getClusterHalfEdge(t):s;let n=r;o(e.getHalfEdgeOrigin(r)===t);do{i(n),n=e.getHalfEdgeNext(e.getHalfEdgeTwin(n))}while(n!==r)}class Ht{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!==f;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===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),o=n===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),a=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,d=32;if(Gt(this.m_rTopoGraph,t,m,(e=>{e===a&&(g=2),e===h&&(l=g),e===o&&(d=g)})),this.m_bConsiderTouch)32!==l&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex)|l),32!==d&&this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex)|d);else{if(32===l||32===d)return 1;if(l===d&&!(h===a||h===m||o===a||o===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)|d)}return 0}classifyTouchCut(e,t,s,i){const r=this.m_rShape.getPrevVertex(e),n=this.m_rShape.getNextVertex(e),h=r===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(r)),o=n===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(n)),a=s===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(s)),m=i===f?f:this.m_rTopoGraph.getHalfEdgeConnector(t,this.m_rTopoGraph.getClusterFromVertex(i));if(!this.m_bConsiderTouch){let t;return(t=a===h||m===h)?this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))):(t=a===o||m===o)&&this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),t?0:1}if(h===f)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===f)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;if(h===o)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!==f){if(h===m)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===m)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=1;Gt(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===o){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===a)return this.m_rShape.setUserIndex(e,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(e,this.m_cutteeBreadcrumbsIndex))),0;if(o===a)return this.m_rShape.setUserIndex(r,this.m_cutteeBreadcrumbsIndex,this.setTbd(this.m_rShape.getUserIndex(r,this.m_cutteeBreadcrumbsIndex))),0;let s=2;Gt(this.m_rTopoGraph,t,a,(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===o){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!==f;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===f||h===f?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!==f;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!==f;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 o=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&&(o=s),32!==o&&this.m_rShape.setUserIndex(i,this.m_cutteeBreadcrumbsIndex,o|s)}}let t=f,s=f,r=32;const n=this.m_rShape.hasSegmentParentage(),h=new E;for(let o=this.m_rShape.getFirstPath(this.m_cuttee);o!==f;o=this.m_rShape.getNextPath(o)){const e=this.m_rShape.isClosedPath(o),a=this.m_rShape.getPathSize(o)+(e?1:0);let m=1,g=this.m_rShape.getFirstVertex(o),l=f,d=!0;for(let o=this.m_rShape.getNextVertex(g);m<a;++m,o=this.m_rShape.getNextVertex(o)){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!==f&&(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,f),r=e,d=!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,f),d=!0),l=this.m_rShape.addVertex(s,g);const a=this.m_rTopoGraph.getClusterFromVertex(g);!d&&n&&this.m_rTopoGraph.isBreakNode(a)&&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,d||this.m_rTopoGraph.isBreakNode(a))}this.m_rTopoGraph.isHalfEdgeCurve(m)&&(this.m_rTopoGraph.querySegmentXY(m,h),this.m_rShape.setSegmentToIndex(this.m_rShape.getVertexIndex(l),h.get().clone())),g=o,d=!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=f,s=f,r=32}}}function Vt(e,t,s){return new Et(s).linesToPolygonsImpl(e,t)}function vt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=new N;return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Tt(n,t,s,r,o)}const g=[0],l=e.getImpl().getIsSimple(m,g);let d=s?-1:l;if(G(d)||0===d)return d;const _=new Xt(e,t,d,o,!1);a===i.enumMultiPoint||a===i.enumPolyline||a===i.enumPolygon?d=_.isSimplePlanarImpl():n("");return e.getImpl().setIsSimple(d,m),r&&r.assign(_.m_nonSimpleResult),d}function Nt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=new N;return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Nt(n,t,s,r,o)}l(a),d(a)||p("OGC simplify is not implemented for this geometry type");const g=[0],_=e.getImpl().getIsSimple(m,g);let u=s?-1:_;if(5===u||0===u)return u;const c=new Xt(e,t,u,o,!0);a===i.enumMultiPoint||a===i.enumPolyline||a===i.enumPolygon?(u=c.isSimplePlanarImpl(),G(u)&&(u=5)):n("");return e.getImpl().setIsSimple(u,m),r&&r.assign(c.m_nonSimpleResult),u}function Tt(e,t,s,r,o){if(r&&(r.m_reason=0,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),e.isEmpty())return 5;const a=e.getGeometryType();if(a===i.enumPoint)return wt(e,r);const m=O(t,e,!1).total();if(a===i.enumEnvelope){const t=e,s=N.constructEmpty();return t.queryEnvelope(s),s.isDegenerate(m)?(r&&(r.m_reason=4,r.m_vertexIndex1=-1,r.m_vertexIndex2=-1),0):5}if(h(a)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Tt(n,t,s,r,o)}const g=[0],l=e.getImpl().getIsSimple(m,g);let d=s?-1:l;if(-1!==d)return d;const _=new Xt(e,t,d,o,!1);return a===i.enumMultiPoint?d=_.multipointIsSimpleAsFeature():a===i.enumPolyline?d=_.polylineIsSimpleAsFeature():a===i.enumPolygon?d=_.polygonIsSimpleAsFeature():n(""),e.getImpl().setIsSimple(d,m),r&&r.assign(_.m_nonSimpleResult),d}function Ft(e,t,s,r){if(e.isEmpty())return e;const o=e.getGeometryType();if(o===i.enumPoint){const t=new ne;if(wt(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(o===i.enumEnvelope){const s=O(t,e,!0).total(),i=e,r=N.constructEmpty();return i.queryEnvelope(r),r.isDegenerate(s)?i.createInstance():e}if(h(o)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),Ft(n,t,s,r)}l(o);const a=O(t,e,!1).total(),m=[0],g=e.getImpl().getIsSimple(a,m),d=s?-1:g;if(G(d)){if(o===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}if((o===i.enumMultiPoint||o===i.enumPolyline)&&d>=1)return e;const _=new Xt(e,t,d,r,!1);let p;return o===i.enumMultiPoint?p=_.multipointSimplifyAsFeature():o===i.enumPolyline?p=_.polylineSimplifyAsFeature():o===i.enumPolygon?p=_.polygonSimplifyAsFeature():n(""),p}function bt(e,t,s,r){if(e.isEmpty())return e;const n=e.getGeometryType();if(n===i.enumPoint){const t=new ne;if(wt(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(n===i.enumEnvelope){const s=e,i=new N;s.queryEnvelope(i);const r=O(t,e,!0).total();return i.isDegenerate(r)?s.createInstance():e}if(h(n)){const i=e,n=new S({vd:i.getDescription()});return n.addSegment(i,!0),bt(n,t,s,r)}l(n),d(n)||p("OGC simplify is not implemented for this geometry type");const o=O(t,e,!1).total(),a=[0],m=e.getImpl().getIsSimple(o,a),g=s?-1:m;if(5===g){if(n===i.enumPolygon&&0!==e.getFillRule()){const t=e.clone();return t.setFillRule(0),t}return e}return ht(e,O(t,e,!0),!1,g,r,0,!0)}function wt(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 Ut{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}}function kt(){return{x:-1,y:-1,ipath:-1,ivertex:-1,ipolygon:-1}}function Dt(e,t,s,i,r){return{x:e,y:t,ipath:s,ivertex:i,ipolygon:r}}function Bt(e,t){return e.x===t.x&&e.y===t.y&&e.ipath===t.ipath&&e.ivertex===t.ivertex&&e.ipolygon===t.ipolygon}function At(e,t){e.x=t.x,e.y=t.y,e.ipath=t.ipath,e.ivertex=t.ivertex,e.ipolygon=t.ipolygon}function Ot(){return{x:-1,y:-1,ipath:-1,ivertex:-1,bBoundary:!1,bEndPoint:!1}}function Rt(e,t,s,i,r,n){return{x:e,y:t,ipath:s,ivertex:i,bBoundary:r,bEndPoint:n}}function Lt(e,t){e.x=t.x,e.y=t.y,e.ipath=t.ipath,e.ivertex=t.ivertex,e.bBoundary=t.bBoundary,e.bEndPoint=t.bEndPoint}class Yt extends Z{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 Mt extends Z{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(),o=n.getReversed();let a=r.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(this.m_helper.m_yScanline,0);if(a===m){const e=h?r.m_segment.getStartY():r.m_segment.getEndY(),t=o?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),a=r.m_segment.intersectionOfYMonotonicWithAxisX(i,0),m=n.m_segment.intersectionOfYMonotonicWithAxisX(i,0)}return a<m?-1:a>m?1:0}}class Xt{constructor(e,t,s,i,r){this.m_multiVertexGeom=null,this.m_edges=[],this.m_freeEdges=[],this.m_lineEdgesRecycle=[],this.m_newEdges=[],this.m_recycledSegIter=null,this.m_crossOverHelperList=new R,this.m_progressTracker=null,this.m_progressCounter=0,this.m_AET=new D,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 ne,this.m_progressCounter=0,this.m_progressTracker=i,this.m_geometry=e,this.m_knownSimpleResult=s,this.m_sr=t;const n=O(t,e,!1);this.m_toleranceIsSimple=n,this.m_toleranceIsSimpleClustering=H(n),this.m_toleranceIsSimpleCracking=L(n),this.m_toleranceSimplify=O(t,e,!0),this.m_description=this.m_geometry.getDescription(),this.m_attributeCount=this.m_description.getAttributeCount(),this.m_bOGCRestrictions=r,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 a(e)&&!this.checkDegenerateSegments(!1)?0:this._CheckClustering()?a(e)?this._CheckCracking()?this.m_geometry.getGeometryType()===i.enumPolyline?this.checkSelfIntersectionsPolylinePlanar()?4:0:this._CheckSelfIntersections()?this._CheckValidRingOrientation():0:0:5:0}isSimplePlanarImpl3D(){return o(0),7}generateSortedPairs(e){let t=null;a(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 w(0),s&&(this.m_pathsForOGCTests.length=0);let r=0;for(let o=0;o<i;o++)if(this.m_pairs.push(2*o),this.m_pairs.push(2*o+1),this.m_pairIndices.add(2*o),this.m_pairIndices.add(2*o+1),s){for(;o>=t.getPathEnd(r);)r++;this.m_pathsForOGCTests.push(r)}const n=new Y,h={parent:this,workPt:new _e,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(!!he(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(a(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 ne(1,s,0),!1}}if(d(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 ne(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 ne(3,s,0):this.m_nonSimpleResult=new ne(2,s,0),!1}}}return!0}checkDegenerateSegments(e){const t=this.m_geometry.getImpl(),s=t.querySegmentIterator(),i=t.hasAttribute(1),r=i?M(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 o=t.calculateLowerLength2D();if(!(o>h)&&!(n&&t.isCurve()&&(o=t.calculateLength2D(),o>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 ne(4,s.getStartPointIndex(),-1),!1}}return!0}checkDegenerateSegments3D(){return o(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 Yt(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!==D.st_nullNode()&&s!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),this.m_AET.getElement(s)))return this.m_nonSimpleResult=new ne(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!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(t),i))return this.m_nonSimpleResult=new ne(5,i,this.m_AET.getElement(t)),!1;const s=this.m_AET.getNext(e);if(s!==D.st_nullNode()&&!this._TestToleranceDistancePlanar(this.m_AET.getElement(s),i))return this.m_nonSimpleResult=new ne(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 c,this.m_editShape.addGeometry(this.m_geometry),this.m_editShape.hasCurves()){this.m_curveStitcher=new ie;const e=N.constructEmpty();this.m_geometry.queryEnvelope(e);const t=K(this.m_toleranceSimplify.total(),e),s=new ne;if(oe(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 ne;return ae(!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=X(!0,e,i,this.m_toleranceIsSimpleCracking,!0);if(r){const e=2===r?7:6;return this.m_nonSimpleResult=new ne(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,o=this.m_xy.read(2*h),a=this.m_xy.read(2*h+1);if(t.length&&(o!==i||a!==r)){if(!this.processBunchForSelfIntersectionTest(t))return!1;t.length=0}t.push(h),i=o,r=a}return!!this.processBunchForSelfIntersectionTest(t)}checkSelfIntersectionsPolylinePlanar(){const e=this.m_geometry.getImpl(),t=[];for(let h=0,o=e.getPathCount();h<o;h++)t.push(e.isClosedPathInXYPlane(h));const s=Ot();let i,r,n;{const h=this.m_pairIndices.read(0),o=this.m_pairs[h]>>1,a=this.m_xy.readPoint2D(2*o),m=this.m_pathsForOGCTests[o];i=t[m],r=e.getPathStart(m),n=e.getPathEnd(m)-1,s.bEndPoint=o===r||o===n,this.m_bOGCRestrictions?s.bBoundary=!i&&s.bEndPoint:s.bBoundary=s.bEndPoint,s.ipath=m,s.x=a.x,s.y=a.y,s.ivertex=o}for(let h=1,o=this.m_pairIndices.size();h<o;h++){const o=this.m_pairIndices.read(h),a=this.m_pairs[o];if(1&a)continue;const m=a>>1,g=this.m_xy.readPoint2D(2*m),l=this.m_pathsForOGCTests[m];let d;l!==s.ipath&&(i=t[l],r=e.getPathStart(l),n=e.getPathEnd(l)-1);const _=m===r||m===n;d=this.m_bOGCRestrictions?!i&&_:_;const p=Rt(g.x,g.y,l,m,d,_);if(p.x===s.x&&p.y===s.y)if(this.m_bOGCRestrictions){if(!(p.bBoundary&&s.bBoundary||p.ipath===s.ipath&&p.bEndPoint&&s.bEndPoint))return this.m_nonSimpleResult=new ne(10,p.ivertex,s.ivertex),!1}else if(!p.bEndPoint||!s.bEndPoint)return this.m_nonSimpleResult=new ne(7,p.ivertex,s.ivertex),!1;Lt(s,p)}return!0}checkSelfIntersectionsPolylinePlanar3D(e){return o(0),!1}checkSelfIntersectionsPolygonsOGC(){const e=this.m_geometry.getImpl(),t=[];let s=-1,i=!1;for(let g=0,l=e.getPathCount();g<l;g++)e.isExteriorRingOGC(g)&&(i=!1,s++,g<l-1&&(e.isExteriorRingOGC(g+1)||(i=!0))),t.push(i?s:-1);const r=kt();{const e=this.m_pairIndices.read(0),s=this.m_pairs[e]>>1,i=this.m_xy.readPoint2D(2*s),n=this.m_pathsForOGCTests[s];r.ipath=n,r.x=i.x,r.y=i.y,r.ivertex=s,r.ipolygon=t[n]}const n=[];for(let g=1,l=this.m_pairIndices.size();g<l;g++){const e=this.m_pairIndices.read(g),s=this.m_pairs[e];if(1&s)continue;const i=s>>1,h=this.m_xy.readPoint2D(2*i),o=this.m_pathsForOGCTests[i],a=Dt(h.x,h.y,o,i,t[o]);if(a.x===r.x&&a.y===r.y){if(a.ipath===r.ipath)return this.m_nonSimpleResult=new ne(11,a.ivertex,r.ivertex),!1;t[a.ipath]>=0&&t[a.ipath]===t[r.ipath]&&(0!==n.length&&Bt(n.at(-1),r)||n.push({...r}),n.push(a))}At(r,a)}if(0===n.length)return!0;const h=new R(!0);t.fill(-1);let o=-1;const a=new _e;for(let g=0,l=n.length;g<l;g++){const e=n[g];e.x===a.x&&e.y===a.y||(o=h.createList(0),a.x=e.x,a.y=e.y);let s=t[e.ipath];-1===s&&(s=h.createList(2),t[e.ipath]=s),h.addElement(s,o),h.addElement(o,s)}const m=[];for(let g=h.getFirstList();-1!==g;g=h.getNextList(g)){const e=h.getListData(g);if(1&e||!(2&e))continue;let s=-1;for(m.push(g),m.push(-1);m.length;){const e=m.at(-1);m.pop();const t=m.at(-1);m.pop();const i=h.getListData(t);if(1&i){s=2&i?t:e;break}h.setListData(t,1|i);for(let s=h.getFirst(t);-1!==s;s=h.getNext(s)){const i=h.getData(s);i!==e&&(m.push(i),m.push(t))}}if(-1!==s){const e=t.indexOf(s);return this.m_nonSimpleResult=new ne(12,e,-1),!1}}return!0}_CheckValidRingOrientation(){const e=null!==this.m_multiPathStitcher?this.m_multiPathStitcher.getImpl():this.m_geometry.getImpl();if(e.calculateArea2D()<=0)return this.m_nonSimpleResult=new ne(8,1===e.getPathCount()?1:-1,-1),0;if(1===e.getPathCount())return this.m_bOGCRestrictions&&!this.checkSelfIntersectionsPolygonsOGC()?0:4;this.m_pathOrientations=new q(e.getPathCount(),0),this.m_pathParentage=new w(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 ne(8,n,-1),0;if((t<0||s<Math.abs(i))&&(this.m_nonSimpleResult=new ne(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 w(i,D.st_nullNode()),this.m_xyToNode2=new w(i,D.st_nullNode()),this.m_freeEdges.length=0,this.m_AET.clear(),this.m_AET.setComparator(new Mt(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,o=e.length;h<o;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,o=this.m_edges.length;h<o;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),o=this.m_crossOverHelperList.getData(n);if(i=this.m_edges[h].m_vertexIndex,r=this.m_edges[o].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 ne(7,i,r),!1;for(let h=0,o=e.length;h<o;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!==D.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,D.st_nullNode())}if(i=this.m_xyToNode2.read(s),i!==D.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,D.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)===D.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)===D.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,o=0;for(;s!==D.st_nullNode()&&(e=this.m_AET.getElement(s),n=this.m_edges[e],h=n.m_pathIndex,o=this.m_pathOrientations.read(h),!(3&o));)i=s,s=this.m_AET.getPrev(s);s===D.st_nullNode()?(r=1,s=i):(t=1==(3&o)?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 o=this.m_pathOrientations.read(h);if(!(3&o)){if(r!==n.getRightSide())return this.m_nonSimpleResult=new ne(8,h,-1),!1;const e=r&&!n.getReversed()?1:2;if(o=-4&o|e,this.m_pathOrientations.write(h,o),2===e&&0===this.m_nonSimpleResult.m_reason){const e=this.m_pathParentage.read(h);if(e!==t&&(this.m_nonSimpleResult=new ne(9,h,e),this.m_bOGCRestrictions))return!1}if(this.m_unknownOrientationPathCount--,!this.m_unknownOrientationPathCount)return!0}t=1==(3&o)?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 Ut,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 Ut,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(e,t,s,i,r){if(s){const s=e.getXYZ(),n=t.getXYZ();return z(s,n,i,r)}{const s=e.getXY(),r=t.getXY();return _e.sqrDistance(s,r)<=i*i}}removeDegenerateSegmentsFromCurvedPath(e,t,s,i){const r=e.hasAttribute(1),n=e.querySegmentIterator();n.resetToPath(t),o(n.nextPath());const h=this.m_toleranceSimplify.total();let a=!1,m=!0;const g=new k,l=new k,d=new _e;for(;n.hasNextSegment();){this.progress_();const e=n.nextSegment();if(Xt.isShortSegment(e,r,h,s))if(a){if(e.queryEnd(l),Xt.isShortSegmentPoints(g,l,r,h,s))continue;m&&(i.startPathPoint(g),m=!1),e.queryEnd(g),i.lineToPoint(g),a=!1}else d.assign(e.getStartXY()),e.queryStart(g),a=!0;else if(a)if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(d,e.getEndXY(),!1),t.setStart(g),Xt.isShortSegment(t,r,h,s))continue;i.addSegment(t,m),m=!1,a=!1}else{if(e.queryEnd(l),Xt.isShortSegmentPoints(g,l,r,h,s))continue;m&&(i.startPathPoint(g),m=!1),i.lineToPoint(l),a=!1}else i.addSegment(e,m),m=!1}if(m)return;if(!a)return;e.isClosedPath(t)?e.getPointByVal(e.getPathStart(t),g):e.getPointByVal(e.getPathEnd(t)-1,g);const _=i.querySegmentIterator();_.resetToLastPath(),_.resetToLastSegment();const p=i.getDescription().getAttributeCount()>1;for(o(_.previousPath());_.hasPreviousSegment();){const e=_.previousSegment();if(e.isCurve()){const t=e.clone();if(t.setCoordsForIntersector(e.getStartXY(),g.getXY(),!1),!Xt.isShortSegment(t,r,h,s)){p&&t.setEnd(g);const e=_.getEndPointIndex();for(let t=i.getPointCount()-1;t>=e;t--)i.removePoint(t);return void i.addSegment(t,!1)}}else if(e.queryStart(l),!Xt.isShortSegmentPoints(l,g,r,h,s)){const e=_.getEndPointIndex();for(let t=i.getPointCount()-1;t>=e;t--)i.removePoint(t);return void i.lineToPoint(g)}}i.removePath(i.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 ne(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=Xt.hasNanZs(e);let s,i=this.m_geometry;t&&(s=this.m_geometry.clone(),e=s.getImpl(),s.replaceNaNs(1,W.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 o=-1;for(let l=0;l<r;l++){const t=n[l];e.getXY(t).isFinite()&&((o<0||0!==this.compareVerticesMultiPoint(o,t))&&(h[t]=!0),o=t)}const a=this.m_geometry.createInstance();let m=0,g=0;for(let l=0;l<r;l++)h[l]?g=l+1:(m<g&&a.addPoints(i,m,g),m=l+1);return m<g&&a.addPoints(i,m,g),a.getImpl().setIsSimple(1,this.m_toleranceSimplify.total()),a}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?M(this.m_sr,e,!0).total():0,o=[],a=[];let m=null;n&&(m=e.getAttributeStreamRef(1));const g=new k,l=e.hasNonLinearSegments(),d=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 _=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,o.push(s))}if(c){const t=s.getEndPointIndex();e.getXY(t).isNAN()||(a.push(t),c=!1)}if(!u){const s=o.at(-1),r=t.getEndPointIndex();if(r-s>1){const t=new _e;t.setSub(e.getXY(s),e.getXY(r)),_=t.length()}else _=i.calculateLength2D();if(_>d)o.push(r),_=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&&(o.push(r),_=0)}}if(!c){const t=a.at(-1),i=s.getStartPointIndex();if(i-t>1){const s=new _e;s.setSub(e.getXY(t),e.getXY(i)),p=s.length()}else p=r.calculateLength2D();if(p>d)a.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&&(a.push(i),p=0)}}}if(o.length>0&&a.length>0&&(o.at(-1)<a.at(-1)?o.length>a.length?o.pop():a.pop():(o.at(-1)===a.at(-1)||a.pop(),a.pop())),a.length+o.length>=2){let e=!1;for(let t=0,s=o.length;t<s;t++)r.getPointByVal(o[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);for(let t=a.length-1;t>0;t--)r.getPointByVal(a[t],g),e?i.lineToPoint(g):(i.startPathPoint(g),e=!0);r.isClosedPath(t.getPathIndex())?i.closePathWithLine():a.length>0&&(r.getPointByVal(a[0],g),i.lineToPoint(g))}o.length=0,a.length=0}return n&&i.replaceNaNs(1,0),i.getImpl().setIsSimple(1,d),i}polygonSimplifyAsFeature(){return this.simplifyPlanar()}simplifyPlanar(){if(1===this.m_geometry.getFillRule()&&!v(this.m_knownSimpleResult))return ot(this.m_geometry,this.m_toleranceSimplify,!0,!1,this.m_knownSimpleResult,this.m_progressTracker,0,!0);const e=new c;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 ie;const i=N.constructEmpty();this.m_geometry.queryEnvelope(i);const n=K(this.m_toleranceSimplify.total(),i);s=Q(this.m_toleranceSimplify.total()),r=re(n,s),J(e,n,this.m_toleranceSimplify.total(),12e3,t,null,this.m_progressTracker)}if(!v(this.m_knownSimpleResult)){const t=this.m_toleranceSimplify.add(r);$(e,t,this.m_progressTracker,!0,!1)}this.m_geometry.getGeometryType()===i.enumPolygon&&Je(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,o=this.m_xy.readPoint2D(2*n);o.y+=1&i?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const a=this.m_xy.readPoint2D(2*h);a.y+=1&r?this.m_toleranceIsSimpleClustering:-this.m_toleranceIsSimpleClustering;const m=o.compare(a);if(0===m&&s){const e=this.m_pathsForOGCTests[n]-this.m_pathsForOGCTests[h];return Ie(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=W.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=Ee(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 qt{getOperatorType(){return 10103}accelerateGeometry(e,t,s){return!1}canAccelerateGeometry(e){return!1}supportsCurves(){return!0}isSimpleAsFeature(e,t,s,i,r){const n=Tt(e,t,s,i,r);return T(e.getGeometryType(),n)}isSimplePlanarDONOTUSE(e,t,s,i,r){const n=vt(e,t,s,i,r);return G(n)}executeMany(e,t,s,i){return new zt(e,t,s,i)}execute(t,s,i,r){const h=new e([t]),o=this.executeMany(h,s,i,r).next();return o||n("null geometry"),o}}class zt extends t{constructor(e,t,s,i){super(),this.m_progressTracker=i,this.m_bForceSimplify=s,this.m_index=-1,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=F(e,-1),s=(new qt).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 Ft(e,this.m_spatialReference,this.m_bForceSimplify,this.m_progressTracker)}}export{qt as O,Et as T,Ne as U,It as a,dt as b,ft as c,xt as d,ut as e,lt as f,pt as g,We as h,ct as i,_t as j,Nt as k,bt as l,nt as m,Je as n,Vt as o,ot as p,Ye as q,it as s};