@itwin/core-frontend 5.14.0-dev.9 → 5.14.2

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 (86) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/lib/cjs/GeoServices.d.ts +3 -0
  3. package/lib/cjs/GeoServices.d.ts.map +1 -1
  4. package/lib/cjs/GeoServices.js +8 -1
  5. package/lib/cjs/GeoServices.js.map +1 -1
  6. package/lib/cjs/IModelApp.d.ts +1 -0
  7. package/lib/cjs/IModelApp.d.ts.map +1 -1
  8. package/lib/cjs/IModelApp.js +1 -0
  9. package/lib/cjs/IModelApp.js.map +1 -1
  10. package/lib/cjs/IModelConnection.d.ts.map +1 -1
  11. package/lib/cjs/IModelConnection.js +7 -2
  12. package/lib/cjs/IModelConnection.js.map +1 -1
  13. package/lib/cjs/extension/ExtensionAdmin.d.ts +0 -2
  14. package/lib/cjs/extension/ExtensionAdmin.d.ts.map +1 -1
  15. package/lib/cjs/extension/ExtensionAdmin.js +44 -22
  16. package/lib/cjs/extension/ExtensionAdmin.js.map +1 -1
  17. package/lib/cjs/extension/ExtensionRuntime.js +1 -0
  18. package/lib/cjs/extension/ExtensionRuntime.js.map +1 -1
  19. package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts +1 -1
  20. package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
  21. package/lib/cjs/extension/providers/RemoteExtensionProvider.js +2 -2
  22. package/lib/cjs/extension/providers/RemoteExtensionProvider.js.map +1 -1
  23. package/lib/cjs/internal/render/webgl/SceneCompositor.d.ts.map +1 -1
  24. package/lib/cjs/internal/render/webgl/SceneCompositor.js +16 -19
  25. package/lib/cjs/internal/render/webgl/SceneCompositor.js.map +1 -1
  26. package/lib/cjs/internal/render/webgl/Target.d.ts +2 -0
  27. package/lib/cjs/internal/render/webgl/Target.d.ts.map +1 -1
  28. package/lib/cjs/internal/render/webgl/Target.js +1 -0
  29. package/lib/cjs/internal/render/webgl/Target.js.map +1 -1
  30. package/lib/cjs/internal/tile/OrbitGtTileTree.d.ts +11 -5
  31. package/lib/cjs/internal/tile/OrbitGtTileTree.d.ts.map +1 -1
  32. package/lib/cjs/internal/tile/OrbitGtTileTree.js +37 -13
  33. package/lib/cjs/internal/tile/OrbitGtTileTree.js.map +1 -1
  34. package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts +5 -3
  35. package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
  36. package/lib/cjs/quantity-formatting/QuantityFormatter.js +7 -2
  37. package/lib/cjs/quantity-formatting/QuantityFormatter.js.map +1 -1
  38. package/lib/cjs/tile/GltfReader.d.ts.map +1 -1
  39. package/lib/cjs/tile/GltfReader.js +3 -1
  40. package/lib/cjs/tile/GltfReader.js.map +1 -1
  41. package/lib/esm/GeoServices.d.ts +3 -0
  42. package/lib/esm/GeoServices.d.ts.map +1 -1
  43. package/lib/esm/GeoServices.js +8 -1
  44. package/lib/esm/GeoServices.js.map +1 -1
  45. package/lib/esm/IModelApp.d.ts +1 -0
  46. package/lib/esm/IModelApp.d.ts.map +1 -1
  47. package/lib/esm/IModelApp.js +1 -0
  48. package/lib/esm/IModelApp.js.map +1 -1
  49. package/lib/esm/IModelConnection.d.ts.map +1 -1
  50. package/lib/esm/IModelConnection.js +7 -2
  51. package/lib/esm/IModelConnection.js.map +1 -1
  52. package/lib/esm/extension/ExtensionAdmin.d.ts +0 -2
  53. package/lib/esm/extension/ExtensionAdmin.d.ts.map +1 -1
  54. package/lib/esm/extension/ExtensionAdmin.js +44 -22
  55. package/lib/esm/extension/ExtensionAdmin.js.map +1 -1
  56. package/lib/esm/extension/ExtensionRuntime.js +1 -0
  57. package/lib/esm/extension/ExtensionRuntime.js.map +1 -1
  58. package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts +1 -1
  59. package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
  60. package/lib/esm/extension/providers/RemoteExtensionProvider.js +2 -2
  61. package/lib/esm/extension/providers/RemoteExtensionProvider.js.map +1 -1
  62. package/lib/esm/internal/render/webgl/SceneCompositor.d.ts.map +1 -1
  63. package/lib/esm/internal/render/webgl/SceneCompositor.js +16 -19
  64. package/lib/esm/internal/render/webgl/SceneCompositor.js.map +1 -1
  65. package/lib/esm/internal/render/webgl/Target.d.ts +2 -0
  66. package/lib/esm/internal/render/webgl/Target.d.ts.map +1 -1
  67. package/lib/esm/internal/render/webgl/Target.js +1 -0
  68. package/lib/esm/internal/render/webgl/Target.js.map +1 -1
  69. package/lib/esm/internal/tile/OrbitGtTileTree.d.ts +11 -5
  70. package/lib/esm/internal/tile/OrbitGtTileTree.d.ts.map +1 -1
  71. package/lib/esm/internal/tile/OrbitGtTileTree.js +36 -12
  72. package/lib/esm/internal/tile/OrbitGtTileTree.js.map +1 -1
  73. package/lib/esm/quantity-formatting/QuantityFormatter.d.ts +5 -3
  74. package/lib/esm/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
  75. package/lib/esm/quantity-formatting/QuantityFormatter.js +7 -2
  76. package/lib/esm/quantity-formatting/QuantityFormatter.js.map +1 -1
  77. package/lib/esm/tile/GltfReader.d.ts.map +1 -1
  78. package/lib/esm/tile/GltfReader.js +3 -1
  79. package/lib/esm/tile/GltfReader.js.map +1 -1
  80. package/lib/public/scripts/parse-imdl-worker.js +1 -1
  81. package/lib/test-public/scripts/checkbrowser.js +24 -0
  82. package/lib/test-public/scripts/draco_encoder.js +52 -0
  83. package/lib/test-public/scripts/draco_wasm_wrapper.js +117 -0
  84. package/lib/test-public/scripts/parse-imdl-worker.js +2 -0
  85. package/lib/test-public/test-worker.js +1 -0
  86. package/package.json +20 -21
@@ -0,0 +1 @@
1
+ (function(){"use strict";function ad(u,t){}function ys(u){const t=parseInt(u,16);return Number.isNaN(t)?0:t}function ic(u,t){return Vo(u,t,!1)}function Vo(u,t,e=!0){const n=u.charCodeAt(t);return n>=(e?48:49)&&n<=57||n>=97&&n<=102}function Oo(u,t,e){if(e===0||!ic(u,t))return!1;for(let n=1;n<e;n++)if(!Vo(u,t+n))return!1;return!0}var $t;(function(u){function t(k){if(ft(k))return 0;const E=k.length,q=E>12?E-10:2;return ys(k.slice(q))}u.getLocalId=t;function e(k){if(ft(k))return 0;const E=k.length;return E<=12?0:ys(k.slice(2,E-10))}u.getBriefcaseId=e;function n(k){return typeof k=="string"?u.fromString(k):u.invalid}u.fromJSON=n;function i(k){if(typeof k!="string")return u.invalid;if(u.isId64(k))return k;k=k.toLowerCase().trim();const E=k.length;if(E<2||k[0]!=="0"||k[1]!=="x")return u.invalid;let q=0,et=0,Nt=2;return E>12&&(Nt=E-10,et=ys(k.slice(2,Nt))),q=ys(k.slice(Nt)),r(q,et)}u.fromString=i;const s=["0000000000","000000000","00000000","0000000","000000","00000","0000","000","00","0",""];function r(k,E){if(typeof k!="number"||typeof E!="number"||(k=Math.floor(k),k===0))return u.invalid;E=Math.floor(E);const q=k.toString(16);return`0x${E===0?q:E.toString(16)+(s[q.length]+q)}`}u.fromLocalAndBriefcaseIds=r;const o=[48,120,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48];function a(k){return k+(k<10?48:87)}function c(k){return k-(k>=87?87:48)}function l(k,E,q){let et=0;for(let Nt=E;Nt<q;Nt++){const se=c(k.charCodeAt(Nt)),Ne=q-Nt-1<<2,Qn=se<<Ne;et=(et|Qn)>>>0}return et}function d(k,E){const q=k>>>0,et=(E&255)*4294967296;if(q+et===0)return u.invalid;const se=o;let Ne=2;for(let Qn=7;Qn>=0;Qn--){const xs=Qn<<2,zo=15<<xs,_s=(E&zo)>>>xs;(Ne>2||_s!==0)&&(se[Ne++]=a(_s))}for(let Qn=7;Qn>=0;Qn--){const xs=Qn<<2,zo=15<<xs,_s=(k&zo)>>>xs;(Ne>2||_s!==0)&&(se[Ne++]=a(_s))}return se.length!==Ne&&(se.length=Ne),String.fromCharCode(...o)}u.fromUint32Pair=d;function h(k){return d(k.lower,k.upper)}u.fromUint32PairObject=h;function g(k,E){return k!==0||(E&255)!==0}u.isValidUint32Pair=g;function m(k,E){return E||(E={lower:0,upper:0}),E.lower=p(k),E.upper=x(k),E}u.getUint32Pair=m;function p(k){if(ft(k))return 0;const E=k.length,q=E>10?E-8:2;return l(k,q,E)}u.getLowerUint32=p;function x(k){const E=k.length;return E<=10||ft(k)?0:l(k,2,E-8)}u.getUpperUint32=x;function _(k,E=!1){if(k instanceof Set)return E?new Set(k):k;const q=new Set;return typeof k=="string"?q.add(k):Array.isArray(k)&&k.forEach(et=>{typeof et=="string"&&q.add(et)}),q}u.toIdSet=_;function*I(k){if(typeof k=="string")yield k;else for(const E of k)yield E}u.iterator=I;function v(k){return typeof k=="string"?[k]:k}u.iterable=v;function S(k){return typeof k=="string"?k:(Array.isArray(k)?k[0]:k.values().next().value)??u.invalid}u.getFirst=S;function w(k){return typeof k=="string"?1:Array.isArray(k)?k.length:k.size}u.sizeOf=w;function T(k,E){return typeof k=="string"?k===E:Array.isArray(k)?k.indexOf(E)!==-1:k.has(E)}u.has=T,u.invalid="0";function R(k){return k.length===18&&k.startsWith("0xffffff")}u.isTransient=R;function L(k){return rt(k)&&R(k)}u.isTransientId64=L;function z(k){const E=k.length;if(E===0||18<E||k[0]!=="0")return!1;if(E===1)return!0;if(E===2||k[1]!=="x")return!1;let q=2;if(E>12){if(q=E-10,!Oo(k,2,q-2))return!1;for(let et=q;et<E&&k.charCodeAt(et)===48;et++)q++;if(q>=E)return!1}return Oo(k,q,E-q)}u.isId64=z;function K(k){return u.invalid!==k}u.isValid=K;function rt(k){return u.invalid!==k&&u.isId64(k)}u.isValidId64=rt;function ft(k){return u.invalid===k}u.isInvalid=ft;class wt{_map=new Map;constructor(E){E!==void 0&&this.addIds(E)}equals(E){if(this===E)return!0;if(this.size!==E.size)return!1;for(const[q,et]of this._map){const Nt=E._map.get(q);if(!Nt||et.size!==Nt.size)return!1;for(const se of et)if(!Nt.has(se))return!1}return!0}clear(){this._map.clear()}addId(E){this.add(u.getLowerUint32(E),u.getUpperUint32(E))}addIds(E){for(const q of u.iterable(E))this.addId(q)}hasId(E){return this.has(u.getLowerUint32(E),u.getUpperUint32(E))}add(E,q){let et=this._map.get(q);et===void 0&&(et=new Set,this._map.set(q,et)),et.add(E)}deleteId(E){this.delete(u.getLowerUint32(E),u.getUpperUint32(E))}deleteIds(E){for(const q of u.iterable(E))this.deleteId(q)}delete(E,q){const et=this._map.get(q);et!==void 0&&(et.delete(E),et.size===0&&this._map.delete(q))}has(E,q){const et=this._map.get(q);return et!==void 0&&et.has(E)}hasPair(E){return this.has(E.lower,E.upper)}get isEmpty(){return this._map.size===0}get size(){let E=0;for(const q of this._map)E+=q[1].size;return E}toId64Array(){const E=[];for(const q of this._map)for(const et of q[1])E.push(u.fromUint32Pair(et,q[0]));return E}toId64Set(){const E=new Set;for(const q of this._map)for(const et of q[1])E.add(u.fromUint32Pair(et,q[0]));return E}forEach(E){for(const q of this._map)for(const et of q[1])E(et,q[0])}}u.Uint32Set=wt;class Yt{_map=new Map;clear(){this._map.clear()}getById(E){return this.get(u.getLowerUint32(E),u.getUpperUint32(E))}setById(E,q){this.set(u.getLowerUint32(E),u.getUpperUint32(E),q)}set(E,q,et){let Nt=this._map.get(q);Nt===void 0&&(Nt=new Map,this._map.set(q,Nt)),Nt.set(E,et)}get(E,q){const et=this._map.get(q);return et!==void 0?et.get(E):void 0}get isEmpty(){return this._map.size===0}get size(){let E=0;for(const q of this._map)E+=q[1].size;return E}forEach(E){for(const q of this._map)for(const et of q[1])E(et[0],q[0],et[1])}}u.Uint32Map=Yt})($t||($t={}));function Ps(u){if(u<0||Math.round(u)!==u)throw new Error("Local Id must be a non-negative integer")}class Is{initialLocalId;_localId;constructor(t=0){Ps(t),this.initialLocalId=t,this._localId=t}get currentLocalId(){return this._localId}getNext(){return $t.fromLocalAndBriefcaseIds(++this._localId,16777215)}peekNext(){return $t.fromLocalAndBriefcaseIds(this._localId+1,16777215)}toJSON(){return{initialLocalId:this.initialLocalId,currentLocalId:this.currentLocalId}}static fromJSON(t){Ps(t.currentLocalId);const e=new Is(t.initialLocalId);return e._localId=t.currentLocalId,e}fork(){return{initialLocalId:this.currentLocalId,currentLocalId:this.currentLocalId}}merge(t){const{initialLocalId:e,currentLocalId:n}=t;if(Ps(e),Ps(n),e>this.currentLocalId)throw new Error("Transient Id sequences do not intersect");if(e>n)throw new Error("Current local Id cannot be less than initial local Id");const i=this.currentLocalId-e;return this._localId+=n-e,s=>s>e&&s<=n?s+i:s}}var vs;(function(u){const t=new RegExp("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");u.empty="00000000-0000-0000-0000-000000000000";function e(r){return t.test(r)}u.isGuid=e;function n(r){return/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(r)}u.isV4Guid=n;function i(){return crypto.randomUUID()}u.createValue=i;function s(r){const o=r.toLowerCase().trim();if(e(o))return o;const a=o.replace(/-/g,""),c=/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;return c.test(a)?a.replace(c,(l,d,h,g,m,p)=>`${d}-${h}-${g}-${m}-${p}`):r}u.normalize=s})(vs||(vs={}));function ki(u,t,e=.1){return u<t-e?-1:u>t+e?1:0}function Et(u,t){return u-t}function Mn(u,t){return u!==t?u<t?-1:1:0}function Ss(u,t){return u===t?0:u<t?-1:1}function fi(u,t,e){return t===void 0?e===void 0?0:-1:e===void 0?1:u(t,e)}function sc(u,t){return fi(Et,u,t)}function Lo(u,t){return fi(Mn,u,t)}function $n(u){return u}function Cr(u,t,e){return Uo(t,n=>e(u,n))}function Uo(u,t){let e=0,n=u.length;for(;e<n;){const i=Math.floor((e+n)/2),s=t(u[i]);if(s===0)return{index:i,equal:!0};s<0?n=i:e=i+1}return{index:e,equal:!1}}var En;(function(u){u[u.Allow=0]="Allow",u[u.Retain=1]="Retain",u[u.Replace=2]="Replace"})(En||(En={}));class Tr{_array=[];_compare;_clone;_duplicatePolicy;constructor(t,e=!1,n=$n){this._compare=t,this._clone=n,typeof e=="boolean"&&(e=e?En.Allow:En.Retain),this._duplicatePolicy=e}get length(){return this._array.length}get isEmpty(){return this.length===0}[Symbol.iterator](){return this._array[Symbol.iterator]()}indexOf(t){const e=this.lowerBound(t);return e.equal?e.index:-1}contains(t){return this.indexOf(t)!==-1}findEqual(t){const e=this.indexOf(t);return e!==-1?this._array[e]:void 0}findEquivalent(t){const e=this.indexOfEquivalent(t);return e!==-1?this._array[e]:void 0}indexOfEquivalent(t){const e=Uo(this._array,n=>0-t(n));return e.equal?e.index:-1}get(t){return t<this.length?this._array[t]:void 0}forEach(t){for(let e=0;e<this.length;e++)t(this._array[e])}slice(t,e){const n=new Tr(this._compare,this._duplicatePolicy,this._clone);return n._array=this._array.slice(t,e),n}lowerBound(t){return Cr(t,this._array,this._compare)}_clear(){this._array.length=0}_extractArray(){const t=this._array;return this._array=[],t}_insert(t,e){const n=this.lowerBound(t);if(n.equal)switch(this._duplicatePolicy){case En.Retain:return n.index;case En.Replace:return this._array[n.index]=this._clone(t),e&&e(t),n.index}return this._array.splice(n.index,0,this._clone(t)),e!==void 0&&e(t),n.index}_remove(t){const e=this.lowerBound(t);return e.equal?(this._array.splice(e.index,1),e.index):-1}}class jn extends Tr{constructor(t,e=!1,n=$n){super(t,e,n)}clear(){this._clear()}extractArray(){return this._extractArray()}insert(t,e){return this._insert(t,e)}remove(t){return this._remove(t)}slice(t,e){const n=new jn(this._compare,this._duplicatePolicy,this._clone);return n._array=this._array.slice(t,e),n}}class rc{_keys;_values;_curIndex=-1;constructor(t,e){this._keys=t,this._values=e}next(){return++this._curIndex>=this._keys.length?{done:!0}:{value:{key:this._keys[this._curIndex],value:this._values[this._curIndex]},done:!1}}}class kr{_keys=[];_compareKeys;_cloneKey;_values=[];_cloneValue;constructor(t,e=$n,n=$n){this._compareKeys=t,this._cloneKey=e,this._cloneValue=n}get size(){return this._keys.length}[Symbol.iterator](){return new rc(this._keys,this._values)}keys(){function*t(e){for(const n of e)yield n.key}return{[Symbol.iterator]:()=>t(this)}}values(){function*t(e){for(const n of e)yield n.value}return{[Symbol.iterator]:()=>t(this)}}clear(){this._keys=[],this._values=[]}get(t){const e=this.lowerBound(t);return e.equal?this._values[e.index]:void 0}has(t){return this.lowerBound(t).equal}delete(t){const e=this.lowerBound(t);return e.equal?(this._values.splice(e.index,1),this._keys.splice(e.index,1),!0):!1}insert(t,e){return this.findOrInsert(t,e).inserted}findOrInsert(t,e){const n=this.lowerBound(t);return n.equal?{value:this._values[n.index],inserted:!1}:(e=this._cloneValue(e),this._keys.splice(n.index,0,this._cloneKey(t)),this._values.splice(n.index,0,this._cloneValue(e)),{value:e,inserted:!0})}set(t,e){e=this._cloneValue(e);const n=this.lowerBound(t);n.equal?this._values[n.index]=e:(this._keys.splice(n.index,0,this._cloneKey(t)),this._values.splice(n.index,0,e))}extractPairs(){const t=[];for(let e=0;e<this.size;e++)t.push({key:this._keys[e],value:this._values[e]});return this.clear(),t}extractArrays(){const t={keys:this._keys,values:this._values};return this.clear(),t}forEach(t){for(let e=0;e<this.size;e++)t(this._keys[e],this._values[e])}lowerBound(t){return Cr(t,this._keys,this._compareKeys)}}function ln(u,t){if(u===void 0)throw new Error("Expected value to be defined, but it was undefined.");return u}class Bo{value;index;constructor(t,e){this.value=t,this.index=e}}class Fr{_array=[];_compareValues;_clone;_maximumSize;constructor(t,e=Number.MAX_SAFE_INTEGER,n=$n){this._compareValues=t,this._clone=n,this._maximumSize=e}get length(){return this._array.length}get isFull(){return this.length>=this._maximumSize}get isEmpty(){return this.length===0}clear(){this._array=[]}insert(t,e){const n=this.lowerBound(t);if(n.equal)return this._array[n.index].index;if(this.isFull)return-1;const i=new Bo(this._clone(t),this._array.length);return e!==void 0&&e(i.value),this._array.splice(n.index,0,i),i.index}indexOf(t){const e=this.lowerBound(t);return e.equal?this._array[e.index].index:-1}lowerBound(t){return Cr(t,this._array,(e,n)=>this._compareValues(e,n.value))}toArray(){const t=[];for(const e of this._array)t[e.index]=e.value;return t}}class oc{_array;constructor(t,e=$n){this._array=new jn(t,!1,e)}get size(){return this._array.length}has(t){return this._array.indexOf(t)!==-1}[Symbol.iterator](){return this._array[Symbol.iterator]()}}class Fi extends oc{constructor(t,e=$n){super(t,e)}clear(){this._array.clear()}add(t){return this._array.insert(t),this}delete(t){return this._array.remove(t)!==-1}}class ac{_array=[];_compare;_clone;constructor(t,e=$n){this._compare=t,this._clone=e}get length(){return this._array.length}get isEmpty(){return this.length===0}[Symbol.iterator](){return this._array[Symbol.iterator]()}_swap(t,e){const n=this._array[t];this._array[t]=this._array[e],this._array[e]=n}_heapify(t){let e=-1;for(;;){const n=2*(t+1),i=n-1;if(i<this.length&&this._compare(this._array[i],this._array[t])<0?e=i:e=t,n<this.length&&this._compare(this._array[n],this._array[e])<0&&(e=n),e!==t)this._swap(e,t),t=e;else break}}sort(){for(let t=Math.ceil(this.length/2);t>=0;t--)this._heapify(t)}push(t){const e=this._clone(t);let n=this.length;for(this._array.push(e);n!==0;){const i=Math.floor((n-1)/2);if(this._compare(this._array[n],this._array[i])<0)this._swap(n,i),n=i;else break}return e}append(t){const e=this._clone(t);return this._array.push(e),e}get front(){return this._peek(0)}pop(){return this._pop(0)}clear(){this._array.length=0}_pop(t){if(t<0||t>=this.length)return;const e=this._array[t];return this._swap(t,this.length-1),this._array.length--,this._heapify(t),e}_peek(t){if(!(t<0||t>=this.length))return this._array[t]}}class Zo{x;y;set(t=0,e=0){this.x=t,this.y=e}setZero(){this.x=0,this.y=0}constructor(t=0,e=0){this.x=t,this.y=e}setFrom(t){t?(this.x=t.x,this.y=t.y):(this.x=0,this.y=0)}freeze(){return Object.freeze(this)}isAlmostEqual(t,e){return f.isSameCoordinate(this.x,t.x,e)&&f.isSameCoordinate(this.y,t.y,e)}isAlmostEqualXY(t,e,n){return f.isSameCoordinate(this.x,t,n)&&f.isSameCoordinate(this.y,e,n)}toJSON(){return[this.x,this.y]}toJSONXY(){return{x:this.x,y:this.y}}setFromJSON(t){if(Array.isArray(t)){this.set(t[0]||0,t[1]||0);return}if(t){this.set(t.x||0,t.y||0);return}this.set(0,0)}distance(t){const e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)}distanceSquared(t){const e=t.x-this.x,n=t.y-this.y;return e*e+n*n}maxDiff(t){return Math.max(Math.abs(this.x-t.x),Math.abs(this.y-t.y))}at(t){return t<.5?this.x:this.y}setAt(t,e){t<.5?this.x=e:this.y=e}indexOfMaxAbs(){let t=0;const e=Math.abs(this.x);return Math.abs(this.y)>e&&(t=1),t}get isAlmostZero(){return f.isSmallMetricDistance(this.x)&&f.isSmallMetricDistance(this.y)}get isZero(){return this.x===0&&this.y===0}maxAbs(){return Math.max(Math.abs(this.x),Math.abs(this.y))}magnitude(){return Math.sqrt(this.x*this.x+this.y*this.y)}magnitudeSquared(){return this.x*this.x+this.y*this.y}isExactEqual(t){return this.x===t.x&&this.y===t.y}isAlmostEqualMetric(t,e=f.smallMetricDistance){return this.maxDiff(t)<=e}vectorTo(t,e){return Q.create(t.x-this.x,t.y-this.y,e)}unitVectorTo(t,e){return this.vectorTo(t,e).normalize(e)}static crossProductToPoints(t,e,n){return f.crossProductXYXY(e.x-t.x,e.y-t.y,n.x-t.x,n.y-t.y)}scaleInPlace(t){return this.x*=t,this.y*=t,this}}class D extends Zo{constructor(t=0,e=0){super(t,e)}clone(t){return D.create(this.x,this.y,t)}static create(t=0,e=0,n){return n?(n.x=t,n.y=e,n):new D(t,e)}static createInterpolated(t,e,n){return new D(f.interpolate(t.x,e,n.x),f.interpolate(t.y,e,n.y))}static fromJSON(t){const e=new D;return e.setFromJSON(t),e}static createFrom(t,e){return t?D.create(t.x,t.y,e):D.create(0,0,e)}static createZero(t){return D.create(0,0,t)}addForwardLeft(t,e,n,i){const s=n.x,r=n.y;return D.create(this.x+t*s-e*r,this.y+t*r+e*s,i)}forwardLeftInterpolate(t,e,n){const i=n.x-this.x,s=n.y-this.y;return D.create(this.x+t*i-e*s,this.y+t*s+e*i)}interpolate(t,e,n){if(t<=.5)return D.create(this.x+t*(e.x-this.x),this.y+t*(e.y-this.y),n);const i=t-1;return D.create(e.x+i*(e.x-this.x),e.y+i*(e.y-this.y),n)}interpolateXY(t,e,n,i){return D.create(f.interpolate(this.x,t,n.x),f.interpolate(this.y,e,n.y),i)}minus(t,e){return D.create(this.x-t.x,this.y-t.y,e)}plus(t,e){return D.create(this.x+t.x,this.y+t.y,e)}plusXY(t=0,e=0,n){return D.create(this.x+t,this.y+e,n)}plusScaled(t,e,n){return D.create(this.x+t.x*e,this.y+t.y*e,n)}plus2Scaled(t,e,n,i,s){return D.create(this.x+t.x*e+n.x*i,this.y+t.y*e+n.y*i,s)}plus3Scaled(t,e,n,i,s,r,o){return D.create(this.x+t.x*e+n.x*i+s.x*r,this.y+t.y*e+n.y*i+s.y*r,o)}static createAdd2Scaled(t,e,n,i,s){return D.create(t.x*e+n.x*i,t.y*e+n.y*i,s)}static createAdd2ScaledXY(t,e,n,i,s,r,o){return D.create(t*n+i*r,e*n+s*r,o)}static createAdd3Scaled(t,e,n,i,s,r,o){return D.create(t.x*e+n.x*i+s.x*r,t.y*e+n.y*i+s.y*r,o)}static createAdd3ScaledXY(t,e,n,i,s,r,o,a,c,l){return D.create(t*n+i*r+o*c,e*n+s*r+a*c,l)}dotVectorsToTargets(t,e){return(t.x-this.x)*(e.x-this.x)+(t.y-this.y)*(e.y-this.y)}crossProductToPoints(t,e){const n=t.x-this.x,i=t.y-this.y,s=e.x-this.x,r=e.y-this.y;return n*r-i*s}fractionOfProjectionToLine(t,e,n=0){const i=t.distanceSquared(e);return i<f.smallMetricDistanceSquared?n:t.dotVectorsToTargets(e,this)/i}}class Q extends Zo{constructor(t=0,e=0){super(t,e)}clone(t){return Q.create(this.x,this.y,t)}static create(t=0,e=0,n){return n?(n.x=t,n.y=e,n):new Q(t,e)}static unitX(t=1){return new Q(t,0)}static unitY(t=1){return new Q(0,t)}static createZero(t){return Q.create(0,0,t)}static createFrom(t,e){return t instanceof Float64Array?t.length>=2?Q.create(t[0],t[1]):t.length>=1?Q.create(t[0],0):Q.create(0,0):Q.create(t.x,t.y,e)}static fromJSON(t){const e=new Q;return e.setFromJSON(t),e}static createPolar(t,e){return Q.create(t*e.cos(),t*e.sin())}static createStartEnd(t,e,n){return Q.create(e.x-t.x,e.y-t.y,n)}static createOffsetBisector(t,e,n){let i=t.plus(e);if(i=i.normalize(),i){const s=i.dotProduct(t);return i.scale(n,i),i.safeDivideOrNull(s)}}static createAdd2Scaled(t,e,n,i,s){return Q.create(t.x*e+n.x*i,t.y*e+n.y*i,s)}static createAdd2ScaledXY(t,e,n,i,s,r,o){return Q.create(t*n+i*r,e*n+s*r,o)}static createAdd3Scaled(t,e,n,i,s,r,o){return Q.create(t.x*e+n.x*i+s.x*r,t.y*e+n.y*i+s.y*r,o)}static createAdd3ScaledXY(t,e,n,i,s,r,o,a,c,l){return Q.create(t*n+i*r+o*c,e*n+s*r+a*c,l)}safeDivideOrNull(t,e){if(t!==0)return this.scale(1/t,e)}normalize(t){const e=f.correctSmallFraction(this.magnitude());return t=t||new Q,this.safeDivideOrNull(e,t)}fractionOfProjectionToVector(t,e){const n=t.magnitudeSquared();return n<f.smallMetricDistanceSquared?e||0:this.dotProduct(t)/n}negate(t){return t=t||new Q,t.x=-this.x,t.y=-this.y,t}rotate90CCWXY(t){t=t||new Q;const e=this.x,n=this.y;return t.x=-n,t.y=e,t}rotate90CWXY(t){t=t||new Q;const e=this.x,n=this.y;return t.x=n,t.y=-e,t}unitPerpendicularXY(t){t=t||new Q;const e=this.x,n=this.y;t.x=-n,t.y=e;const i=e*e+n*n;if(i!==0){const s=1/Math.sqrt(i);t.x*=s,t.y*=s}return t}rotateXY(t,e){const n=t.sin(),i=t.cos(),s=this.x,r=this.y;return e=e||new Q,e.x=s*i-r*n,e.y=s*n+r*i,e}interpolate(t,e,n){if(n=n||new Q,t<=.5)n.x=this.x+t*(e.x-this.x),n.y=this.y+t*(e.y-this.y);else{const i=t-1;n.x=e.x+i*(e.x-this.x),n.y=e.y+i*(e.y-this.y)}return n}plus(t,e){return e=e||new Q,e.x=this.x+t.x,e.y=this.y+t.y,e}minus(t,e){return e=e||new Q,e.x=this.x-t.x,e.y=this.y-t.y,e}plusScaled(t,e,n){return n=n||new Q,n.x=this.x+t.x*e,n.y=this.y+t.y*e,n}plus2Scaled(t,e,n,i,s){return s=s||new Q,s.x=this.x+t.x*e+n.x*i,s.y=this.y+t.y*e+n.y*i,s}plus3Scaled(t,e,n,i,s,r,o){return o=o||new Q,o.x=this.x+t.x*e+n.x*i+s.x*r,o.y=this.y+t.y*e+n.y*i+s.y*r,o}scale(t,e){return e=e||new Q,e.x=this.x*t,e.y=this.y*t,e}scaleToLength(t,e){const n=f.correctSmallFraction(this.magnitude());if(n!==0)return this.scale(t/n,e)}dotProduct(t){return this.x*t.x+this.y*t.y}dotProductStartEnd(t,e){return this.x*(e.x-t.x)+this.y*(e.y-t.y)}crossProduct(t){return this.x*t.y-this.y*t.x}radiansTo(t){return Math.atan2(this.crossProduct(t),this.dotProduct(t))}angleTo(t){return A.createRadians(this.radiansTo(t))}isParallelTo(t,e=!1,n=!1,i){const s=i?.radianSquaredTol??f.smallAngleRadiansSquared,r=i?.distanceSquaredTol??f.smallMetricDistanceSquared,o=this.magnitudeSquared(),a=t.magnitudeSquared();if(o<r||a<r)return n;if(this.dotProduct(t)<0&&!e)return!1;const l=this.crossProduct(t);return l*l<=s*o*a}isPerpendicularTo(t,e=!1,n){const i=n?.radianSquaredTol??f.smallAngleRadiansSquared,s=n?.distanceSquaredTol??f.smallMetricDistanceSquared,r=this.magnitudeSquared(),o=t.magnitudeSquared();if(r<s||o<s)return e;const a=this.dotProduct(t);return a*a<=i*r*o}}var ws;(function(u){function t(e,n,i){return f.isSameCoordinate(e.x,n.x,i)&&f.isSameCoordinate(e.y,n.y,i)}u.almostEqual=t})(ws||(ws={}));var As;(function(u){function t(e,n,i){return f.isSameCoordinate(e.x,n.x,i)&&f.isSameCoordinate(e.y,n.y,i)&&f.isSameCoordinate(e.z,n.z,i)}u.almostEqual=t})(As||(As={}));class Rn{x;y;z;set(t=0,e=0,n=0){this.x=t,this.y=e,this.z=n}setZero(){this.x=0,this.y=0,this.z=0}constructor(t=0,e=0,n=0){this.x=t,this.y=e,this.z=n}static isXAndY(t){return t.x!==void 0&&t.y!==void 0}static hasZ(t){return t.z!==void 0}static isXYAndZ(t){return this.isXAndY(t)&&this.hasZ(t)}static isAnyImmediatePointType(t){return y.isXAndY(t)||f.isNumberArray(t,2)}static accessX(t,e){return t.x!==void 0?t.x:Array.isArray(t)&&t.length>0&&Number.isFinite(t[0])?t[0]:e}static accessY(t,e){return t.y!==void 0?t.y:Array.isArray(t)&&t.length>1&&Number.isFinite(t[1])?t[1]:e}static accessZ(t,e){return t.z!==void 0?t.z:Array.isArray(t)&&t.length>2&&Number.isFinite(t[2])?t[2]:e}setFrom(t){t===void 0?this.setZero():Rn.isXAndY(t)?(this.x=t.x,this.y=t.y,this.z=Rn.hasZ(t)?t.z:0):(this.x=t[0],this.y=t[1],this.z=t[2])}setFromPoint3d(t){t?(this.x=t.x,this.y=t.y,this.z=t.z):this.setZero()}setFromVector3d(t){t?(this.x=t.x,this.y=t.y,this.z=t.z):this.setZero()}isAlmostEqual(t,e){return As.almostEqual(this,t,e)}isAlmostEqualXYZ(t,e,n,i){return f.isSameCoordinate(this.x,t,i)&&f.isSameCoordinate(this.y,e,i)&&f.isSameCoordinate(this.z,n,i)}isAlmostEqualPointPlusScaledVector(t,e,n,i){return f.isSameCoordinate(this.x,t.x+e.x*n,i)&&f.isSameCoordinate(this.y,t.y+e.y*n,i)&&f.isSameCoordinate(this.z,t.z+e.z*n,i)}isAlmostEqualXY(t,e){return f.isSameCoordinate(this.x,t.x,e)&&f.isSameCoordinate(this.y,t.y,e)}toJSON(){return this.toArray()}toArray(){return[this.x,this.y,this.z]}toJSONXYZ(){return{x:this.x,y:this.y,z:this.z}}toFloat64Array(){return Float64Array.of(this.x,this.y,this.z)}setFromJSON(t){if(Array.isArray(t)){this.set(t[0]||0,t[1]||0,t[2]||0);return}if(t){this.set(t.x||0,t.y||0,t.z||0);return}this.set(0,0,0)}distance(t){const e=t.x-this.x,n=t.y-this.y,i=t.z-this.z;return Math.sqrt(e*e+n*n+i*i)}distanceSquared(t){const e=t.x-this.x,n=t.y-this.y,i=t.z-this.z;return e*e+n*n+i*i}distanceXY(t){const e=t.x-this.x,n=t.y-this.y;return Math.sqrt(e*e+n*n)}distanceSquaredXY(t){const e=t.x-this.x,n=t.y-this.y;return e*e+n*n}maxDiff(t){return Math.max(Math.abs(this.x-t.x),Math.abs(this.y-t.y),Math.abs(this.z-t.z))}at(t){return t<.5?this.x:t>1.5?this.z:this.y}setAt(t,e){t<.5?this.x=e:t>1.5?this.z=e:this.y=e}indexOfMaxAbs(){let t=0,e=Math.abs(this.x),n=Math.abs(this.y);return n>e&&(t=1,e=n),n=Math.abs(this.z),n>e&&(t=2),t}get isAlmostZero(){return f.isSmallMetricDistance(this.x)&&f.isSmallMetricDistance(this.y)&&f.isSmallMetricDistance(this.z)}get isZero(){return this.x===0&&this.y===0&&this.z===0}maxAbs(){return Math.max(Math.abs(this.x),Math.abs(this.y),Math.abs(this.z))}maxAbsXY(){return Math.max(Math.abs(this.x),Math.abs(this.y))}magnitude(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}magnitudeSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}magnitudeXY(){return Math.sqrt(this.x*this.x+this.y*this.y)}magnitudeSquaredXY(){return this.x*this.x+this.y*this.y}isExactEqual(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}isAlmostEqualMetric(t){return this.maxDiff(t)<=f.smallMetricDistance}addInPlace(t){this.x+=t.x,this.y+=t.y,this.z+=t.z}subtractInPlace(t){this.x-=t.x,this.y-=t.y,this.z-=t.z}addScaledInPlace(t,e){this.x+=e*t.x,this.y+=e*t.y,this.z+=e*t.z}scaleInPlace(t){return this.x*=t,this.y*=t,this.z*=t,this}addXYZInPlace(t=0,e=0,n=0){this.x+=t,this.y+=e,this.z+=n}cloneAsPoint3d(){return y.create(this.x,this.y,this.z)}vectorTo(t,e){return P.create(t.x-this.x,t.y-this.y,t.z-this.z,e)}scaledVectorTo(t,e,n){return P.create(e*(t.x-this.x),e*(t.y-this.y),e*(t.z-this.z),n)}unitVectorTo(t,e){return this.vectorTo(t,e).normalize(e)}freeze(){return Object.freeze(this)}static x(t,e=0){return t===void 0?e:Array.isArray(t)?t[0]:t.x!==void 0?t.x:e}static y(t,e=0){return t===void 0?e:Array.isArray(t)?t[1]:t.y!==void 0?t.y:e}static z(t,e=0){return t===void 0?e:Array.isArray(t)?t[2]:t.z!==void 0?t.z:e}}class y extends Rn{constructor(t=0,e=0,n=0){super(t,e,n)}static fromJSON(t){const e=new y;return e.setFromJSON(t),e}clone(t){return y.create(this.x,this.y,this.z,t)}static create(t=0,e=0,n=0,i){return i?(i.x=t,i.y=e,i.z=n,i):new y(t,e,n)}static createFrom(t,e){if(t instanceof Float64Array){let n=0,i=0,s=0;return t.length>0&&(n=t[0]),t.length>1&&(i=t[1]),t.length>2&&(s=t[2]),y.create(n,i,s,e)}return y.create(t.x,t.y,Rn.hasZ(t)?t.z:0,e)}static createFromPacked(t,e,n){const i=e*3;if(i>=0&&i+2<t.length)return y.create(t[i],t[i+1],t[i+2],n)}static createFromPackedXYZW(t,e,n){const i=e*4;if(i>=0&&i+3<t.length){const s=t[i+3];if(!f.isSmallMetricDistance(s)){const r=1/s;return y.create(r*t[i],r*t[i+1],r*t[i+2],n)}}}static createArrayFromPackedXYZ(t){const e=[];for(let n=0;n+2<t.length;n+=3)e.push(new y(t[n],t[n+1],t[n+2]));return e}static createZero(t){return y.create(0,0,0,t)}crossProductToPoints(t,e,n){return P.createCrossProduct(t.x-this.x,t.y-this.y,t.z-this.z,e.x-this.x,e.y-this.y,e.z-this.z,n)}crossProductToPointsMagnitude(t,e){return f.crossProductMagnitude(t.x-this.x,t.y-this.y,t.z-this.z,e.x-this.x,e.y-this.y,e.z-this.z)}tripleProductToPoints(t,e,n){return f.tripleProduct(t.x-this.x,t.y-this.y,t.z-this.z,e.x-this.x,e.y-this.y,e.z-this.z,n.x-this.x,n.y-this.y,n.z-this.z)}crossProductToPointsXY(t,e){return f.crossProductXYXY(t.x-this.x,t.y-this.y,e.x-this.x,e.y-this.y)}interpolate(t,e,n){if(t<=.5)return y.create(this.x+t*(e.x-this.x),this.y+t*(e.y-this.y),this.z+t*(e.z-this.z),n);const i=t-1;return y.create(e.x+i*(e.x-this.x),e.y+i*(e.y-this.y),e.z+i*(e.z-this.z),n)}interpolateXYZ(t,e,n,i,s){return y.create(f.interpolate(this.x,t,i.x),f.interpolate(this.y,e,i.y),f.interpolate(this.z,n,i.z),s)}interpolatePerpendicularXY(t,e,n,i){i=i||new y;const s=e.minus(this);return this.interpolate(t,e,i),i.x-=n*s.y,i.y+=n*s.x,i}minus(t,e){return y.create(this.x-t.x,this.y-t.y,this.z-t.z,e)}plus(t,e){return y.create(this.x+t.x,this.y+t.y,this.z+t.z,e)}plusXYZ(t=0,e=0,n=0,i){return y.create(this.x+t,this.y+e,this.z+n,i)}plusScaled(t,e,n){return y.create(this.x+t.x*e,this.y+t.y*e,this.z+t.z*e,n)}plus2Scaled(t,e,n,i,s){return y.create(this.x+t.x*e+n.x*i,this.y+t.y*e+n.y*i,this.z+t.z*e+n.z*i,s)}plus3Scaled(t,e,n,i,s,r,o){return y.create(this.x+t.x*e+n.x*i+s.x*r,this.y+t.y*e+n.y*i+s.y*r,this.z+t.z*e+n.z*i+s.z*r,o)}static createScale(t,e,n){return y.create(t.x*e,t.y*e,t.z*e,n)}static createAdd2Scaled(t,e,n,i,s){return y.create(t.x*e+n.x*i,t.y*e+n.y*i,t.z*e+n.z*i,s)}static createAdd3Scaled(t,e,n,i,s,r,o){return y.create(t.x*e+n.x*i+s.x*r,t.y*e+n.y*i+s.y*r,t.z*e+n.z*i+s.z*r,o)}dotVectorsToTargets(t,e){return(t.x-this.x)*(e.x-this.x)+(t.y-this.y)*(e.y-this.y)+(t.z-this.z)*(e.z-this.z)}fractionOfProjectionToLine(t,e,n=0){const i=t.distanceSquared(e);return i<f.smallMetricDistanceSquared?n:t.dotVectorsToTargets(e,this)/i}}class P extends Rn{constructor(t=0,e=0,n=0){super(t,e,n)}static createArrayFromPackedXYZ(t){const e=[];for(let n=0;n+2<t.length;n+=3)e.push(new P(t[n],t[n+1],t[n+2]));return e}clone(t){return P.create(this.x,this.y,this.z,t)}static create(t=0,e=0,n=0,i){return i?(i.x=t,i.y=e,i.z=n,i):new P(t,e,n)}static createCrossProduct(t,e,n,i,s,r,o){return P.create(e*r-n*s,n*i-t*r,t*s-e*i,o)}addCrossProductToTargetsInPlace(t,e,n,i,s,r,o,a,c){const l=i-t,d=s-e,h=r-n,g=o-t,m=a-e,p=c-n;this.x+=d*p-h*m,this.y+=h*g-l*p,this.z+=l*m-d*g}static createCrossProductToPoints(t,e,n,i){return P.createCrossProduct(e.x-t.x,e.y-t.y,e.z-t.z,n.x-t.x,n.y-t.y,n.z-t.z,i)}static createUnitCrossProductToPoints(t,e,n,i){return P.createCrossProduct(e.x-t.x,e.y-t.y,e.z-t.z,n.x-t.x,n.y-t.y,n.z-t.z,i).normalize()}static createPolar(t,e,n){return P.create(t*e.cos(),t*e.sin(),n)}static createSpherical(t,e,n){const i=n.cos();return P.create(i*t*e.cos(),i*t*e.sin(),t*n.sin())}static fromJSON(t){const e=new P;return e.setFromJSON(t),e}static createFrom(t,e){if(t instanceof Float64Array){let n=0,i=0,s=0;return t.length>0&&(n=t[0]),t.length>1&&(i=t[1]),t.length>2&&(s=t[2]),P.create(n,i,s,e)}else if(Array.isArray(t))return P.create(t[0],t[1],t.length>2?t[2]:0);return P.create(t.x,t.y,Rn.hasZ(t)?t.z:0,e)}static createStartEnd(t,e,n){const i=Rn.accessZ(t,0),r=Rn.accessZ(e,0)-i;return n?(n.set(e.x-t.x,e.y-t.y,r),n):new P(e.x-t.x,e.y-t.y,r)}static createStartEndXYZXYZ(t,e,n,i,s,r,o){return this.create(i-t,s-e,r-n,o)}static createRotateVectorAroundVector(t,e,n){const i=e.normalize();if(i){const s=i.crossProduct(t);let r,o;return n?(r=n.cos(),o=n.sin()):(r=0,o=1),P.createAdd3Scaled(t,r,s,o,i,i.dotProduct(t)*(1-r))}}setStartEnd(t,e){this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z}static createZero(t){return P.create(0,0,0,t)}static unitX(t=1){return new P(t,0,0)}static unitY(t=1){return new P(0,t,0)}static unitZ(t=1){return new P(0,0,t)}safeDivideOrNull(t,e){if(t!==0)return this.scale(1/t,e)}normalizeWithLength(t){const e=this.magnitude(),n=f.correctSmallFraction(e);return t=t||new P,{v:this.safeDivideOrNull(n,t),mag:e}}normalize(t){return this.normalizeWithLength(t).v}normalizeInPlace(){return this.normalizeWithLength(this).v!==void 0}static createNormalized(t=0,e=0,n=0,i){if(i===void 0?i=P.create(t,e,n):i.set(t,e,n),i.normalizeInPlace())return i}static createNormalizedStartEnd(t,e,n){if(n=P.createStartEnd(t,e,n),n.normalizeInPlace())return n}fractionOfProjectionToVector(t,e=0){const n=t.magnitudeSquared();return n<f.smallMetricDistanceSquared?e:this.dotProduct(t)/n}negate(t){return t=t||new P,t.x=-this.x,t.y=-this.y,t.z=-this.z,t}rotate90CCWXY(t){t=t||new P;const e=this.x,n=this.y;return t.x=-n,t.y=e,t.z=this.z,t}rotate90CWXY(t){t=t||new P;const e=this.x,n=this.y;return t.x=n,t.y=-e,t.z=this.z,t}unitPerpendicularXY(t){t=t||new P;const e=this.x,n=this.y;t.x=-n,t.y=e,t.z=0;const i=e*e+n*n;if(i!==0){const s=1/Math.sqrt(i);t.x*=s,t.y*=s}return t}rotateXY(t,e){const n=t.sin(),i=t.cos(),s=this.x,r=this.y;return e=e||new P,e.x=s*i-r*n,e.y=s*n+r*i,e.z=this.z,e}rotate90Towards(t,e){const n=this.crossProduct(t).normalize();return n?n.crossProduct(this,e):void 0}rotate90Around(t,e){const n=t.normalize();return n?n.crossProduct(this).plusScaled(n,n.dotProduct(this),e):void 0}interpolate(t,e,n){if(n=n||new P,t<=.5)n.x=this.x+t*(e.x-this.x),n.y=this.y+t*(e.y-this.y),n.z=this.z+t*(e.z-this.z);else{const i=t-1;n.x=e.x+i*(e.x-this.x),n.y=e.y+i*(e.y-this.y),n.z=e.z+i*(e.z-this.z)}return n}plus(t,e){return e=e||new P,e.x=this.x+t.x,e.y=this.y+t.y,e.z=this.z+t.z,e}minus(t,e){return e=e||new P,e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z,e}plusScaled(t,e,n){return n=n||new P,n.x=this.x+t.x*e,n.y=this.y+t.y*e,n.z=this.z+t.z*e,n}plus2Scaled(t,e,n,i,s){return s=s||new P,s.x=this.x+t.x*e+n.x*i,s.y=this.y+t.y*e+n.y*i,s.z=this.z+t.z*e+n.z*i,s}plus3Scaled(t,e,n,i,s,r,o){return o=o||new P,o.x=this.x+t.x*e+n.x*i+s.x*r,o.y=this.y+t.y*e+n.y*i+s.y*r,o.z=this.z+t.z*e+n.z*i+s.z*r,o}static createAdd2Scaled(t,e,n,i,s){return P.create(t.x*e+n.x*i,t.y*e+n.y*i,t.z*e+n.z*i,s)}static createAdd2ScaledXYZ(t,e,n,i,s,r,o,a,c){return P.create(t*i+s*a,e*i+r*a,n*i+o*a,c)}static createAdd3Scaled(t,e,n,i,s,r,o){return P.create(t.x*e+n.x*i+s.x*r,t.y*e+n.y*i+s.y*r,t.z*e+n.z*i+s.z*r,o)}scale(t,e){return e=e||new P,e.x=this.x*t,e.y=this.y*t,e.z=this.z*t,e}scaleToLength(t,e){const n=f.correctSmallFraction(this.magnitude());if(n!==0)return this.scale(t/n,e)}unitCrossProduct(t,e){return this.crossProduct(t,e).normalize(e)}unitCrossProductWithDefault(t,e,n,i,s){const r=this.crossProduct(t,s).normalize(s);return r===void 0?P.create(e,n,i,s):r}normalizeWithDefault(t,e,n,i){const s=this.normalize(i);return s||(i=P.create(t,e,n,i),i.normalizeInPlace()?i:P.create(1,0,0,i))}tryNormalizeInPlace(t=f.smallFraction){const e=this.magnitude();return e<=Math.abs(t)?!1:(this.scaleInPlace(1/e),!0)}sizedCrossProduct(t,e,n){if(n=this.crossProduct(t,n),n.tryNormalizeInPlace())return n.scaleInPlace(e),n}crossProductMagnitudeSquared(t){const e=this.y*t.z-this.z*t.y,n=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x;return e*e+n*n+i*i}crossProductMagnitude(t){return Math.sqrt(this.crossProductMagnitudeSquared(t))}dotProduct(t){return this.x*t.x+this.y*t.y+this.z*t.z}static dotProductAsXYAndZ(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}dotProductStartEnd(t,e){return this.x*(e.x-t.x)+this.y*(e.y-t.y)+this.z*(e.z-t.z)}dotProductStart3dEnd4d(t,e){const n=e.w;return this.x*(e.x-t.x*n)+this.y*(e.y-t.y*n)+this.z*(e.z-t.z*n)}crossProductStartEnd(t,e,n){return P.createCrossProduct(this.x,this.y,this.z,e.x-t.x,e.y-t.y,e.z-t.z,n)}crossProductStartEndXY(t,e){return f.crossProductXYXY(this.x,this.y,e.x-t.x,e.y-t.y)}dotProductStartEndXYZ(t,e,n,i){return this.x*(e-t.x)+this.y*(n-t.y)+this.z*(i-t.z)}dotProductStartEndXY(t,e){return this.x*(e.x-t.x)+this.y*(e.y-t.y)}dotProductStartEndXYZW(t,e,n,i,s){if(f.isSmallMetricDistance(s))return 0;const r=1/s;return this.x*(r*e-t.x)+this.y*(r*n-t.y)+this.z*(r*i-t.z)}dotProductXY(t){return this.x*t.x+this.y*t.y}dotProductXYZ(t,e,n=0){return this.x*t+this.y*e+this.z*n}tripleProduct(t,e){return f.tripleProduct(this.x,this.y,this.z,t.x,t.y,t.z,e.x,e.y,e.z)}crossProductXY(t){return this.x*t.y-this.y*t.x}crossProduct(t,e){return P.createCrossProduct(this.x,this.y,this.z,t.x,t.y,t.z,e)}crossProductXYZ(t,e,n,i){return P.createCrossProduct(this.x,this.y,this.z,t,e,n,i)}radiansTo(t){return Math.atan2(this.crossProductMagnitude(t),this.dotProduct(t))}angleTo(t){return A.createRadians(this.radiansTo(t))}angleFromPerpendicular(t){return A.createAtan2(this.dotProduct(t),this.crossProductMagnitude(t))}radiansFromPerpendicular(t){return Math.atan2(this.dotProduct(t),this.crossProductMagnitude(t))}angleToXY(t){return A.createAtan2(this.crossProductXY(t),this.dotProductXY(t))}signedRadiansTo(t,e){const n=this.crossProduct(t),i=Math.atan2(n.magnitude(),this.dotProduct(t));return e.dotProduct(n)<0?-i:i}signedAngleTo(t,e){return A.createRadians(this.signedRadiansTo(t,e))}planarRadiansTo(t,e){const n=e.dotProduct(e);if(n===0)return 0;const i=1/n,s=this.plusScaled(e,-this.dotProduct(e)*i),r=t.plusScaled(e,-t.dotProduct(e)*i);return s.signedRadiansTo(r,e)}planarAngleTo(t,e){return A.createRadians(this.planarRadiansTo(t,e))}smallerUnorientedRadiansTo(t){const e=this.dotProduct(t),n=this.crossProductMagnitude(t);return Math.atan2(Math.abs(n),Math.abs(e))}smallerUnorientedAngleTo(t){return A.createRadians(this.smallerUnorientedRadiansTo(t))}isParallelTo(t,e=!1,n=!1,i){const s=i?.radianSquaredTol??f.smallAngleRadiansSquared,r=i?.distanceSquaredTol??f.smallMetricDistanceSquared,o=this.magnitudeSquared(),a=t.magnitudeSquared();return o<r||a<r?n:this.dotProduct(t)<0&&!e?!1:this.crossProductMagnitudeSquared(t)<=s*o*a}isPerpendicularTo(t,e=!1,n){const i=n?.radianSquaredTol??f.smallAngleRadiansSquared,s=n?.distanceSquaredTol??f.smallMetricDistanceSquared,r=this.magnitudeSquared(),o=t.magnitudeSquared();if(r<s||o<s)return e;const a=this.dotProduct(t);return a*a<=i*r*o}}var mt;(function(u){u[u.XYZ=0]="XYZ",u[u.YZX=1]="YZX",u[u.ZXY=2]="ZXY",u[u.XZY=4]="XZY",u[u.YXZ=5]="YXZ",u[u.ZYX=6]="ZYX"})(mt||(mt={}));var ze;(function(u){u[u.X=0]="X",u[u.Y=1]="Y",u[u.Z=2]="Z"})(ze||(ze={}));var yn;(function(u){u[u.Top=1]="Top",u[u.Bottom=2]="Bottom",u[u.Left=3]="Left",u[u.Right=4]="Right",u[u.Front=5]="Front",u[u.Back=6]="Back",u[u.Iso=7]="Iso",u[u.RightIso=8]="RightIso"})(yn||(yn={}));var qi;(function(u){u[u.Unit=0]="Unit",u[u.LongestRangeDirection=1]="LongestRangeDirection",u[u.NonUniformRangeContainment=2]="NonUniformRangeContainment"})(qi||(qi={}));var yt;(function(u){u[u.Unknown=0]="Unknown",u[u.OnPolygonVertex=1]="OnPolygonVertex",u[u.OnPolygonEdgeInterior=2]="OnPolygonEdgeInterior",u[u.InsidePolygon=3]="InsidePolygon",u[u.InsidePolygonProjectsToVertex=4]="InsidePolygonProjectsToVertex",u[u.InsidePolygonProjectsToEdgeInterior=5]="InsidePolygonProjectsToEdgeInterior",u[u.OutsidePolygon=6]="OutsidePolygon",u[u.OutsidePolygonProjectsToVertex=7]="OutsidePolygonProjectsToVertex",u[u.OutsidePolygonProjectsToEdgeInterior=8]="OutsidePolygonProjectsToEdgeInterior"})(yt||(yt={}));let f=class ${static smallMetricDistance=1e-6;static smallMetricDistanceSquared=1e-12;static smallAngleRadians=1e-12;static smallAngleRadiansSquared=1e-24;static smallAngleDegrees=57e-12;static smallAngleSeconds=2e-7;static smallFraction=1e-10;static smallNewtonStep=1e-11;static smallFloatingPoint=1e-15;static fullCircleRadiansMinusSmallAngle=2*Math.PI-$.smallAngleRadians;static largeFractionResult=1e10;static largeCoordinateResult=1e13;static hugeCoordinate=1e12;static isLargeCoordinateResult(t){return t>=this.largeCoordinateResult||t<=-this.largeCoordinateResult}static isHugeCoordinate(t){return $.isLargeCoordinateResult(t)}static isOdd(t){return(t&1)===1}static correctSmallMetricDistance(t,e=0){return t===void 0||Math.abs(t)<=$.smallMetricDistance?e:t}static correctSmallFraction(t,e=0){return t===void 0||Math.abs(t)<=$.smallFraction?e:t}static inverseMetricDistance(t){return Math.abs(t)<=$.smallMetricDistance?void 0:1/t}static inverseMetricDistanceSquared(t){return Math.abs(t)<=$.smallMetricDistanceSquared?void 0:1/t}static isSameCoordinate(t,e,n=$.smallMetricDistance){let i=t-e;return i<0&&(i=-i),i<=n}static isSameFraction(t,e,n=$.smallFraction){return this.isSameCoordinate(t,e,n)}static isSameCoordinateWithToleranceFactor(t,e,n){return $.isSameCoordinate(t,e,n*$.smallMetricDistance)}static isSameCoordinateXY(t,e,n,i,s=$.smallMetricDistance){let r=n-t;return r<0&&(r=-r),r>s?!1:(r=i-e,r<0&&(r=-r),r<=s)}static isSameCoordinateSquared(t,e,n=$.smallMetricDistance){return Math.abs(Math.sqrt(t)-Math.sqrt(e))<=n}static isSamePoint3d(t,e,n=$.smallMetricDistance){return t.distance(e)<=n}static isSameXYZ(t,e,n=$.smallMetricDistance){return t.distance(e)<=n}static isSamePoint3dXY(t,e,n=$.smallMetricDistance){return t.distanceXY(e)<=n}static isSameVector3d(t,e,n=$.smallMetricDistance){return t.distance(e)<=n}static isSamePoint2d(t,e,n=$.smallMetricDistance){return t.distance(e)<=n}static isSameVector2d(t,e,n=$.smallMetricDistance){return t.distance(e)<=n}static lexicalXYLessThan(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}static lexicalYXLessThan(t,e){return t.y<e.y?-1:t.y>e.y?1:t.x<e.x?-1:t.x>e.x?1:0}static lexicalXYZLessThan(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:t.z<e.z?-1:t.z>e.z?1:0}static compareXYZ(t=$.smallMetricDistance){return(e,n)=>{if(As.almostEqual(e,n,t))return 0;if(!$.isSameCoordinate(e.x,n.x,t)){if(e.x<n.x)return-1;if(e.x>n.x)return 1}if(!$.isSameCoordinate(e.y,n.y,t)){if(e.y<n.y)return-1;if(e.y>n.y)return 1}if(!$.isSameCoordinate(e.z,n.z,t)){if(e.z<n.z)return-1;if(e.z>n.z)return 1}return 0}}static compareXY(t=$.smallMetricDistance){return(e,n)=>{if(ws.almostEqual(e,n,t))return 0;if(!$.isSameCoordinate(e.x,n.x,t)){if(e.x<n.x)return-1;if(e.x>n.x)return 1}if(!$.isSameCoordinate(e.y,n.y,t)){if(e.y<n.y)return-1;if(e.y>n.y)return 1}return 0}}static isSmallRelative(t){return Math.abs(t)<=$.smallFraction}static isSmallAngleRadians(t){return Math.abs(t)<=$.smallAngleRadians}static isSmallAngleRadiansSquared(t){return Math.abs(t)<=$.smallAngleRadiansSquared}static isAlmostEqualOptional(t,e,n){if(t!==void 0&&e!==void 0){if(Math.abs(t-e)>n)return!1}else if(t!==void 0||e!==void 0)return!1;return!0}static isAlmostEqualNumber(t,e,n=$.smallAngleRadians){const i=1+Math.abs(t)+Math.abs(e);return Math.abs(t-e)<=n*i}static isAlmostEqualEitherNumber(t,e,n,i=$.smallAngleRadians){return this.isAlmostEqualNumber(t,e,i)||this.isAlmostEqualNumber(t,n,i)}static isAlmostEqualAnyNumber(t,e,n=$.smallAngleRadians){const i=Array.isArray(e)?s=>e[s]:e.iter;for(let s=0;s<e.length;s++)if(this.isAlmostEqualNumber(t,i(s),n))return!0;return!1}static isAlmostEqualXAndY(t,e,n=$.smallAngleRadians){const i=n*(1+Math.abs(t.x)+Math.abs(e.x)+Math.abs(t.y)+Math.abs(e.y));return Math.abs(t.x-e.x)<=i&&Math.abs(t.y-e.y)<=i}static isDistanceWithinTol(t,e=$.smallMetricDistance){return Math.abs(t)<=e}static isSmallMetricDistance(t){return Math.abs(t)<=$.smallMetricDistance}static isSmallMetricDistanceSquared(t){return Math.abs(t)<=$.smallMetricDistanceSquared}static cyclic3dAxis(t){if(t>=0)return t<3?t:t<6?t-3:t%3;const e=t+3;return e>=0?e:2-(-t-1)%3}static axisIndexToRightHandedAxisOrder(t){return t===0?mt.XYZ:t===1?mt.YZX:t===2?mt.ZXY:$.axisIndexToRightHandedAxisOrder($.cyclic3dAxis(t))}static maxXYZ(t,e,n){let i=t;return e>i&&(i=e),n>i&&(i=n),i}static minXYZ(t,e,n){let i=t;return e<i&&(i=e),n<i&&(i=n),i}static maxXY(t,e){let n=t;return e>n&&(n=e),n}static minXY(t,e){let n=t;return e<n&&(n=e),n}static maxAbsXYZ(t,e,n){return $.maxXYZ(Math.abs(t),Math.abs(e),Math.abs(n))}static maxAbsXY(t,e){return $.maxXY(Math.abs(t),Math.abs(e))}static maxAbsDiff(t,e,n){return Math.max(Math.abs(t-e),Math.abs(t-n))}static split3WaySign(t,e,n,i){return t<0?e:t>0?i:n}static split3Way01(t,e=$.smallMetricDistance){return t>e?1:t<-e?-1:0}static square(t){return t*t}static hypotenuseXY(t,e){return Math.sqrt(t*t+e*e)}static hypotenuseSquaredXY(t,e){return t*t+e*e}static hypotenuseXYZ(t,e,n){return Math.sqrt(t*t+e*e+n*n)}static hypotenuseSquaredXYZ(t,e,n){return t*t+e*e+n*n}static hypotenuseXYZW(t,e,n,i){return Math.sqrt(t*t+e*e+n*n+i*i)}static hypotenuseSquaredXYZW(t,e,n,i){return t*t+e*e+n*n+i*i}static distanceXYXY(t,e,n,i){return $.hypotenuseXY(n-t,i-e)}static distanceSquaredXYXY(t,e,n,i){return $.hypotenuseSquaredXY(n-t,i-e)}static distanceXYZXYZ(t,e,n,i,s,r){return $.hypotenuseXYZ(i-t,s-e,r-n)}static tripleProduct(t,e,n,i,s,r,o,a,c){return t*(s*c-r*a)+e*(r*o-i*c)+n*(i*a-s*o)}static determinant4x4(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p,x){return t*this.tripleProduct(r,o,a,l,d,h,m,p,x)-s*this.tripleProduct(e,n,i,l,d,h,m,p,x)+c*this.tripleProduct(e,n,i,r,o,a,m,p,x)-g*this.tripleProduct(e,n,i,r,o,a,l,d,h)}static tripleProductXYW(t,e,n,i,s,r){return $.tripleProduct(t.x,n.x,s.x,t.y,n.y,s.y,e,i,r)}static tripleProductPoint4dXYW(t,e,n){return $.tripleProduct(t.x,e.x,n.x,t.y,e.y,n.y,t.w,e.w,n.w)}static crossProductXYXY(t,e,n,i){return t*i-e*n}static crossProductXYZXYZ(t,e,n,i,s,r,o){return P.create(e*r-n*s,n*i-t*r,t*s-e*i,o)}static crossProductToPointsXY(t,e,n){return this.crossProductXYXY(e.x-t.x,e.y-t.y,n.x-t.x,n.y-t.y)}static crossProductMagnitude(t,e,n,i,s,r){return $.hypotenuseXYZ(e*r-n*s,n*i-t*r,t*s-e*i)}static dotProductXYXY(t,e,n,i){return t*n+e*i}static dotProductXYZXYZ(t,e,n,i,s,r){return t*i+e*s+n*r}static fractionOfProjectionToVectorXYXY(t,e,n,i,s=0){const r=n*n+i*i;return r<$.smallMetricDistanceSquared?s:(t*n+e*i)/r}static meanCurvatureOfRadii(t,e){return .5*(this.safeDivideFraction(1,t,0)+this.safeDivideFraction(1,e,0))}static curvatureMagnitude(t,e,n,i,s,r){let o=e*r-n*s,a=o*o;o=n*i-t*r,a+=o*o,o=t*s-e*i,a+=o*o;const c=Math.sqrt(a),l=Math.sqrt(t*t+e*e+n*n),d=l*l*l;return d>$.smallAngleRadians*c?c/d:0}static clampToStartEnd(t,e,n){return e>n?$.clampToStartEnd(t,n,e):t<e?e:n<t?n:t}static clamp(t,e,n){return Math.max(e,Math.min(n,t))}static resolveNumber(t,e=0){return t!==void 0?t:e}static resolveValue(t,e){return t!==void 0?t:e}static resolveToUndefined(t,e){return t===e?void 0:t}static interpolate(t,e,n){return e<=.5?t+e*(n-t):n-(1-e)*(n-t)}static interpolateByte(t,e,n,i){return t=t>>>i&255,n=n>>>i&255,(Math.floor(t+e*(n-t))&255)<<i}static interpolateColor(t,e,n){e=$.clamp(e,0,1);const i=this.interpolateByte(t,e,n,0),s=this.interpolateByte(t,e,n,8),r=this.interpolateByte(t,e,n,16),o=this.interpolateByte(t,e,n,24);return i|s|r|o}static axisOrderToAxis(t,e){const n=t<=mt.ZXY?t+e:t-mt.XZY-e;return $.cyclic3dAxis(n)}static modulo(t,e){if(e<=0)return e===0?t:-$.modulo(-t,-e);if(t>=0){if(t<e)return t;if(t<2*e)return t-e}else if(t+=e,t>0)return t;const n=Math.floor(t/e);return t-n*e}static defined01(t){return t===void 0?0:1}static conditionalDivideFraction(t,e){if(e!==0&&Math.abs(e)*$.largeFractionResult>=Math.abs(t))return t/e}static safeDivideFraction(t,e,n){const i=$.conditionalDivideFraction(t,e);return i!==void 0?i:n}static conditionalDivideCoordinate(t,e,n=$.largeCoordinateResult){if(e!==0&&Math.abs(e*n)>=Math.abs(t))return t/e}static solveTrigForm(t,e,n){const i=e*e+n*n,s=t*t;let r;if(i>0){const o=1/i,c=1-s*o;if(c<-$.smallMetricDistanceSquared)return r;const l=-t*o,d=l*e,h=l*n;if(c<=$.smallMetricDistanceSquared)r=[Q.create(d,h)];else{const g=Math.sqrt(c*o);r=[Q.create(d-g*n,h+g*e),Q.create(d+g*n,h-g*e)]}}return r}static inverseInterpolate(t,e,n,i,s=0,r){const o=$.conditionalDivideFraction(s-e,i-e);return o!==void 0?$.interpolate(t,o,n):r}static inverseInterpolate01(t,e,n=0){return $.conditionalDivideFraction(n-t,e-t)}static isNumber(t){return Number.isFinite(t)}static isNumberArray(t,e=0){if(Array.isArray(t)&&t.length>=e){let n;for(n of t)if(!Number.isFinite(n))return!1;return!0}return!1}static isArrayOfNumberArray(t,e,n=0){if(Array.isArray(t)&&t.length>=e){let i;for(i of t)if(!$.isNumberArray(i,n))return!1;return!0}return!1}static stepCount(t,e,n=1,i=101){if(t<=0||(e=Math.abs(e),t>=e))return n;const s=Math.floor((e+.999999*t)/t);return s<n?n:s>i?i:s}static isIn01(t,e=!0){return e?t>=0&&t<=1:!0}static isIn01WithTolerance(t,e){return e=Math.abs(e),t+e>=0&&t-e<=1}static restrictToInterval(t,e,n){return e<=n?t<e?e:t>n?n:t:t<n?n:t>e?e:t}static equalStringNoCase(t,e){return t.toUpperCase()===e.toUpperCase()}static exactEqualNumberArrays(t,e){if(Array.isArray(t)&&t.length===0&&(t=void 0),Array.isArray(e)&&e.length===0&&(e=void 0),t===void 0&&e===void 0)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}return!1}static almostEqualArrays(t,e,n){if(Array.isArray(t)&&t.length===0&&(t=void 0),Array.isArray(e)&&e.length===0&&(e=void 0),t===void 0&&e===void 0)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!n(t[i],e[i]))return!1;return!0}return!1}static almostEqualNumberArrays(t,e,n){if(Array.isArray(t)&&t.length===0&&(t=void 0),Array.isArray(e)&&e.length===0&&(e=void 0),t===void 0&&e===void 0)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!n(t[i],e[i]))return!1;return!0}return!1}static areEqualAllowUndefined(t,e,n=!0){return t===void 0&&e===void 0?n:t!==void 0&&e!==void 0?t===e:!1}static cloneMembers(t){if(t===void 0)return;const e=[];for(const n of t)e.push(n.clone());return e}static cloneArray(t){if(t===void 0)return;const e=[];for(const n of t)e.push(n.clone());return e}};class A{static piOver12Radians=.26179938779914946;static piOver4Radians=.7853981633974483;static piOver2Radians=1.5707963267948966;static piRadians=3.141592653589793;static pi3Over2Radians=4.71238898038469;static pi2Radians=6.283185307179586;static degreesPerRadian=45/A.piOver4Radians;static radiansPerDegree=A.piOver4Radians/45;_radians;_degrees;constructor(t=0,e){this._radians=t,this._degrees=e}clone(){return new A(this._radians,this._degrees)}freeze(){return Object.freeze(this)}static createDegrees(t){return new A(A.degreesToRadians(t),t)}static createRadians(t){return new A(t)}static createSmallAngle(){return new A(f.smallAngleRadians)}static createInterpolate(t,e,n){return new A(f.interpolate(t.radians,e,n.radians))}cloneScaled(t){return new A(this.radians*t)}setRadians(t){this._radians=t,this._degrees=void 0}setDegrees(t){this._radians=A.degreesToRadians(t),this._degrees=t}static create360(){return new A(Math.PI*2,360)}static createAtan2(t,e){return new A(Math.atan2(t,e))}setFrom(t){this._radians=t._radians,this._degrees=t._degrees}setFromJSON(t,e){this._radians=e||0,t&&(typeof t=="number"?this.setDegrees(t):typeof t.degrees=="number"?this.setDegrees(t.degrees):typeof t._degrees=="number"?this.setDegrees(t._degrees):typeof t.radians=="number"?this.setRadians(t.radians):typeof t._radians=="number"&&this.setRadians(t._radians))}static fromJSON(t,e){const n=new A;return n.setFromJSON(t,e),n}toJSON(){return this.degrees}toJSONRadians(){return{radians:this.radians}}get radians(){return this._radians}get degrees(){return this._degrees!==void 0?this._degrees:A.radiansToDegrees(this._radians)}static degreesToRadians(t){return t*Math.PI/180}static radiansToDegrees(t){if(t<0)return-A.radiansToDegrees(-t);const e=Math.PI,n=180/e;return t<=.25*e?n*t:t<.75*e?90+180*((t-.5*e)/e):t<=1.25*e?180+180*((t-e)/e):t<=1.75*e?270+180*((t-1.5*e)/e):360+180*((t-2*e)/e)}cos(){return Math.cos(this._radians)}sin(){return Math.sin(this._radians)}tan(){return Math.tan(this._radians)}static isFullCircleRadians(t){return Math.abs(t)>=f.fullCircleRadiansMinusSmallAngle}static isHalfCircleRadians(t){return Math.abs(Math.abs(t)-Math.PI)<=f.smallAngleRadians}get isFullCircle(){return A.isFullCircleRadians(this._radians)}get isHalfCircle(){return A.isHalfCircleRadians(this._radians)}static adjustDegrees0To360(t){if(t>=0){if(t<360)return t;const n=Math.floor(t/360);return t-n*360}else if(t<0)return 360-A.adjustDegrees0To360(-t);return 0}static adjustDegreesSigned180(t){if(Math.abs(t)<=180)return t;if(t>=0){const n=1+Math.floor((t-180)/360);return t-n*360}else if(t<0)return-A.adjustDegreesSigned180(-t);return 0}static adjustRadians0To2Pi(t){if(t>=0){const e=Math.PI*2;if(t<e)return t;const n=Math.floor(t/e);return t-n*e}else if(t<0)return Math.PI*2-A.adjustRadians0To2Pi(-t);return 0}static adjustRadians0ToLessThan2Pi(t){return A.isAlmostEqualRadiansAllowPeriodShift(t,0)&&(t=0),this.adjustRadians0To2Pi(t)}static adjustRadiansMinusPiPlusPi(t){if(Math.abs(t)<=Math.PI)return t;if(t>=0){const e=Math.PI*2,n=1+Math.floor((t-Math.PI)/e);return t-n*e}else if(t<0)return-A.adjustRadiansMinusPiPlusPi(-t);return 0}static zero(){return new A(0)}get isExactZero(){return this.radians===0}get isAlmostZero(){return Math.abs(this.radians)<f.smallAngleRadians}get isAlmostNorthOrSouthPole(){return A.isHalfCircleRadians(this.radians*2)}static createDegreesAdjustPositive(t){return A.createDegrees(A.adjustDegrees0To360(t))}static createDegreesAdjustSigned180(t){return A.createDegrees(A.adjustDegreesSigned180(t))}static isAlmostEqualRadiansAllowPeriodShift(t,e,n=f.smallAngleRadians){const i=Math.abs(t-e);if(i<=n)return!0;const s=Math.PI*2;if(Math.abs(i-s)<=n)return!0;const r=Math.round(i/s),o=i-r*s;return Math.abs(o)<=n}isMagnitudeLessThanOrEqual(t){return Math.abs(this.radians)<=Math.abs(t.radians)}isAlmostEqualAllowPeriodShift(t,e=f.smallAngleRadians){return A.isAlmostEqualRadiansAllowPeriodShift(this._radians,t._radians,e)}static isAlmostEqualRadiansNoPeriodShift(t,e,n=f.smallAngleRadians){return Math.abs(t-e)<n}isAlmostEqualNoPeriodShift(t,e=f.smallAngleRadians){return A.isAlmostEqualRadiansNoPeriodShift(this._radians,t._radians,e)}isAlmostEqual(t,e=f.smallAngleRadians){return this.isAlmostEqualNoPeriodShift(t,e)}static isPerpendicularDotSet(t,e,n){return t>f.smallMetricDistanceSquared&&e>f.smallMetricDistanceSquared&&n*n<=f.smallAngleRadiansSquared*t*e}static trigValuesToHalfAngleTrigValues(t,e){const n=f.hypotenuseXY(t,e);if(n<f.smallMetricDistance)return{c:1,s:0,radians:0};{let i,s=0;const r=t/n,o=e/n;return r>=0?(i=Math.sqrt(.5*(1+r)),s=o/(2*i)):(o>0?s=Math.sqrt(.5*(1-r)):s=-Math.sqrt(.5*(1-r)),i=o/(2*s)),{c:i,s,radians:Math.atan2(s,i)}}}static cleanupTrigValue(t,e=f.smallFloatingPoint){const n=Math.abs(t);if(n<=e)return 0;let i=Math.abs(n-.5);return i<=e?t<0?-.5:.5:(i=Math.abs(n-1),i<=e?t<0?-1:1:t)}static dotProductsToHalfAngleTrigValues(t,e,n,i=!0){const s=t-e,r=2*n;return i&&Math.abs(r)<f.smallAngleRadians*(Math.abs(t)+Math.abs(e))?{c:1,s:0,radians:0}:A.trigValuesToHalfAngleTrigValues(s,r)}static radiansBetweenVectorsXYZ(t,e,n,i,s,r){const o=t*i+e*s+n*r;return Math.atan2(f.crossProductMagnitude(t,e,n,i,s,r),o)}static orientedRadiansBetweenVectorsXYZ(t,e,n,i,s,r,o,a,c,l=!1){const d=t*i+e*s+n*r,h=e*r-n*s,g=n*i-t*r,m=t*s-e*i,p=o*h+a*g+c*m,x=f.hypotenuseXYZ(h,g,m);return p<0?l?Math.PI+Math.atan2(x,-d):-Math.atan2(x,d):Math.atan2(x,d)}addMultipleOf2PiInPlace(t){this._degrees!==void 0?(this._degrees+=t*360,this._radians=A.degreesToRadians(this._degrees)):this._radians+=t*A.pi2Radians}}class at{_radians0;_radians1;get startDegrees(){return A.radiansToDegrees(this._radians0)}get endDegrees(){return A.radiansToDegrees(this._radians1)}get sweepDegrees(){return A.radiansToDegrees(this.sweepRadians)}get startRadians(){return this._radians0}get endRadians(){return this._radians1}get sweepRadians(){return this._radians1-this._radians0}get isEmpty(){return A.isAlmostEqualRadiansNoPeriodShift(0,this.sweepRadians)}get startAngle(){return A.createRadians(this._radians0)}get endAngle(){return A.createRadians(this._radians1)}static create(t){return t instanceof at?t.clone():t instanceof A?new at(0,t.radians):at.create360()}constructor(t=0,e=0){this._radians0=t,this._radians1=e}setStartEndRadians(t=0,e=2*Math.PI){const n=e-t;A.isFullCircleRadians(n)&&(e=t+(n>0?2:-2)*Math.PI),this._radians0=t,this._radians1=e}setStartEndDegrees(t=0,e=360){this.setStartEndRadians(A.degreesToRadians(t),A.degreesToRadians(e))}static createStartEndRadians(t=0,e=2*Math.PI,n){return n=n||new at,n.setStartEndRadians(t,e),n}clonePlusRadians(t){return new at(this._radians0+t,this._radians1+t)}cloneMinusRadians(t){return this.clonePlusRadians(-t)}static createStartEndDegrees(t=0,e=360,n){return at.createStartEndRadians(A.degreesToRadians(t),A.degreesToRadians(e),n)}static createStartEnd(t,e,n){return n=n||new at,n.setStartEndRadians(t.radians,e.radians),n}static createStartSweepRadians(t=0,e=Math.PI,n){return n=n||new at,n.setStartEndRadians(t,t+e),n}static createStartSweepDegrees(t=0,e=360,n){return at.createStartEndRadians(A.degreesToRadians(t),A.degreesToRadians(t+e),n)}static createStartSweep(t,e,n){return at.createStartSweepRadians(t.radians,e.radians,n)}interpolate(t,e){return new at(f.interpolate(this._radians0,t,e._radians0),f.interpolate(this._radians1,t,e._radians1))}setFrom(t){this._radians0=t._radians0,this._radians1=t._radians1}static create360(t,e){t=t||0;const n=t+2*Math.PI;return e?(e.setStartEndRadians(t,n),e):new at(t,n)}static createFullLatitude(){return at.createStartEndRadians(-.5*Math.PI,.5*Math.PI)}reverseInPlace(){const t=this._radians0;this._radians0=this._radians1,this._radians1=t}cloneComplement(t=!1,e){const n=this.sweepRadians>=0?2:-2;return t?at.createStartEndRadians(this.startRadians,this.endRadians-n*Math.PI,e):at.createStartEndRadians(this.endRadians,this.startRadians+n*Math.PI,e)}capLatitudeInPlace(){const t=.5*Math.PI;this._radians0=f.clampToStartEnd(this._radians0,-t,t),this._radians1=f.clampToStartEnd(this._radians1,-t,t)}clampToFullCircle(t){t=t??new at;const e=f.clampToStartEnd(this.sweepRadians,-6.283185307179586,A.pi2Radians);return t.setStartEndRadians(this._radians0,this._radians0+e),t}get isCCW(){return this._radians1>=this._radians0}get isFullCircle(){return A.isFullCircleRadians(this.sweepRadians)}get isFullLatitudeSweep(){const t=Math.PI*.5;return A.isAlmostEqualRadiansNoPeriodShift(this._radians0,-t)&&A.isAlmostEqualRadiansNoPeriodShift(this._radians1,t)}clone(){return new at(this._radians0,this._radians1)}fractionToRadians(t){return t<.5?this._radians0+t*this.sweepRadians:this._radians1+(t-1)*this.sweepRadians}fractionToAngle(t){return A.createRadians(this.fractionToRadians(t))}fractionPeriod(){return this.isEmpty?1:A.pi2Radians/Math.abs(this.sweepRadians)}angleToUnboundedFraction(t){return this.isEmpty?1:(t.radians-this._radians0)/this.sweepRadians}static fractionToSignedPeriodicFractionStartEnd(t,e,n,i){const s=n-e;if(A.isAlmostEqualRadiansNoPeriodShift(0,s)||f.isIn01(t))return t;const r=A.pi2Radians/Math.abs(s);if(t=t%r,t+r<1&&(t+=r),f.isIn01(t))return t;if(i===!0)return t<0?t:t-r;if(i===!1)return t>1?t:t+r;const o=t<0?-t:t-1,a=t<0?t+r:t-r,c=a<0?-a:a-1;return o<c?t:a}fractionToSignedPeriodicFraction(t,e){return at.fractionToSignedPeriodicFractionStartEnd(t,this._radians0,this._radians1,e)}static radiansToPositivePeriodicFractionStartEnd(t,e,n,i=0){const s=f.largeCoordinateResult;let r=this.radiansToSignedPeriodicFractionStartEnd(t,e,n,s);if(r===s)return i;if(r<0){const o=A.pi2Radians/Math.abs(n-e);r+=o}return r}radiansToPositivePeriodicFraction(t,e=0){return at.radiansToPositivePeriodicFractionStartEnd(t,this._radians0,this._radians1,e)}angleToPositivePeriodicFraction(t,e=0){return this.radiansToPositivePeriodicFraction(t.radians,e)}radiansArrayToPositivePeriodicFractions(t){const e=t.length;for(let n=0;n<e;n++)t.reassign(n,this.radiansToPositivePeriodicFraction(t.atUncheckedIndex(n)))}static radiansToSignedPeriodicFractionStartEnd(t,e,n,i=0){const s=n-e;if(A.isAlmostEqualRadiansNoPeriodShift(0,s))return i;if(A.isAlmostEqualRadiansAllowPeriodShift(e,n)){if(A.isAlmostEqualRadiansNoPeriodShift(t,e))return 0;if(A.isAlmostEqualRadiansNoPeriodShift(t,n))return 1}else{if(A.isAlmostEqualRadiansAllowPeriodShift(t,e))return 0;if(A.isAlmostEqualRadiansAllowPeriodShift(t,n))return 1}const r=(t-e)/s;return this.fractionToSignedPeriodicFractionStartEnd(r,e,n,r<0)}radiansToSignedPeriodicFraction(t,e=0){return at.radiansToSignedPeriodicFractionStartEnd(t,this._radians0,this._radians1,e)}angleToSignedPeriodicFraction(t,e=0){return this.radiansToSignedPeriodicFraction(t.radians,e)}static radiansToSignedFractionStartEnd(t,e,n,i=!1,s=0){const r=f.largeCoordinateResult;let o=this.radiansToSignedPeriodicFractionStartEnd(t,e,n,r);if(o===r)return s;if(i&&o>1||!i&&o<0){let a=A.pi2Radians/Math.abs(n-e);i&&(a=-a),o+=a}return o}radiansToSignedFraction(t,e=!1,n=0){return at.radiansToSignedFractionStartEnd(t,this._radians0,this._radians1,e,n)}angleToSignedFraction(t,e=!1,n=0){return this.radiansToSignedFraction(t.radians,e,n)}static isRadiansInStartEnd(t,e,n,i=!0){const s=t-e,r=t-n;return s*r<=0?!0:e===n?i?A.isAlmostEqualRadiansAllowPeriodShift(t,e):A.isAlmostEqualRadiansNoPeriodShift(t,e):i?this.radiansToPositivePeriodicFractionStartEnd(t,e,n,1e3)<=1:!1}isRadiansInSweep(t,e=!0){return at.isRadiansInStartEnd(t,this.startRadians,this.endRadians,e)}isAngleInSweep(t){return this.isRadiansInSweep(t.radians)}setFromJSON(t){t?t instanceof at?this.setFrom(t):f.isNumberArray(t.degrees,2)?this.setStartEndDegrees(t.degrees[0],t.degrees[1]):f.isNumberArray(t.radians,2)?this.setStartEndRadians(t.radians[0],t.radians[1]):f.isNumberArray(t,2)?this.setStartEndDegrees(t[0],t[1]):this.setStartEndRadians():this.setStartEndRadians()}static fromJSON(t){const e=at.create360();return e.setFromJSON(t),e}toJSON(){return[this.startDegrees,this.endDegrees]}isAlmostEqualAllowPeriodShift(t,e=f.smallAngleRadians){return this.isCCW===t.isCCW&&A.isAlmostEqualRadiansAllowPeriodShift(this._radians0,t._radians0,e)&&A.isAlmostEqualRadiansAllowPeriodShift(this.sweepRadians,t.sweepRadians,e)}isAlmostEqualNoPeriodShift(t,e=f.smallAngleRadians){return A.isAlmostEqualRadiansNoPeriodShift(this._radians0,t._radians0,e)&&A.isAlmostEqualRadiansNoPeriodShift(this.sweepRadians,t.sweepRadians,e)}isAlmostEqual(t){return this.isAlmostEqualNoPeriodShift(t)}}class Cs{isPointInPlane(t,e=f.smallMetricDistance){return Math.abs(this.altitude(t))<=e}classifyAltitude(t,e=f.smallMetricDistance){return f.split3Way01(this.altitude(t),e)}classifyAltitudeXYZ(t,e,n,i=f.smallMetricDistance){return f.split3Way01(this.altitudeXYZ(t,e,n),i)}getUnitNormal(t){return P.createNormalized(this.normalX(),this.normalY(),this.normalZ(),t)}getAnyPointOnPlane(t){return this.projectXYZToPlane(0,0,0,t)}projectXYZToPlane(t,e,n,i){const s=y.create(t,e,n,i);return this.projectPointToPlane(s,s)}}class cc{_collection;_curIndex=-1;constructor(t){this._collection=t}next(){return++this._curIndex>=this._collection.length?{done:!0}:{value:this._collection.getPoint3dAtUncheckedPointIndex(this._curIndex),done:!1}}[Symbol.iterator](){return this}}class le{vectorUncheckedIndexIndex(t,e,n){return P.createStartEndXYZXYZ(this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(t),this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(e),n)}vectorXYAndZUncheckedIndex(t,e,n){return P.createStartEndXYZXYZ(t.x,t.y,t.z,this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(e),n)}vectorIndexXYAndZ(t,e,n){const i=this.vectorXYAndZIndex(e,t,n);return i?.negate(i)}dotProductIndexIndexIndex(t,e,n){if(t<0||t>=this.length||e<0||e>=this.length||n<0||n>=this.length)return;const i=this.getXAtUncheckedPointIndex(t),s=this.getYAtUncheckedPointIndex(t),r=this.getZAtUncheckedPointIndex(t);return(this.getXAtUncheckedPointIndex(e)-i)*(this.getXAtUncheckedPointIndex(n)-i)+(this.getYAtUncheckedPointIndex(e)-s)*(this.getYAtUncheckedPointIndex(n)-s)+(this.getZAtUncheckedPointIndex(e)-r)*(this.getZAtUncheckedPointIndex(n)-r)}dotProductIndexIndexXYAndZ(t,e,n){if(!(t<0||t>=this.length||e<0||e>=this.length))return this.dotProductUncheckedIndexIndexXYAndZ(t,e,n)}dotProductUncheckedIndexIndexXYAndZ(t,e,n){const i=this.getXAtUncheckedPointIndex(t),s=this.getYAtUncheckedPointIndex(t),r=this.getZAtUncheckedPointIndex(t);return(this.getXAtUncheckedPointIndex(e)-i)*(n.x-i)+(this.getYAtUncheckedPointIndex(e)-s)*(n.y-s)+(this.getZAtUncheckedPointIndex(e)-r)*(n.z-r)}crossProductIndexIndexXYAndZ(t,e,n,i){if(!(t<0||t>=this.length||e<0||e>=this.length))return this.crossProductUncheckedIndexIndexXYAndZ(t,e,n,i)}crossProductUncheckedIndexIndexXYAndZ(t,e,n,i){const s=this.getXAtUncheckedPointIndex(t),r=this.getYAtUncheckedPointIndex(t),o=this.getZAtUncheckedPointIndex(t);return P.createCrossProduct(this.getXAtUncheckedPointIndex(e)-s,this.getYAtUncheckedPointIndex(e)-r,this.getZAtUncheckedPointIndex(e)-o,n.x-s,n.y-r,n.z-o,i)}crossProductUncheckedIndexIndexIndex(t,e,n,i){const s=this.getXAtUncheckedPointIndex(t),r=this.getYAtUncheckedPointIndex(t),o=this.getZAtUncheckedPointIndex(t);return P.createCrossProduct(this.getXAtUncheckedPointIndex(e)-s,this.getYAtUncheckedPointIndex(e)-r,this.getZAtUncheckedPointIndex(e)-o,this.getXAtUncheckedPointIndex(n)-s,this.getYAtUncheckedPointIndex(n)-r,this.getZAtUncheckedPointIndex(n)-o,i)}distanceSquaredUncheckedIndexIndex(t,e){return f.hypotenuseSquaredXYZ(this.getXAtUncheckedPointIndex(e)-this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(e)-this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(e)-this.getZAtUncheckedPointIndex(t))}distanceSquaredIndexXYAndZ(t,e){if(!(t<0||t>=this.length))return this.distanceSquaredUncheckedIndexXYAndZ(t,e)}distanceSquaredUncheckedIndexXYAndZ(t,e){return f.hypotenuseSquaredXYZ(e.x-this.getXAtUncheckedPointIndex(t),e.y-this.getYAtUncheckedPointIndex(t),e.z-this.getZAtUncheckedPointIndex(t))}distanceUncheckedIndexIndex(t,e){return f.hypotenuseXYZ(this.getXAtUncheckedPointIndex(e)-this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(e)-this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(e)-this.getZAtUncheckedPointIndex(t))}isIndexValid(t){return t>=0&&t<this.length}cyclicIndex(t){return f.modulo(t,this.length)}getRange(t,e){let n=e;n?n.setNull():n=J.createNull();const i=this.length,s=y.create();for(let r=0;r<i;r++)this.getPoint3dAtUncheckedPointIndex(r,s),n.extendPoint(s,t);return n}findOrderedDuplicates(t=f.smallMetricDistance,e=!1){const n=[];if(this.length>1){for(let i=0;i<this.length-1;){let s=i+1;for(;this.almostEqualIndexIndex(i,s,t);++s)n.push(s);i=s}if(e&&n.length>0&&n.length<this.length-1){let i=0;for(;i<=n.length-1&&n[n.length-1-i]===this.length-1-i;++i);for(let s=0;s<i;++s)n[n.length-1-s]-=1}}return n}linearCombination(t,e){const n=Math.min(this.length,t.length),i=e instanceof P?P.createZero(e):y.createZero(e);for(let s=0;s<n;++s)i.x+=t[s]*this.getXAtUncheckedPointIndex(s),i.y+=t[s]*this.getYAtUncheckedPointIndex(s),i.z+=t[s]*this.getZAtUncheckedPointIndex(s);return i}interpolateIndexIndex(t,e,n,i){if(!(t<0||t>=this.length||n<0||n>=this.length))return this.interpolateUncheckedIndexIndex(t,e,n,i)}interpolateUncheckedIndexIndex(t,e,n,i){return y.create(f.interpolate(this.getXAtUncheckedPointIndex(t),e,this.getXAtUncheckedPointIndex(n)),f.interpolate(this.getYAtUncheckedPointIndex(t),e,this.getYAtUncheckedPointIndex(n)),f.interpolate(this.getZAtUncheckedPointIndex(t),e,this.getZAtUncheckedPointIndex(n)),i)}get points(){return new cc(this)}getArray(){const t=[];for(const e of this.points)t.push(e);return t}front(t){if(this.length!==0)return this.getPoint3dAtUncheckedPointIndex(0,t)}back(t){if(this.length!==0)return this.getPoint3dAtUncheckedPointIndex(this.length-1,t)}almostEqualIndexIndex(t,e,n=f.smallMetricDistance){if(!(t<0||t>=this.length||e<0||e>=this.length))return this.almostEqualUncheckedIndexIndex(t,e,n)}almostEqualUncheckedIndexIndex(t,e,n=f.smallMetricDistance){return f.isSameCoordinate(this.getXAtUncheckedPointIndex(t),this.getXAtUncheckedPointIndex(e),n)&&f.isSameCoordinate(this.getYAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(e),n)&&f.isSameCoordinate(this.getZAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(e),n)}almostEqualXYIndexIndex(t,e,n=f.smallMetricDistance){if(!(t<0||t>=this.length||e<0||e>=this.length))return this.almostEqualXYUncheckedIndexIndex(t,e,n)}almostEqualXYUncheckedIndexIndex(t,e,n=f.smallMetricDistance){return f.isSameCoordinate(this.getXAtUncheckedPointIndex(t),this.getXAtUncheckedPointIndex(e),n)&&f.isSameCoordinate(this.getYAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(e),n)}evaluateUncheckedIndexPlaneAltitude(t,e){return e.altitudeXYZ(this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(t))}}class Ts extends le{pushIndexedXYZCollection(t){for(let e=0;e<t.length;e++)this.pushXYZ(t.getXAtUncheckedPointIndex(e),t.getYAtUncheckedPointIndex(e),t.getZAtUncheckedPointIndex(e));return t.length}}class W extends Ts{_data;_xyzInUse;_xyzCapacity;_growthFactor;constructor(t,e,n){super(),n?(this._xyzCapacity=n.length/3,this._xyzInUse=Math.min(t??1/0,this._xyzCapacity),this._data=n):(this._xyzCapacity=t??8,this._xyzInUse=0,this._data=new Float64Array(3*this._xyzCapacity)),this._growthFactor=e!==void 0&&e>=1?e:1.5}copyData(t,e,n){let i=n!==void 0?n*3:0;if(i<0&&(i=0),i>=this._data.length)return{count:0,offset:0};let s=e!==void 0?e*3:t.length;return s>0&&(s>t.length&&(s=t.length),i+s>this._data.length&&(s=this._data.length-i),s%3!==0&&(s-=s%3)),s<=0?{count:0,offset:0}:(s===t.length?this._data.set(t,i):t instanceof Float64Array?this._data.set(t.subarray(0,s),i):this._data.set(t.slice(0,s),i),{count:s/3,offset:i/3})}get length(){return this._xyzInUse}set length(t){this.resize(t,!0)}get float64Length(){return this._xyzInUse*3}float64Data(){return this._data}ensureCapacity(t,e=!0){if(t>this._xyzCapacity){e&&(t=Math.trunc(t*this._growthFactor));const n=this._data;this._data.buffer instanceof ArrayBuffer?this._data=new Float64Array(new ArrayBuffer(t*3*this._data.BYTES_PER_ELEMENT)):this._data=new Float64Array(new SharedArrayBuffer(t*3*this._data.BYTES_PER_ELEMENT)),this.copyData(n,this._xyzInUse),this._xyzCapacity=t}}resize(t,e){t>=0&&t<this._xyzInUse?this._xyzInUse=t:t>this._xyzInUse&&(this.ensureCapacity(t,!1),(e??!1)&&this._data.fill(0,this._xyzInUse*3),this._xyzInUse=t)}clone(t){return t?(t.length!==this.length&&t.clear(),t.resize(this.length)):t=new W(this.length),t.copyData(this._data,this.length),t._xyzInUse=this.length,t}static createCompressed(t,e=f.smallMetricDistance,n){const i=t.findOrderedDuplicates(e,!0),s=t.length-i.length;n||(n=new W(s)),n!==t&&(n.clear(),n.resize(s,!0));for(let r=0,o=0,a=0;r<t.length;++r)a<i.length&&r===i[a]?++a:n.transferFromGrowableXYZArray(o++,t,r);return n.resize(s),n}cloneCompressed(t=f.smallMetricDistance,e){return W.createCompressed(this,t,e)}compressInPlace(t=f.smallMetricDistance){return W.createCompressed(this,t,this)}static create(t,e){if(e)e.clear();else{const n=typeof t[0]=="number"?t.length/3:t.length;e=new W(n)}return e.pushFrom(t),e}static createCapture(t){return new W(0,void 0,t)}static createArrayOfGrowableXYZArray(t){const e=new qo;return bn.streamXYZ(t,e),e.claimArrayOfGrowableXYZArray()}push(t){this.pushXYZ(t.x,t.y,t.z)}pushAll(t){this.ensureCapacity(this._xyzInUse+t.length,!1);for(const e of t)this.push(e)}pushFrom(t){if(t instanceof y)this.pushXYZ(t.x,t.y,t.z);else if(t instanceof W)this.pushFromGrowableXYZArray(t);else if(t instanceof D)this.pushXYZ(t.x,t.y,0);else if(f.isNumberArray(t,4)||t instanceof Float64Array){const e=Math.trunc(t.length/3);this.ensureCapacity(this._xyzInUse+e,!1),this.copyData(t,e,this._xyzInUse),this._xyzInUse+=e}else if(f.isNumberArray(t,3))this.pushXYZ(t[0],t[1],t[2]);else if(f.isNumberArray(t,2))this.pushXYZ(t[0],t[1],0);else if(Array.isArray(t))for(const e of t)this.pushFrom(e);else y.isXYAndZ(t)?this.pushXYZ(t.x,t.y,t.z):y.isXAndY(t)?this.pushXYZ(t.x,t.y,0):t instanceof le&&this.pushIndexedXYZCollection(t)}pushWrap(t){if(this._xyzInUse>=t){this.ensureCapacity(this._xyzInUse+t,!1);for(let e=0;e<t;e++){const n=3*e;this.pushXYZ(this._data[n],this._data[n+1],this._data[n+2])}}}pushXYZ(t,e,n){this.ensureCapacity(this._xyzInUse+1);const i=this._xyzInUse*3;this._data[i]=t,this._data[i+1]=e,this._data[i+2]=n,this._xyzInUse++}shiftForward(t){if(t<=0)return;this.ensureCapacity(this._xyzInUse+t);const e=3*t,n=this._xyzInUse*3;this._data.copyWithin(e,0,n),this._xyzInUse+=t}pushFrontXYZ(t,e,n){this.shiftForward(1),this._data[0]=t,this._data[1]=e,this._data[2]=n}pushFront(t){this.pushFrontXYZ(t.x,t.y,t.z)}moveIndexToIndex(t,e){if(this.isIndexValid(t)&&this.isIndexValid(e)){let n=t*3,i=e*3;this._data[i++]=this._data[n++],this._data[i++]=this._data[n++],this._data[i]=this._data[n]}}pop(){this._xyzInUse>0&&this._xyzInUse--}clear(){this._xyzInUse=0}getPoint3dAtUncheckedPointIndex(t,e){const n=3*t;return y.create(this._data[n],this._data[n+1],this._data[n+2],e)}getPoint2dAtUncheckedPointIndex(t,e){const n=3*t;return D.create(this._data[n],this._data[n+1],e)}getVector3dAtUncheckedVectorIndex(t,e){const n=3*t;return P.create(this._data[n],this._data[n+1],this._data[n+2],e)}getPoint3dAtCheckedPointIndex(t,e){if(this.isIndexValid(t)){const n=3*t;return y.create(this._data[n],this._data[n+1],this._data[n+2],e)}}getXAtUncheckedPointIndex(t){const e=3*t;return this._data[e]}getYAtUncheckedPointIndex(t){const e=3*t;return this._data[e+1]}getZAtUncheckedPointIndex(t){const e=3*t;return this._data[e+2]}getPoint2dAtCheckedPointIndex(t,e){if(this.isIndexValid(t)){const n=3*t;return D.create(this._data[n],this._data[n+1],e)}}getVector3dAtCheckedVectorIndex(t,e){if(this.isIndexValid(t)){const n=3*t;return P.create(this._data[n],this._data[n+1],this._data[n+2],e)}}transferFromGrowableXYZArray(t,e,n){if(this.isIndexValid(t)&&e.isIndexValid(n)){const i=t*3;return this._data[i]=e.getXAtUncheckedPointIndex(n),this._data[i+1]=e.getYAtUncheckedPointIndex(n),this._data[i+2]=e.getZAtUncheckedPointIndex(n),!0}return!1}pushFromGrowableXYZArray(t,e){if(e===void 0){const n=t.length;return this.ensureCapacity(this.length+n,!1),this.copyData(t._data,n,this.length),this._xyzInUse+=n,n}if(t.isIndexValid(e)){const n=e*3;return this.pushXYZ(t._data[n],t._data[n+1],t._data[n+2]),1}return 0}pushIndexedXYZCollection(t){return t instanceof W?this.pushFromGrowableXYZArray(t):(this.ensureCapacity(this._xyzInUse+t.length,!1),super.pushIndexedXYZCollection(t))}setAtCheckedPointIndex(t,e){if(!this.isIndexValid(t))return!1;let n=t*3;return this._data[n++]=e.x,this._data[n++]=e.y,this._data[n]=e.z,!0}setXYZAtCheckedPointIndex(t,e,n,i){if(!this.isIndexValid(t))return!1;let s=t*3;return this._data[s++]=e,this._data[s++]=n,this._data[s]=i,!0}getPoint3dArray(){const t=3*this._xyzInUse,e=[],n=this._data;for(let i=0;i<t;i+=3)e.push(y.create(n[i],n[i+1],n[i+2]));return e}static multiplyTransformInPlace(t,e){if(Array.isArray(e))for(const n of e)n.multiplyTransformInPlace(t);else e.multiplyTransformInPlace(t)}multiplyTransformInPlace(t){const e=this._data,n=this.float64Length,i=t.matrix.coffs,s=t.origin,r=s.x,o=s.y,a=s.z;let c=0,l=0,d=0;for(let h=0;h+2<=n;h+=3)c=e[h],l=e[h+1],d=e[h+2],e[h]=i[0]*c+i[1]*l+i[2]*d+r,e[h+1]=i[3]*c+i[4]*l+i[5]*d+o,e[h+2]=i[6]*c+i[7]*l+i[8]*d+a}reverseInPlace(){const t=this.length;let e,n,i;const s=this._data;for(let r=0,o=t-1;r<o;r++,o--)e=3*r,n=3*o,i=s[e],s[e]=s[n],s[n]=i,e++,n++,i=s[e],s[e]=s[n],s[n]=i,e++,n++,i=s[e],s[e]=s[n],s[n]=i}multiplyMatrix3dInPlace(t){const e=this._data,n=this.float64Length,i=t.coffs;let s=0,r=0,o=0;for(let a=0;a+2<=n;a+=3)s=e[a],r=e[a+1],o=e[a+2],e[a]=i[0]*s+i[1]*r+i[2]*o,e[a+1]=i[3]*s+i[4]*r+i[5]*o,e[a+2]=i[6]*s+i[7]*r+i[8]*o}multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(t){const e=this._data,n=this.float64Length;if(!t.computeCachedInverse(!0))return!1;const i=t.inverseCoffs,s=f.smallFloatingPoint;let r=0,o=0,a=0,c,l,d,h,g,m=0;for(let p=0;p+2<=n;p+=3)r=e[p],o=e[p+1],a=e[p+2],c=i[0]*r+i[3]*o+i[6]*a,l=i[1]*r+i[4]*o+i[7]*a,d=i[2]*r+i[5]*o+i[8]*a,g=c*c+l*l+d*d,g<s?(c=r,l=o,d=a,m++):Math.abs(g-1)>s&&(h=1/Math.sqrt(g),c*=h,l*=h,d*=h),e[p]=c,e[p+1]=l,e[p+2]=d;return m===0}multiplyMatrix4dAndQuietRenormalizeMatrix4d(t){const e=this._data,n=this.float64Length,i=y.create();for(let s=0;s+2<=n;s+=3)t.multiplyXYZWQuietRenormalize(e[s],e[s+1],e[s+2],1,i),e[s]=i.x,e[s+1]=i.y,e[s+2]=i.z}tryTransformInverseInPlace(t){const e=this._data,n=this.float64Length,i=t.matrix;i.computeCachedInverse(!0);const s=i.inverseCoffs;if(!s)return!1;const r=t.origin,o=r.x,a=r.y,c=r.z;let l=0,d=0,h=0;for(let g=0;g+2<n;g+=3)l=e[g]-o,d=e[g+1]-a,h=e[g+2]-c,e[g]=s[0]*l+s[1]*d+s[2]*h,e[g+1]=s[3]*l+s[4]*d+s[5]*h,e[g+2]=s[6]*l+s[7]*d+s[8]*h;return!0}extendRange(t,e){const n=this.float64Length,i=this._data;if(e)for(let s=0;s+2<n;s+=3)t.extendTransformedXYZ(e,i[s],i[s+1],i[s+2]);else for(let s=0;s+2<n;s+=3)t.extendXYZ(i[s],i[s+1],i[s+2])}getRange(t,e){let n=e;return n?n.setNull():n=J.createNull(),this.extendRange(n,t),n}setRange(t,e){t.setNull(),this.extendRange(t,e)}sumLengths(){let t=0;const e=3*(this._xyzInUse-1),n=this._data;for(let i=0;i<e;i+=3)t+=f.hypotenuseXYZ(n[i+3]-n[i],n[i+4]-n[i+1],n[i+5]-n[i+2]);return t}scaleInPlace(t){if(this._data){const e=this.float64Length;for(let n=0;n<e;n++)this._data[n]=this._data[n]*t}}isCloseToPlane(t,e=f.smallMetricDistance){const n=3*this._xyzInUse,i=this._data;for(let s=0;s<n;s+=3)if(Math.abs(t.altitudeXYZ(i[s],i[s+1],i[s+2]))>e)return!1;return!0}forceClosure(t=f.smallMetricDistance){const e=this.distanceIndexIndex(0,this.length-1);if(e!==void 0){if(e>t)this.pushXYZ(this._data[0],this._data[1],this._data[2]);else if(e>0){const n=this._data.length-3;for(let i=0;i<3;i++)this._data[n+i]=this._data[i]}}}interpolate(t,e,n,i){if(this.isIndexValid(t)&&this.isIndexValid(n)){const s=1-e,r=this._data;return t=3*t,n=3*n,y.create(s*r[t]+e*r[n],s*r[t+1]+e*r[n+1],s*r[t+2]+e*r[n+2],i)}}pushInterpolatedFromGrowableXYZArray(t,e,n,i){if(t.isIndexValid(e)&&t.isIndexValid(i)){const s=1-n,r=t._data;e=3*e,i=3*i,this.pushXYZ(s*r[e]+n*r[i],s*r[e+1]+n*r[i+1],s*r[e+2]+n*r[i+2])}}areaXY(){let t=0;const e=3*this._xyzInUse;if(e>6){const n=this._data[e-3],i=this._data[e-2];let s=this._data[0]-n,r=this._data[1]-i,o=0,a=0;for(let c=3;c<e;c+=3,s=o,r=a)o=this._data[c]-n,a=this._data[c+1]-i,t+=f.crossProductXYXY(s,r,o,a)}return .5*t}vectorIndexIndex(t,e,n){if(!(!this.isIndexValid(t)||!this.isIndexValid(e)))return this.vectorUncheckedIndexIndex(t,e,n)}vectorUncheckedIndexIndex(t,e,n){const i=this._data;return t=3*t,e=3*e,P.create(i[e]-i[t],i[e+1]-i[t+1],i[e+2]-i[t+2],n)}vectorXYAndZIndex(t,e,n){if(this.isIndexValid(e))return this.vectorXYAndZUncheckedIndex(t,e,n)}vectorXYAndZUncheckedIndex(t,e,n){const i=this._data;return e=3*e,P.create(i[e]-t.x,i[e+1]-t.y,i[e+2]-t.z,n)}crossProductIndexIndexIndex(t,e,n,i){if(this.isIndexValid(t)&&this.isIndexValid(e)&&this.isIndexValid(n))return this.crossProductUncheckedIndexIndexIndex(t,e,n,i)}crossProductUncheckedIndexIndexIndex(t,e,n,i){const s=t*3,r=e*3,o=n*3,a=this._data;return f.crossProductXYZXYZ(a[r]-a[s],a[r+1]-a[s+1],a[r+2]-a[s+2],a[o]-a[s],a[o+1]-a[s+1],a[o+2]-a[s+2],i)}crossProductUncheckedIndexIndexXYAndZ(t,e,n,i){const s=t*3,r=e*3,o=this._data;return f.crossProductXYZXYZ(o[r]-o[s],o[r+1]-o[s+1],o[r+2]-o[s+2],n.x-o[s],n.y-o[s+1],n.z-o[s+2],i)}evaluateUncheckedIndexDotProductXYZ(t,e,n,i){const s=t*3,r=this._data;return r[s]*e+r[s+1]*n+r[s+2]*i}evaluateUncheckedIndexPlaneAltitude(t,e){const n=t*3,i=this._data;return e.altitudeXYZ(i[n],i[n+1],i[n+2])}accumulateCrossProductIndexIndexIndex(t,e,n,i){if(this.isIndexValid(t)&&this.isIndexValid(e)&&this.isIndexValid(n)){const s=t*3,r=e*3,o=n*3,a=this._data;i.addCrossProductToTargetsInPlace(a[s],a[s+1],a[s+2],a[r],a[r+1],a[r+2],a[o],a[o+1],a[o+2])}}accumulateScaledXYZ(t,e,n){if(this.isIndexValid(t)){const i=t*3,s=this._data;n.x+=e*s[i],n.y+=e*s[i+1],n.z+=e*s[i+2]}}crossProductXYAndZIndexIndex(t,e,n,i){if(this.isIndexValid(e)&&this.isIndexValid(n)){const s=e*3,r=n*3,o=this._data;return f.crossProductXYZXYZ(o[s]-t.x,o[s+1]-t.y,o[s+2]-t.z,o[r]-t.x,o[r+1]-t.y,o[r+2]-t.z,i)}}distanceIndexToPoint(t,e){if(this.isIndexValid(t)){const n=3*t;return f.hypotenuseXYZ(e.x-this._data[n],e.y-this._data[n+1],e.z-this._data[n+2])}}distanceSquaredIndexIndex(t,e){if(this.isIndexValid(t)&&this.isIndexValid(e))return this.distanceSquaredUncheckedIndexIndex(t,e)}distanceSquaredUncheckedIndexIndex(t,e){const n=3*t,i=3*e;return f.hypotenuseSquaredXYZ(this._data[i]-this._data[n],this._data[i+1]-this._data[n+1],this._data[i+2]-this._data[n+2])}distanceIndexIndex(t,e){if(this.isIndexValid(t)&&this.isIndexValid(e))return this.distanceUncheckedIndexIndex(t,e)}distanceUncheckedIndexIndex(t,e){const n=3*t,i=3*e;return f.hypotenuseXYZ(this._data[i]-this._data[n],this._data[i+1]-this._data[n+1],this._data[i+2]-this._data[n+2])}static distanceBetweenPointsIn2Arrays(t,e,n,i){if(t.isIndexValid(e)&&n.isIndexValid(i)){const s=3*e,r=3*i;return f.hypotenuseXYZ(n._data[r]-t._data[s],n._data[r+1]-t._data[s+1],n._data[r+2]-t._data[s+2])}}static isAlmostEqual(t,e){if(t&&e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!t.getPoint3dAtUncheckedPointIndex(n).isAlmostEqual(e.getPoint3dAtUncheckedPointIndex(n)))return!1;return!0}return!t&&!e}sortIndicesLexical(){const t=this._xyzInUse,e=new Uint32Array(t);for(let n=0;n<t;n++)e[n]=n;return e.sort((n,i)=>this.compareLexicalBlock(n,i)),e}compareLexicalBlock(t,e){let n=0,i=0;for(let s=0;s<3;s++){if(n=this._data[t*3+s],i=this._data[e*3+s],n>i)return 1;if(n<i)return-1}return t-e}component(t,e){return this._data[3*t+e]}addSteppedPoints(t,e,n,i){const s=t._data;let r=e*3;const o=t.length*3;let a=0;for(this.ensureCapacity(this._xyzInUse+i,!1);r>=0&&r+2<o&&a<i;)this.pushXYZ(s[r],s[r+1],s[r+2]),r+=n*3,a++}static distanceRangeBetweenCorrespondingPoints(t,e){const n=t._data,i=e._data,s=Math.min(t.length,e.length);let r=0,o;const a=ct.createNull();for(;r<s;)o=3*r,a.extendX(f.hypotenuseXYZ(n[o]-i[o],n[o+1]-i[o+1],n[o+2]-i[o+2])),r++;return a}static removeClosure(t,e=f.smallMetricDistance){for(;t.length>1&&t.distanceUncheckedIndexIndex(0,t.length-1)<e;)t.pop()}fillLocalXYTriangleFrame(t,e,n,i){if(this.isIndexValid(t)&&this.isIndexValid(e)&&this.isIndexValid(n)){let s=t*3;const r=this._data,o=r[s++],a=r[s++],c=r[s++];s=e*3;const l=r[s++]-o,d=r[s++]-a,h=r[s++]-c;s=n*3;const g=r[s++]-o,m=r[s++]-a,p=r[s++]-c;return i=X.createRowValues(l,g,0,o,d,m,0,a,h,p,1,c,i),i.computeCachedInverse()?i:void 0}}mapComponent(t,e){const n=this._data.length;let i;for(let s=0;s+2<n;s+=3)i=e(this._data[s],this._data[s+1],this._data[s+2]),this._data[s+t]=i}mapPoint(t){const e=this._data.length;let n;for(let i=0;i+2<e;i+=3)n=t(this._data[i],this._data[i+1],this._data[i+2]),this._data[i]=n.x,this._data[i+1]=n.y,this._data[i+2]=n.z}}class Mr{startChain(t,e){}handleXYZ(t,e,n){}endChain(t,e){}}class lc extends Mr{_x0;_y0;_z0;handleXYZ(t,e,n){this._x0!==void 0&&this._y0!==void 0&&this._z0!==void 0&&this.handleXYZXYZ(this._x0,this._y0,this._z0,t,e,n),this._x0=t,this._y0=e,this._z0=n}startChain(t,e){this._x0=this._y0=this._z0=void 0}handleXYZXYZ(t,e,n,i,s,r){}}class qo extends Mr{_pointArrays;_currentData;startChain(t,e){this._currentData=void 0}handleXYZ(t,e,n){this._currentData||(this._currentData=new W),this._currentData.pushXYZ(t,e,n)}endChain(t,e){this._currentData!==void 0&&(this._pointArrays===void 0&&(this._pointArrays=[]),this._pointArrays.push(this._currentData),this._currentData=void 0)}claimArrayOfGrowableXYZArray(){const t=this._pointArrays;return this._pointArrays=void 0,t}}class dc extends Mr{_range;_transform;constructor(t,e){super(),t&&(this._transform=t),e&&(this._range=e)}handleXYZ(t,e,n){this._range||(this._range=J.createNull()),this._transform?this._range.extendTransformedXYZ(this._transform,t,e,n):this._range.extendXYZ(t,e,n)}claimResult(){const t=this._range;return this._range=void 0,t||J.createNull()}}class Wo{_resultStack;_xyzFunction;constructor(t){this._xyzFunction=t,this._resultStack=[],this._resultStack.push([])}startChain(t,e){this._resultStack.push([])}handleXYZ(t,e,n){this._resultStack[this._resultStack.length-1].push(this._xyzFunction(t,e,n))}endChain(t,e){const n=this._resultStack[this._resultStack.length-1];this._resultStack.pop(),this._resultStack[this._resultStack.length-1].push(n)}claimResult(){const t=this._resultStack[0];return t.length===1?t[0]:t}}class bn{static _workPoint;static streamXYZ(t,e){let n=0;if(Array.isArray(t))if(t.length>0&&y.isAnyImmediatePointType(t[0])){e.startChain(t,!0);for(const i of t){const s=y.accessX(i),r=y.accessY(i),o=y.accessZ(i,0);s!==void 0&&r!==void 0&&e.handleXYZ(s,r,o),n++}e.endChain(t,!0)}else{e.startChain(t,!1);for(const i of t)n+=this.streamXYZ(i,e);e.endChain(t,!1)}else if(t instanceof le){e.startChain(t,!0);const i=bn._workPoint=y.create(0,0,0,bn._workPoint);for(let s=0;s<t.length;s++)t.getPoint3dAtCheckedPointIndex(s,i),n++,e.handleXYZ(i.x,i.y,i.z);e.endChain(t,!0)}return n}}class G{static _EXTREME_POSITIVE=1e200;static _EXTREME_NEGATIVE=-1e200;static npcScaleFactor(t,e){return e<=t?0:1/(e-t)}static isExtremeValue(t){return Math.abs(t)>=G._EXTREME_POSITIVE}static isExtremePoint3d(t){return G.isExtremeValue(t.x)||G.isExtremeValue(t.y)||G.isExtremeValue(t.z)}static isExtremePoint2d(t){return G.isExtremeValue(t.x)||G.isExtremeValue(t.y)}static rangeToRangeAbsoluteDistance(t,e,n,i){return e<t||i<n?G._EXTREME_POSITIVE:i<t?t-i:i<=e||n<=e?0:n-e}static coordinateToRangeAbsoluteDistance(t,e,n){return n<e?G._EXTREME_POSITIVE:t<e?e-t:t>n?t-n:0}static multiplyIfPositive(t,e,n=0){return t>0?e*t:n}}class J extends G{low;high;setNull(){this.low.x=G._EXTREME_POSITIVE,this.low.y=G._EXTREME_POSITIVE,this.low.z=G._EXTREME_POSITIVE,this.high.x=G._EXTREME_NEGATIVE,this.high.y=G._EXTREME_NEGATIVE,this.high.z=G._EXTREME_NEGATIVE}freeze(){return this.low.freeze(),this.high.freeze(),Object.freeze(this)}static toFloat64Array(t){return Float64Array.of(t.low.x,t.low.y,t.low.z,t.high.x,t.high.y,t.high.z)}toFloat64Array(){return J.toFloat64Array(this)}static fromFloat64Array(t){if(t.length!==6)throw new Error("invalid array");return new this(t[0],t[1],t[2],t[3],t[4],t[5])}static fromArrayBuffer(t){return this.fromFloat64Array(new Float64Array(t))}constructor(t=G._EXTREME_POSITIVE,e=G._EXTREME_POSITIVE,n=G._EXTREME_POSITIVE,i=G._EXTREME_NEGATIVE,s=G._EXTREME_NEGATIVE,r=G._EXTREME_NEGATIVE){super(),this.low=y.create(t,e,n),this.high=y.create(i,s,r)}isAlmostEqual(t,e){return this.low.isAlmostEqual(t.low,e)&&this.high.isAlmostEqual(t.high,e)||this.isNull&&t.isNull}setFrom(t){this.low.setFrom(t.low),this.high.setFrom(t.high)}static createFrom(t,e){return e?(e.setFrom(t),e):this.createXYZXYZOrCorrectToNull(t.low.x,t.low.y,t.low.z,t.high.x,t.high.y,t.high.z,e)}setFromJSON(t){if(!t)return;if(this.setNull(),Array.isArray(t)){const i=y.create();for(const s of t)i.setFromJSON(s),this.extendPoint(i);return}const e=y.fromJSON(t.low),n=y.fromJSON(t.high);!G.isExtremePoint3d(e)&&!G.isExtremePoint3d(n)&&(this.extendPoint(e),this.extendPoint(n))}toJSON(){return{low:this.low.toJSON(),high:this.high.toJSON()}}static fromJSON(t){const e=new this;return e.setFromJSON(t),e}setDirect(t,e,n,i,s,r,o){this.low.x=t,this.low.y=e,this.low.z=n,this.high.x=i,this.high.y=s,this.high.z=r,o&&(this.low.x>this.high.x||this.low.y>this.high.y||this.low.z>this.high.z)&&this.setNull()}clone(t){return t=t||new this.constructor,t.setDirect(this.low.x,this.low.y,this.low.z,this.high.x,this.high.y,this.high.z,!1),t}cloneTranslated(t,e){return e=e||new this.constructor,this.isNull||e.setDirect(this.low.x+t.x,this.low.y+t.y,this.low.z+t.z,this.high.x+t.x,this.high.y+t.y,this.high.z+t.z,!1),e}static createNull(t){return t=t||new this,t.setNull(),t}extend(...t){for(const e of t)this.extendPoint(e)}static create(...t){const e=J.createNull();for(const n of t)e.extendPoint(n);return e}static createFromVariantData(t,e,n){n&&n.setNull();const i=new dc(e,n);return bn.streamXYZ(t,i),i.claimResult()}static createTransformed(t,...e){const n=this.createNull();for(const i of e)n.extendTransformedXYZ(t,i.x,i.y,i.z);return n}static createTransformedArray(t,e){const n=this.createNull();return n.extendArray(e,t),n}static createInverseTransformedArray(t,e){const n=this.createNull();return n.extendInverseTransformedArray(e,t),n}setXYZ(t,e,n){this.low.x=this.high.x=t,this.low.y=this.high.y=e,this.low.z=this.high.z=n}static createXYZ(t,e,n,i){return i=i||new this,i.setDirect(t,e,n,t,e,n,!1),i}static createXYZXYZ(t,e,n,i,s,r,o){return o=o||new this,o.setDirect(Math.min(t,i),Math.min(e,s),Math.min(n,r),Math.max(t,i),Math.max(e,s),Math.max(n,r),!1),o}static createXYZXYZOrCorrectToNull(t,e,n,i,s,r,o){return o=o||new this,t>i||e>s||n>r?this.createNull(o):(o.setDirect(Math.min(t,i),Math.min(e,s),Math.min(n,r),Math.max(t,i),Math.max(e,s),Math.max(n,r),!0),o)}static createRange2d(t,e=0,n){const i=n||new this;return i.setNull(),i.extendXYZ(t.low.x,t.low.y,e),i.extendXYZ(t.high.x,t.high.y,e),i}static createArray(t,e){e=e||new this,e.setNull();let n;for(n of t)e.extendPoint(n);return e}extendArray(t,e){if(Array.isArray(t))if(e)for(const n of t)this.extendTransformedXYZ(e,n.x,n.y,n.z);else for(const n of t)this.extendXYZ(n.x,n.y,n.z);else if(e)for(let n=0;n<t.length;n++)this.extendTransformedXYZ(e,t.getXAtUncheckedPointIndex(n),t.getYAtUncheckedPointIndex(n),t.getZAtUncheckedPointIndex(n));else for(let n=0;n<t.length;n++)this.extendXYZ(t.getXAtUncheckedPointIndex(n),t.getYAtUncheckedPointIndex(n),t.getZAtUncheckedPointIndex(n))}extendInverseTransformedArray(t,e){if(Array.isArray(t))for(const n of t)this.extendInverseTransformedXYZ(e,n.x,n.y,n.z);else for(let n=0;n<t.length;n++)this.extendInverseTransformedXYZ(e,t.getXAtUncheckedPointIndex(n),t.getYAtUncheckedPointIndex(n),t.getZAtUncheckedPointIndex(n))}extendTransformedXYZ(t,e,n,i){const s=t.origin,r=t.matrix.coffs;this.extendXYZ(s.x+r[0]*e+r[1]*n+r[2]*i,s.y+r[3]*e+r[4]*n+r[5]*i,s.z+r[6]*e+r[7]*n+r[8]*i)}extendTransformedXYZW(t,e,n,i,s){const r=t.origin,o=t.matrix.coffs;this.extendXYZW(r.x*s+o[0]*e+o[1]*n+o[2]*i,r.y*s+o[3]*e+o[4]*n+o[5]*i,r.z*s+o[6]*e+o[7]*n+o[8]*i,s)}extendInverseTransformedXYZ(t,e,n,i){const s=t.origin;if(!t.matrix.computeCachedInverse(!0))return!1;const r=t.matrix.inverseCoffs,o=e-s.x,a=n-s.y,c=i-s.z;return this.extendXYZ(r[0]*o+r[1]*a+r[2]*c,r[3]*o+r[4]*a+r[5]*c,r[6]*o+r[7]*a+r[8]*c),!0}extendTransformTransformedXYZ(t,e,n,i,s){const r=e.origin,o=e.matrix.coffs;this.extendTransformedXYZ(t,r.x+o[0]*n+o[1]*i+o[2]*s,r.y+o[3]*n+o[4]*i+o[5]*s,r.z+o[6]*n+o[7]*i+o[8]*s)}get isNull(){return this.high.x<this.low.x||this.high.y<this.low.y||this.high.z<this.low.z}static isNull(t){return t.high.x<t.low.x||t.high.y<t.low.y||t.high.z<t.low.z}get isSinglePoint(){return this.high.x===this.low.x&&this.high.y===this.low.y&&this.high.z===this.low.z}get center(){return this.low.interpolate(.5,this.high)}get xLow(){return this.low.x}get yLow(){return this.low.y}get zLow(){return this.low.z}get xHigh(){return this.high.x}get yHigh(){return this.high.y}get zHigh(){return this.high.z}xLength(){const t=this.high.x-this.low.x;return t>0?t:0}yLength(){const t=this.high.y-this.low.y;return t>0?t:0}zLength(){const t=this.high.z-this.low.z;return t>0?t:0}maxLength(){return Math.max(this.xLength(),this.yLength(),this.zLength())}diagonal(t){return this.low.vectorTo(this.high,t)}diagonalLength(t=!1){return t?this.low.distanceXY(this.high):this.low.distance(this.high)}diagonalLengthSquared(t=!1){return t?this.low.distanceSquaredXY(this.high):this.low.distanceSquared(this.high)}diagonalFractionToPoint(t,e){return this.low.interpolate(t,this.high,e)}fractionToPoint(t,e,n=0,i){return this.low.interpolateXYZ(t,e,n,this.high,i)}localXYZToWorld(t,e,n,i){if(!this.isNull)return this.low.interpolateXYZ(t,e,n,this.high,i)}localToWorld(t,e){return this.localXYZToWorld(t.x,t.y,t.z,e)}localToWorldArrayInPlace(t){if(this.isNull)return!1;for(const e of t)this.low.interpolateXYZ(e.x,e.y,e.z,this.high,e);return!1}worldToLocal(t,e){const n=G.npcScaleFactor(this.low.x,this.high.x),i=G.npcScaleFactor(this.low.y,this.high.y),s=G.npcScaleFactor(this.low.z,this.high.z);if(!(n===0||i===0||s===0))return y.create((t.x-this.low.x)*n,(t.y-this.low.y)*i,(t.z-this.low.z)*s,e)}worldToLocalArrayInPlace(t){const e=G.npcScaleFactor(this.low.x,this.high.x),n=G.npcScaleFactor(this.low.y,this.high.y),i=G.npcScaleFactor(this.low.z,this.high.z);if(e===0||n===0||i===0)return!1;for(const s of t)y.create((s.x-this.low.x)*e,(s.y-this.low.y)*n,(s.z-this.low.z)*i,s);return!0}corners(t){return t!==void 0&&t.length>=8?(t[0].set(this.low.x,this.low.y,this.low.z),t[1].set(this.high.x,this.low.y,this.low.z),t[2].set(this.low.x,this.high.y,this.low.z),t[3].set(this.high.x,this.high.y,this.low.z),t[4].set(this.low.x,this.low.y,this.high.z),t[5].set(this.high.x,this.low.y,this.high.z),t[6].set(this.low.x,this.high.y,this.high.z),t[7].set(this.high.x,this.high.y,this.high.z),t.length=8,t):[y.create(this.low.x,this.low.y,this.low.z),y.create(this.high.x,this.low.y,this.low.z),y.create(this.low.x,this.high.y,this.low.z),y.create(this.high.x,this.high.y,this.low.z),y.create(this.low.x,this.low.y,this.high.z),y.create(this.high.x,this.low.y,this.high.z),y.create(this.low.x,this.high.y,this.high.z),y.create(this.high.x,this.high.y,this.high.z)]}static faceCornerIndices(t){return t===0?[0,4,6,2]:t===1?[1,3,7,5]:t===2?[0,1,5,4]:t===3?[3,2,6,7]:t===4?[0,2,3,1]:[4,5,7,6]}rectangleXY(t=0,e=!0,n=!0){if(this.isNull)return;const i=[this.fractionToPoint(0,0,t),this.fractionToPoint(1,0,t),this.fractionToPoint(1,1,t),this.fractionToPoint(0,1,t)];return n&&i.push(i[0].clone()),e||i.reverse(),i}maxAbs(){return this.isNull?0:Math.max(this.low.maxAbs(),this.high.maxAbs())}maxAbsXY(){return this.isNull?0:Math.max(this.low.maxAbsXY(),this.high.maxAbsXY())}get isAlmostZeroX(){return f.isSmallMetricDistance(this.xLength())}get isAlmostZeroY(){return f.isSmallMetricDistance(this.yLength())}get isAlmostZeroZ(){return f.isSmallMetricDistance(this.zLength())}containsXYZ(t,e,n){return t>=this.low.x&&e>=this.low.y&&n>=this.low.z&&t<=this.high.x&&e<=this.high.y&&n<=this.high.z}containsXY(t,e){return t>=this.low.x&&e>=this.low.y&&t<=this.high.x&&e<=this.high.y}containsPoint(t){return this.containsXYZ(t.x,t.y,t.z)}containsPointXY(t){return t.x>=this.low.x&&t.y>=this.low.y&&t.x<=this.high.x&&t.y<=this.high.y}containsRange(t){return t.low.x>=this.low.x&&t.low.y>=this.low.y&&t.low.z>=this.low.z&&t.high.x<=this.high.x&&t.high.y<=this.high.y&&t.high.z<=this.high.z}intersectsRange(t,e){return e?!(this.low.x>t.high.x+e||this.low.y>t.high.y+e||this.low.z>t.high.z+e||t.low.x>this.high.x+e||t.low.y>this.high.y+e||t.low.z>this.high.z+e):!(this.low.x>t.high.x||this.low.y>t.high.y||this.low.z>t.high.z||t.low.x>this.high.x||t.low.y>this.high.y||t.low.z>this.high.z)}intersectsRangeXY(t,e){return e?!(this.low.x>t.high.x+e||this.low.y>t.high.y+e||t.low.x>this.high.x+e||t.low.y>this.high.y+e):!(this.low.x>t.high.x||this.low.y>t.high.y||t.low.x>this.high.x||t.low.y>this.high.y)}distanceToPoint(t){return this.isNull?G._EXTREME_POSITIVE:Math.min(f.hypotenuseXYZ(G.coordinateToRangeAbsoluteDistance(t.x,this.low.x,this.high.x),G.coordinateToRangeAbsoluteDistance(t.y,this.low.y,this.high.y),G.coordinateToRangeAbsoluteDistance(t.z,this.low.z,this.high.z)),G._EXTREME_POSITIVE)}distanceToPointXY(t){return this.isNull?G._EXTREME_POSITIVE:Math.min(f.hypotenuseXY(G.coordinateToRangeAbsoluteDistance(t.x,this.low.x,this.high.x),G.coordinateToRangeAbsoluteDistance(t.y,this.low.y,this.high.y)),G._EXTREME_POSITIVE)}distanceToRange(t){return Math.min(f.hypotenuseXYZ(G.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,t.low.x,t.high.x),G.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,t.low.y,t.high.y),G.rangeToRangeAbsoluteDistance(this.low.z,this.high.z,t.low.z,t.high.z)),G._EXTREME_POSITIVE)}distanceToRangeXY(t){return Math.min(f.hypotenuseXY(G.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,t.low.x,t.high.x),G.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,t.low.y,t.high.y)),G._EXTREME_POSITIVE)}extendXYZ(t,e,n){t<this.low.x&&(this.low.x=t),t>this.high.x&&(this.high.x=t),e<this.low.y&&(this.low.y=e),e>this.high.y&&(this.high.y=e),n<this.low.z&&(this.low.z=n),n>this.high.z&&(this.high.z=n)}extendInterpolated(t,e,n){if(e<.5)this.extendXYZ(t.x+e*(n.x-t.x),t.y+e*(n.y-t.y),t.z+e*(n.z-t.z));else{const i=1-e;this.extendXYZ(n.x+i*(t.x-n.x),n.y+i*(t.y-n.y),n.z+i*(t.z-n.z))}}extendXOnly(t){t<this.low.x&&(this.low.x=t),t>this.high.x&&(this.high.x=t)}extendYOnly(t){t<this.low.y&&(this.low.y=t),t>this.high.y&&(this.high.y=t)}extendZOnly(t){t<this.low.z&&(this.low.z=t),t>this.high.z&&(this.high.z=t)}extendSingleAxis(t,e){e===ze.X&&this.extendXOnly(t),e===ze.Y&&this.extendYOnly(t),e===ze.Z&&this.extendZOnly(t)}extendXYZW(t,e,n,i){f.isSmallMetricDistance(i)||this.extendXYZ(t/i,e/i,n/i)}extendPoint(t,e){e?this.extendTransformedXYZ(e,t.x,t.y,t.z):this.extendXYZ(t.x,t.y,t.z)}extendTransformedPoint(t,e){this.extendTransformedXYZ(t,e.x,e.y,e.z)}extendRange(t){J.isNull(t)||(this.extendXYZ(t.low.x,t.low.y,t.low.z),this.extendXYZ(t.high.x,t.high.y,t.high.z))}extendWhenLarger(t,e){!J.isNull(t)&&!J.isNull(this)&&(this.high.x+=G.multiplyIfPositive(this.high.x-t.high.x,e),this.high.y+=G.multiplyIfPositive(this.high.y-t.high.y,e),this.high.z+=G.multiplyIfPositive(this.high.z-t.high.z,e),this.low.x-=G.multiplyIfPositive(t.low.x-this.low.x,e),this.low.y-=G.multiplyIfPositive(t.low.y-this.low.y,e),this.low.z-=G.multiplyIfPositive(t.low.z-this.low.z,e))}intersect(t,e){return this.intersectsRange(t)?J.createXYZXYZOrCorrectToNull(Math.max(this.low.x,t.low.x),Math.max(this.low.y,t.low.y),Math.max(this.low.z,t.low.z),Math.min(this.high.x,t.high.x),Math.min(this.high.y,t.high.y),Math.min(this.high.z,t.high.z),e):J.createNull(e)}union(t,e){return this.isNull?t.clone(e):t.isNull?this.clone(e):J.createXYZXYZOrCorrectToNull(Math.min(this.low.x,t.low.x),Math.min(this.low.y,t.low.y),Math.min(this.low.z,t.low.z),Math.max(this.high.x,t.high.x),Math.max(this.high.y,t.high.y),Math.max(this.high.z,t.high.z),e)}scaleAboutCenterInPlace(t){if(!this.isNull){t=Math.abs(t);const e=.5*(this.low.x+this.high.x),n=.5*(this.low.y+this.high.y),i=.5*(this.low.z+this.high.z);this.high.x=f.interpolate(e,t,this.high.x),this.high.y=f.interpolate(n,t,this.high.y),this.high.z=f.interpolate(i,t,this.high.z),this.low.x=f.interpolate(e,t,this.low.x),this.low.y=f.interpolate(n,t,this.low.y),this.low.z=f.interpolate(i,t,this.low.z)}}expandInPlace(t){this.setDirect(this.low.x-t,this.low.y-t,this.low.z-t,this.high.x+t,this.high.y+t,this.high.z+t,!0)}getLocalToWorldTransform(t){return X.createOriginAndMatrix(y.create(this.low.x,this.low.y,this.low.z),C.createRowValues(this.high.x-this.low.x,0,0,0,this.high.y-this.low.y,0,0,0,this.high.z-this.low.z),t)}getNpcToWorldRangeTransform(t){const e=this.getLocalToWorldTransform(t),n=e.matrix;return n.coffs[0]===0&&(n.coffs[0]=1),n.coffs[4]===0&&(n.coffs[4]=1),n.coffs[8]===0&&(n.coffs[8]=1),e}ensureMinLengths(t=.001){let e=(t-this.xLength())/2;e>0&&(this.low.x-=e,this.high.x+=e),e=(t-this.yLength())/2,e>0&&(this.low.y-=e,this.high.y+=e),e=(t-this.zLength())/2,e>0&&(this.low.z-=e,this.high.z+=e)}}class ct extends G{low;high;setNull(){this.low=G._EXTREME_POSITIVE,this.high=G._EXTREME_NEGATIVE}setDirect(t,e,n=!1){this.low=t,this.high=e,n&&t>e&&this.setNull()}constructor(t=G._EXTREME_POSITIVE,e=G._EXTREME_NEGATIVE){super(),this.low=t,this.high=e,this.setDirect(t,e)}isAlmostEqual(t){return f.isSameCoordinate(this.low,t.low)&&f.isSameCoordinate(this.high,t.high)||this.isNull&&t.isNull}setFrom(t){this.low=t.low,this.high=t.high}setFromJSON(t){if(this.setNull(),Array.isArray(t)){let e;for(e of t)Number.isFinite(e)&&this.extendX(e)}else t.low!==void 0&&Number.isFinite(t.low)&&t.high!==void 0&&Number.isFinite(t.high)&&(this.extendX(t.low),this.extendX(t.high))}static fromJSON(t){const e=new this;return t&&e.setFromJSON(t),e}toJSON(){return this.isNull?new Array:[this.low,this.high]}clone(t){return t=t||new this.constructor,t.setDirect(this.low,this.high),t}static createFrom(t,e){return e=e||new this,e.setDirect(t.low,t.high),e}static createNull(t){return t=t||new this,t.setNull(),t}cloneTranslated(t,e){return e=e||this.clone(),e.isNull||(e.low+=t,e.high+=t),e}setX(t){this.low=this.high=t}static createX(t,e){return e=e||new this,e.setDirect(t,t),e}setXXUnordered(t,e){t<=e?(this.low=t,this.high=e):(this.low=e,this.high=t)}get isExact01(){return this.low===0&&this.high===1}static createXX(t,e,n){return n=n||new this,n.setDirect(Math.min(t,e),Math.max(t,e)),n}static createXXOrCorrectToNull(t,e,n){return e<t?ct.createNull(n):(n=n||new this,n.setDirect(Math.min(t,e),Math.max(t,e)),n)}static createArray(t,e){e=e||new this;let n;for(n of t)e.extendX(n);return e}extendArray(t){let e;for(e of t)this.extendX(e)}extendArraySubset(t,e,n){const i=e+n;for(let s=e;s<i;s++)this.extendX(t[s])}get isNull(){return this.high<this.low}get isSinglePoint(){return this.high===this.low}length(){const t=this.high-this.low;return t>0?t:0}fractionToPoint(t){return f.interpolate(this.low,t,this.high)}maxAbs(){return this.isNull?0:Math.max(Math.abs(this.low),Math.abs(this.high))}get isAlmostZeroLength(){return f.isSmallMetricDistance(this.length())}containsX(t){return t>=this.low&&t<=this.high}containsXOpen(t){return t>this.low&&t<this.high}containsRange(t){return t.low>=this.low&&t.high<=this.high}intersectsRange(t){return!(this.low>t.high||t.low>this.high)}intersectRangeXXInPlace(t,e){e<t||e<this.low||t>this.high?this.setNull():(e<this.high&&(this.high=e),t>this.low&&(this.low=t))}distanceToRange(t){return G.rangeToRangeAbsoluteDistance(this.low,this.high,t.low,t.high)}distanceToX(t){return this.isNull?G._EXTREME_POSITIVE:G.coordinateToRangeAbsoluteDistance(t,this.low,this.high)}extendX(t){t<this.low&&(this.low=t),t>this.high&&(this.high=t)}extendRange(t){t.isNull||(this.extendX(t.low),this.extendX(t.high))}extendLow(t){return this.isNull||t<this.low?(this.low=t,!0):!1}extendHigh(t){return this.isNull||t>this.high?(this.high=t,!0):!1}intersect(t,e){return this.intersectsRange(t)?ct.createXXOrCorrectToNull(Math.max(this.low,t.low),Math.min(this.high,t.high),e):ct.createNull(e)}union(t,e){return ct.createXX(Math.min(this.low,t.low),Math.max(this.high,t.high),e)}scaleAboutCenterInPlace(t){if(!this.isNull){t=Math.abs(t);const e=.5*(this.low+this.high);this.high=f.interpolate(e,t,this.high),this.low=f.interpolate(e,t,this.low)}}expandInPlace(t){this.setDirect(this.low-t,this.high+t,!0)}clipLinearMapToInterval(t,e,n,i){if(i<n||this.high<this.low)return!1;const s=f.conditionalDivideFraction(n-t,e),r=f.conditionalDivideFraction(i-t,e);return s===void 0||r===void 0?n<=t&&t<=i?!0:(this.setNull(),!1):(s<r?(s>this.low&&(this.low=s),r<this.high&&(this.high=r)):(s<this.high&&(this.high=s),r>this.low&&(this.low=r)),this.high<this.low?(this.setNull(),!1):!0)}}class Rt extends G{low;high;setNull(){this.low.x=G._EXTREME_POSITIVE,this.low.y=G._EXTREME_POSITIVE,this.high.x=G._EXTREME_NEGATIVE,this.high.y=G._EXTREME_NEGATIVE}static toFloat64Array(t){return Float64Array.of(t.low.x,t.low.y,t.high.x,t.high.y)}toFloat64Array(){return Rt.toFloat64Array(this)}static fromFloat64Array(t){if(t.length!==4)throw new Error("invalid array");return new this(t[0],t[1],t[2],t[3])}static fromArrayBuffer(t){return this.fromFloat64Array(new Float64Array(t))}constructor(t=Rt._EXTREME_POSITIVE,e=Rt._EXTREME_POSITIVE,n=Rt._EXTREME_NEGATIVE,i=Rt._EXTREME_NEGATIVE){super(),this.low=D.create(t,e),this.high=D.create(n,i)}isAlmostEqual(t){return this.low.isAlmostEqual(t.low)&&this.high.isAlmostEqual(t.high)||this.isNull&&t.isNull}setFrom(t){this.low.set(t.low.x,t.low.y),this.high.set(t.high.x,t.high.y)}static createFrom(t,e){return e?(e.setFrom(t),e):this.createXYXYOrCorrectToNull(t.low.x,t.low.y,t.high.x,t.high.y,e)}setFromJSON(t){if(this.setNull(),Array.isArray(t)){const i=D.create();for(const s of t)i.setFromJSON(s),this.extendPoint(i);return}const e=D.fromJSON(t.low),n=D.fromJSON(t.high);!G.isExtremePoint2d(e)&&!G.isExtremePoint2d(n)&&(this.extendPoint(e),this.extendPoint(n))}freeze(){return this.low.freeze(),this.high.freeze(),Object.freeze(this)}toJSON(){return this.isNull?[]:[this.low.toJSON(),this.high.toJSON()]}static fromJSON(t){const e=new this;return t&&e.setFromJSON(t),e}setDirect(t,e,n,i,s){this.low.x=t,this.low.y=e,this.high.x=n,this.high.y=i,s&&(this.low.x>this.high.x||this.low.y>this.high.y)&&this.setNull()}clone(t){return t=t||new this.constructor,t.setDirect(this.low.x,this.low.y,this.high.x,this.high.y,!1),t}cloneTranslated(t,e){return e=e||new this.constructor,this.isNull||e.setDirect(this.low.x+t.x,this.low.y+t.y,this.high.x+t.x,this.high.y+t.y,!1),e}static createNull(t){return t=t||new this,t.setNull(),t}setXY(t,e){this.low.x=this.high.x=t,this.low.y=this.high.y=e}static createXY(t,e,n){return n=n||new this,n.setDirect(t,e,t,e,!1),n}static createXYXY(t,e,n,i,s){return s=s||new this,s.setDirect(Math.min(t,n),Math.min(e,i),Math.max(t,n),Math.max(e,i),!1),s}static createXYXYXY(t,e,n,i,s,r,o){return o=o||new this,o.setDirect(Math.min(t,n,s),Math.min(e,i,r),Math.max(t,n,s),Math.max(e,i,r),!1),o}static createXYXYOrCorrectToNull(t,e,n,i,s){return t>n||e>i?this.createNull(s):(s=s||new this,s.setDirect(Math.min(t,n),Math.min(e,i),Math.max(t,n),Math.max(e,i),!0),s)}static createArray(t,e){e=e||new this;let n;for(n of t)e.extendPoint(n);return e}get isNull(){return this.high.x<this.low.x||this.high.y<this.low.y}static isNull(t){return t.high.x<t.low.x||t.high.y<t.low.y}get isSinglePoint(){return this.high.x===this.low.x&&this.high.y===this.low.y}get center(){return this.low.interpolate(.5,this.high)}get xLow(){return this.low.x}get yLow(){return this.low.y}get xHigh(){return this.high.x}get yHigh(){return this.high.y}xLength(){const t=this.high.x-this.low.x;return t>0?t:0}yLength(){const t=this.high.y-this.low.y;return t>0?t:0}diagonal(t){return this.low.vectorTo(this.high,t)}diagonalLength(){return this.low.distance(this.high)}diagonalLengthSquared(){return this.low.distanceSquared(this.high)}diagonalFractionToPoint(t,e){return this.low.interpolate(t,this.high,e)}fractionToPoint(t,e,n){return this.low.interpolateXY(t,e,this.high,n)}corners3d(t=!1,e=0){return t?[y.create(this.low.x,this.low.y,e),y.create(this.high.x,this.low.y,e),y.create(this.high.x,this.high.y,e),y.create(this.low.x,this.high.y,e),y.create(this.low.x,this.low.y,e)]:[y.create(this.low.x,this.low.y,e),y.create(this.high.x,this.low.y,e),y.create(this.low.x,this.high.y,e),y.create(this.high.x,this.high.y,e)]}maxAbs(){return this.isNull?0:Math.max(this.low.maxAbs(),this.high.maxAbs())}get isAlmostZeroX(){return f.isSmallMetricDistance(this.xLength())}get isAlmostZeroY(){return f.isSmallMetricDistance(this.yLength())}containsXY(t,e){return t>=this.low.x&&e>=this.low.y&&t<=this.high.x&&e<=this.high.y}containsPoint(t){return this.containsXY(t.x,t.y)}containsRange(t){return t.low.x>=this.low.x&&t.low.y>=this.low.y&&t.high.x<=this.high.x&&t.high.y<=this.high.y}intersectsRange(t){return!(this.low.x>t.high.x||this.low.y>t.high.y||t.low.x>this.high.x||t.low.y>this.high.y)}distanceToPoint(t){return this.isNull?Rt._EXTREME_POSITIVE:Math.min(f.hypotenuseXY(G.coordinateToRangeAbsoluteDistance(t.x,this.low.x,this.high.x),G.coordinateToRangeAbsoluteDistance(t.y,this.low.y,this.high.y)),Rt._EXTREME_POSITIVE)}distanceToRange(t){return Math.min(f.hypotenuseXY(G.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,t.low.x,t.high.x),G.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,t.low.y,t.high.y)),Rt._EXTREME_POSITIVE)}extendXY(t,e){t<this.low.x&&(this.low.x=t),t>this.high.x&&(this.high.x=t),e<this.low.y&&(this.low.y=e),e>this.high.y&&(this.high.y=e)}extendTransformedXY(t,e,n){const i=t.multiplyComponentXYZ(0,e,n,0),s=t.multiplyComponentXYZ(1,e,n,0);this.extendXY(i,s)}extendPoint(t){this.extendXY(t.x,t.y)}extendRange(t){Rt.isNull(t)||(this.extendXY(t.low.x,t.low.y),this.extendXY(t.high.x,t.high.y))}intersect(t,e){return this.intersectsRange(t)?Rt.createXYXY(Math.max(this.low.x,t.low.x),Math.max(this.low.y,t.low.y),Math.min(this.high.x,t.high.x),Math.min(this.high.y,t.high.y),e):Rt.createNull(e)}union(t,e){return this.isNull?Rt.createFrom(t,e):Rt.isNull(t)?this.clone(e):Rt.createXYXY(Math.min(this.low.x,t.low.x),Math.min(this.low.y,t.low.y),Math.max(this.high.x,t.high.x),Math.max(this.high.y,t.high.y),e)}scaleAboutCenterInPlace(t){if(!this.isNull){t=Math.abs(t);const e=.5*(this.low.x+this.high.x),n=.5*(this.low.y+this.high.y);this.high.x=f.interpolate(e,t,this.high.x),this.high.y=f.interpolate(n,t,this.high.y),this.low.x=f.interpolate(e,t,this.low.x),this.low.y=f.interpolate(n,t,this.low.y)}}expandInPlace(t){this.setDirect(this.low.x-t,this.low.y-t,this.high.x+t,this.high.y+t,!0)}worldToLocal(t,e){const n=G.npcScaleFactor(this.low.x,this.high.x),i=G.npcScaleFactor(this.low.y,this.high.y);if(!(n===0||i===0))return D.create((t.x-this.low.x)*n,(t.y-this.low.y)*i,e)}}class X{_origin;_matrix;constructor(t,e){this._origin=t,this._matrix=e}static _identity;static get identity(){return this._identity===void 0&&(this._identity=X.createIdentity(),this._identity.freeze()),this._identity}freeze(){return this._origin.freeze(),this._matrix.freeze(),Object.freeze(this)}setFrom(t){this._origin.setFrom(t._origin),this._matrix.setFrom(t._matrix)}setIdentity(){this._origin.setZero(),this._matrix.setIdentity()}setFromJSON(t){if(t){if(t instanceof Object&&t.origin&&t.matrix){this._origin.setFromJSON(t.origin),this._matrix.setFromJSON(t.matrix);return}if(f.isArrayOfNumberArray(t,3,4)){this._matrix.setRowValues(t[0][0],t[0][1],t[0][2],t[1][0],t[1][1],t[1][2],t[2][0],t[2][1],t[2][2]),this._origin.set(t[0][3],t[1][3],t[2][3]);return}if(f.isNumberArray(t,12)){this._matrix.setRowValues(t[0],t[1],t[2],t[4],t[5],t[6],t[8],t[9],t[10]),this._origin.set(t[3],t[7],t[11]);return}}this.setIdentity()}isAlmostEqual(t){return this===t||this.origin.isAlmostEqual(t.origin)&&this.matrix.isAlmostEqual(t.matrix)}isAlmostEqualAllowZRotation(t){return this._origin.isAlmostEqual(t._origin)&&this._matrix.isAlmostEqualAllowZRotation(t._matrix)}toRows(){return[[this._matrix.coffs[0],this._matrix.coffs[1],this._matrix.coffs[2],this._origin.x],[this._matrix.coffs[3],this._matrix.coffs[4],this._matrix.coffs[5],this._origin.y],[this._matrix.coffs[6],this._matrix.coffs[7],this._matrix.coffs[8],this._origin.z]]}toJSON(){return this.toRows()}static fromJSON(t){const e=X.createIdentity();return e.setFromJSON(t),e}clone(t){return t?(t._matrix.setFrom(this._matrix),t._origin.setFrom(this._origin),t):new X(y.createFrom(this._origin),this._matrix.clone())}cloneRigid(t=mt.XYZ){const e=C.createRigidFromMatrix3d(this.matrix,t);if(e)return new X(this.origin.cloneAsPoint3d(),e)}static createRefs(t,e,n){return t||(t=y.createZero()),n?(n._origin=t,n._matrix=e,n):new X(t,e)}static createRowValues(t,e,n,i,s,r,o,a,c,l,d,h,g){return g?(g._origin.set(i,a,h),g._matrix.setRowValues(t,e,n,s,r,o,c,l,d),g):new X(y.create(i,a,h),C.createRowValues(t,e,n,s,r,o,c,l,d))}static createZero(t){return X.createRowValues(0,0,0,0,0,0,0,0,0,0,0,0,t)}static createTranslationXYZ(t=0,e=0,n=0,i){return X.createRefs(P.create(t,e,n),C.createIdentity(),i)}static createTranslation(t,e){return X.createRefs(t,C.createIdentity(),e)}get matrix(){return this._matrix}get origin(){return this._origin}getOrigin(){return y.createFrom(this._origin)}getTranslation(){return P.createFrom(this._origin)}getMatrix(){return this._matrix.clone()}get isIdentity(){return this._matrix.isIdentity&&this._origin.isAlmostZero}static createIdentity(t){return t?(t._origin.setZero(),t._matrix.setIdentity(),t):X.createRefs(y.createZero(),C.createIdentity())}static createOriginAndMatrix(t,e,n){return n?(n._origin.setFromPoint3d(t),n._matrix.setFrom(e),n):X.createRefs(t?t.cloneAsPoint3d():y.createZero(),e===void 0?C.createIdentity():e.clone(),n)}setOriginAndMatrixColumns(t,e,n,i){t!==void 0&&this._origin.setFrom(t),this._matrix.setColumns(e,n,i)}static createOriginAndMatrixColumns(t,e,n,i,s){return s?s.setOriginAndMatrixColumns(t,e,n,i):s=X.createRefs(P.createFrom(t),C.createColumns(e,n,i)),s}static createRigidFromOriginAndColumns(t,e,n,i,s){const r=C.createRigidFromColumns(e,n,i,s?._matrix);if(r)return s?(s._origin.setFrom(t),s):X.createRefs(t?.cloneAsPoint3d(),r)}static createRigidFromOriginAndVector(t,e,n=mt.ZXY,i){const s=C.createRigidHeadsUp(e,n,i?._matrix);if(s)return i?(i._origin.setFrom(t),i):X.createRefs(t?.cloneAsPoint3d(),s)}static createFixedPointAndMatrix(t,e,n){if(t){const i=C.xyzMinusMatrixTimesXYZ(t,e,t);return X.createRefs(i,e.clone(),n)}return X.createRefs(void 0,e.clone())}static createMatrixPickupPutdown(t,e,n,i){const s=C.xyzMinusMatrixTimesXYZ(n,t,e);return X.createRefs(s,t.clone(),i)}static createScaleAboutPoint(t,e,n){const i=C.createScale(e,e,e),s=C.xyzMinusMatrixTimesXYZ(t,i,t);return X.createRefs(s,i,n)}static createFlattenAlongVectorToPlane(t,e,n){const i=C.createFlattenAlongVectorToPlane(t,n);if(i!==void 0)return X.createFixedPointAndMatrix(e,i)}multiplyPoint2d(t,e){return C.xyPlusMatrixTimesXY(this._origin,this._matrix,t,e)}multiplyPoint3d(t,e){return C.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,t,e)}multiplyXYAndZInPlace(t){return C.xyzPlusMatrixTimesXYZInPlace(this._origin,this._matrix,t)}multiplyXYZ(t,e,n=0,i){return C.xyzPlusMatrixTimesCoordinates(this._origin,this._matrix,t,e,n,i)}multiplyComponentXYZ(t,e,n,i=0){const s=this._matrix.coffs,r=3*t;return this.origin.at(t)+s[r]*e+s[r+1]*n+s[r+2]*i}multiplyComponentXYZW(t,e,n,i,s){const r=this._matrix.coffs,o=3*t;return this.origin.at(t)*s+r[o]*e+r[o+1]*n+r[o+2]*i}multiplyXYZW(t,e,n,i,s){return C.xyzPlusMatrixTimesWeightedCoordinates(this._origin,this._matrix,t,e,n,i,s)}multiplyXYZWToFloat64Array(t,e,n,i,s){return C.xyzPlusMatrixTimesWeightedCoordinatesToFloat64Array(this._origin,this._matrix,t,e,n,i,s)}multiplyXYZToFloat64Array(t,e,n,i){return C.xyzPlusMatrixTimesCoordinatesToFloat64Array(this._origin,this._matrix,t,e,n,i)}multiplyTransposeXYZW(t,e,n,i,s){const r=this._matrix.coffs,o=this._origin;return Z.create(t*r[0]+e*r[3]+n*r[6],t*r[1]+e*r[4]+n*r[7],t*r[2]+e*r[5]+n*r[8],t*o.x+e*o.y+n*o.z+i,s)}multiplyPoint3dArrayInPlace(t){let e;for(e of t)C.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,e,e)}multiplyPoint3dArrayArrayInPlace(t){for(const e of t)this.multiplyPoint3dArrayInPlace(e)}multiplyInversePoint3d(t,e){return this._matrix.multiplyInverseXYZAsPoint3d(t.x-this._origin.x,t.y-this._origin.y,t.z-this._origin.z,e)}multiplyInversePoint3dAsPoint2d(t,e){return this._matrix.multiplyInverseXYZAsPoint2d(t.x-this._origin.x,t.y-this._origin.y,t.z-this._origin.z,e)}multiplyInversePoint4d(t,e){const n=t.w;return this._matrix.multiplyInverseXYZW(t.x-n*this.origin.x,t.y-n*this.origin.y,t.z-n*this.origin.z,n,e)}multiplyInverseXYZ(t,e,n,i){return this._matrix.multiplyInverseXYZAsPoint3d(t-this._origin.x,e-this._origin.y,n-this._origin.z,i)}computeCachedInverse(t=!0){return this._matrix.computeCachedInverse(t)}static matchArrayLengths(t,e,n){const i=t.length,s=e.length;if(i>s)for(let r=s;r<i;r++)e.push(n());else s>i&&(e.length=i);return i}multiplyInversePoint3dArray(t,e){if(!this._matrix.computeCachedInverse(!0))return;const n=this.origin.x,i=this.origin.y,s=this.origin.z;e||(e=[]);const r=X.matchArrayLengths(t,e,()=>y.createZero());for(let o=0;o<r;o++)this._matrix.multiplyInverseXYZAsPoint3d(t[o].x-n,t[o].y-i,t[o].z-s,e[o]);return e}multiplyInversePoint3dArrayInPlace(t){if(!this._matrix.computeCachedInverse(!0))return!1;for(const e of t)this._matrix.multiplyInverseXYZAsPoint3d(e.x-this.origin.x,e.y-this.origin.y,e.z-this.origin.z,e);return!0}multiplyPoint2dArray(t,e){if(e){const n=X.matchArrayLengths(t,e,()=>D.createZero());for(let i=0;i<n;i++)C.xyPlusMatrixTimesXY(this._origin,this._matrix,t[i],e[i]);return e}e=[];for(const n of t)e.push(C.xyPlusMatrixTimesXY(this._origin,this._matrix,n));return e}multiplyPoint3dArray(t,e){if(e){const n=X.matchArrayLengths(t,e,()=>y.createZero());for(let i=0;i<n;i++)C.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,t[i],e[i]);return e}e=[];for(const n of t)e.push(C.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,n));return e}multiplyVector(t,e){return this._matrix.multiplyVector(t,e)}multiplyVectorInPlace(t){this._matrix.multiplyVectorInPlace(t)}multiplyVectorXYZ(t,e,n,i){return this._matrix.multiplyXYZ(t,e,n,i)}setMultiplyTransformTransform(t,e){C.xyzPlusMatrixTimesXYZ(t._origin,t._matrix,e._origin,this._origin),t._matrix.multiplyMatrixMatrix(e._matrix,this._matrix)}multiplyTransformTransform(t,e){return e?(e.setMultiplyTransformTransform(this,t),e):X.createRefs(C.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,t._origin),this._matrix.multiplyMatrixMatrix(t._matrix))}multiplyTransformMatrix3d(t,e){return e?(this._matrix.multiplyMatrixMatrix(t,e._matrix),e._origin.setFrom(this._origin),e):X.createRefs(this._origin.cloneAsPoint3d(),this._matrix.multiplyMatrixMatrix(t))}multiplyRange(t,e){if(t.isNull)return t.clone(e);const n=t.low.x,i=t.low.y,s=t.low.z,r=t.high.x,o=t.high.y,a=t.high.z;return e=J.createNull(e),e.extendTransformedXYZ(this,n,i,s),e.extendTransformedXYZ(this,r,i,s),e.extendTransformedXYZ(this,n,o,s),e.extendTransformedXYZ(this,r,o,s),e.extendTransformedXYZ(this,n,i,a),e.extendTransformedXYZ(this,r,i,a),e.extendTransformedXYZ(this,n,o,a),e.extendTransformedXYZ(this,r,o,a),e}inverse(t){const e=this._matrix.inverse(t?t._matrix:void 0);if(e)return t?(e.multiplyXYZ(-this._origin.x,-this._origin.y,-this._origin.z,t._origin),t):X.createRefs(e.multiplyXYZ(-this._origin.x,-this._origin.y,-this._origin.z),e)}static initFromRange(t,e,n,i){const s=e.minus(t);s.x===0&&(s.x=1),s.y===0&&(s.y=1),s.z===0&&(s.z=1);const r=new C;if(n&&(C.createScale(s.x,s.y,s.z,r),X.createOriginAndMatrix(t,r,n)),i){const o=new y(-t.x/s.x,-t.y/s.y,-t.z/s.z);C.createScale(1/s.x,1/s.y,1/s.z,r),X.createOriginAndMatrix(o,r,i)}}}class ht extends Cs{_origin;_normal;constructor(t,e){super(),this._origin=t,this._normal=e}static _create(t,e,n,i,s,r){return new ht(y.create(t,e,n),P.create(i,s,r))}static createXYPlane(t){return t?ht._create(t.x,t.y,t.z,0,0,1):ht._create(0,0,0,0,0,1)}static createYZPlane(t){return t?ht._create(t.x,t.y,t.z,1,0,0):ht._create(0,0,0,1,0,0)}static createZXPlane(t){return t?ht._create(t.x,t.y,t.z,0,1,0):ht._create(0,0,0,0,1,0)}static create(t,e,n){if(n)return e.normalize(n._normal)===void 0?void 0:(t.clone(n._origin),n);const i=e.normalize();if(i!==void 0)return new ht(t.clone(),i)}static createFrom(t,e){if(t instanceof ht)return t.clone(e);if(e)return t.getUnitNormal(e._normal)===void 0?void 0:(t.getAnyPointOnPlane(e._origin),e);const n=t.getUnitNormal();if(n===void 0)return;const i=t.getAnyPointOnPlane();return new ht(i,n)}static createXYZUVW(t,e,n,i,s,r,o){const a=f.hypotenuseXYZ(i,s,r);if(!(a<=f.smallFraction))return o?(o._origin.set(t,e,n),o._normal.set(i/a,s/a,r/a),o):new ht(y.create(t,e,n),P.create(i/a,s/a,r/a))}static createOriginAndTargetXY(t,e,n){const i=e.x-t.x,s=e.y-t.y;return this.createXYZUVW(t.x,t.y,0,s,-i,0,n)}static createXYAngle(t,e,n,i){return i?(i._origin.set(t,e,0),i._normal.set(n.cos(),n.sin(),0),i):new ht(y.create(t,e,0),P.create(n.cos(),n.sin()))}static createPointPointVectorInPlane(t,e,n){const i=n.crossProductStartEnd(t,e);if(i.tryNormalizeInPlace())return new ht(t,i)}static createOriginAndTargets(t,e,n){const i=t.crossProductToPoints(e,n);if(i.tryNormalizeInPlace())return new ht(t,i)}static createOriginAndVectors(t,e,n){const i=e.crossProduct(n);if(i.tryNormalizeInPlace())return new ht(t,i)}isAlmostEqual(t){return this._origin.isAlmostEqual(t._origin)&&this._normal.isAlmostEqual(t._normal)}setFromJSON(t){t?(this._origin.setFromJSON(t.origin),this._normal.setFromJSON(t.normal)):(this._origin.set(0,0,0),this._normal.set(0,0,1))}toJSON(){return{origin:this._origin.toJSON(),normal:this._normal.toJSON()}}static fromJSON(t){const e=ht.createXYPlane();return e.setFromJSON(t),e}getOriginRef(){return this._origin}getNormalRef(){return this._normal}getLocalToWorld(){const t=C.createRigidHeadsUp(this._normal,mt.ZXY);return X.createRefs(this._origin.clone(),t)}getProjectionToPlane(){const t=C.createIdentity();return t.addScaledOuterProductInPlace(this._normal,this._normal,-1),t.markSingular(),X.createFixedPointAndMatrix(this._origin,t)}set(t,e){this._origin.setFrom(t),this._normal.setFrom(e)}clone(t){return t?(t.set(this._origin,this._normal),t):new ht(this._origin.clone(),this._normal.clone())}cloneTransformed(t,e=!1){const n=this.clone();if(e){if(t.multiplyInversePoint3d(n._origin,n._origin),t.matrix.multiplyTransposeVector(n._normal,n._normal)!==void 0&&n._normal.normalizeInPlace())return n}else if(t.multiplyPoint3d(n._origin,n._origin),t.matrix.multiplyInverseTranspose(n._normal,n._normal)!==void 0&&n._normal.normalizeInPlace())return n}setFrom(t){this.set(t._origin,t._normal)}altitude(t){return this._normal.dotProductStartEnd(this._origin,t)}altitudeXY(t,e){return(t-this._origin.x)*this._normal.x+(e-this._origin.y)*this._normal.y}normalX(){return this._normal.x}normalY(){return this._normal.y}normalZ(){return this._normal.z}getUnitNormal(t){return this._normal.clone(t)}getAnyPointOnPlane(t){return this._origin.clone(t)}weightedAltitude(t){return this._normal.dotProductStart3dEnd4d(this._origin,t)}altitudeToPoint(t,e){return this._origin.plusScaled(this._normal,t,e)}velocityXYZ(t,e,n){return this._normal.dotProductXYZ(t,e,n)}velocity(t){return this._normal.dotProduct(t)}altitudeXYZ(t,e,n){return this._normal.dotProductStartEndXYZ(this._origin,t,e,n)}altitudeXYZW(t,e,n,i){return this._normal.dotProductStartEndXYZW(this._origin,t,e,n,i)}projectPointToPlane(t,e){return this.projectXYZToPlane(t.x,t.y,t.z,e)}projectXYZToPlane(t,e,n,i){const s=-this._normal.dotProductStartEndXYZ(this._origin,t,e,n);return y.create(t+s*this._normal.x,e+s*this._normal.y,n+s*this._normal.z,i)}isPointInPlane(t,e=f.smallMetricDistance){const n=this._normal.dotProductStartEnd(this._origin,t);return Math.abs(n)<=e}}var Ct;(function(u){u[u.isolated=0]="isolated",u[u.isolatedAtVertex=1]="isolatedAtVertex",u[u.intervalStart=10]="intervalStart",u[u.intervalInterior=11]="intervalInterior",u[u.intervalEnd=12]="intervalEnd"})(Ct||(Ct={}));var Me;(function(u){u[u.error=0]="error",u[u.success=1]="success",u[u.stoppedAtBoundary=2]="stoppedAtBoundary"})(Me||(Me={}));function ks(u,t){return u?u.clone(t):void 0}class Y{curve;ray;fraction;intervalRole;point;vectorInCurveLocationDetail;a;childDetail;curveSearchStatus;fraction1;point1;pointQ;constructor(){this.pointQ=y.createZero(),this.fraction=0,this.point=y.createZero(),this.a=0}setIntervalRole(t){this.intervalRole=t}captureFractionPoint(t,e){this.fraction=t,this.point=e}captureFraction1Point1(t,e){this.fraction1=t,this.point1=e}get hasFraction1(){return this.fraction1!==void 0}isInterval(){return this.fraction1!==void 0&&this.point1!==void 0}get isIsolated(){return this.intervalRole===void 0||this.intervalRole===Ct.isolated||this.intervalRole===Ct.isolatedAtVertex}get fractionDelta(){return this.fraction1!==void 0?this.fraction1-this.fraction:0}collapseToEnd(){this.fraction1!==void 0&&(this.fraction=this.fraction1),this.point1&&(this.point=this.point1),this.collapseToStart()}collapseToStart(){this.fraction1=void 0,this.point1=void 0}clone(t){return t===this||(t=t||new Y,t.curve=this.curve,t.fraction=this.fraction,t.fraction1=this.fraction1,t.point1=ks(this.point1,t.point1),t.point.setFromPoint3d(this.point),t.vectorInCurveLocationDetail=ks(this.vectorInCurveLocationDetail,t.vectorInCurveLocationDetail),t.a=this.a,t.childDetail=ks(this.childDetail,t.childDetail),t.curveSearchStatus=this.curveSearchStatus),t}setFP(t,e,n,i=0){this.fraction=t,this.point.setFromPoint3d(e),this.vectorInCurveLocationDetail=ks(n,this.vectorInCurveLocationDetail),this.a=i}setFR(t,e,n=0){return this.setFP(t,e.origin,e.direction,n)}setCurve(t){this.curve=t}setDistanceTo(t){this.a=this.point.distance(t)}static create(t,e){return e=e||new Y,e.curve=t,e}static createCurveFractionPoint(t,e,n,i){return i=i||new Y,i.curve=t,i.fraction=e,i.point.setFromPoint3d(n),i.vectorInCurveLocationDetail=void 0,i.a=0,i.childDetail=void 0,i.curveSearchStatus=void 0,i}static createRayFractionPoint(t,e,n,i){return i=i||new Y,i.fraction=e,i.ray=t,i.point.setFromPoint3d(n),i}static createCurveFractionPointDistanceCurveSearchStatus(t,e,n,i,s,r){return r=r||new Y,r.curve=t,r.fraction=e,r.point.setFromPoint3d(n),r.vectorInCurveLocationDetail=void 0,r.a=i,r.childDetail=void 0,r.curveSearchStatus=s,r}static createConditionalMoveSignedDistance(t,e,n,i,s,r){let o=s,a=Me.success;return!t&&!f.isIn01(i)&&(i<0?(o=-e.curveLengthBetweenFractions(n,0),i=0,a=Me.stoppedAtBoundary):i>1&&(i=1,o=e.curveLengthBetweenFractions(n,1),a=Me.stoppedAtBoundary)),r=r||new Y,r.curve=e,r.fraction=i,e.fractionToPoint(i,r.point),r.vectorInCurveLocationDetail=void 0,r.a=o,r.childDetail=void 0,r.curveSearchStatus=a,r}static createCurveEvaluatedFraction(t,e,n){return n=n||new Y,n.curve=t,n.fraction=e,t.fractionToPoint(e,n.point),n.vectorInCurveLocationDetail=void 0,n.a=0,n.childDetail=void 0,n.curveSearchStatus=void 0,n}static createCurveEvaluatedFractionPointAndDerivative(t,e,n){n=n||new Y,n.curve=t,n.fraction=e;const i=t.fractionToPointAndDerivative(e);return n.point.setFromPoint3d(i.origin),n.vectorInCurveLocationDetail=i.direction,n.a=0,n.childDetail=void 0,n.curveSearchStatus=void 0,n}static createCurveEvaluatedFractionFraction(t,e,n,i){return i=i||new Y,i.curve=t,i.fraction=e,t.fractionToPoint(e,i.point),i.fraction1=n,i.point1=t.fractionToPoint(n,i.point1),i.vectorInCurveLocationDetail=void 0,i.a=0,i.childDetail=void 0,i.curveSearchStatus=void 0,i}static createCurveFractionPointDistance(t,e,n,i,s){return s=s||new Y,s.curve=t,s.fraction=e,s.point.setFromPoint3d(n),s.vectorInCurveLocationDetail=void 0,s.a=i,s.childDetail=void 0,s.curveSearchStatus=void 0,s}updateIfCloserCurveFractionPointDistance(t,e,n,i){return this.a<i?!1:(Y.createCurveFractionPointDistance(t,e,n,i,this),!0)}swapFractionsAndPoints(){if(this.fraction1!==void 0){const t=this.fraction;this.fraction=this.fraction1,this.fraction1=t}if(this.point1!==void 0){const t=this.point;this.point=this.point1,this.point1=t}}inverseInterpolateFraction(t,e=0){if(this.fraction1===void 0)return e;const n=f.inverseInterpolate01(this.fraction,this.fraction1,t);return n===void 0?e:n}static chooseSmallerA(t,e){return t?e?t.a<=e.a?t:e:t:e}isSameCurveAndFraction(t,e){return this.curve===t.curve&&f.isAlmostEqualNumber(this.fraction,t.fraction,e)}tryTransformInPlace(t){return this.curve&&!this.curve.tryTransformInPlace(t)||(this.ray&&this.ray.transformInPlace(t),this.curve?this.curve.fractionToPoint(this.fraction,this.point):t.multiplyXYAndZInPlace(this.point),this.vectorInCurveLocationDetail&&t.multiplyVectorInPlace(this.vectorInCurveLocationDetail),this.childDetail&&this.childDetail!==this&&!this.childDetail.tryTransformInPlace(t))?!1:(this.point1&&(this.curve&&this.fraction1?this.curve.fractionToPoint(this.fraction1,this.point1):t.multiplyXYAndZInPlace(this.point1)),!0)}}var Dn;(function(u){u[u.Intersection=0]="Intersection",u[u.PerpendicularChord=1]="PerpendicularChord",u[u.CoincidentGeometry=2]="CoincidentGeometry",u[u.ParallelGeometry=3]="ParallelGeometry"})(Dn||(Dn={}));class Ot{detailA;detailB;approachType;constructor(t,e){this.detailA=t||new Y,this.detailB=e||new Y}static createCapture(t,e,n){return n=n||new Ot,n.detailA=t,n.detailB=e,n}static createCaptureOptionalReverse(t,e,n,i){return i=i||new Ot,i.detailA=t,i.detailB=e,i}clone(t){return t=t||new Ot,t.detailA=this.detailA.clone(),t.detailB=this.detailB.clone(),t.approachType=this.approachType,t}swapDetails(){const t=this.detailA;this.detailA=this.detailB,this.detailB=t}static removeAdjacentDuplicates(t,e=0){return t.flatMap((n,i,s)=>i>=e&&i>0&&!n.detailA.hasFraction1&&!n.detailB.hasFraction1&&n.detailA.isSameCurveAndFraction(s[i-1].detailA)&&n.detailB.isSameCurveAndFraction(s[i-1].detailB)?[]:[n])}tryTransformInPlace(t){return this.detailA.tryTransformInPlace(t)&&this.detailB.tryTransformInPlace(t)}static comparePairsByFractions(t=f.smallFraction,e=f.smallMetricDistance,n=!1,i=!1){return(s,r)=>{const o=s.detailA.curve,a=s.detailB.curve;let c=s.detailA.fraction,l=s.detailB.fraction,d=r.detailA.fraction,h=r.detailB.fraction;i&&(o?.isPhysicallyClosedCurve(e,n)&&(f.isAlmostEqualEitherNumber(s.detailA.fraction,0,1,t)&&(c=0),f.isAlmostEqualEitherNumber(r.detailA.fraction,0,1,t)&&(d=0)),a?.isPhysicallyClosedCurve(e,n)&&(f.isAlmostEqualEitherNumber(s.detailB.fraction,0,1,t)&&(l=0),f.isAlmostEqualEitherNumber(r.detailB.fraction,0,1,t)&&(h=0)));const g=f.isAlmostEqualNumber(c,d,t);return g&&f.isAlmostEqualNumber(l,h,t)||(n?s.detailA.point.isAlmostEqualXY(r.detailA.point,e):s.detailA.point.isAlmostEqual(r.detailA.point,e))&&(n?s.detailB.point.isAlmostEqualXY(r.detailB.point,e):s.detailB.point.isAlmostEqual(r.detailB.point,e))?0:g?l-h:c-d}}static comparePairsByPoints(t=f.smallMetricDistance,e=!1){return(n,i)=>{const s=e?f.compareXY(t):f.compareXYZ(t),r=s(n.detailA.point,i.detailA.point),o=s(n.detailB.point,i.detailB.point),a=r===0;return a&&o===0?0:a?o:r}}}class Ft{_data;_inUse;_growthFactor;constructor(t=8,e){this._data=new Float64Array(t),this._inUse=0,this._growthFactor=e!==void 0&&e>=1?e:1.5}copyData(t,e,n){let i=n??0;if(i<0&&(i=0),i>=this._data.length)return{count:0,offset:0};let s=e??t.length;return s>0&&(s>t.length&&(s=t.length),i+s>this._data.length&&(s=this._data.length-i)),s<=0?{count:0,offset:0}:(s===t.length?this._data.set(t,i):t instanceof Float64Array?this._data.set(t.subarray(0,s),i):this._data.set(t.slice(0,s),i),{count:s,offset:i})}static create(t){const e=new Ft(t.length);return e.copyData(t),e._inUse=t.length,e}static compare(t,e){return t-e}clone(t=!1){const e=new Ft(t?this.capacity():this._inUse);return e.copyData(this._data,this._inUse),e._inUse=this._inUse,e}get length(){return this._inUse}setAtUncheckedIndex(t,e){this._data[t]=e}move(t,e){this._data[e]=this._data[t]}swap(t,e){const n=this._data[t];this._data[t]=this._data[e],this._data[e]=n}push(t){this.ensureCapacity(this._inUse+1),this._data[this._inUse]=t,this._inUse++}pushArray(t){this.ensureCapacity(this._inUse+t.length),this.copyData(t,t.length,this._inUse),this._inUse+=t.length}pushBlockCopy(t,e){t>=0&&t<this._inUse&&e>0&&t+e<=this._inUse&&(this.ensureCapacity(this._inUse+e),this._data.copyWithin(this._inUse,t,t+e),this._inUse+=e)}clear(){this._inUse=0}capacity(){return this._data.length}ensureCapacity(t,e=!0){if(t>this.capacity()){e&&(t*=this._growthFactor);const n=this._data;this._data=new Float64Array(t),this.copyData(n,this._inUse)}}resize(t,e=0){t>=0&&t<this._inUse?this._inUse=t:t>this._inUse&&(this.ensureCapacity(t,!1),this._data.fill(e,this._inUse),this._inUse=t)}pop(){this._inUse>0&&this._inUse--}isIndexValid(t){return t>=0&&t<this.length}atUncheckedIndex(t){return this._data[t]}atIndex(t){if(this.isIndexValid(t))return this.atUncheckedIndex(t)}front(){return this._data[0]}back(){return this._data[this._inUse-1]}reassign(t,e){this._data[t]=e}sort(t=(e,n)=>Ft.compare(e,n)){for(let e=0;e<this._inUse;e++)for(let n=e+1;n<this._inUse;n++){const i=this._data[e],s=this._data[n];t(i,s)>0&&(this._data[e]=s,this._data[n]=i)}}restrictToInterval(t,e){const n=this._data,i=n.length;let s=0,r=0;for(let o=0;o<i;o++)r=n[o],r>=t&&r<=e&&(n[s++]=r);this._inUse=s}compressAdjacentDuplicates(t=0){const e=this._data,n=this._inUse;if(n===0)return;let i=1,s=e[0],r;for(let o=1;o<n;o++)r=e[o],Math.abs(r-s)>t&&(e[i++]=r,s=r);this._inUse=i}reverseInPlace(){this._data.reverse()}}class Fs{coffs;constructor(t=0,e=0,n=0){this.coffs=[t,e,n]}static solveQuadratic(t,e,n){const i=f.conditionalDivideFraction(e,t),s=f.conditionalDivideFraction(n,t);if(i!==void 0&&s!==void 0){const o=i*i-4*s;if(o>0){const c=Math.sqrt(o);return[.5*(-i-c),.5*(-i+c)]}if(o<0)return;const a=-.5*i;return[a,a]}const r=f.conditionalDivideFraction(-n,e);if(r!==void 0)return[r]}addConstant(t){this.coffs[0]+=t}addSquaredLinearTerm(t,e,n=1){this.coffs[0]+=n*(t*t),this.coffs[1]+=n*(2*t*e),this.coffs[2]+=n*(e*e)}realRoots(){const t=Fs.solveQuadratic(this.coffs[2],this.coffs[1],this.coffs[0]);if(t&&t.length>1&&t[0]>t[1]){const e=t[0];t[0]=t[1],t[1]=e}return t}evaluate(t){return this.coffs[0]+t*(this.coffs[1]+t*this.coffs[2])}evaluateDerivative(t){return this.coffs[1]+2*t*this.coffs[2]}tryGetVertexFactorization(){const t=f.conditionalDivideFraction(-this.coffs[1],2*this.coffs[2]);if(t!==void 0){const e=this.evaluate(t);return{c:this.coffs[2],x0:t,y0:e}}}static fromRootsAndC2(t,e,n=1){return new Fs(n*t*e,-n*(t+e),n)}}class Xn{static _EQN_EPS=1e-9;static _safeDivideFactor=1e-14;static isZero(t){return Math.abs(t)<this._EQN_EPS}static isSmallRatio(t,e,n=1e-9,i=8e-16){return Math.abs(t)<=n||Math.abs(t)<i*Math.abs(e)}static cbrt(t){return t>0?Math.pow(t,1/3):t<0?-Math.pow(-t,1/3):0}static safeDivide(t,e,n,i=0,s){return Math.abs(n)>this._safeDivideFactor*Math.abs(e)?(t[s]=e/n,!0):(t[s]=i,!1)}static checkRootProximity(t,e){return e===0?t.atUncheckedIndex(e)<t.atUncheckedIndex(e+1):e>0&&e+1<t.length?t.atUncheckedIndex(e)>t.atUncheckedIndex(e-1)&&t.atUncheckedIndex(e)<t.atUncheckedIndex(e+1):t.atUncheckedIndex(e)>t.atUncheckedIndex(e-1)}static newtonMethodAdjustment(t,e,n){let i=t[n],s=0;for(let r=n-1;r>=0;r--)s=i+e*s,i=t[r]+e*i;if(Math.abs(s)>=1e-14*(1+Math.abs(e)))return i/s}static improveRoots(t,e,n,i){for(let r=0;r<n.length;r++){let o=this.newtonMethodAdjustment(t,n.atUncheckedIndex(r),e);if(o===void 0||o===0)continue;const a=n.atUncheckedIndex(r);let c=0,l=0;for(;o!==void 0&&o!==0&&c<12;){if(Math.abs(o)<1e-10*(1+Math.abs(n.atUncheckedIndex(r)))){if(++l>1)break}else l=0;const d=n.atUncheckedIndex(r)-o;if(n.reassign(r,d),i&&!this.checkRootProximity(n,r)){n.reassign(r,a);break}o=this.newtonMethodAdjustment(t,n.atUncheckedIndex(r),e),c++}}}static appendSolution(t,e){t!==void 0&&e.push(t)}static append2Solutions(t,e,n){n.push(t),n.push(e)}static appendLinearRoot(t,e,n){Xn.appendSolution(f.conditionalDivideFraction(-t,e),n)}static mostDistantFromMean(t){if(!t||t.length===0)return 0;let e=0;for(let s=0;s<t.length;s++)e+=t.atUncheckedIndex(s);e/=t.length;let n=0,i=t.atUncheckedIndex(0);for(let s=0;s<t.length;s++){const r=Math.abs(t.atUncheckedIndex(s)-e);r>n&&(n=r,i=t.atUncheckedIndex(s))}return i}static appendQuadraticRoots(t,e){const n=f.conditionalDivideFraction(1,t[2]);if(!n){this.appendLinearRoot(t[0],t[1],e);return}const i=.5*t[1]*n,s=t[0]*n,r=i*i-s;if(this.isZero(r)){this.appendSolution(-i,e);return}else{if(r<0)return;if(r>0){const o=Math.sqrt(r);this.append2Solutions(o-i,-o-i,e);return}}}static addConstant(t,e){for(let n=0;n<e.length;n++)e.reassign(n,e.atUncheckedIndex(n)+t)}static signedCubeRoot(t){return t>=0?Math.pow(t,1/3):-Math.pow(-t,1/3)}static appendFullCubicSolutions(t,e,n,i,s){const r=e*e-3*t*n,o=t*t,a=r/(9*o),c=-e/(3*t),l=i+c*(n+c*(e+c*t)),d=l*l,h=4*t*t*a*a*a,g=d-h;if(g>0){const m=Math.sqrt(g),p=.5/t;s.push(c+this.signedCubeRoot(p*(-l+m))+this.signedCubeRoot(p*(-l-m)))}else if(g<0){let m=Math.sqrt(h);t<0&&(m=-m);const p=Math.acos(-l/m)/3,x=2*Math.sqrt(a),_=2*Math.PI/3;s.push(c+x*Math.cos(p)),s.push(c+x*Math.cos(p+_)),s.push(c+x*Math.cos(p-_))}else{const m=this.signedCubeRoot(.5*l/t),p=c+m;s.push(c-2*m),s.push(p),s.push(p)}}static appendCubicRoots(t,e){f.conditionalDivideCoordinate(1,t[3])!==void 0?(this.appendFullCubicSolutions(t[3],t[2],t[1],t[0],e),this.improveRoots(t,3,e,!1)):this.appendQuadraticRoots(t,e),e.sort()}static appendQuarticRoots(t,e){const n=new Float64Array(4);let i,s;const r=new Float64Array(1);if(!this.safeDivide(r,1,t[4],0,0)){this.appendCubicRoots(t,e);return}const o=t[3]*r[0],a=t[2]*r[0],c=t[1]*r[0],l=t[0]*r[0],d=-.25*o,h=o*o,g=-.375*h+a,m=.125*h*o-.5*o*a+c,p=-.01171875*h*h+.0625*h*a-.25*o*c+l,x=new Ft;if(this.isZero(p)){n[0]=m,n[1]=g,n[2]=0,n[3]=1,this.appendCubicRoots(n,e),e.push(0),this.addConstant(d,e);return}else{n[0]=.5*p*g-.125*m*m,n[1]=-p,n[2]=-.5*g,n[3]=1,this.appendCubicRoots(n,x);const _=this.mostDistantFromMean(x);if(i=_*_-p,s=2*_-g,this.isSmallRatio(i,p))i=0;else if(i>0)i=Math.sqrt(i);else return;if(this.isSmallRatio(s,g))s=0;else if(s>0)s=Math.sqrt(s);else return;n[0]=_-i,n[1]=m<0?-s:s,n[2]=1,this.appendQuadraticRoots(n,e),n[0]=_+i,n[1]=m<0?s:-s,n[2]=1,this.appendQuadraticRoots(n,e)}this.addConstant(d,e),e.sort(),this.improveRoots(t,4,e,!0)}static appendCosSinRadians(t,e,n,i,s){n&&n.push(t),i&&i.push(e),s&&s.push(Math.atan2(e,t))}static appendImplicitLineUnitCircleIntersections(t,e,n,i,s,r,o=1e-14){let a;const c=e*e+n*n,l=t*t;let d=0;if(o<0?a=0:a=2*o,c<=0)d=t===0?-2:-1;else{const h=-t/c,m=1-l/c;if(m<-a){const p=Math.sqrt(c),x=t<0?1/p:-1/p;this.appendCosSinRadians(e*x,n*x,i,s,r),this.appendCosSinRadians(h*e,h*n,i,s,r),d=0}else if(m<a){const p=Math.sqrt(c),x=t<0?1/p:-1/p;this.appendCosSinRadians(e*x,n*x,i,s,r),this.appendCosSinRadians(h*e,h*n,i,s,r),d=1}else{const p=Math.sqrt(m/c),x=h*e,_=h*n;this.appendCosSinRadians(x-p*n,_+p*e,i,s,r),this.appendCosSinRadians(x+p*n,_-p*e,i,s,r),d=2}}return d}}class we{static degreeKnownEvaluate(t,e,n){if(e<0)return 0;let i=t[e];for(let s=e-1;s>=0;s--)i=n*i+t[s];return i}static evaluate(t,e){const n=t.length-1;return this.degreeKnownEvaluate(t,n,e)}static accumulate(t,e,n){let i=t.length-1;const s=e.length-1;for(let r=0;r<=s;r++)t[r]+=n*e[r];for(;i>=0&&t[i]===0;)i--;return i}static zero(t){for(let e=0;e<t.length;e++)t[e]=0}}class Mi{static _smallAngle=1e-11;static S=Float64Array.from([0,2,-2]);static C=Float64Array.from([1,-2]);static W=Float64Array.from([1,-2,2]);static CW=Float64Array.from([1,-4,6,-4]);static SW=Float64Array.from([0,2,-6,8,-4]);static SC=Float64Array.from([0,2,-6,4]);static SS=Float64Array.from([0,0,4,-8,4]);static CC=Float64Array.from([1,-4,4]);static WW=Float64Array.from([1,-4,8,-8,4]);static CCMinusSS=Float64Array.from([1,-4,0,8,-4]);static solveAngles(t,e,n,i){let s=Math.abs(n),r;i.length=0;const o=this._smallAngle;for(let d=0;d<=e;d++)r=Math.abs(t[d]),r>s&&(s=r);const a=o*s;let c=e;for(;c>0&&Math.abs(t[c])<=a;)c--;const l=new Ft;if(c!==-1){if(c===0||(c===1?l.push(-t[0]/t[1]):c===2?Xn.appendQuadraticRoots(t,l):c===3?Xn.appendCubicRoots(t,l):c===4&&Xn.appendQuarticRoots(t,l)),l.length>0)for(let d=0;d<l.length;d++){const h=we.evaluate(this.S,l.atUncheckedIndex(d)),g=we.evaluate(this.C,l.atUncheckedIndex(d));i.push(Math.atan2(h,g))}c<e&&i.push(-.5*Math.PI)}return i.length>0}static _coefficientRelTolSquared=1e-24;static solveUnitCircleImplicitQuadricIntersection(t,e,n,i,s,r,o){const a=new Float64Array(5);we.zero(a);let c;const l=f.hypotenuseSquaredXYZ(i,s,r),d=f.hypotenuseSquaredXYZ(t,e,n);if(d<=Mi._coefficientRelTolSquared*l)we.accumulate(a,this.C,i),we.accumulate(a,this.S,s),we.accumulate(a,this.W,r),c=2;else if(d-2*t*n<=2*Mi._coefficientRelTolSquared*d){const m=.5*(t+n);we.accumulate(a,this.C,i),we.accumulate(a,this.S,s),we.accumulate(a,this.W,r+m),c=2}else we.accumulate(a,this.CW,i),we.accumulate(a,this.SW,s),we.accumulate(a,this.WW,r),we.accumulate(a,this.SS,n),we.accumulate(a,this.CC,t),we.accumulate(a,this.SC,e),c=4;const h=Math.max(Math.abs(t),Math.abs(n),Math.abs(e),Math.abs(i),Math.abs(s),Math.abs(r));return this.solveAngles(a,c,h,o)}static solveUnitCircleEllipseIntersection(t,e,n,i,s,r,o,a){a.length=0;const c=n*n+i*i,l=2*(n*s+i*r),d=s*s+r*r,h=2*(n*t+i*e),g=2*(s*t+r*e),m=t*t+e*e-1,p=this.solveUnitCircleImplicitQuadricIntersection(c,l,d,h,g,m,o);for(const x of o){const _=Math.cos(x),I=Math.sin(x),v=t+n*_+s*I,S=e+i*_+r*I;a.push(Math.atan2(S,v))}return p}static solveUnitCircleHomogeneousEllipseIntersection(t,e,n,i,s,r,o,a,c,l,d){d.length=0;const h=i*i+s*s-r*r,g=2*(i*o+s*a-r*c),m=o*o+a*a-c*c,p=2*(i*t+s*e-r*n),x=2*(o*t+a*e-c*n),_=t*t+e*e-n*n,I=this.solveUnitCircleImplicitQuadricIntersection(h,g,m,p,x,_,l);for(const v of l){const S=Math.cos(v),w=Math.sin(v),T=t+i*S+o*w,R=e+s*S+a*w;d.push(Math.atan2(R,T))}return I}}class Ms{a;b;c;d;constructor(t,e,n,i){this.a=t,this.b=e,this.c=n,this.d=i}evaluate(t,e){return this.a+this.b*t+e*(this.c+this.d*t)}static createUnitSquareValues(t,e,n,i){return new Ms(t,e,e,i-e-n)}static solveBilinearPair(t,e,n,i,s,r,o,a){const c=f.crossProductXYXY(t,s,n,o),l=f.crossProductXYXY(e,r,n,o)+f.crossProductXYXY(t,s,i,a),d=f.crossProductXYXY(e,r,i,a),h=Fs.solveQuadratic(d,l,c);if(h===void 0)return;const g=[];for(const m of h){const p=f.conditionalDivideFraction(-(t+e*m),n+i*m),x=f.conditionalDivideFraction(-(s+r*m),o+a*m);p!==void 0?g.push(D.create(m,p)):x!==void 0&&g.push(D.create(m,x))}return g}static solvePair(t,e,n,i){return Ms.solveBilinearPair(t.a-e,t.b,t.c,t.d,n.a-i,n.b,n.c,n.d)}}class Go{a;cosineCoff;sineCoff;constructor(t,e,n){this.a=t,this.cosineCoff=e,this.sineCoff=n}set(t,e,n){this.a=t,this.cosineCoff=e,this.sineCoff=n}evaluateRadians(t){return this.a+this.cosineCoff*Math.cos(t)+this.sineCoff*Math.sin(t)}range(t){const e=f.hypotenuseXY(this.cosineCoff,this.sineCoff);return ct.createXX(this.a-e,this.a+e,t)}rangeInStartEndRadians(t,e,n){if(A.isFullCircleRadians(e-t))return this.range(n);n=ct.createXX(this.evaluateRadians(t),this.evaluateRadians(e),n);const i=Math.atan2(this.sineCoff,this.cosineCoff),s=i+Math.PI;return at.isRadiansInStartEnd(i,t,e)&&n.extendX(this.evaluateRadians(i)),at.isRadiansInStartEnd(s,t,e)&&n.extendX(this.evaluateRadians(s)),n}rangeInSweep(t,e){return this.rangeInStartEndRadians(t.startRadians,t.endRadians,e)}referenceMinMaxRadians(){return Math.atan2(this.sineCoff,this.cosineCoff)}}class bt{static lineXYUVTransverseIntersection(t,e,n,i){const s=n.x-t.x,r=n.y-t.y,o=f.crossProductXYXY(e.x,e.y,i.x,i.y),a=f.crossProductXYXY(s,r,i.x,i.y),c=f.crossProductXYXY(s,r,e.x,e.y),l=f.conditionalDivideFraction(a,o),d=f.conditionalDivideFraction(c,o);if(l!==void 0&&d!==void 0)return{x:l,y:d}}static lineSegment2dXYTransverseIntersectionUnbounded(t,e,n,i,s){const r=e.x-t.x,o=e.y-t.y,a=i.x-n.x,c=i.y-n.y;return this.lineSegmentXYUVTransverseIntersectionUnbounded(t.x,t.y,r,o,n.x,n.y,a,c,s)}static lineSegmentXYUVTransverseIntersectionUnbounded(t,e,n,i,s,r,o,a,c){const l=this.lineXYUVTransverseIntersection({x:t,y:e},{x:n,y:i},{x:s,y:r},{x:o,y:a});return l?(c.set(l.x,l.y),!0):(c.set(0,0),!1)}static lineSegment3dXYTransverseIntersectionUnbounded(t,e,n,i,s){const r=e.x-t.x,o=e.y-t.y,a=i.x-n.x,c=i.y-n.y;return this.lineSegmentXYUVTransverseIntersectionUnbounded(t.x,t.y,r,o,n.x,n.y,a,c,s)}static lineSegmentXYUVOverlapUnbounded(t,e,n,i,s=f.smallMetricDistance){const r=s*s,o=(x,_,I)=>{const v=f.dotProductXYXY(I.x,I.y,I.x,I.y),S=f.dotProductXYXY(x.x-_.x,x.y-_.y,I.x,I.y),w=f.safeDivideFraction(S,v,0);return{f:w,p:{x:_.x+w*I.x,y:_.y+w*I.y}}},a=o(t,n,i);if(f.distanceSquaredXYXY(t.x,t.y,a.p.x,a.p.y)>r)return;const c=t.x+e.x,l=t.y+e.y,d=o({x:c,y:l},n,i);if(f.distanceSquaredXYXY(c,l,d.p.x,d.p.y)>r)return;const h=o(n,t,e);if(f.distanceSquaredXYXY(n.x,n.y,h.p.x,h.p.y)>r)return;const g=n.x+i.x,m=n.y+i.y,p=o({x:g,y:m},t,e);if(!(f.distanceSquaredXYXY(g,m,p.p.x,p.p.y)>r))return h.f>p.f&&([h.f,p.f]=[p.f,h.f]),a.f>d.f&&([a.f,d.f]=[d.f,a.f]),{f0:{x:h.f,y:a.f},f1:{x:p.f,y:d.f}}}static lineSegmentXYUVIntersectionUnbounded(t,e,n,i,s=f.smallMetricDistance){const r=this.lineSegmentXYUVOverlapUnbounded(t,e,n,i,s);if(r)return r;const o=this.lineXYUVTransverseIntersection(t,e,n,i);if(o)return{f0:o}}static lineSegment3dHXYTransverseIntersectionUnbounded(t,e,n,i,s){const r=f.tripleProduct(t.x,e.x,n.x,t.y,e.y,n.y,t.w,e.w,n.w),o=f.tripleProduct(t.x,e.x,i.x,t.y,e.y,i.y,t.w,e.w,i.w),a=f.conditionalDivideFraction(-r,o-r);if(a!==void 0){const c=f.tripleProduct(n.x,i.x,t.x,n.y,i.y,t.y,n.w,i.w,t.w),l=f.tripleProduct(n.x,i.x,e.x,n.y,i.y,e.y,n.w,i.w,e.w),d=f.conditionalDivideFraction(-c,l-c);if(d!==void 0)return Q.create(d,a,s)}}static lineSegment3dHXYClosestPointUnbounded(t,e,n){const i=e.x*t.w-t.x*e.w,s=e.y*t.w-t.y*e.w,r=f.tripleProduct(t.x,-s,n.x,t.y,i,n.y,t.w,0,n.w),o=f.tripleProduct(e.x,-s,n.x,e.y,i,n.y,e.w,0,n.w);return f.conditionalDivideFraction(-r,o-r)}static lineSegment3dXYClosestPointUnbounded(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=i*i+s*s,o=n.x-t.x,a=n.y-t.y,c=i*o+s*a;return f.conditionalDivideFraction(c,r)}static lineSegment3dClosestPointUnbounded(t,e,n){const i=e.x-t.x,s=e.y-t.y,r=e.z-t.z,o=i*i+s*s+r*r,a=n.x-t.x,c=n.y-t.y,l=n.z-t.z,d=i*a+s*c+r*l;return f.conditionalDivideFraction(d,o)}static lineSegment3dClosestApproachUnbounded(t,e,n,i,s){return this.ray3dXYZUVWClosestApproachUnbounded(t.x,t.y,t.z,e.x-t.x,e.y-t.y,e.z-t.z,n.x,n.y,n.z,i.x-n.x,i.y-n.y,i.z-n.z,s)}static ray3dXYZUVWClosestApproachUnbounded(t,e,n,i,s,r,o,a,c,l,d,h,g){const m=o-t,p=a-e,x=c-n,_=f.hypotenuseSquaredXYZ(i,s,r),I=f.hypotenuseSquaredXYZ(l,d,h),v=f.dotProductXYZXYZ(i,s,r,l,d,h),S=f.dotProductXYZXYZ(m,p,x,i,s,r),w=f.dotProductXYZXYZ(m,p,x,l,d,h);return bt.linearSystem2d(_,-v,v,-I,S,w,g)}static linearSystem2d(t,e,n,i,s,r,o){const a=f.crossProductXYXY(t,n,e,i),c=f.crossProductXYXY(s,r,e,i),l=f.crossProductXYXY(t,n,s,r),d=f.conditionalDivideFraction(c,a),h=f.conditionalDivideFraction(l,a);return d!==void 0&&h!==void 0?(o.set(d,h),!0):(o.set(0,0),!1)}static linearSystem3d(t,e,n,i,s,r,o,a,c,l,d,h,g){const m=f.tripleProduct(t,i,o,e,s,a,n,r,c),p=f.tripleProduct(l,d,h,e,s,a,n,r,c),x=f.tripleProduct(t,i,o,l,d,h,n,r,c),_=f.tripleProduct(t,i,o,e,s,a,l,d,h),I=f.conditionalDivideFraction(p,m),v=f.conditionalDivideFraction(x,m),S=f.conditionalDivideFraction(_,m);if(I!==void 0&&v!==void 0&&S!==void 0)return P.create(I,v,S,g)}static intersect3Planes(t,e,n,i,s,r,o){return this.linearSystem3d(e.x,e.y,e.z,i.x,i.y,i.z,r.x,r.y,r.z,f.dotProductXYZXYZ(t.x,t.y,t.z,e.x,e.y,e.z),f.dotProductXYZXYZ(n.x,n.y,n.z,i.x,i.y,i.z),f.dotProductXYZXYZ(s.x,s.y,s.z,r.x,r.y,r.z),o)}static eliminateFromPivot(t,e,n,i){const s=t.length;let r=f.conditionalDivideFraction(n[e],t[e]);if(r===void 0)return!1;r*=i;for(let o=e+1;o<s;o++)n[o]+=r*t[o];return!0}static solveBilinearPair(t,e,n,i,s,r,o,a){return Ms.solveBilinearPair(t,e,n,i,s,r,o,a)}}class O{origin;direction;a;static _workVector0;static _workVector1;static _workVector2;static _workVector3;static _workVector4;static _workMatrix;constructor(t,e){this.origin=t,this.direction=e,this.a=void 0}static _create(t,e,n,i,s,r){return new O(y.create(t,e,n),P.create(i,s,r))}static createXAxis(){return O._create(0,0,0,1,0,0)}static createYAxis(){return O._create(0,0,0,0,1,0)}static createZAxis(){return O._create(0,0,0,0,0,1)}static createZero(t){return t?(t.origin.setZero(),t.direction.setZero(),t):new O(y.createZero(),P.createZero())}isAlmostEqual(t,e=f.smallMetricDistance){return this.origin.isAlmostEqual(t.origin,e)&&this.direction.isAlmostEqual(t.direction,e)}dotProductToPoint(t){return this.direction.dotProductStartEnd(this.origin,t)}dotProductToPointXY(t){return this.direction.dotProductStartEndXY(this.origin,t)}pointToFraction(t){return f.safeDivideFraction(this.dotProductToPoint(t),this.direction.magnitudeSquared(),0)}projectPointToRay(t){return this.origin.plusScaled(this.direction,this.pointToFraction(t))}isAlmostEqualPointSet(t,e){if(!this.direction.isParallelTo(t.direction,!0,!1,e))return!1;const n=e?.distanceSquaredTol??f.smallMetricDistanceSquared;let i=this.projectPointToRay(t.origin);return!(t.origin.distanceSquared(i)>n||(i=t.projectPointToRay(this.origin),this.origin.distanceSquared(i)>n))}static create(t,e,n){return n?(n.set(t,e),n):new O(t.clone(),e.clone())}static createWeightedDerivative(t,e,n){const i=t[3],s=e[3],r=t[0],o=t[1],a=t[2],c=e[0]*i-t[0]*s,l=e[1]*i-t[1]*s,d=e[2]*i-t[2]*s;if(f.isSmallMetricDistance(i))return;const h=1/i,g=h*h;return O.createXYZUVW(r*h,o*h,a*h,c*g,l*g,d*g,n)}static createXYZUVW(t,e,n,i,s,r,o){return o?(o.getOriginRef().set(t,e,n),o.getDirectionRef().set(i,s,r),o):new O(y.create(t,e,n),P.create(i,s,r))}static createCapture(t,e){return new O(t,e)}static createPointVectorNumber(t,e,n,i){return i?(i.origin.setFrom(t),i.direction.setFrom(e),i.a=n,i):(i=new O(t.clone(),e.clone()),i.a=n,i)}static createStartEnd(t,e,n){return n?(n.origin.setFrom(t),n.direction.setStartEnd(t,e),n):new O(t.clone(),P.createStartEnd(t,e))}getOriginRef(){return this.origin}getDirectionRef(){return this.direction}set(t,e){this.origin.setFrom(t),this.direction.setFrom(e)}clone(t){return t?(t.set(this.origin.clone(),this.direction.clone()),t):new O(this.origin.clone(),this.direction.clone())}cloneTransformed(t,e){return O.create(t.multiplyPoint3d(this.origin,e?.origin),t.multiplyVector(this.direction,e?.direction),e)}cloneInverseTransformed(t,e){if(!t.computeCachedInverse(!0))return;const n=t.multiplyInversePoint3d(this.origin,e?.origin),i=t.matrix.multiplyInverseXYZAsVector3d(this.direction.x,this.direction.y,this.direction.z,e?.direction);return O.create(n,i,e)}transformInPlace(t){t.multiplyPoint3d(this.origin,this.origin),t.multiplyVector(this.direction,this.direction)}setFrom(t){this.set(t.origin,t.direction)}fractionToPoint(t,e){return this.origin.plusScaled(this.direction,t,e)}toRigidZFrame(t){const e=O._workMatrix=C.createRigidHeadsUp(this.direction,mt.ZXY,O._workMatrix);return X.createOriginAndMatrix(this.origin,e,t)}setFromJSON(t){if(!t){this.origin.set(0,0,0),this.direction.set(0,0,1);return}this.origin.setFromJSON(t.origin),this.direction.setFromJSON(t.direction)}toJSON(){return{origin:this.origin.toJSON(),direction:this.direction.toJSON()}}static fromJSON(t){const e=O.createXAxis();return e.setFromJSON(t),e}trySetDirectionMagnitudeInPlace(t=1){return this.direction.tryNormalizeInPlace()?(this.direction.scaleInPlace(t),!0):(this.direction.setZero(),this.a=0,!1)}tryNormalizeInPlaceWithAreaWeight(t){const e=f.smallMetricDistanceSquared;return this.a=t,Math.abs(t)>e&&this.direction.tryNormalizeInPlace(e)?!0:(this.direction.setZero(),this.a=0,!1)}distance(t){const e=this.direction.magnitudeSquared(),n=this.dotProductToPoint(t),i=f.inverseMetricDistanceSquared(e);return Math.sqrt(i?this.origin.distanceSquared(t)-n*n*i:this.origin.distanceSquared(t))}intersectionWithPlane(t,e){const n=P.createStartEnd(t.getOriginRef(),this.origin),i=this.direction.dotProduct(t.getNormalRef()),s=this.direction.magnitudeSquared(),r=n.dotProduct(t.getNormalRef()),o=f.conditionalDivideFraction(-r,i);if(!(o===void 0||f.conditionalDivideFraction(s,i)===void 0))return e&&this.origin.plusScaled(this.direction,o,e),o}intersectionWithRange3d(t,e){if(t.isNull)return ct.createNull(e);const n=ct.createXX(-f.largeCoordinateResult,f.largeCoordinateResult,e);return n.clipLinearMapToInterval(this.origin.x,this.direction.x,t.low.x,t.high.x),n.clipLinearMapToInterval(this.origin.y,this.direction.y,t.low.y,t.high.y),n.clipLinearMapToInterval(this.origin.z,this.direction.z,t.low.z,t.high.z),n}intersectionWithTriangle(t,e,n,i,s,r){(i===void 0||i<0)&&(i=f.smallMetricDistance),(s===void 0||s<0)&&(s=f.smallFloatingPoint);const o=O._workVector0=P.createStartEnd(t,e,O._workVector0),a=O._workVector1=P.createStartEnd(t,n,O._workVector1),c=O._workVector2=this.direction.crossProduct(a,O._workVector2),l=o.dotProduct(c);if(l>=-i&&l<=i)return;const d=1/l,h=O._workVector3=P.createStartEnd(t,this.origin,O._workVector3);let g=d*h.dotProduct(c);if(g<0)if(g>=-s)g=0;else return;else if(g>1)if(g<=1+s)g=1;else return;const m=O._workVector4=h.crossProduct(o,O._workVector4);let p=d*this.direction.dotProduct(m);if(p<0)if(p>=-s)p=0;else return;else if(g+p>1+s)return;const x=d*a.dotProduct(m);if(!(x<-i))return this.origin.plusScaled(this.direction,x,r)}perpendicularPartOfVectorToTarget(t,e){const n=P.createStartEnd(this.origin,t),i=this.direction.magnitudeSquared(),s=this.direction.dotProductStartEnd(this.origin,t),r=f.safeDivideFraction(s,i,0);return n.plusScaled(this.direction,-r,e)}static closestApproachRay3dRay3d(t,e){const n=Q.create();let i,s,r,o,a;bt.ray3dXYZUVWClosestApproachUnbounded(t.origin.x,t.origin.y,t.origin.z,t.direction.x,t.direction.y,t.direction.z,e.origin.x,e.origin.y,e.origin.z,e.direction.x,e.direction.y,e.direction.z,n)?(i=n.x,s=n.y,r=t.fractionToPoint(i),o=e.fractionToPoint(s),a=r.isAlmostEqualMetric(o)?Dn.Intersection:Dn.PerpendicularChord):(s=0,i=t.pointToFraction(e.origin),r=t.fractionToPoint(i),o=e.fractionToPoint(s),a=r.isAlmostEqualMetric(o)?Dn.CoincidentGeometry:Dn.ParallelGeometry);const c=Ot.createCapture(Y.createRayFractionPoint(t,i,t.fractionToPoint(i)),Y.createRayFractionPoint(e,s,e.fractionToPoint(s)));return c.approachType=a,c}static interpolatePointAndTangent(t,e,n,i,s){s=s??O.createZero();const r=n.x-t.x,o=n.y-t.y,a=n.z-t.z;if(s.direction.set(i*r,i*o,i*a),e<=.5)s.origin.set(t.x+e*r,t.y+e*o,t.z+e*a);else{const c=e-1;s.origin.set(n.x+c*r,n.y+c*o,n.z+c*a)}return s}}class At extends Cs{origin;vectorU;vectorV;constructor(t,e,n){super(),this.origin=t,this.vectorU=e,this.vectorV=n}static createOriginAndVectors(t,e,n,i){return i?(i.origin.setFrom(t),i.vectorU.setFrom(e),i.vectorV.setFrom(n),i):new At(t.clone(),e.clone(),n.clone())}clone(t){return t!==void 0&&t.setOriginAndVectors(this.origin,this.vectorU,this.vectorV),new At(this.origin.clone(),this.vectorU.clone(),this.vectorV.clone())}static createFrom(t,e){if(t instanceof At)return t.clone(e);const n=t.getUnitNormal();if(n===void 0)return;const i=t.getAnyPointOnPlane(),s=C.createPerpendicularVectorFavorXYPlane(n);if(s.tryNormalizeInPlace()){const r=n.unitCrossProduct(s);if(r!==void 0)return new At(i,s,r)}}static createFromTransformColumnsXYAndLengths(t,e,n,i){return i?(i.origin.setFrom(t.getOrigin()),t.matrix.columnX(i.vectorU),t.matrix.columnY(i.vectorV)):i=new At(t.getOrigin(),t.matrix.columnX(),t.matrix.columnY()),e!==void 0&&i.vectorU.scaleToLength(e,i.vectorU),n!==void 0&&i.vectorV.scaleToLength(n,i.vectorV),i}static createCapture(t,e,n,i){return i?(i.origin=t,i.vectorU=e,i.vectorV=n,i):new At(t,e,n)}setOriginAndVectorsXYZ(t,e,n,i,s,r,o,a,c){return this.origin.set(t,e,n),this.vectorU.set(i,s,r),this.vectorV.set(o,a,c),this}setOriginAndVectors(t,e,n){return this.origin.setFrom(t),this.vectorU.setFrom(e),this.vectorV.setFrom(n),this}static createOriginAndVectorsXYZ(t,e,n,i,s,r,o,a,c,l){return l?l.setOriginAndVectorsXYZ(t,e,n,i,s,r,o,a,c):new At(y.create(t,e,n),P.create(i,s,r),P.create(o,a,c))}static createOriginAndTargets(t,e,n,i){return At.createOriginAndVectorsXYZ(t.x,t.y,t.z,e.x-t.x,e.y-t.y,e.z-t.z,n.x-t.x,n.y-t.y,n.z-t.z,i)}static createXYPlane(t){return At.createOriginAndVectorsXYZ(0,0,0,1,0,0,0,1,0,t)}static createOriginAndVectorsArrays(t,e,n,i){return At.createOriginAndVectorsXYZ(t[0],t[1],t[2],e[0],e[1],e[2],n[0],n[1],n[2],i)}static createOriginAndVectorsWeightedArrays(t,e,n,i){const s=t[3];if(i=At.createXYPlane(i),f.isSmallMetricDistance(s))return i;const r=1/s,o=e[3]*r*r,a=n[3]*r*r;return i.origin.set(t[0]*r,t[1]*r,t[2]*r),P.createAdd2ScaledXYZ(e[0],e[1],e[2],r,t[0],t[1],t[2],-o,i.vectorU),P.createAdd2ScaledXYZ(n[0],n[1],n[2],r,t[0],t[1],t[2],-a,i.vectorV),i}fractionToPoint(t,e,n){return this.origin.plus2Scaled(this.vectorU,t,this.vectorV,e,n)}fractionToVector(t,e,n){return P.createAdd2Scaled(this.vectorU,t,this.vectorV,e,n)}setFromJSON(t){!t||!t.origin||!t.vectorV?(this.origin.set(0,0,0),this.vectorU.set(1,0,0),this.vectorV.set(0,1,0)):(this.origin.setFromJSON(t.origin),this.vectorU.setFromJSON(t.vectorU),this.vectorV.setFromJSON(t.vectorV))}toJSON(){return{origin:this.origin.toJSON(),vectorU:this.vectorU.toJSON(),vectorV:this.vectorV.toJSON()}}static fromJSON(t){const e=At.createXYPlane();return e.setFromJSON(t),e}isAlmostEqual(t){return this.origin.isAlmostEqual(t.origin)&&this.vectorU.isAlmostEqual(t.vectorU)&&this.vectorV.isAlmostEqual(t.vectorV)}normalizeInPlace(){const t=this.vectorU.normalizeInPlace(),e=this.vectorV.normalizeInPlace();return t&&e}getUnitNormal(t){return this.vectorU.unitCrossProduct(this.vectorV,t)}unitNormal(t){return this.vectorU.unitCrossProduct(this.vectorV,t)}getAnyPointOnPlane(t){return this.origin.clone(t)}static _workVector;unitNormalRay(t){At._workVector||(At._workVector=P.create());const e=this.vectorU.unitCrossProduct(this.vectorV,At._workVector);if(e!==void 0)return O.create(this.origin,e,t)}toRigidFrame(t){return X.createRigidFromOriginAndColumns(this.origin,this.vectorU,this.vectorV,mt.XYZ,t)}transformInPlace(t){t.multiplyPoint3d(this.origin,this.origin),t.multiplyVector(this.vectorU,this.vectorU),t.multiplyVector(this.vectorV,this.vectorV)}normalX(){const t=this.vectorU.unitCrossProduct(this.vectorV);return t!==void 0?t.x:0}normalY(){const t=this.vectorU.unitCrossProduct(this.vectorV);return t!==void 0?t.y:0}normalZ(){const t=this.vectorU.unitCrossProduct(this.vectorV);return t!==void 0?t.z:0}altitude(t){const e=this.vectorU.unitCrossProduct(this.vectorV);return e===void 0?0:f.dotProductXYZXYZ(t.x-this.origin.x,t.y-this.origin.y,t.z-this.origin.z,e.x,e.y,e.z)}altitudeXYZ(t,e,n){const i=this.vectorU.unitCrossProduct(this.vectorV);return i===void 0?0:f.dotProductXYZXYZ(t-this.origin.x,e-this.origin.y,n-this.origin.z,i.x,i.y,i.z)}velocity(t){const e=this.vectorU.unitCrossProduct(this.vectorV);return e===void 0?0:f.dotProductXYZXYZ(t.x,t.y,t.z,e.x,e.y,e.z)}velocityXYZ(t,e,n){const i=this.vectorU.unitCrossProduct(this.vectorV);return i===void 0?0:f.dotProductXYZXYZ(t,e,n,i.x,i.y,i.z)}weightedAltitude(t){const e=t.w;return f.tripleProduct(t.x-this.origin.x*e,t.y-this.origin.y*e,t.z-this.origin.z*e,this.vectorU.x,this.vectorU.y,this.vectorU.z,this.vectorV.x,this.vectorV.y,this.vectorV.z)}projectPointToPlane(t,e){return this.projectXYZToPlane(t.x,t.y,t.z,e)}projectXYZToPlane(t,e,n,i){const s=this.vectorU.unitCrossProduct(this.vectorV);if(s!==void 0){const a=-s.dotProductStartEndXYZ(this.origin,t,e,n);return y.create(t+a*s.x,e+a*s.y,n+a*s.z,i)}const r=this.vectorU.magnitudeSquared(),o=this.vectorV.magnitudeSquared();if(r>=o){const a=this.vectorU.dotProductStartEndXYZ(this.origin,t,e,n),c=f.conditionalDivideCoordinate(a,r,0);if(c!==void 0)return y.create(t+c*this.vectorU.x,e+c*this.vectorU.y,n+c*this.vectorU.z,i)}else{const a=this.vectorV.dotProductStartEndXYZ(this.origin,t,e,n),c=f.conditionalDivideCoordinate(a,o,0);if(c!==void 0)return y.create(t+c*this.vectorV.x,e+c*this.vectorV.y,n+c*this.vectorV.z,i)}return this.origin.clone(i)}}function Er(u,t,e,n,i,s){return s*(u-2*i*t-n*e)}class Z extends Cs{xyzw;set(t=0,e=0,n=0,i=0){return this.xyzw[0]=t,this.xyzw[1]=e,this.xyzw[2]=n,this.xyzw[3]=i,this}setComponent(t,e){t>=0&&t<4&&(this.xyzw[t]=e)}get x(){return this.xyzw[0]}set x(t){this.xyzw[0]=t}get y(){return this.xyzw[1]}set y(t){this.xyzw[1]=t}get z(){return this.xyzw[2]}set z(t){this.xyzw[2]=t}get w(){return this.xyzw[3]}set w(t){this.xyzw[3]=t}constructor(t=0,e=0,n=0,i=0){super(),this.xyzw=new Float64Array(4),this.xyzw[0]=t,this.xyzw[1]=e,this.xyzw[2]=n,this.xyzw[3]=i}static create(t=0,e=0,n=0,i=0,s){return s?s.set(t,e,n,i):new Z(t,e,n,i)}static createPlaneFrom(t){return new Z(t.normalX(),t.normalY(),t.normalZ(),t.altitudeXYZ(0,0,0))}setFrom(t){return this.xyzw[0]=t.xyzw[0],this.xyzw[1]=t.xyzw[1],this.xyzw[2]=t.xyzw[2],this.xyzw[3]=t.xyzw[3],this}clone(t){return t?t.setFrom(this):new Z(this.xyzw[0],this.xyzw[1],this.xyzw[2],this.xyzw[3])}setFromJSON(t){f.isNumberArray(t,4)?this.set(t[0],t[1],t[2],t[3]):this.set(0,0,0,0)}static fromJSON(t){const e=new Z;return e.setFromJSON(t),e}isAlmostEqual(t,e=f.smallMetricDistance){return f.isSameCoordinate(this.x,t.x,e)&&f.isSameCoordinate(this.y,t.y,e)&&f.isSameCoordinate(this.z,t.z,e)&&f.isSameCoordinate(this.w,t.w,e)}isAlmostEqualXYZW(t,e,n,i,s=f.smallMetricDistance){return f.isSameCoordinate(this.x,t,s)&&f.isSameCoordinate(this.y,e,s)&&f.isSameCoordinate(this.z,n,s)&&f.isSameCoordinate(this.w,i,s)}toJSON(){return[this.xyzw[0],this.xyzw[1],this.xyzw[2],this.xyzw[3]]}distanceXYZW(t){return f.hypotenuseXYZW(t.xyzw[0]-this.xyzw[0],t.xyzw[1]-this.xyzw[1],t.xyzw[2]-this.xyzw[2],t.xyzw[3]-this.xyzw[3])}distanceSquaredXYZW(t){return f.hypotenuseSquaredXYZW(t.xyzw[0]-this.xyzw[0],t.xyzw[1]-this.xyzw[1],t.xyzw[2]-this.xyzw[2],t.xyzw[3]-this.xyzw[3])}realDistanceXY(t){const e=this.w,n=t.w;if(!(f.isSmallMetricDistance(e)||f.isSmallMetricDistance(n)))return f.hypotenuseXY(t.xyzw[0]/n-this.xyzw[0]/e,t.xyzw[1]/n-this.xyzw[1]/e)}realDistanceSquaredXY(t){const e=this.w,n=t.w;if(!(f.isSmallMetricDistance(e)||f.isSmallMetricDistance(n)))return f.hypotenuseSquaredXY(t.xyzw[0]/n-this.xyzw[0]/e,t.xyzw[1]/n-this.xyzw[1]/e)}maxDiff(t){return Math.max(Math.abs(t.xyzw[0]-this.xyzw[0]),Math.abs(t.xyzw[1]-this.xyzw[1]),Math.abs(t.xyzw[2]-this.xyzw[2]),Math.abs(t.xyzw[3]-this.xyzw[3]))}maxAbs(){return Math.max(Math.abs(this.xyzw[0]),Math.abs(this.xyzw[1]),Math.abs(this.xyzw[2]),Math.abs(this.xyzw[3]))}magnitudeXYZW(){return f.hypotenuseXYZW(this.xyzw[0],this.xyzw[1],this.xyzw[2],this.xyzw[3])}magnitudeSquaredXYZ(){return f.hypotenuseSquaredXYZ(this.xyzw[0],this.xyzw[1],this.xyzw[2])}minus(t,e){return Z.create(this.xyzw[0]-t.xyzw[0],this.xyzw[1]-t.xyzw[1],this.xyzw[2]-t.xyzw[2],this.xyzw[3]-t.xyzw[3],e)}crossWeightedMinus(t,e){const n=this.xyzw[3],i=t.xyzw[3];return P.create(i*this.xyzw[0]-n*t.xyzw[0],i*this.xyzw[1]-n*t.xyzw[1],i*this.xyzw[2]-n*t.xyzw[2],e)}crossWeightedMinusPoint3d(t,e){const n=this.xyzw[3];return P.create(this.xyzw[0]-n*t.x,this.xyzw[1]-n*t.y,this.xyzw[2]-n*t.z,e)}plus(t,e){return Z.create(this.xyzw[0]+t.xyzw[0],this.xyzw[1]+t.xyzw[1],this.xyzw[2]+t.xyzw[2],this.xyzw[3]+t.xyzw[3],e)}get isAlmostZero(){return f.isSmallMetricDistance(this.maxAbs())}static createZero(){return new Z(0,0,0,0)}static createPlanePointPointZ(t,e,n){return Z.create(t.y*e.w-t.w*e.y,t.w*e.x-t.x*e.w,0,t.x*e.y-t.y*e.x,n)}static createFromPackedXYZ(t,e=0,n){if(e>=0&&e+2<t.length)return Z.create(t[e],t[e+1],t[e+2],1,n)}static createFromPacked(t,e=0,n){if(e>=0&&e+3<t.length)return Z.create(t[e],t[e+1],t[e+2],t[e+3],n)}static createFromPackedXYZW(t,e=0,n){return Z.create(t[e],t[e+1],t[e+2],t[e+3],n)}static createFromPointAndWeight(t,e){return new Z(t.x,t.y,t.z,e)}static createFromPoint(t){if(t instanceof D)return new Z(t.x,t.y,0,1);if(t instanceof y)return new Z(t.x,t.y,t.z,1);if(t instanceof Z)return t.clone();if(Array.isArray(t)){const r=t.length>0?t[0]:0,o=t.length>1?t[1]:0,a=t.length>2?t[2]:0,c=t.length>3?t[3]:1;return new Z(r,o,a,c)}const e=t.x,n=t.y,i=t.hasOwnProperty("z")?t.z:0,s=t.hasOwnProperty("w")?t.w:1;return new Z(e,n,i,s)}plusScaled(t,e,n){return Z.create(this.xyzw[0]+t.xyzw[0]*e,this.xyzw[1]+t.xyzw[1]*e,this.xyzw[2]+t.xyzw[2]*e,this.xyzw[3]+t.xyzw[3]*e,n)}interpolate(t,e,n){const i=1-t;return Z.create(this.xyzw[0]*i+e.xyzw[0]*t,this.xyzw[1]*i+e.xyzw[1]*t,this.xyzw[2]*i+e.xyzw[2]*t,this.xyzw[3]*i+e.xyzw[3]*t,n)}plus2Scaled(t,e,n,i,s){return Z.create(this.xyzw[0]+t.xyzw[0]*e+n.xyzw[0]*i,this.xyzw[1]+t.xyzw[1]*e+n.xyzw[1]*i,this.xyzw[2]+t.xyzw[2]*e+n.xyzw[2]*i,this.xyzw[3]+t.xyzw[3]*e+n.xyzw[3]*i,s)}plus3Scaled(t,e,n,i,s,r,o){return Z.create(this.xyzw[0]+t.xyzw[0]*e+n.xyzw[0]*i+s.xyzw[0]*r,this.xyzw[1]+t.xyzw[1]*e+n.xyzw[1]*i+s.xyzw[1]*r,this.xyzw[2]+t.xyzw[2]*e+n.xyzw[2]*i+s.xyzw[2]*r,this.xyzw[3]+t.xyzw[3]*e+n.xyzw[3]*i+s.xyzw[3]*r,o)}static createAdd2Scaled(t,e,n,i,s){return Z.create(t.xyzw[0]*e+n.xyzw[0]*i,t.xyzw[1]*e+n.xyzw[1]*i,t.xyzw[2]*e+n.xyzw[2]*i,t.xyzw[3]*e+n.xyzw[3]*i,s)}static createAdd3Scaled(t,e,n,i,s,r,o){return Z.create(t.xyzw[0]*e+n.xyzw[0]*i+s.xyzw[0]*r,t.xyzw[1]*e+n.xyzw[1]*i+s.xyzw[1]*r,t.xyzw[2]*e+n.xyzw[2]*i+s.xyzw[2]*r,t.xyzw[3]*e+n.xyzw[3]*i+s.xyzw[3]*r,o)}dotVectorsToTargets(t,e){return(t.xyzw[0]-this.xyzw[0])*(e.xyzw[0]-this.xyzw[0])+(t.xyzw[1]-this.xyzw[1])*(e.xyzw[1]-this.xyzw[1])+(t.xyzw[2]-this.xyzw[2])*(e.xyzw[2]-this.xyzw[2])+(t.xyzw[3]-this.xyzw[3])*(e.xyzw[3]-this.xyzw[3])}dotProduct(t){return this.xyzw[0]*t.xyzw[0]+this.xyzw[1]*t.xyzw[1]+this.xyzw[2]*t.xyzw[2]+this.xyzw[3]*t.xyzw[3]}dotProductXYZW(t,e,n,i){return this.xyzw[0]*t+this.xyzw[1]*e+this.xyzw[2]*n+this.xyzw[3]*i}altitude(t){return this.xyzw[0]*t.x+this.xyzw[1]*t.y+this.xyzw[2]*t.z+this.xyzw[3]}altitudeXYZ(t,e,n){return this.xyzw[0]*t+this.xyzw[1]*e+this.xyzw[2]*n+this.xyzw[3]}weightedAltitude(t){return this.xyzw[0]*t.x+this.xyzw[1]*t.y+this.xyzw[2]*t.z+this.xyzw[3]*t.w}velocity(t){return this.xyzw[0]*t.x+this.xyzw[1]*t.y+this.xyzw[2]*t.z}velocityXYZ(t,e,n){return this.xyzw[0]*t+this.xyzw[1]*e+this.xyzw[2]*n}normalX(){return this.x}normalY(){return this.y}normalZ(){return this.z}static unitX(){return new Z(1,0,0,0)}static unitY(){return new Z(0,1,0,0)}static unitZ(){return new Z(0,0,1,0)}static unitW(){return new Z(0,0,0,1)}safeDivideOrNull(t,e){if(t!==0)return this.scale(1/t,e)}projectPointToPlane(t,e){return this.projectXYZToPlane(t.x,t.y,t.z,e)}projectXYZToPlane(t,e,n,i){const s=this.altitudeXYZ(t,e,n),r=this.magnitudeSquaredXYZ(),o=f.conditionalDivideCoordinate(-s,r,f.largeFractionResult*f.largeFractionResult);return o===void 0?y.create(t,e,n,i):y.create(t+o*this.x,e+o*this.y,n+o*this.z,i)}scale(t,e){return e=e||new Z,e.xyzw[0]=this.xyzw[0]*t,e.xyzw[1]=this.xyzw[1]*t,e.xyzw[2]=this.xyzw[2]*t,e.xyzw[3]=this.xyzw[3]*t,e}negate(t){return t=t||new Z,t.xyzw[0]=-this.xyzw[0],t.xyzw[1]=-this.xyzw[1],t.xyzw[2]=-this.xyzw[2],t.xyzw[3]=-this.xyzw[3],t}normalizeWeight(t){const e=f.correctSmallFraction(this.xyzw[3]);return t=t||new Z,this.safeDivideOrNull(e,t)}realPoint(t){const e=f.correctSmallFraction(this.xyzw[3]);if(e===0)return;const n=1/e;return y.create(this.xyzw[0]*n,this.xyzw[1]*n,this.xyzw[2]*n,t)}realPointOrVector(){const t=f.correctSmallFraction(this.xyzw[3]);if(t===0)return P.create(this.x,this.y,this.z);const e=1/t;return y.create(this.x*e,this.y*e,this.z*e)}static createRealPoint3dDefault000(t,e,n,i,s){const r=f.correctSmallFraction(i),o=r===0?0:1/r;return y.create(t*o,e*o,n*o,s)}static createRealDerivativeRay3dDefault000(t,e,n,i,s,r,o,a,c){const l=f.correctSmallFraction(i),d=l===0?0:1/l,h=d*d;return O.createXYZUVW(t*d,e*d,n*d,(s*i-a*t)*h,(r*i-a*e)*h,(o*i-a*n)*h,c)}static createRealDerivativePlane3dByOriginAndVectorsDefault000(t,e,n,i,s,r,o,a,c,l,d,h,g){const m=f.correctSmallFraction(i),p=m===0?0:1/m,x=p*p,_=t*p,I=e*p,v=n*p,S=(s*i-a*t)*x,w=(r*i-a*e)*x,T=(o*i-a*n)*x;return At.createOriginAndVectorsXYZ(_,I,v,S,w,T,Er(c,a,h,_,S,p),Er(l,a,h,I,w,p),Er(d,a,h,v,T,p),g)}realPointDefault000(t){const e=f.correctSmallFraction(this.xyzw[3]);if(e===0)return y.create(0,0,0,t);t=t||new y;const n=1/e;return y.create(this.xyzw[0]*n,this.xyzw[1]*n,this.xyzw[2]*n,t)}normalizeXYZW(t){const e=f.correctSmallFraction(this.magnitudeXYZW());return t=t||new Z,this.safeDivideOrNull(e,t)}static determinantIndexed3X3(t,e,n,i,s,r){return f.tripleProduct(t.xyzw[i],t.xyzw[s],t.xyzw[r],e.xyzw[i],e.xyzw[s],e.xyzw[r],n.xyzw[i],n.xyzw[s],n.xyzw[r])}static perpendicularPoint4dPlane(t,e,n){return Z.create(Z.determinantIndexed3X3(t,e,n,1,2,3),-Z.determinantIndexed3X3(t,e,n,2,3,0),Z.determinantIndexed3X3(t,e,n,3,0,1),-Z.determinantIndexed3X3(t,e,n,0,1,2))}toPlane3dByOriginAndUnitNormal(t){return ht.createFrom(this,t)}normalizeQuaternion(){const t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(t>0){const e=1/t;this.x*=e,this.y*=e,this.z*=e,this.w*=e}return t}static interpolateQuaternions(t,e,n,i){i||(i=new Z);const s=.9995;if(e===0)return i=t,i;if(e===1)return i=n,i;if(e===.5)return t.plus(n,i),i.normalizeQuaternion(),i;const r=t.clone(),o=n.clone();let a=t.dotProduct(n);if(a<0&&(o.negate(o),a=-a),a>s)return r.interpolate(e,o,i),i.normalizeQuaternion(),i;a<-1?a=-1:a>1&&(a=1);const c=new Z;o.plusScaled(r,-a,c),c.normalizeQuaternion();const d=Math.acos(a)*e;return i=Z.createAdd2Scaled(r,Math.cos(d),c,Math.sin(d)),i}radiansToPoint4dXYZW(t){const e=this.magnitudeXYZW(),n=t.magnitudeXYZW(),i=this.dotProduct(t),s=f.conditionalDivideFraction(i,e*n);if(s!==void 0)return Math.acos(s)}}class Lt{static loadMatrix(t,e,n,i,s,r,o,a,c,l){t[0]=e,t[1]=n,t[2]=i,t[3]=s,t[4]=r,t[5]=o,t[6]=a,t[7]=c,t[8]=l}static multiplyMatrixMatrix(t,e,n){return(!n||n.length<9)&&(n=new Float64Array(9)),Lt.loadMatrix(n,t[0]*e[0]+t[1]*e[3]+t[2]*e[6],t[0]*e[1]+t[1]*e[4]+t[2]*e[7],t[0]*e[2]+t[1]*e[5]+t[2]*e[8],t[3]*e[0]+t[4]*e[3]+t[5]*e[6],t[3]*e[1]+t[4]*e[4]+t[5]*e[7],t[3]*e[2]+t[4]*e[5]+t[5]*e[8],t[6]*e[0]+t[7]*e[3]+t[8]*e[6],t[6]*e[1]+t[7]*e[4]+t[8]*e[7],t[6]*e[2]+t[7]*e[5]+t[8]*e[8]),n}static multiplyMatrixMatrixTranspose(t,e,n){return(!n||n.length<9)&&(n=new Float64Array(9)),Lt.loadMatrix(n,t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[0]*e[3]+t[1]*e[4]+t[2]*e[5],t[0]*e[6]+t[1]*e[7]+t[2]*e[8],t[3]*e[0]+t[4]*e[1]+t[5]*e[2],t[3]*e[3]+t[4]*e[4]+t[5]*e[5],t[3]*e[6]+t[4]*e[7]+t[5]*e[8],t[6]*e[0]+t[7]*e[1]+t[8]*e[2],t[6]*e[3]+t[7]*e[4]+t[8]*e[5],t[6]*e[6]+t[7]*e[7]+t[8]*e[8]),n}static multiplyMatrixTransposeMatrix(t,e,n){return(!n||n.length<9)&&(n=new Float64Array(9)),Lt.loadMatrix(n,t[0]*e[0]+t[3]*e[3]+t[6]*e[6],t[0]*e[1]+t[3]*e[4]+t[6]*e[7],t[0]*e[2]+t[3]*e[5]+t[6]*e[8],t[1]*e[0]+t[4]*e[3]+t[7]*e[6],t[1]*e[1]+t[4]*e[4]+t[7]*e[7],t[1]*e[2]+t[4]*e[5]+t[7]*e[8],t[2]*e[0]+t[5]*e[3]+t[8]*e[6],t[2]*e[1]+t[5]*e[4]+t[8]*e[7],t[2]*e[2]+t[5]*e[5]+t[8]*e[8]),n}static transposeInPlace(t){let e=t[1];t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e}static copyTransposed(t,e){return e===t?Lt.transposeInPlace(e):((!e||e.length<9)&&(e=new Float64Array(9)),e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8]),e}static copy(t,e){return e!==t&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8]),e}}var j;(function(u){u[u.unknown=0]="unknown",u[u.inverseStored=1]="inverseStored",u[u.singular=2]="singular"})(j||(j={}));class C{static useCachedInverse=!0;static numUseCache=0;static numComputeCache=0;coffs;inverseCoffs;inverseState;static _identity;static _productBuffer=new Float64Array(9);static get identity(){return this._identity===void 0&&(this._identity=C.createIdentity(),this._identity.freeze()),this._identity}freeze(){return this.computeCachedInverse(!0),Object.freeze(this)}constructor(t){this.coffs=t&&t.length>=9?t:new Float64Array(9),this.inverseCoffs=void 0,this.inverseState=j.unknown}toJSON(){return[[this.coffs[0],this.coffs[1],this.coffs[2]],[this.coffs[3],this.coffs[4],this.coffs[5]],[this.coffs[6],this.coffs[7],this.coffs[8]]]}setFromJSON(t){if(this.inverseCoffs=void 0,!t){this.setRowValues(0,0,0,0,0,0,0,0,0);return}if(!Array.isArray(t)){t instanceof C&&this.setFrom(t);return}if(f.isArrayOfNumberArray(t,3,3)){this.setRowValues(t[0][0],t[0][1],t[0][2],t[1][0],t[1][1],t[1][2],t[2][0],t[2][1],t[2][2]);return}if(t.length===9){this.setRowValues(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]);return}else if(t.length===4){this.setRowValues(t[0],t[1],0,t[2],t[3],0,0,0,1);return}this.setRowValues(0,0,0,0,0,0,0,0,0)}static fromJSON(t){const e=C.createIdentity();return e.setFromJSON(t),e}isAlmostEqual(t,e){return f.isDistanceWithinTol(this.maxDiff(t),e)}isAlmostEqualColumn(t,e,n){const i=f.maxAbsXYZ(this.coffs[t]-e.coffs[t],this.coffs[t+3]-e.coffs[t+3],this.coffs[t+6]-e.coffs[t+6]);return f.isDistanceWithinTol(i,n)}isAlmostEqualColumnXYZ(t,e,n,i,s){const r=f.maxAbsXYZ(this.coffs[t]-e,this.coffs[t+3]-n,this.coffs[t+6]-i);return f.isDistanceWithinTol(r,s)}isAlmostEqualAllowZRotation(t,e){if(this.isAlmostEqual(t,e))return!0;if(!this.isAlmostEqualColumn(ze.Z,t,e))return!1;const n=this.columnX(),i=this.columnY(),s=this.columnZ(),r=n.signedAngleTo(t.columnX(),s);let o=P.createRotateVectorAroundVector(n,s,r);return!(!o||!t.isAlmostEqualColumnXYZ(0,o.x,o.y,o.z,e)||(o=P.createRotateVectorAroundVector(i,s,r),!o)||!t.isAlmostEqualColumnXYZ(1,o.x,o.y,o.z,e))}isExactEqual(t){return this.maxDiff(t)===0}get isXY(){return this.coffs[2]===0&&this.coffs[5]===0&&this.coffs[6]===0&&this.coffs[7]===0&&this.coffs[8]===1}static _create(t){return t||new C}static createRowValues(t,e,n,i,s,r,o,a,c,l){return l=l||new C,l.inverseState=j.unknown,l.coffs[0]=t,l.coffs[1]=e,l.coffs[2]=n,l.coffs[3]=i,l.coffs[4]=s,l.coffs[5]=r,l.coffs[6]=o,l.coffs[7]=a,l.coffs[8]=c,l}static createCapture(t,e){const n=new C(t);return e&&e.length>=9?(n.inverseCoffs=e,n.inverseState=j.inverseStored):n.inverseState=j.unknown,n}static createColumnsInAxisOrder(t,e,n,i,s){return s||(s=new C),t===mt.YZX?s.setColumns(i,e,n):t===mt.ZXY?s.setColumns(n,i,e):t===mt.XZY?s.setColumns(e,i,n):t===mt.YXZ?s.setColumns(n,e,i):t===mt.ZYX?s.setColumns(i,n,e):s.setColumns(e,n,i),s}createInverseCoffsWithZeros(){return this.inverseCoffs||(this.inverseState=j.unknown,this.inverseCoffs=new Float64Array(9)),this.inverseCoffs!==void 0}setupInverseTranspose(){const t=this.coffs;this.inverseState=j.inverseStored,this.inverseCoffs=Float64Array.from([t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]])}setRowValues(t,e,n,i,s,r,o,a,c){this.coffs[0]=t,this.coffs[1]=e,this.coffs[2]=n,this.coffs[3]=i,this.coffs[4]=s,this.coffs[5]=r,this.coffs[6]=o,this.coffs[7]=a,this.coffs[8]=c,this.inverseState=j.unknown}setIdentity(){this.setRowValues(1,0,0,0,1,0,0,0,1),this.setupInverseTranspose()}setZero(){this.setRowValues(0,0,0,0,0,0,0,0,0),this.inverseState=j.singular}setFrom(t){if(t===void 0){this.setIdentity();return}if(t!==this){for(let e=0;e<9;e++)this.coffs[e]=t.coffs[e];if(t.inverseState===j.inverseStored&&t.inverseCoffs!==void 0){if(this.createInverseCoffsWithZeros()){for(let e=0;e<9;e++)this.inverseCoffs[e]=t.inverseCoffs[e];this.inverseState=j.inverseStored}}else t.inverseState!==j.inverseStored?this.inverseState=t.inverseState:this.inverseState=j.unknown}}clone(t){return t=t||new C,t.setFrom(this),t}static createZero(){const t=new C;return t.inverseState=j.singular,t}static createIdentity(t){return t=t||new C,t.setIdentity(),t}static createScale(t,e,n,i){return i?i.setZero():i=new C,i.coffs[0]=t,i.coffs[4]=e,i.coffs[8]=n,t===0||e===0||n===0?i.inverseState=j.singular:(i.inverseState=j.inverseStored,i.inverseCoffs=Float64Array.from([1/t,0,0,0,1/e,0,0,0,1/n])),i}static createUniformScale(t){return C.createScale(t,t,t)}static createPerpendicularVectorFavorXYPlane(t,e){const s=t.magnitude()/64;return Math.abs(t.x)<s&&Math.abs(t.y)<s?P.createCrossProduct(t.x,t.y,t.z,0,-1,0,e):P.createCrossProduct(0,0,1,t.x,t.y,t.z,e)}static createPerpendicularVectorFavorPlaneContainingZ(t,e){return e=C.createPerpendicularVectorFavorXYPlane(t,e),t.crossProduct(e,e)}static createShuffledColumns(t,e,n,i,s){const r=C._create(s);return r.setColumn(f.axisOrderToAxis(i,0),t),r.setColumn(f.axisOrderToAxis(i,1),e),r.setColumn(f.axisOrderToAxis(i,2),n),r.inverseState=j.unknown,r}static createRigidFromColumns(t,e,n,i){const s=t.normalize();if(s){const r=s.unitCrossProduct(e);if(r){const o=r.unitCrossProduct(t);if(o){const a=C.createShuffledColumns(s,o,r,n,i);return a.setupInverseTranspose(),a}}}}static createRigidHeadsUp(t,e=mt.ZXY,n){const i=C.createPerpendicularVectorFavorXYPlane(t),s=C.createRigidFromColumns(t,i,e,n);return s?(s.setupInverseTranspose(),s):C.createIdentity(n)}static createRotationAroundVector(t,e,n){const i=e.cos(),s=e.sin(),r=1-i,o=t.normalize();if(o){const a=C.createRowValues(o.x*o.x*r+i,o.x*o.y*r-s*o.z,o.x*o.z*r+s*o.y,o.y*o.x*r+s*o.z,o.y*o.y*r+i,o.y*o.z*r-s*o.x,o.z*o.x*r-s*o.y,o.z*o.y*r+s*o.x,o.z*o.z*r+i,n);return a.setupInverseTranspose(),a}}static createRotationAroundAxisIndex(t,e,n){const i=e.cos(),s=e.sin();let r;return t===ze.X?r=C.createRowValues(1,0,0,0,i,-s,0,s,i,n):t===ze.Y?r=C.createRowValues(i,0,s,0,1,0,-s,0,i,n):r=C.createRowValues(i,-s,0,s,i,0,0,0,1,n),r.setupInverseTranspose(),r}applyGivensRowOp(t,e,n,i){let s=3*t,r=3*e;const o=s+3;for(;s<o;s++,r++){const a=this.coffs[s],c=this.coffs[r];this.coffs[s]=a*n+c*i,this.coffs[r]=-a*i+c*n}}applyGivensColumnOp(t,e,n,i){const s=t+9;for(;t<s;t+=3,e+=3){const r=this.coffs[t],o=this.coffs[e];this.coffs[t]=r*n+o*i,this.coffs[e]=-r*i+o*n}}static createColumns(t,e,n,i){return C.createRowValues(t.x,e.x,n.x,t.y,e.y,n.y,t.z,e.z,n.z,i)}static createColumnsXYW(t,e,n,i,s,r,o){return C.createRowValues(t.x,n.x,s.x,t.y,n.y,s.y,e,i,r,o)}static createViewedAxes(t,e,n=0,i=0){const s=t.crossProduct(e);if(s.normalizeInPlace()){const r=C.createColumns(t,e,s);if(n!==0){let o=Math.sqrt(.5),a=n<0?-o:o;if(Math.abs(n)!==1){const c=A.degreesToRadians(45*n);o=Math.cos(c),a=Math.sin(c)}r.applyGivensColumnOp(2,0,o,a)}if(i!==0){const o=i*Math.atan(Math.sqrt(.5)),a=Math.cos(o),c=Math.sin(o);r.applyGivensColumnOp(1,2,a,-c)}return r}}static createStandardWorldToView(t,e=!1,n){switch(t){case yn.Bottom:n=C.createRowValues(1,0,0,0,-1,0,0,0,-1);break;case yn.Left:n=C.createRowValues(0,-1,0,0,0,1,-1,0,0);break;case yn.Right:n=C.createRowValues(0,1,0,0,0,1,1,0,0);break;case yn.Front:n=C.createRowValues(1,0,0,0,0,1,0,-1,0);break;case yn.Back:n=C.createRowValues(-1,0,0,0,0,1,0,1,0);break;case yn.Iso:n=C.createRowValues(.707106781186548,-.7071067811865476,0,.408248290463863,.408248290463863,.816496580927726,-.577350269189626,-.5773502691896257,.5773502691896257);break;case yn.RightIso:n=C.createRowValues(.707106781186548,.7071067811865476,0,-.408248290463863,.408248290463863,.816496580927726,.577350269189626,-.5773502691896257,.5773502691896257);break;case yn.Top:default:n=C.createIdentity(n)}return e&&n.transposeInPlace(),n}applySymmetricJacobi(t,e,n,i){const s=i.at(t,t),r=i.at(e,e),o=i.at(t,e);if(Math.abs(o)<f.smallFloatingPoint*(s+r))return 0;const a=A.trigValuesToHalfAngleTrigValues(s-r,2*o),c=a.c,l=a.s;return Math.abs(l)<2e-15?0:(i.applyGivensRowOp(t,e,c,l),i.applyGivensColumnOp(t,e,c,l),n.applyGivensColumnOp(t,e,c,l),Math.abs(o))}symmetricEigenvalues(t,e){const n=this.clone();t.setIdentity(),n.coffs[3]=n.coffs[1],n.coffs[6]=n.coffs[2],n.coffs[7]=n.coffs[5];const i=1e-12*this.sumSquares(),s=7;for(let r=0;r<s;r++)if(this.applySymmetricJacobi(0,1,t,n)+this.applySymmetricJacobi(0,2,t,n)+this.applySymmetricJacobi(1,2,t,n)<i)return e.set(n.at(0,0),n.at(1,1),n.at(2,2)),!0;return!1}applyFastSymmetricJacobi(t,e,n,i){const s=4*t,r=4*e,o=3*t+e,a=3*e+t,c=3*t+n,l=3*n+t,d=3*e+n,h=3*n+e,g=this.coffs[s],m=this.coffs[r],p=this.coffs[o];if(Math.abs(p)<f.smallFloatingPoint*(g+m))return 0;const x=A.trigValuesToHalfAngleTrigValues(g-m,2*p),_=x.c,I=x.s,v=_*_,S=I*I,w=2*_*I;this.coffs[s]=v*g+w*p+S*m,this.coffs[r]=S*g-w*p+v*m,this.coffs[o]=0,this.coffs[a]=0;const T=this.coffs[c],R=this.coffs[d];return this.coffs[c]=_*T+I*R,this.coffs[d]=-I*T+_*R,this.coffs[l]=this.coffs[c],this.coffs[h]=this.coffs[d],i.applyGivensColumnOp(t,e,_,I),Math.abs(p)}fastSymmetricEigenvalues(t,e){const n=this.clone();t.setIdentity();const i=1e-12*this.sumSquares(),s=7;for(let r=0;r<s;r++)if(n.applyFastSymmetricJacobi(0,1,2,t)+n.applyFastSymmetricJacobi(0,2,1,t)+n.applyFastSymmetricJacobi(1,2,0,t)<i)return e.set(n.at(0,0),n.at(1,1),n.at(2,2)),!0;return!1}getAxisAndAngleOfRotation(){const t=this.coffs[0]+this.coffs[4]+this.coffs[8],e=this.coffs[3]-this.coffs[1],n=this.coffs[7]-this.coffs[5],i=this.coffs[2]-this.coffs[6],s=(t-1)/2,r=f.hypotenuseXYZ(e,n,i)/2,o=s*s+r*r-1;if(Math.abs(o)>f.smallAngleRadians)return{axis:P.create(0,0,1),angle:A.createRadians(0),ok:!1};if(Math.abs(r)<f.smallAngleRadians){if(s>0)return{axis:P.create(0,0,1),angle:A.createRadians(0),ok:!0};const l=this.coffs[0],d=this.coffs[4],h=this.coffs[8];if(f.isAlmostEqualNumber(-1,d)&&f.isAlmostEqualNumber(-1,h))return{axis:P.create(1,0,0),angle:A.createDegrees(180),ok:!0};if(f.isAlmostEqualNumber(-1,l)&&f.isAlmostEqualNumber(-1,h))return{axis:P.create(0,1,0),angle:A.createDegrees(180),ok:!0};if(f.isAlmostEqualNumber(-1,l)&&f.isAlmostEqualNumber(-1,d))return{axis:P.create(0,0,1),angle:A.createDegrees(180),ok:!0};const g=C.createIdentity(),m=P.create(0,0,0);if(this.fastSymmetricEigenvalues(g,m)){for(let p=0;p<2;p++){const x=m.at(p);if(f.isAlmostEqualNumber(1,x))return{axis:g.getColumn(p),angle:A.createDegrees(180),ok:!0}}return{axis:P.create(0,0,1),angle:A.createRadians(0),ok:!1}}return{axis:P.create(0,0,1),angle:A.createRadians(0),ok:!1}}const a=1/(2*r);return{axis:P.create(n*a,i*a,e*a),angle:A.createAtan2(r,s),ok:!0}}applyJacobiColumnRotation(t,e,n){const i=this.coffs[t]*this.coffs[t]+this.coffs[t+3]*this.coffs[t+3]+this.coffs[t+6]*this.coffs[t+6],s=this.coffs[e]*this.coffs[e]+this.coffs[e+3]*this.coffs[e+3]+this.coffs[e+6]*this.coffs[e+6],r=this.coffs[t]*this.coffs[e]+this.coffs[t+3]*this.coffs[e+3]+this.coffs[t+6]*this.coffs[e+6],o=A.trigValuesToHalfAngleTrigValues(i-s,2*r),a=o.c,c=o.s;return Math.abs(c)<2e-15?0:(this.applyGivensColumnOp(t,e,a,c),n.applyGivensRowOp(t,e,a,c),Math.abs(r))}factorPerpendicularColumns(t,e){t.setFrom(this),e.setIdentity();const n=1e-12*this.sumSquares(),i=7;for(let s=0;s<i;s++)if(t.applyJacobiColumnRotation(0,1,e)+t.applyJacobiColumnRotation(0,2,e)+t.applyJacobiColumnRotation(1,2,e)<n)return!0;return!1}factorOrthogonalScaleOrthogonal(t,e,n){const i=C.createZero();if(!this.factorPerpendicularColumns(i,n))return!1;const s=[];s.push(i.getColumn(0)),s.push(i.getColumn(1)),s.push(i.getColumn(2)),e.set(s[0].magnitude(),s[1].magnitude(),s[2].magnitude()),i.determinant()<0&&(e.z=-e.z);const o=f.smallFloatingPoint,a=Math.abs(e.x)<o,c=Math.abs(e.y)<o,l=Math.abs(e.z)<o;return!a&&!c&&!l?t=i.scaleColumns(1/e.x,1/e.y,1/e.z,t):!a&&!c?(s[0].scaleInPlace(1/e.x),s[1].scaleInPlace(1/e.y),s[0].unitCrossProduct(s[1],s[2]),t.setColumns(s[0],s[1],s[2])):a?t.setIdentity():t=C.createRigidHeadsUp(s[0],mt.XYZ,t),!0}static createPartialRotationVectorToVector(t,e,n,i){let s=t.unitCrossProduct(n);if(s)return C.createRotationAroundVector(s,A.createRadians(e*t.planarAngleTo(n,s).radians),i);if(!(f.isSmallMetricDistance(t.magnitude())||f.isSmallMetricDistance(n.magnitude())))return t.dotProduct(n)>0?C.createIdentity(i):(s=C.createPerpendicularVectorFavorPlaneContainingZ(t,s),C.createRotationAroundVector(s,A.createRadians(e*Math.PI),i))}static createRotationVectorToVector(t,e,n){return this.createPartialRotationVectorToVector(t,1,e,n)}static create90DegreeRotationAroundAxis(t){if(t=f.cyclic3dAxis(t),t===0){const e=C.createRowValues(1,0,0,0,0,-1,0,1,0);return e.setupInverseTranspose(),e}else if(t===1){const e=C.createRowValues(0,0,1,0,1,0,-1,0,0);return e.setupInverseTranspose(),e}else{const e=C.createRowValues(0,-1,0,1,0,0,0,0,1);return e.setupInverseTranspose(),e}}columnX(t){return P.create(this.coffs[0],this.coffs[3],this.coffs[6],t)}columnY(t){return P.create(this.coffs[1],this.coffs[4],this.coffs[7],t)}columnZ(t){return P.create(this.coffs[2],this.coffs[5],this.coffs[8],t)}columnXMagnitudeSquared(){return f.hypotenuseSquaredXYZ(this.coffs[0],this.coffs[3],this.coffs[6])}columnYMagnitudeSquared(){return f.hypotenuseSquaredXYZ(this.coffs[1],this.coffs[4],this.coffs[7])}columnZMagnitudeSquared(){return f.hypotenuseSquaredXYZ(this.coffs[2],this.coffs[5],this.coffs[8])}columnXMagnitude(){return f.hypotenuseXYZ(this.coffs[0],this.coffs[3],this.coffs[6])}columnYMagnitude(){return f.hypotenuseXYZ(this.coffs[1],this.coffs[4],this.coffs[7])}columnZMagnitude(){return f.hypotenuseXYZ(this.coffs[2],this.coffs[5],this.coffs[8])}columnXYCrossProductMagnitude(){return f.crossProductMagnitude(this.coffs[0],this.coffs[3],this.coffs[6],this.coffs[1],this.coffs[4],this.coffs[7])}rowXMagnitude(){return f.hypotenuseXYZ(this.coffs[0],this.coffs[1],this.coffs[2])}rowYMagnitude(){return f.hypotenuseXYZ(this.coffs[3],this.coffs[4],this.coffs[5])}rowZMagnitude(){return f.hypotenuseXYZ(this.coffs[6],this.coffs[7],this.coffs[8])}columnXCrossColumnY(t){return f.crossProductXYZXYZ(this.coffs[0],this.coffs[3],this.coffs[6],this.coffs[1],this.coffs[4],this.coffs[7],t)}columnXDotColumnY(){return this.coffs[0]*this.coffs[1]+this.coffs[3]*this.coffs[4]+this.coffs[6]*this.coffs[7]}columnXDotColumnZ(){return this.coffs[0]*this.coffs[2]+this.coffs[3]*this.coffs[5]+this.coffs[6]*this.coffs[8]}columnYDotColumnZ(){return this.coffs[1]*this.coffs[2]+this.coffs[4]*this.coffs[5]+this.coffs[7]*this.coffs[8]}columnDotXYZ(t,e,n,i){return this.coffs[t]*e+this.coffs[t+3]*n+this.coffs[t+6]*i}rowX(t){return P.create(this.coffs[0],this.coffs[1],this.coffs[2],t)}rowY(t){return P.create(this.coffs[3],this.coffs[4],this.coffs[5],t)}rowZ(t){return P.create(this.coffs[6],this.coffs[7],this.coffs[8],t)}dotColumnX(t){return t.x*this.coffs[0]+t.y*this.coffs[3]+t.z*this.coffs[6]}dotColumnY(t){return t.x*this.coffs[1]+t.y*this.coffs[4]+t.z*this.coffs[7]}dotColumnZ(t){return t.x*this.coffs[2]+t.y*this.coffs[5]+t.z*this.coffs[8]}dotRowX(t){return t.x*this.coffs[0]+t.y*this.coffs[1]+t.z*this.coffs[2]}dotRowY(t){return t.x*this.coffs[3]+t.y*this.coffs[4]+t.z*this.coffs[5]}dotRowZ(t){return t.x*this.coffs[6]+t.y*this.coffs[7]+t.z*this.coffs[8]}dotRowXXYZ(t,e,n){return t*this.coffs[0]+e*this.coffs[1]+n*this.coffs[2]}dotRowYXYZ(t,e,n){return t*this.coffs[3]+e*this.coffs[4]+n*this.coffs[5]}dotRowZXYZ(t,e,n){return t*this.coffs[6]+e*this.coffs[7]+n*this.coffs[8]}columnZCrossVector(t,e){return f.crossProductXYZXYZ(this.coffs[2],this.coffs[5],this.coffs[8],t.x,t.y,t.z,e)}setColumnsPoint4dXYZ(t,e,n){this.inverseState=j.unknown,this.setRowValues(t.x,e.x,n.x,t.y,e.y,n.y,t.z,e.z,n.z)}setColumn(t,e){const n=f.cyclic3dAxis(t);this.inverseState=j.unknown,e?(this.coffs[n]=e.x,this.coffs[n+3]=e.y,this.coffs[n+6]=e.z):(this.coffs[n]=0,this.coffs[n+3]=0,this.coffs[n+6]=0)}setColumns(t,e,n){this.setColumn(0,t),this.setColumn(1,e),this.setColumn(2,n)}setRow(t,e){const n=3*f.cyclic3dAxis(t);this.coffs[n]=e.x,this.coffs[n+1]=e.y,this.coffs[n+2]=e.z,this.inverseState=j.unknown}getColumn(t,e){const n=f.cyclic3dAxis(t);return P.create(this.coffs[n],this.coffs[n+3],this.coffs[n+6],e)}getRow(t,e){const n=3*f.cyclic3dAxis(t);return P.create(this.coffs[n],this.coffs[n+1],this.coffs[n+2],e)}static createRows(t,e,n,i){return C.createRowValues(t.x,t.y,t.z,e.x,e.y,e.z,n.x,n.y,n.z,i)}static createDirectionalScale(t,e,n){const i=t.normalize();if(i){const s=i.x,r=i.y,o=i.z,a=e-1;return C.createRowValues(1+a*s*s,a*s*r,a*s*o,a*r*s,1+a*r*r,a*r*o,a*o*s,a*o*r,1+a*o*o,n)}return C.createUniformScale(e)}static createFlattenAlongVectorToPlane(t,e){const n=C.createIdentity(),i=t.dotProduct(e),s=f.conditionalDivideCoordinate(1,-i);if(s!==void 0)return n.addScaledOuterProductInPlace(t,e,s),n}multiplyPoint(t,e){const n=t.x,i=t.y,s=t.z;return y.create(this.coffs[0]*n+this.coffs[1]*i+this.coffs[2]*s,this.coffs[3]*n+this.coffs[4]*i+this.coffs[5]*s,this.coffs[6]*n+this.coffs[7]*i+this.coffs[8]*s,e)}multiplyVector(t,e){const n=t.x,i=t.y,s=t.z;return P.create(this.coffs[0]*n+this.coffs[1]*i+this.coffs[2]*s,this.coffs[3]*n+this.coffs[4]*i+this.coffs[5]*s,this.coffs[6]*n+this.coffs[7]*i+this.coffs[8]*s,e)}multiplyVectorArrayInPlace(t){for(const e of t)e.set(this.coffs[0]*e.x+this.coffs[1]*e.y+this.coffs[2]*e.z,this.coffs[3]*e.x+this.coffs[4]*e.y+this.coffs[5]*e.z,this.coffs[6]*e.x+this.coffs[7]*e.y+this.coffs[8]*e.z)}static xyzMinusMatrixTimesXYZ(t,e,n,i){const s=n.x,r=n.y,o=n.z;return y.create(t.x-(e.coffs[0]*s+e.coffs[1]*r+e.coffs[2]*o),t.y-(e.coffs[3]*s+e.coffs[4]*r+e.coffs[5]*o),t.z-(e.coffs[6]*s+e.coffs[7]*r+e.coffs[8]*o),i)}static xyPlusMatrixTimesXY(t,e,n,i){const s=n.x,r=n.y;return D.create(t.x+e.coffs[0]*s+e.coffs[1]*r,t.y+e.coffs[3]*s+e.coffs[4]*r,i)}static xyzPlusMatrixTimesXYZ(t,e,n,i){const s=n.x,r=n.y,o=n.z;return y.create(t.x+e.coffs[0]*s+e.coffs[1]*r+e.coffs[2]*o,t.y+e.coffs[3]*s+e.coffs[4]*r+e.coffs[5]*o,t.z+e.coffs[6]*s+e.coffs[7]*r+e.coffs[8]*o,i)}static xyzPlusMatrixTimesXYZInPlace(t,e,n){const i=n.x,s=n.y,r=n.z;n.x=t.x+e.coffs[0]*i+e.coffs[1]*s+e.coffs[2]*r,n.y=t.y+e.coffs[3]*i+e.coffs[4]*s+e.coffs[5]*r,n.z=t.z+e.coffs[6]*i+e.coffs[7]*s+e.coffs[8]*r}static xyzPlusMatrixTimesCoordinates(t,e,n,i,s,r){return y.create(t.x+e.coffs[0]*n+e.coffs[1]*i+e.coffs[2]*s,t.y+e.coffs[3]*n+e.coffs[4]*i+e.coffs[5]*s,t.z+e.coffs[6]*n+e.coffs[7]*i+e.coffs[8]*s,r)}static xyzPlusMatrixTimesWeightedCoordinates(t,e,n,i,s,r,o){return Z.create(e.coffs[0]*n+e.coffs[1]*i+e.coffs[2]*s+t.x*r,e.coffs[3]*n+e.coffs[4]*i+e.coffs[5]*s+t.y*r,e.coffs[6]*n+e.coffs[7]*i+e.coffs[8]*s+t.z*r,r,o)}static xyzPlusMatrixTimesWeightedCoordinatesToFloat64Array(t,e,n,i,s,r,o){return(!o||o.length<4)&&(o=new Float64Array(4)),o[0]=e.coffs[0]*n+e.coffs[1]*i+e.coffs[2]*s+t.x*r,o[1]=e.coffs[3]*n+e.coffs[4]*i+e.coffs[5]*s+t.y*r,o[2]=e.coffs[6]*n+e.coffs[7]*i+e.coffs[8]*s+t.z*r,o[3]=r,o}static xyzPlusMatrixTimesCoordinatesToFloat64Array(t,e,n,i,s,r){return(!r||r.length<3)&&(r=new Float64Array(3)),r[0]=e.coffs[0]*n+e.coffs[1]*i+e.coffs[2]*s+t.x,r[1]=e.coffs[3]*n+e.coffs[4]*i+e.coffs[5]*s+t.y,r[2]=e.coffs[6]*n+e.coffs[7]*i+e.coffs[8]*s+t.z,r}multiplyTransposeVector(t,e){e=e||new P;const n=t.x,i=t.y,s=t.z;return e.x=this.coffs[0]*n+this.coffs[3]*i+this.coffs[6]*s,e.y=this.coffs[1]*n+this.coffs[4]*i+this.coffs[7]*s,e.z=this.coffs[2]*n+this.coffs[5]*i+this.coffs[8]*s,e}multiplyXYZ(t,e,n,i){return i=i||new P,i.x=this.coffs[0]*t+this.coffs[1]*e+this.coffs[2]*n,i.y=this.coffs[3]*t+this.coffs[4]*e+this.coffs[5]*n,i.z=this.coffs[6]*t+this.coffs[7]*e+this.coffs[8]*n,i}multiplyXYZtoXYZ(t,e){const n=t.x,i=t.y,s=t.z;return e.x=this.coffs[0]*n+this.coffs[1]*i+this.coffs[2]*s,e.y=this.coffs[3]*n+this.coffs[4]*i+this.coffs[5]*s,e.z=this.coffs[6]*n+this.coffs[7]*i+this.coffs[8]*s,e}multiplyXY(t,e,n){return n=n||new P,n.x=this.coffs[0]*t+this.coffs[1]*e,n.y=this.coffs[3]*t+this.coffs[4]*e,n.z=this.coffs[6]*t+this.coffs[7]*e,n}originPlusMatrixTimesXY(t,e,n,i){return y.create(t.x+this.coffs[0]*e+this.coffs[1]*n,t.y+this.coffs[3]*e+this.coffs[4]*n,t.z+this.coffs[6]*e+this.coffs[7]*n,i)}multiplyVectorInPlace(t){const e=t.x,n=t.y,i=t.z;t.x=this.coffs[0]*e+this.coffs[1]*n+this.coffs[2]*i,t.y=this.coffs[3]*e+this.coffs[4]*n+this.coffs[5]*i,t.z=this.coffs[6]*e+this.coffs[7]*n+this.coffs[8]*i}multiplyTransposeVectorInPlace(t){const e=t.x,n=t.y,i=t.z;t.x=this.coffs[0]*e+this.coffs[3]*n+this.coffs[6]*i,t.y=this.coffs[1]*e+this.coffs[4]*n+this.coffs[7]*i,t.z=this.coffs[2]*e+this.coffs[5]*n+this.coffs[8]*i}multiplyTransposeXYZ(t,e,n,i){return i=i||new P,i.x=this.coffs[0]*t+this.coffs[3]*e+this.coffs[6]*n,i.y=this.coffs[1]*t+this.coffs[4]*e+this.coffs[7]*n,i.z=this.coffs[2]*t+this.coffs[5]*e+this.coffs[8]*n,i}multiplyInverse(t,e){if(this.computeCachedInverse(!0),this.inverseCoffs){const n=t.x,i=t.y,s=t.z;return P.create(this.inverseCoffs[0]*n+this.inverseCoffs[1]*i+this.inverseCoffs[2]*s,this.inverseCoffs[3]*n+this.inverseCoffs[4]*i+this.inverseCoffs[5]*s,this.inverseCoffs[6]*n+this.inverseCoffs[7]*i+this.inverseCoffs[8]*s,e)}}multiplyInverseTranspose(t,e){if(this.computeCachedInverse(!0),this.inverseCoffs){const n=t.x,i=t.y,s=t.z;return P.create(this.inverseCoffs[0]*n+this.inverseCoffs[3]*i+this.inverseCoffs[6]*s,this.inverseCoffs[1]*n+this.inverseCoffs[4]*i+this.inverseCoffs[7]*s,this.inverseCoffs[2]*n+this.inverseCoffs[5]*i+this.inverseCoffs[8]*s,e)}}multiplyInverseXYZAsVector3d(t,e,n,i){if(this.computeCachedInverse(!0),this.inverseCoffs)return P.create(this.inverseCoffs[0]*t+this.inverseCoffs[1]*e+this.inverseCoffs[2]*n,this.inverseCoffs[3]*t+this.inverseCoffs[4]*e+this.inverseCoffs[5]*n,this.inverseCoffs[6]*t+this.inverseCoffs[7]*e+this.inverseCoffs[8]*n,i)}multiplyInverseXYZW(t,e,n,i,s){if(this.computeCachedInverse(!0),this.inverseCoffs)return Z.create(this.inverseCoffs[0]*t+this.inverseCoffs[1]*e+this.inverseCoffs[2]*n,this.inverseCoffs[3]*t+this.inverseCoffs[4]*e+this.inverseCoffs[5]*n,this.inverseCoffs[6]*t+this.inverseCoffs[7]*e+this.inverseCoffs[8]*n,i,s)}multiplyInverseXYZAsPoint3d(t,e,n,i){if(this.computeCachedInverse(!0),this.inverseCoffs)return y.create(this.inverseCoffs[0]*t+this.inverseCoffs[1]*e+this.inverseCoffs[2]*n,this.inverseCoffs[3]*t+this.inverseCoffs[4]*e+this.inverseCoffs[5]*n,this.inverseCoffs[6]*t+this.inverseCoffs[7]*e+this.inverseCoffs[8]*n,i)}multiplyInverseXYZAsPoint2d(t,e,n,i){if(this.computeCachedInverse(!0))return D.create(this.inverseCoffs[0]*t+this.inverseCoffs[1]*e+this.inverseCoffs[2]*n,this.inverseCoffs[3]*t+this.inverseCoffs[4]*e+this.inverseCoffs[5]*n,i)}finishInverseCoffs(t,e,n){e&&n&&this.createInverseCoffsWithZeros()?(this.inverseState=j.inverseStored,t(e,n,this.inverseCoffs)):this.inverseState=j.unknown}multiplyMatrixMatrix(t,e){return e=e||new C,Lt.multiplyMatrixMatrix(this.coffs,t.coffs,e.coffs),this.inverseState===j.inverseStored&&t.inverseState===j.inverseStored?e.finishInverseCoffs((n,i,s)=>Lt.multiplyMatrixMatrix(n,i,s),t.inverseCoffs,this.inverseCoffs):this.inverseState===j.singular||t.inverseState===j.singular?e.inverseState=j.singular:e.inverseState=j.unknown,e}multiplyMatrixMatrixInverse(t,e){if(t.computeCachedInverse(!0))return e=e||new C,Lt.multiplyMatrixMatrix(this.coffs,t.inverseCoffs,C._productBuffer),this.inverseState===j.inverseStored?e.finishInverseCoffs((n,i,s)=>Lt.multiplyMatrixMatrix(n,i,s),t.coffs,this.inverseCoffs):e.inverseState=j.unknown,Lt.copy(C._productBuffer,e.coffs),e}multiplyMatrixInverseMatrix(t,e){if(this.computeCachedInverse(!0))return Lt.multiplyMatrixMatrix(this.inverseCoffs,t.coffs,C._productBuffer),e=e||new C,t.inverseState===j.inverseStored?e.finishInverseCoffs((n,i,s)=>Lt.multiplyMatrixMatrix(n,i,s),t.inverseCoffs,this.coffs):e.inverseState=j.unknown,Lt.copy(C._productBuffer,e.coffs),e}multiplyMatrixMatrixTranspose(t,e){return e=e||new C,Lt.multiplyMatrixMatrixTranspose(this.coffs,t.coffs,e.coffs),this.inverseState===j.inverseStored&&t.inverseState===j.inverseStored?e.finishInverseCoffs((n,i,s)=>Lt.multiplyMatrixTransposeMatrix(n,i,s),t.inverseCoffs,this.inverseCoffs):this.inverseState===j.singular||t.inverseState===j.singular?e.inverseState=j.singular:e.inverseState=j.unknown,e}multiplyMatrixTransposeMatrix(t,e){return e=e||new C,Lt.multiplyMatrixTransposeMatrix(this.coffs,t.coffs,e.coffs),this.inverseState===j.inverseStored&&t.inverseState===j.inverseStored?e.finishInverseCoffs((n,i,s)=>Lt.multiplyMatrixMatrixTranspose(n,i,s),t.inverseCoffs,this.inverseCoffs):this.inverseState===j.singular||t.inverseState===j.singular?e.inverseState=j.singular:e.inverseState=j.unknown,e}multiplyMatrixTransform(t,e){return e?(this.multiplyXYZtoXYZ(t.origin,e.origin),this.multiplyMatrixMatrix(t.matrix,e.matrix),e):X.createRefs(this.multiplyXYZ(t.origin.x,t.origin.y,t.origin.z),this.multiplyMatrixMatrix(t.matrix))}transpose(t){return t||(t=new C),Lt.copyTransposed(this.coffs,t.coffs),this.inverseCoffs!==void 0?(t.inverseState=j.inverseStored,t.inverseCoffs=Lt.copyTransposed(this.inverseCoffs,t.inverseCoffs)):(t.inverseState=this.inverseState,t.inverseCoffs=void 0),t}transposeInPlace(){Lt.transposeInPlace(this.coffs),this.inverseCoffs&&Lt.transposeInPlace(this.inverseCoffs)}inverse(t){if(this.computeCachedInverse(!0))return t===this?(Lt.copy(this.coffs,C._productBuffer),Lt.copy(this.inverseCoffs,this.coffs),Lt.copy(C._productBuffer,this.inverseCoffs),t):(t===void 0&&(t=C.createIdentity()),t.createInverseCoffsWithZeros(),t.inverseCoffs,Lt.copy(this.coffs,t.inverseCoffs),Lt.copy(this.inverseCoffs,t.coffs),t.inverseState=this.inverseState,t)}static rowColumnDot(t,e,n,i){return t[e]*n[i]+t[e+1]*n[i+3]+t[e+2]*n[i+6]}static indexedRowCrossProduct(t,e,n,i,s){i[s]=t[e+1]*t[n+2]-t[e+2]*t[n+1],i[s+3]=t[e+2]*t[n]-t[e]*t[n+2],i[s+6]=t[e]*t[n+1]-t[e+1]*t[n]}indexedColumnCrossProductInPlace(t,e,n){const i=this.coffs;i[n]=i[t+3]*i[e+6]-i[t+6]*i[e+3],i[n+3]=i[t+6]*i[e]-i[t]*i[e+6],i[n+6]=i[t]*i[e+3]-i[t+3]*i[e]}axisOrderCrossProductsInPlace(t){switch(t){case mt.XYZ:{this.indexedColumnCrossProductInPlace(0,1,2),this.indexedColumnCrossProductInPlace(2,0,1);break}case mt.YZX:{this.indexedColumnCrossProductInPlace(1,2,0),this.indexedColumnCrossProductInPlace(0,1,2);break}case mt.ZXY:{this.indexedColumnCrossProductInPlace(2,0,1),this.indexedColumnCrossProductInPlace(1,2,0);break}case mt.XZY:{this.indexedColumnCrossProductInPlace(0,2,1),this.indexedColumnCrossProductInPlace(1,0,2);break}case mt.YXZ:{this.indexedColumnCrossProductInPlace(1,0,2),this.indexedColumnCrossProductInPlace(2,1,0);break}case mt.ZYX:{this.indexedColumnCrossProductInPlace(2,1,0),this.indexedColumnCrossProductInPlace(0,2,1);break}}}normalizeColumnsInPlace(t){const e=this.columnXMagnitude(),n=this.columnYMagnitude(),i=this.columnZMagnitude();return t&&t.set(e,n,i),f.isSmallMetricDistance(e)||f.isSmallMetricDistance(n)||f.isSmallMetricDistance(i)?!1:(this.scaleColumns(1/e,1/n,1/i,this),!0)}normalizeRowsInPlace(t){const e=this.rowXMagnitude(),n=this.rowYMagnitude(),i=this.rowZMagnitude();return t&&t.set(e,n,i),f.isSmallMetricDistance(e)||f.isSmallMetricDistance(n)||f.isSmallMetricDistance(i)?!1:(this.scaleRows(1/e,1/n,1/i,this),!0)}isSingular(){return!this.computeCachedInverse(!0)}markSingular(){this.inverseState=j.singular}computeCachedInverse(t){if(t&&C.useCachedInverse&&this.inverseState!==j.unknown)return C.numUseCache++,this.inverseState===j.inverseStored;if(this.inverseState=j.unknown,this.createInverseCoffsWithZeros()){const e=this.coffs,n=this.inverseCoffs;C.indexedRowCrossProduct(e,3,6,n,0),C.indexedRowCrossProduct(e,6,0,n,1),C.indexedRowCrossProduct(e,0,3,n,2),C.numComputeCache++;const i=C.rowColumnDot(e,0,n,0);if(i===0)this.inverseState=j.singular;else{const s=1/i;for(let r=0;r<9;r++)n[r]*=s;return this.inverseState=j.inverseStored,!0}}return this.inverseCoffs=void 0,!1}static flatIndexOf(t,e){return 3*f.cyclic3dAxis(t)+f.cyclic3dAxis(e)}indexedColumnWithWeight(t,e,n){return t=f.cyclic3dAxis(t),Z.create(this.coffs[t],this.coffs[t+3],this.coffs[t+6],e,n)}at(t,e){return this.coffs[C.flatIndexOf(t,e)]}setAt(t,e,n){this.coffs[C.flatIndexOf(t,e)]=n,this.inverseState=j.unknown}scale(t,e){return C.createRowValues(this.coffs[0]*t,this.coffs[1]*t,this.coffs[2]*t,this.coffs[3]*t,this.coffs[4]*t,this.coffs[5]*t,this.coffs[6]*t,this.coffs[7]*t,this.coffs[8]*t,e)}scaleColumns(t,e,n,i){return C.createRowValues(this.coffs[0]*t,this.coffs[1]*e,this.coffs[2]*n,this.coffs[3]*t,this.coffs[4]*e,this.coffs[5]*n,this.coffs[6]*t,this.coffs[7]*e,this.coffs[8]*n,i)}scaleColumnsInPlace(t,e,n){if(this.coffs[0]*=t,this.coffs[1]*=e,this.coffs[2]*=n,this.coffs[3]*=t,this.coffs[4]*=e,this.coffs[5]*=n,this.coffs[6]*=t,this.coffs[7]*=e,this.coffs[8]*=n,this.inverseState===j.inverseStored&&this.inverseCoffs!==void 0){const i=f.conditionalDivideFraction(1,t),s=f.conditionalDivideFraction(1,e),r=f.conditionalDivideFraction(1,n);i!==void 0&&s!==void 0&&r!==void 0?(this.inverseCoffs[0]*=i,this.inverseCoffs[1]*=i,this.inverseCoffs[2]*=i,this.inverseCoffs[3]*=s,this.inverseCoffs[4]*=s,this.inverseCoffs[5]*=s,this.inverseCoffs[6]*=r,this.inverseCoffs[7]*=r,this.inverseCoffs[8]*=r):this.inverseState=j.singular}}scaleRows(t,e,n,i){return C.createRowValues(this.coffs[0]*t,this.coffs[1]*t,this.coffs[2]*t,this.coffs[3]*e,this.coffs[4]*e,this.coffs[5]*e,this.coffs[6]*n,this.coffs[7]*n,this.coffs[8]*n,i)}scaleRowsInPlace(t,e,n){if(this.coffs[0]*=t,this.coffs[1]*=t,this.coffs[2]*=t,this.coffs[3]*=e,this.coffs[4]*=e,this.coffs[5]*=e,this.coffs[6]*=n,this.coffs[7]*=n,this.coffs[8]*=n,this.inverseState===j.inverseStored&&this.inverseCoffs!==void 0){const i=f.conditionalDivideFraction(1,t),s=f.conditionalDivideFraction(1,e),r=f.conditionalDivideFraction(1,n);i!==void 0&&s!==void 0&&r!==void 0?(this.inverseCoffs[0]*=i,this.inverseCoffs[1]*=s,this.inverseCoffs[2]*=r,this.inverseCoffs[3]*=i,this.inverseCoffs[4]*=s,this.inverseCoffs[5]*=r,this.inverseCoffs[6]*=i,this.inverseCoffs[7]*=s,this.inverseCoffs[8]*=r):this.inverseState=j.singular}}addScaledInPlace(t,e){for(let n=0;n<9;n++)this.coffs[n]+=e*t.coffs[n];this.inverseState=j.unknown}addScaledOuterProductInPlace(t,e,n){this.coffs[0]+=n*t.x*e.x,this.coffs[1]+=n*t.x*e.y,this.coffs[2]+=n*t.x*e.z,this.coffs[3]+=n*t.y*e.x,this.coffs[4]+=n*t.y*e.y,this.coffs[5]+=n*t.y*e.z,this.coffs[6]+=n*t.z*e.x,this.coffs[7]+=n*t.z*e.y,this.coffs[8]+=n*t.z*e.z,this.inverseState=j.unknown}static createRigidViewAxesZTowardsEye(t,e,n,i){i=C.createIdentity(i);const s=f.hypotenuseXY(t,e);if(f.isSmallMetricDistance(s))n<0&&i.scaleColumnsInPlace(1,-1,-1);else{const r=t/s,o=e/s;if(i.setRowValues(-o,0,r,r,0,o,0,1,0),n!==0){const a=f.hypotenuseXYZ(t,e,n),c=n/a,l=s/a;i.applyGivensColumnOp(1,2,l,-c)}}return i}determinant(){return this.coffs[0]*this.coffs[4]*this.coffs[8]-this.coffs[0]*this.coffs[5]*this.coffs[7]-this.coffs[1]*this.coffs[3]*this.coffs[8]+this.coffs[1]*this.coffs[5]*this.coffs[6]+this.coffs[2]*this.coffs[3]*this.coffs[7]-this.coffs[2]*this.coffs[4]*this.coffs[6]}conditionNumber(){const t=Math.abs(this.determinant()),e=f.hypotenuseXYZ(this.coffs[0],this.coffs[3],this.coffs[6])+f.hypotenuseXYZ(this.coffs[1],this.coffs[4],this.coffs[7])+f.hypotenuseXYZ(this.coffs[2],this.coffs[5],this.coffs[8]);return f.safeDivideFraction(t,e,0)}sumSquares(){let t=0;for(let e=0;e<9;e++)t+=this.coffs[e]*this.coffs[e];return t}sumDiagonalSquares(){let t=0;for(let e=0;e<9;e+=4)t+=this.coffs[e]*this.coffs[e];return t}sumDiagonal(){return this.coffs[0]+this.coffs[4]+this.coffs[8]}maxAbs(){let t=0;for(let e=0;e<9;e++)t=Math.max(t,Math.abs(this.coffs[e]));return t}maxDiff(t){let e=0;for(let n=0;n<9;n++)e=Math.max(e,Math.abs(this.coffs[n]-t.coffs[n]));return e}get isIdentity(){return this.maxDiff(C.identity)<f.smallAngleRadians}get isDiagonal(){const t=this.sumSquares(),e=this.sumDiagonalSquares(),n=Math.abs(t-e);return Math.sqrt(n)<=f.smallAngleRadians*(1+Math.sqrt(t))}sumSkewSquares(){return f.hypotenuseSquaredXYZ(this.coffs[1]-this.coffs[3],this.coffs[2]-this.coffs[6],this.coffs[5]-this.coffs[7])}isSymmetric(){const t=this.sumSkewSquares();return Math.sqrt(t)<=f.smallAngleRadians*(1+Math.sqrt(this.sumSquares()))}get hasCachedInverse(){return this.inverseState===j.inverseStored&&this.inverseCoffs!==void 0}get isUpperTriangular(){const t=this.sumSquares(),e=f.hypotenuseSquaredXYZ(this.coffs[3],this.coffs[6],this.coffs[7]);return Math.sqrt(e)<=f.smallAngleRadians*(1+Math.sqrt(t))}get isLowerTriangular(){const t=this.sumSquares(),e=f.hypotenuseSquaredXYZ(this.coffs[1],this.coffs[2],this.coffs[5]);return Math.sqrt(e)<=f.smallAngleRadians*(1+Math.sqrt(t))}sameDiagonalScale(){const t=this.sumSquares(),e=this.sumDiagonalSquares(),n=Math.abs(t-e);if(Math.sqrt(n)<=f.smallAngleRadians*(1+Math.sqrt(t))&&f.isSameCoordinate(this.coffs[0],this.coffs[4])&&f.isSameCoordinate(this.coffs[0],this.coffs[8]))return this.coffs[0]}testPerpendicularUnitRowsAndColumns(){return this.multiplyMatrixMatrixTranspose(this).isIdentity}isRigid(t=!1){return this.testPerpendicularUnitRowsAndColumns()&&(t||this.determinant()>0)}factorRigidWithSignedScale(t){const n=this.multiplyMatrixMatrixTranspose(this).sameDiagonalScale();if(n===void 0||n<=0)return;const i=this.determinant()>0?Math.sqrt(n):-Math.sqrt(n),s=1/i;return{rigidAxes:this.scaleColumns(s,s,s,t),scale:i}}factorRigidSkew(t,e,n=mt.XYZ){return C.createRigidFromMatrix3d(this,n,t)?(t.multiplyMatrixTransposeMatrix(this,e),!0):(t.setIdentity(),e.setFrom(this),!1)}get isSignedPermutation(){let t=0;for(let e=0;e<3;e++)for(let n=0;n<3;n++){const i=this.at(e,n);if(i!==0)if(i===1||i===-1){if(t++,this.at(e+1,n)!==0||this.at(e+2,n)!==0||this.at(e,n+1)!==0||this.at(e,n+2)!==0)return!1}else return!1}return t===3}makeRigid(t=mt.XYZ){const e=this.maxAbs();if(f.isSmallMetricDistance(e))return!1;const n=1/e;return this.scaleColumnsInPlace(n,n,n),this.axisOrderCrossProductsInPlace(t),this.normalizeColumnsInPlace()}static createRigidFromMatrix3d(t,e=mt.XYZ,n){if(n=t.clone(n),n.makeRigid(e))return n}static createFromQuaternion(t){const e=t.x*t.x,n=t.y*t.y,i=t.z*t.z,s=t.w*t.w,r=e+n+i+s;if(r===0)return C.createIdentity();{const o=1/r;return C.createRowValues(o*(s+e-n-i),2*o*(t.w*t.z+t.x*t.y),2*o*(t.x*t.z-t.w*t.y),2*o*(t.x*t.y-t.w*t.z),o*(s-e+n-i),2*o*(t.w*t.x+t.y*t.z),2*o*(t.x*t.z+t.w*t.y),2*o*(t.y*t.z-t.w*t.x),o*(s-e-n+i))}}static computeQuatTerm(t,e,n,i){let s;return i>.5?(s=.5*Math.sqrt(i),e*t<0&&(s=-s)):s=t*n,s}toQuaternion(){const t=Z.createZero(),e=[[this.coffs[0],this.coffs[3],this.coffs[6]],[this.coffs[1],this.coffs[4],this.coffs[7]],[this.coffs[2],this.coffs[5],this.coffs[8]]],n=e[0][0],i=e[1][1],s=e[2][2],r=[];r[0]=1+n-i-s,r[1]=1-n+i-s,r[2]=1-n-i+s,r[3]=1+n+i+s;let o,a=0;for(let c=1;c<=3;c++)r[c]>r[a]&&(a=c);return a===0?(t.x=.5*Math.sqrt(r[0]),o=1/(4*t.x),t.y=C.computeQuatTerm(e[0][1]+e[1][0],t.x,o,r[1]),t.z=C.computeQuatTerm(e[0][2]+e[2][0],t.x,o,r[2]),t.w=C.computeQuatTerm(e[2][1]-e[1][2],t.x,o,r[3])):a===1?(t.y=.5*Math.sqrt(r[1]),o=1/(4*t.y),t.x=C.computeQuatTerm(e[0][1]+e[1][0],t.y,o,r[0]),t.z=C.computeQuatTerm(e[1][2]+e[2][1],t.y,o,r[2]),t.w=C.computeQuatTerm(e[0][2]-e[2][0],t.y,o,r[3])):a===2?(t.z=.5*Math.sqrt(r[2]),o=1/(4*t.z),t.x=C.computeQuatTerm(e[0][2]+e[2][0],t.z,o,r[0]),t.y=C.computeQuatTerm(e[1][2]+e[2][1],t.z,o,r[1]),t.w=C.computeQuatTerm(e[1][0]-e[0][1],t.z,o,r[3])):(t.w=.5*Math.sqrt(r[3]),o=1/(4*t.w),t.x=C.computeQuatTerm(e[2][1]-e[1][2],t.w,o,r[0]),t.y=C.computeQuatTerm(e[0][2]-e[2][0],t.w,o,r[1]),t.z=C.computeQuatTerm(e[1][0]-e[0][1],t.w,o,r[2])),t}}class Wi{world;local;a;closestEdgeIndex;closestEdgeParam;constructor(){this.world=new y,this.local=new y,this.a=0,this.closestEdgeIndex=0,this.closestEdgeParam=0}invalidate(){this.world.setZero(),this.local.setZero(),this.a=0,this.closestEdgeIndex=0,this.closestEdgeParam=0}static create(t){return t===void 0?t=new Wi:t.invalidate(),t}copyContentsFrom(t){this.world.setFrom(t.world),this.local.setFrom(t.local),this.a=t.a,this.closestEdgeIndex=t.closestEdgeIndex,this.closestEdgeParam=t.closestEdgeParam}get isValid(){return!this.local.isZero}get isInsideOrOn(){return this.isValid&&this.local.x>=0&&this.local.y>=0&&this.local.z>=0}get classify(){if(!this.isValid)return yt.Unknown;if(this.isInsideOrOn){let t=0;return Math.abs(this.local.x)===0&&++t,Math.abs(this.local.y)===0&&++t,Math.abs(this.local.z)===0&&++t,t===2?yt.OnPolygonVertex:t===1?yt.OnPolygonEdgeInterior:yt.InsidePolygonProjectsToEdgeInterior}return this.closestEdgeParam===0?yt.OutsidePolygonProjectsToVertex:yt.OutsidePolygonProjectsToEdgeInterior}}class gt{points;edgeLength2;static _workPoint;static _workVector0;static _workVector1;static _workRay;static _workMatrix;constructor(t,e,n){this.points=[],this.points.push(t),this.points.push(e),this.points.push(n),this.edgeLength2=[],this.edgeLength2.push(e.distanceSquared(n)),this.edgeLength2.push(t.distanceSquared(n)),this.edgeLength2.push(t.distanceSquared(e))}set(t,e,n){this.points[0].setFromPoint3d(t),this.points[1].setFromPoint3d(e),this.points[2].setFromPoint3d(n),this.edgeLength2[0]=this.points[1].distanceSquared(this.points[2]),this.edgeLength2[1]=this.points[0].distanceSquared(this.points[2]),this.edgeLength2[2]=this.points[0].distanceSquared(this.points[1])}setFrom(t){for(let e=0;e<3;++e)this.points[e].setFromPoint3d(t.points[e]),this.edgeLength2[e]=t.edgeLength2[e]}static createXYZXYZXYZ(t,e,n,i,s,r,o,a,c,l){return l?(l.points[0].set(t,e,n),l.points[1].set(i,s,r),l.points[2].set(o,a,c),l):new this(y.create(t,e,n),y.create(i,s,r),y.create(o,a,c))}static create(t,e,n,i){return i?(i.set(t,e,n),i):new this(t.clone(),e.clone(),n.clone())}clone(t){return gt.create(this.points[0],this.points[1],this.points[2],t)}cloneTransformed(t,e){return gt.create(t.multiplyPoint3d(this.points[0],e?.points[0]),t.multiplyPoint3d(this.points[1],e?.points[1]),t.multiplyPoint3d(this.points[2],e?.points[2]),e)}get area(){return .5*this.points[0].crossProductToPointsMagnitude(this.points[1],this.points[2])}edgeLengthSquared(t){return this.edgeLength2[f.cyclic3dAxis(t)]}edgeLength(t){return Math.sqrt(this.edgeLengthSquared(t))}get aspectRatio(){return f.safeDivideFraction(this.area,this.edgeLengthSquared(0)+this.edgeLengthSquared(1)+this.edgeLengthSquared(2),0)}get perimeter(){return this.edgeLength(0)+this.edgeLength(1)+this.edgeLength(2)}normal(t){const e=this.points[0].crossProductToPoints(this.points[1],this.points[2],t);if(e.tryNormalizeInPlace())return e}fractionToPoint(t,e,n,i){return y.createAdd3Scaled(this.points[0],t,this.points[1],e,this.points[2],n,i)}pointToFraction(t,e){const n=gt._workVector0=this.normal(gt._workVector0);if(n===void 0)return Wi.create(e);const i=gt._workRay=O.create(t,n,gt._workRay);return this.intersectRay3d(i,e)}static edgeOppositeVertexIndexToStartVertexIndex(t){return f.cyclic3dAxis(t+1)}static edgeStartVertexIndexToOppositeVertexIndex(t){return f.cyclic3dAxis(t-1)}static isInsideTriangle(t,e,n){return t>0&&e>0&&n>0}static isInsideOrOnTriangle(t,e,n){return t>=0&&e>=0&&n>=0}static isInRegionBeyondEdge(t,e,n){return t<0&&e>=0&&n>=0?0:t>=0&&e<0&&n>=0?1:t>=0&&e>=0&&n<0?2:-1}static isInRegionBeyondVertex(t,e,n){return e<0&&n<0?0:t<0&&n<0?1:t<0&&e<0?2:-1}static isOnVertex(t,e,n){return t===1&&e===0&&n===0?0:t===0&&e===1&&n===0?1:t===0&&e===0&&n===1?2:-1}static isOnBoundedEdge(t,e,n){return t===0&&e>0&&n>0?0:t>0&&e===0&&n>0?1:t>0&&e>0&&n===0?2:-1}static indexOfMinimum(t){let e=0,n=t(0);const i=t(1);return n>i&&(e=1,n=i),n>t(2)&&(e=2),e}distanceSquared(t,e,n,i,s,r){return-this.edgeLengthSquared(0)*(s-e)*(r-n)-this.edgeLengthSquared(1)*(r-n)*(i-t)-this.edgeLengthSquared(2)*(i-t)*(s-e)}closestVertexIndex(t,e,n){return gt.indexOfMinimum(i=>{const s=gt._workPoint=y.createZero(gt._workPoint);return s.setAt(i,1),this.distanceSquared(s.x,s.y,s.z,t,e,n)})}dotProductOfEdgeVectorsAtVertex(t){const e=f.cyclic3dAxis(t),n=f.cyclic3dAxis(e+1),i=f.cyclic3dAxis(n+1);return f.dotProductXYZXYZ(this.points[n].x-this.points[e].x,this.points[n].y-this.points[e].y,this.points[n].z-this.points[e].z,this.points[i].x-this.points[e].x,this.points[i].y-this.points[e].y,this.points[i].z-this.points[e].z)}computeProjectionToEdge(t,e){t=f.cyclic3dAxis(t);const n=f.cyclic3dAxis(t+1),i=f.cyclic3dAxis(n+1);return e[i]+e[t]*this.dotProductOfEdgeVectorsAtVertex(n)/this.edgeLengthSquared(t)}closestPoint(t,e,n){const i=[t,e,n];let s=-1,r=0;return gt.isInsideTriangle(t,e,n)?(s=gt.indexOfMinimum(o=>i[o]*i[o]/this.edgeLengthSquared(o)),r=this.computeProjectionToEdge(s,i)):(s=gt.isInRegionBeyondVertex(t,e,n))>=0?(s=f.cyclic3dAxis(s+1),r=this.computeProjectionToEdge(s,i),(r<0||r>1)&&(s=f.cyclic3dAxis(s+1),r=this.computeProjectionToEdge(s,i),(r<0||r>1)&&(r=0,s=gt.edgeStartVertexIndexToOppositeVertexIndex(this.closestVertexIndex(t,e,n))))):(s=gt.isInRegionBeyondEdge(t,e,n))>=0?(r=this.computeProjectionToEdge(s,i),r<0?r=0:r>1&&(r=0,s=f.cyclic3dAxis(s+1))):(s=gt.isOnBoundedEdge(t,e,n))>=0?r=1-i[gt.edgeOppositeVertexIndexToStartVertexIndex(s)]:(s=gt.isOnVertex(t,e,n))>=0&&(r=0,s=gt.edgeStartVertexIndexToOppositeVertexIndex(s)),{closestEdgeIndex:s<0?-1:gt.edgeOppositeVertexIndexToStartVertexIndex(s),closestEdgeParam:r}}intersectRay3d(t,e){e=Wi.create(e);const n=t.origin,i=t.direction,s=gt._workVector0=P.createStartEnd(this.points[0],this.points[1],gt._workVector0),r=gt._workVector1=P.createStartEnd(this.points[0],this.points[2],gt._workVector1),o=i.tripleProduct(s,r);if(o*o<=s.dotProduct(s)*r.dotProduct(r)*i.dotProduct(i)*f.smallAngleRadiansSquared)return e;const a=gt._workMatrix=C.createColumns(s,r,i,gt._workMatrix),c=P.createStartEnd(this.points[0],n,gt._workVector0),l=gt._workVector1;if(a.multiplyInverse(c,l)===void 0)return e;e.a=-l.z,t.fractionToPoint(e.a,e.world),e.local.set(1-l.x-l.y,l.x,l.y);const d=this.closestPoint(e.local.x,e.local.y,e.local.z);return e.closestEdgeIndex=d.closestEdgeIndex,e.closestEdgeParam=d.closestEdgeParam,e}intersectSegment(t,e,n){return gt._workRay=O.createStartEnd(t,e,gt._workRay),this.intersectRay3d(gt._workRay,n)}snapLocationToEdge(t,e=f.smallMetricDistance,n=f.smallFloatingPoint){if(!t.isValid)return!1;if(n>0){let i=0,s=0;for(let r=0;r<3;r++){const o=Math.abs(t.local.at(r));o>0&&o<n&&(t.local.setAt(r,0),i++),s+=t.local.at(r)}if(i>0&&s>0)return t.local.scaleInPlace(1/s),i===1?(t.closestEdgeIndex=gt.edgeOppositeVertexIndexToStartVertexIndex(gt.isOnBoundedEdge(t.local.x,t.local.y,t.local.z)),t.closestEdgeParam=1-t.local.at(t.closestEdgeIndex)):(t.closestEdgeIndex=gt.isOnVertex(t.local.x,t.local.y,t.local.z),t.closestEdgeParam=0),this.fractionToPoint(t.local.x,t.local.y,t.local.z,t.world),!0}if(e>0){const i=t.closestEdgeIndex,s=(i+1)%3,r=(s+1)%3,o=gt._workPoint=this.points[i].interpolate(t.closestEdgeParam,this.points[s],gt._workPoint),a=t.world.distance(o);if(a>0&&a<e)return t.local.setAt(i,1-t.closestEdgeParam),t.local.setAt(s,t.closestEdgeParam),t.local.setAt(r,0),t.world.setFrom(o),!0}return!1}dotProductOfCrossProductsFromOrigin(t){return gt._workVector0=this.points[0].crossProductToPoints(this.points[1],this.points[2],gt._workVector0),gt._workVector1=t.points[0].crossProductToPoints(t.points[1],t.points[2],gt._workVector1),gt._workVector0.dotProduct(gt._workVector1)}centroid(t){return y.create((this.points[0].x+this.points[1].x+this.points[2].x)/3,(this.points[0].y+this.points[1].y+this.points[2].y)/3,(this.points[0].z+this.points[1].z+this.points[2].z)/3,t)}incenter(t){const e=this.edgeLength(0),n=this.edgeLength(1),i=this.edgeLength(2),s=f.safeDivideFraction(1,e+n+i,0);return this.fractionToPoint(s*e,s*n,s*i,t)}circumcenter(t){const e=this.edgeLengthSquared(0),n=this.edgeLengthSquared(1),i=this.edgeLengthSquared(2),s=e*(n+i-e),r=n*(i+e-n),o=i*(e+n-i),a=f.safeDivideFraction(1,s+r+o,0);return this.fractionToPoint(a*s,a*r,a*o,t)}isAlmostEqual(t,e){return this.points[0].isAlmostEqual(t.points[0],e)&&this.points[1].isAlmostEqual(t.points[1],e)&&this.points[2].isAlmostEqual(t.points[2],e)}}class Es{surface;uv;point;a;constructor(t,e,n){this.surface=t,this.point=n||y.createZero(),this.uv=e||D.createZero(),this.a=0}static createSurfaceUVPoint(t,e,n){const i=new Es(t);return e&&i.uv.setFrom(e),i.point.setFromPoint3d(n),i}static createSurfaceUVNumbersPoint(t,e,n,i){const s=new Es(t);return s.uv.x=e,s.uv.y=n,s.point.setFromPoint3d(i),s}}class hc{curveDetail;surfaceDetail;constructor(t,e){this.curveDetail=t,this.surfaceDetail=e}}class Ge{point00;point10;point01;point11;constructor(t,e,n,i){this.point00=t,this.point10=e,this.point01=n,this.point11=i}static create(t,e,n,i){return new Ge(t.clone(),e.clone(),n.clone(),i.clone())}static createXYZ(t,e,n,i,s,r,o,a,c,l,d,h){return new Ge(y.create(t,e,n),y.create(i,s,r),y.create(o,a,c),y.create(l,d,h))}clone(){return new Ge(this.point00.clone(),this.point10.clone(),this.point01.clone(),this.point11.clone())}isAlmostEqual(t){return this.point00.isAlmostEqual(t.point00)&&this.point10.isAlmostEqual(t.point10)&&this.point01.isAlmostEqual(t.point01)&&this.point11.isAlmostEqual(t.point11)}tryTransformInPlace(t){return t.multiplyPoint3d(this.point00,this.point00),t.multiplyPoint3d(this.point10,this.point10),t.multiplyPoint3d(this.point01,this.point01),t.multiplyPoint3d(this.point11,this.point11),!0}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}extendRange(t,e){e?(t.extendTransformedPoint(e,this.point00),t.extendTransformedPoint(e,this.point10),t.extendTransformedPoint(e,this.point01),t.extendTransformedPoint(e,this.point11)):(t.extendPoint(this.point00),t.extendPoint(this.point10),t.extendPoint(this.point01),t.extendPoint(this.point11))}uvFractionToPoint(t,e,n){const i=(1-t)*(1-e),s=t*(1-e),r=(1-t)*e,o=t*e;return y.create(i*this.point00.x+s*this.point10.x+r*this.point01.x+o*this.point11.x,i*this.point00.y+s*this.point10.y+r*this.point01.y+o*this.point11.y,i*this.point00.z+s*this.point10.z+r*this.point01.z+o*this.point11.z,n)}uvFractionToPointAndTangents(t,e,n){const i=1-t,s=1-e,r=i*s,o=t*s,a=i*e,c=t*e;return At.createOriginAndVectorsXYZ(r*this.point00.x+o*this.point10.x+a*this.point01.x+c*this.point11.x,r*this.point00.y+o*this.point10.y+a*this.point01.y+c*this.point11.y,r*this.point00.z+o*this.point10.z+a*this.point01.z+c*this.point11.z,s*(this.point10.x-this.point00.x)+e*(this.point11.x-this.point01.x),s*(this.point10.y-this.point00.y)+e*(this.point11.y-this.point01.y),s*(this.point10.z-this.point00.z)+e*(this.point11.z-this.point01.z),i*(this.point01.x-this.point00.x)+t*(this.point11.x-this.point10.x),i*(this.point01.y-this.point00.y)+t*(this.point11.y-this.point10.y),i*(this.point01.z-this.point00.z)+t*(this.point11.z-this.point10.z),n)}static conditionalPivot(t,e,n,i){if(Math.abs(e[i][t])>Math.abs(e[n][t])){const s=e[n];e[n]=e[i],e[i]=s}}intersectRay(t){const e=this.point10.minus(this.point00),n=this.point01.minus(this.point00),i=this.point11.minus(this.point10);i.subtractInPlace(n);const s=[new Float64Array([-t.direction.x,this.point00.x-t.origin.x,e.x,n.x,i.x]),new Float64Array([-t.direction.y,this.point00.y-t.origin.y,e.y,n.y,i.y]),new Float64Array([-t.direction.z,this.point00.z-t.origin.z,e.z,n.z,i.z])];Ge.conditionalPivot(0,s,0,1),Ge.conditionalPivot(0,s,0,2),bt.eliminateFromPivot(s[0],0,s[1],-1),bt.eliminateFromPivot(s[0],0,s[2],-1);const r=bt.solveBilinearPair(s[1][1],s[1][2],s[1][3],s[1][4],s[2][1],s[2][2],s[2][3],s[2][4]);if(r){const o=[];for(const a of r){const c=-(s[0][1]+s[0][2]*a.x+(s[0][3]+s[0][4]*a.x)*a.y)/s[0][0],l=t.fractionToPoint(c);o.push(new hc(Y.createRayFractionPoint(t,c,l),Es.createSurfaceUVPoint(this,a,l)))}return o}}maxUEdgeLength(){return f.maxXY(this.point00.distance(this.point10),this.point01.distance(this.point11))}maxVEdgeLength(){return f.maxXY(this.point00.distance(this.point01),this.point10.distance(this.point11))}}class Rs{static oneMillimeter=.001;static oneCentimeter=.01;static oneMeter=1;static oneKilometer=1e3;static diameterOfEarth=12742*Rs.oneKilometer;static circumferenceOfEarth=40075*Rs.oneKilometer;static earthRadiusWGS84={polar:63567523142e-4,equator:6378137}}var Ht;(function(u){u[u.None=0]="None",u[u.OnTangent=1]="OnTangent",u[u.OnCurve=2]="OnCurve"})(Ht||(Ht={}));class Ut{static resolveVariantCurveExtendParameterToCurveExtendMode(t,e){return t??=!1,t===!1?Ht.None:t===!0?Ht.OnCurve:Array.isArray(t)?t.length>e?t[e]:Ht.None:t}static correctFraction(t,e){return t??=!1,e<0?Ut.resolveVariantCurveExtendParameterToCurveExtendMode(t,0)===Ht.None&&(e=0):e>1&&Ut.resolveVariantCurveExtendParameterToCurveExtendMode(t,1)===Ht.None&&(e=1),e}static resolveRadiansToValidSweepFraction(t,e,n){t??=!1;let i=n.radiansToSignedPeriodicFraction(e),s=!0;if(!n.isRadiansInSweep(e)){const r=n.fractionPeriod(),o=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(t,0),a=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(t,1);o!==Ht.None?a===Ht.None&&i>1&&(i-=r):a!==Ht.None?i<0&&(i+=r):(i=f.clamp(i,0,1),s=!1)}return{fraction:i,isValid:s}}static resolveRadiansToSweepFraction(t,e,n){return this.resolveRadiansToValidSweepFraction(t,e,n).fraction}}class dn{numStroke;curveLength;a0;a1;componentData;primitive;componentIndex;constructor(t,e,n,i,s){this.numStroke=t,this.curveLength=e,this.a0=n,this.a1=i,this.componentData=s}static createWithCurvePrimitive(t,e,n,i,s,r){const o=new dn(e,n,i,s,r);return o.primitive=t,o}static createWithComponentIndex(t=0,e=0,n=0,i=0,s=0){const r=new dn(e,n,i,s);return r.componentIndex=t,r}static createWithCurvePrimitiveAndOptionalParent(t,e,n){const i=e?e.a1:0,s=new dn(0,0,i,i,n);return s.primitive=t,s}addToCountAndLength(t,e){const n=this.a1+e;this.componentData&&this.componentData.push(new dn(t,e,this.a1,n)),this.numStroke+=t,this.curveLength+=e,this.a1=n}isCompatibleComponentStructure(t,e){if(e&&this.numStroke!==t.numStroke)return!1;if(this.componentData===void 0&&t.componentData===void 0)return!0;if(this.componentData&&t.componentData){if(this.componentData.length!==t.componentData.length)return!1;const n=this.componentData.length;for(let i=0;i<n;i++)if(!this.componentData[i].isCompatibleComponentStructure(t.componentData[i],e))return!1;return!0}return!1}clone(){const t=new dn(this.numStroke,this.curveLength,this.a0,this.a1);if(this.componentData){t.componentData=[];for(const e of this.componentData)t.componentData.push(e.clone())}return t}fractionToA(t){return f.interpolate(this.a0,t,this.a1)}}class Ae{range(t,e){e&&e.setNull();const n=e||J.createNull();return this.extendRange(n,t),n}tryTranslateInPlace(t,e=0,n=0){return this.tryTransformInPlace(X.createTranslationXYZ(t,e,n))}get children(){}isAlmostEqual(t){if(this.isSameGeometryClass(t)){const e=this.children,n=t.children;if(e&&n){if(e.length!==n.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].isAlmostEqual(n[i]))return!1;return!0}else return!(e||n)}return!1}static areAlmostEqual(t,e){return t instanceof Ae&&e instanceof Ae?t.isAlmostEqual(e):t===void 0&&e===void 0}static computeScaledTolerance(t,e){const n=Math.abs(e?.relativeTolerance??f.smallMetricDistance),i=Math.abs(e?.minimumTolerance??f.smallMetricDistanceSquared),s=J.createNull();(Array.isArray(t)?t:[t]).forEach(o=>o.extendRange(s,e?.transform));const r=s.isNull?0:e?.xyOnly?s.maxAbsXY():s.maxAbs();return i+n*r}static scaleToleranceForGeometry(t,e,n){if(e>0){const i=J.createNull();if((Array.isArray(t)?t:[t]).forEach(s=>s.extendRange(i,n?.transform)),!i.isNull){const s=n?.xyOnly?i.maxAbsXY():i.maxAbs();if(s>0){const o=Math.floor(Math.log10(s/e));o>10&&(e*=Math.pow(10,o-10))}}}return e}}class Ho{constructor(t=f.smallNewtonStep,e=2,n=15){this._stepSizeTolerance=t,this._successiveConvergenceTarget=e,this._maxIterations=n}_numAccepted=0;_successiveConvergenceTarget;_stepSizeTolerance;_maxIterations;numIterations=0;get stepSizeTolerance(){return this._stepSizeTolerance}_leastDelta=Number.MAX_VALUE;testConvergence(t){return this.cacheCandidate&&t<this._leastDelta&&this.numIterations>.5*this._maxIterations&&(this._leastDelta=t,this.cacheCandidate()),Math.abs(t)<this._stepSizeTolerance?(this._numAccepted++,this._numAccepted>=this._successiveConvergenceTarget):(this._numAccepted=0,!1)}runIterations(){for(this._numAccepted=0,this.numIterations=0,this._leastDelta=Number.MAX_VALUE;this.numIterations++<this._maxIterations&&this.computeStep();){if(this.testConvergence(this.currentStepSize()))return this.applyCurrentStep(!0),!0;this.applyCurrentStep(!1)}return this.restoreCandidate&&this.numIterations>=this._maxIterations&&Math.abs(this.currentStepSize())>this._leastDelta&&this.restoreCandidate(),!1}}class uc{currentF}class Rr extends uc{_parentCurvePrimitive;constructor(){super(),this._parentCurvePrimitive=void 0}startParentCurvePrimitive(t){this._parentCurvePrimitive=t}endParentCurvePrimitive(t){this._parentCurvePrimitive=void 0}}class br extends Ho{_func;_currentStep;_currentX;derivativeH;constructor(t,e){super(void 0,void 0,e),this._func=t,this.derivativeH=1e-8}setX(t){this._currentX=t}getX(){return this._currentX}applyCurrentStep(){this.setX(this._currentX-this._currentStep)}computeStep(){if(this._func.evaluate(this._currentX)){const t=this._func.currentF;if(this._func.evaluate(this._currentX+this.derivativeH)){const e=this._func.currentF,n=f.conditionalDivideFraction(t,(e-t)/this.derivativeH);if(n!==void 0)return this._currentStep=n,!0}}return!1}currentStepSize(){return Math.abs(this._currentStep/(1+Math.abs(this._currentX)))}}class Jo{currentF;constructor(){this.currentF=At.createXYPlane()}}class bs extends Ho{_func;_currentStep;_currentUV;constructor(t,e,n){super(n,void 0,e),this._func=t,this._currentStep=Q.createZero(),this._currentUV=D.createZero()}setUV(t,e){this._currentUV.set(t,e)}getU(){return this._currentUV.x}getV(){return this._currentUV.y}applyCurrentStep(){this.setUV(this._currentUV.x-this._currentStep.x,this._currentUV.y-this._currentStep.y)}computeStep(){if(!this._func.evaluate(this._currentUV.x,this._currentUV.y))return!1;const t=this._func.currentF,e=t.vectorU,n=t.vectorV,i=t.origin;return!!bt.linearSystem2d(e.x,n.x,e.y,n.y,i.x,i.y,this._currentStep)}currentStepSize(){return f.maxAbsXY(this._currentStep.x/(1+Math.abs(this._currentUV.x)),this._currentStep.y/(1+Math.abs(this._currentUV.y)))}_cachedUV;cacheCandidate(){this._cachedUV?this._cachedUV.setFrom(this._currentUV):this._cachedUV=this._currentUV.clone()}restoreCandidate(){this._cachedUV&&this.setUV(this._cachedUV.x,this._cachedUV.y)}}class Ko extends Jo{_curveP;_curveQ;_rayP;_rayQ;constructor(t,e){super(),this._curveP=t,this._curveQ=e,this._rayP=O.createZero(),this._rayQ=O.createZero()}evaluate(t,e){return this._curveP.fractionToPointAndDerivative(t,this._rayP),this._curveQ.fractionToPointAndDerivative(e,this._rayQ),this.currentF.setOriginAndVectorsXYZ(this._rayP.origin.x-this._rayQ.origin.x,this._rayP.origin.y-this._rayQ.origin.y,0,this._rayP.direction.x,this._rayP.direction.y,0,-this._rayQ.direction.x,-this._rayQ.direction.y,0),!0}}class Qo extends Jo{_curveP;_curveQ;_planeP;_planeQ;constructor(t,e){super(),this._curveP=t,this._curveQ=e,this._planeP=At.createXYPlane(),this._planeQ=At.createXYPlane()}evaluate(t,e){this._curveP.fractionToPointAnd2Derivatives(t,this._planeP),this._curveQ.fractionToPointAnd2Derivatives(e,this._planeQ);const n=this._planeP.origin.x-this._planeQ.origin.x,i=this._planeP.origin.y-this._planeQ.origin.y,s=this._planeP.vectorU.x,r=this._planeP.vectorU.y,o=this._planeQ.vectorU.x,a=this._planeQ.vectorU.y,c=this._planeP.vectorV.x,l=this._planeP.vectorV.y,d=this._planeQ.vectorV.x,h=this._planeQ.vectorV.y;return this.currentF.setOriginAndVectorsXYZ(s*n+r*i,o*n+a*i,0,c*n+l*i+s*s+r*r,o*s+a*r,0,-(s*o+r*a),d*n+h*i-o*o-a*a,0),!0}}class $o extends Rr{_curve;_announceTangent;_spacePoint;_vectorToEye;_distanceTol;_distanceTolSquared;_fractionA=0;_functionA=0;_fractionB=0;_functionB=0;_numThisCurve=0;_fractionMRU;_curveMRU;_workRay;_workDetail;_newtonSolver;constructor(t,e,n){super(),this._announceTangent=e,this._spacePoint=t,this._vectorToEye=n?.vectorToEye??P.unitZ(),this._distanceTol=n?.distanceTol??f.smallMetricDistance,this._distanceTolSquared=this._distanceTol*this._distanceTol,this._workRay=O.createZero(),this.startCurvePrimitive(void 0),this._newtonSolver=new br(this)}needPrimaryGeometryForStrokes(){return!0}startCurvePrimitive(t){this._curve=t,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(t,e,n,i){this.startCurvePrimitive(t),e<1&&(e=1);const s=1/e;for(let r=0;r<=e;r++){const o=f.interpolate(n,r*s,i);t.fractionToPointAndDerivative(o,this._workRay),this.announceRay(o,this._workRay)}}announceCandidate(t,e,n){this._parentCurvePrimitive&&(t=this._parentCurvePrimitive),!(this._curveMRU===t&&f.isAlmostEqualOptional(this._fractionMRU,e,f.smallFloatingPoint))&&(this._workDetail=Y.createCurveFractionPoint(t,e,n,this._workDetail),this._announceTangent(this._workDetail),this._fractionMRU=e,this._curveMRU=t)}announceSegmentInterval(t,e,n,i,s,r){let o,a;const c=this._spacePoint.distanceSquared(e),l=this._spacePoint.distanceSquared(n);c<l?(o=s,a=e):(o=r,a=n);const d=this.evaluateFunction(void 0,(s+r)/2,t);d!==void 0&&f.isDistanceWithinTol(d,this._distanceTol)&&this.announceCandidate(t,o,a)}searchInterval(){if(f.isDistanceWithinTol(this._functionA,this._distanceTolSquared)&&this.announceSolutionFraction(this._fractionA),f.isDistanceWithinTol(this._functionB,this._distanceTolSquared)&&this.announceSolutionFraction(this._fractionB),this._functionA*this._functionB<0){const t=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);t&&(this._newtonSolver.setX(t),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}announceSolutionFraction(t){this._curve&&this.announceCandidate(this._curve,t,this._curve.fractionToPoint(t))}evaluateFunction(t,e,n){if(t)this._workRay.setFrom(t);else if(e!==void 0&&n)this._workRay=n.fractionToPointAndDerivative(e,this._workRay);else return;const i=this._vectorToEye.unitCrossProduct(this._workRay.direction);return i?i.dotProductStartEnd(this._workRay.origin,this._spacePoint):void 0}evaluate(t){const e=this._parentCurvePrimitive??this._curve,n=this.evaluateFunction(void 0,t,e);return n===void 0?!1:(this.currentF=n,!0)}announceRay(t,e){const n=this.evaluateFunction(e);n!==void 0&&(this._functionB=n,this._fractionB=t,this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB)}announcePointTangent(t,e,n){}}class Xt{static _allRows=[];static getRow(t){const e=Xt._allRows;for(e.length===0&&(e.push(new Float64Array([1])),e.push(new Float64Array([1,1])),e.push(new Float64Array([1,2,1])),e.push(new Float64Array([1,3,3,1])),e.push(new Float64Array([1,4,6,4,1])),e.push(new Float64Array([1,5,10,10,5,1])),e.push(new Float64Array([1,6,15,20,15,6,1])),e.push(new Float64Array([1,7,21,35,35,21,7,1])));e.length<=t;){const n=e.length,i=e[n-1],s=new Float64Array(n+1);s[0]=1;for(let r=1;r<n;r++)s[r]=i[r-1]+i[r];s[n]=1,e.push(s)}return e[t]}static getBezierBasisValues(t,e,n){const i=t-1,s=Xt.getRow(i);(n===void 0||n.length<t)&&(n=new Float64Array(t));for(let a=0;a<t;a++)n[a]=s[a];let r=e;for(let a=1;a<t;a++,r*=e)n[a]*=r;const o=1-e;r=o;for(let a=t-2;a>=0;a--,r*=o)n[a]*=r;return n}static getBezierBasisDerivatives(t,e,n){(n===void 0||n.length<t)&&(n=new Float64Array(t)),n=this.getBezierBasisValues(t-1,e,n);const i=t-1;n[t-1]=i*n[t-2];for(let s=t-2;s>0;s--)n[s]=i*(n[s-1]-n[s]);return n[0]=-i*n[0],n}}class jo{coffs;constructor(t){if(t instanceof Float64Array)this.coffs=t.slice();else if(Array.isArray(t)){this.coffs=new Float64Array(t.length);let e=0;for(const n of t)this.coffs[e++]=n}else this.coffs=new Float64Array(t)}allocateToOrder(t){this.coffs.length!==t?this.coffs=new Float64Array(t):this.coffs.fill(0)}createPeer(){return new jt(this.order)}get order(){return this.coffs.length}copyFrom(t){if(this.order===t.order)for(let e=0;e<this.coffs.length;e++)this.coffs[e]=t.coffs[e];else this.coffs=t.coffs.slice()}scaleInPlace(t){for(let e=0;e<this.coffs.length;e++)this.coffs[e]*=t}addInPlace(t){for(let e=0;e<this.coffs.length;e++)this.coffs[e]+=t}roots(t,e){const n=jt.create(this);n.addInPlace(-t),n.clampZero();const i=jt.deflateRoots(n);return this.filter01(i,!0)}filter01(t,e=!1){if(!t||!e)return t;let n=!1;for(const i of t)if(f.isIn01(i)){n=!0;break}if(n){const i=[];for(const s of t)f.isIn01(s)&&i.push(s);return i}}zero(){this.coffs.fill(0)}subdivide(t,e,n){const i=this.order;if(e.order!==i||n.order!==i)return!1;const s=1-t;n.copyFrom(this);let r=i-1;for(let o=0;o<i;o++){e.coffs[o]=n.coffs[0];for(let a=0;a<r;a++)n.coffs[a]=s*n.coffs[a]+t*n.coffs[a+1];r--}return!0}static maxAbsDiff(t,e){const n=t.order;if(e.order!==n)return;let i=0,s;for(let r=0;r<n;r++)s=Math.abs(t.coffs[r]-e.coffs[r]),s>i&&(i=s);return i}clampZero(t=f.smallFloatingPoint){if(t>0)for(let e=0;e<this.coffs.length;++e){const n=this.coffs[e];n&&Math.abs(n)<t&&(this.coffs[e]=0)}}}class Ve{static accumulateScaledShiftedComponentTimesComponentDelta(t,e,n,i,s,r,o,a){const c=i-1,l=i,d=i+c-1;if(t.length!==d)return;const h=Xt.getRow(l-1),g=Xt.getRow(c-1),m=Xt.getRow(d-1);let p;for(let x=0;x<l;x++){p=s*(o+e[r+x*n])*h[x];for(let _=0,I=a;_<c;_++,I+=n)t[x+_]+=p*g[_]*(e[I+n]-e[I])/m[x+_]}}static scaledComponentSum(t,e,n,i,s,r,o,a){const c=i;if(t.length===c)for(let l=0,d=0;l<c;l++,d+=n)t[l]=r*e[d+s]+a*e[d+o]}static componentDifference(t,e,n,i,s){const o=i-1;if(t.length===o)for(let a=0,c=s;a<o;c+=n,a++)t[a]=e[c+n]-e[c]}static accumulateProduct(t,e,n,i=1){const s=e.length,r=n.length,o=s+r-1;if(t.length!==o)return;let a,c,l;const d=Xt.getRow(s-1),h=Xt.getRow(r-1),g=Xt.getRow(o-1);for(a=0;a<s;a++)for(l=i*d[a]*e[a],c=0;c<r;c++)t[a+c]+=l*h[c]*n[c]/g[a+c]}static accumulateProductWithDifferences(t,e,n,i=1){const s=e.length-1,r=n.length,o=s+r-1;if(t.length!==o)return;let a,c,l;const d=Xt.getRow(s-1),h=Xt.getRow(r-1),g=Xt.getRow(o-1);for(a=0;a<s;a++)for(l=i*d[a]*(e[a+1]-e[a]),c=0;c<r;c++)t[a+c]+=l*h[c]*n[c]/g[a+c]}static univariateDifference(t,e){const n=e.length;if(e.length+1!==n)for(let i=0;i<n;i++)e[i]=t[i+1]-t[i]}static accumulate(t,e,n){if(n.length===e)for(let i=0;i<e;i++)n[i]+=t[i]}}class jt extends jo{_order;get order(){return this._order}constructor(t){super(t),this._order=super.order}allocateOrder(t){this._order!==t&&(super.allocateToOrder(t),this._order=t),this.coffs.fill(0)}clone(t=!1){if(t){const n=new jt(this.order);return n.coffs=this.coffs.slice(0,this.order),n}const e=new jt(this.coffs.length);return e._order=this._order,e.coffs=this.coffs.slice(),e}static create(t){const e=new jt(t.order);return e.coffs=t.coffs.slice(),e}static createCoffs(t){return new jt(t)}static createArraySubset(t,e,n,i){i?i.order!==n&&i.allocateToOrder(n):i=new jt(n);for(let s=0;s<n;s++)i.coffs[s]=t[e+s];return i}static createProduct(t,e){const n=new jt(t.order+e.order-1),i=Xt.getRow(t.order-1),s=Xt.getRow(e.order-1),r=Xt.getRow(t.order+e.order-2);for(let o=0;o<t.order;o++){const a=t.coffs[o]*i[o];for(let c=0;c<e.order;c++){const l=e.coffs[c]*s[c],d=o+c,h=r[d];n.coffs[d]+=a*l/h}}return n}addSquaredSquaredBezier(t,e){const n=t.length,i=this.order;if(n*2!==i+1)return!1;const s=Xt.getRow(n-1),r=Xt.getRow(i-1),o=this.coffs;for(let a=0;a<n;a++){const c=t[a]*s[a]*e;for(let l=0;l<n;l++){const d=t[l]*s[l],h=a+l,g=r[h];o[h]+=c*d/g}}return!0}addConstant(t){for(let e=0;e<this.coffs.length;e++)this.coffs[e]+=t}_basisValues;basisFunctions(t,e){this._basisValues=Xt.getBezierBasisValues(this.order,t,this._basisValues),(!e||e.length<this.order)&&(e=new Float64Array(this.order));let n=0;for(const i of this._basisValues)e[n++]=i;return e}static sumWeightedBlocks(t,e,n,i,s){for(let a=0;a<i;a++)s[a]=0;let r=0,o;for(let a=0;a<e;a++){const c=t[a];for(o=0;o<i;o++)s[o]+=c*n[r++]}}sumBasisFunctions(t,e,n,i){return(!i||i.length<n)&&(i=new Float64Array(n)),this._basisValues=Xt.getBezierBasisValues(this.order,t,this._basisValues),jt.sumWeightedBlocks(this._basisValues,this.order,e,n,i),i}sumBasisFunctionDerivatives(t,e,n,i){return(!i||i.length<n)&&(i=new Float64Array(n)),this._basisValues=Xt.getBezierBasisDerivatives(this.order,t,this._basisValues),jt.sumWeightedBlocks(this._basisValues,this.order,e,n,i),i}evaluate(t){this._basisValues=Xt.getBezierBasisValues(this.order,t,this._basisValues);let e=0;for(let n=0;n<this.order;n++)e+=this._basisValues[n]*this.coffs[n];return e}deflateLeft(){const t=this.order,e=t-1,n=Xt.getRow(e-1),i=Xt.getRow(t-1);let s;for(let r=0;r<e;r++)s=this.coffs[r+1],this.coffs[r]=s*i[r+1]/n[r];this._order--}deflateRight(){const t=this.order,e=t-1,n=Xt.getRow(e-1),i=Xt.getRow(t-1);let s,r;for(let o=0;o<e;o++)s=this.coffs[o],r=s*i[o]/n[o],this.coffs[o]=r;this._order--}deflateRoot(t){const e=this.order,n=e-1;if(e===1)return this._order=0,this.coffs[0];if(e<1)return this._order=0,0;const i=Xt.getRow(e-1),s=Xt.getRow(n-1),r=-t,o=1-t;let a=0;if(t>.5){let c=this.coffs[0]/r,l;this.coffs[0]=c;let d;for(let h=1;h<n;h++)d=this.coffs[h]*i[h],l=(d-c*o)/r,this.coffs[h]=l/s[h],c=l;a=this.coffs[e-1]-c*o}else{let c=this.coffs[e-1]/o,l;this.coffs[e-1]=c;let d;for(let h=e-2;h>0;h--)d=this.coffs[h]*i[h],l=(d-c*r)/o,this.coffs[h]=l/s[h-1],c=l;a=this.coffs[0]-c*r;for(let h=0;h<n;h++)this.coffs[h]=this.coffs[h+1]}return this._order=n,a}static _basisBuffer;static _basisBuffer1;runNewton(t,e=f.smallNewtonStep){const n=this.order-1;let i=0,s=t,r,o;const a=10,c=this.order,l=this.coffs,d=c-1,h=20;for(let g=0;g<h;g++){jt._basisBuffer=Xt.getBezierBasisValues(c,s,jt._basisBuffer),r=0;for(let p=0;p<c;p++)r+=l[p]*jt._basisBuffer[p];jt._basisBuffer1=Xt.getBezierBasisValues(d,s,jt._basisBuffer1),o=0;for(let p=0;p<d;p++)o+=(l[p+1]-l[p])*jt._basisBuffer1[p];if(o*=n,Math.abs(r)>a*Math.abs(o))return;const m=r/o;if(Math.abs(m)<e){if(i++,i>=2)return s-m}else i=0;s-=m}}static deflateRoots(t){const e=[],n=t.coffs;let i,s,r,o,a;for(;t.order>1;){const c=t.order;if(n[0]===0){t.deflateLeft(),e.push(0);continue}let l=0,d=0;for(let h=1;h<c;h++)if(i=n[h-1],s=n[h],i*s<=0&&(l++,r=-i/(s-i),o=(h-1+r)/(c-1),a=t.runNewton(o,1e-10),a!==void 0)){e.push(a),t.deflateRoot(a),d++;break}if(!d){if(l===0)break;break}}return e.length>0?e:void 0}}class Ds extends jo{constructor(t=0,e=0){super(2),this.coffs[0]=t,this.coffs[1]=e}clone(){return new Ds(this.coffs[0],this.coffs[1])}static solveCoffs(t,e){return f.conditionalDivideFraction(-t,e-t)}basisFunctions(t,e){return(!e||e.length<2)&&(e=new Float64Array(2)),e[0]=1-t,e[1]=t,e}sumBasisFunctions(t,e,n,i){(!i||i.length<n)&&(i=new Float64Array(n));const s=1-t;for(let r=0;r<n;r++)i[r]=s*e[r]+t*e[r+n];return i}sumBasisFunctionDerivatives(t,e,n,i){(!i||i.length<n)&&(i=new Float64Array(n));for(let s=0;s<n;s++)i[s]=e[s+n]-e[s];return i}evaluate(t){return(1-t)*this.coffs[0]+t*this.coffs[1]}solve(t){const e=this.coffs[1]-this.coffs[0];return f.conditionalDivideFraction(t-this.coffs[0],e)}roots(t,e){const n=this.solve(t);if(n!==void 0&&(!e||f.isIn01(n)))return[n]}}class fc extends Rr{_curve;_plane;_intersections;_fractionA=0;_functionA=0;_functionB=0;_fractionB=0;_derivativeB=0;_numThisCurve=0;_ray;_newtonSolver;effectiveCurve(){return this._parentCurvePrimitive?this._parentCurvePrimitive:this._curve}get getDerivativeB(){return this._derivativeB}constructor(t,e){super(),this._plane=t,this._intersections=e,this.startCurvePrimitive(void 0),this._ray=O.createZero(),this._newtonSolver=new br(this)}startCurvePrimitive(t){this._curve=t,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(t,e,n,i){this.startCurvePrimitive(t),e<1&&(e=1);const s=1/e;for(let r=0;r<=e;r++){const o=f.interpolate(n,r*s,i);t.fractionToPointAndDerivative(o,this._ray),this.announcePointTangent(this._ray.origin,o,this._ray.direction)}}announceSegmentInterval(t,e,n,i,s,r){const o=this._plane.altitude(e),a=this._plane.altitude(n);if(o*a>0)return;const c=Ds.solveCoffs(o,a);if(c!==void 0){const l=f.interpolate(s,c,r);this._newtonSolver.setX(l),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX())}}announceSolutionFraction(t){const e=this.effectiveCurve();e&&(this._ray=e.fractionToPointAndDerivative(t,this._ray),this._intersections.push(Y.createCurveFractionPoint(e,t,this._ray.origin)))}evaluate(t){const e=this.effectiveCurve();return e?(this.currentF=this._plane.altitude(e.fractionToPoint(t)),!0):!1}searchInterval(){if(!(this._functionA*this._functionB>0)&&(this._functionA===0&&this.announceSolutionFraction(this._fractionA),this._functionB===0&&this.announceSolutionFraction(this._fractionB),this._functionA*this._functionB<0)){const t=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);t&&(this._newtonSolver.setX(t),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}evaluateB(t,e,n){this._functionB=this._plane.altitude(t),this._derivativeB=this._plane.velocity(n),this._fractionB=e}announcePointTangent(t,e,n){this.evaluateB(t,e,n),this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB}}class ta extends Rr{_curve;_closestPoint;_spacePoint;_extend;_xyOnly;_fractionA=0;_functionA=0;_fractionB=0;_functionB=0;_numThisCurve=0;_workPoint;_workRay;_newtonSolver;constructor(t,e,n,i){super(),this._spacePoint=t,this._workPoint=y.create(),this._workRay=O.createZero(),this._closestPoint=n,this._closestPoint&&(this._closestPoint.a=f.largeCoordinateResult),this._extend=e??!1,this._xyOnly=i??!1,this.startCurvePrimitive(void 0),this._newtonSolver=new br(this)}claimResult(){if(this._closestPoint&&(this._newtonSolver.setX(this._closestPoint.fraction),this._curve=this._closestPoint.curve,this._newtonSolver.runIterations())){let t=this._newtonSolver.getX();t=Ut.correctFraction(this._extend,t),this.announceSolutionFraction(t)}return this._closestPoint}needPrimaryGeometryForStrokes(){return!0}startCurvePrimitive(t){this._curve=t,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(t,e,n,i){this.startCurvePrimitive(t),this.announceSolutionFraction(0),this.announceSolutionFraction(1),e<1&&(e=1);const s=1/e;for(let r=0;r<=e;r++){const o=f.interpolate(n,r*s,i);t.fractionToPointAndDerivative(o,this._workRay),this.announceRay(o,this._workRay)}}announceCandidate(t,e,n){const i=this._xyOnly?this._spacePoint.distanceXY(n):this._spacePoint.distance(n);this._closestPoint&&i>this._closestPoint.a||(this._closestPoint=Y.createCurveFractionPoint(t,e,n,this._closestPoint),this._closestPoint.a=i,this._parentCurvePrimitive!==void 0&&(this._closestPoint.curve=this._parentCurvePrimitive))}announceSegmentInterval(t,e,n,i,s,r){let o=0;this._xyOnly?o=bt.lineSegment3dXYClosestPointUnbounded(e,n,this._spacePoint)??0:o=this._spacePoint.fractionOfProjectionToLine(e,n,0);const a=s===0?Ut.resolveVariantCurveExtendParameterToCurveExtendMode(this._extend,0):Ht.None,c=r===1?Ut.resolveVariantCurveExtendParameterToCurveExtendMode(this._extend,1):Ht.None;o=Ut.correctFraction([a,c],o),this._workPoint=e.interpolate(o,n);const l=f.interpolate(s,o,r);this.announceCandidate(t,l,this._workPoint)}searchInterval(){if(!(this._functionA*this._functionB>0)&&(this._functionA===0&&this.announceSolutionFraction(this._fractionA),this._functionB===0&&this.announceSolutionFraction(this._fractionB),this._functionA*this._functionB<0)){const t=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);t&&(this._newtonSolver.setX(t),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}announceSolutionFraction(t){this._curve&&this.announceCandidate(this._curve,t,this._curve.fractionToPoint(t))}evaluateFunction(t,e,n){if(t)this._workRay.setFrom(t);else if(e!==void 0&&n)this._workRay=n.fractionToPointAndDerivative(e,this._workRay);else return;return this._xyOnly?this._workRay.dotProductToPointXY(this._spacePoint):this._workRay.dotProductToPoint(this._spacePoint)}evaluate(t){let e=this._curve;this._parentCurvePrimitive&&(e=this._parentCurvePrimitive);const n=this.evaluateFunction(void 0,t,e);return n===void 0?!1:(this.currentF=n,!0)}announceRay(t,e){const n=this.evaluateFunction(e);this._functionB=n,this._fractionB=t,this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB}announcePointTangent(t,e,n){this._workRay.set(t,n),this.announceRay(e,this._workRay)}}class ie{static gaussX1Interval01=new Float64Array([.5]);static gaussW1Interval01=new Float64Array([1]);static gaussX2Interval01=new Float64Array([.21132486540518708,.7886751345948129]);static gaussW2Interval01=new Float64Array([.5,.5]);static gaussX3Interval01=new Float64Array([.1127016653792583,.5,.8872983346207417]);static gaussW3Interval01=new Float64Array([.2777777777777778,.4444444444444444,.2777777777777778]);static gaussX4Interval01=new Float64Array([.06943184420297371,.33000947820757187,.6699905217924281,.9305681557970262]);static gaussW4Interval01=new Float64Array([.17392742256872692,.3260725774312731,.3260725774312731,.17392742256872692]);static gaussX5Interval01=new Float64Array([.04691007703066802,.23076534494715845,.5,.7692346550528415,.9530899229693319]);static gaussW5Interval01=new Float64Array([.11846344252809454,.23931433524968324,.28444444444444444,.23931433524968324,.11846344252809454]);static mapWeights(t,e,n,i,s,r){const o=n.length;for(let a=0;a<o;a++)s[a]=t+e*n[a],r[a]=e*i[a];return o}static setupGauss1(t,e,n,i){return ie.mapWeights(t,e-t,ie.gaussX1Interval01,ie.gaussW1Interval01,n,i)}static setupGauss2(t,e,n,i){return ie.mapWeights(t,e-t,ie.gaussX2Interval01,ie.gaussW2Interval01,n,i)}static setupGauss3(t,e,n,i){return ie.mapWeights(t,e-t,ie.gaussX3Interval01,ie.gaussW3Interval01,n,i)}static setupGauss5(t,e,n,i){return ie.mapWeights(t,e-t,ie.gaussX5Interval01,ie.gaussW5Interval01,n,i)}static setupGauss4(t,e,n,i){return ie.mapWeights(t,e-t,ie.gaussX4Interval01,ie.gaussW4Interval01,n,i)}static sum1(t,e,n,i){let s=0;for(let r=0;r<n;r++)s+=e[r]*i(t[r]);return s}static doGaussIntegral(t,e,n,i,s=5){const r=new Dr(s);i<1&&(i=1);const o=1/i;let a=0;for(let c=1;c<=i;c++){const l=f.interpolate(t,(c-1)*o,e),d=c===i?e:f.interpolate(t,c*o,e),h=r.mapXAndW(l,d);for(let g=0;g<h;g++)a+=r.gaussW[g]*n(r.gaussX[g])}return a}}class Dr{gaussX;gaussW;mapXAndWFunction;mapXAndW(t,e){return this.mapXAndWFunction(t,e,this.gaussX,this.gaussW)}constructor(t){switch(this.gaussX=new Float64Array(7),this.gaussW=new Float64Array(7),(t>5||t<1)&&(t=5),t){case 1:this.mapXAndWFunction=(n,i,s,r)=>ie.setupGauss1(n,i,s,r);break;case 2:this.mapXAndWFunction=(n,i,s,r)=>ie.setupGauss2(n,i,s,r);break;case 3:this.mapXAndWFunction=(n,i,s,r)=>ie.setupGauss3(n,i,s,r);break;case 4:this.mapXAndWFunction=(n,i,s,r)=>ie.setupGauss4(n,i,s,r);break;default:this.mapXAndWFunction=(n,i,s,r)=>ie.setupGauss5(n,i,s,r);break}}}class Xr{_curve;_summedLength;_ray;_fraction0;_fraction1;_gaussMapper;tangentMagnitude(t){return this._ray=this._curve.fractionToPointAndDerivative(t,this._ray),this._ray.direction.magnitude()}get getFraction0(){return this._fraction0}get getFraction1(){return this._fraction1}getSum(){return this._summedLength}constructor(t=0,e=1,n=5){this.startCurvePrimitive(void 0),this._summedLength=0,this._ray=O.createZero(),t<e?(this._fraction0=t,this._fraction1=e):(this._fraction0=e,this._fraction1=t),this._gaussMapper=new Dr(n)}startCurvePrimitive(t){this._curve=t}startParentCurvePrimitive(t){}endParentCurvePrimitive(t){}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(t,e,n,i){const s=ct.createXX(n,i);if(s.intersectRangeXXInPlace(this._fraction0,this._fraction1),!s.isNull){this.startCurvePrimitive(t),e<1&&(e=1);const r=1/e;for(let o=1;o<=e;o++){const a=s.fractionToPoint((o-1)*r),c=o===e?s.high:s.fractionToPoint(o*r),l=this._gaussMapper.mapXAndW(a,c);for(let d=0;d<l;d++)this._summedLength+=this._gaussMapper.gaussW[d]*this.tangentMagnitude(this._gaussMapper.gaussX[d])}}}announceSegmentInterval(t,e,n,i,s,r){const o=e.distance(n);if(this._fraction0<=s&&r<=this._fraction1)this._summedLength+=o;else{const a=ct.createXX(s,r);a.intersectRangeXXInPlace(this._fraction0,this._fraction1),a.isNull||(this._summedLength+=o*a.length()/(r-s))}}announcePointTangent(t,e,n){}}class st extends Ae{geometryCategory="curvePrimitive";constructor(){super()}strokeData;startCut;endCut;parent;fractionToPointAndUnitTangent(t,e){const n=this.fractionToPointAndDerivative(t,e);return n.trySetDirectionMagnitudeInPlace(1),n}fractionToCurvature(t){const e=this.fractionToPointAnd2Derivatives(t);if(!e)return;const i=e.vectorU.crossProduct(e.vectorV).magnitude(),s=e.vectorU.magnitude();return f.conditionalDivideFraction(i,s*s*s)}fractionToFrenetFrame(t,e){const n=this.fractionToPointAnd2Derivatives(t);if(!n)return;let i=C.createRigidFromColumns(n.vectorU,n.vectorV,mt.XYZ);if(i)return X.createRefs(n.origin,i,e);const s=C.createPerpendicularVectorFavorXYPlane(n.vectorU,n.vectorV);if(i=C.createRigidFromColumns(n.vectorU,s,mt.XYZ),i)return X.createRefs(n.origin,i,e)}fractionToSignedXYRadiusOfCurvature(t){const e=this.fractionToPointAnd2Derivatives(t);if(!e)return 0;const n=e.vectorU.crossProductXY(e.vectorV),i=e.vectorU.magnitude();if(i===0)return 0;const s=f.conditionalDivideCoordinate(i*i*i,n);return s!==void 0?s:0}fractionAndDistanceToPointOnTangent(t,e){return this.fractionToPointAndUnitTangent(t).fractionToPoint(e)}curveLength(){const t=new Xr;return this.emitStrokableParts(t),t.getSum()}curveLengthBetweenFractions(t,e){if(t===e)return 0;if(this.getFractionToDistanceScale()!==void 0){const s=this.curveLength();return Math.abs((e-t)*s)}const i=new Xr(t,e);return this.emitStrokableParts(i),Math.abs(i.getSum())}rangeBetweenFractions(t,e,n){return this.rangeBetweenFractionsByClone(t,e,n)}rangeBetweenFractionsByClone(t,e,n){if(t===e)return J.create(this.fractionToPoint(t));const i=this.clonePartialCurve(t,e);return i?i.range(n):J.createNull()}rangeBetweenFractionsByCount(t,e,n,i,s=0){const r=J.createNull(),o=y.create();r.extendPoint(this.startPoint(o)),r.extendPoint(this.endPoint(o));const a=(l,d,h)=>{let g=l;for(let m=0;m<h;m++,g+=d)this.fractionToPoint(g,o),i?r.extendTransformedPoint(i,o):r.extendPoint(o)},c=n-2;if(c>0){const d=1/(c+1)*(e-t);a(t+d,d,c)}if(s>0){const l=r.clone(),d=c+1,g=2*(.5/d)*(e-t);a(t+g*.5,g,d),r.extendWhenLarger(l,s)}return r}curveLengthWithFixedIntervalCountQuadrature(t,e,n,i=5){if(t>e){const r=t;t=e,e=r}const s=new Xr(t,e,i);return s.announceIntervalForUniformStepStrokes(this,n,t,e),Math.abs(s.getSum())}moveSignedDistanceFromFraction(t,e,n,i){if(this.getFractionToDistanceScale()!==void 0){const r=this.curveLength(),o=f.conditionalDivideFraction(e,r);return o===void 0?Y.createCurveFractionPointDistanceCurveSearchStatus(this,t,this.fractionToPoint(t),0,Me.error):Y.createConditionalMoveSignedDistance(n,this,t,t+o,e,i)}return this.moveSignedDistanceFromFractionGeneric(t,e,n,i)}moveSignedDistanceFromFractionGeneric(t,e,n,i){let s;if(e===0)return Y.createCurveEvaluatedFraction(this,t,i);e>0?(s=1,t>=1&&(e+=this.curveLengthBetweenFractions(.9,t),t=.9)):(s=0,t<=0&&(e-=this.curveLengthBetweenFractions(t,.1),t=.1));const o=this.curveLengthBetweenFractions(t,s),a=Math.abs(e);if(o<a&&!n)return Y.createConditionalMoveSignedDistance(n,this,t,s,e,i);const c=f.conditionalDivideCoordinate(a,o);if(c===void 0)return i=Y.createCurveEvaluatedFraction(this,t,i),i.curveSearchStatus=Me.error,i;const l=e<0?-1:1;let d=f.interpolate(t,c,s),h=t,g=0;const m=1e-12*o;let p=0;const x=O.createXAxis();for(let _=0;_<10;_++){const I=this.curveLengthBetweenFractions(h,d),v=d>h?l:-l,S=g+v*I,w=a-S;if(Math.abs(w)<m){if(p++,p>1)break}else p=0;this.fractionToPointAndDerivative(d,x);const T=x.direction.magnitude();if(h=d,d=h+l*w/T,h===d){p=100;break}g=S}return p>1?Y.createConditionalMoveSignedDistance(n,this,t,d,e,i):(i=Y.createCurveEvaluatedFraction(this,t,i),i.curveSearchStatus=Me.error,i)}get isExtensibleFractionSpace(){return!1}closestPoint(t,e=!1,n){const i=new ta(t,e,n);return this.emitStrokableParts(i),i.claimResult()}closestPointXY(t,e=!1,n){const i=new ta(t,e,n,!0);return this.emitStrokableParts(i),i.claimResult()}emitTangents(t,e,n){const i=new $o(t,e,n);this.emitStrokableParts(i,n?.strokeOptions)}allTangents(t,e){const n=[];return this.emitTangents(t,i=>n.push(i.clone()),e),n.length===0?void 0:n}closestTangent(t,e){const n=e?.hintPoint??t;let i;e?.vectorToEye&&!e.vectorToEye.isExactEqual({x:0,y:0,z:1})&&(i=C.createRigidViewAxesZTowardsEye(e.vectorToEye.x,e.vectorToEye.y,e.vectorToEye.z));const s=c=>i?.multiplyTransposeXYZ(n.x-c.x,n.y-c.y,n.z-c.z).magnitudeSquaredXY()??c.distanceSquaredXY(n);let r,o=f.largeCoordinateResult;const a=c=>{const l=s(c.point);(!r||l<o)&&(r=c.clone(r),o=l)};return this.emitTangents(t,a,e),r}announceClipIntervals(t,e){return t.announceClippedCurveIntervals?.(this,e)??!1}clonePartialCurve(t,e){}getFractionToDistanceScale(){}reverse(){return this.reverseInPlace(),this}appendPlaneIntersectionPoints(t,e){const n=new fc(t,e),i=e.length;return this.emitStrokableParts(n),e.length-i}static snapAndRestrictDetails(t,e=!0,n=!1,i=f.smallAngleRadians,s=f.smallMetricDistance){const r=t.length;let o=0;const a=y.create(),c=y.create();let l;for(let d=0;d<r;d++){l=void 0;const h=t[d];let g=h.fraction,m=e||f.isIn01(g);h.curve&&(h.curve.startPoint(a),h.curve.endPoint(c)),i>0&&(Math.abs(g)<i&&(g=0,m=!0,h.intervalRole=Ct.isolatedAtVertex,l=a),Math.abs(g-1)<i&&(g=1,m=!0,h.intervalRole=Ct.isolatedAtVertex,l=c,h.curve&&(l=h.curve.startPoint(c)))),s>0&&h.curve!==void 0&&(h.point.distance(a)<=s?(g=0,h.intervalRole=Ct.isolatedAtVertex,l=a):h.point.distance(c)<=s&&(g=1,h.intervalRole=Ct.isolatedAtVertex,l=c)),m&&(n&&(h.fraction=g,l!==void 0&&h.point.setFrom(l)),o<d&&(t[o]=h),o++)}o<r&&(t.length=o)}startPoint(t){return this.fractionToPoint(0,t)}endPoint(t){return this.fractionToPoint(1,t)}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){const n=this.startPoint(),i=this.endPoint();return n!==void 0&&i!==void 0&&(e?n.isAlmostEqualXY(i,t):n.isAlmostEqual(i,t))}computeAndAttachRecursiveStrokeCounts(t,e){const n=this.computeStrokeCountForOptions(t),i=this.curveLength();st.installStrokeCountMap(this,dn.createWithCurvePrimitive(this,n,i,0,i),e)}addMappedStrokesToLineString3D(t,e){const n=e.numPoints();if(t.primitive&&t.primitive===this&&t.numStroke>0)for(let i=0;i<=t.numStroke;i++){const s=i/t.numStroke;e.appendFractionToPoint(this,s)}return e.numPoints()-n}static installStrokeCountMap(t,e,n){n&&n.addToCountAndLength(e.numStroke,e.curveLength),t.strokeData=e}collectCurvePrimitivesGo(t,e,n=!1){t.push(this)}collectCurvePrimitives(t,e=!1,n=!1){const i=t===void 0?[]:t;return this.collectCurvePrimitivesGo(i,e,n),i}projectedParameterRange(t,e){}}class Bt extends Ts{data;constructor(t){super(),this.data=t}isValidIndex(t){return this.isIndexValid(t)}getPoint3dAtCheckedPointIndex(t,e){if(this.isValidIndex(t)){const n=this.data[t];return y.create(n.x,n.y,n.z,e)}}getPoint3dAtUncheckedPointIndex(t,e){const n=this.data[t];return y.create(n.x,n.y,n.z,e)}getVector3dAtCheckedVectorIndex(t,e){if(this.isValidIndex(t)){const n=this.data[t];return P.create(n.x,n.y,n.z,e)}}getXAtUncheckedPointIndex(t){return this.data[t].x}getYAtUncheckedPointIndex(t){return this.data[t].y}getZAtUncheckedPointIndex(t){return this.data[t].z}vectorIndexIndex(t,e,n){if(this.isValidIndex(t)&&this.isValidIndex(e))return this.vectorUncheckedIndexIndex(t,e,n)}vectorUncheckedIndexIndex(t,e,n){return P.createStartEnd(this.data[t],this.data[e],n)}vectorXYAndZIndex(t,e,n){if(this.isValidIndex(e))return this.vectorXYAndZUncheckedIndex(t,e,n)}vectorXYAndZUncheckedIndex(t,e,n){return P.createStartEnd(t,this.data[e],n)}crossProductXYAndZIndexIndex(t,e,n,i){if(this.isValidIndex(e)&&this.isValidIndex(n))return P.createCrossProductToPoints(t,this.data[e],this.data[n],i)}crossProductIndexIndexIndex(t,e,n,i){if(this.isValidIndex(t)&&this.isValidIndex(e)&&this.isValidIndex(n))return this.crossProductUncheckedIndexIndexIndex(t,e,n,i)}crossProductUncheckedIndexIndexIndex(t,e,n,i){return P.createCrossProductToPoints(this.data[t],this.data[e],this.data[n],i)}crossProductUncheckedIndexIndexXYAndZ(t,e,n,i){return P.createCrossProductToPoints(this.data[t],this.data[e],n,i)}accumulateCrossProductIndexIndexIndex(t,e,n,i){const s=this.data;this.isValidIndex(t)&&this.isValidIndex(e)&&this.isValidIndex(n)&&i.addCrossProductToTargetsInPlace(s[t].x,s[t].y,s[t].z,s[e].x,s[e].y,s[e].z,s[n].x,s[n].y,s[n].z)}accumulateScaledXYZ(t,e,n){if(this.isValidIndex(t)){const i=this.data[t];n.x+=e*i.x,n.y+=e*i.y,n.z+=e*i.z}}get length(){return this.data.length}push(t){this.data.push(t.clone())}pushXYZ(t,e,n){this.data.push(y.create(t===void 0?0:t,e===void 0?0:e,n===void 0?0:n))}back(t){if(this.data.length>0)return this.data[this.data.length-1].clone(t)}front(t){if(this.data.length>0)return this.data[0].clone(t)}pop(){this.data.length>0&&this.data.pop()}clear(){this.data.length=0}reverseInPlace(){this.data.reverse()}distanceSquaredIndexIndex(t,e){const n=this.data.length;if(t>=0&&t<n&&e>=0&&e<n)return this.distanceSquaredUncheckedIndexIndex(t,e)}distanceSquaredUncheckedIndexIndex(t,e){return this.data[t].distanceSquared(this.data[e])}distanceIndexIndex(t,e){const n=this.data.length;if(t>=0&&t<n&&e>=0&&e<n)return this.distanceUncheckedIndexIndex(t,e)}distanceUncheckedIndexIndex(t,e){return this.data[t].distance(this.data[e])}cyclicIndex(t){return t%this.data.length}}function ea(u,t,e){if(t!==void 0){const n=t*e;if(n>=0&&n<=u)return n}return u}class Pe{static preciseSum(t){const e=t.length;if(e===0)return 0;let n=t[0],i=0,s,r;for(let o=1;o<e;o++)s=t[o]-i,r=n+s,i=r-n-s,n=r;return n}static isExactEqual(t,e){if(t&&e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}return t===void 0&&e===void 0}static isAlmostEqual(t,e,n=f.smallMetricDistance){if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(Math.abs(t[i]-e[i])>n)return!1;return!0}return t===void 0&&e===void 0}static sum(t){let e=0;for(const n of t)e+=n;return e}static isCoordinateInArray(t,e){if(e){for(const n of e)if(f.isSameCoordinate(t,n))return!0}return!1}static maxAbsArray(t){const e=t.length;if(e===0)return 0;let n=Math.abs(t[0]);for(let i=1;i<e;i++){const s=Math.abs(t[i]);n<s&&(n=s)}return n}static maxAbsTwo(t,e){return t=Math.abs(t),e=Math.abs(e),t>e?t:e}static maxAbsDiff(t,e){let n=0;const i=Math.min(t.length,e.length);for(let s=0;s<i;s++)n=Math.max(n,Math.abs(t[s]-e[s]));return n}static maxAbsDiffFloat64(t,e){let n=0;const i=Math.min(t.length,e.length);for(let s=0;s<i;s++)n=Math.max(n,Math.abs(t[s]-e[s]));return n}static createArrayWithMaxStepSize(t,e,n){if(t===e)return[t];const i=e-t,s=Math.max(1,Math.floor(Math.abs(i/n))),r=[];r.push(t);for(let o=1;o<s;o++)r.push(t+o/s*i);return r.push(e),r}static create(t){const e=[];for(const n of t)e.push(n);return e}static copy2d(t){const e=[];for(const n of t){const i=[];for(const s of n)i.push(s);e.push(i)}return e}static copy3d(t){const e=[];for(const n of t){const i=[];for(const s of n){const r=[];for(const o of s)r.push(o);i.push(r)}e.push(i)}return e}static unpack2d(t,e){if(!(e<1))return re.unpackNumbersToNestedArrays(t,e)}static unpack3d(t,e,n){if(!(n<1||e<1))return re.unpackNumbersToNestedArraysIJK(t,n,e)}static pack(t){const e=t.length;let n=0,i=0,s=0;e>0&&(s=e,Array.isArray(t[0])&&(n=t[0].length,n>0&&(s*=n,Array.isArray(t[0][0])&&(i=t[0][0].length,i>0&&(s*=i)))));const r=new Float64Array(s);if(i>0){const o=t;for(let a=0,c=0;a<e;++a)for(let l=0;l<n;++l)for(let d=0;d<i;++d)r[c++]=o[a][l][d]}else if(n>0){const o=t;for(let a=0,c=0;a<e;++a)for(let l=0;l<n;++l)r[c++]=o[a][l]}else if(e>0){const o=t;for(let a=0,c=0;a<e;++a)r[c++]=o[a]}return r}static cloneWithStartAndEndMultiplicity(t,e,n){const i=[];if(t===void 0||t.length===0)return i;let s=1;const r=t[0],o=t[t.length-1];for(;s<t.length&&t[s]===r;)s++;let a=1;const c=t.length-1;for(;c-a>=0&&t[c-a]===o;)a++;for(let l=0;l<e;l++)i.push(r);for(let l=s;l+a<t.length;l++)i.push(t[l]);for(let l=0;l<n;l++)i.push(o);return i}static linearCombination(t,e){const n=Math.min(t.length,e.length);let i=0;for(let s=0;s<n;++s)i+=e[s]*t[s];return i}static linearCombinationOfColors(t,e){const n=Math.min(t.length,e.length),i=[0,0,0,0];for(let s=0,r=0;s<4;++s,r+=8){for(let o=0;o<n;++o){const a=f.clamp(e[o],0,1),c=t[o]>>>r&255;i[s]+=a*c}i[s]=(Math.floor(i[s])&255)<<r}return i[0]|i[1]|i[2]|i[3]}static searchStrictlyIncreasingNumbers(t,e){const n=t.length-1;if(n<=0||e<0||e>=t[n])return;let i=Math.floor(e*n/t[n]);for(;t[i]>e;)i--;for(;t[i+1]<=e;)i++;return i}}class na{static packPointsAndWeightsToFloat64Array(t,e,n){if(Array.isArray(t)&&t[0]instanceof y){const o=t;if(o.length!==e.length)return;const a=4*o.length;(!n||n.length<a)&&(n=new Float64Array(a));for(let c=0,l=0;l<o.length;l++)n[c++]=o[l].x,n[c++]=o[l].y,n[c++]=o[l].z,n[c++]=e[l];return n}const i=t,s=e.length;if(i.length!==3*s)return;const r=4*s;(!n||n.length<r)&&(n=new Float64Array(r));for(let o=0,a=0;a<s;a++){const c=3*a;n[o++]=i[c],n[o++]=i[c+1],n[o++]=i[c+2],n[o++]=e[a]}return n}static packToFloat64Array(t,e){const n=4*t.length;(!e||e.length<n)&&(e=new Float64Array(n));let i=0;for(const s of t)e[i++]=s.x,e[i++]=s.y,e[i++]=s.z,e[i++]=s.w;return e}static unpackToPoint4dArray(t){const e=[];for(let n=0;n+3<t.length;n+=4)e.push(Z.create(t[n],t[n+1],t[n+2],t[n+3]));return e}static unpackFloat64ArrayToPointsAndWeights(t,e,n,i=(s,r,o)=>y.create(s,r,o)){e.length=0,n.length=0;for(let s=0;s+3<t.length;s+=4)e.push(i(t[s],t[s+1],t[s+2])),n.push(t[s+3])}static _workPoint4d=Z.create();static multiplyInPlace(t,e){const n=e.length,i=na._workPoint4d;for(let s=0;s+3<n;s+=4)t.multiplyXYZW(e[s],e[s+1],e[s+2],e[s+3],i),e[s]=i.x,e[s+1]=i.y,e[s+2]=i.z,e[s+3]=i.w}static isAlmostEqual(t,e,n=f.smallMetricDistance){if(t&&e){if(t instanceof Float64Array&&e instanceof Float64Array){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!f.isSameCoordinate(t[i],e[i],n))return!1}else if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].isAlmostEqual(e[i],n))return!1}else{const i=t instanceof Float64Array?e:t,s=t instanceof Float64Array?t:e;if(s.length!==i.length*4)return!1;for(let r=0;r<i.length;++r)if(!f.isSameCoordinate(i[r].x,s[4*r],n)||!f.isSameCoordinate(i[r].y,s[4*r+1],n)||!f.isSameCoordinate(i[r].z,s[4*r+2],n)||!f.isSameCoordinate(i[r].w,s[4*r+3],n))return!1}return!0}return t===void 0&&e===void 0}static isCloseToPlane(t,e,n=f.smallMetricDistance){if(Array.isArray(t)){for(const i of t)if(Math.abs(e.altitudeXYZW(i.x,i.y,i.z,i.w))>n)return!1}else if(t instanceof Float64Array){const i=t.length;for(let s=0;s+2<i;s+=4)if(Math.abs(e.altitudeXYZW(t[s],t[s+1],t[s+2],t[s+3]))>n)return!1}return!0}}class re{static packToFloat64Array(t,e){const n=3*t.length;(!e||e.length<n)&&(e=new Float64Array(n));let i=0;for(const s of t)e[i++]=s.x,e[i++]=s.y,e[i++]=s.z;return e}static packToNumberArray(t,e){const n=3*t.length;e||(e=Array(n)),e.length=n;let i=0;for(const s of t)e[i++]=s.x,e[i++]=s.y,e[i++]=s.z;return e}static evaluateTrilinearWeights(t,e,n,i,s,r,o){t[0]=e*i*r,t[1]=n*i*r,t[2]=e*s*r,t[3]=n*s*r,t[4]=e*i*o,t[5]=n*i*o,t[6]=e*s*o,t[7]=n*s*o}static sumWeightedX(t,e){let n=0;const i=t.length;for(let s=0;s<i;s++)n+=t[s]*e[s].x;return n}static sumWeightedY(t,e){let n=0;const i=t.length;for(let s=0;s<i;s++)n+=t[s]*e[s].y;return n}static sumWeightedZ(t,e){let n=0;const i=t.length;for(let s=0;s<i;s++)n+=t[s]*e[s].z;return n}static _weightUVW=new Float64Array(8);static _weightDU=new Float64Array(8);static _weightDV=new Float64Array(8);static _weightDW=new Float64Array(8);static evaluateTrilinearPoint(t,e,n,i,s){s||(s=y.create(0,0,0)),this.evaluateTrilinearWeights(this._weightUVW,1-e,e,1-n,n,1-i,i);let r;for(let o=0;o<8;o++)r=this._weightUVW[o],s.x+=r*t[o].x,s.y+=r*t[o].y,s.z+=r*t[o].z;return s}static evaluateTrilinearDerivativeTransform(t,e,n,i,s){return this.evaluateTrilinearWeights(this._weightUVW,1-e,e,1-n,n,1-i,i),this.evaluateTrilinearWeights(this._weightDU,-1,1,1-n,n,1-i,i),this.evaluateTrilinearWeights(this._weightDV,1-e,e,-1,1,1-i,i),this.evaluateTrilinearWeights(this._weightDW,1-e,e,1-n,n,-1,1),X.createRowValues(this.sumWeightedX(this._weightDU,t),this.sumWeightedX(this._weightDV,t),this.sumWeightedX(this._weightDW,t),this.sumWeightedX(this._weightUVW,t),this.sumWeightedY(this._weightDU,t),this.sumWeightedY(this._weightDV,t),this.sumWeightedY(this._weightDW,t),this.sumWeightedY(this._weightUVW,t),this.sumWeightedZ(this._weightDU,t),this.sumWeightedZ(this._weightDV,t),this.sumWeightedZ(this._weightDW,t),this.sumWeightedZ(this._weightUVW,t),s)}static unpackNumbersToPoint3dArray(t){const e=[];for(let n=0;n+2<t.length;n+=3)e.push(y.create(t[n],t[n+1],t[n+2]));return e}static unpackNumbersToNestedArrays(t,e){const n=[],i=t.length;let s=0,r=0;for(;s<i;){const o=[];for(r=s+e,r>i&&(r=i);s<r;s++)o.push(t[s]);n.push(o)}return n}static unpackNumbersToNestedArraysIJK(t,e,n){const i=[],s=t.length;let r=0,o=0,a;for(;r<s;){const c=[];for(a=r+e*n;r<a;){const l=[];for(o=r+e,o>s&&(o=s);r<o;r++)l.push(t[r]);c.push(l)}i.push(c)}return i}static multiplyInPlace(t,e){const n=y.create(),i=e.length;for(let s=0;s+2<i;s+=3)t.multiplyXYZ(e[s],e[s+1],e[s+2],n),e[s]=n.x,e[s+1]=n.y,e[s+2]=n.z}static isAlmostEqual(t,e,n=f.smallMetricDistance){if(t&&e){if(t instanceof Float64Array&&e instanceof Float64Array){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!f.isSameCoordinate(t[i],e[i],n))return!1}else if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].isAlmostEqual(e[i],n))return!1}else{const i=t instanceof Float64Array?e:t,s=t instanceof Float64Array?t:e;if(s.length!==i.length*3)return!1;for(let r=0;r<i.length;++r)if(!f.isSameCoordinate(i[r].x,s[3*r],n)||!f.isSameCoordinate(i[r].y,s[3*r+1],n)||!f.isSameCoordinate(i[r].z,s[3*r+2],n))return!1}return!0}return t===void 0&&e===void 0}static centroid(t,e){if(t instanceof le){e=y.create(0,0,0,e);const i=y.create();if(t.length>0){for(let s=0;s<t.length;s++)t.getPoint3dAtCheckedPointIndex(s,i),e.x+=i.x,e.y+=i.y,e.z+=i.z;e.scaleInPlace(1/t.length)}return e}const n=new Bt(t);return this.centroid(n)}static indexOfMostDistantPoint(t,e,n){if(t.length===0)return;let i=-1,s,r=-1;for(let o=0;o<t.length;o++)s=e.distance(t[o]),s>i&&(e.vectorTo(t[o],n),i=s,r=o);return r}static indexOfPointWithMaxCrossProductMagnitude(t,e,n,i){if(t.length===0)return;let s=-1,r,o=-1,a;for(let c=0;c<t.length;c++)a=e.vectorTo(t[c],a),r=a.crossProductMagnitude(n),r>s&&(i.setFrom(a),s=r,o=c);return o}static closestPointIndex(t,e){let n=-1,i=Number.MAX_VALUE,s;const r=e.x,o=e.y,a=e.z;for(let c=0;c<t.length;c++)s=f.distanceXYZXYZ(r,o,a,t[c].x,t[c].y,t[c].z),s<i&&(n=c,i=s);return n}static isCloseToPlane(t,e,n=f.smallMetricDistance){if(Array.isArray(t)){let i;for(i of t)if(Math.abs(e.altitude(i))>n)return!1}else if(t instanceof Float64Array){const i=t.length;for(let s=0;s+2<i;s+=3)if(Math.abs(e.altitudeXYZ(t[s],t[s+1],t[s+2]))>n)return!1}return!0}static sumEdgeLengths(t,e=!1,n){let i=0;if(Array.isArray(t)){const s=ea(t.length,n,1)-1;for(let r=0;r<s;r++)i+=t[r].distance(t[r+1]);e&&s>0&&(i+=t[0].distance(t[s]))}else if(t instanceof Float64Array){const s=ea(t.length,n,3);let r=0;for(;r+5<s;r+=3)i+=f.hypotenuseXYZ(t[r+3]-t[r],t[r+4]-t[r+1],t[r+5]-t[r+2]);e&&r>=3&&(i+=f.hypotenuseXYZ(t[0]-t[r],t[1]-t[r+1],t[2]-t[r+2]))}return i}static countNonDuplicates(t,e=f.smallMetricDistance){let n=t.length;for(;n>1&&t[0].isAlmostEqual(t[n-1],e);)n--;for(let i=0;i+1<n;i++)if(t[i].isAlmostEqual(t[i+1],e))return 0;return n}static clonePoint3dArray(t){const e=[];if(t.length===0)return e;if(t instanceof Float64Array){for(let n=0;n+2<t.length;n+=3)e.push(y.create(t[n],t[n+1],t[n+2]));return e}for(const n of t)Array.isArray(n)?e.push(y.create(n[0],n[1],n[2])):e.push(y.create(n.x,n.y,n.z));return e}static clonePoint2dArray(t){return t.map(e=>D.create(e.x,e.y))}static cloneWithMaxEdgeLength(t,e){if(t.length===0)return[];const n=[t[0]];for(let i=1;i<t.length;i++){const s=t[i-1].distance(t[i]),r=f.stepCount(e,s,1);for(let o=1;o<r;o++)n.push(t[i-1].interpolate(o/r,t[i]));n.push(t[i])}return n}static xyzToArray(t,e,n){return[t,e,n]}static cloneDeepJSONNumberArrays(t){const e=new Wo((n,i,s)=>this.xyzToArray(n,i,s));return bn.streamXYZ(t,e),e.claimResult()}static cloneXYZPropsAsNumberArray(t){const e=[];for(const n of t)if(n instanceof y)e.push([n.x,n.y,n.z]);else if(Array.isArray(n)){const i=n.length>0?n[0]:0,s=n.length>1?n[1]:0,r=n.length>2?n[2]:0;e.push([i,s,r])}else{const i=n.x!==void 0?n.x:0,s=n.y!==void 0?n.y:0,r=n.z!==void 0?n.z:0;e.push([i,s,r])}return e}static cloneXYZPropsAsFloat64Array(t){const e=new Float64Array(t.length*3);let n=0;for(const i of t)i instanceof y?(e[n++]=i.x,e[n++]=i.y,e[n++]=i.z):Array.isArray(i)?(e[n++]=i.length>0?i[0]:0,e[n++]=i.length>1?i[1]:0,e[n++]=i.length>2?i[2]:0):(e[n++]=i.x!==void 0?i.x:0,e[n++]=i.y!==void 0?i.y:0,e[n++]=i.z!==void 0?i.z:0);return e}static cloneDeepXYZPoint3dArrays(t){const e=new Wo((n,i,s)=>y.create(n,i,s));return bn.streamXYZ(t,e),e.claimResult()}static distanceIndexedPointBToSegmentAC(t,e,n,i,s){const r=P.createStartEnd(t[e],t[i]),o=P.createStartEnd(t[e],t[n]),a=r.dotProduct(r),c=r.dotProduct(o),l=f.conditionalDivideFraction(c,a);if(l===void 0)return o.magnitude();if(!s){if(l>1)return t[n].distance(t[i]);if(l<0)return o.magnitude()}const d=o.magnitudeSquared()-l*l*a;return d<=0?0:Math.sqrt(d)}static computeConvexHullXY(t,e,n,i=!1){e.length=0,n.length=0;let s=t.length;const r=t.slice(0,s);if(r.sort((c,l)=>f.lexicalXYLessThan(c,l)),s<3){for(const c of r)e.push(c);i&&r.length>0&&e.push(r[0]);return}e.push(r[0]),e.push(r[1]);let o=0;for(let c=2;c<s;c++){const l=r[c];let d=e.length-1;for(;d>=1&&e[d-1].crossProductToPointsXY(e[d],l)<=0;)r[o++]=e[d],d--,e.pop();e.push(l)}const a=e.length-1;r.length=o,r.push(e[0]),r.sort((c,l)=>f.lexicalXYLessThan(c,l)),s=r.length,e.push(r[s-1]);for(let c=s-1;c-- >0;){const l=r[c];let d=e.length-1;for(;d>a&&e[d-1].crossProductToPointsXY(e[d],l)<=0;)n.push(e[d]),d--,e.pop();c>0&&e.push(l)}i&&e.push(e[0])}static minMaxPoints(t){if(t.length===0)return;const e={minXPoint:t[0].clone(),maxXPoint:t[0].clone(),minYPoint:t[0].clone(),maxYPoint:t[0].clone()};let n;for(let i=1;i<t.length;i++)n=t[i],n.x<e.minXPoint.x&&e.minXPoint.setFromPoint3d(n),n.x>e.maxXPoint.x&&e.maxXPoint.setFromPoint3d(n),n.y<e.minYPoint.y&&e.minYPoint.setFromPoint3d(n),n.y>e.maxYPoint.y&&e.maxYPoint.setFromPoint3d(n);return e}}class ia{static decomposeLU(t,e,n){const i=t-1,s=Math.floor(e/2);let r;for(let o=0;o<=i;o++){const a=Math.min(i,o+s);for(let c=o;c<=a;c++){const l=Math.max(0,c-s);r=0;for(let d=l;d<o;d++)r+=n[o*e+d-o+s]*n[d*e+c-d+s];n[o*e+c-o+s]-=r}for(let c=o+1;c<=a;c++){const l=Math.max(0,c-s);r=0;for(let d=l;d<o;d++)r+=n[c*e+d-c+s]*n[d*e+o-d+s];if(Math.abs(n[o*e+s])<1e-9)return!1;n[c*e+o-c+s]=(n[c*e+o-c+s]-r)/n[o*e+s]}}return!0}static arrayAddScaledBlock(t,e,n,i){const s=t.length;let r=s*n;for(let o=0;o<s;o++,r++)t[o]+=e[r]*i}static blockAssignBlockMinusArray(t,e,n,i,s){const r=s.length;let o=e*r,a=i*r;for(let c=0;c<r;c++,a++,o++)t[o]=n[a]-s[c]}static blockSumOfScaledBlockScaledArray(t,e,n,i,s,r,o){const a=r.length;let c=e*a,l=i*a;for(let d=0;d<a;d++,l++,c++)t[c]=n[l]*s+r[d]*o}static solveBandedSystemMultipleRHS(t,e,n,i,s){if(!this.decomposeLU(t,e,n))return;const r=t-1,o=Math.floor(e/2),a=new Float64Array(i),c=new Float64Array(i*t),l=new Float64Array(i*t);for(let d=0;d<=r;d++){a.fill(0);const h=Math.max(0,d-o);for(let g=h;g<d;g++)this.arrayAddScaledBlock(a,c,g,n[d*e+g-d+o]);this.blockAssignBlockMinusArray(c,d,s,d,a)}for(let d=r;d>=0;d--){const h=f.conditionalDivideCoordinate(1,n[d*e+o]);if(h===void 0)return;a.fill(0);const g=Math.min(r,d+o);for(let m=d+1;m<=g;m++)this.arrayAddScaledBlock(a,l,m,n[d*e+m-d+o]);this.blockSumOfScaledBlockScaledArray(l,d,c,d,h,a,-h)}return l}static multiplyBandedTimesFull(t,e,n,i,s){const r=new Float64Array(s.length),o=Math.floor(e/2);let a,c,l,d;for(let h=0;h<t;h++){c=h-o,c<0&&(c=0),l=h+o+1,l>t&&(l=t),d=o+h*(e-1);for(let g=0;g<i;g++){a=0;for(let m=c;m<l;m++)a+=n[d+m]*s[m*i+g];r[h*i+g]=a}}return r}}class Yn{static _workPoint;getXAtUncheckedPointIndex(t){const e=this.getPoint2dAtCheckedPointIndex(t,Yn._workPoint);return Yn._workPoint===void 0&&(Yn._workPoint=e),e?e.x:0}getYAtUncheckedPointIndex(t){const e=this.getPoint2dAtCheckedPointIndex(t,Yn._workPoint);return Yn._workPoint===void 0&&(Yn._workPoint=e),e?e.y:0}linearCombination(t,e){const n=Math.min(this.length,t.length),i=e instanceof Q?Q.createZero(e):D.createZero(e);for(let s=0;s<n;++s)i.x+=t[s]*this.getXAtUncheckedPointIndex(s),i.y+=t[s]*this.getYAtUncheckedPointIndex(s);return i}}class gc extends Yn{}class Ie extends gc{_data;_xyInUse;_xyCapacity;_growthFactor;constructor(t,e,n){super(),n?(this._xyCapacity=n.length/2,this._xyInUse=Math.min(t??1/0,this._xyCapacity),this._data=n):(this._xyCapacity=t??8,this._xyInUse=0,this._data=new Float64Array(2*this._xyCapacity)),this._growthFactor=e!==void 0&&e>=1?e:1.5}copyData(t,e,n){let i=n!==void 0?n*2:0;if(i<0&&(i=0),i>=this._data.length)return{count:0,offset:0};let s=e!==void 0?e*2:t.length;return s>0&&(s>t.length&&(s=t.length),i+s>this._data.length&&(s=this._data.length-i),s%2!==0&&(s-=s%2)),s<=0?{count:0,offset:0}:(s===t.length?this._data.set(t,i):t instanceof Float64Array?this._data.set(t.subarray(0,s),i):this._data.set(t.slice(0,s),i),{count:s/2,offset:i/2})}get length(){return this._xyInUse}set length(t){this.resize(t,!0)}get float64Length(){return this._xyInUse*2}float64Data(){return this._data}ensureCapacity(t,e=!0){if(t>this._xyCapacity){e&&(t=Math.trunc(t*this._growthFactor));const n=this._data;this._data.buffer instanceof ArrayBuffer?this._data=new Float64Array(new ArrayBuffer(t*2*this._data.BYTES_PER_ELEMENT)):this._data=new Float64Array(new SharedArrayBuffer(t*2*this._data.BYTES_PER_ELEMENT)),this.copyData(n,this._xyInUse),this._xyCapacity=t}}resize(t,e){t>=0&&t<this._xyInUse?this._xyInUse=t:t>this._xyInUse&&(this.ensureCapacity(t,!1),(e??!1)&&this._data.fill(0,this._xyInUse*2),this._xyInUse=t)}clone(){const t=new Ie(this.length);return t.copyData(this._data,this.length),t._xyInUse=this.length,t}static create(t,e){if(e)e.clear();else{const n=typeof t[0]=="number"?t.length/2:t.length;e=new Ie(n)}return e.pushFrom(t),e}static createCapture(t){return new Ie(0,void 0,t)}static createArrayOfGrowableXYZArray(t){return W.createArrayOfGrowableXYZArray(t)}push(t){this.pushXY(t.x,t.y)}pushAll(t){this.ensureCapacity(this._xyInUse+t.length,!1);for(const e of t)this.push(e)}pushAllXYAndZ(t){if(this.ensureCapacity(this._xyInUse+t.length,!1),t instanceof W){const e=t.float64Data(),n=t.length*3;for(let i=0;i+2<n;i+=3)this.pushXY(e[i],e[i+1])}else for(const e of t)this.pushXY(e.x,e.y)}pushFrom(t){if(t instanceof y)this.pushXY(t.x,t.y);else if(t instanceof W)this.pushAllXYAndZ(t);else if(t instanceof D)this.pushXY(t.x,t.y);else if(f.isNumberArray(t,3)||t instanceof Float64Array){const e=Math.trunc(t.length/2);this.ensureCapacity(this._xyInUse+e,!1),this.copyData(t,e,this._xyInUse),this._xyInUse+=e}else if(f.isNumberArray(t,2))this.pushXY(t[0],t[1]);else if(Array.isArray(t))for(const e of t)this.pushFrom(e);else if(y.isXAndY(t))this.pushXY(t.x,t.y);else if(t instanceof Yn){const e=t.length;this.ensureCapacity(this._xyInUse+e,!1);for(let n=0;n<e;n++)this.pushXY(t.getXAtUncheckedPointIndex(n),t.getYAtUncheckedPointIndex(n))}}pushWrap(t){if(this._xyInUse>=t){this.ensureCapacity(this._xyInUse+t,!1);for(let e=0;e<t;e++){const n=2*e;this.pushXY(this._data[n],this._data[n+1])}}}pushXY(t,e){this.ensureCapacity(this._xyInUse+1);const n=this._xyInUse*2;this._data[n]=t,this._data[n+1]=e,this._xyInUse++}pop(){this._xyInUse>0&&this._xyInUse--}isIndexValid(t){return!(t>=this._xyInUse||t<0)}clear(){this._xyInUse=0}getPoint2dAtUncheckedPointIndex(t,e){const n=2*t;return D.create(this._data[n],this._data[n+1],e)}getXAtUncheckedPointIndex(t){return this._data[2*t]}getYAtUncheckedPointIndex(t){return this._data[2*t+1]}getPoint2dArray(){const t=2*this._xyInUse,e=[],n=this._data;for(let i=0;i<t;i+=2)e.push(D.create(n[i],n[i+1]));return e}getPoint2dAtCheckedPointIndex(t,e){if(this.isIndexValid(t)){const n=2*t;return D.create(this._data[n],this._data[n+1],e)}}getVector2dAtCheckedVectorIndex(t,e){if(this.isIndexValid(t)){const n=2*t;return Q.create(this._data[n],this._data[n+1],e)}}transferFromGrowableXYArray(t,e,n){if(this.isIndexValid(t)&&e.isIndexValid(n)){const i=t*2,s=n*2;return this._data[i]=e._data[s],this._data[i+1]=e._data[s+1],!0}return!1}pushFromGrowableXYArray(t,e){if(e===void 0){const n=t.length;return this.ensureCapacity(this.length+n,!1),this.copyData(t._data,n,this.length),this._xyInUse+=n,n}if(t.isIndexValid(e)){const n=e*2;return this.pushXY(t._data[n],t._data[n+1]),1}return 0}pushInterpolatedFromGrowableXYArray(t,e,n,i){if(t.isIndexValid(e)&&t.isIndexValid(i)){const s=1-n,r=t._data;e=2*e,i=2*i,this.pushXY(s*r[e]+n*r[i],s*r[e+1]+n*r[i+1])}}static createFromGrowableXYZArray(t,e,n){const i=t.length;if(n?(n.ensureCapacity(i,!1),n.clear()):n=new Ie(i),e){const s=t.float64Data(),r=3*i;let o,a,c;for(let l=0;l<r;l+=3)o=s[l],a=s[l+1],c=s[l+2],n.pushXY(e.multiplyComponentXYZ(0,o,a,c),e.multiplyComponentXYZ(1,o,a,c))}else n.pushAllXYAndZ(t);return n}front(t){if(this._xyInUse!==0)return this.getPoint2dAtUncheckedPointIndex(0,t)}back(t){if(!(this._xyInUse<1))return this.getPoint2dAtUncheckedPointIndex(this._xyInUse-1,t)}setAtCheckedPointIndex(t,e){if(!this.isIndexValid(t))return!1;const n=t*2;return this._data[n]=e.x,this._data[n+1]=e.y,!0}setXYAtCheckedPointIndex(t,e,n){if(!this.isIndexValid(t))return!1;const i=t*2;return this._data[i]=e,this._data[i+1]=n,!0}getPoint3dArray(t=0){const e=2*this._xyInUse,n=[],i=this._data;for(let s=0;s<e;s+=2)n.push(y.create(i[s],i[s+1],t));return n}reverseInPlace(){const t=this.length;let e,n,i;const s=this._data;for(let r=0,o=t-1;r<o;r++,o--)e=2*r,n=2*o,i=s[e],s[e]=s[n],s[n]=i,e++,n++,i=s[e],s[e]=s[n],s[n]=i}multiplyTransformInPlace(t){const e=this._data,n=this.float64Length,i=t.matrix.coffs,s=t.origin,r=s.x,o=s.y;let a=0,c=0;for(let l=0;l+1<n;l+=2)a=e[l],c=e[l+1],e[l]=i[0]*a+i[1]*c+r,e[l+1]=i[3]*a+i[4]*c+o}multiplyMatrix3dInPlace(t){const e=this._data,n=this.float64Length,i=t.coffs;let s=0,r=0;for(let o=0;o+1<n;o+=2)s=e[o],r=e[o+1],e[o]=i[0]*s+i[1]*r,e[o+1]=i[3]*s+i[4]*r}tryTransformInverseInPlace(t){const e=this._data,n=this.float64Length,i=t.matrix;i.computeCachedInverse(!0);const s=i.inverseCoffs;if(!s)return!1;const r=t.origin,o=r.x,a=r.y;let c=0,l=0;for(let d=0;d+1<n;d+=2)c=e[d]-o,l=e[d+1]-a,e[d]=s[0]*c+s[1]*l,e[d+1]=s[3]*c+s[4]*l;return!0}extendRange(t,e){const n=this.float64Length,i=this._data;if(e)for(let s=0;s+1<n;s+=2)t.extendTransformedXY(e,i[s],i[s+1]);else for(let s=0;s+1<n;s+=2)t.extendXY(i[s],i[s+1])}sumLengths(){let t=0;const e=2*(this._xyInUse-1),n=this._data;for(let i=0;i<e;i+=2)t+=f.hypotenuseXY(n[i+2]-n[i],n[i+3]-n[i+1]);return t}scaleInPlace(t){if(this._data){const e=this.float64Length;for(let n=0;n<e;n++)this._data[n]=this._data[n]*t}}interpolate(t,e,n,i){if(this.isIndexValid(t)&&this.isIndexValid(n)){const s=1-e,r=this._data;return t=2*t,n=2*n,D.create(s*r[t]+e*r[n],s*r[t+1]+e*r[n+1],i)}}areaXY(){let t=0;const e=2*this._xyInUse;if(e>4){const n=this._data[e-2],i=this._data[e-1];let s=this._data[0]-n,r=this._data[1]-i,o=0,a=0;for(let c=2;c<e;c+=2,s=o,r=a)o=this._data[c]-n,a=this._data[c+1]-i,t+=f.crossProductXYXY(s,r,o,a)}return .5*t}vectorIndexIndex(t,e,n){if(!this.isIndexValid(t)||!this.isIndexValid(e))return;const i=this._data;return t=2*t,e=2*e,Q.create(i[e]-i[t],i[e+1]-i[t+1],n)}vectorXAndYIndex(t,e,n){if(this.isIndexValid(e)){const i=this._data;return e=2*e,Q.create(i[e]-t.x,i[e+1]-t.y,n)}}crossProductIndexIndexIndex(t,e,n){if(this.isIndexValid(t)&&this.isIndexValid(e)&&this.isIndexValid(n)){const i=t*2,s=e*2,r=n*2,o=this._data;return f.crossProductXYXY(o[s]-o[i],o[s+1]-o[i+1],o[r]-o[i],o[r+1]-o[i+1])}}crossProductXAndYIndexIndex(t,e,n){if(this.isIndexValid(e)&&this.isIndexValid(n)){const i=e*2,s=n*2,r=this._data;return f.crossProductXYXY(r[i]-t.x,r[i+1]-t.y,r[s]-t.x,r[s+1]-t.y)}}distance(t,e){if(this.isIndexValid(t)&&this.isIndexValid(e)){const n=2*t,i=2*e;return f.hypotenuseXY(this._data[i]-this._data[n],this._data[i+1]-this._data[n+1])}}distanceIndexToPoint(t,e){if(this.isIndexValid(t)){const n=2*t;return f.hypotenuseXY(e.x-this._data[n],e.y-this._data[n+1])}}static isAlmostEqual(t,e){if(t&&e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!t.getPoint2dAtUncheckedPointIndex(n).isAlmostEqual(e.getPoint2dAtUncheckedPointIndex(n)))return!1;return!0}return!t&&!e}sortIndicesLexical(){const t=this._xyInUse,e=new Uint32Array(t);for(let n=0;n<t;n++)e[n]=n;return e.sort((n,i)=>this.compareLexicalBlock(n,i)),e}compareLexicalBlock(t,e){let n=0,i=0;for(let s=0;s<2;s++){if(n=this._data[t*2+s],i=this._data[e*2+s],n>i)return 1;if(n<i)return-1}return t-e}component(t,e){return this._data[2*t+e]}isAlmostEqual(t,e=f.smallMetricDistance){const n=this._xyInUse;if(t._xyInUse!==n)return!1;const i=this._data,s=t._data;for(let r=0;r<2*n;r++)if(Math.abs(i[r]-s[r])>e)return!1;return!0}}class Zt{chordTol;angleTol;maxEdgeLength;needConvexFacets;minStrokesPerPrimitive;shouldTriangulate=!1;_needNormals;_needTwoSided;_needParams;get needParams(){return this._needParams!==void 0?this._needParams:!1}set needParams(t){this._needParams=t}get needNormals(){return this._needNormals!==void 0?this._needNormals:!1}set needNormals(t){this._needNormals=t}get needTwoSided(){return this._needTwoSided!==void 0?this._needTwoSided:!0}set needTwoSided(t){this._needTwoSided=t}needColors;defaultCircleStrokes=16;get hasAngleTol(){return this.angleTol!==void 0&&Math.abs(this.angleTol.radians)>0}get hasChordTol(){return this.chordTol!==void 0&&this.chordTol>0}get hasMaxEdgeLength(){return this.maxEdgeLength!==void 0&&this.maxEdgeLength>0}_maximizeConvexFacets;get maximizeConvexFacets(){return this._maximizeConvexFacets??!1}set maximizeConvexFacets(t){this._maximizeConvexFacets=t,t&&(this.shouldTriangulate=t)}clone(){const t=new Zt;return t.chordTol=this.chordTol,t.angleTol=this.angleTol?.clone(),t.maxEdgeLength=this.maxEdgeLength,t.minStrokesPerPrimitive=this.minStrokesPerPrimitive,t.shouldTriangulate=this.shouldTriangulate,t._needNormals=this._needNormals,t._needTwoSided=this._needTwoSided,t._needParams=this._needParams,t.needColors=this.needColors,t.defaultCircleStrokes=this.defaultCircleStrokes,t._maximizeConvexFacets=this._maximizeConvexFacets,t}applyMaxEdgeLength(t,e){return e=Math.abs(e),this.maxEdgeLength&&this.maxEdgeLength>0&&t*this.maxEdgeLength<e&&(t=f.stepCount(this.maxEdgeLength,e,t)),t}applyAngleTol(t,e,n){return Zt.applyAngleTol(this,t,e,n)}static applyAngleTol(t,e,n,i){n=Math.abs(n);let s=i||Math.PI/8;return t&&t.angleTol&&t.angleTol.radians>0&&(s=t.angleTol.radians),e*s<n&&(e=f.stepCount(s,n,e)),e}static applyMaxEdgeLength(t,e,n){return n<0&&(n=-n),e<1&&(e=1),t&&t.maxEdgeLength&&t.maxEdgeLength*e<n&&(e=f.stepCount(t.maxEdgeLength,n,e)),e}applyTolerancesToArc(t,e=Math.PI*2){let n=1;return n=this.applyAngleTol(n,e,Math.PI*.25),n=this.applyMaxEdgeLength(n,e*t),n=this.applyChordTol(n,t,e),n=this.applyMinStrokesPerPrimitive(n),n}applyChordTol(t,e,n){if(this.chordTol&&this.chordTol>0&&this.chordTol<e){const i=this.chordTol,s=2*Math.acos(1-i/e);t=f.stepCount(s,n,t)}return t}applyChordTolToLengthAndRadians(t,e,n){if(this.chordTol&&this.chordTol>0){const i=f.conditionalDivideFraction(e,n);if(i!==void 0)return this.applyChordTol(t,i,n)}return t}applyMinStrokesPerPrimitive(t){return this.minStrokesPerPrimitive!==void 0&&Number.isFinite(this.minStrokesPerPrimitive)&&this.minStrokesPerPrimitive>t&&(t=this.minStrokesPerPrimitive),t}static createForCurves(){const t=new Zt;return t.angleTol=A.createDegrees(15),t}static createForFacets(){const t=new Zt;return t.angleTol=A.createDegrees(22.5),t}}class Ei{minArcDegrees=180;maxChamferTurnDegrees=91;allowSharpestCorners=!1;leftOffsetDistance=0;preserveEllipticalArcs=!1;constructor(t,e=180,n=91,i=!1,s=!1){this.leftOffsetDistance=t,this.minArcDegrees=e,this.maxChamferTurnDegrees=n,this.preserveEllipticalArcs=i,this.allowSharpestCorners=s}clone(){return new Ei(this.leftOffsetDistance,this.minArcDegrees,this.maxChamferTurnDegrees,this.preserveEllipticalArcs,this.allowSharpestCorners)}setFrom(t){this.leftOffsetDistance=t.leftOffsetDistance,this.minArcDegrees=t.minArcDegrees,this.maxChamferTurnDegrees=t.maxChamferTurnDegrees,this.preserveEllipticalArcs=t.preserveEllipticalArcs,this.allowSharpestCorners=t.allowSharpestCorners}static create(t){return t instanceof Ei?t:new Ei(t)}needArc(t){return Math.abs(t.degrees)>=this.minArcDegrees-f.smallAngleDegrees}numChamferPoints(t){const e=Math.abs(t.degrees),n=10;let i=120;this.allowSharpestCorners&&(i=this.maxChamferTurnDegrees);const s=f.clamp(this.maxChamferTurnDegrees,n,i);return e<=s+f.smallAngleDegrees?1:Math.ceil(e/s)}}class Oe{jointOptions;strokeOptions;constructor(t,e){this.jointOptions=Ei.create(t),this.strokeOptions=e!==void 0?e:Zt.createForCurves()}get minArcDegrees(){return this.jointOptions.minArcDegrees}set minArcDegrees(t){this.jointOptions.minArcDegrees=t}get maxChamferTurnDegrees(){return this.jointOptions.maxChamferTurnDegrees}set maxChamferTurnDegrees(t){this.jointOptions.maxChamferTurnDegrees=t}get allowSharpestCorners(){return this.jointOptions.allowSharpestCorners}set allowSharpestCorners(t){this.jointOptions.allowSharpestCorners=t}get leftOffsetDistance(){return this.jointOptions.leftOffsetDistance}set leftOffsetDistance(t){this.jointOptions.leftOffsetDistance=t}get preserveEllipticalArcs(){return this.jointOptions.preserveEllipticalArcs}set preserveEllipticalArcs(t){this.jointOptions.preserveEllipticalArcs=t}static create(t){return t instanceof Oe?t:new Oe(t)}static getOffsetDistance(t){return typeof t=="number"?t:t.leftOffsetDistance}clone(){return new Oe(this.jointOptions.clone(),this.strokeOptions.clone())}}class U extends st{curvePrimitiveType="lineSegment";isSameGeometryClass(t){return t instanceof U}_point0;_point1;get point0Ref(){return this._point0}get point1Ref(){return this._point1}get points(){return[this._point0.clone(),this._point1.clone()]}get isExtensibleFractionSpace(){return!0}constructor(t,e){super(),this._point0=t,this._point1=e}setRefs(t,e){this._point0=t,this._point1=e}set(t,e){this._point0=t.clone(),this._point1=e.clone()}setFrom(t){this._point0.setFrom(t._point0),this._point1.setFrom(t._point1)}startPoint(t){return t?(t.setFrom(this._point0),t):this._point0.clone()}endPoint(t){return t?(t.setFrom(this._point1),t):this._point1.clone()}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){return!1}fractionToPointAndDerivative(t,e){return e=e||O.createZero(),e.direction.setStartEnd(this._point0,this._point1),this._point0.interpolate(t,this._point1,e.origin),e}fractionToPointAnd2Derivatives(t,e){return e=e||At.createXYPlane(),e.vectorU.setStartEnd(this._point0,this._point1),e.vectorV.set(0,0,0),this._point0.interpolate(t,this._point1,e.origin),e}clone(){return U.create(this._point0,this._point1)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}static create(t,e,n){return n?(n.set(t,e),n):new U(t.clone(),e.clone())}static createCapture(t,e){return new U(t,e)}static createXYXY(t,e,n,i,s=0,r){return r?(r._point0.set(t,e,s),r._point1.set(n,i,s),r):new U(y.create(t,e,s),y.create(n,i,s))}static createXYZXYZ(t,e,n,i,s,r,o){return o?(o._point0.set(t,e,n),o._point1.set(i,s,r),o):new U(y.create(t,e,n),y.create(i,s,r))}fractionToPoint(t,e){return this._point0.interpolate(t,this._point1,e)}curveLength(){return this._point0.distance(this._point1)}curveLengthBetweenFractions(t,e){return Math.abs(e-t)*this._point0.distance(this._point1)}quickLength(){return this.curveLength()}closestPoint(t,e=!1,n){let i=t.fractionOfProjectionToLine(this._point0,this._point1,0);return i=Ut.correctFraction(e,i),n=Y.create(this,n),n.fraction=i,this._point0.interpolate(i,this._point1,n.point),n.vectorInCurveLocationDetail=void 0,n.a=n.point.distance(t),n}static closestApproach(t,e,n,i,s){const r=Q.create();if(s===void 0&&(s=Ot.createCapture(Y.create(),Y.create())),bt.lineSegment3dClosestApproachUnbounded(t._point0,t._point1,n._point0,n._point1,r)){const l=Ut.correctFraction(e,r.x),d=Ut.correctFraction(i,r.y);if(l===r.x&&d===r.y)return Y.createCurveEvaluatedFraction(t,l,s.detailA),Y.createCurveEvaluatedFraction(n,d,s.detailB),s.detailA.a=s.detailB.a=s.detailA.point.distance(s.detailB.point),s;if(l!==r.x&&d!==r.y){const h=l<.5?t._point0:t._point1,g=d<.5?n._point0:n._point1;n.closestPoint(h,i,s.detailB),t.closestPoint(g,e,s.detailA),s.detailA.a<=s.detailB.a?Y.createCurveFractionPoint(n,d,g,s.detailB):Y.createCurveFractionPoint(t,l,h,s.detailA)}else if(d!==r.y){const h=d<.5?n._point0:n._point1;t.closestPoint(h,e,s.detailA),s.detailB.setCurve(n),s.detailB.point.setFrom(h),s.detailB.fraction=d}else{const h=l<.5?t._point0:t._point1;n.closestPoint(h,i,s.detailB),s.detailA.setCurve(t),s.detailA.point.setFrom(h),s.detailA.fraction=l}return s.detailA.a=s.detailB.a=s.detailA.point.distance(s.detailB.point),s}const o=[t.closestPoint(n._point0,e),t.closestPoint(n._point1,e),n.closestPoint(t._point0,i),n.closestPoint(t._point1,i)];let a=o[0].a,c=0;for(let l=1;l<4;l++)o[l].a<a&&(c=l,a=o[l].a);return c===0?(o[0].clone(s.detailA),Y.createCurveEvaluatedFraction(n,0,s.detailB),s.detailB.a=s.detailA.a):c===1?(o[1].clone(s.detailA),Y.createCurveEvaluatedFraction(n,1,s.detailB),s.detailB.a=s.detailA.a):c===2?(o[2].clone(s.detailB),Y.createCurveEvaluatedFraction(t,0,s.detailA),s.detailA.a=s.detailB.a):(o[3].clone(s.detailB),Y.createCurveEvaluatedFraction(t,1,s.detailA),s.detailA.a=s.detailB.a),s}reverseInPlace(){const t=this._point0;this._point0=this._point1,this._point1=t}tryTransformInPlace(t){return this._point0=t.multiplyPoint3d(this._point0,this._point0),this._point1=t.multiplyPoint3d(this._point1,this._point1),!0}isInPlane(t){return f.isSmallMetricDistance(t.altitude(this._point0))&&f.isSmallMetricDistance(t.altitude(this._point1))}appendPlaneIntersectionPoints(t,e){const n=t.altitude(this._point0),i=t.altitude(this._point1),s=Ds.solveCoffs(n,i);let r=0;if(s!==void 0){r++;const o=Y.createCurveFractionPoint(this,s,this.fractionToPoint(s));o.intervalRole=Ct.isolated,e.push(o)}return r}extendRange(t,e){e?(t.extendTransformedPoint(e,this._point0),t.extendTransformedPoint(e,this._point1)):(t.extendPoint(this._point0),t.extendPoint(this._point1))}setFromJSON(t){if(t)t.startPoint&&t.endPoint?(this._point0.setFromJSON(t.startPoint),this._point1.setFromJSON(t.endPoint)):Array.isArray(t)&&t.length>1&&(this._point0.setFromJSON(t[0]),this._point1.setFromJSON(t[1]));else{this._point0.set(0,0,0),this._point1.set(1,0,0);return}}getFractionToDistanceScale(){return this.curveLength()}toJSON(){return[this._point0.toJSON(),this._point1.toJSON()]}static fromJSON(t){const e=new U(y.createZero(),y.create());return e.setFromJSON(t),e}isAlmostEqual(t){if(t instanceof U){const e=t;return this._point0.isAlmostEqual(e._point0)&&this._point1.isAlmostEqual(e._point1)}return!1}emitStrokes(t,e){const n=this.computeStrokeCountForOptions(e);t.appendFractionalStrokePoints(this,n,0,1)}emitStrokableParts(t,e){t.startCurvePrimitive(this);const n=this.computeStrokeCountForOptions(e);t.announceSegmentInterval(this,this._point0,this._point1,n,0,1),t.endCurvePrimitive(this)}computeStrokeCountForOptions(t){let e=1;return t&&(t.maxEdgeLength&&(e=t.applyMaxEdgeLength(e,this.curveLength())),e=t.applyMinStrokesPerPrimitive(e)),e}dispatchToGeometryHandler(t){return t.handleLineSegment3d(this)}announceClipIntervals(t,e){return t.announceClippedSegmentIntervals(0,1,this._point0,this._point1,e?(n,i)=>e(n,i,this):void 0)}clonePartialCurve(t,e){return U.create(this.fractionToPoint(t),this.fractionToPoint(e))}rangeBetweenFractions(t,e,n){if(!n){const r=J.create();return r.extendInterpolated(this._point0,t,this._point1),r.extendInterpolated(this._point0,e,this._point1),r}const i=this.fractionToPoint(t),s=this.fractionToPoint(e);return n&&(n.multiplyPoint3d(i,i),n.multiplyPoint3d(s,s)),J.create(i,s)}constructOffsetXY(t){const e=P.createStartEnd(this._point0,this._point1);if(e.normalizeInPlace()){e.rotate90CCWXY(e);const n=Oe.getOffsetDistance(t);return U.create(this._point0.plusScaled(e,n),this._point1.plusScaled(e,n))}}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}}function Xs(u,t,e,n,i,s,r){const o=u.length;if(n>0){for(let a=e;a+1<o;a++)if(u.vectorIndexIndex(a,a+1,r),t.crossProduct(r,r),r.normalizeInPlace())return s.addScaledInPlace(r,i),s.isAlmostEqualXYZ(0,0,0,f.smallFraction)&&r.scale(-i,s),!0}else{e+1>=o&&(e=o-2);for(let a=e;a>=0;a--)if(u.vectorIndexIndex(a,a+1,r),r.crossProduct(t,r),r.normalizeInPlace())return s.addScaledInPlace(r,i),s.isAlmostEqualXYZ(0,0,0,f.smallFraction)&&r.scale(-i,s),!0}return!1}class F extends st{curvePrimitiveType="lineString";static _workPointA=y.create();static _workPointB=y.create();static _workPointC=y.create();static _workRay=O.createXAxis();isSameGeometryClass(t){return t instanceof F}get isExtensibleFractionSpace(){return!0}_points;_fractions;_uvParams;_derivatives;_surfaceNormals;_pointIndices;_uvIndices;_normalIndices;get points(){return this._points.getPoint3dArray()}get packedPoints(){return this._points}get fractions(){return this._fractions}get packedDerivatives(){return this._derivatives}get packedUVParams(){return this._uvParams}get packedSurfaceNormals(){return this._surfaceNormals}get normalIndices(){return this._normalIndices}get paramIndices(){return this._uvIndices}get pointIndices(){return this._pointIndices}constructor(t){super(),t?this._points=t:this._points=new W}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}static create(...t){const e=new F;return e.addPoints(t),e}static createCapture(t){return new F(t)}static createXY(t,e,n=!1){const i=new F,s=i._points;for(const r of t)s.pushXYZ(r.x,r.y,e);return n&&s.length>1&&s.almostEqualUncheckedIndexIndex(0,s.length-1)&&s.transferFromGrowableXYZArray(s.length-1,s,0),i}addPoints(...t){this._points.pushFrom(t)}addSteppedPoints(t,e,n,i){this._points.addSteppedPoints(t,e,n,i)}addPoint(t){this._points.push(t)}addPointXYZ(t,e,n=0){this._points.pushXYZ(t,e,n)}addFraction(t){this._fractions||(this._fractions=new Ft),this._fractions.push(t)}ensureEmptyFractions(){const t=this.numPoints();return this._fractions?(this._fractions.clear(),this._fractions.ensureCapacity(t),this._fractions):(this._fractions=new Ft(t),this._fractions)}ensureEmptyUVParams(){const t=this.numPoints();return this._uvParams?(this._uvParams.clear(),this._uvParams.ensureCapacity(t),this._uvParams):(this._uvParams=new Ie(t),this._uvParams)}ensureEmptySurfaceNormals(){const t=this.numPoints();return this._surfaceNormals?(this._surfaceNormals.clear(),this._surfaceNormals.ensureCapacity(t),this._surfaceNormals):(this._surfaceNormals=new W(t),this._surfaceNormals)}ensureEmptyDerivatives(){const t=this.numPoints();return this._derivatives?(this._derivatives.clear(),this._derivatives.ensureCapacity(t),this._derivatives):(this._derivatives=new W(t),this._derivatives)}ensureEmptyNormalIndices(){const t=this.numPoints();return this._normalIndices?(this._normalIndices.clear(),this._normalIndices.ensureCapacity(t),this._normalIndices):(this._normalIndices=new Ft(t),this._normalIndices)}ensureEmptyUVIndices(){const t=this.numPoints();return this._uvIndices?(this._uvIndices.clear(),this._uvIndices.ensureCapacity(t),this._uvIndices):(this._uvIndices=new Ft(t),this._uvIndices)}ensureEmptyPointIndices(){const t=this.numPoints();return this._pointIndices?(this._pointIndices.clear(),this._pointIndices.ensureCapacity(t),this._pointIndices):(this._pointIndices=new Ft(t),this._pointIndices)}addUVParam(t){this._uvParams||(this._uvParams=new Ie),this._uvParams.pushXY(t.x,t.y)}addUVParamAsUV(t,e){this._uvParams||(this._uvParams=new Ie),this._uvParams.pushXY(t,e)}addDerivative(t){this._derivatives||(this._derivatives=new W),this._derivatives.push(t)}addSurfaceNormal(t){this._surfaceNormals||(this._surfaceNormals=new W),this._surfaceNormals.push(t)}addClosurePoint(){const t=this._points.distanceIndexIndex(0,this._points.length-1);t!==void 0&&!f.isSameCoordinate(t,0)&&this._points.pushWrap(1)}popPoint(){this._points.pop()}computeUVFromXYZTransform(t){this._uvParams=Ie.createFromGrowableXYZArray(this._points,t)}static createRectangleXY(t,e,n,i=!0){const s=F.create(),r=t.x,o=t.x+e,a=t.y,c=t.y+n,l=t.z;return s.addPointXYZ(r,a,l),s.addPointXYZ(o,a,l),s.addPointXYZ(o,c,l),s.addPointXYZ(r,c,l),i&&s.addClosurePoint(),s}static createRegularPolygonXY(t,e,n,i=!0){e<3&&(e=3);const s=F.create(),r=i?0:-1,o=Math.PI/e;let a,c,l;i||(n=n/Math.cos(o));for(let d=0;d<e;d++)l=(r+2*d)*o,a=A.cleanupTrigValue(Math.cos(l)),c=A.cleanupTrigValue(Math.sin(l)),s.addPointXYZ(t.x+n*a,t.y+n*c,t.z);return s.addClosurePoint(),s}setFrom(t){this._points=t._points.clone(this._points),t._derivatives?this._derivatives=t._derivatives.clone(this._derivatives):this._derivatives=void 0,t._fractions?this._fractions=t._fractions.clone(!1):this._fractions=void 0,t._surfaceNormals?this._surfaceNormals=t._surfaceNormals.clone(this._surfaceNormals):this._surfaceNormals=void 0,t._uvParams?this._uvParams=t._uvParams.clone():this._uvParams=void 0}static createPoints(t){const e=new F;let n;for(n of t)e._points.push(n);return e}static createIndexedPoints(t,e,n=!1){const i=new F;for(const s of e)i._points.push(t[s]);return n&&e.length>1&&i._points.push(t[e[0]]),i}static createFloat64Array(t){const e=new F;for(let n=0;n+3<=t.length;n+=3)e._points.push(y.create(t[n],t[n+1],t[n+2]));return e}clone(){const t=new F;return t.setFrom(this),t}setFromJSON(t){if(this._points.clear(),Array.isArray(t)){let e;for(e of t)this._points.push(y.fromJSON(e))}}toJSON(){const t=[];let e=0;for(;this._points.isIndexValid(e);)t.push(this._points.getPoint3dAtUncheckedPointIndex(e).toJSON()),e++;return t}static fromJSON(t){const e=new F;return e.setFromJSON(t),e}fractionToPoint(t,e){const n=this._points.length;if(n<=0)return y.createZero();if(n===1)return y.createFrom(this._points.getPoint3dAtUncheckedPointIndex(0),e);const i=1/(n-1);if(t<=i)return this._points.interpolateUncheckedIndexIndex(0,t/i,1,e);if(t+i>=1)return this._points.interpolateUncheckedIndexIndex(n-1,(1-t)/i,n-2,e);const s=Math.floor(t/i);return this._points.interpolateUncheckedIndexIndex(s,(t-s*i)/i,s+1,e)}fractionToPointAndDerivative(t,e){e=e||O.createZero();const n=this._points.length;if(n<=1)return e.direction.setZero(),n===1?e.origin.setFrom(this._points.getPoint3dAtUncheckedPointIndex(0)):e.origin.setZero(),e;const s=1/(n-1);if(t<=s)return e=e||O.createZero(),this._points.interpolate(0,t/s,1,e.origin),this._points.vectorIndexIndex(0,1,e.direction),e.direction.scaleInPlace(1/s),e;if(t+s>=1)return e=e||O.createZero(),this._points.interpolate(n-2,1-(1-t)/s,n-1,e.origin),this._points.vectorIndexIndex(n-2,n-1,e.direction),e.direction.scaleInPlace(1/s),e;e=e||O.createZero();const r=Math.floor(t/s),o=(t-r*s)/s;return this._points.interpolate(r,o,r+1,e.origin),this._points.vectorIndexIndex(r,r+1,e.direction),e.direction.scaleInPlace(1/s),e}fractionToPointAnd2Derivatives(t,e){const n=this.fractionToPointAndDerivative(t);return e=At.createCapture(n.origin,n.direction,P.createZero(),e),e}static mapLocalToGlobalFraction(t,e,n){return n<1?0:(t+e)/n}segmentIndexAndLocalFractionToGlobalFraction(t,e){return F.mapLocalToGlobalFraction(t,e,this._points.length-1)}static mapGlobalToLocalFraction(t,e){if(e<1)return{index:0,fraction:0};const n=t*e;let i;return t<=0?i=0:t>=1?i=e-1:i=Math.floor(n),{index:i,fraction:n-i}}globalFractionToSegmentIndexAndLocalFraction(t){return F.mapGlobalToLocalFraction(t,this._points.length-1)}fractionToFrenetFrame(t,e){const n=this._points.length;if(n<=1)return n===1?X.createTranslation(this._points.getPoint3dAtUncheckedPointIndex(0),e):X.createIdentity(e);if(n===2){const g=C.createRigidHeadsUp(this._points.vectorUncheckedIndexIndex(0,1),mt.XYZ);return X.createOriginAndMatrix(this._points.interpolate(0,t,1),g,e)}const i=n-1,s=1/i;let r=0,o=0;t<=s?(o=t/s,r=0):t+s>=1?(r=n-2,o=1-(1-t)/s):(r=Math.floor(t/s),o=t*i-r);const a=this._points.interpolateUncheckedIndexIndex(r,o,r+1),c=this._points.vectorUncheckedIndexIndex(r,r+1),l=P.create(),d=P.create();r===0?Xs(this._points,c,r+1,1,1,l,d):r+2>=n?Xs(this._points,c,r-1,-1,1,l,d):(Xs(this._points,c,r-1,-1,1-o,l,d),Xs(this._points,c,r+1,1,o,l,d));const h=C.createRigidFromColumns(l,c,mt.ZXY);return h?X.createOriginAndMatrix(a,h,e):X.createTranslation(a,e)}startPoint(t){return this._points.length===0?y.createZero(t):this._points.getPoint3dAtUncheckedPointIndex(0,t)}pointAt(t,e){if(this._points.isIndexValid(t))return this.pointAtUnchecked(t,e)}pointAtUnchecked(t,e){return this._points.getPoint3dAtUncheckedPointIndex(t,e)}vectorBetween(t,e,n){return this._points.vectorIndexIndex(t,e,n)}derivativeAt(t,e){if(this._derivatives&&this._derivatives.isIndexValid(t))return this._derivatives.getVector3dAtCheckedVectorIndex(t,e)}surfaceNormalAt(t,e){if(this._surfaceNormals&&this._surfaceNormals.isIndexValid(t))return this._surfaceNormals.getVector3dAtCheckedVectorIndex(t,e)}numPoints(){return this._points.length}numEdges(){return this._points.length>0?this._points.length-1:0}endPoint(t){return this._points.length===0?y.createZero(t):this._points.getPoint3dAtUncheckedPointIndex(this._points.length-1,t)}reverseInPlace(){if(this._points.length>=2){if(this._points.reverseInPlace(),this._fractions){this._fractions.reverseInPlace();for(let t=0;t<this._fractions.length;++t)this._fractions.reassign(t,1-this._fractions.atUncheckedIndex(t))}this._uvParams&&this._uvParams.reverseInPlace(),this._derivatives&&(this._derivatives.reverseInPlace(),this._derivatives.scaleInPlace(-1)),this._surfaceNormals&&this._surfaceNormals.reverseInPlace(),this._pointIndices&&this._pointIndices.reverseInPlace(),this._uvIndices&&this._uvIndices.reverseInPlace(),this._normalIndices&&this._normalIndices.reverseInPlace()}}tryTransformInPlace(t){return this._points.multiplyTransformInPlace(t),this._derivatives&&this._derivatives.multiplyMatrix3dInPlace(t.matrix),this._surfaceNormals&&this._surfaceNormals.multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(t.matrix),!0}curveLength(){return this._points.sumLengths()}curveLengthBetweenFractions(t,e){const i=this._points.length-1;if(e===t||i<1)return 0;if(e<t)return this.curveLengthBetweenFractions(e,t);const s=t*i,r=e*i,o=Math.max(1,Math.ceil(s)),a=Math.min(Math.floor(r),i-1);if(o>a)return Math.abs(r-s)*this._points.distanceUncheckedIndexIndex(a,o);const c=o-s,l=r-a;let d=c*this._points.distanceUncheckedIndexIndex(o-1,o);for(let h=o;h<a;h++)d+=this._points.distanceUncheckedIndexIndex(h,h+1);return d+=l*this._points.distanceUncheckedIndexIndex(a,a+1),d}rangeBetweenFractions(t,e,n){const i=J.create();if(this.points.length<1)return i;if(e<t)return this.rangeBetweenFractions(e,t,n);const s=this._points.length-1,r=t*s,o=Math.max(0,Math.floor(r)),a=r-o,c=y.create();if(this._points.interpolate(o,a,o+1,c),i.extendPoint(c,n),e===t)return i;const l=e*s,d=Math.min(Math.floor(l),s-1),h=l-d;this._points.interpolate(d,h,d+1,c),i.extendPoint(c,n);for(let g=o+1;g<=d;g++)this._points.getPoint3dAtUncheckedPointIndex(g,c),i.extendPoint(c,n);return i}moveSignedDistanceFromFraction(t,e,n,i){const r=this._points.length-1,o=t*r;let a=f.restrictToInterval(Math.floor(o),0,r-1);const c=o-a,l=this._points.interpolateUncheckedIndexIndex(a,c,a+1,F._workPointA),d=F._workPointB,h=new mc(l,t,e);if(e>0){for(;a<=r;)if(a++,this._points.getPoint3dAtCheckedPointIndex(a,d),h.announcePoint(d,a/r))return Y.createCurveFractionPointDistanceCurveSearchStatus(this,h.fraction0,h.point0,e,Me.success,i);return n&&h.announceExtrapolation(this._points,r-1,r,(r-1)/r,1),Y.createCurveFractionPointDistanceCurveSearchStatus(this,h.fraction0,h.point0,e,h.distanceStatus(),i)}else{for(c<=0&&a--;a>=0;a--)if(this._points.getPoint3dAtCheckedPointIndex(a,d),h.announcePoint(d,a/r))return Y.createCurveFractionPointDistanceCurveSearchStatus(this,h.fraction0,h.point0,e,Me.success,i);return n&&h.announceExtrapolation(this._points,1,0,1/r,0),Y.createCurveFractionPointDistanceCurveSearchStatus(this,h.fraction0,h.point0,-h.distance0,h.distanceStatus(),i)}}quickLength(){return this.curveLength()}quickUnitNormal(t){let e=Math.floor(this._points.length/3);if(e<1&&(e=1),t=this._points.crossProductIndexIndexIndex(0,e,e+e),t&&t.normalizeInPlace())return t}closestPoint(t,e=!1,n){n=Y.create(this,n);const i=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,0),s=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,1),r=this._points.length;if(r>0){const o=r-1;if(n.setFP(1,this._points.getPoint3dAtUncheckedPointIndex(o),void 0),n.setDistanceTo(t),r>1){let a=0,c=0;for(let l=1;l<r;l++)a=t.fractionOfProjectionToLine(this._points.getPoint3dAtUncheckedPointIndex(l-1),this._points.getPoint3dAtUncheckedPointIndex(l)),a<0?(!i||l>1)&&(a=0):a>1&&(!s||l<o)&&(a=1),this._points.getPoint3dAtUncheckedPointIndex(l-1).interpolate(a,this._points.getPoint3dAtUncheckedPointIndex(l),n.pointQ),c=n.pointQ.distance(t),c<n.a&&n.setFP(this.segmentIndexAndLocalFractionToGlobalFraction(l-1,a),n.pointQ,void 0,c)}}return n}isInPlane(t){return this._points.isCloseToPlane(t,f.smallMetricDistance)}static pushVertexHit(t,e,n,i,s){const r=Y.createCurveFractionPoint(n,i,s);t.push(r),e===0?r.setIntervalRole(Ct.isolatedAtVertex):e===1?(t[t.length-2].setIntervalRole(Ct.intervalStart),r.setIntervalRole(Ct.intervalEnd)):(t[t.length-2].setIntervalRole(Ct.intervalInterior),r.setIntervalRole(Ct.intervalEnd))}appendPlaneIntersectionPoints(t,e){if(this._points.length<1)return 0;const n=e.length,i=this._points.length,s=i===1?1:i-1,r=F._workPointA,o=F._workPointB,a=F._workPointC;this._points.getPoint3dAtUncheckedPointIndex(0,r);let c=0,l=0,d=0,h=0;for(let g=0;g<this._points.length;g++,r.setFrom(o),d=c)if(this._points.getPoint3dAtUncheckedPointIndex(g,o),c=f.correctSmallMetricDistance(t.altitude(o)),c===0)F.pushVertexHit(e,l++,this,g/s,o);else if(d*c<0){h=d/(d-c),r.interpolate(h,o,a);const m=Y.createCurveFractionPoint(this,(g-1+h)/s,a);m.setIntervalRole(Ct.isolated),e.push(m),l=0}return e.length-n}extendRange(t,e){this._points.extendRange(t,e)}isAlmostEqual(t){return!(!(t instanceof F)||!W.isAlmostEqual(this._points,t._points))}appendStrokePoint(t,e){const n=this._points.length;let i=!0;n>0&&(e!==void 0&&this._fractions&&f.isSmallRelative(e-this._fractions.back())||t.isAlmostEqual(this._points.getPoint3dAtUncheckedPointIndex(n-1)))&&(i=!1),i&&(this._points.push(t),e!==void 0&&this.addFraction(e))}removeDuplicatePoints(t=f.smallMetricDistance){const e=this._points.length;if(e<2)return;let n=1;for(let i=1;i<e;i++){const s=this._points.distanceIndexIndex(i,n-1);s!==void 0&&s>t&&(this._points.moveIndexToIndex(i,n),this._fractions!==void 0&&this._fractions.setAtUncheckedIndex(n,this._fractions.atUncheckedIndex(i)),this._derivatives&&this._derivatives.moveIndexToIndex(i,n),n++)}this._points.resize(n),this._fractions&&this._fractions.resize(n),this._derivatives&&this._derivatives.resize(n)}appendFractionToPoint(t,e){let n,i;const s=this._points.length;this._derivatives?(n=t.fractionToPointAndDerivative(e,F._workRay),i=n.origin):i=t.fractionToPoint(e,F._workPointA),!(s>0&&i.isAlmostEqual(this._points.getPoint3dAtUncheckedPointIndex(s-1)))&&(n&&this._derivatives?.push(n.direction),this._fractions&&this._fractions.push(e),this._points.push(i))}clear(){this._points.clear(),this._fractions&&this._fractions.clear(),this._derivatives&&this._derivatives.clear()}static createForStrokes(t=0,e){const n=F.create();return t>0&&n._points.ensureCapacity(t),e&&(e.needParams&&(n._fractions=new Ft(t),n._uvParams=new Ie(t)),e.needNormals&&(n._derivatives=new W(t),n._surfaceNormals=new W(t))),n}appendFractionalStrokePoints(t,e,n=0,i=1,s=!0){let r=1,o=e-1;if(s&&(r=0,o=e),e>=1){const a=(i-n)/e;for(let c=r;c<=o;c++)this.appendFractionToPoint(t,n+c*a)}}appendInterpolatedStrokePoints(t,e,n,i){if(i&&this.appendStrokePoint(e,0),t>1){const s=1/t;for(let r=1;r<t;r++){const o=r*s;this.appendStrokePoint(e.interpolate(o,n),o)}}i&&this.appendStrokePoint(n,1)}emitStrokes(t,e){const n=this._points.length,i=F._workPointA,s=F._workPointB;if(n>0)if(e&&e.hasMaxEdgeLength){t.appendStrokePoint(this._points.getPoint3dAtUncheckedPointIndex(0));for(let r=1;r<n;r++){this._points.getPoint3dAtUncheckedPointIndex(r-1,i),this._points.getPoint3dAtUncheckedPointIndex(r,s);const o=e.applyMaxEdgeLength(1,i.distance(s));o>1&&t.appendInterpolatedStrokePoints(o,i,s,!1),t.appendStrokePoint(s)}}else for(let r=0;r<n;r++)t.appendStrokePoint(this._points.getPoint3dAtUncheckedPointIndex(r))}emitStrokableParts(t,e){const n=this._points.length;if(t.startCurvePrimitive(this),n>1){const i=1/(n-1);if(e&&e.hasMaxEdgeLength)for(let s=1;s<n;s++){const r=e.applyMaxEdgeLength(1,this._points.getPoint3dAtUncheckedPointIndex(s-1).distance(this._points.getPoint3dAtUncheckedPointIndex(s)));t.announceSegmentInterval(this,this._points.getPoint3dAtUncheckedPointIndex(s-1),this._points.getPoint3dAtUncheckedPointIndex(s),r,(s-1)*i,s*i)}else for(let s=1;s<n;s++)t.announceSegmentInterval(this,this._points.getPoint3dAtUncheckedPointIndex(s-1),this._points.getPoint3dAtUncheckedPointIndex(s),1,(s-1)*i,s*i)}t.endCurvePrimitive(this)}computeStrokeCountForOptions(t){const e=this._points.length;let n=e-1;if(t&&t.hasMaxEdgeLength){n=0;for(let i=1;i<e;i++)n+=t.applyMaxEdgeLength(1,this._points.distanceUncheckedIndexIndex(i-1,i))}return n}computeAndAttachRecursiveStrokeCounts(t,e){const n=this._points.length,i=t!==void 0&&t.hasMaxEdgeLength,s=dn.createWithCurvePrimitiveAndOptionalParent(this,e,[]);for(let r=1;r<n;r++){const o=this._points.distanceUncheckedIndexIndex(r-1,r),a=i?t.applyMaxEdgeLength(1,o):1;s.addToCountAndLength(a,o)}st.installStrokeCountMap(this,s,e)}dispatchToGeometryHandler(t){return t.handleLineString3d(this)}announceClipIntervals(t,e){const n=this._points.length;if(n<2)return!1;let i=0,s=1;const r=(l,d)=>{e&&e(f.interpolate(i,l,s),f.interpolate(i,d,s),this)},o=F._workPointA,a=F._workPointB;this._points.getPoint3dAtUncheckedPointIndex(0,o);let c=!1;for(let l=1;l<n;l++,o.setFrom(a),i=s)this._points.getPoint3dAtUncheckedPointIndex(l,a),s=l/(n-1),t.announceClippedSegmentIntervals(0,1,o,a,r)&&(c=!0);return c}static _indexPoint=y.create();addResolvedPoint(t,e,n){const i=this._points.length;if(i!==0){if(i===1){this._points.getPoint3dAtUncheckedPointIndex(0,F._indexPoint),n.push(F._indexPoint);return}t<0&&(t=0),t>i-2&&(t=i-2,e+=1),this._points.interpolate(t,e,t+1,F._indexPoint),n.push(F._indexPoint)}}clonePartialCurve(t,e){if(e<t){const c=this.clonePartialCurve(e,t);return c&&c.reverseInPlace(),c}const n=this._points.length;if(n<2)return this.clone();n>2&&this.isPhysicallyClosed&&(t<0&&(t=0),e>1&&(e=1));let i,s;const r=this.globalFractionToSegmentIndexAndLocalFraction(t),o=this.globalFractionToSegmentIndexAndLocalFraction(e);t<0?i=1:0<=t&&t<=1?i=f.isSmallRelative(1-r.fraction)?r.index+2:r.index+1:i=n,e<0?s=-1:0<=e&&e<=1?s=f.isSmallRelative(o.fraction)?o.index-1:o.index:s=n-2;const a=F.create();this.addResolvedPoint(r.index,r.fraction,a._points);for(let c=i;c<=s;c++)this._points.isIndexValid(c)&&a._points.pushFromGrowableXYZArray(this._points,c);return this.addResolvedPoint(o.index,o.fraction,a._points),a}getIndexedSegment(t,e){if(t>=0&&t<this.numEdges())return this.getUncheckedIndexedSegment(t,e)}getUncheckedIndexedSegment(t,e){return U.create(this._points.getPoint3dAtUncheckedPointIndex(t),this._points.getPoint3dAtUncheckedPointIndex(t+1),e)}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){return this._points.length?e?this._points.almostEqualXYUncheckedIndexIndex(0,this._points.length-1,t):this._points.almostEqualUncheckedIndexIndex(0,this._points.length-1,t):!1}get isPhysicallyClosed(){return this.isPhysicallyClosedCurve()}addMappedStrokesToLineString3D(t,e){const n=e.numPoints(),i=this._points,s=F._workPointA,r=F._workPointB,o=F._workPointC,a=i.length;if(t.primitive&&t.primitive===this&&t.componentData&&t.componentData.length+1===a){i.getPoint3dAtUncheckedPointIndex(0,s);for(let c=0;c+1<a;c++,s.setFromPoint3d(r)){i.getPoint3dAtUncheckedPointIndex(c+1,r);const l=t.componentData[c],d=l.numStroke,h=s.vectorTo(r);h.scale(d);for(let g=0;g<=d;g++){const m=g/d,p=l.fractionToA(m);e.addPoint(s.interpolate(m,r,o)),e._fractions&&e._fractions.push(p),e._derivatives&&e._derivatives.push(h)}}}return e.numPoints()-n}static createArrayOfLineString3d(t){const e=new qo;bn.streamXYZ(t,e);const n=e.claimArrayOfGrowableXYZArray(),i=[];if(n!==void 0)for(const s of n)i.push(F.createCapture(s));return i}collectCurvePrimitivesGo(t,e,n=!1){if(n){let i;for(let s=0;(i=this.getIndexedSegment(s))!==void 0;s++)t.push(i)}else t.push(this)}constructOffsetXY(t){const e=Oe.create(t),n=[];for(const i of this.collectCurvePrimitives(void 0,!0,!0)){const s=i.constructOffsetXY(e);s!==void 0&&(s instanceof st?n.push(s):Array.isArray(s)&&s.forEach(r=>n.push(r)))}return n}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}static convertLocalToGlobalDetail(t,e,n,i,s){return t.childDetail=t.clone(s),t.childDetail.a=e,t.fraction=this.mapLocalToGlobalFraction(e,t.fraction,n),t.curve=i,t}}class mc{distance0;point0;fraction0;targetDistance;constructor(t,e,n){this.point0=t,this.distance0=0,this.targetDistance=Math.abs(n),this.fraction0=e}distanceStatus(){return f.isSameCoordinate(this.distance0,this.targetDistance)?Me.success:Me.stoppedAtBoundary}announcePoint(t,e){const n=this.point0.distance(t),i=this.distance0+n;if(i<this.targetDistance&&!f.isSameCoordinate(i,this.targetDistance))return this.point0.setFromPoint3d(t),this.distance0=i,this.fraction0=e,!1;const s=this.targetDistance-this.distance0,r=f.safeDivideFraction(s,n,0);return this.point0.interpolate(r,t,this.point0),this.fraction0=f.interpolate(this.fraction0,r,e),this.distance0=this.targetDistance,!0}announceExtrapolation(t,e,n,i,s){const r=this.targetDistance-this.distance0,o=t.distanceIndexIndex(e,n);if(!o)return!1;const a=f.conditionalDivideFraction(r,o);return a===void 0?!1:(t.interpolate(n,-a,e,this.point0),this.distance0=this.targetDistance,this.fraction0=f.interpolate(s,-a,i),!0)}}class sa{handleCurveCollection(t){}handlePath(t){return this.handleCurveCollection(t)}handleLoop(t){return this.handleCurveCollection(t)}handleParityRegion(t){return this.handleCurveCollection(t)}handleUnionRegion(t){return this.handleCurveCollection(t)}handleBagOfCurves(t){return this.handleCurveCollection(t)}handleCurveChainWithDistanceIndex(t){return this.handlePath(t.path)}}class Ys extends sa{handleLineSegment3d(t){}handleLineString3d(t){}handleArc3d(t){}handleCurveCollection(t){}handleCurveChainWithDistanceIndex(t){}handleBSplineCurve3d(t){}handleInterpolationCurve3d(t){}handleAkimaCurve3d(t){}handleBSplineCurve3dH(t){}handleBSplineSurface3d(t){}handleCoordinateXYZ(t){}handleBSplineSurface3dH(t){}handleIndexedPolyface(t){}handleTransitionSpiral(t){}handlePath(t){}handleLoop(t){}handleParityRegion(t){}handleUnionRegion(t){}handleBagOfCurves(t){}handleSphere(t){}handleCone(t){}handleBox(t){}handleTorusPipe(t){}handleLinearSweep(t){}handleRotationalSweep(t){}handleRuledSweep(t){}handlePointString3d(t){}handleBezierCurve3d(t){}handleBezierCurve3dH(t){}}class Gi extends sa{handleLineSegment3d(t){}handleLineString3d(t){}handleArc3d(t){}handleBSplineCurve3d(t){}handleInterpolationCurve3d(t){}handleAkimaCurve3d(t){}handleBSplineCurve3dH(t){}handleBSplineSurface3d(t){}handleCoordinateXYZ(t){}handleBSplineSurface3dH(t){}handleIndexedPolyface(t){}handleTransitionSpiral(t){}handleChildren(t){const e=t.children;if(e)for(const n of e)n.dispatchToGeometryHandler(this)}handleCurveCollection(t){return this.handleChildren(t)}handleSphere(t){}handleCone(t){}handleBox(t){}handleTorusPipe(t){}handleLinearSweep(t){}handleRotationalSweep(t){}handleRuledSweep(t){}handlePointString3d(t){}handleBezierCurve3d(t){}handleBezierCurve3dH(t){}}class pc{_curve;_fractions;constructor(t,e=f.smallFraction){this._curve=void 0,t&&this.startCurvePrimitive(t),this._fractions=new Fi((n,i)=>ki(n,i,e))}startParentCurvePrimitive(t){}startCurvePrimitive(t){this._curve=t}announcePointTangent(t,e,n){this._fractions.add(e)}announceIntervalForUniformStepStrokes(t,e,n,i){e<1&&(e=1),this._fractions.add(n);const s=1/e;for(let r=1;r<e;r++)this._fractions.add(f.interpolate(n,r*s,i));this._fractions.add(i)}needPrimaryGeometryForStrokes(){return!0}announceSegmentInterval(t,e,n,i,s,r){this._fractions.add(s),this._fractions.add(r)}endCurvePrimitive(t){}endParentCurvePrimitive(t){}claimFractions(t=!1){return t&&(this._fractions.delete(0),this._fractions.delete(1)),[...this._fractions]}claimLineString(t){if(!this._curve)return;t??=F.create();const e=y.create();for(const n of this._fractions)t.addPoint(this._curve.fractionToPoint(n,e)),t.addFraction(n);return t}}class Le extends Gi{plane;range;lowPoint;highPoint;constructor(t){super(),this.plane=t,this.range=ct.createNull(),this.resetRange()}resetRange(){this.range.setNull()}announcePoint(t){const e=this.plane.altitude(t);this.range.extendLow(e)&&(this.lowPoint=t.clone(this.lowPoint)),this.range.extendHigh(e)&&(this.highPoint=t.clone(this.highPoint))}announcePoints(t){for(let e=0;e<t.length;e++){const n=t.evaluateUncheckedIndexPlaneAltitude(e,this.plane);this.range.extendLow(n)&&(this.lowPoint=t.getPoint3dAtUncheckedPointIndex(e,this.lowPoint)),this.range.extendHigh(n)&&(this.highPoint=t.getPoint3dAtUncheckedPointIndex(e,this.highPoint))}}static createCapture(t){return new Le(t)}handleLineSegment3d(t){this.announcePoint(t.point0Ref),this.announcePoint(t.point1Ref)}handleLineString3d(t){this.announcePoints(t.packedPoints)}_strokeOptions;initStrokeOptions(){this._strokeOptions===void 0&&(this._strokeOptions=new Zt,this._strokeOptions.angleTol=A.createDegrees(1))}handleBSplineCurve3d(t){this.initStrokeOptions();const e=F.create();t.emitStrokes(e,this._strokeOptions),this.handleLineString3d(e)}handleBSplineCurve3dH(t){this.initStrokeOptions();const e=F.create();t.emitStrokes(e,this._strokeOptions),this.handleLineString3d(e)}_sineCosinePolynomial;_workPoint;handleArc3d(t){this._sineCosinePolynomial=t.getPlaneAltitudeSineCosinePolynomial(this.plane,this._sineCosinePolynomial);let e=this._sineCosinePolynomial.referenceMinMaxRadians();t.sweep.isRadiansInSweep(e)&&this.announcePoint(this._workPoint=t.radiansToPoint(e,this._workPoint)),e+=Math.PI,t.sweep.isRadiansInSweep(e)&&this.announcePoint(this._workPoint=t.radiansToPoint(e,this._workPoint)),this.announcePoint(this._workPoint=t.startPoint(this._workPoint)),this.announcePoint(this._workPoint=t.endPoint(this._workPoint))}static findExtremesInDirection(t,e){const n=e instanceof O?e.origin:y.createZero(),i=e instanceof O?e.direction:e,s=ht.create(n,i);if(s){const r=new Le(s);if(t instanceof Ae)t.dispatchToGeometryHandler(r);else if(t instanceof W)r.announcePoints(t);else for(const o of t)r.announcePoint(o);return r}}static findExtremePointsInDirection(t,e,n){const i=this.findExtremesInDirection(t,e);if(i&&i.highPoint&&i.lowPoint)return U.create(i.lowPoint,i.highPoint,n)}static findExtremeAltitudesInDirection(t,e,n){const i=this.findExtremesInDirection(t,e);if(i&&!i.range.isNull)return ct.createFrom(i.range,n)}static findExtremeFractionsAlongDirection(t,e,n){const i=this.findExtremeAltitudesInDirection(t,e,n);if(i!==void 0){const s=e instanceof P?e.magnitude():e.direction.magnitude(),r=f.conditionalDivideCoordinate(1,s);if(r!==void 0)return i.low*=r,i.high*=r,i}}}class qt{x0;x1;constructor(t,e){this.x0=t,this.x1=e}set(t,e){this.x0=t,this.x1=e}shift(t){this.x0+=t,this.x1+=t}static create(t=0,e=1,n){return n?(n.set(t,e),n):new qt(t,e)}setFrom(t){this.x0=t.x0,this.x1=t.x1}clone(){return new qt(this.x0,this.x1)}get isIn01(){return f.isIn01(this.x0)&&f.isIn01(this.x1)}fractionToPoint(t){return f.interpolate(this.x0,t,this.x1)}signedDelta(){return this.x1-this.x0}absoluteDelta(){return Math.abs(this.x1-this.x0)}reverseInPlace(){const t=this.x0;this.x0=this.x1,this.x1=t}reverseIfNeededForDeltaSign(t=1){t*(this.x1-this.x0)<0&&this.reverseInPlace()}isAlmostEqual(t){return f.isSameCoordinate(this.x0,t.x0)&&f.isSameCoordinate(this.x1,t.x1)}get isExact01(){return this.x0===0&&this.x1===1}get isExact01Reversed(){return this.x0===1&&this.x1===0}clipBy01FunctionValuesPositive(t,e){const n=e-t,i=t+this.x0*n,s=t+this.x1*n,r=s-i;if(i>0){if(s>=0)return!0;const o=-i/r;return this.x1=this.x0+o*(this.x1-this.x0),!0}else if(i<0){if(s<0)return!1;const o=-i/r;return this.x0=this.x0+o*(this.x1-this.x0),!0}return s>0}clampDirectedTo01(t=!0,e=!0,n=!1){let i=this.x0,s=this.x1;if(s>i){if(i<0&&t&&(i=0),s>1&&e&&(s=1),i>s||i===s&&!n)return!1}else if(i>1&&e&&(i=1),s<0&&t&&(s=0),i<s||i===s&&!n)return!1;return this.set(i,s),!0}}var Ce;(function(u){u[u.None=0]="None",u[u.OpenByAddingControlPoints=1]="OpenByAddingControlPoints",u[u.OpenByRemovingKnots=2]="OpenByRemovingKnots"})(Ce||(Ce={}));class Jt{knots;degree;_knot0;_knot1;_wrapMode;static knotTolerance=1e-9;get leftKnot(){return this._knot0}get rightKnot(){return this._knot1}get leftKnotIndex(){return this.degree-1}get rightKnotIndex(){return this.knots.length-this.degree}get wrappable(){return this._wrapMode===void 0?Ce.None:this._wrapMode}set wrappable(t){this._wrapMode=t}get numSpans(){return this.rightKnotIndex-this.leftKnotIndex}constructor(t,e,n){if(this.degree=e,this._wrapMode=n,this._knot0=0,this._knot1=1,Array.isArray(t))this.knots=new Float64Array(t.length),this.setKnots(t),this.setupFixedValues();else if(t instanceof Float64Array)this.knots=t.slice(),this.setupFixedValues();else{const i=t;this.knots=new Float64Array(i)}}clone(){return new Jt(this.knots,this.degree,this.wrappable)}setupFixedValues(){this.degree>0&&this.knots.length>this.degree&&(this._knot0=this.knots[this.degree-1],this._knot1=this.knots[this.knots.length-this.degree])}get knotLength01(){return this._knot1-this._knot0}testClosable(t){t===void 0&&(t=this.wrappable);const e=this.degree,n=this.leftKnotIndex,i=this.rightKnotIndex;if(t===Ce.OpenByAddingControlPoints){const s=this.rightKnot-this.leftKnot,r=i-n;for(let o=0;o<n+e;o++){const a=o+r;if(Math.abs(this.knots[o]+s-this.knots[a])>=Jt.knotTolerance)return!1}return!0}if(t===Ce.OpenByRemovingKnots){const s=e-1,r=this.leftKnot,o=this.rightKnot;for(let a=0;a<s;a++)if(Math.abs(r-this.knots[n-a-1])>=Jt.knotTolerance||Math.abs(o-this.knots[i+a+1])>=Jt.knotTolerance)return!1;return!0}return!1}isAlmostEqual(t){return this.degree!==t.degree?!1:Pe.isAlmostEqual(this.knots,t.knots,Jt.knotTolerance)}getKnotMultiplicity(t){let e=0;for(const n of this.knots)if(Math.abs(n-t)<Jt.knotTolerance)++e;else if(t<n)break;return e}getKnotMultiplicityAtIndex(t){let e=0;if(t>=0&&t<this.knots.length){const n=this.knots[t];++e;for(let i=t-1;i>=0;--i){const s=this.knots[i];if(Math.abs(s-n)<Jt.knotTolerance)++e;else if(n>s)break}for(let i=t+1;i<this.knots.length;++i){const s=this.knots[i];if(Math.abs(s-n)<Jt.knotTolerance)++e;else if(n<s)break}}return e}normalize(){if(this.knotLength01<Jt.knotTolerance)return!1;const t=1/this.knotLength01,e=this.leftKnot;for(let n=0;n<this.knots.length;++n)this.knots[n]=(this.knots[n]-e)*t;for(let n=this.rightKnotIndex-1;n>this.leftKnotIndex&&this.knots[n]===this.knots[this.rightKnotIndex];--n)this.knots[n]=1;for(let n=this.rightKnotIndex+1;n<this.knots.length&&this.knots[n]===this.knots[this.rightKnotIndex];++n)this.knots[n]=1;return this.knots[this.rightKnotIndex]=1,this.setupFixedValues(),!0}setKnots(t,e){const n=e?t.length-2:t.length;if(n!==this.knots.length&&(this.knots=new Float64Array(n)),e)for(let i=1;i+1<t.length;i++)this.knots[i-1]=t[i];else for(let i=0;i<t.length;i++)this.knots[i]=t[i];this.setupFixedValues()}setKnotsCapture(t){this.knots=t,this.setupFixedValues()}static createUniformClamped(t,e,n,i){const s=new Jt(t+e-1,e);let r=0;for(let a=0;a<e;a++)s.knots[r++]=n;const o=1/(t-e);for(let a=1;a+e<t;a++)s.knots[r++]=n+a*o*(i-n);for(let a=0;a<e;a++)s.knots[r++]=i;return s.setupFixedValues(),s}static createUniformWrapped(t,e,n,i){const s=new Jt(t+2*e-1,e),r=1/t;for(let o=1-e,a=0;o<t+e;o++,a++)s.knots[a]=f.interpolate(n,o*r,i);return s.setupFixedValues(),s}static create(t,e,n){const i=n?t.length-2:t.length,s=new Jt(i,e);return s.setKnots(t,n),s}grevilleKnot(t){if(t<0)return this.leftKnot;if(t>this.rightKnotIndex)return this.rightKnot;t=Math.floor(t);let e=0;for(let n=t;n<t+this.degree;n++)e+=this.knots[n];return e/this.degree}createBasisArray(){return new Float64Array(this.degree+1)}baseKnotFractionToKnot(t,e){const n=this.knots[t];return e=f.clamp(e,0,1),n+e*(this.knots[t+1]-n)}spanFractionToKnot(t,e){const n=this.spanIndexToLeftKnotIndex(t);return e=f.clamp(e,0,1),this.knots[n]+e*(this.knots[n+1]-this.knots[n])}spanFractionToFraction(t,e){return(this.spanFractionToKnot(t,e)-this.leftKnot)/(this.rightKnot-this.leftKnot)}fractionToKnot(t){return t=f.clamp(t,0,1),f.interpolate(this.knots[this.degree-1],t,this.knots[this.knots.length-this.degree])}isKnotInValidSpan(t,e){const n=t>=this.degree-1&&t+this.degree<this.knots.length,i=this.knots[t]<=e&&e<=this.knots[t+1];return n&&i}evaluateBasisFunctions(t,e,n){if(n.length<this.degree+1)return!1;if(n[0]=1,this.degree<1)return!0;const i=this.knots[t],s=this.knots[t+1];if(n[1]=(e-i)/(s-i),n[0]=1-n[1],this.degree<2)return!0;for(let r=1;r<this.degree;r++){let o=t-r,a=t+1,c=0;for(let l=0;l<=r;l++){const d=this.knots[o++],h=this.knots[a++],g=(e-d)/(h-d),m=n[l]*g,p=n[l]*(1-g);n[l]=c+p,c=m}n[r+1]=c}return!0}evaluateBasisFunctions1(t,e,n,i,s){if(n.length<this.degree+1||i.length<this.degree+1||s&&s.length<this.degree+1)return!1;if(n[0]=1,i[0]=0,this.degree<1)return!0;const r=this.knots[t];let a=1/(this.knots[t+1]-r);if(n[1]=(e-r)*a,n[0]=1-n[1],i[0]=-a,i[1]=a,s&&(s[0]=0,s[1]=0),this.degree<2)return!0;for(let c=1;c<this.degree;c++){let l=t-c,d=l+c+1,h=0,g=0,m=0;for(let p=0;p<=c;p++){const x=this.knots[l++];a=1/(this.knots[d++]-x);const I=(e-x)*a,v=1-I,S=n[p]*I,w=n[p]*v,T=i[p]*I+n[p]*a,R=i[p]*v-n[p]*a,L=2*i[p]*a;if(n[p]=h+w,i[p]=g+R,h=S,g=T,s){const z=s[p]*I+L,K=s[p]*v-L;s[p]=m+K,m=z}}n[c+1]=h,i[c+1]=g,s&&(s[c+1]=m)}return!0}knotToLeftKnotIndex(t){for(let e=this.leftKnotIndex;e<this.rightKnotIndex;++e)if(t<this.knots[e+1])return e;for(let e=this.rightKnotIndex;e>this.leftKnotIndex;--e)if(this.knots[e]-this.knots[e-1]>=Jt.knotTolerance)return e-1;return this.rightKnotIndex-1}spanIndexToLeftKnotIndex(t){const e=this.degree;return t<=0?e-1:Math.min(t+e-1,this.knots.length-e-1)}spanIndexToSpanLength(t){const e=this.spanIndexToLeftKnotIndex(t);return this.knots[e+1]-this.knots[e]}isIndexOfRealSpan(t){return t>=0&&t<this.numSpans?!f.isSmallMetricDistance(this.spanIndexToSpanLength(t)):!1}reflectKnots(){const t=this.leftKnot,e=this.rightKnot,n=this.knots.length;for(let i=0;i<n;i++)this.knots[i]=t+(e-this.knots[i]);this.knots.reverse()}static copyKnots(t,e,n,i){const s=n&&i===Ce.OpenByAddingControlPoints,r=e-1,o=t.length-e,a=t[r],l=t[o]-a,d=[];n&&(s?d.push(t[o-e]-l):d.push(t[0]));for(const h of t)d.push(h);return n&&(s?d.push(t[r+e]+l):d.push(t[t.length-1])),d}copyKnots(t){const e=t&&this.testClosable()?this.wrappable:void 0;return Jt.copyKnots(this.knots,this.degree,t,e)}}class gi{_packedData;_order;_blockSize;_basis;constructor(t,e){this._blockSize=t,this._order=Math.floor(e.length/t),this._packedData=e,this._basis=new jt(this._order)}clonePolygon(t){const e=this._packedData.length;if(!t||t.length!==e)return this._packedData.slice();for(let n=0;n<e;n++)t[n]=this._packedData[n];return t}get order(){return this._order}get packedData(){return this._packedData}static create(t){if(!(t.length<1)){if(t[0]instanceof y){const e=new Float64Array(t.length*3);let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=i.z;return new gi(3,e)}else if(t[0]instanceof Z){const e=new Float64Array(t.length*4);let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=i.z,e[n++]=i.w;return new gi(4,e)}else if(t[0]instanceof D){const e=new Float64Array(t.length*2);let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y;return new gi(2,e)}}}evaluate(t,e){return this._basis.sumBasisFunctions(t,this._packedData,this._blockSize,e)}evaluateDerivative(t,e){return this._basis.sumBasisFunctionDerivatives(t,this._packedData,this._blockSize,e)}getPolygonPoint(t,e){if((!e||e.length<this._blockSize)&&(e=new Float64Array(this._blockSize)),t>=0&&t<this._order){const n=this._blockSize*t;for(let i=0;i<this._blockSize;i++)e[i]=this._packedData[n+i];return e}}setPolygonPoint(t,e){if(t>=0&&t<this._order){const n=this._blockSize*t;for(let i=0;i<this._blockSize;i++)this._packedData[n+i]=e[i]}}loadSpanPoles(t,e){let n=e*this._blockSize;for(let i=0;i<this._packedData.length;i++)this._packedData[i]=t[n++]}loadSpanPolesWithWeight(t,e,n,i){let s=0;const r=this._order;let o=n*e;for(let a=0;a<r;a++){for(let c=0;c<e;c++)this._packedData[s++]=t[o++];this._packedData[s++]=i}}unpackToJsonArrays(){return re.unpackNumbersToNestedArrays(this._packedData,this._blockSize)}isAlmostEqual(t){if(t instanceof gi){if(this._blockSize!==t._blockSize||this._order!==t._order||this._packedData.length!==t._packedData.length)return!1;for(let e=0;e<this._packedData.length;e++)if(!f.isSameCoordinate(this._packedData[e],t._packedData[e]))return!1;return!0}return!1}reverseInPlace(){const t=this._blockSize,e=this._order;let n,i,s;for(n=0,i=(e-1)*t;n<i;n+=t,i-=t)for(let r=0;r<t;r++)s=this._packedData[n+r],this._packedData[n+r]=this._packedData[i+r],this._packedData[i+r]=s}interpolatePoleInPlace(t,e,n){let i=t*this._blockSize,s=n*this._blockSize;const r=this._packedData;for(let o=0;o<this._blockSize;o++,i++,s++)r[i]+=e*(r[s]-r[i])}saturateInPlace(t,e){const n=t.degree,i=e+n-1,s=i+1;if(e<0||e>=t.numSpans)return!1;const r=t.knots,o=r[i],a=r[s];if(this.setInterval(o,a),a<=o+Jt.knotTolerance)return!1;for(let c=n-1;c>0;c--){let l=i-c;if(r[l]<o){let d=s;for(let h=0;h<c;h++,l++,d++){const g=r[l],m=r[d],p=(o-g)/(m-g);this.interpolatePoleInPlace(h,p,h+1)}}}for(let c=n-1;c>0;c--){let l=s+c;if(r[l]>a)for(let d=0;d<c;d++,l--){const h=r[l],g=(a-h)/(o-h);this.interpolatePoleInPlace(n-d,g,n-d-1)}}return!0}static saturate1dInPlace(t,e,n){const i=e.degree,s=n+i-1,r=s+1;if(n<0||n>=e.numSpans)return!1;const o=e.knots,a=o[s],c=o[r];if(c<=a+Jt.knotTolerance)return!1;for(let l=i-1;l>0;l--){let d=s-l;if(o[d]<a){let h=r;for(let g=0;g<l;g++,d++,h++){const m=o[d],p=o[h],x=(a-m)/(p-m);t[g]=t[g]+x*(t[g+1]-t[g])}}}for(let l=i-1;l>0;l--){let d=r+l,h;if(o[d]>c)for(let g=0;g<l;g++,d--){const m=o[d],p=(c-m)/(a-m);h=i-g,t[h]+=p*(t[h-1]-t[h])}}return!0}subdivideInPlaceKeepLeft(t){if(f.isAlmostEqualNumber(t,1))return!0;if(f.isAlmostEqualNumber(t,0))return!1;const e=1-t,n=this.order;for(let i=1;i<n;i++)for(let s=n-1;s>=i;s--)this.interpolatePoleInPlace(s,e,s-1);return!0}subdivideInPlaceKeepRight(t){if(f.isAlmostEqualNumber(t,0))return!0;if(f.isAlmostEqualNumber(t,1))return!1;const e=this.order;for(let n=1;n<e;n++)for(let i=0;i+n<e;i++)this.interpolatePoleInPlace(i,t,i+1);return!0}subdivideToIntervalInPlace(t,e){return f.isAlmostEqualNumber(t,e)?!1:e<t?(this.subdivideToIntervalInPlace(e,t),this.reverseInPlace(),!0):(this.subdivideInPlaceKeepLeft(e),this.subdivideInPlaceKeepRight(t/e),!0)}interval;setInterval(t,e){this.interval=qt.create(t,e,this.interval)}fractionToParentFraction(t){return this.interval?this.interval.fractionToPoint(t):t}}class ra extends st{curvePrimitiveType="bezierCurve";_polygon;_workData0;_workData1;_workPoint0;_workPoint1;constructor(t,e){super(),this._polygon=new gi(t,e),this._workPoint0=y.create(),this._workPoint1=y.create(),this._workData0=new Float64Array(t),this._workData1=new Float64Array(t)}reverseInPlace(){this._polygon.reverseInPlace()}saturateInPlace(t,e){const n=this._polygon.saturateInPlace(t,e);return n&&this.setInterval(t.spanFractionToFraction(e,0),t.spanFractionToFraction(e,1)),n}get degree(){return this._polygon.order-1}get order(){return this._polygon.order}get numPoles(){return this._polygon.order}setInterval(t,e){this._polygon.setInterval(t,e)}fractionToParentFraction(t){return this._polygon.fractionToParentFraction(t)}emitStrokes(t,e){const n=this.computeStrokeCountForOptions(e),i=1/n;for(let s=0;s<=n;s++){const r=s*i;this.fractionToPoint(r,this._workPoint0),t.appendStrokePoint(this._workPoint0)}}emitStrokableParts(t,e){const n=this.computeStrokeCountForOptions(e);t.announceIntervalForUniformStepStrokes(this,n,0,1)}copyPolesAsJsonArray(){return this._polygon.unpackToJsonArrays()}isInPlane(t){let e=this._workPoint0;for(let n=0;;n++){if(e=this.getPolePoint3d(n,e),!e)return!0;if(!t.isPointInPlane(e))break}return!1}polygonLength(){if(!this.getPolePoint3d(0,this._workPoint0))return 0;let t=0,e=0;for(;this.getPolePoint3d(++t,this._workPoint1);)e+=this._workPoint0.distance(this._workPoint1),this._workPoint0.setFrom(this._workPoint1);return e}startPoint(t){return this.getPolePoint3d(0,t)??y.createZero()}endPoint(t){return this.getPolePoint3d(this.order-1,t)??y.createZero()}quickLength(){return this.polygonLength()}_workBezier;_workCoffsA;_workCoffsB;allocateAndZeroBezierWorkData(t,e,n){t>0&&(this._workBezier!==void 0&&this._workBezier.order===t?this._workBezier.zero():this._workBezier=new jt(t)),e>0&&(this._workCoffsA!==void 0&&this._workCoffsA.length===e?this._workCoffsA.fill(0):this._workCoffsA=new Float64Array(e)),n>0&&(this._workCoffsB!==void 0&&this._workCoffsB.length===n?this._workCoffsB.fill(0):this._workCoffsB=new Float64Array(n))}computeStrokeCountForOptions(t){this.getPolePoint3d(0,this._workPoint0),this.getPolePoint3d(1,this._workPoint1);let e=1;if(this._workPoint0&&this._workPoint1){let n=this._workPoint1.x-this._workPoint0.x,i=this._workPoint1.y-this._workPoint0.y,s=this._workPoint1.z-this._workPoint0.z,r,o,a,c=0,l=f.hypotenuseXYZ(n,i,s);this._workPoint1.setFromPoint3d(this._workPoint0);let d=l,h=l,g=0,m;for(let S=2;this.getPolePoint3d(S,this._workPoint1);S++)r=this._workPoint1.x-this._workPoint0.x,o=this._workPoint1.y-this._workPoint0.y,a=this._workPoint1.z-this._workPoint0.z,m=A.radiansBetweenVectorsXYZ(n,i,s,r,o,a),c+=m,g=f.maxAbsXY(m,g),l=f.hypotenuseXYZ(r,o,a),d+=l,h=f.maxXY(h,l),n=r,i=o,s=a,this._workPoint0.setFrom(this._workPoint1);const p=h*this.degree,x=Math.sqrt(p*d);let _=g*(this.degree-1);this.degree<3&&(_*=3);const I=Math.sqrt(_*c),v=this.degree;e=Zt.applyAngleTol(t,Zt.applyMaxEdgeLength(t,v,x),I,.1),t&&(e=t.applyChordTolToLengthAndRadians(e,d,_))}return e}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}constructOffsetXY(t){const e=Oe.create(t),n=new Vs(this,e.leftOffsetDistance);return this.emitStrokableParts(n,e.strokeOptions),n.claimResult()}clonePartialCurve(t,e){const n=this.clone();return n._polygon.subdivideToIntervalInPlace(t,e),n}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}}class Pn extends ra{isSameGeometryClass(t){return t instanceof Pn}tryTransformInPlace(t){const e=this._workData0;for(let n=0;n<this._polygon.order;n++)this._polygon.getPolygonPoint(n,e),t.multiplyXYZToFloat64Array(e[0],e[1],e[2],e),this._polygon.setPolygonPoint(n,e);return!0}_workRay0;_workRay1;getPolePoint3d(t,e){const n=this._polygon.getPolygonPoint(t,this._workData0);if(n)return y.create(n[0],n[1],n[2],e)}getPolePoint4d(t,e){const n=this._polygon.getPolygonPoint(t,this._workData0);if(n)return Z.create(n[0],n[1],n[2],1,e)}constructor(t){super(3,t),this._workRay0=O.createXAxis(),this._workRay1=O.createXAxis()}copyPointsAsLineString(){const t=F.create(),e=y.createZero();for(let n=0;n<this._polygon.order;n++)this.getPolePoint3d(n,e),t.addPoint(e);return t}static create(t){if(t.length<1)return;const e=new Float64Array(t.length*3);if(t[0]instanceof y){let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=i.z;return new Pn(e)}else if(t[0]instanceof D){let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=0;return new Pn(e)}}static createOrder(t){const e=new Float64Array(t*3);return new Pn(e)}loadSpanPoles(t,e){this._polygon.loadSpanPoles(t,e)}clone(){return new Pn(this._polygon.clonePolygon())}fractionToPoint(t,e){return this._polygon.evaluate(t,this._workData0),y.create(this._workData0[0],this._workData0[1],this._workData0[2],e)}fractionToPointAndDerivative(t,e){return this._polygon.evaluate(t,this._workData0),this._polygon.evaluateDerivative(t,this._workData1),O.createXYZUVW(this._workData0[0],this._workData0[1],this._workData0[2],this._workData1[0],this._workData1[1],this._workData1[2],e)}fractionToPointAnd2Derivatives(t,e){e||(e=At.createXYPlane());const s=this.fractionToPointAndDerivative(t,this._workRay0);e.origin.setFrom(s.origin),e.vectorU.setFrom(s.direction);const r=this.fractionToPointAndDerivative(t-1e-8,this._workRay0),o=this.fractionToPointAndDerivative(t+1e-8,this._workRay1);return P.createAdd2Scaled(r.direction,-5e7,o.direction,5e7,e.vectorV),e}isAlmostEqual(t){return t instanceof Pn?this._polygon.isAlmostEqual(t._polygon):!1}dispatchToGeometryHandler(t){return t.handleBezierCurve3d(this)}extendRange(t,e){const n=this.order;if(n<2)return;const i=n-1;if(e){this.allocateAndZeroBezierWorkData(i,n,0);const s=this._workBezier,r=this._workCoffsA;this.getPolePoint3d(0,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0);const o=this._polygon.packedData;for(let a=0;a<3;a++){for(let l=0,d=0;l<n;l++,d+=3)r[l]=e.multiplyComponentXYZ(a,o[d],o[d+1],o[d+2]);Ve.univariateDifference(r,s.coffs);const c=s.roots(0,!0);if(c&&c.length>0)for(const l of c)this.fractionToPoint(l,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0)}}else{this.allocateAndZeroBezierWorkData(i,0,0);const s=this._workBezier;this.getPolePoint3d(0,this._workPoint0),t.extend(this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),t.extend(this._workPoint0);for(let r=0;r<3;r++){Ve.componentDifference(s.coffs,this._polygon.packedData,3,n,r);const o=s.roots(0,!0);if(o)for(const a of o)this.fractionToPoint(a,this._workPoint0),t.extend(this._workPoint0)}}}}class In extends ra{isSameGeometryClass(t){return t instanceof In}tryTransformInPlace(t){const e=this._workData0;for(let n=0;n<this._polygon.order;n++)this._polygon.getPolygonPoint(n,e),t.multiplyXYZWToFloat64Array(e[0],e[1],e[2],e[3],e),this._polygon.setPolygonPoint(n,e);return!0}tryMultiplyMatrix4dInPlace(t){t.multiplyBlockedFloat64ArrayInPlace(this._polygon.packedData)}_workRay0;_workRay1;getPolePoint4d(t,e){const n=this._polygon.getPolygonPoint(t,this._workData0);if(n)return Z.create(n[0],n[1],n[2],n[3],e)}getPolePoint3d(t,e){const n=this._polygon.getPolygonPoint(t,this._workData0);if(n)return y.createFromPackedXYZW(n,0,e)}isUnitWeight(t){t===void 0&&(t=f.smallAngleRadians);const e=1-t,n=1+t,i=this._polygon.packedData,s=i.length;let r;for(let o=3;o<s;o+=4)if(r=i[o],r<e||r>n)return!1;return!0}constructor(t){super(4,t),this._workRay0=O.createXAxis(),this._workRay1=O.createXAxis()}static create(t){if(t.length<1)return;const e=new Float64Array(t.length*4);if(t[0]instanceof y){let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=i.z,e[n++]=1;return new In(e)}else if(t[0]instanceof Z){let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=i.z,e[n++]=i.w;return new In(e)}else if(t[0]instanceof D){let n=0;for(const i of t)e[n++]=i.x,e[n++]=i.y,e[n++]=0,e[n++]=1;return new In(e)}}static createOrder(t){const e=new Float64Array(t*4);return new In(e)}loadSpan3dPolesWithWeight(t,e,n){this._polygon.loadSpanPolesWithWeight(t,3,e,n)}loadSpan4dPoles(t,e){this._polygon.loadSpanPoles(t,e)}clone(){return new In(this._polygon.clonePolygon())}fractionToPoint(t,e){return this._polygon.evaluate(t,this._workData0),e=y.createFromPackedXYZW(this._workData0,0,e),e||y.createZero()}fractionToPoint4d(t,e){return this._polygon.evaluate(t,this._workData0),e=Z.createFromPacked(this._workData0,0,e),e||Z.createZero()}fractionToPointAndDerivative(t,e){return this._polygon.evaluate(t,this._workData0),this._polygon.evaluateDerivative(t,this._workData1),e=O.createWeightedDerivative(this._workData0,this._workData1,e),e||O.createXAxis()}fractionToPointAnd2Derivatives(t,e){e||(e=At.createXYPlane());const s=this.fractionToPointAndDerivative(t,this._workRay0);e.origin.setFrom(s.origin),e.vectorU.setFrom(s.direction);const r=this.fractionToPointAndDerivative(t-1e-8,this._workRay0),o=this.fractionToPointAndDerivative(t+1e-8,this._workRay1);return P.createAdd2Scaled(r.direction,-5e7,o.direction,5e7,e.vectorV),e}isAlmostEqual(t){return t instanceof In?this._polygon.isAlmostEqual(t._polygon):!1}dispatchToGeometryHandler(t){return t.handleBezierCurve3dH(this)}poleProductsXYZW(t,e,n,i,s){const r=this.numPoles,o=this._polygon.packedData;for(let a=0,c=0;a<r;a++,c+=4)t[a]=e*o[c]+n*o[c+1]+i*o[c+2]+s*o[c+3]}updateClosestPointByTruePerpendicular(t,e,n=!1,i=!1){let s=0,r;if(this.order<2)return!1;if(this.isUnitWeight()){const o=2*this.order-2;this.allocateAndZeroBezierWorkData(o,0,0);const a=this._workBezier;Ve.accumulateScaledShiftedComponentTimesComponentDelta(a.coffs,this._polygon.packedData,4,this.order,1,0,-t.x,0),Ve.accumulateScaledShiftedComponentTimesComponentDelta(a.coffs,this._polygon.packedData,4,this.order,1,1,-t.y,1),Ve.accumulateScaledShiftedComponentTimesComponentDelta(a.coffs,this._polygon.packedData,4,this.order,1,2,-t.z,2),r=a.roots(0,!0)}else{const o=this.order,a=2*this.order-2,c=o+a-1;this.allocateAndZeroBezierWorkData(c,o,a);const l=this._workBezier,d=this._workCoffsA,h=this._workCoffsB,g=this._polygon.packedData;for(let m=0;m<3;m++){for(let p=0;p<d.length;p++)d[p]=0;for(let p=0;p<h.length;p++)h[p]=0;Ve.scaledComponentSum(d,g,4,o,3,t.at(m),m,-1),Ve.accumulateScaledShiftedComponentTimesComponentDelta(h,g,4,o,1,3,0,m),Ve.accumulateScaledShiftedComponentTimesComponentDelta(h,g,4,o,-1,m,0,3),Ve.accumulateProduct(l.coffs,d,h)}r=l.roots(0,!0)}if(r)for(const o of r){const a=this.fractionToPoint(o),c=a.distance(t);s+=e.updateIfCloserCurveFractionPointDistance(this,o,a,c)?1:0}return n&&(s+=this.updateDetailAtFraction(e,0,t)?1:0),i&&(s+=this.updateDetailAtFraction(e,1,t)?1:0),s>0}updateDetailAtFraction(t,e,n){const i=this.fractionToPoint(e),s=i.distance(n);return t.updateIfCloserCurveFractionPointDistance(this,e,i,s)}extendRange(t,e){const n=this.order;if(n<2)return;const i=n*2-2;if(e){this.allocateAndZeroBezierWorkData(i,n,n);const s=this._workBezier,r=this._workCoffsA,o=this._workCoffsB;this.getPolePoint3d(0,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0);const a=this._polygon.packedData;let c;for(let l=0;l<3;l++){s.zero();for(let h=0,g=0;h<n;h++,g+=4)c=a[g+3],r[h]=e.multiplyComponentXYZW(l,a[g],a[g+1],a[g+2],c),o[h]=c;Ve.accumulateProductWithDifferences(s.coffs,r,o,1),Ve.accumulateProductWithDifferences(s.coffs,o,r,-1);const d=s.roots(0,!0);if(d&&d.length>0)for(const h of d)this.fractionToPoint(h,this._workPoint0),t.extendTransformedPoint(e,this._workPoint0)}}else{this.allocateAndZeroBezierWorkData(i,0,0);const s=this._workBezier,r=this._polygon.packedData;this.getPolePoint3d(0,this._workPoint0),t.extend(this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),t.extend(this._workPoint0);for(let o=0;o<3;o++){s.zero(),Ve.accumulateScaledShiftedComponentTimesComponentDelta(s.coffs,r,4,n,1,o,0,3),Ve.accumulateScaledShiftedComponentTimesComponentDelta(s.coffs,r,4,n,-1,3,0,o);const a=s.roots(0,!0);if(a)for(const c of a)this.fractionToPoint(c,this._workPoint0),t.extend(this._workPoint0)}}}}class Yr{knots;packedData;poleLength;get degree(){return this.knots.degree}get order(){return this.knots.degree+1}get numSpan(){return this.numPoles-this.knots.degree}get numPoles(){return this.packedData.length/this.poleLength}getPoint3dPole(t,e){return y.createFromPacked(this.packedData,t,e)}basisBuffer;basisBuffer1;basisBuffer2;poleBuffer;poleBuffer1;poleBuffer2;constructor(t,e,n,i){this.knots=i,this.packedData=new Float64Array(t*e),this.poleLength=e,this.basisBuffer=new Float64Array(n),this.basisBuffer1=new Float64Array(n),this.basisBuffer2=new Float64Array(n),this.poleBuffer=new Float64Array(e),this.poleBuffer1=new Float64Array(e),this.poleBuffer2=new Float64Array(e)}static create(t,e,n,i){return new Yr(t,e,n,i)}spanFractionToKnot(t,e){return this.knots.spanFractionToKnot(t,e)}evaluateBasisFunctionsInSpan(t,e,n,i,s){t<0&&(t=0),t>=this.numSpan&&(t=this.numSpan-1);const r=t+this.degree-1,o=this.knots.baseKnotFractionToKnot(r,e);return i?this.knots.evaluateBasisFunctions1(r,o,n,i,s):this.knots.evaluateBasisFunctions(r,o,n)}sumPoleBufferForSpan(t){this.poleBuffer.fill(0);let e=t*this.poleLength;for(const n of this.basisBuffer)for(let i=0;i<this.poleLength;i++)this.poleBuffer[i]+=n*this.packedData[e++]}sumPoleBuffer1ForSpan(t){this.poleBuffer1.fill(0);let e=t*this.poleLength;for(const n of this.basisBuffer1)for(let i=0;i<this.poleLength;i++)this.poleBuffer1[i]+=n*this.packedData[e++]}sumPoleBuffer2ForSpan(t){this.poleBuffer2.fill(0);let e=t*this.poleLength;for(const n of this.basisBuffer2)for(let i=0;i<this.poleLength;i++)this.poleBuffer2[i]+=n*this.packedData[e++]}evaluateBuffersInSpan(t,e){this.evaluateBasisFunctionsInSpan(t,e,this.basisBuffer),this.sumPoleBufferForSpan(t)}evaluateBuffersInSpan1(t,e){this.evaluateBasisFunctionsInSpan(t,e,this.basisBuffer,this.basisBuffer1),this.sumPoleBufferForSpan(t),this.sumPoleBuffer1ForSpan(t)}evaluateBuffersAtKnot(t,e=0){const n=this.knots.knotToLeftKnotIndex(t);e<1?(this.knots.evaluateBasisFunctions(n,t,this.basisBuffer),this.sumPoleBufferForSpan(n-this.degree+1)):e===1?(this.knots.evaluateBasisFunctions1(n,t,this.basisBuffer,this.basisBuffer1),this.sumPoleBufferForSpan(n-this.degree+1),this.sumPoleBuffer1ForSpan(n-this.degree+1)):(this.knots.evaluateBasisFunctions1(n,t,this.basisBuffer,this.basisBuffer1,this.basisBuffer2),this.sumPoleBufferForSpan(n-this.degree+1),this.sumPoleBuffer1ForSpan(n-this.degree+1),this.sumPoleBuffer2ForSpan(n-this.degree+1))}reverseInPlace(){const t=this.poleLength,e=this.packedData;for(let n=0,i=t*(this.numPoles-1);n<i;n+=t,i-=t)for(let s=0;s<t;s++)[e[n+s],e[i+s]]=[e[i+s],e[n+s]];this.knots.reflectKnots()}testCloseablePolygon(t){return this.testClosablePolygon(t)}testClosablePolygon(t){t===void 0&&(t=this.knots.wrappable);let e=0;if(t===Ce.OpenByAddingControlPoints)e=this.degree;else if(t===Ce.OpenByRemovingKnots)e=1;else return!1;const n=this.poleLength,i=(this.numPoles-e)*n,s=e*n;for(let r=0;r<s;r++)if(!f.isSameCoordinate(this.packedData[r],this.packedData[r+i]))return!1;return!0}addKnot(t,e){if(t<this.knots.leftKnot||t>this.knots.rightKnot)return!1;let n=this.knots.knotToLeftKnotIndex(t);if(Math.abs(t-this.knots.knots[n])<Jt.knotTolerance)t=this.knots.knots[n];else if(Math.abs(t-this.knots.knots[n+1])<Jt.knotTolerance){if(n+=this.knots.getKnotMultiplicityAtIndex(n+1),n>this.knots.rightKnotIndex)return!0;t=this.knots.knots[n]}const i=Math.min(e,this.degree)-this.knots.getKnotMultiplicity(t);if(i<=0)return!0;let s=this.knots.knots.length;const r=new Float64Array(s+i);for(let l=0;l<s;++l)r[l]=this.knots.knots[l];let o=this.numPoles;const a=new Float64Array(this.packedData.length+i*this.poleLength);for(let l=0;l<this.packedData.length;++l)a[l]=this.packedData[l];const c=new Float64Array(this.degree*this.poleLength);for(let l=0;l<i;++l){let d=0;const h=n-this.degree+2;for(let m=h;m<h+this.degree;++m){const p=(t-r[m-1])/(r[m+this.degree-1]-r[m-1]);for(let x=m*this.poleLength;x<(m+1)*this.poleLength;++x)c[d++]=f.interpolate(a[x-this.poleLength],p,a[x])}a.copyWithin((h+this.degree)*this.poleLength,(h+this.degree-1)*this.poleLength,o*this.poleLength);let g=h*this.poleLength;for(const m of c)a[g++]=m;r.copyWithin(n+2,n+1,s),r[n+1]=t,++n,++s,++o}return this.knots.setKnotsCapture(r),this.packedData=a,!0}}class Ns extends st{curvePrimitiveType="bsplineCurve";_bcurve;_definitionData;set definitionData(t){this._definitionData=t}get definitionData(){return this._definitionData}constructor(t,e,n,i){super(),this._bcurve=Yr.create(e,t,n,i)}get degree(){return this._bcurve.degree}get order(){return this._bcurve.order}get numSpan(){return this._bcurve.numSpan}get numPoles(){return this._bcurve.numPoles}get polesRef(){return this._bcurve.packedData}get knotsRef(){return this._bcurve.knots.knots}get poleDimension(){return this._bcurve.poleLength}copyKnots(t){return this._bcurve.knots.copyKnots(t)}getWrappable(){return this._bcurve.knots.wrappable}setWrappable(t){this._bcurve.knots.wrappable=t}get isClosableCurve(){const t=this._bcurve.knots.wrappable;return t===Ce.None||!this._bcurve.knots.testClosable(t)||!this._bcurve.testClosablePolygon(t)?Ce.None:t}fractionToPoint(t,e){return this.knotToPoint(this._bcurve.knots.fractionToKnot(t),e)}fractionToPointAndDerivative(t,e){const n=this._bcurve.knots.fractionToKnot(t);return e=this.knotToPointAndDerivative(n,e),e.direction.scaleInPlace(this._bcurve.knots.knotLength01),e}fractionToPointAnd2Derivatives(t,e){const n=this._bcurve.knots.fractionToKnot(t);e=this.knotToPointAnd2Derivatives(n,e);const i=this._bcurve.knots.knotLength01;return e.vectorU.scaleInPlace(i),e.vectorV.scaleInPlace(i*i),e}startPoint(t){return this.evaluatePointInSpan(0,0,t)}endPoint(t){return this.evaluatePointInSpan(this.numSpan-1,1,t)}reverseInPlace(){this._bcurve.reverseInPlace()}collectBezierSpans(t){const e=[],n=this.numSpan;for(let i=0;i<n;i++)if(this._bcurve.knots.isIndexOfRealSpan(i)){const s=this.getSaturatedBezierSpan3dOr3dH(i,t);s&&e.push(s)}return e}poleIndexToDataIndex(t){if(t>=0&&t<this.numPoles)return t*this._bcurve.poleLength}closestPoint(t,e=!1,n){const i=this.fractionToPoint(0);n=Y.createCurveFractionPointDistance(this,0,i,i.distance(t),n);let s;const r=this.numSpan;for(let o=0;o<r;o++)this._bcurve.knots.isIndexOfRealSpan(o)&&(s=this.getSaturatedBezierSpan3dOr3dH(o,!0,s),s&&s.updateClosestPointByTruePerpendicular(t,n,!1,!0)&&(n.curve=this,n.fraction=s.fractionToParentFraction(n.fraction)));return n}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}clonePartialCurve(t,e){let n;if(t>e)return n=this.clonePartialCurve(e,t),n.reverseInPlace(),n;n=this.clone();const i=n._bcurve.knots.knots.length;let s=n._bcurve.knots.fractionToKnot(t),r=n._bcurve.knots.fractionToKnot(e);if(n._bcurve.addKnot(s,n.degree),n._bcurve.addKnot(r,n.degree),i===n._bcurve.knots.knots.length)return n;s>r&&([s,r]=[r,s]);const o=n._bcurve.knots.knotToLeftKnotIndex(s)-n.degree+1,a=o*n._bcurve.poleLength,c=n._bcurve.knots.knotToLeftKnotIndex(r);let l=c-n._bcurve.knots.getKnotMultiplicityAtIndex(c)+1;n._bcurve.knots.knots[c]<r&&(l=c+1);const d=(l+1)*n._bcurve.poleLength,h=l+n.degree;return n._bcurve.knots.setKnotsCapture(n._bcurve.knots.knots.slice(o,h)),n._bcurve.packedData=n._bcurve.packedData.slice(a,d),n.setWrappable(Ce.None),n}appendPlaneIntersectionPoints(t,e){const n=this.numPoles,i=this.order,s=new Float64Array(n),r=this.numSpan,o=Z.create(),a=ct.createNull();for(let h=0;h<n;h++)this.getPolePoint4d(h,o),s[h]=t.weightedAltitude(o),a.extendX(s[h]);let c,l=0,d=-1e3;if(a.containsX(0)){for(let h=0;h<r;h++)if(this._bcurve.knots.isIndexOfRealSpan(h)&&(a.setNull(),a.extendArraySubset(s,h,i),a.containsX(0))){c=jt.createArraySubset(s,h,i,c),gi.saturate1dInPlace(c.coffs,this._bcurve.knots,h);const g=c.roots(0,!0);if(g)for(const m of g){l++;const p=this._bcurve.knots.spanFractionToFraction(h,m);if(!f.isAlmostEqualNumber(p,d)){const x=Y.createCurveEvaluatedFraction(this,p);x.intervalRole=Ct.isolated,e.push(x),d=p}}}}return l}constructOffsetXY(t){const e=Oe.create(t),n=new Vs(this,e.leftOffsetDistance);return this.emitStrokableParts(n,e.strokeOptions),n.claimResult()}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}}class me extends Ns{_workBezier;initializeWorkBezier(){return this._workBezier===void 0&&(this._workBezier=Pn.createOrder(this.order)),this._workBezier}constructor(t,e,n){super(3,t,e,n)}isSameGeometryClass(t){return t instanceof me}tryTransformInPlace(t){return re.multiplyInPlace(t,this._bcurve.packedData),!0}getPolePoint3d(t,e){const n=this.poleIndexToDataIndex(t);if(n!==void 0){const i=this._bcurve.packedData;return y.create(i[n],i[n+1],i[n+2],e)}}getPolePoint4d(t,e){const n=this.poleIndexToDataIndex(t);if(n!==void 0){const i=this._bcurve.packedData;return Z.create(i[n],i[n+1],i[n+2],1,e)}}spanFractionToKnot(t,e){return this._bcurve.spanFractionToKnot(t,e)}copyPoints(){return re.unpackNumbersToNestedArrays(this._bcurve.packedData,3)}copyPointsFloat64Array(){return this._bcurve.packedData.slice()}copyKnots(t){return this._bcurve.knots.copyKnots(t)}static createUniformKnots(t,e){const n=t instanceof Float64Array?t.length/3:t.length;if(e<2||n<e)return;const i=Jt.createUniformClamped(n,e-1,0,1),s=new me(n,e,i);if(t instanceof Float64Array)for(let r=0;r<3*n;r++)s._bcurve.packedData[r]=t[r];else if(t instanceof W)s._bcurve.packedData=t.float64Data().slice(0,3*n);else{let r=0;for(const o of t)s._bcurve.packedData[r++]=o.x,s._bcurve.packedData[r++]=o.y,s._bcurve.packedData[r++]=o.z}return s}static createPeriodicUniformKnots(t,e){if(e<2)return;let n=t instanceof Float64Array?t.length/3:t.length;if(n<2)return;const i=y.createZero(),s=y.createZero();let r=!1;do t instanceof Float64Array?(i.set(t[0],t[1],t[2]),s.set(t[3*n-3],t[3*n-2],t[3*n-1])):t instanceof W?(t.getPoint3dAtUncheckedPointIndex(0,i),t.getPoint3dAtUncheckedPointIndex(n-1,s)):(i.setFromPoint3d(t[0]),s.setFromPoint3d(t[n-1])),(r=i.isAlmostEqual(s))&&--n;while(r&&n>1);if(n<e)return;const o=e-1,a=n,c=Jt.createUniformWrapped(a,o,0,1);c.wrappable=Ce.OpenByAddingControlPoints;const l=new me(n+o,e,c);if(t instanceof Float64Array){let d=0;for(let h=0;h<3*n;h++)l._bcurve.packedData[d++]=t[h];for(let h=0;h<3*o;h++)l._bcurve.packedData[d++]=t[h]}else if(t instanceof W){let d=0;for(let h=0;h<3*n;h++)l._bcurve.packedData[d++]=t.float64Data()[h];for(let h=0;h<3*o;h++)l._bcurve.packedData[d++]=t.float64Data()[h]}else{let d=0;for(let h=0;h<n;h++)l._bcurve.packedData[d++]=t[h].x,l._bcurve.packedData[d++]=t[h].y,l._bcurve.packedData[d++]=t[h].z;for(let h=0;h<o;h++)l._bcurve.packedData[d++]=t[h].x,l._bcurve.packedData[d++]=t[h].y,l._bcurve.packedData[d++]=t[h].z}return l}static createFromInterpolationCurve3dOptions(t){return Nn.createThroughPointsC2Cubic(t)}static createFromAkimaCurve3dOptions(t){return Nn.createThroughPoints(t.fitPoints,4)}static create(t,e,n){if(n<2)return;let i=t.length;if(t instanceof Float64Array&&(i=Math.floor(i/3)),i<n)return;const s=e.length,r=i+n===s;if(!r&&i+n!==s+2)return;const o=Jt.create(e,n-1,r),a=new me(i,n,o);let c=0;if(t instanceof Float64Array)for(const l of t)a._bcurve.packedData[c++]=l;else if(t[0]instanceof y)for(const l of t)a._bcurve.packedData[c++]=l.x,a._bcurve.packedData[c++]=l.y,a._bcurve.packedData[c++]=l.z;else if(Array.isArray(t[0])&&t[0].length===3)for(const l of t)for(const d of l)a._bcurve.packedData[c++]=d;else return;return a}clone(){const t=this._bcurve.knots.clone(),e=new me(this.numPoles,this.order,t);return e._bcurve.packedData=this._bcurve.packedData.slice(),e}evaluatePointInSpan(t,e,n){return this._bcurve.evaluateBuffersInSpan(t,e),y.createFrom(this._bcurve.poleBuffer,n)}evaluatePointAndDerivativeInSpan(t,e){return this._bcurve.evaluateBuffersInSpan1(t,e),O.createCapture(y.createFrom(this._bcurve.poleBuffer),P.createFrom(this._bcurve.poleBuffer1))}knotToPoint(t,e){return this._bcurve.evaluateBuffersAtKnot(t),y.createFrom(this._bcurve.poleBuffer,e)}knotToPointAndDerivative(t,e){return this._bcurve.evaluateBuffersAtKnot(t,1),e?(e.origin.setFrom(this._bcurve.poleBuffer),e.direction.setFrom(this._bcurve.poleBuffer1),e):O.createCapture(y.createFrom(this._bcurve.poleBuffer),P.createFrom(this._bcurve.poleBuffer1))}knotToPointAnd2Derivatives(t,e){return this._bcurve.evaluateBuffersAtKnot(t,2),At.createOriginAndVectorsXYZ(this._bcurve.poleBuffer[0],this._bcurve.poleBuffer[1],this._bcurve.poleBuffer[2],this._bcurve.poleBuffer1[0],this._bcurve.poleBuffer1[1],this._bcurve.poleBuffer1[2],this._bcurve.poleBuffer2[0],this._bcurve.poleBuffer2[1],this._bcurve.poleBuffer2[2],e)}isAlmostEqual(t){return t instanceof me?this._bcurve.knots.isAlmostEqual(t._bcurve.knots)&&re.isAlmostEqual(this._bcurve.packedData,t._bcurve.packedData):!1}isInPlane(t){return re.isCloseToPlane(this._bcurve.packedData,t)}quickLength(){return re.sumEdgeLengths(this._bcurve.packedData)}emitStrokableParts(t,e){const n=this.initializeWorkBezier(),i=this.numSpan;let s;for(let r=0;r<i;r++){const o=this.getSaturatedBezierSpan3dOr3dH(r,!1,n);o&&(s=o.computeStrokeCountForOptions(e),t.announceBezierCurve?t.announceBezierCurve(o,s,this,r,this._bcurve.knots.spanFractionToFraction(r,0),this._bcurve.knots.spanFractionToFraction(r,1)):t.announceIntervalForUniformStepStrokes(this,s,this._bcurve.knots.spanFractionToFraction(r,0),this._bcurve.knots.spanFractionToFraction(r,1)))}}computeStrokeCountForOptions(t){const e=this.initializeWorkBezier(),n=this.numSpan;let i=0;for(let s=0;s<n;s++){const r=this.getSaturatedBezierSpan3d(s,e);r&&(i+=r.computeStrokeCountForOptions(t))}return i}computeAndAttachRecursiveStrokeCounts(t,e){const n=this.initializeWorkBezier(),i=this.numSpan,s=dn.createWithCurvePrimitiveAndOptionalParent(this,e,[]);for(let r=0;r<i;r++)if(this.getSaturatedBezierSpan3d(r,n)){const a=n.curveLength(),c=n.computeStrokeCountForOptions(t);s.addToCountAndLength(c,a)}st.installStrokeCountMap(this,s,e)}emitStrokes(t,e){const n=this.initializeWorkBezier(),i=this.numSpan;for(let s=0;s<i;s++){const r=this.getSaturatedBezierSpan3d(s,n);r&&r.emitStrokes(t,e)}}get isClosable(){return this.isClosableCurve}getSaturatedBezierSpan3dOr3dH(t,e,n){return e?this.getSaturatedBezierSpan3dH(t,n):this.getSaturatedBezierSpan3d(t,n)}getSaturatedBezierSpan3d(t,e){if(t<0||t>=this.numSpan)return;const n=this.order;(e===void 0||!(e instanceof Pn)||e.order!==n)&&(e=Pn.createOrder(n));const i=e;if(i.loadSpanPoles(this._bcurve.packedData,t),i.saturateInPlace(this._bcurve.knots,t))return i}getSaturatedBezierSpan3dH(t,e){if(t<0||t>=this.numSpan)return;const n=this.order;(e===void 0||!(e instanceof In)||e.order!==n)&&(e=In.createOrder(n));const i=e;if(i.loadSpan3dPolesWithWeight(this._bcurve.packedData,t,1),i.saturateInPlace(this._bcurve.knots,t))return i}dispatchToGeometryHandler(t){return t.handleBSplineCurve3d(this)}extendRange(t,e){const n=this._bcurve.packedData,i=n.length-2;if(e)for(let s=0;s<i;s+=3)t.extendTransformedXYZ(e,n[s],n[s+1],n[s+2]);else for(let s=0;s<i;s+=3)t.extendXYZ(n[s],n[s+1],n[s+2])}}class Nn{static createThroughPoints(t,e){const n=t.length;if(e>n||e<2)return;const i=e-1,s=1+2*i,r=new Float64Array(s*n),o=new Float64Array(e),a=new W,c=Jt.createUniformClamped(n,e-1,0,1),l=y.create();for(let h=0;h<n;h++){const g=c.grevilleKnot(h),m=c.knotToLeftKnotIndex(g);c.evaluateBasisFunctions(m,g,o);let p=0;for(let I=1;I<e;I++)o[I]>o[p]&&(p=I);const x=i-p,_=h*s;for(let I=0;I<e;I++){const v=h-i+x+I;_+v>=0&&v<n&&(r[_+x+I]=o[I])}t instanceof le?a.push(t.getPoint3dAtUncheckedPointIndex(h,l)):a.push(t[h].clone())}const d=ia.solveBandedSystemMultipleRHS(n,s,r,3,a.float64Data());if(d)return me.create(d,c.knots,e)}static createThroughPointsC2Cubic(t){const e=t.clone();if(!this.C2CubicFit.validateOptions(e))return;const n=this.C2CubicFit.constructPoles(e);if(n===void 0)return;const i=this.C2CubicFit.convertFitParamsToCubicKnotVector(e.knots,e.closed);if(i===void 0)return;const s=me.create(n,i,e.order);return e.closed&&s?.setWrappable(Ce.OpenByAddingControlPoints),s}}(function(u){class t{static normalizeKnots(n){if(n===void 0||n.length<2)return n=void 0,!1;const i=Jt.create(n,1,!1);if(!i.normalize())return n=void 0,!1;for(let s=0;s<n.length;++s)n[s]=i.knots[s];return!0}static constructChordLengthParameters(n){if(n.length<2)return;const i=[0];for(let s=1;s<n.length;++s)i[s]=i[s-1]+n[s].distance(n[s-1]);if(this.normalizeKnots(i))return i}static constructUniformParameters(n){if(n<2)return;const i=Jt.createUniformClamped(n+2,3,0,1),s=[];for(let r=i.leftKnotIndex;r<=i.rightKnotIndex;++r)s.push(i.knots[r]);return s}static removeDuplicateFitPoints(n){n.knots!==void 0&&n.knots.length!==n.fitPoints.length&&(n.knots=void 0);const s=new Bt(n.fitPoints).findOrderedDuplicates(void 0,!0);if(s.length>0){let r=0;for(let o=0,a=0;o<n.fitPoints.length;++o)a<s.length&&o===s[a]?++a:(n.fitPoints[r]=n.fitPoints[o],n.knots&&(n.knots[r]=n.knots[o]),++r);n.fitPoints.splice(r),n.knots&&n.knots.splice(r)}return!0}static constructFitParametersFromPoints(n,i,s){let r;return(i||!s)&&(r=this.constructChordLengthParameters(n)),r===void 0&&(r=this.constructUniformParameters(n.length)),r}static constructFitParameters(n){return n.knots===void 0&&(n.knots=this.constructFitParametersFromPoints(n.fitPoints,n.isChordLenKnots,n.closed)),n.knots?.length===n.fitPoints.length}static computeAlphaBetaGamma(n,i,s,r,o,a,c,l){let d=1/(l+c+a);n[r]=a*a*d,i[r]=a*(l+c)*d,d=1/(c+a+o),i[r]+=c*(a+o)*d,s[r]=c*c*d,d=1/(c+a),n[r]*=d,i[r]*=d,s[r]*=d}static setUpSystem2Points(n,i,s){return n.length!==2||i.length!==2||s.length!==2?!1:(n[0]=n[1]=s[0]=s[1]=0,i[0]=i[1]=1,!0)}static setUpSystem3Points(n,i,s,r,o,a){if(r.knots===void 0||n.length!==3||i.length!==3||s.length!==3||r.knots.length!==3||r.fitPoints.length!==3)return!1;let c=0,l=0,d=0,h=0,g=0,m=0;return o?(n[0]=0,l=r.knots[1]-r.knots[0],c=r.knots[2]-r.knots[1],g=l+c,m=1/g,i[0]=(l+g)*m,s[0]=-l*m):(n[0]=s[0]=0,i[0]=1),d=r.knots[1]-r.knots[0],l=r.knots[2]-r.knots[1],m=1/(d+l),m*=m,n[1]=l*l*m,i[1]=2*(l*d)*m,s[1]=d*d*m,a?(d=r.knots[2]-r.knots[1],h=r.knots[1]-r.knots[0],g=h+d,m=1/g,n[2]=-d*m,i[2]=(d+g)*m,s[2]=0):(n[2]=s[2]=0,i[2]=1),!0}static setUpSystem4PointsOrMore(n,i,s,r,o,a){if(r.knots===void 0||n.length!==i.length||n.length!==s.length||n.length!==r.knots.length||r.knots.length!==r.fitPoints.length)return!1;const c=r.fitPoints.length-1,l=c-1;let d=0,h=0,g=0,m=0,p=0,x=0;r.closed?(h=r.knots[1]-r.knots[0],m=r.knots[l]-r.knots[l-1],g=r.knots[l+1]-r.knots[l],d=r.knots[2]-r.knots[1],this.computeAlphaBetaGamma(n,i,s,0,d,h,g,m),m=g,g=h,h=r.knots[2]-r.knots[1],d=r.knots[3]-r.knots[2],this.computeAlphaBetaGamma(n,i,s,1,d,h,g,m),d=g,h=r.knots[l+1]-r.knots[l],m=r.knots[l-1]-r.knots[l-2],g=r.knots[l]-r.knots[l-1],this.computeAlphaBetaGamma(n,i,s,l,d,h,g,m)):(o?(n[0]=0,h=r.knots[1]-r.knots[0],d=r.knots[2]-r.knots[1],p=h+d,x=1/p,i[0]=(h+p)*x,s[0]=-h*x):(n[0]=s[0]=0,i[0]=1),h=r.knots[2]-r.knots[1],g=r.knots[1]-r.knots[0],m=0,d=r.knots[3]-r.knots[2],this.computeAlphaBetaGamma(n,i,s,1,d,h,g,m),h=r.knots[l+1]-r.knots[l],g=r.knots[l]-r.knots[l-1],m=r.knots[l-1]-r.knots[l-2],d=0,this.computeAlphaBetaGamma(n,i,s,l,d,h,g,m),a?(g=r.knots[c]-r.knots[c-1],m=r.knots[c-1]-r.knots[c-2],p=m+g,x=1/p,n[c]=-g*x,i[c]=(g+p)*x,s[c]=0):(n[c]=s[c]=0,i[c]=1));for(let _=2;_<l;++_)h=r.knots[_+1]-r.knots[_],m=r.knots[_-1]-r.knots[_-2],g=r.knots[_]-r.knots[_-1],d=r.knots[_+2]-r.knots[_+1],this.computeAlphaBetaGamma(n,i,s,_,d,h,g,m);return!0}static setUpSystem(n,i,s,r){let o=!1,a=!1;r.isNaturalTangents&&!r.closed&&(o=r.startTangent===void 0,a=r.endTangent===void 0);let c=!1;return r.fitPoints.length===2?c=this.setUpSystem2Points(n,i,s):r.fitPoints.length===3?c=this.setUpSystem3Points(n,i,s,r,o,a):4<=r.fitPoints.length&&(c=this.setUpSystem4PointsOrMore(n,i,s,r,o,a)),c}static setBesselEndCondition(n,i,s){if(n.length!==i.fitPoints.length+2||i.knots===void 0)return!1;const r=1/3,o=i.fitPoints.length-1;if(o===1)return s?n[0].interpolate(r,n[3],n[1]):n[3].interpolate(r,n[0],n[2]),!0;if(o===2){const a=(i.knots[2]-i.knots[1])/(i.knots[2]-i.knots[0]),c=1-a,l=n[2].plus2Scaled(n[0],-a*a,n[4],-c*c);return s?y.createAdd2Scaled(l,1/(2*a),n[0],a).interpolate(r,n[0],n[1]):y.createAdd2Scaled(l,1/(2*c),n[4],c).interpolate(r,n[4],n[3]),!0}if(s){const a=(i.knots[2]-i.knots[1])/(i.knots[2]-i.knots[0]),c=1-a,l=n[2].plus2Scaled(n[0],-a*a,n[3],-c*c);y.createAdd2Scaled(l,1/(2*a),n[0],a).interpolate(r,n[0],n[1])}else{const a=(i.knots[o]-i.knots[o-1])/(i.knots[o]-i.knots[o-2]),c=1-a,l=n[o].plus2Scaled(n[o-1],-a*a,n[o+2],-c*c);y.createAdd2Scaled(l,1/(2*c),n[o+2],c).interpolate(r,n[o+2],n[o+1])}return!0}static setNaturalEndCondition(n,i,s){return n.length!==i.fitPoints.length+2?!1:i.fitPoints.length-1===1?this.setBesselEndCondition(n,i,s):(s?n[1]=n[0]:n[n.length-2]=n[n.length-1],!0)}static setChordLengthScaledEndCondition(n,i,s){if(n.length!==i.fitPoints.length+2)return!1;const r=s?i.startTangent:i.endTangent;if(r===void 0)return!1;let o=0,a=0,c=0;const l=i.fitPoints.length-1;l===1?s?(o=0,a=1,c=3):(o=3,a=2,c=0):s?(o=0,a=1,c=2):(o=l+2,a=l+1,c=l);const d=n[c].distance(n[o]);return n[o].plusScaled(r,d/3,n[a]),!0}static setBesselLengthScaledEndCondition(n,i,s){if(n.length!==i.fitPoints.length+2)return!1;const r=s?i.startTangent:i.endTangent;if(r===void 0||!this.setBesselEndCondition(n,i,s))return!1;const o=i.fitPoints.length-1,a=s?0:o+2,c=s?1:o+1;return n[a].plusScaled(r,n[a].distance(n[c]),n[c]),!0}static setPhysicallyClosedEndCondition(n,i){const s=i.fitPoints.length-1;if(!i.isColinearTangents||s<=2||i.startTangent!==void 0&&i.endTangent!==void 0||i.isNaturalTangents||!n[0].isAlmostEqual(n[s+2]))return!0;if(i.startTangent!==void 0){const r=P.createStartEnd(n[1],n[0]).normalize();if(r!==void 0){const o=n[s+2].distance(n[s+1]);n[s+2].plusScaled(r,o,n[s+1])}}else if(i.endTangent!==void 0){const r=P.createStartEnd(n[s+1],n[s+2]).normalize();if(r!==void 0){const o=n[0].distance(n[1]);n[0].plusScaled(r,o,n[1])}}else{const r=P.createStartEnd(n[s+1],n[1]).normalize();if(r!==void 0){const o=n[0].distance(n[1]);n[0].plusScaled(r,o,n[1]);const a=n[s+2].distance(n[s+1]);n[s+2].plusScaled(r,-a,n[s+1])}}return!0}static setEndConditions(n,i){if(n.length!==i.fitPoints.length)return!1;const s=y.createZero(),r=y.createZero();n.splice(1,0,s),n.splice(n.length-1,0,r);let o=!1;return i.startTangent===void 0?i.isNaturalTangents?o=this.setNaturalEndCondition(n,i,!0):o=this.setBesselEndCondition(n,i,!0):i.isChordLenTangents?o=this.setChordLengthScaledEndCondition(n,i,!0):o=this.setBesselLengthScaledEndCondition(n,i,!0),i.endTangent===void 0?i.isNaturalTangents?o=this.setNaturalEndCondition(n,i,!1):o=this.setBesselEndCondition(n,i,!1):i.isChordLenTangents?o=this.setChordLengthScaledEndCondition(n,i,!1):o=this.setBesselLengthScaledEndCondition(n,i,!1),o&&(o=this.setPhysicallyClosedEndCondition(n,i)),o}static solveNearTridiagonal(n,i,s,r){if(i.length!==s.length||i.length!==r.length||i.length!==n.length)return;const o=[],a=n.length-1,c=n.slice(0,-1);let l=0;for(let d=1;d<a;++d){if((l=f.conditionalDivideFraction(-i[d],s[d-1]))===void 0)return;s[d]+=l*r[d-1],i[d]=l*i[d-1],c[d].addScaledInPlace(c[d-1],l)}if((l=f.conditionalDivideFraction(1,s[a-1]+i[a-1]))!==void 0){r[a-1]*=l,c[a-1].scaleInPlace(l);for(let d=a-2;d>=0;--d){if((l=f.conditionalDivideFraction(1,s[d]))===void 0)return;y.createScale(c[d].plus2Scaled(c[d+1],-r[d],c[a-1],-i[d]),l,c[d]),r[d]=-(r[d]*r[d+1]+i[d]*r[a-1])*l}if((l=f.conditionalDivideFraction(1,1+r[0]))!==void 0){o.push(y.createScale(c[0],l));for(let d=1;d<a;++d)o.push(c[d].plusScaled(o[0],-r[d]));return o}}}static validateOptions(n){if(n.order=4,n.knots=this.convertCubicKnotVectorToFitParams(n.knots,n.fitPoints.length,!0),!this.removeDuplicateFitPoints(n))return!1;let i=n.fitPoints.length>1&&n.fitPoints[0].isAlmostEqual(n.fitPoints[n.fitPoints.length-1]);if(n.fitPoints.length===3&&i&&(n.fitPoints.pop(),n.knots!==void 0&&n.knots.pop(),i=n.fitPoints[0].isAlmostEqual(n.fitPoints[n.fitPoints.length-1])),n.fitPoints.length<=2){if(i)return!1;n.closed=!1}return n.closed&&(i||(n.fitPoints.push(n.fitPoints[0].clone()),n.knots!==void 0&&n.knots.push(n.knots[n.knots.length-1]+(n.knots[n.knots.length-1]-n.knots[0])/(n.knots.length-1))),n.fitPoints.length<=4&&(n.closed=!1)),n.fitPoints.length<2?!1:(n.startTangent!==void 0&&(n.startTangent.isAlmostZero?n.startTangent=void 0:n.startTangent.normalizeInPlace()),n.endTangent!==void 0&&(n.endTangent.isAlmostZero?n.endTangent=void 0:n.endTangent.normalizeInPlace()),!0)}static convertCubicKnotVectorToFitParams(n,i,s){let r=n?.slice();if(r!==void 0){const o=r.length-i;switch(o){case 0:break;case 4:case 6:{for(let a=0;a<o/2;++a)r.pop(),r.shift();break}default:{r=void 0;break}}s&&!this.normalizeKnots(r)&&(r=void 0)}return r}static convertFitParamsToCubicKnotVector(n,i,s){const r=n?.slice();if(r!==void 0){const o=s?6:4;if(i){const a=r.length-2;for(let c=2;c<=o;c+=2)r.unshift(r[a]-1),r.push(1+r[c])}else for(let a=0;a<o/2;++a)r.unshift(0),r.push(1)}return r}static convertToJsonKnots(n){n.knots!==void 0?(n.knots=this.convertCubicKnotVectorToFitParams(n.knots,n.fitPoints.length,!1),n.knots=this.convertFitParamsToCubicKnotVector(n.knots,n.closed,!0)):(n.knots=this.constructFitParametersFromPoints(re.clonePoint3dArray(n.fitPoints),n.isChordLenKnots,n.closed),n.knots=this.convertFitParamsToCubicKnotVector(n.knots,n.closed,!0))}static constructPoles(n){if(!this.constructFitParameters(n)||n.knots===void 0)return;const i=n.fitPoints.length,s=Array(i),r=Array(i),o=Array(i);if(!this.setUpSystem(s,r,o,n))return;let a=[];if(n.closed){if((a=this.solveNearTridiagonal(n.fitPoints,s,r,o))!==void 0&&a.length>2){const c=a.pop();a.unshift(c);for(let l=0;l<n.order-1;++l)a.push(a[l].clone())}}else{const c=n.fitPoints.slice();if(!this.setEndConditions(c,n)||c.length!==i+2)return;const l=new Float64Array(i*3),d=new Float64Array(i*3);for(let m=0,p=0,x=0;m<i;++m)l[p++]=s[m],l[p++]=r[m],l[p++]=o[m],d[x++]=c[m+1].x,d[x++]=c[m+1].y,d[x++]=c[m+1].z;const h=ia.solveBandedSystemMultipleRHS(i,3,l,3,d);if(h===void 0)return;a=new Float64Array(3+h.length+3);let g=0;a[g++]=n.fitPoints[0].x,a[g++]=n.fitPoints[0].y,a[g++]=n.fitPoints[0].z;for(let m=0;m<h.length;)a[g++]=h[m++];a[g++]=n.fitPoints[n.fitPoints.length-1].x,a[g++]=n.fitPoints[n.fitPoints.length-1].y,a[g++]=n.fitPoints[n.fitPoints.length-1].z}return a}}u.C2CubicFit=t})(Nn||(Nn={}));class Nr extends st{dispatchToGeometryHandler(t){return this._proxyCurve.dispatchToGeometryHandler(t)}_proxyCurve;constructor(t){super(),this._proxyCurve=t}get proxyCurve(){return this._proxyCurve}computeStrokeCountForOptions(t){return this._proxyCurve.computeStrokeCountForOptions(t)}emitStrokableParts(t,e){this._proxyCurve.emitStrokableParts(t,e)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}clonePartialCurve(t,e){return this._proxyCurve.clonePartialCurve(t,e)}emitStrokes(t,e){this._proxyCurve.emitStrokes(t,e)}extendRange(t,e){this._proxyCurve.extendRange(t,e)}range(t,e){return this._proxyCurve.range(t,e)}fractionToPoint(t,e){return this._proxyCurve.fractionToPoint(t,e)}fractionToPointAndDerivative(t,e){return this._proxyCurve.fractionToPointAndDerivative(t,e)}fractionToPointAnd2Derivatives(t,e){return this._proxyCurve.fractionToPointAnd2Derivatives(t,e)}isInPlane(t){return this._proxyCurve.isInPlane(t)}quickLength(){return this._proxyCurve.quickLength()}constructOffsetXY(t){return this._proxyCurve.constructOffsetXY(t)}projectedParameterRange(t,e){return this._proxyCurve.projectedParameterRange(t,e)}}class zs{constructor(t,e){this._fitPoints=t||[],this._knots=e}_order;_closed;_isChordLenKnots;_isColinearTangents;_isChordLenTangents;_isNaturalTangents;_startTangent;_endTangent;_fitPoints;_knots;get order(){return f.resolveNumber(this._order,4)}set order(t){this._order=t}get closed(){return f.resolveValue(this._closed,!1)}set closed(t){this._closed=t}get isChordLenKnots(){return f.resolveNumber(this._isChordLenKnots,0)}set isChordLenKnots(t){this._isChordLenKnots=t}get isColinearTangents(){return f.resolveNumber(this._isColinearTangents,0)}set isColinearTangents(t){this._isColinearTangents=t}get isChordLenTangents(){return f.resolveNumber(this._isChordLenTangents,0)}set isChordLenTangents(t){this._isChordLenTangents=t}get isNaturalTangents(){return f.resolveNumber(this._isNaturalTangents,0)}set isNaturalTangents(t){this._isNaturalTangents=t}get startTangent(){return this._startTangent}set startTangent(t){this._startTangent=t}get endTangent(){return this._endTangent}set endTangent(t){this._endTangent=t}get fitPoints(){return this._fitPoints}set fitPoints(t){this._fitPoints=t}get knots(){return this._knots}set knots(t){this._knots=t}captureOptionalProps(t,e,n,i,s,r,o,a){this._order=f.resolveToUndefined(t,0),this._closed=f.resolveToUndefined(e,!1),this._isChordLenKnots=f.resolveToUndefined(n,0),this._isColinearTangents=f.resolveToUndefined(i,0),this._isChordLenTangents=f.resolveToUndefined(s,0),this._isNaturalTangents=f.resolveToUndefined(r,0),this._startTangent=o,this._endTangent=a}cloneAsInterpolationCurve3dProps(){const t={fitPoints:re.cloneDeepJSONNumberArrays(this.fitPoints),knots:this._knots?.slice()};return this._order!==void 0&&(t.order=this._order),this._closed!==void 0&&(t.closed=this._closed),this._isChordLenKnots!==void 0&&(t.isChordLenKnots=this._isChordLenKnots),this._isColinearTangents!==void 0&&(t.isColinearTangents=this._isColinearTangents),this._isChordLenTangents!==void 0&&(t.isChordLenTangents=this._isChordLenTangents),this._isNaturalTangents!==void 0&&(t.isNaturalTangents=this._isNaturalTangents),this._startTangent!==void 0&&(t.startTangent=this._startTangent?.toArray()),this._endTangent!==void 0&&(t.endTangent=this._endTangent?.toArray()),t}clone(){const t=new zs(re.clonePoint3dArray(this.fitPoints),this.knots?.slice());return t._order=this.order,t._closed=this.closed,t._isChordLenKnots=this.isChordLenKnots,t._isColinearTangents=this.isColinearTangents,t._isChordLenTangents=this.isChordLenTangents,t._isNaturalTangents=this.isNaturalTangents,t._startTangent=this._startTangent?.clone(),t._endTangent=this._endTangent?.clone(),t}static create(t){const e=new zs(re.clonePoint3dArray(t.fitPoints),t.knots?.slice());return e._order=t.order,e._closed=t.closed,e._isChordLenKnots=t.isChordLenKnots,e._isColinearTangents=t.isColinearTangents,e._isChordLenTangents=t.isChordLenTangents,e._isNaturalTangents=t.isNaturalTangents,e._startTangent=t.startTangent?P.fromJSON(t.startTangent):void 0,e._endTangent=t.endTangent?P.fromJSON(t.endTangent):void 0,e}static areAlmostEqualAllow000AsUndefined(t,e){return t!==void 0&&t.maxAbs()===0&&(t=void 0),e!==void 0&&e.maxAbs()===0&&(e=void 0),t!==void 0&&e!==void 0?t.isAlmostEqual(e):t===void 0&&e===void 0}static areAlmostEqual(t,e){if(t===void 0&&e===void 0)return!0;if(t!==void 0&&e!==void 0&&f.areEqualAllowUndefined(t.order,e.order)&&f.areEqualAllowUndefined(t.closed,e.closed)&&f.areEqualAllowUndefined(t.isChordLenKnots,e.isChordLenKnots)&&f.areEqualAllowUndefined(t.isColinearTangents,e.isColinearTangents)&&f.areEqualAllowUndefined(t.isNaturalTangents,e.isNaturalTangents)&&this.areAlmostEqualAllow000AsUndefined(t.startTangent,e.startTangent)&&this.areAlmostEqualAllow000AsUndefined(t.endTangent,e.endTangent)&&f.almostEqualArrays(t.fitPoints,e.fitPoints,(n,i)=>n.isAlmostEqual(i))){if(f.almostEqualNumberArrays(t.knots,e.knots,(s,r)=>s===r)||t.knots===void 0&&e.knots===void 0)return!0;let n=t.knots,i=e.knots;return t.knots===void 0?n=Nn.C2CubicFit.constructFitParametersFromPoints(t.fitPoints,t.isChordLenKnots,t.closed):e.knots===void 0&&(i=Nn.C2CubicFit.constructFitParametersFromPoints(e.fitPoints,e.isChordLenKnots,e.closed)),n=Nn.C2CubicFit.convertCubicKnotVectorToFitParams(n,t.fitPoints.length,!1),i=Nn.C2CubicFit.convertCubicKnotVectorToFitParams(i,e.fitPoints.length,!1),f.almostEqualNumberArrays(n,i,(s,r)=>f.isAlmostEqualNumber(s,r))}return!1}reverseInPlace(){this.fitPoints.reverse(),this.knots&&this.knots.reverse();const t=this._startTangent;this._startTangent=this.endTangent,this._endTangent=t}}class Vs{_offsetDistance;_fitOptions;_p0=y.createZero();_p1=y.createZero();_v0=P.createZero();_v1=P.createZero();_r0=O.createZero();constructor(t,e){this._offsetDistance=e,this._fitOptions=new zs;const n=t.fractionToPointAndUnitTangent(0,this._r0).direction.clone(),i=t.fractionToPointAndUnitTangent(1,this._r0).direction.negate();this._fitOptions.startTangent=n,this._fitOptions.endTangent=i,(this._fitOptions.closed=t.startPoint(this._p0).isAlmostEqual(t.endPoint(this._p1))&&n.isParallelTo(i,!0))&&(this._fitOptions.isChordLenKnots=1)}pushOffsetPoint(t,e){(!f.isSmallMetricDistance(e.x)||!f.isSmallMetricDistance(e.y))&&this._fitOptions.fitPoints.push(t.plusScaled(e.unitPerpendicularXY(this._v0),this._offsetDistance))}needPrimaryGeometryForStrokes(){return!0}startParentCurvePrimitive(t){}startCurvePrimitive(t){}endCurvePrimitive(t){}endParentCurvePrimitive(t){}announceIntervalForUniformStepStrokes(t,e,n,i){for(let s=0;s<=e;++s){const r=f.interpolate(n,s/e,i),o=t.fractionToPointAndDerivative(r,this._r0);this.pushOffsetPoint(o.origin,o.direction)}}announceSegmentInterval(t,e,n,i,s,r){if(i>0){const o=P.createStartEnd(e,n,this._v1);for(let a=0;a<=i;++a)this.pushOffsetPoint(e.interpolate(a/i,n,this._p0),o)}}announcePointTangent(t,e,n){this.pushOffsetPoint(t,n)}claimResult(){return Nn.createThroughPointsC2Cubic(this._fitOptions)}}class zr{constructor(){}announceUnexpected(t,e){}announceCurvePrimitive(t,e=-1){}announcePath(t,e=-1){let n=0;for(const i of t.children)this.announceCurvePrimitive(i,n++)}announceLoop(t,e=-1){let n=0;for(const i of t.children)this.announceCurvePrimitive(i,n++)}announceParityRegion(t,e=-1){let n=0;for(const i of t.children)this.announceLoop(i,n++)}announceUnionRegion(t,e=-1){let n=0;for(const i of t.children)i.curveCollectionType==="loop"?this.announceLoop(i,n++):this.announceParityRegion(i,n++)}announceBagOfCurves(t,e=-1){for(const n of t.children)n instanceof st?this.announceCurvePrimitive(n):n.announceToCurveProcessor(this)}}class Vr extends zr{_stack;constructor(){super(),this._stack=[]}enter(t){this._stack.push(t)}leave(){return this._stack.pop()}announceUnexpected(t,e){}announceCurvePrimitive(t,e=-1){}announcePath(t,e=-1){this.enter(t),super.announcePath(t,e),this.leave()}announceLoop(t,e=-1){this.enter(t),super.announceLoop(t,e),this.leave()}announceParityRegion(t,e=-1){this.enter(t);let n=0;for(const i of t.children)this.announceLoop(i,n++);this.leave()}announceUnionRegion(t,e=-1){this.enter(t);let n=0;for(const i of t.children)i.curveCollectionType==="loop"?this.announceLoop(i,n++):this.announceParityRegion(i,n++);this.leave()}announceBagOfCurves(t,e=-1){this.enter(t);let n=0;for(const i of t.children)i instanceof st?this.announceCurvePrimitive(i,n++):i.announceToCurveProcessor(this);this.leave()}}class Ri extends Vr{_result;_transform;constructor(t){super(),this._transform=t,this._result=void 0}static clone(t,e){const n=new Ri(e);return t.announceToCurveProcessor(n),n._result}enter(t){t instanceof ut&&super.enter(t.cloneEmptyPeer())}leave(){const t=super.leave();return t&&(this._stack.length===0?this._result=t:this._stack[this._stack.length-1].tryAddChild(t)),t}doClone(t){return this._transform?t.cloneTransformed(this._transform):t.clone()}announceCurvePrimitive(t,e){const n=this.doClone(t);if(n!==void 0&&this._stack.length>0){const i=this._stack[this._stack.length-1];if(i instanceof de||i instanceof Ee)if(Array.isArray(n))for(const s of n)i.tryAddChild(s);else i.tryAddChild(n)}}}class Or extends Ri{constructor(){super(void 0)}doClone(t){if(t instanceof F&&t.numPoints()>1){const e=t.packedPoints,n=e.length,i=[];for(let s=0;s+1<n;s++)i.push(U.createCapture(e.getPoint3dAtUncheckedPointIndex(s),e.getPoint3dAtUncheckedPointIndex(s+1)));return i}return t.clone()}static clone(t){const e=new Or;return t.announceToCurveProcessor(e),e._result}}class Lr extends Vr{numLineSegment;numLineString;numOther;constructor(){super(),this.numLineSegment=0,this.numLineString=0,this.numOther=0}static hasNonLinearPrimitives(t){const e=new Lr;return t.announceToCurveProcessor(e),e.numOther>0}announceCurvePrimitive(t,e){t instanceof U?this.numLineSegment++:t instanceof F?this.numLineString++:this.numOther++}}class Ur extends Vr{maxGap;constructor(){super(),this.maxGap=0}static maxGap(t){const e=new Ur;return t.announceToCurveProcessor(e),e.maxGap}announceCurvePrimitive(t,e){if(this._stack.length>0){const n=this._stack[this._stack.length-1];if(n instanceof de){const s=n.cyclicCurvePrimitive(e+1);t!==void 0&&s!==void 0&&(this.maxGap=Math.max(this.maxGap,t.endPoint().distance(s.startPoint())))}}}}class Br extends zr{_sum;constructor(){super(),this._sum=0}static sumLengths(t){const e=new Br;return t.announceToCurveProcessor(e),e._sum}announceCurvePrimitive(t,e){this._sum+=t.curveLength()}}class Zr extends zr{transform;constructor(t){super(),this.transform=t}static tryTransformInPlace(t,e){const n=new Zr(e);return t.announceToCurveProcessor(n),!0}announceCurvePrimitive(t,e){t.tryTransformInPlace(this.transform)}}class ut extends Ae{geometryCategory="curveCollection";sumLengths(){return Br.sumLengths(this)}computeClosestPoint(t,e=!1,n,i=!1){let s;const r=new Y;let o=this.isAnyRegion()?!1:e;for(let a=0;a<this.children.length;a++){const c=this.children[a];if(this.isPath()){const d=a===0?Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,0):Ht.None,h=a===this.children.length-1?Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,1):Ht.None;o=[d,h]}(i?c.closestPointXY(t,o,r):c.closestPoint(t,o,r))&&(s=n=Y.chooseSmallerA(s,r).clone(n))}return s}closestPoint(t,e=!1,n){return this.computeClosestPoint(t,e,n)}closestPointXY(t,e=!1,n){return this.computeClosestPoint(t,e,n,!0)}emitTangents(t,e,n){const i=new $o(t,e,n);if(this.children!==void 0)for(const s of this.children)s instanceof st?s.emitStrokableParts(i,n?.strokeOptions):s instanceof ut&&s.emitTangents(t,e,n)}allTangents(t,e){const n=[];return this.emitTangents(t,i=>n.push(i.clone()),e),n.length===0?void 0:n}closestTangent(t,e){const n=e?.hintPoint??t;let i;e?.vectorToEye&&!e.vectorToEye.isExactEqual({x:0,y:0,z:1})&&(i=C.createRigidViewAxesZTowardsEye(e.vectorToEye.x,e.vectorToEye.y,e.vectorToEye.z));const s=c=>i?.multiplyTransposeXYZ(n.x-c.x,n.y-c.y,n.z-c.z).magnitudeSquaredXY()??c.distanceSquaredXY(n);let r,o=f.largeCoordinateResult;const a=c=>{const l=s(c.point);(!r||l<o)&&(r=c.clone(r),o=l)};return this.emitTangents(t,a,e),r}reverseInPlace(){for(const t of this.children)t.reverseInPlace()}reverse(){return this.reverseInPlace(),this}maxGap(){return Ur.maxGap(this)}checkForNonLinearPrimitives(){return Lr.hasNonLinearPrimitives(this)}tryTransformInPlace(t){return Zr.tryTransformInPlace(this,t)}clone(){return Ri.clone(this)}cloneTransformed(t){return Ri.clone(this,t)}cloneWithExpandedLineStrings(){return Or.clone(this)}collectCurvePrimitivesGo(t,e,n=!1){if(this.children)for(const i of this.children)(i instanceof st||i instanceof ut)&&i.collectCurvePrimitivesGo(t,e,n)}collectCurvePrimitives(t,e=!1,n=!1){const i=t===void 0?[]:t;return this.collectCurvePrimitivesGo(i,e,n),i}get isAnyRegionType(){return this.dgnBoundaryType()===2||this.dgnBoundaryType()===4||this.dgnBoundaryType()===5}isAnyRegion(){return this.isAnyRegionType}get isOpenPath(){return this.dgnBoundaryType()===1}isPath(){return this.isOpenPath}get isClosedPath(){return this.dgnBoundaryType()===2}isLoop(){return this.isClosedPath}extendRange(t,e){const n=this.children;if(n)for(const i of n)i.extendRange(t,e)}static createCurveLocationDetailOnAnyCurvePrimitive(t,e=.5){if(t){if(t instanceof st)return Y.createCurveEvaluatedFraction(t,e);if(t instanceof ut&&t.children!==void 0)for(const n of t.children){const i=this.createCurveLocationDetailOnAnyCurvePrimitive(n,e);if(i)return i}}}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}findParentOfDescendant(t){for(const e of this.children){if(e===t)return this;if(e instanceof ut){const n=e.findParentOfDescendant(t);if(n)return n}}}isInPlane(t){if(this.children.length===0)return!1;for(const e of this.children)if(!(e instanceof ut&&e.children.length===0)&&!e.isInPlane(t))return!1;return!0}}class de extends ut{_curves;constructor(){super(),this._curves=[]}get children(){return this._curves}startPoint(t){const e=this.getChild(0);if(e)return e.fractionToPoint(0,t)}endPoint(t){const e=this.getChild(this._curves.length-1);if(e)return e.fractionToPoint(1,t)}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){const n=this.startPoint(),i=this.endPoint();return n!==void 0&&i!==void 0&&(e?n.isAlmostEqualXY(i,t):n.isAlmostEqual(i,t))}startPointAndDerivative(t){const e=this.getChild(0);if(e)return e.fractionToPointAndDerivative(0,t)}endPointAndDerivative(t){const e=this.getChild(this._curves.length-1);if(e)return e.fractionToPointAndDerivative(1,t)}cyclicCurvePrimitive(t,e=!0){const n=this.children.length;if(n!==0){if(t>=0&&t<n)return this.children[t];if(e){const i=f.modulo(t,n);return this.children[i]}}}getPackedStrokes(t){const e=this.cloneStroked(t);if(e instanceof de){const n=e.children;if(n.length===1){const i=n[0];if(i instanceof F)return i.packedPoints}}}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(t){return t&&t instanceof st?(this._curves.push(t),!0):!1}getChild(t){if(t<this._curves.length)return this._curves[t]}extendRange(t,e){for(const n of this._curves)n.extendRange(t,e)}reverseChildrenInPlace(){for(const t of this._curves)t.reverseInPlace();this._curves.reverse()}reverseInPlace(){this.reverseChildrenInPlace()}childIndex(t,e){for(let n=0;n<this._curves.length;n++)if(this._curves[n]===t)return n;if(e??!1)for(let n=0;n<this._curves.length;n++){const i=this._curves[n];if(i instanceof Nr&&i.proxyCurve===t)return n}}primitiveIndexAndFractionToCurveLocationDetailPointAndDerivative(t,e,n=!1,i){const s=this.cyclicCurvePrimitive(t,n);if(s)return Y.createCurveEvaluatedFractionPointAndDerivative(s,e,i)}}class Ee extends ut{curveCollectionType="bagOfCurves";isSameGeometryClass(t){return t instanceof Ee}_children;constructor(){super(),this._children=[]}get children(){return this._children}static create(...t){const e=new Ee;for(const n of t)e.tryAddChild(n);return e}dgnBoundaryType(){return 0}announceToCurveProcessor(t,e=-1){return t.announceBagOfCurves(this,e)}cloneStroked(t){const e=new Ee;let n;for(n of this.children)if(n instanceof st){const i=F.create();n.emitStrokes(i,t),i&&e.children.push(i)}else if(n instanceof ut){const i=n.cloneStroked(t);i&&e.children.push(i)}return e}cloneEmptyPeer(){return new Ee}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(t){return t&&this._children.push(t),!0}getChild(t){if(t<this._children.length)return this._children[t]}dispatchToGeometryHandler(t){return t.handleBagOfCurves(this)}}class Pt extends de{curveCollectionType="path";isSameGeometryClass(t){return t instanceof Pt}announceToCurveProcessor(t,e=-1){return t.announcePath(this,e)}constructor(){super()}static create(...t){const e=new Pt;for(const n of t)n instanceof xt?e.children.push(...n.path.children):n instanceof st?e.children.push(n):Array.isArray(n)&&n.length>0&&n[0]instanceof y&&e.children.push(F.create(n));return e}static createArray(t){return this.create(...t)}cloneStroked(t){const e=F.create();for(const n of this.children)n.emitStrokes(e,t);return Pt.create(e)}dgnBoundaryType(){return 1}cloneEmptyPeer(){return new Pt}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}dispatchToGeometryHandler(t){return t.handlePath(this)}}class Os{chainDistance0;chainDistance1;childFraction0;childFraction1;childCurve;range;a;constructor(t,e,n,i,s,r){this.childFraction0=t,this.childFraction1=e,this.chainDistance0=n,this.chainDistance1=i,this.childCurve=s,this.range=r,this.a=0}containsChainDistance(t){return t>=this.chainDistance0&&t<=this.chainDistance1}quickMinDistanceToChildCurve(t){if(this.range)return this.range.distanceToPoint(t);const e=this.childCurve.closestPoint(t,!1);return e?e.a:0}static collectSortedQuickMinDistances(t,e){const n=[];for(const i of t)i.a=i.quickMinDistanceToChildCurve(e),n.push(i);return n.sort((i,s)=>i.a-s.a),n}containsChildCurveAndChildFraction(t,e){return this.childCurve===t&&e>=this.childFraction0&&e<=this.childFraction1}chainDistanceToInterpolatedChildFraction(t){return f.inverseInterpolate(this.childFraction0,this.chainDistance0,this.childFraction1,this.chainDistance1,t,this.childFraction0)}chainDistanceToAccurateChildFraction(t,e){return this.childCurve.moveSignedDistanceFromFraction(this.childFraction0,t-this.chainDistance0,e??!1).fraction}fractionScaleFactor(t){return t*(this.childFraction1-this.childFraction0)/(this.chainDistance1-this.chainDistance0)}reverseFractionsAndDistances(t){const e=this.childFraction0,n=this.childFraction1,i=this.chainDistance0,s=this.chainDistance1;this.childFraction0=1-n,this.childFraction1=1-e,this.chainDistance0=t-s,this.chainDistance1=t-i}childFractionToChainDistance(t){let e=this.childCurve.curveLengthBetweenFractions(this.childFraction0,t);return t<this.childFraction0&&(e=-e),this.chainDistance0+e}}class qr{_fragments;_accumulatedDistance;constructor(){this._accumulatedDistance=0,this._fragments=[]}startParentCurvePrimitive(t){}startCurvePrimitive(t){}endParentCurvePrimitive(t){}endCurvePrimitive(t){}announcePointTangent(t,e,n){}announceSegmentInterval(t,e,n,i,s,r){const o=e.clone(),a=n.clone();let c=this._accumulatedDistance;if(i<=1)this._accumulatedDistance+=e.distance(n),this._fragments.push(new Os(s,r,c,this._accumulatedDistance,t,J.create(o,a)));else{let l;for(let d=1,h=s;d<=i;d++,h=l)l=f.interpolate(s,d/i,r),e.interpolate(l,n,a),c=this._accumulatedDistance,this._accumulatedDistance+=Math.abs(l-h)*e.distance(n),this._fragments.push(new Os(h,l,c,this._accumulatedDistance,t,J.create(o,a))),o.setFrom(a)}}announceIntervalForUniformStepStrokes(t,e,n,i){let s,r,o;for(let a=1,c=n;a<=e;a++,c=s){s=f.interpolate(n,a/e,i),r=t.curveLengthBetweenFractions(c,s),o=this._accumulatedDistance,this._accumulatedDistance+=r;const l=t.rangeBetweenFractions(c,s);this._fragments.push(new Os(c,s,o,this._accumulatedDistance,t,l))}}needPrimaryGeometryForStrokes(){return!0}static createPathFragmentIndex(t,e){const n=new qr;for(const s of t.children)s.emitStrokableParts(n,e);return n._fragments}}class xt extends st{curvePrimitiveType="curveChainWithDistanceIndex";_path;_fragments;_totalLength;static _numCalls=0;static _numTested=0;static _numAssigned=0;static _numCandidate=0;isSameGeometryClass(t){return t instanceof xt}constructor(t,e){super(),this._path=t instanceof Pt?t:Pt.create(...t.children),this._fragments=e,this._totalLength=e.length>0?e[e.length-1].chainDistance1:0}cloneTransformed(t,e){return xt.createCapture(this._path.cloneTransformed(t),e)}get path(){return this._path}get fragments(){return this._fragments}clone(t){return xt.createCapture(this._path.clone(),t)}clonePartialCurve(t,e,n){const i=t instanceof Y,s=e instanceof Y;let r=i?t.fraction:t,o=s?e.fraction:e;if(r===o)return;const a=r>o;a&&([r,o]=[o,r]);const c=r*this._totalLength,l=o*this._totalLength,d=this.chainDistanceToFragment(c,!0);if(!d)return;const h=this.chainDistanceToFragment(l,!0);if(!h)return;const g=this._path.childIndex(d.childCurve,!0);if(g===void 0)return;const m=this._path.childIndex(h.childCurve,!0);if(m===void 0)return;const p=i&&t.childDetail?t.childDetail.fraction:d.chainDistanceToAccurateChildFraction(c,!0),x=s&&e.childDetail?e.childDetail.fraction:h.chainDistanceToAccurateChildFraction(l,!0),_=Pt.create(),I=(v,S,w,T)=>{if(S===w)return!1;let R;return S===0&&w===1?(R=v.clone(),T&&R.reverseInPlace()):R=T?v.clonePartialCurve(w,S):v.clonePartialCurve(S,w),R?(_.children.push(R),!0):!1};if(d.childCurve===h.childCurve)return I(d.childCurve,p,x,a)?xt.createCapture(_,n):void 0;I(this._path.children[g],p,1,a);for(let v=g+1;v<m;v++)I(this._path.children[v],0,1,a);return I(this._path.children[m],0,x,a),a&&_.children.reverse(),xt.createCapture(_,n)}isInPlane(t){for(const e of this._path.children)if(!e.isInPlane(t))return!1;return!0}startPoint(t){return this._path.cyclicCurvePrimitive(0)?.startPoint(t)??y.createZero(t)}endPoint(t){return this._path.cyclicCurvePrimitive(-1)?.endPoint(t)??y.createZero(t)}emitStrokes(t,e){for(const n of this._path.children)n.emitStrokes(t,e)}emitStrokableParts(t,e){for(const n of this._path.children)n.emitStrokableParts(t,e)}computeStrokeCountForOptions(t){let e=0;for(const n of this._path.children)e+=n.computeStrokeCountForOptions(t);return e}collectCurvePrimitivesGo(t,e=!1,n=!1){if(e)for(const i of this._path.children)i.collectCurvePrimitivesGo(t,e,n);else t.push(this)}computeAndAttachRecursiveStrokeCounts(t,e){const n=dn.createWithCurvePrimitiveAndOptionalParent(this,e);for(const i of this._path.children)i.computeAndAttachRecursiveStrokeCounts(t,n);st.installStrokeCountMap(this,n,e)}dispatchToGeometryHandler(t){return t.handleCurveChainWithDistanceIndex(this)}extendRange(t,e){this._path.extendRange(t,e)}curveLengthBetweenFractions(t,e){return Math.abs(e-t)*this._totalLength}static flattenNestedChains(t){if(t.children.findIndex(i=>i instanceof xt)===-1)return t;const e=t.clone(),n=e.children.flatMap(i=>i instanceof xt?i.path.children:i);return e.children.splice(0,1/0,...n),e}static createCapture(t,e){t=this.flattenNestedChains(t);const n=qr.createPathFragmentIndex(t,e);return new xt(t,n)}chainDistanceToFragment(t,e=!1){const n=this.chainDistanceToFragmentIndex(t,e);if(n!==void 0)return this._fragments[n]}chainDistanceToFragmentIndex(t,e=!1){const n=this._fragments,i=n.length;if(i>0){if(t<0)return e?0:void 0;if(t>this._totalLength)return e?i-1:void 0;for(let s=0;s<i;s++)if(n[s].containsChainDistance(t))return s}}chainDistanceToChainFraction(t){return t/this._totalLength}curveAndChildFractionToFragment(t,e){const n=this._fragments.length,i=this._fragments;if(n>0){if(e<0)return i[0];if(e>1)return i[n-1];for(const s of i)if(s.containsChildCurveAndChildFraction(t,e))return s}}curveLength(){return this._totalLength}quickLength(){return this._totalLength}fractionToPoint(t,e){const n=t*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(i){const s=i.chainDistanceToAccurateChildFraction(n,!0);return i.childCurve.fractionToPoint(s,e)}return y.createZero(e)}fractionToPointAndDerivative(t,e){e=O.createZero(e);const n=t*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return e;const s=i.chainDistanceToAccurateChildFraction(n,!0);e=i.childCurve.fractionToPointAndDerivative(s,e);const r=f.safeDivideFraction(this._totalLength,e.direction.magnitude(),0);return e.direction.scaleInPlace(r),e}fractionToPointAndUnitTangent(t,e){e=O.createZero(e);const n=t*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return e;const s=i.chainDistanceToAccurateChildFraction(n,!0);return e=i.childCurve.fractionToPointAndDerivative(s,e),e.direction.normalizeInPlace(),e}fractionToPointAnd2Derivatives(t,e){const n=t*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return;const s=i.chainDistanceToAccurateChildFraction(n,!0);if(e=i.childCurve.fractionToPointAnd2Derivatives(s,e),!e)return;const r=e.vectorU.magnitude(),o=r*r,a=e.vectorU.dotProduct(e.vectorV),c=f.safeDivideFraction(-a,o,0);e.vectorV.addScaledInPlace(e.vectorU,c);const l=f.safeDivideFraction(this._totalLength,r,0);return e.vectorU.scaleInPlace(l),e.vectorV.scaleInPlace(l*l),e}tryTransformInPlace(t){return this._path.tryTransformInPlace(t)}reverseInPlace(){this._path.reverseChildrenInPlace();for(const t of this._fragments)t.reverseFractionsAndDistances(this._totalLength);this._fragments.reverse()}isAlmostEqual(t){return t instanceof xt?f.isSameCoordinate(this._totalLength,t._totalLength)&&this._path.isAlmostEqual(t._path):!1}moveSignedDistanceFromFraction(t,e,n,i){const r=t*this._totalLength+e,o=this.chainDistanceToFragment(r,!0);if(!o)return i=Y.create(void 0,i),i.curveSearchStatus=Me.error,i;const a=o.childCurve.moveSignedDistanceFromFraction(o.childFraction0,r-o.chainDistance0,n,i?.childDetail),c=t+e/this._totalLength,l=Y.createConditionalMoveSignedDistance(n,this,t,c,e,i);return l.childDetail=a,l}static getClosestPointTestCounts(t=!0){const e={numCalls:this._numCalls,numTested:this._numTested,numAssigned:this._numAssigned,numCandidate:this._numCandidate};return t&&(this._numTested=this._numAssigned=this._numCandidate=0),e}computeClosestPoint(t,e=!1,n,i=!1){let s,r=Number.MAX_VALUE;if(this.path.children.length===1)s=i?this.path.children[0].closestPointXY(t,e):this.path.children[0].closestPoint(t,e);else{const a=Os.collectSortedQuickMinDistances(this._fragments,t),c=[Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,0),Ht.None],l=[Ht.None,Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,1)],d=this._fragments[0],h=this._fragments[this._fragments.length-1];xt._numCalls++,xt._numCandidate+=a.length;let g;for(const m of a){if(m.a>r)break;xt._numTested++;const p=m.childCurve;e=p===d.childCurve?c:p===h.childCurve?l:!1,g=i?p.closestPointXY(t,e,g):p.closestPoint(t,e,g),g&&g.a<r&&(r=g.a,s=g.clone(s),xt._numAssigned++)}}if(s)return this.computeChainDetail(s,n)}closestPoint(t,e=!1,n){return this.computeClosestPoint(t,e,n)}closestPointXY(t,e=!1,n){return this.computeClosestPoint(t,e,n,!0)}constructOffsetXY(t){const e=Oe.create(t),n=[];for(const i of this.collectCurvePrimitives(void 0,!0,!0)){const s=i.constructOffsetXY(e);s!==void 0&&(s instanceof st?n.push(s):Array.isArray(s)&&s.forEach(r=>n.push(r)))}return n}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}computeChainDetail(t,e){if(!t.curve)return;const n=this.curveAndChildFractionToFragment(t.curve,t.fraction);if(n){const i=n.childFractionToChainDistance(t.fraction),s=this.chainDistanceToChainFraction(i),r=Y.createCurveFractionPoint(this,s,t.point,e);return r.childDetail=t,r.a=t.a,r}}static convertChildDetailToChainDetailSingle(t,e,n){if(e){const i=e.computeChainDetail(t.detailA);i&&(t.detailA=i)}if(n){const i=n.computeChainDetail(t.detailB);i&&(t.detailB=i)}return t}static convertChildDetailToChainDetail(t,e,n,i,s){for(let r=e;r<t.length;++r)t[r]=this.convertChildDetailToChainDetailSingle(t[r],n,i);return s&&(t=Ot.removeAdjacentDuplicates(t,e)),t}}class tt extends de{curveCollectionType="loop";isInner=!1;isSameGeometryClass(t){return t instanceof tt}constructor(){super()}static create(...t){const e=new tt;for(const n of t)n instanceof xt?e.children.push(...n.path.children):e.children.push(n);return e}static createArray(t){return this.create(...t)}static createPolygon(t){const e=F.create(t);return e.addClosurePoint(),tt.create(e)}cloneStroked(t){const e=F.create();for(const n of this.children)n.emitStrokes(e,t);return e.removeDuplicatePoints(),e.isPhysicallyClosed&&(e.popPoint(),e.addClosurePoint()),tt.create(e)}dgnBoundaryType(){return 2}announceToCurveProcessor(t,e=-1){return t.announceLoop(this,e)}cloneEmptyPeer(){const t=new tt;return t.isInner=this.isInner,t}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}dispatchToGeometryHandler(t){return t.handleLoop(this)}isAlmostEqual(t){return super.isAlmostEqual(t)?this.isInner===t.isInner:!1}}class oa{loopA;curveA;loopB;curveB;constructor(t,e,n,i){this.loopA=t,this.curveA=e,this.loopB=n,this.curveB=i}setA(t,e){this.loopA=t,this.curveA=e}setB(t,e){this.loopB=t,this.curveB=e}}class Hi{_vectorU;_vectorV;_point0;_point1;_tolerance;get tolerance(){return this._tolerance}constructor(t=f.smallMetricDistance){this._tolerance=t}static create(t=f.smallMetricDistance){return new Hi(t)}static assignDetailInterpolatedFractionsAndPoints(t,e,n,i,s,r=!1){r?(t.fraction=n,t.fraction1=e):(t.fraction=e,t.fraction1=n),t.point=i.interpolate(t.fraction,s,t.point),t.point1=i.interpolate(t.fraction1,s,t.point1)}projectPointToSegmentXY(t,e,n){this._vectorU=P.createStartEnd(e,n,this._vectorU),this._vectorV=P.createStartEnd(e,t,this._vectorV);const i=this._vectorU.dotProductXY(this._vectorU),s=this._vectorU.dotProductXY(this._vectorV),r=f.safeDivideFraction(s,i,0);return Y.createCurveFractionPoint(void 0,r,e.interpolate(r,n))}clampCoincidentOverlapToSegmentBounds(t,e,n,i,s,r=!1,o=!1,a=!1,c=!1){const l=qt.create(t.detailA.fraction,t.detailA.hasFraction1?t.detailA.fraction1:t.detailA.fraction),d=qt.create(t.detailB.fraction,t.detailB.hasFraction1?t.detailB.fraction1:t.detailB.fraction),h=l.signedDelta()<0,g=()=>{const v=l.x0,S=l.x1,w=d.x0,T=d.x1;return Hi.assignDetailInterpolatedFractionsAndPoints(t.detailA,v,S,e,n,v>S),Hi.assignDetailInterpolatedFractionsAndPoints(t.detailB,w,T,i,s,w>T),t},m=l.clampDirectedTo01(!r,!o,!1),p=d.clampDirectedTo01(!a,!c,!1);if(m&&p){if(f.isAlmostEqualNumber(l.absoluteDelta(),d.absoluteDelta(),f.smallFraction))return g();if(l.clampDirectedTo01(!0,!0,!1)&&d.clampDirectedTo01(!0,!0,!1))return g()}const x=(v,S,w,T)=>(v.clone(t.detailA.point),S.clone(t.detailB.point),t.detailA.fraction=w?0:1,t.detailB.fraction=T?0:1,t.detailA.collapseToStart(),t.detailB.collapseToStart(),t),_=l.clampDirectedTo01(!0,!0,!0),I=d.clampDirectedTo01(!0,!0,!0);if(_&&I){const v=t.detailA.point1??t.detailA.point;if(h){if(t.detailA.point.isAlmostEqual(e,this.tolerance))return x(e,i,!0,!0);if(v.isAlmostEqual(n,this.tolerance))return x(n,s,!1,!1)}else{if(v.isAlmostEqual(e,this.tolerance))return x(e,s,!0,!1);if(t.detailA.point.isAlmostEqual(n,this.tolerance))return x(n,i,!1,!0)}}}coincidentSegmentRangeXY(t,e,n,i){const s={x:e.x-t.x,y:e.y-t.y},r={x:i.x-n.x,y:i.y-n.y},o=bt.lineSegmentXYUVOverlapUnbounded(t,s,n,r,this._tolerance);if(!o||!o.f1)return;const a=Y.createCurveFractionPoint(void 0,o.f0.x,t.interpolate(o.f0.x,e));a.captureFraction1Point1(o.f1.x,t.interpolate(o.f1.x,e));const c=Y.createCurveFractionPoint(void 0,o.f0.y,n.interpolate(o.f0.y,i));return c.captureFraction1Point1(o.f1.y,n.interpolate(o.f1.y,i)),Ot.createCapture(a,c)}createDetailPair(t,e,n,i,s,r){const o=s-i,a=f.conditionalDivideFraction(n.x0-i,o),c=f.conditionalDivideFraction(n.x1-i,o);if(a!==void 0&&c!==void 0){const l=Y.createCurveEvaluatedFractionFraction(t,n.x0,n.x1),d=Y.createCurveEvaluatedFractionFraction(e,a,c);return r&&l.swapFractionsAndPoints(),Ot.createCapture(l,d)}}appendDetailPair(t,e){return e===void 0?t:t===void 0?[e]:(t.push(e),t)}coincidentArcIntersectionXY(t,e,n=!0){let i;if(t.center.isAlmostEqual(e.center,this.tolerance)){const s=t.matrixRef.multiplyMatrixInverseMatrix(e.matrixRef);if(s){const r=s.at(0,0),o=s.at(1,0),a=s.at(0,1),c=s.at(1,1),l=f.hypotenuseXY(r,o),d=f.hypotenuseXY(a,c),h=f.dotProductXYXY(r,o,a,c),g=f.crossProductXYXY(r,o,a,c);if(f.isAlmostEqualNumber(l,1)&&f.isAlmostEqualNumber(d,1)&&f.isAlmostEqualNumber(0,h)){const m=Math.atan2(o,r),p=g>0?1:-1,x=m+p*e.sweep.startRadians,_=m+p*e.sweep.endRadians,I=p*t.sweep.sweepRadians*e.sweep.sweepRadians<0,v=at.createStartEndRadians(x,_),S=t.sweep,w=S.fractionPeriod(),T=S.radiansToPositivePeriodicFraction(v.startRadians),R=v.sweepRadians/S.sweepRadians,L=T+R,z=qt.create(T,L),K=(rt,ft)=>{const wt=i?i.length:0,Yt=rt.x0,k=rt.x1;if(rt.clampDirectedTo01()&&!f.isSmallRelative(rt.absoluteDelta()))i=this.appendDetailPair(i,this.createDetailPair(t,e,rt,Yt,k,I));else{const E=I?ft:!ft,q=this._point0=ft?t.startPoint(this._point0):t.endPoint(this._point0),et=this._point1=E?e.startPoint(this._point1):e.endPoint(this._point1);if(q.isAlmostEqual(et,this.tolerance)){const Nt=Y.createCurveFractionPoint(t,ft?0:1,q),se=Y.createCurveFractionPoint(e,E?0:1,et);i=this.appendDetailPair(i,Ot.createCapture(Nt,se))}}return i!==void 0&&i.length>wt};K(z,!1),L>=w?K(qt.create(T-w,L-w),!0):T===0&&K(qt.create(T+w,L+w),!0)}}}return i}}class Mt extends st{_spiralType;_designProperties;_localToWorld;_activeFractionInterval;get activeFractionInterval(){return this._activeFractionInterval}get localToWorld(){return this._localToWorld}constructor(t,e,n,i){super(),this._spiralType=t||"unknownSpiralType",this._designProperties=i,this._localToWorld=e,this._activeFractionInterval=n||qt.create(0,1)}get spiralType(){return this._spiralType}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){return!1}static radiusToCurvature(t){return t===0?0:1/t}static curvatureToRadius(t){return Math.abs(t)<f.smallAngleRadians?0:1/t}clonePartialCurve(t,e){const n=this.clone(),i=this._activeFractionInterval.fractionToPoint(t),s=this._activeFractionInterval.fractionToPoint(e);return n._activeFractionInterval.set(i,s),n.refreshComputedProperties(),n}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}static averageCurvature(t){return .5*(Mt.radiusToCurvature(t.x0)+Mt.radiusToCurvature(t.x1))}static averageCurvatureR0R1(t,e){return .5*(Mt.radiusToCurvature(t)+Mt.radiusToCurvature(e))}static interpolateCurvatureR0R1(t,e,n){return f.interpolate(Mt.radiusToCurvature(t),e,Mt.radiusToCurvature(n))}static radiusRadiusSweepRadiansToArcLength(t,e,n){return Math.abs(n/Mt.averageCurvatureR0R1(t,e))}static radiusRadiusLengthToSweepRadians(t,e,n){return Mt.averageCurvatureR0R1(t,e)*n}static radius0LengthSweepRadiansToRadius1(t,e,n){return Mt.curvatureToRadius(2*n/e-Mt.radiusToCurvature(t))}static radius1LengthSweepRadiansToRadius0(t,e,n){return Mt.curvatureToRadius(2*n/e-Mt.radiusToCurvature(t))}get designProperties(){return this._designProperties}applyRigidPartOfTransform(t){const e=t.matrix.factorRigidWithSignedScale();if(e!==void 0){const n=t.multiplyTransformTransform(this.localToWorld),i=e.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);return this._localToWorld=X.createOriginAndMatrix(n.origin,i),this.designProperties&&this.designProperties.applyScaleFactor(e.scale),e}}constructOffsetXY(t){const e=Oe.create(t),n=new Vs(this,e.leftOffsetDistance);return this.emitStrokableParts(n,e.strokeOptions),n.claimResult()}extendRange(t,e){t.extendRange(this.rangeBetweenFractions(0,1,e))}rangeBetweenFractions(t,e,n){const i=this.activeStrokes;if(i===void 0)return J.createNull();let s=Math.ceil(i.numPoints()*Math.abs(e-t));return s=f.clamp(5,s,30),this.rangeBetweenFractionsByCount(t,e,s,n,.5)}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}}class zt extends Gi{_extendA0;_extendA1;_geometryB;_extendB0;_extendB1;_results;_worldToLocalPerspective;_worldToLocalAffine;_coincidentGeometryContext;static _workPointA0H=Z.create();static _workPointA1H=Z.create();static _workPointB0H=Z.create();static _workPointB1H=Z.create();static _workPointAA0=y.create();static _workPointAA1=y.create();static _workPointBB0=y.create();static _workPointBB1=y.create();static _workPointA0=y.create();static _workPointA1=y.create();static _workPointB0=y.create();static _workPointB1=y.create();_xyzwA0;_xyzwA1;_xyzwPlane;_xyzwB;constructor(t,e,n,i,s=f.smallMetricDistance){super(),this._extendA0=e,this._extendA1=e,this._geometryB=n instanceof Nr?n.proxyCurve:n,this._extendB0=i,this._extendB1=i,this._worldToLocalPerspective=void 0,this._worldToLocalAffine=void 0,t!==void 0&&!t.isIdentity()&&(this._worldToLocalAffine=t.asTransform,this._worldToLocalAffine||(this._worldToLocalPerspective=t.clone())),this._coincidentGeometryContext=Hi.create(s),this._results=[]}resetGeometryA(t,e){t!==void 0&&(this._extendA0=t),e!==void 0&&(this._extendA1=e)}resetGeometryB(t,e,n){t&&(this._geometryB=t),e!==void 0&&(this._extendB0=e),n!==void 0&&(this._extendB1=n)}acceptFraction(t,e,n,i=1e-12){return!(!t&&e<-i||!n&&e>1+i)}acceptFractionOnLine(t,e,n,i,s){if(!t&&e<0)return f.isDistanceWithinTol(e*e*i.distanceSquaredXY(s),this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance);if(!n&&e>1){const r=e-1;return f.isDistanceWithinTol(r*r*i.distanceSquaredXY(s),this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance)}return!0}grabPairedResults(t=!1){const e=this._results;return t&&(this._results=[]),e}recordPointWithLocalFractions(t,e,n,i,s,r,o,a,c,l,d){let h,g,m,p,x=!1;l&&l.detailA.isInterval()&&l.detailB.isInterval()?(x=!0,h=f.interpolate(n,l.detailA.fraction,i),g=f.interpolate(o,l.detailB.fraction,a),m=f.interpolate(n,l.detailA.fraction1,i),p=f.interpolate(o,l.detailB.fraction1,a)):(h=m=f.interpolate(n,t,i),g=p=f.interpolate(o,s,a));const _=this._results.length;if(_>0&&!x){const S=this._results[_-1].detailA,w=this._results[_-1].detailB;if(c){if(w.isSameCurveAndFraction({curve:e,fraction:h},d)&&S.isSameCurveAndFraction({curve:r,fraction:g},d))return}else if(S.isSameCurveAndFraction({curve:e,fraction:h},d)&&w.isSameCurveAndFraction({curve:r,fraction:g},d))return}const I=Y.createCurveFractionPoint(e,h,e.fractionToPoint(h)),v=Y.createCurveFractionPoint(r,g,r.fractionToPoint(g));x?(I.captureFraction1Point1(m,e.fractionToPoint(m)),v.captureFraction1Point1(p,r.fractionToPoint(p))):(I.setIntervalRole(Ct.isolated),v.setIntervalRole(Ct.isolated)),c?this._results.push(new Ot(v,I)):this._results.push(new Ot(I,v))}recordPairs(t,e,n,i){if(n!==void 0)for(const s of n)this.recordPointWithLocalFractions(s.detailA.fraction,t,0,1,s.detailB.fraction,e,0,1,i,s)}computeSegmentSegment3D(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p){const x={x:s.x-n.x,y:s.y-n.y},_={x:h.x-l.x,y:h.y-l.y},I=bt.lineSegmentXYUVIntersectionUnbounded(n,x,l,_,this._coincidentGeometryContext.tolerance);if(I)if(I.f1){const v=Y.createCurveFractionPoint(void 0,I.f0.x,n.interpolate(I.f0.x,s));v.captureFraction1Point1(I.f1.x,n.interpolate(I.f1.x,s));const S=Y.createCurveFractionPoint(void 0,I.f0.y,l.interpolate(I.f0.y,h));S.captureFraction1Point1(I.f1.y,l.interpolate(I.f1.y,h));const w=Ot.createCapture(v,S);this._coincidentGeometryContext.clampCoincidentOverlapToSegmentBounds(w,n,s,l,h,e,o,c,m)&&this.recordPointWithLocalFractions(w.detailA.fraction,t,i,r,w.detailB.fraction,a,d,g,p,w)}else this.acceptFractionOnLine(e,I.f0.x,o,n,s)&&this.acceptFractionOnLine(c,I.f0.y,m,l,h)&&this.recordPointWithLocalFractions(I.f0.x,t,i,r,I.f0.y,a,d,g,p)}computeSegmentSegment3DH(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p){if(this._worldToLocalPerspective===void 0)return;const x=zt._workPointA0H,_=zt._workPointA1H,I=zt._workPointB0H,v=zt._workPointB1H;this._worldToLocalPerspective.multiplyPoint3d(n,1,x),this._worldToLocalPerspective.multiplyPoint3d(s,1,_),this._worldToLocalPerspective.multiplyPoint3d(l,1,I),this._worldToLocalPerspective.multiplyPoint3d(h,1,v);const S=bt.lineSegment3dHXYTransverseIntersectionUnbounded(x,_,I,v);if(S!==void 0){const w=S.x,T=S.y;this.acceptFraction(e,w,o)&&this.acceptFraction(c,T,m)&&this.recordPointWithLocalFractions(w,t,i,r,T,a,d,g,p)}}dispatchSegmentSegment(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p){this._worldToLocalAffine?(zt.setTransformedWorkPoints(this._worldToLocalAffine,n,s,l,h),this.computeSegmentSegment3D(t,e,zt._workPointA0,i,zt._workPointA1,r,o,a,c,zt._workPointB0,d,zt._workPointB1,g,m,p)):this._worldToLocalPerspective?this.computeSegmentSegment3DH(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p):this.computeSegmentSegment3D(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p)}computeSegmentArc(t,e,n,i,s,r,o,a,c,l,d){const h=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance,g=new Ft(2),m=new Ft(2),p=new Ft(2),x=(ft,wt,Yt)=>f.isDistanceWithinTol(Yt,h)?(this.recordPointWithLocalFractions(ft,t,i,r,wt,a,0,1,d),!0):!1,_=a.toTransformedVectors(this._worldToLocalAffine);let I=n,v=s;const S=a.startPoint(),w=a.endPoint();this._worldToLocalAffine&&(I=this._worldToLocalAffine.multiplyPoint3d(n),v=this._worldToLocalAffine.multiplyPoint3d(s),this._worldToLocalAffine.multiplyXYAndZInPlace(S),this._worldToLocalAffine.multiplyXYAndZInPlace(w));const T=f.tripleProductXYW(I,1,v,1,_.center,1),R=f.tripleProductXYW(I,1,v,1,_.vector0,0),L=f.tripleProductXYW(I,1,v,1,_.vector90,0);let z=Xn.appendImplicitLineUnitCircleIntersections(T,R,L,g,m,p,h);const K=z===0;K&&(z=1);const rt=[];for(let ft=0;ft<z;ft++){const wt=_.center.plus2Scaled(_.vector0,g.atUncheckedIndex(ft),_.vector90,m.atUncheckedIndex(ft)),Yt=_.sweep.radiansToSignedFraction(p.atUncheckedIndex(ft),c),k=_.sweep.fractionToSignedPeriodicFraction(Yt,void 0),E=bt.lineSegment3dXYClosestPointUnbounded(I,v,wt);if(E!==void 0){const q=I.interpolate(E,v);rt.push({fArc:Yt,fArcNearest01:k,fLine:E,arcPt:wt,linePt:q})}}for(const ft of rt){const{fArc:wt,fArcNearest01:Yt,fLine:k,arcPt:E,linePt:q}=ft;if(K&&!f.isDistanceWithinTol(E.distanceSquaredXY(q),h))continue;if(this.acceptFraction(e,k,o)&&this.acceptFraction(c,wt,l)){this.recordPointWithLocalFractions(k,t,i,r,wt,a,0,1,d);continue}const et=c||l||f.isIn01(wt),Nt=e&&k<0||o&&k>1||f.isIn01(k);let se=!1;et&&!Nt?se=x(k<0?0:1,wt,(k<0?I:v).distanceSquaredXY(E)):!et&&Nt&&(se=x(k,Yt<0?0:1,q.distanceSquaredXY(Yt<0?S:w))),se||x(k<.5?0:1,Yt<.5?0:1,(k<.5?I:v).distanceSquaredXY(Yt<.5?S:w))}}computeSegmentArcHomogeneous(t,e,n,i,s,r,o,a,c,l,d){if(!this._worldToLocalPerspective)return;const h=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance,g=new Ft(2),m=new Ft(2),p=new Ft(2),x=(ft,wt,Yt)=>Yt===void 0||!f.isDistanceWithinTol(Yt,h)?!1:(this.recordPointWithLocalFractions(ft,t,i,r,wt,a,0,1,d),!0),_=a.toTransformedPoint4d(this._worldToLocalPerspective),I=this._worldToLocalPerspective.multiplyPoint3d(n,1),v=this._worldToLocalPerspective.multiplyPoint3d(s,1),S=this._worldToLocalPerspective.multiplyPoint3d(a.startPoint(),1),w=this._worldToLocalPerspective.multiplyPoint3d(a.endPoint(),1),T=f.tripleProductPoint4dXYW(I,v,_.center),R=f.tripleProductPoint4dXYW(I,v,_.vector0),L=f.tripleProductPoint4dXYW(I,v,_.vector90);let z=Xn.appendImplicitLineUnitCircleIntersections(T,R,L,g,m,p,h);const K=z===0;K&&(z=1);const rt=[];for(let ft=0;ft<z;ft++){const wt=_.center.plus2Scaled(_.vector0,g.atUncheckedIndex(ft),_.vector90,m.atUncheckedIndex(ft)),Yt=_.sweep.radiansToSignedFraction(p.atUncheckedIndex(ft),c),k=_.sweep.fractionToSignedPeriodicFraction(Yt,void 0),E=bt.lineSegment3dHXYClosestPointUnbounded(I,v,wt);if(E!==void 0){const q=I.interpolate(E,v);rt.push({fArc:Yt,fArcNearest01:k,fLine:E,arcPt:wt,linePt:q})}}for(const ft of rt){const{fArc:wt,fArcNearest01:Yt,fLine:k,arcPt:E,linePt:q}=ft;if(K){const Ne=E.realDistanceSquaredXY(q);if(Ne===void 0||!f.isDistanceWithinTol(Ne,h))continue}if(this.acceptFraction(e,k,o)&&this.acceptFraction(c,wt,l)){this.recordPointWithLocalFractions(k,t,i,r,wt,a,0,1,d);continue}const et=c||l||f.isIn01(wt),Nt=e&&k<0||o&&k>1||f.isIn01(k);let se=!1;et&&!Nt?se=x(k<0?0:1,wt,(k<0?I:v).realDistanceSquaredXY(E)):!et&&Nt&&(se=x(k,Yt<0?0:1,q.realDistanceSquaredXY(Yt<0?S:w))),se||x(k<.5?0:1,Yt<.5?0:1,(k<.5?I:v).realDistanceSquaredXY(Yt<.5?S:w))}}dispatchSegmentArc(t,e,n,i,s,r,o,a,c,l,d){this._worldToLocalPerspective?this.computeSegmentArcHomogeneous(t,e,n,i,s,r,o,a,c,l,d):this.computeSegmentArc(t,e,n,i,s,r,o,a,c,l,d)}dispatchArcArcThisOrder(t,e,n,i,s,r,o,a,c){const l=e.inverse();if(l){const d=l.multiplyMatrixMatrix(r),h=[],g=[];Mi.solveUnitCircleHomogeneousEllipseIntersection(d.coffs[2],d.coffs[5],d.coffs[8],d.coffs[0],d.coffs[3],d.coffs[6],d.coffs[1],d.coffs[4],d.coffs[7],h,g);const m=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance;for(let p=0;p<h.length;p++){let x=t.sweep.radiansToSignedFraction(g[p],n),_=s.sweep.radiansToSignedFraction(h[p],o);if(this.acceptFraction(n,x,i)&&this.acceptFraction(o,_,a))this.recordPointWithLocalFractions(x,t,0,1,_,s,0,1,c);else{x=t.sweep.fractionToSignedPeriodicFraction(x)<.5?0:1,_=s.sweep.fractionToSignedPeriodicFraction(_)<.5?0:1;const I=t.fractionToPoint(x,zt._workPointAA0),v=s.fractionToPoint(_,zt._workPointBB0),S=I.distanceSquaredXY(v);f.isDistanceWithinTol(S,m)&&this.recordPointWithLocalFractions(x,t,0,1,_,s,0,1,c)}}}}dispatchArcArc(t,e,n,i,s,r,o){if(this._coincidentGeometryContext&&!this._worldToLocalPerspective&&!this._worldToLocalAffine){const h=this._coincidentGeometryContext.coincidentArcIntersectionXY(t,i,!0);if(h){this.recordPairs(t,i,h,o);return}}let a,c;if(this._worldToLocalPerspective){const h=t.toTransformedPoint4d(this._worldToLocalPerspective),g=i.toTransformedPoint4d(this._worldToLocalPerspective);a=C.createColumnsXYW(h.vector0,h.vector0.w,h.vector90,h.vector90.w,h.center,h.center.w),c=C.createColumnsXYW(g.vector0,g.vector0.w,g.vector90,h.vector90.w,g.center,g.center.w)}else{const h=t.toTransformedVectors(this._worldToLocalAffine),g=i.toTransformedVectors(this._worldToLocalAffine);a=C.createColumnsXYW(h.vector0,0,h.vector90,0,h.center,1),c=C.createColumnsXYW(g.vector0,0,g.vector90,0,g.center,1)}const l=a.conditionNumber(),d=c.conditionNumber();l>d?this.dispatchArcArcThisOrder(t,a,e,n,i,c,s,r,o):this.dispatchArcArcThisOrder(i,c,s,r,t,a,e,n,!o)}dispatchArcBsplineCurve3d(t,e,n,i,s,r,o){let a;if(this._worldToLocalPerspective){const l=t.toTransformedPoint4d(this._worldToLocalPerspective);a=C.createColumnsXYW(l.vector0,l.vector0.w,l.vector90,l.vector90.w,l.center,l.center.w)}else{const l=t.toTransformedVectors(this._worldToLocalAffine);a=C.createColumnsXYW(l.vector0,0,l.vector90,0,l.center,1)}const c=a.inverse();if(c){const l=i.order,d=2*l-1,h=new Float64Array(l),g=new jt(d),m=c.at(0,0),p=c.at(0,1),x=0,_=c.at(0,2),I=c.at(1,0),v=c.at(1,1),S=0,w=c.at(1,2),T=c.at(2,0),R=c.at(2,1),L=0,z=c.at(2,2);let K;for(let rt=0;K=i.getSaturatedBezierSpan3dH(rt,K),!!K;rt++){this._worldToLocalPerspective?K.tryMultiplyMatrix4dInPlace(this._worldToLocalPerspective):this._worldToLocalAffine&&K.tryTransformInPlace(this._worldToLocalAffine),g.zero(),K.poleProductsXYZW(h,m,p,x,_),g.addSquaredSquaredBezier(h,1),K.poleProductsXYZW(h,I,v,S,w),g.addSquaredSquaredBezier(h,1),K.poleProductsXYZW(h,T,R,L,z),g.addSquaredSquaredBezier(h,-1);const ft=g.roots(0,!0);if(ft)for(const wt of ft){const Yt=K.fractionToParentFraction(wt),k=K.fractionToPoint4d(wt),E=k.dotProductXYZW(m,p,x,_),q=k.dotProductXYZW(I,v,S,w),et=t.sweep.radiansToSignedFraction(Math.atan2(q,E),e);this.acceptFraction(e,et,n)&&this.acceptFraction(s,Yt,r)&&this.recordPointWithLocalFractions(et,t,0,1,Yt,i,0,1,o)}}}}transformBeziers(t){if(this._worldToLocalAffine)for(const e of t)e.tryTransformInPlace(this._worldToLocalAffine);else if(this._worldToLocalPerspective)for(const e of t)e.tryMultiplyMatrix4dInPlace(this._worldToLocalPerspective)}getRanges(t){const e=[];e.length=0;for(const n of t)e.push(n.range());return e}dispatchBezierBezierStrokeFirst(t,e,n,i,s,r,o,a){this._xyzwA0||(this._xyzwA0=Z.create()),this._xyzwA1||(this._xyzwA1=Z.create()),this._xyzwPlane||(this._xyzwPlane=Z.create()),this._xyzwB||(this._xyzwB=Z.create()),t.fractionToPoint4d(0,this._xyzwA0);let c=0,l;const d=1e-5,h=1/n;for(let g=1;g<=n;g++,c=l,this._xyzwA0.setFrom(this._xyzwA1)){l=g*h,t.fractionToPoint4d(l,this._xyzwA1),Z.createPlanePointPointZ(this._xyzwA0,this._xyzwA1,this._xyzwPlane),i.poleProductsXYZW(o.coffs,this._xyzwPlane.x,this._xyzwPlane.y,this._xyzwPlane.z,this._xyzwPlane.w);const m=o.roots(0,!0);if(m){const p=this._coincidentGeometryContext.tolerance*1e-4;for(const x of m){let _=x;i.fractionToPoint4d(_,this._xyzwB);const I=bt.lineSegment3dHXYClosestPointUnbounded(this._xyzwA0,this._xyzwA1,this._xyzwB);if(I!==void 0&&f.isIn01WithTolerance(I,d)){let v=f.interpolate(c,I,l);const S=new Ko(t,i),w=new bs(S);w.setUV(v,_);let T=w.runIterations();v=w.getU(),_=w.getV();const R=t.fractionToParentFraction(v),L=i.fractionToParentFraction(_);if(this.acceptFraction(!1,R,!1)&&this.acceptFraction(!1,L,!1)){const z=t.fractionToPoint(v,zt._workPointA0),K=i.fractionToPoint(_,zt._workPointB0);T||(T=z.isAlmostEqualXY(K,p)),T&&this.recordPointWithLocalFractions(R,e,0,1,L,s,0,1,a)}}}}}}dispatchBSplineCurve3dBSplineCurve3d(t,e,n){const i=t.collectBezierSpans(!0),s=e.collectBezierSpans(!0),r=i.length,o=s.length;this.transformBeziers(i),this.transformBeziers(s);const a=this.getRanges(i),c=this.getRanges(s),l=t.order,d=e.order,h=new jt(l),g=new jt(d);for(let m=0;m<r;m++)for(let p=0;p<o;p++)if(a[m].intersectsRangeXY(c[p])){const x=i[m].computeStrokeCountForOptions(),_=s[p].computeStrokeCountForOptions();x<_?this.dispatchBezierBezierStrokeFirst(i[m],t,x,s[p],e,_,g,n):this.dispatchBezierBezierStrokeFirst(s[p],e,_,i[m],t,x,h,!n)}}projectPoint(t,e=1){return this._worldToLocalPerspective?this._worldToLocalPerspective.multiplyPoint3d(t,e):this._worldToLocalAffine?this._worldToLocalAffine.multiplyXYZW(t.x,t.y,t.z,e):Z.createFromPointAndWeight(t,e)}mapNPCPlaneToWorld(t,e){this._worldToLocalAffine?this._worldToLocalAffine.multiplyTransposeXYZW(t.x,t.y,t.z,t.w,e):this._worldToLocalPerspective?this._worldToLocalPerspective.multiplyTransposePoint4d(t,e):t.clone(e)}dispatchSegmentBsplineCurve(t,e,n,i,s,r,o,a,c,l,d){const h=this.projectPoint(n),g=this.projectPoint(s),m=Z.createPlanePointPointZ(h,g);this.mapNPCPlaneToWorld(m,m);const p=[];a.appendPlaneIntersectionPoints(m,p);for(const x of p){const _=x.fraction,I=x.point,v=this.projectPoint(I),S=bt.lineSegment3dHXYClosestPointUnbounded(h,g,v);S!==void 0&&this.acceptFraction(e,S,o)&&this.acceptFraction(c,_,l)&&this.recordPointWithLocalFractions(S,t,i,r,_,a,0,1,d)}}dispatchLineStringBSplineCurve(t,e,n,i,s,r,o){const a=t.numPoints();if(a>1){const c=1/(a-1);let l,d;l=0;const h=zt._workPointA0,g=zt._workPointA1;t.pointAt(0,h);for(let m=1;m<a;m++,h.setFrom(g),l=d)t.pointAt(m,g),d=m*c,this.dispatchSegmentBsplineCurve(t,m===1&&e,h,l,g,d,m+1===a&&n,i,s,r,o)}}computeSegmentLineString(t,e,n,i,s,r,o){const a=t.point0Ref,c=t.point1Ref,l=zt._workPointBB0,d=zt._workPointBB1,h=i.numPoints();if(h>1){const g=1/(h-1);let m,p;m=0,i.pointAt(0,l);for(let x=1;x<h;x++,l.setFrom(d),m=p)i.pointAt(x,d),p=x*g,this.dispatchSegmentSegment(t,e,a,0,c,1,n,i,x===1&&s,l,m,d,p,x+1===h&&r,o)}}computeArcLineString(t,e,n,i,s,r,o){const a=zt._workPointBB0,c=zt._workPointBB1,l=i.numPoints();if(l>1){const d=1/(l-1);let h,g;h=0,i.pointAt(0,a);for(let m=1;m<l;m++,a.setFrom(c),h=g)i.pointAt(m,c),g=m*d,this.dispatchSegmentArc(i,m===1&&s,a,h,c,g,m+1===l&&r,t,e,n,!o)}}computeLineStringLineString(t,e,n,i,s,r,o){const a=zt._workPointAA0,c=zt._workPointAA1,l=zt._workPointBB0,d=zt._workPointBB1,h=t.numPoints(),g=i.numPoints();if(h>1&&g>1){t.pointAt(0,a);const m=1/(h-1),p=1/(g-1);let x=0,_,I,v;t.pointAt(0,a);for(let S=1;S<h;S++,a.setFrom(c),x=I){I=S*m,_=0,t.pointAt(S,c),i.pointAt(0,l);for(let w=1;w<g;w++,l.setFrom(d),_=v)i.pointAt(w,d),v=w*p,this.dispatchSegmentSegment(t,S===1&&e,a,x,c,I,S+1===h&&n,i,w===1&&s,l,_,d,v,w+1===g&&r,o)}}}static setTransformedWorkPoints(t,e,n,i,s){t.multiplyPoint3d(e,this._workPointA0),t.multiplyPoint3d(n,this._workPointA1),t.multiplyPoint3d(i,this._workPointB0),t.multiplyPoint3d(s,this._workPointB1)}dispatchCurveCollection(t,e){const n=this._geometryB;if(!n||!n.children||!(n instanceof ut))return;const i=n.children,s=this._extendB0,r=this._extendB1;for(let o=0;o<i.length;o++){let a=s,c=r;n instanceof Pt&&i.length>1?o===0?c=!1:o===i.length-1?a=!1:a=c=!1:n instanceof tt&&(a=c=!1),this.resetGeometryB(i[o],a,c),e(t)}this.resetGeometryB(n,s,r)}dispatchCurveChainWithDistanceIndex(t,e){if(!this._geometryB||!(this._geometryB instanceof xt))return;const n=this._results.length,i=this._geometryB;this.resetGeometryB(i.path),this.dispatchCurveCollection(t,e),this.resetGeometryB(i),this._results=xt.convertChildDetailToChainDetail(this._results,n,void 0,i,!0)}refineSpiralResultsByNewton(t,e,n,i=!1){if(n>=this._results.length)return;const s=new Ko(t,e),r=50,o=new bs(s,r),a=2*o.stepSizeTolerance,c=Ot.comparePairsByFractions(a,this._coincidentGeometryContext.tolerance,!0),l=new jn(c,En.Retain),d=(g,m,p,x,_,I)=>{const v=Y.createCurveFractionPoint(g,m,p),S=Y.createCurveFractionPoint(x,_,I);v.setIntervalRole(Ct.isolated),S.setIntervalRole(Ct.isolated),l.insert(new Ot(i?S:v,i?v:S))},h=this._coincidentGeometryContext.tolerance*1e-4;for(let g=n;g<this._results.length;g++){const m=this._results[g],p=i?m.detailB:m.detailA,x=i?m.detailA:m.detailB;x.curve instanceof F;const _=i?this._extendB0:this._extendA0,I=i?this._extendB1:this._extendA1;o.setUV(p.fraction,x.fraction);let v=o.runIterations();const S=o.getU(),w=o.getV();if(this.acceptFraction(_,S,I)&&this.acceptFraction(!1,w,!1,f.smallFraction)){const T=t.fractionToPoint(S,zt._workPointA0),R=e.fractionToPoint(w,zt._workPointB0);v||(v=T.isAlmostEqualXY(R,h)),v&&d(t,S,T,e,w,R)}}this._results.splice(n,this._results.length-n,...l.extractArray())}strokeCurve(t,e,n){const i=n||F.create();return t.emitStrokes(i,e),i}computeMaxSpiralStrokeError(t,e,n,i){let s=0;if(e.numEdges()>0){const r=t.fractionToCurvature(0),o=t.fractionToCurvature(1),a=r!==void 0&&o!==void 0&&Math.abs(r)>Math.abs(o)?0:e.numEdges()-1,c=y.create(),l=Y.create();if(e.packedPoints.interpolateIndexIndex(a,.5,a+1,c)&&t.closestPoint(c,!1,l)&&(s=l.a),n&&n instanceof Mt&&i&&i instanceof F){const d=this.computeMaxSpiralStrokeError(n,i);d>s&&(s=d)}}return s}appendDiscreteIntersectionResults(t,e,n,i,s){const r=this._results.length,o=this._geometryB,a=this._extendB0,c=this._extendB1;if(this.resetGeometryA(!1,!1),this.resetGeometryB(t,e,n),this.handleLineString3d(i),!s)for(let l=r;l<this._results.length;l++)this._results[l].swapDetails();return this.resetGeometryA(e,n),this.resetGeometryB(o,a,c),this._results.length-r}appendDiscreteCloseApproachResults(t,e,n,i){const s=this._results.length,r=He.closeApproachProjectedXYPairs(i?e:t,i?t:e,n);return r.sort((o,a)=>o.detailA.a-a.detailA.a),this._results.push(...r),this._results.length-s}dispatchCurveSpiral(t,e,n,i,s){let r=t;t instanceof Mt&&(r=this.strokeCurve(t),e=n=!1);const o=this.strokeCurve(i),a=1.01*this.computeMaxSpiralStrokeError(i,o,t,r),c=this._results.length;this.appendDiscreteIntersectionResults(r,e,n,o,s),this.appendDiscreteCloseApproachResults(r,o,a,s),this.refineSpiralResultsByNewton(t,i,c,s)}handleChildren(t){const e=t.children;if(!e)return;const n=this._extendA0,i=this._extendA1;for(let s=0;s<e.length;s++){let r=n,o=i;t instanceof Pt&&e.length>1?s===0?o=!1:s===e.length-1?r=!1:r=o=!1:t instanceof tt&&(r=o=!1),this.resetGeometryA(r,o),e[s].dispatchToGeometryHandler(this)}this.resetGeometryA(n,i)}handleLineSegment3d(t){if(this._geometryB instanceof U){const e=this._geometryB;this.dispatchSegmentSegment(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,e,this._extendB0,e.point0Ref,0,e.point1Ref,1,this._extendB1,!1)}else this._geometryB instanceof F?this.computeSegmentLineString(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof N?this.dispatchSegmentArc(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof me?this.dispatchSegmentBsplineCurve(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof Mt?this.dispatchCurveSpiral(t,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineSegment3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineSegment3d.bind(this))}handleLineString3d(t){if(this._geometryB instanceof F){const e=this._geometryB;this.computeLineStringLineString(t,this._extendA0,this._extendA1,e,this._extendB0,this._extendB1,!1)}else this._geometryB instanceof U?this.computeSegmentLineString(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.computeArcLineString(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof me?this.dispatchLineStringBSplineCurve(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof Mt?this.dispatchCurveSpiral(t,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineString3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineString3d.bind(this))}handleArc3d(t){this._geometryB instanceof U?this.dispatchSegmentArc(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof F?this.computeArcLineString(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof N?this.dispatchArcArc(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof me?this.dispatchArcBsplineCurve3d(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof Mt?this.dispatchCurveSpiral(t,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleArc3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleArc3d.bind(this))}handleBSplineCurve3d(t){this._geometryB instanceof U?this.dispatchSegmentBsplineCurve(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof F?this.dispatchLineStringBSplineCurve(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.dispatchArcBsplineCurve3d(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof Ns?this.dispatchBSplineCurve3dBSplineCurve3d(t,this._geometryB,!1):this._geometryB instanceof Mt?this.dispatchCurveSpiral(t,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleBSplineCurve3d.bind(this))}handleTransitionSpiral(t){this._geometryB instanceof xt?this.dispatchCurveChainWithDistanceIndex(t,this.handleTransitionSpiral.bind(this)):this._geometryB instanceof st?this.dispatchCurveSpiral(this._geometryB,this._extendB0,this._extendB1,t,!0):this._geometryB instanceof ut&&this.dispatchCurveCollection(t,this.handleTransitionSpiral.bind(this))}handleCurveChainWithDistanceIndex(t){super.handleCurveChainWithDistanceIndex(t),this._results=xt.convertChildDetailToChainDetail(this._results,0,t,void 0,!0)}handleBSplineCurve3dH(t){}}class hn extends Gi{_extendA0;_extendA1;_geometryB;_extendB0;_extendB1;_results;static _workVector2dA=Q.create();static _workPointAA0=y.create();static _workPointAA1=y.create();static _workPointBB0=y.create();static _workPointBB1=y.create();constructor(t,e,n){super(),this._extendA0=t,this._extendA1=t,this._geometryB=e,this._extendB0=n,this._extendB1=n,this._results=[]}resetGeometry(t){this._geometryB=t}grabPairedResults(t=!1){const e=this._results;return t&&(this._results=[]),e}acceptFraction(t,e,n,i=1e-12){return!(!t&&e<-i||!n&&e>1+i)}recordPointWithLocalFractions(t,e,n,i,s,r,o,a,c){const l=f.interpolate(n,t,i),d=f.interpolate(o,s,a),h=this._results.length;if(h>0){const _=this._results[h-1].detailA,I=this._results[h-1].detailB;if(c){if(I.isSameCurveAndFraction({curve:e,fraction:l})&&_.isSameCurveAndFraction({curve:r,fraction:d}))return}else if(_.isSameCurveAndFraction({curve:e,fraction:l})&&I.isSameCurveAndFraction({curve:r,fraction:d}))return}const g=e.fractionToPoint(l),m=r.fractionToPoint(d);if(!g.isAlmostEqualMetric(m))return;const p=Y.createCurveFractionPoint(e,l,g);p.setIntervalRole(Ct.isolated);const x=Y.createCurveFractionPoint(r,d,m);if(x.setIntervalRole(Ct.isolated),c){const _=new Ot(x,p);this._results.push(_)}else{const _=new Ot(p,x);this._results.push(_)}}computeSegmentSegment3D(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p){const x=hn._workVector2dA;bt.lineSegment3dClosestApproachUnbounded(n,s,l,h,x)&&this.acceptFraction(e,x.x,o)&&this.acceptFraction(c,x.y,m)&&this.recordPointWithLocalFractions(x.x,t,i,r,x.y,a,d,g,p)}dispatchSegmentSegment(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p){this.computeSegmentSegment3D(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p)}createPlaneWithPreferredPerpendicular(t,e,n,i,s){n=f.restrictToInterval(Math.abs(n),0,1-f.smallFraction);const r=e.magnitudeSquared(),o=i.magnitudeSquared(),a=Math.abs(e.dotProduct(i)),c=e.unitCrossProduct(a*a<=n*n*r*o?i:s);if(c)return ht.create(t,c)}dispatchSegmentArc(t,e,n,i,s,r,o,a,c,l,d){const h=P.createStartEnd(n,s),m=this.createPlaneWithPreferredPerpendicular(n,h,.94,a.perpendicularVector,a.vector0);if(m!==void 0){const p=[];a.appendPlaneIntersectionPoints(m,p);let x,_;for(const I of p){const v=a.sweep.fractionToSignedPeriodicFraction(I.fraction,c);this.acceptFraction(c,v,l)&&(x=bt.lineSegment3dClosestPointUnbounded(n,s,I.point),x!==void 0&&(_=n.interpolate(x,s,_),_.isAlmostEqualMetric(I.point)&&this.acceptFraction(e,x,o)&&this.recordPointWithLocalFractions(x,t,i,r,v,a,0,1,d)))}}}dispatchArcArcInPlane(t,e,n,i,s,r,o){const a=t.otherArcAsLocalVectors(i);if(a!==void 0){const c=[],l=[];Mi.solveUnitCircleHomogeneousEllipseIntersection(a.center.x,a.center.y,1,a.vector0.x,a.vector0.y,0,a.vector90.x,a.vector90.y,0,c,l);for(let d=0;d<c.length;d++){const h=t.sweep.radiansToSignedFraction(l[d],e),g=i.sweep.radiansToSignedFraction(c[d],s);this.acceptFraction(e,h,n)&&this.acceptFraction(s,g,r)&&this.recordPointWithLocalFractions(h,t,0,1,g,i,0,1,o)}}}dispatchArcArc(t,e,n,i,s,r,o){const a=ht.create(t.center,t.perpendicularVector),c=ht.create(i.center,i.perpendicularVector);if(!(a===void 0||c===void 0))if(a.getNormalRef().isParallelTo(c.getNormalRef()))a.isPointInPlane(c.getOriginRef())&&c.isPointInPlane(a.getOriginRef())&&this.dispatchArcArcInPlane(t,e,n,i,s,r,o);else{const l=[];i.appendPlaneIntersectionPoints(a,l);const d=[];t.appendPlaneIntersectionPoints(c,d);for(const h of l)for(const g of d)if(g.point.isAlmostEqual(h.point)){const m=t.sweep.fractionToSignedPeriodicFraction(g.fraction,e),p=i.sweep.fractionToSignedPeriodicFraction(h.fraction,s);this.acceptFraction(e,m,n)&&this.acceptFraction(s,p,r)&&this.recordPointWithLocalFractions(m,t,0,1,p,i,0,1,o)}}}dispatchArcBsplineCurve3d(t,e,n,i,s,r,o){}dispatchBSplineCurve3dBSplineCurve3d(t,e,n){}dispatchSegmentBsplineCurve(t,e,n,i,s,r,o,a,c,l,d){}dispatchLineStringBSplineCurve(t,e,n,i,s,r,o){}computeSegmentLineString(t,e,n,i,s,r,o){const a=t.point0Ref,c=t.point1Ref,l=hn._workPointBB0,d=hn._workPointBB1,h=i.numPoints();if(h>1){const g=1/(h-1);let m,p;m=0,i.pointAt(0,l);for(let x=1;x<h;x++,l.setFrom(d),m=p)i.pointAt(x,d),p=x*g,this.dispatchSegmentSegment(t,e,a,0,c,1,n,i,x===1&&s,l,m,d,p,x+1===h&&r,o)}}computeArcLineString(t,e,n,i,s,r,o){const a=hn._workPointBB0,c=hn._workPointBB1,l=i.numPoints();if(l>1){const d=1/(l-1);let h,g;h=0,i.pointAt(0,a);for(let m=1;m<l;m++,a.setFrom(c),h=g)i.pointAt(m,c),g=m*d,this.dispatchSegmentArc(i,m===1&&s,a,h,c,g,m+1===l&&r,t,e,n,!o)}}computeLineStringLineString(t,e,n){const i=hn._workPointAA0,s=hn._workPointAA1,r=hn._workPointBB0,o=hn._workPointBB1,a=t.numPoints(),c=e.numPoints();if(a>1&&c>1){t.pointAt(0,i);const l=1/(a-1),d=1/(c-1);let h=0,g,m,p;t.pointAt(0,i);for(let x=1;x<a;x++,i.setFrom(s),h=m){m=x*l,g=0,t.pointAt(x,s),e.pointAt(0,r);for(let _=1;_<c;_++,r.setFrom(o),g=p)e.pointAt(_,o),p=_*d,this.dispatchSegmentSegment(t,x===1&&this._extendA0,i,h,s,m,x+1===a&&this._extendA1,e,_===1&&this._extendB0,r,g,o,p,_+1===c&&this._extendB1,n)}}}dispatchCurveCollection(t,e){const n=this._geometryB;if(!n||!n.children||!(n instanceof ut))return;const i=n.children,s=this._extendB0,r=this._extendB1;for(let o=0;o<i.length;o++)this.resetGeometry(i[o]),n instanceof Pt&&i.length>1?o===0?this._extendB1=!1:o===i.length-1?this._extendB0=!1:this._extendB0=this._extendB1=!1:n instanceof tt&&(this._extendB0=this._extendB1=!1),e(t),this._extendB0=s,this._extendB1=r;this.resetGeometry(n)}dispatchCurveChainWithDistanceIndex(t,e){if(!this._geometryB||!(this._geometryB instanceof xt))return;const n=this._results.length,i=this._geometryB;this.resetGeometry(i.path),this.dispatchCurveCollection(t,e),this.resetGeometry(i),this._results=xt.convertChildDetailToChainDetail(this._results,n,void 0,i,!0)}handleChildren(t){const e=t.children,n=this._extendA0,i=this._extendA1;if(e)for(let s=0;s<e.length;s++)t instanceof Pt&&e.length>1?s===0?this._extendA1=!1:s===e.length-1?this._extendA0=!1:this._extendA0=this._extendA1=!1:t instanceof tt&&(this._extendA0=this._extendA1=!1),e[s].dispatchToGeometryHandler(this),this._extendA0=n,this._extendA1=i}handleLineSegment3d(t){if(this._geometryB instanceof U){const e=this._geometryB;this.dispatchSegmentSegment(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,e,this._extendB0,e.point0Ref,0,e.point1Ref,1,this._extendB1,!1)}else this._geometryB instanceof F?this.computeSegmentLineString(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof N?this.dispatchSegmentArc(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof me?this.dispatchSegmentBsplineCurve(t,this._extendA0,t.point0Ref,0,t.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineSegment3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineSegment3d.bind(this))}handleLineString3d(t){if(this._geometryB instanceof F){const e=this._geometryB;this.computeLineStringLineString(t,e,!1)}else this._geometryB instanceof U?this.computeSegmentLineString(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.computeArcLineString(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof me?this.dispatchLineStringBSplineCurve(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineString3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineString3d.bind(this))}handleArc3d(t){this._geometryB instanceof U?this.dispatchSegmentArc(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof F?this.computeArcLineString(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof N?this.dispatchArcArc(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof me?this.dispatchArcBsplineCurve3d(t,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleArc3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleArc3d.bind(this))}handleBSplineCurve3d(t){this._geometryB instanceof U?this.dispatchSegmentBsplineCurve(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof F?this.dispatchLineStringBSplineCurve(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.dispatchArcBsplineCurve3d(this._geometryB,this._extendB0,this._extendB1,t,this._extendA0,this._extendA1,!0):this._geometryB instanceof Ns?this.dispatchBSplineCurve3dBSplineCurve3d(t,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleBSplineCurve3d.bind(this))}handleCurveChainWithDistanceIndex(t){super.handleCurveChainWithDistanceIndex(t),this._results=xt.convertChildDetailToChainDetail(this._results,0,t,void 0,!0)}handleBSplineCurve3dH(t){}}class He{static intersectionXYPairs(t,e,n,i,s=f.smallMetricDistance){return He.intersectionProjectedXYPairs(void 0,t,e,n,i,s)}static intersectionProjectedXYPairs(t,e,n,i,s,r=f.smallMetricDistance){const o=new zt(t,n,i,s,r);return e.dispatchToGeometryHandler(o),o.grabPairedResults()}static intersectionXYZPairs(t,e,n,i){const s=new hn(e,n,i);return t.dispatchToGeometryHandler(s),s.grabPairedResults()}static allIntersectionsAmongPrimitivesXY(t,e=f.smallMetricDistance){const n=new zt(void 0,!1,void 0,!1,e);for(let i=0;i<t.length;i++){const s=t[i];for(let r=i+1;r<t.length;r++)n.resetGeometryB(t[r]),s.dispatchToGeometryHandler(n)}return n.grabPairedResults()}static closeApproachProjectedXYPairs(t,e,n=f.largeCoordinateResult){const i=f.isNumber(n),s=i?n:n.maxDistance??f.largeCoordinateResult,r=i?void 0:n.xyTolerance,o=i?void 0:n.newtonTolerance,a=i?void 0:n.maxIterations,c=new Re(e,r,o,a);return c.maxDistanceToAccept=s,t.dispatchToGeometryHandler(c),c.grabPairedResults()}static closestApproachProjectedXYPair(t,e,n){n===void 0&&(n={maxDistance:f.largeCoordinateResult});const i=this.closeApproachProjectedXYPairs(t,e,n);if(!i.length)return;let s=0,r=f.largeCoordinateResult;for(let o=0;o<i.length;++o){const a=i[o].detailA.a;a<r&&(s=o,r=a)}return i[s]}}class Re extends Gi{_geometryB;_maxDistanceToAccept;_maxDistanceSquared;_xyTolerance;_newtonTolerance;_maxIterations;_results;static _workPointAA0=y.create();static _workPointAA1=y.create();static _workPointBB0=y.create();static _workPointBB1=y.create();static _workPointB=y.create();constructor(t,e=f.smallMetricDistance,n=f.smallNewtonStep,i=50){super(),this._geometryB=t instanceof Nr?t.proxyCurve:t,this._maxDistanceSquared=f.smallMetricDistanceSquared,this._xyTolerance=e,this._newtonTolerance=n,this._maxIterations=i;const s=Ot.comparePairsByPoints(e,!0);this._results=new jn(s,En.Retain)}set maxDistanceToAccept(t){t===void 0?(this._maxDistanceToAccept=void 0,this._maxDistanceSquared=f.smallMetricDistanceSquared):(this._maxDistanceToAccept=Math.abs(t),this._maxDistanceSquared=t*t)}get maxDistanceToAccept(){return this._maxDistanceToAccept}get isMaxDistanceSet(){return this._maxDistanceToAccept!==void 0&&this._maxDistanceToAccept>0}resetGeometry(t){t&&(this._geometryB=t)}acceptFraction(t,e=1e-12){return!(t<-e||t>1+e)}grabPairedResults(){return this._results.extractArray()}testAndRecordPointPair(t,e,n,i,s,r,o){n||(n=t.fractionToPoint(e)),r||(r=i.fractionToPoint(s));const a=n.distanceSquaredXY(r);if(a<=this._maxDistanceSquared){const c=Math.sqrt(a),l=Y.createCurveFractionPointDistance(t,e,n,c),d=Y.createCurveFractionPointDistance(i,s,r,c);l.setIntervalRole(Ct.isolated),d.setIntervalRole(Ct.isolated);const h=Ot.createCapture(l,d);o&&h.swapDetails(),this._results.insert(h)}}testAndRecordPair(t,e){const n=t.detailA.point.distanceSquaredXY(t.detailB.point);if(n>this._maxDistanceSquared)return;const i=Math.sqrt(n);t.detailA.a=t.detailB.a=i,t.detailA.setIntervalRole(Ct.isolated),t.detailB.setIntervalRole(Ct.isolated),e&&t.swapDetails(),this._results.insert(t)}testAndRecordLocalPair(t,e,n,i,s,r,o,a){const c=f.interpolate(n,t.detailA.fraction,i),l=f.interpolate(r,t.detailB.fraction,o),d=e.fractionToPoint(c),h=s.fractionToPoint(l),g=d.distanceSquaredXY(h);if(g>this._maxDistanceSquared)return;const m=Math.sqrt(g);Y.createCurveFractionPointDistance(e,c,d,m,t.detailA),Y.createCurveFractionPointDistance(s,l,h,m,t.detailB),t.detailA.setIntervalRole(Ct.isolated),t.detailB.setIntervalRole(Ct.isolated),a&&t.swapDetails(),this._results.insert(t)}static updatePointToSegmentDistance(t,e,n,i,s,r,o){let a=!1;i<0?i=0:i>1&&(i=1);const c=s.interpolate(i,r,this._workPointB),l=c.distanceSquaredXY(n);return l<=Math.min(o,t.detailA.a)&&(t.detailA.setFP(e,n,void 0,l),t.detailB.setFP(i,c,void 0,l),a=!0),a}static segmentSegmentBoundedApproach(t,e,n,i,s){const r=e.x-t.x,o=e.y-t.y,a=i.x-n.x,c=i.y-n.y,l=n.x-t.x,d=n.y-t.y,h=i.x-t.x,g=i.y-t.y,m=n.x-e.x,p=n.y-e.y,x=f.crossProductXYXY(r,o,l,d),_=f.crossProductXYXY(r,o,h,g),I=-f.crossProductXYXY(a,c,l,d),v=-f.crossProductXYXY(a,c,m,p);if(x*_<0&&I*v<0){const L=-I/(v-I),z=-x/(_-x);return Ot.createCapture(Y.createCurveFractionPoint(void 0,L,t.interpolate(L,e)),Y.createCurveFractionPoint(void 0,z,n.interpolate(z,i)))}const S=new Ot;S.detailA.a=2*s;let w=!1;const T=f.hypotenuseSquaredXY(r,o);if(x*x<=s*T){const L=f.safeDivideFraction(f.dotProductXYXY(r,o,l,d),T,0);this.updatePointToSegmentDistance(S,0,n,L,t,e,s)&&(w=!0)}if(_*_<=s*T){const L=f.safeDivideFraction(f.dotProductXYXY(r,o,h,g),T,0);this.updatePointToSegmentDistance(S,1,i,L,t,e,s)&&(w=!0)}const R=f.hypotenuseSquaredXY(a,c);if(I*I<=s*R){const L=f.safeDivideFraction(-f.dotProductXYXY(a,c,l,d),R,0);this.updatePointToSegmentDistance(S,0,t,L,n,i,s)&&(w=!1)}if(v*v<=s*R){const L=f.safeDivideFraction(-f.dotProductXYXY(a,c,m,p),R,0);this.updatePointToSegmentDistance(S,1,e,L,n,i,s)&&(w=!1)}if(!(S.detailA.a>s))return w&&S.swapDetails(),S}testAndRecordEndPointApproaches(t,e,n){const i=Re._workPointB,s=r=>r instanceof N&&r.sweep.isFullCircle;s(t)||(this.testAndRecordProjection(t,0,t.startPoint(i),e,n),this.testAndRecordProjection(t,1,t.endPoint(i),e,n)),s(e)||(this.testAndRecordProjection(e,0,e.startPoint(i),t,!n),this.testAndRecordProjection(e,1,e.endPoint(i),t,!n))}testAndRecordProjection(t,e,n,i,s){const r=i.closestPointXY(n);r&&this.testAndRecordPointPair(t,e,n,i,r.fraction,r.point,s)}computeSegmentSegment(t,e,n,i,s,r,o,a,c,l,d){const h=Re.segmentSegmentBoundedApproach(e,i,o,c,this._maxDistanceSquared);h&&(h.detailA.setCurve(t),h.detailB.setCurve(r),this.testAndRecordLocalPair(h,t,n,s,r,a,l,d))}announceAllPerpendicularsSegmentArcBounded(t,e,n,i){const s=n.vector0.crossProductStartEndXY(t,e),r=n.vector90.crossProductStartEndXY(t,e),o=Math.atan2(r,s);for(const a of[o,o+Math.PI]){const c=n.radiansToPoint(a),l=n.sweep.radiansToSignedPeriodicFraction(a);if(this.acceptFraction(l)){const d=bt.lineSegment3dXYClosestPointUnbounded(t,e,c);d!==void 0&&this.acceptFraction(d)&&i(d,void 0,l,c)}}}computeSegmentArc(t,e,n){let i=!1;const s=e.toTransformedVectors(),r=f.tripleProductXYW(t.point0Ref,1,t.point1Ref,1,s.center,1),o=f.tripleProductXYW(t.point0Ref,1,t.point1Ref,1,s.vector0,0),a=f.tripleProductXYW(t.point0Ref,1,t.point1Ref,1,s.vector90,0),c=new Ft(2),l=new Ft(2),d=new Ft(2),h=Xn.appendImplicitLineUnitCircleIntersections(r,o,a,c,l,d);for(let g=0;g<h;g++){const m=s.center.plus2Scaled(s.vector0,c.atUncheckedIndex(g),s.vector90,l.atUncheckedIndex(g)),p=s.sweep.radiansToSignedPeriodicFraction(d.atUncheckedIndex(g));if(this.acceptFraction(p)){const x=bt.lineSegment3dXYClosestPointUnbounded(t.point0Ref,t.point1Ref,m);x!==void 0&&this.acceptFraction(x)&&(this.testAndRecordPointPair(t,x,void 0,e,p,m,n),i=!0)}}i||(this.testAndRecordEndPointApproaches(t,e,n),this.announceAllPerpendicularsSegmentArcBounded(t.point0Ref,t.point1Ref,e,(g,m,p,x)=>this.testAndRecordPointPair(t,g,m,e,p,x,n)))}allPerpendicularsArcArcBounded(t,e,n=!1){const i=new Qo(t,e),s=1/10,r=s/2,o=new bs(i,100);for(let a=r;a<1;a+=s)for(let c=r;c<1;c+=s)if(o.setUV(a,c),o.runIterations()){const l=o.getU(),d=o.getV();this.acceptFraction(l)&&this.acceptFraction(d)&&this.testAndRecordPointPair(t,l,void 0,e,d,void 0,n)}}dispatchArcArc(t,e,n){const i=t.range(),s=e.range();this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),s.intersectsRangeXY(i)&&(this.testAndRecordEndPointApproaches(t,e,n),this.allPerpendicularsArcArcBounded(t,e,n))}computeSegmentLineString(t,e,n){const i=e.numPoints(),s=f.safeDivideFraction(1,i-1,0),r=t.point0Ref,o=t.point1Ref,a=Re._workPointBB0,c=Re._workPointBB1;for(let l=0;l<i-1;++l){const d=l*s,h=l+1===i-1?1:(l+1)*s;e.packedPoints.getPoint3dAtUncheckedPointIndex(l,a),e.packedPoints.getPoint3dAtUncheckedPointIndex(l+1,c),this.computeSegmentSegment(t,r,0,o,1,e,a,d,c,h,n)}}computeArcLineString(t,e,n){const i=t.range(),s=e.range();if(this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),!s.intersectsRangeXY(i))return;const r=Re._workPointBB0,o=Re._workPointBB1,a=He.intersectionXYPairs(t,!1,e,!1,this._xyTolerance);for(const l of a)this.testAndRecordPair(l,n);const c=f.safeDivideFraction(1,e.numEdges(),0);for(let l=1;l<e.numEdges();++l)this.testAndRecordProjection(e,l*c,e.pointAtUnchecked(l,r),t,!n);this.testAndRecordEndPointApproaches(t,e,n),e.startPoint(r);for(let l=0;l<e.numEdges();++l,r.setFrom(o))e.pointAtUnchecked(l+1,o),this.announceAllPerpendicularsSegmentArcBounded(r,o,t,(d,h,g,m)=>{const p=e.segmentIndexAndLocalFractionToGlobalFraction(l,d);this.testAndRecordPointPair(t,g,m,e,p,h,n)})}classifyBitsPointRangeXY(t,e,n){let i=0;return t<n.low.x?i=1:t>n.high.x&&(i=2),e<n.low.y?i|=4:e>n.high.y&&(i|=8),i}computeLineStringLineString(t,e,n){const i=t.range(),s=e.range();if(this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),!s.intersectsRangeXY(i))return;let r,o;const a=J.createNull(),c=Re._workPointAA0,l=Re._workPointAA1,d=Re._workPointBB0,h=Re._workPointBB1,g=t.numPoints(),m=e.numPoints();if(g>1&&m>1){const p=1/(g-1),x=1/(m-1);let _=0,I,v,S;t.pointAt(0,c);for(let w=1;w<g;w++,c.setFrom(l),_=I)if(I=w*p,v=0,t.pointAt(w,l),a.setNull(),a.extendPoint(c),a.extendPoint(l),this._maxDistanceToAccept&&a.expandInPlace(this._maxDistanceToAccept),a.intersectsRangeXY(s)){e.pointAt(0,d),r=this.classifyBitsPointRangeXY(d.x,d.y,a);for(let T=1;T<m;T++,d.setFrom(h),v=S,r=o)e.pointAt(T,h),o=this.classifyBitsPointRangeXY(h.x,h.y,a),S=T*x,(r&o)===0&&this.computeSegmentSegment(t,c,_,l,I,e,d,v,h,S,n)}}}dispatchCurveCollection(t,e){const n=this._geometryB;if(!(!n||!n.children||!(n instanceof ut))){for(const i of n.children)this.resetGeometry(i),e(t);this._geometryB=n}}dispatchCurveChainWithDistanceIndex(t,e){if(!this._geometryB||!(this._geometryB instanceof xt))return;const n=this.grabPairedResults(),i=this._geometryB;for(const r of i.path.children)this.resetGeometry(r),e(t);this.resetGeometry(i),this._results.extractArray().forEach(r=>{xt.convertChildDetailToChainDetailSingle(r,void 0,i),this._results.insert(r)}),n.forEach(r=>this._results.insert(r))}needsStroking(t){return t instanceof Ns||t instanceof Mt}refineStrokedResultsByNewton(t,e,n,i,s,r=!1){const o=new Qo(e,i),a=new bs(o,this._maxIterations,this._newtonTolerance);for(const c of t){const l=r?c.detailB:c.detailA,d=r?c.detailA:c.detailB;d.curve instanceof F;const h=n?e.closestPointXY(l.point)?.fraction??l.fraction:l.fraction,g=s?i.closestPointXY(d.point)?.fraction??d.fraction:d.fraction;if(a.setUV(h,g),a.runIterations()){const m=a.getU(),p=a.getV();this.acceptFraction(m)&&this.acceptFraction(p)&&this.testAndRecordPointPair(e,m,void 0,i,p,void 0,r)}}}strokeCurve(t,e,n){const i=n||F.create();return t.emitStrokes(i,e),i}computeDiscreteCloseApproachResults(t,e,n){const i=this.maxDistanceToAccept,s=this.grabPairedResults(),r=this._geometryB;if(this.maxDistanceToAccept=i?i*1.2:void 0,this.resetGeometry(t),this.handleLineString3d(e),!n)for(const a of this._results)a.swapDetails();this.resetGeometry(r),this.maxDistanceToAccept=i;const o=this._results.extractArray();return s.forEach(a=>this._results.insert(a)),o}dispatchCurveStrokedCurve(t,e,n){const i=He.intersectionXYPairs(t,!1,e,!1,this._xyTolerance);for(const c of i)this.testAndRecordPair(c,n);const s=this.needsStroking(t),r=s?this.strokeCurve(t):t,o=this.strokeCurve(e),a=this.computeDiscreteCloseApproachResults(r,o,n);if(this.refineStrokedResultsByNewton(a,t,s,e,!0,n),t instanceof F){const c=f.safeDivideFraction(1,t.numEdges(),0),l=Re._workPointBB0;for(let d=1;d<t.numEdges();++d)this.testAndRecordProjection(t,d*c,t.pointAtUnchecked(d,l),e,n)}this.testAndRecordEndPointApproaches(t,e,n)}handleLineSegment3d(t){if(this._geometryB instanceof U){const e=this._geometryB;this.computeSegmentSegment(t,t.point0Ref,0,t.point1Ref,1,e,e.point0Ref,0,e.point1Ref,1,!1)}else this._geometryB instanceof F?this.computeSegmentLineString(t,this._geometryB,!1):this._geometryB instanceof N?this.computeSegmentArc(t,this._geometryB,!1):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(t,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineSegment3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineSegment3d.bind(this))}handleLineString3d(t){this._geometryB instanceof U?this.computeSegmentLineString(this._geometryB,t,!0):this._geometryB instanceof F?this.computeLineStringLineString(t,this._geometryB,!1):this._geometryB instanceof N?this.computeArcLineString(this._geometryB,t,!0):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(t,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleLineString3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleLineString3d.bind(this))}handleArc3d(t){this._geometryB instanceof U?this.computeSegmentArc(this._geometryB,t,!0):this._geometryB instanceof F?this.computeArcLineString(t,this._geometryB,!1):this._geometryB instanceof N?this.dispatchArcArc(t,this._geometryB,!1):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(t,this._geometryB,!1):this._geometryB instanceof ut?this.dispatchCurveCollection(t,this.handleArc3d.bind(this)):this._geometryB instanceof xt&&this.dispatchCurveChainWithDistanceIndex(t,this.handleArc3d.bind(this))}handleBSplineCurve3d(t){this._geometryB instanceof xt?this.dispatchCurveChainWithDistanceIndex(t,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof st?this.dispatchCurveStrokedCurve(this._geometryB,t,!0):this._geometryB instanceof ut&&this.dispatchCurveCollection(t,this.handleBSplineCurve3d.bind(this))}handleTransitionSpiral(t){this._geometryB instanceof xt?this.dispatchCurveChainWithDistanceIndex(t,this.handleTransitionSpiral.bind(this)):this._geometryB instanceof st?this.dispatchCurveStrokedCurve(this._geometryB,t,!0):this._geometryB instanceof ut&&this.dispatchCurveCollection(t,this.handleTransitionSpiral.bind(this))}handleCurveChainWithDistanceIndex(t){super.handleCurveChainWithDistanceIndex(t),this._results.extractArray().forEach(n=>{xt.convertChildDetailToChainDetailSingle(n,t,void 0),this._results.insert(n)})}handleBSplineCurve3dH(t){}}function Ji(u,t){return f.isAlmostEqualNumber(u,t,f.smallFraction)?0:u<t?-1:1}function xc(u,t){return f.isAlmostEqualNumber(u,t,f.smallFraction)?0:u<t?1:-1}class ti{_quadrant;_fractions;_interpolateStartTangent;_interpolateEndTangent;_averageAdded;constructor(t,e,n,i){this._quadrant=t,this._fractions=e,this._interpolateStartTangent=n,this._interpolateEndTangent=i,this._averageAdded=!1}static create(t,e=[],n=!0,i=!0){return new ti(t,e,n,i)}get quadrant(){return this._quadrant}get fractions(){return this._fractions}set fractions(t){this._fractions=t}get interpolateStartTangent(){return this._interpolateStartTangent}set interpolateStartTangent(t){this._interpolateStartTangent=t}get interpolateEndTangent(){return this._interpolateEndTangent}set interpolateEndTangent(t){this._interpolateEndTangent=t}get averageAdded(){return this._fractions.length===3?this._averageAdded:!1}set averageAdded(t){this._averageAdded=t}static getQuadrantRadians(t,e){if(at.isRadiansInStartEnd(t,0,A.piOver2Radians)&&at.isRadiansInStartEnd(e,0,A.piOver2Radians))return{quadrant:1,angle0:0,angle1:A.piOver2Radians};if(at.isRadiansInStartEnd(t,A.piOver2Radians,A.piRadians)&&at.isRadiansInStartEnd(e,A.piOver2Radians,A.piRadians))return{quadrant:2,angle0:A.piOver2Radians,angle1:A.piRadians};if(at.isRadiansInStartEnd(t,A.piRadians,A.pi3Over2Radians)&&at.isRadiansInStartEnd(e,A.piRadians,A.pi3Over2Radians))return{quadrant:3,angle0:A.piRadians,angle1:A.pi3Over2Radians};if(at.isRadiansInStartEnd(t,A.pi3Over2Radians,A.pi2Radians)&&at.isRadiansInStartEnd(e,A.pi3Over2Radians,A.pi2Radians))return{quadrant:4,angle0:A.pi3Over2Radians,angle1:A.pi2Radians}}static getQ1FractionalRange(t){const n=.5*Math.PI;let i=t.radiansToSignedPeriodicFraction(0),s=t.radiansToSignedPeriodicFraction(n);return t.isCCW||([i,s]=[s,i]),s<i&&(s+=1),ct.createXX(i,s)}reverse(){this._fractions.reverse(),[this._interpolateStartTangent,this._interpolateEndTangent]=[this._interpolateEndTangent,this._interpolateStartTangent]}}class Ls{announceQuadrantBegin(t,e){return!0}announceArc(t,e,n,i){}announceQuadrantEnd(t,e){}}class bi extends Ls{_ellipticalArc;_maxPerpendicular;constructor(t){super(),this._ellipticalArc=t,this._maxPerpendicular=void 0}static create(t){return new bi(t)}get ellipticalArc(){return this._ellipticalArc}static computePrimitiveErrorXY(t,e,n,i){const s=new Re;s.maxDistanceToAccept=t.quickLength()/2;const r=n!==void 0&&i!==void 0,o=r?e.clonePartialCurve(n,i):e;s.allPerpendicularsArcArcBounded(t,o);let a;for(const c of s.grabPairedResults()){if(f.isAlmostEqualEitherNumber(c.detailA.fraction,0,1,f.smallFraction)||f.isAlmostEqualEitherNumber(c.detailB.fraction,0,1,f.smallFraction))continue;const l=c.detailA.point.distanceXY(c.detailB.point);(!a||a.detailA.a<l)&&(r&&(c.detailB.fraction=f.interpolate(n,c.detailB.fraction,i),c.detailB.setCurve(e)),c.detailA.a=c.detailB.a=l,a=c)}return a}get maxPerpendicular(){return this._maxPerpendicular}set maxPerpendicular(t){this._maxPerpendicular=t}updateMaxPerpendicular(t,e,n){const i=bi.computePrimitiveErrorXY(t,this.ellipticalArc,e,n);i&&(!this.maxPerpendicular||this.maxPerpendicular.detailA.a<i.detailA.a)&&(this.maxPerpendicular=i)}announceArc(t,e,n,i){this.updateMaxPerpendicular(t,n,i)}}class Wr extends Ls{_fullEllipseXY;_f;_bracket0;_bracket1;_error0;_error1;constructor(t,e,n,i){super(),this._fullEllipseXY=t,this._bracket0=e,this._f=n,this._bracket1=i,this._error0=this._error1=f.largeCoordinateResult}static create(t,e,n,i){return new Wr(t,e,n,i)}get fullEllipseXY(){return this._fullEllipseXY}get f(){return this._f}get isConverged(){return!!(f.isSmallMetricDistance(this._error0-this._error1)||f.isSmallRelative(this._bracket0-this._bracket1))}announceQuadrantBegin(t,e){return t.quadrant,t.fractions.length===4||t.fractions.length===3&&t.interpolateStartTangent,this._error0=this._error1=f.largeCoordinateResult,!0}announceArc(t,e,n,i){if(f.isAlmostEqualEitherNumber(this.f,n,i,0)){const s=bi.computePrimitiveErrorXY(t,this.fullEllipseXY,n,i);s&&(this.f===i?this._error0=s.detailA.a:this._error1=s.detailA.a)}}announceQuadrantEnd(t,e){if(f.isLargeCoordinateResult(this._error0)||f.isLargeCoordinateResult(this._error1)||this.isConverged)return;const n=t.fractions.length;this._error0<this._error1?this._bracket0=this._f:this._bracket1=this._f,this._f=t.fractions[n-2]=f.interpolate(this._bracket0,.5,this._bracket1)}}class Us extends Ls{_fullEllipseXY;_fractionRangeQ1;_refinement;_maxError;_originalRefinementCount;static _maxIters=50;constructor(t,e){super(),this._fullEllipseXY=t,this._fractionRangeQ1=ti.getQ1FractionalRange(t.sweep),this._maxError=e>0?e:Di.defaultMaxError,this._originalRefinementCount=0}static create(t,e){return new Us(t,e)}get fullEllipseXY(){return this._fullEllipseXY}get isRefined(){return this._refinement===void 0||this._refinement.length===0?!1:this._originalRefinementCount<this._refinement.length}announceQuadrantBegin(t,e){t.quadrant,this._refinement=new jn(e?xc:Ji,!1);for(const n of t.fractions)this._fractionRangeQ1.containsX(n)&&this._refinement.insert(n);return 2<=(this._originalRefinementCount=this._refinement.length)}getPreviousFraction(t){if(this._refinement===void 0)return;const e=this._refinement.indexOf(t);return e>=1?this._refinement.get(e-1):void 0}announceArc(t,e,n,i){if(this._refinement===void 0)return;if(this._originalRefinementCount>2){const h=bi.computePrimitiveErrorXY(t,this.fullEllipseXY,n,i);if(!h||h.detailA.a<=this._maxError)return}const s=f.interpolate(n,.5,i),r=f.isAlmostEqualEitherNumber(n,this._fractionRangeQ1.low,this._fractionRangeQ1.high,0),o=f.isAlmostEqualEitherNumber(i,this._fractionRangeQ1.low,this._fractionRangeQ1.high,0);!r&&e===void 0&&(e=this.getPreviousFraction(n));const a=e===void 0?[n,s,i]:[e,n,s,i],c=[ti.create(1,a,r,o)],l=Wr.create(this.fullEllipseXY,n,s,i);let d=0;do mi.processQuadrantFractions(this.fullEllipseXY,c,l);while(d++<Us._maxIters&&!l.isConverged);this._refinement.insert(l.f)}announceQuadrantEnd(t,e){this._refinement&&(t.fractions=[...this._refinement])}getRefinedInteriorQ1Angles(t){if(t?t.length=0:t=[],this._refinement)for(const e of this._refinement)this._fractionRangeQ1.containsXOpen(e)&&t.push(this.fullEllipseXY.sweep.fractionToRadians(e));return t}}class Gr{_context;_options;constructor(t,e){this._context=t,this._options=e}static create(t,e){return new Gr(t,e)}computeRadiansStrictlyInsideQuadrant1(t){if(t||(t=[]),this._context.isValidEllipticalArc){const e=A.piOver2Radians/(this._options.numSamplesInQuadrant-1);for(let n=1;n<this._options.numSamplesInQuadrant-1;++n)t.push(n*e)}return t}}class Bs{_context;_options;_xMag2;_yMag2;_curvatureRange;constructor(t,e){this._context=t,this._options=e,this._xMag2=t.ellipticalArc.matrixRef.columnXMagnitudeSquared(),this._yMag2=t.ellipticalArc.matrixRef.columnYMagnitudeSquared(),this._curvatureRange=ct.createXX(Math.sqrt(this._xMag2)/this._yMag2,Math.sqrt(this._yMag2)/this._xMag2)}static create(t,e){return new Bs(t,e)}curvatureToRadians(t){if(!this._curvatureRange.containsX(t))return;const e=Math.cbrt(this._xMag2*this._yMag2/(t*t)),n=Math.sqrt(Math.abs((e-this._xMag2)/(this._yMag2-this._xMag2)));return Math.acos(n)}computeRadiansStrictlyInsideQuadrant1(t){if(t||(t=[]),this._context.isValidEllipticalArc){const e=1/(this._options.numSamplesInQuadrant-1);for(let n=1;n<this._options.numSamplesInQuadrant-1;++n){const i=this._options.remapFunction(n*e),s=(1-i)*this._curvatureRange.low+i*this._curvatureRange.high,r=this.curvatureToRadians(s);r!==void 0&&t.push(r)}}return t}}class Hr extends Bs{constructor(t,e){super(t,e.clone()),this._options.remapFunction=n=>n}static create(t,e){return new Hr(t,e)}}class Jr{_context;_options;_fullEllipseXY;constructor(t,e){this._context=t,this._options=e,this._fullEllipseXY=t.cloneLocalArc(!0)??N.createUnitCircle()}static create(t,e){return new Jr(t,e)}get fullEllipseXY(){return this._fullEllipseXY}computeRadiansStrictlyInsideQuadrant1(t){if(!this._context.isValidEllipticalArc)return[];const e=ti.getQ1FractionalRange(this.fullEllipseXY.sweep),n=[ti.create(1,[e.low,e.high],!0,!0)],i=Us.create(this.fullEllipseXY,this._options.maxError);do mi.processQuadrantFractions(this.fullEllipseXY,n,i);while(i.isRefined);return i.getRefinedInteriorQ1Angles(t)}}class Kr extends Ls{_chain;_quadrantChain;constructor(t,e){super(),this._chain=t.sweep.isFullCircle&&!e?tt.create():Pt.create()}static create(t,e=!1){return new Kr(t,e)}get chain(){return this._chain.children.length>0?this._chain:void 0}announceQuadrantBegin(t,e){return this._quadrantChain=void 0,!0}announceArc(t,e,n,i){this._quadrantChain||(this._quadrantChain=Pt.create()),this._quadrantChain.tryAddChild(t)}announceQuadrantEnd(t,e){if(this._quadrantChain){e&&this._quadrantChain.reverseChildrenInPlace();for(const n of this._quadrantChain.children)this._chain.tryAddChild(n)}}}class mi{_ellipticalArc;_localToWorld;_isValidEllipticalArc;static workPt0=y.createZero();static workPt1=y.createZero();static workPt2=y.createZero();static workRay=O.createZero();constructor(t){this._isValidEllipticalArc=!1;const e=t.toScaledMatrix3d();if(this._ellipticalArc=N.createScaledXYColumns(e.center,e.axes,e.r0,e.r90,e.sweep),this._localToWorld=X.createRefs(e.center,e.axes),this._localToWorld.matrix.isSingular()||this._ellipticalArc.sweep.isEmpty)return;const n=t.matrixRef.columnXMagnitudeSquared(),i=t.matrixRef.columnYMagnitudeSquared();f.isSmallMetricDistanceSquared(n)||f.isSmallMetricDistanceSquared(i)||f.isSameCoordinateSquared(n,i)||(this._isValidEllipticalArc=!0)}static create(t){return new mi(t)}get ellipticalArc(){return this._ellipticalArc}get localToWorld(){return this._localToWorld}get isValidEllipticalArc(){return this._isValidEllipticalArc}cloneLocalArc(t){if(!this.isValidEllipticalArc)return;const e=this.localToWorld.inverse();if(!e)return;const n=this.ellipticalArc.cloneTransformed(e);if(t){let i=2*Math.PI;n.sweep.isCCW||(i=-i),n.sweep.setStartEndRadians(n.sweep.startRadians,n.sweep.startRadians+i)}return n}static processQuadrantFractions(t,e,n){const i=this.workPt0,s=this.workPt1,r=this.workPt2,o=this.workRay,a=(m,p,x)=>{const _=N.createCircularStartTangentEnd(m.origin,m.direction,p);if(_ instanceof N)return x&&_.reverseInPlace(),_},c=(m,p,x)=>{const _=N.createCircularStartMiddleEnd(m,p,x);if(!(_ instanceof N))return;const I=_.vector0.signedAngleTo(P.createStartEnd(_.center,p),_.matrixRef.columnZ());return _.sweep.setStartEndRadians(I.radians,_.sweep.endRadians),_},l=(m,p)=>{t.fractionToPointAndDerivative(m,o),t.fractionToPoint(p,s),m>p&&o.direction.scaleInPlace(-1);const x=a(o,s,!1);x&&n.announceArc(x,void 0,m,p)},d=(m,p,x)=>{let _=m;n.getPreviousFraction&&(_=n.getPreviousFraction(p)??m),t.fractionToPoint(_,i),t.fractionToPoint(p,s),t.fractionToPoint(x,r);const I=c(i,s,r);I&&n.announceArc(I,_,p,x)},h=(m,p)=>{t.fractionToPoint(m,i),t.fractionToPointAndDerivative(p,o),p>m&&o.direction.scaleInPlace(-1);const x=a(o,i,!0);x&&n.announceArc(x,void 0,m,p)},g=m=>{if(!m.interpolateStartTangent&&!m.interpolateEndTangent)return!1;const p=m.fractions.length;if(p<2)return!1;const _=t.vector0.magnitudeSquared()>t.vector90.magnitudeSquared()?m.quadrant===2||m.quadrant===4:m.quadrant===1||m.quadrant===3,v=!(m.fractions[0]>m.fractions[p-1])&&_===t.sweep.isCCW;return v&&m.reverse(),v};for(const m of e){const p=m.fractions.length;if(p<2)continue;const x=g(m);if(n.announceQuadrantBegin(m,x)){m.interpolateStartTangent&&l(m.fractions[0],m.fractions[1]);for(let _=0;_+2<p-1;++_)d(m.fractions[_],m.fractions[_+1],m.fractions[_+2]);p>2&&(m.interpolateEndTangent?h(m.fractions[p-2],m.fractions[p-1]):d(m.fractions[p-3],m.fractions[p-2],m.fractions[p-1])),n.announceQuadrantEnd(m,x),x&&m.reverse()}}}computeApproximationError(t){const e=this.cloneLocalArc();if(!e)return;const n=bi.create(e);mi.processQuadrantFractions(e,t,n);const i=n.maxPerpendicular;return i&&i.tryTransformInPlace(this.localToWorld)?i:void 0}computeSampleFractions(t,e=!1){if(!this.isValidEllipticalArc)return[];const n=(h,g)=>f.isAlmostEqualNumber(h,g,f.smallAngleRadians)?0:h<g?-1:1,i=(h,g)=>f.isAlmostEqualNumber(h,g,f.smallAngleRadians)?0:h<g?1:-1,s=(h,g)=>Ji(h.fractions[h.fractions.length-1],g.fractions[0])<=0?-1:Ji(g.fractions[g.fractions.length-1],h.fractions[0])<=0?1:0,r=(h,g)=>{const m=g.isRadiansInSweep(h,!0);if(m){const p=g.radiansToSignedPeriodicFraction(h);f.isIn01(p)&&(h=g.fractionToRadians(p))}return{angle:h,inSweep:m}},o=(h,g,m,p,x)=>{if(p===void 0&&(p=0),x===void 0&&(x=1),p>x)return o(h,g,m,x,p);const _=m.radiansToSignedPeriodicFraction(g);if(!(_<p-f.smallFraction||x+f.smallFraction<_))return f.restrictToInterval(_,0,1),h.add(_),_},a=(h,g,m,p)=>{if(g>m)return a(h,m,g,p);if(A.isAlmostEqualRadiansNoPeriodShift(g,m))return;const x=ti.getQuadrantRadians(g,m);if(x===void 0)return;const _=new Fi(Ji),I=o(_,g,p),v=o(_,m,p);if(I===void 0||v===void 0)return;for(const T of h){let R=T;x.quadrant===2?R=A.piRadians-R:x.quadrant===3?R=A.piRadians+R:x.quadrant===4&&(R=A.pi2Radians-R),o(_,R,p,I,v)}const S=ti.create(x.quadrant,[..._]);return S.fractions.length===2&&(S.fractions.splice(1,0,f.interpolate(S.fractions[0],.5,S.fractions[1])),S.averageAdded=!0),S},c=(h,g)=>{const m=new Fi(g.isCCW?n:i);m.add(g.endRadians);for(const _ of[0,A.piOver2Radians,A.piRadians,A.pi3Over2Radians,A.pi2Radians]){const I=r(_,g);I.inSweep&&m.add(I.angle)}const p=new Fi(s);let x=g.startRadians;for(const _ of m){const I=a(h,x,_,g);I&&p.add(I),x=_}return[...p]},l=(h,g)=>{const m=new Fi(Ji);m.add(0),m.add(1);for(const p of[0,A.piOver2Radians,A.piRadians,A.pi3Over2Radians])o(m,p,g);for(const p of h)for(const x of[p,A.piRadians-p,A.piRadians+p,A.pi2Radians-p])o(m,x,g);return[...m]},d=[];switch(t.sampleMethod){case pi.UniformParameter:{Gr.create(this,t).computeRadiansStrictlyInsideQuadrant1(d);break}case pi.UniformCurvature:{Hr.create(this,t).computeRadiansStrictlyInsideQuadrant1(d);break}case pi.NonUniformCurvature:{Bs.create(this,t).computeRadiansStrictlyInsideQuadrant1(d);break}case pi.AdaptiveSubdivision:{Jr.create(this,t).computeRadiansStrictlyInsideQuadrant1(d);break}}return e?c(d,this.ellipticalArc.sweep):l(d,this.ellipticalArc.sweep)}constructCircularArcChainApproximation(t){if(!this.isValidEllipticalArc)return;t||(t=Di.create());const e=this.computeSampleFractions(t,!0),n=Kr.create(this.ellipticalArc,t.forcePath);return mi.processQuadrantFractions(this.ellipticalArc,e,n),n.chain}}var pi;(function(u){u[u.UniformParameter=0]="UniformParameter",u[u.UniformCurvature=1]="UniformCurvature",u[u.NonUniformCurvature=2]="NonUniformCurvature",u[u.AdaptiveSubdivision=3]="AdaptiveSubdivision"})(pi||(pi={}));class Di{_sampleMethod;_numSamplesInQuadrant;_maxError;_remapFunction;_forcePath;static defaultMaxError=Rs.oneCentimeter;constructor(t,e,n,i,s){this._sampleMethod=t,this._numSamplesInQuadrant=e,this._maxError=n,this._remapFunction=i,this._forcePath=s}static create(t=pi.AdaptiveSubdivision,e=4,n=this.defaultMaxError,i=r=>r*r,s=!1){return e<2&&(e=2),n<=0&&(n=this.defaultMaxError),new Di(t,e,n,i,s)}clone(){return new Di(this.sampleMethod,this.numSamplesInQuadrant,this.maxError,this.remapFunction,this.forcePath)}get sampleMethod(){return this._sampleMethod}set sampleMethod(t){this._sampleMethod=t}get numSamplesInQuadrant(){return this._numSamplesInQuadrant}set numSamplesInQuadrant(t){this._numSamplesInQuadrant=t}get maxError(){return this._maxError}set maxError(t){this._maxError=t}get remapFunction(){return this._remapFunction}set remapFunction(t){this._remapFunction=t}get forcePath(){return this._forcePath}set forcePath(t){this._forcePath=t}}class N extends st{curvePrimitiveType="arc";isSameGeometryClass(t){return t instanceof N}_center;_matrix;_sweep;static _workPointA=y.create();static _workPointB=y.create();static _workPointC=y.create();static _workVectorU=P.create();static _workVectorV=P.create();static _workVectorW=P.create();static _workRay0=O.createZero();static _workRay1=O.createZero();static _workRay2=O.createZero();get center(){return this._center.clone()}set center(t){this._center.setFrom(t)}get centerRef(){return this._center}get vector0(){return this._matrix.columnX()}get vector90(){return this._matrix.columnY()}binormalVector(t){const e=this.fractionToPointAnd2Derivatives(0);return e.vectorU.crossProduct(e.vectorV,t)}get perpendicularVector(){return this._matrix.columnZ()}matrixClone(){return this._matrix.clone()}get matrixRef(){return this._matrix}get sweep(){return this._sweep}set sweep(t){this._sweep.setFrom(t)}get isExtensibleFractionSpace(){return!0}constructor(t,e,n){super(),this._center=t,this._matrix=e,this._sweep=n.clampToFullCircle(n)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}setRefs(t,e,n){this._center=t,this._matrix=e,n.clampToFullCircle(this._sweep)}set(t,e,n){return t?this._center.setFrom(t):this._center.setZero(),e?this._matrix.setFrom(e):this._matrix.setIdentity(),n?n.clampToFullCircle(this._sweep):at.create360(0,this._sweep),this}setFrom(t){this._center.setFrom(t._center),this._matrix.setFrom(t._matrix),this._sweep.setFrom(t._sweep)}clone(){return new N(this._center.clone(),this._matrix.clone(),this._sweep.clone())}static createRefs(t,e,n,i){return i?i.set(t,e,n):new N(t??y.createZero(),e??C.createIdentity(),n??at.create360())}static createScaledXYColumns(t,e,n,i,s,r){const o=e.columnX(),a=e.columnY();return N.create(t,o.scale(n,o),a.scale(i,a),s,r)}static createCenterNormalRadius(t,e,n,i){const s=C.createRigidHeadsUp(e);return N.createScaledXYColumns(t,s,n,n,void 0,i)}static create(t,e,n,i,s){const r=e.unitCrossProductWithDefault(n,0,0,0),o=C.createColumns(e,n,r,s?._matrix);return s?s.set(t,o,i):this.createRefs(t?.clone(),o,i?.clone())}static createStartMiddleEnd(t,e,n,i,s){const r=y.createAdd2Scaled(t,.5,n,.5),o=P.createStartEnd(r,t),a=P.createStartEnd(r,e),c=o.dotProduct(a),l=o.magnitudeSquared();if(Math.abs(c)>=l)return;const h=o.crossProduct(a).unitCrossProductWithDefault(o,0,0,0),g=a.dotProduct(h),m=f.safeDivideFraction(l*g,Math.sqrt(l*l-c*c),0);if(!f.isSmallMetricDistanceSquared(m))return h.scaleInPlace(m),N.create(r,o,h,i,s)}static createCircularStartTangentEnd(t,e,n,i){const s=P.createStartEnd(t,n),r=C.createRigidFromColumns(e,s,mt.XYZ);if(r!==void 0){const o=s.dotProduct(s),a=r.dotColumnY(s),c=f.conditionalDivideCoordinate(o,2*a);if(c!==void 0){const l=r.columnY();l.scaleInPlace(-c);const d=r.columnX();d.scaleInPlace(c);const h=l.plus(s);let m=l.angleTo(h).radians;e.dotProduct(h)<0&&(m=2*Math.PI-m);const p=t.plusScaled(l,-1),x=at.createStartEndRadians(0,m);return N.create(p,l,d,x,i)}}return U.create(t,n)}static createCircularStartTangentRadius(t,e,n,i,s){i===void 0&&(i=P.unitZ());const r=i.unitCrossProduct(e);if(r===void 0)return;const o=t.plusScaled(r,n);r.scaleInPlace(-n);const a=e.scaleToLength(Math.abs(n));return a!==void 0?N.create(o,r,a,at.create(s)):void 0}static createCircularStartEndRadius(t,e,n,i,s){const r=.25*t.distanceSquared(e),o=n*n;if(o<r)return;const a=Math.sqrt(o-r),c=P.createZero(this._workVectorU),l=P.createZero(this._workVectorV);if(i instanceof y?t.crossProductToPoints(i,e,c):c.setFrom(i),!c.normalizeInPlace()||!c.crossProductStartEnd(t,e,l).scaleToLength(a,l))return;const d=y.createZero(s?.centerRef);t.interpolate(.5,e,d).addInPlace(l);const h=P.createStartEnd(d,t,this._workVectorW),g=P.createStartEnd(d,e,this._workVectorV),m=at.createStartEndRadians(0,h.signedRadiansTo(g,c),s?.sweep),p=c.crossProduct(h,this._workVectorV),x=C.createColumns(h,p,c,s?.matrixRef);return this.createRefs(d,x,m,s)}cloneAtZ(t){return t===void 0&&(t=this._center.z),N.createXYZXYZXYZ(this._center.x,this._center.y,t,this._matrix.coffs[0],this._matrix.coffs[3],0,this._matrix.coffs[1],this._matrix.coffs[4],0,this._sweep)}static createXYZXYZXYZ(t,e,n,i,s,r,o,a,c,l,d){return N.create(y.create(t,e,n),P.create(i,s,r),P.create(o,a,c),l,d)}quickEccentricity(){const t=this._matrix.columnXMagnitude(),e=this._matrix.columnYMagnitude(),n=this._matrix.columnXYCrossProductMagnitude(),i=f.maxXY(t,e);return n/(i*i)}static createCircularStartMiddleEnd(t,e,n,i){const s=P.createStartEnd(t,e),r=P.createStartEnd(t,n),o=s.magnitudeSquared(),a=r.magnitudeSquared(),c=s.sizedCrossProduct(r,Math.sqrt(Math.sqrt(o*a)));if(c){const l=bt.linearSystem3d(c.x,c.y,c.z,s.x,s.y,s.z,r.x,r.y,r.z,0,.5*o,.5*a);if(l){const d=y.create(t.x,t.y,t.z).plus(l),h=P.createStartEnd(d,t),g=P.createRotateVectorAroundVector(h,c,A.createDegrees(90));if(g){const m=P.createStartEnd(d,n),p=h.signedAngleTo(m,c);return p.radians<0&&p.addMultipleOf2PiInPlace(1),N.create(d,h,g,at.createStartEndRadians(0,p.radians),i)}}}return F.create(t,e,n)}getFractionToDistanceScale(){const t=this.circularRadius();if(t!==void 0)return Math.abs(t*this._sweep.sweepRadians)}fractionToPoint(t,e){const n=this._sweep.fractionToRadians(t);return this._matrix.originPlusMatrixTimesXY(this._center,Math.cos(n),Math.sin(n),e)}fractionAndRadialFractionToPoint(t,e,n){const i=this._sweep.fractionToRadians(t);return this._matrix.originPlusMatrixTimesXY(this._center,e*Math.cos(i),e*Math.sin(i),n)}fractionToPointAndDerivative(t,e){return e=this.radiansToPointAndDerivative(this._sweep.fractionToRadians(t),e),e.direction.scaleInPlace(this._sweep.sweepRadians),e}fractionToPointAnd2Derivatives(t,e){const n=this._sweep.fractionToRadians(t);e||(e=At.createXYPlane());const i=Math.cos(n),s=Math.sin(n);this._matrix.originPlusMatrixTimesXY(this._center,i,s,e.origin);const r=this._sweep.sweepRadians;this._matrix.multiplyXY(-r*s,r*i,e.vectorU);const o=r*r;return this._matrix.multiplyXY(-o*i,-o*s,e.vectorV),e}radiansToPointAndDerivative(t,e){e=e||O.createZero();const n=Math.cos(t),i=Math.sin(t);return this._matrix.originPlusMatrixTimesXY(this._center,n,i,e.origin),this._matrix.multiplyXY(-i,n,e.direction),e}radiansToPoint(t,e){e=e||y.create();const n=Math.cos(t),i=Math.sin(t);return this._matrix.originPlusMatrixTimesXY(this._center,n,i,e),e}radiansToRotatedBasis(t,e){e=e||At.createXYPlane();const n=Math.cos(t),i=Math.sin(t);return e.origin.setFromPoint3d(this.center),this._matrix.multiplyXY(n,i,e.vectorU),this._matrix.multiplyXY(-i,n,e.vectorV),e}angleToPointAndDerivative(t,e){e=e||O.createZero();const n=t.cos(),i=t.sin();return this._matrix.originPlusMatrixTimesXY(this._center,n,i,e.origin),this._matrix.multiplyXY(-i,n,e.direction),e}startPoint(t){return this.fractionToPoint(0,t)}isPhysicallyClosedCurve(t=f.smallMetricDistance,e=!1){return this.sweep.isFullCircle?!0:super.isPhysicallyClosedCurve(t,e)}endPoint(t){return this.fractionToPoint(1,t)}curveLength(){return this.curveLengthBetweenFractions(0,1)}static quadratureGuassCount=5;static quadratureGaussCount=5;static quadratureIntervalAngleDegrees=10;curveLengthBetweenFractions(t,e){const n=this.getFractionToDistanceScale();if(n!==void 0)return n*Math.abs(e-t);let i=t,s=e;t>e&&(i=e,s=t);const r=(s-i)*this._sweep.sweepDegrees;let o=this.quickEccentricity();o<1e-5&&(o=1e-5);let a=Math.ceil(r/(o*N.quadratureIntervalAngleDegrees));return a>400&&(a=400),a<1&&(a=1),super.curveLengthWithFixedIntervalCountQuadrature(i,s,a,N.quadratureGaussCount)}quickLength(){const t=Math.abs(this._sweep.sweepRadians);let e=Math.ceil(4*t/Math.PI);e<1&&(e=1),e<4?e+=3:e<6&&(e+=2);const n=N._workPointA,i=N._workPointB;let s=0;this.fractionToPoint(0,n);for(let a=1;a<=e;a++)this.fractionToPoint(a/e,i),s+=n.distance(i),n.setFromPoint3d(i);const r=t/e,o=r/(2*Math.sin(.5*r));return s*o}moveSignedDistanceFromFraction(t,e,n,i){if(!this.isCircular)return super.moveSignedDistanceFromFractionGeneric(t,e,n,i);const s=this.curveLength(),r=f.conditionalDivideFraction(e,s);return r===void 0?Y.createCurveFractionPointDistanceCurveSearchStatus(this,t,this.fractionToPoint(t),0,Me.error):Y.createConditionalMoveSignedDistance(n,this,t,t+r,e,i)}allPerpendicularAngles(t,e=!0,n=!1){const i=[],s=t.vectorTo(this.center),r=this._matrix.columnXMagnitudeSquared(),o=this._matrix.columnXDotColumnY(),a=this._matrix.columnYMagnitudeSquared();return Mi.solveUnitCircleImplicitQuadricIntersection(o,a-r,-o,this._matrix.dotColumnY(s),-this._matrix.dotColumnX(s),0,i),n&&(i.push(this.sweep.startRadians),i.push(this.sweep.endRadians)),i}closestPoint(t,e=!1,n){n=Y.create(this,n);const i=this.allPerpendicularAngles(t,!0,!1);if(!this._sweep.isFullCircle){const r=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,0),o=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,1);r===Ht.None&&o===Ht.None&&(i.push(this._sweep.startRadians),i.push(this._sweep.endRadians))}const s=O.createZero();if(i.length===0)n.setFR(0,this.radiansToPointAndDerivative(this._sweep.startRadians,s),t.distance(n.point));else{let r=Number.MAX_VALUE,o=0;for(const a of i){const c=Ut.resolveRadiansToValidSweepFraction(e,a,this.sweep);c.isValid&&(this.fractionToPointAndDerivative(c.fraction,s),o=t.distance(s.origin),o<r&&(r=o,n.setFR(c.fraction,s,o)))}}return n}closestPointXY(t,e=!1,n){const i=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,0),s=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(e,1);return e=i!==Ht.None||s!==Ht.None,super.closestPointXY(t,e,n)}emitTangents(t,e,n){const i=P.createStartEnd(this.centerRef,t);let s;if(n?.vectorToEye?s=C.createColumns(this.matrixRef.getColumn(0),this.matrixRef.getColumn(1),n.vectorToEye).multiplyInverse(i):s=this.matrixRef.multiplyInverse(i),s!==void 0&&s!==void 0){const r=s.magnitudeSquaredXY();if(r>=1){const o=Math.sqrt(r-1),a=Math.atan2(s.y,s.x),c=Math.atan2(o,1),l=f.isSmallAngleRadians(c)?[a]:[a+c,a-c];for(const d of l){const h=Ut.resolveRadiansToValidSweepFraction(n?.extend??!1,d,this.sweep);if(h.isValid){const g=Y.createCurveFractionPoint(this,h.fraction,this.fractionToPoint(h.fraction));e(g)}}}}}reverseInPlace(){this._sweep.reverseInPlace()}tryTransformInPlace(t){return this._center=t.multiplyPoint3d(this._center,this._center),this._matrix=t.matrix.multiplyMatrixMatrix(this._matrix,this._matrix),this.setVector0Vector90(this._matrix.columnX(),this._matrix.columnY()),!0}isInPlane(t){const e=t.getNormalRef();return f.isSmallMetricDistance(t.altitude(this._center))&&f.isSmallMetricDistance(this._matrix.dotColumnX(e))&&f.isSmallMetricDistance(this._matrix.dotColumnY(e))}get isCircular(){const t=this._matrix.columnXMagnitudeSquared(),e=this._matrix.columnYMagnitudeSquared(),n=this._matrix.columnXDotColumnY();return A.isPerpendicularDotSet(t,e,n)&&f.isSameCoordinateSquared(t,e)}get isCircularXY(){const t=this._matrix.columnX(),e=this._matrix.columnY(),n=t.magnitudeSquaredXY(),i=e.magnitudeSquaredXY(),s=t.dotProductXY(e);return A.isPerpendicularDotSet(n,i,s)&&f.isSameCoordinateSquared(n,i)}get isDegenerateCircle(){return f.isSmallMetricDistanceSquared(this._matrix.columnXMagnitudeSquared())&&f.isSmallMetricDistanceSquared(this._matrix.columnYMagnitudeSquared())}circularRadiusXY(){const t=this._matrix.at(0,0),e=this._matrix.at(1,0),n=this._matrix.at(0,1),i=this._matrix.at(1,1),s=f.dotProductXYXY(t,e,t,e),r=f.dotProductXYXY(n,i,n,i),o=f.dotProductXYXY(t,e,n,i);if(A.isPerpendicularDotSet(s,r,o)&&f.isSameCoordinateSquared(s,r))return f.hypotenuseXY(t,e)}circularRadius(){return this.isCircular?this._matrix.columnXMagnitude():void 0}maxVectorLength(){return Math.max(this._matrix.columnXMagnitude(),this._matrix.columnYMagnitude())}appendPlaneIntersectionPoints(t,e){const n=t.altitude(this._center),i=this._matrix.coffs,s=t.velocityXYZ(i[0],i[3],i[6]),r=t.velocityXYZ(i[1],i[4],i[7]),o=f.solveTrigForm(n,s,r);let a=0;if(o!==void 0){a=o.length;let c;for(c of o){const l=Math.atan2(c.y,c.x),d=this._sweep.radiansToPositivePeriodicFraction(l),h=Y.createCurveFractionPoint(this,d,this.fractionToPoint(d));h.intervalRole=Ct.isolated,(A.isAlmostEqualRadiansAllowPeriodShift(l,this._sweep.startRadians)||A.isAlmostEqualRadiansAllowPeriodShift(l,this._sweep.endRadians))&&(h.intervalRole=Ct.isolatedAtVertex),e.push(h)}}return a}extendRange(t,e){this.extendRangeInSweep(t,this._sweep,e)}extendRangeInSweep(t,e,n){const i=new Go(0,0,0),s=this._center.clone(N._workPointA),r=this._matrix.columnX(N._workVectorU),o=this._matrix.columnY(N._workVectorV);n&&(n.multiplyPoint3d(s,s),n.multiplyVector(r,r),n.multiplyVector(o,o));const a=N._workPointB,c=N._workPointC,l=ct.createNull();for(let d=0;d<3;d++)i.set(s.at(d),r.at(d),o.at(d)),i.rangeInSweep(e,l),a.setAt(d,l.low),c.setAt(d,l.high);t.extend(a),t.extend(c)}rangeBetweenFractions(t,e,n){const i=at.createStartEndRadians(this.sweep.fractionToRadians(t),this.sweep.fractionToRadians(e)),s=J.create();return this.extendRangeInSweep(s,i,n),s}getPlaneAltitudeSineCosinePolynomial(t,e){return e||(e=new Go(0,0,0)),e.set(t.altitude(this._center),t.velocityXYZ(this._matrix.coffs[0],this._matrix.coffs[3],this._matrix.coffs[6]),t.velocityXYZ(this._matrix.coffs[1],this._matrix.coffs[4],this._matrix.coffs[7])),e}static createUnitCircle(t){return N.createRefs(void 0,void 0,void 0,t)}static createXY(t,e,n,i){const s=C.createScale(e,e,1,i?.matrixRef);return i?i.set(t,s,n):N.createRefs(t.clone(),s,n?.clone())}static createXYEllipse(t,e,n,i,s){const r=C.createScale(e,n,1,s?.matrixRef);return s?s.set(t,r,i):N.createRefs(t.clone(),r,i?.clone())}setVector0Vector90(t,e){this._matrix.setColumns(t,e,t.unitCrossProductWithDefault(e,0,0,0))}toScaledMatrix3d(){const t=A.dotProductsToHalfAngleTrigValues(this._matrix.columnXMagnitudeSquared(),this._matrix.columnYMagnitudeSquared(),this._matrix.columnXDotColumnY(),!0),e=this._matrix.multiplyXY(t.c,t.s),n=this._matrix.multiplyXY(-t.s,t.c),i=C.createRigidFromColumns(e,n,mt.XYZ);return{center:this._center.clone(),axes:i||C.createIdentity(),r0:e.magnitude(),r90:n.magnitude(),sweep:this.sweep.cloneMinusRadians(t.radians)}}toVectors(){return{center:this.center.clone(),vector0:this._matrix.columnX(),vector90:this._matrix.columnY(),sweep:this.sweep.clone()}}toTransformedVectors(t){return t?{center:t.multiplyPoint3d(this._center),vector0:t.multiplyVector(this._matrix.columnX()),vector90:t.multiplyVector(this._matrix.columnY()),sweep:this.sweep.clone()}:{center:this._center.clone(),vector0:this._matrix.columnX(),vector90:this._matrix.columnY(),sweep:this.sweep.clone()}}toTransformedPoint4d(t){return{center:t.multiplyPoint3d(this._center,1),vector0:t.multiplyPoint3d(this._matrix.columnX(),0),vector90:t.multiplyPoint3d(this._matrix.columnY(),0),sweep:this.sweep.clone()}}setFromJSON(t){if(t&&t.center&&t.vector0&&t.vector90&&t.sweep){this._center.setFromJSON(t.center);const e=P.create(),n=P.create();e.setFromJSON(t.vector0),n.setFromJSON(t.vector90),this.setVector0Vector90(e,n),this._sweep.setFromJSON(t.sweep)}else this._center.set(0,0,0),this._matrix.setFrom(C.identity),this._sweep.setStartEndRadians()}toJSON(){return{center:this._center.toJSON(),sweep:this._sweep.toJSON(),vector0:this._matrix.columnX().toJSON(),vector90:this._matrix.columnY().toJSON()}}isAlmostEqual(t,e=f.smallMetricDistance,n=f.smallAngleRadians){if(t instanceof N){const i=t;return this._center.isAlmostEqual(i._center,e)&&this._matrix.isAlmostEqual(i._matrix,e)&&this._sweep.isAlmostEqualAllowPeriodShift(i._sweep,n)}return!1}emitStrokes(t,e){const n=this.computeStrokeCountForOptions(e);t.appendFractionalStrokePoints(this,n,0,1,!0)}emitStrokableParts(t,e){const n=this.computeStrokeCountForOptions(e);t.startCurvePrimitive(this),t.announceIntervalForUniformStepStrokes(this,n,0,1),t.endCurvePrimitive(this)}computeStrokeCountForOptions(t){let e;if(t){const n=this.maxVectorLength();e=t.applyTolerancesToArc(n,this._sweep.sweepRadians)}else e=Zt.applyAngleTol(void 0,1,this._sweep.sweepRadians);return e}dispatchToGeometryHandler(t){return t.handleArc3d(this)}clonePartialCurve(t,e){if(e<t){const i=this.clonePartialCurve(e,t);return i.reverseInPlace(),i}const n=this.clone();return n.sweep.setStartEndRadians(this.sweep.fractionToRadians(t),this.sweep.fractionToRadians(e)),n}cloneInRotatedBasis(t){const e=t.cos(),n=t.sin(),i=this._matrix.multiplyXY(e,n),s=this._matrix.multiplyXY(-n,e),r=at.createStartEndRadians(this._sweep.startRadians-t.radians,this._sweep.endRadians-t.radians);return N.create(this._center.clone(),i,s,r)}cloneAxisAligned(){const t=ht.create(this.center,this.perpendicularVector.crossProduct(P.unitX()));if(!t)return;const e=[];if(this.appendPlaneIntersectionPoints(t,e)!==2)return;const n=t.getNormalRef().dotProduct(this.perpendicularVector.crossProductStartEnd(this.center,e[0].point))>0?0:1,i=this.sweep.fractionToAngle(e[n].fraction),s=this.cloneInRotatedBasis(i);if(this.perpendicularVector.dotProduct(P.unitZ())<-f.smallAngleRadians){if(this.matrixRef.isSingular())return;const r=C.createRowValues(1,0,0,0,-1,0,0,0,-1);s.matrixRef.multiplyMatrixMatrix(r,s.matrixRef),s.sweep.setStartEndDegrees(-s.sweep.startDegrees,-s.sweep.endDegrees)}return s}announceClipIntervals(t,e){return t.announceClippedArcIntervals(this,e)}otherArcAsLocalVectors(t){const e=this._matrix.multiplyInverseXYZAsPoint3d(t.center.x-this.center.x,t.center.y-this.center.y,t.center.z-this.center.z),n=this._matrix.multiplyInverse(t.vector0),i=this._matrix.multiplyInverse(t.vector90);if(e&&n&&i)return{center:e,vector0:n,vector90:i,sweep:this.sweep.clone()}}static createFilletArc(t,e,n,i){const s=P.createStartEnd(e,t),r=P.createStartEnd(e,n),o=s.magnitude(),a=r.magnitude();if(s.normalizeInPlace()&&r.normalizeInPlace()){const c=s.plus(r);if(c.normalizeInPlace()){const l=r.minus(s),d=l.magnitude(),h=.5*d;if(!f.isSmallAngleRadians(h)){const g=Math.sqrt(1-h*h),m=h/g,p=Math.acos(h),x=i/h,_=i/m,I=_/o,v=_/a,S=e.plusScaled(c,x);return c.scaleInPlace(-i),l.scaleInPlace(i/d),{arc:N.create(S,c,l,at.createStartEndRadians(-p,p)),fraction10:I,fraction12:v,point:e.clone()}}}}return{fraction10:0,fraction12:0,point:e.clone()}}scaleAboutCenterInPlace(t){this._matrix.scaleColumnsInPlace(t,t,1)}areaToChordXY(t,e){const n=f.crossProductXYXY(this._matrix.coffs[0],this._matrix.coffs[3],this._matrix.coffs[1],this._matrix.coffs[4]),i=this._sweep.fractionToRadians(t),r=.5*(this._sweep.fractionToRadians(e)-i),o=Math.cos(r)*Math.sin(r);return(r-o)*n}constructOffsetXY(t){const e=Oe.create(t);if(this.isCircular||e.preserveEllipticalArcs){const i=this.cloneAtZ(),s=i.sweep.sweepRadians*i.matrixRef.coffs[8]>=0?1:-1,r=i.matrixRef.columnXMagnitude(),o=r-s*e.leftOffsetDistance,a=this.isCircular?r:i.matrixRef.columnYMagnitude(),c=this.isCircular?o:a-s*e.leftOffsetDistance;if(!f.isSmallMetricDistance(o)&&r*o>0&&(this.isCircular||!f.isSmallMetricDistance(c)&&a*c>0)){const l=o/r,d=this.isCircular?l:c/a;return i.matrixRef.scaleColumnsInPlace(l,d,1),i}return}const n=new Vs(this,e.leftOffsetDistance);return this.emitStrokableParts(n,e.strokeOptions),n.claimResult()}projectedParameterRange(t,e){return Le.findExtremeFractionsAlongDirection(this,t,e)}constructCircularArcChainApproximation(t){t||(t=Di.create());const n=mi.create(this).constructCircularArcChainApproximation(t);return!n&&this.isCircular?this.sweep.isFullCircle&&t.forcePath?Pt.create(this):this:n}computeTangentIntersection(t=0,e=1,n){const i=this.fractionToPointAndDerivative(t,N._workRay0),s=this.fractionToPointAndDerivative(e,N._workRay1);if(i.direction.isParallelTo(s.direction,!0,!0))return;const r=i.clone(N._workRay2);if(this.matrixRef.multiplyInverseXYZAsPoint3d(i.origin.x,i.origin.y,i.origin.z,i.origin)&&this.matrixRef.multiplyInverseXYZAsPoint3d(s.origin.x,s.origin.y,s.origin.z,s.origin)&&this.matrixRef.multiplyInverseXYZAsVector3d(i.direction.x,i.direction.y,i.direction.z,i.direction)&&this.matrixRef.multiplyInverseXYZAsVector3d(s.direction.x,s.direction.y,s.direction.z,s.direction)){const o=bt.lineXYUVTransverseIntersection(i.origin,i.direction,s.origin,s.direction);if(o)return r.fractionToPoint(o.x,n)}}}class pt{_coffs;constructor(){this._coffs=new Float64Array(16)}setFrom(t){for(let e=0;e<16;e++)this._coffs[e]=t._coffs[e]}clone(t){if(t===this)return this;t===void 0&&(t=new pt);for(let e=0;e<16;e++)t._coffs[e]=this._coffs[e];return t}setZero(){for(let t=0;t<16;t++)this._coffs[t]=0}setIdentity(){for(let t=0;t<16;t++)this._coffs[t]=0;this._coffs[0]=this._coffs[5]=this._coffs[10]=this._coffs[15]=1}static is1000(t,e,n,i,s){return Math.abs(t-1)<=s&&Math.abs(e)<=s&&Math.abs(n)<=s&&Math.abs(i)<=s}isIdentity(t=1e-10){return pt.is1000(this._coffs[0],this._coffs[1],this._coffs[2],this._coffs[3],t)&&pt.is1000(this._coffs[5],this._coffs[6],this._coffs[7],this._coffs[4],t)&&pt.is1000(this._coffs[10],this._coffs[11],this._coffs[8],this._coffs[9],t)&&pt.is1000(this._coffs[15],this._coffs[12],this._coffs[13],this._coffs[14],t)}static createZero(t){return t?(t.setZero(),t):new pt}static createRowValues(t,e,n,i,s,r,o,a,c,l,d,h,g,m,p,x,_){return _=_||new pt,_._coffs[0]=t,_._coffs[1]=e,_._coffs[2]=n,_._coffs[3]=i,_._coffs[4]=s,_._coffs[5]=r,_._coffs[6]=o,_._coffs[7]=a,_._coffs[8]=c,_._coffs[9]=l,_._coffs[10]=d,_._coffs[11]=h,_._coffs[12]=g,_._coffs[13]=m,_._coffs[14]=p,_._coffs[15]=x,_}static createRows(t,e,n,i,s){return this.createRowValues(t.x,t.y,t.z,t.w,e.x,e.y,e.z,e.w,n.x,n.y,n.z,n.w,i.x,i.y,i.z,i.w,s)}setOriginAndVectors(t,e,n,i){this._coffs[0]=e.x,this._coffs[1]=n.x,this._coffs[2]=i.x,this._coffs[3]=t.x,this._coffs[4]=e.y,this._coffs[5]=n.y,this._coffs[6]=i.y,this._coffs[7]=t.y,this._coffs[8]=e.z,this._coffs[9]=n.z,this._coffs[10]=i.z,this._coffs[11]=t.z,this._coffs[12]=0,this._coffs[13]=0,this._coffs[14]=0,this._coffs[15]=1}static createTransform(t,e){const n=t.matrix,i=t.origin;return pt.createRowValues(n.coffs[0],n.coffs[1],n.coffs[2],i.x,n.coffs[3],n.coffs[4],n.coffs[5],i.y,n.coffs[6],n.coffs[7],n.coffs[8],i.z,0,0,0,1,e)}static createIdentity(t){return t=pt.createZero(t),t._coffs[0]=1,t._coffs[5]=1,t._coffs[10]=1,t._coffs[15]=1,t}static createTranslationXYZ(t,e,n,i){return i=pt.createZero(i),i._coffs[0]=1,i._coffs[5]=1,i._coffs[10]=1,i._coffs[15]=1,i._coffs[3]=t,i._coffs[7]=e,i._coffs[11]=n,i}plusScaled(t,e,n){n=this.clone(n);for(let i=0;i<16;i++)n._coffs[i]+=e*t._coffs[i];return n}static createTranslationAndScaleXYZ(t,e,n,i,s,r,o){return pt.createRowValues(i,0,0,t,0,s,0,e,0,0,r,n,0,0,0,1,o)}static createBoxToBox(t,e,n,i,s){const r=e.x-t.x,o=e.y-t.y,a=e.z-t.z,c=i.x-n.x,l=i.y-n.y,d=i.z-n.z,h=f.conditionalDivideFraction(c,r),g=f.conditionalDivideFraction(l,o),m=f.conditionalDivideFraction(d,a);if(h!==void 0&&g!==void 0&&m!==void 0)return pt.createTranslationAndScaleXYZ(n.x-h*t.x,n.y-g*t.y,n.z-m*t.z,h,g,m,s)}setFromJSON(t){if(f.isArrayOfNumberArray(t,4,4))for(let e=0;e<4;++e)for(let n=0;n<4;++n)this._coffs[e*4+n]=t[e][n];else this.setZero()}maxDiff(t){let e=0;for(let n=0;n<16;n++)e=Math.max(e,Math.abs(this._coffs[n]-t._coffs[n]));return e}maxAbs(){let t=0;for(let e=0;e<16;e++)t=Math.max(t,Math.abs(this._coffs[e]));return t}isAlmostEqual(t){return f.isSmallMetricDistance(this.maxDiff(t))}isExactEqual(t){return this.maxDiff(t)===0}toJSON(){const t=[];for(let e=0;e<4;++e){const n=e*4;t.push([this._coffs[n],this._coffs[n+1],this._coffs[n+2],this._coffs[n+3]])}return t}static fromJSON(t){const e=new pt;return e.setFromJSON(t),e}getSteppedPoint(t,e,n){return Z.create(this._coffs[t],this._coffs[t+e],this._coffs[t+2*e],this._coffs[t+3*e],n)}columnX(){return this.getSteppedPoint(0,4)}columnY(){return this.getSteppedPoint(1,4)}columnZ(){return this.getSteppedPoint(2,4)}columnW(){return this.getSteppedPoint(3,4)}rowX(){return this.getSteppedPoint(0,1)}rowY(){return this.getSteppedPoint(4,1)}rowZ(){return this.getSteppedPoint(8,1)}rowW(){return this.getSteppedPoint(12,1)}get hasPerspective(){return this._coffs[12]!==0||this._coffs[13]!==0||this._coffs[14]!==0||this._coffs[15]!==1}diagonal(){return this.getSteppedPoint(0,5)}weight(){return this._coffs[15]}matrixPart(){return C.createRowValues(this._coffs[0],this._coffs[1],this._coffs[2],this._coffs[4],this._coffs[5],this._coffs[6],this._coffs[8],this._coffs[9],this._coffs[10])}get asTransform(){if(!this.hasPerspective)return X.createRowValues(this._coffs[0],this._coffs[1],this._coffs[2],this._coffs[3],this._coffs[4],this._coffs[5],this._coffs[6],this._coffs[7],this._coffs[8],this._coffs[9],this._coffs[10],this._coffs[11])}toTransform(t){const e=X.createIdentity(t);let n=!1;if(this.weight()!==0){const i=1/this.weight();for(let s=0;s<3;s++)for(let r=0;r<3;r++)e.matrix.setAt(s,r,i*this.atIJ(s,r));e.origin.set(i*this.atIJ(0,3),i*this.atIJ(1,3),i*this.atIJ(2,3)),n=f.isSmallMetricDistance(i*Math.abs(this.atIJ(3,0)+Math.abs(this.atIJ(3,1))+Math.abs(this.atIJ(3,2))))}return{transform:e,isValid:n}}multiplyMatrixMatrix(t,e){e=e&&e!==this&&e!==t?e:new pt;for(let n=0;n<16;n+=4)for(let i=0;i<4;i++)e._coffs[n+i]=this._coffs[n]*t._coffs[i]+this._coffs[n+1]*t._coffs[i+4]+this._coffs[n+2]*t._coffs[i+8]+this._coffs[n+3]*t._coffs[i+12];return e}multiplyMatrixMatrixTranspose(t,e){e=e&&e!==this&&e!==t?e:new pt;let n=0;for(let i=0;i<16;i+=4)for(let s=0;s<16;s+=4)e._coffs[n++]=this._coffs[i]*t._coffs[s]+this._coffs[i+1]*t._coffs[s+1]+this._coffs[i+2]*t._coffs[s+2]+this._coffs[i+3]*t._coffs[s+3];return e}multiplyMatrixTransposeMatrix(t,e){e=e&&e!==this&&e!==t?e:new pt;let n=0;for(let i=0;i<4;i+=1)for(let s=0;s<4;s+=1)e._coffs[n++]=this._coffs[i]*t._coffs[s]+this._coffs[i+4]*t._coffs[s+4]+this._coffs[i+8]*t._coffs[s+8]+this._coffs[i+12]*t._coffs[s+12];return e}cloneTransposed(t){return pt.createRowValues(this._coffs[0],this._coffs[4],this._coffs[8],this._coffs[12],this._coffs[1],this._coffs[5],this._coffs[9],this._coffs[13],this._coffs[2],this._coffs[6],this._coffs[10],this._coffs[14],this._coffs[3],this._coffs[7],this._coffs[11],this._coffs[15],t)}multiplyXYZW(t,e,n,i,s){return s=s||Z.createZero(),s.set(this._coffs[0]*t+this._coffs[1]*e+this._coffs[2]*n+this._coffs[3]*i,this._coffs[4]*t+this._coffs[5]*e+this._coffs[6]*n+this._coffs[7]*i,this._coffs[8]*t+this._coffs[9]*e+this._coffs[10]*n+this._coffs[11]*i,this._coffs[12]*t+this._coffs[13]*e+this._coffs[14]*n+this._coffs[15]*i)}multiplyBlockedFloat64ArrayInPlace(t){const e=t.length;let n,i,s,r;for(let o=0;o+3<e;o+=4)n=t[o],i=t[o+1],s=t[o+2],r=t[o+3],t[o]=this._coffs[0]*n+this._coffs[1]*i+this._coffs[2]*s+this._coffs[3]*r,t[o+1]=this._coffs[4]*n+this._coffs[5]*i+this._coffs[6]*s+this._coffs[7]*r,t[o+2]=this._coffs[8]*n+this._coffs[9]*i+this._coffs[10]*s+this._coffs[11]*r,t[o+3]=this._coffs[12]*n+this._coffs[13]*i+this._coffs[14]*s+this._coffs[15]*r}multiplyPoint3d(t,e,n){return this.multiplyXYZW(t.x,t.y,t.z,e,n)}multiplyPoint3dArray(t,e,n=1){t.forEach((i,s)=>{e[s]=this.multiplyXYZW(i.x,i.y,i.z,n,e[s])})}multiplyTransposeXYZW(t,e,n,i,s){return s=s||Z.createZero(),s.set(this._coffs[0]*t+this._coffs[4]*e+this._coffs[8]*n+this._coffs[12]*i,this._coffs[1]*t+this._coffs[5]*e+this._coffs[9]*n+this._coffs[13]*i,this._coffs[2]*t+this._coffs[6]*e+this._coffs[10]*n+this._coffs[14]*i,this._coffs[3]*t+this._coffs[7]*e+this._coffs[11]*n+this._coffs[15]*i)}rowDotColumn(t,e,n){const i=t*4,s=n;return this._coffs[i]*e._coffs[s]+this._coffs[i+1]*e._coffs[s+4]+this._coffs[i+2]*e._coffs[s+8]+this._coffs[i+3]*e._coffs[s+12]}rowDotXYZW(t,e,n,i,s){const r=t*4;return this._coffs[r]*e+this._coffs[r+1]*n+this._coffs[r+2]*i+this._coffs[r+3]*s}rowDotRow(t,e,n){const i=t*4,s=n*4;return this._coffs[i]*e._coffs[s]+this._coffs[i+1]*e._coffs[s+1]+this._coffs[i+2]*e._coffs[s+2]+this._coffs[i+3]*e._coffs[s+3]}columnDotColumn(t,e,n){const i=t,s=n;return this._coffs[i]*e._coffs[s]+this._coffs[i+4]*e._coffs[s+4]+this._coffs[i+8]*e._coffs[s+8]+this._coffs[i+12]*e._coffs[s+12]}columnDotRow(t,e,n){const i=t,s=4*n;return this._coffs[i]*e._coffs[s]+this._coffs[i+4]*e._coffs[s+1]+this._coffs[i+8]*e._coffs[s+2]+this._coffs[i+12]*e._coffs[s+3]}atIJ(t,e){return this._coffs[t*4+e]}setAtIJ(t,e,n){this._coffs[t*4+e]=n}multiplyXYZWQuietRenormalize(t,e,n,i,s){s=s||y.createZero(),s.set(this._coffs[0]*t+this._coffs[1]*e+this._coffs[2]*n+this._coffs[3]*i,this._coffs[4]*t+this._coffs[5]*e+this._coffs[6]*n+this._coffs[7]*i,this._coffs[8]*t+this._coffs[9]*e+this._coffs[10]*n+this._coffs[11]*i);const r=this._coffs[12]*t+this._coffs[13]*e+this._coffs[14]*n+this._coffs[15]*i,o=f.conditionalDivideCoordinate(s.x,r),a=f.conditionalDivideCoordinate(s.y,r),c=f.conditionalDivideCoordinate(s.z,r);return o!==void 0&&a!==void 0&&c!==void 0&&(s.x=o,s.y=a,s.z=c),s}multiplyPoint4dArrayQuietRenormalize(t,e){t.forEach((n,i)=>{e[i]=this.multiplyXYZWQuietRenormalize(n.x,n.y,n.z,n.w,e[i])})}multiplyPoint4d(t,e){return this.multiplyXYZW(t.xyzw[0],t.xyzw[1],t.xyzw[2],t.xyzw[3],e)}multiplyTransposePoint4d(t,e){return this.multiplyTransposeXYZW(t.xyzw[0],t.xyzw[1],t.xyzw[2],t.xyzw[3],e)}multiplyPoint3dQuietNormalize(t,e){return this.multiplyXYZWQuietRenormalize(t.x,t.y,t.z,1,e)}multiplyPoint3dArrayQuietNormalize(t){t.forEach(e=>this.multiplyXYZWQuietRenormalize(e.x,e.y,e.z,1,e))}addMomentsInPlace(t,e,n,i){this._coffs[0]+=t*t,this._coffs[1]+=t*e,this._coffs[2]+=t*n,this._coffs[3]+=t*i,this._coffs[4]+=e*t,this._coffs[5]+=e*e,this._coffs[6]+=e*n,this._coffs[7]+=e*i,this._coffs[8]+=n*t,this._coffs[9]+=n*e,this._coffs[10]+=n*n,this._coffs[11]+=n*i,this._coffs[12]+=i*t,this._coffs[13]+=i*e,this._coffs[14]+=i*n,this._coffs[15]+=i*i}addScaledInPlace(t,e=1){for(let n=0;n<16;n++)this._coffs[n]+=e*t._coffs[n]}rowOperation(t,e,n,i){if(i===0)return;let s=t*4+n,r=e*4+n;for(let o=n;o<4;o++,s++,r++)this._coffs[r]+=i*this._coffs[s]}determinant(){const t=this._coffs;return f.determinant4x4(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15])}createInverse(t){let e=this.columnX().maxAbs();if(e===0)return;const n=1/e;if(e=this.columnY().maxAbs(),e===0)return;const i=1/e;if(e=this.columnZ().maxAbs(),e===0)return;const s=1/e;if(e=this.columnW().maxAbs(),e===0)return;const r=1/e,o=this.columnX(),a=this.columnY(),c=this.columnZ(),l=this.columnW();o.scale(n,o),a.scale(i,a),c.scale(s,c),l.scale(r,l);const d=Z.perpendicularPoint4dPlane(a,c,l),h=Z.perpendicularPoint4dPlane(o,l,c),g=Z.perpendicularPoint4dPlane(l,o,a),m=Z.perpendicularPoint4dPlane(c,a,o);t=pt.createRows(d,h,g,m,t);const p=d.dotProduct(o),x=h.dotProduct(a),_=g.dotProduct(c),I=m.dotProduct(l),v=t.maxAbs();if(p*x>0&&p*_>0&&p*I>0){if(f.conditionalDivideCoordinate(v,p)!==void 0){const w=1/p;return t.scaleRowsInPlace(n*w,i*w,s*w,r*w),t}}else return}rowArrays(t){return t?[[t(this._coffs[0]),t(this._coffs[1]),t(this._coffs[2]),t(this._coffs[3])],[t(this._coffs[4]),t(this._coffs[5]),t(this._coffs[6]),t(this._coffs[7])],[t(this._coffs[8]),t(this._coffs[9]),t(this._coffs[10]),t(this._coffs[11])],[t(this._coffs[12]),t(this._coffs[13]),t(this._coffs[14]),t(this._coffs[15])]]:[[this._coffs[0],this._coffs[1],this._coffs[2],this._coffs[3]],[this._coffs[4],this._coffs[5],this._coffs[6],this._coffs[7]],[this._coffs[8],this._coffs[9],this._coffs[10],this._coffs[11]],[this._coffs[12],this._coffs[13],this._coffs[14],this._coffs[15]]]}scaleRowsInPlace(t,e,n,i){for(let s=0;s<4;s++)this._coffs[s]*=t;for(let s=4;s<8;s++)this._coffs[s]*=e;for(let s=8;s<12;s++)this._coffs[s]*=n;for(let s=12;s<16;s++)this._coffs[s]*=i}addScaledOuterProductInPlace(t,e,n){let i=t.x*n;this._coffs[0]+=i*e.x,this._coffs[1]+=i*e.y,this._coffs[2]+=i*e.z,this._coffs[3]+=i*e.w,i=t.y*n,this._coffs[4]+=i*e.x,this._coffs[5]+=i*e.y,this._coffs[6]+=i*e.z,this._coffs[7]+=i*e.w,i=t.z*n,this._coffs[8]+=i*e.x,this._coffs[9]+=i*e.y,this._coffs[10]+=i*e.z,this._coffs[11]+=i*e.w,i=t.w*n,this._coffs[12]+=i*e.x,this._coffs[13]+=i*e.y,this._coffs[14]+=i*e.z,this._coffs[15]+=i*e.w}addTranslationSandwichInPlace(t,e,n,i,s){const r=t._coffs[3],o=t._coffs[7],a=t._coffs[11],c=t._coffs[12],l=t._coffs[13],d=t._coffs[14],h=t._coffs[15],g=e*h,m=n*h,p=i*h;this._coffs[0]+=s*(t._coffs[0]+e*r+c*e+e*g),this._coffs[1]+=s*(t._coffs[1]+n*r+l*e+e*m),this._coffs[2]+=s*(t._coffs[2]+i*r+d*e+e*p),this._coffs[3]+=s*(r+g),this._coffs[4]+=s*(t._coffs[4]+e*o+c*n+n*g),this._coffs[5]+=s*(t._coffs[5]+n*o+l*n+n*m),this._coffs[6]+=s*(t._coffs[6]+i*o+d*n+n*p),this._coffs[7]+=s*(o+m),this._coffs[8]+=s*(t._coffs[8]+e*a+c*i+i*g),this._coffs[9]+=s*(t._coffs[9]+n*a+l*i+i*m),this._coffs[10]+=s*(t._coffs[10]+i*a+d*i+i*p),this._coffs[11]+=s*(a+p),this._coffs[12]+=s*(c+g),this._coffs[13]+=s*(l+m),this._coffs[14]+=s*(d+p),this._coffs[15]+=s*h}multiplyTranslationSandwichInPlace(t,e,n){const i=this._coffs[3],s=this._coffs[7],r=this._coffs[11],o=this._coffs[12],a=this._coffs[13],c=this._coffs[14],l=this._coffs[15],d=t*l,h=e*l,g=n*l;this._coffs[0]+=t*i+o*t+t*d,this._coffs[1]+=e*i+a*t+t*h,this._coffs[2]+=n*i+c*t+t*g,this._coffs[3]+=d,this._coffs[4]+=t*s+o*e+e*d,this._coffs[5]+=e*s+a*e+e*h,this._coffs[6]+=n*s+c*e+e*g,this._coffs[7]+=h,this._coffs[8]+=t*r+o*n+n*d,this._coffs[9]+=e*r+a*n+n*h,this._coffs[10]+=n*r+c*n+n*g,this._coffs[11]+=g,this._coffs[12]+=d,this._coffs[13]+=h,this._coffs[14]+=g}}class Qr{xTest;yTest;u0;v0;u1;v1;numLeftCrossing;numRightCrossing;numHit;constructor(t,e){this.xTest=t,this.yTest=e,this.u0=this.v0=this.u1=this.v1=0,this.numLeftCrossing=this.numRightCrossing=0,this.numHit=0}tryStartEdge(t,e,n,i){return e!==this.yTest?(this.u0=t-this.xTest,this.v0=e-this.yTest,this.u1=n-this.xTest,this.v1=i-this.yTest,!0):!1}updateUV01(t,e){return this.u0=this.u1,this.v0=this.v1,this.u1=t,this.v1=e,!0}advance(t,e){const n=t-this.xTest,i=e-this.yTest,s=i*this.v1;if(s>0)return this.updateUV01(n,i);if(s<0){const o=-this.v1/(i-this.v1),a=this.u1+o*(n-this.u1);return a===0?(this.numHit++,!1):(a>0?this.numRightCrossing++:this.numLeftCrossing++,this.updateUV01(n,i))}return i===0?this.v1===0?n*this.u1<=0?(this.numHit++,!1):(this.u1=n,this.v1=i,!0):n===0?(this.numHit++,!1):this.updateUV01(n,i):this.u1===0?(this.numHit++,!1):(this.v0*i<0&&(this.u1>0?this.numRightCrossing++:this.numLeftCrossing++),this.updateUV01(n,i))}classifyCounts(){return this.numHit>0?0:(this.numLeftCrossing&1)===1?1:-1}}class te{constructor(t,e,n){this._toleranceSquared=n*n,this._source=t,this._dest=e}_source;_dest;_toleranceSquared;acceptPointByIndex(t){const e=this._source.getPoint3dAtCheckedPointIndex(this._source.cyclicIndex(t));e&&this._dest.push(e)}static _vector01=P.create();static _vectorQ=P.create();indexOfMaxCrossProduct(t,e){let n=0,i,s;for(let r=t;r<=e;r++){const o=this._source.cyclicIndex(r),a=this._source.cyclicIndex(r+1),c=this._source.cyclicIndex(r+2);this._source.crossProductIndexIndexIndex(o,a,c,te._vectorQ),i=te._vectorQ.magnitudeSquared(),i>n&&(n=i,s=r)}return s}indexOfMaxDeviation(t,e){const n=this._source.cyclicIndex(t),i=this._source.cyclicIndex(e);let s=this._toleranceSquared,r,o,a,c,l;this._source.vectorUncheckedIndexIndex(n,i,te._vector01);const d=te._vector01.magnitudeSquared();for(let h=t+1;h<e;h++)l=this._source.cyclicIndex(h),this._source.vectorIndexIndex(n,l,te._vectorQ),o=te._vector01.dotProduct(te._vectorQ),o<=0?a=te._vectorQ.magnitudeSquared():o>d?(this._source.vectorIndexIndex(i,l,te._vectorQ),a=te._vectorQ.magnitudeSquared()):(c=o/d,a=te._vectorQ.magnitudeSquared()-d*c*c),a>s&&(s=a,r=h);return r}recursiveCompressByChordErrorGo(t,e){if(e===t+1){this.acceptPointByIndex(e);return}const n=this.indexOfMaxDeviation(t,e);n===void 0?this.acceptPointByIndex(e):(this.recursiveCompressByChordErrorGo(t,n),this.recursiveCompressByChordErrorGo(n,e))}static compressPoint3dArrayByChordError(t,e=f.smallMetricDistance,n=!1){const i=new Bt(t),s=new Bt([]);return this.compressCollectionByChordError(i,s,e,n),s.data}static compressCollectionByChordError(t,e,n=f.smallMetricDistance,i=!1){e.clear();const s=t.length;if(s===1){e.push(t.getPoint3dAtUncheckedPointIndex(0));return}const r=new te(t,e,n);let o=0,a=s-1;if(s>2&&!i&&t.distanceUncheckedIndexIndex(0,s-1)<=n){const c=r.indexOfMaxCrossProduct(0,s-1);c!==void 0&&(o=c+1,a=o+s)}r.acceptPointByIndex(o),r.recursiveCompressByChordErrorGo(o,a)}static compressInPlaceByShortEdgeLength(t,e){const n=t.length;if(n<2)return;let i=0,s=n-1;for(;s>0&&t.distanceUncheckedIndexIndex(s-1,n-1)<=e;)s--;if(s===0){t.length=1;return}s<n-1&&t.moveIndexToIndex(n-1,s);let r=i+1;for(;r<=s;)t.distanceUncheckedIndexIndex(i,r)>e&&(t.moveIndexToIndex(r,i+1),i++),r++;t.length=i+1}static compressInPlaceBySmallTriangleArea(t,e){const n=t.length;if(n<3)return;let i=0;const s=P.create();for(let r=1;r+1<n;r++)t.crossProductIndexIndexIndex(i,r,r+1,s),.5*s.magnitude()>e&&t.moveIndexToIndex(r,++i);t.moveIndexToIndex(n-1,++i),t.length=i+1}static compressInPlaceByPerpendicularDistance(t,e,n=1.0001){const i=t.length;if(i<3)return;let s=0;const r=te._vector01,o=te._vectorQ;let a;const c=e*e;let l,d=1;for(;d+1<i;d++){t.vectorIndexIndex(s,d+1,r),t.vectorIndexIndex(s,d,o),l=r.magnitudeSquared();const h=f.conditionalDivideFraction(o.dotProduct(r),l);if(h!==void 0&&h>=0&&h<=n&&(a=te._vectorQ.magnitudeSquared()-l*h*h,a<=c)){t.moveIndexToIndex(d+1,++s),d=d+1;continue}t.moveIndexToIndex(d,++s)}d<i&&t.moveIndexToIndex(d,++s),t.length=s+1}static compressColinearWrapInPlace(t,e,n){const i=t.length-1;if(i>=3&&t[0].distance(t[i])<e){const s=i-1,r=0,a=P.createStartEnd(t[s],t[1]),c=P.createStartEnd(t[s],t[r]),l=a.dotProduct(a),d=a.dotProduct(c),h=f.conditionalDivideFraction(d,l);if(h!==void 0&&h>0&&h<1){const g=c.magnitudeSquared()-h*h*l;Math.sqrt(Math.abs(g))<n&&(t[0]=t[s],t.pop())}}}}class Wt extends ut{curveCollectionType="parityRegion";isSameGeometryClass(t){return t instanceof Wt}_children;get children(){return this._children}constructor(){super(),this._children=[]}addLoops(t){if(t!==void 0){if(t instanceof tt)this.children.push(t);else if(Array.isArray(t))for(const e of t)e instanceof tt?this.children.push(e):Array.isArray(e)&&this.addLoops(e)}}static createLoops(t){if(t instanceof tt)return t;const e=new Wt;return e.addLoops(t),e}static create(...t){const e=new Wt;for(const n of t)e.children.push(n);return e}dgnBoundaryType(){return 4}announceToCurveProcessor(t,e=-1){return t.announceParityRegion(this,e)}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}cloneStroked(t){const e=new Wt;let n;for(n of this.children){const i=n.cloneStroked(t);i&&e.children.push(i)}return e}cloneEmptyPeer(){return new Wt}tryAddChild(t){return t&&t instanceof tt?(this._children.push(t),!0):!1}getChild(t){if(t<this._children.length)return this._children[t]}dispatchToGeometryHandler(t){return t.handleParityRegion(this)}}class ve extends ut{curveCollectionType="unionRegion";isSameGeometryClass(t){return t instanceof ve}_children;get children(){return this._children}constructor(){super(),this._children=[]}static create(...t){const e=new ve;for(const n of t)e.tryAddChild(n);return e}dgnBoundaryType(){return 5}announceToCurveProcessor(t,e=-1){return t.announceUnionRegion(this,e)}cloneStroked(t){const e=new ve;let n;for(n of this._children){const i=n.cloneStroked(t);i&&e.children.push(i)}return e}cloneEmptyPeer(){return new ve}clone(){return super.clone()}cloneTransformed(t){return super.cloneTransformed(t)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(t){return t&&(t instanceof Wt||t instanceof tt)?(this._children.push(t),!0):!1}getChild(t){if(t<this._children.length)return this._children[t]}dispatchToGeometryHandler(t){return t.handleUnionRegion(this)}}class aa{searchFractions=[.2349,.4142,.6587,.8193];constructInteriorPoint(t){if(t.direction.z=0,!t.direction.normalizeInPlace())return;t.direction.rotate90CCWXY(t.direction),this.signedArea<0&&t.direction.scaleInPlace(-1);const e=Math.sqrt(Math.abs(this.signedArea)),n=y.create();for(let i=1e-5;i<3;i*=5)if(t.fractionToPoint(i*e,n),this.classifyPointXY(n)===1)return n}}class _c extends aa{data;_signedArea;get signedArea(){return this._signedArea}constructor(t){super(),this.data=t,this._signedArea=nt.areaXY(t)}classifyPointXY(t){return nt.classifyPointInPolygonXY(t.x,t.y,this.data)}getAnyInteriorPoint(){for(let t=0;t<this.data.length;t++)for(const e of this.searchFractions){const n=this.constructInteriorPointNearEdge(t,e);if(n!==void 0)return n}}grabPolygon(){return this.data}grabLoop(){return tt.createPolygon(this.data)}reverseForAreaSign(t){t*this._signedArea<0&&(this.data.reverseInPlace(),this._signedArea*=-1)}constructInteriorPointNearEdge(t,e){if(0<=t&&t+1<this.data.length){const n=O.createCapture(this.data.interpolateUncheckedIndexIndex(t,e,t+1),this.data.vectorUncheckedIndexIndex(t,t+1));return this.constructInteriorPoint(n)}}}class yc extends aa{data;_signedArea;get signedArea(){return this._signedArea}constructor(t){super(),this.data=t;const e=ot.computeXYAreaMoments(t);this._signedArea=e!==void 0?e.quantitySum:0}classifyPointXY(t){return ot.testPointInOnOutRegionXY(this.data,t.x,t.y)}constructInteriorPointNearChild(t,e){if(t<this.data.children.length){const n=this.data.children[t].fractionToPointAndDerivative(e);return this.constructInteriorPoint(n)}}getAnyInteriorPoint(){for(let t=0;t<this.data.children.length;t++)for(const e of this.searchFractions){const n=this.constructInteriorPointNearChild(t,e);if(n!==void 0)return n}}grabPolygon(){const t=this.data.cloneStroked(),e=F.create();for(const n of t.children)n.emitStrokes(e);return e.packedPoints}grabLoop(){return this.data}reverseForAreaSign(t){t*this._signedArea<0&&(this.data.reverseChildrenInPlace(),this._signedArea*=-1)}}class ei{_loopCarrier;anyPoint;sortKey;range;parentIndex;isHole;outputSetIndex;constructor(t,e){t instanceof Ts?this._loopCarrier=new _c(t):this._loopCarrier=new yc(t),this.range=e,this.sortKey=Math.abs(this._loopCarrier.signedArea),this.isHole=!1}static pushPolygon(t,e){const n=e.getRange(),i=new ei(e,n);return i.sortKey>0?(t.push(i),!0):!1}static pushLoop(t,e){const n=e.range(),i=new ei(e,n);return i.sortKey>0?(t.push(i),!0):!1}static assignParentsAndDepth(t){t.sort((e,n)=>n.sortKey-e.sortKey);for(let e=t.length;e-- >0;){const n=t[e],i=n._loopCarrier.getAnyInteriorPoint();if(i!==void 0){n.parentIndex=n.outputSetIndex=void 0;for(let s=e;s-- >0;){const r=t[s];if(r.range.containsXY(i.x,i.y)&&r._loopCarrier.classifyPointXY(i)===1){n.parentIndex=s;break}}}}}static assemblePolygonSet(t){const e=[];for(const n of t){n.isHole=!1;const i=n.parentIndex;if(i!==void 0&&(n.isHole=!t[i].isHole),!n.isHole)n._loopCarrier.reverseForAreaSign(1),n.outputSetIndex=e.length,e.push([]),e[n.outputSetIndex].push(n._loopCarrier.grabPolygon());else{n._loopCarrier.reverseForAreaSign(-1);const s=t[i].outputSetIndex;e[s].push(n._loopCarrier.grabPolygon())}}return e}static assembleLoopSet(t){const e=[],n=t.length;for(let i=0;i<n;i++){const s=t[i],r=s.parentIndex;if(s.isHole=r!==void 0?!t[r].isHole:!1,!s.isHole){s._loopCarrier.reverseForAreaSign(1);const o=s._loopCarrier.grabLoop();let a;for(let c=i+1;c<n;c++){const l=t[c];l.parentIndex===i&&(a===void 0?(a=Wt.create(),a.tryAddChild(o),l._loopCarrier.reverseForAreaSign(-1),a.tryAddChild(l._loopCarrier.grabLoop())):(l._loopCarrier.reverseForAreaSign(-1),a.tryAddChild(l._loopCarrier.grabLoop())))}a!==void 0?e.push(a):e.push(o)}}return e}static sortAsAnyRegion(t){this.assignParentsAndDepth(t);const e=this.assembleLoopSet(t);if(e.length===1)return e[0];{const n=ve.create();for(const i of e)n.tryAddChild(i);return n}}static sortAsArrayOfArrayOfPolygons(t){return this.assignParentsAndDepth(t),this.assemblePolygonSet(t)}grabPolygon(){return this._loopCarrier.grabPolygon()}grabLoop(){return this._loopCarrier.grabLoop()}reverseForAreaSign(t){this._loopCarrier.reverseForAreaSign(t)}getAnyInteriorPoint(){return this._loopCarrier.getAnyInteriorPoint()}}class Dt{origin;needOrigin;sums;localToWorldMap;radiusOfGyration;absoluteQuantity;static _vectorA;static _vectorB;static _vectorC;_point0=y.create();_point1=y.create();constructor(){this.origin=y.createZero(),this.needOrigin=!1,this.sums=pt.createZero(),this.localToWorldMap=X.createIdentity(),this.radiusOfGyration=P.create(),this.absoluteQuantity=.1,this.absoluteQuantity=void 0}get quantitySum(){return this.sums.weight()}signFactor(t){return t*this.quantitySum>0?1:-1}setOriginIfNeeded(t){this.needOrigin&&(this.origin.setFromPoint3d(t),this.needOrigin=!1)}setOriginFromGrowableXYZArrayIfNeeded(t){this.needOrigin&&t.length>0&&(t.getPoint3dAtCheckedPointIndex(0,this.origin),this.needOrigin=!1)}setOriginXYZIfNeeded(t,e,n){this.needOrigin&&(this.origin.set(t,e,n),this.needOrigin=!1)}static create(t,e=!1){const n=new Dt;return n.needOrigin=e,t&&(n.origin.setFromPoint3d(t),n.needOrigin=!1),n}static momentTensorFromInertiaProducts(t){const e=t.sumDiagonal(),n=C.createScale(e,e,e);return n.addScaledInPlace(t,-1),n}static sortColumnsForIncreasingMoments(t,e){const n=[t.indexedColumnWithWeight(0,e.x),t.indexedColumnWithWeight(1,e.y),t.indexedColumnWithWeight(2,e.z)].sort((i,s)=>i.w<s.w?-1:i.w>s.w?1:0);t.setColumnsPoint4dXYZ(n[0],n[1],n[2]),t.determinant()<0&&t.scaleColumnsInPlace(-1,-1,-1),t.at(0,0)<0&&t.scaleColumnsInPlace(-1,-1,1),t.at(2,2)<0&&t.scaleColumnsInPlace(1,-1,-1),e.set(n[0].w,n[1].w,n[2].w)}static pointsToPrincipalAxes(t){const e=new Dt;return t.length===0?e:(e.clearSums(t[0]),e.accumulatePointMomentsFromOrigin(t),this.inertiaProductsToPrincipalAxes(e.origin,e.sums))}static inertiaProductsToPrincipalAxes(t,e){const n=new Dt;if(n.sums.setFrom(e),n.origin.setFrom(t),!n.shiftOriginAndSumsToCentroidOfSums())return;const i=n.sums.matrixPart(),s=n.sums.weight();s<0&&i.scaleColumnsInPlace(-1,-1,-1);const r=Dt.momentTensorFromInertiaProducts(i),o=P.create(),a=C.createZero();if(r.fastSymmetricEigenvalues(a,o),!(o.x<0))return Dt.sortColumnsForIncreasingMoments(a,o),s<0&&a.scaleColumnsInPlace(1,-1,-1),n.localToWorldMap=X.createOriginAndMatrix(n.origin,a),n.radiusOfGyration.set(Math.sqrt(Math.abs(o.x)),Math.sqrt(Math.abs(o.y)),Math.sqrt(Math.abs(o.z))),n.radiusOfGyration.scaleInPlace(1/Math.sqrt(Math.abs(s))),n.absoluteQuantity=Math.abs(s),n}static areEquivalentPrincipalAxes(t,e){if(t&&e&&f.isSameCoordinate(t.quantitySum,e.quantitySum)&&t.localToWorldMap.getOrigin().isAlmostEqual(e.localToWorldMap.getOrigin())&&t.radiusOfGyration.isAlmostEqual(e.radiusOfGyration)){if(f.isSameCoordinate(t.radiusOfGyration.x,t.radiusOfGyration.y)){if(f.isSameCoordinate(t.radiusOfGyration.x,t.radiusOfGyration.z))return!0;const s=t.localToWorldMap.matrix.columnZ(),r=e.localToWorldMap.matrix.columnZ();return!!s.isParallelTo(r,!0)}const n=P.create(),i=P.create();for(let s=0;s<3;s++)if(t.localToWorldMap.matrix.getColumn(s,n),e.localToWorldMap.matrix.getColumn(s,i),!n.isParallelTo(i,!0))return!1;return!0}return!1}clearSums(t){this.sums.setZero(),t?this.origin.setFrom(t):this.origin.setZero()}accumulatePointMomentsFromOrigin(t){for(const e of t)this.sums.addMomentsInPlace(e.x-this.origin.x,e.y-this.origin.y,e.z-this.origin.z,1)}shiftOriginAndSumsToCentroidOfSums(){const t=this.sums.columnW().realPoint();return t?(this.shiftOriginAndSumsByXYZ(t.x,t.y,t.z),!0):!1}shiftOriginAndSumsByXYZ(t,e,n){this.origin.addXYZInPlace(t,e,n),this.sums.multiplyTranslationSandwichInPlace(-t,-e,-n)}shiftOriginAndSumsToNewOrigin(t){this.shiftOriginAndSumsByXYZ(t.x-this.origin.x,t.y-this.origin.y,t.z-this.origin.z)}accumulateTriangleMomentsXY(t,e,n){this.setOriginXYZIfNeeded(e.x,e.y,0);const i=this.origin.x,s=this.origin.y,r=Dt._vectorA=t!==void 0?Z.create(t.x-i,t.y-s,0,1,Dt._vectorA):Z.create(0,0,0,1,Dt._vectorA),o=Dt._vectorB=Z.create(e.x-i,e.y-s,0,1,Dt._vectorB),a=Dt._vectorC=Z.create(n.x-i,n.y-s,0,1,Dt._vectorC),c=f.crossProductXYXY(o.x-r.x,o.y-r.y,a.x-r.x,a.y-r.y);if(c!==0){const l=c/12,d=c/24;this.sums.addScaledOuterProductInPlace(r,r,l),this.sums.addScaledOuterProductInPlace(r,o,d),this.sums.addScaledOuterProductInPlace(r,a,d),this.sums.addScaledOuterProductInPlace(o,r,d),this.sums.addScaledOuterProductInPlace(o,o,l),this.sums.addScaledOuterProductInPlace(o,a,d),this.sums.addScaledOuterProductInPlace(a,r,d),this.sums.addScaledOuterProductInPlace(a,o,d),this.sums.addScaledOuterProductInPlace(a,a,l)}}accumulateScaledOuterProduct(t,e){this.setOriginXYZIfNeeded(t.x,t.y,0);const n=Dt._vectorA=Z.create(t.x-this.origin.x,t.y-this.origin.y,t.z-this.origin.z,1,Dt._vectorA);this.sums.addScaledOuterProductInPlace(n,n,e)}accumulateLineMomentsXYZ(t,e){this.setOriginXYZIfNeeded(t.x,t.y,t.z);const n=this.origin.x,i=this.origin.y,s=this.origin.z,r=Dt._vectorA=Z.create(t.x-n,t.y-i,t.z-s,1,Dt._vectorA),o=Dt._vectorB=Z.create(e.x-n,e.y-i,e.z-s,1,Dt._vectorB),a=t.distance(e),c=a/3,l=a/6;this.sums.addScaledOuterProductInPlace(r,r,c),this.sums.addScaledOuterProductInPlace(r,o,l),this.sums.addScaledOuterProductInPlace(o,r,l),this.sums.addScaledOuterProductInPlace(o,o,c)}accumulateTriangleToLineStringMomentsXY(t,e){const n=e.length;if(n>1){e.getPoint3dAtUncheckedPointIndex(0,this._point0);for(let i=1;i<n;i++)e.getPoint3dAtUncheckedPointIndex(i,this._point1),this.accumulateTriangleMomentsXY(t,this._point0,this._point1),this._point0.setFromPoint3d(this._point1)}}accumulateXYProductsInCentroidalFrame(t,e,n,i,s,r,o){const a=pt.createRowValues(t,e,0,0,e,n,0,0,0,0,0,0,0,0,0,i),c=f.crossProductXYXY(r.x,o.x,r.y,o.y),l=pt.createRowValues(r.x,o.x,0,s.x-this.origin.x,r.y,o.y,0,s.y-this.origin.y,0,0,0,0,0,0,0,1),h=l.multiplyMatrixMatrix(a).multiplyMatrixMatrixTranspose(l);this.sums.addScaledInPlace(h,c)}accumulateProducts(t,e){this.setOriginIfNeeded(t.origin),this.sums.addTranslationSandwichInPlace(t.sums,this.origin.x-t.origin.x,this.origin.y-t.origin.y,this.origin.z-t.origin.z,e)}accumulateProductsFromOrigin(t,e,n){this.setOriginIfNeeded(t),this.sums.addTranslationSandwichInPlace(e,this.origin.x-t.x,this.origin.y-t.y,this.origin.z-t.z,n)}toJSON(){return{origin:this.origin,sums:this.sums.toJSON(),radiusOfGyration:this.radiusOfGyration.toJSON(),localToWorld:this.localToWorldMap.toJSON()}}}class Zs extends Ys{_geometry1;_fraction;constructor(t,e,n){super(),this._geometry1=n,this._fraction=e}handleLineSegment3d(t){if(this._geometry1 instanceof U){const e=this._geometry1;return U.create(t.startPoint().interpolate(this._fraction,e.startPoint()),t.endPoint().interpolate(this._fraction,e.endPoint()))}}handleLineString3d(t){if(this._geometry1 instanceof F){const e=this._geometry1;if(t.numPoints()===e.numPoints()){const n=t.numPoints(),i=F.create(),s=y.create(),r=y.create(),o=y.create(),a=this._fraction;for(let c=0;c<n;c++)t.pointAt(c,r),e.pointAt(c,o),r.interpolate(a,o,s),i.addPoint(s);if(t.fractions&&e.fractions)for(let c=0;c<n;c++)i.addFraction(f.interpolate(t.fractions.atUncheckedIndex(c),a,e.fractions.atUncheckedIndex(c)));if(t.strokeData&&e.strokeData&&(i.strokeData=t.strokeData.clone()),t.packedDerivatives&&e.packedDerivatives){const c=P.create(),l=P.create();for(let d=0;d<n;d++)t.packedDerivatives.getVector3dAtCheckedVectorIndex(d,c),e.packedDerivatives.getVector3dAtCheckedVectorIndex(d,l),i.addDerivative(c.interpolate(a,l))}return i}}}handleArc3d(t){if(this._geometry1 instanceof N){const e=this._geometry1;return N.create(t.center.interpolate(this._fraction,e.center),t.vector0.interpolate(this._fraction,e.vector0),t.vector90.interpolate(this._fraction,e.vector90),t.sweep.interpolate(this._fraction,e.sweep))}}static interpolateBetween(t,e,n){const i=new Zs(t,e,n);return t.dispatchToGeometryHandler(i)}}class qs extends Ae{geometryCategory="solid";_capped;constructor(t){super(),this._capped=t}get capped(){return this._capped}set capped(t){this._capped=t}get isSkew(){return!1}}class xi extends qs{solidPrimitiveType="cone";_localToWorld;_radiusA;_radiusB;_maxRadius;constructor(t,e,n,i){super(i),this._localToWorld=t,this._radiusA=e,this._radiusB=n,this._maxRadius=Math.max(this._radiusA,this._radiusB)}clone(){return new xi(this._localToWorld.clone(),this._radiusA,this._radiusB,this.capped)}getConstructiveFrame(){return this._localToWorld.cloneRigid()}tryTransformInPlace(t){return t.matrix.isSingular()?!1:(t.multiplyTransformTransform(this._localToWorld,this._localToWorld),t.matrix.determinant()<0&&(this._localToWorld.origin.addInPlace(this._localToWorld.matrix.columnZ()),this._localToWorld.matrix.scaleColumnsInPlace(1,1,-1),[this._radiusA,this._radiusB]=[this._radiusB,this._radiusA]),!0)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t)?e:void 0}static createAxisPoints(t,e,n,i,s){const r=t.vectorTo(e),o=r.magnitude();if(f.isSmallMetricDistance(o)||(n=f.correctSmallMetricDistance(n),i=f.correctSmallMetricDistance(i),n*i<0)||n+i===0)return;const a=C.createRigidHeadsUp(r);a.scaleColumns(1,1,o,a);const c=X.createOriginAndMatrix(t,a);return new xi(c,n,i,s??!1)}static createBaseAndTarget(t,e,n,i,s,r,o){s=Math.abs(f.correctSmallMetricDistance(s)),r=Math.abs(f.correctSmallMetricDistance(r));const a=t.vectorTo(e),c=X.createOriginAndMatrixColumns(t,n,i,a);return new xi(c,s,r,o??!1)}static createDgnCone(t,e,n,i,s,r,o){const a=C.createRigidFromColumns(n,i,mt.XYZ);if(a){const c=n.magnitude();return this.createBaseAndTarget(t,e,a.columnX(),a.columnY(),s*c,r*c,o)}}getCenterA(){return this._localToWorld.multiplyXYZ(0,0,0)}getCenterB(){return this._localToWorld.multiplyXYZ(0,0,1)}getVectorX(){return this._localToWorld.matrix.columnX()}getVectorY(){return this._localToWorld.matrix.columnY()}getRadiusA(){return this._radiusA}getRadiusB(){return this._radiusB}getMaxRadius(){return this._maxRadius}vFractionToRadius(t){return f.interpolate(this._radiusA,t,this._radiusB)}isSameGeometryClass(t){return t instanceof xi}isAlmostEqual(t){return t instanceof xi?this.capped!==t.capped||!this._localToWorld.isAlmostEqualAllowZRotation(t._localToWorld)?!1:f.isSameCoordinate(this._radiusA,t._radiusA)&&f.isSameCoordinate(this._radiusB,t._radiusB):!1}dispatchToGeometryHandler(t){return t.handleCone(this)}strokeConstantVSection(t,e,n){let i=16;e!==void 0?i=e:n!==void 0&&(i=n.defaultCircleStrokes),i=f.clampToStartEnd(i,4,64);const s=this.vFractionToRadius(t),r=F.createForStrokes(e,n),o=Math.PI*2,a=o/i;let c=0;const l=r.fractions,d=r.packedDerivatives,h=r.packedUVParams,g=r.packedSurfaceNormals,m=y.create(),p=P.create(),x=P.create(),_=P.create(),I=this._localToWorld;let v,S,w,T;for(let R=0;R<=i;R++)R*2<=i?c=R*a:c=(R-i)*a,w=Math.cos(c),T=Math.sin(c),v=s*w,S=s*T,I.multiplyXYZ(v,S,t,m),r.addPoint(m),l&&l.push(R/i),d&&(I.matrix.multiplyXYZ(-S*o,v*o,0,p),d.push(p)),g&&(I.matrix.multiplyXYZ(-T,w,0,p),I.matrix.multiplyXYZ(0,0,1,x),p.unitCrossProduct(x,_),g.push(_)),h&&h.pushXY(R/i,t);return r}constantVSection(t){const e=this.vFractionToRadius(t),n=this._localToWorld,i=n.multiplyXYZ(0,0,t),s=n.matrix.multiplyXYZ(e,0,0),r=n.matrix.multiplyXYZ(0,e,0);return tt.create(N.create(i,s,r))}extendRange(t,e){const n=this.constantVSection(0),i=this.constantVSection(1);n.extendRange(t,e),i.extendRange(t,e)}uvFractionToPoint(t,e,n){const i=t*Math.PI*2,s=f.interpolate(this._radiusA,e,this._radiusB),r=Math.cos(i),o=Math.sin(i);return this._localToWorld.multiplyXYZ(s*r,s*o,e,n)}uvFractionToPointAndTangents(t,e,n){const i=t*Math.PI*2,s=f.interpolate(this._radiusA,e,this._radiusB),r=this._radiusB-this._radiusA,o=Math.cos(i),a=Math.sin(i),c=2*Math.PI;return At.createOriginAndVectors(this._localToWorld.multiplyXYZ(s*o,s*a,e),this._localToWorld.multiplyVectorXYZ(-s*a*c,s*o*c,0),this._localToWorld.multiplyVectorXYZ(r*o,r*a,1),n)}get isSkew(){return!this._localToWorld.matrix.columnZ().isParallelTo(this._localToWorld.matrix.columnXCrossColumnY(),!0,!0)}cylinderRadius(t=!1){let e=0;if(t||!this.isSkew){const n=this._localToWorld.matrix.columnXMagnitude(),i=this._localToWorld.matrix.columnYMagnitude();f.isSameCoordinate(n,i)&&f.isSameCoordinate(this._radiusA,this._radiusB)&&(e=Math.abs(n*this._radiusA))}return e}get isClosedVolume(){return this.capped}maxIsoParametricDistance(){const t=this._localToWorld.matrix.columnX(),e=this._localToWorld.matrix.columnY(),n=t.unitCrossProduct(e);if(!n)return Q.createZero();const i=this._localToWorld.matrix.columnZ(),s=n.dotProduct(i),o=i.plusScaled(n,s).magnitudeXY();return Q.create(Math.PI*2*Math.max(this._radiusA,this._radiusB),f.hypotenuseXY(Math.abs(this._radiusB-this._radiusA)+o,s))}}class Pc{_cachedObjects;_numDrop;_numCreate;_numReuse;constructor(){this._cachedObjects=[],this._numDrop=0,this._numCreate=0,this._numReuse=0}dropToCache(t){t&&(this._numDrop++,this.clearForCache(t),this._cachedObjects.push(t))}grabFromCache(){let t=this._cachedObjects.pop();return t===void 0?(t=this.createForCache(),this._numCreate++):this._numReuse++,t}dropAllToCache(t){for(;t.length>0;)this.dropToCache(t.pop())}}class $r extends Pc{constructor(){super()}createForCache(t=10,e=1.5){return new W(t,e)}clearForCache(t){t.length=0}grabAndFill(t){const e=this.grabFromCache();return e.pushFrom(t),e}}class Ws{_data;_inUse;_blockSize;_growthFactor;constructor(t,e=8,n){this._data=new Float64Array(e*t),this._inUse=0,this._blockSize=t>0?t:1,this._growthFactor=n!==void 0&&n>=1?n:1.5}copyData(t,e,n){let i=n!==void 0?n*this.numPerBlock:0;if(i<0&&(i=0),i>=this._data.length)return{count:0,offset:0};let s=e!==void 0?e*this.numPerBlock:t.length;return s>0&&(s>t.length&&(s=t.length),i+s>this._data.length&&(s=this._data.length-i),s%this.numPerBlock!==0&&(s-=s%this.numPerBlock)),s<=0?{count:0,offset:0}:(s===t.length?this._data.set(t,i):t instanceof Float64Array?this._data.set(t.subarray(0,s),i):this._data.set(t.slice(0,s),i),{count:s/this.numPerBlock,offset:i/this.numPerBlock})}clone(){const t=new Ws(this.numPerBlock,this.numBlocks,this._growthFactor);return t.copyData(this._data,this.numBlocks),t._inUse=this.numBlocks,t}get length(){return this._inUse}get numBlocks(){return this._inUse}get numPerBlock(){return this._blockSize}getWithinBlock(t,e){return this._data[t*this._blockSize+e]}clear(){this._inUse=0}blockCapacity(){return this._data.length/this._blockSize}ensureBlockCapacity(t,e=!0){if(t>this.blockCapacity()){e&&(t*=this._growthFactor);const n=this._data;this._data=new Float64Array(t*this._blockSize),this.copyData(n,this._inUse)}}addBlock(t){const e=this.newBlockIndex();let n=t.length;n>this._blockSize&&(n=this._blockSize);for(let i=0;i<n;i++)this._data[e+i]=t[i]}newBlockIndex(){const t=this._blockSize*this._inUse;t+1>this._data.length&&this.ensureBlockCapacity(1+this._inUse),this._inUse++;for(let e=t;e<t+this._blockSize;e++)this._data[e]=0;return t}popBlock(){this._inUse>0&&this._inUse--}blockIndexToDoubleIndex(t){return this._blockSize*t}checkedComponent(t,e){if(!(t>=this._inUse||t<0||e<0||e>=this._blockSize))return this._data[this._blockSize*t+e]}component(t,e){return this._data[this._blockSize*t+e]}static compareLexicalBlock(t,e,n,i){let s=0,r=0;for(let o=0;o<e;o++){if(s=t[n+o],r=t[i+o],s>r)return 1;if(s<r)return-1}return n-i}sortIndicesLexical(t=(e,n,i,s)=>Ws.compareLexicalBlock(e,n,i,s)){const e=this._inUse,n=new Uint32Array(e),i=this._data,s=this._blockSize;for(let r=0;r<e;r++)n[r]=r;return n.sort((r,o)=>t(i,s,r*s,o*s)),n}distanceBetweenBlocks(t,e){let n=0,i=this.blockIndexToDoubleIndex(t),s=this.blockIndexToDoubleIndex(e),r=0;const o=this._data;for(let a=0;a<this._blockSize;a++)r=o[i++]-o[s++],n+=r*r;return Math.sqrt(n)}distanceBetweenSubBlocks(t,e,n,i){let s=0;const r=this.blockIndexToDoubleIndex(t),o=this.blockIndexToDoubleIndex(e);let a=0;const c=this._data;for(let l=n;l<i;l++)a=c[r+l]-c[o+l],s+=a*a;return Math.sqrt(s)}}class Tt extends Ws{static _vectorFactor=.8732;static sortVectorComponent(t){let e=1;for(let n=1;n<t;n++)e*=Tt._vectorFactor;return e}_numCoordinatePerPoint;_numExtraDataPerPoint;constructor(t,e,n){super(1+t+e,n),this._numExtraDataPerPoint=e,this._numCoordinatePerPoint=t}addBlock(t){const e=this.newBlockIndex()+1,n=Math.min(this.numPerBlock-1,t.length);for(let i=0;i<n;i++)this._data[e+i]=t[i]}addDirect(t,e,n,i,s){const r=this.newBlockIndex();this._data[r+1]=t,e!==void 0&&(this._data[r+2]=e),n!==void 0&&(this._data[r+3]=n),i!==void 0&&(this._data[r+4]=i),s!==void 0&&(this._data[r+5]=s)}addPoint2d(t,e,n,i){const s=this.newBlockIndex();this._data[s+1]=t.x,this._data[s+2]=t.y,e!==void 0&&(this._data[s+3]=e),n!==void 0&&(this._data[s+4]=n),i!==void 0&&(this._data[s+5]=i)}addPoint3d(t,e,n,i){const s=this.newBlockIndex();this._data[s+1]=t.x,this._data[s+2]=t.y,this._data[s+3]=t.z,e!==void 0&&(this._data[s+4]=e),n!==void 0&&(this._data[s+5]=n),i!==void 0&&(this._data[s+6]=i)}getPoint2d(t,e){const n=this.blockIndexToDoubleIndex(t);return D.create(this._data[n+1],this._data[n+2],e)}getPoint3d(t,e){const n=this.blockIndexToDoubleIndex(t);return y.create(this._data[n+1],this._data[n+2],this._data[n+3],e)}getExtraData(t,e){const n=this.blockIndexToDoubleIndex(t);return this._data[n+1+this._numCoordinatePerPoint+e]}getData(t,e){const n=this.blockIndexToDoubleIndex(t);return this._data[n+e]}setExtraData(t,e,n){const i=this.blockIndexToDoubleIndex(t);this._data[i+1+this._numCoordinatePerPoint+e]=n}static clusterTerminator=4294967295;static isClusterTerminator(t){return t===Tt.clusterTerminator}clusterIndicesLexical(t=f.smallMetricDistance){this.setupPrimaryClusterSort();const e=this.sortIndicesLexical(),n=new Uint32Array(2*e.length);let i=0;const s=this.numBlocks;let r=0,o=0,a=0,c=0,l=0;const d=1,h=1+this._numCoordinatePerPoint;for(c=0;c<s;c++)if(r=e[c],!Tt.isClusterTerminator(r)){for(n[i++]=r,a=this.component(r,0)+t,e[c]=Tt.clusterTerminator,l=c+1;l<s;l++)if(o=e[l],o!==Tt.clusterTerminator){if(this.component(o,0)>a)break;this.distanceBetweenSubBlocks(r,o,d,h)<=t&&(n[i++]=o,e[l]=Tt.clusterTerminator)}n[i++]=Tt.clusterTerminator}return n.slice(0,i)}setupPrimaryClusterSort(){const t=this.numBlocks,e=this._numCoordinatePerPoint,n=new Float64Array(e);n[0]=1;for(let o=1;o<e;o++)n[o]=n[o-1]*Tt._vectorFactor;let i=0,s=0;const r=this._data;for(let o=0;o<t;o++){i=this.blockIndexToDoubleIndex(o),s=0;for(let a=0;a<e;a++)s+=n[a]*r[i+1+a];r[i]=s}}toJSON(){const t=[];for(let e=0;e<this.numBlocks;e++){let n=this.blockIndexToDoubleIndex(e);const i=[e,this._data[n++]],s=[];for(let r=0;r<this._numCoordinatePerPoint;r++)s.push(this._data[n++]);i.push(s);for(let r=0;r<this._numExtraDataPerPoint;r++)i.push(this._data[n++]);t.push(i)}return t}createIndexBlockToClusterIndex(t){const e=this.numBlocks,n=new Uint32Array(e);n.fill(Tt.clusterTerminator);let i=0;for(const s of t)s>=e?i++:n[s]=i;return n}createIndexBlockToClusterStart(t){const e=t.length,n=this.numBlocks,i=new Uint32Array(n),s=Tt.clusterTerminator;i.fill(s);let r=0;for(let o=0;o<e;o++){const a=t[o];a>n?r=o+1:i[a]=r}return i}countClusters(t){let e=0;const n=Tt.clusterTerminator;for(const i of t)i===n&&e++;return e}createIndexClusterToClusterStart(t){let e=this.countClusters(t);const n=new Uint32Array(e),i=Tt.clusterTerminator;n.fill(i);const s=t.length;let r=0;for(let o=0;o<s;o++)t[o]===i?r=o+1:o===r&&(n[e++]=r);return n}sortSubsetsBySingleKey(t,e){const n=1+e;let i=0,s,r,o;const a=t.length;for(let c=0;c<a;c++)if(t[c]===Tt.clusterTerminator){for(let l=i;l+1<c;l++){r=this.getWithinBlock(t[l],n);for(let d=l+1;d<c;d++)o=this.getWithinBlock(t[d],n),o<r&&(s=t[l],t[l]=t[d],t[d]=s,r=o)}i=c+1}}static clusterPoint3dArray(t,e=f.smallMetricDistance){const n=new Tt(3,0,t.length);t.forEach(a=>{n.addDirect(a.x,a.y,a.z)});const i=n.clusterIndicesLexical(e),s=new Ki(t.length,0);let r=0,o=0;return i.forEach(a=>{Tt.isClusterTerminator(a)?(r++,o=0):(o===0&&s.packedPoints.push(t[a].clone()),s.oldToNew[a]=r,o++)}),s}static clusterNumberArray(t,e=f.smallMetricDistance){const n=new Tt(1,0,t.length);t.forEach(a=>{n.addDirect(a)});const i=n.clusterIndicesLexical(e),s=new Ic(t.length);let r=0,o=0;return i.forEach(a=>{Tt.isClusterTerminator(a)?(r++,o=0):(o===0&&s.packedNumbers.push(t[a]),s.oldToNew[a]=r,o++)}),s}static clusterGrowablePoint2dArray(t,e=f.smallMetricDistance){const n=new Tt(2,0,t.length),i=D.create(),s=t.length;for(let d=0;d<s;d++)t.getPoint2dAtUncheckedPointIndex(d,i),n.addDirect(i.x,i.y);const r=n.clusterIndicesLexical(e),o=n.countClusters(r),a=new to(t.length,o);let c=0,l=0;return r.forEach(d=>{Tt.isClusterTerminator(d)?(c++,l=0):(l===0&&a.growablePackedPoints.pushFromGrowableXYArray(t,d),a.oldToNew[d]=c,l++)}),a}static clusterGrowablePoint3dArray(t,e=f.smallMetricDistance){const n=new Tt(3,0,t.length),i=y.create(),s=t.length;for(let d=0;d<s;d++)t.getPoint3dAtUncheckedPointIndex(d,i),n.addDirect(i.x,i.y,i.z);const r=n.clusterIndicesLexical(e),o=n.countClusters(r),a=new Ki(t.length,o);let c=0,l=0;return r.forEach(d=>{Tt.isClusterTerminator(d)?(c++,l=0):(l===0&&a.growablePackedPoints.pushFromGrowableXYZArray(t,d),a.oldToNew[d]=c,l++)}),a}}function jr(u,t){let e=0;return u.forEach((n,i,s)=>{n<t.length?s[i]=t[n]:e++}),e===0}class Ki{packedPoints;growablePackedPoints;oldToNew;static invalidIndex=4294967295;constructor(t,e){this.packedPoints=[],this.growablePackedPoints=new W(e),this.oldToNew=new Uint32Array(t);for(let n=0;n<t;n++)this.oldToNew[n]=Ki.invalidIndex}updateIndices(t){return jr(t,this.oldToNew)}}class to{growablePackedPoints;oldToNew;static invalidIndex=4294967295;constructor(t,e){this.growablePackedPoints=new Ie(e),this.oldToNew=new Uint32Array(t);for(let n=0;n<t;n++)this.oldToNew[n]=to.invalidIndex}updateIndices(t){return jr(t,this.oldToNew)}}class Ic{packedNumbers;oldToNew;static invalidIndex=4294967295;constructor(t){this.packedNumbers=[],this.oldToNew=new Uint32Array(t);for(let e=0;e<t;e++)this.oldToNew[e]=Ki.invalidIndex}updateIndices(t){return jr(t,this.oldToNew)}}var Te;(function(u){u[u.Scalar=0]="Scalar",u[u.Distance=1]="Distance",u[u.Vector=2]="Vector",u[u.Normal=3]="Normal"})(Te||(Te={}));class Gs{input;values;constructor(t,e){if(this.input=t,e instanceof Float64Array){this.values=[];for(const n of e)this.values.push(n)}else this.values=e}copyValues(t,e,n,i){for(let s=0;s<i;s++)this.values[e*i+s]=t.values[n*i+s]}clone(){return new Gs(this.input,this.values.slice())}isAlmostEqual(t,e){const n=e||1e-8;return Math.abs(this.input-t.input)<n&&Pe.isAlmostEqual(this.values,t.values,n)}}let ca=class Ar{data;dataType;name;inputName;constructor(t,e,n,i){this.data=t,this.dataType=e,this.name=n,this.inputName=i}clone(){const t=[];for(const e of this.data)t.push(e.clone());return new Ar(t,this.dataType,this.name,this.inputName)}isAlmostEqual(t,e){if(this.dataType!==t.dataType||this.name!==t.name||this.inputName!==t.inputName||this.data.length!==t.data.length)return!1;for(let n=0;n<this.data.length;n++)if(!this.data[n].isAlmostEqual(t.data[n],e))return!1;return!0}static isScalar(t){return t===Te.Distance||t===Te.Scalar}get isScalar(){return Ar.isScalar(this.dataType)}static entriesPerValue(t){return this.isScalar(t)?1:3}get entriesPerValue(){return Ar.entriesPerValue(this.dataType)}get valueCount(){return this.data.length===0?0:this.data[0].values.length/this.entriesPerValue}get scalarRange(){if(!this.isScalar)return;const t=ct.createNull();for(const e of this.data)t.extendArray(e.values);return t}computeDisplacementRange(t=1,e){if(e=J.createNull(e),Te.Vector===this.dataType)for(const n of this.data){const i=n.values;for(let s=0;s<i.length;s+=3)e.extendXYZ(i[s]*t,i[s+1]*t,i[s+2]*t)}return e}};class Hs{channels;indices;constructor(t,e){this.channels=t,this.indices=e}clone(){const t=this.channels.map(e=>e.clone());return new Hs(t,this.indices.slice())}isAlmostEqual(t,e){if(!Pe.isExactEqual(this.indices,t.indices)||this.channels.length!==t.channels.length)return!1;for(let n=0;n<this.channels.length;n++)if(!this.channels[n].isAlmostEqual(t.channels[n],e))return!1;return!0}static isAlmostEqual(t,e,n){return t===e?!0:t&&e?t.isAlmostEqual(e,n):!1}createForVisitor(){const t=[];for(const e of this.channels){const n=[];for(const i of e.data)n.push(new Gs(i.input,[]));t.push(new ca(n,e.dataType,e.name,e.inputName))}return new Hs(t,[])}tryTransformInPlace(t){let e;const n=t.matrix,i=n.determinant(),s=Math.pow(Math.abs(i),1/3)*(i>=0?1:-1);for(const r of this.channels)for(const o of r.data)switch(r.dataType){case Te.Scalar:continue;case Te.Distance:{for(let a=0;a<o.values.length;a++)o.values[a]*=s;break}case Te.Normal:{if(e=e??n.inverse(),!e)return!1;la(o.values,a=>{e.multiplyTransposeVectorInPlace(a);const c=a.magnitudeSquared(),l=1e-15;if(c>l&&Math.abs(c-1)>l){const d=1/Math.sqrt(c);a.scaleInPlace(d)}});break}case Te.Vector:{la(o.values,a=>n.multiplyVectorInPlace(a));break}}return!0}}function la(u,t){const e=new y;for(let n=0;n<u.length;n+=3)e.set(u[n],u[n+1],u[n+2]),t(e),u[n]=e.x,u[n+1]=e.y,u[n+2]=e.z}var da;(function(u){(function(t){t[t.SubdivisionSurface=-1e3]="SubdivisionSurface"})(u.TaggedNumericTagType||(u.TaggedNumericTagType={})),(function(t){t[t.ChooseBasedOnFacets=0]="ChooseBasedOnFacets",t[t.CatmullClark=1]="CatmullClark",t[t.Loop=2]="Loop",t[t.DooSabin=3]="DooSabin"})(u.SubdivisionMethod||(u.SubdivisionMethod={})),(function(t){t[t.FixedDepth=-100]="FixedDepth",t[t.AbsoluteTolerance=-101]="AbsoluteTolerance",t[t.FractionOfRangeBoxTolerance=-102]="FractionOfRangeBoxTolerance"})(u.SubdivisionControlCode||(u.SubdivisionControlCode={}))})(da||(da={}));class eo{tagA;tagB;constructor(t=0,e=0,n,i){this.tagA=t,this.tagB=e,n&&(this.intData=n),i&&(this.doubleData=i)}intData;doubleData;pushIntPair(t,e){this.intData||(this.intData=[]),this.intData.push(t),this.intData.push(e)}pushIndexedDouble(t,e){this.intData||(this.intData=[]),this.doubleData||(this.doubleData=[]),this.intData.push(t),this.intData.push(this.doubleData.length),this.doubleData.push(e)}tagToInt(t,e,n,i){if(this.intData){for(let s=0;s+1<this.intData.length;s+=2)if(this.intData[s]===t)return Math.min(Math.max(this.intData[s+1],e),n)}return i}tagToIndexedDouble(t,e,n,i){if(this.intData){for(let s=0;s+1<this.intData.length;s+=2)if(this.intData[s]===t)return f.clamp(this.getDoubleData(this.intData[s+1],i),e,n)}return i}getDoubleData(t,e){return this.doubleData&&0<=t&&t<this.doubleData.length?this.doubleData[t]:e}isAlmostEqual(t){return t===void 0||this.tagA!==t.tagA||this.tagB!==t.tagB?!1:f.exactEqualNumberArrays(this.intData,t.intData)&&f.almostEqualArrays(this.doubleData,t.doubleData,(e,n)=>f.isAlmostEqualNumber(e,n))}static areAlmostEqual(t,e){return t===void 0&&e===void 0?!0:t!==void 0&&e!==void 0?t.isAlmostEqual(e):!1}clone(t){return t||(t=new eo(this.tagA,this.tagB)),this.intData&&(t.intData=this.intData.slice()),this.doubleData&&(t.doubleData=this.doubleData.slice()),t}}class ne{static planarityLocalRelTol=1e-13;point;pointIndex;normal;normalIndex;param;paramIndex;color;colorIndex;face;auxData;taggedNumericData;edgeVisible;_twoSided;_expectedClosure;edgeMateIndex;edgeIndexToEdgeMateIndex(t){if(t!==void 0&&this.edgeMateIndex!==void 0&&t>=0&&t<this.edgeMateIndex.length)return this.edgeMateIndex[t]}isValidEdgeIndex(t){return t!==void 0&&t>=0&&t<this.pointIndex.length}constructor(t=!1,e=!1,n=!1,i=!0){this.point=new W,this.pointIndex=[],t&&(this.normal=new W,this.normalIndex=[]),e&&(this.param=new Ie,this.paramIndex=[]),n&&(this.color=[],this.colorIndex=[]),this.face=[],this.edgeVisible=[],this._twoSided=i,this._expectedClosure=0}clone(){const t=new ne;return t.point=this.point.clone(),t.pointIndex=this.pointIndex.slice(),this.normal&&(t.normal=this.normal.clone()),this.normalIndex&&(t.normalIndex=this.normalIndex.slice()),this.param&&(t.param=this.param.clone()),this.paramIndex&&(t.paramIndex=this.paramIndex.slice()),this.color&&(t.color=this.color.slice()),this.colorIndex&&(t.colorIndex=this.colorIndex.slice()),t.face=this.face.slice(),this.auxData&&(t.auxData=this.auxData.clone()),this.taggedNumericData&&(t.taggedNumericData=this.taggedNumericData.clone()),t.edgeVisible=this.edgeVisible.slice(),t.twoSided=this.twoSided,t.expectedClosure=this.expectedClosure,this.edgeMateIndex&&(t.edgeMateIndex=this.edgeMateIndex.slice()),t}isAlmostEqual(t){return!(!W.isAlmostEqual(this.point,t.point)||!Pe.isExactEqual(this.pointIndex,t.pointIndex)||!W.isAlmostEqual(this.normal,t.normal)||!Pe.isExactEqual(this.normalIndex,t.normalIndex)||!Ie.isAlmostEqual(this.param,t.param)||!Pe.isExactEqual(this.paramIndex,t.paramIndex)||!Pe.isExactEqual(this.color,t.color)||!Pe.isExactEqual(this.colorIndex,t.colorIndex)||!Hs.isAlmostEqual(this.auxData,t.auxData)||!eo.areAlmostEqual(this.taggedNumericData,t.taggedNumericData)||!Pe.isExactEqual(this.edgeVisible,t.edgeVisible)||this.twoSided!==t.twoSided||this.expectedClosure!==t.expectedClosure||!Pe.isExactEqual(this.edgeMateIndex,t.edgeMateIndex))}get requireNormals(){return this.normal!==void 0}get requireParams(){return this.param!==void 0}get requireColors(){return this.color!==void 0}get pointCount(){return this.point.length}get normalCount(){return this.normal?this.normal.length:0}get paramCount(){return this.param?this.param.length:0}get colorCount(){return this.color?this.color.length:0}get indexCount(){return this.pointIndex.length}get faceCount(){return this.face.length}getPoint(t,e){return this.point.getPoint3dAtCheckedPointIndex(t,e)}getNormal(t,e){return this.normal?this.normal.getVector3dAtCheckedVectorIndex(t,e):void 0}getParam(t,e){return this.param?this.param.getPoint2dAtCheckedPointIndex(t,e):void 0}getColor(t){return this.color?this.color[t]:0}getEdgeVisible(t){return this.edgeVisible[t]}get twoSided(){return this._twoSided}set twoSided(t){this._twoSided=t}get expectedClosure(){return this._expectedClosure}set expectedClosure(t){this._expectedClosure=t}setTaggedNumericData(t){this.taggedNumericData=t}copyPointTo(t,e){this.point.getPoint3dAtUncheckedPointIndex(t,e)}copyNormalTo(t,e){this.normal&&this.normal.getVector3dAtUncheckedVectorIndex(t,e)}copyParamTo(t,e){this.param&&this.param.getPoint2dAtUncheckedPointIndex(t,e)}isAlmostEqualParamIndexUV(t,e,n){return this.param!==void 0&&t>=0&&t<this.param.length?f.isSameCoordinate(e,this.param.getXAtUncheckedPointIndex(t))&&f.isSameCoordinate(n,this.param.getYAtUncheckedPointIndex(t)):!1}gatherIndexedData(t,e,n,i){const s=n-e;i>s&&(i=s);const r=s+i;this.resizeAllArrays(r);for(let o=0;o<s;o++)this.point.transferFromGrowableXYZArray(o,t.point,t.pointIndex[e+o]);for(let o=0;o<i;o++)this.point.transferFromGrowableXYZArray(s+o,this.point,o);for(let o=0;o<s;o++)this.pointIndex[o]=t.pointIndex[e+o];for(let o=0;o<i;o++)this.pointIndex[s+o]=this.pointIndex[o];if(this.normal&&this.normalIndex&&t.normal&&t.normalIndex){for(let o=0;o<s;o++)this.normal.transferFromGrowableXYZArray(o,t.normal,t.normalIndex[e+o]);for(let o=0;o<i;o++)this.normal.transferFromGrowableXYZArray(s+o,this.normal,o);for(let o=0;o<s;o++)this.normalIndex[o]=t.normalIndex[e+o];for(let o=0;o<i;o++)this.normalIndex[s+o]=this.normalIndex[o]}if(this.param&&this.paramIndex&&t.param&&t.paramIndex){for(let o=0;o<s;o++)this.param.transferFromGrowableXYArray(o,t.param,t.paramIndex[e+o]);for(let o=0;o<i;o++)this.param.transferFromGrowableXYArray(s+o,this.param,o);for(let o=0;o<s;o++)this.paramIndex[o]=t.paramIndex[e+o];for(let o=0;o<i;o++)this.paramIndex[s+o]=this.paramIndex[o]}if(this.color&&this.colorIndex&&t.color&&t.colorIndex){for(let o=0;o<s;o++)this.color[o]=t.color[t.colorIndex[e+o]];for(let o=0;o<i;o++)this.color[s+o]=this.color[o];for(let o=0;o<s;o++)this.colorIndex[o]=t.colorIndex[e+o];for(let o=0;o<i;o++)this.colorIndex[s+o]=this.colorIndex[o]}for(let o=0;o<s;o++)this.edgeVisible[o]=t.edgeVisible[e+o];for(let o=0;o<i;o++)this.edgeVisible[s+o]=this.edgeVisible[o];if(this.auxData&&t.auxData&&this.auxData.channels.length===t.auxData.channels.length){for(let o=0;o<this.auxData.channels.length;o++){const a=this.auxData.channels[o],c=t.auxData.channels[o],l=a.entriesPerValue;if(a.data.length===c.data.length)for(let d=0;d<a.data.length;d++){const h=a.data[d],g=c.data[d];for(let m=0;m<s;m++)h.copyValues(g,m,t.auxData.indices[e+m],l);for(let m=0;m<i;m++)h.copyValues(h,t.auxData.indices[s+m],m,l)}}for(let o=0;o<s;o++)this.auxData.indices[o]=t.auxData.indices[e+o];for(let o=0;o<i;o++)this.auxData.indices[s+o]=this.auxData.indices[o]}if(this.edgeMateIndex&&t.edgeMateIndex){for(let o=0;o<s;o++)this.edgeMateIndex[o]=t.edgeMateIndex[e+o];for(let o=0;o<i;o++)this.edgeMateIndex[s+o]=this.edgeMateIndex[o]}}static trimArray(t,e){t&&e<t.length&&(t.length=e)}trimAllIndexArrays(t){if(ne.trimArray(this.pointIndex,t),ne.trimArray(this.paramIndex,t),ne.trimArray(this.normalIndex,t),ne.trimArray(this.colorIndex,t),ne.trimArray(this.edgeVisible,t),this.auxData){ne.trimArray(this.auxData.indices,t);for(const e of this.auxData.channels)for(const n of e.data)ne.trimArray(n.values,e.entriesPerValue*t)}ne.trimArray(this.edgeMateIndex,t)}resizeAllArrays(t){if(t>this.point.length){for(;this.point.length<t;)this.point.push(y.create());for(;this.pointIndex.length<t;)this.pointIndex.push(-1);if(this.normal)for(;this.normal.length<t;)this.normal.push(P.create());if(this.normalIndex)for(;this.normalIndex.length<t;)this.normalIndex.push(-1);if(this.param)for(;this.param.length<t;)this.param.push(D.create());if(this.paramIndex)for(;this.paramIndex.length<t;)this.paramIndex.push(-1);if(this.color)for(;this.color.length<t;)this.color.push(0);if(this.colorIndex)for(;this.colorIndex.length<t;)this.colorIndex.push(-1);for(;this.edgeVisible.length<t;)this.edgeVisible.push(!1);if(this.auxData){for(const e of this.auxData.channels)for(const n of e.data)for(;n.values.length<t*e.entriesPerValue;)n.values.push(0);this.auxData.indices&&this.auxData.indices.push(-1)}if(this.edgeMateIndex)for(;this.edgeMateIndex.length<t;)this.edgeMateIndex.push(void 0)}else if(t<this.point.length){if(this.point.resize(t),this.pointIndex.length=t,this.normal&&this.normal.resize(t),this.normalIndex&&(this.normalIndex.length=t),this.param&&this.param.resize(t),this.paramIndex&&(this.paramIndex.length=t),this.color&&(this.color.length=t),this.colorIndex&&(this.colorIndex.length=t),this.edgeVisible.length=t,this.auxData){for(const e of this.auxData.channels)for(const n of e.data)n.values.length=t*e.entriesPerValue;this.auxData.indices&&(this.auxData.indices.length=t)}this.edgeMateIndex&&(this.edgeMateIndex.length=t)}}resizeAllDataArrays(t){if(t>this.point.length){for(;this.point.length<t;)this.point.push(y.create());for(;this.pointIndex.length<t;)this.pointIndex.push(-1);for(;this.edgeVisible.length<t;)this.edgeVisible.push(!1);if(this.normal)for(;this.normal.length<t;)this.normal.push(P.create());if(this.param)for(;this.param.length<t;)this.param.push(D.create());if(this.color)for(;this.color.length<t;)this.color.push(0);if(this.auxData)for(const e of this.auxData.channels)for(const n of e.data)for(;n.values.length<t*e.entriesPerValue;)n.values.push(0)}else if(t<this.point.length&&(this.point.resize(t),this.edgeVisible.length=t,this.pointIndex.length=t,this.normal&&this.normal.resize(t),this.param&&this.param.resize(t),this.color&&(this.color.length=t),this.auxData))for(const e of this.auxData.channels)for(const n of e.data)n.values.length=t*e.entriesPerValue}range(t,e){const n=J.createNull(t);return this.extendRange(n,e),n}extendRange(t,e){t.extendArray(this.point,e)}tryTransformInPlace(t){if(this.point.multiplyTransformInPlace(t),this.normal&&!t.matrix.isIdentity&&this.normal.multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(t.matrix),this.face.length>0){const e=Math.cbrt(Math.abs(t.matrix.determinant()));for(const n of this.face)n.scaleDistances(e)}return this.auxData&&this.auxData.tryTransformInPlace(t),!0}compress(t=f.smallMetricDistance){const e=Tt.clusterGrowablePoint3dArray(this.point,t);if(this.point=e.growablePackedPoints,e.updateIndices(this.pointIndex),this.normalIndex&&this.normal){const n=Tt.clusterGrowablePoint3dArray(this.normal);this.normal=n.growablePackedPoints,n.updateIndices(this.normalIndex)}if(this.paramIndex&&this.param){const n=Tt.clusterGrowablePoint2dArray(this.param);this.param=n.growablePackedPoints,n.updateIndices(this.paramIndex)}if(this.colorIndex&&this.color){const n=Tt.clusterNumberArray(this.color);this.color=n.packedNumbers,n.updateIndices(this.colorIndex)}if(this.auxData&&this.auxData.channels.length===1&&this.auxData.channels[0].data.length===1){const n=this.auxData.channels[0].entriesPerValue;if(n===1){const i=Tt.clusterNumberArray(this.auxData.channels[0].data[0].values);this.auxData.channels[0].data[0].values=i.packedNumbers,i.updateIndices(this.auxData.indices)}else if(n===3){const i=W.create(this.auxData.channels[0].data[0].values),s=Tt.clusterGrowablePoint3dArray(i);this.auxData.channels[0].data[0].values=Pe.create(s.growablePackedPoints.float64Data()),s.updateIndices(this.auxData.indices)}}}static isValidFacetStartIndexArray(t){if(t.length===0)return!1;for(let e=0;e+1<t.length;e++)if(t[e]>=t[e+1])return!1;return!0}static reverseIndices(t,e,n){if(!e||e.length===0)return!0;if(e.length>0&&t[t.length-1]===e.length){for(let i=0;i+1<t.length;i++){let s=t[i],r=t[i+1];if(n)for(;r>s+2;){r--,s++;const o=e[s];e[s]=e[r],e[r]=o}else for(;r>s+1;){r--;const o=e[s];e[s]=e[r],e[r]=o,s++}}return!0}return!1}static reverseIndicesSingleFacet(t,e,n,i){if(!n||n.length===0)return!0;if(n.length>0&&e[e.length-1]===n.length&&t>=0&&t+1<e.length){let s=e[t],r=e[t+1];if(i)for(;r>s+2;){r--,s++;const o=n[s];n[s]=n[r],n[r]=o}else for(;r>s+1;){r--;const o=n[s];n[s]=n[r],n[r]=o,s++}return!0}return!1}reverseIndices(t){t&&ne.isValidFacetStartIndexArray(t)&&(ne.reverseIndices(t,this.pointIndex,!0),this.normalIndex!==this.pointIndex&&ne.reverseIndices(t,this.normalIndex,!0),this.paramIndex!==this.pointIndex&&ne.reverseIndices(t,this.paramIndex,!0),this.colorIndex!==this.pointIndex&&ne.reverseIndices(t,this.colorIndex,!0),ne.reverseIndices(t,this.edgeVisible,!1))}reverseIndicesSingleFacet(t,e){ne.reverseIndicesSingleFacet(t,e,this.pointIndex,!0),this.normalIndex!==this.pointIndex&&ne.reverseIndicesSingleFacet(t,e,this.normalIndex,!0),this.paramIndex!==this.pointIndex&&ne.reverseIndicesSingleFacet(t,e,this.paramIndex,!0),this.colorIndex!==this.pointIndex&&ne.reverseIndicesSingleFacet(t,e,this.colorIndex,!0),ne.reverseIndicesSingleFacet(t,e,this.edgeVisible,!1)}reverseNormals(){this.normal&&this.normal.scaleInPlace(-1)}}class Xi extends ne{_currentFacetIndex;_nextFacetIndex;_numWrap;_numEdges;_polyface;constructor(t,e){super(t.data.normalCount>0,t.data.paramCount>0,t.data.colorCount>0,t.twoSided),this._polyface=t,this._numWrap=e,t.data.auxData&&(this.auxData=t.data.auxData.createForVisitor()),t.data.edgeMateIndex&&(this.edgeMateIndex=[]),this._numEdges=0,this._nextFacetIndex=0,this._currentFacetIndex=-1,this.reset()}clientPolyface(){return this._polyface}getVisitableFacetCount(){return this._polyface.facetCount}setNumWrap(t){this._numWrap=t}get numEdgesThisFacet(){return this._numEdges}static create(t,e){return new Xi(t,e)}moveToReadIndex(t){if(!this._polyface.isValidFacetIndex(t))return!1;const e=this._polyface.numEdgeInFacet(t);return(this._currentFacetIndex!==t||e+this._numWrap!==this.pointCount)&&(this._currentFacetIndex=t,this._numEdges=e,this.resizeAllArrays(this._numEdges+this._numWrap),this.gatherIndexedData(this._polyface.data,this._polyface.facetIndex0(this._currentFacetIndex),this._polyface.facetIndex1(this._currentFacetIndex),this._numWrap)),this._nextFacetIndex=t+1,!0}moveToNextFacet(){return this._nextFacetIndex!==this._currentFacetIndex?this.moveToReadIndex(this._nextFacetIndex):(this._nextFacetIndex++,!0)}reset(){this.moveToReadIndex(0),this._nextFacetIndex=0}tryGetDistanceParameter(t,e){if(t<0||t>=this.numEdgesThisFacet||this.param===void 0||this._polyface.data.face.length===0)return;const n=this._polyface.tryGetFaceData(this._currentFacetIndex);if(n)return n.convertParamXYToDistance(this.param.getXAtUncheckedPointIndex(t),this.param.getYAtUncheckedPointIndex(t),e)}tryGetNormalizedParameter(t,e){if(t<0||t>=this.numEdgesThisFacet||this.param===void 0||this._polyface.data.face.length===0)return;const n=this._polyface.tryGetFaceData(this._currentFacetIndex);if(n)return n.convertParamXYToNormalized(this.param.getXAtUncheckedPointIndex(t),this.param.getYAtUncheckedPointIndex(t),e)}currentReadIndex(){return this._currentFacetIndex}clientPointIndex(t){return this.pointIndex[t]}clientParamIndex(t){return this.paramIndex?this.paramIndex[t]:-1}clientNormalIndex(t){return this.normalIndex?this.normalIndex[t]:-1}clientColorIndex(t){return this.colorIndex?this.colorIndex[t]:-1}clientAuxIndex(t){return this.auxData?this.auxData.indices[t]:-1}clearArrays(){this.point.length=0,this.edgeVisible.length=0,this.param!==void 0&&(this.param.length=0),this.normal!==void 0&&(this.normal.length=0),this.color!==void 0&&(this.color.length=0)}pushDataFrom(t,e){this.point.pushFromGrowableXYZArray(t.point,e),this.edgeVisible.push(t.edgeVisible[e]),this.param&&t.param&&e<t.param.length&&this.param.pushFromGrowableXYArray(t.param,e),this.normal&&t.normal&&e<t.normal.length&&this.normal.pushFromGrowableXYZArray(t.normal,e),this.color&&t.color&&e<t.color.length&&this.color.push(t.color[e])}pushInterpolatedDataFrom(t,e,n,i){e>i&&this.pushInterpolatedDataFrom(t,i,1-n,e),this.point.pushInterpolatedFromGrowableXYZArray(t.point,e,n,i);const s=(e+1)%t.edgeVisible.length===i?t.edgeVisible[e]:!1;this.edgeVisible.push(s),this.param&&t.param&&e<t.param.length&&i<t.param.length&&this.param.pushInterpolatedFromGrowableXYArray(t.param,e,n,i),this.normal&&t.normal&&e<t.normal.length&&i<t.normal.length&&this.normal.pushInterpolatedFromGrowableXYZArray(t.normal,e,n,i),this.color&&t.color&&e<t.color.length&&i<t.color.length&&this.color.push(f.interpolateColor(t.color[e],n,t.color[i]))}createSubsetVisitor(t,e=0){return Qi.createSubsetVisitor(this._polyface,t,e)}}class Qi extends Xi{_facetIndices;_currentSubsetIndex;_nextSubsetIndex;constructor(t,e,n){super(t,n),this._facetIndices=e.slice(),this._currentSubsetIndex=-1,this._nextSubsetIndex=0,this.reset()}isValidSubsetIndex(t){return t>=0&&t<this._facetIndices.length}static createSubsetVisitor(t,e,n=0){return new Qi(t,e,n)}moveToReadIndex(t){return this.isValidSubsetIndex(t)?(this._currentSubsetIndex=t,this._nextSubsetIndex=t+1,super.moveToReadIndex(this._facetIndices[t])):!1}moveToNextFacet(){return this._nextSubsetIndex!==this._currentSubsetIndex?this.moveToReadIndex(this._nextSubsetIndex):(this._nextSubsetIndex++,!0)}reset(){this._facetIndices&&(this.moveToReadIndex(0),this._nextSubsetIndex=0)}parentFacetIndex(t){return t===void 0&&(t=this._currentSubsetIndex),this.isValidSubsetIndex(t)?this._facetIndices[t]:void 0}getVisitableFacetCount(){return this._facetIndices.length}static createNormalComparison(t,e=P.unitZ(),n=A.createSmallAngle(),i=0){if(t instanceof un)return this.createNormalComparison(t.createVisitor(),e,n,i);const s=t,r=[],o=P.createZero();for(s.reset();s.moveToNextFacet();)nt.unitNormal(s.point,o)&&(o.dotProduct(e)<0||o.angleFromPerpendicular(e).isMagnitudeLessThanOrEqual(n)||r.push(s.currentReadIndex()));return Qi.createSubsetVisitor(s.clientPolyface(),r,i)}}class Js{_paramDistanceRange;_paramRange;get paramDistanceRange(){return this._paramDistanceRange}get paramRange(){return this._paramRange}constructor(t,e){this._paramDistanceRange=t,this._paramRange=e}static createNull(){return new Js(Rt.createNull(),Rt.createNull())}clone(t){return t?(this._paramDistanceRange.clone(t._paramDistanceRange),this._paramRange.clone(t._paramRange),t):new Js(this._paramDistanceRange.clone(),this._paramRange.clone())}setNull(){this._paramDistanceRange.setNull(),this._paramRange.setNull()}convertParamXYToDistance(t,e,n){n=n||D.create();const i=this._paramRange.high.minus(this._paramRange.low);return n.x=i.x===0?t:this._paramDistanceRange.low.x+(t-this._paramRange.low.x)*(this._paramDistanceRange.high.x-this._paramDistanceRange.low.x)/i.x,n.y=i.y===0?e:this.paramDistanceRange.low.y+(e-this._paramRange.low.y)*(this._paramDistanceRange.high.y-this._paramDistanceRange.low.y)/i.y,n}convertParamXYToNormalized(t,e,n){n=n||D.create();const i=this._paramRange.high.minus(this._paramRange.low);return n.x=i.x===0?t:(t-this._paramRange.low.x)/i.x,n.y=i.y===0?e:(e-this._paramRange.low.y)/i.y,n}convertParamToDistance(t,e){return this.convertParamXYToDistance(t.x,t.y,e)}convertParamToNormalized(t,e){return this.convertParamXYToNormalized(t.x,t.y,e)}scaleDistances(t){this._paramDistanceRange.low.x*=t,this._paramDistanceRange.low.y*=t,this._paramDistanceRange.high.x*=t,this._paramDistanceRange.high.y*=t}setParamDistanceRangeFromNewFaceData(t,e,n){const i=D.create(),s=D.create();this.setNull();let r=0;const o=Xi.create(t,0);if(!o.moveToReadIndex(e)||n<=e)return!1;do{const a=o.numEdgesThisFacet,c=o.point,l=[],d=o.param,h=[];if(!d)return!1;d.extendRange(this._paramRange);const g=Q.create(),m=Q.create();for(let p=0;p<a;p++){if(l[2]=p,h[2]=p,p>1){d.vectorIndexIndex(h[1],h[0],g),d.vectorIndexIndex(h[1],h[2],m);const x=c.getPoint3dAtUncheckedPointIndex(l[0]).minus(c.getPoint3dAtUncheckedPointIndex(l[1])),_=c.getPoint3dAtUncheckedPointIndex(l[1]).minus(c.getPoint3dAtUncheckedPointIndex(l[2])),I=Math.abs(g.x*m.y-m.x*g.y);if(I){const v=y.createFrom(x);v.scaleInPlace(m.y),v.addScaledInPlace(_,-g.y);const S=y.createFrom(_);S.scaleInPlace(g.x),S.addScaledInPlace(x,-m.x);const w=D.create(v.magnitude()/I,S.magnitude()/I);i.x+=w.x,i.y+=w.y,s.x+=w.x*w.x,s.y+=w.y*w.y,r++}}h[0]=h[1],h[1]=h[2],l[0]=l[1],l[1]=l[2]}}while(o.moveToNextFacet()&&o.currentReadIndex()<n);if(r!==0){const a=D.create(i.x/r,i.y/r),c=D.create(Math.sqrt(Math.abs(s.x/r-a.x*a.x)),Math.sqrt(Math.abs(s.y/r-a.y*a.y)));this._paramDistanceRange.low.set(0,0),this._paramDistanceRange.high.set((a.x+c.x)*(this._paramRange.high.x-this._paramRange.low.x),(a.y+c.y)*(this._paramRange.high.y-this._paramRange.low.y))}return!0}}class It extends Ae{geometryCategory="polyface";data;constructor(t){super(),this.data=t}get twoSided(){return this.data.twoSided}set twoSided(t){this.data.twoSided=t}get expectedClosure(){return this.data.expectedClosure}set expectedClosure(t){this.data.expectedClosure=t}static areIndicesValid(t,e,n,i,s){if(t===void 0&&i===void 0)return!0;if(t===void 0||i===void 0||e<0||e>=t.length||n<=e||n>t.length)return!1;for(let r=e;r<n;r++)if(t[r]<0||t[r]>=s)return!1;return!0}get facetCount(){}}class un extends It{_facetStart;_facetToFaceData;constructor(t,e,n){super(t),e?this._facetStart=e.slice():(this._facetStart=[],this._facetStart.push(0)),n?this._facetToFaceData=n.slice():this._facetToFaceData=[]}edgeIndexToFacetIndex(t){if(t!==void 0)return Pe.searchStrictlyIncreasingNumbers(this._facetStart,t)}edgeIndexToFaceLoop(t){const e=this.edgeIndexToFacetIndex(t);if(e!==void 0)return ct.createXX(this.facetIndex0(e),this.facetIndex1(e))}isSameGeometryClass(t){return t instanceof un}isAlmostEqual(t){return t instanceof un?this.data.isAlmostEqual(t.data)&&Pe.isExactEqual(this._facetStart,t._facetStart)&&Pe.isExactEqual(this._facetToFaceData,t._facetToFaceData):!1}get isEmpty(){return this.data.pointCount===0||this.data.pointIndex.length===0}tryTransformInPlace(t){return this.data.tryTransformInPlace(t),t.matrix.determinant()<0&&this.reverseIndices(),!0}reverseSingleFacet(t){this.data.reverseIndicesSingleFacet(t,this._facetStart)}clone(){return new un(this.data.clone(),this._facetStart.slice(),this._facetToFaceData.slice())}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t),e}reverseIndices(){this.data.reverseIndices(this._facetStart)}reverseNormals(){this.data.reverseNormals()}tryGetFaceData(t){if(t<0||t>=this._facetToFaceData.length)return;const e=this._facetToFaceData[t];if(!(e<0||e>=this.data.face.length))return this.data.face[e]}addIndexedPolyface(t,e,n){const i=t.facetCount,s=this.data.point.length,r=y.create();for(let o=0;o<t.data.point.length;o++)t.data.point.getPoint3dAtUncheckedPointIndex(o,r),n?(n.multiplyPoint3d(r,r),this.addPoint(r)):this.addPoint(r);for(let o=0;o<i;o++){const a=t._facetStart[o],c=t._facetStart[o+1];if(e)for(let l=c;l-- >a;)this.addPointIndex(s+t.data.pointIndex[l],t.data.edgeVisible[l>a?l-1:c-1]);else for(let l=a;l<c;l++)this.addPointIndex(s+t.data.pointIndex[l],t.data.edgeVisible[l]);this.terminateFacet(!1)}if(this.data.param!==void 0&&t.data.param!==void 0&&t.data.paramIndex!==void 0){const o=this.data.param.length;this.data.param.pushFromGrowableXYArray(t.data.param);for(let a=0;a<i;a++){const c=t._facetStart[a],l=t._facetStart[a+1];if(e)for(let d=l;d-- >c;)this.addParamIndex(o+t.data.paramIndex[d]);else for(let d=c;d<l;d++)this.addParamIndex(o+t.data.paramIndex[d])}}if(this.data.normal!==void 0&&t.data.normal!==void 0&&t.data.normalIndex!==void 0){const o=this.data.normal.length;for(let a=0;a<t.data.normal.length;a++){const c=t.data.normal.getVector3dAtUncheckedVectorIndex(a);n&&n.multiplyVector(c,c),e&&c.scaleInPlace(-1),this.addNormal(c)}for(let a=0;a<i;a++){const c=t._facetStart[a],l=t._facetStart[a+1];if(e)for(let d=l;d-- >c;)this.addNormalIndex(o+t.data.normalIndex[d]);else for(let d=c;d<l;d++)this.addNormalIndex(o+t.data.normalIndex[d])}}if(this.data.color!==void 0&&t.data.color!==void 0&&t.data.colorIndex!==void 0){const o=this.data.color.length;for(const a of t.data.color)this.addColor(a);for(let a=0;a<i;a++){const c=t._facetStart[a],l=t._facetStart[a+1];if(e)for(let d=l;d-- >c;)this.addColorIndex(o+t.data.colorIndex[d]);else for(let d=c;d<l;d++)this.addColorIndex(o+t.data.colorIndex[d])}}if(t.data.face.length!==0){const o=this.data.face.length;for(const a of t.data.face){const c=a.clone();this.data.face.push(c)}for(const a of t._facetToFaceData)this._facetToFaceData.push(o+a)}}get zeroTerminatedIndexCount(){return this.data.pointIndex.length+this._facetStart.length-1}static create(t=!1,e=!1,n=!1,i=!0){return new un(new ne(t,e,n,i))}addPoint(t,e){if(e!==void 0){const n=this.data.point.distanceIndexToPoint(e,t);if(n!==void 0&&f.isSmallMetricDistance(n))return e}return this.data.point.pushXYZ(t.x,t.y,t.z),this.data.point.length-1}addPointXYZ(t,e,n){return this.data.point.pushXYZ(t,e,n),this.data.point.length-1}addParam(t){return this.data.param||(this.data.param=new Ie),this.data.param.push(t),this.data.param.length-1}addParamUV(t,e,n,i){return this.data.param||(this.data.param=new Ie),n!==void 0&&this.data.isAlmostEqualParamIndexUV(n,t,e)?n:i!==void 0&&this.data.isAlmostEqualParamIndexUV(i,t,e)?i:(this.data.param.pushXY(t,e),this.data.param.length-1)}addNormal(t,e,n){const i=(s,r)=>{const o=s.distanceIndexToPoint(r,t);return o!==void 0&&f.isSmallMetricDistance(o)};if(this.data.normal){if(e!==void 0&&i(this.data.normal,e))return e;if(n!==void 0&&i(this.data.normal,n))return n;if(e!==void 0||n!==void 0){const s=this.data.normal.length-1;if(i(this.data.normal,s))return s}}return this.addNormalXYZ(t.x,t.y,t.z)}addNormalXYZ(t,e,n){return this.data.normal||(this.data.normal=new W),this.data.normal.pushXYZ(t,e,n),this.data.normal.length-1}addColor(t){return this.data.color||(this.data.color=[]),this.data.color.push(t),this.data.color.length-1}addPointIndex(t,e=!0){this.data.pointIndex.push(t),this.data.edgeVisible.push(e)}addNormalIndex(t){this.data.normalIndex||(this.data.normalIndex=[]),this.data.normalIndex.push(t)}addParamIndex(t){this.data.paramIndex||(this.data.paramIndex=[]),this.data.paramIndex.push(t)}addColorIndex(t){this.data.colorIndex||(this.data.colorIndex=[]),this.data.colorIndex.push(t)}cleanupOpenFacet(){this.data.trimAllIndexArrays(this.data.pointIndex.length)}validateAllIndices(t=0,e){const n=this.data.pointIndex.length,i=e??[];return n===0?(i.push("empty pointIndex array"),!1):t<0||t>=n?(i.push("invalid input offset"),!1):(this.data.normalIndex&&this.data.normalIndex.length!==n&&i.push("normalIndex count must match pointIndex count"),this.data.paramIndex&&this.data.paramIndex.length!==n&&i.push("paramIndex count must equal pointIndex count"),this.data.colorIndex&&this.data.colorIndex.length!==n&&i.push("colorIndex count must equal pointIndex count"),this.data.edgeVisible.length!==n&&i.push("visibleIndex count must equal pointIndex count"),It.areIndicesValid(this.data.pointIndex,t,n,this.data.point,this.data.point?this.data.point.length:0)||i.push("invalid point index encountered"),It.areIndicesValid(this.data.normalIndex,t,n,this.data.normal,this.data.normal?this.data.normal.length:0)||i.push("invalid normal index encountered"),It.areIndicesValid(this.data.paramIndex,t,n,this.data.param,this.data.param?this.data.param.length:0)||i.push("invalid param index encountered"),It.areIndicesValid(this.data.colorIndex,t,n,this.data.color,this.data.color?this.data.color.length:0)||i.push("invalid color index encountered"),this.data.edgeMateIndex&&(this.data.edgeMateIndex.length!==n?i.push("edgeMateIndex count must equal pointIndex count"):this.data.edgeMateIndex.every(s=>s===void 0||this.data.isValidEdgeIndex(s))||i.push("invalid edgeMate encountered")),i.length===0)}terminateFacet(t=!0){const e=this._facetStart.length-1,n=this._facetStart[e],i=this.data.pointIndex.length;if(t){const s=[];if(i<n+2&&s.push("Less than 3 indices in the last facet"),this.validateAllIndices(n,s),s.length>0)return this.data.trimAllIndexArrays(n),s}this._facetStart.push(i)}get facetCount(){return this._facetStart.length-1}get faceCount(){return this.data.faceCount}get pointCount(){return this.data.pointCount}get colorCount(){return this.data.colorCount}get paramCount(){return this.data.paramCount}get normalCount(){return this.data.normalCount}isValidFacetIndex(t){return t>=0&&t<this.facetCount}numEdgeInFacet(t){return this.isValidFacetIndex(t)?this._facetStart[t+1]-this._facetStart[t]:0}facetIndex0(t){return this._facetStart[t]}facetIndex1(t){return this._facetStart[t+1]}get facetStart(){return this._facetStart}createVisitor(t=0){return Xi.create(this,t)}extendRange(t,e){this.data.extendRange(t,e)}getFaceDataByFacetIndex(t){return this.data.face[this._facetToFaceData[t]]}setNewFaceData(t=0){const e=this._facetToFaceData.length;if(e>=this._facetStart.length)return!1;t===0&&(t=this._facetStart.length);const n=Xi.create(this,0);if(!n.moveToReadIndex(e))return!1;const i=Js.createNull();if(this.data.param&&this.data.param.length>0){do n.param?.extendRange(i.paramRange);while(n.moveToNextFacet()&&n.currentReadIndex()<t);i.setParamDistanceRangeFromNewFaceData(this,e,t)}this.data.face.push(i);const s=this.data.face.length-1;for(let r=this._facetToFaceData.length;r<t;r++)this._facetToFaceData.push(this._facetStart[r]===0?0:s);return!0}dispatchToGeometryHandler(t){return t.handleIndexedPolyface(this)}static hasEdgeMateIndex(t){let e;if(t instanceof It?t instanceof un&&(e=t):t.clientPolyface()&&t.clientPolyface()instanceof un&&(e=t.clientPolyface()),e){const n=e.data.edgeMateIndex;if(n&&n.length>0&&n.length===e.data.indexCount)return{parent:e,edgeMateIndex:n}}}}class ha{_parentArray;constructor(t=0){this._parentArray=[];for(let e=0;e<t;e++)this._parentArray.push(e)}get length(){return this._parentArray.length}isValidIndex(t){return 0<=t&&t<this._parentArray.length}addLeaf(){const t=this._parentArray.length;return this._parentArray.push(t),t}findRoot(t){if(!this.isValidIndex(t))return t;let e=t,n=this._parentArray[t];for(;n!==e;)e=n,n=this._parentArray[e];const i=e;for(e=t;e!==i;)n=this._parentArray[e],this._parentArray[e]=i,e=n;return i}mergeSubsets(t,e){if(!this.isValidIndex(t)||!this.isValidIndex(e))return t;const n=this.findRoot(t),i=this.findRoot(e);return n!==i&&(this._parentArray[n]=i),this.findRoot(t)}askParent(t){return this.isValidIndex(t)?this._parentArray[t]:t}countRoots(){let t=0;const e=this._parentArray.length;for(let n=0;n<e;n++)this._parentArray[n]===n&&t++;return t}countNonTrivialPaths(){let t=0;const e=this._parentArray.length;for(let n=0;n<e;n++){const i=this._parentArray[n];i!==n&&this._parentArray[i]!==i&&t++}return t}collectRootIndices(){const t=[],e=this._parentArray.length;for(let n=0;n<e;n++)this._parentArray[n]===n&&t.push(n);return t}}class no{_freeMasks;_originalFreeMasks;_firstFreeMask;constructor(t,e){this._freeMasks=t,this._originalFreeMasks=t,this._firstFreeMask=e}static create(t){let e=0,n=1;for(let i=0;i<32;i++){if((n&t)!==0){e=n;break}n=n<<1}if(e!==0)return new no(t,e)}grabMask(){if(!this.hasFreeMask)return 0;let t=this._firstFreeMask;for(;!(t&this._freeMasks);)t=t<<1;return this._freeMasks&=~t,t}dropMask(t){t&=this._originalFreeMasks,this._freeMasks|=t}get hasFreeMask(){return this._freeMasks!==0}}var M;(function(u){u[u.EXTERIOR=1]="EXTERIOR",u[u.BOUNDARY_EDGE=2]="BOUNDARY_EDGE",u[u.PRIMARY_EDGE=4]="PRIMARY_EDGE",u[u.BRIDGE_EDGE=8]="BRIDGE_EDGE",u[u.REGULARIZED_EDGE=16]="REGULARIZED_EDGE",u[u.TRIANGULATED_FACE=256]="TRIANGULATED_FACE",u[u.NULL_FACE=512]="NULL_FACE",u[u.VISITED=65536]="VISITED",u[u.NULL_MASK=0]="NULL_MASK",u[u.ALL_GRAB_DROP_MASKS=4293918720]="ALL_GRAB_DROP_MASKS",u[u.ALL_MASK=4294967295]="ALL_MASK"})(M||(M={}));class V{i;maskBits;x;y;z;sortAngle;sortData;edgeTag;faceTag;_id;get id(){return this._id}_facePredecessor;_faceSuccessor;_edgeMate;get facePredecessor(){return this._facePredecessor}get faceSuccessor(){return this._faceSuccessor}get edgeMate(){return this._edgeMate}static _totalNodesCreated=0;constructor(t=0,e=0,n=0,i=0){this._id=V._totalNodesCreated++,Number.isSafeInteger(V._totalNodesCreated)||(V._totalNodesCreated=0),this.i=i,this.maskBits=0,this.x=t,this.y=e,this.z=n,this.sortAngle=void 0,this.sortData=void 0,this.edgeTag=void 0,this.faceTag=void 0,this._facePredecessor=this,this._faceSuccessor=this,this._edgeMate=this}faceStepY(t){let e=this;if(t>0)for(let n=0;n<t;n++)e=e.faceSuccessor;else if(t<0)for(let n=0;n>t;n--)e=e.facePredecessor;return e.y}static createHalfEdgePair(t){const e=new V,n=new V;return t&&(t.push(e),t.push(n)),V.setFaceLinks(e,n),V.setFaceLinks(n,e),V.setEdgeMates(e,n),e}static createHalfEdgePairWithCoordinates(t=0,e=0,n=0,i=0,s=0,r=0,o=0,a=0,c){const l=V.createHalfEdgePair(c),d=l._edgeMate;return l.x=t,l.y=e,l.z=n,l.i=i,d.x=s,d.y=r,d.z=o,d.i=a,l}static setFaceLinks(t,e){t._faceSuccessor=e,e._facePredecessor=t}static setEdgeMates(t,e){t._edgeMate=e,e._edgeMate=t}static splitEdge(t,e=0,n=0,i=0,s=0,r){const o=new V(e,n,i,s),a=new V(e,n,i,s);if(r&&(r.push(o),r.push(a)),t===void 0)o._faceSuccessor=o._facePredecessor=o,a._faceSuccessor=a._facePredecessor=a,V.setEdgeMates(o,a);else{const c=t._faceSuccessor,l=t._edgeMate,d=l._faceSuccessor;V.setFaceLinks(o,c),V.setFaceLinks(t,o),V.setFaceLinks(l,a),V.setFaceLinks(a,d),V.setEdgeMates(o,l),V.setEdgeMates(a,t),this.transferEdgeProperties(t,o),this.transferEdgeProperties(l,a)}return o}static healEdge(t,e=!0){if(t.isIsolatedEdge)return;const n=t.vertexSuccessor;if(n.vertexSuccessor!==t||e&&!t.vectorToFaceSuccessor().isParallelTo(t.facePredecessor.vectorToFaceSuccessor(),!1,!0))return;const i=t.facePredecessor,s=t.faceSuccessor,r=n.facePredecessor,o=n.faceSuccessor;return this.setFaceLinks(i,s),this.setFaceLinks(r,o),this.setEdgeMates(i,r),this.setFaceLinks(t,n),this.setFaceLinks(n,t),this.setEdgeMates(t,n),i}static splitEdgeCreateSliverFace(t,e){const n=t.edgeMate,i=new V,s=new V;return e&&(e.push(i),e.push(s)),i._faceSuccessor=i._facePredecessor=s,s._faceSuccessor=s._facePredecessor=i,V.setEdgeMates(i,n),V.setEdgeMates(s,t),i.copyDataFrom(t,!0,!0,!1,!1),s.copyDataFrom(n,!0,!0,!1,!1),i}static _edgePropertyMasks=[M.EXTERIOR,M.BOUNDARY_EDGE,M.PRIMARY_EDGE,M.BRIDGE_EDGE,M.REGULARIZED_EDGE,M.NULL_FACE];static transferEdgeProperties(t,e){e.edgeTag=t.edgeTag;for(const n of this._edgePropertyMasks)t.getMask(n)?e.setMask(n):e.clearMask(n)}get vertexSuccessor(){return this.facePredecessor.edgeMate}get vertexPredecessor(){return this.edgeMate.faceSuccessor}setMask(t){this.maskBits|=t}getMask(t){return this.maskBits&t}clearMask(t){this.maskBits&=~t}applyMask(t,e=!1){e?this.clearMask(t):this.setMask(t)}setMaskAroundVertex(t){let e=this;do e.setMask(t),e=e.vertexSuccessor;while(e!==this)}setXYZAroundVertex(t,e,n){let i=this;do i.x=t,i.y=e,i.z=n,i=i.vertexSuccessor;while(i!==this)}setMaskAroundFace(t){let e=this;do e.setMask(t),e=e.faceSuccessor;while(e!==this)}setMaskAroundEdge(t){this.setMask(t),this.edgeMate.setMask(t)}clearMaskAroundEdge(t){this.clearMask(t),this.edgeMate.clearMask(t)}countEdgesAroundFace(){let t=0,e=this;do t++,e=e.faceSuccessor;while(e!==this);return t}findAroundVertex(t){let e=this;do{if(e===t)return!0;e=e.vertexSuccessor}while(e!==this);return!1}findAroundFace(t){let e=this;do{if(e===t)return!0;e=e.faceSuccessor}while(e!==this);return!1}isMaskedAroundFace(t,e=!0){let n=this;if(e)do{if(!n.isMaskSet(t))return!1;n=n.faceSuccessor}while(n!==this);else do{if(n.isMaskSet(t))return!1;n=n.faceSuccessor}while(n!==this);return!0}setMaskAndEdgeTagAroundFace(t,e,n=!1){let i=this;do{if(i.setMask(t),i.edgeTag=e,n){const s=i.edgeMate;s.setMask(t),s.edgeTag=e}i=i.faceSuccessor}while(i!==this)}countEdgesAroundVertex(){let t=0,e=this;do t++,e=e.vertexSuccessor;while(e!==this);return t}countMaskAroundFace(t,e=!0){let n=0,i=this;if(e)do i.isMaskSet(t)&&n++,i=i.faceSuccessor;while(i!==this);else do i.isMaskSet(t)||n++,i=i.faceSuccessor;while(i!==this);return n}countMaskAroundVertex(t,e=!0){let n=0,i=this;if(e)do i.isMaskSet(t)&&n++,i=i.vertexSuccessor;while(i!==this);else do i.isMaskSet(t)||n++,i=i.vertexSuccessor;while(i!==this);return n}findMaskAroundVertex(t,e=!0,n=!1){let i=this;do{if(i.isMaskSet(t)===e)return i;i=n?i.vertexPredecessor:i.vertexSuccessor}while(i!==this)}findMaskAroundFace(t,e=!0){let n=this;do{if(n.isMaskSet(t)===e)return n;n=n.faceSuccessor}while(n!==this)}findMaskAroundEdge(t,e=!0){if(this.isMaskSet(t)===e)return this;const n=this.edgeMate;if(n.isMaskSet(t)===e)return n}testAndSetMask(t){const e=this.maskBits&t;return this.maskBits|=t,e}setXYZFrom(t){this.x=t.x,this.y=t.y,this.z=t.z}setXYZ(t){this.x=t.x,this.y=t.y,this.z=t.z}isMaskSet(t){return(this.maskBits&t)!==0}static filterIsMaskOn(t,e){return t.isMaskSet(e)}static filterIsMaskOff(t,e){return!t.isMaskSet(e)}static createEdgeXYXY(t,e,n,i){const s=new V(t,e),r=new V(n,i);return s._faceSuccessor=s._facePredecessor=s._edgeMate=r,r._faceSuccessor=r._facePredecessor=r._edgeMate=s,s}static pinch(t,e){if(t!==e){const n=t._facePredecessor,i=e._facePredecessor;e._facePredecessor=n,t._facePredecessor=i,i._faceSuccessor=t,n._faceSuccessor=e}}get isDangling(){return this.edgeMate.faceSuccessor===this}yankFromVertexLoop(){const t=this.edgeMate.faceSuccessor;if(t!==this)return V.pinch(this,t),t}decommission(){this._facePredecessor=void 0,this._faceSuccessor=void 0,this._edgeMate=void 0}static nodeToSelf(t){return t}static nodeToId(t){return t.id}static nodeToIdString(t){return t.id.toString()}static nodeToIdMaskXY(t){return{id:t.id,mask:V.nodeToMaskString(t),xy:[t.x,t.y]}}static nodeToIdXYString(t){return`${t.id.toString()}+${V.nodeToMaskString(t)}[${t.x},${t.y}]`}static nodeToIdXYZString(t){return`[${t.id.toString()}: ${t.x},${t.y},${t.z}]`}static nodeToMaskString(t){let e="";return t.isMaskSet(M.BOUNDARY_EDGE)&&(e+="B"),t.isMaskSet(M.PRIMARY_EDGE)&&(e+="P"),t.isMaskSet(M.EXTERIOR)&&(e+="X"),t.isMaskSet(M.NULL_FACE)&&(e+="N"),e}static nodeToXY(t){return[t.x,t.y]}vectorToFaceSuccessorXY(t){return Q.create(this.faceSuccessor.x-this.x,this.faceSuccessor.y-this.y,t)}vectorToFaceSuccessor(t){const e=this.faceSuccessor;return P.create(e.x-this.x,e.y-this.y,e.z-this.z,t)}vectorToFacePredecessor(t){const e=this.facePredecessor;return P.create(e.x-this.x,e.y-this.y,e.z-this.z,t)}static isNodeVisibleInSector(t,e){if(e.vertexSuccessor===e)return!0;const n=e.faceSuccessor,i=e.facePredecessor,s=this.crossProductXYToTargets(e,n,t),r=this.crossProductXYToTargets(i,e,t);if(s>0&&r>0)return!0;const o=this.crossProductXYToTargets(i,e,n);return r<=0&&s<=0?r===0&&s===0&&o===0?i===n&&e.vertexSuccessor!==e?t===n:V.dotProductNodeToNodeVectorsXY(i,e,e,t)>0:!1:o===0&&r!==0&&s!==0?i!==n:o<0}static crossProductXYToTargets(t,e,n){return f.crossProductXYXY(e.x-t.x,e.y-t.y,n.x-t.x,n.y-t.y)}static dotProductNodeToNodeVectorsXY(t,e,n,i){return f.dotProductXYXY(e.x-t.x,e.y-t.y,i.x-n.x,i.y-n.y)}static crossProductXYAlongChain(t,e,n){return f.crossProductXYXY(e.x-t.x,e.y-t.y,n.x-e.x,n.y-e.y)}static isSectorConvex(t,e,n,i=0){const s=.5*V.crossProductXYAlongChain(t,e,n);return i=i??0,Math.abs(s)<=Math.abs(i)?V.dotProductNodeToNodeVectorsXY(t,e,e,n)>0:s>-i}isSectorConvex(t){return t===void 0&&(t=f.smallMetricDistanceSquared*this.signedFaceArea()),V.isSectorConvex(this.facePredecessor,this,this.faceSuccessor,t)}isFaceConvex(t=f.smallMetricDistanceSquared){let e=this;const n=t>0?t*e.signedFaceArea():0;do{if(!e.isSectorConvex(n))return!1;e=e.faceSuccessor}while(e!==this);return!0}isolateEdge(){const t=this.edgeMate;this.yankFromVertexLoop(),t.yankFromVertexLoop()}get isIsolatedEdge(){return this===this.vertexSuccessor&&this.edgeMate===this.edgeMate.vertexSuccessor}belowYX(t){return this.y<t.y?!0:this.y>t.y?!1:this.x<t.x}static testNodeMaskNotExterior(t){return!t.isMaskSet(M.EXTERIOR)}static testMateMaskExterior(t){return t.edgeMate.isMaskSet(M.EXTERIOR)}static sectorSweepRadiansXYZ(t,e){const n=t.faceSuccessor,i=t.facePredecessor;return A.orientedRadiansBetweenVectorsXYZ(n.x-t.x,n.y-t.y,n.z-t.z,i.x-t.x,i.y-t.y,i.z-t.z,e.x,e.y,e.z,!0)}static testFacePositiveAreaXY(t){return t.countEdgesAroundFace()>2&&t.signedFaceArea()>0}isEqualXY(t){return this.x===t.x&&this.y===t.y}distanceXY(t){return f.distanceXYXY(this.x,this.y,t.x,t.y)}distanceXYZ(t){return f.distanceXYZXYZ(this.x,this.y,this.z,t.x,t.y,t.z)}collectMaskedEdgesAroundFace(t,e=!0,n){n===void 0?n=[]:n.length=0;let i=this;do i.isMaskSet(t)===e&&n.push(i),i=i.faceSuccessor;while(i!==this);return n}announceEdgesInFace(t){let e=this;do t(e),e=e.faceSuccessor;while(e!==this)}announceEdgesInSuperFace(t,e,n){let s=0;const r=t instanceof Function?t:l=>l.isMaskSet(t),o=l=>{let d=l;do{if(!r(d))return d;n?.(d),d=d.vertexPredecessor}while(d!==l)},a=o(this);if(!a)return!1;let c=a;do if(e(c),c=o(c.faceSuccessor),!c)return!1;while(c!==a&&s++<1e4);return s<1e4}collectAroundFace(t){const e=[];let n=this;do e.push(t?t(n):n),n=n.faceSuccessor;while(n!==this);return e}collectMaskedEdgesAroundVertex(t,e=!0,n){n===void 0?n=[]:n.length=0;let i=this;do i.isMaskSet(t)===e&&n.push(i),i=i.vertexSuccessor;while(i!==this);return n}collectAroundVertex(t){const e=[];let n=this;do e.push(t?t(n):n),n=n.vertexSuccessor;while(n!==this);return e}announceEdgesAroundVertex(t){let e=this;do t(e),e=e.vertexSuccessor;while(e!==this)}sumAroundFace(t){let e=this,n=0;do n+=t(e),e=e.faceSuccessor;while(e!==this);return n}sumAroundVertex(t){let e=this,n=0;do n+=t(e),e=e.vertexSuccessor;while(e!==this);return n}clearMaskAroundFace(t){let e=this;do e.clearMask(t),e=e.faceSuccessor;while(e!==this)}clearMaskAroundVertex(t){let e=this;do e.clearMask(t),e=e.vertexSuccessor;while(e!==this)}signedFaceArea(){let t=0,e=this.x,n=0;const i=this.y;let s=0,r=0,o,a=this;do o=a.faceSuccessor,n=o.x,r=o.y-i,t+=(e-n)*(s+r),e=n,s=r,a=o;while(a!==this);return .5*t}fractionToPoint2d(t,e){const n=this.faceSuccessor;return D.create(this.x+(n.x-this.x)*t,this.y+(n.y-this.y)*t,e)}fractionToPoint3d(t,e){const n=this.faceSuccessor;return y.create(this.x+(n.x-this.x)*t,this.y+(n.y-this.y)*t,this.z+(n.z-this.z)*t,e)}fractionAlongAndPerpendicularToPoint2d(t,e,n){const i=this.faceSuccessor,s=i.x-this.x,r=i.y-this.y;return D.create(this.x+s*t-r*e,this.y+r*t+s*e,n)}getPoint3d(t){return y.create(this.x,this.y,this.z,t)}getPoint2d(t){return D.create(this.x,this.y,t)}getVector3dAlongEdge(t){const e=this.faceSuccessor;return P.create(e.x-this.x,e.y-this.y,e.z-this.z,t)}getVector2dAlongEdge(t){const e=this.faceSuccessor;return Q.create(e.x-this.x,e.y-this.y,t)}fractionToX(t){const e=this.faceSuccessor;return this.x+(e.x-this.x)*t}fractionToY(t){const e=this.faceSuccessor;return this.y+(e.y-this.y)*t}fractionToZ(t){const e=this.faceSuccessor;return this.z+(e.z-this.z)*t}static transverseIntersectionFractions(t,e,n){const i=t.faceSuccessor,s=e.faceSuccessor;if(n||(n=Q.create()),bt.linearSystem2d(i.x-t.x,e.x-s.x,i.y-t.y,e.y-s.y,e.x-t.x,e.y-t.y,n))return n}static horizontalScanFraction(t,e){const n=t.faceSuccessor,i=n.y-t.y;if(f.isSameCoordinate(e,t.y)&&f.isSameCoordinate(e,n.y))return t;if(!f.isSameCoordinate(i,0))return f.conditionalDivideFraction(e-t.y,i)}static horizontalScanFraction01(t,e){const n=t.faceSuccessor,i=n.y-t.y;if(f.isSameCoordinate(e,t.y)&&f.isSameCoordinate(e,n.y)||f.isSameCoordinate(i,0))return;const s=f.conditionalDivideFraction(e-t.y,i);if(s!==void 0&&s>=0&&s<=1)return s}copyDataFrom(t,e,n,i,s){e&&(this.x=t.x,this.y=t.y,this.z=t.z),n&&(this.i=t.i),i&&V.transferEdgeProperties(t,this),s&&(this.faceTag=t.faceTag)}isSplitWasherFace(t=M.BRIDGE_EDGE){if(!this.countMaskAroundFace(t))return!1;const e=new Fi((i,s)=>i.id-s.id);let n=this;do n.isMaskSet(t)&&e.add(n),n=n.faceSuccessor;while(n!==this);if(e.size===0)return!1;for(const i of e)if(!e.has(i.edgeMate)||!i.edgeMate.isMaskSet(t))return!1;return!0}}class be{allHalfEdges;_maskManager;constructor(){this.allHalfEdges=[],this._maskManager=no.create(M.ALL_GRAB_DROP_MASKS)}grabMask(t=!0){const e=this._maskManager.grabMask();return t&&this.clearMask(e),e}dropMask(t){this._maskManager.dropMask(t)}get hasFreeMask(){return this._maskManager.hasFreeMask}createEdgeXYZXYZ(t=0,e=0,n=0,i=0,s=0,r=0,o=0,a=0){return V.createHalfEdgePairWithCoordinates(t,e,n,i,s,r,o,a,this.allHalfEdges)}createEdgeIdId(t=0,e=0){return V.createHalfEdgePairWithCoordinates(0,0,0,t,0,0,0,e,this.allHalfEdges)}createEdgeXYZHalfEdge(t=0,e=0,n=0,i=0,s,r=0){const o=V.createHalfEdgePairWithCoordinates(t,e,n,i,s.x,s.y,s.z,r,this.allHalfEdges),a=o.faceSuccessor;return V.pinch(s,a),o}createEdgeHalfEdgeHalfEdge(t,e,n,i=0){const s=V.createHalfEdgePairWithCoordinates(t.x,t.y,t.z,e,n.x,n.y,n.z,i,this.allHalfEdges),r=s.faceSuccessor;return V.pinch(t,s),V.pinch(n,r),s}createEdgeXYAndZ(t,e,n,i){return V.createHalfEdgePairWithCoordinates(t.x,t.y,t.z,e,n.x,n.y,n.z,i,this.allHalfEdges)}splitEdge(t,e=0,n=0,i=0,s=0){return V.splitEdge(t,e,n,i,s,this.allHalfEdges)}splitEdgeCreateSliverFace(t){return V.splitEdgeCreateSliverFace(t,this.allHalfEdges)}splitEdgeAtFraction(t,e){return V.splitEdge(t,t.fractionToX(e),t.fractionToY(e),t.fractionToZ(e),0,this.allHalfEdges)}decommission(){for(const t of this.allHalfEdges)t.decommission();this.allHalfEdges.length=0,this.allHalfEdges=void 0}addEdgeXY(t,e,n,i,s,r,o,a){const c=V.createEdgeXYXY(t,e,n,i),l=c.faceSuccessor;return c.edgeTag=s,c.faceTag=o,l.edgeTag=r,l.faceTag=a,this.allHalfEdges.push(c,l),c}clearMask(t){for(const e of this.allHalfEdges)e.maskBits&=~t}setMask(t){for(const e of this.allHalfEdges)e.maskBits|=t}reverseMask(t){for(const e of this.allHalfEdges)e.maskBits^=t}countMask(t){let e=0;for(const n of this.allHalfEdges)n.isMaskSet(t)&&e++;return e}collectSegments(){const t=[];for(const e of this.allHalfEdges)e.id<e.edgeMate.id&&t.push(U.createXYXY(e.x,e.y,e.faceSuccessor.x,e.faceSuccessor.y));return t}countVertexLoops(){let t=0;return this.announceVertexLoops((e,n)=>(t++,!0)),t}countFaceLoops(){let t=0;return this.announceFaceLoops((e,n)=>(t++,!0)),t}countFaceLoopsWithMaskFilter(t,e){let n=0;return this.announceFaceLoops((i,s)=>(t(s,e)&&n++,!0)),n}collectVertexLoops(){const t=[];return this.announceVertexLoops((e,n)=>(t.push(n),!0)),t}collectFaceLoops(){const t=[];return this.announceFaceLoops((e,n)=>(t.push(n),!0)),t}announceVertexLoops(t){this.clearMask(M.VISITED);for(const e of this.allHalfEdges)if(!e.getMask(M.VISITED)&&(e.setMaskAroundVertex(M.VISITED),!t(this,e)))break}announceFaceLoops(t){this.clearMask(M.VISITED);for(const e of this.allHalfEdges)if(!e.getMask(M.VISITED)&&(e.setMaskAroundFace(M.VISITED),!t(this,e)))break}announceEdges(t){this.clearMask(M.VISITED);for(const e of this.allHalfEdges){if(e.getMask(M.VISITED))continue;const n=e.edgeMate;if(e.setMask(M.VISITED),n.setMask(M.VISITED),!t(this,e))break}}announceNodes(t){for(const e of this.allHalfEdges)if(!t(this,e))break}countNodes(){return this.allHalfEdges.length}transformInPlace(t){for(const e of this.allHalfEdges)t.multiplyXYAndZInPlace(e)}yankAndDeleteEdges(t){const e=this.allHalfEdges.length;let n=0;for(let s=0;s<e;s++){const r=this.allHalfEdges[s];t(r)?r.yankFromVertexLoop():this.allHalfEdges[n++]=r}const i=e-n;return this.allHalfEdges.length=n,i}deleteIsolatedEdges(){const t=this.allHalfEdges.length;let e=0;for(let i=0;i<t;i++){const s=this.allHalfEdges[i];s.isIsolatedEdge||(this.allHalfEdges[e++]=s)}const n=t-e;return this.allHalfEdges.length=e,n}constructIdToVertexIndexMap(){const t=new Map;return this.allHalfEdges.forEach((e,n)=>t.set(e.id,n)),this.announceVertexLoops((e,n)=>{let i=this.allHalfEdges.length;return n.announceEdgesAroundVertex(s=>{const r=t.get(s.id);r!==void 0&&r<i&&(i=r)}),n.announceEdgesAroundVertex(s=>t.set(s.id,i)),!0}),t}constructIdToFaceIndexMap(){const t=new Map;return this.allHalfEdges.forEach((e,n)=>t.set(e.id,n)),this.announceFaceLoops((e,n)=>{let i=this.allHalfEdges.length;return n.announceEdgesInFace(s=>{const r=t.get(s.id);r!==void 0&&r<i&&(i=r)}),n.announceEdgesInFace(s=>t.set(s.id,i)),!0}),t}}class vc{priorityQueue;activeEdges;constructor(t=(e,n)=>Vt.compareNodesYXUp(e,n)){this.priorityQueue=new ac(t),this.activeEdges=[]}popQueueToArray(){if(this.priorityQueue.isEmpty)return;const t=this.priorityQueue.pop();return this.activeEdges.push(t),t}popArrayToArrayIndex(t){const e=this.activeEdges.length;if(0<=t&&t<e-1&&e>0){const n=this.activeEdges.pop();this.activeEdges[t]=n}}removeArrayMembersWithY1Below(t){let e=0;const n=this.activeEdges.length;for(let i=0;i<n;i++){const s=this.activeEdges[i];s.faceSuccessor.y>=t&&(e<i&&(this.activeEdges[e]=s),e++)}this.activeEdges.length=e}}class Yi{static announceEdge;constructor(t){this.graph=t,this.upEdges=[],this.downEdges=[],this.bottomPeaks=[],this.topPeaks=[],this.localMin=[],this.localMax=[]}graph;upEdges;downEdges;topPeaks;bottomPeaks;localMin;localMax;collectVerticalEventsAroundFace(t){let e=t,n,i,s,r;this.upEdges.length=0,this.downEdges.length=0,this.topPeaks.length=0,this.bottomPeaks.length=0,this.localMin.length=0,this.localMax.length=0;do n=e.faceSuccessor,i=n.faceSuccessor,s=Vt.compareNodesYXUp(e,n)<0,r=Vt.compareNodesYXUp(n,i)<0,s?(this.upEdges.push(e),r||(Vt.crossProductToTargets(n,e,i)<0?this.localMax.push(n):this.topPeaks.push(n))):(this.downEdges.push(e),r&&(Vt.crossProductToTargets(n,e,i)>0?this.bottomPeaks.push(n):this.localMin.push(n))),e=n;while(e!==t)}collectVerticalEventFromEdgesInAndArray(t){let e,n,i,s,r;this.upEdges.length=0,this.downEdges.length=0,this.topPeaks.length=0,this.bottomPeaks.length=0,this.localMin.length=0,this.localMax.length=0;for(e of t)n=e.faceSuccessor,i=n.faceSuccessor,s=Vt.compareNodesYXUp(e,n)<0,r=Vt.compareNodesYXUp(n,i)<0,s?(this.upEdges.push(e),r||(Vt.crossProductToTargets(n,e,i)<0?this.localMax.push(n):this.topPeaks.push(n))):(this.downEdges.push(e),r&&(Vt.crossProductToTargets(n,e,i)>0?this.bottomPeaks.push(n):this.localMin.push(n)))}swapArrays(){let t=this.downEdges;this.downEdges=this.upEdges,this.upEdges=t,t=this.localMax,this.localMax=this.localMin,this.localMin=t,t=this.topPeaks,this.topPeaks=this.bottomPeaks,this.bottomPeaks=t}findTopVisibleEdge(t,e,n){const i=t.y,s=t.x;let r,o=Number.MAX_SAFE_INTEGER,a;for(const c of e){const l=c.faceSuccessor;if(c===t||l===t)continue;const d=Vt.compareNodesYXUp(t,c),h=Vt.compareNodesYXUp(t,l);if(d*h>=0)continue;const g=V.horizontalScanFraction01(c,i);g!==void 0&&(r=n*(c.fractionToX(g)-s),r>0&&r<o&&(a=c,o=r))}return a}highestUpPeakConnection(t,e,n){let i;for(const s of this.topPeaks){const r=s.y,o=s.x;if(!(i!==void 0&&Vt.compareNodesYXUp(s,i)<0)&&Vt.compareNodesYXUp(s,t)<0){if(e){const a=V.horizontalScanFraction01(e,r);if(a===void 0||o<=e.fractionToX(a))continue}if(n){const a=V.horizontalScanFraction01(n,r);if(a===void 0||n.fractionToX(a)<=o)continue}i=s}}return i}updateMaxNode(t,e,n){return t?e&&n(t,e)<0?e:t:e}negateXY(){for(const t of this.graph.allHalfEdges)t.x*=-1,t.y*=-1}downwardConnectionFromBottomPeak(t){let e;const n=(o,a)=>Vt.compareNodesYXUp(o,a),i=this.findTopVisibleEdge(t,this.upEdges,1),s=this.findTopVisibleEdge(t,this.downEdges,-1);e=this.updateMaxNode(e,i,n),s&&(e=this.updateMaxNode(e,s.faceSuccessor,n));const r=this.highestUpPeakConnection(t,s,i);return r!==void 0&&(e=this.updateMaxNode(e,r,n)),e}findVisibleSector(t,e){let n=t;do{if(V.isNodeVisibleInSector(e,n))return n;n=n.vertexSuccessor}while(n!==t)}joinNodes(t,e,n){const i=this.graph.createEdgeXYZXYZ(t.x,t.y,t.z,0,e.x,e.y,e.z,0),s=this.findVisibleSector(t,e),r=this.findVisibleSector(e,t);if(s!==void 0&&r!==void 0)return V.pinch(s,i),V.pinch(r,i.edgeMate),i.setMaskAroundEdge(M.REGULARIZED_EDGE),Yi.announceEdge&&Yi.announceEdge(this.graph,i,i.edgeMate,n),i}runRegularization(t=!0,e=!0){if(t){this.bottomPeaks.sort((n,i)=>Vt.compareNodesYXUp(n,i));for(const n of this.bottomPeaks){if(!Vt.isDownPeak(n))continue;const i=this.downwardConnectionFromBottomPeak(n);i!==void 0&&this.joinNodes(n,i,1)}}if(e){this.negateXY(),this.swapArrays(),this.bottomPeaks.sort((n,i)=>Vt.compareNodesYXUp(n,i));for(const n of this.bottomPeaks){if(!Vt.isDownPeak(n))continue;const i=this.downwardConnectionFromBottomPeak(n);i!==void 0&&this.joinNodes(n,i,-1)}this.negateXY(),this.swapArrays()}}regularizeFace(t,e=!0,n=!0){this.collectVerticalEventsAroundFace(t),this.runRegularization(e,n)}regularizeGraph(t=!0,e=!0){this.collectVerticalEventFromEdgesInAndArray(this.graph.allHalfEdges),this.runRegularization(t,e)}static isMonotoneFace(t){let e=0,n=0,i,s=t;do{const r=s.faceSuccessor,o=r.faceSuccessor,a=Vt.compareNodesYXUp(s,r),c=Vt.compareNodesYXUp(r,o);a*c<=0&&(a>0&&(e++,i=r),c>0&&n++)}while((s=s.faceSuccessor)!==t);return e===1&&n===1?i:void 0}static collectMappedFaceRepresentatives(t,e,n,i,s){i&&(i.length=0),s&&(s.length=0);const r=M.VISITED;t.clearMask(r);for(const o of t.allHalfEdges)if(!o.getMask(r)&&(o.setMaskAroundFace(r),!e||o.signedFaceArea()>0)){const a=n(o);a?i&&i.push(a):s&&s.push(o)}}}class Sc{_graph;_candidates;_mask;constructor(t,e){this._graph=t,this._candidates=[],this._mask=e,this._graph.clearMask(e)}clear(){for(;this.chooseAndRemoveAny()!==void 0;);}getLength(){let t=0;for(const e of this._candidates)e.isMaskSet(this._mask)&&t++;return t}getNumCandidates(){return this._candidates.length}get graph(){return this._graph}teardown(){this._graph.dropMask(this._mask),this._candidates.length=0}get mask(){return this._mask}popAndReturn(){const t=this._candidates.length;if(t===0)return;const e=this._candidates[t-1];return this._candidates.pop(),e}getAtIndex(t){if(t>=0&&t<this._candidates.length){const e=this._candidates[t];if(e.isMaskSet(this._mask))return e}}addToSet(t){return t.isMaskSet(this._mask)?!1:(this._candidates.push(t),this.setMaskInScope(t),!0)}isCandidateInSet(t){return t.isMaskSet(this._mask)}removeFromSet(t){return t.isMaskSet(this._mask)?(this.clearMaskInScope(t),!0):!1}chooseAndRemoveAny(){for(;;){const t=this.popAndReturn();if(!t)return;if(this.removeFromSet(t))return t}}[Symbol.iterator](){return new wc(this)}addAroundFace(t){let e=t;do this.addToSet(e),e=e.faceSuccessor;while(e!==t)}addAroundVertex(t){let e=t;do this.addToSet(e),e=e.vertexSuccessor;while(e!==t)}}class Ks extends Sc{constructor(t,e){super(t,e)}static create(t){const e=t.grabMask();if(e!==M.NULL_MASK)return new Ks(t,e)}setMaskInScope(t){t.setMaskAroundEdge(this._mask)}clearMaskInScope(t){t.clearMaskAroundEdge(this._mask)}countHalfEdgesAroundCandidate(t){return t?2:0}}class wc{_markSet;_nextReadIndex;constructor(t){this._markSet=t,this._nextReadIndex=0}next(){const t=this._markSet.getNumCandidates();for(;this._nextReadIndex<t;){const e=this._markSet.getAtIndex(this._nextReadIndex++);if(e!==void 0)return{done:!1,value:e}}return{done:!0,value:void 0}}[Symbol.iterator](){return this}}class zn{_node;_x;_y;_z;_u;_v;constructor(t,e,n,i,s,r){this._x=e,this._y=n,this._z=i,this._u=s,this._v=r,this._node=t}set(t,e,n,i,s,r){return this._x=e,this._y=n,this._z=i,this._u=s,this._v=r,this._node=t,this}setFrom(t){this._x=t.x,this._y=t.y,this._z=t.z,this._u=t.u,this._v=t.v,this._node=t.node}static createNodeAndRayOrigin(t,e,n){const i=t.x,s=t.y,r=t.z,o=i-e.origin.x,a=s-e.origin.y,c=f.dotProductXYXY(o,a,e.direction.x,e.direction.y),l=f.crossProductXYXY(e.direction.x,e.direction.y,o,a);return n?n.set(t,i,s,r,c,l):new zn(t,i,s,r,c,l)}static create(t,e=0,n=0,i=0,s=0,r=0){return new zn(t,e,n,i,s,r)}get node(){return this._node}get x(){return this._x}get y(){return this._y}get z(){return this._z}get u(){return this._u}get v(){return this._v}getXYZAsPoint3d(t){return y.create(this._x,this._y,this._z,t)}getUVAsPoint2d(t){return D.create(this._u,this._v,t)}classifyU(t,e){const n=this.u-t;return Math.abs(n)<=e?0:n>=0?1:-1}classifyV(t,e){const n=t-this._v;return Math.abs(n)<=e?0:n>=0?1:-1}}var ke;(function(u){u[u.None=0]="None",u[u.Vertex=1]="Vertex",u[u.Edge=2]="Edge",u[u.Face=3]="Face",u[u.ExteriorFace=4]="ExteriorFace"})(ke||(ke={}));class Ue{_node;x;y;z;_edgeFraction;_topo;_iTag;_dTag;_isExteriorTarget;constructor(t,e,n,i,s,r,o,a,c){this._node=t,this.x=e,this.y=n,this.z=i,this._topo=s,this._edgeFraction=r,this._iTag=o,this._dTag=a,this._isExteriorTarget=c}setFrom(t){this._node=t._node,this.x=t.x,this.y=t.y,this.z=t.z,this._topo=t._topo,this._edgeFraction=t._edgeFraction,this._iTag=t._iTag,this._dTag=t._dTag}resetAsUnknown(){this._node=void 0,this._topo=ke.None}static create(){return new Ue(void 0,0,0,0,ke.None)}get iTag(){return this._iTag}set iTag(t){this._iTag=t}get dTag(){return this._dTag}set dTag(t){this._dTag=t}hasDTag(){return this._dTag!==void 0}get topo(){return this._topo}static createEdgeAtFraction(t,e){const n=t.faceSuccessor,i=f.interpolate(t.x,e,n.x),s=f.interpolate(t.y,e,n.y),r=f.interpolate(t.z,e,n.z);return new Ue(t,i,s,r,ke.Edge,e)}resetAsFace(t,e){return this._topo=ke.Face,t&&(this._node=t),e&&(this.x=e.x,this.y=e.y,this.z=e.z),this._isExteriorTarget=void 0,this}resetAsUndefinedWithTag(t){return this._topo=ke.None,this._dTag=0,this._iTag=0,this._dTag=t,this._node=void 0,this._isExteriorTarget=void 0,this}resetAtEdgeAndFraction(t,e){this._topo=ke.Edge,this._node=t;const n=t.faceSuccessor;return this._edgeFraction=e,this.x=f.interpolate(t.x,e,n.x),this.y=f.interpolate(t.y,e,n.y),this.z=f.interpolate(t.z,e,n.z),this._isExteriorTarget=void 0,this}static createVertex(t){return new Ue(t,t.x,t.y,t.z,ke.Vertex)}resetAsVertex(t){return this._topo=ke.Vertex,this._node=t,this._edgeFraction=0,this.setXYZFromNode(t),this._isExteriorTarget=void 0,this}setIsExteriorTarget(t){this._isExteriorTarget=t}setXYZFromNode(t){this.x=t.x,this.y=t.y,this.z=t.z}get edgeFraction(){return this._edgeFraction}get isExteriorTarget(){return this._isExteriorTarget!==void 0?this._isExteriorTarget:!1}isFace(){return this._topo===ke.Face&&this._node!==void 0}isEdge(){return this._topo===ke.Edge&&this._node!==void 0&&this._edgeFraction!==void 0}isVertex(){return this._topo===ke.Vertex&&this._node!==void 0}get isUnclassified(){return this._topo===ke.None}get node(){return this._node}clonePoint(t){return y.create(this.x,this.y,this.z,t)}isAtXY(t,e,n=f.smallMetricDistance){return this._topo!==ke.None&&f.isSameCoordinateXY(this.x,this.y,t,e,n)}}var De;(function(u){u[u.NoHits=0]="NoHits",u[u.TargetOnVertex=1]="TargetOnVertex",u[u.TargetOnEdge=2]="TargetOnEdge",u[u.Bracket=3]="Bracket",u[u.TargetBefore=4]="TargetBefore",u[u.TargetAfter=5]="TargetAfter"})(De||(De={}));class io{_tol;constructor(t){this._tol=t}static create(t=f.smallMetricDistance){return new io(t)}panic(){return Ue.create()}reAimFromEdge(t,e,n){if(!t.isEdge())return this.panic();const i=t.node,s=zn.createNodeAndRayOrigin(i,e),r=zn.createNodeAndRayOrigin(i.edgeMate,e),o=-s.classifyV(0,this._tol),a=-r.classifyV(0,this._tol);let c;if(o*a<0)o>0?c=t.resetAsFace(s.node):c=t.resetAsFace(r.node);else if(o===0||a===0){const l=s.classifyU(n,this._tol),d=r.classifyU(n,this._tol);if(o===0&&l===0)c=t.resetAsVertex(s.node),c.iTag=1;else if(a===0&&d===0)c=t.resetAsVertex(r.node),c.iTag=1;else if(o===0&&a===0)if(l*d<0){const h=(n-s.u)/(r.u-s.u);c=t.resetAtEdgeAndFraction(s.node,h),c.iTag=1}else l<0&&d<0?s.u>r.u?c=t.resetAsVertex(s.node):c=t.resetAsVertex(r.node):(t.resetAsUnknown(),c=this.panic());else o===0?s.classifyU(0,this._tol)===0?c=t.resetAsVertex(s.node):c=t.resetAsFace(a>0?r.node:s.node):r.classifyU(0,this._tol)===0?c=t.resetAsVertex(r.node):c=t.resetAsFace(o>0?s.node:r.node)}else t.resetAsUnknown(),c=this.panic();return c}reAimFromVertex(t,e,n){if(!t.isVertex())return this.panic();e.origin.isExactEqual(t);const i=t.node;let s=i;const r=o=>{if(Math.abs(o-n)<=this._tol)t.resetAsVertex(s.faceSuccessor).iTag=1;else if(o>n)t.resetAtEdgeAndFraction(s,n/o);else if(o>this._tol)t.resetAsVertex(s.faceSuccessor);else return!1;return!0};do{const o=zn.createNodeAndRayOrigin(s.faceSuccessor,e),a=zn.createNodeAndRayOrigin(s.facePredecessor,e),c=o.u,l=a.u,d=o.v,h=a.v;if(Math.abs(d)<=this._tol){if(r(c))return t;if(Math.abs(c)<=this._tol&&d<=0&&h>this._tol&&(c>=0||c<0&&l>this._tol))return t.resetAsFace(s,s)}else if(d<-this._tol){if(h>this._tol)return t.resetAsFace(s,s);if(h>=-this._tol){if(Math.abs(l)<=this._tol){if(h>0&&(l>=0||c>this._tol&&l<0))return t.resetAsFace(s,s)}else if(c>this._tol&&l<0)return t.resetAsVertex(s.faceSuccessor)}}s=s.vertexSuccessor}while(s!==i);return this.panic()}reAimAroundFace(t,e,n,i,s){t.isMaskSet(M.EXTERIOR),i.resetAsUndefinedWithTag(-Number.MAX_VALUE),s.resetAsUndefinedWithTag(Number.MAX_VALUE);const r=zn.createNodeAndRayOrigin(t,e);let o,a=t;do{const c=a.faceSuccessor;o=zn.createNodeAndRayOrigin(c,e,o);const l=r.u,d=o.u,h=r.v,g=o.v;if(Math.abs(g)<this._tol){const m=Ue.createVertex(c);if(m.dTag=d,Math.abs(d-n)<this._tol)return s.setFrom(m),i.setFrom(m),De.TargetOnVertex;s.hasDTag()&&i.hasDTag(),d>n&&d<s.dTag&&s.setFrom(m),d<n&&d>i.dTag&&i.setFrom(m)}else if(h*g<0){const m=-h/(g-h),p=f.interpolate(l,m,d),x=Ue.createEdgeAtFraction(r.node,m);if(x.dTag=p,Math.abs(p-n)<=this._tol)return s.setFrom(x),i.setFrom(x),De.TargetOnEdge;s.hasDTag()&&i.hasDTag(),p>n&&p<s.dTag&&s.setFrom(x),p<n&&p>i.dTag&&i.setFrom(x)}r.setFrom(o),a=a.faceSuccessor}while(a!==t);return s.iTag=0,i.iTag=0,i.isUnclassified?s.isUnclassified?De.NoHits:De.TargetBefore:s.isUnclassified?De.TargetAfter:De.Bracket}setSearchRay(t,e,n){n.origin.setFromPoint3d(t),P.createStartEnd(n.origin,e,n.direction),n.direction.z=0;const i=n.direction.magnitudeXY();return i<this._tol?!1:(n.a=i,n.direction.scaleInPlace(1/i),!0)}}var ni;(function(u){u[u.Ignore=0]="Ignore",u[u.Replace=1]="Replace",u[u.ReplaceIfLarger=2]="ReplaceIfLarger",u[u.ReplaceIfSmaller=3]="ReplaceIfSmaller"})(ni||(ni={}));class so{_graph;_edgeSet;_searcher;_tolerance;constructor(t,e){this._graph=t;const n=Ks.create(t);this._edgeSet=n,this._searcher=Ue.create(),this._tolerance=e}static create(t,e=f.smallMetricDistance){return t.hasFreeMask?new so(t,e):void 0}get graph(){return this._graph}retriangulateFromBaseVertex(t){const e=t.countEdgesAroundFace();if(e<4||t.isMaskSet(M.EXTERIOR))return;this._edgeSet.addAroundFace(t);const n=e-3;let i=t.faceSuccessor,s=t;for(let r=0;r<n;r++)i=i.faceSuccessor,s=this._graph.createEdgeHalfEdgeHalfEdge(s,0,i,0),i=s.faceSuccessor,this._edgeSet.addToSet(s)}reset(){this._searcher=Ue.create()}get currentPosition(){return this._searcher}searchForNearestEdgeOrVertex(t){const e=Ue.create();e.dTag=Number.MAX_VALUE;const n=y.create();let i,s;for(const r of this._graph.allHalfEdges){const o=r.faceSuccessor;i=bt.lineSegment3dXYClosestPointUnbounded(r,o,t),i!==void 0&&(i>1?(s=t.distanceXY(o),s<e.dTag&&(e.resetAsVertex(o),e.dTag=s)):i<0?(s=t.distanceXY(r),s<e.dTag&&(e.resetAsVertex(r),e.dTag=s)):(r.fractionToPoint3d(i,n),s=t.distanceXY(n),s<e.dTag&&e.resetAtEdgeAndFraction(r,i)))}return e}searchForNearestVertex(t){const e=Ue.create();e.dTag=Number.MAX_VALUE;let n;for(const i of this._graph.allHalfEdges)n=t.distanceXY(i),n<e.dTag&&(e.resetAsVertex(i),e.dTag=n);return e}resetSearch(t,e){e?this._searcher=this.searchForNearestEdgeOrVertex(t):this._searcher=this.searchForNearestVertex(t)}reclassifyFaceHit(t){if(this._searcher.node===void 0||!this._searcher.isFace()||this._searcher.node.isMaskSet(M.EXTERIOR))return!1;const e=y.create(t.x,t.y),n=this._searcher.node.collectAroundFace(o=>{const a=y.create(o.x,o.y);return a.node=o,a}),i=nt.closestPointOnBoundary(n,e,this._tolerance);if(i.code,yt.OnPolygonEdgeInterior,i.a>this._tolerance)return!1;const s=n[i.closestEdgeIndex].node,r=i.closestEdgeParam<.5?s:s.faceSuccessor;return i.point.distanceSquaredXY(r)<=this._tolerance*this._tolerance?this._searcher.resetAsVertex(r):this._searcher.resetAtEdgeAndFraction(s,i.closestEdgeParam),!0}reclassifyEdgeHit(t){if(this._searcher.node===void 0||!this._searcher.isEdge()||this._searcher.node.isMaskSet(M.BOUNDARY_EDGE))return!1;const e=y.create(t.x,t.y),n=[];for(let o=this._searcher.node.faceSuccessor;o!==this._searcher.node;o=o.faceSuccessor){const a=y.create(o.x,o.y);a.node=o,n.push(a)}for(let o=this._searcher.node.vertexPredecessor;o!==this._searcher.node.edgeMate;o=o.faceSuccessor){const a=y.create(o.x,o.y);a.node=o,n.push(a)}const i=nt.closestPointOnBoundary(n,e,this._tolerance);if(i.a>this._tolerance)return!1;const s=n[i.closestEdgeIndex].node,r=i.closestEdgeParam<.5?s:s.faceSuccessor;return i.code===yt.OnPolygonVertex?this._searcher.resetAsVertex(r):i.point.distanceSquaredXY(r)<=this._tolerance*this._tolerance?this._searcher.resetAsVertex(r):this._searcher.resetAtEdgeAndFraction(s,i.closestEdgeParam),!0}updateZAroundVertex(t,e,n){ni.Ignore!==n&&(ni.ReplaceIfLarger===n&&e.z<=t.z||ni.ReplaceIfSmaller===n&&e.z>=t.z||t.setXYZAroundVertex(t.x,t.y,e.z))}insertAndRetriangulate(t,e){if(this.moveToPoint(this._searcher,t),this._searcher.node===void 0)return!1;if(this.reclassifyFaceHit(t)||this.reclassifyEdgeHit(t),this._searcher.isFace()){if(!this._searcher.node.isMaskSet(M.EXTERIOR)){const n=this._graph.createEdgeXYZHalfEdge(t.x,t.y,t.z,0,this._searcher.node,0);this.retriangulateFromBaseVertex(n),B.flipTrianglesInEdgeSet(this._graph,this._edgeSet),this._searcher.resetAsVertex(n)}}else if(this._searcher.isEdge()){const n=this._graph.splitEdgeAtFraction(this._searcher.node,this._searcher.edgeFraction),i=n.vertexPredecessor;this.updateZAroundVertex(n,t,ni.Replace),this.retriangulateFromBaseVertex(n),this.retriangulateFromBaseVertex(i),B.flipTrianglesInEdgeSet(this._graph,this._edgeSet),this._searcher.resetAsVertex(n)}else this._searcher.isVertex()&&this.updateZAroundVertex(this._searcher.node,t,e);return!0}moveToPoint(t,e,n){const i=io.create(this._tolerance);if(t.iTag=0,t.isUnclassified&&(Ac(this.graph,t,.5,M.NULL_MASK),t.isUnclassified))return!1;let s=0;const r=O.createXAxis();for(;t.iTag===0&&s<2&&!(n!==void 0&&!n(t));){if(!i.setSearchRay(t,e,r))return!1;if(r.a,t.isFace()){const o=Ue.create(),a=Ue.create();switch(i.reAimAroundFace(t.node,r,r.a,o,a)){case De.NoHits:{t.resetAsUnknown();break}case De.TargetOnVertex:{t.setFrom(o),t.iTag=1;break}case De.TargetOnEdge:{t.setFrom(o),t.iTag=1;break}case De.Bracket:{t.resetAsFace(o.node,e),t.iTag=1;break}case De.TargetBefore:{t.resetAsFace(t.node,e),t.iTag=1;break}case De.TargetAfter:{t.node===o.node&&t.isFace()&&(o.isEdge()||o.isVertex())?s++:s=0,t.setFrom(o);break}}}else if(t.isEdge()){if(i.reAimFromEdge(t,r,r.a),t.isUnclassified)break}else if(t.isVertex()&&(i.reAimFromVertex(t,r,r.a),t.isUnclassified))break}return t.isAtXY(e.x,e.y,this._tolerance)?!0:(s>1&&t.node!==void 0&&t.setIsExteriorTarget(!0),!1)}}function Ac(u,t,e,n){for(const i of u.allHalfEdges)if(!i.isMaskSet(n))return t.resetAtEdgeAndFraction(i,e),!0;return!1}class B{static flipEdgeBetweenTriangles(t,e,n,i,s,r){V.pinch(t,s),V.pinch(n,i),V.pinch(r,n),V.pinch(s,e),s.x=e.x,s.y=e.y,s.z=e.z,s.i=e.i,n.i=r.i,n.x=r.x,n.y=r.y,n.z=r.z}static computeCircumcircleDeterminantIsStrongPositive(t){const e=t.faceSuccessor,n=e.faceSuccessor;if(n.faceSuccessor!==t)return!1;const i=t.edgeMate,r=i.faceSuccessor.faceSuccessor;if(r.faceSuccessor!==i)return!1;const o=e.x-t.x,a=e.y-t.y,c=n.x-t.x,l=n.y-t.y;if(f.crossProductXYXY(o,a,c,l)<0)return!1;const d=r.x-t.x,h=r.y-t.y,g=d*d+h*h,m=c*c+l*l,p=o*o+a*a,x=f.tripleProduct(d,h,g,c,l,m,o,a,p);if(x<0)return!1;const _=Math.abs(d*l*p)+Math.abs(h*m*o)+Math.abs(g*c*a)+Math.abs(d*m*a)+Math.abs(h*c*p)+Math.abs(g*l*o);return x>1e-12*_}static flipTriangles(t){const e=Ks.create(t);if(!e)return 0;for(const i of t.allHalfEdges)e.addToSet(i);const n=this.flipTrianglesInEdgeSet(t,e);return e.teardown(),n}static flipTrianglesInEdgeSet(t,e){const n=M.EXTERIOR|M.PRIMARY_EDGE|M.BOUNDARY_EDGE,s=10*t.allHalfEdges.length;let r=0,o=0,a;for(;(a=e.chooseAndRemoveAny())!==void 0&&!(!a.isMaskSet(n)&&(B.computeCircumcircleDeterminantIsStrongPositive(a)?(B.flipEdgeBetweenTriangles(a.edgeMate.faceSuccessor,a.edgeMate.facePredecessor,a.edgeMate,a.faceSuccessor,a,a.facePredecessor),e.addAroundFace(a),e.addAroundFace(a.edgeMate),r++):o++,r+o>s)););return r}static createTriangulatedGraphFromPoints(t,e=ni.ReplaceIfLarger,n=f.smallMetricDistance){if(t.length<3)return;const i=[],s=[];re.computeConvexHullXY(t,i,s,!0);const r=new be,o=so.create(r,n),a=B.createFaceLoopFromCoordinates(r,i,!0,!0);if(a!==void 0){for(const c of s)o.insertAndRetriangulate(c,e);return a.countEdgesAroundFace()>3?B.createTriangulatedGraphFromSingleLoop(i):r}}static createTriangulatedGraphFromLoops(t){if(t.length<1)return;const e=M.BOUNDARY_EDGE|M.PRIMARY_EDGE,n=new be,i=[];let s=-1e4,r=-1;for(let c=0;c<t.length;c++){let l=B.directCreateFaceLoopFromCoordinates(n,t[c]);if(l){l=l.faceSuccessor;const d=l.vertexSuccessor;l.setMaskAroundFace(e),d.setMaskAroundFace(e);const h=l.signedFaceArea(),g=Math.abs(h);i.push(h>=0?l:d),(c===0||g>s)&&(s=g,r=c)}}if(i.length===0)return;const o=i[r];i[r]=i[i.length-1],i.pop(),o.vertexSuccessor.setMaskAroundFace(M.EXTERIOR);for(let c=0;c<i.length;c++){const l=i[c];l.setMaskAroundFace(M.EXTERIOR),i[c]=this.getLeftmost(l.vertexSuccessor)}const a=B.spliceLeftMostNodesOfHoles(n,o,i);if(a&&B.triangulateSingleFace(n,a))return n}static triangulateAllPositiveAreaFaces(t){const e=t.collectFaceLoops();let n=0;for(const i of e)i.countEdgesAroundFace()>3&&i.signedFaceArea()>0&&(B.triangulateSingleFace(t,i)||n++);return n===0}static _workTransform;static triangulateAllInteriorFaces(t,e,n){const i=t.collectFaceLoops(),s=e?t.grabMask():M.NULL_MASK;n=e||n;let r,o,a=0,c=0;for(const l of i)if(l.countEdgesAroundFace()>3){if(l.getMask(M.EXTERIOR))continue;if(e&&(a=t.countNodes(),o=l.collectAroundFace(),r=this._workTransform=Qt.createRightHandedLocalToWorld(o,this._workTransform),r?.multiplyInversePoint3dArrayInPlace(o)),B.triangulateSingleFace(t,l,n)||c++,r&&o){for(let d=a;d<t.countNodes();++d)o.push(t.allHalfEdges[d]);r.multiplyPoint3dArrayInPlace(o)}}return t.dropMask(s),c===0}static createTriangulatedGraphFromSingleLoop(t){const e=new be,n=B.createFaceLoopFromCoordinates(e,t,!0,!0);if(!(!n||e.countNodes()<6)&&B.triangulateSingleFace(e,n))return B.flipTriangles(e),e}static interiorEdgeSplit(t,e,n){let i=0,s=0,r=0;if(Array.isArray(n))i=n[0],s=n[1],r=n.length>2?n[3]:0;else{const o=n;o.hasOwnProperty("x")&&(i=o.x),o.hasOwnProperty("y")&&(s=o.y),o.hasOwnProperty("z")&&(r=o.z)}return e&&B.isAlmostEqualXAndYXY(e,i,s)?e:t.splitEdge(e,i,s,r)}static getUnwrappedLength(t){let e=t.length,n,i,s,r;for(;e>1&&(t instanceof le?(n=t.getXAtUncheckedPointIndex(0),i=t.getYAtUncheckedPointIndex(0),s=t.getXAtUncheckedPointIndex(e-1),r=t.getYAtUncheckedPointIndex(e-1)):f.isArrayOfNumberArray(t,e,2)?(n=t[0][0],i=t[0][1],s=t[e-1][0],r=t[e-1][1]):(n=t[0].x,i=t[0].y,s=t[e-1].x,r=t[e-1].y),f.isAlmostEqualNumber(n,s)&&f.isAlmostEqualNumber(i,r));)--e;return e}static directCreateFaceLoopFromCoordinates(t,e){const n=this.getUnwrappedLength(e);let i;if(e instanceof le){const s=y.create();for(let r=0;r<n;r++)e.getPoint3dAtCheckedPointIndex(r,s),i=B.interiorEdgeSplit(t,i,s)}else for(let s=0;s<n;s++)i=B.interiorEdgeSplit(t,i,e[s]);return i}static directCreateChainsFromCoordinates(t,e,n=0){const i=new Cc(t,n);return bn.streamXYZ(e,i),i.claimSeeds()}static maskAndOrientNewFaceLoop(t,e,n,i,s){if(e){e=e.faceSuccessor;const r=e.signedFaceArea(),o=e.edgeMate;i!==M.NULL_MASK&&(e.setMaskAroundFace(i),o.setMaskAroundFace(i));let a=e;n&&r<0&&(a=o);const c=a.vertexSuccessor;return s!==M.NULL_MASK&&c.setMaskAroundFace(s),a}}static createFaceLoopFromCoordinates(t,e,n,i){const s=B.directCreateFaceLoopFromCoordinates(t,e);return B.maskAndOrientNewFaceLoop(t,s,n,M.BOUNDARY_EDGE|M.PRIMARY_EDGE,i?M.EXTERIOR:M.NULL_MASK)}static createFaceLoopFromCoordinatesAndMasks(t,e,n,i,s){const r=B.directCreateFaceLoopFromCoordinates(t,e);return B.maskAndOrientNewFaceLoop(t,r,n,i,s)}static joinNeighborsOfEar(t,e){const n=t.createEdgeXYZXYZ(e.facePredecessor.x,e.facePredecessor.y,e.facePredecessor.z,e.facePredecessor.i,e.faceSuccessor.x,e.faceSuccessor.y,e.faceSuccessor.z,e.faceSuccessor.i),i=n.edgeMate;V.pinch(e.faceSuccessor,i),V.pinch(e.facePredecessor,n),e.setMaskAroundFace(M.TRIANGULATED_FACE)}static isInteriorTriangle(t){if(!t.isMaskSet(M.TRIANGULATED_FACE)||t.isMaskSet(M.EXTERIOR))return!1;const e=t.faceSuccessor;if(!e.isMaskSet(M.TRIANGULATED_FACE)||e.isMaskSet(M.EXTERIOR))return!1;const n=e.faceSuccessor;return!n.isMaskSet(M.TRIANGULATED_FACE)||n.isMaskSet(M.EXTERIOR)?!1:n.faceSuccessor===t}static doPostCutFlips(t){let e=t,n=e.facePredecessor,i=n.edgeMate;for(;B.isInteriorTriangle(n)&&B.isInteriorTriangle(i)&&B.computeCircumcircleDeterminantIsStrongPositive(n);){const r=i.faceSuccessor;B.flipEdgeBetweenTriangles(r,r.faceSuccessor,r.facePredecessor,e,e.facePredecessor,e.faceSuccessor),e=n,n=e.facePredecessor,i=n.edgeMate}return e}static triangulateSingleFace(t,e,n=!1){if(!e)return B.setDebugGraph(t),!1;let i,s,r,o=e.countEdgesAroundFace(),a=0;for(e.clearMaskAroundFace(M.TRIANGULATED_FACE);!e.isMaskSet(M.TRIANGULATED_FACE);){if(r=e?.facePredecessor,i=e.faceSuccessor,s=i.faceSuccessor,i===e||s===e)return!0;if(s.faceSuccessor===e)return e.setMaskAroundFace(M.TRIANGULATED_FACE),!0;if(B.isAlmostEqualXAndYXY(s,r.x,r.y)&&!s.findAroundVertex(r)){const c=s.faceSuccessor;if(this.nodeInTriangle(r,e,i,c)){const d=s.vertexPredecessor;V.pinch(r.vertexSuccessor,d)}else V.pinch(r,s),e.setMaskAroundFace(M.TRIANGULATED_FACE);e=s;continue}if(++a>o)return B.setDebugGraph(t),!1;if(B.isEar(e)){o--,a=0,e.faceSuccessor.faceSuccessor!==e.facePredecessor?(B.joinNeighborsOfEar(t,e),n||(e=B.doPostCutFlips(e)),e=e.faceSuccessor.edgeMate.faceSuccessor):(e.setMaskAroundFace(M.TRIANGULATED_FACE),e=i.faceSuccessor);continue}e=i}return!0}static sDebugGraph;static sEnableDebugGraphCapture=!1;static claimDebugGraph(){const t=B.sDebugGraph;return B.sDebugGraph=void 0,B.sEnableDebugGraphCapture=!1,t}static setDebugGraph(t){B.sEnableDebugGraphCapture&&(B.sDebugGraph=t)}static clearAndEnableDebugGraphCapture(t){B.sEnableDebugGraphCapture=t,B.sDebugGraph=void 0}static findAroundOrAtVertex(t,e){return t.findAroundVertex(e)?!0:B.isAlmostEqualXAndYXY(t,e.x,e.y)}static _edgeInterval=ct.createNull();static _earRange=Rt.createNull();static _edgeRange=Rt.createNull();static _planes=[ht.createXYPlane(),ht.createXYPlane(),ht.createXYPlane()];static isEar(t){const e=t.facePredecessor,n=t,i=t.faceSuccessor,s=B.signedTolerancedCCWTriangleArea(e,n,i);if(s<=0)return!1;const r=this._planes;if(!ht.createOriginAndTargetXY(e,n,r[0])||!ht.createOriginAndTargetXY(n,i,r[1])||!ht.createOriginAndTargetXY(i,e,r[2]))return!1;const o=this._earRange,a=this._edgeRange,c=this._edgeInterval;Rt.createXYXYXY(e.x,e.y,n.x,n.y,i.x,i.y,o),o.expandInPlace(f.smallMetricDistance);let l=i;const d=1e-8,h=-d,g=1+d,m=1-d,p=1e-10*s;for(;l!==e;){const x=l.faceSuccessor;if(Rt.createXYXY(l.x,l.y,x.x,x.y,a),o.intersectsRange(a)&&(ct.createXX(h,g,c),ee.clipSegmentBelowPlanesXY(r,l,x,c,p),!c.isNull)){if(c.low>m){if(!this.findAroundOrAtVertex(e,x)&&!this.findAroundOrAtVertex(n,x)&&!this.findAroundOrAtVertex(i,x))return!1}else if(c.high<d){if(!this.findAroundOrAtVertex(e,l)&&!this.findAroundOrAtVertex(n,l)&&!this.findAroundOrAtVertex(i,l))return!1}else if(!(this.findAroundOrAtVertex(n,x)&&this.findAroundOrAtVertex(i,l))){if(!(this.findAroundOrAtVertex(e,x)&&this.findAroundOrAtVertex(n,l)))return!1}}l=l.faceSuccessor}return!0}static spliceLeftMostNodesOfHoles(t,e,n){n.sort((s,r)=>B.compareX(s,r));let i=0;for(const s of n)B.eliminateHole(t,s,e)||i++;return i===0?e:void 0}static compareX(t,e){return t.x-e.x}static eliminateHole(t,e,n){const i=B.findHoleBridge(e,n);return i?B.splitFace(t,i,e)!==void 0:!1}static findHoleBridge(t,e){let n=e;if(!n)return;const i=t.x,s=t.y;let r=-1/0,o;do{if(s<=n.y&&s>=n.faceSuccessor.y&&n.faceSuccessor.y!==n.y){const g=n.x+(s-n.y)*(n.faceSuccessor.x-n.x)/(n.faceSuccessor.y-n.y);if(g<=i&&g>r){if(r=g,g===i){if(s===n.y)return n;if(s===n.faceSuccessor.y)return n.faceSuccessor}o=n.x<n.faceSuccessor.x?n:n.faceSuccessor}}n=n.faceSuccessor}while(n!==e);if(!o)return;if(i===r)return o.facePredecessor;const a=o,c=o.x,l=o.y;let d=1/0,h;for(n=o.faceSuccessor;n!==a;)i>=n.x&&n.x>=c&&i!==n.x&&B.pointInTriangle(s<l?i:r,s,c,l,s<l?r:i,s,n.x,n.y)&&(h=Math.abs(s-n.y)/(i-n.x),(h<d||h===d&&n.x>o.x)&&B.locallyInside(n,t)&&(o=n,d=h)),n=n.faceSuccessor;return o}static getLeftmost(t){let e=t,n=t;do e.x<n.x&&(n=e),e=e.faceSuccessor;while(e!==t);return n}static pointInTriangle(t,e,n,i,s,r,o,a){return(s-o)*(e-a)-(t-o)*(r-a)>=0&&(t-o)*(i-a)-(n-o)*(e-a)>=0&&(n-o)*(r-a)-(s-o)*(i-a)>=0}static nodeInTriangle(t,e,n,i){return B.signedTolerancedCCWTriangleArea(t,e,i)>0&&B.signedTolerancedCCWTriangleArea(e,n,i)>0&&B.signedTolerancedCCWTriangleArea(n,t,i)>0}static signedCWTriangleArea(t,e,n){return .5*((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))}static signedTolerancedCCWTriangleArea(t,e,n,i=1e-12){const s=e.x-t.x,r=e.y-t.y,o=n.x-t.x,a=n.y-t.y,c=.5*(s*a-r*o);if(c<0)return c;const l=s*s+r*r,d=o*o+a*a;return c<i*(l+d)?0:c}static isAlmostEqualXAndYXY(t,e,n){return f.isAlmostEqualNumber(t.x,e)&&f.isAlmostEqualNumber(t.y,n)}static locallyInside(t,e){return B.signedCWTriangleArea(t.facePredecessor,t,t.faceSuccessor)<0?B.signedCWTriangleArea(t,e,t.faceSuccessor)>=0&&B.signedCWTriangleArea(t,t.facePredecessor,e)>=0:B.signedCWTriangleArea(t,e,t.facePredecessor)<0||B.signedCWTriangleArea(t,t.faceSuccessor,e)<0}static splitFace(t,e,n){if(V.isNodeVisibleInSector(e,n)&&V.isNodeVisibleInSector(n,e)){const i=t.createEdgeXYZXYZ(e.x,e.y,e.z,e.i,n.x,n.y,n.z,n.i),s=i.faceSuccessor;return V.pinch(e,i),V.pinch(n,s),i}}static triangulateSingleMonotoneFace(t,e){let n=e.facePredecessor,i=e.faceSuccessor,s;for(;n!==i&&i!==e&&i.faceSuccessor!==n;){if(V.crossProductXYAlongChain(n,e,i)<=0||!e.belowYX(n)||!e.belowYX(i))return!1;if(n.belowYX(i)){let r=n,o=e,a=i;for(;r!==a&&r.belowYX(i);){for(;a!==i&&a!==r&&a!==o&&V.crossProductXYAlongChain(r,o,a)>0;){if(s=B.splitFace(t,r,a),s===void 0)return!1;r=s,o=r.faceSuccessor,a=o.faceSuccessor}a=o,o=r,r=r.facePredecessor}for(n=o,a=i,o=a.facePredecessor,r=o.facePredecessor;a.faceSuccessor!==r&&r!==n;){if(s=B.splitFace(t,r,a),s===void 0)return!1;o=s,r=o.facePredecessor}if(a.faceSuccessor!==r){if(s=B.splitFace(t,r,a),s===void 0)return!1;r=s}e=r,i=e.faceSuccessor,n=e.facePredecessor}else{let r=n,o=e,a=i;for(;r!==a&&a.belowYX(n);){for(;r!==n&&a!==r&&a!==o&&V.crossProductXYAlongChain(r,o,a)>0;){if(s=B.splitFace(t,r,a),s===void 0)return!1;r=s.facePredecessor,o=s}r=o,o=a,a=a.faceSuccessor}for(i=o,r=n,o=r.faceSuccessor,a=o.faceSuccessor;a.faceSuccessor!==r&&a!==i;){if(s=B.splitFace(t,r,a),s===void 0)return!1;r=s,a=a.faceSuccessor}if(a.faceSuccessor!==r&&B.splitFace(t,r,a)===void 0)return!1;e=i,i=e.faceSuccessor,n=e.facePredecessor}}return!0}}class Cc extends lc{_seeds;_baseNode;_nodeB;_nodeC;_graph;_id;constructor(t,e){super(),this._graph=t,this._id=e}startChain(t,e){super.startChain(t,e),this._baseNode=void 0,this._nodeB=void 0}handleXYZXYZ(t,e,n,i,s,r){this._nodeC=this._graph.createEdgeXYZXYZ(t,e,n,this._id,i,s,r,this._id),this._baseNode===void 0?(this._baseNode=this._nodeC,this._nodeB=this._baseNode.faceSuccessor):(this._nodeB,this._nodeB&&(V.pinch(this._nodeB,this._nodeC),this._nodeB=this._nodeC.faceSuccessor))}endChain(t,e){super.endChain(t,e),this._baseNode!==void 0&&(this._seeds===void 0&&(this._seeds=[]),this._seeds.push(this._baseNode)),this._baseNode=void 0,this._nodeB=void 0,this._nodeC=void 0}claimSeeds(){return this._seeds===void 0?[]:this._seeds}}class Tc{numUpEdge=0;numIntersectionTest=0;numSplit=0;numPopOut=0;numA0B0=0;numA0B1=0;constructor(){}}class ua{index;radiusOfCurvature;node;radians;constructor(t,e,n,i){this.index=t,this.radiusOfCurvature=e,this.node=n,this.radians=i}}class Vt{static compareNodesYXUp(t,e){return t.y<e.y?-1:t.y>e.y?1:t.x<e.x?-1:t.x>e.x?1:0}static isDownPeak(t){const e=t.facePredecessor,n=t.faceSuccessor;return this.compareNodesYXUp(t,e)<0&&this.compareNodesYXUp(t,n)<0&&this.crossProductToTargets(t,e,n)>0}static crossProductToTargets(t,e,n){return f.crossProductXYXY(e.x-t.x,e.y-t.y,n.x-t.x,n.y-t.y)}static graphRange(t){const e=J.create();for(const n of t.allHalfEdges)e.extendXYZ(n.x,n.y,n.z);return e}static graphRangeXY(t){const e=Rt.createNull();for(const n of t.allHalfEdges)e.extendXY(n.x,n.y);return e}static segmentArrayToGraphEdges(t,e,n){const i=[];let s=0;for(const r of t){const o=e.createEdgeXYZXYZ(r.point0Ref.x,r.point0Ref.y,r.point0Ref.z,s,r.point1Ref.x,r.point1Ref.y,r.point1Ref.z,s+1),a=o.edgeMate;s+=2,o.setMaskAroundFace(n),i.push(o),i.push(a)}return i}static isolateAllEdges(t){for(const e of t.allHalfEdges){const n=e.vertexPredecessor;V.pinch(e,n)}}static isSectorConvexAfterEdgeRemoval(t,e,n,i=0){let s=t;do{if(s.isMaskSet(n)||s.edgeMate.isMaskSet(n))break;s=s.vertexSuccessor}while(s!==t&&s.isMaskSet(e));if(s===t)return!1;let r=t;do{if(r.isMaskSet(n)||r.edgeMate.isMaskSet(n))break;r=r.vertexPredecessor}while(r!==t&&r.isMaskSet(e));return r===t?!1:V.isSectorConvex(s.edgeMate,t,r.faceSuccessor,i)}static markRemovableEdgesToExpandConvexFaces(t,e,n=M.BOUNDARY_EDGE){if(M.NULL_MASK===e)return 0;const i=t.grabMask(!0);let s=0;for(const r of t.allHalfEdges){if(!r.isMaskSet(i)&&!r.isMaskSet(n)&&!r.edgeMate.isMaskSet(n)){const o=f.smallMetricDistanceSquared*(r.signedFaceArea()+r.edgeMate.signedFaceArea());this.isSectorConvexAfterEdgeRemoval(r,e,n,o)&&this.isSectorConvexAfterEdgeRemoval(r.edgeMate,e,n,o)&&(r.setMaskAroundEdge(e),++s)}r.setMaskAroundEdge(i)}return t.dropMask(i),s}static collectRemovableEdgesToExpandConvexFaces(t,e=M.BOUNDARY_EDGE){const n=[],i=t.grabMask(!0);if(0<this.markRemovableEdgesToExpandConvexFaces(t,i,e)){const s=t.grabMask(!0);for(const r of t.allHalfEdges)r.isMaskSet(i)&&!r.isMaskSet(s)&&(r.setMaskAroundEdge(s),n.push(r));t.dropMask(s)}return t.dropMask(i),n}static expandConvexFaces(t,e=M.BOUNDARY_EDGE){const n=t.grabMask(!0),i=this.markRemovableEdgesToExpandConvexFaces(t,n,e);return i>0&&.5*t.yankAndDeleteEdges(s=>s.getMask(n)),t.dropMask(n),i}static isEveryFaceConvex(t,e=M.EXTERIOR){const n=t.collectFaceLoops();for(const i of n)if(!i.isMaskedAroundFace(e)&&!i.isFaceConvex())return!1;return!0}}class Je{static getCommonThetaEndIndex(t,e,n,i,s=f.smallAngleRadians){let r=n+1;const o=t.getExtraData(e[n],0);for(;r<i;){const a=t.getExtraData(e[r],0);if(!A.isAlmostEqualRadiansAllowPeriodShift(o,a,s))return r;r++}return r}static _announceVertexNeighborhoodFunction;static set announceVertexNeighborhoodFunction(t){this._announceVertexNeighborhoodFunction=t}static doAnnounceVertexNeighborhood(t,e,n,i,s){if(this._announceVertexNeighborhoodFunction){const r=[];for(let o=i;o<s;o++){const a=t.getExtraData(e[o],1),c=t.getExtraData(e[o],0),l=n[a],d=this.curvatureSortKey(l);r.push(new ua(e[o],d,l,c))}this._announceVertexNeighborhoodFunction(r)}}static secondarySortAroundVertex(t,e,n,i,s,r=f.smallAngleRadians){const o=[];for(let a=i;a<s;){const c=this.getCommonThetaEndIndex(t,e,a,s,r);if(a+1<c){o.length=0;for(let l=a;l<c;l++){const d=t.getExtraData(e[l],1),h=n[d],g=this.curvatureSortKey(h);o.push(new ua(e[l],g,h))}o.sort((l,d)=>l.radiusOfCurvature-d.radiusOfCurvature);for(let l=0;l<o.length;l++)e[a+l]=o[l].index}a=c}}static curvatureSortKey(t){if(t.edgeTag!==void 0&&t.edgeTag instanceof Y){const e=t.edgeTag;if(e.curve!==void 0){const n=t.sortData!==void 0&&t.sortData<0,i=n&&e.fraction1!==void 0?e.fraction1:e.fraction,s=e.curve.fractionToSignedXYRadiusOfCurvature(i);return n?-s:s}}return 0}static isNullFace(t){return t.isMaskSet(M.NULL_FACE)&&t.faceSuccessor.isMaskSet(M.NULL_FACE)&&t===t.faceSuccessor.faceSuccessor}static clusterAndMergeXYTheta(t,e,n=f.smallMetricDistance,i=f.smallAngleRadians){const s=t.allHalfEdges,r=s.length;t.clearMask(M.NULL_FACE);const o=new Tt(2,2,r);for(let m=0;m<r;m++){const p=s[m],x=p.x,_=p.y;V.pinch(p,p.vertexSuccessor),o.addDirect(x,_,0,m)}const a=o.clusterIndicesLexical(n);let c=0;const l=a.length;for(let m=0;m<l;m++)if(a[m]===Tt.clusterTerminator){if(m>c){const p=o.getExtraData(a[c],1),x=s[p];for(let _=c+1;_<m;_++){const I=o.getExtraData(a[_],1),v=s[I];v.x=x.x,v.y=x.y}}c=m+1}for(const m of a)if(m!==Tt.clusterTerminator){const p=s[m],x=p.faceSuccessor;let _=e;if(_){const v=p.edgeTag;(v===void 0||v.curve===void 0||v.curve instanceof U)&&(_=void 0)}let I=_?_(p):Math.atan2(x.y-p.y,x.x-p.x);A.isAlmostEqualRadiansAllowPeriodShift(I,-Math.PI,i)&&(I=Math.PI),o.setExtraData(m,0,I)}o.sortSubsetsBySingleKey(a,2);const d=[];c=0;let h,g;for(let m=0;m<l;m++)if(a[m]===Tt.clusterTerminator){if(m>c){m>c+1&&this.secondarySortAroundVertex(o,a,s,c,m,i),this.doAnnounceVertexNeighborhood(o,a,s,c,m);const p=o.getExtraData(a[c],1);h=o.getExtraData(a[c],0);let _=s[p];for(let I=c+1;I<m;I++){const v=o.getExtraData(a[I],1);g=o.getExtraData(a[I],0);const S=s[v];if(_.isMaskSet(M.NULL_FACE)){const w=d.findIndex(T=>_===T);w>=0&&(d[w]=d[d.length-1],d.pop()),_=S,h=g}else if(S.isMaskSet(M.NULL_FACE)){const w=d.findIndex(T=>S===T);w>=0&&(d[w]=d[d.length-1],d.pop())}else{if(V.pinch(_,S),A.isAlmostEqualRadiansAllowPeriodShift(h,g,i)){const w=_.faceSuccessor,T=S.edgeMate;if(w.isEqualXY(T)){const R=this.curvatureSortKey(_),L=this.curvatureSortKey(S);f.isSameCoordinate(R,L,n)&&(V.pinch(w,T),_.setMask(M.NULL_FACE),T.setMask(M.NULL_FACE),d.push(T))}}_=S,h=g}}}c=m+1}}static buildVerticalSweepPriorityQueue(t){const e=new vc;for(const n of t.allHalfEdges)Vt.compareNodesYXUp(n,n.faceSuccessor)<0&&e.priorityQueue.push(n);return e}static computeIntersectionFractionsOnEdges(t,e,n=f.smallMetricDistance){const i=t.faceSuccessor,s={x:i.x-t.x,y:i.y-t.y},r=e.faceSuccessor,o={x:r.x-e.x,y:r.y-e.y};let a=bt.lineSegmentXYUVIntersectionUnbounded(t,s,e,o,n);if(a){const c=(l,d,h)=>{const g=f.interpolate(d.x,l,h.x),m=f.interpolate(d.y,l,h.y);return f.isSameCoordinateXY(g,m,d.x,d.y,n)?0:f.isSameCoordinateXY(g,m,h.x,h.y,n)?1:l};a.f0.x=c(a.f0.x,t,i),a.f0.y=c(a.f0.y,e,r),a.f1&&(a.f1.x=c(a.f1.x,t,i),a.f1.y=c(a.f1.y,e,r)),a.f1&&!(f.isIn01(a.f1.x)&&f.isIn01(a.f1.y))&&(a.f1=void 0),f.isIn01(a.f0.x)&&f.isIn01(a.f0.y)||(a.f1?(a.f0=a.f1,a.f1=void 0):a=void 0)}return a}static splitIntersectingEdges(t,e=f.smallMetricDistance,n=1e-8){const i=new Tc,s=this.buildVerticalSweepPriorityQueue(t);let r,o;const a=n,c=1-a;let l,d;for(;(r=s.priorityQueue.pop())!==void 0;){i.numUpEdge++;const h=s.activeEdges.length;for(s.removeArrayMembersWithY1Below(r.y-e),i.numPopOut+=h-s.activeEdges.length,l=0;l<s.activeEdges.length;l++)if(d=s.activeEdges[l],o=d.faceSuccessor,f.isSameCoordinateXY(r.x,r.y,d.x,d.y,e))i.numA0B0++;else if(f.isSameCoordinateXY(o.x,o.y,r.x,r.y,e))i.numA0B1++;else{i.numIntersectionTest++;const g=this.computeIntersectionFractionsOnEdges(r,d,e);if(g){const m=(p,x)=>{if(x!==void 0&&x>a&&x<c){const _=t.splitEdgeAtFraction(p,x);s.priorityQueue.push(_),i.numSplit++}};m(r,g.f0.x),m(r,g.f1?.x),m(d,g.f0.y),m(d,g.f1?.y)}}s.activeEdges.push(r)}return i}static formGraphFromSegments(t){const e=new be;return Vt.segmentArrayToGraphEdges(t,e,M.BOUNDARY_EDGE),this.splitIntersectingEdges(e),this.clusterAndMergeXYTheta(e),e}static formGraphFromChains(t,e=!0,n=M.PRIMARY_EDGE){if(t.length<1)return;const i=new be,s=B.directCreateChainsFromCoordinates(i,t);for(const r of s)r.setMaskAroundFace(n);return this.splitIntersectingEdges(i),this.clusterAndMergeXYTheta(i),e&&new Yi(i).regularizeGraph(!0,!0),i}}class Vn{tolerance;static _defaultPrimarySortDirection=P.create(.294234298,.72391399,.45234328798);primarySortDirection;static createPrimarySortVector(t){return t===void 0&&(t=this._defaultPrimarySortDirection.clone()),t.normalizeWithDefault(Vn._defaultPrimarySortDirection.x,Vn._defaultPrimarySortDirection.y,Vn._defaultPrimarySortDirection.z)}constructor(t,e){this.tolerance=t,this.primarySortDirection=e}static createFromUnValidated(t){const e=new Vn(f.smallMetricDistance,Vn.createPrimarySortVector());return t!==void 0&&(t.tolerance!==void 0&&(e.tolerance=t.tolerance),t.primarySortDirection!==void 0&&(e.primarySortDirection=Vn.createPrimarySortVector())),e}clone(){return new Vn(this.tolerance,this.primarySortDirection)}}class Ke{_graph;_options;_plane;_convexClipper;constructor(t){this._graph=new be,this._options=t}set plane(t){this._plane=t}get plane(){return this._plane}set convexClipper(t){this._convexClipper=t}get convexClipper(){return this._convexClipper}static create(t){const e=Vn.createFromUnValidated(t);return new Ke(e)}addSegment(t,e){this._graph.createEdgeXYZXYZ(t.x,t.y,t.z,0,e.x,e.y,e.z,0)}addLineSegment3dArray(t){for(const e of t)this.addSegment(e.point0Ref,e.point1Ref)}addSegmentsOnPlane(t,e=!1){if(!this._plane)return;const n=this._plane;let i=e?t.length-1:0,s=t.evaluateUncheckedIndexPlaneAltitude(i,n),r=e?0:1,o;for(;r<t.length;i=r++,s=o)o=t.evaluateUncheckedIndexPlaneAltitude(r,n),f.isSmallMetricDistance(s)&&f.isSmallMetricDistance(o)&&this._graph.createEdgeXYZXYZ(t.getXAtUncheckedPointIndex(i),t.getYAtUncheckedPointIndex(i),t.getZAtUncheckedPointIndex(i),0,t.getXAtUncheckedPointIndex(r),t.getYAtUncheckedPointIndex(r),t.getZAtUncheckedPointIndex(r),0)}primarySortKey(t){return this._options.primarySortDirection.dotProductXYZ(t.x,t.y,t.z)}static nodeCompareSortData(t,e){return t.sortData!==void 0&&e.sortData,t.sortData-e.sortData}static isIsolatedEnd(t){return t.vertexSuccessor===t}static isChainInteriorVertex(t){const e=t.vertexSuccessor;return e!==t&&e.vertexSuccessor===t}clusterAndMergeVerticesXYZ(){Vt.isolateAllEdges(this._graph);for(const i of this._graph.allHalfEdges)i.sortData=this.primarySortKey(i);const t=this._graph.allHalfEdges.slice();t.sort((i,s)=>Ke.nodeCompareSortData(i,s));const e=this._options.tolerance,n=t.length;for(let i=0;i<n;i++){const s=t[i],o=s.sortData+e;if(Ke.isIsolatedEnd(s))for(let a=i+1;a<n;a++){const c=t[a];if(Ke.isIsolatedEnd(c)){if(c.sortData,c.sortData>o)break;s.distanceXYZ(c)<=e&&(V.pinch(s,c),c.setXYZFrom(s))}}}}collectMaximalLineString3dFromStartNode(t,e,n){if(!e.isMaskSet(n)){const i=F.create();for(i.addPointXYZ(e.x,e.y,e.z);e.setMask(n),e.edgeMate.setMask(n),e=e.faceSuccessor,i.addPointXYZ(e.x,e.y,e.z),!(e.isMaskSet(n)||!Ke.isChainInteriorVertex(e)););t.push(i)}}collectMaximalGrowableXYXArrayFromStartNode(t,e,n){if(!e.isMaskSet(n)){const i=new W;for(i.pushXYZ(e.x,e.y,e.z);e.setMask(n),e.edgeMate.setMask(n),e=e.faceSuccessor,i.pushXYZ(e.x,e.y,e.z),!(e.isMaskSet(n)||!Ke.isChainInteriorVertex(e)););i.length>0&&t.push(i)}}exciseAndMarkSlingEdges(t){let e=0;for(const n of this._graph.allHalfEdges)if(n.distanceXYZ(n.edgeMate)<this._options.tolerance&&!n.isMaskSet(t)){const i=n.edgeMate;V.pinch(n,n.vertexPredecessor),V.pinch(i,i.vertexPredecessor),n.setMask(t),i.setMask(t),e++}return e}collectMaximalChains(){const t=[],e=M.VISITED;this.exciseAndMarkSlingEdges(e),this._graph.clearMask(e);for(const n of this._graph.allHalfEdges)Ke.isChainInteriorVertex(n)||this.collectMaximalLineString3dFromStartNode(t,n,e);for(const n of this._graph.allHalfEdges)this.collectMaximalLineString3dFromStartNode(t,n,e);return t}collectMaximalGrowableXYZArrays(){const t=[],e=M.VISITED;this.exciseAndMarkSlingEdges(e),this._graph.clearMask(e);for(const n of this._graph.allHalfEdges)Ke.isChainInteriorVertex(n)||this.collectMaximalGrowableXYXArrayFromStartNode(t,n,e);for(const n of this._graph.allHalfEdges)this.collectMaximalGrowableXYXArrayFromStartNode(t,n,e);return t}}class fa{constructor(){this._unmatchedEdges=new Map,this._graph=new be,this._halfEdgesAroundCurrentLoop=[]}_unmatchedEdges;_graph;get graph(){return this._graph}_halfEdgesAroundCurrentLoop;indexPairToString(t,e){return`${t.toString()},${e.toString()}`}insertLoop(t,e){const n=t.length;if(n>2){let i=t[n-1];this._halfEdgesAroundCurrentLoop.length=0;for(const r of t){const o=this.indexPairToString(i,r),a=this._unmatchedEdges.get(o);if(a===void 0){const c=this.indexPairToString(r,i),l=this._graph.createEdgeIdId(i,r);e!==void 0&&e(l),this._unmatchedEdges.set(c,l.edgeMate),this._halfEdgesAroundCurrentLoop.push(l),l.edgeMate.setMask(M.EXTERIOR)}else this._halfEdgesAroundCurrentLoop.push(a),a.clearMask(M.EXTERIOR);i=r}let s=this._halfEdgesAroundCurrentLoop[this._halfEdgesAroundCurrentLoop.length-1];for(const r of this._halfEdgesAroundCurrentLoop){const o=s.faceSuccessor;V.pinch(r,o),s=r}return this._halfEdgesAroundCurrentLoop[0]}}}class kc{positiveSum;numPositive;negativeSum;numNegative;numZero;largestPositiveItem;largestNegativeItem;largestPositiveValue;largestNegativeValue;negativeItemArray;zeroItemArray;positiveItemArray;constructor(t){this.positiveSum=this.negativeSum=0,this.numPositive=this.numNegative=this.numZero=0,this.largestPositiveValue=this.largestNegativeValue=0,t&&(this.negativeItemArray=[],this.positiveItemArray=[],this.zeroItemArray=[])}announceItem(t,e){e<0?(this.numNegative++,this.negativeSum+=e,this.negativeItemArray&&this.negativeItemArray.push(t),e<this.largestNegativeValue&&(this.largestNegativeValue=e,this.largestNegativeItem=t)):e>0?(this.numPositive++,this.positiveSum+=e,this.positiveItemArray&&this.positiveItemArray.push(t),e>this.largestPositiveValue&&(this.largestPositiveValue=e,this.largestPositiveItem=t)):(this.numZero++,this.zeroItemArray&&this.zeroItemArray.push(t))}}class Fc{_targetMask;_targetValue;constructor(t,e=!0){this._targetMask=t,this._targetValue=e}testEdge(t){return t.isMaskSet(this._targetMask)===this._targetValue}}let On=class Fn{static signedFaceArea(t){return t.signedFaceArea()}static collectFaceAreaSummary(t,e=!1,n=i=>Fn.signedFaceArea(i)){const i=new kc(e);let s;t instanceof be?s=t.collectFaceLoops():s=t;for(const r of s){const o=n(r);i.announceItem(r,o)}return i}static findMinimumAreaFace(t,e){return Fn.collectFaceAreaSummary(t,!1,e).largestNegativeItem}static isTriangulatedCCW(t,e=!0,n=0){let i;t instanceof be?i=t.collectFaceLoops():i=t;let s=0,r=0;for(const o of i){const a=o.countEdgesAroundFace();if(a>=3){if(o.signedFaceArea()>0){if(a>3&&(r++,r>n))return!1}else if(s++,s>1&&!e)return!1}}return!0}static pushAndMaskAllNodesInFace(t,e,n,i){i.push(t),t.collectAroundFace(s=>{s.setMask(e),n.push(s)})}static parityFloodFromSeed(t,e,n,i){const s=[];if(t.isMaskSet(e))return s;const r=i|e,o=[];for(Fn.pushAndMaskAllNodesInFace(t,r,o,s);o.length>0;){const a=o.pop(),c=a.edgeMate;if(c&&!c.isMaskSet(e)){let l=a.isMaskSet(i);(!n||n.testEdge(a))&&(l=!l),Fn.pushAndMaskAllNodesInFace(c,l?r:e,o,s)}}return s}static correctParityInSingleComponent(t,e){const n=Fn.findMinimumAreaFace(e);if(n){if(!n.isMaskSet(t))for(const i of e)i.isMaskSet(t)?i.clearMaskAroundFace(t):i.setMaskAroundFace(t)}}static correctParityInComponentArrays(t,e){if(t!==M.NULL_MASK)for(const n of e)Fn.correctParityInSingleComponent(t,n)}static collectConnectedComponentsWithExteriorParityMasks(t,e,n=M.NULL_MASK){const i=[],s=M.VISITED,r=n|s;t.clearMask(r);for(const o of t.allHalfEdges)if(!o.isMaskSet(s)){const a=Fn.parityFloodFromSeed(o,s,e,n);i.push(a)}return Fn.correctParityInComponentArrays(n,i),i}static exploreComponent(t,e,n=M.EXTERIOR,i=1/0,s){i<=0&&(i=1/0);const r=e|n;let o=0;const a=[],c=s||[];for(a.push(t);a.length>0&&o<i;){const d=a.shift();d&&!d.isMaskSet(r)&&(c.push(d),++o,d.collectAroundFace(h=>{h.setMask(e);const g=h.vertexSuccessor;g.isMaskSet(r)||a.push(g)}))}if(a.length===0)return{faces:c,nextSeed:void 0};let l=a[0];for(const d of a)if(d.vertexSuccessor.isMaskSet(n)||d.edgeMate.isMaskSet(n)){l=d;break}return{faces:c,nextSeed:l}}static collectConnectedComponents(t,e=1/0,n=M.EXTERIOR){const i=[];t.countMask(n)===0&&(n=M.NULL_MASK);const s=M.VISITED;t.clearMask(s);const r=s|n,o=a=>{for(let c=a;c<t.countNodes();++c)if(!t.allHalfEdges[c].isMaskSet(r)&&t.allHalfEdges[c].edgeMate.isMaskSet(r)){a=c;break}return a};for(let a=0;a<t.countNodes();++a){if(t.allHalfEdges[a].isMaskSet(r))continue;const c=o(a);let l=t.allHalfEdges[c];do{const d=Fn.exploreComponent(l,s,n,e);l=d.nextSeed,d.faces.length>0&&i.push(d.faces)}while(l!==void 0);t.allHalfEdges[a].isMaskSet(s)||--a}return i}static pointInOrOnFaceXY(t,e,n){const i=new Qr(e,n);let s=t,r=t.faceSuccessor;for(;!i.tryStartEdge(s.x,s.y,r.x,r.y);s=r){if(r===t)return ct.createXX(r.x,r.faceSuccessor.x).containsX(e)?0:-1;r=s.faceSuccessor}let o=r.faceSuccessor;for(;;){if(!i.advance(o.x,o.y))return i.classifyCounts();if(o===r)break;o=o.faceSuccessor}return i.classifyCounts()}static collectExtendedBoundaryLoopFromSeed(t,e,n,i){let s=0;for(;!t.getMask(e)&&n(t);){i(t,s++),t.setMask(e);const r=t.faceSuccessor;let o=r;for(;;){if(o.getMask(e))return;if(n(o)){t=o;break}if(o=o.vertexPredecessor,o===r)break}}}static collectExtendedBoundaryLoopsInGraph(t,e){const n=[],i=t.grabMask(!0),s=o=>o.getMask(e)===0&&o.edgeMate.getMask(e)!==0,r=(o,a)=>{a===0&&n.push([]),n[n.length-1].push(o)};for(const o of t.allHalfEdges)this.collectExtendedBoundaryLoopFromSeed(o,i,s,r);return t.dropMask(i),n}};class Mc{static spaceTriangleAspectRatio(t,e,n){const s=.5*t.crossProductToPoints(e,n).magnitude(),r=t.distanceSquared(e)+e.distanceSquared(n)+n.distanceSquared(t);return f.safeDivideFraction(s,r,0)}static spaceQuadDiagonalAspectRatio(t,e,n,i){const s=this.spaceTriangleAspectRatio(t,e,n),r=this.spaceTriangleAspectRatio(t,n,i);return Math.max(s,r)}static triangulateGreedyEarCut(t,e){const n=nt.areaNormal(t),i=[],s=t.slice();for(gn.removeClosurePoint(s);s.length>2;){let r=-1,o=0,a=s.length-2,c=s.length-1,l;for(l=0;l<s.length;a=c,c=l,l++){const h=this.spaceTriangleAspectRatio(s[a],s[c],s[l]);s[a].crossProductToPoints(s[c],s[l]).dotProduct(n)>0&&h>r&&(r=h,o=a)}if(r<=0)return!1;a=o,c=(a+1)%s.length,l=(c+1)%s.length;const d=[];d.push(s[a],s[c],s[l]),s.splice(c,1),i.push(d)}return e(t,i),!0}static triangulateSimplestSpaceLoopGo(t,e,n){const i=re.countNonDuplicates(t);if(n!==void 0&&re.sumEdgeLengths(t,!0,i)>n||i<3)return!1;if(i===3)return this.spaceTriangleAspectRatio(t[0],t[1],t[2])===0?!1:(e(t,[t.slice()]),!0);if(i===4){const s=this.spaceQuadDiagonalAspectRatio(t[0],t[1],t[2],t[3]),r=this.spaceQuadDiagonalAspectRatio(t[1],t[2],t[3],t[0]);return s===0&&r===0?!1:s>r?(e(t,[[t[0],t[1],t[2]],[t[2],t[3],t[0]]]),!0):(e(t,[[t[0],t[1],t[3]],[t[3],t[1],t[2]]]),!0)}return this.triangulateGreedyEarCut(t,e)}static triangulateSimplestSpaceLoop(t,e,n){return t instanceof F?this.triangulateSimplestSpaceLoopGo(t.points,e,n):this.triangulateSimplestSpaceLoopGo(t,e,n)}}class ro{detailA;detailB;constructor(t,e){this.detailA=t,this.detailB=e}static create(t,e){return new ro(t,e)}}class $i{_facetIndex;_detail;_normal;_param;_color;constructor(t=-1,e){this._facetIndex=t,this._detail=e||Wi.create()}invalidate(t=!0){this._facetIndex=-1,t&&this._detail.invalidate(),this._normal=void 0,this._param=void 0,this._color=void 0}static create(t=-1,e,n){return n?n.invalidate(!1):n=new $i,n._facetIndex=t,e!==void 0&&n._detail!==e&&n._detail.copyContentsFrom(e),n}static createCapture(t,e){return new $i(t,e)}get facetIndex(){return this._facetIndex}get edgeCount(){return 3}get point(){return this._detail.world}get a(){return this._detail.a}get closestEdge(){return{startVertexIndex:this._detail.closestEdgeIndex,edgeParam:this._detail.closestEdgeParam}}get _isValid(){return this._facetIndex>=0}get isValid(){return this._isValid&&this._detail.isValid}get isConvex(){return!0}get isInsideOrOn(){return this._isValid&&this._detail.isInsideOrOn}get classify(){return this._detail.classify}clone(){const t=new $i;return t.copyContentsFrom(this),t}copyContentsFrom(t){this._facetIndex=t._facetIndex,this._detail.copyContentsFrom(t._detail),this._normal=t._normal?.clone(),this._param=t._param?.clone(),this._color=t._color}getNormal(t){if(this._detail.isValid&&this._normal===void 0&&t!==void 0){this._normal=P.create();const e=[this._detail.local.x,this._detail.local.y,this._detail.local.z];t.linearCombination(e,this._normal)}return this._normal}getParam(t){if(this._detail.isValid&&this._param===void 0&&t!==void 0){this._param=D.create();const e=[this._detail.local.x,this._detail.local.y,this._detail.local.z];t.linearCombination(e,this._param)}return this._param}getColor(t){if(this._detail.isValid&&this._color===void 0&&t!==void 0){const e=[this._detail.local.x,this._detail.local.y,this._detail.local.z];this._color=Pe.linearCombinationOfColors(t,e)}return this._color}getBarycentricCoordinates(){return[this._detail.local.x,this._detail.local.y,this._detail.local.z]}}class Ln{_facetIndex;_edgeCount;_detail;constructor(t=-1,e=0,n){this._facetIndex=t,this._edgeCount=e,this._detail=n||en.create()}invalidate(t=!0){this._facetIndex=-1,this._edgeCount=0,t&&this._detail.invalidate()}static create(t=-1,e=0,n,i){return i?i.invalidate(!1):i=new Ln,i._facetIndex=t,i._edgeCount=e,n!==void 0&&i._detail!==n&&i._detail.copyContentsFrom(n),i}static createCapture(t,e,n){return new Ln(t,e,n)}get facetIndex(){return this._facetIndex}get edgeCount(){return this._edgeCount}get point(){return this._detail.point}get a(){return this._detail.a}get closestEdge(){return{startVertexIndex:this._detail.closestEdgeIndex,edgeParam:this._detail.closestEdgeParam}}get _isValid(){return this._facetIndex>=0&&this._edgeCount>=3}get isValid(){return this._isValid&&this._detail.isValid}get isConvex(){return!1}get isInsideOrOn(){return this._isValid&&this._detail.isInsideOrOn}get classify(){return this._detail.code}clone(){const t=new Ln;return t.copyContentsFrom(this),t}copyContentsFrom(t){this._facetIndex=t._facetIndex,this._edgeCount=t._edgeCount,this._detail.copyContentsFrom(t._detail)}getNormal(){}getParam(){}getColor(){}getBarycentricCoordinates(){}}class ii extends Ln{_normal;_param;_color;_barycentricCoordinates;constructor(t=-1,e=0,n){super(t,e,n)}invalidate(t=!0){super.invalidate(t),this._normal=void 0,this._param=void 0,this._color=void 0,this._barycentricCoordinates=void 0}static create(t=-1,e=0,n,i){return i?i.invalidate(!1):i=new ii,super.create(t,e,n,i)}static createCapture(t,e,n){return new ii(t,e,n)}get isConvex(){return!0}clone(){const t=new ii;return t.copyContentsFrom(this),t}copyContentsFrom(t){super.copyContentsFrom(t),this._normal=t._normal?.clone(),this._param=t._param?.clone(),this._color=t._color,this._barycentricCoordinates=t._barycentricCoordinates?.slice()}getNormal(t,e,n=f.smallMetricDistance){if(this._detail.isValid&&this._normal===void 0&&t!==void 0){const i=this.getBarycentricCoordinates(e,n);i!==void 0&&(this._normal=P.create(),t.linearCombination(i,this._normal))}return this._normal}getParam(t,e,n=f.smallMetricDistance){if(this._detail.isValid&&this._param===void 0&&t!==void 0){const i=this.getBarycentricCoordinates(e,n);i!==void 0&&(this._param=D.create(),t.linearCombination(i,this._param))}return this._param}getColor(t,e,n=f.smallMetricDistance){if(this._detail.isValid&&this._color===void 0&&t!==void 0){const i=this.getBarycentricCoordinates(e,n);i!==void 0&&(this._color=Pe.linearCombinationOfColors(t,i))}return this._color}getBarycentricCoordinates(t,e=f.smallMetricDistance){return this._detail.isValid&&this._barycentricCoordinates===void 0&&t!==void 0&&(this._barycentricCoordinates=nt.convexBarycentricCoordinates(t,this._detail.point,e)),this._barycentricCoordinates}}class Fe{_v;_a;constructor(t,e,n){this._v=[t,e],this._a=n}clone(){return new Fe(this._v[0],this._v[1],this._a)}get startVertex(){return this._v[0]}get endVertex(){return this._v[1]}get facetIndex(){return this._a}get isLowHigh(){return this._v[0]<this._v[1]}get lowVertex(){return this.isLowHigh?this._v[0]:this._v[1]}get highVertex(){return this.isLowHigh?this._v[1]:this._v[0]}static areSameEdge(t,e){return t._v[0]===e._v[0]&&t._v[1]===e._v[1]}static areDirectedPartners(t,e){return t._v[0]===e._v[1]&&t._v[1]===e._v[0]}static areUndirectedPartners(t,e){return this.areSameEdge(t,e)||this.areDirectedPartners(t,e)}static relativeOrientation(t,e){return this.areSameEdge(t,e)?1:this.areDirectedPartners(t,e)?-1:0}get isNullEdge(){return this._v[0]===this._v[1]}static lessThan(t,e){const n=t.lowVertex,i=e.lowVertex;if(n<i)return-1;if(i<n)return 1;const s=t.highVertex,r=e.highVertex;return s<r?-1:r<s?1:t.startVertex-e.startVertex}toJSON(){return[this._v[0],this._v[1],this._a]}static clusterToJSON(t){if(t instanceof Fe)return t.toJSON();const e=[];for(const n of t)e.push(n.toJSON())}static clusterArrayToJSON(t){const e=[];for(const n of t)e.push(Fe.clusterToJSON(n));return e}}class Qs{edges;constructor(){this.edges=[]}addEdge(t,e,n){const i=new Fe(t,e,n);return this.edges.push(i),i}addPath(t,e,n){if(t.length===0)return;const i=t.length-1;for(let s=0;s<i;s++)this.addEdge(t[s],t[s+1],e);n&&this.addEdge(t[i],t[0],e)}sort(){this.edges.sort((t,e)=>Fe.lessThan(t,e))}collectSortableEdgeCluster(t,e,n){if(n!==void 0&&e>t)if(e===t+1)n.push(this.edges[t]);else{const i=[];for(let s=t;s<e;s++)i.push(this.edges[s]);n.push(i)}}sortAndCollectClusters(t,e,n,i){this.sort(),t&&(t.length=0),e&&(e.length=0),n&&(n.length=0),i&&(i.length=0);const s=this.edges.length;let r;for(let o=0;o<s;o+=r){const a=this.edges[o];r=1;for(let c=o+1;c<s&&Fe.areUndirectedPartners(a,this.edges[c]);c++)r++;this.edges[o].isNullEdge?this.collectSortableEdgeCluster(o,o+r,n):r===2&&Fe.areDirectedPartners(a,this.edges[o+1])?this.collectSortableEdgeCluster(o,o+r,t):r===1?this.collectSortableEdgeCluster(o,o+1,e):this.collectSortableEdgeCluster(o,o+r,i)}}}class Ec{numPositive;numNegative;firstEdgeIndex;constructor(t){this.numPositive=this.numNegative=0,this.firstEdgeIndex=t}recordOrientation(t){t>0?this.numPositive++:t<0&&this.numNegative++}}class si{_edges;_edgeToPartnerEdge;_edgeToEdgeInComponent;_facetToFirstEdgeInComponent;_facetOrientation;_components;_visitor;_mesh;constructor(t){this._visitor=t.createVisitor(1),this._edges=St.createIndexedEdges(this._visitor),this._edgeToPartnerEdge=[],this._edgeToEdgeInComponent=[],this._facetToFirstEdgeInComponent=[],this._facetOrientation=[],this._components=[],this._mesh=t}edgeIdToFacetOrientation(t){const e=this._edges.edges[t].facetIndex;return this._facetOrientation[e]}setupUnoriented(){this._edges.sort();const t=this._edges.edges;let e=-1;const n=this._edges.edges.length;for(let i=0;i<n;i++){const s=this._edges.edges[i].facetIndex;s>e&&(e=s),this._edgeToEdgeInComponent.push(i),this._edgeToPartnerEdge.push(i)}for(let i=0;i<=e;i++)this._facetToFirstEdgeInComponent.push(-1),this._facetOrientation.push(0);for(let i=0;i<n;i++){const s=this._edges.edges[i].facetIndex,r=this._facetToFirstEdgeInComponent[s];r===-1?this._facetToFirstEdgeInComponent[s]=i:si.swapEntries(this._edgeToEdgeInComponent,i,r)}for(let i=0;i<n;i++){let s=i+1;for(;s<n&&Fe.areUndirectedPartners(t[i],t[s]);)si.swapEntries(this._edgeToPartnerEdge,i,s),s++;if(s>i+2)return!1}return!0}recordFacetInComponent(t,e){const n=this._components[this._components.length-1];this._facetOrientation[t]=e,n.recordOrientation(e)}initializeComponent(t){const e=this._edges.edges[t].facetIndex;this._components.push(new Ec(t)),this.recordFacetInComponent(e,1)}_workArray=[];pushFacetEdgesOnStack(t,e){si.extractCyclicIndices(this._edgeToEdgeInComponent,t,this._workArray);for(const n of this._workArray)e.push(n)}doFlood(){const t=[],e=this._edges.edges,n=e.length,i=[];for(let s=0;s<n;s++)if(this.edgeIdToFacetOrientation(s)===0){t.length=0,this.initializeComponent(s),this.pushFacetEdgesOnStack(s,t);let r;for(;(r=t.pop())!==void 0;){const o=e[r].facetIndex,a=this._facetOrientation[o];si.extractCyclicIndices(this._edgeToPartnerEdge,r,i);for(const c of i)if(c!==r){const l=e[c].facetIndex,d=this._facetOrientation[l];if(d===0){const h=Fe.areDirectedPartners(e[r],e[c])?a:-a;this.recordFacetInComponent(l,h),this.pushFacetEdgesOnStack(c,t),si.swapEntries(this._edgeToEdgeInComponent,r,c)}else if(Fe.relativeOrientation(e[r],e[c])*a*d>0)return!1}}}return!0}doFacetReversals(){let t=0;for(this._visitor.reset();this._visitor.moveToNextFacet();){const e=this._visitor.currentReadIndex();this._facetOrientation[e]<0&&(t++,this._mesh.reverseSingleFacet(e))}return t}static doFixup(t){const e=new si(t);if(!e.setupUnoriented())return!1;const n=e.doFlood();return n&&e.doFacetReversals(),n}static swapEntries(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}static extractCyclicIndices(t,e,n){n.length=0;let i=e;do n.push(i),i=t[i];while(i!==e)}}class ga{constructor(t,e,n){this.index=t,this.area=e,this.normal=n}index;area;normal;addWeightedNormal(t,e){this.area+=t,this.normal.addScaledInPlace(e,t)}divideNormalByArea(){this.area>0,this.area>0&&this.normal.scaleInPlace(1/this.area)}}class ji{constructor(t,e,n){this.facetData=t,this.sectorClusterData=void 0,this.sectorIndex=e,this.vertexIndex=n}facetData;sectorIndex;vertexIndex;sectorClusterData;static cbSectorSort(t,e){return t.sectorIndex-e.sectorIndex}static cbVertexSort(t,e){return t.vertexIndex-e.vertexIndex}static pushToArray(t,e,n,i){t.push(new ji(e,n,i))}}class ma{static buildFastAverageNormals(t,e){const n=t.createVisitor(0),i=P.create(0,0,1),s=f.smallMetricDistanceSquared,r=[];let o=0,a=0;for(;n.moveToNextFacet();){let h=nt.areaNormalGo(n.point),g=0;h?(g=h.magnitude(),g<s?(h.setFromVector3d(i),g=0):h.scaleInPlace(1/g)):(h=i.clone(),g=0);const m=new ga(o++,g,h);for(let p=0;p<n.pointCount;p++)ji.pushToArray(r,m,a++,n.clientPointIndex(p))}r.sort((h,g)=>ji.cbVertexSort(h,g));const c=[];let l=e.radians;l<1e-4&&(l=1e-4);let d=0;for(let h=0;h<r.length;h++){const g=r[h],m=g.vertexIndex,p=g.facetData;if(g.sectorClusterData===void 0){const x=new ga(d++,0,P.createZero());c.push(x);for(let _=h;_<r.length;_++){const I=r[_];if(I.vertexIndex!==m)break;I.facetData.normal.angleTo(p.normal).radians>l||I.sectorClusterData===void 0&&(x.addWeightedNormal(1,I.facetData.normal),I.sectorClusterData=x)}}}r.sort((h,g)=>ji.cbSectorSort(h,g)),t.data.normalIndex=[],t.data.normal=new W(r.length);for(const h of c)h.divideNormalByArea(),h.index=t.data.normal.length,t.data.normal.push(h.normal);for(const h of r)h.sectorClusterData,h.sectorClusterData&&t.data.normalIndex.push(h.sectorClusterData.index)}static buildPerFaceNormals(t){const e=t.createVisitor(0),n=P.create(0,0,1),i=P.create(0,0,1),s=new W(t.faceCount),r=[];for(;e.moveToNextFacet();){const o=s.length;nt.unitNormal(e.point,n)?s.push(n):s.push(i);for(let a=0;a<e.pointCount;a++)r.push(o)}t.data.normalIndex=r,t.data.normal=s}}function $s(u){return u===void 0?!1:u}class Rc{constructor(){this.numActiveSectors=0,this.numInactiveSectors=0,this.averageNormal=P.create(),this.radiansSum=0,this.maxDeviationRadiansFromAverage=0}clear(){this.numActiveSectors=0,this.numInactiveSectors=0,this.averageNormal.setZero(),this.radiansSum=0,this.maxDeviationRadiansFromAverage=0}numActiveSectors;numInactiveSectors;averageNormal;maxDeviationRadiansFromAverage;radiansSum;accumulateNormal(t,e,n){if(t.isMaskSet(n))this.numInactiveSectors++;else{const i=V.sectorSweepRadiansXYZ(t,e);this.averageNormal.addScaledInPlace(e,i),this.radiansSum+=i,this.numActiveSectors++}}finishNormalAveraging(){return!!(this.numActiveSectors>0&&this.averageNormal.normalizeInPlace())}recordDeviation(t,e){if(e){const n=this.averageNormal.radiansTo(t);this.maxDeviationRadiansFromAverage=Math.max(Math.abs(this.maxDeviationRadiansFromAverage),n)}}get maxDeviationRadians(){return this.maxDeviationRadiansFromAverage}}function bc(u){_t.stringDebugFunction!==void 0&&(_t.stringDebugFunction(` Sector xyz ${u.xyz.x},${u.xyz.y},${u.xyz.z} `),_t.stringDebugFunction(` normal ${u.normal.x},${u.normal.y},${u.normal.z} `))}class oo{constructor(t,e){this.facetIndex=t,this.facetNormal=e}facetIndex;facetNormal}class he{constructor(t,e){this.xyz=e,this.normal=t,this.count=0}normal;xyz;count;static edgeHasLargeExteriorAngleBetweenNormals(t,e,n,i,s=Math.PI*.5){const r=t.edgeTag,a=t.edgeMate.edgeTag;if(r!==void 0&&a!==void 0){t.vectorToFaceSuccessor(e);const c=r.normal.signedRadiansTo(a.normal,e);if(f.split3WaySign(i,-1,1,1)*c>=s&&(P.createAdd2Scaled(r.normal,1,a.normal,1,n),n.normalizeInPlace()))return!0}return!1}static almostEqualNormals(t,e,n=f.smallAngleRadians){return t.normal.radiansTo(e.normal)<=n}static radiansBetweenNormals(t,e){return t.normal.radiansTo(e.normal)}setOffsetPointAtDistanceAtHalfEdge(t,e){t.getPoint3d(this.xyz),this.xyz.addScaledInPlace(this.normal,e)}static setXYZAtHalfEdge(t,e){const n=t.edgeTag;n!==void 0&&e!==void 0&&n.xyz.set(e.x,e.y,e.z)}setXYAndZ(t){this.xyz.set(t.x,t.y,t.z)}static setNormalAtHalfEdge(t,e,n){const i=t.edgeTag;i!==void 0&&(i.normal.set(e.x,e.y,e.z),n!==void 0&&i.setOffsetPointAtDistanceAtHalfEdge(t,n))}static sweepRadiansAroundNormal(t,e){const n=t.edgeTag,i=t.vertexSuccessor.edgeTag;if(n!==void 0&&i!==void 0)return n.normal.planarRadiansTo(i.normal,e)}static getSectorPointAtHalfEdge(t,e,n){const i=t.edgeTag;return i!==void 0?(e!==void 0&&e.setFromPoint3d(i.xyz),n!==void 0&&n.push(i.xyz),!0):!1}static pushXYZ(t,e){const n=e.edgeTag;return n!==void 0&&t.push(n.xyz),n}static accumulateScaledNormalAtHalfEdge(t,e,n){const i=t.edgeTag;i!==void 0&&n.addScaledInPlace(i.normal,e)}}class _t{constructor(t,e,n){this._basePolyface=t,this._baseGraph=e,this._breakMaskA=e.grabMask(),this._breakMaskB=e.grabMask(),this._insideOfChamferFace=e.grabMask(),this._outsideOfChamferFace=e.grabMask(),this._insideChamferSling=e.grabMask(),this._outsideEndOfChamferFace=e.grabMask(),this._exteriorMask=M.EXTERIOR,this._offsetCoordinatesReassigned=e.grabMask(),this._smoothRadiansBetweenNormals=n.smoothSingleAngleBetweenNormals.radians,this._chamferTurnRadians=n.chamferAngleBetweenNormals.radians,this._smoothAccumulatedRadiansBetweenNormals=n.smoothAccumulatedAngleBetweenNormals.radians}_basePolyface;_baseGraph;get exteriorMask(){return this._exteriorMask}_exteriorMask;_offsetCoordinatesReassigned;get breakMaskA(){return this._breakMaskA}_breakMaskA;get breakMaskB(){return this._breakMaskB}_breakMaskB;get insideOfChamferFace(){return this._insideOfChamferFace}_insideOfChamferFace;get outsideOfChamferFace(){return this._outsideOfChamferFace}_outsideOfChamferFace;get insideChamferSling(){return this._insideChamferSling}_insideChamferSling;get outsideEndOfChamferFace(){return this._outsideEndOfChamferFace}_outsideEndOfChamferFace;_smoothRadiansBetweenNormals;_smoothAccumulatedRadiansBetweenNormals;_chamferTurnRadians;static graphDebugFunction;static stringDebugFunction;applyFaceNormalOffsetsToSectorData(t){this._baseGraph.announceNodes((e,n)=>{const i=n.edgeTag;return i!==void 0&&i.setOffsetPointAtDistanceAtHalfEdge(n,t),!0})}static buildOffsetMeshWithEdgeChamfers(t,e,n,i){const s=this.buildBaseGraph(t);if(s!==void 0){const r=new _t(t,s,i);r.applyFaceNormalOffsetsToSectorData(n),_t.graphDebugFunction!==void 0&&_t.graphDebugFunction("BaseGraph",s,r._breakMaskA,r._breakMaskB);const o=i.outputSelector?i.outputSelector:{outputOffsetsFromFaces:!0,outputOffsetsFromEdges:!0,outputOffsetsFromVertices:!0};$s(o.outputOffsetsFromFacesBeforeChamfers)&&r.announceFacetsWithSectorCoordinatesAroundFaces(e),r.addChamferTopologyToAllEdges(i,n),r.computeOffsetFacetIntersections(n),_t.graphDebugFunction!==void 0&&_t.graphDebugFunction("after computeEdgeChamfers",s,r._breakMaskA,r._breakMaskB),$s(o.outputOffsetsFromFaces)&&r.announceFacetsWithSectorCoordinatesAroundFaces(e),$s(o.outputOffsetsFromEdges)&&r.announceFacetsWithSectorCoordinatesAroundEdges(e),$s(o.outputOffsetsFromVertices)&&r.announceFacetsWithSectorCoordinatesAroundVertices(e)}}announceSimpleOffsetFromFaces(t,e){const n=new W,i=y.create(),s=P.create(),r=o=>(o.getPoint3d(i),i.addInPlace(s),n.push(i),0);this._baseGraph.announceFaceLoops((o,a)=>{if(!a.isMaskSet(M.EXTERIOR)){const c=a.faceTag;s.setFromVector3d(c.facetNormal.direction),s.scaleInPlace(e),n.length=0,a.sumAroundFace(r),t.addPolygonGrowableXYZArray(n)}return!0})}announceFacetsWithSectorCoordinatesAroundFaces(t){const e=new W,n=i=>{const s=i.edgeTag;return s!==void 0&&e.push(s.xyz),0};this._baseGraph.announceFaceLoops((i,s)=>(s.isMaskSet(M.EXTERIOR)||(e.length=0,s.sumAroundFace(n),e.length>2&&t.addPolygonGrowableXYZArray(e)),!0))}countBits(t){let e=0,n=t;for(;n!==0;)n&1&&e++,n=n>>1;return e}announceFacetsWithSectorCoordinatesAroundEdges(t){const e=new W,n=f.smallMetricDistance,i=this._exteriorMask|this._outsideEndOfChamferFace|this._outsideOfChamferFace|this._insideOfChamferFace|this._insideChamferSling;this._baseGraph.announceEdges((s,r)=>{if(r.findMaskAroundEdge(this._exteriorMask)!==void 0)return!0;if(r.isMaskSet(i))return!0;{const o=r.faceSuccessor,a=r.edgeMate;if(!a.isMaskSet(i)){const c=a.faceSuccessor;e.clear(),he.getSectorPointAtHalfEdge(r,void 0,e),he.getSectorPointAtHalfEdge(o,void 0,e),he.getSectorPointAtHalfEdge(a,void 0,e),he.getSectorPointAtHalfEdge(c,void 0,e),te.compressInPlaceByShortEdgeLength(e,n),e.length>2&&t.addPolygonGrowableXYZArray(e)}}return!0})}getCoordinateString(t,e=!0,n=!1){return e?n?`${V.nodeToIdXYZString(t)} ==> ${V.nodeToIdXYZString(t.faceSuccessor)}`:`${V.nodeToIdXYZString(t)}`:n?`==> ${V.nodeToIdXYZString(t.faceSuccessor)}`:""}inspectMasks(t,e=!0,n=!1){return"[".concat(t.id.toString(),t.isMaskSet(this._exteriorMask)?"X":"",t.isMaskSet(this.breakMaskA)?"A":"",t.isMaskSet(this.breakMaskB)?"B":"",t.isMaskSet(this.insideChamferSling)?"(sling)":"",t.isMaskSet(this.insideOfChamferFace)?"(in chamfer)":"",t.isMaskSet(this.outsideEndOfChamferFace)?"(@sling)":"",t.isMaskSet(this.outsideOfChamferFace)?"(@chamfer)":"",this.getCoordinateString(t,e,n),"]")}announceFacetsWithSectorCoordinatesAroundVertices(t){const e=new W,n=f.smallMetricDistance;this._baseGraph.announceVertexLoops((i,s)=>(s.findMaskAroundVertex(this._exteriorMask)||(e.length=0,s.sumAroundVertex(r=>(r.isMaskSet(this._insideChamferSling)||he.getSectorPointAtHalfEdge(r,void 0,e),0)),te.compressInPlaceByShortEdgeLength(e,n),e.length>2&&t.addPolygonGrowableXYZArray(e)),!0))}static buildBaseGraph(t){const e=new fa,n=t.createVisitor(),i=y.create(),s=y.create();for(n.reset();n.moveToNextFacet();){const r=nt.centroidAreaNormal(n.point);if(r!==void 0){const o=e.insertLoop(n.pointIndex,c=>{const l=c.edgeMate;t.data.getPoint(c.i,i),c.setXYZ(i),t.data.getPoint(l.i,s),l.setXYZ(s)}),a=new oo(n.currentReadIndex(),r);o!==void 0&&o.sumAroundFace(c=>(c.faceTag=a,c.edgeTag=new he(r.direction.clone(),c.getPoint3d()),0))}}return e.graph}setOffsetAtDistanceAroundVertex(t,e,n=!1){t.sumAroundVertex(i=>{const s=i.edgeTag;return s!==void 0&&(n&&this.isInsideChamferOrSling(t)||s.setOffsetPointAtDistanceAtHalfEdge(i,e)),0})}setOffsetXYAndZAroundVertex(t,e){t.sumAroundVertex(n=>{const i=n.edgeTag;return i!==void 0&&(i.setXYAndZ(e),n.setMask(this._offsetCoordinatesReassigned)),0})}announceNodeAndSectorPropertiesInSmoothSector(t,e){let n=0;for(let i=t;;i=i.vertexSuccessor){const s=i.edgeTag;if(s!==void 0&&(e(i,s),n++),i.isMaskSet(this._breakMaskB)||i.isMaskSet(this._exteriorMask)||i===t&&n===0)return n}}computeAverageNormalAndMaxDeviationAroundVertex(t,e){e.clear();const n=this._exteriorMask|this._insideChamferSling;if(t.sumAroundVertex(i=>{const s=i.edgeTag;return s&&e.accumulateNormal(i,s.normal,n),0}),!!e.finishNormalAveraging())return t.sumAroundVertex(i=>{const s=i.edgeTag;return s&&e.recordDeviation(s.normal,!i.isMaskSet(n)),0}),e.maxDeviationRadians}assignOffsetByAverageNormalAroundVertex(t,e,n,i){const s=this.computeAverageNormalAndMaxDeviationAroundVertex(t,n);return _t.stringDebugFunction&&(_t.stringDebugFunction(`XYZ ${V.nodeToIdXYZString(t)} Average Normal ${JSON.stringify(n.averageNormal.toJSON())}`),_t.stringDebugFunction(` angle ratio ${n.radiansSum/(2*Math.PI)} maxDeviation ${n.maxDeviationRadiansFromAverage}`)),s!==void 0&&s<=e?(t.sumAroundVertex(r=>(he.setNormalAtHalfEdge(r,n.averageNormal,i),0)),!0):!1}markBreakEdgesAndSaveAverageNormalsAroundVertex(t){t.clearMaskAroundVertex(this._breakMaskA),t.clearMaskAroundVertex(this._breakMaskB);const e=this._smoothRadiansBetweenNormals,n=this._smoothAccumulatedRadiansBetweenNormals;let i=0,s=t,r=0;do{const a=s.edgeMate,c=a.faceSuccessor;s.isMaskSet(this._exteriorMask)?a.isMaskSet(this._exteriorMask)||(c.setMask(this._breakMaskB),i++):s.isMaskSet(this._outsideOfChamferFace)?s.setMask(this._breakMaskA):s.isMaskSet(this._outsideEndOfChamferFace)?(s.setMask(this._breakMaskA),s.setMask(this._breakMaskB)):s.isMaskSet(this._insideChamferSling)||(s.isMaskSet(this._insideOfChamferFace)?(s.setMask(this._breakMaskA),s.setMask(this._breakMaskB),c.setMask(this._breakMaskB)):a.isMaskSet(this._exteriorMask)?(i++,s.setMask(this._breakMaskA)):he.almostEqualNormals(s.edgeTag,c.edgeTag,e)?r++:(s.setMask(this._breakMaskA),i++,c.setMask(this._breakMaskB))),s=s.vertexSuccessor}while(s!==t);_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` numSkip ${r} `),i===0&&(t.setMask(this._breakMaskA),t.vertexPredecessor.setMask(this._breakMaskB),i=1);const o=s.findMaskAroundVertex(this._breakMaskA);if(o!==void 0){s=o;do if(s.isMaskSet(this._breakMaskA)&&!s.isMaskSet(this._breakMaskB)){let a=0;do{const c=s.vertexSuccessor;a+=he.radiansBetweenNormals(s.edgeTag,c.edgeTag),a>n&&(s.setMask(this._breakMaskB),c.setMask(this._breakMaskA),i++,a=0),s=c}while(!s.isMaskSet(this._breakMaskB))}else s=s.vertexSuccessor;while(s!==o)}if(i>0&&o!==void 0){s=o;const a=P.create(),c=P.create(),l=P.create();a.setZero();do{if(s.isMaskSet(this._breakMaskA)&&!s.isMaskSet(this._breakMaskB)){let d=s;for(a.setZero();;){d.vectorToFaceSuccessor(c),d.vectorToFacePredecessor(l);let h=c.signedRadiansTo(l,d.faceTag.facetNormal.direction);if(h<0&&(h+=Math.PI*2),he.accumulateScaledNormalAtHalfEdge(d,h,a),d.isMaskSet(this._breakMaskB))break;d=d.vertexSuccessor}if(a.normalizeInPlace())for(d=s;he.setNormalAtHalfEdge(d,a),!d.isMaskSet(this._breakMaskB);)d=d.vertexSuccessor}s=s.vertexSuccessor}while(s!==o)}}compute3SectorIntersection(t,e,n,i){const s=t.edgeTag,r=e.edgeTag,o=n.edgeTag;return bt.intersect3Planes(s.xyz,s.normal,r.xyz,r.normal,o.xyz,o.normal,i)}compute3SectorIntersectionDebug(t,e,n,i){const s=t.edgeTag,r=e.edgeTag,o=n.edgeTag;if(_t.stringDebugFunction!==void 0){_t.stringDebugFunction(`compute3${this.inspectMasks(t)}${this.inspectMasks(e)}${this.inspectMasks(n)} `);for(const c of[s,r,o])bc(c)}const a=bt.intersect3Planes(s.xyz,s.normal,r.xyz,r.normal,o.xyz,o.normal,i);return _t.stringDebugFunction!==void 0&&(a===void 0?_t.stringDebugFunction(" NO INTERSECTION"):_t.stringDebugFunction(` ComputedVector ${a.x},${a.y},${a.z} `)),a}compute2SectorIntersection(t,e,n){const i=t.edgeTag,s=e.edgeTag,r=i.normal.crossProduct(s.normal);return bt.intersect3Planes(i.xyz,i.normal,s.xyz,s.normal,s.xyz,r,n)}addChamferTopologyToAllEdges(t,e){const n=[],i=t.chamferAngleBetweenNormals.radians,s=y.create(),r=P.create(),o=P.create(),a=P.create();this._baseGraph.announceEdges((c,l)=>(he.edgeHasLargeExteriorAngleBetweenNormals(l,r,a,e,i)&&n.push(l),!0));for(const c of n)if(he.edgeHasLargeExteriorAngleBetweenNormals(c,r,a,i)){const l=this._baseGraph.splitEdgeCreateSliverFace(c),d=l.facePredecessor,h=l.getPoint3d();h.addScaledInPlace(a,e);const g=O.createCapture(h,a.clone()),m=new oo(-1,g);let p=-1;for(const x of[l,d]){r.scale(p,o),x.getPoint3d(s),x.setMask(this._insideOfChamferFace),x.edgeMate.setMask(this._outsideOfChamferFace),x.faceTag=m;const _=this._baseGraph.splitEdge(void 0,s.x,s.y,s.z,x.i),I=_.edgeMate;_.setMask(this._outsideEndOfChamferFace),_.faceTag=m,I.setMask(this._insideChamferSling),V.pinch(x,_);const v=O.create(s,o),S=new oo(-1,v);I.faceTag=S,x.edgeTag=new he(a.clone(),h.clone()),_.edgeTag=new he(a.clone(),h.clone()),I.edgeTag=new he(o.clone(),s.clone());const w=this.compute3SectorIntersection(x,x.edgeMate,I),T=this.compute3SectorIntersection(_,_.vertexSuccessor,I);he.setXYZAtHalfEdge(x,w),he.setXYZAtHalfEdge(_,T),p*=-1}}}computeOffsetFacetIntersections(t){_t.stringDebugFunction!==void 0&&_t.stringDebugFunction("***** recompute intersections");const e=[],n=y.create(),i=y.create(),s=2*t,r=new Rc,o=A.degreesToRadians(25);this._baseGraph.announceVertexLoops((a,c)=>{let l=c.findMaskAroundVertex(this._outsideEndOfChamferFace);if(l===void 0&&(l=c.findMaskAroundVertex(this._breakMaskA)),l===void 0&&(l=c),_t.stringDebugFunction!==void 0){const d=_t.stringDebugFunction;d(""),d(` VERTEX LOOP ${JSON.stringify(l.getPoint3d().toJSON())} `),l.announceEdgesAroundVertex(h=>d(this.inspectMasks(h,!1,!0)))}if(this.assignOffsetByAverageNormalAroundVertex(l,o,r,t))return!0;if(this.markBreakEdgesAndSaveAverageNormalsAroundVertex(l),this.setOffsetAtDistanceAroundVertex(l,t,!0),l.collectMaskedEdgesAroundVertex(this._breakMaskA,!0,e),_t.stringDebugFunction!==void 0){_t.stringDebugFunction(` BREAK EDGES from ${this.inspectMasks(l,!0,!1)}`);for(const d of e)_t.stringDebugFunction(this.inspectMasks(d,!1,!0))}if(!(e.length<=1))if(e.length===2){const d=this.compute2SectorIntersection(e[0],e[1]);d!==void 0&&this.setOffsetXYAndZAroundVertex(l,d)}else if(e.length===3){_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` Vertex Update just ${e.length} `);const d=this.compute3SectorIntersection(e[0],e[1],e[2]);d!==void 0&&this.setOffsetXYAndZAroundVertex(l,d)}else{_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` Vertex Update breakEdges ${e.length} `),l.getPoint3d(n);for(let d=0;d<e.length;d++){const h=d,g=(h+1)%e.length,m=(g+1)%e.length;if(e[h].isMaskSet(this._outsideEndOfChamferFace)&&e[g].isMaskSet(this._outsideOfChamferFace)&&e[m].isMaskSet(this._insideOfChamferFace)){_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` ChamferChamfer Fixup ${this.inspectMasks(e[h])} ${this.inspectMasks(e[g])} ${this.inspectMasks(e[m])} `);const p=this.compute3SectorIntersection(e[h],e[g],e[m]);if(p!==void 0){for(const x of[h,g,m])this.announceNodeAndSectorPropertiesInSmoothSector(e[x],(_,I)=>{I.setXYAndZ(p),_.setMask(this._offsetCoordinatesReassigned)});d+=2}}}for(let d=0;d<e.length;d++){const h=d,g=(h+1)%e.length;this.isInsideSling(e[h],e[g])||(!this.isOffsetAssigned(e[h])&&e[g].isMaskSet(this.insideOfChamferFace)?this.transferXYZFromNodeToSmoothSector(e[g],e[h],"push left from chamfer",i):!this.isOffsetAssigned(e[g])&&e[h].isMaskSet(this.outsideEndOfChamferFace)&&this.transferXYZFromNodeToSmoothSector(e[h],e[g],"push right from chamfer",i))}for(let d=0;d<e.length;d++){const h=d,g=(h+1)%e.length,m=(g+1)%e.length;if(this.isInsideSling(e[h],e[g],e[m])||this.isOffsetAssigned(e[g]))continue;_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` Intersection Fixup ${this.inspectMasks(e[h])} ${this.inspectMasks(e[g])} ${this.inspectMasks(e[m])} `);const p=this.compute3SectorIntersection(e[h],e[g],e[m]);p!==void 0&&n.distance(p)<s&&this.announceNodeAndSectorPropertiesInSmoothSector(e[g],(x,_)=>{_.setXYAndZ(p),x.setMask(this._offsetCoordinatesReassigned)})}}if(_t.stringDebugFunction!==void 0){const d=l.countMaskAroundVertex(this._offsetCoordinatesReassigned,!1),g=` **** Vertex offset mask counts(TRUE ${l.countMaskAroundVertex(this._offsetCoordinatesReassigned,!0)})(FALSE ${d})`;_t.stringDebugFunction(g)}return!0})}isInsideSling(t,e,n){return t.isMaskSet(this._insideChamferSling)||e!==void 0&&e.isMaskSet(this._insideChamferSling)||n!==void 0&&n.isMaskSet(this._insideChamferSling)}isInsideChamferOrSling(t){return t.isMaskSet(this._insideChamferSling)||t.isMaskSet(this._insideOfChamferFace)||t.isMaskSet(this._outsideEndOfChamferFace)}isOffsetAssigned(t,e,n){return t.isMaskSet(this._offsetCoordinatesReassigned)||e!==void 0&&e.isMaskSet(this._offsetCoordinatesReassigned)||n!==void 0&&n.isMaskSet(this._offsetCoordinatesReassigned)}transferXYZFromNodeToSmoothSector(t,e,n,i){_t.stringDebugFunction!==void 0&&_t.stringDebugFunction(` ${n} ${this.inspectMasks(t)} to ${this.inspectMasks(e)}} `),he.getSectorPointAtHalfEdge(t,i,void 0),this.announceNodeAndSectorPropertiesInSmoothSector(e,(s,r)=>{r.setXYAndZ(i),s.setMask(this._offsetCoordinatesReassigned)})}}class js{_spacePoints;_spacePointsRange;_numSpacePoints;constructor(t){this._spacePoints=t,this._spacePointsRange=t.getRange(),this._numSpacePoints=this._spacePoints.length}static create(t){if(t.length>1)return new js(t)}_segmentPoint0=y.create();_segmentPoint1=y.create();_localSegmentPoint0=y.create();_localSegmentPoint1=y.create();_clipFractions=qt.create(0,1);_localFrame=X.createIdentity();_polygonRange=J.create();projectToPolygon(t,e,n,i){t.setRange(this._polygonRange);let s=0;if(!this._polygonRange.intersectsRangeXY(this._spacePointsRange))return s;for(let r=1;r+1<t.length;r++){s++;const o=t.fillLocalXYTriangleFrame(0,r,r+1,this._localFrame);if(o){for(let a=1;a<this._numSpacePoints;a++)if(s++,this._spacePoints.getPoint3dAtCheckedPointIndex(a-1,this._segmentPoint0),this._spacePoints.getPoint3dAtCheckedPointIndex(a,this._segmentPoint1),o.multiplyInversePoint3d(this._segmentPoint0,this._localSegmentPoint0),o.multiplyInversePoint3d(this._segmentPoint1,this._localSegmentPoint1),this._clipFractions.set(0,1),this._clipFractions.clipBy01FunctionValuesPositive(this._localSegmentPoint0.x,this._localSegmentPoint1.x)&&this._clipFractions.clipBy01FunctionValuesPositive(this._localSegmentPoint0.y,this._localSegmentPoint1.y)&&this._clipFractions.clipBy01FunctionValuesPositive(1-this._localSegmentPoint0.x-this._localSegmentPoint0.y,1-this._localSegmentPoint1.x-this._localSegmentPoint1.y)){s++;const c=this._localSegmentPoint0.interpolate(this._clipFractions.x0,this._localSegmentPoint1),l=this._localSegmentPoint0.interpolate(this._clipFractions.x1,this._localSegmentPoint1),d=this._localFrame.multiplyPoint3d(c),h=this._localFrame.multiplyPoint3d(l),g=this._localFrame.multiplyXYZ(c.x,c.y,0),m=this._localFrame.multiplyXYZ(l.x,l.y,0),p=f.inverseInterpolate01(this._localSegmentPoint0.z,this._localSegmentPoint1.z);if(p!==void 0&&p>this._clipFractions.x0&&p<this._clipFractions.x1){s++;const x=this._segmentPoint0.interpolate(p,this._segmentPoint1),_=x.clone();e(this._spacePoints,a-1,n,i,[d,x,g],2,1),e(this._spacePoints,a-1,n,i,[h,_,m],1,2)}else this._localSegmentPoint0.z>0?e(this._spacePoints,a-1,n,i,[d,h,m,g],3,2):e(this._spacePoints,a-1,n,i,[h,d,g,m],2,3)}}}return s}}class ts{edgePlane;clip;_crossingPoints;constructor(t,e){this.edgePlane=t,this.clip=e,this._crossingPoints=[]}static createPointPointSweep(t,e,n){const i=P.createStartEnd(t,e),s=i.fractionOfProjectionToVector(n),r=i.plusScaled(n,-s),o=H.createNormalAndPoint(r,t),a=H.createNormalAndPoint(r,e),c=H.createOriginAndVectors(t,i,n);if(o!==void 0&&a!==void 0&&c!==void 0){a.negateInPlace();const l=vt.createPlanes([o,a]);return new ts(c,l)}}processPolygon(t,e){this._crossingPoints.length=0,Array.isArray(t)?ol.polygonPlaneCrossings(this.edgePlane,t,this._crossingPoints):nn.polygonPlaneCrossings(this.edgePlane,t,this._crossingPoints),this._crossingPoints.length===2&&this.clip.announceClippedSegmentIntervals(0,1,this._crossingPoints[0],this._crossingPoints[1],(n,i)=>{e(this._crossingPoints[0].interpolate(n,this._crossingPoints[1]),this._crossingPoints[0].interpolate(i,this._crossingPoints[1]))})}}class ao{_edgeClippers;_localToWorld;_worldToLocal;_localRange;constructor(t,e){this._edgeClippers=t,e!==void 0&&(this._localToWorld=e.localToWorld,this._worldToLocal=e.worldToLocal,this._localRange=e.localRange)}static create(t,e){if(e===void 0&&(e=P.create(0,0,1)),t.length>1){const n=y.createZero(),i=y.createZero(),s=[];t.getPoint3dAtUncheckedPointIndex(0,n);const r=X.createRigidFromOriginAndVector(n,e)??X.createIdentity(),o=r.inverse(),a=t.getRange(o);for(let c=1;c<t.length;c++){t.getPoint3dAtUncheckedPointIndex(c,i);const l=ts.createPointPointSweep(n,i,e);l!==void 0&&(n.setFrom(i),s.push(l))}return new ao(s,{localToWorld:r,worldToLocal:o,localRange:a})}}processPolygon(t,e){if(!(this._worldToLocal!==void 0&&this._localRange!==void 0&&!J.createTransformedArray(this._worldToLocal,t).intersectsRangeXY(this._localRange)))for(const n of this._edgeClippers)n.processPolygon(t,e)}}class co{_range;_numXEdge;_numYEdge;_data;constructor(t,e,n){this._range=t,this._numXEdge=Math.max(e,1),this._numYEdge=Math.max(n,1),this._data=[];for(let i=0;i<n;i++){const s=[];for(let r=0;r<e;r++)s.push(void 0);this._data.push(s)}}get numXEdge(){return this._numXEdge}get numYEdge(){return this._numYEdge}xIndex(t){const e=(t-this._range.low.x)/(this._range.high.x-this._range.low.x),n=Math.floor(e*this._numXEdge);return n<0?0:n>this._numXEdge-1?this._numXEdge-1:n}yIndex(t){const e=(t-this._range.low.y)/(this._range.high.y-this._range.low.y),n=Math.floor(e*this._numYEdge);return n<0?0:n>this._numYEdge-1?this._numYEdge-1:n}static createWithEstimatedCounts(t,e,n){if(t.low.x>=t.high.x||t.low.y>=t.high.y)return;const i=Rt.createXYXY(t.low.x,t.low.y,t.high.x,t.high.y),s=i.xLength(),r=i.yLength();let o,a;return r>s?(a=Math.ceil(Math.sqrt(r*e/(n*s))),o=Math.ceil(e/a)):(o=Math.ceil(Math.sqrt(s*e/(n*r))),a=Math.ceil(e/(o*n))),new co(i,o,a)}addDataAtXY(t,e,n){const i=this.xIndex(t),s=this.yIndex(e);let r=this._data[s][i];r||(r=[],this._data[s][i]=r),r.push(n)}getDataAtXY(t,e){const n=this.xIndex(t),i=this.yIndex(e);return this._data[i][n]}getDataAtIndex(t,e){if(!(t<0)&&!(t>=this._numXEdge)&&!(e<0)&&!(e>=this._numYEdge))return this._data[e][t]}isValidIndex(t,e){return!(t<0||t>=this._numXEdge||e<0||e>=this._numYEdge)}}class lo{_points;_buckets;get indexGrid(){return this._buckets}constructor(t,e){this._points=t,this._buckets=e}static create(t,e){const n=t.length;if(n<1)return;const i=t.getRange();i.expandInPlace(f.smallMetricDistance*1e3);const s=co.createWithEstimatedCounts(i,n,e);if(s===void 0)return;const r=new lo(t,s);for(let o=0;o<n;o++)s.addDataAtXY(t.getXAtUncheckedPointIndex(o),t.getYAtUncheckedPointIndex(o),o);return r}announcePointsInRange(t,e){const n=this._buckets.xIndex(t.low.x),i=this._buckets.xIndex(t.high.x),s=this._buckets.yIndex(t.low.y),r=this._buckets.yIndex(t.high.y),o=this._points.length;for(let a=n;a<=i;a++)for(let c=s;c<=r;c++){const l=this._buckets.getDataAtIndex(a,c);if(l!==void 0){for(const d of l)if(d<o){const h=this._points.getXAtUncheckedPointIndex(d),g=this._points.getYAtUncheckedPointIndex(d),m=this._points.getZAtUncheckedPointIndex(d);if(t.containsXY(h,g)&&!e(d,h,g,m))return}}}}}class es{_count;_sumX;_sumXX;_minMax;_origin;constructor(t=0){this._minMax=ct.createNull(),this._count=this._sumX=this._sumXX=0,this._origin=t}get count(){return this._count}get mean(){return this._count>0?this._sumX/this._count:0}get meanSquare(){return this._count>0?this._sumXX/this._count:0}get minMax(){return this._minMax.clone()}get standardDeviation(){if(this._count<1)return 0;const t=this.mean,e=this._sumXX,n=this._sumX;return Math.sqrt((e-2*t*n+this._count*t*t)/this._count)}clearSums(){this._count=this._sumX=this._sumXX=0,this._minMax.setNull()}get origin(){return this._origin}setOrigin(t){this._origin=t}shiftOriginAndSums(t){const e=t-this._origin;this._origin=t,this._sumXX=this._sumXX-2*e*this._sumX+this._count*e*e,this._sumX=this._sumX-this._count*e,this._minMax.cloneTranslated(-e,this._minMax)}accumulate(t){t=t-this._origin,this._count+=1,this._sumX+=t,this._sumXX+=t*t,this._minMax.extendX(t)}accumulateArray(t){for(const e of t)this.accumulate(e)}clone(t){return t||(t=new es),this._minMax.clone(t._minMax),t._count=this._count,t._origin=this._origin,t._sumX=this._sumX,t._sumXX=this._sumXX,t}isAlmostEqual(t){return f.isAlmostEqualNumber(this._sumX,t._sumX)&&f.isAlmostEqualNumber(this._sumXX,t._sumXX)&&f.isAlmostEqualNumber(this._origin,t._origin)&&this._count===t._count&&this._minMax.isAlmostEqual(t._minMax)}}class Dc{range;xSums;ySums;zSums;constructor(){this.range=J.createNull(),this.xSums=new es,this.ySums=new es,this.zSums=new es,this._workRange=J.createNull()}_workRange;accumulateGrowableXYZArrayRange(t){t.setRange(this._workRange),this.range.extendRange(this._workRange),this.xSums.accumulate(this._workRange.xLength()),this.ySums.accumulate(this._workRange.yLength()),this.zSums.accumulate(this._workRange.zLength())}}class tr{vectorToEye;collectOnForwardFacets;collectOnSideFacets;collectOnRearFacets;sideAngle;assembleChains;searcher;constructor(t,e,n,i,s,r,o){this.vectorToEye=t,this.sideAngle=e,this.assembleChains=n,this.collectOnForwardFacets=i,this.collectOnSideFacets=s,this.collectOnRearFacets=r,this.searcher=o}static create(t,e,n,i,s,r,o){return new tr(!t||o?P.unitZ():t.clone(),e?.clone()??A.createRadians(f.smallAngleRadians),n??!0,i??!0,s??!0,r??!0,o)}get collectAll(){return this.collectOnForwardFacets&&this.collectOnSideFacets&&this.collectOnRearFacets}collectFromThisFacetNormal(t){return t===void 0?!1:t.angleFromPerpendicular(this.vectorToEye).isMagnitudeLessThanOrEqual(this.sideAngle)?this.collectOnSideFacets:t.dotProduct(this.vectorToEye)>0?this.collectOnForwardFacets:this.collectOnRearFacets}}class ho{smoothSingleAngleBetweenNormals;smoothAccumulatedAngleBetweenNormals;chamferAngleBetweenNormals;outputSelector;constructor(t=A.createDegrees(25),e=A.createDegrees(60),n=A.createDegrees(90)){this.smoothSingleAngleBetweenNormals=t.clone(),this.smoothAccumulatedAngleBetweenNormals=e.clone(),this.chamferAngleBetweenNormals=n.clone()}static create(t=A.createDegrees(25),e=A.createDegrees(60),n=A.createDegrees(120)){const i=t.clone(),s=e.clone(),r=n.clone();return i.degrees<1&&s.setDegrees(1),s.degrees<1&&s.setDegrees(1),s.degrees<15&&s.setDegrees(15),new ho(i,s,r)}}var ns;(function(u){u[u.SelectNone=0]="SelectNone",u[u.SelectAny=1]="SelectAny",u[u.SelectAll=2]="SelectAll",u[u.SelectOneByParity=3]="SelectOneByParity"})(ns||(ns={}));class St{static visitorToLoop(t){const e=F.createPoints(t.point.getPoint3dArray());return tt.create(e)}static indexedPolyfaceToLoops(t){const e=Ee.create(),n=t.createVisitor(1);for(;n.moveToNextFacet();){const i=St.visitorToLoop(n);e.tryAddChild(i)}return e}static sumFacetAreas(t,e){let n=0;t instanceof It?t=t.createVisitor(1):t.setNumWrap(1);let i;for(e!==void 0&&(i=e.normalize()),t.reset();t.moveToNextFacet();){const s=nt.areaNormal(t.point.getPoint3dArray());n+=i?s.dotProduct(i):s.magnitude()}return n}static sumTetrahedralVolumes(t,e){let n=0;if(t instanceof It)return St.sumTetrahedralVolumes(t.createVisitor(0),e);let i=e;const s=y.create(),r=y.create(),o=y.create();for(t.reset();t.moveToNextFacet();){i===void 0&&(i=t.point.getPoint3dAtUncheckedPointIndex(0)),t.point.getPoint3dAtUncheckedPointIndex(0,s);for(let a=1;a+1<t.point.length;a++)t.point.getPoint3dAtUncheckedPointIndex(a,r),t.point.getPoint3dAtUncheckedPointIndex(a+1,o),n+=i.tripleProductToPoints(s,r,o)}return n/6}static sumVolumeBetweenFacetsAndPlane(t,e,n){const i=t instanceof It?t.createVisitor(0):t;i.setNumWrap(0);const s=y.create(),r=y.create(),o=P.create(),a=pt.createZero();let c=0;const l=n?void 0:Dt.create(void 0,!0),d=n?void 0:Dt.create(void 0,!0),h={skipMoments:n,p0:s,p1:r,v0:o,m0:a};for(i.reset();i.moveToNextFacet();){const g=nt.volumeBetweenPolygonAndPlane(i.point,e,h);c+=g.volume6,l&&d&&g.origin&&g.products&&(g.area2>0?l.accumulateProductsFromOrigin(g.origin,g.products,1):d.accumulateProductsFromOrigin(g.origin,g.products,1))}return{volume:c/6,positiveProjectedFacetAreaMoments:l?Dt.inertiaProductsToPrincipalAxes(l.origin,l.sums):void 0,negativeProjectedFacetAreaMoments:d?Dt.inertiaProductsToPrincipalAxes(d.origin,d.sums):void 0}}static sumFacetSecondAreaMomentProducts(t,e){if(t instanceof It)return St.sumFacetSecondAreaMomentProducts(t.createVisitor(0),e);const n=pt.createZero();for(t.reset();t.moveToNextFacet();)nt.addSecondMomentAreaProducts(t.point,e,n);return n}static sumFacetSecondVolumeMomentProducts(t,e){if(t instanceof It)return St.sumFacetSecondVolumeMomentProducts(t.createVisitor(0),e);const n=pt.createZero();for(t.reset();t.moveToNextFacet();)nt.addSecondMomentVolumeProducts(t.point,e,n);return n}static computePrincipalAreaMoments(t){const e=t.data.getPoint(0);if(!e)return;const n=St.sumFacetSecondAreaMomentProducts(t,e);return Dt.inertiaProductsToPrincipalAxes(e,n)}static computePrincipalVolumeMoments(t){const e=t.data.getPoint(0);if(!e)return;const n=St.sumFacetSecondVolumeMomentProducts(t,e);return Dt.inertiaProductsToPrincipalAxes(e,n)}static areFacetsConvex(t){if(t instanceof It)return this.areFacetsConvex(t.createVisitor(0));for(t.setNumWrap(0),t.reset();t.moveToNextFacet();)if(t.pointCount>3&&!nt.isConvex(t.point))return!1;return!0}static dihedralAngleSummary(t,e=!1){const n=new Qs,i=t instanceof It?t.data.point:void 0,s=t instanceof It?t.createVisitor(1):t;s.setNumWrap(1);const r=[];let o=0;for(s.reset();s.moveToNextFacet();){const m=s.pointCount-1,p=nt.areaNormalGo(s.point);if(p!==void 0){r.push(p);for(let x=0;x<m;x++){const _=n.addEdge(s.clientPointIndex(x),s.clientPointIndex(x+1),o);i||(_.edgeVector=P.createStartEnd(s.point.getPoint3dAtUncheckedPointIndex(x),s.point.getPoint3dAtUncheckedPointIndex(x+1)))}o++}}const a=[],c=[];if(n.sortAndCollectClusters(c,e?void 0:a,void 0,a),a.length>0)return-2;let l=0,d=0,h=0;const g=P.create();for(const m of c)if(Array.isArray(m)&&m.length===2){const p=m[0],x=m[1];if(i){if(!i.vectorIndexIndex(p.startVertex,p.endVertex,g))return-2}else g.setFrom(p.edgeVector);const _=r[p.facetIndex],I=r[x.facetIndex],v=_.signedAngleTo(I,g);v.isAlmostZero?d++:v.radians>0?l++:h++}return l>0&&h===0?1:h>0&&l===0?-1:d>0&&l===0&&h===0?0:-2}static isConvexByDihedralAngleCount(t,e=!1){return this.dihedralAngleSummary(t,e)>0}static isSubsetVisitor(t){if(t instanceof It)return!1;const e=t.clientPolyface()?.facetCount,n=t.getVisitableFacetCount?.();return e===void 0||n===void 0?!1:e>n}static isPolyfaceManifoldFast(t,e){if(e)return;if(this.isSubsetVisitor(t))return!1;const n=un.hasEdgeMateIndex(t);if(n){for(const i of n.edgeMateIndex)if(i===void 0)return!1;return!0}}static isPolyfaceManifold(t,e=!1){const n=this.isPolyfaceManifoldFast(t,e);if(n!==void 0)return n;const i=[];return this.createIndexedEdges(t).sortAndCollectClusters(void 0,e?void 0:i,void 0,i),i.length===0}static isPolyfaceClosedByEdgePairing(t){return this.isPolyfaceManifold(t,!1)}static announceBoundaryEdgesFast(t,e,n,i,s){if(n!==i)return!1;if(!n&&!s)return!0;if(this.isSubsetVisitor(t))return!1;const r=un.hasEdgeMateIndex(t);if(!r)return!1;const o=y.create(),a=y.create();for(let c=0;c<r.edgeMateIndex.length;c++){const l=r.edgeMateIndex[c];if(n&&l===void 0||s&&l===c){const g=r.parent.edgeIndexToFacetIndex(c);if(g!==void 0){const m=r.parent.data.pointIndex[c];let p=c+1;p>=r.parent.facetIndex1(g)&&(p=r.parent.facetIndex0(g));const x=r.parent.data.pointIndex[p];r.parent.data.getPoint(m,o),r.parent.data.getPoint(x,a),e(o,a,m,x,g)}}}return!0}static announceBoundaryEdges(t,e,n=!0,i=!0,s=!0){if(this.announceBoundaryEdgesFast(t,e,n,i,s)||!n&&!i&&!s)return;const r=t instanceof It?t.data.point:void 0,o=t instanceof It?t.createVisitor(1):t;o.setNumWrap(1);const a=new Qs;for(o.reset();o.moveToNextFacet();){const p=o.pointCount-1;for(let x=0;x<p;x++){const _=a.addEdge(o.clientPointIndex(x),o.clientPointIndex(x+1),o.currentReadIndex());r||(_.pointA=o.point.getPoint3dAtUncheckedPointIndex(x),_.pointB=o.point.getPoint3dAtUncheckedPointIndex(x+1))}}const c=[],l=n?c:void 0,d=s?c:void 0,h=i?c:void 0;if(a.sortAndCollectClusters(void 0,l,d,h),c.length===0)return;const g=y.create(),m=y.create();for(const p of c){const x=p instanceof Fe?p:p[0],_=x.startVertex,I=x.endVertex;r?(r.getPoint3dAtUncheckedPointIndex(_,g),r.getPoint3dAtUncheckedPointIndex(I,m)):(g.setFrom(x.pointA),m.setFrom(x.pointB)),e(g,m,_,I,x.facetIndex)}}static boundaryEdges(t,e=!0,n=!0,i=!0){const s=new Ee,r=(o,a,c,l,d)=>{s.tryAddChild(U.create(o,a))};if(St.announceBoundaryEdges(t,r,e,n,i),s.children.length!==0)return s}static collectBoundaryEdges(t,e=!0,n=!0,i=!0){const s=new xe(f.smallMetricDistance,f.smallMetricDistance),r=(o,a)=>s.captureCurve(U.create(o,a));return St.announceBoundaryEdges(t,r,e,n,i),s.grabResult(!0)}static createIndexedEdges(t){const e=new Qs,n=t instanceof It?t.createVisitor(1):t;for(n.setNumWrap(1),n.reset();n.moveToNextFacet();)e.addPath(n.pointIndex,n.currentReadIndex(),!1);return e}static announceSilhouetteEdges(t,e,n,i=A.createSmallAngle()){if(t instanceof It)return this.announceSilhouetteEdges(t.createVisitor(1),e,n,i);const s=t.clientPolyface();if(s===void 0)return;t.setNumWrap(1);const r=this.createIndexedEdges(t),o=[];r.sortAndCollectClusters(o);const a=i.radians<0?-i.radians:i.radians,c=y.create(),l=y.create(),d=P.create(),h=g=>{if(!St.computeFacetUnitNormal(t,g,d))return{isSideFace:!1,perpAngle:0};const m=d.radiansFromPerpendicular(n);return{isSideFace:Math.abs(m)<=a,perpAngle:m}};for(const g of o){if(!Array.isArray(g)||g.length!==2)continue;const m=g[0].startVertex,p=g[0].endVertex;if(!s.data.getPoint(m,c)||!s.data.getPoint(p,l))continue;const x=h(g[0].facetIndex);if(x.isSideFace){e(c,l,m,p,g[0].facetIndex);continue}const _=h(g[1].facetIndex);if(_.isSideFace){e(l,c,p,m,g[1].facetIndex);continue}if(x.perpAngle*_.perpAngle<0){e(c,l,m,p,g[0].facetIndex);continue}}}static collectSilhouetteEdges(t,e,n=A.createSmallAngle()){const i=new xe(f.smallMetricDistance,f.smallMetricDistance);return St.announceSilhouetteEdges(t,(s,r)=>i.captureCurve(U.create(s,r)),e,n),i.grabResult(!0)}static announceSweepLinestringToConvexPolyfaceXY(t,e,n){const i=js.create(t);if(i){const s=e.createVisitor(0);for(s.reset();s.moveToNextFacet();)i.projectToPolygon(s.point,n,e,s.currentReadIndex())}}static _asyncWorkLimit=1e6;static setAsyncWorkLimit(t){const e=this._asyncWorkLimit;return this._asyncWorkLimit=t,e}static get asyncWorkLimit(){return this._asyncWorkLimit}static awaitBlockCount=0;static async continueAnnounceSweepLinestringToConvexPolyfaceXY(t,e,n,i){let s=0;for(;s<this.asyncWorkLimit&&n.moveToNextFacet();)s+=t.projectToPolygon(n.point,i,e,n.currentReadIndex());return s}static async asyncAnnounceSweepLinestringToConvexPolyfaceXY(t,e,n){const i=js.create(t);this.awaitBlockCount=0;let s=0;if(i){const r=e.createVisitor(0);let o;for(;0<(o=await Promise.resolve(St.continueAnnounceSweepLinestringToConvexPolyfaceXY(i,e,r,n)));)s+=o,this.awaitBlockCount++}return s}static partitionFacetIndicesByVertexConnectedComponent(t){if(t instanceof It)return this.partitionFacetIndicesByVertexConnectedComponent(t.createVisitor(0));const e=new ha(this.visitorClientPointCount(t));for(t.reset();t.moveToNextFacet();){const r=t.pointIndex[0];for(const o of t.pointIndex)e.mergeSubsets(r,o)}const n=e.collectRootIndices(),i=[],s=n.length;for(let r=0;r<s;r++)i.push([]);for(t.reset();t.moveToNextFacet();){const r=t.pointIndex[0],o=e.findRoot(r);for(let a=0;a<s;a++)if(n[a]===o){i[a].push(t.currentReadIndex());break}}return i}static partitionFacetIndicesByVisibilityVector(t,e,n){if(t instanceof It)return this.partitionFacetIndicesByVisibilityVector(t.createVisitor(0),e,n);const i=[];for(let c=0;c<3;c++)i.push([]);const s=i[0],r=i[1],o=i[2],a=Math.max(n.radians,1e-8);for(t.reset();t.moveToNextFacet();){const c=nt.areaNormalGo(t.point),l=t.currentReadIndex();if(c){const d=c.angleFromPerpendicular(e);Math.abs(d.radians)<a?o.push(l):c.dotProduct(e)<0?r.push(l):s.push(l)}}return i}static boundaryOfVisibleSubset(t,e,n,i=A.createDegrees(.001)){const s=t instanceof It?t.createVisitor(0):t;if(!s.createSubsetVisitor)return;const r=this.partitionFacetIndicesByVisibilityVector(t,n,i);if(r[e].length===0)return;const o=s.createSubsetVisitor(r[e],1);return this.boundaryEdges(o,!0,!1,!1)}static announceBoundaryChainsAsLineString3d(t,e){const n=new xe(f.smallMetricDistance),i=(s,r)=>n.captureCurve(U.create(s,r));St.announceBoundaryEdges(t,i,!0,!1,!1),n.announceChainsAsLineString3d(e)}static cloneWithMaximalPlanarFacets(t,e){if(t instanceof It)return this.cloneWithMaximalPlanarFacets(t.createVisitor(0),e);const n=St.visitorClientFacetCount(t),i=St.collectEdgesByDihedralAngle(t,e),s=St.partitionFacetIndicesBySortableEdgeClusters(i,n),r=it.create(),o=t,a=[],c=[],l=P.createZero();for(const x of s)if(x.length===1)o.moveToReadIndex(x[0])&&r.addFacetFromVisitor(o);else if(x.length>1){const _=P.createZero(),I=y.createZero();o.moveToReadIndex(x[0])&&o.point.getPoint3dAtCheckedPointIndex(0,I);for(const v of x)o.moveToReadIndex(v)&&nt.areaNormalGo(o.point,l)&&_.addInPlace(l);c.push(O.createCapture(I,_)),a.push(x)}const d=St.clonePartitions(t,a);a.length,c.length,a.length,d.length;const h=1e-4,g=1e-4,m=X.createIdentity(),p=X.createIdentity();for(let x=0;x<d.length;++x){const _=d[x],I=[],v=[];St.announceBoundaryEdges(_,(w,T,R,L)=>{I.push(U.create(w,T)),v.push([w.clone(),T.clone()])},!0,!1,!1);const S=Gn.collectChains(I,h,g);if(S&&(c[x].toRigidZFrame(m),m.inverse(p))){p.multiplyPoint3dArrayArrayInPlace(v);const w=!(S instanceof tt),T=Je.formGraphFromChains(v,w,M.BOUNDARY_EDGE);if(T){On.collectConnectedComponentsWithExteriorParityMasks(T,new Fc(M.BOUNDARY_EDGE),M.EXTERIOR);const R=it.graphToPolyface(T);r.addIndexedPolyface(R,!1,m)}}}return r.claimPolyface(!0)}static fillSimpleHoles(t,e,n){if(t instanceof It)return this.fillSimpleHoles(t.createVisitor(0),e,n);const i=it.create(),s=[];St.announceBoundaryChainsAsLineString3d(t,r=>{r.reverseInPlace(),s.push(r)});for(const r of s){const o=r.points;let a=!1;r.isPhysicallyClosed?(e.maxEdgesAroundHole!==void 0&&o.length>e.maxEdgesAroundHole||e.maxPerimeter!==void 0&&re.sumEdgeLengths(o,!1)>e.maxPerimeter||e.upVector!==void 0&&nt.sumTriangleAreasPerpendicularToUpVector(o,e.upVector)<=0)&&(a=!0):a=!0,!a&&Mc.triangulateSimplestSpaceLoop(o,(c,l)=>{for(const d of l)i.addPolygon(d)})||(a=!0),a&&n!==void 0&&n.push(r)}if(e.includeOriginalMesh!==void 0&&e.includeOriginalMesh)for(t.reset();t.moveToNextFacet();)i.addFacetFromVisitor(t);return i.claimPolyface(!0)}static clonePartitions(t,e){if(t instanceof It)return this.clonePartitions(t.createVisitor(0),e);t.setNumWrap(0);const n=[],i=Zt.createForFacets();i.needNormals=t.normal!==void 0,i.needParams=t.param!==void 0,i.needColors=t.color!==void 0,i.needTwoSided=t.twoSided;for(const s of e){const r=it.create(i);t.reset();for(const o of s)t.moveToReadIndex(o),r.addFacetFromVisitor(t);n.push(r.claimPolyface(!0))}return n}static cloneFiltered(t,e){if(t instanceof It)return this.cloneFiltered(t.createVisitor(0),e);t.setNumWrap(0);const n=Zt.createForFacets();n.needNormals=t.normal!==void 0,n.needParams=t.param!==void 0,n.needColors=t.color!==void 0,n.needTwoSided=t.twoSided;const i=it.create(n);for(t.reset();t.moveToNextFacet();)e(t)&&i.addFacetFromVisitor(t);return i.claimPolyface(!0)}static cloneWithDanglingEdgesRemoved(t){if(t instanceof It)return this.cloneWithDanglingEdgesRemoved(t.createVisitor(0));const e=Zt.createForFacets();e.needNormals=t.normal!==void 0,e.needParams=t.param!==void 0,e.needColors=t.color!==void 0,e.needTwoSided=t.twoSided;const n=it.create(e),i=(s,r)=>{const o=s.length;for(let a=0;a<o;++a){let c=1,l=a,d=a;for(;c+2<=o;){const h=l===0?o-1:l-1,g=d===o-1?0:d+1;if(r[s[h]]!==r[s[g]])break;l=h,d=g,c+=2}if(c>1)return l<d?s.splice(l,c-1):l>d&&(s.splice(l),s.splice(0,d)),!0}return!1};for(t.setNumWrap(0),t.reset();t.moveToNextFacet();){const s=[...Array(t.pointIndex.length).keys()];for(;i(s,t.pointIndex););n.addFacetFromIndexedVisitor(t,s)}return n.claimPolyface(!0)}static visitorClientPointCount(t){if(t instanceof It)return t.data.point.length;const e=t.clientPolyface();if(e!==void 0)return e.data.point.length;const n=t.currentReadIndex();t.reset();let i=-1;for(;t.moveToNextFacet();)for(const s of t.pointIndex)s>i&&(i=s);return t.moveToReadIndex(n),i+1}static visitorClientFacetCount(t){if(t instanceof It){if(t.facetCount!==void 0)return t.facetCount;t=t.createVisitor(0)}if(t.getVisitableFacetCount)return t.getVisitableFacetCount();const e=t.clientPolyface();if(e!==void 0&&e.facetCount!==void 0)return e.facetCount;const n=t.currentReadIndex();let i=0;for(t.reset();t.moveToNextFacet();)++i;return t.moveToReadIndex(n),i}static partitionFacetIndicesBySortableEdgeClusters(t,e){const n=new ha(e);for(const o of t)if(!(o instanceof Fe)){const a=o[0];for(let c=1;c<o.length;c++)n.mergeSubsets(a.facetIndex,o[c].facetIndex)}const i=n.collectRootIndices(),s=[],r=i.length;for(let o=0;o<r;o++)s.push([]);for(let o=0;o<e;o++){const a=n.findRoot(o);for(let c=0;c<r;c++)if(i[c]===a){s[c].push(o);break}}return s}static partitionFacetIndicesByEdgeConnectedComponent(t,e=!1){if(t instanceof It)return this.partitionFacetIndicesByEdgeConnectedComponent(t.createVisitor(0),e);t.setNumWrap(1);const n=new Qs;t.reset();let i=0;for(;t.moveToNextFacet();){const r=t.pointCount-1;i++;for(let o=0;o<r;o++)e&&t.edgeVisible[o]||n.addEdge(t.clientPointIndex(o),t.clientPointIndex(o+1),t.currentReadIndex())}const s=[];return n.sortAndCollectClusters(s,s,s,s),this.partitionFacetIndicesBySortableEdgeClusters(s,i)}static sweepLineStringToFacetsXYReturnSweptFacets(t,e){const n=it.create();return this.announceSweepLinestringToConvexPolyfaceXY(t,e,(i,s,r,o,a)=>{a.length===4?n.addQuadFacet(a):a.length===3&&n.addTriangleFacet(a)}),n.claimPolyface(!0)}static sweepLinestringToFacetsXYreturnSweptFacets(t,e){return this.sweepLineStringToFacetsXYReturnSweptFacets(t,e)}static sweepLineStringToFacets(t,e,n){let i=[];n===void 0&&(n=tr.create());let s;n.assembleChains&&(s=Ke.create());const r=s?(c,l)=>s.addSegment(c,l):(c,l)=>i.push(U.create(c,l)),o=P.createZero(),a=e instanceof It?e.createVisitor(0):e;if(a.setNumWrap(0),n.searcher&&n.vectorToEye.isParallelTo(P.unitZ())){const c=J.createNull(),l=y.createZero(),d=y.createZero();let h;const g=(m,p)=>(a.moveToReadIndex(p)&&(n.collectAll||n.collectFromThisFacetNormal(nt.areaNormalGo(a.point,o)))&&h?.processPolygon(a.point,(x,_)=>r(x,_)),!0);for(let m=1;m<t.length;m++)t.getPoint3dAtUncheckedPointIndex(m-1,l),t.getPoint3dAtUncheckedPointIndex(m,d),(h=ts.createPointPointSweep(l,d,n.vectorToEye))&&(c.setNull(),c.extend(l,d),n.searcher.searchRange2d(c,g))}else{const c=ao.create(t,n.vectorToEye);if(c)for(a.reset();a.moveToNextFacet();)(n.collectAll||n.collectFromThisFacetNormal(nt.areaNormalGo(a.point,o)))&&c.processPolygon(a.point.getArray(),r)}return s&&(s.clusterAndMergeVerticesXYZ(),i=s.collectMaximalChains()),i}static sweepLineStringToFacetsXY(t,e,n){const i=Ke.create(),s=P.unitZ(),r=J.create(),o=y.createZero(),a=y.createZero(),c=e instanceof It?e.createVisitor(0):e;c.setNumWrap(0);let l;const d=(g,m)=>(c.moveToReadIndex(m)&&l?.processPolygon(c.point,(p,x)=>i.addSegment(p,x)),!0),h=Array.isArray(t)?new Bt(t):t;for(let g=1;g<h.length;g++)h.getPoint3dAtUncheckedPointIndex(g-1,o),h.getPoint3dAtUncheckedPointIndex(g,a),(l=ts.createPointPointSweep(o,a,s))&&(r.setNull(),r.extend(o,a),n.searchRange2d(r,d));return i.clusterAndMergeVerticesXYZ(),i.collectMaximalChains()}static sweepLinestringToFacetsXYReturnLines(t,e){const n=tr.create(P.unitZ(),A.createSmallAngle(),!1,!0,!0,!0);return St.sweepLineStringToFacets(t,e,n)}static sweepLinestringToFacetsXYReturnChains(t,e){return St.sweepLineStringToFacets(t,e)}static async asyncSweepLinestringToFacetsXYReturnChains(t,e){const n=Ke.create();return await Promise.resolve(this.asyncAnnounceSweepLinestringToConvexPolyfaceXY(t,e,(s,r,o,a,c,l,d)=>{n.addSegment(c[l],c[d])})),n.clusterAndMergeVerticesXYZ(),n.collectMaximalChains()}static collectRangeLengthData(t){if(t instanceof It)return this.collectRangeLengthData(t.createVisitor(0));const e=new Dc;for(t.reset();t.moveToNextFacet();)e.accumulateGrowableXYZArrayRange(t.point);return e}static cloneWithTVertexFixup(t){const e=t.createVisitor(1),n=t.createVisitor(0),i=lo.create(t.data.point,30),s=it.create();if(!i)return s.addFacetsFromVisitor(e),s.claimPolyface(!1);const r=J.createNull(),o=y.create(),a=y.create(),c=y.create(),l=U.create(o,a);for(e.reset();e.moveToNextFacet();){n.clearArrays();for(let d=0;d+1<e.point.length;d++){e.point.getPoint3dAtUncheckedPointIndex(d,o),e.point.getPoint3dAtUncheckedPointIndex(d+1,a),n.pushDataFrom(e,d),r.setNull(),U.create(o,a,l);let h;if(r.extend(o),r.extend(a),r.ensureMinLengths(f.smallMetricDistance),i.announcePointsInRange(r,(g,m,p,x)=>{t.data.point.getPoint3dAtUncheckedPointIndex(g,c);const _=l.closestPoint(c,!1);return _!==void 0&&_.fraction>0&&_.fraction<1&&!_.point.isAlmostEqual(o)&&!_.point.isAlmostEqual(a)&&c.isAlmostEqual(_.point)&&(h===void 0&&(h=[]),_.a=g,h.push(_)),!0}),h!==void 0){h.sort((g,m)=>g.fraction-m.fraction);for(const g of h)n.pushInterpolatedDataFrom(e,d,g.fraction,d+1)}}s.addFacetFromGrowableArrays(n.point,n.normal,n.param,n.color,n.edgeVisible)}return s.claimPolyface()}static compareFacetIndexAndVertexIndices(t,e){if(t.length!==e.length)return t.length-e.length;for(let n=1;n<t.length;n++)if(t[n]!==e[n])return t[n]-e[n];return 0}static announceDuplicateFacetIndices(t,e){const n=t.createVisitor(0),i=[];for(n.reset();n.moveToNextFacet();){const l=[n.currentReadIndex()],d=n.pointIndex,h=d.length;let g=0;for(let m=1;m<n.pointIndex.length;m++)d[m]<d[g]&&(g=m);if(d[(g+1)%h]<d[(g+h-1)%h])for(let m=0;m<h;m++)l.push(d[(g+m)%h]);else for(let m=0;m<h;m++)l.push(d[(g+h-m)%h]);i.push(l)}i.sort((c,l)=>this.compareFacetIndexAndVertexIndices(c,l));let s,r;const o=i.length,a=[];for(s=0;s<o;s=r){for(r=s+1,a.length=0,a.push(i[s][0]);r<o&&this.compareFacetIndexAndVertexIndices(i[s],i[r])===0;)a.push(i[r][0]),r++;e(a)}}static collectDuplicateFacetIndices(t,e=!1){const n=[];return this.announceDuplicateFacetIndices(t,i=>{(e||i.length>1)&&n.push(i.slice())}),n}static cloneByFacetDuplication(t,e,n){const i=it.create(),s=t.createVisitor(0);return this.announceDuplicateFacetIndices(t,r=>{let o=0;r.length===1?e&&(o=1):r.length>1&&(n===ns.SelectAny?o=1:n===ns.SelectAll?o=r.length:n===ns.SelectOneByParity&&(o=(r.length&1)===1?1:0));for(let a=0;a<o;a++)s.moveToReadIndex(r[a]),i.addFacetFromVisitor(s)}),i.claimPolyface()}static cloneWithColinearEdgeFixup(t){const e=t.createVisitor(2),n=t.createVisitor(0),i=it.create(),s=P.create(),r=P.create(),o=t.data.point.length,a=new Int32Array(o);for(e.reset();e.moveToNextFacet();)for(let c=0;c+2<e.point.length;c++){e.point.vectorIndexIndex(c,c+1,s),e.point.vectorIndexIndex(c+1,c+2,r);const l=e.clientPointIndex(c+1);a[l]>=0&&(s.angleTo(r).isAlmostZero?a[l]++:a[l]=-1)}for(e.reset();e.moveToNextFacet();){n.clearArrays();for(let c=0;c+2<e.point.length;c++){const l=e.clientPointIndex(c);a[l]<0&&n.pushDataFrom(e,c)}n.point.length>2&&i.addFacetFromGrowableArrays(n.point,n.normal,n.param,n.color,n.edgeVisible)}return i.claimPolyface()}static setEdgeVisibility(t,e,n){for(const i of e)if(i instanceof Fe)this.setSingleEdgeVisibility(t,i.facetIndex,i.startVertex,n);else if(Array.isArray(i))for(const s of i)this.setSingleEdgeVisibility(t,s.facetIndex,s.startVertex,n)}static setSingleEdgeVisibility(t,e,n,i){const s=t.data,r=t.facetIndex0(e),o=t.facetIndex1(e);for(let a=r;a<o;a++)s.pointIndex[a]===n&&(s.edgeVisible[a]=i)}static getSingleEdgeVisibility(t,e,n){const i=t.data,s=t.facetIndex0(e),r=t.facetIndex1(e);for(let o=s;o<r;o++)if(i.pointIndex[o]===n)return i.edgeVisible[o]}static collectEdgesByDihedralAngle(t,e,n=!1){if(t instanceof It)return this.collectEdgesByDihedralAngle(t.createVisitor(1),e,n);t.setNumWrap(1);const i=this.createIndexedEdges(t),s=[];i.sortAndCollectClusters(s),(e===void 0||e.radians<0)&&(e=A.createRadians(f.smallAngleRadians));const r=[],o=P.create(),a=P.create();for(const c of s)if(Array.isArray(c)&&c.length===2){const l=c[0],d=c[1];if(St.computeFacetUnitNormal(t,l.facetIndex,o)!==void 0&&St.computeFacetUnitNormal(t,d.facetIndex,a)!==void 0){const h=o.smallerUnorientedAngleTo(a);n?h.radians>e.radians&&r.push(c):h.radians<=e.radians&&r.push(c)}}return r}static markPairedEdgesInvisible(t,e){const n=t.createVisitor(1),i=this.createIndexedEdges(n),s=[],r=[];if(i.sortAndCollectClusters(s,r,r,r),this.markAllEdgeVisibility(t,!1),this.setEdgeVisibility(t,r,!0),e!==void 0){const o=P.create(),a=P.create();for(const c of s)if(Array.isArray(c)&&c.length===2){const l=c[0],d=c[1];St.computeFacetUnitNormal(n,l.facetIndex,o)!==void 0&&St.computeFacetUnitNormal(n,d.facetIndex,a)!==void 0&&o.smallerUnorientedAngleTo(a).radians>e.radians&&(this.setSingleEdgeVisibility(t,l.facetIndex,l.startVertex,!0),this.setSingleEdgeVisibility(t,d.facetIndex,d.startVertex,!0))}}}static computeFacetUnitNormal(t,e,n){if(n||(n=P.create()),t.moveToReadIndex(e)&&nt.unitNormal(t.point,n))return n}static markAllEdgeVisibility(t,e){const n=t.data;for(let i=0;i<n.edgeVisible.length;i++)n.edgeVisible[i]=e}static convertToHalfEdgeGraph(t){const e=new fa,n=t.createVisitor(0),i=y.create();for(n.reset();n.moveToNextFacet();)e.insertLoop(n.pointIndex,s=>{t.data.getPoint(s.i,i),s.setXYZ(i),t.data.getPoint(s.edgeMate.i,i),s.edgeMate.setXYZ(i)});return e.graph}static reorientVertexOrderAroundFacetsForConsistentOrientation(t){return si.doFixup(t)}static buildPerFaceNormals(t){ma.buildPerFaceNormals(t)}static buildAverageNormals(t,e=A.createDegrees(31)){ma.buildFastAverageNormals(t,e)}static cloneOffset(t,e,n=ho.create()){const i=Zt.createForFacets(),s=it.create(i);return _t.buildOffsetMeshWithEdgeChamfers(t,s,e,n),s.claimPolyface()}static _workTriangle;static _workTriDetail;static _workPolyDetail;static _workFacetDetail3;static _workFacetDetailC;static _workFacetDetailNC;static intersectRay3d(t,e,n){if(t instanceof It)return St.intersectRay3d(t.createVisitor(0),e,n);let i;const s=n?[n.distanceTolerance,n.parameterTolerance]:void 0;for(t.setNumWrap(0);t.moveToNextFacet();){const r=t.pointCount,o=t.point;if(r===3){const a=this._workTriangle=gt.create(o.getPoint3dAtUncheckedPointIndex(0),o.getPoint3dAtUncheckedPointIndex(1),o.getPoint3dAtUncheckedPointIndex(2),this._workTriangle),c=this._workTriDetail=a.intersectRay3d(e,this._workTriDetail);a.snapLocationToEdge(c,n?.distanceTolerance,n?.parameterTolerance),i=this._workFacetDetail3=$i.create(t.currentReadIndex(),c,this._workFacetDetail3)}else{const a=this._workPolyDetail=nt.intersectRay3d(o,e,s,this._workPolyDetail);nt.isConvex(o)?i=this._workFacetDetailC=ii.create(t.currentReadIndex(),r,a,this._workFacetDetailC):i=this._workFacetDetailNC=Ln.create(t.currentReadIndex(),r,a,this._workFacetDetailNC)}if(i.isInsideOrOn){if(n?.needNormal&&t.normal&&i.getNormal(t.normal,o,n?.distanceTolerance),n?.needParam&&t.param&&i.getParam(t.param,o,n?.distanceTolerance),n?.needColor&&t.color&&i.getColor(t.color,o,n?.distanceTolerance),n?.needBarycentricCoordinates&&i.getBarycentricCoordinates(o,n?.distanceTolerance),n?.acceptIntersection&&!n.acceptIntersection(i,t))continue;return i}}}}class vt{static hugeVal=1e37;_planes;constructor(t){this._planes=t||[]}get planes(){return this._planes}toJSON(){const t=[];for(const e of this._planes)t.push(e.toJSON());return t}static fromJSON(t,e){if(e=e||new vt,e._planes.length=0,!Array.isArray(t))return e;for(const n of t){const i=H.fromJSON(n);i&&e._planes.push(i)}return e}isAlmostEqual(t){if(this._planes.length!==t._planes.length)return!1;for(let e=0;e<this._planes.length;e++)if(!this._planes[e].isAlmostEqual(t._planes[e]))return!1;return!0}static createPlanes(t,e){e=e||new vt;for(const n of t)if(n instanceof H)e._planes.push(n);else if(n instanceof ht){const i=H.createPlane(n);e._planes.push(i)}return e}static createRange3dPlanes(t,e=!0,n=!0,i=!0,s=!0,r=!0,o=!0){const a=vt.createEmpty();return e&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(1,0,0,t.low.x,0,0)),n&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(-1,0,0,t.high.x,0,0)),i&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(0,1,0,0,t.low.y,0)),s&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(0,-1,0,0,t.high.y,0)),r&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(0,0,1,0,0,t.low.z)),o&&a.addPlaneToConvexSet(H.createNormalAndPointXYZXYZ(0,0,-1,0,0,t.high.z)),a}static createEmpty(t){return t?(t._planes.length=0,t):new vt}negateAllPlanes(){for(const t of this._planes)t.negateInPlace()}static createXYBox(t,e,n,i,s){s=s||new vt,s._planes.length=0;const r=H.createNormalAndDistance(P.create(-1,0,0),-n,!1,!0),o=H.createNormalAndDistance(P.create(1,0,0),t,!1,!0),a=H.createNormalAndDistance(P.create(0,-1,0),-i,!1,!0),c=H.createNormalAndDistance(P.create(0,1,0),e,!1,!0);return r&&o&&a&&c&&s._planes.push(r,o,a,c),s}static createXYPolyLine(t,e,n,i){i=i||new vt,i._planes.length=0;for(let s=0;s+1<t.length;s++){const o=P.createStartEnd(t[s],t[s+1]).unitPerpendicularXY();if(o.z=0,n||o.scaleInPlace(-1),o.normalize()){const c=e!==void 0?e[s]:!1,l=H.createNormalAndPoint(o,t[s],c,c);l&&i._planes.push(l)}}return i}static createXYPolyLineInsideLeft(t,e){e=e||new vt,e._planes.length=0;for(let n=0;n+1<t.length;n++){const s=P.createStartEnd(t[n],t[n+1]).unitPerpendicularXY();if(s.z=0,s.normalize()){const o=H.createNormalAndPoint(s,t[n],!1,!1);o&&e._planes.push(o)}}return e}static setPlaneAndXYLoopCCW(t,e,n){const i=t.length-1,s=t.length;let r=t.getXAtUncheckedPointIndex(i),o=t.getYAtUncheckedPointIndex(i),a,c,l,d;n._planes.length=0;const h=t.getZAtUncheckedPointIndex(i),g=t.crossProductIndexIndexIndex(0,2,1);if(g?.normalizeInPlace()){H.createNormalAndPointXYZXYZ(g.x,g.y,g.z,r,o,h,!1,!1,e);for(let m=0;m<s;m++,r=a,o=c){a=t.getXAtUncheckedPointIndex(m),c=t.getYAtUncheckedPointIndex(m),l=-(c-o),d=a-r;const p=H.createNormalAndPointXYZXYZ(l,d,0,a,c,h);p&&n._planes.push(p)}}}clone(t){t=t||new vt,t._planes.length=0;for(const e of this._planes)t._planes.push(e.clone());return t}hasIntersectionWithRay(t,e,n=f.smallMetricDistance){let i=-f.largeCoordinateResult,s=f.largeCoordinateResult;e&&e.setNull();const r=1e-13;for(const o of this._planes){const a=o.velocity(t.direction),c=o.altitude(t.origin);if(Math.abs(a)<=r){if(c<-n)return!1}else{const l=-c/a;a<0?l<s&&(s=l):l>i&&(i=l)}}return s<i?!1:(e&&(e.extendX(i),e.extendX(s)),!0)}multiplyPlanesByMatrix4d(t,e=!0,n=!0){if(e){const i=t.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._planes)i.multiplyPlaneByMatrix4d(t,!1,n);return!0}isPointInside(t){for(const e of this._planes)if(!e.isPointInside(t))return!1;return!0}isPointOnOrInside(t,e=f.smallMetricDistance){const n=Math.abs(e);for(const i of this._planes)if(!i.isPointOnOrInside(t,i.interior?n:e))return!1;return!0}isSphereInside(t,e){const n=Math.abs(e)+f.smallMetricDistance;for(const i of this._planes)if(!i.isPointOnOrInside(t,n))return!1;return!0}announceClippedSegmentIntervals(t,e,n,i,s){let r;if(e<t)return!1;for(const o of this._planes){const a=-o.altitude(n),c=-o.altitude(i);if(r=f.conditionalDivideFraction(-a,c-a),r===void 0){if(a>0)return!1}else if(c>a){if(r<t)return!1;r<e&&(e=r)}else if(a>c){if(r>e)return!1;r>t&&(t=r)}else if(a>0)return!1}return e>=t?(s&&s(t,e),!0):!1}static _clipFractionArray=new Ft;announceClippedArcIntervals(t,e){const n=vt._clipFractionArray;n.clear();for(const i of this.planes)i.appendIntersectionRadians(t,n);return t.sweep.radiansArrayToPositivePeriodicFractions(n),ee.selectIntervals01(t,n,this,e)}announceClippedCurveIntervals(t,e){const n=vt._clipFractionArray;n.clear();const i=[];for(const s of this.planes)t.appendPlaneIntersectionPoints(s,i);for(const s of i)n.push(s.fraction);return ee.selectIntervals01(t,n,this,e)}clipUnboundedSegment(t,e,n){return this.announceClippedSegmentIntervals(-Number.MAX_VALUE,Number.MAX_VALUE,t,e,n)}transformInPlace(t){for(const e of this._planes)e.transformInPlace(t)}clipConvexPolygonInPlace(t,e,n=f.smallMetricDistance){for(const i of this._planes)if(i.clipConvexPolygonInPlace(t,e,!0,n),t.length<3)return}clipInsidePushOutside(t,e,n){const i=ct.createNull();let s=n.grabFromCache(),r=n.grabFromCache(),o=n.grabFromCache();o.pushFrom(t);for(const a of this._planes)if(nn.splitConvexPolygonInsideOutsidePlane(a,o,s,r,i),r.length>0){if(e&&ee.captureOrDrop(r,3,e,n),r=n.grabFromCache(),s.length<3){o.length=0;break}n.dropToCache(o),o=s,s=n.grabFromCache()}if(n.dropToCache(s),n.dropToCache(r),o.length>0)return o;n.dropToCache(o)}classifyPointContainment(t,e){let n=!0;const i=e?1e-8:-1e-8,s=1e-8;for(const r of this._planes){let o=0;for(const a of t)r.altitude(a)<(r.interior?s:i)&&(o++,n=!1);if(o===t.length)return oe.StronglyOutside}return n?oe.StronglyInside:oe.Ambiguous}static createSweptPolyline(t,e,n){const i=vt.createEmpty();let s=!1;t.length>3&&t[0].isAlmostEqual(t[t.length-1])&&nt.areaNormal(t).dotProduct(e)>0&&(s=!0);for(let r=0;r+1<t.length;r++)if(s){const o=H.createEdgeAndUpVector(t[r+1],t[r],e,n);if(o)i.addPlaneToConvexSet(o);else return}else{const o=H.createEdgeAndUpVector(t[r],t[r+1],e,n);if(o)i.addPlaneToConvexSet(o);else return}return i}addPlaneToConvexSet(t){t instanceof H?this._planes.push(t):t instanceof ht&&this._planes.push(H.createPlane(t))}clipPointsOnOrInside(t,e,n){e.length=0,n.length=0;for(const i of t)this.isPointOnOrInside(i,0)?e.push(i):n.push(i)}polygonClip(t,e,n,i,s=f.smallMetricDistance){t instanceof W?t.clone(e):W.create(t,e),n||(n=new W);for(const r of this._planes)if(i!==r){if(e.length===0)break;r.clipConvexPolygonInPlace(e,n,!0,s)}}reloadSweptPolygon(t,e,n){this._planes.length=0;const i=t.length;if(i<=2)return 0;const s=nt.areaNormal(t),r=e.dotProduct(s)>0,o=r?1:i-1;for(let a=0;a<i;a++){const c=(a+o)%i,l=t[a],d=t[c];if(l.isAlmostEqual(d))continue;const h=P.createStartEnd(l,d),m=P.createCrossProduct(e.x,e.y,e.z,h.x,h.y,h.z).normalize();let p;if(m){p=m.dotProduct(l);const x=H.createNormalAndDistance(m,p,!1,!1);x&&this._planes.push(x)}}if(n!==0){let a=s.normalize();if(a){e.dotProduct(a)*n<0&&(a=a.negate());const l=t[0],d=a.dotProduct(l),h=H.createNormalAndDistance(a,d,!1,!1);h&&this._planes.push(h)}}return r?1:-1}computePlanePlanePlaneIntersections(t,e,n,i=!0){const s=C.createIdentity(),r=this._planes,o=y.createZero(),a=r.length;let c=0;for(let l=0;l<a;l++)for(let d=l+1;d<a;d++)for(let h=d+1;h<a;h++)C.createRowValues(r[l].inwardNormalRef.x,r[l].inwardNormalRef.y,r[l].inwardNormalRef.z,r[d].inwardNormalRef.x,r[d].inwardNormalRef.y,r[d].inwardNormalRef.z,r[h].inwardNormalRef.x,r[h].inwardNormalRef.y,r[h].inwardNormalRef.z,s),s.computeCachedInverse(!1)&&(s.multiplyInverseXYZAsPoint3d(r[l].distance,r[d].distance,r[h].distance,o),(!i||this.isPointOnOrInside(o,f.smallMetricDistance))&&(c++,n&&n.multiplyPoint3d(o,o),t&&t.push(o.clone()),e&&e.extendPoint(o)));return c}setInvisible(t){for(const e of this._planes)e.setInvisible(t)}addZClipPlanes(t,e,n){e!==void 0&&this.addPlaneToConvexSet(H.createNormalAndDistance(P.create(0,0,1),e,t)),n!==void 0&&this.addPlaneToConvexSet(H.createNormalAndDistance(P.create(0,0,-1),-n,t))}appendPolygonClip(t,e,n,i){const s=this.clipInsidePushOutside(t,n,i);s&&e.push(s)}static createConvexPolyface(t,e){e=this.createEmpty(e);let n=0;St.isPolyfaceClosedByEdgePairing(t)&&(n=St.sumTetrahedralVolumes(t));const i=n>0?-1:1,s=y.createZero(),r=P.createZero(),o=ht.createXYPlane(),a=t instanceof It?t.createVisitor(0):t;for(a.setNumWrap(0),a.reset();a.moveToNextFacet();)nt.areaNormalGo(a.point,r)&&(r.scaleInPlace(i),a.point.front(s),e.addPlaneToConvexSet(ht.create(s,r,o)));return{clipper:e,volume:n}}}class fe{_convexSets;get convexSets(){return this._convexSets}constructor(){this._convexSets=[]}toJSON(){const t=[];for(const e of this._convexSets)t.push(e.toJSON());return t}static fromJSON(t,e){if(e=e||new fe,e._convexSets.length=0,!Array.isArray(t))return e;for(const n of t)e._convexSets.push(vt.fromJSON(n));return e}static createEmpty(t){return t?(t._convexSets.length=0,t):new fe}isAlmostEqual(t){if(this._convexSets.length!==t._convexSets.length)return!1;for(let e=0;e<this._convexSets.length;e++)if(!this._convexSets[e].isAlmostEqual(t._convexSets[e]))return!1;return!0}static createConvexSets(t,e){e=e||new fe;for(const n of t)e._convexSets.push(n);return e}clone(t){t=t||new fe,t._convexSets.length=0;for(const e of this._convexSets)t._convexSets.push(e.clone());return t}addConvexSet(t){t&&this._convexSets.push(t)}hasIntersectionWithRay(t,e){if(e===void 0){for(const i of this._convexSets)if(i.hasIntersectionWithRay(t))return!0;return!1}e.setNull();const n=ct.createNull();for(const i of this._convexSets)i.hasIntersectionWithRay(t,n)&&e.extendRange(n);return!e.isNull}isPointInside(t){for(const e of this._convexSets)if(e.isPointInside(t))return!0;return!1}isPointOnOrInside(t,e=f.smallMetricDistance){for(const n of this._convexSets)if(n.isPointOnOrInside(t,e))return!0;return!1}isSphereInside(t,e){for(const n of this._convexSets)if(n.isSphereInside(t,e))return!0;return!1}isAnyPointInOrOnFromSegment(t){for(const e of this._convexSets)if(e.announceClippedSegmentIntervals(0,1,t.point0Ref,t.point1Ref))return!0;return!1}appendIntervalsFromSegment(t,e){for(const n of this._convexSets)n.announceClippedSegmentIntervals(0,1,t.point0Ref,t.point1Ref,(i,s)=>e.push(qt.create(i,s)))}transformInPlace(t){for(const e of this._convexSets)e.transformInPlace(t)}classifyPointContainment(t,e){for(const n of this._convexSets){const i=n.classifyPointContainment(t,e);if(i!==oe.StronglyOutside)return i}return oe.StronglyOutside}polygonClip(t,e,n,i,s=f.smallMetricDistance){e.length=0,Array.isArray(t)&&(t=W.create(t)),n||(n=new W);for(const r of this._convexSets){const o=new W;r.polygonClip(t,o,n,i,s),o.length!==0&&e.push(o)}}announceClippedSegmentIntervals(t,e,n,i,s){let r=0;for(const o of this._convexSets)o.announceClippedSegmentIntervals(t,e,n,i,s)&&r++;return r>0}static _clipFractionArray=new Ft;announceClippedArcIntervals(t,e){const n=fe._clipFractionArray;n.clear();for(const i of this._convexSets)for(const s of i.planes)s.appendIntersectionRadians(t,n);return t.sweep.radiansArrayToPositivePeriodicFractions(n),ee.selectIntervals01(t,n,this,e)}announceClippedCurveIntervals(t,e){const n=fe._clipFractionArray;n.clear();const i=[];for(const s of this._convexSets)for(const r of s.planes)t.appendPlaneIntersectionPoints(r,i);for(const s of i)n.push(s.fraction);return ee.selectIntervals01(t,n,this,e)}computePlanePlanePlaneIntersectionsInAllConvexSets(t,e,n,i=!0){let s=0;for(const r of this._convexSets)s+=r.computePlanePlanePlaneIntersections(t,e,n,i);return s}multiplyPlanesByMatrix4d(t,e=!0,n=!0){if(e){const i=t.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._convexSets)i.multiplyPlanesByMatrix4d(t,!1,n);return!0}setInvisible(t){for(const e of this._convexSets)e.setInvisible(t)}addOutsideZClipSets(t,e,n){if(e){const i=vt.createEmpty();i.addZClipPlanes(t,void 0,e),this._convexSets.push(i)}if(n){const i=vt.createEmpty();i.addZClipPlanes(t,n),this._convexSets.push(i)}}takeConvexSets(t){let e;for(;(e=t._convexSets.pop())!==void 0;)this._convexSets.push(e)}appendPolygonClip(t,e,n,i){const s=n.length,r=e.length;let o=[i.grabAndFill(t)],a=[],c,l;for(const d of this._convexSets){for(;(l=o.pop())!==void 0;)d.appendPolygonClip(l,e,a,i),i.dropToCache(l);c=a,a=o,o=c}for(;(l=o.pop())!==void 0;)n.push(l);n.length===s?ee.restoreSingletonInPlaceOfMultipleShards(e,r,t,i):e.length===r&&ee.restoreSingletonInPlaceOfMultipleShards(n,s,t,i)}}class Qe{_origin;_direction;constructor(t,e){this._origin=t,this._direction=e}set(t,e){this._origin.setFrom(t),this._direction.setFrom(e)}static createZero(t){return t?(t.origin.setZero(),t.direction.setZero(),t):new Qe(D.createZero(),Q.createZero())}static createOriginAndTarget(t,e,n){return n?(n._origin.setFrom(t),n._direction.set(e.x-t.x,e.y-t.y),n):new Qe(D.createFrom(t),Q.createStartEnd(t,e))}static createOriginAndDirection(t,e,n){return n?(n.set(t,e),n):new Qe(D.createFrom(t),Q.createFrom(e))}static createOriginAndDirectionCapture(t,e,n){return n?(n._origin=t,n._direction=e,n):new Qe(t,e)}get origin(){return this._origin}get direction(){return this._direction}parallelRay(t,e){return e?(this._origin.addForwardLeft(0,t,this._direction,e._origin),e._direction.setFrom(this._direction),e):new Qe(this._origin.addForwardLeft(0,t,this._direction),this._direction.clone())}ccwPerpendicularRay(t){return t?(t._origin.setFrom(this._origin),this._direction.rotate90CCWXY(t._direction),t):new Qe(this._origin.clone(),this._direction.rotate90CCWXY())}cwPerpendicularRay(t){return t?(t._origin.setFrom(this._origin),this._direction.rotate90CWXY(t._direction),t):new Qe(this._origin.clone(),this._direction.rotate90CWXY())}normalizeDirectionInPlace(t=1,e=0){return this._direction.normalize(this._direction)?!0:(this._direction.x=t,this._direction.y=e,!1)}intersectUnboundedLine(t,e){const n=Q.createStartEnd(t,e),s=Q.createStartEnd(t,this._origin).crossProduct(n),r=this._direction.crossProduct(n),o=f.conditionalDivideFraction(-s,r),a=o!==void 0;return{hasIntersection:a,fraction:a?o:0,cross:r}}intersectionWithRange2d(t,e){if(t.isNull)return ct.createNull(e);const n=ct.createXX(-f.largeCoordinateResult,f.largeCoordinateResult,e);return n.clipLinearMapToInterval(this.origin.x,this.direction.x,t.low.x,t.high.x),n.clipLinearMapToInterval(this.origin.y,this.direction.y,t.low.y,t.high.y),n}projectionFraction(t){return this._origin.vectorTo(t).fractionOfProjectionToVector(this._direction)}perpendicularProjectionFraction(t){const e=this._direction.crossProduct(this._origin.vectorTo(t)),n=this._direction.magnitudeSquared();return f.safeDivideFraction(e,n,0)}fractionToPoint(t,e){return this._origin.plusScaled(this._direction,t,e)}}class Kt{_voronoiGraph;_inputGraph;_inputGraphIsTriangulation;_inputGraphRange;_idToIndexMap;_circumcenterMap;_circumcenterRange;_isCurveBased;_superFaceMask;static _workXY0=D.createZero();static _workXY1=D.createZero();static _workRay=Qe.createZero();static _workArc=N.createUnitCircle();constructor(t,e=!1){this._voronoiGraph=new be,this._inputGraph=t,this._inputGraphRange=Vt.graphRangeXY(t),this._idToIndexMap=t.constructIdToVertexIndexMap(),this._circumcenterMap=new Map,this._inputGraphIsTriangulation=e?!1:this.populateCircumcenters(this._circumcenterMap),this._circumcenterRange=Rt.createArray(Array.from(this._circumcenterMap.values())),this._isCurveBased=!1,this._superFaceMask=M.NULL_MASK}get getInputGraph(){return this._inputGraph}get getInputGraphRange(){return this._inputGraphRange}get getVoronoiGraph(){return this._voronoiGraph}get isCurveBased(){return this._isCurveBased}get getSuperFaceMask(){return this._superFaceMask}get isValid(){return this._inputGraph.allHalfEdges.length<2||this._idToIndexMap.size===0?!1:this._inputGraphIsTriangulation?this._circumcenterMap.size>0:!0}static addEdgeWithEdgeTags(t,e,n,i,s){return t.addEdgeXY(e.x,e.y,n.x,n.y,i,s)}static addEdgeWithFaceTags(t,e,n,i,s){return t.addEdgeXY(e.x,e.y,n.x,n.y,void 0,void 0,i,s)}getTriangleId(t){return t!==t.faceSuccessor.faceSuccessor.faceSuccessor?-1:Math.min(t.id,t.faceSuccessor.id,t.facePredecessor.id)}populateCircumcenters(t){t.clear();let e=!0;const n=y.createZero(),i=y.createZero(),s=y.createZero();return this._inputGraph.announceFaceLoops((r,o)=>{if(o.isMaskSet(M.EXTERIOR))return!0;if(o.countEdgesAroundFace()!==3)return e=!1;o.getPoint3d(n),o.faceSuccessor.getPoint3d(i),o.facePredecessor.getPoint3d(s),n.z=i.z=s.z=0;const a=N.createCircularStartMiddleEnd(n,i,s,Kt._workArc);return a instanceof N&&t.set(this.getTriangleId(o),a.center),!0}),e||t.clear(),e}getTriangleEdgeBisector(t,e,n){const i=t,s=t.faceSuccessor,r=t.facePredecessor,o=1/3,a=D.createAdd2ScaledXY(i.x,i.y,.5,s.x,s.y,.5),c=D.createAdd3ScaledXY(i.x,i.y,o,s.x,s.y,o,r.x,r.y,o),l=Q.createStartEnd(e,a);a.dotVectorsToTargets(e,c)<0&&l.negate(l);const d=Qe.createOriginAndDirectionCapture(D.createFrom(e),l,Kt._workRay),h=n.intersect(d);if(!(h!==void 0&&h.length===2)||h[0]<=0&&h[1]<=0||h[0]>=1&&h[1]>=1)return;const m=d.fractionToPoint(f.clamp(h[0],0,1),Kt._workXY0),p=d.fractionToPoint(h[1],Kt._workXY1);return{start:m,end:p}}addVoronoiEdgeForDelaunayBoundaryEdge(t,e){const n=this.getTriangleId(t);if(n<0)return!1;const i=this._circumcenterMap.get(n);if(!i)return!0;const s=this.getTriangleEdgeBisector(t,i,e);if(!s)return!0;const r=this._idToIndexMap.get(t.edgeMate.id),o=this._idToIndexMap.get(t.id);return Kt.addEdgeWithFaceTags(this._voronoiGraph,s.start,s.end,r,o),!0}addVoronoiEdgeForDelaunayInteriorEdge(t,e,n){const i=this.getTriangleId(t),s=this.getTriangleId(t.edgeMate);if(i<0||s<0)return!1;const r=this._circumcenterMap.get(i),o=this._circumcenterMap.get(s);if(!r&&!o)return!0;if(!r||!o)return!r&&t.findMaskAroundFace(M.BOUNDARY_EDGE)?this.addVoronoiEdgeForDelaunayBoundaryEdge(t.edgeMate,e):!o&&t.edgeMate.findMaskAroundFace(M.BOUNDARY_EDGE)?this.addVoronoiEdgeForDelaunayBoundaryEdge(t,e):!1;if(ws.almostEqual(r,o,n))return!0;const a=Qe.createOriginAndTarget(r,o,Kt._workRay),c=e.intersect(a);if(!(c!==void 0&&c.length===2)||c[0]<=0&&c[1]<=0||c[0]>=1&&c[1]>=1)return!0;const d=a.fractionToPoint(f.clamp(c[0],0,1),Kt._workXY0),h=a.fractionToPoint(f.clamp(c[1],0,1),Kt._workXY1),g=this._idToIndexMap.get(t.edgeMate.id),m=this._idToIndexMap.get(t.id);return Kt.addEdgeWithFaceTags(this._voronoiGraph,d,h,g,m),!0}populateMasksAndFaceTags(){this._voronoiGraph.announceFaceLoops((t,e)=>{let n,i=e;do n=i.faceTag,i=i.faceSuccessor;while(n===void 0&&i!==e);return n!==void 0?e.announceEdgesInFace(s=>s.faceTag=n):e.announceEdgesInFace(s=>{s.setMask(M.EXTERIOR),s.setMaskAroundEdge(M.BOUNDARY_EDGE)}),!0})}static createFromDelaunayGraph(t,e=f.smallMetricDistance,n){const i=new Kt(t);if(!i.isValid)return;let s=!0;const r=new pa(i._inputGraphRange,n||i._circumcenterRange);if(i._inputGraph.announceEdges((o,a)=>a.isMaskSet(M.BOUNDARY_EDGE)?(a.isMaskSet(M.EXTERIOR)&&(a=a.edgeMate),s=i.addVoronoiEdgeForDelaunayBoundaryEdge(a,r)):s=i.addVoronoiEdgeForDelaunayInteriorEdge(a,r,e)),!!s)return r.addEdgesToGraph(i._voronoiGraph),Je.splitIntersectingEdges(i._voronoiGraph,e),Je.clusterAndMergeXYTheta(i._voronoiGraph,void 0,e),i.populateMasksAndFaceTags(),i}static createColinearXYGraph(t){const e=new be;let n;if(Array.isArray(t)||(n=Array.from(t.values()),t=Array.from(t.keys())),t.length<2)return e;let i=this.addEdgeWithEdgeTags(e,t[0],t[1],n?n[0]:0,n?n[1]:0);for(let s=1;s<t.length-1;s++){const r=this.addEdgeWithEdgeTags(e,t[s],t[s+1],n?n[s]:0,n?n[s+1]:0);V.pinch(i.faceSuccessor,r),i=r}return e.setMask(M.EXTERIOR|M.BOUNDARY_EDGE),e}static getEdgeBisector(t,e){const n=t,i=t.faceSuccessor,s=D.createAdd2ScaledXY(n.x,n.y,.5,i.x,i.y,.5),r=Q.createStartEnd(n,i);[r.x,r.y]=[-r.y,r.x];const o=Qe.createOriginAndDirectionCapture(s,r),a=e.intersect(o);return a!==void 0&&a.length>1&&a[0]<0&&a[1]>0?{start:o.fractionToPoint(a[0]),end:o.fractionToPoint(a[1])}:void 0}static createFromColinearGraph(t,e=f.smallMetricDistance,n){const i=new Kt(t,!0);if(!i.isValid)return;let s=!0;const r=new pa(i._inputGraphRange,n);if(i._inputGraph.announceEdges((o,a)=>{const c=Kt.getEdgeBisector(a,r);if(!c)return s=!1;const l=i._idToIndexMap.get(a.id),d=i._idToIndexMap.get(a.edgeMate.id);return this.addEdgeWithFaceTags(i._voronoiGraph,c.start,c.end,l,d),!0}),!!s)return r.addEdgesToGraph(i._voronoiGraph),Je.splitIntersectingEdges(i._voronoiGraph,e),Je.clusterAndMergeXYTheta(i._voronoiGraph,void 0,e),i.populateMasksAndFaceTags(),i}static createFromPoints(t,e=f.smallMetricDistance,n){const i=new jn(f.compareXY(e),En.Retain,r=>r.clone());t.forEach(r=>i.insert(r));const s=i.extractArray();if(!(s.length<2))if(gn.isColinear(s,e,!0)){const r=Kt.createColinearXYGraph(s);return r?Kt.createFromColinearGraph(r,e,n):void 0}else{const r=B.createTriangulatedGraphFromPoints(s,void 0,e);return r?Kt.createFromDelaunayGraph(r,e,n):void 0}}static pushInteriorStrokePoints(t,e,n,i,s){const r=F.create();e.emitStrokes(r,i);let o;const a=r.numPoints();for(let d=1;d<a-1;++d)(o=r.pointAt(d,s))&&t.insert(o,n);const c=(a>2?r.pointAt(1):void 0)??e.fractionToPoint(.5),l=(a>2?r.pointAt(a-2):void 0)??c;return{p0:c,p1:l}}static computeCircleIntersection(t,e,n,i){const s=He.intersectionProjectedXYPairs(void 0,t,!1,e,!1,i);if(s.length)return s.length>1&&(n?s.sort((r,o)=>r.detailB.fraction-o.detailB.fraction):s.sort((r,o)=>o.detailB.fraction-r.detailB.fraction)),s[0].detailB.point}static pushSymmetricPointPairAtJoint=(t,e,n,i,s)=>{const r=N.createUnitCircle(s),o=n.cp.startPoint(r.centerRef),a=.5*Math.min(e.pt.distance(o),n.pt.distance(o));r.matrixRef.setAt(0,0,a),r.matrixRef.setAt(1,1,a);const c=this.computeCircleIntersection(r,e.cp,!1,i),l=this.computeCircleIntersection(r,n.cp,!0,i);return!c||!l?!1:(t.set(c,e.i),t.set(l,n.i),!0)};static createStrokePointsWithIndices(t,e,n=f.smallMetricDistance){const i=t.children;if(!i)return;const s=i.length;if(s<2)return;e=e?.clone()??Zt.createForCurves(),(!e.minStrokesPerPrimitive||e.minStrokesPerPrimitive<2)&&(e.minStrokesPerPrimitive=2);const r=y.createZero(),o=N.createUnitCircle(Kt._workArc),a=U.createXYXY(0,0,0,0),c=O.createZero();let l,d,h;const g=(x,_)=>x instanceof F?x.getIndexedSegment(_,a):_?void 0:x,m=new kr(f.compareXY(n),x=>x.clone()),p=t.isPhysicallyClosedCurve(n,!0);p||(t.startPoint(r)&&m.insert(r,0),t.endPoint(r)&&m.insert(r,s-1));for(let x=0;x<s;x++){let _=i[x];Gn.isColinear(_,{colinearRay:c,xyColinear:!0,maxDeviation:n})&&(_=U.createCapture(_.startPoint(),_.endPoint()));let I=0;for(let v;v=g(_,I);I++){h=this.pushInteriorStrokePoints(m,v,x,e,r);const S={pt:h.p0,cp:v,i:x};d&&this.pushSymmetricPointPairAtJoint(m,d,S,n,o),l=p&&x===0&&I===0?S:l,d={pt:h.p1,cp:v,i:x}}}return d&&l&&this.pushSymmetricPointPairAtJoint(m,d,l,n,o),m}static createGraphFromPointsWithIndices(t,e){if(t.size<2)return;let n,i=!1;const s=y.createZero(),r=Array.from(t.keys());return gn.isColinear(r,e,!0)?(n=Kt.createColinearXYGraph(t),i=!1):(n=B.createTriangulatedGraphFromPoints(r,void 0,.1*e),(i=n!==void 0)&&n.announceVertexLoops((o,a)=>{const c=t.get(a.getPoint3d(s));return c!==void 0&&a.announceEdgesAroundVertex(l=>l.edgeTag=c),!0})),n?{graph:n,isTriangulation:i}:void 0}static createFromCurveChain(t,e,n=f.smallMetricDistance,i){const s=Kt.createStrokePointsWithIndices(t,e);if(!s)return;const r=Kt.createGraphFromPointsWithIndices(s,n);if(!r)return;const o=r.isTriangulation?Kt.createFromDelaunayGraph(r.graph,n,i):Kt.createFromColinearGraph(r.graph,n,i);return o&&(o._isCurveBased=!0),o}isEdgeInVoronoiSuperFace(t,e){if(!this._isCurveBased||t.faceTag===void 0)return!1;const n=this._inputGraph.allHalfEdges[t.faceTag].edgeTag;if(t.edgeMate.isMaskSet(M.EXTERIOR))return e===void 0?!0:e===n;if(t.edgeMate.faceTag===void 0)return!1;const i=this._inputGraph.allHalfEdges[t.edgeMate.faceTag].edgeTag;return e!==void 0?n===e&&i!==e:n!==i}findNextVoronoiSuperFaceStart(){if(!this._isCurveBased)return;let t;return this._voronoiGraph.announceEdges((e,n)=>n.isMaskSet(M.EXTERIOR)||n.isMaskSet(this._superFaceMask)||!this.isEdgeInVoronoiSuperFace(n)?!0:(t=n,!1)),t}collectVoronoiSuperFace(t){if(!this._isCurveBased||t.faceTag===void 0)return;const e=[],n=this._inputGraph.allHalfEdges[t.faceTag].edgeTag;return t.announceEdgesInSuperFace(s=>!this.isEdgeInVoronoiSuperFace(s,n),s=>{e.push(s),s.setMask(this._superFaceMask)})&&e.length>2?e:void 0}computeVoronoiSuperFaces(t){if(!this._isCurveBased||t<1)return;const e=[];this._superFaceMask===M.NULL_MASK&&(this._superFaceMask=this._voronoiGraph.grabMask(!1)),this._voronoiGraph.clearMask(this._superFaceMask);for(let n=0;n<t;n++){const i=this.findNextVoronoiSuperFaceStart();if(!i)break;const s=this.collectVoronoiSuperFace(i);if(!s)return;e.push(s)}return e.sort((n,i)=>{const s=this._inputGraph.allHalfEdges[n[0].faceTag].edgeTag,r=this._inputGraph.allHalfEdges[i[0].faceTag].edgeTag;return s-r}),e.length>0?e:void 0}generateClippersFromVoronoiSuperFaces(t){if(!this._isCurveBased||this._superFaceMask===M.NULL_MASK)return;const e=[],n=this._voronoiGraph.grabMask(),i=this._voronoiGraph.grabMask(),s=(r,o)=>r.announceEdgesInSuperFace(a=>!a.isMaskSet(this._superFaceMask),a=>a.edgeMate.applyMask(n,o));B.triangulateAllInteriorFaces(this._voronoiGraph,!1,!0),Vt.expandConvexFaces(this._voronoiGraph,this._superFaceMask);for(const r of t){if(r.length<3){e.length=0;break}const o=[];if(!s(r[0],!1)){e.length=0;break}On.exploreComponent(r[0],i,n,void 0,o),s(r[0],!0);const a=[];for(const c of o){const l=[];c.announceEdgesInFace(d=>{if(!d.isMaskSet(M.BOUNDARY_EDGE)){const h=H.createMidPointEdgeXY(d,d.faceSuccessor);h&&l.push(h)}}),l.length===c.countMaskAroundFace(M.BOUNDARY_EDGE,!1)&&a.push(vt.createPlanes(l))}a.length===o.length&&e.push(fe.createConvexSets(a))}return this._voronoiGraph.dropMask(i),this._voronoiGraph.dropMask(n),e.length===t.length?e:void 0}}Kt||(Kt={});class pa{bbox;constructor(t,e){if(this.bbox=Rt.createFrom(t),e&&this.bbox.union(e,this.bbox),!this.bbox.isNull&&!this.bbox.isSinglePoint){const n=.02473*(this.bbox.xLength()+this.bbox.yLength());this.bbox.expandInPlace(n)}}intersect(t){const e=t.intersectionWithRange2d(this.bbox);if(!e.isNull)return e.isSinglePoint?[e.low]:[e.low,e.high]}addEdgesToGraph(t){t.addEdgeXY(this.bbox.low.x,this.bbox.low.y,this.bbox.high.x,this.bbox.low.y),t.addEdgeXY(this.bbox.high.x,this.bbox.low.y,this.bbox.high.x,this.bbox.high.y),t.addEdgeXY(this.bbox.high.x,this.bbox.high.y,this.bbox.low.x,this.bbox.high.y),t.addEdgeXY(this.bbox.low.x,this.bbox.high.y,this.bbox.low.x,this.bbox.low.y)}}class Be{static advanceIntervalDifference(t,e,n,i){const s=e.length;let r=t.low,o=t.high;for(;n<s;){const a=e[n];if(a.high<r)n++;else if(a.high<=o)a.low>r&&i.push(ct.createXX(r,a.low)),r=a.high,n++;else{a.low<o&&(o=a.low);break}}return r<o&&i.push(ct.createXX(r,o)),i}static differenceSorted(t,e){const n=t.length,i=0,s=[];for(let r=0;r<n;r++)Be.advanceIntervalDifference(t[r],e,i,s);return s}static advanceIntervalIntersection(t,e,n){return e.low>t.high?!0:e.high>=t.high?(n.push(ct.createXX(e.low,t.high)),!0):(n.push(ct.createXX(e.low,e.high)),!1)}static intersectSorted(t,e){let n=0,i=0;const s=t.length,r=e.length,o=[];for(;n<s&&i<r;){const a=t[n],c=e[i];a.low<=c.low?Be.advanceIntervalIntersection(a,c,o)?n++:i++:Be.advanceIntervalIntersection(c,a,o)?i++:n++}return o}static advanceIntervalUnion(t,e,n){if(n>=e.length)return!1;const i=e[n];return i.low>t.high?!1:(i.high>t.high&&(t.high=i.high),!0)}static unionSorted(t,e){const n=t.length,i=e.length;let s=0,r=0;const o=[];for(;s<n&&r<i;){const a=t[s],c=e[r];let l;a.low<=c.low?(l=a.clone(),s++):(l=c.clone(),r++);let d=!0;do{const h=Be.advanceIntervalUnion(l,t,s),g=Be.advanceIntervalUnion(l,e,r);h&&s++,g&&r++,h||g||(d=!1)}while(d);o.push(l)}for(;s<n;)o.push(t[s++]);for(;r<i;)o.push(e[r++]);return o}static paritySorted(t,e){const n=[];for(const i of t)n.push(i.clone());for(const i of e)n.push(i.clone());return n.sort(uo),Be.simplifySortParity(n,!0),n}static sort(t){t.sort(uo)}static simplifySortUnion(t,e=!1){if(t.length<2)return;t.sort(uo);let n=0;for(let i=1;i<t.length;i++)t[i].low<=t[n].high?t[i].high>t[n].high&&(t[n].high=t[i].high):(n++,t[n].setFrom(t[i]));if(t.length=n+1,e){n=-1;for(let i=0;i<t.length;i++)t[i].low<t[i].high&&n<i&&t[++n].setFrom(t[i])}}static simplifySortParity(t,e=!1){const n=[];for(const a of t)a.low!==a.high&&(n.push(a.low),n.push(a.high));const i=n.length;n.sort((a,c)=>a<c?-1:a>c?1:0);let s=0,r,o;for(let a=0;a<i;a+=2)if(r=n[a],o=n[a+1],!e)ct.createXX(r,o,t[s++]);else{for(;a+2<i&&n[a+2]===o;)a+=2,o=n[a+1];o>r&&ct.createXX(r,o,t[s++])}t.length=s}static testUnion(t,e){return this.countContainingRanges(t,e)>0}static testParity(t,e){let n=!1;for(const i of t)i.containsX(e)&&(n=!n);return n}static countContainingRanges(t,e){let n=0;for(const i of t)i.containsX(e)&&n++;return n}static getBreaks(t,e,n=!1,i=!1,s=!0){e||(e=new Ft(2*t.length)),s&&e.clear();for(const r of t)e.push(r.low),e.push(r.high);return n&&e.sort(),i&&e.compressAdjacentDuplicates(),e}static appendFractionalPoints(t,e,n,i,s,r,o,a){const c=t.length;if(c>0){e!==void 0&&a.push(t[0].fractionToPoint(e));for(let l=0;l<c;l++)n!==void 0&&(i||t[l].low!==t[l].high)&&a.push(t[l].fractionToPoint(n)),l>1&&s!==void 0&&(r||t[l].low!==t[l].high)&&a.push(f.interpolate(t[l-1].high,s,t[l].low));o!==void 0&&a.push(t[c-1].fractionToPoint(o))}return a}static firstLowToLastHigh(t){return t.length===0?ct.createNull():ct.createXX(t[0].low,t[t.length-1].high)}static sumLengths(t){let e=0;for(const n of t)e+=n.length();return e}static isSorted(t,e=!0){const n=t.length;if(e){for(let i=0;i+1<n;i++)if(t[i].high>=t[i+1].low)return!1}else for(let i=0;i+1<n;i++)if(t[i].high>t[i+1].low)return!1;return!0}}function uo(u,t){return u.low<t.low?-1:u.low>t.low?1:u.high<t.high?-1:u.high>t.high?1:0}class Un{points=[];planes=vt.createEmpty();children=[];startIdx=-1;numPoints=-1;constructor(){}static createWithIndices(t,e,n){return n=n||new Un,n.startIdx=t,n.numPoints=e,n.children.length=0,n}static createTreeForPolygon(t,e){return e=e||new Un,e.empty(),is.createPointsRef(t).buildHullTree(e),e}static createHullAndInletsForPolygon(t,e){return e=e||new Un,e.empty(),is.createPointsRef(t).buildHullAndInletsForPolygon(e),e}extractLoopsGo(t){t.push(re.clonePoint3dArray(this.points));for(const e of this.children)e.extractLoopsGo(t)}extractLoops(){const t=[];return this.extractLoopsGo(t),t}empty(){this.points.length=0,this.planes.planes.length=0,this.children.length=0,this.startIdx=-1,this.numPoints=-1}clone(t){t=t||new Un;for(const e of this.points)t.points.push(e.clone());t.planes=vt.createEmpty();for(const e of this.planes.planes)t.planes.planes.push(e.clone());for(const e of this.children)t.children.push(e.clone());return t.startIdx=this.startIdx,t.numPoints=this.numPoints,t}addEmptyChild(t,e){const n=Un.createWithIndices(t,e);this.children.push(n)}addPlane(t){this.planes.addPlaneToConvexSet(t)}isPointOnOrInside(t){if(!this.planes.isPointOnOrInside(t,0))return!1;for(const n of this.children)if(n.isPointOnOrInside(t))return!1;return!0}captureConvexClipPlaneSetAsVoid(t){this.children.push(t)}appendCurvePrimitiveClipIntervals(t,e,n){new er().appendSingleClipPrimitive(this,t,e,n)}appendCurveCollectionClipIntervals(t,e,n){new er().appendCurveCollectionClip(this,t,e,n)}appendPolygonClip(t,e,n,i){const s=n.length,r=this.planes.clipInsidePushOutside(t,n,i);if(r===void 0)ee.restoreSingletonInPlaceOfMultipleShards(n,s,t,i);else{let o=[r],a=[],c,l;for(const d of this.children){for(a.length=0;(l=o.pop())!==void 0;)d.appendPolygonClip(l,n,a,i),i.dropToCache(l);c=a,a=o,o=c}for(;(l=o.pop())!==void 0;)e.push(l)}}depth(){let e=0;for(const n of this.children)e=Math.max(e,n.depth());return 1+e}}class is{_points=[];_stack=[];constructor(){}static createPointsRef(t,e){return e=e||new is,e._points=t,nt.areaXY(t)<0&&e._points.reverse(),e._points[e._points.length-1].isAlmostEqualMetric(e._points[0])&&e._points.pop(),e}get period(){return this._points.length}indexAfter(t){return(t+1)%this._points.length}indexBefore(t){return(t+this._points.length-1)%this._points.length}pushIndex(t){this._stack.push(t)}static cross(t,e,n){return t.crossProductToPointsXY(e,n)}cyclicStackPoint(t){let e;const n=this._stack;return t>0?e=t:e=t+10*n.length,e=e%n.length,this._points[n[e]]}signFromStackTip(t,e){const n=this.cyclicStackPoint(-2),i=this.cyclicStackPoint(-1),s=this._points[t];return e*is.cross(n,i,s)>=0?1:-1}get indexOfMaxX(){let t=0;const e=this._points,n=this._points.length;for(let i=1;i<n;i++)e[i].x>e[t].x&&(t=i);return t}extendHullChain(t,e,n){for(;this._stack.length>1&&this.signFromStackTip(t,e)<0;)this._stack.pop();n&&this.pushIndex(t)}collectHullChain(t,e,n){if(this._stack.length=0,e>2){let i=t;for(let s=0;s<e;s++)this.extendHullChain(i,n,!0),i=this.indexAfter(i)}}collectHullPointsInArray(t,e,n,i){if(t.length=0,n>2){let s=e;for(let r=0;r<n;r++)t.push(this._points[s]),s=this.indexAfter(s)}}buildHullTreeGo(t,e,n=!0){this.collectHullChain(t.startIdx,t.numPoints,e?1:-1),t.points.length=0;const i=this._stack,s=this._points,r=i.length;for(let o=0;o<r;o++){const a=i[o];if(t.points.push(s[a]),o+1<r){let c=i[o+1];if(c===this.indexAfter(a)){const l=H.createEdgeAndUpVector(s[a],s[c],P.create(0,0,1),A.createRadians(0));l!==void 0&&(e&&l.negateInPlace(),t.addPlane(l))}else c<a&&(c+=this.period),t.addEmptyChild(a,c-a+1)}}if(n)for(const o of t.children)this.buildHullTreeGo(o,!e);else for(const o of t.children)this.collectHullPointsInArray(o.points,o.startIdx,o.numPoints,e?-1:1);return!0}buildHullAndInletsForPolygon(t){return Un.createWithIndices(this.indexOfMaxX,this.period+1,t),this.buildHullTreeGo(t,!0,!1)}buildHullTree(t){return Un.createWithIndices(this.indexOfMaxX,this.period+1,t),this.buildHullTreeGo(t,!0)}}class er{_curve;_intervalStack;_stackDepth;constructor(){this._stackDepth=0,this._intervalStack=[]}setCurveRef(t){this._curve=t}popSegmentFrame(){this._stackDepth>0&&(this._topOfStack.length=0,this._stackDepth-=1)}clearSegmentStack(){for(;this._stackDepth>0;)this.popSegmentFrame()}pushEmptySegmentFrame(){for(this._stackDepth+=1;this._intervalStack.length<this._stackDepth;)this._intervalStack.push([]);this._topOfStack.length=0}get _topOfStack(){return this._intervalStack[this._stackDepth-1]}set _topOfStack(t){const e=this._stackDepth;e>0&&(this._intervalStack[e-1]=t)}stackEntry(t){return t<=this._stackDepth?this._intervalStack[this._stackDepth-1-t]:[]}isTopOfStackEmpty(){return this._topOfStack.length===0}static _fractionIntervals=[];appendSingleClipToStack(t,e){const n=er._fractionIntervals;if(this._curve instanceof U){const i=this._curve;let s=0,r=0;return i.announceClipIntervals(t,(o,a,c)=>{s=o,r=a})&&e.push(ct.createXX(s,r)),!0}else if(this._curve instanceof N){const i=this._curve;n.length=0,i.announceClipIntervals(t,(s,r,o)=>{n.push(s),n.push(r)});for(let s=0;s<n.length;s+=2)e.push(ct.createXX(n[s],n[s+1]));return!0}else if(this._curve instanceof F&&this._curve.points.length>1){const i=this._curve;let s=0,r=0;const o=i.points.length,a=1/(o-1);for(let c=0;c<o-1;c++)U.create(i.points[c],i.points[c+1]).announceClipIntervals(t,(d,h,g)=>{s=d,r=h})&&e.push(ct.createXX((c+s)*a,(c+r)*a));return!0}else if(this._curve instanceof me){const i=this._curve;n.length=0,i.announceClipIntervals(t,(s,r,o)=>{n.push(s),n.push(r)});for(let s=0;s<n.length;s+=2)e.push(ct.createXX(n[s],n[s+1]));return!0}return!1}recurse(t){if(this.pushEmptySegmentFrame(),this.appendSingleClipToStack(t.planes,this._topOfStack),Be.sort(this._topOfStack),!this.isTopOfStackEmpty())for(const e of t.children){if(this.recurse(e),this.isTopOfStackEmpty())this.popSegmentFrame();else{const n=Be.differenceSorted(this.stackEntry(1),this.stackEntry(0));this.popSegmentFrame(),this._topOfStack=n}if(this.isTopOfStackEmpty())break}}appendSingleClipPrimitive(t,e,n,i){if(this.setCurveRef(e),this.clearSegmentStack(),this.recurse(t),this._stackDepth!==1)return;const s=this._topOfStack;for(const r of s){const o=r.low,a=r.high,c=e.fractionToPoint(o),l=e.fractionToPoint(a);n.push(Ot.createCapture(Y.createCurveFractionPoint(e,o,c),Y.createCurveFractionPoint(e,a,l)))}this.popSegmentFrame()}appendCurveCollectionClip(t,e,n,i){for(const s of e.children)s instanceof st?this.appendSingleClipPrimitive(t,s,n,i):s instanceof ut&&this.appendCurveCollectionClip(t,s,n,i)}}var vn;(function(u){u[u.None=0]="None",u[u.XLow=1]="XLow",u[u.XHigh=2]="XHigh",u[u.YLow=4]="YLow",u[u.YHigh=8]="YHigh",u[u.ZLow=16]="ZLow",u[u.ZHigh=32]="ZHigh",u[u.XAndY=15]="XAndY",u[u.All=63]="All"})(vn||(vn={}));class Bn{_clipPlanes;_invisible;fetchClipPlanesRef(){return this.ensurePlaneSets(),this._clipPlanes}get invisible(){return this._invisible}constructor(t,e=!1){this._clipPlanes=t,this._invisible=e}static createCapture(t,e=!1){let n;return t instanceof fe&&(n=t),t instanceof vt&&(n=fe.createConvexSets([t])),new Bn(n,e)}toJSON(){const t={};return this._clipPlanes&&(t.clips=this._clipPlanes.toJSON()),this._invisible&&(t.invisible=!0),{planes:t}}arePlanesDefined(){return this._clipPlanes!==void 0}clone(){const t=this._clipPlanes?this._clipPlanes.clone():void 0;return new Bn(t,this._invisible)}ensurePlaneSets(){}pointInside(t,e=f.smallMetricDistanceSquared){this.ensurePlaneSets();let n=!0;return this._clipPlanes&&(n=this._clipPlanes.isPointOnOrInside(t,e)),n}isPointOnOrInside(t,e=f.smallMetricDistanceSquared){this.ensurePlaneSets();let n=!0;return this._clipPlanes&&(n=this._clipPlanes.isPointOnOrInside(t,e)),n}announceClippedSegmentIntervals(t,e,n,i,s){this.ensurePlaneSets();let r=!1;return this._clipPlanes&&(r=this._clipPlanes.announceClippedSegmentIntervals(t,e,n,i,s)),r}announceClippedArcIntervals(t,e){this.ensurePlaneSets();let n=!1;return this._clipPlanes&&(n=this._clipPlanes.announceClippedArcIntervals(t,e)),n}announceClippedCurveIntervals(t,e){this.ensurePlaneSets();let n=!1;return this._clipPlanes&&(n=this._clipPlanes.announceClippedCurveIntervals(t,e)),n}multiplyPlanesByMatrix4d(t,e=!0,n=!0){if(e){const i=t.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}return this._clipPlanes&&this._clipPlanes.multiplyPlanesByMatrix4d(t),!0}transformInPlace(t){return this._clipPlanes&&this._clipPlanes.transformInPlace(t),!0}setInvisible(t){this._invisible=t}containsZClip(){const t=this.fetchClipPlanesRef();if(t!==void 0){for(const e of t.convexSets)for(const n of e.planes)if(Math.abs(n.inwardNormalRef.z)>1e-6&&Math.abs(n.distance)!==Number.MAX_VALUE)return!0}return!1}classifyPointContainment(t,e=!0){this.ensurePlaneSets();const n=this._clipPlanes;let i=oe.StronglyInside;return n&&(i=n.classifyPointContainment(t,!1)),i}static fromJSON(t){if(!t)return;const e=Sn.fromClipShapeJSON(t);return e||Bn.fromJSONClipPrimitive(t)}static fromJSONClipPrimitive(t){const e=t?.planes;if(!e)return;const n=e.clips?fe.fromJSON(e.clips):void 0,i=e.invisible!==void 0?e.invisible:!1;return new Bn(n,i)}}class fo{pointA;pointB;normal;constructor(t,e,n,i){this.pointA=y.create(t.x,t.y,i),this.pointB=y.create(e.x,e.y,i),this.normal=n}static makeUnitPerpendicularToBisector(t,e,n){let i=e.normal.minus(t.normal);if(!(i.normalize(i)===void 0&&(i=P.createStartEnd(t.pointA,e.pointB),i.normalize(i)===void 0)))return n&&i.scale(-1,i),i}}class Sn extends Bn{_polygon;_zLow;_zHigh;_isMask;_transformFromClip;_transformToClip;constructor(t=[],e,n,i,s=!1,r=!1){super(void 0,r),this._isMask=!1,this._polygon=t,this.initSecondaryProps(s,e,n,i)}get invisible(){return this._invisible}get transformFromClip(){return this._transformFromClip}get transformToClip(){return this._transformToClip}get transformValid(){return this._transformFromClip!==void 0}get zLowValid(){return this._zLow!==void 0}get zHighValid(){return this._zHigh!==void 0}get transformIsValid(){return this._transformFromClip!==void 0}hasZLow(){return this._zLow!==void 0}hasZHigh(){return this._zHigh!==void 0}hasTransformFromClip(){return this._transformFromClip!==void 0}hasTransformToClip(){return this._transformToClip!==void 0}hasTransforms(){return this._transformFromClip!==void 0&&this._transformToClip!==void 0}get zLow(){return this._zLow}get zHigh(){return this._zHigh}get polygon(){return this._polygon}get isMask(){return this._isMask}setPolygon(t){t[0].isAlmostEqual(t[t.length-1])||t.push(t[0].clone()),this._polygon=t}ensurePlaneSets(){this._clipPlanes===void 0&&(this._clipPlanes=fe.createEmpty(),this.parseClipPlanes(this._clipPlanes),this._transformFromClip&&this._clipPlanes.transformInPlace(this._transformFromClip))}initSecondaryProps(t,e,n,i){this._isMask=t,this._zLow=e,this._zHigh=n,i!==void 0?(this._transformFromClip=i,this._transformToClip=i.inverse()):(this._transformFromClip=X.createIdentity(),this._transformToClip=X.createIdentity())}toJSON(){const t={points:this._polygon.map(e=>e.toJSON())};return this.invisible&&(t.invisible=!0),this._transformFromClip&&!this._transformFromClip.isIdentity&&(t.trans=this._transformFromClip.toJSON()),this.isMask&&(t.mask=!0),typeof this.zLow<"u"&&this.zLow!==-Number.MAX_VALUE&&(t.zlow=this.zLow),typeof this.zHigh<"u"&&this.zHigh!==Number.MAX_VALUE&&(t.zhigh=this.zHigh),{shape:t}}static fromClipShapeJSON(t,e){const n=t?.shape;if(!n)return;const i=n.points?n.points.map(l=>y.fromJSON(l)):[],s=n.trans?X.fromJSON(n.trans):void 0,r=typeof n.zlow=="number"?n.zlow:void 0,o=typeof n.zhigh=="number"?n.zhigh:void 0,a=typeof n.mask=="boolean"&&n.mask,c=typeof n.invisible=="boolean"&&n.invisible;return Sn.createShape(i,r,o,s,a,c,e)}static createFrom(t,e){const n=Sn.createEmpty(!1,!1,void 0,e);n._invisible=t._invisible;for(const i of t._polygon)n._polygon.push(i.clone());return n._isMask=t._isMask,n._zLow=t._zLow,n._zHigh=t._zHigh,n._transformToClip=t._transformToClip?t._transformToClip.clone():void 0,n._transformFromClip=t._transformFromClip?t._transformFromClip.clone():void 0,n}static createShape(t=[],e,n,i,s=!1,r=!1,o){if(t.length<3)return;const a=t.slice(0);return a[0].isAlmostEqual(a[a.length-1])?a[0].clone(a[a.length-1]):a.push(a[0].clone()),o?(o._clipPlanes=void 0,o._invisible=r,o._polygon=a,o.initSecondaryProps(s,e,n,i),o):new Sn(a,e,n,i,s,r)}static createBlock(t,e,n=!1,i=!1,s,r){const o=t.low,a=t.high,c=[];for(let d=0;d<5;d++)c.push(y.create());return c[0].x=c[3].x=c[4].x=o.x,c[1].x=c[2].x=a.x,c[0].y=c[1].y=c[4].y=o.y,c[2].y=c[3].y=a.y,Sn.createShape(c,vn.None!==(e&vn.ZLow)?o.z:void 0,vn.None!==(e&vn.ZHigh)?a.z:void 0,s,n,i,r)}static createEmpty(t=!1,e=!1,n,i){return i?(i._clipPlanes=void 0,i._invisible=e,i._polygon.length=0,i.initSecondaryProps(t,void 0,void 0,n),i):new Sn([],void 0,void 0,n,t,e)}get isValidPolygon(){return!(this._polygon.length<3||!this._polygon[0].isExactEqual(this._polygon[this._polygon.length-1]))}clone(t){return Sn.createFrom(this,t)}parseClipPlanes(t){const e=this._polygon;if(e.length===3&&!this._isMask&&e[0].isExactEqual(e[e.length-1]))return this.parseLinearPlanes(t,this._polygon[0],this._polygon[1]),!0;if(!this.isMask){const n=nt.testXYPolygonTurningDirections(this.polygon);if(n!==0)return this.parseConvexPolygonPlanes(t,this._polygon,n,!1),!0}return this.parsePolygonPlanes(t,this._polygon,this.isMask),!0}parseLinearPlanes(t,e,n,i){const s=Q.createStartEnd(e,n);if(!s.normalize(s))return!1;i===0&&(i=void 0);const r=vt.createEmpty();if(i===void 0){const o=Q.create(-s.y,s.x);r.addPlaneToConvexSet(H.createNormalAndPoint(P.create(s.x,s.y),e,this._invisible)),r.addPlaneToConvexSet(H.createNormalAndPoint(P.create(-s.x,-s.y),n,this._invisible)),r.addPlaneToConvexSet(H.createNormalAndPoint(P.create(o.x,o.y),e,this._invisible)),r.addPlaneToConvexSet(H.createNormalAndPoint(P.create(-o.x,-o.y),e,this._invisible))}else{const o=P.create(e.x,e.y,-i),a=P.create(n.x,n.y,-i),c=P.createZero(),l=P.createZero();a.crossProduct(o,c).normalize(c),o.crossProduct(c,l).normalize(l),r.addPlaneToConvexSet(H.createNormalAndDistance(c,0,this._invisible)),r.addPlaneToConvexSet(H.createNormalAndDistance(l,0,this._invisible)),c.negate(c),a.crossProduct(c,l).normalize(l),r.addPlaneToConvexSet(H.createNormalAndDistance(c,0,this._invisible)),r.addPlaneToConvexSet(H.createNormalAndDistance(l,0,this._invisible))}return r.addZClipPlanes(this._invisible,this._zLow,this._zHigh),t.addConvexSet(r),!0}parseConvexPolygonPlanes(t,e,n,i,s){const r=[],o=n<0;s===0&&(s=void 0);const a=s===void 0?0:-s;for(let c=0;c<e.length-1;c++){const l=Q.createStartEnd(e[c],e[c+1]);if(l.normalize(l)){const d=P.create(o?l.y:-l.y,o?-l.x:l.x);r.push(new fo(e[c],e[c+1],d,a))}}if(r.length<3)return!1;if(i){const c=r.length-1;for(let l=0;l<=c;l++){const d=r[l],h=r[l?l-1:c],g=r[l===c?0:l+1],m=vt.createEmpty(),p=fo.makeUnitPerpendicularToBisector(h,d,!o),x=fo.makeUnitPerpendicularToBisector(d,g,o);p&&m.addPlaneToConvexSet(H.createNormalAndPoint(p,d.pointA,this._invisible,!0)),m.addPlaneToConvexSet(H.createNormalAndPoint(d.normal,d.pointB,this._invisible,!1)),x&&m.addPlaneToConvexSet(H.createNormalAndPoint(x,g.pointA,this._invisible,!0)),t.addConvexSet(m)}t.addOutsideZClipSets(this._invisible,this._zLow,this._zHigh)}else{const c=vt.createEmpty();if(s===void 0)for(const l of r)c.addPlaneToConvexSet(H.createNormalAndPoint(l.normal,l.pointA));else{const l=P.createZero();if(o)for(const d of r)P.createFrom(d.pointA).crossProduct(P.createFrom(d.pointB),l).normalize(l),c.addPlaneToConvexSet(H.createNormalAndDistance(l,0));else for(const d of r)P.createFrom(d.pointB).crossProduct(P.createFrom(d.pointA),l).normalize(l),c.addPlaneToConvexSet(H.createNormalAndDistance(l,0))}c.addZClipPlanes(this._invisible,this._zLow,this._zHigh),t.addConvexSet(c)}return!0}parsePolygonPlanes(t,e,n,i){const s=gn.compressDanglers(e,!0),r=(o,a)=>{if(!a.isMaskSet(M.EXTERIOR)){const c=a.collectAroundFace(d=>{if(!d.isMaskSet(M.EXTERIOR))return y.create(d.x,d.y,0)});c.push(c[0].clone());const l=nt.testXYPolygonTurningDirections(c);this.parseConvexPolygonPlanes(t,c,l,!1,i)}return!0};if(n){const o=re.clonePoint3dArray(s),c=Un.createHullAndInletsForPolygon(o).extractLoops();if(c.length===0)return!1;const l=c[0],d=nt.testXYPolygonTurningDirections(l);this.parseConvexPolygonPlanes(t,l,-d,!0,i);for(let h=1;h<c.length;h++){const g=B.createTriangulatedGraphFromSingleLoop(c[h]);g&&(B.flipTriangles(g),g.announceFaceLoops(r))}return!0}else{const o=B.createTriangulatedGraphFromSingleLoop(s);if(o===void 0)return!1;B.flipTriangles(o),o.announceFaceLoops(r)}return!0}multiplyPlanesByMatrix4d(t,e=!0,n=!0){return this.ensurePlaneSets(),super.multiplyPlanesByMatrix4d(t,e,n)}transformInPlace(t){return t.isIdentity||(super.transformInPlace(t),this._transformFromClip?t.multiplyTransformTransform(this._transformFromClip,this._transformFromClip):this._transformFromClip=t.clone(),this._transformToClip=this._transformFromClip.inverse()),!0}get isXYPolygon(){return this._polygon.length===0?!1:this._transformFromClip===void 0?!0:this._transformFromClip.matrix.columnZ().magnitudeXY()<1e-8}performTransformToClip(t){this._transformToClip!==void 0&&this._transformToClip.multiplyPoint3d(t,t)}performTransformFromClip(t){this._transformFromClip!==void 0&&this._transformFromClip.multiplyPoint3d(t,t)}classifyPointContainment(t,e){this.ensurePlaneSets();const n=this._clipPlanes;let i=oe.StronglyInside;if(n&&(i=n.classifyPointContainment(t,!1)),this._isMask&&!e)switch(i){case oe.StronglyInside:return oe.StronglyOutside;case oe.StronglyOutside:return oe.StronglyInside;case oe.Ambiguous:return oe.Ambiguous}return i}}class Xc{_clippers;_intervalsA;_intervalsB;_keepInside;constructor(t){this._keepInside=t,this._clippers=[],this._intervalsA=[],this._intervalsB=[]}toJSON(){const t=[];for(const i of this._clippers){const s=i;s.toJSON&&t.push(s.toJSON())}const e=this.operationName,n={};return n[e]=t,n}captureChild(t){if(Array.isArray(t))for(const e of t)this.captureChild(e);else this._clippers.push(t)}toggleResult(){return this.selectResult(!this._keepInside)}selectResult(t){const e=this._keepInside;return this._keepInside=t,e}testedAnnounceNN(t,e,n){return t<e?(n&&n(t,e),1):0}testedAnnounceNNC(t,e,n,i){return t<e?(i&&i(t,e,n),1):0}swapAB(){const t=this._intervalsA;this._intervalsA=this._intervalsB,this._intervalsB=t}announcePartsNN(t,e,n,i,s){let r=0;if(t)for(const o of e)r+=this.testedAnnounceNN(o.low,o.high,s);else{let o=n;for(const a of e)r+=this.testedAnnounceNN(o,a.low,s),o=a.high;r+=this.testedAnnounceNN(o,i,s)}return r>0}announcePartsNNC(t,e,n,i,s,r){let o=0;if(t)for(const a of e)o+=this.testedAnnounceNNC(a.low,a.high,s,r);else{let a=n;for(const c of e)o+=this.testedAnnounceNNC(a,c.low,s,r),a=c.high;o+=this.testedAnnounceNNC(a,i,s,r)}return o>0}isPointOnOrInside(t){const e=this.isPointOnOrInsideChildren(t);return this._keepInside?e:!e}announceClippedSegmentIntervals(t,e,n,i,s){this._intervalsA.length=0;const r=(a,c)=>{this._intervalsB.push(ct.createXX(a,c))};let o=0;for(const a of this._clippers)this._intervalsB.length=0,a.announceClippedSegmentIntervals(t,e,n,i,r),Be.simplifySortUnion(this._intervalsB),o===0?this.swapAB():this._intervalsA=this.combineIntervals(this._intervalsA,this._intervalsB),o++;return this.announcePartsNN(this._keepInside,this._intervalsA,t,e,s)}announceClippedArcIntervals(t,e){this._intervalsA.length=0;const n=(s,r)=>{this._intervalsB.push(ct.createXX(s,r))};let i=0;for(const s of this._clippers)this._intervalsB.length=0,s.announceClippedArcIntervals(t,n),Be.simplifySortUnion(this._intervalsB),i===0?this.swapAB():this._intervalsA=this.combineIntervals(this._intervalsA,this._intervalsB),i++;return this.announcePartsNNC(this._keepInside,this._intervalsA,0,1,t,e)}announceClippedCurveIntervals(t,e){this._intervalsA.length=0;const n=(s,r,o)=>{this._intervalsB.push(ct.createXX(s,r))};let i=0;for(const s of this._clippers)this._intervalsB.length=0,s.announceClippedCurveIntervals?.(t,n)??void 0,Be.simplifySortUnion(this._intervalsB),i===0?this.swapAB():this._intervalsA=this.combineIntervals(this._intervalsA,this._intervalsB),i++;return this.announcePartsNNC(this._keepInside,this._intervalsA,0,1,t,e)}}class Yc extends Xc{get operationName(){return this._keepInside?"AND":"NAND"}constructor(t){super(t)}isPointOnOrInsideChildren(t){for(const e of this._clippers)if(!e.isPointOnOrInside(t))return!1;return!0}combineIntervals(t,e){return Be.intersectSorted(t,e)}appendPolygonClip(t,e,n,i){ee.doPolygonClipSequence(t,this._clippers,this._keepInside?e:n,this._keepInside?n:e,void 0,$e.passToNextStep,$e.acceptOut,$e.acceptIn,i)}}class wn{_clips;boundingRange=J.createNull();get clips(){return this._clips}constructor(t){this._clips=t||[]}get isValid(){return this._clips.length>0}static createEmpty(t){return t?(t._clips.length=0,t):new wn}static createCapture(t,e){return e?(e._clips=t,e):new wn(t)}static create(t,e){const n=[];for(const i of t)n.push(i.clone());return wn.createCapture(n,e)}clone(t){const e=t||new wn;e._clips.length=0;for(const n of this._clips)e._clips.push(n.clone());return e.boundingRange.setFrom(this.boundingRange),e}toJSON(){return this.isValid?this.clips.map(t=>t.toJSON()):[]}static fromJSON(t,e){if(e=e||new wn,e.clear(),!Array.isArray(t))return e;try{for(const n of t){const i=Bn.fromJSON(n);i&&e._clips.push(i)}}catch{e.clear()}return e}clear(){this._clips.length=0}appendClone(t){this._clips.push(t.clone())}appendReference(t){this._clips.push(t)}appendShape(t,e,n,i,s=!1,r=!1){const o=Sn.createShape(t,e,n,i,s,r);return o?(this._clips.push(o),!0):!1}pointInside(t,e=f.smallMetricDistanceSquared){return this.isPointOnOrInside(t,e)}isPointOnOrInside(t,e=f.smallMetricDistanceSquared){if(!this.boundingRange.isNull&&!this.boundingRange.containsPoint(t))return!1;for(const n of this._clips)if(!n.pointInside(t,e))return!1;return!0}_clipNodeProxy;ensureProxyClipNode(){if(this._clipNodeProxy)return!0;this._clipNodeProxy=new Yc(!0);let t=0;for(const e of this._clips){const n=e.fetchClipPlanesRef();n&&(t++,this._clipNodeProxy.captureChild(n))}return t>0}announceClippedSegmentIntervals(t,e,n,i,s){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedSegmentIntervals(t,e,n,i,s):!1}announceClippedArcIntervals(t,e){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedArcIntervals(t,e):!1}announceClippedCurveIntervals(t,e){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedCurveIntervals(t,e):!1}appendPolygonClip(t,e,n,i){this.ensureProxyClipNode(),this._clipNodeProxy&&this._clipNodeProxy.appendPolygonClip(t,e,n,i)}transformInPlace(t){for(const e of this._clips)if(e.transformInPlace(t)===!1)return!1;return this.boundingRange.isNull||t.multiplyRange(this.boundingRange,this.boundingRange),!0}extractBoundaryLoops(t,e){let n=vn.None,i=-Number.MAX_VALUE,s=Number.MAX_VALUE;const r=[];let o=0;if(this._clips.length===0)return r;let a;const c=X.createIdentity(),l=X.createIdentity(),d=X.createIdentity();for(const h of this._clips)if(h instanceof Sn&&(a!==void 0&&h!==a&&(c.setIdentity(),l.setIdentity(),a.hasTransformToClip()&&h.hasTransformFromClip()&&(h.transformFromClip.clone(c),a.transformToClip.clone(l)),d.setFrom(l.multiplyTransformTransform(c))),a||(a=h),t[o]=[],h.polygon!==void 0)){n=vn.XAndY,h.hasZHigh()&&(n=n|vn.ZHigh,s=h.zHigh),h.hasZLow()&&(n=n|vn.ZLow,i=h.zLow);for(const g of h.polygon)t[o].push(g.clone());d.multiplyPoint3dArray(t[o],t[o]),o++}return r.push(n),r.push(i),r.push(s),e&&a&&a.hasTransformFromClip()&&e.setFrom(a.transformFromClip),r}setInvisible(t){for(const e of this._clips)e.setInvisible(t)}parseClipPlanes(){for(const t of this._clips)t.fetchClipPlanesRef()}multiplyPlanesByMatrix4d(t,e=!0,n=!0){if(e){const i=t.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._clips)i.multiplyPlanesByMatrix4d(t,!1,n);return!0}classifyPointContainment(t,e=!1){let n=oe.Ambiguous;for(const i of this._clips){const s=i.classifyPointContainment(t,e);if(oe.Ambiguous===s)return oe.Ambiguous;if(oe.Ambiguous===n)n=s;else if(n!==s)return oe.Ambiguous}return n}classifyRangeContainment(t,e){const n=t.corners();return this.classifyPointContainment(n,e)}isAnyLineStringPointInside(t){for(const e of this._clips){const n=e.fetchClipPlanesRef();if(n!==void 0)for(let i=0;i+1<t.length;i++){const s=U.create(t[i],t[i+1]);if(n.isAnyPointInOrOnFromSegment(s))return!0}}return!1}sumSizes(t,e,n){let i=0;for(let s=e;s<n;s++)i+=t[s].x1-t[s].x0;return i}static _TARGET_FRACTION_SUM=.99999999;isLineStringCompletelyContained(t){const e=[];for(let n=0;n+1<t.length;n++){const i=U.create(t[n],t[n+1]);let s=0,r=0;for(const o of this._clips){const a=o.fetchClipPlanesRef();if(a!==void 0){a.appendIntervalsFromSegment(i,e);const c=e.length;if(s+=this.sumSizes(e,r,c),r=c,s>=wn._TARGET_FRACTION_SUM)break}}if(s<wn._TARGET_FRACTION_SUM)return!1}return!0}toCompactString(){function t(a){return`${a.toString()}_`}function e(a){return`${t(a.x)}${t(a.y)}${t(a.z)}`}function n(a){const c=a.toString();return c.length,c}function i(a){let c=a.invisible?1:0;return c|=a.interior?2:0,`${n(c)}${e(a.inwardNormalRef)}${t(a.distance)}`}function s(a){let c="";for(const l of a.planes)c=`${c}${i(l)}`;return`${c}_`}function r(a){let l=(a.invisible?1:0).toString();l.length;const d=a.fetchClipPlanesRef();if(d)for(const h of d.convexSets)l=`${l}${s(h)}`;return`${l}_`}let o="";for(const a of this.clips)o=`${o}${r(a)}`;return`${o}_`}}var xa;(function(u){function t(e){if(!e||!e.isValid)return;const n=e;n.clipString===void 0&&(n.clipString=e.toCompactString());const i=n;return i.clipString,i}u.fromClipVector=t})(xa||(xa={}));class An{_positiveOffsetLeft;_positiveOffsetRight;_turnDegrees;constructor(t,e){this._positiveOffsetLeft=t,this._positiveOffsetRight=e,this._turnDegrees=60}static createUnit(t,e,n,i=!0){let s=e,r=e+1;const o=t.length-1;n?e<0?(s=o-1,r=o):e>=o&&(s=0,r=1):e===0?(s=0,r=1):r>o&&(s=o-1,r=o);const a=t.vectorIndexIndex(s,r);if(a)return i&&(a.z=0),a.normalize(a)}static createDirectedPlane(t,e,n,i,s=!1){return H.createNormalAndPointXYZXYZ(e.x*i,e.y*i,e.z*i,t.x+n*e.x,t.y+n*e.y,t.z+n*e.z,s,s)}createChamferCut(t,e,n,i){const s=n.angleToXY(i).degrees;if(Math.abs(s)>this._turnDegrees){const r=n.interpolate(.5,i);r.rotate90CCWXY(r),r.normalizeInPlace(),s>0?t.addPlaneToConvexSet(An.createDirectedPlane(e,r,-this._positiveOffsetRight,1,!1)):t.addPlaneToConvexSet(An.createDirectedPlane(e,r,this._positiveOffsetLeft,-1,!1))}}createOffsetFromSegment(t,e,n,i,s){if(i===void 0)return;n===void 0&&(n=i),s===void 0&&(s=i);const r=n.interpolate(.5,i);r.normalizeInPlace();const o=i.rotate90CCWXY(),a=i.interpolate(.5,s);a.normalizeInPlace();const c=vt.createEmpty();return c.addPlaneToConvexSet(An.createDirectedPlane(t,o,this._positiveOffsetLeft,-1,!1)),c.addPlaneToConvexSet(An.createDirectedPlane(t,o,-this._positiveOffsetRight,1,!1)),c.addPlaneToConvexSet(An.createDirectedPlane(t,r,0,1,!0)),c.addPlaneToConvexSet(An.createDirectedPlane(e,a,0,-1,!0)),this.createChamferCut(c,t,n,i),this.createChamferCut(c,e,i,s),c}static createClipBetweenOffsets(t,e,n,i,s){const r=new An(e,n),o=fe.createEmpty();if(t.length>1){const a=t.almostEqualUncheckedIndexIndex(0,t.length-1);for(let c=0;c+1<t.length;c++){const l=this.createUnit(t,c-1,a),d=this.createUnit(t,c,a),h=this.createUnit(t,c+1,a),g=r.createOffsetFromSegment(t.getPoint3dAtUncheckedPointIndex(c),t.getPoint3dAtUncheckedPointIndex(c+1),l,d,h);g?.addZClipPlanes(!1,i,s),g&&o.addConvexSet(g)}}else{const a=vt.createEmpty();a.addZClipPlanes(!1,i,s),a.planes.length>0&&o.addConvexSet(a)}return o}}var oe;(function(u){u[u.StronglyInside=1]="StronglyInside",u[u.Ambiguous=2]="Ambiguous",u[u.StronglyOutside=3]="StronglyOutside"})(oe||(oe={}));var $e;(function(u){u[u.acceptIn=1]="acceptIn",u[u.acceptOut=-1]="acceptOut",u[u.passToNextStep=0]="passToNextStep"})($e||($e={}));var Ni;(function(u){u[u.ClipRequired=0]="ClipRequired",u[u.TrivialReject=1]="TrivialReject",u[u.TrivialAccept=2]="TrivialAccept"})(Ni||(Ni={}));class ee{static _workTransform;static _workRange;static _workClipper;static _selectIntervals01TestPoint=y.create();static selectIntervals01(t,e,n,i){e.push(0),e.push(1),e.sort();let s=e.atUncheckedIndex(0),r,o;const a=ee._selectIntervals01TestPoint,c=e.length;for(let l=1;l<c;l++)if(r=e.atUncheckedIndex(l),r>s+f.smallFraction){if(o=.5*(s+r),o>=0&&o<=1&&(t.fractionToPoint(o,a),n.isPointOnOrInside(a)))if(i)i(s,r,t);else return!0;s=r}return!1}static announceNNC(t,e,n){if(n)for(const i of t)n(i.low,i.high,e);return t.length>0}static collectClippedCurves(t,e){const n=[];return t.announceClipIntervals(e,(i,s,r)=>{if(i!==s){const o=r.clonePartialCurve(i,s);o&&n.push(o)}}),n}static clipAnyRegion(t,e){let n;const i=ee._workTransform=Qt.createRightHandedFrame(void 0,t,ee._workTransform);if(!i)return n;const s=i?.inverse();if(!s)return n;const r=t.cloneTransformed(s),o=ee._workRange=r.range(),a=o.xLength(),c=o.yLength(),l=F.createRectangleXY(o.low,a,c,!0);l.tryTransformInPlace(i);const d=[],h=[],g=new $r;if(e.appendPolygonClip?.(l.packedPoints,d,h,g),d.length===0)return n;for(const m of d){const p=tt.createPolygon(m);p.tryTransformInPlace(s);const x=ot.regionBooleanXY(r,p,Ze.Intersection);x&&(x.tryTransformInPlace(i),n||(n=x instanceof ve?x:ve.create(x)),x instanceof ve?n.children.push(...x.children):n.tryAddChild(x))}return n?ot.simplifyRegion(n):void 0}static clipAnyCurve(t,e){if(t instanceof st)return ee.collectClippedCurves(t,e);if(t.isAnyRegion()){const i=ee.clipAnyRegion(t,e);return i?[i]:[]}const n=[];if(t instanceof Pt||t instanceof Ee)for(const i of t.children){const s=ee.clipAnyCurve(i,e);n.push(...s)}return n}static clipPolygonToClipShape(t,e){const n=this.clipPolygonToClipShapeReturnGrowableXYZArrays(t,e),i=[];for(const s of n)i.push(s.getPoint3dArray());return i}static clipPolygonToClipShapeReturnGrowableXYZArrays(t,e){const n=[],i=e.fetchClipPlanesRef();return i&&i.polygonClip(t,n),n}static pointSetSingleClipStatus(t,e,n){if(e.convexSets.length===0)return Ni.TrivialAccept;for(const i of e.convexSets){let s=!1,r=!1;for(const o of i.planes){let a=0,c=0;const l=o.distance-n,d=y.create(),h=P.create();for(let g=0;g<t.length;g++)t.getPoint3dAtUncheckedPointIndex(g,d),h.setFrom(d),h.dotProduct(o.inwardNormalRef)>l?a++:c++;if(r=c!==0?!0:r,a===0){s=!0;break}}if(!r)return Ni.TrivialAccept;if(!s)return Ni.ClipRequired}return Ni.TrivialReject}static announceLoopsOfConvexClipPlaneSetIntersectRange(t,e,n,i=!0,s=!0,r=!1){const o=new W;if(i){if(t instanceof vt)for(const a of t.planes){if(r&&a.invisible)continue;const c=a.intersectRange(e,!0);if(c){const l=new W;t.polygonClip(c,l,o,a),l.length>0&&n(l)}}else if(!(r&&t.invisible)){const a=t.intersectRange(e,!0);a&&n(a)}}if(s){const a=e.corners();for(let c=0;c<6;c++){const l=J.faceCornerIndices(c),d=new W,h=F.createIndexedPoints(a,l);t instanceof vt?(t.polygonClip(h.packedPoints,d,o),d.length>0&&n(d)):(t.clipConvexPolygonInPlace(h.packedPoints,o),h.packedPoints.length>0&&n(h.packedPoints))}}}static loopsOfConvexClipPlaneIntersectionWithRange(t,e,n=!0,i=!0,s=!1){const r=[];if(t instanceof fe)for(const o of t.convexSets)this.announceLoopsOfConvexClipPlaneSetIntersectRange(o,e,a=>{a.length>0&&r.push(tt.createPolygon(a))},n,i,s);else(t instanceof vt||t instanceof H)&&this.announceLoopsOfConvexClipPlaneSetIntersectRange(t,e,o=>{o.length>0&&r.push(tt.createPolygon(o))},n,i,s);return r}static rangeOfConvexClipPlaneSetIntersectionWithRange(t,e){const n=J.createNull();return this.announceLoopsOfConvexClipPlaneSetIntersectRange(t,e,i=>{i.length>0&&n.extendArray(i)},!0,!0,!1),n}static rangeOfClipperIntersectionWithRange(t,e,n=!0){if(t===void 0)return e.clone();if(t instanceof vt)return this.rangeOfConvexClipPlaneSetIntersectionWithRange(t,e);if(t instanceof fe){const i=J.createNull();for(const s of t.convexSets){const r=this.rangeOfConvexClipPlaneSetIntersectionWithRange(s,e);i.extendRange(r)}return i}if(t instanceof Bn)return n&&t.invisible?e.clone():this.rangeOfClipperIntersectionWithRange(t.fetchClipPlanesRef(),e);if(t instanceof wn){const i=e.clone();for(const s of t.clips)if(!(n&&s.invisible)){const r=this.rangeOfClipperIntersectionWithRange(s,e,n);i.intersect(r,i)}return i}return e.clone()}static doesClipperIntersectRange(t,e,n=!0){if(t===void 0)return!0;if(t instanceof vt)return this.doesConvexClipPlaneSetIntersectRange(t,e);if(t instanceof fe){for(const i of t.convexSets)if(this.doesConvexClipPlaneSetIntersectRange(i,e))return!0;return!1}if(t instanceof Bn)return n&&t.invisible?!0:this.doesClipperIntersectRange(t.fetchClipPlanesRef(),e);if(t instanceof wn){const i=e.clone();for(const s of t.clips)if(!(n&&s.invisible)){const r=this.rangeOfClipperIntersectionWithRange(s,e,n);i.intersect(r,i)}return!i.isNull}return!1}static doesConvexClipPlaneSetIntersectRange(t,e,n=!0,i=!0,s=!1){const r=new W;if(n)for(const o of t.planes){if(s&&o.invisible)continue;const a=o.intersectRange(e,!0);if(a){const c=new W;if(t.polygonClip(a,c,r,o),c.length>0)return!0}}if(i){const o=e.corners();for(let a=0;a<6;a++){const c=J.faceCornerIndices(a),l=new W,d=F.createIndexedPoints(o,c);if(t.polygonClip(d.packedPoints,l,r),l.length>0)return!0}}return!1}static createClipperFromTransformedRange3d(t,e,n){e||(e=X.createIdentity());const i=it.create();i.addTransformedRangeMesh(e,t);const s=i.claimPolyface(),r=this._workClipper=vt.createConvexPolyface(s,this._workClipper).clipper;if(r.planes.length>0)return r;if(n){s.data.point.length<=2;for(let o=0;o<2;++o){const a=s.data.point.getPoint3dAtCheckedPointIndex(o);a&&n.push(a)}}}static rangeIntersectPointOrSegment(t,e,n,i){const s=i?(o,a,c)=>{i.extendPoint(c.fractionToPoint(o),n),i.extendPoint(c.fractionToPoint(a),n)}:void 0;let r=!1;if(e.length>1){const o=U.createCapture(e[0],e[1]),a=vt.createRange3dPlanes(t);r=o.announceClipIntervals(a,s)}else e.length>0&&(r=t.containsPoint(e[0]),r&&i&&i.extendPoint(e[0],n));return r}static doLocalRangesIntersect(t,e,n,i,s){const r=this._workTransform=i.inverse(this._workTransform);if(!r)return!1;let o=n;s&&(o=this._workRange=n.clone(this._workRange),o.expandInPlace(s));const a=[],c=r.multiplyTransformTransform(e,r),l=this.createClipperFromTransformedRange3d(t,c,a);return l?this.doesClipperIntersectRange(l,o):this.rangeIntersectPointOrSegment(o,a,i)}static rangeOfIntersectionOfLocalRanges(t,e,n,i,s){const r=J.createNull(s),o=this._workTransform=i.inverse(this._workTransform);if(!o)return r;const a=[],c=o.multiplyTransformTransform(e,o),l=this.createClipperFromTransformedRange3d(t,c,a);return l?this.announceLoopsOfConvexClipPlaneSetIntersectRange(l,n,d=>{d.extendRange(r,i)}):this.rangeIntersectPointOrSegment(n,a,i,r),r}static isClipper(t){return!!(t&&t.isPointOnOrInside&&t.announceClippedSegmentIntervals&&t.announceClippedArcIntervals)}static restoreSingletonInPlaceOfMultipleShards(t,e,n,i){if(t&&t.length>e+1){for(;t.length>e;){const s=t.pop();i.dropToCache(s)}t.push(i.grabAndFill(n))}}static createXYOffsetClipFromLineString(t,e,n,i,s){return Array.isArray(t)?An.createClipBetweenOffsets(new Bt(t),e,n,i,s):An.createClipBetweenOffsets(t,e,n,i,s)}static captureOrDrop(t,e,n,i){t.length>=e?n.push(t):i.dropToCache(t)}static clipSegmentToLLeftOfLineXY(t,e,n,i,s,r=1e-14){const o=e.x-t.x,a=e.y-t.y,c=-(o*(n.y-t.y)-a*(n.x-t.x)),l=-(o*(i.y-t.y)-a*(i.x-t.x));if(!(c<r&&l<r))if(c*l>0)c>0&&s.setNull();else if(c*l<0){const d=-c/(l-c);return c<0?s.intersectRangeXXInPlace(0,d):s.intersectRangeXXInPlace(d,1)}else c>0?s.intersectRangeXXInPlace(1,1):l>0&&s.intersectRangeXXInPlace(0,0)}static clipSegmentToCCWTriangleXY(t,e,n,i,s,r,o=1e-14){r.isNull||(this.clipSegmentToLLeftOfLineXY(t,e,i,s,r,o),r.isNull||(this.clipSegmentToLLeftOfLineXY(e,n,i,s,r,o),r.isNull||this.clipSegmentToLLeftOfLineXY(n,t,i,s,r,o)))}static clipSegmentBelowPlaneXY(t,e,n,i,s=1e-14){const r=t.altitudeXY(e.x,e.y),o=t.altitudeXY(n.x,n.y);if(!(r<s&&o<s))if(r*o>0)r>0&&i.setNull();else if(r*o<0){const a=-r/(o-r);return r<0?i.intersectRangeXXInPlace(0,a):i.intersectRangeXXInPlace(a,1)}else r>0?i.intersectRangeXXInPlace(1,1):o>0&&i.intersectRangeXXInPlace(0,0)}static clipSegmentBelowPlanesXY(t,e,n,i,s=1e-14){const r=t.length;for(let o=0;!i.isNull&&o<r;o++)this.clipSegmentBelowPlaneXY(t[o],e,n,i,s)}static announcePolylineClip(t,e,n){for(let i=0;i+1<e.length;i++)t.announceClippedSegmentIntervals(0,1,e[i],e[i+1],(s,r)=>{n(e[i].interpolate(s,e[i+1]),e[i].interpolate(r,e[i+1]))})}static sumPolylineClipLength(t,e){let n=0;for(let i=0;i+1<e.length;i++){const s=e[i].distance(e[i+1]);t.announceClippedSegmentIntervals(0,1,e[i],e[i+1],(r,o)=>{n+=Math.abs(o-r)*s})}return n}static doPolygonClipSequence(t,e,n,i,s,r,o,a,c){c===void 0&&(c=new $r);let l=[c.grabAndFill(t)],d=[];const h=[],g=[],m=n?n.length:0,p=i?i.length:0;let x;for(const _ of e)if(_.appendPolygonClip){for(;(x=l.pop())!==void 0;)_.appendPolygonClip(x,h,g,c),_i(r,h,n,i,d,c),_i(o,g,n,i,d,c),c.dropToCache(x);const I=l;l=d,d=I}_i(a,l,n,i,s,c),i?.length===p&&ee.restoreSingletonInPlaceOfMultipleShards(n,m,t,c),n?.length===m&&ee.restoreSingletonInPlaceOfMultipleShards(i,p,t,c)}static doPolygonClipParitySequence(t,e,n,i,s){s===void 0&&(s=new $r);let r=[s.grabAndFill(t)],o=[],a=[],c=[];const l=[],d=[];let h;for(const g of e)if(g.appendPolygonClip){for(;(h=o.pop())!==void 0;)g.appendPolygonClip(h,l,d,s),_i($e.acceptOut,l,a,c,void 0,s),_i($e.acceptIn,d,a,c,void 0,s),s.dropToCache(h);for(;(h=r.pop())!==void 0;)g.appendPolygonClip(h,l,d,s),_i($e.acceptIn,l,a,c,void 0,s),_i($e.acceptOut,d,a,c,void 0,s),s.dropToCache(h);const m=o;o=a,a=m;const p=r;r=c,c=p}r.length===0?n?.push(s.grabAndFill(t)):r.length===0?i?.push(s.grabAndFill(t)):(_a(o,n,s),_a(r,i,s))}static createComplementaryClips(t){const e=t.planes,n=ct.createNull(),i=e.length,s=[];for(const r of e){const o=vt.createEmpty();o.addPlaneToConvexSet(r.cloneNegated()),s.push(o)}for(let r=0;r<i;r++)for(let o=r+1;o<i;o++){const a=je.planePlaneIntersectionRay(e[r],e[o]);if(a&&t.hasIntersectionWithRay(a,n)){const c=e[o].inwardNormalRef.minus(e[r].inwardNormalRef),l=H.createNormalAndPoint(c,a.origin);if(l){const d=l.cloneNegated();s[r].addPlaneToConvexSet(l),s[o].addPlaneToConvexSet(d)}}}return fe.createConvexSets(s)}static createClippersForRegionsClosestToCurvePrimitivesXY(t,e,n=f.smallMetricDistance,i){const s=Kt.createFromCurveChain(t,e,n,i);if(!s)return;const r=s.computeVoronoiSuperFaces(t.children.length);if(!(r===void 0||r.length!==t.children.length))return s.generateClippersFromVoronoiSuperFaces(r)}}function _a(u,t,e){if(t===void 0)e.dropAllToCache(u);else for(const n of u)t.push(n);u.length=0}function _i(u,t,e,n,i,s){let r;if(u===$e.acceptIn?r=e:u===$e.acceptOut?r=n:u===$e.passToNextStep&&(r=i),r===void 0)s.dropAllToCache(t);else for(const o of t)r.push(o);t.length=0}class H extends Cs{_inwardNormal;_distanceFromOrigin;_invisible;_interior;constructor(t,e,n,i){super(),this._invisible=n,this._interior=i,this._inwardNormal=t,this._distanceFromOrigin=e}isAlmostEqual(t){return f.isSameCoordinate(this._distanceFromOrigin,t._distanceFromOrigin)&&this._inwardNormal.isAlmostEqual(t._inwardNormal)&&this._interior===t._interior&&this._invisible===t._invisible}clone(){return new H(this._inwardNormal.clone(),this._distanceFromOrigin,this._invisible,this._interior)}cloneNegated(){const t=new H(this._inwardNormal.clone(),this._distanceFromOrigin,this._invisible,this._interior);return t.negateInPlace(),t}static createPlane(t,e=!1,n=!1,i){const s=t.getNormalRef().dotProduct(t.getOriginRef());return i?(i._invisible=e,i._interior=n,i._inwardNormal=t.getNormalRef().clone(),i._distanceFromOrigin=s,i):new H(t.getNormalRef().clone(),s,e,n)}static createNormalAndDistance(t,e,n=!1,i=!1,s){const r=t.normalize();if(r)return s&&(s._invisible=n,s._interior=i,s._inwardNormal=r,s._distanceFromOrigin=e),new H(r,e,n,i)}static createNormalAndPoint(t,e,n=!1,i=!1,s){const r=t.normalize();if(r){const o=r.dotProduct(e);return s&&(s._invisible=n,s._interior=i,s._inwardNormal=r,s._distanceFromOrigin=o),new H(r,o,n,i)}}static createOriginAndVectors(t,e,n,i=!1,s=!1,r){const o=n.crossProduct(e);return this.createNormalAndPoint(o,t,i,s,r)}static createNormalAndPointXYZXYZ(t,e,n,i,s,r,o=!1,a=!1,c){const l=f.hypotenuseXYZ(t,e,n),d=f.conditionalDivideFraction(1,l);if(d!==void 0){if(c)return c._inwardNormal.set(t*d,e*d,n*d),c._distanceFromOrigin=c._inwardNormal.dotProductXYZ(i,s,r),c._invisible=o,c._interior=a,c;const h=P.create(t*d,e*d,n*d);return new H(h,h.dotProductXYZ(i,s,r),o,a)}}toJSON(){const t={normal:this.inwardNormalRef.toJSON(),dist:this.distance};return this.interior&&(t.interior=!0),this.invisible&&(t.invisible=!0),t}static fromJSON(t,e){return t&&t.normal&&t.dist!==void 0&&Number.isFinite(t.dist)?H.createNormalAndDistance(P.fromJSON(t.normal),t.dist,!!t.invisible,!!t.interior):H.createNormalAndDistance(P.unitZ(),0,!1,!1,e)}setFlags(t,e){this._invisible=t,this._interior=e}get distance(){return this._distanceFromOrigin}get inwardNormalRef(){return this._inwardNormal}get interior(){return this._interior}get invisible(){return this._invisible}static createEdgeAndUpVector(t,e,n,i,s){const r=P.createFrom(e.minus(t));let o=n.crossProduct(r).normalize();if(o){if(i!==void 0&&!i.isAlmostZero){const a=P.createRotateVectorAroundVector(o,r,i);a&&(o=a.clone())}return o.negate(o),H.createNormalAndPoint(o,t,!1,!1,s)}}static createEdgeXY(t,e,n){const i=P.create(t.y-e.y,e.x-t.x);if(i.normalizeInPlace())return H.createNormalAndPoint(i,t,!1,!1,n)}static createMidPointEdgeXY(t,e,n){return H.createNormalAndPointXYZXYZ(t.y-e.y,e.x-t.x,0,.5*(t.x+e.x),.5*(t.y+e.y),0,!1,!1,n)}getPlane3d(){const t=this._distanceFromOrigin,e=y.create(this._inwardNormal.x*t,this._inwardNormal.y*t,this._inwardNormal.z*t),n=ht.createXYPlane();return ht.create(e,this._inwardNormal,n),n}getPlane4d(){return Z.create(this._inwardNormal.x,this._inwardNormal.y,this._inwardNormal.z,-this._distanceFromOrigin)}setPlane4d(t){const e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),n=e===0?1:1/e;this._inwardNormal.x=n*t.x,this._inwardNormal.y=n*t.y,this._inwardNormal.z=n*t.z,this._distanceFromOrigin=-n*t.w}weightedAltitude(t){return t.x*this._inwardNormal.x+t.y*this._inwardNormal.y+t.z*this._inwardNormal.z-t.w*this._distanceFromOrigin}altitude(t){return t.x*this._inwardNormal.x+t.y*this._inwardNormal.y+t.z*this._inwardNormal.z-this._distanceFromOrigin}altitudeXYZ(t,e,n){return t*this._inwardNormal.x+e*this._inwardNormal.y+n*this._inwardNormal.z-this._distanceFromOrigin}normalX(){return this._inwardNormal.x}normalY(){return this._inwardNormal.y}normalZ(){return this._inwardNormal.z}velocity(t){return t.x*this._inwardNormal.x+t.y*this._inwardNormal.y+t.z*this._inwardNormal.z}velocityXYZ(t,e,n){return t*this._inwardNormal.x+e*this._inwardNormal.y+n*this._inwardNormal.z}dotProductPlaneNormalPoint(t){return t.x*this._inwardNormal.x+t.y*this._inwardNormal.y+t.z*this._inwardNormal.z}isPointOnOrInside(t,e=f.smallMetricDistance){let n=this.altitude(t);return e&&(n+=e),n>=0}isPointInside(t,e=f.smallMetricDistance){let n=this.altitude(t);return e&&(n-=e),n>0}isPointOn(t,e=f.smallMetricDistance){return Math.abs(this.altitude(t))<=e}appendIntersectionRadians(t,e){const n=t.toVectors(),i=this.altitude(t.center),s=this.velocity(n.vector0),r=this.velocity(n.vector90);Xn.appendImplicitLineUnitCircleIntersections(i,s,r,void 0,void 0,e)}static _clipFractionArray=new Ft;announceClippedArcIntervals(t,e){const n=H._clipFractionArray;return n.clear(),this.appendIntersectionRadians(t,n),t.sweep.radiansArrayToPositivePeriodicFractions(n),ee.selectIntervals01(t,n,this,e)}announceClippedCurveIntervals(t,e){const n=H._clipFractionArray;n.clear();const i=[];t.appendPlaneIntersectionPoints(this,i);for(const s of i)n.push(s.fraction);return ee.selectIntervals01(t,n,this,e)}getBoundedSegmentSimpleIntersection(t,e){const n=this.altitude(t),i=this.altitude(e);if(!(n*i>0)&&!(n===0&&i===0))return-n/(i-n)}transformInPlace(t){const e=this.getPlane3d(),n=t.matrix,i=t.multiplyPoint3d(e.getOriginRef()),s=n.multiplyInverseTranspose(e.getNormalRef());if(!s)return!1;e.set(i,s);const r=e.getNormalRef().normalize();return r?(this._inwardNormal=r,this._distanceFromOrigin=this._inwardNormal.dotProduct(e.getOriginRef()),!0):!1}setInvisible(t){this._invisible=t}negateInPlace(){this._inwardNormal=this._inwardNormal.negate(),this._distanceFromOrigin=-this._distanceFromOrigin}offsetDistance(t){this._distanceFromOrigin+=t}clipConvexPolygonInPlace(t,e,n=!0,i=f.smallMetricDistance){return nn.clipConvexPolygonInPlace(this,t,e,n,i)}multiplyPlaneByMatrix4d(t,e=!0,n=!0){const i=this.getPlane4d();if(e){const s=t.createInverse();return s?this.multiplyPlaneByMatrix4d(s,!1,n):!1}return n?t.multiplyTransposePoint4d(i,i):t.multiplyPoint4d(i,i),this.setPlane4d(i),!0}announceClippedSegmentIntervals(t,e,n,i,s){if(e<t)return!1;const r=-this.altitude(n),a=-this.altitude(i)-r,c=f.conditionalDivideFraction(-r,a);return c===void 0?r<=0?(s&&s(t,e),!0):!1:(a>0?c<e&&(e=c):c>t&&(t=c),e<t?!1:(s&&s(t,e),!0))}getFrame(){const t=this._distanceFromOrigin,e=y.create(this._inwardNormal.x*t,this._inwardNormal.y*t,this._inwardNormal.z*t),n=C.createRigidHeadsUp(this._inwardNormal,mt.ZXY);return X.createOriginAndMatrix(e,n)}intersectRange(t,e=!1){if(t.isNull)return;const n=t.corners(),i=this.getFrame();i.multiplyInversePoint3dArrayInPlace(n);const s=J.createArray(n);if(s.low.z*s.high.z>0)return;const r=new W;if(r.pushXYZ(s.low.x,s.low.y,0),r.pushXYZ(s.high.x,s.low.y,0),r.pushXYZ(s.high.x,s.high.y,0),r.pushXYZ(s.low.x,s.high.y,0),r.multiplyTransformInPlace(i),nn.intersectRangeConvexPolygonInPlace(t,r),r.length!==0)return e&&r.pushWrap(1),r}appendPolygonClip(t,e,n,i){const s=ct.createNull(),r=i.grabFromCache(),o=i.grabFromCache();nn.splitConvexPolygonInsideOutsidePlane(this,t,r,o,s),ee.captureOrDrop(r,3,e,i),ee.captureOrDrop(o,3,n,i)}projectPointToPlane(t,e){return this.projectXYZToPlane(t.x,t.y,t.z,e)}projectXYZToPlane(t,e,n,i){const s=-this.altitudeXYZ(t,e,n);return y.create(t+s*this._inwardNormal.x,e+s*this._inwardNormal.y,n+s*this._inwardNormal.z,i)}}class Cn{curves;localToWorld;axis;_xyStrokes;_facets;constructor(t,e,n){if(t instanceof st){const i=t;t=t.startPoint().isAlmostEqual(t.endPoint())?new tt:new Pt,t.tryAddChild(i)}this.curves=t,this.localToWorld=e,this.axis=n}static createForLinearSweep(t,e){const n=Qt.createRightHandedFrame(e,t);if(n)return new Cn(t,n,void 0)}static createForPolygon(t,e){const n=Qt.createRightHandedFrame(e,t);if(n){const i=F.createArrayOfLineString3d(t),s=[];for(const r of i)r.addClosurePoint(),s.push(tt.create(r));if(s.length===1)return new Cn(s[0],n,void 0);if(s.length>1)return new Cn(Wt.createLoops(s),n,void 0)}}static createForRotation(t,e){const n=Qt.createRightHandedFrame(void 0,t,e);if(n)return new Cn(t,n,e.clone())}getCurves(){return this.curves}tryTransformInPlace(t){if(this.curves.tryTransformInPlace(t)){this.axis&&this.axis.transformInPlace(t);const e=this.axis!==void 0?Qt.createRightHandedFrame(void 0,this.curves,this.axis):Qt.createRightHandedFrame(void 0,this.curves);if(e)return this.localToWorld.setFrom(e),this._xyStrokes=void 0,!0}return!1}clone(){return new Cn(this.curves.clone(),this.localToWorld.clone(),this.axis)}cloneTransformed(t){const e=this.clone();if(e.tryTransformInPlace(t))return e}isAlmostEqual(t){if(!(t instanceof Cn)||!this.curves.isAlmostEqual(t.curves)||!this.localToWorld.isAlmostEqual(t.localToWorld))return!1;if(this.axis&&t.axis){if(!this.axis.isAlmostEqual(t.axis))return!1}else if(this.axis||t.axis)return!1;return!0}computeXYStrokes(t){this._xyStrokes=void 0;const e=this.localToWorld.inverse();if(e){const n=this.curves.cloneStroked(t);n.tryTransformInPlace(e)&&(this._xyStrokes=n)}}get xyStrokes(){return this._xyStrokes}buildFacets(t){if(this._facets||!this.curves.isAnyRegion())return;const e=this.localToWorld.inverse();if(!e)return;const n=this.curves.cloneTransformed(e);n&&(this._facets=ot.facetRegionXY(n,t))&&this._facets.tryTransformInPlace(this.localToWorld)}purgeFacets(){this._facets=void 0}emitFacets(t,e,n){this.buildFacets(t.options),this._facets&&t.addIndexedPolyface(this._facets,e,n)}announceFacets(t,e){this.buildFacets(e),this._facets&&t(this._facets)}sweepToUnionOfConvexClipPlaneSets(t,e=!1,n=!1,i){i||(i=Zt.createForFacets()),t||(e=n=!1,t=this.localToWorld.matrix.columnZ()),i.maximizeConvexFacets=!0,this.buildFacets(i);const s=this._facets;if(s){const r=y.create(),o=y.create(),a=fe.createEmpty(),c=s.createVisitor(1);for(c.reset();c.moveToNextFacet();){const l=c.point.length-1,d=vt.createEmpty();for(let h=0;h<l;h++){c.point.getPoint3dAtUncheckedPointIndex(h,r),c.point.getPoint3dAtUncheckedPointIndex(h+1,o);const g=H.createEdgeAndUpVector(o,r,t),m=c.edgeVisible[h];g?.setFlags(!m,!m),d.addPlaneToConvexSet(g)}a.addConvexSet(d)}if(e||n){const l=this.localToWorld.matrix.columnZ(),d=this.localToWorld.getOrigin(),h=d.plus(t),g=l.clone(),m=l.negate(),p=vt.createEmpty();e&&p.addPlaneToConvexSet(H.createNormalAndPoint(g,d)),n&&p.addPlaneToConvexSet(H.createNormalAndPoint(m,h)),a.addConvexSet(p)}return a}}}class yi extends qs{solidPrimitiveType="ruledSweep";_contours;constructor(t,e){super(e),this._contours=t}static create(t,e){const n=[];for(const i of t){const s=Cn.createForLinearSweep(i);if(s===void 0)return;n.push(s)}return new yi(n,e)}sweepContoursRef(){return this._contours}cloneSweepContours(){const t=[];for(const e of this._contours)t.push(e.clone());return t}cloneContours(){const t=[];for(const e of this._contours)t.push(e.curves.clone());return t}clone(){return new yi(this.cloneSweepContours(),this.capped)}tryTransformInPlace(t){if(t.matrix.isSingular())return!1;for(const e of this._contours)if(!e.tryTransformInPlace(t))return!1;return t.matrix.determinant()<0&&this._contours.reverse(),!0}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t)?e:void 0}getConstructiveFrame(){if(this._contours.length!==0)return this._contours[0].localToWorld.cloneRigid()}isSameGeometryClass(t){return t instanceof yi}isAlmostEqual(t){if(t instanceof yi){if(this.capped!==t.capped||this._contours.length!==t._contours.length)return!1;for(let e=0;e<this._contours.length;e++)if(!this._contours[e].isAlmostEqual(t._contours[e]))return!1;return!0}return!1}dispatchToGeometryHandler(t){return t.handleRuledSweep(this)}constantVSection(t){const e=this._contours.length;if(e<2)return;const n=t*e;let i=0;t>=1?i=e-1:i=Math.floor(n),i+1>=e&&(i=e-2);const s=i+1,r=f.clampToStartEnd(n-i,0,1);return yi.mutatePartners(this._contours[i].curves,this._contours[s].curves,(o,a)=>{const c=Zs.interpolateBetween(o,r,a);if(c instanceof st)return c})}extendRange(t,e){for(const n of this._contours)n.curves.extendRange(t,e)}static mutatePartners(t,e,n){if(t.isSameGeometryClass(e)){if(t instanceof de&&e instanceof de){const i=t,s=e,r=i.cloneEmptyPeer(),o=i.children,a=s.children;if(o.length!==a.length)return;for(let c=0;c<o.length;c++){const l=n(o[c],a[c]);if(!l)return;r.children.push(l)}return r}else if(t instanceof ut&&e instanceof ut){const i=t.cloneEmptyPeer(),s=t.children,r=e.children,o=i.children;if(s===void 0||r===void 0||o===void 0||s.length!==r.length)return;for(let a=0;a<s.length;a++){const c=s[a],l=r[a];if(c instanceof st&&l instanceof st){const d=n(c,l);if(!d)return;o.push(d)}else if(c instanceof ut&&l instanceof ut){const d=this.mutatePartners(c,l,n);if(!d)return;d instanceof ut&&o.push(d)}}return i}}}get isClosedVolume(){const t=this._contours.length;return t>1&&(this.capped||this._contours[0].isAlmostEqual(this._contours[t-1]))}}class ri extends qs{solidPrimitiveType="torusPipe";_localToWorld;_radiusA;_radiusB;_sweep;_isReversed;constructor(t,e,n,i,s){super(s),this._localToWorld=t,this._radiusA=e,this._radiusB=n,this._sweep=i,this._isReversed=!1}clone(){const t=new ri(this._localToWorld.clone(),this._radiusA,this._radiusB,this._sweep.clone(),this.capped);return t._isReversed=this._isReversed,t}tryTransformInPlace(t){return t.matrix.isSingular()?!1:(t.multiplyTransformTransform(this._localToWorld,this._localToWorld),t.matrix.determinant()<0&&this._localToWorld.matrix.scaleColumnsInPlace(1,1,-1),!0)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t)?e:void 0}static createInFrame(t,e,n,i,s){if(e=Math.abs(f.correctSmallMetricDistance(e)),n=Math.abs(f.correctSmallMetricDistance(n)),e<n||e===0||n===0||i.isAlmostZero)return;let r=1,o=1,a=!1;t.matrix.determinant()<0&&(o*=-1);const c=i.clone();i.radians<0&&(c.setRadians(-i.radians),o*=-1,r*=-1,a=!0);const l=t.clone();l.matrix.scaleColumnsInPlace(1,r,o);const d=new ri(l,e,n,c,s);return d._isReversed=a,d}static createDgnTorusPipe(t,e,n,i,s,r,o){const a=e.unitCrossProductWithDefault(n,0,0,1),c=X.createOriginAndMatrixColumns(t,e,n,a);return ri.createInFrame(c,i,s,r,o)}static createAlongArc(t,e,n){if(A.isAlmostEqualRadiansAllowPeriodShift(0,t.sweep.startRadians)||(t=t.cloneInRotatedBasis(t.sweep.startAngle)),!t.isCircular){const r=t.perpendicularVector.sizedCrossProduct(t.vector0,t.matrixRef.columnXMagnitude());if(!r)return;t=N.create(t.center,t.vector0,r,t.sweep)}const i=t.toScaledMatrix3d(),s=X.createOriginAndMatrix(t.center,i.axes);return ri.createInFrame(s,i.r0,e,A.createRadians(t.sweep.sweepRadians),n)}getConstructiveFrame(){return this._localToWorld.cloneRigid()}cloneCenter(){return this._localToWorld.getOrigin()}cloneVectorX(){const t=this._localToWorld.matrix.columnX();return t.normalizeWithDefault(1,0,0,t)}cloneVectorY(){const t=this._localToWorld.matrix.columnY();return t.normalizeWithDefault(0,1,0,t)}cloneVectorZ(){const t=this._localToWorld.matrix.columnZ();return t.normalizeWithDefault(0,0,1,t)}getMajorRadius(){return this._radiusA*this._localToWorld.matrix.columnXMagnitude()}getMinorRadius(){return this._radiusB*this._localToWorld.matrix.columnZMagnitude()}getSweepAngle(){return this._sweep.clone()}getIsReversed(){return this._isReversed}getThetaFraction(){return this._sweep.radians/(Math.PI*2)}cloneLocalToWorld(){return this._localToWorld.clone()}isSameGeometryClass(t){return t instanceof ri}isAlmostEqual(t){return t instanceof ri?!(!this._sweep.isFullCircle&&this.capped!==t.capped||!this.cloneCenter().isAlmostEqual(t.cloneCenter())||!this.cloneVectorX().isAlmostEqual(t.cloneVectorX())||!this.cloneVectorY().isAlmostEqual(t.cloneVectorY())||!this.cloneVectorZ().isAlmostEqual(t.cloneVectorZ())||!f.isSameCoordinate(this.getMinorRadius(),t.getMinorRadius())||!f.isSameCoordinate(this.getMajorRadius(),t.getMajorRadius())||!this.getSweepAngle().isAlmostEqualNoPeriodShift(t.getSweepAngle())):!1}vFractionToRadians(t){return this._sweep.radians*t}dispatchToGeometryHandler(t){return t.handleTorusPipe(this)}constantVSection(t){const e=this.vFractionToRadians(t),n=Math.cos(e),i=Math.sin(e),s=this._radiusA,r=this._radiusB,o=this._localToWorld.multiplyXYZ(s*n,s*i,0),a=this._localToWorld.multiplyVectorXYZ(r*n,r*i,0),c=this._localToWorld.multiplyVectorXYZ(0,0,r);return tt.create(N.create(o,a,c))}constantUSection(t){const e=this._sweep.radians,n=t*2*Math.PI,i=this._radiusA,s=this._radiusB,o=this._localToWorld.matrix,a=this._localToWorld.multiplyXYZ(0,0,s*Math.sin(n)),c=i+s*Math.cos(n),l=o.multiplyXYZ(c,0,0),d=o.multiplyXYZ(0,c,0);return Pt.create(N.create(a,l,d,at.createStartEndRadians(0,e)))}extendRange(t,e){const n=this._sweep.radians,i=this._radiusA,s=this._radiusB,r=this._localToWorld,o=Math.ceil(n/(Math.PI/16)),a=16;let c=0,l=0,d=0,h=0,g=0,m=0,p=0,x=0,_=0;const I=n/o;for(let v=0;v<=o;v++)if(h=v*I,g=Math.cos(h),m=Math.sin(h),v===0||v===o?(c=-Math.PI,l=2*Math.PI/a,d=a):(c=-.5*Math.PI,l=Math.PI/a,d=2*a-1),e)for(_=0;_<=d;_++)x=c+_*l,p=i+s*Math.cos(x),t.extendTransformTransformedXYZ(e,r,g*p,m*p,Math.sin(x)*s);else for(_=0;_<=d;_++)x=c+_*l,p=i+s*Math.cos(x),t.extendTransformedXYZ(r,g*p,m*p,Math.sin(x)*s)}uvFractionToPoint(t,e,n){const i=e*this._sweep.radians,s=t*Math.PI*2,r=Math.cos(i),o=Math.sin(i),a=this._radiusA,c=this._radiusB,l=a+Math.cos(s)*c;return this._localToWorld.multiplyXYZ(l*r,l*o,c*Math.sin(s),n)}uvFractionToPointAndTangents(t,e,n){const i=e*this._sweep.radians,s=t*Math.PI*2,r=this._sweep.radians,o=Math.PI*2,a=Math.cos(i),c=Math.sin(i),l=Math.sin(s),d=Math.cos(s),h=this._radiusA,g=this._radiusB,m=h+Math.cos(s)*g,p=g*l,x=g*d;return At.createOriginAndVectors(this._localToWorld.multiplyXYZ(a*m,c*m,p),this._localToWorld.multiplyVectorXYZ(-a*p*o,-c*p*o,x*o),this._localToWorld.multiplyVectorXYZ(-m*c*r,m*a*r,0),n)}maxIsoParametricDistance(){const t=Math.abs(this.getMajorRadius()),e=Math.abs(this.getMinorRadius());return Q.create(e*Math.PI*2,(t+e)*this._sweep.radians)}get isSkew(){return!this._localToWorld.matrix.columnZ().isParallelTo(this._localToWorld.matrix.columnXCrossColumnY(),!0,!0)}get isClosedVolume(){return this.capped||this._sweep.isFullCircle}}class Pi{constructor(){}static _clothoidEvaluator;static _biquadraticEvaluator;static _blossEvaluator;static _sineEvaluator;static _cosineEvaluator;static findEvaluator(t){if(t==="clothoid")return this._clothoidEvaluator?this._clothoidEvaluator:this._clothoidEvaluator=new Nc;if(t==="bloss")return this._blossEvaluator?this._blossEvaluator:this._blossEvaluator=new zc;if(t==="biquadratic")return this._biquadraticEvaluator?this._biquadraticEvaluator:this._biquadraticEvaluator=new Vc;if(t==="sine")return this._sineEvaluator?this._sineEvaluator:this._sineEvaluator=new Oc;if(t==="cosine")return this._cosineEvaluator?this._cosineEvaluator:this._cosineEvaluator=new Lc}}class Nc extends Pi{constructor(){super()}fractionToCurvatureFraction(t){return t}fractionToCurvatureFractionDerivative(t){return 1}fractionToArea(t){return t*t*.5}}class zc extends Pi{constructor(){super()}fractionToCurvatureFraction(t){return t*t*(3-2*t)}fractionToCurvatureFractionDerivative(t){return 6*t*(1-t)}fractionToArea(t){return t*t*t*(1-.5*t)}}class Vc extends Pi{constructor(){super()}integratedBasis(t){return t*t*t*(2/3)}basis(t){return 2*t*t}basisDerivative(t){return 4*t}fractionToCurvatureFraction(t){return t<=.5?this.basis(t):1-this.basis(1-t)}fractionToCurvatureFractionDerivative(t){return t<=.5?this.basisDerivative(t):this.basisDerivative(1-t)}fractionToArea(t){if(t<=.5)return this.integratedBasis(t);const e=1-t;return .5-e+this.integratedBasis(e)}}class Oc extends Pi{constructor(){super()}fractionToCurvatureFraction(t){const e=2*Math.PI;return t-Math.sin(t*e)/e}fractionToCurvatureFractionDerivative(t){const e=2*Math.PI;return 1-Math.cos(t*e)}fractionToArea(t){const e=2*Math.PI;return .5*t*t+(Math.cos(t*e)-1)/(e*e)}}class Lc extends Pi{constructor(){super()}fractionToCurvatureFraction(t){return .5*(1-Math.cos(t*Math.PI))}fractionToCurvatureFractionDerivative(t){const e=Math.PI;return .5*e*Math.sin(t*e)}fractionToArea(t){const e=Math.PI;return .5*t-.5*Math.sin(t*e)/e}}class nr{radius0;radius1;bearing0;bearing1;curveLength;constructor(t,e,n,i,s){this.radius0=t,this.radius1=e,this.bearing0=n,this.bearing1=i,this.curveLength=s}numDefinedProperties(){return f.defined01(this.radius0)+f.defined01(this.radius1)+f.defined01(this.bearing0)+f.defined01(this.bearing1)+f.defined01(this.curveLength)}clone(){return new nr(this.radius0,this.radius1,this.bearing0===void 0?void 0:this.bearing0.clone(),this.bearing1===void 0?void 0:this.bearing1.clone(),this.curveLength)}getIsValidCompleteSet(){if(this.curveLength!==void 0&&this.bearing0!==void 0&&this.bearing1!==void 0&&this.radius0!==void 0&&this.radius1!==void 0){const t=Mt.radiusRadiusSweepRadiansToArcLength(this.radius0,this.radius1,this.bearing1.radians-this.bearing0.radians);return f.isSameCoordinate(this.curveLength,t)}return!1}tryResolveAnySingleUnknown(){if(this.getIsValidCompleteSet())return!0;if(this.bearing0&&this.bearing1){const t=this.bearing1.radians-this.bearing0.radians;return this.curveLength===void 0&&this.radius0!==void 0&&this.radius1!==void 0?(this.curveLength=Mt.radiusRadiusSweepRadiansToArcLength(this.radius0,this.radius1,t),!0):this.curveLength!==void 0&&this.radius0===void 0&&this.radius1!==void 0?(this.radius0=Mt.radius1LengthSweepRadiansToRadius0(this.radius1,this.curveLength,t),!0):this.curveLength!==void 0&&this.radius0!==void 0&&this.radius1===void 0?(this.radius1=Mt.radius0LengthSweepRadiansToRadius1(this.radius0,this.curveLength,t),!0):!1}return this.curveLength===void 0||this.radius0===void 0||this.radius1===void 0?!1:this.bearing0?(this.bearing1=A.createRadians(this.bearing0.radians+Mt.radiusRadiusLengthToSweepRadians(this.radius0,this.radius1,this.curveLength)),!0):this.bearing1?(this.bearing0=A.createRadians(this.bearing1.radians-Mt.radiusRadiusLengthToSweepRadians(this.radius0,this.radius1,this.curveLength)),!0):!1}almostEqualCoordinate(t,e){return t===void 0&&e===void 0?!0:t!==void 0&&e!==void 0?f.isSameCoordinate(t,e):!1}almostEqualBearing(t,e){return t===void 0&&e===void 0?!0:t!==void 0&&e!==void 0?t.isAlmostEqualNoPeriodShift(e):!1}isAlmostEqual(t){return!(!t||!this.almostEqualCoordinate(this.radius0,t.radius0)||!this.almostEqualCoordinate(this.radius1,t.radius1)||!this.almostEqualBearing(this.bearing0,t.bearing0)||!this.almostEqualBearing(this.bearing1,t.bearing1)||!this.almostEqualCoordinate(this.curveLength,t.curveLength))}applyScaleFactor(t){t!==0&&(this.radius0!==void 0&&(this.radius0*=t),this.radius1!==void 0&&(this.radius1*=t),this.curveLength!==void 0&&(this.curveLength*=t))}static areAlmostEqual(t,e){return t===void 0?e===void 0:t.isAlmostEqual(e)}}class ae extends Mt{curvePrimitiveType="transitionSpiral";radius01;bearing01;_globalStrokes;_activeStrokes;get activeStrokes(){return this._activeStrokes!==void 0?this._activeStrokes:this._globalStrokes}_evaluator;_arcLength01;_curvature01;constructor(t,e,n,i,s,r,o,a){super(t,r,s,a),this._evaluator=e,this.radius01=n,this.bearing01=i,this._arcLength01=o,this._globalStrokes=F.create(),this._curvature01=qt.create(0,1),this.refreshComputedProperties()}static defaultSpiralType="clothoid";globalFractionToBearingRadians(t){const e=this._evaluator.fractionToArea(t),n=this._arcLength01;return this.bearing01.startRadians+t*n*this._curvature01.x0+e*n*this._curvature01.signedDelta()}globalFractionToCurvature(t){const e=this._evaluator.fractionToCurvatureFraction(t);return this._curvature01.fractionToPoint(e)}fractionToBearingRadians(t){const e=this.activeFractionInterval.fractionToPoint(t);return this.bearing01.startRadians+e*this._arcLength01*(this._curvature01.x0+.5*e*(this._curvature01.x1-this._curvature01.x0))}fractionToCurvature(t){return this._curvature01.fractionToPoint(this.activeFractionInterval.fractionToPoint(t))}static _gaussFraction;static _gaussWeight;static _gaussMapper;static initWorkSpace(){ae._gaussFraction=new Float64Array(5),ae._gaussWeight=new Float64Array(5),ae._gaussMapper=(t,e,n,i)=>ie.setupGauss5(t,e,n,i)}fullSpiralIncrementalIntegral(t,e,n,i){const s=ae._gaussFraction,r=ae._gaussWeight,o=ae._gaussMapper(e,n,s,r),a=this._arcLength01;let c=0,l=0,d=0;for(let h=0;h<o;h++){const g=this.globalFractionToBearingRadians(s[h]);c=r[h]*a,l+=c*Math.cos(g),d+=c*Math.sin(g)}i?C.xyzPlusMatrixTimesXYZ(t,this.localToWorld.matrix,{x:l,y:d,z:0},t):t.addXYZInPlace(l,d,0)}refreshComputedProperties(){this._curvature01=qt.create(Mt.radiusToCurvature(this.radius01.x0),Mt.radiusToCurvature(this.radius01.x1)),this._globalStrokes.clear();const t=y.create();this._globalStrokes.appendStrokePoint(t);const e=16,n=1/e;for(let i=1;i<=e;i++){const s=(i-1)*n,r=i*n;this.fullSpiralIncrementalIntegral(t,s,r,!1),this._globalStrokes.appendStrokePoint(t)}if(this._globalStrokes.tryTransformInPlace(this.localToWorld),!this.activeFractionInterval.isExact01){this._activeStrokes===void 0&&(this._activeStrokes=F.create()),this._activeStrokes.clear();for(let i=0;i<=e;i++){const s=i*n;this._activeStrokes.addPoint(this.fractionToPoint(s))}}}static createRadiusRadiusBearingBearing(t,e,n,i,s){const r=Mt.radiusRadiusSweepRadiansToArcLength(t.x0,t.x1,e.sweepRadians);s===void 0&&(s="clothoid");const o=Pi.findEvaluator(s);if(o)return new ae(s,o,t.clone(),e.clone(),n.clone(),i.clone(),r,new nr(t.x0,t.x1,e.startAngle.clone(),e.endAngle.clone(),void 0))}static createFrom4OutOf5(t,e,n,i,s,r,o,a){t===void 0&&(t="clothoid");const c=Pi.findEvaluator(t);if(!c)return;const l=new nr(e,n,i,s,r),d=l.clone();if(l.tryResolveAnySingleUnknown())return o===void 0&&(o=qt.create(0,1)),new ae(t,c,qt.create(l.radius0,l.radius1),at.createStartEnd(l.bearing0,l.bearing1),o?o.clone():qt.create(0,1),a,l.curveLength,d)}setFrom(t){return this.localToWorld.setFrom(t.localToWorld),this.radius01.setFrom(t.radius01),this._curvature01.setFrom(t._curvature01),this.bearing01.setFrom(t.bearing01),this.localToWorld.setFrom(t.localToWorld),this.activeFractionInterval.setFrom(t.activeFractionInterval),this._arcLength01=t._arcLength01,this}clone(){return new ae(this._spiralType,this._evaluator,this.radius01.clone(),this.bearing01.clone(),this.activeFractionInterval.clone(),this.localToWorld.clone(),this._arcLength01,this._designProperties?.clone())}tryTransformInPlace(t){const e=this.applyRigidPartOfTransform(t);return e!==void 0&&(this._curvature01.x0/=e.scale,this._curvature01.x1/=e.scale,this.radius01.x0*=e.scale,this.radius01.x1*=e.scale,this._arcLength01*=e.scale),this.refreshComputedProperties(),!0}startPoint(t){return this.activeStrokes.startPoint(t)}endPoint(t){return this.activeStrokes.endPoint(t)}isInPlane(t){return t.isPointInPlane(this.localToWorld.origin)&&f.isSameCoordinate(0,this.localToWorld.matrix.dotColumnX(t.getNormalRef()))&&f.isSameCoordinate(0,this.localToWorld.matrix.dotColumnY(t.getNormalRef()))}quickLength(){return this.curveLength()}curveLength(){return this._arcLength01*this._activeFractionInterval.absoluteDelta()}curveLengthBetweenFractions(t,e){return this._arcLength01*(this._activeFractionInterval.absoluteDelta()*Math.abs(e-t))}isSameGeometryClass(t){return t instanceof Mt}emitStrokes(t,e){if(!e)this.activeStrokes.emitStrokes(t,e);else{const n=new pc(this);this.emitStrokableParts(n,e),n.claimLineString(t)}}emitStrokableParts(t,e){const n=this.computeStrokeCountForOptions(e);t.startParentCurvePrimitive(this);const i=this.activeStrokes;!(t.needPrimaryGeometryForStrokes===void 0?!1:t.needPrimaryGeometryForStrokes())&&n<=i.numPoints()?this.activeStrokes.emitStrokableParts(t,e):t.announceIntervalForUniformStepStrokes(this,n,0,1),t.endParentCurvePrimitive(this)}computeStrokeCountForOptions(t){let e;if(t){const n=Math.min(Math.abs(this.radius01.x0),Math.abs(this.radius01.x1));e=t.applyTolerancesToArc(n,this.bearing01.sweepRadians),e=t.applyMaxEdgeLength(e,this.curveLength()),e=t.applyMinStrokesPerPrimitive(e)}else e=Zt.applyAngleTol(void 0,4,this.bearing01.sweepRadians);return e}reverseInPlace(){this.activeFractionInterval.reverseInPlace(),this._activeStrokes===void 0&&(this._activeStrokes=this._globalStrokes.clone()),this._activeStrokes.reverseInPlace()}fractionToPoint(t,e){const n=this.activeFractionInterval.fractionToPoint(t),i=this._globalStrokes.packedPoints.length-1;if(i<1)return y.createZero(e);if(t>1){e=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(i,e);const s=1/i;let r=1,o=r+s;for(;o<n;)this.fullSpiralIncrementalIntegral(e,r,o,!0),r=o,o+=s;this.fullSpiralIncrementalIntegral(e,r,n,!0)}else if(t<0){e=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(0,e);const s=1/i;let r=0,o=r-s;for(;o>n;)this.fullSpiralIncrementalIntegral(e,r,o,!0),r=o,o-=s;this.fullSpiralIncrementalIntegral(e,r,n,!0)}else{const s=f.clampToStartEnd(n,0,1),r=Math.trunc(s*i),o=r/i;e=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(r,e),this.fullSpiralIncrementalIntegral(e,o,n,!0)}return e}fractionToPointAndDerivative(t,e){const n=this.activeFractionInterval.fractionToPoint(t);e=e||O.createZero(),this.fractionToPoint(t,e.origin);const i=this.globalFractionToBearingRadians(n),s=this._arcLength01*this.activeFractionInterval.signedDelta();return this.localToWorld.matrix.multiplyXY(s*Math.cos(i),s*Math.sin(i),e.direction),e}fractionToFrenetFrame(t,e){const n=this.activeFractionInterval.fractionToPoint(t);e=e||X.createIdentity(),e.origin.setFrom(this.fractionToPoint(t)),C.createRigidFromMatrix3d(this.localToWorld.matrix,mt.XYZ,e.matrix);const i=this.globalFractionToBearingRadians(n),s=Math.cos(i),r=Math.sin(i);return e.matrix.applyGivensColumnOp(0,1,s,r),e}fractionToPointAnd2Derivatives(t,e){const n=this.activeFractionInterval.fractionToPoint(t),i=this.fractionToPoint(t),s=this.globalFractionToBearingRadians(n),r=Math.cos(s),o=Math.sin(s),a=this._arcLength01*this.activeFractionInterval.signedDelta(),c=a,l=c*a,d=this.localToWorld.matrix.multiplyXY(c*r,c*o),h=this.localToWorld.matrix.multiplyXY(-l*o,l*r);return h.scaleInPlace(this.globalFractionToCurvature(n)),At.createCapture(i,d,h,e)}dispatchToGeometryHandler(t){return t.handleTransitionSpiral(this)}isAlmostEqual(t){return t instanceof ae?this.radius01.isAlmostEqual(t.radius01)&&this.bearing01.isAlmostEqualAllowPeriodShift(t.bearing01)&&this.localToWorld.isAlmostEqual(t.localToWorld)&&f.isSameCoordinate(this._arcLength01,t._arcLength01)&&this.activeFractionInterval.isAlmostEqual(t.activeFractionInterval)&&this._curvature01.isAlmostEqual(t._curvature01):!1}}ae.initWorkSpace();var ir;(function(u){u[u.Sections=0]="Sections",u[u.AlsoRuledSweep=1]="AlsoRuledSweep",u[u.AlsoMesh=2]="AlsoMesh"})(ir||(ir={}));class je{static addPartialSegment(t,e,n,i,s,r){(e||r>s)&&n!==void 0&&i!==void 0&&!f.isAlmostEqualNumber(s,r)&&t.tryAddChild(U.create(n.interpolate(s,i),n.interpolate(r,i)))}static createArcPointTangentPoint(t,e,n){const i=N.createCircularStartTangentEnd(t,e,n);if(i instanceof N)return i}static createFilletsInLineString(t,e,n=!0){if(Array.isArray(t))return this.createFilletsInLineString(new Bt(t),e,n);if(t instanceof F)return this.createFilletsInLineString(t.packedPoints,e,n);const i=typeof n=="boolean",s=i?n:n.allowCusp??!0,r=i?!1:n.filletClosure??!1,o=i?f.smallMetricDistance:n.closureTolerance??f.smallMetricDistance,a=i?f.smallMetricDistance:n.cuspTolerance??f.smallMetricDistance,c=i?!0:n.cuspSegments??!0,l=i?!1:n.simplifyPath??!1;let d=t.length;if(r&&t.almostEqualIndexIndex(0,d-1,o)&&d--,d<=1)return;const h=y.create(),g=y.create(),m=y.create(),p=[];for(let z=0;z<d;z++){let K=Math.abs(Array.isArray(e)?z<e.length?e[z]:0:e);Number.isFinite(K)||(K=0),K===0||!r&&(z===0||z===d-1)?p.push({fraction10:0,fraction12:0,point:t.getPoint3dAtUncheckedPointIndex(z)}):(t.getPoint3dAtUncheckedPointIndex(f.modulo(z-1,d),h),t.getPoint3dAtUncheckedPointIndex(z,g),t.getPoint3dAtUncheckedPointIndex(f.modulo(z+1,d),m),p.push(N.createFilletArc(h,g,m,K)))}const x=(z,K)=>z.fraction12+K.fraction10>1,_=(z,K,rt)=>t.distanceUncheckedIndexIndex(z,t.cyclicIndex(z+1))*(K.fraction12+rt.fraction10-1),I=(z,K)=>K===0?z.fraction12>1:z.fraction10>1,v=(z,K,rt)=>x(K,rt)&&(!s||_(z,K,rt)>a),S=z=>{z.fraction10=z.fraction12=0,z.arc=void 0};for(let z=0;z<(r?d:d-1);z++){const K=p[z],rt=p[f.modulo(z+1,d)];if(v(z,K,rt)){const ft=I(K,0),wt=I(rt,1);ft&&!wt?S(K):!ft&&wt||!ft&&!wt?S(rt):rt.fraction10<K.fraction12?S(K):S(rt),v(z,K,rt)&&(S(K),S(rt))}}const w=Pt.create();for(let z=0;z<d;z++){const K=p[z];if(w.tryAddChild(K.arc),z+1<d||r){const rt=p[f.modulo(z+1,d)];this.addPartialSegment(w,c,K.point,rt.point,K.fraction12,1-rt.fraction10)}}if(!l)return w;const T=o*o,R=w.children.filter(z=>z.range().diagonalLengthSquared(!0)>=T);if(R.length===0)return;const L=Pt.create(...R);return ot.consolidateAdjacentPrimitives(L,{consolidateLoopSeam:!0,duplicatePointTolerance:o,colinearPointTolerance:o}),L}static validateOpenPathStartEnd(t){const e=t.children.length,n=t.children[0],i=t.children[e-1];if(n instanceof N){const s=n.startPoint();t=Pt.create(U.create(s,s),...t.children)}if(i instanceof N){const s=i.endPoint();t=Pt.create(...t.children,U.create(s,s))}return t}static splitAndAppendArc(t,e,n){const i=y.createZero();for(let s=0;s<n.length-1;s++)t.tryAddChild(e.clonePartialCurve(n[s],n[s+1])),s+1<n.length-1&&(e.fractionToPoint(n[s+1],i),t.tryAddChild(U.create(i,i)))}static updatePathForRelaxedValidation(t,e,n){const i=new Pt,s=t.children.length;for(let r=0;r<s;r++){const o=t.children[r],a=o instanceof N?Math.abs(o.sweep.sweepDegrees):void 0,c=f.smallAngleDegrees;if(a!==void 0&&a>360+c)return;if(!e&&r===0){i.tryAddChild(o);continue}const l=t.cyclicCurvePrimitive(r-1),d=o.fractionToPointAndDerivative(0).direction,h=l.fractionToPointAndDerivative(1).direction,m=!d.isParallelTo(h,!1,!0,n)&&(o instanceof N&&(l instanceof U||l instanceof F)||l instanceof N&&(o instanceof U||o instanceof F));if(o instanceof N&&l instanceof N||m){const x=o.startPoint();i.tryAddChild(U.create(x,x))}a!==void 0&&a>120&&a<=240?je.splitAndAppendArc(i,o,[0,.5,1]):a!==void 0&&a>240&&a<=360+c?je.splitAndAppendArc(i,o,[0,1/3,2/3,1]):i.tryAddChild(o)}return i}static validateArcNeighbors(t,e,n){const i=t.getChild(e);if(!i||!(i instanceof N))return!1;const s=t.cyclicCurvePrimitive(e-1);if(!s||!(s instanceof U)&&!(s instanceof F))return!1;const r=i.fractionToPointAndDerivative(0).direction,o=s.fractionToPointAndDerivative(1).direction;if(!r.isParallelTo(o,!1,!0,n))return!1;const a=t.cyclicCurvePrimitive(e+1);if(!a||!(a instanceof U)&&!(a instanceof F))return!1;const c=i.fractionToPointAndDerivative(1).direction,l=a.fractionToPointAndDerivative(0).direction;return!!c.isParallelTo(l,!1,!0,n)}static validateFilletedLineString(t,e,n){if(t.children.length===0)return;const i=n?.relaxedValidation??!1;let s=t;if(e||(s=this.validateOpenPathStartEnd(s)),i&&(s=this.updatePathForRelaxedValidation(s,e,n?.parallelOptions)),s===void 0)return;const r=s.children.length;for(let o=0;o<r;o++){const a=s.children[o];if(!(a instanceof N)&&!(a instanceof U)&&!(a instanceof F)||a instanceof N&&(a.circularRadius()===void 0||Math.abs(a.sweep.sweepDegrees)>180-f.smallAngleDegrees||!this.validateArcNeighbors(s,o,n?.parallelOptions)))return}return s}static addJointBetweenConnectedArcs(t,e,n,i){if(!n&&e<2)return;const s=t.getChild(e);if(!s||!(s instanceof N))return;const r=t.cyclicCurvePrimitive(e-1);if(!r||!(r instanceof U)||r.curveLength()>0)return;const o=t.cyclicCurvePrimitive(e-2);!o||!(o instanceof N)||i.push([r.startPoint(),0])}static fromFilletedLineString(t,e){const n=t instanceof tt?Pt.create(...t.children):t,i=n.isPhysicallyClosedCurve(e?.distanceTol),s=this.validateFilletedLineString(n,i,e);if(!s)return;const r=[],o=s.children.length,a=s.cyclicCurvePrimitive(-1);let c=i&&a&&a instanceof N;for(let l=0;l<o;l++){const d=s.children[l];if(d instanceof N){this.addJointBetweenConnectedArcs(s,l,i,r),c=!0;const h=d.computeTangentIntersection(),g=d.circularRadius();if(g!==void 0&&h!==void 0)r.push([h,g]);else return}else if(d instanceof U)c?c=!1:r.push([d.startPoint(),0]);else if(d instanceof F){const h=c?1:0;c=!1;for(let g=h;g<d.numPoints()-1;g++)r.push([d.pointAtUnchecked(g),0])}}if(i)r.length>0&&!r[0][0].isAlmostEqual(r[r.length-1][0],e?.distanceTol)&&r.push(r[0]);else{const l=s.endPoint();l&&r.push([l,0])}return r}static createRectangleXY(t,e,n,i,s=0,r){let o=f.correctSmallMetricDistance(r);const a=Math.min(t,n),c=Math.max(t,n),l=Math.min(e,i),d=Math.max(e,i);if(o=Math.min(Math.abs(o),.5*(c-a),.5*(d-l)),o===0)return tt.createPolygon([y.create(a,l,s),y.create(c,l,s),y.create(c,d,s),y.create(a,d,s),y.create(a,l,s)]);{const h=P.create(o,0,0),g=P.create(0,o,0),m=a+o,p=l+o,x=c-o,_=d-o,I=[y.create(x,_,s),y.create(m,_,s),y.create(m,p,s),y.create(x,p,s)],v=tt.create();for(let S=0;S<4;S++){const w=I[S],T=I[(S+1)%4],R=P.createStartEnd(w,T),L=N.create(w,h,g,at.createStartEndDegrees(0,90));v.tryAddChild(L);const z=L.endPoint();R.isAlmostZero||v.tryAddChild(U.create(z,z.plus(R))),h.rotate90CCWXY(h),g.rotate90CCWXY(g)}return v}}static appendToArcInPlace(t,e,n=!1,i=f.smallMetricDistance){if(t.center.isAlmostEqual(e.center,i)){const s=f.split3WaySign(t.sweep.sweepRadians*e.sweep.sweepRadians,-1,0,1),r=t.angleToPointAndDerivative(t.sweep.fractionToAngle(1));t.sweep.sweepRadians<0&&r.direction.scaleInPlace(-1);const o=e.angleToPointAndDerivative(e.sweep.fractionToAngle(0));if(e.sweep.sweepRadians<0&&o.direction.scaleInPlace(-1),r.isAlmostEqual(o,i))return t.sweep.setStartEndRadians(t.sweep.startRadians,t.sweep.startRadians+t.sweep.sweepRadians+s*e.sweep.sweepRadians),!0;if(n&&(o.direction.scaleInPlace(-1),r.isAlmostEqual(o,i)))return t.sweep.setStartEndRadians(t.sweep.startRadians,t.sweep.startRadians+t.sweep.sweepRadians-s*e.sweep.sweepRadians),!0}return!1}static assembleArcChainOnEllipsoid(t,e,n=.5){const i=Pt.create();for(let s=0;s+1<e.length;s++){const r=t.sectionArcInPlaneOfInterpolatedNormal(e[s].toAngles(),n,e[s+1].toAngles());i.tryAddChild(r)}return i}static appendGeometryQueryArray(t,e){if(t instanceof Ae)e.push(t);else if(Array.isArray(t))for(const n of t)this.appendGeometryQueryArray(n,e)}static createPipeSegments(t,e){if(t instanceof U)return xi.createAxisPoints(t.startPoint(),t.endPoint(),e,e,!1);if(t instanceof N)return ri.createAlongArc(t,e,!1);if(t instanceof st){const n=it.create();return n.addMiteredPipes(t,e),n.claimPolyface()}else if(t instanceof de){const n=[];for(const i of t.children){const s=this.createPipeSegments(i,e);this.appendGeometryQueryArray(s,n)}return n}}static startPointAndTangent(t){if(t instanceof st)return t.fractionToPointAndDerivative(0);if(t.length<2)return;Array.isArray(t)&&(t=new Bt(t));const e=O.createZero();return t.getPoint3dAtUncheckedPointIndex(0,e.origin),t.vectorIndexIndex(0,1,e.direction),e}static createArcFromSectionData(t,e){const n=je.startPointAndTangent(t);if(!n)return;let i;if(e instanceof N)i=e.clone(),i.center=n.origin;else{const s=P.create(),r=P.create(),o=typeof e=="number"?e:e.x,a=typeof e=="number"?e:e.y,c=C.createRigidHeadsUp(n.direction,mt.ZXY);c.columnX(s).scaleInPlace(o),c.columnY(r).scaleInPlace(a),i=N.create(n.origin,s,r)}return i.binormalVector().dotProduct(n.direction)<0&&i.reverseInPlace(),i}static createMiteredPipeSections(t,e){const n=je.createArcFromSectionData(t,e);if(!n)return[];const i=je.createMiteredSweepSections(t,n);return i?i.sections:[]}static strokeSmoothCurve(t,e){let n,i;if(t instanceof st){n=t.fractionToPointAndDerivative(0).direction,i=t.fractionToPointAndDerivative(1).direction;const s=F.create();t.emitStrokes(s,e),t=s.packedPoints}else if(t instanceof de){n=t.startPointAndDerivative()?.direction,i=t.endPointAndDerivative()?.direction;const s=t.getPackedStrokes(e);if(!s)return;t=s}else Array.isArray(t)&&(t=new Bt(t));return{strokes:t,startTangent:n,endTangent:i}}static alignFirstAndLastBisectorPlanes(t,e,n,i){const s=i?.startTangent??n?.startTangent??t.getNormalRef(),r=i?.endTangent??n?.endTangent??e.getNormalRef();if(i?.wrapIfPhysicallyClosed&&t.getOriginRef().isAlmostEqual(e.getOriginRef())){const o=s.plus(r);if(o.tryNormalizeInPlace()){t.getNormalRef().setFrom(o),e.getNormalRef().setFrom(o);return}}s.tryNormalizeInPlace()&&t.getNormalRef().setFrom(s),r.tryNormalizeInPlace()&&e.getNormalRef().setFrom(r)}static alignClosedCurveToPlane(t,e){let n;if(t instanceof st?t.startPoint().isAlmostEqual(t.endPoint())&&(n=tt.create(t)):t.isAnyRegion()&&(n=t),n){const i=C.createRigidHeadsUp(e).transpose(),s=n.cloneTransformed(X.createOriginAndMatrix(void 0,i)),r=ot.computeXYArea(s);r&&r<0&&t.reverseInPlace()}}static doSweepToPlane(t,e,n,i,s){const r=P.createStartEnd(e.getOriginRef(),n.getOriginRef()),o=X.createFlattenAlongVectorToPlane(r,i.getOriginRef(),i.getNormalRef());if(o===void 0)return s;const a=s.cloneTransformed(o);return a===void 0?s:(t.planes.push(i),t.sections.push(a),a)}static createMiteredSweepSections(t,e,n){n||(n={});const i=this.strokeSmoothCurve(t,n.strokeOptions);if(!i)return;const s=gn.createBisectorPlanesForDistinctPoints(i.strokes);if(!s||s.length<2)return;this.alignFirstAndLastBisectorPlanes(s[0],s[s.length-1],i,n),this.alignClosedCurveToPlane(e,s[0].getNormalRef());const r={sections:[],planes:[]};let o=this.doSweepToPlane(r,s[0],s[1],s[0],e);for(let a=1;a<s.length;a++)o=this.doSweepToPlane(r,s[a-1],s[a],s[a],o);if(n.outputSelect){const a=yi.create(r.sections,n.capped??!1);if(a&&(r.ruledSweep=a,ir.AlsoMesh===n.outputSelect)){const c=it.create(n.strokeOptions);c.addRuledSweep(a),r.mesh=c.claimPolyface()}}return r}static createArcPointTangentRadius(t,e,n,i,s){return N.createCircularStartTangentRadius(t,e,n,i,s)}static createLineSpiralSpiralLine(t,e,n,i){const s=P.createStartEnd(e,n),r=P.createStartEnd(n,i),o=s.magnitude(),a=Math.atan2(s.y,s.x),c=s.angleToXY(r),l=.5*c.radians,d=a+c.radians,h=C.createRotationAroundAxisIndex(ze.Z,A.createRadians(a)),g=X.createRefs(e.clone(),h),m=ae.createFrom4OutOf5(t,0,void 0,A.createRadians(0),A.createRadians(l),o,void 0,g);if(m){const p=a+l,x=P.createPolar(1,A.createRadians(p)),_=x.dotProductStartEnd(e,n),I=x.dotProductStartEnd(e,m.endPoint()),v=_/I,S=ae.createFrom4OutOf5(t,0,void 0,A.createRadians(0),A.createRadians(l),o*v,void 0,g);if(S===void 0)return;const w=s.magnitude(),T=P.createStartEnd(n,i);T.scaleToLength(w,T);const R=n.plus(T),L=C.createRotationAroundAxisIndex(ze.Z,A.createRadians(d+Math.PI)),z=X.createRefs(R,L),K=ae.createFrom4OutOf5(t,0,-S.radius01.x1,A.zero(),void 0,S.curveLength(),qt.create(1,0),z);return K===void 0?void 0:[S,K]}}static createLineSpiralSpiralLineWithSpiralLength(t,e,n,i,s){const r=P.createStartEnd(e,n),o=P.createStartEnd(n,i),a=Math.atan2(r.y,r.x),c=r.angleToXY(o),l=.5*c.radians,d=.5*(Math.PI-c.radians),h=Math.atan2(-o.y,-o.x),g=ae.createFrom4OutOf5(t,0,void 0,A.zero(),A.createRadians(l),s,void 0,X.createIdentity());if(g){const m=g.fractionToPoint(1),p=e.distance(n),x=i.distance(n),_=m.y/Math.tan(d),I=f.conditionalDivideFraction(p-_-m.x,p),v=f.conditionalDivideFraction(x-_-m.x,x);if(I!==void 0&&v!==void 0){const S=C.createRotationAroundAxisIndex(ze.Z,A.createRadians(a)),w=e.interpolate(I,n),T=X.createRefs(w,S),R=ae.createFrom4OutOf5(t,0,void 0,A.zero(),A.createRadians(l),s,void 0,T);if(R===void 0)return;const L=C.createRotationAroundAxisIndex(ze.Z,A.createRadians(h)),z=i.interpolate(v,n),K=X.createRefs(z,L),rt=ae.createFrom4OutOf5(t,0,void 0,A.zero(),A.createRadians(-l),s,void 0,K);return rt===void 0?void 0:[R,rt]}}}static createLineSpiralArcSpiralLine(t,e,n,i,s,r,o){const a=P.createStartEnd(e,n);a.z=0;const c=P.createStartEnd(i,n);c.z=0;const l=a.normalize(),d=c.normalize();if(l===void 0||d===void 0)return;const h=l.unitPerpendicularXY(),g=d.unitPerpendicularXY(),m=a.angleToXY(c),p=f.split3WaySign(m.radians,1,-1,-1),x=-p,_=p*Math.abs(o),I=x*Math.abs(o),v=ae.createFrom4OutOf5(t,0,_,A.zero(),void 0,s,void 0,X.createIdentity()),S=ae.createFrom4OutOf5(t,0,I,A.zero(),void 0,r,void 0,X.createIdentity());if(v===void 0||S===void 0)return;const w=v.fractionToPointAndUnitTangent(1),T=S.fractionToPointAndUnitTangent(1),R=w.origin.x-_*w.direction.y,L=w.origin.y+_*w.direction.x,z=T.origin.x-I*T.direction.y,K=T.origin.y+I*T.direction.x,rt=P.createAdd2Scaled(l,R,h,L),ft=P.createAdd2Scaled(d,z,g,K),wt=Q.create();if(bt.linearSystem2d(l.x,-d.x,l.y,-d.y,ft.x-rt.x,ft.y-rt.y,wt)){const Yt=n.plusScaled(l,wt.x),k=n.plusScaled(d,wt.y),E=X.createOriginAndMatrixColumns(Yt,l,h,P.unitZ()),q=X.createOriginAndMatrixColumns(k,d,g,P.unitZ());v.tryTransformInPlace(E),S.tryTransformInPlace(q);const et=v.fractionToPointAndUnitTangent(1),Nt=S.fractionToPointAndUnitTangent(1);Nt.direction.scaleInPlace(-1);const se=et.direction.angleToXY(Nt.direction);_<0&&se.setRadians(-se.radians);const Ne=je.createArcPointTangentRadius(et.origin,et.direction,_,void 0,se);return Ne===void 0?void 0:[v,Ne,S]}}static planePlaneIntersectionRay(t,e){const n=t.altitudeXYZ(0,0,0),i=e.altitudeXYZ(0,0,0),s=t.normalX(),r=t.normalY(),o=t.normalZ(),a=e.normalX(),c=e.normalY(),l=e.normalZ(),d=f.crossProductXYXY(r,o,c,l),h=f.crossProductXYXY(o,s,l,a),g=f.crossProductXYXY(s,r,a,c),m=bt.linearSystem3d(s,r,o,a,c,l,d,h,g,-n,-i,0);if(m!==void 0)return O.createXYZUVW(m.x,m.y,m.z,d,h,g)}}class sr extends Gi{_perpVector;_maxDistance;_localToWorld;constructor(t){super(),this._perpVector=P.createZero(),this._maxDistance=0,this._localToWorld=t.toRigidZFrame()}_localPoint=y.create();_worldPoint=y.create();announcePoint(t){this._localToWorld.multiplyInversePoint3d(t,this._localPoint);const e=this._localPoint.magnitudeXY();e>=this._maxDistance&&(this._maxDistance=e,this._perpVector.setFromPoint3d(this._localPoint),this._perpVector.z=0,this._localToWorld.matrix.multiplyXY(this._localPoint.x,this._localPoint.y,this._perpVector))}handleLineSegment3d(t){this.announcePoint(t.startPoint(this._worldPoint)),this.announcePoint(t.endPoint(this._worldPoint))}handleLineString3d(t){for(let e=0;e<t.numPoints();e++)t.pointAt(e,this._worldPoint),this.announcePoint(this._worldPoint)}handleArc3d(t){const e=Zt.applyAngleTol(void 0,3,t.sweep.sweepRadians,.1),n=1/e;for(let i=0;i<=e;i++)t.fractionToPoint(i*n,this._worldPoint),this.announcePoint(this._worldPoint)}static computeMaxVectorFromRay(t,e){const n=new sr(t);return e.dispatchToGeometryHandler(n),n._perpVector.clone()}static buildRotationalNormalsInLineStrings(t,e,n){if(t instanceof F){const i=t.packedPoints,s=t.packedDerivatives,r=t.ensureEmptySurfaceNormals();if(s&&r){const o=P.create(),a=P.create(),c=y.create(),l=i.length;for(let d=0;d<l;d++)i.getPoint3dAtUncheckedPointIndex(d,c),e.perpendicularPartOfVectorToTarget(c,o),o.isAlmostZero?e.direction.crossProduct(n,a):e.direction.crossProduct(o,a),t.packedDerivatives.getVector3dAtCheckedVectorIndex(d,o),o.crossProduct(a,a),a.normalizeInPlace(),r.push(a)}}else if(t.children){const i=t.children;for(const s of i)this.buildRotationalNormalsInLineStrings(s,e,n)}}}class ya{startSweeps(t,e,n){return!0}endSweeps(t,e,n){return!0}}class Uc extends ya{myMap;constructor(){super(),this.myMap=dn.createWithComponentIndex()}startPass(t){return t===0?(this.myMap.numStroke=0,!0):t===1}visit(t,e){return t===0?(e.numStroke>this.myMap.numStroke&&(this.myMap.numStroke=e.numStroke),!0):t===1?(e.numStroke=this.myMap.numStroke,!0):!1}endPass(t){return!0}}class Bc extends ya{maxCurveLength;constructor(){super(),this.maxCurveLength=0}startPass(t){return t===0?(this.maxCurveLength=0,!0):t===1}visit(t,e){return t===0?(this.maxCurveLength=f.maxXY(e.curveLength,this.maxCurveLength),!0):t===1?(e.a0=0,e.a1=this.maxCurveLength,!0):!1}endPass(t){return!0}}class rr{maps;parent;options;constructor(t,e){this.parent=t,this.maps=[],this.options=e}static create(t,e){const n=new rr(t,e);n.parent=t;for(const i of t.children)i.computeAndAttachRecursiveStrokeCounts(e),i.strokeData&&n.maps.push(i.strokeData);return n}getStrokes(){const t=F.create();this.options&&(this.options.needNormals||this.options.needParams)&&(t.ensureEmptyFractions(),t.ensureEmptyDerivatives(),t.ensureEmptyUVParams());for(const e of this.maps)e.primitive&&e.primitive.addMappedStrokesToLineString3D(e,t);return t}static applySummed01LimitsWithinArray(t,e){let n=e;for(const i of t)i.a0+=n,i.componentData?i.a1=this.applySummed01LimitsWithinArray(i.componentData,i.a0):i.a1+=n,n=i.a1;return n}applySummed01Limits(t){return rr.applySummed01LimitsWithinArray(this.maps,t)}}class Zn{chains;parent;constructor(t){this.parent=t,this.chains=[]}static create(t,e){const n=new Zn(t),i=r=>n.chains.push(rr.create(r,e)),s=r=>{for(const o of r.children)i(o)};if(t instanceof ve)for(const r of t.children)r instanceof Wt?s(r):i(r);else t instanceof Wt?s(t):t instanceof de&&i(t);return n}static areSectionsCompatible(t,e){if(t.length<2)return!0;const n=t[0].chains.length;for(let i=1;i<t.length;i++){if(t[i].chains.length!==n)return!1;for(let s=0;s<n;s++){const r=t[0].chains[s].maps.length;if(t[i].chains[s].maps.length!==r)return!1;for(let o=0;o<r;o++)if(!t[0].chains[s].maps[o].isCompatibleComponentStructure(t[i].chains[s].maps[o],e))return!1}}return!0}static remapa0a1WithinEachChain(t){for(const e of t)for(const n of e.chains)n.applySummed01Limits(0)}static applyMultipassVisitorCallback(t,e,n,i,s){const r=t.length;if(!s.startSweeps(e,n,i))return!1;for(let o=0;s.startPass(o);o++){for(let a=0;a<r;a++){let c=t[a].chains[e].maps[n];if(c.componentData&&i!==void 0&&(c=c.componentData[i]),!s.visit(o,c))return!1}if(!s.endPass(o))return!1}return s.endSweeps(e,n,i)}static runMultiPassVisitorAtCorrespondingPrimitives(t,e){if(!Zn.areSectionsCompatible(t,!1))return!1;const i=t[0].chains.length;for(let s=0;s<i;s++){const r=t[0].chains[s].maps.length;for(let o=0;o<r;o++){const a=t[0].chains[s].maps[o].componentData?.length??0;if(a>0){for(let c=0;c<a;c++)if(!this.applyMultipassVisitorCallback(t,s,o,c,e))return!1}else if(!this.applyMultipassVisitorCallback(t,s,o,void 0,e))return!1}}return!0}static enforceStrokeCountCompatibility(t){if(t.length<2)return!0;const e=new Uc;return this.runMultiPassVisitorAtCorrespondingPrimitives(t,e)}static enforceCompatibleDistanceSums(t){if(t.length<2)return!0;const e=new Bc;return this.runMultiPassVisitorAtCorrespondingPrimitives(t,e)?(this.remapa0a1WithinEachChain(t),!0):!1}getStrokes(){if(this.chains.length===1)return this.chains[0].getStrokes();{const t=Wt.create();for(const e of this.chains){const n=e.getStrokes();n instanceof F&&t.tryAddChild(tt.create(n))}return t}}static extendDistanceRangeBetweenStrokes(t,e,n){if(t instanceof F){if(e instanceof F&&t.numPoints()===e.numPoints()){const i=t.numPoints(),s=y.create(),r=y.create(),o=t.packedPoints,a=e.packedPoints;for(let c=0;c<i;c++)o.getPoint3dAtCheckedPointIndex(c,s),a.getPoint3dAtCheckedPointIndex(c,r),n.extendX(s.distance(r));return!0}}else if(t instanceof Wt){if(e instanceof Wt){const i=t.children,s=e.children,r=i.length;if(r===s.length){for(let o=0;o<r;o++)if(!this.extendDistanceRangeBetweenStrokes(i[o],s[o],n))return!1;return!0}}}else if(t instanceof de&&e instanceof de){const i=t.children,s=e.children,r=i.length;if(r===s.length){for(let o=0;o<r;o++)if(!this.extendDistanceRangeBetweenStrokes(i[o],s[o],n))return!1;return!0}}return!1}}class Pa{static sampledRangeOfOffsetPatch(t,e,n,i){const s=J.createNull();n=Math.ceil(f.clamp(n,2,500)),i=Math.ceil(f.clamp(i,2,500));const r=1/n,o=1/i,a=y.create(),c=At.createXYPlane();let l,d;for(let h=0;h<=i;h++){d=h*o;for(let g=0;g<=n;g++)if(l=g*r,e!==void 0){t.uvFractionToPointAndTangents(l,d,c);const m=c.unitNormal();m!==void 0&&(c.origin.addScaledInPlace(m,e),s.extend(c.origin))}else t.uvFractionToPoint(l,d,a),s.extendXYZ(a.x,a.y,a.z)}return s}static sampledRangeOfOffsetEllipsoidPatch(t,e,n){const i=Zt.applyAngleTol(n,2,t.latitudeSweep.sweepRadians,A.degreesToRadians(5)),s=Zt.applyAngleTol(n,2,t.longitudeSweep.sweepRadians,A.degreesToRadians(5));return this.sampledRangeOfOffsetPatch(t,e,i,s)}constructor(){}static createLinestringOnUVLine(t,e,n,i,s,r,o=!1,a=!1){const c=F.create(),l=y.create();let d,h,g;const m=r+1;for(let p=0;p<m;p++)d=p/r,h=f.interpolate(e,d,i),g=f.interpolate(n,d,s),t.uvFractionToPoint(h,g,l),c.addPoint(l),o&&c.addUVParamAsUV(h,g),a&&c.addFraction(d);return c}}class or{static points=[y.create(0,0,0),y.create(1,0,0),y.create(0,1,0),y.create(1,1,0),y.create(0,0,1),y.create(1,0,1),y.create(0,1,1),y.create(1,1,1)];static pointsClone(){const t=[];for(const e of this.points)t.push(e.clone());return t}static primaryCapId=-1;static cornerIndexCCW=[[1,0,2,3],[4,5,7,6],[0,1,5,4],[1,3,7,5],[3,2,6,7],[2,0,4,6]];static partnerFace=[[5,4,3,2],[2,3,4,5],[0,3,1,5],[0,4,1,2],[0,5,1,3],[0,2,1,4]];static faceId=[[or.primaryCapId,0],[or.primaryCapId,1],[0,0],[0,1],[0,2],[0,3]];static faceDirections=[[[0,1,2],[-1,1,-1]],[[0,1,2],[1,1,1]],[[0,2,1],[1,-1,1]],[[1,2,0],[1,1,1]],[[0,2,1],[-1,1,1]],[[1,2,0],[-1,1,-1]]];static axisEdgeVertex=[[[0,1],[2,3],[4,5],[6,7]],[[0,2],[1,3],[4,6],[5,7]],[[0,4],[1,5],[2,6],[3,7]]]}class Zc{points;begin;end;constructor(t,e,n){this.points=t,this.begin=e,this.end=n}static createComplete(t){return new this(t,0,t.length)}static createBeginEnd(t,e,n){return new this(t,e,n)}static createBeginLength(t,e,n){return new this(t,e,e+n)}advanceBegin(){return this.begin++,this.begin<this.end}advanceEnd(){return this.end++,this.end>this.points.length&&(this.end=this.points.length),this.begin<this.end}localIndexToParentIndex(t){if(t>=0){const e=this.begin+t;if(e<this.points.length)return e}}get isValidSubset(){return this.length===0||this.localIndexToParentIndex(0)!==void 0&&this.localIndexToParentIndex(this.length-1)!==void 0}restrictEnd(){this.end>this.points.length&&(this.end=this.points.length)}get isNonEmpty(){return this.begin<this.end}advanceToTail(t){return this.begin=t.end-1,this.isNonEmpty}advanceToHead(t){return this.begin=t.begin,this.isNonEmpty}setFrom(t,e,n){this.points=t.points,this.begin=e===void 0?t.begin:e,this.end=n===void 0?t.end:n,this.restrictEnd()}get length(){return this.end>this.begin?this.end-this.begin:0}get isSingleton(){return this.begin+1===this.end}}class ar extends Zc{}class Xe extends gt{_quality;_isValid;id;constructor(t,e,n,i,s,r){super(t,e,n),this._isValid=r,this._quality=s,this.id=i}setFrom(t){return super.setFrom(t),this._isValid=t._isValid,this._quality=t._quality,this.id=t.id,this}static createFromIndexedXYZ(t,e,n,i,s,r,o,a){a||(a=new Xe(y.create(),y.create(),y.create(),o,0,!1)),a.id=o;let c=0;return t.getPoint3dAtCheckedPointIndex(e,a.points[0])!==void 0&&c++,n.getPoint3dAtCheckedPointIndex(i,a.points[1])!==void 0&&c++,s.getPoint3dAtCheckedPointIndex(r,a.points[2])!==void 0&&c++,c===3?a.updateAspectRatio():a.markInvalid(),a}get isValid(){return this._isValid}markInvalid(t){this._isValid=!1,t!==void 0&&(this._quality=t)}updateAspectRatio(){this._quality=super.aspectRatio,this._isValid=this._quality>0}clone(t){return t?t.setFrom(this):new Xe(this.points[0].clone(),this.points[1].clone(),this.points[2].clone(),this.id,this._quality,this._isValid)}static copyWithLowerQuality(t,e,n){if(n=t.clone(n),e.isValid){const i=t.dotProductOfCrossProductsFromOrigin(e);n._quality=f.minXY(t.aspectRatio,e.aspectRatio),i<0&&(n._quality-=1)}return n}static updateIfOtherHasHigherQuality(t,e){e.isValid&&e._quality>t._quality&&t.setFrom(e)}}class go{_vector1;constructor(t){this._turnRadians=t,this._xyzA=y.create(),this._xyzB=y.create(),this._forwardA=P.create(),this._forwardB=P.create(),this._vector1=P.create(),this._crossA=P.create(),this._crossB=P.create()}_turnRadians;isForwardVector(t,e,n){if(t.dotProduct(e)<=0)return!1;const i=t.angleFromPerpendicular(n);return!(Math.abs(i.radians)>this._turnRadians)}isPlanarBase(t,e,n,i,s,r,o,a,c,l){return e+1<t.length&&i+1<n.length&&(t.getPoint3dAtUncheckedPointIndex(e,s),n.getPoint3dAtUncheckedPointIndex(i,a),t.vectorXYAndZIndex(s,e+1,o),n.vectorXYAndZIndex(a,i+1,l),P.createStartEnd(s,a,this._vector1),this._vector1.crossProduct(o,r),this._vector1.crossProduct(l,c),!s.isAlmostEqual(a)&&r.angleTo(c).radians<this._turnRadians)}advanceToPlanarLimit(t,e,n,i,s,r,o,a){for(e.setFrom(t,t.begin,n);e.end<t.end&&(e.points.vectorXYAndZIndex(i,e.end,this._vector1),!(!this.isForwardVector(this._vector1,r,s)||!this.isForwardVector(this._vector1,a,o)||e.end>0&&(e.points.vectorIndexIndex(e.end-1,e.end,this._vector1),!this.isForwardVector(this._vector1,r,s))));)e.end++}_triangleA1;_triangleB1;_triangleA2;_triangleB2;_triangleA3;_triangleB3;_bestTriangle;_workTriangle;addGreedy(t,e,n,i=!1){for(t.restrictEnd(),e.restrictEnd();t.length>1&&e.length>1;)if(this._triangleA1=Xe.createFromIndexedXYZ(t.points,t.begin,t.points,t.begin+1,e.points,e.begin,1,this._triangleA1),this._triangleA2=Xe.createFromIndexedXYZ(t.points,t.begin+1,t.points,t.begin+2,e.points,e.begin,2,this._triangleA2),this._triangleA3=Xe.createFromIndexedXYZ(t.points,t.begin,t.points,t.begin+1,e.points,e.begin+1,3,this._triangleA3),this._triangleB1=Xe.createFromIndexedXYZ(e.points,e.begin+1,e.points,e.begin,t.points,t.begin,-1,this._triangleB1),this._triangleB2=Xe.createFromIndexedXYZ(e.points,e.begin+2,e.points,e.begin+1,t.points,t.begin,-2,this._triangleB2),this._triangleB3=Xe.createFromIndexedXYZ(e.points,e.begin+1,e.points,e.begin,t.points,t.begin+1,-3,this._triangleB3),this._bestTriangle=Xe.copyWithLowerQuality(this._triangleA1,this._triangleB3,this._bestTriangle),this._workTriangle=Xe.copyWithLowerQuality(this._triangleB1,this._triangleA3,this._workTriangle),Xe.updateIfOtherHasHigherQuality(this._bestTriangle,this._workTriangle),this._bestTriangle.id>0){if(t.advanceBegin(),n(this._bestTriangle),i)return}else if(e.advanceBegin(),n(this._bestTriangle),i)return;if(t.isSingleton)for(;e.length>=2;)this._workTriangle=Xe.createFromIndexedXYZ(e.points,e.begin+1,e.points,e.begin,t.points,t.begin,0,this._workTriangle),n(this._workTriangle),e.advanceBegin();if(e.isSingleton)for(;t.length>=2;)this._workTriangle=Xe.createFromIndexedXYZ(t.points,t.begin,t.points,t.begin+1,e.points,e.begin,0,this._workTriangle),n(this._workTriangle),t.advanceBegin()}_xyzA;_xyzB;_forwardA;_forwardB;_crossA;_crossB;emitTriangles(t,e,n){this.emitTrianglesGo(Ia(t),Ia(e),n)}emitTrianglesGo(t,e,n){const i=ar.createComplete(t),s=ar.createComplete(e),r=ar.createComplete(t),o=ar.createComplete(e);for(;i.length>0&&s.length>0&&(i.length>1||s.length>1);)this.isPlanarBase(t,i.begin,e,s.begin,this._xyzA,this._crossA,this._forwardA,this._xyzB,this._crossB,this._forwardB)?(this.advanceToPlanarLimit(i,r,i.begin+1,this._xyzA,this._crossA,this._forwardA,this._crossB,this._forwardB),this.advanceToPlanarLimit(s,o,s.begin+1,this._xyzB,this._crossB,this._forwardB,this._crossA,this._forwardA),this.addGreedy(r,o,n),i.advanceToTail(r),s.advanceToTail(o)):this.isPlanarBase(t,i.begin+1,e,s.begin,this._xyzA,this._crossA,this._forwardA,this._xyzB,this._crossB,this._forwardB)?(r.setFrom(i,i.begin,i.begin+2),o.setFrom(s,s.begin,s.begin+1),this.addGreedy(r,o,n),i.advanceToTail(r),s.advanceToTail(o)):this.isPlanarBase(t,i.begin,e,s.begin+1,this._xyzA,this._crossA,this._forwardA,this._xyzB,this._crossB,this._forwardB)?(r.setFrom(i,i.begin,i.begin+1),o.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,o,n),i.advanceToTail(r),s.advanceToTail(o)):i.length>1&&s.length>1?(r.setFrom(i,i.begin,i.begin+2),o.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,o,n,!0),i.advanceToHead(r),s.advanceToHead(o)):i.length>1?(r.setFrom(i,i.begin,i.begin+2),o.setFrom(s),this.addGreedy(r,o,n),i.advanceToTail(r),s.advanceToTail(o)):s.length>1&&(r.setFrom(i),o.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,o,n),i.advanceToTail(r),s.advanceToTail(o));this.addGreedy(i,s,n)}static defaultNearColinearAngle=A.createDegrees(15);static createContext(t=this.defaultNearColinearAngle){return new go(t.radians)}}function Ia(u,t=f.smallMetricDistance){let e=!1;const n=u.length;for(let r=0;r+1<n;r++)if(u.distanceUncheckedIndexIndex(r,r+1)<=t){e=!0;break}if(!e)return u;const i=new W(n);i.pushXYZ(u.getXAtUncheckedPointIndex(0),u.getYAtUncheckedPointIndex(0),u.getZAtUncheckedPointIndex(0));let s=0;for(let r=1;r<n;r++)u.distanceUncheckedIndexIndex(s,r)>t&&(i.pushXYZ(u.getXAtUncheckedPointIndex(r),u.getYAtUncheckedPointIndex(r),u.getZAtUncheckedPointIndex(r)),s=r);return u.distanceUncheckedIndexIndex(0,n-1)<=t&&(i.pop(),i.pushFromGrowableXYZArray(i,0)),i}function va(u,t){return Array.isArray(u)?u[t]:u(t)}function qn(u,t){if(t!==void 0)if(Array.isArray(t)){if(u<t.length)return t[u]}else return t}function Sa(u){return u!==void 0?Array.isArray(u)?u.length:1:0}class qc{getIsAborted(){return!1}}class Wc{getIsAborted(){return!1}getXYOnly(){return!1}}class Gc extends Wc{isRangePairActive(t,e){const n=this.getCurrentDistance();return(this.getXYOnly()?t.distanceToRangeXY(e):t.distanceToRange(e))<=n}}let Hc=0;class ss{_range;_appData;_children;_id;constructor(t,e,n){this._range=t,this._appData=e,this._children=n,this._id=Hc++}static createCapture(t,e,n){return new ss(t,e,n)}setRange(t){this._range.setFrom(t)}getRange(t){return this._range.clone(t)}getRangeRef(){return this._range}getChildByIndex(t){return qn(t,this._children)}getAppDataByIndex(t){return qn(t,this._appData)}getAllChildren(){return this._children}getAllAppData(){return this._appData}getNumChildren(){return Sa(this._children)}getNumAppData(){return Sa(this._appData)}recurseIntoTree(t){if(t(this))if(Array.isArray(this._children))for(const n of this._children)n.recurseIntoTree(t);else this._children!==void 0&&this._children.recurseIntoTree(t)}searchTopDown(t){if(t.isRangeActive(this._range)){let e;for(let i=0;(e=this.getAppDataByIndex(i))!==void 0;i++)if(t.processAppData(e),t.getIsAborted())return;let n;for(let i=0;(n=this.getChildByIndex(i))!==void 0;i++)n.searchTopDown(t)}}static processAppDataAndAppDataStack(t,e,n,i){if(t!==void 0){let s,r;for(let o=e.length;o-- >0;){const a=e[o]._appData;for(let c=0;(r=qn(c,a))!==void 0;c++)for(let l=0;(s=qn(l,t))!==void 0;l++)if(n?i.processAppDataPair(r,s):i.processAppDataPair(s,r),i.getIsAborted())return}}}static processAppDataAndAppData(t,e,n,i){if(t!==void 0&&e!==void 0){let s,r;for(let o=0;(r=qn(o,e))!==void 0;o++)for(let a=0;(s=qn(a,t))!==void 0;a++)if(n?i.processAppDataPair(r,s):i.processAppDataPair(s,r),i.getIsAborted())return}}static pushPaths(t,e,n){e.push(t),t._appData!==void 0&&n.push(t)}static popPaths(t,e,n){e[e.length-1],e.pop(),t._appData!==void 0&&n.pop()}static recursivePairSearch(t,e,n,i,s,r,o){const a=t._appData!==void 0,c=i._appData!==void 0;let l,d;if(a&&r.length>0&&this.processAppDataAndAppDataStack(t._appData,r,!1,o),n.length>0&&c&&this.processAppDataAndAppDataStack(i._appData,n,!0,o),o.isRangePairActive(t._range,i._range))if(this.processAppDataAndAppData(t._appData,i._appData,!1,o),t._children!==void 0&&i._children!==void 0){this.pushPaths(t,e,n),this.pushPaths(i,s,r);for(let h=0;(l=qn(h,t._children))!==void 0;h++)for(let g=0;(d=qn(g,i._children))!==void 0;g++)this.recursivePairSearch(l,e,n,d,s,r,o);this.popPaths(t,e,n),this.popPaths(i,s,r)}else t._children!==void 0?this.leftRecursivePairSearch(t,i,r,!1,o):i._children!==void 0&&this.leftRecursivePairSearch(i,t,n,!0,o)}static leftRecursivePairSearch(t,e,n,i,s){e._children;let r;for(let o=0;(r=qn(o,t._children))!==void 0;o++)s.isRangePairActive(r._range,e._range)&&(this.processAppDataAndAppData(r._appData,e._appData,i,s),this.processAppDataAndAppDataStack(r._appData,n,i,s),this.leftRecursivePairSearch(r,e,n,i,s))}static searchTwoTreesTopDown(t,e,n){this.recursivePairSearch(t,[],[],e,[],[],n)}}class cr{static getRecursiveNodeCount(t){let e=0;return t.recurseIntoTree(n=>(e++,!0)),e}static getRecursiveAppDataCount(t){let e=0;return t.recurseIntoTree(n=>(e+=n.getNumAppData(),!0)),e}static createLeafInIndexRange(t,e,n,i,s){const r=[],o=J.createNull();i=Math.min(i,s);for(let a=n;a<i;a++)r.push(va(e,a)),o.extendRange(va(t,a));return ss.createCapture(o,r,void 0)}static createRecursiveByIndexSplits(t,e,n,i,s,r,o){i>s&&(i=s);const a=J.createNull(),c=[],l=r*o;if(i<=n+l)for(let d=n+o;n<i;n=d,d=Math.min(d+o,i)){const h=cr.createLeafInIndexRange(t,e,n,d,s);h!==void 0&&(a.extendRange(h.getRangeRef()),c.push(h))}else{const d=Math.ceil((i-n)/r);for(let h=n+d;n<i;n=h,h=Math.min(h+d,i)){const g=this.createRecursiveByIndexSplits(t,e,n,h,s,r,o);g!==void 0&&(a.extendRange(g.getRangeRef()),c.push(g))}}return c.length>0?ss.createCapture(a,void 0,c):void 0}static createByIndexSplits(t,e,n,i=2,s=2){if(!(n<=0||Array.isArray(t)&&t.length!==n||Array.isArray(e)&&e.length!==n))return i<2&&(i=2),cr.createRecursiveByIndexSplits(t,e,0,n,n,i,s)}}class lr{itemAtMinValue;minValue;triggerForSavingToArray;savedItems=[];savedValues=[];constructor(t){this.resetMinValueAndItem(void 0,void 0),this.resetTriggerValueForSavingToArray(t,!1)}static create(t){return new lr(t)}resetMinValueAndItem(t=void 0,e=void 0){this.itemAtMinValue=t,this.minValue=e}resetTriggerValueForSavingToArray(t,e=!1){this.triggerForSavingToArray=t,e&&(this.savedItems=[],this.savedValues=[])}testAndSave(t,e){return this.doesValueTrigger(e)&&(this.savedValues.push(e),this.savedItems.push(t)),this.isNewMinValue(e)?(this.minValue=e,this.itemAtMinValue=t,!0):!1}doesValueTrigger(t){return this.triggerForSavingToArray!==void 0&&t<=this.triggerForSavingToArray}isNewMinValue(t){return this.minValue===void 0||t<this.minValue}isNewMinOrTrigger(t){return this.isNewMinValue(t)||this.doesValueTrigger(t)}}class Jc extends qc{context;searchState;spacePoint;searchFacetInterior;constructor(t,e,n,i=!1){super(),this.context=e,n!==void 0&&n<0&&(n=void 0),this.searchState=lr.create(n),this.spacePoint=y.createFrom(t),this.searchFacetInterior=i}getResult(){if(this.searchState.minValue!==void 0&&this.searchState.itemAtMinValue!==void 0)return this.searchState.itemAtMinValue}getSavedItems(){if(this.searchState.savedItems.length>0)return this.searchState.savedItems}isRangeActive(t){const e=t.distanceToPoint(this.spacePoint);return this.searchState.isNewMinValue(e)?(this.context.numRangeTestTrue++,!0):(this.context.numRangeTestFalse++,!1)}processAppData(t){if(this.context.visitor.setNumWrap(0),this.context.visitor.moveToReadIndex(t)){let e;if(this.searchFacetInterior?e=nt.closestPoint(this.context.visitor.point,this.spacePoint):e=nt.closestPointOnBoundary(this.context.visitor.point,this.spacePoint),this.context.numFacetTest++,e&&this.searchState.isNewMinOrTrigger(e.a)){const n=this.context.visitor.pointCount,i=this.context.convexFacets?ii.createCapture(this.context.visitor.currentReadIndex(),n,e):Ln.createCapture(this.context.visitor.currentReadIndex(),n,e);this.searchState.testAndSave(i,e.a)}}}}class Kc extends Gc{contextA;contextB;searchState;searchFacetInterior;constructor(t,e,n,i=!1){super(),this.contextA=t,this.contextB=e,n!==void 0&&n<0&&(n=void 0),this.searchState=lr.create(n),this.searchFacetInterior=i&&t.convexFacets&&e.convexFacets}getResult(){if(this.searchState.minValue!==void 0)return this.searchState.itemAtMinValue}getSavedItems(){if(this.searchState.savedItems.length>0)return this.searchState.savedItems}getCurrentDistance(){const t=this.searchState.minValue;return t===void 0?Number.MAX_VALUE:t}processAppDataPair(t,e){if(this.contextA.visitor.setNumWrap(1),this.contextB.visitor.setNumWrap(1),this.contextA.visitor.moveToReadIndex(t)&&this.contextB.visitor.moveToReadIndex(e)){const n=nt.closestApproach(this.contextA.visitor.point,this.contextB.visitor.point,void 0,this.searchFacetInterior);if(this.contextA.numFacetTest++,n&&this.searchState.isNewMinOrTrigger(n.detailA.a)){const i=this.contextA.visitor.pointCount-1,s=this.contextB.visitor.pointCount-1,r=ro.create(this.contextA.convexFacets?ii.createCapture(t,i,n.detailA):Ln.createCapture(t,i,n.detailA),this.contextB.convexFacets?ii.createCapture(e,s,n.detailB):Ln.createCapture(e,s,n.detailB));this.searchState.testAndSave(r,r.detailA.a)}}}}class mo{visitor;convexFacets;numRangeTestTrue;numRangeTestFalse;numFacetTest;numSearch;_rangeTreeRoot;constructor(t,e,n=!1){this.visitor=e,this.convexFacets=n,this._rangeTreeRoot=t,this.numRangeTestTrue=0,this.numRangeTestFalse=0,this.numFacetTest=0,this.numSearch=0}static createCapture(t,e=4,n=4,i=!1){if(t instanceof It)return this.createCapture(t.createVisitor(0),e,n,i);const s=St.visitorClientFacetCount(t),r=cr.createByIndexSplits(o=>(t.moveToReadIndex(o),t.range()),o=>o,s,e,n);return r?new mo(r,t,i):void 0}searchForClosestPoint(t,e,n=!1){const i=new Jc(t,this,e,n);this.numSearch++;const s=St.visitorClientFacetCount(this.visitor),r=f.clamp(Math.floor(s/20),2,7),o=Math.floor(s/r);i.processAppData(0),i.processAppData(s-1);for(let a=o;a+1<s;a+=o)i.processAppData(a);return this._rangeTreeRoot.searchTopDown(i),i.searchState.savedItems.length<=1?i.getResult():i.getSavedItems()}static searchForClosestApproach(t,e,n,i=!1){const s=new Kc(t,e,n,i);return ss.searchTwoTreesTopDown(t._rangeTreeRoot,e._rangeTreeRoot,s),s.searchState.savedItems.length<=1?s.getResult():s.getSavedItems()}}class tn{xyz;xyzIndex;normal;normalIndex;uv;uvIndex;sectionDerivative;constructor(t=!1,e=!1,n=!1){this.xyz=y.create(),this.normalIndex=-1,this.uvIndex=-1,this.xyzIndex=-1,t&&(this.normal=P.create()),e&&(this.uv=D.create(),this.uvIndex=-1),n&&(this.sectionDerivative=P.create())}copyContentsFrom(t){this.xyz.setFromPoint3d(t.xyz),this.xyzIndex=t.xyzIndex,this.normal&&this.normal.setFromVector3d(t.normal),this.normalIndex=t.normalIndex,this.uv&&this.uv.setFrom(t.uv),this.uvIndex=t.uvIndex,this.sectionDerivative&&this.sectionDerivative.setFrom(t.sectionDerivative)}loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(t,e,n,i,s){e.getPoint3dAtCheckedPointIndex(t,this.xyz),this.uv&&i&&s!==void 0&&this.uv.set(i.atUncheckedIndex(t),s),this.xyzIndex=-1,this.normalIndex=-1,this.uvIndex=-1,this.sectionDerivative!==void 0&&n!==void 0&&n.getVector3dAtCheckedVectorIndex(t,this.sectionDerivative)}static suppressSmallUnitVectorComponents(t){const e=f.smallFloatingPoint;Math.abs(t.x)<e&&(t.x=0),Math.abs(t.y)<e&&(t.y=0),Math.abs(t.z)<e&&(t.z=0)}static _edgeVector=P.create();static computeNormalsAlongRuleLine(t,e){if(t.sectionDerivative&&e.sectionDerivative&&t.normal&&e.normal){const n=tn._edgeVector;P.createStartEnd(t.xyz,e.xyz,n),t.sectionDerivative.crossProduct(n,t.normal),e.sectionDerivative.crossProduct(n,e.normal),t.normal.normalizeInPlace(),e.normal.normalizeInPlace(),tn.suppressSmallUnitVectorComponents(t.normal),tn.suppressSmallUnitVectorComponents(e.normal)}}}class it extends Ys{_polyface;_options;get options(){return this._options}_reversed;get reversedFlag(){return this._reversed}claimPolyface(t=!0,e=f.smallMetricDistance){return t&&this._polyface.data.compress(e),this._polyface}toggleReversedFacetFlag(){this._reversed=!this._reversed}constructor(t){super(),this._options=t||Zt.createForFacets(),this._polyface=un.create(this._options.needNormals,this._options.needParams,this._options.needColors,this._options.needTwoSided),this._reversed=!1}static create(t){return new it(t)}addTransformedUnitBox(t){this.addTransformedRangeMesh(t,J.createXYZXYZ(0,0,0,1,1,1))}addTransformedRangeMesh(t,e,n){const i=this._polyface.data.pointCount,s=e.corners();for(const o of s)this._polyface.addPoint(t.multiplyPoint3d(o));let r=0;for(const o of or.cornerIndexCCW){if(!n||r<n.length&&n[r]){const a=o.map(c=>c+i);this._reversed&&a.reverse(),this._options.shouldTriangulate?(this.addIndexedTrianglePointIndexes(a[0],a[1],a[2],!1),this.addIndexedTrianglePointIndexes(a[0],a[2],a[3],!1)):this.addIndexedQuadPointIndexes(a[0],a[1],a[3],a[2],!1),this._polyface.terminateFacet()}r++}}addTriangleFan(t,e,n){const i=e.numPoints();if(i>2){n&&this.toggleReversedFacetFlag();const s=this.addPoint(t);let r=this.findOrAddPointInLineStringUnchecked(e,0),o=0;for(let a=1;a<i;a++)o=this.findOrAddPointInLineStringUnchecked(e,a),this.addIndexedTrianglePointIndexes(s,r,o),r=o;n&&this.toggleReversedFacetFlag()}}addTrianglesInUncheckedConvexPolygon(t,e){const n=t.numPoints();if(n>2){e&&this.toggleReversedFacetFlag();let i,s;this._options.needNormals&&(i=t.quickUnitNormal(it._workVectorFindOrAdd),i&&(e&&i.scaleInPlace(-1),s=this._polyface.addNormal(i)));const o=this._options.needParams?t.packedUVParams:void 0;let a=-1,c=-1,l=-1;o&&(a=this.addParamInGrowableXYArrayUnchecked(o,0),c=this.addParamInGrowableXYArrayUnchecked(o,1));const d=this.findOrAddPointInLineStringUnchecked(t,0);let h=this.findOrAddPointInLineStringUnchecked(t,1),g=0,m=n;t.isPhysicallyClosed&&m--;for(let p=2;p<m;p++,h=g,c=l)g=this.findOrAddPointInLineStringUnchecked(t,p),this.addIndexedTrianglePointIndexes(d,h,g,!1),s!==void 0&&this.addIndexedTriangleNormalIndexes(s,s,s),o&&(l=this.addParamInGrowableXYArrayUnchecked(o,p),this.addIndexedTriangleParamIndexes(a,c,l)),this._polyface.terminateFacet();e&&this.toggleReversedFacetFlag()}}addPoint(t){return this._polyface.addPoint(t)}addParamXY(t,e){return this._polyface.addParamUV(t,e)}static _workPointFindOrAddA=y.create();static _workVectorFindOrAdd=P.create();static _workUVFindOrAdd=D.create();findOrAddPointInLineStringUnchecked(t,e,n,i){const s=t.pointAtUnchecked(e,it._workPointFindOrAddA);return n&&n.multiplyPoint3d(s,s),this._polyface.addPoint(s,i)}findOrAddPointInLineString(t,e,n,i){if(t.packedPoints.isIndexValid(e))return this.findOrAddPointInLineStringUnchecked(t,e,n,i)}findOrAddPointInGrowableXYZArrayUnchecked(t,e,n,i){const s=t.getPoint3dAtUncheckedPointIndex(e,it._workPointFindOrAddA);return n&&n.multiplyPoint3d(s,s),this._polyface.addPoint(s,i)}findOrAddPointInGrowableXYZArray(t,e,n,i){if(t.isIndexValid(e))return this.findOrAddPointInGrowableXYZArrayUnchecked(t,e,n,i)}findOrAddNormalInGrowableXYZArrayUnchecked(t,e,n,i){const s=t.getVector3dAtUncheckedVectorIndex(e,it._workVectorFindOrAdd);return n&&n.multiplyVector(s,s),this._polyface.addNormal(s,i)}findOrAddNormalInGrowableXYZArray(t,e,n,i){if(t.isIndexValid(e))return this.findOrAddNormalInGrowableXYZArrayUnchecked(t,e,n,i)}addParamInGrowableXYArrayUnchecked(t,e){const n=t.getPoint2dAtUncheckedPointIndex(e,it._workUVFindOrAdd);return this._polyface.addParam(n)}addParamInGrowableXYArray(t,e){if(t.isIndexValid(e))return this.addParamInGrowableXYArrayUnchecked(t,e)}findOrAddParamInLineString(t,e,n,i,s){const r=t.fractions?.atIndex(e)??e/t.points.length;return this._polyface.addParamUV(r,n,i,s)}findOrAddNormalInLineString(t,e,n,i,s){const r=t.packedSurfaceNormals;if(r){const o=r.getVector3dAtCheckedVectorIndex(e,it._workVectorFindOrAdd);if(o)return n&&n.multiplyVector(o,o),this._polyface.addNormal(o,i,s)}}addPointXYZ(t,e,n){return this._polyface.addPointXYZ(t,e,n)}static _workVector0;static _workVector1;getUVTransformForTriangleFacet(t,e,n,i){const s=it._workVector0=t.vectorTo(e,it._workVector0),r=it._workVector1=t.vectorTo(n,it._workVector1);return X.createRigidFromOriginAndColumns(t,s,r,mt.XYZ,i)}getNormalForTriangularFacet(t,e,n,i){const s=t.crossProductToPoints(e,n,i);return s.tryNormalizeInPlace()?s:P.createZero(i)}static _workUV0;static _workUV1;static _workUV2;static _workUV3;static _workNormal0;static _workNormal1;static _workNormal2;static _workNormal3;static _workTransform;addQuadFacet(t,e,n,i){if(t.length<4)return;t instanceof W&&(t=t.getPoint3dArray());const s=this.options.needParams,r=this.options.needNormals,o=this.options.needColors,a=it._workUV0=D.createZero(it._workUV0),c=it._workUV1=D.createZero(it._workUV1),l=it._workUV2=D.createZero(it._workUV2),d=it._workUV3=D.createZero(it._workUV3),h=it._workNormal0=P.createZero(it._workNormal0),g=it._workNormal1=P.createZero(it._workNormal1),m=it._workNormal2=P.createZero(it._workNormal2),p=it._workNormal3=P.createZero(it._workNormal3);let x=0,_=0,I=0,v=0;if(s)if(e&&e.length>3)a.setFrom(e[0]),c.setFrom(e[1]),l.setFrom(e[2]),d.setFrom(e[3]);else{const L=it._workTransform=this.getUVTransformForTriangleFacet(t[0],t[1],t[3],it._workTransform);L&&(L.multiplyInversePoint3dAsPoint2d(t[0],a),L.multiplyInversePoint3dAsPoint2d(t[1],c),L.multiplyInversePoint3dAsPoint2d(t[2],l),L.multiplyInversePoint3dAsPoint2d(t[3],d))}if(r&&(n&&n.length>3?(h.setFrom(n[0]),g.setFrom(n[1]),m.setFrom(n[2]),p.setFrom(n[3])):(this.getNormalForTriangularFacet(t[0],t[1],t[2],h),g.setFrom(h),m.setFrom(h),p.setFrom(h))),o&&i&&i.length>3&&(x=i[0],_=i[1],I=i[2],v=i[3]),this._options.shouldTriangulate){const L=t[0].distanceSquared(t[2]),z=t[1].distanceSquared(t[3]);L+f.smallFloatingPoint>=z?(this.addTriangleFacet([t[0],t[1],t[2]],s?[a,c,l]:void 0,r?[h,g,m]:void 0,o?[x,_,I]:void 0),this.addTriangleFacet([t[0],t[2],t[3]],s?[a,l,d]:void 0,r?[h,m,p]:void 0,o?[x,I,v]:void 0)):(this.addTriangleFacet([t[0],t[1],t[3]],s?[a,c,d]:void 0,r?[h,g,p]:void 0,o?[x,_,v]:void 0),this.addTriangleFacet([t[1],t[2],t[3]],s?[c,l,d]:void 0,r?[g,m,p]:void 0,o?[_,I,v]:void 0));return}let S,w,T,R;s&&(S=this._polyface.addParam(a),w=this._polyface.addParam(c),T=this._polyface.addParam(l),R=this._polyface.addParam(d),this.addIndexedQuadParamIndexes(S,w,R,T)),r&&(S=this._polyface.addNormal(h),w=this._polyface.addNormal(g),T=this._polyface.addNormal(m),R=this._polyface.addNormal(p),this.addIndexedQuadNormalIndexes(S,w,R,T)),o&&(S=this._polyface.addColor(x),w=this._polyface.addColor(_),T=this._polyface.addColor(I),R=this._polyface.addColor(v),this.addIndexedQuadColorIndexes(S,w,R,T)),S=this.addPoint(t[0]),w=this.addPoint(t[1]),T=this.addPoint(t[2]),R=this.addPoint(t[3]),this.addIndexedQuadPointIndexes(S,w,R,T)}addIndexedQuadPointIndexes(t,e,n,i,s=!0){this._reversed?(this._polyface.addPointIndex(t),this._polyface.addPointIndex(n),this._polyface.addPointIndex(i),this._polyface.addPointIndex(e)):(this._polyface.addPointIndex(t),this._polyface.addPointIndex(e),this._polyface.addPointIndex(i),this._polyface.addPointIndex(n)),s&&this._polyface.terminateFacet()}addIndexedQuadParamIndexes(t,e,n,i){this._reversed?(this._polyface.addParamIndex(t),this._polyface.addParamIndex(n),this._polyface.addParamIndex(i),this._polyface.addParamIndex(e)):(this._polyface.addParamIndex(t),this._polyface.addParamIndex(e),this._polyface.addParamIndex(i),this._polyface.addParamIndex(n))}addIndexedQuadNormalIndexes(t,e,n,i){this._reversed?(this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(n),this._polyface.addNormalIndex(i),this._polyface.addNormalIndex(e)):(this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(i),this._polyface.addNormalIndex(n))}addIndexedQuadColorIndexes(t,e,n,i){this._reversed?(this._polyface.addColorIndex(t),this._polyface.addColorIndex(n),this._polyface.addColorIndex(i),this._polyface.addColorIndex(e)):(this._polyface.addColorIndex(t),this._polyface.addColorIndex(e),this._polyface.addColorIndex(i),this._polyface.addColorIndex(n))}addTriangleFacet(t,e,n,i){if(t.length<3)return;t instanceof W&&(t=t.getPoint3dArray());let s,r,o;if(this.options.needParams){if(e&&e.length>2)s=this._polyface.addParam(e[0]),r=this._polyface.addParam(e[1]),o=this._polyface.addParam(e[2]);else{const a=it._workUV0=D.createZero(it._workUV0),c=it._workTransform=this.getUVTransformForTriangleFacet(t[0],t[1],t[2],it._workTransform);c?.multiplyInversePoint3dAsPoint2d(t[0],a),o=r=s=this._polyface.addParam(a),c&&(c.multiplyInversePoint3dAsPoint2d(t[1],a),r=this._polyface.addParam(a),c.multiplyInversePoint3dAsPoint2d(t[2],a),o=this._polyface.addParam(a))}this.addIndexedTriangleParamIndexes(s,r,o)}if(this.options.needNormals){if(n&&n.length>2)s=this._polyface.addNormal(n[0]),r=this._polyface.addNormal(n[1]),o=this._polyface.addNormal(n[2]);else{const a=it._workNormal0=P.createZero(it._workNormal0);this.getNormalForTriangularFacet(t[0],t[1],t[2],a),o=r=s=this._polyface.addNormal(a)}this.addIndexedTriangleNormalIndexes(s,r,o)}this.options.needColors&&(i&&i.length>2?(s=this._polyface.addColor(i[0]),r=this._polyface.addColor(i[1]),o=this._polyface.addColor(i[2])):o=r=s=this._polyface.addColor(0),this.addIndexedTriangleColorIndexes(s,r,o)),s=this.addPoint(t[0]),r=this.addPoint(t[1]),o=this.addPoint(t[2]),this.addIndexedTrianglePointIndexes(s,r,o,!0)}addIndexedTrianglePointIndexes(t,e,n,i=!0){this._reversed?(this._polyface.addPointIndex(t),this._polyface.addPointIndex(n),this._polyface.addPointIndex(e)):(this._polyface.addPointIndex(t),this._polyface.addPointIndex(e),this._polyface.addPointIndex(n)),i&&this._polyface.terminateFacet()}addIndexedTriangleParamIndexes(t,e,n){this._reversed?(this._polyface.addParamIndex(t),this._polyface.addParamIndex(n),this._polyface.addParamIndex(e)):(this._polyface.addParamIndex(t),this._polyface.addParamIndex(e),this._polyface.addParamIndex(n))}addIndexedTriangleNormalIndexes(t,e,n){this._reversed?(this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(n),this._polyface.addNormalIndex(e)):(this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(n))}addIndexedTriangleColorIndexes(t,e,n){this._reversed?(this._polyface.addColorIndex(t),this._polyface.addColorIndex(n),this._polyface.addColorIndex(e)):(this._polyface.addColorIndex(t),this._polyface.addColorIndex(e),this._polyface.addColorIndex(n))}setSectorIndices(t){t.xyzIndex=this.addPoint(t.xyz),t.normal&&(t.normalIndex=this._polyface.addNormal(t.normal)),t.uv&&(t.uvIndex=this._polyface.addParam(t.uv))}addSectorTriangle(t,e,n){t.xyz.isAlmostEqual(e.xyz)||e.xyz.isAlmostEqual(n.xyz)||n.xyz.isAlmostEqual(t.xyz)||(this._options.needNormals&&this.addIndexedTriangleNormalIndexes(t.normalIndex,e.normalIndex,n.normalIndex),this._options.needParams&&this.addIndexedTriangleParamIndexes(t.uvIndex,e.uvIndex,n.uvIndex),this.addIndexedTrianglePointIndexes(t.xyzIndex,e.xyzIndex,n.xyzIndex,!0))}addSectorQuadA01B01(t,e,n,i){t.xyz.isAlmostEqual(e.xyz)&&n.xyz.isAlmostEqual(i.xyz)||(this._options.shouldTriangulate?(this.addSectorTriangle(t,e,i),this.addSectorTriangle(i,n,t)):(this._options.needNormals&&this.addIndexedQuadNormalIndexes(t.normalIndex,e.normalIndex,n.normalIndex,i.normalIndex),this._options.needParams&&this.addIndexedQuadParamIndexes(t.uvIndex,e.uvIndex,n.uvIndex,i.uvIndex),this.addIndexedQuadPointIndexes(t.xyzIndex,e.xyzIndex,n.xyzIndex,i.xyzIndex,!0)))}addBetweenLineStringsWithRuleEdgeNormals(t,e,n,i,s=!1){const r=t.packedPoints,o=n.packedPoints,a=t.packedDerivatives,c=n.packedDerivatives,l=t.fractions,d=n.fractions,h=this._options.needNormals,g=this._options.needParams,m=new tn(h,g,h),p=new tn(h,g,h),x=new tn(h,g,h),_=new tn(h,g,h),I=new tn(h,g,h),v=new tn(h,g,h),S=r.length;if(!(S<2||S!==o.length)){m.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(0,r,a,l,e),x.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(0,o,c,d,i),h&&tn.computeNormalsAlongRuleLine(m,x),this.setSectorIndices(m),this.setSectorIndices(x),I.copyContentsFrom(m),v.copyContentsFrom(x);for(let w=1;w<S;w++)p.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(w,r,a,l,e),_.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(w,o,a,d,i),tn.computeNormalsAlongRuleLine(p,_),this.setSectorIndices(p),this.setSectorIndices(_),this.addSectorQuadA01B01(m,p,x,_),m.copyContentsFrom(p),x.copyContentsFrom(_);s&&this.addSectorQuadA01B01(m,I,x,v)}}addBetweenLineStringsWithStoredIndices(t,e){const n=t.pointIndices,i=e.pointIndices;if(!n||!i||n.length<2||n.length!==i.length)return;const s=n.length;let r=t.normalIndices,o=e.normalIndices;(!this._options.needNormals||r&&o&&(r.length<s||o.length<s))&&(r=void 0,o=void 0);let a=t.paramIndices,c=e.paramIndices;(!this._options.needParams||a&&c&&(a.length<s||c.length<s))&&(a=void 0,c=void 0);for(let l=1;l<s;l++)this.options.shouldTriangulate?(Aa(n.atUncheckedIndex(l-1),n.atUncheckedIndex(l),i.atUncheckedIndex(l))&&(this.addIndexedTrianglePointIndexes(n.atUncheckedIndex(l-1),n.atUncheckedIndex(l),i.atUncheckedIndex(l),!1),r&&o&&this.addIndexedTriangleNormalIndexes(r.atUncheckedIndex(l-1),r.atUncheckedIndex(l),o.atUncheckedIndex(l-1)),a&&c&&this.addIndexedTriangleParamIndexes(a.atUncheckedIndex(l-1),a.atUncheckedIndex(l),c.atUncheckedIndex(l-1))),Aa(i.atUncheckedIndex(l),i.atUncheckedIndex(l-1),n.atUncheckedIndex(l-1))&&(this.addIndexedTrianglePointIndexes(n.atUncheckedIndex(l-1),i.atUncheckedIndex(l),i.atUncheckedIndex(l-1),!1),r&&o&&this.addIndexedTriangleNormalIndexes(r.atUncheckedIndex(l-1),o.atUncheckedIndex(l),o.atUncheckedIndex(l-1)),a&&c&&this.addIndexedTriangleParamIndexes(a.atUncheckedIndex(l-1),c.atUncheckedIndex(l),c.atUncheckedIndex(l-1)))):(n.atUncheckedIndex(l-1)!==n.atUncheckedIndex(l)||i.atUncheckedIndex(l-1)!==i.atUncheckedIndex(l))&&(this.addIndexedQuadPointIndexes(n.atUncheckedIndex(l-1),n.atUncheckedIndex(l),i.atUncheckedIndex(l-1),i.atUncheckedIndex(l),!1),r&&o&&this.addIndexedQuadNormalIndexes(r.atUncheckedIndex(l-1),r.atUncheckedIndex(l),o.atUncheckedIndex(l-1),o.atUncheckedIndex(l)),a&&c&&this.addIndexedQuadParamIndexes(a.atUncheckedIndex(l-1),a.atUncheckedIndex(l),c.atUncheckedIndex(l-1),c.atUncheckedIndex(l))),this._polyface.terminateFacet()}addBetweenTransformedLineStrings(t,e,n,i=!1){if(t instanceof F){const s=t.numPoints();if(s>1){let r=this.findOrAddPointInLineStringUnchecked(t,0,e),o=this.findOrAddPointInLineStringUnchecked(t,0,n);const a=r,c=o;let l=0,d=0;for(let h=1;h<s;h++)l=this.findOrAddPointInLineStringUnchecked(t,h,e),d=this.findOrAddPointInLineStringUnchecked(t,h,n),this.addIndexedQuadPointIndexes(r,l,o,d),r=l,o=d;i&&s>2&&this.addIndexedQuadPointIndexes(r,a,o,c)}}else{const s=t.children;if(s)for(const r of s)this.addBetweenTransformedLineStrings(r,e,n)}}addBetweenStrokeSetPair(t,e,n,i){if(t instanceof F&&n instanceof F)this.addBetweenLineStringsWithRuleEdgeNormals(t,e,n,i,!1);else if(t instanceof Wt&&n instanceof Wt){if(t.children.length===n.children.length)for(let s=0;s<t.children.length;s++)this.addBetweenStrokeSetPair(t.children[s],e,n.children[s],i)}else if(t instanceof de&&n instanceof de){const s=t.children,r=n.children;if(s.length===r.length)for(let o=0;o<s.length;o++){const a=s[o],c=r[o];a instanceof F&&c instanceof F&&this.addBetweenLineStringsWithRuleEdgeNormals(a,e,c,i)}}}addCone(t){let e=16;this._options&&(e=this._options.applyTolerancesToArc(t.getMaxRadius()));let n=1;const i=t.strokeConstantVSection(0,e,this._options),s=t.strokeConstantVSection(1,e,this._options);if(this._options){const o=W.distanceRangeBetweenCorrespondingPoints(i.packedPoints,s.packedPoints);n=this._options.applyMaxEdgeLength(1,o.low)}const r=t.maxIsoParametricDistance();this.addUVGridBody(t,e,n,qt.create(0,r.x),qt.create(0,r.y)),this.endFace(),t.capped&&(f.isSmallMetricDistance(t.getRadiusA())||(this.addTrianglesInUncheckedConvexPolygon(i,!0),this.endFace()),f.isSmallMetricDistance(t.getRadiusB())||(this.addTrianglesInUncheckedConvexPolygon(s,!1),this.endFace()))}addTorusPipe(t,e,n){const i=t.getThetaFraction();let s=f.clamp(f.resolveNumber(e,8),4,64),r=f.clamp(f.resolveNumber(n,Math.ceil(16*i)),2,64);this._options&&(s=this._options.applyTolerancesToArc(t.getMinorRadius()),r=this._options.applyTolerancesToArc(t.getMajorRadius(),t.getSweepAngle().radians)),this.toggleReversedFacetFlag();const o=t.maxIsoParametricDistance();this.addUVGridBody(t,s,r,qt.create(0,o.x),qt.create(0,o.y)),this.toggleReversedFacetFlag();const a=t.getConstructiveFrame();if(a&&t.capped&&i<1){const c=t.getMinorRadius(),l=t.getMajorRadius(),d=2*c,h=l-c,g=l+c,m=-c,p=X.createRowValues(d,0,0,h,0,0,-1,0,0,d,0,m),_=a.multiplyTransformTransform(p).inverse();if(_){const L=Pa.createLinestringOnUVLine(t,0,0,1,0,s,!1,!0);L.computeUVFromXYZTransform(_),this.addTrianglesInUncheckedConvexPolygon(L,!1)}const I=t.getSweepAngle().radians,v=Math.cos(I),S=Math.sin(I),w=X.createRowValues(-v*d,0,-S,g*v,-S*d,0,v,g*S,0,d,0,m),R=a.multiplyTransformTransform(w).inverse();if(R){const L=Pa.createLinestringOnUVLine(t,1,1,0,1,s,!1,!0);L.computeUVFromXYZTransform(R),this.addTrianglesInUncheckedConvexPolygon(L,!1)}}}addLinearSweepLineStringsXYZOnly(t,e){if(t instanceof F){let n=y.create(),i=y.create(),s=0,r=0,o=0,a=0;const c=t.numPoints();for(let l=0;l<c;l++)n=t.pointAtUnchecked(l,n),i=n.plus(e,i),r=this.addPoint(n),a=this.addPoint(i),l>0&&this.addIndexedQuadPointIndexes(s,r,o,a),s=r,o=a}else if(t instanceof de)for(const n of t.children)this.addLinearSweepLineStringsXYZOnly(n,e)}addRotationalSweep(t){const e=t.getSweepContourRef(),i=Zn.create(e.getCurves(),this._options).getStrokes(),s=t.cloneAxisRay(),r=t.getSweep();r.radians<0&&(s.direction.scaleInPlace(-1),r.setRadians(-r.radians));const o=sr.computeMaxVectorFromRay(s,i),a=s.direction.crossProduct(o),c=e.localToWorld.matrix.dotColumnZ(a)>0;c||i.reverseInPlace(),this._options.needNormals&&sr.buildRotationalNormalsInLineStrings(i,s,a);const l=o.magnitude(),d=Math.abs(l*r.radians);let h=Zt.applyAngleTol(this._options,1,r.radians,void 0);h=Zt.applyMaxEdgeLength(this._options,h,d);for(let g=1;g<=h;g++){const m=t.getFractionalRotationTransform((g-1)/h),p=t.getFractionalRotationTransform(g/h);this.addBetweenRotatedStrokeSets(i,m,g-1,p,g)}if(t.capped){e.purgeFacets();const g=c;e.emitFacets(this,g,void 0),e.emitFacets(this,!g,t.getFractionalRotationTransform(1))}}addTriangulatedRegion(t){const e=Cn.createForLinearSweep(t);e&&e.emitFacets(this,this.reversedFlag,void 0)}applyStrokeCountsToCurvePrimitives(t){const e=this._options;if(t instanceof st)t.computeStrokeCountForOptions(e);else if(t instanceof ut){const n=t.children;if(n)for(const i of n)this.applyStrokeCountsToCurvePrimitives(i)}}addBetweenStrokeSetsWithRuledNormals(t,e,n){const i=[t],s=[0];for(let r=1;r<n;r++){const o=r/n,a=Zs.interpolateBetween(t,r/n,e);i.push(a),s.push(o)}i.push(e),s.push(1);for(let r=0;r<n;r++)this.addBetweenStrokeSetPair(i[r],s[r],i[r+1],s[r+1])}createIndicesInLineString(t,e,n){const i=t.numPoints();if(i<1)return;const s=t.ensureEmptyPointIndices(),r=this.findOrAddPointInLineStringUnchecked(t,0,n);if(s.push(r),i>1){let o=r,a;for(let c=1;c+1<i;c++)a=this.findOrAddPointInLineStringUnchecked(t,c,n,o),s.push(a),o=a;a=this.findOrAddPointInLineStringUnchecked(t,i-1,n,r),s.push(a)}if(this._options.needNormals&&t.packedSurfaceNormals&&t.packedSurfaceNormals.length>=i){const o=t.ensureEmptyNormalIndices(),a=this.findOrAddNormalInLineString(t,0,n);if(o.push(a),i>1){let c=a,l;for(let d=1;d+1<i;d++)l=this.findOrAddNormalInLineString(t,d,n,c),o.push(l),c=l;l=this.findOrAddNormalInLineString(t,i-1,n,a,c),o.push(l)}}if(this._options.needParams){const o=t.ensureEmptyUVIndices(),a=this.findOrAddParamInLineString(t,0,e);if(o.push(a),i>1){let c=a,l;for(let d=1;d+1<i;d++)l=this.findOrAddParamInLineString(t,d,e,c),o.push(l),c=l;l=this.findOrAddParamInLineString(t,i-1,e,c,a),o.push(l)}}}addBetweenRotatedStrokeSets(t,e,n,i,s){if(t instanceof F){const r=t.cloneTransformed(e);this.createIndicesInLineString(r,n);const o=t.cloneTransformed(i);this.createIndicesInLineString(o,s),this.addBetweenLineStringsWithStoredIndices(r,o)}else if(t instanceof Wt)for(const r of t.children)this.addBetweenRotatedStrokeSets(r,e,n,i,s);else if(t instanceof de)for(const r of t.children)r instanceof F&&this.addBetweenRotatedStrokeSets(r,e,n,i,s)}addLinearSweep(t){const e=t.getCurvesRef(),i=Zn.create(e,this._options).getStrokes(),s=t.cloneSweepVector(),r=X.createTranslation(s),o=i.cloneTransformed(r),a=this._options.applyMaxEdgeLength(1,s.magnitude());if(this.addBetweenStrokeSetsWithRuledNormals(i,o,a),t.capped&&e.isAnyRegionType){const c=t.getSweepContourRef();c.purgeFacets();const l=c.localToWorld.matrix.dotColumnZ(s)>0;c.emitFacets(this,l,void 0),c.emitFacets(this,!l,r)}}addRuledSweep(t){const e=t.sweepContoursRef();let n,i;const s=[];for(const r of e)s.push(Zn.create(r.curves,this._options));if(Zn.enforceStrokeCountCompatibility(s)){Zn.enforceCompatibleDistanceSums(s);for(let r=0;r<e.length;r++){if(i=s[r].getStrokes(),i||(i=e[r].curves.cloneStroked()),r>0&&n&&i){const o=ct.createNull();if(Zn.extendDistanceRangeBetweenStrokes(n,i,o)&&!o.isNull){const a=this._options.applyMaxEdgeLength(1,o.high);this.addBetweenStrokeSetsWithRuledNormals(n,i,a)}}n=i}}return t.capped&&e[0].curves.isAnyRegionType&&(e[0].purgeFacets(),e[0].emitFacets(this,!0,void 0),e[e.length-1].purgeFacets(),e[e.length-1].emitFacets(this,!1,void 0)),!0}addSphere(t,e){let n=e||this.options.applyTolerancesToArc(t.maxAxisRadius());f.isOdd(n)&&(n+=1);const i=f.clampToStartEnd(Math.abs(n*t.latitudeSweepFraction),1,Math.ceil(n*.5)),s=t.strokeConstantVSection(0,n,this._options);t.capped&&!f.isSmallMetricDistance(s.quickLength())&&(this.addTrianglesInUncheckedConvexPolygon(s,!0),this.endFace());const r=t.maxIsoParametricDistance();this.addUVGridBody(t,n,i,qt.create(0,r.x),qt.create(0,r.y)),this.endFace();const o=t.strokeConstantVSection(1,n,this._options);t.capped&&!f.isSmallMetricDistance(o.quickLength())&&(this.addTrianglesInUncheckedConvexPolygon(o,!1),this.endFace())}addBox(t){const e=t.getCorners(),n=f.maxXY(t.getBaseX(),t.getBaseX()),i=f.maxXY(t.getBaseY(),t.getTopY());let s=0;for(let d=0;d<4;d++)s=f.maxXY(s,e[d].distance(e[d+4]));const r=this._options.applyMaxEdgeLength(1,n),o=this._options.applyMaxEdgeLength(1,i),a=this._options.applyMaxEdgeLength(1,s),c=qt.create(0,n),l=qt.create(0,s);this.addUVGridBody(Ge.create(e[0],e[1],e[4],e[5]),r,a,c,l),c.shift(n),this.addUVGridBody(Ge.create(e[1],e[3],e[5],e[7]),o,a,c,l),c.shift(i),this.addUVGridBody(Ge.create(e[3],e[2],e[7],e[6]),r,a,c,l),c.shift(n),this.addUVGridBody(Ge.create(e[2],e[0],e[6],e[4]),o,a,c,l),this.endFace(),t.capped&&(c.set(0,n),l.set(0,i),this.addUVGridBody(Ge.create(e[4],e[5],e[6],e[7]),r,o,c,l),this.endFace(),c.set(0,n),l.set(0,i),this.addUVGridBody(Ge.create(e[2],e[3],e[0],e[1]),r,o,c,l),this.endFace())}addPolygon(t,e){for(e===void 0&&(e=t.length);e>1&&t[e-1].isAlmostEqual(t[0]);)e--;let n=0;if(this._reversed)for(let i=e;--i>=0;)n=this.addPoint(t[i]),this._polyface.addPointIndex(n);else for(let i=0;i<e;i++)n=this.addPoint(t[i]),this._polyface.addPointIndex(n);this._polyface.terminateFacet()}addPolygonGrowableXYZArray(t){let e=t.length;for(;e>2&&f.isSmallMetricDistance(t.distanceUncheckedIndexIndex(0,e-1));)e--;for(;e>2&&f.isSmallMetricDistance(t.distanceUncheckedIndexIndex(e-2,e-1));)e--;if(e===3){const i=t.crossProductUncheckedIndexIndexIndex(0,1,2).magnitude(),s=t.distanceUncheckedIndexIndex(0,1)+t.distanceUncheckedIndexIndex(0,2)+t.distanceUncheckedIndexIndex(1,2);i<f.smallMetricDistance*s&&(e=0)}if(e>2){let n=0;if(this._reversed)for(let i=e;--i>=0;)n=this.findOrAddPointInGrowableXYZArrayUnchecked(t,i),this._polyface.addPointIndex(n);else for(let i=0;i<e;i++)n=this.findOrAddPointInGrowableXYZArrayUnchecked(t,i),this._polyface.addPointIndex(n);this._polyface.terminateFacet()}}addFacetFromGrowableArrays(t,e,n,i,s){let r=t.length;for(;r>1&&f.isSmallMetricDistance(t.distanceUncheckedIndexIndex(0,r-1));)r--;let o=0;if(e&&e.length<r&&(e=void 0),n&&n.length<r&&(n=void 0),i&&i.length<r&&(i=void 0),s&&s.length<r&&(s=void 0),this._reversed)for(let a=r;--a>=0;)o=this.findOrAddPointInGrowableXYZArrayUnchecked(t,a),this._polyface.addPointIndex(o),e&&(o=this.findOrAddNormalInGrowableXYZArrayUnchecked(e,a),this._polyface.addNormalIndex(o)),n&&(o=this.addParamInGrowableXYArrayUnchecked(n,a),this._polyface.addParamIndex(o)),i&&(o=this._polyface.addColor(i[a]),this._polyface.addColorIndex(o));else for(let a=0;a<r;a++)o=this.findOrAddPointInGrowableXYZArrayUnchecked(t,a),this._polyface.addPointIndex(o,s?s[a]:!0),e&&(o=this.findOrAddNormalInGrowableXYZArrayUnchecked(e,a),this._polyface.addNormalIndex(o)),n&&(o=this.addParamInGrowableXYArrayUnchecked(n,a),this._polyface.addParamIndex(o)),i&&(o=this._polyface.addColor(i[a]),this._polyface.addColorIndex(o));this._polyface.terminateFacet()}addFacetFromVisitor(t){this.addFacetFromGrowableArrays(t.point,t.normal,t.param,t.color,t.edgeVisible)}addFacetsFromVisitor(t){for(t.reset();t.moveToNextFacet();)this.addFacetFromVisitor(t)}addFacetFromIndexedVisitor(t,e){if(e.length>t.pointIndex.length)return!1;const n=new W(e.length),i=t.normal?new W(e.length):void 0,s=t.param?new Ie(e.length):void 0,r=t.color?new Array(e.length):void 0,o=t.edgeVisible?new Array(e.length):void 0;for(let a=0;a<e.length;++a){const c=e[a];if(c<0||c>=t.point.length)return!1;n.pushXYZ(t.point.getXAtUncheckedPointIndex(c),t.point.getYAtUncheckedPointIndex(c),t.point.getZAtUncheckedPointIndex(c)),t.normal&&i&&i.pushXYZ(t.normal.getXAtUncheckedPointIndex(c),t.normal.getYAtUncheckedPointIndex(c),t.normal.getZAtUncheckedPointIndex(c)),t.param&&s&&s.pushXY(t.param.getXAtUncheckedPointIndex(c),t.param.getYAtUncheckedPointIndex(c)),t.color&&r&&(r[a]=t.color[c]),t.edgeVisible&&o&&(o[a]=t.edgeVisible[c])}return this.addFacetFromGrowableArrays(n,i,s,r,o),!0}addIndexedPolyface(t,e=!1,n){this._polyface.addIndexedPolyface(t,e,n)}endFace(){return this._polyface.setNewFaceData()}handleCone(t){return this.addCone(t)}handleTorusPipe(t){return this.addTorusPipe(t)}handleSphere(t){return this.addSphere(t)}handleBox(t){return this.addBox(t)}handleLinearSweep(t){return this.addLinearSweep(t)}handleRotationalSweep(t){return this.addRotationalSweep(t)}handleRuledSweep(t){return this.addRuledSweep(t)}handleLoop(t){return this.addTriangulatedRegion(t)}handleParityRegion(t){return this.addTriangulatedRegion(t)}handleUnionRegion(t){return this.addTriangulatedRegion(t)}addGeometryQuery(t){t.dispatchToGeometryHandler(this)}addGraph(t,e=i=>V.testNodeMaskNotExterior(i),n=i=>V.testMateMaskExterior(i)){let i=0;const s=this._options.needNormals,r=this._options.needParams;let o=0;s&&(o=this._polyface.addNormalXYZ(0,0,1)),t.announceFaceLoops((a,c)=>{if(e(c)&&c.countEdgesAroundFace()>2){let l=c;do i=this.addPointXYZ(l.x,l.y,l.z),this._polyface.addPointIndex(i,n===void 0?!0:n(l)),r&&(i=this.addParamXY(l.x,l.y),this._polyface.addParamIndex(i)),s&&this._polyface.addNormalIndex(o),l=l.faceSuccessor;while(l!==c);this._polyface.terminateFacet()}return!0})}addGraphFaces(t){let e=0;for(const n of t){let i=n;do e=this.addPointXYZ(i.x,i.y,i.z),this._polyface.addPointIndex(e),i=i.faceSuccessor;while(i!==n);this._polyface.terminateFacet()}}static graphToPolyface(t,e,n=r=>V.testNodeMaskNotExterior(r),i=r=>V.testMateMaskExterior(r),s=f.smallMetricDistance){const r=it.create(e);return r.addGraph(t,n,i),r.endFace(),r.claimPolyface(!0,s)}static graphFacesToPolyface(t){const e=it.create();return e.addGraphFaces(t),e.endFace(),e.claimPolyface()}static polygonToTriangulatedPolyface(t,e){if(e||(e=Qt.createFrameWithCCWPolygon(t)),e){const n=e.multiplyInversePoint3dArray(t);if(!n)return;nt.areaXY(n)<0&&n.reverse();const s=B.createTriangulatedGraphFromSingleLoop(n);if(s){const r=this.graphToPolyface(s);return r.tryTransformInPlace(e),r}}}addCoordinateFacets(t,e,n,i=!1){for(let s=0;s<t.length;s++){const r=e?e[s]:void 0,o=n?n[s]:void 0;t[s].length===3?this.addTriangleFacet(t[s],r,o):t[s].length===4&&this.addQuadFacet(t[s],r,o)}i&&this.endFace()}addUVGridBody(t,e,n,i,s){let r=new Ft(e),o=new Ft(e),a,c,l,d;const h=this._reversed,g=this.options.needNormals;g&&(l=new Ft(e),d=new Ft(e));const m=this.options.needParams;m&&(a=new Ft(e),c=new Ft(e)),r.ensureCapacity(e),o.ensureCapacity(e);const p=D.create(),x=P.create(),_=1/e,I=1/n,v=At.createXYPlane();for(let S=0;S<=n;S++){o.clear(),d&&d.clear(),c&&c.clear();for(let w=0;w<=e;w++){const T=w*_,R=S*I;t.uvFractionToPointAndTangents(T,R,v),o.push(this._polyface.addPoint(v.origin)),d&&(v.vectorU.crossProduct(v.vectorV,x),x.normalizeInPlace(),h&&x.scaleInPlace(-1),d.push(this._polyface.addNormal(x))),c&&c.push(this._polyface.addParam(D.create(i?i.fractionToPoint(T):T,s?s.fractionToPoint(R):R,p)))}if(S>0)for(let w=0;w<e;w++)this._options.shouldTriangulate?(this.addIndexedTrianglePointIndexes(r.atUncheckedIndex(w),r.atUncheckedIndex(w+1),o.atUncheckedIndex(w),!1),l&&d&&this.addIndexedTriangleNormalIndexes(l.atUncheckedIndex(w),l.atUncheckedIndex(w+1),d.atUncheckedIndex(w)),a&&c&&this.addIndexedTriangleParamIndexes(a.atUncheckedIndex(w),a.atUncheckedIndex(w+1),c.atUncheckedIndex(w)),this._polyface.terminateFacet(),this.addIndexedTrianglePointIndexes(o.atUncheckedIndex(w),r.atUncheckedIndex(w+1),o.atUncheckedIndex(w+1),!1),l&&d&&this.addIndexedTriangleNormalIndexes(d.atUncheckedIndex(w),l.atUncheckedIndex(w+1),d.atUncheckedIndex(w+1)),a&&c&&this.addIndexedTriangleParamIndexes(c.atUncheckedIndex(w),a.atUncheckedIndex(w+1),c.atUncheckedIndex(w+1)),this._polyface.terminateFacet()):(this.addIndexedQuadPointIndexes(r.atUncheckedIndex(w),r.atUncheckedIndex(w+1),o.atUncheckedIndex(w),o.atUncheckedIndex(w+1),!1),g&&l&&d&&this.addIndexedQuadNormalIndexes(l.atUncheckedIndex(w),l.atUncheckedIndex(w+1),d.atUncheckedIndex(w),d.atUncheckedIndex(w+1)),m&&a&&c&&this.addIndexedQuadParamIndexes(a.atUncheckedIndex(w),a.atUncheckedIndex(w+1),c.atUncheckedIndex(w),c.atUncheckedIndex(w+1)),this._polyface.terminateFacet());[r,o]=[o,r],m&&([a,c]=[c,a]),g&&([l,d]=[d,l])}r.clear(),o.clear()}static pointsToTriangulatedPolyface(t,e){const n=B.createTriangulatedGraphFromPoints(t,ni.ReplaceIfLarger,e?.chordTol);if(n)return it.graphToPolyface(n,e)}addGreedyTriangulationBetweenLineStrings(t,e){go.createContext().emitTriangles(wa(t),wa(e),i=>{this.addTriangleFacet(i.points)})}addMiteredPipes(t,e,n=12,i=!1){const s=je.createArcFromSectionData(t,e);if(!s)return;n<3&&(n=3);const r=F.create();r.appendFractionalStrokePoints(s,n,0,1,!0);const o=this._options.clone(),a=ir.AlsoMesh,c=e instanceof N?s.binormalVector():void 0,l={strokeOptions:o,capped:i,outputSelect:a,startTangent:c},d=je.createMiteredSweepSections(t,r,l);d&&d.mesh&&this.addIndexedPolyface(d.mesh)}getEdgeIndices(t){let e=-1,n=-1;for(let i=this._polyface.facetIndex0(t.facetIndex);i<this._polyface.facetIndex1(t.facetIndex);++i)t.startVertex===this._polyface.data.pointIndex[i]?e=i:t.endVertex===this._polyface.data.pointIndex[i]&&(n=i);return e<0||n<0?void 0:{edgeIndexA:e,edgeIndexB:n}}addSweptFace(t,e){const n=this.getEdgeIndices(t);if(n===void 0)return!1;const i=e+t.facetIndex;if(!this._polyface.isValidFacetIndex(i))return!1;const s=this._polyface.numEdgeInFacet(t.facetIndex);if(s!==this._polyface.numEdgeInFacet(i))return!1;const r=this._polyface.facetIndex0(t.facetIndex),o=this._polyface.facetIndex0(i),a=n.edgeIndexA-r,c=n.edgeIndexB-r,l=s-1-a,d=s-1-c,h=[n.edgeIndexB,n.edgeIndexA,o+l,o+d],g=[];let m;this.options.needColors&&this._polyface.data.color&&this._polyface.data.colorIndex&&(m=[]);for(let p=0;p<4;++p){const x=h[p],_=this._polyface.data.getPoint(this._polyface.data.pointIndex[x]);if(_===void 0)return!1;if(g.push(_),m&&this._polyface.data.colorIndex&&0<=x&&x<this._polyface.data.colorIndex.length){const I=this._polyface.data.getColor(this._polyface.data.colorIndex[x]);m.push(I)}}return this.addQuadFacet(g,void 0,void 0,m),!0}addSweptIndexedPolyface(t,e,n=!1){let i=!0;const s=St.sumFacetAreas(t,e);f.isAlmostEqualNumber(0,s)&&(i=!1);const r=St.partitionFacetIndicesByVisibilityVector(t,e,A.createDegrees(.001)),o=r[0].length,a=r[1].length;r[2].length>0&&(i=!1),o>0&&a>0&&(i=!1);const l=o>0,d=this._polyface.facetCount;this.addIndexedPolyface(t,l);const h=this._polyface.facetCount;this.addIndexedPolyface(t,!l,X.createTranslation(e));const g=h-d,m=Array.from({length:g},(v,S)=>d+S),p=Qi.createSubsetVisitor(this._polyface,m,1),x=St.createIndexedEdges(p),_=[];x.sortAndCollectClusters(void 0,_,void 0,void 0);const I=this._options.shouldTriangulate;this._options.shouldTriangulate=n;for(const v of _)if(v instanceof Fe)this.addSweptFace(v,g);else if(Array.isArray(v))for(const S of v)this.addSweptFace(S,g);return this._options.shouldTriangulate=I,i}}function wa(u){return Array.isArray(u)?new Bt(u):u instanceof F?u.packedPoints:u}function Aa(u,t,e){return u!==t&&t!==e&&e!==u}var Ca;(function(u){function t(e,n){const i=[],s=e.constructIdToFaceIndexMap(),r=[],o=d=>d.isMaskSet(M.EXTERIOR)?!1:(r.push(s.get(d.id)??-1),!0),a=f.smallFloatingPoint,c=it.graphToPolyface(e,void 0,o,()=>!0,a);c.data.point.multiplyMatrix3dInPlace(C.createScale(1,1,0));const l=mo.createCapture(c,void 0,void 0,!1);if(l){const d=Array.isArray(n)?n:[n];for(const h of d){let g;const m=l.searchForClosestPoint(h,void 0,!0);if(m&&m.a<f.smallFloatingPoint){const p=r[m.facetIndex];p>=0&&p<e.allHalfEdges.length&&(g=e.allHalfEdges[p])}i.push(g)}}return i.length===0?void 0:i.length===1?i[0]:i}u.findContainingFaceXY=t})(Ca||(Ca={}));class Qc{_activeMomentData;_gaussMapper;constructor(t=5){this._activeMomentData=Dt.create(),this._activeMomentData.needOrigin=!0,this._gaussMapper=new Dr(t)}get momentData(){return this._activeMomentData}startParentCurvePrimitive(t){}startCurvePrimitive(t){}endCurvePrimitive(t){}endParentCurvePrimitive(t){}announceIntervalForUniformStepStrokes(t,e,n,i){this.startCurvePrimitive(t),e<1&&(e=1);const s=1/e;let r,o;for(let a=1;a<=e;a++){const c=f.interpolate(n,(a-1)*s,i),l=a===e?i:f.interpolate(n,a*s,i),d=this._gaussMapper.mapXAndW(c,l);for(let h=0;h<d;h++){o=this._gaussMapper.gaussX[h];const g=t.fractionToPointAndDerivative(o);r=this._gaussMapper.gaussW[h]*g.direction.magnitude(),this._activeMomentData.accumulateScaledOuterProduct(g.origin,r)}}}announceSegmentInterval(t,e,n,i,s,r){this._activeMomentData.accumulateLineMomentsXYZ(e,n)}announcePointTangent(t,e,n){}visitLeaves(t){if(t instanceof st)t.emitStrokableParts(this);else if(t instanceof ut)for(const e of t.children)this.visitLeaves(e)}}class pe{_chains;_makeClones;static _staticPointA;static _staticPointB;pushNewChain(t){const e=[];t&&e.push(t),this._chains.push(e)}findOrCreateTailChain(){return this._chains.length===0&&this.pushNewChain(),this._chains[this._chains.length-1]}_xyzWork0;findAnyChainToConnect(t){for(let e=0;e<this._chains.length;e++){const n=this._chains[e];if(this._xyzWork1=n[n.length-1].endPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(t))return{chainIndex:e,atEnd:!0};if(this._xyzWork1=n[0].startPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(t))return{chainIndex:e,atEnd:!1}}}constructor(t){this._chains=[],this._makeClones=t}_xyzWork1;announceCurvePrimitive(t,e=!1){if(t){if(this._makeClones){const n=t.clone();if(!n||!(n instanceof st))return;this.transferMarkup(t,n),t=n}if(e){this._xyzWork0=t.startPoint(this._xyzWork0);let n=this.findAnyChainToConnect(this._xyzWork0);n?n.atEnd?this._chains[n.chainIndex].push(t):(t.reverseInPlace(),this._chains[n.chainIndex].splice(0,0,t)):(this._xyzWork0=t.endPoint(this._xyzWork0),n=this.findAnyChainToConnect(this._xyzWork0),n?n.atEnd?(t.reverseInPlace(),this._chains[n.chainIndex].push(t)):this._chains[n.chainIndex].splice(0,0,t):this._chains.push([t]))}else{const n=this.findOrCreateTailChain();n.length===0||!pe.needBreakBetweenPrimitives(n[n.length-1],t)?n.push(t):this.pushNewChain(t)}}}transferMarkup(t,e){t&&e&&(e.startCut=t.startCut,e.endCut=t.endCut)}promoteArrayToCurves(t,e){if(t.length!==0)return e&&(pe._staticPointA=t[0].startPoint(pe._staticPointA),pe._staticPointB=t[t.length-1].endPoint(pe._staticPointB),pe._staticPointA.isAlmostEqual(pe._staticPointB))?tt.createArray(t):t.length===1?t[0]:Pt.createArray(t)}grabResult(t=!1){const e=this._chains;if(e.length===0)return;if(e.length===1)return this.promoteArrayToCurves(e[0],t);const n=Ee.create();for(const i of e){const s=this.promoteArrayToCurves(i,t);n.tryAddChild(s)}return n}static needBreakBetweenPrimitives(t,e,n=!1){return t===void 0||e===void 0||t.endCut!==void 0||e.startCut!==void 0?!0:(pe._staticPointA=t.endPoint(pe._staticPointA),pe._staticPointB=e.startPoint(pe._staticPointB),n?!pe._staticPointA.isAlmostEqualXY(pe._staticPointB):!pe._staticPointA.isAlmostEqual(pe._staticPointB))}}var fn;(function(u){u[u.Unknown=0]="Unknown",u[u.Cap=1]="Cap",u[u.Extend=2]="Extend",u[u.Trim=-1]="Trim",u[u.JustGeometry=3]="JustGeometry",u[u.Gap=4]="Gap"})(fn||(fn={}));class Gt{flexure;curve0;fraction0;curve1;fraction1;jointCurve;swingPoint;nextJoint;previousJoint;constructor(t,e,n){this.curve0=t,this.curve1=e,this.swingPoint=n,this.flexure=fn.Unknown}static constructArc(t,e,n){if(e!==void 0&&f.isSameCoordinate(t.origin.distance(e),n.origin.distance(e))){const i=t.direction.angleToXY(n.direction),s=P.createStartEnd(e,t.origin),r=s.rotate90CCWXY();return N.create(e,s,r,at.createStartEndRadians(0,i.radians))}}shallowExtract(){return{curve0:this.curve0,curve1:this.curve1,fraction0:this.fraction0,fraction1:this.fraction1}}static link(t,e){t.nextJoint=e,e&&(e.previousJoint=t),t.curve1&&e&&!e.curve0?e.curve0=t.curve1:!t.curve1&&e&&e.curve0&&(t.curve1=e.curve0)}nextJointFraction0(t){return this.nextJoint&&this.nextJoint.fraction0!==void 0?this.nextJoint.fraction0:t}static addStrokes(t,e){e&&e.emitStrokes(t)}static addPoint(t,e){t.packedPoints.length>0&&(t.endPoint().isAlmostEqual(e)||t.packedPoints.push(e))}static collectStrokesFromChain(t,e,n=100){let i=-2*n;Gt.visitJointsOnChain(t,s=>{if(this.addStrokes(e,s.jointCurve),s.curve1&&s.fraction1!==void 0){const r=s.fraction1,o=s.nextJointFraction0(1);let a;r===0&&o===1?a=s.curve1.clone():r<o&&(a=s.curve1.clonePartialCurve(r,o)),a&&(s.jointCurve||this.addPoint(e,a.startPoint())),this.addStrokes(e,a)}return i++<n},n)}static collectPrimitive(t,e){if(e){if(t.length>0){const n=t[t.length-1].endPoint(),i=e.startPoint();n.isAlmostEqual(i)||t.push(U.create(n,i))}t.push(e)}}static adjustJointToPrimitives(t){const e=t.jointCurve;if(e instanceof F){if(t.curve0){const n=t.curve0.endPoint(),i=e.startPoint();n.isAlmostEqual(i)||e.packedPoints.setAtCheckedPointIndex(0,n)}if(t.curve1){const n=t.curve1.startPoint(),i=e.endPoint();n.isAlmostEqual(i)||e.packedPoints.setAtCheckedPointIndex(e.packedPoints.length-1,n)}}}static collectCurvesFromChain(t,e,n=100){if(t===void 0)return;let i=-2*n;Gt.visitJointsOnChain(t,s=>{if(this.adjustJointToPrimitives(s),this.collectPrimitive(e,s.jointCurve),s.curve1&&s.fraction1!==void 0){const r=s.fraction1,o=s.nextJointFraction0(1);let a;r===0&&o===1?a=s.curve1.clone():r<o&&(a=s.curve1.clonePartialCurve(r,o)),this.collectPrimitive(e,a)}return i++<n},n)}static annotateChain(t,e,n=100){t&&Gt.visitJointsOnChain(t,i=>(i.annotateJointMode(e),!0),n)}static visitJointsOnChain(t,e,n=100){let i=t;if(i){let s=0;for(;i!==void 0;){if(s++>=n+5)return!0;if(!e(i))return!1;if(i=i.nextJoint,i===t)break}}return!0}annotateExtension(t){if(this.curve0&&this.curve1){const e=this.curve0.fractionToPointAndDerivative(1),n=this.curve1.fractionToPointAndDerivative(0);e.direction.z=n.direction.z=0;const i=O.closestApproachRay3dRay3d(e,n);if(i.approachType===Dn.Intersection&&i.detailA.fraction>=0&&i.detailB.fraction<=0){this.fraction0=1,this.fraction1=0,this.flexure=fn.Extend;const s=e.getDirectionRef().angleToXY(n.getDirectionRef());if(t.needArc(s)){const o=Gt.constructArc(e,this.curve0.baseCurveEnd,n);if(o){this.jointCurve=o;return}}const r=t.numChamferPoints(s);if(r<=1){this.jointCurve=F.create(e.origin,i.detailA.point,n.origin);return}if(r>1){const o=s.radians,a=2*r,c=o/a,l=Gt.constructArc(e,this.curve0.baseCurveEnd,n);if(l!==void 0){const d=1/Math.cos(c),h=F.create();this.jointCurve=h,h.addPoint(e.origin);for(let g=0;g<r;g++){const m=(1+2*g)/a;h.addPoint(l.fractionAndRadialFractionToPoint(m,d))}h.addPoint(n.origin);return}}}this.flexure=fn.Gap,this.jointCurve=U.create(this.curve0.fractionToPoint(1),this.curve1.fractionToPoint(0)),this.fraction0=1,this.fraction1=0}}selectIntersectionIndexByFraction(t,e,n){let i=-1,s=Number.MAX_VALUE;for(let r=0;r<n.length;r++){const o=Math.abs(n[r].detailA.fraction-t)+Math.abs(n[r].detailB.fraction-e);o<s&&(s=o,i=r)}return i}annotateJointMode(t){if(!this.curve0&&this.curve1)this.flexure=fn.Cap,this.fraction1=0;else if(this.curve0&&!this.curve1)this.flexure=fn.Cap,this.fraction0=1;else if(this.curve0&&this.curve1)if(this.curve0.endPoint().isAlmostEqualXY(this.curve1.startPoint()))this.fraction0=1,this.fraction1=0,this.flexure=fn.Trim;else if(this.curve0 instanceof U&&this.curve1 instanceof U){const e=this.curve0.fractionToPointAndDerivative(0),n=this.curve1.fractionToPointAndDerivative(0);e.direction.z=n.direction.z=0;const i=O.closestApproachRay3dRay3d(e,n);(i.approachType===Dn.Intersection||i.approachType===Dn.PerpendicularChord)&&(this.fraction0=i.detailA.fraction,this.fraction1=i.detailB.fraction,this.fraction0>=1&&this.fraction1<=0?this.annotateExtension(t):this.fraction0<1&&this.fraction1>0?this.flexure=fn.Trim:this.fraction0>1&&this.fraction1>1&&(this.flexure=fn.Gap,this.jointCurve=U.create(this.curve0.fractionToPoint(1),this.curve1.fractionToPoint(0)),this.fraction0=1,this.fraction1=0))}else{const e=He.intersectionXYPairs(this.curve0,!1,this.curve1,!1),n=this.selectIntersectionIndexByFraction(1,0,e);n>=0?(this.flexure=fn.Trim,this.fraction0=e[n].detailA.fraction,this.fraction1=e[n].detailB.fraction):this.annotateExtension(t)}}static removeDegeneratePrimitives(t,e,n){let i=t,s=0,r=0;if(i)for(;i!==void 0&&r++<n;){const o=i.nextJoint;if(i&&o&&i.previousJoint&&o.nextJoint&&i.fraction1!==void 0&&o.fraction0!==void 0){const a=i.fraction1,c=o.fraction0,l=o.fraction1,d=o.nextJoint.fraction0,h=a>=c||a>1,g=l!==void 0&&l>1||l!==void 0&&d!==void 0&&l>=d;if(h&&g){const m=o.nextJoint,p=new Gt(i.curve0,m.curve1,void 0);Gt.link(i.previousJoint,p),Gt.link(p,m.nextJoint),p.annotateJointMode(e),p.previousJoint&&p.previousJoint.annotateJointMode(e),p.nextJoint&&p.nextJoint.annotateJointMode(e),s+=2,(i===t||o===t||m===t)&&(t=p),i=p}else if(h){const m=new Gt(i.curve0,o.curve1,void 0);Gt.link(i.previousJoint,m),Gt.link(m,o.nextJoint),m.annotateJointMode(e),m.previousJoint&&m.previousJoint.annotateJointMode(e),m.nextJoint&&m.nextJoint.annotateJointMode(e),s++,(i===t||o===t)&&(t=m),i=m}}if(i=i.nextJoint,i===t)break}return{newStart:t,numJointRemoved:s}}}class dr{constructor(){}static _unitAlong=P.create();static _unitPerp=P.create();static _offsetA=y.create();static _offsetB=y.create();static createOffsetSegment(t,e,n){if(P.createStartEnd(t,e,this._unitAlong),this._unitAlong.z=0,this._unitAlong.normalizeInPlace()){this._unitAlong.rotate90CCWXY(this._unitPerp);const i=U.create(t.plusScaled(this._unitPerp,n,this._offsetA),e.plusScaled(this._unitPerp,n,this._offsetB));return Ii.applyBasePoints(i,t.clone(),e.clone()),i}}constructPolygonWireXYOffset(t,e,n){e&&!t[0].isAlmostEqual(t[t.length-1])&&(e=!1);const i=Ei.create(n),s=t.length;let r,o,a;for(let h=0;h+1<s;++h)if(!a)(r=dr.createOffsetSegment(t[h],t[h+1],i.leftOffsetDistance))&&(a=o=new Gt(void 0,r,t[h]));else{const g=dr.createOffsetSegment(t[h],t[h+1],i.leftOffsetDistance);if(g){const m=new Gt(r,g,t[h]);Gt.link(a,m),a=m,r=g}}if(!r||!a||!o)return;const c=e?o:new Gt(r,void 0,t[s-1]);Gt.link(a,c),Gt.annotateChain(o,i,s);for(let h=0;h++<5;){const g=Gt.removeDegeneratePrimitives(o,i,s);if(o=g.newStart,g.numJointRemoved===0)break}const l=F.create();Gt.collectStrokesFromChain(o,l,s);const d=l.packedPoints.length;if(d>1)return l.packedPoints.almostEqualUncheckedIndexIndex(0,d-1)?tt.create(l):Pt.create(l)}}class Ii{constructor(){}static applyBasePoints(t,e,n){return t!==void 0&&(e!==void 0&&(t.baseCurveStart=e),n!==void 0&&(t.baseCurveEnd=n)),t}static createSingleOffsetPrimitiveXY(t,e){const n=t.constructOffsetXY(e);if(n!==void 0){if(Array.isArray(n)){const i=t.collectCurvePrimitives(void 0,!0,!0);if(i.length!==n.length)return;for(let s=0;s<i.length;++s)this.applyBasePoints(n[s],i[s].startPoint(),i[s].endPoint());return n}return this.applyBasePoints(n,t.startPoint(),t.endPoint())}}static constructCurveXYOffset(t,e){const n=t instanceof tt,i=Oe.create(e),s=[];for(const h of t.children){const g=Ii.createSingleOffsetPrimitiveXY(h,i);if(g!==void 0){if(g instanceof st)s.push(g);else if(Array.isArray(g))for(const m of g)m instanceof st&&s.push(m)}}let r,o,a,c;for(const h of s)h&&(o=new Gt(r,h,h.fractionToPoint(0)),o!==void 0&&c===void 0&&(c=o),a&&Gt.link(a,o),a=o,r=h);c&&a&&t instanceof tt&&Gt.link(a,c);const l=s.length;if(Gt.annotateChain(c,i.jointOptions,l),c)for(let h=0;h++<5;){const g=Gt.removeDegeneratePrimitives(c,i.jointOptions,l);if(c=g.newStart,g.numJointRemoved===0)break}const d=[];return Gt.collectCurvesFromChain(c,d,l),ot.createLoopPathOrBagOfCurves(d,n,!0)}}class hr extends Ri{constructor(){super(void 0)}doClone(t){return t instanceof N&&t.sweep.isFullCircle?[t.clonePartialCurve(0,.5),t.clonePartialCurve(.5,1)]:t}static clone(t){const e=new hr;return t.announceToCurveProcessor(e),e._result}}class $c extends Ys{_consolidateLinearGeometry;_consolidateCompatibleArcs;_consolidateLoopSeam;_disableLinearCompression;_duplicatePointTolerance;_colinearPointTolerance;constructor(t){super(),this._consolidateLinearGeometry=t?.consolidateLinearGeometry??!0,this._consolidateCompatibleArcs=t?.consolidateCompatibleArcs??!0,this._consolidateLoopSeam=t?.consolidateLoopSeam??!1,this._disableLinearCompression=t?.disableLinearCompression??!1,this._duplicatePointTolerance=t?.duplicatePointTolerance??f.smallMetricDistance,this._colinearPointTolerance=t?.colinearPointTolerance??f.smallMetricDistance}handleCurveChain(t){const n=t.children.length,i=[];let s=0;for(let r=0;r<n;){const o=t.children[r];if(this._consolidateLinearGeometry&&(o instanceof U||o instanceof F)){i.length=0;let a=r;for(;a<t.children.length;a++){const c=t.children[a];if(c instanceof U)i.push(c.startPoint()),i.push(c.endPoint());else if(c instanceof F){const l=c.packedPoints;for(let d=0;d<l.length;d++)i.push(l.getPoint3dAtUncheckedPointIndex(d))}else break}if(i.length<=1)t.children[s++]=o;else if(this._disableLinearCompression){const c=gn.compressShortEdges(i,f.smallFloatingPoint);t.children[s++]=F.createPoints(c)}else{const c=gn.compressShortEdges(i,this._duplicatePointTolerance),l=gn.compressByChordError(c,this._colinearPointTolerance,!0);r===0&&a===n&&this._consolidateLoopSeam&&te.compressColinearWrapInPlace(l,this._duplicatePointTolerance,this._colinearPointTolerance),l.length<2?t.children[s++]=F.create(l[0]):l.length===2?t.children[s++]=U.create(l[0],l[1]):t.children[s++]=F.createPoints(l)}r=a}else if(this._consolidateCompatibleArcs&&o instanceof N){for(;++r<t.children.length;){const a=t.children[r];if(!(a instanceof N)||!je.appendToArcInPlace(o,a,!1,this._duplicatePointTolerance))break}t.children[s++]=o}else t.children[s++]=o,r++}t.children.length=s}handlePath(t){return this.handleCurveChain(t)}handleLoop(t){if(this.handleCurveChain(t),t.children.length>1&&this._consolidateLoopSeam){const e=t.children[t.children.length-1],n=t.children[0];if((e instanceof U||e instanceof F)&&(n instanceof U||n instanceof F)){if(this._consolidateLinearGeometry&&!this._disableLinearCompression){const i=e.points;i.pop(),t.children[0]=F.createPoints([...i,...n.points]),t.children.pop()}}else e instanceof N&&n instanceof N&&this._consolidateCompatibleArcs&&je.appendToArcInPlace(e,n,!1,this._duplicatePointTolerance)&&(t.children[0]=e,t.children.pop())}}handleParityRegion(t){for(const e of t.children)e.dispatchToGeometryHandler(this)}handleUnionRegion(t){for(const e of t.children)e.dispatchToGeometryHandler(this)}}class Ta{fraction;otherCurveDetail;constructor(t,e){this.fraction=t,this.otherCurveDetail=e}setFrom(t,e){e&&this.isSameFraction(t)&&(this.otherCurveDetail=t.otherCurveDetail?t.otherCurveDetail:this.otherCurveDetail),this.fraction=t.fraction}isSameFraction(t){return f.isSmallAngleRadians(this.fraction-t.fraction)}set(t,e){this.fraction=t,this.otherCurveDetail=e}}class ur{static hasInteriorDetailAIntersections(t,e=f.smallAngleRadians){if(t.length===0)return!1;for(const n of t)if(n.detailA.fraction>e||n.detailA.fraction<1-e)return!0;return!1}collectFragmentAndAdvanceCut(t,e,n,i){if(!e.isSameFraction(n)){const s=t.clonePartialCurve(e.fraction,n.fraction);s!==void 0&&(s.startCut=e.otherCurveDetail,s.endCut=n.otherCurveDetail,i.push(s))}e.setFrom(n,!0)}collectSinglePrimitiveFragments(t,e,n){if(e===void 0||!ur.hasInteriorDetailAIntersections(e)){n.push(t.clone());return}e.sort((r,o)=>r.detailA.fraction-o.detailA.fraction);const i=new Ta(0,void 0),s=new Ta(1,void 0);for(const r of e)s.set(r.detailA.fraction,r.detailB),this.collectFragmentAndAdvanceCut(t,i,s,n);s.set(1,void 0),this.collectFragmentAndAdvanceCut(t,i,s,n)}static cloneCurvesWithXYSplits(t,e){const n=new ur;if(t instanceof st){const i=[],s=He.intersectionXYPairs(t,!1,e,!1);return n.collectSinglePrimitiveFragments(t,s,i),i.length===1?i[0]:Pt.createArray(i)}else if(t instanceof de){const i=[];for(const s of t.children){const r=He.intersectionXYPairs(s,!1,e,!1);n.collectSinglePrimitiveFragments(s,r,i)}return Pt.createArray(i)}}}class jc{static testPointInOnOutLoopXY(t,e,n){let i;const s=y.create(e,n);for(let r=0;Math.abs(r)<6;r=-1.2313*(r+.3212897)){i=ht.createXYAngle(e,n,A.createRadians(r));const o=i.getNormalRef(),a=[];for(const x of t.children)x instanceof st&&x.appendPlaneIntersectionPoints(i,a);st.snapAndRestrictDetails(a,!1,!0);let c=0,l=0,d=0,h,g;for(const x of a){if(x.intervalRole!==Ct.isolated&&x.intervalRole!==void 0&&d++,h=x.point.x-e,g=x.point.y-n,f.isSameCoordinateXY(h,g,0,0))return 0;const _=f.crossProductXYXY(o.x,o.y,h,g);if(s.isAlmostEqualXY(x.point))return 0;_<0?c++:_>0&&l++}if(d!==0)continue;const m=c&1,p=l&1;if(m===p)return m===1?1:-1}return-1}static testPointInOnOutParityRegionXY(t,e,n){let i=-1;for(const s of t.children)if(s instanceof tt){const r=this.testPointInOnOutLoopXY(s,e,n);if(r===0)return 0;r>0&&(i=-i)}return i}static testPointInOnOutUnionRegionXY(t,e,n){for(const i of t.children){const s=this.testPointInOnOutRegionXY(i,e,n);if(s>=0)return s}return-1}static testPointInOnOutRegionXY(t,e,n){return t instanceof tt?this.testPointInOnOutLoopXY(t,e,n):t instanceof Wt?this.testPointInOnOutParityRegionXY(t,e,n):t instanceof ve?this.testPointInOnOutUnionRegionXY(t,e,n):-1}}class tl{startComponent(t){return!0}finishComponent(t){return!0}enterFace(t,e){return!0}leaveFace(t,e){return!0}}class el extends tl{_faceSelectFunction;_inComponent;_exteriorMask;constructor(t,e){super(),this._inComponent=[!1,!1,!1],this._exteriorMask=e,this._faceSelectFunction=t}startComponent(t){return t.setMaskAroundFace(this._exteriorMask),!0}enterFace(t,e){const n=e.edgeTag;return(e.edgeTag===1||e.edgeTag===2)&&(this._inComponent[n]=!this._inComponent[n]),this._faceSelectFunction(this._inComponent[1],this._inComponent[2])||e.setMaskAroundFace(this._exteriorMask),!0}leaveFace(t,e){const n=e.edgeTag;return(e.edgeTag===1||e.edgeTag===2)&&(this._inComponent[n]=!this._inComponent[n]),!0}}class vi{static faceToFaceSearchFromOuterLoop(t,e,n,i){if(t.isMaskSet(e)||!i.startComponent(t))return;const s=[];t.setMaskAroundFace(e);let r=t;do{let o=r,a=r.edgeMate;if(!a.isMaskSet(e)){s.push(r),s.push(a);let c=a.faceSuccessor;if(a.setMaskAroundFace(e),o=a,i.enterFace(s,a))for(;;){if(a=c.edgeMate,!a.isMaskSet(e)){if(a.setMaskAroundFace(e),!i.enterFace(s,a))return;s.push(c),s.push(a),c=a,o=a}if(c.setMask(n),c=c.faceSuccessor,c===o){if(i.leaveFace(s,c),s.length<=2)break;s.pop(),c=s[s.length-1],s.pop(),o=s[s.length-1]}if(c.isMaskSet(n))return}}r=r.faceSuccessor}while(r!==t);i.finishComponent(t)}static doPolygonBoolean(t,e,n,i){const s=new be,r=M.BOUNDARY_EDGE|M.PRIMARY_EDGE,o=ot.addLoopsWithEdgeTagToGraph(s,t,r,1),a=ot.addLoopsWithEdgeTagToGraph(s,e,r,2);if(i&&i("unmerged loops",s,"U"),o||a){Je.splitIntersectingEdges(s),i&&i("After splitIntersectingEdges",s,"S"),Je.clusterAndMergeXYTheta(s),i&&i("After clusterAndMergeXYTheta",s,"M"),new Yi(s).regularizeGraph(!0,!0),i&&i("After regularize",s,"MR");const l=On.findMinimumAreaFace(s);if(l===void 0)return;const d=M.EXTERIOR,h=s.grabMask(),g=s.grabMask(),m=d|h|g;s.clearMask(m);const p=new el(n,d);return this.faceToFaceSearchFromOuterLoop(l,h,g,p),i&&i("After faceToFaceSearchFromOuterLoop",s,"MRX"),s.dropMask(h),s.dropMask(g),s}}static doBinaryBooleanBetweenMultiLoopInputs(t,e,n,i,s,r){const o=new be,a=M.BOUNDARY_EDGE|M.PRIMARY_EDGE,c=Wn.create(e,s);c.graph=o,c.faceAreaFunction=d=>On.signedFaceArea(d);for(const d of t)if(d.length>2){const h=new oi(d,c.groupA);ot.addLoopsWithEdgeTagToGraph(o,d,a,h)}for(const d of i)if(d.length>2){const h=new oi(d,c.groupB);ot.addLoopsWithEdgeTagToGraph(o,d,a,h)}return Je.splitIntersectingEdges(o),Je.clusterAndMergeXYTheta(o),new Yi(o).regularizeGraph(!0,!0),c.runClassificationSweep(n),r&&c.unmaskMaskedNullFaces(M.EXTERIOR),o}}var ue;(function(u){u[u.Union=0]="Union",u[u.Parity=1]="Parity",u[u.Intersection=2]="Intersection",u[u.NonBounding=-1]="NonBounding"})(ue||(ue={}));class oi{region;sweepState;parentGroup;constructor(t,e){this.region=t,this.parentGroup=e,this.sweepState=0}clearState(){this.sweepState=0}}class po{members;groupOpType;parent;_numIn;constructor(t,e){this.members=[],this.parent=t,this.groupOpType=e,this._numIn=0}clearState(){for(const t of this.members)t.clearState();this._numIn=0}range(){const t=J.createNull();for(const e of this.members)if(e.region instanceof Ae)e.region.extendRange(t);else{const n=J.createFromVariantData(e.region);t.extendRange(n)}return t}getInOut(){return this.groupOpType===ue.Union?this._numIn>0:this.groupOpType===ue.Parity?f.isOdd(this._numIn):this.groupOpType===ue.Intersection?this._numIn===this.members.length:!1}addMember(t,e=!1){if(t instanceof tt||t instanceof Wt){let n=t.clone();ot.consolidateAdjacentPrimitives(n),n=hr.clone(n),this.members.push(new oi(n,this))}else if(t instanceof ve)for(const n of t.children)this.addMember(n);else if(Array.isArray(t))for(const n of t)this.addMember(n);else e&&t instanceof U&&this.members.push(new oi(t,this))}recordMemberStateChange(t,e){const n=f.isOdd(t),i=f.isOdd(e);!n&&i?this._numIn++:n&&!i&&this._numIn--}}class Wn{groupA;groupB;extraGeometry;graph;faceAreaFunction;binaryOp;constructor(t,e){this.groupA=new po(this,t),this.groupB=new po(this,e),this.extraGeometry=new po(this,ue.NonBounding),this.binaryOp=Ze.Union}static create(t,e){return new Wn(t,e)}addMembers(t,e){this.groupA.addMember(t),this.groupB.addMember(e),this.addConnectives()}_workSegment;static _bridgeDirection=P.createNormalized(1,-.12328974132467);addConnectives(){const t=this.groupA.range(),e=this.groupB.range(),n=t.union(e);let i=.1;this._workSegment=Le.findExtremePointsInDirection(n.corners(),Wn._bridgeDirection,this._workSegment),this._workSegment&&(i*=this._workSegment.point0Ref.distanceXY(this._workSegment.point1Ref));const s=[],r=ot.computeMinimumArea(),o=c=>{const l=ot.computeXYArea(c);l===void 0||Math.abs(l)<r||(this._workSegment=Le.findExtremePointsInDirection(c,Wn._bridgeDirection,this._workSegment),this._workSegment&&s.push(this._workSegment.point1Ref))};for(const c of[this.groupA.members,this.groupB.members])for(const l of c)if(l.region instanceof tt)o(l.region);else if(l.region instanceof Wt)for(const d of l.region.children)o(d);const a=O.createZero();for(const c of s){const l=i+O.create(c,Wn._bridgeDirection,a).intersectionWithRange3d(n).high,d=y.createAdd2Scaled(c,1,Wn._bridgeDirection,l),h=U.createXYXY(c.x,c.y,d.x,d.y);this.extraGeometry.addMember(h,!0)}}annotateAndMergeCurvesInGraph(t=f.smallMetricDistance){const e=[];for(const s of[this.groupA,this.groupB,this.extraGeometry])for(const r of s.members){let o=e.length;if(r.region instanceof Ae)for(ot.collectCurvePrimitives(r.region,e,!0,!0);o<e.length;o++)e[o].parent=r}const n=He.allIntersectionsAmongPrimitivesXY(e,t),i=os.assembleHalfEdgeGraph(e,n,t);ot.removeExtraneousBridgeEdges(this.graph=i,void 0,this.faceAreaFunction=rs)}_announceFaceFunction;runClassificationSweep(t,e){this._announceFaceFunction=e,this.binaryOp=t,this.graph.clearMask(M.EXTERIOR);for(const r of[this.groupA,this.groupB])r.clearState();const n=this.graph.grabMask(),i=this.graph.grabMask(),s=xo.create(this.graph);for(const r of s.components){const o=r.faces[r.faceAreas.indexOf(Math.min(...r.faceAreas))],c=M.EXTERIOR|n|i;this.graph.clearMask(c),vi.faceToFaceSearchFromOuterLoop(o,n,i,this)}this.graph.dropMask(n),this.graph.dropMask(i)}unmaskMaskedNullFaces(t){for(const e of this.graph.allHalfEdges){const n=e.faceSuccessor;n.faceSuccessor===e&&e.getMask(t)&&n.getMask(t)&&(!e.edgeMate.getMask(t)||!n.edgeMate.getMask(t))&&(e.clearMask(t),n.clearMask(t))}}getInOut(){return this.binaryOp===Ze.Union?this.groupA.getInOut()||this.groupB.getInOut():this.binaryOp===Ze.Intersection?this.groupA.getInOut()&&this.groupB.getInOut():this.binaryOp===Ze.AMinusB?this.groupA.getInOut()&&!this.groupB.getInOut():this.binaryOp===Ze.BMinusA?!this.groupA.getInOut()&&this.groupB.getInOut():this.binaryOp===Ze.Parity?this.groupA.getInOut()!==this.groupB.getInOut():!1}recordTransitionAcrossEdge(t,e){const n=s=>{if(s.parentGroup.groupOpType===ue.NonBounding)return s;if(e!==0){const r=s.sweepState;s.sweepState+=e,s.parentGroup.recordMemberStateChange(r,s.sweepState)}return s},i=t.edgeTag;if(i instanceof oi)return n(i);if(i instanceof Y&&i.curve){const s=i.curve.parent;if(s instanceof oi)return n(s)}}startComponent(t){return t.setMaskAroundFace(M.EXTERIOR),this._announceFaceFunction&&this._announceFaceFunction(this.graph,t,-1,rs(t)),!0}finishComponent(t){return!0}enterFace(t,e){this.recordTransitionAcrossEdge(e,1);const n=this.getInOut();return n||e.setMaskAroundFace(M.EXTERIOR),this._announceFaceFunction&&this._announceFaceFunction(this.graph,e,n?1:0,rs(e)),!0}leaveFace(t,e){return this.recordTransitionAcrossEdge(e,-1),!0}}function nl(u,t,e,n){let i;u&&u.point1?i=-(u.point1.x-u.point.x)*(.5*(u.point.y+u.point1.y)-n.y):i=-(e.x-t.x)*(.5*(t.y+e.y)-n.y);let s=0;if(u&&u.curve&&u.isInterval()&&!(u.curve instanceof U))if(u.curve instanceof N)s=u.curve.areaToChordXY(u.fraction,u.fraction1);else{const r=u.curve.clonePartialCurve(u.fraction,u.fraction1);s=(r?ot.computeXYArea(tt.create(r,U.create(u.point1,u.point))):0)??0}return i+s}function rs(u){let t=0,e=u;do t+=e.sortData*nl(e.edgeTag,e,e.faceSuccessor,u);while((e=e.faceSuccessor)!==u);return t}class il{faces;faceAreas;range;constructor(t){this.faces=t,this.range=Rt.createNull(),this.faceAreas=[]}buildFaceData(t,e){const n=i=>(t?t(i,this.range):this.range.extendXY(i.x,i.y),0);this.range.setNull();for(const i of this.faces)i.sumAroundFace(n);this.faceAreas.length=0,e===rs&&!this.faces.every(i=>i.edgeTag instanceof Y)&&(e=void 0),e||(e=i=>On.signedFaceArea(i));for(const i of this.faces)this.faceAreas.push(e(i))}}class xo{components;graph;constructor(t){this.graph=t,this.components=[]}static create(t,e){const n=new xo(t),i=On.collectConnectedComponentsWithExteriorParityMasks(t,void 0);for(const s of i){const r=new il(s);r.buildFaceData(e,rs),n.components.push(r)}return n}}class sl{primitiveToPair=new Map;primitiveToIndex=new Map;_numIndexedPrimitives=0;assignPrimitiveIndex(t){t!==void 0&&this.primitiveToIndex.get(t)===void 0&&this.primitiveToIndex.set(t,this._numIndexedPrimitives++)}insertPrimitiveToPair(t,e){if(t){const n=this.primitiveToPair.get(t);this.assignPrimitiveIndex(t),n?n.push(e):this.primitiveToPair.set(t,[e])}}insertPair(t){const e=t.detailA.curve;e&&this.insertPrimitiveToPair(e,t);const n=t.detailB.curve;n&&this.insertPrimitiveToPair(n,t)}splitAndAppendMissingClosedPrimitives(t,e=f.smallMetricDistance){for(const n of t){let i=!1;if(n instanceof N?i=n.sweep.isFullCircle:!(n instanceof U)&&!(n instanceof F)&&(i=n.startPoint().isAlmostEqualXY(n.endPoint(),e)),i&&!this.primitiveToPair.has(n)){const s=n.clonePartialCurve(0,.5),r=n.clonePartialCurve(.5,1);s&&r&&(this.insertPair(Ot.createCapture(Y.createCurveEvaluatedFraction(s,0),Y.createCurveEvaluatedFraction(r,1))),this.insertPair(Ot.createCapture(Y.createCurveEvaluatedFraction(s,1),Y.createCurveEvaluatedFraction(r,0))))}}}}class os{static assembleHalfEdgeGraph(t,e,n=f.smallMetricDistance,i=f.smallAngleRadians){const s=new sl;for(const c of e)s.insertPair(c);t.length>s.primitiveToPair.size&&s.splitAndAppendMissingClosedPrimitives(t,n);const r=(c,l)=>c.detailA.curve===l?c.detailA.fraction:c.detailB.fraction,o=(c,l)=>c.detailA.curve===l?c.detailA:c.detailB,a=new be;for(const c of s.primitiveToPair.entries()){const l=c[0],d=c[1].reduce((g,m)=>{const p=o(m,l);if(p.isInterval()){const x=Y.createCurveFractionPoint(l,p.fraction,p.point),_=Y.createCurveFractionPoint(l,p.fraction1,p.point1);return[...g,Ot.createCapture(x,x),Ot.createCapture(_,_)]}return[...g,m]},[]);d.sort((g,m)=>{const p=r(g,l),x=r(m,l);return p-x});let h={point:l.startPoint(),fraction:0};for(const g of d){const m=o(g,l),p=f.restrictToInterval(m.fraction,0,1);h=this.addHalfEdge(a,l,h.point,h.fraction,m.point,p,n)}this.addHalfEdge(a,l,h.point,h.fraction,l.endPoint(),1,n)}return Je.clusterAndMergeXYTheta(a,c=>c.sortAngle??0,n,i),a}static isCurveTrivialXY(t,e,n,i,s,r){if(f.isSmallRelative(n-s))return!0;if(!(t instanceof U)){const o=t.clonePartialCurve(n,s);if(o?.tryTransformInPlace(X.createRowValues(1,0,0,0,0,1,0,0,0,0,0,0)))return o.curveLength()<=r}return e.isAlmostEqualXY(i,r)}static addHalfEdge(t,e,n,i,s,r,o=f.smallMetricDistance){if(!this.isCurveTrivialXY(e,n,i,s,r,o)){const a=t.createEdgeXYAndZ(n,0,s,0);e.parent&&e.parent instanceof oi&&e.parent.parentGroup.groupOpType===ue.NonBounding&&a.setMaskAroundEdge(M.BRIDGE_EDGE);const c=Y.createCurveEvaluatedFractionFraction(e,i,r),l=a.edgeMate;a.edgeTag=c,a.sortData=1,l.edgeTag=c,l.sortData=-1;const d=(h,g)=>{const m=e.fractionToPointAndDerivative(h),p=g?-1:1;return Math.atan2(p*m.direction.y,p*m.direction.x)};a.sortAngle=d(i,!1),l.sortAngle=d(r,!0)}return{point:s,fraction:r}}static collectSignedLoop(t,e,n=1e-10,i){let s=i?0:ot.computeXYArea(t);return s===void 0&&(s=0),Math.abs(s)<n&&(s=0),t.computedAreaInPlanarSubdivision=s,s>0?e.positiveAreaLoops.push(t):s<0?e.negativeAreaLoops.push(t):e.slivers.push(t),s}static extractGeometryFromEdge(t){if(t.sortData!==void 0&&t.edgeTag&&t.edgeTag instanceof Y){const e=t.edgeTag;if(e.curve&&e.fraction1!==void 0){const n=t.sortData<0;return{detail:e,reversed:n}}}}static createCurveInEdge(t,e){let n;const i=this.extractGeometryFromEdge(t);if(i&&i.detail.curve&&i.detail.isInterval()){const s=i.reversed?i.detail.fraction1:i.detail.fraction,r=i.reversed?i.detail.fraction:i.detail.fraction1;n=i.detail.curve.clonePartialCurve(s,r),n&&e!==void 0&&n.tryTransformInPlace(X.createRowValues(1,0,0,0,0,1,0,0,0,0,0,e))}return n}static createLoopInFace(t,e){const n=e?.announceEdge?!1:e?.compress??!1,i=tt.create(),s=r=>{const o=this.createCurveInEdge(r,e?.z);o&&(e?.announceEdge?.(r,o,i),i.tryAddChild(o))};if(Array.isArray(t)?t.forEach(s):t.announceEdgesInFace(s),n&&ot.consolidateAdjacentPrimitives(i,{consolidateLoopSeam:!0}),i.isPhysicallyClosedCurve(e?.closureTol,!0))return i}static createLoopOrParityRegionInFace(t,e){let n;const i=e?.visitMask??M.VISITED,s=e?.bridgeMask??M.BRIDGE_EDGE;let r;if(t.isSplitWasherFace(s)&&(r=t.findMaskAroundFace(s,!0))){const o=[],a=[],c=[r],l=g=>{g.setMask(i),a.push(g)},d=g=>{g.isMaskSet(i)||c.push(g)};t.clearMaskAroundFace(i);let h;for(;(h=c.pop())!==void 0;){h.setMask(i);const g=h.findMaskAroundFace(s,!1);if(g){if(g.isMaskSet(i))continue;if(a.length=0,g.announceEdgesInSuperFace(s,l,d)){const m=this.createLoopInFace(a,e);if(m){o.push(m);continue}}}}n=ot.sortOuterAndHoleLoopsXY(o),n=ot.simplifyRegion(n)}else n=this.createLoopInFace(t,e);return n&&(n instanceof tt||n instanceof Wt)?n:void 0}static isNullFace(t){const e=t.faceSuccessor.faceSuccessor===t;let n=!1;if(e){const i=Je.curvatureSortKey(t),s=Je.curvatureSortKey(t.faceSuccessor.edgeMate);f.isSameCoordinate(i,s)||(n=!0)}return e&&!n}static getNonNullEdgeMate(t,e){if(this.isNullFace(e))return;let n=e.edgeMate;for(;this.isNullFace(n);)if(n=n.faceSuccessor.edgeMate,n===e)return;return n}static collectSignedLoopSetsInHalfEdgeGraph(t,e=f.smallMetricDistance,n=1e-10){const i=On.collectConnectedComponentsWithExteriorParityMasks(t,void 0),s=[],r=new Map;for(const o of i){const a={positiveAreaLoops:[],negativeAreaLoops:[],slivers:[]},c=[];for(const l of o){const d=this.isNullFace(l),h=d?void 0:(m,p,x)=>{const _=this.getNonNullEdgeMate(t,m);if(_!==void 0){const I=r.get(_);if(I===void 0){const v=new oa(x,p,void 0,void 0);r.set(m,v)}else I instanceof oa&&(I.setB(x,p),c.push(I),r.delete(_))}},g=this.createLoopInFace(l,{announceEdge:h,closureTol:e});g&&this.collectSignedLoop(g,a,n,d)}a.edges=c,s.push(a),r.clear()}return s}}class ka extends Ys{_activeMomentData;_point0=y.create();_point1=y.create();handleArc3d(t){const e=this._activeMomentData;if(e===void 0)return;const n=t.sweep.sweepRadians,i=n*.5;let s=Math.sin(i),r=Math.cos(i),o=Math.sin(n);A.isFullCircleRadians(n)&&(s=0,r=-1,o=0);const a=2*s*s*s*r/(i-s*r),c=s*s*s,l=c*c,d=.5*(n-o),h=.25*d*(1-a/3),p=.25*d*(1+a)-4*l/(9*d),x=h,_=4*s*s*s/(3*(n-o)),I=t.sweep.fractionToRadians(.5),v=t.radiansToRotatedBasis(I),S=v.origin.plusScaled(v.vectorU,_);e.accumulateXYProductsInCentroidalFrame(p,0,x,d,S,v.vectorU,v.vectorV);const w=t.fractionToPoint(0),T=t.fractionToPoint(1);e.accumulateTriangleMomentsXY(void 0,w,T)}handleLineString3d(t){const e=this._activeMomentData;e!==void 0&&e.accumulateTriangleToLineStringMomentsXY(void 0,t.packedPoints)}handleLineSegment3d(t){const e=this._activeMomentData;e!==void 0&&(t.startPoint(this._point0),t.endPoint(this._point1),e.accumulateTriangleMomentsXY(void 0,this._point0,this._point1))}handleLoop(t){const e=this._activeMomentData=Dt.create();e.needOrigin=!1;for(const n of t.children)n.dispatchToGeometryHandler(this);return this._activeMomentData=void 0,e}handleAnyRegion(t){const e=ot.regionBooleanXY(t,void 0,Ze.Union);if(!e)return;if(e instanceof tt)return this.handleLoop(e);const n=Dt.create();for(const i of e.children){const s=i.dispatchToGeometryHandler(this);if(s){const r=e instanceof Wt&&s.quantitySum<0?-1:1,o=s.signFactor(r);n.accumulateProducts(s,o)}}return n}handleParityRegion(t){return this.handleAnyRegion(t)}handleUnionRegion(t){return this.handleAnyRegion(t)}_strokeOptions;getStrokeOptions(){if(this._strokeOptions)return this._strokeOptions;const t=Zt.createForCurves();return t.angleTol=A.createDegrees(5),this._strokeOptions=t,t}handleCurvePrimitive(t){const e=F.create(),n=this.getStrokeOptions();t.emitStrokes(e,n),this.handleLineString3d(e)}handleBSplineCurve3d(t){this.handleCurvePrimitive(t)}handleBSplineCurve3dH(t){this.handleCurvePrimitive(t)}handleTransitionSpiral(t){this.handleCurvePrimitive(t)}}var Ze;(function(u){u[u.Union=0]="Union",u[u.Parity=1]="Parity",u[u.Intersection=2]="Intersection",u[u.AMinusB=3]="AMinusB",u[u.BMinusA=4]="BMinusA"})(Ze||(Ze={}));class ot{static computeXYAreaMoments(t){const e=new ka,n=t.dispatchToGeometryHandler(e);if(n instanceof Dt)return n.shiftOriginAndSumsToCentroidOfSums(),n}static computeXYAreaTolerance(t,e=f.smallMetricDistance){if(e===0)return f.smallFloatingPoint*10;const n=.5*Math.abs(e);return n*(t.xLength()+t.yLength()+n)}static computeMinimumArea(t=f.smallMetricDistance){const e=Math.PI*t*t,n=f.smallFloatingPoint*10;return e<n?n:e}static computeXYArea(t){const e=new ka,n=t.dispatchToGeometryHandler(e);if(n instanceof Dt)return n.quantitySum}static computeXYZWireMomentSums(t){const e=new Qc;e.visitLeaves(t);const n=e.momentData;return n.shiftOriginAndSumsToCentroidOfSums(),n}static centroidAreaNormal(t,e){const n=Qt.createRightHandedFrame(void 0,t);if(!n)return;const i=n.matrix.columnZ(e?.direction),s=i.isParallelTo(P.unitZ(),!0);let r=t;if(!s){const l=n.inverse();r=t.cloneTransformed(l)}const o=ot.computeXYAreaMoments(r);if(!o)return;const a=o.origin.clone(e?.origin);s?n.origin.z!==0&&(a.z+=n.origin.z):n.multiplyPoint3d(a,a);let c=o.sums.weight();return c<0&&(c=-c,i.scale(-1,i)),e||(e=O.createCapture(a,i)),e.a=c,e}static addLoopsToGraph(t,e,n){if(e instanceof tt){const i=e.getPackedStrokes();i&&this.addLoopsToGraph(t,i,n)}else if(e instanceof Wt)for(const i of e.children){const s=i.getPackedStrokes();s&&this.addLoopsToGraph(t,s,n)}else if(e instanceof le){const i=B.directCreateFaceLoopFromCoordinates(t,e);i!==void 0&&n(t,i)}else if(Array.isArray(e)&&e.length>0)if(y.isAnyImmediatePointType(e[0])){const i=B.directCreateFaceLoopFromCoordinates(t,e);i!==void 0&&n(t,i)}else if(e[0]instanceof le)for(const i of e){const s=B.directCreateFaceLoopFromCoordinates(t,i);s!==void 0&&n(t,s)}else for(const i of e)Array.isArray(i)&&this.addLoopsToGraph(t,i,n)}static addLoopsWithEdgeTagToGraph(t,e,n,i){const s=[];if(this.addLoopsToGraph(t,e,(r,o)=>{o&&(s.push(o),o.setMaskAndEdgeTagAroundFace(n,i,!0))}),s.length>0)return s}static finishGraphToPolyface(t,e){if(t)return e&&(B.triangulateAllPositiveAreaFaces(t),B.flipTriangles(t)),it.graphToPolyface(t)}static polygonXYAreaIntersectLoopsToPolyface(t,e,n=!1){const i=vi.doPolygonBoolean(t,e,(s,r)=>s&&r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static polygonXYAreaUnionLoopsToPolyface(t,e,n=!1){const i=vi.doPolygonBoolean(t,e,(s,r)=>s||r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static polygonXYAreaDifferenceLoopsToPolyface(t,e,n=!1){const i=vi.doPolygonBoolean(t,e,(s,r)=>s&&!r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static simplifyRegionType(t){if(t instanceof ve){if(t.children.length===1)return this.simplifyRegionType(t.children[0])}else if(t instanceof Wt&&t.children.length===1)return t.children[0];return t}static simplifyRegion(t){if(t instanceof tt)return t.children.length>0?t:void 0;for(let e=0;e<t.children.length;++e){const n=t.children[e],i=this.simplifyRegion(n);i?i!==n&&t.children.splice(e--,1,i):t.children.splice(e--,1)}if(t.children.length!==0)return t.children.length===1?t.children.splice(0,1)[0]:t}static getZCoordinate(t){const e=Qt.createRightHandedFrame(void 0,t);return e?e.origin.z:0}static convertToRegionGroupOpType(t){return Ze.Parity===t?ue.Parity:Ze.Intersection===t?ue.Intersection:ue.Union}static regionBooleanXY(t,e,n,i=f.smallMetricDistance){const s=typeof i=="number",r=s?i:i.mergeTolerance??f.smallMetricDistance,o=s?!1:i.simplifyUnion??!1,a=s?ue.Union:ot.convertToRegionGroupOpType(i.operationGroupA),c=s?ue.Union:ot.convertToRegionGroupOpType(i.operationGroupB);let l;const d=Wn.create(a,c);d.addMembers(t,e),d.annotateAndMergeCurvesInGraph(r);const h=M.BRIDGE_EDGE,g=d.graph.grabMask(!1),m=o?d.graph.grabMask(!1):M.NULL_MASK,p=o?[]:void 0;d.graph.clearMask(g|m);const x=this.computeMinimumArea(r),_=ot.getZCoordinate(n===Ze.BMinusA?e:t),I={compress:!0,closureTol:r,bridgeMask:h,visitMask:g,z:_};let v=0;if(d.runClassificationSweep(n,(S,w,T,R)=>{if(!(w.countEdgesAroundFace()<2)&&!(Math.abs(R)<x)){if(o)T===1?v++:(w.setMaskAroundFace(m),p?.push(w));else if(T===1){const L=os.createLoopOrParityRegionInFace(w,I);L&&(l||(l=ve.create()),l.tryAddChild(L)&&v++)}}}),o&&v>0&&p&&p.length>0){d.graph.clearMask(g);const S=[];for(const w of p){const T=[],R=z=>z.isMaskSet(g)||!z.isMaskSet(m)||z.edgeMate.isMaskSet(m),L=z=>T.push(z);if(w.announceEdgesInSuperFace(R,L)){T.forEach(K=>K.setMask(g));const z=os.createLoopInFace(T,I);z&&S.push(z)}}l=this.sortOuterAndHoleLoopsXY(S)}return d.graph.dropMask(g|m),l?this.simplifyRegion(l):void 0}static polygonBooleanXYToPolyface(t,e,n,i=!1){const s=vi.doBinaryBooleanBetweenMultiLoopInputs(t,ue.Union,e,n,ue.Union,!0);return this.finishGraphToPolyface(s,i)}static polygonBooleanXYToLoops(t,e,n){const i=vi.doBinaryBooleanBetweenMultiLoopInputs(t,ue.Union,e,n,ue.Union,!0);if(!i)return;const s=On.collectExtendedBoundaryLoopsInGraph(i,M.EXTERIOR),r=[];for(const o of s){const a=new W;for(const l of o)a.pushXYZ(l.x,l.y,l.z);a.pushWrap(1);const c=tt.create();c.tryAddChild(F.createCapture(a)),r.push(c)}return ot.sortOuterAndHoleLoopsXY(r)}static constructPolygonWireXYOffset(t,e,n){return new dr().constructPolygonWireXYOffset(t,e,n)}static constructCurveXYOffset(t,e){const n=Oe.create(e);return Gn.constructCurveXYOffset(t,n)}static testPointInOnOutRegionXY(t,e,n){return jc.testPointInOnOutRegionXY(t,e,n)}static createLoopPathOrBagOfCurves(t,e=!0,n=!1){const i=t.length;if(i===0)return;let s=0,r=!1;e&&(s=f.maxXY(s,t[0].startPoint().distance(t[i-1].endPoint())));for(let a=0;a+1<i;a++)s=f.maxXY(s,t[a].endPoint().distance(t[a+1].startPoint()));let o;f.isSmallMetricDistance(s)?(o=e?tt.create():Pt.create(),r=!0):o=Ee.create();for(const a of t)o.tryAddChild(a);return r&&n&&ot.consolidateAdjacentPrimitives(o),o}static _graphCheckPointFunction;static setCheckPointFunction(t){this._graphCheckPointFunction=t}static cloneCurvesWithXYSplits(t,e){return ur.cloneCurvesWithXYSplits(t,e)}static splitToPathsBetweenBreaks(t,e){if(t===void 0)return;if(t instanceof st)return t;const n=t.collectCurvePrimitives(),i=new pe(e);for(const s of n)i.announceCurvePrimitive(s);return i.grabResult()}static collectInsideAndOutsideOffsets(t,e,n){return Gn.collectInsideAndOutsideXYOffsets(t,e,n)}static collectChains(t,e=f.smallMetricDistance){return Gn.collectChains(t,e)}static splitPathsByRegionInOnOutXY(t,e){const n={insideParts:[],outsideParts:[],coincidentParts:[]},i=ot.cloneCurvesWithXYSplits(t,e),s=ot.splitToPathsBetweenBreaks(i,!0);if(s instanceof ut)for(const r of s.children){const o=ut.createCurveLocationDetailOnAnyCurvePrimitive(r);if(o){const a=ot.testPointInOnOutRegionXY(e,o.point.x,o.point.y);Fa(r,a,n.outsideParts,n.coincidentParts,n.insideParts)}}else if(s instanceof st){const r=ut.createCurveLocationDetailOnAnyCurvePrimitive(s);if(r){const o=ot.testPointInOnOutRegionXY(e,r.point.x,r.point.y);Fa(s,o,n.outsideParts,n.coincidentParts,n.insideParts)}}return n}static rectangleEdgeTransform(t,e=!0){if(t instanceof F)return this.rectangleEdgeTransform(t.packedPoints);if(t instanceof le){let n;if(e&&t.length===5){if(!t.almostEqualUncheckedIndexIndex(0,4))return;n=t}else if(!e&&t.length===4)n=t;else{if(t.length<(e?5:4))return;if(n=W.create(t),te.compressInPlaceByShortEdgeLength(n,f.smallMetricDistance),n.length<(e?5:4))return}n.length>=4;const i=n.vectorUncheckedIndexIndex(0,1),s=n.vectorUncheckedIndexIndex(0,3),r=n.vectorUncheckedIndexIndex(1,2),o=i.crossProduct(s);if(o.normalizeInPlace()&&r.isAlmostEqual(s)&&i.isPerpendicularTo(s))return X.createOriginAndMatrixColumns(n.getPoint3dAtUncheckedPointIndex(0),i,s,o)}else{if(Array.isArray(t))return this.rectangleEdgeTransform(new Bt(t),e);if(t instanceof tt&&t.children.length===1&&t.children[0]instanceof F)return this.rectangleEdgeTransform(t.children[0].packedPoints,!0);if(t instanceof Pt&&t.children.length===1&&t.children[0]instanceof F)return this.rectangleEdgeTransform(t.children[0].packedPoints,e);if(t instanceof de&&!t.checkForNonLinearPrimitives()){const n=t.getPackedStrokes();if(n)return this.rectangleEdgeTransform(n)}}}static consolidateAdjacentPrimitives(t,e){const n=new $c(e);t.dispatchToGeometryHandler(n)}static sortOuterAndHoleLoopsXY(t){const e=[];for(const n of t)if(n instanceof tt)ei.pushLoop(e,n);else if(n instanceof le){const i=tt.createPolygon(n);ei.pushLoop(e,i)}return ei.sortAsAnyRegion(e)}static getEdgeGeometry(t,e){let n=!1,i=!1,s=!1,r=!1;return t.edgeTag instanceof Y&&t.edgeTag.curve!==void 0&&t.edgeTag.isInterval()&&t.sortData&&e.edgeTag instanceof Y&&e.edgeTag.curve!==void 0&&e.edgeTag.isInterval()&&e.sortData&&(n=t.edgeTag.curve===e.edgeTag.curve||t.edgeTag.curve.isAlmostEqual(e.edgeTag.curve),i=!n&&t.edgeTag.curve.isAlmostEqual(e.edgeTag.curve.clone().reverse()),s=t.sortData>0,r=e.sortData>0),{sameCurves:n,reversedCurves:i,senseEdge0:s,senseEdge1:r}}static areEdgesDiametric(t,e){let n=!1,i=!1,s=!1,r=!1;if(t!==e){const o=ot.getEdgeGeometry(t,e);i=o.reversedCurves,s=o.senseEdge0,r=o.senseEdge1,n=o.sameCurves&&s!==r||i&&s===r}return{diametric:n,reversedCurves:i,senseEdge0:s,senseEdge1:r}}static isHealableEdgeOrNullFace(t,e){if(e){if(!t.findAroundVertex(e))return!1}else if(e=t.vertexSuccessor,e.vertexSuccessor!==t)return!1;const n=ot.areEdgesDiametric(t,e);if(!n.diametric)return!1;const i=n.senseEdge0?t.edgeTag.fraction:t.edgeTag.fraction1;let s=n.senseEdge1?e.edgeTag.fraction:e.edgeTag.fraction1;return n.reversedCurves&&(s=1-s),f.isSmallRelative(i-s)}static isHealableNullFaceBundle(t){const e=[],n=[],i=a=>{const c=a.faceSuccessor;return c.faceSuccessor===a&&ot.areEdgesDiametric(a,c).diametric};t.announceEdgesAroundVertex(a=>{i(a)||e.push(n.length),n.push(a)});const s=n.length;if(s<4||e.length!==2||f.modulo(s,2)>0)return{isHealable:!1};const r=e[0];if(e[1]-r!==s/2)return{isHealable:!1};const o=[];for(let a=1;a<s/2;a++){const c=f.modulo(r+a,s),l=f.modulo(2*r-c,s);if(!ot.isHealableEdgeOrNullFace(n[c],n[l]))return{isHealable:!1};o.push([n[c],n[l]])}return{isHealable:!0,nullFacePairs:o}}static healSplitEdgeAndCurve(t){const e=t.vertexSuccessor,n=V.healEdge(t,!1);if(!n)return;const i=(s,r)=>{const o=ot.getEdgeGeometry(s,r);o.sameCurves||o.reversedCurves;let a=o.senseEdge0?s.edgeTag.fraction1:s.edgeTag.fraction;o.reversedCurves&&(a=1-a);const c=o.senseEdge0?s.edgeTag.point1:s.edgeTag.point;o.senseEdge1?r.edgeTag.captureFraction1Point1(a,c):r.edgeTag.captureFractionPoint(a,c)};i(t,n),i(e,n.edgeMate)}static isolateExtraneousBridgeEdges(t,e,n){const i=[],s=[],r=c=>{c.isDangling||i.push(c.vertexSuccessor),c.edgeMate.isDangling||i.push(c.edgeMate.vertexSuccessor),c.isolateEdge()};t.announceEdges((c,l)=>(e(l)&&(l.isDangling||l.edgeMate.isDangling||!l.findAroundFace(l.edgeMate)||n(l)<0?r(l):s.push(l)),!0));const o=c=>c.isIsolatedEdge?!1:n(c)<0?!0:c.findAroundFace(c.edgeMate)?!1:n(c.edgeMate)<0;let a;do{a=0;for(const c of s)o(c)&&(r(c),a++)}while(a>0);return i.filter(c=>!c.isIsolatedEdge)}static removeExtraneousBridgeEdges(t,e,n){n||(n=s=>On.signedFaceArea(s)),e||(e=s=>s.isMaskSet(M.BRIDGE_EDGE));const i=ot.isolateExtraneousBridgeEdges(t,e,n);for(const s of i){if(s.isDangling||s.isIsolatedEdge)continue;if(ot.isHealableEdgeOrNullFace(s)){ot.healSplitEdgeAndCurve(s);continue}const r=ot.isHealableNullFaceBundle(s);if(r.isHealable&&r.nullFacePairs){for(const[o,a]of r.nullFacePairs)V.pinch(o,a);for(const[o,a]of r.nullFacePairs)ot.healSplitEdgeAndCurve(o),ot.healSplitEdgeAndCurve(a)}}return t.deleteIsolatedEdges()}static collectRegionsAndClosedPrimitives(t,e,n=f.smallMetricDistance){const i=[];Array.isArray(t)||(t=[t]);for(const s of t)s instanceof tt||s instanceof Wt||s instanceof ve?i.push(s):s instanceof Pt&&s.isPhysicallyClosedCurve(n)?i.push(tt.create(...s.children)):s instanceof st&&s.isPhysicallyClosedCurve(n)?i.push(tt.create(s)):e&&e.push(s);return i}static constructAllXYRegionLoops(t,e=f.smallMetricDistance,n=!0){e=Ae.scaleToleranceForGeometry(t,e,{xyOnly:!0});let i=ot.collectCurvePrimitives(t,void 0,!0,!0);i=hr.clone(Ee.create(...i)).children;let s=!1;if(n){const l=Wn.create(ue.Union,ue.Union),d=[],h=this.collectRegionsAndClosedPrimitives(t,d,e);s=d.length>0,h.length>0&&(l.addMembers(h,void 0),l.annotateAndMergeCurvesInGraph(e),l.graph.announceEdges((g,m)=>{if(m.isMaskSet(M.BRIDGE_EDGE)){const p=U.create(m.getPoint3d(),m.faceSuccessor.getPoint3d());p.parent=new oi(p,l.extraGeometry),i.push(p)}return!0}))}const r=1e4*f.smallAngleRadians,o=He.allIntersectionsAmongPrimitivesXY(i,e),a=os.assembleHalfEdgeGraph(i,o,e,r);n&&s&&ot.removeExtraneousBridgeEdges(a);const c=this.computeMinimumArea(e);return os.collectSignedLoopSetsInHalfEdgeGraph(a,e,c)}static collectCurvePrimitives(t,e,n=!1,i=!1){const s=e===void 0?[]:e;if(t instanceof st)t.collectCurvePrimitives(s,n,i);else if(t instanceof ut)t.collectCurvePrimitives(s,n,i);else if(Array.isArray(t))for(const r of t)this.collectCurvePrimitives(r,s,n,i);return s}static expandLineStrings(t){const e=[];for(const n of t)if(n instanceof F)for(let i=0;i+1<n.packedPoints.length;i++){const s=n.getIndexedSegment(i);s!==void 0&&e.push(s)}else e.push(n);return e}static curveArrayRange(t,e){const n=J.create();if(t instanceof Ae)t.extendRange(n,e);else if(Array.isArray(t))for(const i of t)i instanceof Ae?i.extendRange(n,e):i instanceof y?n.extendPoint(i,e):i instanceof W?n.extendRange(i.getRange(e)):Array.isArray(i)&&n.extendRange(this.curveArrayRange(i,e));return n}static triangulateStrokedRegionComponent(t){let e;if(Array.isArray(t)){if(t.length===0)return;const n=t[0];if(y.isAnyImmediatePointType(n))e=B.createTriangulatedGraphFromSingleLoop(t);else if(t.length>1){let i;if(n instanceof Ts)i=t;else{i=[];for(const r of t)i.push(W.create(r))}const s=nt.sortOuterAndHoleLoopsXY(i);s.length===1&&(e=B.createTriangulatedGraphFromLoops(s[0]))&&B.flipTriangles(e)}else e=B.createTriangulatedGraphFromSingleLoop(n)}else e=B.createTriangulatedGraphFromSingleLoop(t);return e||(e=vi.doPolygonBoolean(t,[],(n,i)=>n))&&B.triangulateAllPositiveAreaFaces(e)&&B.flipTriangles(e),e}static strokeRegionComponent(t,e){const n=t.cloneStroked(e),i=[];if(n instanceof tt)n.children.length>0&&n.children[0]instanceof F&&i.push(n.children[0].packedPoints);else if(n instanceof Wt)for(const s of n.children)s.children.length>0&&s.children[0]instanceof F&&i.push(s.children[0].packedPoints);return i}static triangulateRegionComponent(t,e){const n=this.strokeRegionComponent(t,e);return this.triangulateStrokedRegionComponent(n)}static facetRegionXY(t,e){let n;if(t instanceof ve)for(const i of t.children){const s=ot.triangulateRegionComponent(i,e);s&&(n?n.allHalfEdges.push(...s.allHalfEdges):n=s)}else n=this.triangulateRegionComponent(t,e);if(n)return e?.maximizeConvexFacets&&Vt.expandConvexFaces(n),it.graphToPolyface(n,e)}static convexDecomposePolygonXY(t,e=!0){const n=ot.triangulateStrokedRegionComponent(t);if(!n)return;e&&Vt.expandConvexFaces(n);const i=[];return n.announceFaceLoops((s,r)=>(r.isMaskSet(M.EXTERIOR)||i.push(W.create(r.collectAroundFace(o=>o.getPoint3d()))),!0)),i}}function Fa(u,t,e,n,i){t>0?i.push(u):t<0?e.push(u):n.push(u)}class xe{_chains;_gapTolerance;_planeTolerance;static _staticPointA;static _staticPointB;_xyzWork0;_xyzWork1;constructor(t=f.smallMetricDistance,e){this._chains=[],this._gapTolerance=t,this._planeTolerance=e}findAnyChainToConnect(t,e=-1){for(let n=0;n<this._chains.length;n++){if(e===n)continue;const i=this._chains[n];if(this._xyzWork1=i[i.length-1].endPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(t,this._gapTolerance))return{chainIndex:n,atEnd:!0};if(this._xyzWork1=i[0].startPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(t,this._gapTolerance))return{chainIndex:n,atEnd:!1}}}captureCurvePrimitive(t){this.attachPrimitiveToAnyChain(t)||this._chains.push([t])}captureCurve(t){if(t instanceof st)this.captureCurvePrimitive(t);else if(t instanceof ut)for(const e of t.children)this.captureCurve(e)}simpleEndPointMove(t,e,n){if(t instanceof U)return e?t.point1Ref.setFrom(n):t.point0Ref.setFrom(n),!0;if(t instanceof F&&t.numPoints()>0){const i=e?t.numPoints()-1:0;return t.packedPoints.setAtCheckedPointIndex(i,n),!0}return!1}moveHeadOrTail(t,e){const n=t.endPoint(),i=e.startPoint(),s=f.smallMetricDistance*.001;let r=n.distanceSquaredXY(i);if(r<=s*s)return!1;const o=this._gapTolerance*this._gapTolerance;if(r>o)return!1;if(this.simpleEndPointMove(e,!1,n)||this.simpleEndPointMove(t,!0,i))return!0;if(!(t instanceof N&&e instanceof N))return!1;const a=He.intersectionXYPairs(t,!0,e,!0);let c=-1,l=1/0;for(let d=0;d<a.length;++d){const h=a[d].detailA.point.distanceSquaredXY(n),g=a[d].detailB.point.distanceSquaredXY(i);r=h+g,h<=o&&g<=o&&r<l&&(l=r,c=d)}if(c>=0){const d=t.sweep.fractionToRadians(a[c].detailA.fraction);t.sweep.setStartEndRadians(t.sweep.startRadians,d);const h=e.sweep.fractionToRadians(a[c].detailB.fraction);return e.sweep.setStartEndRadians(h,e.sweep.endRadians),!0}return!1}attachPrimitiveToAnyChain(t){if(t.curveLength()<this._gapTolerance)return!0;{this._xyzWork0=t.startPoint(this._xyzWork0);let e=this.findAnyChainToConnect(this._xyzWork0);if(e)if(e.atEnd){const n=this._chains[e.chainIndex],i=n.length-1;return this._chains[e.chainIndex].push(t),this.moveHeadOrTail(n[i],n[i+1]),this.searchAndMergeChainIndex(e.chainIndex),!0}else{t.reverseInPlace();const n=this._chains[e.chainIndex];return n.splice(0,0,t),this.moveHeadOrTail(n[0],n[1]),this.searchAndMergeChainIndex(e.chainIndex),!0}else if(this._xyzWork0=t.endPoint(this._xyzWork0),e=this.findAnyChainToConnect(this._xyzWork0),e)if(e.atEnd){t.reverseInPlace();const n=this._chains[e.chainIndex],i=n.length-1;return this._chains[e.chainIndex].push(t),this.moveHeadOrTail(n[i],n[i+1]),this.searchAndMergeChainIndex(e.chainIndex),!0}else{const n=this._chains[e.chainIndex];return n.splice(0,0,t),this.moveHeadOrTail(n[0],n[1]),this.searchAndMergeChainIndex(e.chainIndex),!0}}return!1}mergeChainsForwardForward(t,e){const n=this._chains[t],i=this._chains[e];for(const r of i)n.push(r);i.length=0;const s=this._chains.length-1;e!==s&&(this._chains[e]=this._chains[s]),this._chains.pop()}reverseChain(t){const e=this._chains[t];e.reverse();for(const n of e)n.reverseInPlace()}searchAndMergeChainIndex(t){const e=this._chains[t],n=e.length-1;this._xyzWork0=e[0].startPoint(this._xyzWork0);let i=this.findAnyChainToConnect(this._xyzWork0,t);if(i){i.atEnd||this.reverseChain(i.chainIndex),this.mergeChainsForwardForward(i.chainIndex,t);return}if(this._xyzWork0=e[n].endPoint(this._xyzWork0),i=this.findAnyChainToConnect(this._xyzWork0,t),i){i.atEnd&&this.reverseChain(i.chainIndex),this.mergeChainsForwardForward(t,i.chainIndex);return}}promoteArrayToCurves(t,e){if(t.length!==0){if(e){const n=t[0],i=t[t.length-1];if(xe._staticPointA=n.startPoint(xe._staticPointA),xe._staticPointB=i.endPoint(xe._staticPointB),this.moveHeadOrTail(i,n)&&(xe._staticPointA=n.startPoint(xe._staticPointA),xe._staticPointB=i.endPoint(xe._staticPointB)),xe._staticPointA.isAlmostEqual(xe._staticPointB,this._gapTolerance)){const s=Qt.createRightHandedLocalToWorld(t);if(s){const r=s.inverse();if(r){const o=ot.curveArrayRange(t,r);if(this._planeTolerance!==void 0&&o.zLength()<=this._planeTolerance)return tt.createArray(t)}}return Pt.createArray(t)}}return t.length===1?t[0]:Pt.createArray(t)}}chainToLineString3d(t,e){if(t.length===0)return;const n=F.create();for(const i of t)i.emitStrokes(n,e);return n.removeDuplicatePoints(this._gapTolerance),n}grabResult(t=!1){const e=this._chains;if(e.length===0)return;if(e.length===1)return this.promoteArrayToCurves(e[0],t);const n=Ee.create();for(const i of e){const s=this.promoteArrayToCurves(i,t);n.tryAddChild(s)}return n}announceChainsAsLineString3d(t,e){const n=this._chains;if(n.length===1){const i=this.chainToLineString3d(n[0],e);i&&t(i)}else if(n.length>1)for(const i of n){const s=this.chainToLineString3d(i,e);s&&t(s)}}}class Gn{static sumLengths(t){let e=0;if(t instanceof st)e+=t.curveLength();else if(t instanceof ut)e+=t.sumLengths();else if(Array.isArray(t))for(const n of t)e+=this.sumLengths(n);return e}static extendRange(t,e,n){if(Array.isArray(e))for(const i of e)this.extendRange(t,i,n);else e.extendRange(t,n);return t}static appendXYOffsets(t,e,n){let i=0;if(t instanceof st){const s=Ii.constructCurveXYOffset(Pt.create(t),e);s&&(i+=this.sumLengths(s),n.push(s))}else if(t instanceof tt||t instanceof Pt){const s=Ii.constructCurveXYOffset(t,e);s&&(i+=this.sumLengths(s),n.push(s))}else if(t instanceof Ee)for(const s of t.children)i+=this.appendXYOffsets(s,e,n);else if(Array.isArray(t))for(const s of t)i+=this.appendXYOffsets(s,e,n);return i}static collectInsideAndOutsideXYOffsets(t,e,n){const i=new xe(n,n);for(const l of t)i.captureCurve(l);const s=i.grabResult(!0),r=[],o=[],a=Gn.appendXYOffsets(s,e,r),c=Gn.appendXYOffsets(s,-e,o);return a>c?{outsideOffsets:r,insideOffsets:o,chains:s}:{insideOffsets:r,outsideOffsets:o,chains:s}}static constructCurveXYOffset(t,e){return Ii.constructCurveXYOffset(t,e)}static createSingleOffsetPrimitiveXY(t,e){return Ii.createSingleOffsetPrimitiveXY(t,e)}static collectChains(t,e=f.smallMetricDistance,n){const i=new xe(e,n);for(const s of t)i.captureCurve(s);return i.grabResult(!0)}static collectChainsAsLineString3d(t,e,n,i=f.smallMetricDistance,s){const r=new xe(i);for(const o of t)r.captureCurve(o);r.announceChainsAsLineString3d(e,n)}static computeLocalRange(t,e,n){const i=[t];if(n&&i.push(n),n=Qt.createRightHandedFrame(P.unitZ(),...i),!n)return!1;const s=n.inverse();return e.setNull(),Array.isArray(t)||!(t instanceof Ae)?J.createFromVariantData(t,s,e):this.extendRange(e,t,s),!0}static isPlanar(t,e){const n=J.create(),i=e?.localToWorld??X.createIdentity();if(!this.computeLocalRange(t,n,i))return;const s=e?.maxDeviation??f.smallMetricDistance;return n.zLength()<=Math.abs(s)?i:void 0}static isColinear(t,e){const n=J.create(),i=e?.localToWorld??X.createIdentity();if(!this.computeLocalRange(t,n,i))return;const s=Math.abs(e?.maxDeviation??f.smallMetricDistance);if(n.zLength()>s)return;const r=e?.colinearRay??O.createZero();r.origin.setFrom(i.origin);const o=n.xLength(),a=n.yLength();if(o<=s&&a<=s)return r.direction.setZero(),r;if(a<=s)return i.matrix.columnX(r.direction),r;if(o<=s)return i.matrix.columnY(r.direction),r;if(!e?.xyColinear)return;const c=Math.abs(e?.radianTolerance??f.smallAngleRadians);if(!(Math.abs(i.matrix.columnDotXYZ(ze.Z,0,0,1))>c))return o>a?i.matrix.columnX(r.direction):i.matrix.columnY(r.direction),r.direction.z=0,r}}class gn{static edgeLengthRange(t){const e=ct.createNull();for(let n=1;n<t.length;n++)e.extendX(t[n-1].distance(t[n]));return e}static compressByChordError(t,e=f.smallMetricDistance,n=!1){return te.compressPoint3dArrayByChordError(t,e,n)}static compressShortEdges(t,e){const n=W.create(t);return te.compressInPlaceByShortEdgeLength(n,e),n.getPoint3dArray()}static compressSmallTriangles(t,e){const n=W.create(t);return te.compressInPlaceBySmallTriangleArea(n,e),n.getPoint3dArray()}static compressByPerpendicularDistance(t,e,n=2){const i=W.create(t);let s=i.length;for(let r=0;r<n;r++){te.compressInPlaceByPerpendicularDistance(i,e);const o=i.length;if(o===s)break;s=o}return i.getPoint3dArray()}static squaredDistanceToInterpolatedPoint(t,e,n,i){const s=1-n,r=t.x-(s*e.x+n*i.x),o=t.y-(s*e.y+n*i.y),a=t.z-(s*e.z+n*i.z);return r*r+o*o+a*a}static isDanglerConfiguration(t,e,n,i,s){if(e<0||e>=t.length)return!1;const r=t[e],o=r.distanceSquared(i);if(o<=s)return!0;if(n<0||n>=t.length)return!1;const a=t[n],c=r.dotVectorsToTargets(a,i);if(c<=0)return!1;const l=r.distanceSquared(a);let d;if(o>=l){const h=c/o;d=this.squaredDistanceToInterpolatedPoint(a,r,h,i)}else{const h=c/l;d=this.squaredDistanceToInterpolatedPoint(i,r,h,a)}return d<s}static compressDanglers(t,e=!1,n=f.smallMetricDistance){let i=t.length;const s=n*n;if(e)for(;i>1&&t[i-1].distanceSquared(t[0])<=s;)i--;const r=[];r.push(t[0].clone());for(let o=1;o<i;o++){const a=t[o];for(;this.isDanglerConfiguration(r,r.length-1,r.length-2,a,s);)r.pop();r.push(a.clone())}if(e){let o=0,a=r.length-1;for(;a>o+2;)if(this.isDanglerConfiguration(r,o,o+1,r[a],s))o++;else if(this.isDanglerConfiguration(r,a,a-1,r[o],s))a--;else break;a+1<r.length&&(r.length=a+1),o>0&&r.splice(0,o)}return r}static addClosurePoint(t){if(t.length===0)return;const e=t[0];if(Array.isArray(e)){for(const i of t)Array.isArray(i)&&this.addClosurePoint(i);return}const n=t[t.length-1];e instanceof y&&n instanceof y&&!e.isAlmostEqual(n)&&t.push(e.clone())}static removeClosurePoint(t){if(t.length===0)return;const e=t[0];if(Array.isArray(e)){for(const i of t)Array.isArray(i)&&this.removeClosurePoint(i);return}const n=t[t.length-1];e instanceof y&&n instanceof y&&e.isAlmostEqual(n)&&t.pop()}static createBisectorPlanesForDistinctPoints(t,e=!1){const n=gn.compressShortEdges(t,f.smallMetricDistance);if(n.length<2)return;const i=[],s=n[0],r=n[1],o=P.createNormalizedStartEnd(s,r);if(!o)return;const a=ht.create(s,o),c=ht.createXYPlane();i.push(a.clone());for(let h=1;h+1<n.length;h++)if(P.createNormalizedStartEnd(n[h],n[h+1],o),ht.create(n[h],o,c)!==void 0){const g=a.getNormalRef().interpolate(.5,c.getNormalRef()),m=ht.create(n[h],g);m!==void 0&&i.push(m),a.setFrom(c)}const l=ht.create(n[n.length-1],a.getNormalRef());i.push(l);const d=i.length-1;if(d>0&&e){const h=i[0],g=i[d];if(f.isSamePoint3d(h.getOriginRef(),g.getOriginRef())){const m=h.getNormalRef().plus(g.getNormalRef()),p=ht.create(h.getOriginRef(),m);if(p!==void 0){i[0]=p;const x=ht.create(g.getOriginRef(),m);i[d]=x}}}return i.length>1?i:void 0}static _workSegmentA;static _workSegmentB;static _workLocalDetailPair;static closestApproach(t,e,n,i,s=Number.MAX_VALUE,r){Array.isArray(t)&&(t=new Bt(t)),Array.isArray(n)&&(n=new Bt(n));let o=s,a=!1;const c=t.length-1,l=n.length-1,d=[Ht.None,Ht.None],h=[Ht.None,Ht.None],g=(p,x,_,I)=>{p[0]=p[1]=Ht.None,_===0?p[0]=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(x,0):_===I-1&&(p[1]=Ut.resolveVariantCurveExtendParameterToCurveExtendMode(x,1))},m=(p,x,_)=>_===void 0?U.createCapture(p.getPoint3dAtUncheckedPointIndex(x),p.getPoint3dAtUncheckedPointIndex(x+1)):(p.getPoint3dAtUncheckedPointIndex(x,_.point0Ref),p.getPoint3dAtUncheckedPointIndex(x+1,_.point1Ref),_);for(let p=0;p<c;p++){this._workSegmentA=m(t,p,this._workSegmentA),g(d,e,p,c);for(let x=0;x<l;x++)if(this._workSegmentB=m(n,x,this._workSegmentB),g(h,i,x,l),(this._workLocalDetailPair=U.closestApproach(this._workSegmentA,d,this._workSegmentB,h,this._workLocalDetailPair))!==void 0){const _=this._workLocalDetailPair.detailA.a;if(_<o){const I=r?.detailA.childDetail,v=r?.detailB.childDetail;r=this._workLocalDetailPair.clone(r),F.convertLocalToGlobalDetail(r.detailA,p,c,void 0,I),F.convertLocalToGlobalDetail(r.detailB,x,l,void 0,v),r.detailA.childDetail&&r.detailB.childDetail&&(r.detailA.childDetail.curve=r.detailB.childDetail.curve=void 0),o=_,a=!0}}}return a?r:void 0}static isColinear(t,e=f.smallMetricDistance,n=!1){return t.length<3?!0:Gn.isColinear(t,{maxDeviation:e,xyColinear:n})!==void 0}}class en{point;a;v;code;closestEdgeIndex;closestEdgeParam;constructor(){this.point=new y,this.a=0,this.v=new P,this.code=yt.Unknown,this.closestEdgeIndex=0,this.closestEdgeParam=0}invalidate(){this.point.setZero(),this.a=0,this.v.setZero(),this.code=yt.Unknown,this.closestEdgeIndex=0,this.closestEdgeParam=0}static create(t){return t===void 0?t=new en:t.invalidate(),t}copyContentsFrom(t){this.point.setFrom(t.point),this.a=t.a,this.v.setFrom(t.v),this.code=t.code,this.closestEdgeIndex=t.closestEdgeIndex,this.closestEdgeParam=t.closestEdgeParam}get isValid(){return this.code!==yt.Unknown}get isInsideOrOn(){return this.code===yt.InsidePolygon||this.code===yt.OnPolygonVertex||this.code===yt.OnPolygonEdgeInterior||this.code===yt.InsidePolygonProjectsToVertex||this.code===yt.InsidePolygonProjectsToEdgeInterior}static createAtVertexOrEdge(t,e,n=0){const i=new en;return i.point.setFrom(t),i.closestEdgeIndex=e,i.closestEdgeParam=n,n=f.clamp(n,0,1),i.code=n>0&&n<1?yt.OnPolygonEdgeInterior:yt.OnPolygonVertex,i}}class fr{detailA;detailB;constructor(t,e){this.detailA=t||en.create(),this.detailB=e||en.create()}static create(t,e,n){return n?(n.detailA=t,n.detailB=e,n):new fr(t,e)}clone(t){return t=t||new fr,t.detailA.copyContentsFrom(this.detailA),t.detailB.copyContentsFrom(this.detailB),t}swapDetails(){const t=this.detailA;this.detailA=this.detailB,this.detailB=t}}class gr{xyz;edge;sortCoordinate0;sortCoordinate1;sortDelta;isNotch;constructor(t){this.xyz=t,this.edge=void 0,this.sortCoordinate0=this.sortCoordinate1=0,this.sortDelta=0,this.isNotch=!1}static createCaptureWithReturnEdge(t){const e=new gr(t);if(t.length>=2){const n=t.getPoint3dAtUncheckedPointIndex(0),i=t.getPoint3dAtUncheckedPointIndex(t.length-1);e.edge=O.createStartEnd(n,i)}return e}setSortCoordinates(t){if(!this.edge)return;this.sortDelta=this.edge.direction.dotProduct(t.direction);const e=t.dotProductToPoint(this.edge.origin);this.sortDelta>=0?(this.sortCoordinate0=e,this.sortCoordinate1=e+this.sortDelta):(this.sortCoordinate0=e+this.sortDelta,this.sortCoordinate1=e)}containsSortLimits(t){return t.sortCoordinate0>=this.sortCoordinate1||t.sortCoordinate0<=this.sortCoordinate0||t.sortCoordinate1<=this.sortCoordinate0||t.sortCoordinate1>=this.sortCoordinate1?0:this.sortDelta*t.sortDelta>0?1:-1}absorb(t){this.xyz.pushFromGrowableXYZArray(t.xyz),this.sortCoordinate0=t.sortCoordinate1}static sortFunction(t,e){return t.sortCoordinate0-e.sortCoordinate0>0?1:-1}}class rl{inputLoops;outputLoops;constructor(){this.inputLoops=[],this.outputLoops=[]}mostDistantPoint(t,e,n){let i=-1;n.setZero();let s;for(const r of this.inputLoops)r.xyz.front(e)&&(s=e.distanceSquared(t),s>i&&(i=s,n.setFromPoint3d(e))),r.xyz.back(e)&&(s=e.distanceSquared(t),s>i&&(i=s,n.setFromPoint3d(e)))}sortInputs(){if(this.inputLoops.length>0&&this.inputLoops[0].xyz.length>0){const t=this.inputLoops[0].xyz.getPoint3dAtUncheckedPointIndex(0),e=y.create(),n=y.create();this.mostDistantPoint(t,e,n),this.mostDistantPoint(n,e,t);const i=O.createStartEnd(t,n);i.direction.normalizeInPlace();for(const s of this.inputLoops)s.setSortCoordinates(i);this.inputLoops.sort((s,r)=>gr.sortFunction(s,r))}}sortAndMergeLoops(){this.sortInputs();const t=this.inputLoops,e=this.outputLoops,n=[];e.length=0;for(const i of t){for(i.isNotch=!1;n.length>0;){const s=n[n.length-1],r=s.containsSortLimits(i);if(r===0){s.isNotch||e.push(s),n.pop();continue}else if(r===1){i.isNotch=!1;break}else{s.absorb(i),i.isNotch=!0;break}}n.push(i)}for(const i of n)i.isNotch||e.push(i)}}class nt{static sumTriangleAreas(t){let e=0;const n=t.length;if(Array.isArray(t)){if(n>=3){const s=t[0],r=s.vectorTo(t[1]);let o=P.create();for(let a=2;a<n;a++)o=s.vectorTo(t[a],o),e+=r.crossProductMagnitude(o),r.setFrom(o)}return e*.5}const i=P.create();for(let s=2;s<n;s++)t.crossProductIndexIndexIndex(0,s-1,s,i),e+=i.magnitude();return e*.5}static sumTriangleAreasPerpendicularToUpVector(t,e){let n=e.magnitude();n<f.smallMetricDistance&&(e=P.create(0,0,1),n=1);let i=0;const s=t.length;if(Array.isArray(t)){if(s>=3){const o=t[0],a=o.vectorTo(t[1]);let c=P.create();for(let l=2;l<s;l++)c=o.vectorTo(t[l],c),i+=a.tripleProduct(c,e),a.setFrom(c)}return i*.5/n}const r=P.create();for(let o=2;o<s;o++)t.crossProductIndexIndexIndex(0,o-1,o,r),i+=r.dotProduct(e);return i*.5/n}static sumTriangleAreasXY(t){let e=0;const n=t.length;if(n>=3){const i=t[0],s=i.vectorTo(t[1]);let r=P.create();for(let o=2;o<n;o++)r=i.vectorTo(t[o],r),e+=s.crossProductXY(r),s.setFrom(r)}return e*=.5,e}static _triangleMomentWeights=pt.createRowValues(2/24,1/24,0,4/24,1/24,2/24,0,4/24,0,0,0,0,4/24,4/24,0,12/24);static _tetrahedralMomentWeights=pt.createRowValues(1/60,1/120,1/120,1/24,1/120,1/60,1/120,1/24,1/120,1/120,1/60,1/24,1/24,1/24,1/24,1/6);static _vector0=P.create();static _vector1=P.create();static _vector2=P.create();static _vectorOrigin=P.create();static _normal=P.create();static _matrixA=pt.createIdentity();static _matrixB=pt.createIdentity();static _matrixC=pt.createIdentity();static areaNormalGo(t,e){e?e.setZero():e=new P;const n=t.length;if(n===3)t.crossProductIndexIndexIndex(0,1,2,e);else if(n>3)for(let i=2;i<n;i++)t.accumulateCrossProductIndexIndexIndex(0,i-1,i,e);return e.scaleInPlace(.5),e.isZero?void 0:e}static areaNormal(t,e){return e||(e=P.create()),nt.areaNormalGo(new Bt(t),e),e}static area(t){return nt.areaNormal(t).magnitude()}static areaXY(t){let e=0;if(t instanceof le){if(t.length>2){const n=t.getXAtUncheckedPointIndex(0),i=t.getYAtUncheckedPointIndex(0);let s=t.getXAtUncheckedPointIndex(1)-n,r=t.getYAtUncheckedPointIndex(1)-i,o,a;for(let c=2;c<t.length;c++,s=o,r=a)o=t.getXAtUncheckedPointIndex(c)-n,a=t.getYAtUncheckedPointIndex(c)-i,e+=f.crossProductXYXY(s,r,o,a)}}else for(let n=1;n+1<t.length;n++)e+=t[0].crossProductToPointsXY(t[n],t[n+1]);return .5*e}static sumAreaXY(t){let e=0;for(const n of t)e+=this.areaXY(n);return e}static centroidAreaNormal(t,e){if(Array.isArray(t)){const i=new Bt(t);return this.centroidAreaNormal(i,e)}const n=t.length;if(n===3){const i=t.crossProductUncheckedIndexIndexIndex(0,1,2,e?.direction),s=.5*i.magnitude(),r=t.getPoint3dAtUncheckedPointIndex(0,e?.origin);return t.accumulateScaledXYZ(1,1,r),t.accumulateScaledXYZ(2,1,r),r.scaleInPlace(1/3),e||(e=O.createCapture(r,i)),e.tryNormalizeInPlaceWithAreaWeight(s)?e:void 0}if(n>=3){const i=P.createZero();for(let m=2;m<n;m++)t.accumulateCrossProductIndexIndexIndex(0,m-1,m,i);i.normalizeInPlace();const s=t.getPoint3dAtUncheckedPointIndex(0),r=P.create(),o=P.create();t.vectorXYAndZIndex(s,1,r);let a=P.create();const c=P.createZero(),l=P.createZero(e?.direction);let d;for(let m=2;m<n;m++){t.vectorXYAndZIndex(s,m,o),a=r.crossProduct(o,a),d=i.dotProduct(a),l.addInPlace(a);const p=d/6;c.plus2Scaled(r,p,o,p,c),r.setFrom(o)}const h=.5*l.magnitude(),g=f.conditionalDivideFraction(1,h);if(g!==void 0){const m=s.plusScaled(c,g,e?.origin);return e||(e=O.createCapture(m,l)),e.tryNormalizeInPlaceWithAreaWeight(h),e}}}static centroidAndAreaXY(t,e){let n=0;if(e.set(0,0),t.length<3)return;const i=t[0];let s=Q.create(0,0),r=0;for(let a=1;a+1<t.length;a++){const c=i.vectorTo(t[a]),l=i.vectorTo(t[a+1]),d=c.crossProduct(l);s=s.plus(c.plus(l).scale(d)),r+=d}n=r*.5;const o=f.conditionalDivideFraction(1,6*n);if(o===void 0){e.setFrom(i);return}return e.setFrom(i.plusScaled(s,o)),n}static unitNormal(t,e){e.setZero();let n=t.length;return n>1&&t.getPoint3dAtUncheckedPointIndex(0).isExactEqual(t.getPoint3dAtUncheckedPointIndex(n-1))&&--n,n===3?(t.crossProductIndexIndexIndex(0,1,2,e),e.normalizeInPlace()):n===4?(t.vectorIndexIndex(0,2,nt._vector0),t.vectorIndexIndex(1,3,nt._vector1),nt._vector0.crossProduct(nt._vector1,e),e.normalizeInPlace()):(nt.areaNormalGo(t,e),e.normalizeInPlace())}static addSecondMomentAreaProducts(t,e,n){this.addSecondMomentTransformedProducts(nt._triangleMomentWeights,t,e,2,n)}static addSecondMomentVolumeProducts(t,e,n){this.addSecondMomentTransformedProducts(nt._tetrahedralMomentWeights,t,e,3,n)}static addSecondMomentTransformedProducts(t,e,n,i,s){const r=nt._normal;if(nt.unitNormal(e,r)){const o=nt._vector0,a=nt._vector1,c=nt._vector2,l=nt._matrixA,d=nt._matrixB,h=nt._matrixC,g=e.vectorXYAndZUncheckedIndex(n,0,nt._vectorOrigin),m=e.length;let p=0;for(let x=2;x<m;x++)i===2?(e.vectorIndexIndex(0,x-1,o),e.vectorIndexIndex(0,x,a),p=r.tripleProduct(o,a),l.setOriginAndVectors(g,o,a,r),l.multiplyMatrixMatrix(t,d),d.multiplyMatrixMatrixTranspose(l,h),s.addScaledInPlace(h,p)):i===3&&(e.vectorXYAndZIndex(n,0,o),e.vectorXYAndZIndex(n,x-1,a),e.vectorXYAndZIndex(n,x,c),p=o.tripleProduct(a,c),l.setOriginAndVectors(n,o,a,c),l.multiplyMatrixMatrix(t,d),d.multiplyMatrixMatrixTranspose(l,h),s.addScaledInPlace(h,p))}}static volumeBetweenPolygonAndPlane(t,e,n){let i,s,r=0,o=0;if(t.length>=3){const a=t.evaluateUncheckedIndexPlaneAltitude(0,e);for(let c=1;c+1<t.length;c++){const l=t.crossProductUncheckedIndexIndexIndex(0,c,c+1,n?.workVector),d=t.evaluateUncheckedIndexPlaneAltitude(c,e),h=t.evaluateUncheckedIndexPlaneAltitude(c+1,e),g=l.dotProductXYZ(e.normalX(),e.normalY(),e.normalZ());r+=g,o+=g*(a+d+h)}n?.skipMoments||(i=t.getPoint3dAtUncheckedPointIndex(0,n?.workPoint0),s=pt.createZero(n?.workMatrix),t.mapPoint((c,l,d)=>e.projectXYZToPlane(c,l,d,n?.workPoint1)),nt.addSecondMomentAreaProducts(t,i,s))}return{volume6:o,area2:r,origin:i,products:s}}static testXYPolygonTurningDirections(t){let e=t.length,n=e-1;for(;n>1&&t[n].x===t[0].x&&t[n].y===t[0].y;)e=n--;if(e>2){let i=D.create(t[n].x-t[n-1].x,t[n].y-t[n-1].y);const s=D.create(t[0].x-t[n].x,t[0].y-t[n].y),r=i.x*s.y-i.y*s.x;for(let o=1;o<e;o++)if(i=s.clone(),D.create(t[o].x-t[o-1].x,t[o].y-t[o-1].y,s),(i.x*s.y-i.y*s.x)*r<=0)return 0;return r>0?1:-1}return 0}static isConvex(t){if(!(t instanceof le))return this.isConvex(new Bt(t));let e=t.length;e>1&&t.getPoint3dAtUncheckedPointIndex(0).isExactEqual(t.getPoint3dAtUncheckedPointIndex(e-1))&&--e;const n=P.create();if(!this.unitNormal(t,n))return!1;let i=0,s=0;const r=this._vector0;let o=P.createStartEnd(t.getPoint3dAtUncheckedPointIndex(e-1),t.getPoint3dAtUncheckedPointIndex(0),this._vector1);for(let a=1;a<=e;a++){r.setFromVector3d(o),o=P.createStartEnd(t.getPoint3dAtUncheckedPointIndex(a-1),t.getPoint3dAtUncheckedPointIndex(a%e),o);const c=n.tripleProduct(r,o);c>=0?i+=c:s+=c}return Math.abs(s)<f.smallMetricDistanceSquared*i}static classifyPointInPolygon(t,e,n){const i=new Qr(t,e);let s=0;const r=n.length;let o,a=-1;for(s=0;s<r;s++)if(o=s+1,o>=r&&(o=0),i.tryStartEdge(n[s].x,n[s].y,n[o].x,n[o].y)){a=o;break}if(!(a<0)){for(let c=1;c<=r;c++)if(o=a+c,o>=r&&(o-=r),!i.advance(n[o].x,n[o].y))return i.classifyCounts();return i.classifyCounts()}}static classifyPointInPolygonXY(t,e,n){const i=new Qr(t,e);let s=0;const r=n.length;let o,a=-1;for(s=0;s<r;s++)if(o=s+1,o>=r&&(o=0),i.tryStartEdge(n.getXAtUncheckedPointIndex(s),n.getYAtUncheckedPointIndex(s),n.getXAtUncheckedPointIndex(o),n.getYAtUncheckedPointIndex(o))){a=o;break}if(!(a<0)){for(let c=1;c<=r;c++)if(o=a+c,o>=r&&(o-=r),!i.advance(n.getXAtUncheckedPointIndex(o),n.getYAtUncheckedPointIndex(o)))return i.classifyCounts();return i.classifyCounts()}}static orientLoopsCCWForOutwardNormalInPlace(t,e){if(t instanceof le)return this.orientLoopsCCWForOutwardNormalInPlace([t],e);const n=P.create();let i=0;for(const s of t)this.unitNormal(s,n)&&n.dotProduct(e)<0&&(s.reverseInPlace(),i++);return i}static sortOuterAndHoleLoopsXY(t){const e=[];for(const n of t)ei.pushPolygon(e,n);return ei.sortAsArrayOfArrayOfPolygons(e)}static sortOuterAndHoleLoops(t,e){const n=Qt.createRightHandedFrame(e,t),i=n?.inverse(),s=[];if(i!==void 0)for(const a of t){const c=new W(a.length);for(const l of a.points)c.push(i.multiplyPoint3d(l));s.push(c)}const r=nt.sortOuterAndHoleLoopsXY(s),o=[];if(n!==void 0)for(const a of r){const c=[];for(const l of a){const d=new W(l.length);for(const h of l.points)d.push(n.multiplyPoint3d(h));c.push(d)}o.push(c)}return o}static closestPointOnBoundary(t,e,n=f.smallMetricDistance,i){if(!(t instanceof le))return this.closestPointOnBoundary(new Bt(t),e,n,i);const s=Array.isArray(n)?n[0]:n,r=Array.isArray(n)?Math.abs(n[1]):0,o=s*s;let a=t.length;for(;a>1&&!(t.distanceSquaredUncheckedIndexIndex(0,a-1)>o);)--a;if(i=en.create(i),a===0)return i;const c=m=>(t.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=i.point.distance(e),i.v.setZero(),i.code=yt.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i);if(a===1)return c(0);const l=m=>{let p=!1,x=0,_=0,I=0;if(m>=0&&m<a){let v=m+1;v===a&&(v=0),_=t.distanceSquaredUncheckedIndexIndex(m,v),_>o&&(I=t.distanceSquaredUncheckedIndexXYAndZ(m,e),x=t.dotProductUncheckedIndexIndexXYAndZ(m,v,e)/_,p=!0)}return{isValid:p,edgeParam:x,uDotU:_,vDotV:I}};let d=!1,h=a-1;for(;h>0;--h){const m=l(h);if(m.isValid){d=m.edgeParam>1+r;break}}if(h<=0)return c(0);let g=f.largeCoordinateResult;for(let m=0;m<a;++m){let p=m+1;p===a&&(p=0);const x=l(m);if(x.isValid){if(x.edgeParam<=r){const _=x.vDotV;if(_<=o)return t.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(_),i.v.setZero(),i.code=yt.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i;_<g&&d&&(t.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(_),t.crossProductUncheckedIndexIndexIndex(m,h,p,i.v),i.code=yt.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,g=_),d=!1}else if(x.edgeParam<=1+r){x.edgeParam=f.clamp(x.edgeParam,0,1);const _=x.vDotV-x.edgeParam*x.edgeParam*x.uDotU;if(_<=o){const I=x.vDotV;if(x.edgeParam<=.5&&I<=o)return t.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(I),i.v.setZero(),i.code=yt.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i;const v=_+(1-x.edgeParam)*(1-x.edgeParam)*x.uDotU;return x.edgeParam>.5&&v<=o?(t.getPoint3dAtUncheckedPointIndex(p,i.point),i.a=Math.sqrt(v),i.v.setZero(),i.code=yt.OnPolygonVertex,i.closestEdgeIndex=p,i.closestEdgeParam=0,i):(t.interpolateIndexIndex(m,x.edgeParam,p,i.point),i.a=Math.sqrt(_),i.v.setZero(),i.code=yt.OnPolygonEdgeInterior,i.closestEdgeIndex=m,i.closestEdgeParam=x.edgeParam,i)}_<g&&(t.interpolateIndexIndex(m,x.edgeParam,p,i.point),i.a=Math.sqrt(_),t.crossProductUncheckedIndexIndexXYAndZ(m,p,e,i.v),i.code=x.edgeParam<1?yt.OnPolygonEdgeInterior:yt.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=x.edgeParam,g=_),d=!1}else d=!0;h=m}}return i}static closestPoint(t,e,n=f.smallMetricDistance,i){if(!(t instanceof le))return this.closestPoint(new Bt(t),e,n,i);if(!this.unitNormal(t,this._normal))return en.create(i);const s=this._workPlane=ht.createXYZUVW(t.getXAtUncheckedPointIndex(0),t.getYAtUncheckedPointIndex(0),t.getZAtUncheckedPointIndex(0),this._normal.x,this._normal.y,this._normal.z,this._workPlane),r=this._workXYZ=s.projectPointToPlane(e,this._workXYZ);return i=this.closestPointOnBoundary(t,r,n,i),i.isValid&&(i.v.dotProduct(this._normal)>0&&(i.point.setFrom(r),yt.OnPolygonVertex===i.code?i.code=yt.InsidePolygonProjectsToVertex:yt.OnPolygonEdgeInterior===i.code&&(i.code=yt.InsidePolygonProjectsToEdgeInterior)),i.a=e.distance(i.point),i.v.setZero()),i}static _workXYZ;static _workXY0;static _workXY1;static _workXY2;static _workRay;static _workMatrix3d;static _workPlane;static intersectRay3d(t,e,n=f.smallMetricDistance,i){if(!(t instanceof le))return this.intersectRay3d(new Bt(t),e,n,i);if(!this.unitNormal(t,this._normal))return en.create(i);this._workPlane=ht.createXYZUVW(t.getXAtUncheckedPointIndex(0),t.getYAtUncheckedPointIndex(0),t.getZAtUncheckedPointIndex(0),this._normal.x,this._normal.y,this._normal.z,this._workPlane),this._workPlane;const s=this._workXYZ=y.createZero(this._workXYZ),r=e.intersectionWithPlane(this._workPlane,s);if(r===void 0)return en.create(i);if(i=this.closestPointOnBoundary(t,s,n,i),i.isValid){i.point.setFrom(s),i.a=r;const o=i.v.dotProduct(this._normal);o===0||(yt.OnPolygonVertex===i.code?i.code=o>0?yt.InsidePolygonProjectsToVertex:yt.OutsidePolygonProjectsToVertex:yt.OnPolygonEdgeInterior===i.code&&(i.code=o>0?yt.InsidePolygonProjectsToEdgeInterior:yt.OutsidePolygonProjectsToEdgeInterior))}return i}static intersectSegment(t,e,n,i=f.smallMetricDistance,s){return this._workRay=O.createStartEnd(e,n,this._workRay),this.intersectRay3d(t,this._workRay,i,s)}static computeEdgeDataXY(t,e,n,i,s=f.smallMetricDistance,r){const o=e%t.length,a=(o+1)%t.length;t.vectorUncheckedIndexIndex(o,a,i).unitPerpendicularXY(i).negate(i);const c=t.getXAtUncheckedPointIndex(o)-n.x,l=t.getYAtUncheckedPointIndex(o)-n.y;let d=f.dotProductXYXY(c,l,i.x,i.y);const h=f.crossProductXYXY(c,l,i.x,i.y),g=f.distanceXYXY(t.getXAtUncheckedPointIndex(o),t.getYAtUncheckedPointIndex(o),t.getXAtUncheckedPointIndex(a),t.getYAtUncheckedPointIndex(a));let m=f.safeDivideFraction(h,g,0);return f.isSameCoordinate(0,d,s)&&(d=0),f.isSameCoordinate(0,m,s)?m=0:f.isSameCoordinate(1,m,s)&&(m=1),D.create(d,m,r)}static convexBarycentricCoordinatesOnEdge(t,e,n,i,s,r,o,a){const c=!n.isZero&&i.x===0&&f.isIn01(i.y),l=!r.isZero&&o.x===0&&f.isIn01(o.y);if(c&&l)return a.fill(0),a[s]=1,a;const d=t.length;if(c){a.fill(0);const h=e,g=s,m=i.y;return a[h]=1-m,a[g]=m,a}if(l){a.fill(0);const h=s,g=(s+1)%d,m=o.y;return a[h]=1-m,a[g]=m,a}}static convexBarycentricCoordinates(t,e,n=f.smallMetricDistance){if(Array.isArray(t))return this.convexBarycentricCoordinates(new Bt(t),e);let i=t.length;for(;i>1&&t.getPoint3dAtUncheckedPointIndex(0).isExactEqual(t.getPoint3dAtUncheckedPointIndex(i-1));)--i;if(i<3||!nt.unitNormal(t,this._normal))return;const s=this._workMatrix3d=C.createRigidHeadsUp(this._normal,mt.ZXY,this._workMatrix3d),r=new W(i);for(let _=0;_<i;++_){const I=this._workXYZ=s.multiplyInverseXYZAsPoint3d(t.getXAtUncheckedPointIndex(_),t.getYAtUncheckedPointIndex(_),t.getZAtUncheckedPointIndex(_),this._workXYZ);r.push(I)}this._workXYZ;const o=s.multiplyInverseXYZAsPoint3d(e.x,e.y,e.z,this._workXYZ);let a=i-1;const c=this._vector0,l=this._workXY0=this.computeEdgeDataXY(r,a,o,c,n,this._workXY0);if(l.x<0)return;const d=P.createFrom(c,this._vector1),h=this._workXY1=D.createFrom(l,this._workXY1),g=Array(t.length).fill(0),m=n>0?1/(n*n):f.largeCoordinateResult;let p=0;for(let _=0;_<i;++_){const I=P.createFrom(c,this._vector2),v=this._workXY2=_<i-1?this.computeEdgeDataXY(r,_,o,I,n,this._workXY2):D.createFrom(l,this._workXY2);if(v.x<0)return;if(this.convexBarycentricCoordinatesOnEdge(r,a,d,h,_,I,v,g)!==void 0)return g;if(I.x===0&&I.y===0||h.x===0||v.x===0)continue;const S=Math.abs(d.crossProductXY(I)),w=f.conditionalDivideCoordinate(S,h.x*v.x,m);g[_]=w,p+=w,d.setFrom(I),h.setFrom(v),a=_}const x=f.conditionalDivideCoordinate(1,p);for(let _=0;_<i;++_)g[_]*=x;return g}static forceClosure(t,e=f.smallMetricDistance){t.length>=2&&(t instanceof W?t.forceClosure(e):t[0].distance(t[t.length-1])>e?t.push(t[0].clone()):t[t.length-1].setFromPoint3d(t[0]))}static ensureClosed(t,e=f.smallMetricDistance){if(t.length>=2){let n=!1;if(t instanceof le?n=!t.almostEqualIndexIndex(0,t.length-1,0):n=!t[0].isExactEqual(t[t.length-1]),n){const i=W.create(t);this.forceClosure(i,e),t=i}}return t}static _workCLDPair;static closestApproach(t,e,n=Number.MAX_VALUE,i=!1){let s;const r=this.ensureClosed(t),o=this.ensureClosed(e),a=this._workCLDPair=gn.closestApproach(r,!1,o,!1,n,this._workCLDPair);return a&&a.detailA.childDetail&&a.detailB.childDetail&&(s=fr.create(en.createAtVertexOrEdge(a.detailA.point,a.detailA.childDetail.a,a.detailA.childDetail.fraction),en.createAtVertexOrEdge(a.detailB.point,a.detailB.childDetail.a,a.detailB.childDetail.fraction)),s.detailA.a=s.detailB.a=a.detailA.a),s}}class nn{static _xyz0Work=y.create();static _xyz1Work=y.create();static _xyz2Work=y.create();static splitConvexPolygonInsideOutsidePlane(t,e,n,i,s){const r=nn._xyz0Work,o=nn._xyz1Work,a=nn._xyz2Work,c=e.length;n.clear(),i.clear();const l=1e-8;if(c>2){e.back(r);let d=t.altitude(r),h=0,g=0;s.setX(d);for(let m=0;m<c;m++)e.getPoint3dAtUncheckedPointIndex(m,o),h=t.altitude(o),s.extendX(h),d*h<0?(g=-d/(h-d),g>1-l?(n.push(o),i.push(o)):g<l?h>0?(n.push(r),n.push(o)):(i.push(r),i.push(o)):(r.interpolate(g,o,a),n.push(a),i.push(a),h>0?n.push(o):i.push(o))):(h>=0&&n.push(o),h<=0&&i.push(o)),r.setFromPoint3d(o),d=h}}static clipConvexPolygonInPlace(t,e,n,i=!0,s=f.smallMetricDistance){for(;e.length>1&&e.getPoint3dAtUncheckedPointIndex(0).isExactEqual(e.getPoint3dAtUncheckedPointIndex(e.length-1));)e.pop();const r=e.length;if(r<3)return e.clear(),0;const o=i?1:-1,a=x=>{const _=o*e.evaluateUncheckedIndexPlaneAltitude(x,t);return Math.abs(_)<s?0:_},c=1e-8;let l=0,d=0,h=0;const g=n||new W;g.clear();let m,p=a(r-1);for(let x=r-1,_=0;_<r;p=m,x=_++){if(m=a(_),m<0&&l++,p*m<0){const I=-p/(m-p);if(!(I>1-c&&m>0)){const v=e.interpolateUncheckedIndexIndex(x,I,_,this._xyz0Work);g.pushXYZ(v.x,v.y,v.z),d++}}m>=0&&(g.pushXYZ(e.getXAtUncheckedPointIndex(_),e.getYAtUncheckedPointIndex(_),e.getZAtUncheckedPointIndex(_)),m===0&&p!==0&&h++),x=_,p=m}return l>0&&(e.clear(),e.pushIndexedXYZCollection(g)),g.clear(),d+h}static polygonPlaneCrossings(t,e,n){if(n.length=0,e.length>=2){const i=this._xyz0Work;e.getPoint3dAtUncheckedPointIndex(e.length-1,i);let s=t.altitude(i);const r=this._xyz1Work;for(let o=0;o<e.length;o++){e.getPoint3dAtUncheckedPointIndex(o,r);const a=t.altitude(r);if(s*a<0){const c=-s/(a-s);n.push(i.interpolate(c,r))}a===0&&n.push(r.clone()),i.setFromPoint3d(r),s=a}}}static gatherCutLoopsFromPlaneClip(t,e,n=3,i=f.smallMetricDistance){const s=new rl;let r=0;const o=e.length;for(;r<o;r++){const c=e.evaluateUncheckedIndexPlaneAltitude(r,t);if(Math.abs(c)<=i)break}if(r===o)return s;let a=r;for(;a<o;){const c=new W;c.pushFromGrowableXYZArray(e,a);let l=a+1;for(;l<o;){c.pushFromGrowableXYZArray(e,l);const d=e.evaluateUncheckedIndexPlaneAltitude(l,t);if(Math.abs(d)<=i)break;l++}if(l===o)for(let d=0;d<=r;d++)c.pushFromGrowableXYZArray(e,d);c.length>=n&&s.inputLoops.push(gr.createCaptureWithReturnEdge(c)),a=l}return s}static reorderCutLoops(t){if(!(t.inputLoops.length<=1))if(t.inputLoops.length===2){const e=t.inputLoops[0].edge,n=t.inputLoops[1].edge;if(e&&n)if(e.direction.dotProduct(n.direction)>0)t.outputLoops.push(t.inputLoops[0]),t.outputLoops.push(t.inputLoops[1]);else{const i=t.inputLoops[1].xyz;t.inputLoops[0].xyz.pushFromGrowableXYZArray(i),t.outputLoops.push(t.inputLoops[0])}}else t.sortAndMergeLoops()}static intersectRangeConvexPolygonInPlace(t,e){if(t.isNull)return;const n=new W,i=Z.create();if(i.set(0,0,-1,t.high.z),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0&&(i.set(0,0,1,-t.low.z),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0&&(i.set(0,-1,0,t.high.y),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0&&(i.set(0,1,0,-t.low.y),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0&&(i.set(-1,0,0,t.high.x),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0&&(i.set(1,0,0,-t.low.x),this.clipConvexPolygonInPlace(i,e,n,!0),e.length!==0))))))return e}}class ol{static convexPolygonSplitInsideOutsidePlane(t,e,n,i,s){const r=new Bt(e),o=new Bt(n),a=new Bt(i);nn.splitConvexPolygonInsideOutsidePlane(t,r,o,a,s)}static polygonPlaneCrossings(t,e,n){const i=new Bt(e);return nn.polygonPlaneCrossings(t,i,n)}static convexPolygonClipInPlace(t,e,n,i=f.smallMetricDistance){const s=new Bt(e),r=n?new Bt(n):void 0;return nn.clipConvexPolygonInPlace(t,s,r,!0,i)}}class Qt{_origin;_vector0;_vector1;_vector2;static _workMatrix;static _workVector0;static _workVector1;static _workPoint;areStronglyIndependentVectors(t,e,n=f.smallAngleRadians){return t!==void 0&&e!==void 0?t.smallerUnorientedRadiansTo(e)>n:!1}clear(){this._origin=void 0,this._vector0=void 0,this._vector1=void 0,this._vector2=void 0}constructor(){this.clear()}getValidatedFrame(t=!1,e){if(this._origin&&this._vector0&&this._vector1){const n=(i,s)=>Qt._workMatrix=C.createRigidFromColumns(i,s,mt.XYZ,Qt._workMatrix);if(t){if(this._vector2){const i=n(this._vector0,this._vector1);if(i)return this._vector0.tripleProduct(this._vector1,this._vector2)<0&&i.scaleColumns(1,1,-1),X.createOriginAndMatrix(this._origin,i,e);const s=this._vector2;this._vector1=this._vector2=void 0,this.announceVector(s)}}else{const i=n(this._vector0,this._vector1);if(i)return X.createOriginAndMatrix(this._origin,i,e);this._vector1=this._vector2=void 0}}}applyDefaultUpVector(t){t&&this._vector0&&!this._vector1&&!t.isParallelTo(this._vector0)&&(this._vector1=t.crossProduct(this._vector0))}get hasOrigin(){return this._origin!==void 0}savedVectorCount(){return this._vector0?this._vector1?this._vector2?3:2:1:0}announcePoint(t){return this._origin?this._origin.isAlmostEqual(t)?this.savedVectorCount():this.announceVector(this._origin.vectorTo(t)):(this._origin=y.createFrom(t),this.savedVectorCount())}announceVector(t){if(t.isAlmostZero)return this.savedVectorCount();if(!this._vector0)return this._vector0=t.clone(this._vector0),1;if(!this._vector1)return this.areStronglyIndependentVectors(t,this._vector0,1e-5)?(this._vector1=t.clone(this._vector1),2):1;if(!this._vector2){const e=this._vector0.unitCrossProduct(this._vector1);return e&&!f.isSameCoordinate(0,e.dotProduct(t))?(this._vector2=t.clone(this._vector2),3):2}return 3}announce(t){if(!(this.savedVectorCount()>1)&&t!==void 0)if(t instanceof y)this.announcePoint(t);else if(t instanceof P)this.announceVector(t);else if(f.isArrayOfNumberArray(t,1,3))for(const e of t)this.announcePoint({x:e[0],y:e[1],z:e[2]});else if(f.isArrayOfNumberArray(t,1,2))for(const e of t)this.announcePoint({x:e[0],y:e[1],z:0});else if(Array.isArray(t))for(const e of t){if(this.savedVectorCount()>1)break;this.announce(e)}else if(t instanceof st)if(t instanceof U)this.announcePoint(t.startPoint()),this.announcePoint(t.endPoint());else if(t instanceof N){const e=t.fractionToPointAnd2Derivatives(0);this.announcePoint(e.origin),this.announceVector(e.vectorU),this.announceVector(e.vectorV)}else if(t instanceof F){for(const e of t.points)if(this.announcePoint(e),this.savedVectorCount()>1)break}else if(t instanceof me){const e=y.create();for(let n=0;this.savedVectorCount()<2&&t.getPolePoint3d(n,e)instanceof y;n++)this.announcePoint(e)}else{const e=t.fractionToFrenetFrame(0);e!==void 0&&(this.announcePoint(e.getOrigin()),this.announceVector(e.matrix.getColumn(0)),this.announceVector(e.matrix.getColumn(1)))}else if(t instanceof ut){if(t.children){for(const e of t.children)if(this.announce(e),this.savedVectorCount()>1)break}}else if(t instanceof le){const e=y.create();for(let n=0;this.savedVectorCount()<2&&t.getPoint3dAtCheckedPointIndex(n,e)instanceof y;n++)this.announcePoint(e)}else t.hasOwnProperty("x")&&t.hasOwnProperty("y")&&t.hasOwnProperty("z")&&this.announcePoint(t)}static createRightHandedFrame(t,...e){let n=e.length>0&&e[e.length-1]instanceof X?e.pop():void 0;const i=o=>(t&&o.matrix.dotColumnZ(t)<0&&o.matrix.scaleColumnsInPlace(1,-1,-1),o),s=new Qt;for(const o of e)if(s.announce(o),s.applyDefaultUpVector(t),n=s.getValidatedFrame(!1,n))return i(n);const r=(o,a)=>o.fractionToFrenetFrame(0,a);for(const o of e)if(o instanceof st){if(n=r(o,n))return i(n)}else if(o instanceof ut){const a=o.collectCurvePrimitives();for(const c of a)if(n=r(c,n))return i(n)}}static createRightHandedLocalToWorld(...t){return this.createRightHandedFrame(void 0,t)}static createFrameToDistantPoints(t,e){if(t.length>2){const n=t[0],i=Qt._workVector0??P.create();re.indexOfMostDistantPoint(t,t[0],i);const s=Qt._workVector1??P.create();re.indexOfPointWithMaxCrossProductMagnitude(t,n,i,s);const r=Qt._workMatrix=C.createRigidFromColumns(i,s,mt.XYZ,Qt._workMatrix);if(r)return X.createOriginAndMatrix(n,r,e)}}static createFrameWithCCWPolygon(t,e){if(t.length>2){const n=nt.centroidAreaNormal(t);if(n)return n.toRigidZFrame(e)}}static createLocalToWorldTransformInRange(t,e=qi.NonUniformRangeContainment,n=0,i=0,s=0,r=1,o){if(t.isNull)return X.createIdentity(o);let a=1,c=1,l=1;e===qi.LongestRangeDirection?a=c=l=f.correctSmallMetricDistance(t.maxLength(),r):e===qi.NonUniformRangeContainment&&(a=f.correctSmallMetricDistance(t.xLength(),r)*f.maxAbsDiff(n,0,1),c=f.correctSmallMetricDistance(t.yLength(),r)*f.maxAbsDiff(i,0,1),l=f.correctSmallMetricDistance(t.zLength(),r)*f.maxAbsDiff(s,0,1));const d=Qt._workPoint=t.fractionToPoint(n,i,s,Qt._workPoint),h=Qt._workMatrix=C.createScale(a,c,l,Qt._workMatrix);return X.createOriginAndMatrix(d,h,o)}}class qe{_matrix0;_matrix1;constructor(t,e){this._matrix0=t,this._matrix1=e}get transform0(){return this._matrix0}get transform1(){return this._matrix1}static createRefs(t,e){return new qe(t,e)}static createIdentity(){return new qe(pt.createIdentity(),pt.createIdentity())}static createTransform(t,e){if(e===void 0){if(e=t.inverse(),e===void 0)return}else if(!t.multiplyTransformTransform(e).isIdentity)return;return new qe(pt.createTransform(t),pt.createTransform(e))}static createBoxMap(t,e,n,i,s){const r=pt.createBoxToBox(t,e,n,i,s?s.transform0:void 0),o=pt.createBoxToBox(n,i,t,e,s?s.transform1:void 0);if(r&&o)return s||new qe(r,o)}setFrom(t){this._matrix0.setFrom(t._matrix0),this._matrix1.setFrom(t._matrix1)}clone(){return new qe(this._matrix0.clone(),this._matrix1.clone())}setIdentity(){this._matrix0.setIdentity(),this._matrix1.setIdentity()}setFromJSON(t){t.matrix0&&t.matrix1?(this._matrix0.setFromJSON(t.matrix0),this._matrix1.setFromJSON(t.matrix1)):this.setIdentity()}static fromJSON(t){const e=new qe(pt.createIdentity(),pt.createIdentity());return e.setFromJSON(t),e}toJSON(){return{matrix0:this._matrix0.toJSON(),matrix1:this._matrix1.toJSON()}}isAlmostEqual(t){return this._matrix0.isAlmostEqual(t._matrix0)&&this._matrix1.isAlmostEqual(t._matrix1)}static createVectorFrustum(t,e,n,i,s){s=Math.max(s,1e-8);const r=X.createOriginAndMatrix(t,C.createColumns(e,n,i)),o=r.inverse();if(!o)return;const a=new qe(pt.createTransform(o),pt.createTransform(r));return new qe(pt.createRowValues(1,0,0,0,0,1,0,0,0,0,s,0,0,0,s-1,1),pt.createRowValues(1,0,0,0,0,1,0,0,0,0,1/s,0,0,0,(1-s)/s,1)).multiplyMapMap(a)}multiplyMapMap(t){return new qe(this._matrix0.multiplyMatrixMatrix(t._matrix0),t._matrix1.multiplyMatrixMatrix(this._matrix1))}reverseInPlace(){const t=this._matrix0;this._matrix0=this._matrix1,this._matrix1=t}sandwich0This1(t){return new qe(t._matrix0.multiplyMatrixMatrix(this._matrix0.multiplyMatrixMatrix(t._matrix1)),t._matrix0.multiplyMatrixMatrix(this._matrix1.multiplyMatrixMatrix(t._matrix1)))}sandwich1This0(t){return new qe(t._matrix1.multiplyMatrixMatrix(this._matrix0.multiplyMatrixMatrix(t._matrix0)),t._matrix1.multiplyMatrixMatrix(this._matrix1.multiplyMatrixMatrix(t._matrix0)))}}class ai extends qs{solidPrimitiveType="box";_localToWorld;_baseX;_baseY;_topX;_topY;constructor(t,e,n,i,s,r){super(r),this._localToWorld=t,this._baseX=e,this._baseY=n,this._topX=i,this._topY=s}clone(){return new ai(this._localToWorld.clone(),this._baseX,this._baseY,this._topX,this._topY,this.capped)}getConstructiveFrame(){return this._localToWorld.cloneRigid()}tryTransformInPlace(t){return t.matrix.isSingular()?!1:(t.multiplyTransformTransform(this._localToWorld,this._localToWorld),t.matrix.determinant()<0&&(this._localToWorld.origin.addInPlace(this._localToWorld.matrix.columnZ()),this._localToWorld.matrix.scaleColumnsInPlace(1,1,-1),[this._baseX,this._topX]=[this._topX,this._baseX],[this._baseY,this._topY]=[this._topY,this._baseY]),!0)}cloneTransformed(t){const e=this.clone();return e.tryTransformInPlace(t)?e:void 0}static createDgnBox(t,e,n,i,s,r,o,a,c){const l=t.vectorTo(i),d=X.createOriginAndMatrixColumns(t,e,n,l);return new ai(d,s,r,o,a,c)}static createDgnBoxWithAxes(t,e,n,i,s,r,o,a){return ai.createDgnBox(t,e.columnX(),e.columnY(),n,i,s,r,o,a)}static createRange(t,e){if(!t.isNull){const n=t.low,i=t.xLength(),s=t.yLength(),r=t.low.clone();return r.z=r.z+t.zLength(),ai.createDgnBox(n,P.unitX(),P.unitY(),r,i,s,i,s,e)}}getBaseX(){return this._baseX}getBaseY(){return this._baseY}getTopX(){return this._topX}getTopY(){return this._topY}getBaseOrigin(){return this._localToWorld.multiplyXYZ(0,0,0)}getTopOrigin(){return this._localToWorld.multiplyXYZ(0,0,1)}getVectorX(){return this._localToWorld.matrix.columnX()}getVectorY(){return this._localToWorld.matrix.columnY()}getVectorZ(){return this._localToWorld.matrix.columnZ()}isSameGeometryClass(t){return t instanceof ai}isAlmostEqual(t){return t instanceof ai?this.capped!==t.capped||!this._localToWorld.isAlmostEqual(t._localToWorld)?!1:f.isSameCoordinate(this._baseX,t._baseX)&&f.isSameCoordinate(this._baseY,t._baseY)&&f.isSameCoordinate(this._topX,t._topX)&&f.isSameCoordinate(this._topY,t._topY):!1}dispatchToGeometryHandler(t){return t.handleBox(this)}strokeConstantVSection(t){const e=f.interpolate(this._baseX,t,this._topX),n=f.interpolate(this._baseY,t,this._topY),i=F.create(),s=this._localToWorld,r=y.create();return s.multiplyXYZ(0,0,t,r),i.addPoint(r),s.multiplyXYZ(e,0,t,r),i.addPoint(r),s.multiplyXYZ(e,n,t,r),i.addPoint(r),s.multiplyXYZ(0,n,t,r),i.addPoint(r),s.multiplyXYZ(0,0,t,r),i.addPoint(r),i}getCorners(){const t=this._localToWorld,e=this._baseX,n=this._baseY,i=this._topX,s=this._topY;return[t.multiplyXYZ(0,0,0),t.multiplyXYZ(e,0,0),t.multiplyXYZ(0,n,0),t.multiplyXYZ(e,n,0),t.multiplyXYZ(0,0,1),t.multiplyXYZ(i,0,1),t.multiplyXYZ(0,s,1),t.multiplyXYZ(i,s,1)]}constantVSection(t){const e=this.strokeConstantVSection(t);return tt.create(e)}extendRange(t,e){const n=this._localToWorld,i=this._baseX,s=this._baseY,r=this._topX,o=this._topY;e?(t.extendTransformTransformedXYZ(e,n,0,0,0),t.extendTransformTransformedXYZ(e,n,i,0,0),t.extendTransformTransformedXYZ(e,n,0,s,0),t.extendTransformTransformedXYZ(e,n,i,s,0),t.extendTransformTransformedXYZ(e,n,0,0,1),t.extendTransformTransformedXYZ(e,n,r,0,1),t.extendTransformTransformedXYZ(e,n,0,o,1),t.extendTransformTransformedXYZ(e,n,r,o,1)):(t.extendTransformedXYZ(n,0,0,0),t.extendTransformedXYZ(n,i,0,0),t.extendTransformedXYZ(n,0,s,0),t.extendTransformedXYZ(n,i,s,0),t.extendTransformedXYZ(n,0,0,1),t.extendTransformedXYZ(n,r,0,1),t.extendTransformedXYZ(n,0,o,1),t.extendTransformedXYZ(n,r,o,1))}get isSkew(){return!this._localToWorld.matrix.columnZ().isParallelTo(this._localToWorld.matrix.columnXCrossColumnY(),!0,!0)}get isClosedVolume(){return this.capped}}const sn={aliceBlue:16775408,amber:49151,antiqueWhite:14150650,aqua:16776960,aquamarine:13959039,azure:16777200,beige:14480885,bisque:12903679,black:0,blanchedAlmond:13495295,blue:16711680,blueViolet:14822282,brown:2763429,burlyWood:8894686,cadetBlue:10526303,chartreuse:65407,chocolate:1993170,coral:5275647,cornflowerBlue:15570276,cornSilk:14481663,crimson:3937500,cyan:16776960,darkBlue:9109504,darkBrown:2179941,darkCyan:9145088,darkGoldenrod:755384,darkGray:11119017,darkGreen:25600,darkGrey:11119017,darkKhaki:7059389,darkMagenta:9109643,darkOliveGreen:3107669,darkOrange:36095,darkOrchid:13382297,darkRed:139,darkSalmon:8034025,darkSeagreen:9419919,darkSlateBlue:9125192,darkSlateGray:5197615,darkSlateGrey:5197615,darkTurquoise:13749760,darkViolet:13828244,deepPink:9639167,deepSkyBlue:16760576,dimGray:6908265,dimGrey:6908265,dodgerBlue:16748574,fireBrick:2237106,floralWhite:15792895,forestGreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostWhite:16775416,gold:55295,goldenrod:2139610,gray:8421504,green:32768,greenYellow:3145645,grey:8421504,honeydew:15794160,hotPink:11823615,indianRed:6053069,indigo:8519755,ivory:15794175,khaki:9234160,lavender:16443110,lavenderBlush:16118015,lawnGreen:64636,lemonChiffon:13499135,lightBlue:15128749,lightCoral:8421616,lightCyan:16777184,lightGoldenrodYellow:13826810,lightGray:13882323,lightGreen:9498256,lightGrey:13882323,lightPink:12695295,lightSalmon:8036607,lightSeagreen:11186720,lightSkyBlue:16436871,lightSlateGray:10061943,lightSlateGrey:10061943,lightSteelBlue:14599344,lightyellow:14745599,lime:65280,limeGreen:3329330,linen:15134970,magenta:16711935,maroon:128,mediumAquamarine:11193702,mediumBlue:13434880,mediumOrchid:13850042,mediumPurple:14381203,mediumSeaGreen:7451452,mediumSlateBlue:15624315,mediumSpringGreen:10156544,mediumTurquoise:13422920,mediumVioletRed:8721863,midnightBlue:7346457,mintCream:16449525,mistyRose:14804223,moccasin:11920639,navajoWhite:11394815,navy:8388608,oldLace:15136253,olive:32896,oliveDrab:2330219,orange:42495,orangeRed:17919,orchid:14053594,paleGoldenrod:11200750,paleGreen:10025880,paleTurquoise:15658671,paleVioletRed:9662683,papayaWhip:14020607,peachPuff:12180223,peru:4163021,pink:13353215,plum:14524637,powderBlue:15130800,purple:8388736,rebeccaPurple:10040166,red:255,rosyBrown:9408444,royalBlue:14772545,saddleBrown:1262987,salmon:7504122,sandyBrown:6333684,seaGreen:5737262,seaShell:15660543,sienna:2970272,silver:12632256,skyBlue:15453831,slateBlue:13458026,slateGray:9470064,slateGrey:9470064,snow:16448255,springGreen:8388352,steelBlue:11829830,tan:9221330,teal:8421376,thistle:14204888,tomato:4678655,turquoise:13688896,violet:15631086,wheat:11788021,white:16777215,whiteSmoke:16119285,yellow:65535,yellowGreen:3329434};class _o{h;s;l;constructor(t=0,e=0,n=0){this.h=t,this.s=e,this.l=n}clone(t,e,n){return new _o(t??this.h,e??this.s,n??this.l)}toColorDef(t=0){return lt.fromHSL(this.h,this.s,this.l,t)}static fromColorDef(t){return t.toHSL()}}var zi;(function(u){u[u.VISIBILITY_GOAL=40]="VISIBILITY_GOAL",u[u.HSV_SATURATION_WEIGHT=4]="HSV_SATURATION_WEIGHT",u[u.HSV_VALUE_WEIGHT=2]="HSV_VALUE_WEIGHT"})(zi||(zi={}));class Si{h;s;v;constructor(t=0,e=0,n=0){this.h=t,this.s=e,this.v=n}clone(t,e,n){return new Si(t??this.h,e??this.s,n??this.v)}toColorDef(t=0){return lt.fromHSV(this,t)}static fromColorDef(t){return t.toHSV()}adjusted(t,e){let n;if(t){if(n=e*zi.HSV_VALUE_WEIGHT,this.v>=n)return new Si(this.h,this.s,this.v-n);n-=this.v;const s=Math.min(this.s+n,100);return new Si(this.h,s,0)}if(n=e*zi.HSV_SATURATION_WEIGHT,this.s>=n)return new Si(this.h,this.s-n,this.v);n-=this.s;const i=Math.min(this.v+n,100);return new Si(this.h,0,i)}}const _e=new Uint8Array(4),mn=new Uint32Array(_e.buffer);class lt{_tbgr;constructor(t){mn[0]=t,this._tbgr=mn[0]}static create(t){return this.fromTbgr(this.computeTbgr(t))}static computeTbgr(t){switch(typeof t){case"number":return t;case"string":return this.computeTbgrFromString(t);default:return 0}}toJSON(){return this._tbgr}static fromJSON(t){return this.create(t)}static from(t,e,n,i){return this.fromTbgr(this.computeTbgrFromComponents(t,e,n,i))}static computeTbgrFromComponents(t,e,n,i){return _e[0]=t,_e[1]=e,_e[2]=n,_e[3]=i||0,mn[0]}static fromTbgr(t){switch(t){case sn.black:return this.black;case sn.white:return this.white;case sn.red:return this.red;case sn.green:return this.green;case sn.blue:return this.blue;default:return new lt(t)}}static fromAbgr(t){return this.fromTbgr(this.getAbgr(t))}static fromString(t){return this.fromTbgr(this.computeTbgrFromString(t))}static isValidColor(t){return typeof t=="number"?t>=0&&t<=4294967295&&Math.floor(t)===t:this.tryComputeTbgrFromString(t)!==void 0}static computeTbgrFromString(t){return this.tryComputeTbgrFromString(t)??0}static tryComputeTbgrFromString(t){if(typeof t!="string")return;t=t.toLowerCase();let e=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(t);if(e){let n;const i=e[1],s=e[2],r=c=>c[c.length-1]==="%",o=c=>{const l=parseFloat(c);return 255*f.clamp(r(c)?l/100:l,0,1)},a=c=>{const l=r(c)?parseFloat(c)/100*255:parseInt(c,10);return f.clamp(l,0,255)};switch(i){case"rgb":case"rgba":if(n=/^(\d+%*)\s*[, ]\s*(\d+%*)\s*[, ]\s*(\d+%*)\s*([,\/]\s*([0-9]*\.?[0-9]+%*)\s*)?$/.exec(s),n)return this.computeTbgrFromComponents(a(n[1]),a(n[2]),a(n[3]),typeof n[5]=="string"?255-o(n[5]):0);break;case"hsl":case"hsla":if(n=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(s),n){const c=parseFloat(n[1])/360,l=parseInt(n[2],10)/100,d=parseInt(n[3],10)/100,h=typeof n[5]=="string"?255-o(n[5]):0;return this.computeTbgrFromHSL(c,l,d,h)}break}}else if(e=/^\#([a-f0-9]+)$/.exec(t)){const n=e[1],i=n.length;if(i===3)return this.computeTbgrFromComponents(parseInt(n.charAt(0)+n.charAt(0),16),parseInt(n.charAt(1)+n.charAt(1),16),parseInt(n.charAt(2)+n.charAt(2),16),0);if(i===6)return this.computeTbgrFromComponents(parseInt(n.charAt(0)+n.charAt(1),16),parseInt(n.charAt(2)+n.charAt(3),16),parseInt(n.charAt(4)+n.charAt(5),16),0)}if(t&&t.length>0){for(const[n,i]of Object.entries(sn))if(n.toLowerCase()===t)return i}}get colors(){return lt.getColors(this._tbgr)}static getColors(t){return mn[0]=t,{b:_e[2],g:_e[1],r:_e[0],t:_e[3]}}get tbgr(){return this._tbgr}getAbgr(){return lt.getAbgr(this._tbgr)}static getAbgr(t){return mn[0]=t,_e[3]=255-_e[3],mn[0]}getRgb(){return lt.getRgb(this._tbgr)}static getRgb(t){return mn[0]=t,(_e[0]<<16)+(_e[1]<<8)+_e[2]}withAlpha(t){const e=lt.withAlpha(this._tbgr,t);return e===this._tbgr?this:lt.fromTbgr(e)}static withAlpha(t,e){return mn[0]=t,_e[3]=255-(e|0),mn[0]}getAlpha(){return lt.getAlpha(this._tbgr)}static getAlpha(t){return mn[0]=t,255-_e[3]}get isOpaque(){return lt.isOpaque(this._tbgr)}static isOpaque(t){return this.getAlpha(t)===255}getTransparency(){return lt.getTransparency(this._tbgr)}static getTransparency(t){return mn[0]=t,_e[3]}withTransparency(t){const e=lt.withTransparency(this._tbgr,t);return e===this._tbgr?this:lt.fromTbgr(e)}static withTransparency(t,e){return this.withAlpha(t,255-e)}get name(){return lt.getName(this.tbgr)}static getName(t){for(const[e,n]of Object.entries(sn))if(n===t)return e}toHexString(){return lt.toHexString(this.tbgr)}static toHexString(t){return`#${`000000${this.getRgb(t).toString(16)}`.slice(-6)}`}static getColorsString(t){const e=this.getColors(t);return`${e.r},${e.g},${e.b}`}toRgbString(){return lt.toRgbString(this.tbgr)}static toRgbString(t){return`rgb(${this.getColorsString(t)})`}toRgbaString(){return lt.toRgbaString(this.tbgr)}static toRgbaString(t){return`rgba(${this.getColorsString(t)},${this.getAlpha(t)/255})`}lerp(t,e){return lt.fromTbgr(lt.lerp(this.tbgr,t.tbgr,e))}static lerp(t,e,n){const i=this.getColors(t),s=this.getColors(e);return i.r+=(s.r-i.r)*n,i.g+=(s.g-i.g)*n,i.b+=(s.b-i.b)*n,this.computeTbgrFromComponents(i.r,i.g,i.b,i.t)}inverse(){return lt.fromTbgr(lt.inverse(this.tbgr))}static inverse(t){const e=this.getColors(t);return this.computeTbgrFromComponents(255-e.r,255-e.g,255-e.b)}static fromHSL(t,e,n,i=0){return this.fromTbgr(this.computeTbgrFromHSL(t,e,n,i))}static computeTbgrFromHSL(t,e,n,i=0){const s=(l,d,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?l+(d-l)*6*h:h<.5?d:h<.6666666666666666?l+(d-l)*6*(.6666666666666666-h):l),r=(l,d,h)=>Math.round(s(l,d,h)*255);if(t=((l,d)=>(l%d+d)%d)(t,1),e=f.clamp(e,0,1),n=f.clamp(n,0,1),e===0)return n*=255,this.computeTbgrFromComponents(n,n,n,i);const a=n<=.5?n*(1+e):n+e-n*e,c=2*n-a;return this.computeTbgrFromComponents(r(c,a,t+1/3),r(c,a,t),r(c,a,t-1/3),i)}toHSL(){const t=this.colors;t.r/=255,t.g/=255,t.b/=255;const e=Math.max(t.r,t.g,t.b),n=Math.min(t.r,t.g,t.b);let i=0,s;const r=(n+e)/2;if(n===e)s=0;else{const o=e-n;switch(s=r<=.5?o/(e+n):o/(2-e-n),e){case t.r:i=(t.g-t.b)/o+(t.g<t.b?6:0);break;case t.g:i=(t.b-t.r)/o+2;break;case t.b:i=(t.r-t.g)/o+4;break}i/=6}return new _o(i,s,r)}toHSV(){const{r:t,g:e,b:n}=this.colors;let i=t<e?t:e;n<i&&(i=n);let s=t>e?t:e;n>s&&(s=n);const r=Math.floor(s/255*100+.5),o=s-i,a=s!==0?Math.floor(o/s*100+.5):0;let c=0;if(a){const l=(s-t)/o,d=(s-e)/o,h=(s-n)/o;let g;t===s?g=h-d:e===s?g=2+l-h:g=4+d-l,g*=60,g<0&&(g+=360),c=Math.floor(g+.5),c>=360&&(c=0)}else c=0;return new Si(c,a,r)}static fromHSV(t,e=0){if(!t.s||t.h===-1){const p=255&Math.floor(255*t.v/100+.5+3e-14);return lt.from(p,p,p,0)}let n=t.h,i=t.s,s=t.v;n===360&&(n=0),n/=60;const r=Math.floor(n),o=n-r;s/=100,i/=100;const a=255&Math.floor(s*(1-i)*255+.5),c=255&Math.floor(s*(1-i*o)*255+.5),l=255&Math.floor(s*(1-i*(1-o))*255+.5),d=255&Math.floor(s*255+.5);let h=0,g=0,m=0;switch(r){case 0:h=d,m=l,g=a;break;case 1:h=c,m=d,g=a;break;case 2:h=a,m=d,g=l;break;case 3:h=a,m=c,g=d;break;case 4:h=l,m=a,g=d;break;case 5:h=d,m=a,g=c;break}return lt.from(h,m,g,e)}visibilityCheck(t){const e=this.colors,n=t.colors,i=Math.abs(e.r-n.r),s=Math.abs(e.g-n.g),r=Math.abs(e.b-n.b);return .3*i+.59*s+.11*r}adjustedForContrast(t,e){const n=this.visibilityCheck(t);if(zi.VISIBILITY_GOAL<=n)return e!==void 0?this.withAlpha(e):this;const i=Math.floor((zi.VISIBILITY_GOAL-n)/255*100);let s=this.toHSV(),r=s.clone();s=s.adjusted(!0,i),r=r.adjusted(!1,i),e===void 0&&(e=this.getAlpha());const o=lt.fromHSV(s).withAlpha(e),a=lt.fromHSV(r).withAlpha(e);return a.getRgb()===t.getRgb()?o:o.getRgb()===t.getRgb()||a.visibilityCheck(t)>=o.visibilityCheck(t)?a:o}equals(t){return this._tbgr===t._tbgr}static black=new lt(sn.black);static white=new lt(sn.white);static red=new lt(sn.red);static green=new lt(sn.green);static blue=new lt(sn.blue)}var Vi;(function(u){u[u.Rgba=0]="Rgba",u[u.Rgb=2]="Rgb",u[u.Alpha=5]="Alpha"})(Vi||(Vi={}));class Oi{data;format;width;get numBytesPerPixel(){return Oi.getNumBytesPerPixel(this.format)}static getNumBytesPerPixel(t){switch(t){case Vi.Alpha:return 1;case Vi.Rgb:return 3;default:return 4}}get height(){return Oi.computeHeight(this.data,this.format,this.width)}static create(t,e,n){if(!this.isValidData(t,e,n))throw new Error("The number of bytes supplied for ImageBuffer do not match its width and format.");return new Oi(t,e,n)}static isValidData(t,e,n){const i=this.computeHeight(t,e,n);return n>0&&i>0&&Math.floor(n)===n&&Math.floor(i)===i}static computeHeight(t,e,n){return t.length/(n*this.getNumBytesPerPixel(e))}constructor(t,e,n){this.data=t,this.format=e,this.width=n}}var Ma;(function(u){u[u.Jpeg=0]="Jpeg",u[u.Png=2]="Png",u[u.Svg=3]="Svg"})(Ma||(Ma={}));class al{data;format;constructor(t,e){this.data=t,this.format=e}}var ci;(function(u){let t;(function(r){r[r.None=0]="None",r[r.Invert=1]="Invert",r[r.Outline=2]="Outline"})(t=u.Flags||(u.Flags={}));let e;(function(r){r[r.None=0]="None",r[r.Linear=1]="Linear",r[r.Curved=2]="Curved",r[r.Cylindrical=3]="Cylindrical",r[r.Spherical=4]="Spherical",r[r.Hemispherical=5]="Hemispherical",r[r.Thematic=6]="Thematic"})(e=u.Mode||(u.Mode={}));class n{value;color;constructor(o){this.value=o.value,this.color=lt.fromJSON(o.color)}}u.KeyColor=n;function i(r,o){return r.value===o.value&&r.color.equals(o.color)}u.keyColorEquals=i;class s{mode=e.None;flags=t.None;angle;tint;shift=0;thematicSettings;keys=[];static fromJSON(o){const a=new s;return o&&(a.mode=o.mode,a.flags=o.flags===void 0?t.None:o.flags,a.angle=o.angle?A.fromJSON(o.angle):void 0,a.tint=o.tint,a.shift=o.shift?o.shift:0,o.keys.forEach(c=>a.keys.push(new n(c))),a.thematicSettings=o.thematicSettings===void 0?void 0:Se.fromJSON(o.thematicSettings)),a}static _fixedSchemeKeys=[[[0,0,255,0],[.25,0,255,255],[.5,0,0,255],[.75,255,0,255],[1,255,0,0]],[[0,255,0,0],[.25,255,0,255],[.5,0,0,255],[.75,0,255,255],[1,0,255,0]],[[0,0,0,0],[1,255,255,255]],[[0,152,148,188],[.5,204,160,204],[1,152,72,128]],[[0,0,255,0],[.2,72,96,160],[.4,152,96,160],[.6,128,32,104],[.7,148,180,128],[1,240,240,240]]];static _fixedCustomKeys=[[0,255,0,0],[1,0,255,0]];static createThematic(o){const a=new s;if(a.mode=e.Thematic,a.thematicSettings=o,o.colorScheme<pn.Custom)for(const c of u.Symb._fixedSchemeKeys[o.colorScheme])a.keys.push(new n({value:c[0],color:lt.computeTbgrFromComponents(c[1],c[3],c[2])}));else if(o.customKeys.length>1,o.customKeys.length>1)o.customKeys.forEach(c=>a.keys.push(c));else for(const c of u.Symb._fixedCustomKeys)a.keys.push(new n({value:c[0],color:lt.from(c[1],c[3],c[2]).toJSON()}));return a}toJSON(){return{...this,thematicSettings:this.thematicSettings?.toJSON(),keys:this.keys.map(o=>({value:o.value,color:o.color.toJSON()}))}}clone(){return s.fromJSON(this.toJSON())}equals(o){return s.compareSymb(this,o)===0}static compareSymb(o,a){if(o===a)return 0;if(o.mode!==a.mode)return o.mode-a.mode;if(o.flags!==a.flags)return o.flags===void 0?-1:a.flags===void 0?1:o.flags-a.flags;if(o.tint!==a.tint)return o.tint===void 0?-1:a.tint===void 0?1:o.tint-a.tint;if(o.shift!==a.shift)return o.shift===void 0?-1:a.shift===void 0?1:o.shift-a.shift;if(o.angle===void 0!=(a.angle===void 0))return o.angle===void 0?-1:1;if(o.angle&&!o.angle.isAlmostEqualNoPeriodShift(a.angle))return o.angle.radians-a.angle.radians;if(o.keys.length!==a.keys.length)return o.keys.length-a.keys.length;for(let c=0;c<o.keys.length;c++){if(o.keys[c].value!==a.keys[c].value)return o.keys[c].value-a.keys[c].value;if(!o.keys[c].color.equals(a.keys[c].color))return o.keys[c].color.tbgr-a.keys[c].color.tbgr}if(o.thematicSettings!==a.thematicSettings){if(o.thematicSettings===void 0)return-1;if(a.thematicSettings===void 0)return 1;{const c=Se.compare(o.thematicSettings,a.thematicSettings);if(c!==0)return c}}return 0}compare(o){return u.Symb.compareSymb(this,o)}roundToByte(o){return Math.min(o+.5,255)&255}mapColor(o){o<0?o=0:o>1&&(o=1),(this.flags&t.Invert)!==0&&(o=1-o);let a=0,c,l,d;if(this.keys.length<=2)l=1-o,d=o;else{for(;a<this.keys.length-2&&o>this.keys[a+1].value;)a++;c=this.keys[a+1].value-this.keys[a].value,d=c<1e-4?0:(o-this.keys[a].value)/c,l=1-d}const h=this.keys[a].color,g=this.keys[a+1].color,m=h.colors,p=g.colors,x=l*m.r+d*p.r,_=l*m.g+d*p.g,I=l*m.b+d*p.b,v=l*m.t+d*p.t;return lt.from(this.roundToByte(x),this.roundToByte(_),this.roundToByte(I),this.roundToByte(v))}get hasTranslucency(){for(const o of this.keys)if(!o.color.isOpaque)return!0;return!1}get isOutlined(){return(this.flags&t.Outline)!==0}getThematicImageForRenderer(o){e.Thematic,this.mode;let a=this.thematicSettings;a===void 0&&(a=Se.defaults);const c=Math.min(a.stepCount,o),l=ye.Smooth===a.mode?o:c,d=new Uint8Array(1*l*4);let h=d.length-1;function g(p){d[h--]=p.getAlpha(),d[h--]=p.colors.b,d[h--]=p.colors.g,d[h--]=p.colors.r}switch(a.mode){case ye.Smooth:{for(let p=0;p<l;p++){const x=1-p/l;g(this.mapColor(x))}break}case ye.SteppedWithDelimiter:case ye.IsoLines:case ye.Stepped:{a.stepCount>1;for(let p=0;p<l;p++){const x=1-p/(l-1);g(this.mapColor(x))}break}}return Oi.create(d,Vi.Rgba,1)}getImage(o,a){return this.mode===e.Thematic&&(o=1),this.produceImage({width:o,height:a,includeThematicMargin:!0})}produceImage(o){const{width:a,height:c,includeThematicMargin:l}={...o},d=this.angle===void 0?0:this.angle.radians,h=Math.cos(d),g=Math.sin(d),m=new Uint8Array(a*c*4);let p=m.length-1;const x=Math.min(1,Math.abs(this.shift));switch(this.mode){case e.Linear:case e.Cylindrical:{const I=.5-.25*x*h,v=.5-.25*x*g;let S,w=S=0,T;for(let R=0;R<2;R++)for(let L=0;L<2;L++)T=(L-I)*h+(R-v)*g,T<w&&(w=T),T>S&&(S=T);for(let R=0;R<c;R++){const L=R/c-v;for(let z=0;z<a;z++){T=(z/a-I)*h+L*g;let rt;this.mode===e.Linear?T>0?rt=.5+.5*T/S:rt=.5-.5*T/w:T>0?rt=Math.sin(Math.PI/2*(1-T/S)):rt=Math.sin(Math.PI/2*(1-T/w));const ft=this.mapColor(rt);m[p--]=ft.getAlpha(),m[p--]=ft.colors.b,m[p--]=ft.colors.g,m[p--]=ft.colors.r}}break}case e.Curved:{const I=.5+.5*g-.25*x*h,v=.5-.5*h-.25*x*g;for(let S=0;S<c;S++){const w=S/c-v;for(let T=0;T<a;T++){const R=T/a-I,L=.8*(R*h+w*g),z=w*h-R*g,K=Math.sin(Math.PI/2*(1-Math.sqrt(L*L+z*z))),rt=this.mapColor(K);m[p--]=rt.getAlpha(),m[p--]=rt.colors.b,m[p--]=rt.colors.g,m[p--]=rt.colors.r}}break}case e.Spherical:{const I=.5+.125*Math.sin(2*d),v=.5*x*(h+g)*I,S=.5*x*(g-h)*I;for(let w=0;w<c;w++){const T=S+w/c-.5;for(let R=0;R<a;R++){const L=v+R/a-.5,z=Math.sin(Math.PI/2*(1-Math.sqrt(L*L+T*T)/I)),K=this.mapColor(z);m[p--]=K.getAlpha(),m[p--]=K.colors.b,m[p--]=K.colors.g,m[p--]=K.colors.r}}break}case e.Hemispherical:{const I=.5+.5*g-.5*x*h,v=.5-.5*h-.5*x*g;for(let S=0;S<c;S++){const w=S/c-v;for(let T=0;T<a;T++){const R=T/a-I,L=Math.sin(Math.PI/2*(1-Math.sqrt(R*R+w*w))),z=this.mapColor(L);m[p--]=z.getAlpha(),m[p--]=z.colors.b,m[p--]=z.colors.g,m[p--]=z.colors.r}}break}case e.Thematic:{const I=this.thematicSettings??Se.defaults;for(let v=0;v<c;v++){let S=1-v/c,w;if(l&&(S<Se.margin||S>Se.contentMax))w=I.marginColor;else switch(S=(S-Se.margin)/Se.contentRange,I.mode){case ye.SteppedWithDelimiter:case ye.IsoLines:case ye.Stepped:{if(I.stepCount>1){const T=Math.floor(S*I.stepCount-1e-5)/(I.stepCount-1);w=this.mapColor(T)}else throw new Error(`Thematic gradient mode ${String(I.mode)} requires at least two steps.`);break}case ye.Smooth:w=this.mapColor(S);break}for(let T=0;T<a;T++)m[p--]=w.getAlpha(),m[p--]=w.colors.b,m[p--]=w.colors.g,m[p--]=w.colors.r}}}return Oi.create(m,Vi.Rgba,a)}}u.Symb=s})(ci||(ci={}));var li;(function(u){u[u.Opaque=0]="Opaque",u[u.Translucent=1]="Translucent",u[u.Mixed=2]="Mixed"})(li||(li={}));var ye;(function(u){u[u.Smooth=0]="Smooth",u[u.Stepped=1]="Stepped",u[u.SteppedWithDelimiter=2]="SteppedWithDelimiter",u[u.IsoLines=3]="IsoLines"})(ye||(ye={}));var as;(function(u){u[u.SurfaceOnly=0]="SurfaceOnly",u[u.MultiplySurfaceAndGradient=1]="MultiplySurfaceAndGradient"})(as||(as={}));var pn;(function(u){u[u.BlueRed=0]="BlueRed",u[u.RedBlue=1]="RedBlue",u[u.Monochrome=2]="Monochrome",u[u.Topographic=3]="Topographic",u[u.SeaMountain=4]="SeaMountain",u[u.Custom=5]="Custom"})(pn||(pn={}));class Se{mode;stepCount;marginColor;colorScheme;customKeys;colorMix;transparencyMode;static get margin(){return .001}static get contentRange(){return 1-2*Se.margin}static get contentMax(){return 1-Se.margin}static defaults=new Se({});static _defaultCustomKeys=[[0,255,255,255],[1,0,0,0]];get textureTransparency(){let t=li.Opaque;if(pn.Custom===this.colorScheme){let e=!1,n=!1;for(const i of this.customKeys){const s=i.color.isOpaque;e=e||s,n=n||!s}n&&(t=e?li.Mixed:li.Translucent)}return t!==li.Mixed&&this.marginColor.isOpaque!==(t===li.Opaque)&&(t=li.Mixed),t}equals(t){return this.mode!==t.mode||this.stepCount!==t.stepCount||!this.marginColor.equals(t.marginColor)||this.colorScheme!==t.colorScheme||this.customKeys.length!==t.customKeys.length||this.colorMix!==t.colorMix||this.transparencyMode!==t.transparencyMode?!1:this.customKeys.every((e,n)=>ci.keyColorEquals(e,t.customKeys[n]))}static compare(t,e){let n=0;if((n=Et(t.mode,e.mode))!==0||(n=Et(t.stepCount,e.stepCount))!==0||(n=Et(t.marginColor.tbgr,e.marginColor.tbgr))!==0||(n=Et(t.colorScheme,e.colorScheme))!==0||(n=Et(t.colorMix,e.colorMix))!==0||(n=Et(t.customKeys.length,e.customKeys.length))!==0||(n=Et(t.transparencyMode,e.transparencyMode))!==0)return n;for(let i=0;i<t.customKeys.length;i++)if((n=Et(t.customKeys[i].color.tbgr,e.customKeys[i].color.tbgr))!==0)return n;return n}constructor(t){if(this.customKeys=[],t===void 0)this.mode=ye.Smooth,this.stepCount=10,this.marginColor=lt.fromJSON(),this.colorScheme=pn.BlueRed,this.colorMix=0,this.transparencyMode=as.SurfaceOnly;else{if(this.mode=t.mode!==void 0&&t.mode!==null?t.mode:ye.Smooth,(this.mode<ye.Smooth||this.mode>ye.IsoLines)&&(this.mode=ye.Smooth),this.stepCount=typeof t.stepCount=="number"?t.stepCount:10,this.stepCount<2&&(this.stepCount=2),this.marginColor=lt.fromJSON(t.marginColor),this.colorScheme=t.colorScheme!==void 0&&t.colorScheme!==null?t.colorScheme:pn.BlueRed,(this.colorScheme<pn.BlueRed||this.colorScheme>pn.Custom)&&(this.colorScheme=pn.BlueRed),t.customKeys!==void 0&&t.customKeys!==null&&t.customKeys.forEach(e=>this.customKeys.push(new ci.KeyColor(e))),this.colorScheme===pn.Custom&&this.customKeys.length<2){this.customKeys=[];for(const e of Se._defaultCustomKeys)this.customKeys.push(new ci.KeyColor({value:e[0],color:lt.computeTbgrFromComponents(e[1],e[3],e[2])}))}this.colorMix=t.colorMix??0,this.transparencyMode=t.transparencyMode??as.SurfaceOnly}}static fromJSON(t){return t?new Se(t):this.defaults}toJSON(){const t={};ye.Smooth!==this.mode&&(t.mode=this.mode),this.stepCount!==10&&(t.stepCount=this.stepCount);const e=this.marginColor.toJSON();return e!==0&&(t.marginColor=e),pn.BlueRed!==this.colorScheme&&(t.colorScheme=this.colorScheme),this.colorMix!==0&&(t.colorMix=this.colorMix),as.SurfaceOnly!==this.transparencyMode&&(t.transparencyMode=this.transparencyMode),this.customKeys.length>0&&(t.customKeys=this.customKeys.map(n=>({value:n.value,color:n.color.toJSON()}))),t}clone(t){if(t===void 0)return Se.fromJSON(this.toJSON());const e={mode:t.mode!==void 0?t.mode:this.mode,stepCount:t.stepCount!==void 0?t.stepCount:this.stepCount,marginColor:t.marginColor!==void 0?t.marginColor:this.marginColor.tbgr,colorScheme:t.colorScheme!==void 0?t.colorScheme:this.colorScheme,customKeys:t.customKeys!==void 0?t.customKeys:this.customKeys.map(n=>({value:n.value,color:n.color.tbgr})),colorMix:t.colorMix!==void 0?t.colorMix:this.colorMix,transparencyMode:t.transparencyMode??this.transparencyMode};return Se.fromJSON(e)}}var Ea;(function(u){u[u.Height=0]="Height",u[u.InverseDistanceWeightedSensors=1]="InverseDistanceWeightedSensors",u[u.Slope=2]="Slope",u[u.HillShade=3]="HillShade"})(Ea||(Ea={}));class mr{r;g;b;constructor(t,e,n){this.r=t,this.g=e,this.b=n,this.r=Math.max(0,Math.min(this.r,255)),this.g=Math.max(0,Math.min(this.g,255)),this.b=Math.max(0,Math.min(this.b,255))}static fromColorDef(t){const e=t.colors;return new mr(e.r,e.g,e.b)}toColorDef(t=0){return lt.from(this.r,this.g,this.b,t)}toJSON(){return{r:this.r,g:this.g,b:this.b}}static fromJSON(t){let e=255,n=255,i=255;return t!==void 0&&(typeof t.r=="number"&&(e=t.r),typeof t.g=="number"&&(n=t.g),typeof t.b=="number"&&(i=t.b)),new mr(e,n,i)}equals(t){return this.r===t.r&&this.g===t.g&&this.b===t.b}compareTo(t){return Et(this.r,t.r)||Et(this.g,t.g)||Et(this.b,t.b)}toHexString(){return this.toColorDef().toHexString()}}var Hn;(function(u){u[u.Solid=0]="Solid",u[u.Code0=0]="Code0",u[u.Code1=2155905152]="Code1",u[u.Code2=4177066232]="Code2",u[u.Code3=4292935648]="Code3",u[u.Code4=4262526480]="Code4",u[u.Code5=3772834016]="Code5",u[u.Code6=4169726088]="Code6",u[u.Code7=4279828248]="Code7",u[u.HiddenLine=3435973836]="HiddenLine",u[u.Invisible=1]="Invisible",u[u.Invalid=-1]="Invalid"})(Hn||(Hn={}));var Ra;(function(u){u[u.Never=0]="Never",u[u.ByView=1]="ByView",u[u.Always=2]="Always",u[u.Blanking=3]="Blanking"})(Ra||(Ra={}));var ba;(function(u){u[u.None=0]="None",u[u.Solid=1]="Solid",u[u.Outline=2]="Outline"})(ba||(ba={}));var Tn;(function(u){u[u.Primary=0]="Primary",u[u.Construction=1]="Construction",u[u.Dimension=2]="Dimension",u[u.Pattern=3]="Pattern"})(Tn||(Tn={}));class pr{data;batchModelId;batchModelIdPair;numFeatures;anyDefined;type;animationNodeIds;get byteLength(){return this.data.byteLength}constructor(t,e,n,i,s){switch(this.data=t,this.batchModelId=e,this.batchModelIdPair=$t.getUint32Pair(e),this.numFeatures=n,this.type=i,this.animationNodeIds=s,this.numFeatures){case 0:this.anyDefined=!1;break;case 1:this.anyDefined=Li.isDefined(this.getFeature(0,Li.create()));break;default:this.anyDefined=!0;break}this.data.length>=this._subCategoriesOffset,this.animationNodeIds===void 0||(this.animationNodeIds.length,this.numFeatures)}static pack(t){const e=new Map;for(const r of t.getArray())e.get(r.value.subCategoryId.toString())===void 0&&e.set(r.value.subCategoryId,e.size);const n=3*t.length,i=n+2*e.size,s=new Uint32Array(i);for(const r of t.getArray()){const o=r.value,a=r.index*3;let c=ln(e.get(o.subCategoryId));c|=o.geometryClass<<24,s[a+0]=$t.getLowerUint32(o.elementId),s[a+1]=$t.getUpperUint32(o.elementId),s[a+2]=c}return e.forEach((r,o,a)=>{const c=n+2*r;s[c+0]=$t.getLowerUint32(o),s[c+1]=$t.getUpperUint32(o)}),new pr(s,t.modelId,t.length,t.type)}getFeature(t,e){const n=this.getPackedFeature(t,ll);return Li.unpack(n,e,this.batchModelId)}findFeature(t,e){return t<this.numFeatures?this.getFeature(t,e):void 0}getElementIdPair(t,e){e=e??{lower:0,upper:0},t<this.numFeatures;const n=3*t;return e.lower=this.data[n],e.upper=this.data[n+1],e}getSubCategoryIdPair(t){const e=3*t;let n=this.data[e+2];return n=(n&16777215)>>>0,n=n*2+this._subCategoriesOffset,{lower:this.data[n],upper:this.data[n+1]}}getAnimationNodeId(t){return this.animationNodeIds!==void 0&&t<this.numFeatures?this.animationNodeIds[t]:0}getPackedFeature(t,e){t<this.numFeatures;const n=3*t;e.elementId.lower=this.data[n],e.elementId.upper=this.data[n+1];const i=this.data[n+2];e.geometryClass=i>>>24&255;let s=(i&16777215)>>>0;return s=s*2+this._subCategoriesOffset,e.subCategoryId.lower=this.data[s],e.subCategoryId.upper=this.data[s+1],e.animationNodeId=this.getAnimationNodeId(t),e.modelId.lower=this.batchModelIdPair.lower,e.modelId.upper=this.batchModelIdPair.upper,e}getModelIdPair(t,e){return e.lower=this.batchModelIdPair.lower,e.upper=this.batchModelIdPair.upper,e}findElementId(t){if(!(t>=this.numFeatures))return this.readId(3*t)}get isUniform(){return this.numFeatures===1}getUniform(t){return this.isUniform?this.getFeature(0,t):void 0}get isVolumeClassifier(){return wi.VolumeClassifier===this.type}get isPlanarClassifier(){return wi.VolumeClassifier===this.type}get isClassifier(){return this.isVolumeClassifier||this.isPlanarClassifier}unpack(){const t=new Da(this.numFeatures,this.batchModelId),e=Li.create();for(let n=0;n<this.numFeatures;n++)this.getFeature(n,e),t.insertWithIndex(new cs(e.elementId,e.subCategoryId,e.geometryClass),n);return t}populateAnimationNodeIds(t,e){this.animationNodeIds,this.animationNodeIds=dl(this,t,e)}*iterator(t){for(let e=0;e<this.numFeatures;e++)this.getPackedFeature(e,t),t.index=e,yield t}iterable(t){return{[Symbol.iterator]:()=>this.iterator(t)}}get _subCategoriesOffset(){return this.numFeatures*3}readId(t){return $t.fromUint32Pair(this.data[t],this.data[t+1])}}function cl(){const u={upper:0,lower:0};return{modelId:{...u},elementId:{...u},subCategoryId:{...u},geometryClass:Tn.Primary,animationNodeId:0}}const ll=cl();function dl(u,t,e){let n;const i=yo.createWithIndex();for(const s of u.iterable(i)){const r=t(s);if(r!==0){if(!n){const o=u.numFeatures;n=e<256?new Uint8Array(o):e<65536?new Uint16Array(o):new Uint32Array(o)}n[s.index]=r}}return n}class cs{elementId;subCategoryId;geometryClass;constructor(t=$t.invalid,e=$t.invalid,n=Tn.Primary){this.elementId=t,this.subCategoryId=e,this.geometryClass=n}get isDefined(){return!$t.isInvalid(this.elementId)||!$t.isInvalid(this.subCategoryId)||this.geometryClass!==Tn.Primary}get isUndefined(){return!this.isDefined}equals(t){return this.compare(t)===0}compare(t){if(this===t)return 0;let e=Et(this.geometryClass,t.geometryClass);return e===0&&(e=Ss(this.elementId,t.elementId),e===0&&(e=Ss(this.subCategoryId,t.subCategoryId))),e}}var Li;(function(u){function t(){return{modelId:$t.invalid,elementId:$t.invalid,subCategoryId:$t.invalid,geometryClass:Tn.Primary}}u.create=t;function e(i){return!$t.isInvalid(i.modelId)||!$t.isInvalid(i.elementId)||!$t.isInvalid(i.subCategoryId)||i.geometryClass!==Tn.Primary}u.isDefined=e;function n(i,s,r){return s.modelId=r??$t.fromUint32PairObject(i.modelId),s.elementId=$t.fromUint32PairObject(i.elementId),s.subCategoryId=$t.fromUint32PairObject(i.subCategoryId),s.geometryClass=i.geometryClass,s}u.unpack=n})(Li||(Li={}));var yo;(function(u){function t(){const n={upper:0,lower:0};return{modelId:{...n},elementId:{...n},subCategoryId:{...n},geometryClass:Tn.Primary,animationNodeId:0}}u.create=t;function e(){const n=t();return n.index=0,n}u.createWithIndex=e})(yo||(yo={}));var wi;(function(u){u[u.Primary=0]="Primary",u[u.VolumeClassifier=1]="VolumeClassifier",u[u.PlanarClassifier=2]="PlanarClassifier"})(wi||(wi={}));class Da extends Fr{modelId;type;constructor(t,e=$t.invalid,n=wi.Primary){super((i,s)=>i.compare(s),t),this.modelId=e,this.type=n}get maxFeatures(){return this._maximumSize}get anyDefined(){return this.length>1||this.length===1&&this._array[0].value.isDefined}get isUniform(){return this.length===1}get uniform(){return this.length===1?this._array[0].value:void 0}get isVolumeClassifier(){return wi.VolumeClassifier===this.type}get isPlanarClassifier(){return wi.PlanarClassifier===this.type}findFeature(t){for(const e of this._array)if(e.index===t)return e.value}insertWithIndex(t,e){const n=this.lowerBound(t);n.equal,this.isFull;const i=new Bo(t,e);this._array.splice(n.index,0,i)}getArray(){return this._array}pack(){return pr.pack(this)}}class hl{colors;indices;isOpaque;constructor(t,e,n){this.colors=new Uint32Array(t.buffer),this.indices=Uint16Array.from(e),this.isOpaque=!n}}class Xa{_color;get hasAlpha(){return!this._color.isOpaque}get isUniform(){return this._color instanceof lt}get numColors(){return this.isUniform?1:this.nonUniform.colors.length}constructor(){this._color=lt.white}reset(){this._color=lt.white}get uniform(){return this.isUniform?this._color:void 0}initUniform(t){this._color=typeof t=="number"?lt.fromJSON(t):t}get nonUniform(){return this.isUniform?void 0:this._color}initNonUniform(t,e,n){this._color=new hl(t,e,n)}}var kn;(function(u){u[u.Empty=0]="Empty",u[u.Uniform=1]="Uniform",u[u.NonUniform=2]="NonUniform"})(kn||(kn={}));class Po{type=kn.Empty;featureID=0;featureIDs;get isUniform(){return kn.Uniform===this.type}get isEmpty(){return kn.Empty===this.type}reset(){this.type=kn.Empty,this.featureID=0,this.featureIDs=void 0}}var b;(function(u){u[u._000=0]="_000",u[u._100=1]="_100",u[u._010=2]="_010",u[u._110=3]="_110",u[u._001=4]="_001",u[u._101=5]="_101",u[u._011=6]="_011",u[u._111=7]="_111",u[u.LeftBottomRear=0]="LeftBottomRear",u[u.RightBottomRear=1]="RightBottomRear",u[u.LeftTopRear=2]="LeftTopRear",u[u.RightTopRear=3]="RightTopRear",u[u.LeftBottomFront=4]="LeftBottomFront",u[u.RightBottomFront=5]="RightBottomFront",u[u.LeftTopFront=6]="LeftTopFront",u[u.RightTopFront=7]="RightTopFront",u[u.CORNER_COUNT=8]="CORNER_COUNT"})(b||(b={}));const xr=[new y(0,0,0),new y(1,0,0),new y(0,1,0),new y(1,1,0),new y(0,0,1),new y(1,0,1),new y(0,1,1),new y(1,1,1)];xr.forEach(u=>Object.freeze(u)),Object.freeze(xr);const ul=new y(.5,.5,.5);Object.freeze(ul);class ls{points=[];constructor(){for(let t=0;t<8;++t)this.points[t]=xr[t].clone()}initNpc(){for(let t=0;t<8;++t)y.createFrom(xr[t],this.points[t]);return this}getCorner(t){return this.points[t]}getCenter(){return this.getCorner(b.RightTopFront).interpolate(.5,this.getCorner(b.LeftBottomRear))}distance(t,e){return this.getCorner(t).distance(this.getCorner(e))}getFraction(){return f.safeDivideFraction(this.distance(b.LeftTopFront,b.RightBottomFront),this.distance(b.LeftTopRear,b.RightBottomRear),0)}multiply(t){t.multiplyPoint3dArrayInPlace(this.points)}translate(t){for(const e of this.points)e.plus(t,e)}transformBy(t,e){return e=e||new ls,t.multiplyPoint3dArray(this.points,e.points),e}toRange(t){return J.createArray(this.points,t)}clone(t){return t=t||new ls,t.setFrom(this),t}setFrom(t){this.setFromCorners(t.points)}setFromCorners(t){for(let e=0;e<8;++e)this.points[e].setFrom(t[e])}scaleAboutCenter(t){const e=this.clone(),n=.5*(1+t);e.points[b._111].interpolate(n,e.points[b._000],this.points[b._000]),e.points[b._011].interpolate(n,e.points[b._100],this.points[b._100]),e.points[b._101].interpolate(n,e.points[b._010],this.points[b._010]),e.points[b._001].interpolate(n,e.points[b._110],this.points[b._110]),e.points[b._110].interpolate(n,e.points[b._001],this.points[b._001]),e.points[b._010].interpolate(n,e.points[b._101],this.points[b._101]),e.points[b._100].interpolate(n,e.points[b._011],this.points[b._011]),e.points[b._000].interpolate(n,e.points[b._111],this.points[b._111])}get frontCenter(){return this.getCorner(b.LeftBottomFront).interpolate(.5,this.getCorner(b.RightTopFront))}get rearCenter(){return this.getCorner(b.LeftBottomRear).interpolate(.5,this.getCorner(b.RightTopRear))}scaleXYAboutCenter(t){const e=this.frontCenter,n=this.rearCenter;e.interpolate(t,this.points[b.LeftTopFront],this.points[b.LeftTopFront]),e.interpolate(t,this.points[b.RightTopFront],this.points[b.RightTopFront]),e.interpolate(t,this.points[b.LeftBottomFront],this.points[b.LeftBottomFront]),e.interpolate(t,this.points[b.RightBottomFront],this.points[b.RightBottomFront]),n.interpolate(t,this.points[b.LeftTopRear],this.points[b.LeftTopRear]),n.interpolate(t,this.points[b.RightTopRear],this.points[b.RightTopRear]),n.interpolate(t,this.points[b.LeftBottomRear],this.points[b.LeftBottomRear]),n.interpolate(t,this.points[b.RightBottomRear],this.points[b.RightBottomRear])}toMap4d(){const t=this.getCorner(b.LeftBottomRear),e=t.vectorTo(this.getCorner(b.RightBottomRear)),n=t.vectorTo(this.getCorner(b.LeftTopRear)),i=t.vectorTo(this.getCorner(b.LeftBottomFront));return qe.createVectorFrustum(t,e,n,i,this.getFraction())}getRotation(t){const e=this.getCorner(b.LeftBottomRear),n=e.vectorTo(this.getCorner(b.RightBottomRear)),i=e.vectorTo(this.getCorner(b.LeftTopRear)),s=C.createRigidFromColumns(n,i,mt.XYZ,t);return s&&s.transposeInPlace(),s}getEyePoint(t){const e=this.getFraction();if(Math.abs(e-1)<1e-8)return;const n=this.getCorner(b.LeftBottomRear),i=n.vectorTo(this.getCorner(b.LeftBottomFront));return n.plusScaled(i,1/(1-e),t)}invalidate(){for(let t=0;t<8;++t)this.points[t].set(0,0,0)}equals(t){for(let e=0;e<8;++e)if(!this.points[e].isExactEqual(t.points[e]))return!1;return!0}isSame(t){for(let e=0;e<8;++e)if(!this.points[e].isAlmostEqual(t.points[e]))return!1;return!0}initFromRange(t){const e=i=>i.z!==void 0?i.z:0,n=this.points;n[0].x=n[2].x=n[4].x=n[6].x=t.low.x,n[1].x=n[3].x=n[5].x=n[7].x=t.high.x,n[0].y=n[1].y=n[4].y=n[5].y=t.low.y,n[2].y=n[3].y=n[6].y=n[7].y=t.high.y,n[0].z=n[1].z=n[2].z=n[3].z=e(t.low),n[4].z=n[5].z=n[6].z=n[7].z=e(t.high)}static fromRange(t,e){const n=e!==void 0?e:new ls;return n.initFromRange(t),n}get hasMirror(){const t=this.points,e=t[b._000].vectorTo(t[b._001]),n=t[b._000].vectorTo(t[b._010]),i=t[b._000].vectorTo(t[b._100]);return e.tripleProduct(n,i)>0}fixPointOrder(){if(!this.hasMirror)return;const t=this.points;for(let e=0;e<8;e+=2){const n=t[e];t[e]=t[e+1],t[e+1]=n}}getRangePlanes(t,e,n){const i=vt.createEmpty(),s=P.create();return P.createCrossProductToPoints(this.points[5],this.points[3],this.points[1],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[1])-n)),P.createCrossProductToPoints(this.points[2],this.points[4],this.points[0],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[0])-n)),P.createCrossProductToPoints(this.points[3],this.points[6],this.points[2],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[2])-n)),P.createCrossProductToPoints(this.points[4],this.points[1],this.points[0],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[0])-n)),e&&(P.createCrossProductToPoints(this.points[1],this.points[2],this.points[0],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[0])-n))),t&&(P.createCrossProductToPoints(this.points[6],this.points[5],this.points[4],s),s.normalizeInPlace()&&i.addPlaneToConvexSet(H.createNormalAndDistance(s,s.dotProduct(this.points[4])-n))),i}getIntersectionWithPlane(t){const n=H.createPlane(t).intersectRange(this.toRange(),!0);if(n===void 0)return;const i=this.getRangePlanes(!1,!1,0),s=new W,r=new W;return i.polygonClip(n,r,s),r.length<4?void 0:r.getPoint3dArray()}}var xn;(function(u){u[u.None=0]="None",u[u.ByView=1]="ByView",u[u.Always=2]="Always",u[u.Behind=4]="Behind",u[u.Blanking=6]="Blanking",u[u.Background=8]="Background"})(xn||(xn={}));class Ai{fillFlags=xn.None;linePixels=Hn.Solid;rasterWidth=1;lineColor=lt.black;fillColor=lt.black;material;gradient;setLineTransparency(t){this.lineColor=this.lineColor.withTransparency(t)}setFillTransparency(t){this.fillColor=this.fillColor.withTransparency(t)}clone(t){return t=t??new Ai,t.fillFlags=this.fillFlags,t.linePixels=this.linePixels,t.rasterWidth=this.rasterWidth,t.lineColor=this.lineColor,t.fillColor=this.fillColor,t.material=this.material,t.gradient=this.gradient,t}static fromSymbology(t,e,n,i=Hn.Solid){const s=new Ai;return s.lineColor=t,s.fillColor=e,s.rasterWidth=n,s.linePixels=i,s}static fromBlankingFill(t){const e=new Ai;return e.fillColor=t,e.fillFlags=xn.Blanking,e}}const Ya=new Uint16Array(1);function fl(u,t,e){return u<t?t:u>e?e:u}function Na(u){return za(.5+(fl(u,-1,1)*.5+.5)*255)}function za(u){return Ya[0]=u,Ya[0]}function _r(u){return u<0?-1:1}class Ci{value;constructor(t){this.value=za(t)}static encode(t){return this.encodeXYZ(t.x,t.y,t.z)}static encodeXYZ(t,e,n){const i=Math.abs(t)+Math.abs(e)+Math.abs(n);let s=t/i,r=e/i;if(n<0){const o=s,a=r;s=(1-Math.abs(a))*_r(o),r=(1-Math.abs(o))*_r(a)}return Na(r)<<8|Na(s)}static fromVector(t){return new Ci(this.encode(t))}decode(){return Ci.decodeValue(this.value)}static decodeValue(t,e){let n=t&255,i=t>>8;n=n/255*2-1,i=i/255*2-1;const s=1-(Math.abs(n)+Math.abs(i));let r;if(e===void 0?r=new P(n,i,s):(r=e,r.x=n,r.y=i,r.z=s),r.z<0){const o=r.x,a=r.y;r.x=(1-Math.abs(a))*_r(o),r.y=(1-Math.abs(o))*_r(a)}return r.normalizeInPlace(),r}}class gl{first;second;constructor(t,e){this.first=t,this.second=e}}var dt;(function(u){u.rangeScale16=65535,u.rangeScale8=255;function t(o,a=u.rangeScale16){return o===0?o:a/o}u.computeScale=t;function e(o,a=u.rangeScale16){return o>=0&&o<a+1}u.isInRange=e;function n(o,a,c,l=u.rangeScale16){return Math.floor(Math.max(0,Math.min(l,.5+(o-a)*c)))}u.quantize=n;function i(o,a,c,l=u.rangeScale16){return e(n(o,a,c,l))}u.isQuantizable=i;function s(o,a,c){return c===0?a:a+o/c}u.unquantize=s;function r(o){return e(o)&&o===Math.floor(o)}u.isQuantized=r})(dt||(dt={}));class di{origin=new D;scale=new D;constructor(t=0,e=0,n=0,i=0){this.setFrom(t,e,n,i)}setFrom(t,e,n,i){this.origin.x=t,this.origin.y=e,this.scale.x=n,this.scale.y=i}copyFrom(t){this.setFrom(t.origin.x,t.origin.y,t.scale.x,t.scale.y)}clone(t){const e=t!==void 0?t:new di;return e.copyFrom(this),e}setFromRange(t,e=dt.rangeScale16){t.isNull?this.origin.x=this.origin.y=this.scale.x=this.scale.y=0:this.setFrom(t.low.x,t.low.y,dt.computeScale(t.high.x-t.low.x,e),dt.computeScale(t.high.y-t.low.y,e))}static fromRange(t,e,n=dt.rangeScale16){const i=e!==void 0?e:new di;return i.setFromRange(t,n),i}unquantize(t,e,n){return n=n??new D,n.x=dt.unquantize(t,this.origin.x,this.scale.x),n.y=dt.unquantize(e,this.origin.y,this.scale.y),n}static fromNormalizedRange(t=dt.rangeScale16){return di.fromRange(Rt.createArray([D.create(-1,-1),D.create(1,1)]),void 0,t)}static fromZeroToOne(t=dt.rangeScale16){return di.fromRange(Rt.createArray([D.create(0,0),D.create(1,1)]),void 0,t)}static fromOriginAndScale(t,e,n,i){return new di(t,e,n,i)}get rangeDiagonal(){return Q.createFrom({x:this.scale.x===0?0:dt.rangeScale16/this.scale.x,y:this.scale.y===0?0:dt.rangeScale16/this.scale.y})}isQuantizable(t){return dt.isQuantizable(t.x,this.origin.x,this.scale.x)&&dt.isQuantizable(t.y,this.origin.y,this.scale.y)}toJSON(){return{origin:{x:this.origin.x,y:this.origin.y},scale:{x:this.scale.x,y:this.scale.y}}}static fromJSON(t){return this.fromOriginAndScale(t.origin.x,t.origin.y,t.scale.x,t.scale.y)}}class hi{_x=0;_y=0;get x(){return this._x}set x(t){dt.isQuantized(t),this._x=t}get y(){return this._y}set y(t){dt.isQuantized(t),this._y=t}constructor(){}init(t,e){this.x=dt.quantize(t.x,e.origin.x,e.scale.x),this.y=dt.quantize(t.y,e.origin.y,e.scale.y)}static create(t,e){const n=new hi;return n.init(t,e),n}copyFrom(t){this.x=t.x,this.y=t.y}clone(t){const e=t!==void 0?t:new hi;return e.copyFrom(this),e}setFromScalars(t,e){this.x=t,this.y=e}static fromScalars(t,e){const n=new hi;return n.setFromScalars(t,e),n}unquantize(t,e){const n=e!==void 0?e:new D;return n.x=dt.unquantize(this.x,t.origin.x,t.scale.x),n.y=dt.unquantize(this.y,t.origin.y,t.scale.y),n}}var Va;(function(u){const t=new hi;function e(i,s,r){const o=s*2,a=i[o+0],c=i[o+1];if(a===void 0||c===void 0)throw new Error("Index out of range");return r=r??new hi,r.setFromScalars(a,c),r}u.getQPoint=e;function n(i,s,r){return e(i.points,s,t).unquantize(i.params,r)}u.unquantizePoint=n})(Va||(Va={}));class rn{origin=new y;scale=new y;constructor(t=0,e=0,n=0,i=0,s=0,r=0){this.setFrom(t,e,n,i,s,r)}setFrom(t,e,n,i,s,r){this.origin.x=t,this.origin.y=e,this.origin.z=n,this.scale.x=i,this.scale.y=s,this.scale.z=r}copyFrom(t){this.setFrom(t.origin.x,t.origin.y,t.origin.z,t.scale.x,t.scale.y,t.scale.z)}clone(t){const e=t!==void 0?t:new rn;return e.copyFrom(this),e}setFromOriginAndScale(t,e){this.setFrom(t.x,t.y,t.z,e.x,e.y,e.z)}setFromRange(t,e=dt.rangeScale16){t.isNull?(this.origin.x=this.origin.y=this.origin.z=0,this.scale.x=this.scale.y=this.scale.z=0):this.setFrom(t.low.x,t.low.y,t.low.z,dt.computeScale(t.high.x-t.low.x,e),dt.computeScale(t.high.y-t.low.y,e),dt.computeScale(t.high.z-t.low.z,e))}unquantize(t,e,n,i){const s=i!==void 0?i:new y;return s.x=dt.unquantize(t,this.origin.x,this.scale.x),s.y=dt.unquantize(e,this.origin.y,this.scale.y),s.z=dt.unquantize(n,this.origin.z,this.scale.z),s}static fromRange(t,e,n=dt.rangeScale16){const i=e!==void 0?e:new rn;return i.setFromRange(t,n),i}static fromOriginAndScale(t,e,n){const i=n!==void 0?n:new rn;return i.setFromOriginAndScale(t,e),i}static fromNormalizedRange(t=dt.rangeScale16){return rn.fromRange(J.createArray([y.create(-1,-1,-1),y.create(1,1,1)]),void 0,t)}static fromZeroToOne(t=dt.rangeScale16){return rn.fromRange(J.createArray([y.create(0,0,0),y.create(1,1,1)]),void 0,t)}get rangeDiagonal(){return P.createFrom({x:this.scale.x===0?0:dt.rangeScale16/this.scale.x,y:this.scale.y===0?0:dt.rangeScale16/this.scale.y,z:this.scale.z===0?0:dt.rangeScale16/this.scale.z})}isQuantizable(t){return dt.isQuantizable(t.x,this.origin.x,this.scale.x)&&dt.isQuantizable(t.y,this.origin.y,this.scale.y)&&dt.isQuantizable(t.z,this.origin.z,this.scale.z)}computeRange(t){const e=J.createNull(t);return e.extendPoint(this.origin),e.extendPoint(this.origin.plus(this.rangeDiagonal)),e}toJSON(){return{origin:{x:this.origin.x,y:this.origin.y,z:this.origin.z},scale:{x:this.scale.x,y:this.scale.y,z:this.scale.z}}}static fromJSON(t,e){return this.fromOriginAndScale(y.fromJSON(t.origin),y.fromJSON(t.scale),e)}}class Jn{_x=0;_y=0;_z=0;get x(){return this._x}set x(t){dt.isQuantized(t),this._x=t}get y(){return this._y}set y(t){dt.isQuantized(t),this._y=t}get z(){return this._z}set z(t){dt.isQuantized(t),this._z=t}constructor(){}init(t,e){this.x=dt.quantize(t.x,e.origin.x,e.scale.x),this.y=dt.quantize(t.y,e.origin.y,e.scale.y),this.z=dt.quantize(t.z,e.origin.z,e.scale.z)}static create(t,e){const n=new Jn;return n.init(t,e),n}copyFrom(t){this.x=t.x,this.y=t.y,this.z=t.z}clone(t){const e=t!==void 0?t:new Jn;return e.copyFrom(this),e}setFromScalars(t,e,n){this.x=t,this.y=e,this.z=n}static fromScalars(t,e,n,i){const s=i===void 0?new Jn:i;return s.setFromScalars(t,e,n),s}unquantize(t,e){const n=e!==void 0?e:new y;return n.x=dt.unquantize(this.x,t.origin.x,t.scale.x),n.y=dt.unquantize(this.y,t.origin.y,t.scale.y),n.z=dt.unquantize(this.z,t.origin.z,t.scale.z),n}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}compare(t){let e=this.x-t.x;return e===0&&(e=this.y-t.y,e===0&&(e=this.z-t.z)),e}}var Oa;(function(u){const t=new Jn;function e(i,s,r){const o=s*3,a=i[o+0],c=i[o+1],l=i[o+2];if(a===void 0||c===void 0||l===void 0)throw new Error("Index out of range");return r=r??new Jn,r.setFromScalars(a,c,l),r}u.getQPoint=e;function n(i,s,r){return e(i.points,s,t).unquantize(i.params,r)}u.unquantizePoint=n})(Oa||(Oa={}));class on{params;_list=[];get list(){return this._list}constructor(t){this.params=t?t.clone():rn.fromRange(J.createNull())}static fromPoints(t,e){let n;const i=rn.fromRange(J.createArray(t));e?(n=e,n.reset(i)):n=new on(i);for(const s of t)n.add(s);return n}clear(){this._list.length=0}reset(t){this.clear(),this.params.copyFrom(t)}add(t){this._list.push(Jn.create(t,this.params))}push(t){this._list.push(t.clone())}get length(){return this._list.length}unquantize(t,e){return t<this.length,t<this.length?this._list[t].unquantize(this.params,e):e!==void 0?e:new y}requantize(t){for(let e=0;e<this.length;e++){const n=this.unquantize(e);this._list[e].init(n,t)}this.params.copyFrom(t)}toTypedArray(){const t=new Uint16Array(this.length*3),e=this._list;for(let n=0;n<this.length;n++){const i=e[n];t[n*3+0]=i.x,t[n*3+1]=i.y,t[n*3+2]=i.z}return t}fromTypedArray(t,e){this.params.setFromRange(t),this._list.length=e.length/3;for(let n=0,i=0;n<this.list.length;n++)this._list[n]=Jn.fromScalars(e[i++],e[i++],e[i++])}static createFrom(t,e){const n=new on(e);for(const i of t)n.add(i);return n}[Symbol.iterator](){return this.list[Symbol.iterator]()}}var ds;(function(u){u[u.Normal=0]="Normal",u[u.Edge=1]="Edge",u[u.Outline=2]="Outline"})(ds||(ds={}));class ml{key;textureMapping;_guid;constructor(t){this.key=t.key,this.textureMapping=t.textureMapping,this._guid=vs.createValue()}get hasTexture(){return this.textureMapping?.texture!==void 0}compare(t){return Ss(this._guid,t._guid)}}class ui{type;_guid;get isTileSection(){return ui.Type.TileSection===this.type}get isGlyph(){return ui.Type.Glyph===this.type}get isSkyBox(){return ui.Type.SkyBox===this.type}constructor(t){this.type=t,this._guid=vs.createValue()}[Symbol.dispose](){this.dispose()}compare(t){return Ss(this._guid,t._guid)}}(function(u){(function(t){t[t.Normal=0]="Normal",t[t.Glyph=1]="Glyph",t[t.TileSection=2]="TileSection",t[t.SkyBox=3]="SkyBox",t[t.FilteredTileSection=4]="FilteredTileSection",t[t.ThematicGradient=5]="ThematicGradient"})(u.Type||(u.Type={}))})(ui||(ui={}));function pl(u,t){return fi((e,n)=>e.compare(n),u.normalMap,t.normalMap)||Lo(u.greenUp,t.greenUp)||sc(u.scale,t.scale)||Lo(u.useConstantLod,t.useConstantLod)}class Ti{texture;normalMapParams;params;constructor(t,e){this.texture=t,this.params=e}computeUVParams(t,e=X.createIdentity()){return this.params.computeUVParams(t,e)}compare(t){return this===t?0:this.texture.compare(t.texture)||this.params.compare(t.params)||fi((e,n)=>pl(e,n),this.normalMapParams,t.normalMapParams)}}(function(u){let t;(function(s){s[s.None=-1]="None",s[s.Parametric=0]="Parametric",s[s.ElevationDrape=1]="ElevationDrape",s[s.Planar=2]="Planar",s[s.DirectionalDrape=3]="DirectionalDrape",s[s.Cubic=4]="Cubic",s[s.Spherical=5]="Spherical",s[s.Cylindrical=6]="Cylindrical",s[s.Solid=7]="Solid",s[s.FrontProject=8]="FrontProject"})(t=u.Mode||(u.Mode={}));class e{transform;constructor(r=1,o=0,a=0,c=0,l=1,d=0){const h=new y(a,d,0),g=C.createRowValues(r,o,0,c,l,0,0,0,1);this.transform=X.createRefs(h,g)}static identity=new e;compare(r){if(this===r)return 0;const o=Et(this.transform.origin.x,r.transform.origin.x)||Et(this.transform.origin.y,r.transform.origin.y);if(o!==0)return o;for(const a of[0,1,3,4]){const c=Et(this.transform.matrix.coffs[a],r.transform.matrix.coffs[a]);if(c!==0)return c}return 0}}u.Trans2x3=e;function n(s,r){return Et(s.repetitions,r.repetitions)||Et(s.offset.x,r.offset.x)||Et(s.offset.y,r.offset.y)||Et(s.minDistClamp,r.minDistClamp)||Et(s.maxDistClamp,r.maxDistClamp)}class i{textureMatrix;weight;mode;worldMapping;useConstantLod;constantLodParams;constructor(r){this.textureMatrix=r?.textureMat2x3??e.identity,this.weight=r?.textureWeight??1,this.mode=r?.mapMode??t.Parametric,this.worldMapping=r?.worldMapping??!1,this.useConstantLod=r?.useConstantLod??!1,this.constantLodParams={repetitions:r?.constantLodProps?.repetitions??1,offset:r?.constantLodProps?.offset??{x:0,y:0},minDistClamp:r?.constantLodProps?.minDistClamp??1,maxDistClamp:r?.constantLodProps?.maxDistClamp??4096*1024*1024}}compare(r){return this===r?0:Et(this.weight,r.weight)||Et(this.mode,r.mode)||Mn(this.worldMapping,r.worldMapping)||Mn(this.useConstantLod,r.useConstantLod)||this.textureMatrix.compare(r.textureMatrix)||n(this.constantLodParams,r.constantLodParams)}computeUVParams(r,o=X.createIdentity()){switch(this.mode){default:case u.Mode.Parametric:return this.computeParametricUVParams(r,this.textureMatrix.transform,!this.worldMapping);case u.Mode.Planar:{const a=r.normalIndex;return a?!this.worldMapping||r.normalIndex!==void 0&&(a[0]!==a[1]||a[0]!==a[2])?this.computeParametricUVParams(r,this.textureMatrix.transform,!this.worldMapping):this.computePlanarUVParams(r,this.textureMatrix.transform):void 0}case u.Mode.ElevationDrape:return this.computeElevationDrapeUVParams(r,this.textureMatrix.transform,o)}}computeParametricUVParams(r,o,a){const c=[];for(let l=0;l<r.numEdgesThisFacet;l++){let d=D.create();(a||!r.tryGetDistanceParameter(l,d))&&(r.tryGetNormalizedParameter(l,d)||(d=ln(r.getParam(l)))),c.push(o.multiplyPoint2d(d))}return c}computePlanarUVParams(r,o){const a=[],c=r.point;let l;if(r.normal===void 0?l=c.getPoint3dAtUncheckedPointIndex(0).crossProductToPoints(c.getPoint3dAtUncheckedPointIndex(1),c.getPoint3dAtUncheckedPointIndex(2)):l=ln(r.normal.getVector3dAtCheckedVectorIndex(0)),!l.normalize(l))return;l.scale(-1,l);const d=P.create(l.y,-l.x,0),h=d.magnitude();d.normalize(d),h<.001&&(l.set(0,0,-1),d.set(1,0,0));const g=d.crossProduct(l).normalize();if(!g)return;const m=r.numEdgesThisFacet;for(let p=0;p<m;p++){const x=P.createFrom(c.getPoint3dAtUncheckedPointIndex(p));a.push(D.create(x.dotProduct(d),x.dotProduct(g))),o.multiplyPoint2d(a[p],a[p])}return a}computeElevationDrapeUVParams(r,o,a){const c=[],l=r.numEdgesThisFacet;for(let d=0;d<l;d++){const h=r.point.getPoint3dAtUncheckedPointIndex(d);a!==void 0&&a.multiplyPoint3d(h,h),c.push(D.createFrom(h)),o.multiplyPoint2d(c[d],c[d])}return c}}u.Params=i})(Ti||(Ti={})),Object.freeze(Ti.Trans2x3.identity);class La{indices;constructor(t=[]){this.indices=t.slice()}addIndex(t){const{indices:e}=this;(e.length===0||e[e.length-1]!==t)&&e.push(t)}clear(){this.indices.length=0}}class Ua{indices=[0,0];constructor(t,e){t===void 0||e===void 0||(t<e?(this.indices[0]=t,this.indices[1]=e):(this.indices[0]=e,this.indices[1]=t))}compareTo(t){let e=this.indices[0]-t.indices[0];return e===0&&(e=this.indices[1]-t.indices[1]),e}}class xl{visible=[];silhouette=[];appearance;polylineGroups=[];silhouetteNormals=[];constructor(){}}class Ba{edges;init(t){return this.clear(),t!==void 0&&0<t.visible.length&&(this.edges=t.visible),this.isValid}clear(){this.edges=void 0}get isValid(){return 0<this.numEdges}get numEdges(){return this.edges!==void 0?this.edges.length:0}}class _l extends Ba{normals;init(t){return this.clear(),t!==void 0&&0<t.silhouette.length&&(this.edges=t.silhouette,this.normals=t.silhouetteNormals),this.isValid}clear(){this.normals=void 0,super.clear()}}class yl{groups;constructor(t){this.init(t)}init(t){return this.groups=t?.filter(e=>e.polylines.length>0),this.isValid}get numGroups(){return this.groups?.length??0}get isValid(){return this.numGroups>0}clear(){this.groups=void 0}}const hs=Symbol.for("Implementations of this interface can only be obtained from the containing package");function Pl(u){return`${u}_core-frontend_INTERNAL_ONLY_DO_NOT_USE`}const ge=Symbol.for(Pl("accumulator"));var Ye;(function(u){u[u.ViewBackground=0]="ViewBackground",u[u.Scene=1]="Scene",u[u.WorldDecoration=2]="WorldDecoration",u[u.WorldOverlay=3]="WorldOverlay",u[u.ViewOverlay=4]="ViewOverlay"})(Ye||(Ye={}));var We;(function(u){u[u.Mesh=0]="Mesh",u[u.Polyline=1]="Polyline",u[u.Point=2]="Point"})(We||(We={}));var yr;(function(u){u.vertex=.1,u.facetArea=.1})(yr||(yr={}));class Pr{indices=new Uint32Array(3);visible=[!0,!0,!0];singleSided;constructor(t=!0){this.singleSided=t}setIndices(t,e,n){this.indices[0]=t,this.indices[1]=e,this.indices[2]=n}setEdgeVisibility(t,e,n){this.visible[0]=t,this.visible[1]=e,this.visible[2]=n}isEdgeVisible(t){return this.visible[t]}get isDegenerate(){return this.indices[0]===this.indices[1]||this.indices[0]===this.indices[2]||this.indices[1]===this.indices[2]}}class Il{_flags=[];indices=[];get length(){return this._flags.length}get isEmpty(){return this.length===0}addTriangle(t){let e=t.singleSided?1:0;for(let n=0;n<3;n++)t.isEdgeVisible(n)&&(e|=2<<n),this.indices.push(t.indices[n]);this._flags.push(e)}addFromTypedArray(t,e=0){for(let n=0;n<t.length;)this.indices.push(t[n++]),this.indices.push(t[n++]),this.indices.push(t[n++]),this._flags.push(e)}getTriangle(t,e){const n=e!==void 0?e:new Pr;if(t>this.length)return new Pr;const i=this._flags[t];n.singleSided=(i&1)!==0;const s=t*3;for(let r=0;r<3;r++)n.indices[r]=this.indices[s+r],n.visible[r]=(i&2<<r)!==0;return n}}class vl{_sortedIndices=new Uint32Array(3);constructor(t){const e=t.indices,n=this._sortedIndices;e[0]<e[1]?e[0]<e[2]?(n[0]=e[0],e[1]<e[2]?(n[1]=e[1],n[2]=e[2]):(n[1]=e[2],n[2]=e[1])):(n[0]=e[2],n[1]=e[0],n[2]=e[1]):e[1]<e[2]?(n[0]=e[1],e[0]<e[2]?(n[1]=e[0],n[2]=e[2]):(n[1]=e[2],n[2]=e[0])):(n[0]=e[2],n[1]=e[1],n[2]=e[0]),n[0]<n[1],n[1]<n[2]}compare(t){let e=0;for(let n=0;n<3&&(e=this._sortedIndices[n]-t._sortedIndices[n],e===0);n++);return e}}class Sl extends jn{constructor(){super((t,e)=>t.compare(e))}insertKey(t,e){return this.insert(new vl(t),e)}}function Io(u,t,e){let n=ki(u.x,t.x,e.x);return n===0&&(n=ki(u.y,t.y,e.y),n===0&&(n=ki(u.z,t.z,e.z))),n}function Za(u,t){return fi((e,n)=>e.compare(n),u,t)}class vo{position;normal;uvParam;fillColor;feature;constructor(t,e,n,i,s){this.position=t.clone(),this.fillColor=e,this.normal=n,this.uvParam=i?.clone(),this.feature=s}static create(t){return new vo(t.position,t.fillColor,t.normal,t.uvParam,t.feature)}equals(t,e){return this.fillColor!==t.fillColor||Za(this.feature,t.feature)!==0||this.normal!==void 0&&(t.normal,this.normal.value!==t.normal.value)||Io(this.position,t.position,e)!==0?!1:this.uvParam!==void 0?(t.uvParam,this.uvParam.isAlmostEqual(t.uvParam,1e-4)):!0}compare(t,e){if(this===t)return 0;let n=this.fillColor-t.fillColor;return n===0&&(n=Io(this.position,t.position,e),n===0&&(n=Za(this.feature,t.feature),n===0&&(this.normal!==void 0&&(t.normal,n=this.normal.value-t.normal.value),n===0&&this.uvParam!==void 0&&(t.uvParam,n=ki(this.uvParam.x,t.uvParam.x),n===0&&(n=ki(this.uvParam.x,t.uvParam.y)))))),n}}class wl extends Fr{_tolerance;constructor(t){super((e,n)=>e.compare(n,t)),this._tolerance=t}insertKey(t,e){return this.insert(vo.create(t),e)}arePositionsAlmostEqual(t,e){return this.comparePositions(t,e)===0}comparePositions(t,e){return Io(t.position,e.position,this._tolerance)}}class Ir extends Fr{_hasTransparency=!1;constructor(){super(Et,65535)}hasColor(t){return this.indexOf(t)!==-1}insert(t){return this.isEmpty?this._hasTransparency=Ir.isTranslucent(t):(Ir.isTranslucent(t),this.hasTransparency,void 0),super.insert(t)}get hasTransparency(){return this._hasTransparency}get isUniform(){return this.length===1}toColorIndex(t,e){if(t.reset(),this.length!==0)if(this.length===1)t.initUniform(this._array[0].value);else{const n=new Uint32Array(this.length);for(const i of this._array)n[i.index]=i.value;t.initNonUniform(n,e,this.hasTransparency)}}static isTranslucent(t){return!lt.isOpaque(t)}}function Al(u,t){return fi((e,n)=>e.compare(n),u,t)}function Cl(u,t){return fi((e,n)=>e.compare(n),u,t)}class kt{static minTransparency=15;type=kt.Type.Mesh;material;gradient;_textureMapping;lineColor;fillColor;width;linePixels;fillFlags;ignoreLighting;constructor(t,e,n,i=0,s=Hn.Solid,r=xn.None,o,a,c=!1,l){this.type=t,this.material=o,this.gradient=a,this.lineColor=kt.adjustTransparency(e),this.fillColor=kt.adjustTransparency(n),this.width=i,this.linePixels=s,this.fillFlags=r,this.ignoreLighting=c,this._textureMapping=l}static createForType(t,e,n,i=!1){const s=kt.adjustTransparency(e.lineColor);switch(t){case kt.Type.Mesh:{let r;if(e.gradient!==void 0&&n!==void 0){const o=n(e.gradient);o!==void 0&&(r=new Ti(o,new Ti.Params))}return new kt(t,s,kt.adjustTransparency(e.fillColor),e.rasterWidth,e.linePixels,e.fillFlags,e.material,e.gradient,i,r)}case kt.Type.Linear:return new kt(t,s,s,e.rasterWidth,e.linePixels);default:return new kt(t,s,s,0,Hn.Solid,xn.Always,void 0,void 0,!0)}}static createForMesh(t,e,n){return kt.createForType(kt.Type.Mesh,t,n,e)}static createForLinear(t){return kt.createForType(kt.Type.Linear,t)}static createForText(t){return kt.createForType(kt.Type.Text,t)}get regionEdgeType(){return this.hasBlankingFill?kt.RegionEdgeType.None:this.gradient!==void 0&&this.gradient.flags!==void 0?(this.gradient.flags&ci.Flags.Outline)!==0||xn.None===(this.fillFlags&xn.Always)?kt.RegionEdgeType.Outline:kt.RegionEdgeType.None:this.fillColor.equals(this.lineColor)?kt.RegionEdgeType.Default:kt.RegionEdgeType.Outline}get wantRegionOutline(){return kt.RegionEdgeType.Outline===this.regionEdgeType}get hasBlankingFill(){return xn.Blanking===(this.fillFlags&xn.Blanking)}get hasFillTransparency(){return this.fillColor.getAlpha()!==255}get hasLineTransparency(){return this.lineColor.getAlpha()!==255}get textureMapping(){return this.material!==void 0?this.material.textureMapping:this._textureMapping}get isTextured(){return this.textureMapping!==void 0}equals(t,e=kt.ComparePurpose.Strict){return kt.ComparePurpose.Merge===e?this.compareForMerge(t)===0:t===this?!0:!(this.type!==t.type||this.ignoreLighting!==t.ignoreLighting||this.width!==t.width||this.linePixels!==t.linePixels||this.fillFlags!==t.fillFlags||this.wantRegionOutline!==t.wantRegionOutline||this.material!==t.material||this.textureMapping!==t.textureMapping||!this.fillColor.equals(t.fillColor)||!this.lineColor.equals(t.lineColor))}compareForMerge(t){if(t===this)return 0;let e=Et(this.type,t.type);return e===0&&(e=Mn(this.ignoreLighting,t.ignoreLighting),e===0&&(e=Et(this.width,t.width),e===0&&(e=Et(this.linePixels,t.linePixels),e===0&&(e=Et(this.fillFlags,t.fillFlags),e===0&&(e=Mn(this.wantRegionOutline,t.wantRegionOutline),e===0&&(e=Mn(this.hasFillTransparency,t.hasFillTransparency),e===0&&(e=Mn(this.hasLineTransparency,t.hasLineTransparency),e===0&&(e=Al(this.material,t.material),e===0&&this.material===void 0&&this.isTextured&&(e=Cl(this.textureMapping,t.textureMapping)))))))))),e}static adjustTransparency(t){return t.colors.t<kt.minTransparency?t.withTransparency(0):t}}(function(u){(function(t){t[t.Mesh=0]="Mesh",t[t.Linear=1]="Linear",t[t.Text=2]="Text"})(u.Type||(u.Type={})),(function(t){t[t.None=0]="None",t[t.Default=1]="Default",t[t.Outline=2]="Outline"})(u.RegionEdgeType||(u.RegionEdgeType={})),(function(t){t[t.Merge=0]="Merge",t[t.Strict=1]="Strict"})(u.ComparePurpose||(u.ComparePurpose={}))})(kt||(kt={}));function Tl(u){if(!u.polylines||u.polylines.length===0)return;const t=[];for(const s of u.polylines)s.indices.length>0&&t.push(s.indices);if(t.length===0)return;const e={is2d:u.is2d,isPlanar:u.isPlanar,isDisjoint:u.type===We.Point};u.displayParams.regionEdgeType===kt.RegionEdgeType.Outline&&(!u.displayParams.gradient||u.displayParams.gradient.isOutlined?e.type=ds.Edge:e.type=ds.Outline);const n=new Xa;u.colorMap.toColorIndex(n,u.colors);const i=new Po;return u.toFeatureIndex(i),{width:u.displayParams.width,linePixels:u.displayParams.linePixels,flags:e,polylines:t,points:u.points,colors:n,features:i,cumulativeDistances:u.cumulativeDistances}}class kl{edges=new Ba;silhouettes=new _l;polylines=new yl;width=0;linePixels=Hn.Solid;color;clear(){this.edges.clear(),this.silhouettes.clear(),this.polylines.clear(),this.width=0,this.linePixels=Hn.Solid}get isValid(){return this.edges.isValid||this.silhouettes.isValid||this.polylines.isValid}}function Fl(u){if(!u.triangles||u.triangles.isEmpty||u.points.length===0)return;const t=u.displayParams.textureMapping?.texture,e=u.displayParams.textureMapping?.params?.useConstantLod,n=u.displayParams.textureMapping?.params?.constantLodParams,i=t&&u.uvParams.length>0?{texture:t,uvParams:u.uvParams,useConstantLod:e,constantLodParams:n}:void 0,s=new Xa;u.colorMap.toColorIndex(s,u.colors);const r=new Po;u.toFeatureIndex(r);let o;return u.edges&&(o=new kl,o.width=u.edges.appearance?.width??u.displayParams.width,o.linePixels=u.edges.appearance?.linePixels??u.displayParams.linePixels,o.edges.init(u.edges),o.silhouettes.init(u.edges),o.color=u.edges.appearance?.color,o.polylines.init(u.edges.polylineGroups)),{vertIndices:u.triangles.indices,points:u.points,normals:!u.displayParams.ignoreLighting&&u.normals.length>0?u.normals:void 0,textureMapping:i,colors:s,features:r,material:u.displayParams.material,fillFlags:u.displayParams.fillFlags,isPlanar:u.isPlanar,is2d:u.is2d,hasBakedLighting:u.hasBakedLighting===!0,isVolumeClassifier:u.isVolumeClassifier===!0,edges:o,auxChannels:u.auxChannels}}class Ui{_data;points;normals=[];uvParams=[];colorMap=new Ir;colors=[];cumulativeDistances;edges;features;type;is2d;isPlanar;hasBakedLighting;isVolumeClassifier;displayParams;_auxChannels;constructor(t){const{displayParams:e,features:n,type:i,range:s,is2d:r,isPlanar:o}=t;if(this._data=We.Mesh===i?new Il:[],this.displayParams=e,this.features=n?new Ui.Features(n):void 0,this.type=i,this.is2d=r,this.isPlanar=o,this.hasBakedLighting=t.hasBakedLighting===!0,this.isVolumeClassifier=t.isVolumeClassifier===!0,t.quantizePositions)this.points=new on(rn.fromRange(s));else{const a=[];a.range=s;const c=s.center;a.add=l=>{a.push(l.minus(c))},this.points=a}}static create(t){return new Ui(t)}get triangles(){return We.Mesh===this.type?this._data:void 0}get polylines(){return We.Mesh!==this.type?this._data:void 0}get auxChannels(){return this._auxChannels}addAuxChannels(t,e){if(this._auxChannels){if(this._auxChannels.length!==t.length)return;for(let n=0;n<t.length;n++){const i=t[n],s=this._auxChannels[n];if(i.dataType!==s.dataType||i.name!==s.name||i.inputName!==s.inputName)return}}this._auxChannels||(this._auxChannels=t.map(n=>new ca(n.data.map(i=>new Gs(i.input,[])),n.dataType,n.name,n.inputName)));for(let n=0;n<t.length;n++){const i=t[n],s=this._auxChannels[n],r=s.valueCount;for(let o=0;o<i.data.length;o++)s.data[o].copyValues(i.data[o],r,e,s.entriesPerValue)}}toFeatureIndex(t){this.features!==void 0&&this.features.toFeatureIndex(t)}toMeshArgs(){return Fl(this)}toPolylineArgs(){return Tl(this)}addPolyline(t){const{type:e,polylines:n}=this;We.Polyline===e||We.Point,!(We.Polyline===e&&t.indices.length<2)&&n!==void 0&&n.push(t)}addTriangle(t){const{triangles:e,type:n}=this;We.Mesh,e!==void 0&&e.addTriangle(t)}addVertex(t){const{feature:e,position:n,normal:i,uvParam:s,fillColor:r}=t;return this.points.add(n),i!==void 0&&this.normals.push(i),s!==void 0&&this.uvParams.push(s),e&&(this.features,this.features.add(e,this.points.length)),this.colorMap.length===0?(this.colorMap.insert(r),this.colorMap.isUniform,this.colorMap.indexOf(r),void 0):(!this.colorMap.isUniform||!this.colorMap.hasColor(r))&&(this.colors.length===0&&(this.colors.length=this.points.length-1),this.colors.push(this.colorMap.insert(r)),this.colorMap.isUniform,void 0),this.points.length-1}}(function(u){class t{table;indices=[];uniform=0;initialized=!1;constructor(n){this.table=n}add(n,i){const s=this.table.insert(n);if(!this.initialized)this.uniform=s,this.initialized=!0;else if(0<this.indices.length)this.indices.push(s);else{for(;this.indices.length<i-1;)this.indices.push(this.uniform);this.indices.push(s)}}setIndices(n){this.indices.length=0,this.uniform=0,this.initialized=0<n.length,0<n.length,n.length===1?this.uniform=n[0]:1<n.length&&(this.indices=n)}toFeatureIndex(n){const i=n??new Po;return this.initialized?this.indices.length===0?(i.type=kn.Uniform,i.featureID=this.uniform):(i.type=kn.NonUniform,i.featureIDs=new Uint32Array(this.indices)):i.type=kn.Empty,i}}u.Features=t})(Ui||(Ui={}));class qa extends Array{features;range;constructor(t,e){super(),this.features=t,this.range=e}}class So{vertexMap;_triangleSet;_currentPolyface;mesh;tolerance;areaTolerance;tileRange;get currentPolyface(){return this._currentPolyface}get displayParams(){return this.mesh.displayParams}set displayParams(t){this.mesh.displayParams=t}get triangleSet(){return this._triangleSet===void 0&&(this._triangleSet=new Sl),this._triangleSet}constructor(t,e,n,i){this.mesh=t,this.tolerance=e,this.areaTolerance=n,this.tileRange=i;let s;if(t.points instanceof on){const r=t.points.params.unquantize(0,0,0);s=t.points.params.unquantize(1,1,1).minus(r,r)}else s={x:e,y:e,z:e};this.vertexMap=new wl(s)}static create(t){const e=Ui.create(t),{tolerance:n,areaTolerance:i,range:s}=t;return new So(e,n,i,s)}addStrokePointLists(t,e,n,i){for(const s of t)e?this.addPointString(s.points,n,i):this.addPolyline(s.points,n,i)}addFromPolyface(t,e,n){this.beginPolyface(t,e.edgeOptions);const i=t.createVisitor();for(;i.moveToNextFacet();)this.addFromPolyfaceVisitor(i,e,n);this.endPolyface()}addFromPolyfaceVisitor(t,e,n){const{pointCount:i,normalCount:s,paramCount:r,requireNormals:o}=t,{includeParams:a,mappedTexture:c}=e,l=o&&s<i;if(i<3||l)return;const d=a&&r>0,h=i-2,g={...e,triangleCount:h,haveParam:d};for(let m=0;m<h;m++){const p=this.createTriangle(m,t,g,n);p!==void 0&&this.addTriangle(p)}}createTriangleVertices(t,e,n,i){const{point:s,requireNormals:r}=e,{fillColor:o,haveParam:a}=n;let c;if(a&&n.mappedTexture){this.mesh.points.length===0||this.mesh.uvParams.length;const d=n.mappedTexture,h=d.params.textureMatrix.transform;h&&(c=d.computeUVParams(e,h))}const l=[];for(let d=0;d<3;++d){const h=d===0?0:t+d,g=s.getPoint3dAtUncheckedPointIndex(h),m=r?Ci.fromVector(ln(e.getNormal(h))):void 0,p=c?c[h]:void 0;l[d]={position:g,fillColor:o,normal:m,uvParam:p,sourceIndex:h,feature:i}}if(!(this.vertexMap.arePositionsAlmostEqual(l[0],l[1])||this.vertexMap.arePositionsAlmostEqual(l[0],l[2])||this.vertexMap.arePositionsAlmostEqual(l[1],l[2])))return l}createTriangle(t,e,n,i){const s=this.createTriangleVertices(t,e,n,i);if(s===void 0)return;const{edgeVisible:r}=e,o=new Pr;return o.setEdgeVisibility(t===0?r[0]:!1,r[t+1],t===n.triangleCount-1?r[t+2]:!1),s.forEach((a,c)=>{let l;e.auxData?(l=this.mesh.addVertex(a),this.mesh.addAuxChannels(e.auxData.channels,a.sourceIndex)):l=this.addVertex(a),o.indices[c]=l,this.currentPolyface!==void 0&&this.currentPolyface.vertexIndexMap.set(l,e.clientPointIndex(a.sourceIndex))}),o}addPolyline(t,e,n){const{mesh:i}=this,s=new La;for(const r of t)s.addIndex(this.addVertex({position:r,fillColor:e,feature:n}));i.addPolyline(s)}addPointString(t,e,n){const{mesh:i}=this,s=new La;for(const r of t)s.addIndex(this.addVertex({position:r,fillColor:e,feature:n}));i.addPolyline(s)}beginPolyface(t,e){if(!e.generateNoEdges){const n=this.mesh.triangles;this._currentPolyface=new Ml(t,e,n===void 0?0:n.length)}}endPolyface(){const{currentPolyface:t,mesh:e}=this;t!==void 0&&(this._currentPolyface=void 0,Rl(e,t))}addVertex(t,e=!0){const n=i=>this.mesh.addVertex(i);return this.vertexMap.insertKey(t,e?n:void 0)}addTriangle(t){if(t.isDegenerate)return;const e=n=>this.mesh.addTriangle(t);this.triangleSet.insertKey(t,e)}}class _n{type;minCreaseAngle=20*A.radiansPerDegree;get generateAllEdges(){return this.type===_n.Type.AllEdges}get generateNoEdges(){return this.type===_n.Type.NoEdges}get generateCreaseEdges(){return(this.type&_n.Type.CreaseEdges)!==0}get createEdgeChains(){return(this.type&_n.Type.CreateChains)!==0}constructor(t=_n.Type.NoEdges){this.type=t}}(function(u){(function(t){t[t.NoEdges=0]="NoEdges",t[t.CreaseEdges=2]="CreaseEdges",t[t.SmoothEdges=4]="SmoothEdges",t[t.CreateChains=8]="CreateChains",t[t.DefaultEdges=2]="DefaultEdges",t[t.AllEdges=6]="AllEdges"})(u.Type||(u.Type={}))})(_n||(_n={}));class Ml{polyface;edgeOptions;vertexIndexMap=new Map;baseTriangleIndex;constructor(t,e,n){this.polyface=t,this.edgeOptions=e,this.baseTriangleIndex=n}}class El{visible;faceIndex0;edge;point0;point1;faceIndex1;constructor(t,e,n,i,s){this.visible=t,this.faceIndex0=e,this.edge=n,this.point0=i,this.point1=s}addFace(t,e){this.faceIndex1===void 0&&(this.visible||=t,this.faceIndex1=e)}}function Rl(u,t){if(!u.triangles)return;const e=new kr((a,c)=>a.compareTo(c)),n=[],i=new Pr,s=[new y,new y,new y],r=[0,0,0];for(let a=t.baseTriangleIndex;a<u.triangles.length;a++){let c=!1;u.triangles.getTriangle(a,i);for(let d=0;d<3;d++){const h=t.vertexIndexMap.get(i.indices[d]);if(h===void 0){c=!0;continue}r[d]=h,t.polyface.data.getPoint(h,s[d])}if(c)continue;for(let d=0;d<3;d++){const h=(d+1)%3,g=n.length,m=new Ua(i.indices[d],i.indices[h]),p=new Ua(r[d],r[h]),x=new El(i.isEdgeVisible(d),g,m,s[d],s[h]),_=e.findOrInsert(p,x);_.inserted||_.value.addFace(x.visible,g)}const l=P.createCrossProductToPoints(s[0],s[1],s[2]);l.normalizeInPlace(),n.push(l)}if(!t.edgeOptions.generateAllEdges){const a=Math.cos(t.edgeOptions.minCreaseAngle);for(const c of e.values())if(c.faceIndex1!==void 0){const l=n[c.faceIndex0],d=n[c.faceIndex1];Math.abs(l.dotProduct(d))>a&&(c.visible=!1)}}u.edges===void 0&&(u.edges=new xl);const o=.999999;for(const a of e.values())if(a.visible)u.edges.visible.push(a.edge);else if(a.faceIndex1!==void 0){const c=n[a.faceIndex0],l=n[a.faceIndex1];Math.abs(c.dotProduct(l))<o&&(u.edges.silhouette.push(a.edge),u.edges.silhouetteNormals.push(new gl(Ci.fromVector(c),Ci.fromVector(l))))}}class Bi extends kr{range;vertexTolerance;facetAreaTolerance;tolerance;is2d;features;options;_isVolumeClassifier;_keyOrder=0;constructor(t,e,n,i,s){super((r,o)=>r.compare(o)),this.tolerance=t,this.vertexTolerance=t*yr.vertex,this.facetAreaTolerance=t*yr.facetArea,this.range=e,this.is2d=n,this.options=i,this._isVolumeClassifier=s?.isVolumeClassifier??!1,s&&(this.features=new Da(2048*1024,s.modelId))}static createFromGeometries(t,e,n,i,s,r){const o=new Bi(e,n,i,s,r);for(const a of t)o.loadGeometry(a);return o}toMeshes(){const t=new qa(this.features,this.range);for(const e of this._values)e.mesh.points.length>0&&t.push(e.mesh);return t}loadGeometry(t){this.loadPolyfacePrimitiveList(t),this.loadStrokePrimitiveList(t)}loadPolyfacePrimitiveList(t){const e=t.getPolyfaces(this.tolerance);if(e!==void 0)for(const n of e)this.loadIndexedPolyface(n,t.feature)}loadIndexedPolyface(t,e){const{indexedPolyface:n,displayParams:i,isPlanar:s}=t,{pointCount:r,normalCount:o}=n,{fillColor:a,isTextured:c}=i,l=i.textureMapping;if(r===0)return;const d=this.getBuilder(i,We.Mesh,o>0,s),h=new _n(t.displayEdges&&this.options.wantEdges?_n.Type.DefaultEdges:_n.Type.NoEdges);d.addFromPolyface(n,{edgeOptions:h,includeParams:c,fillColor:a.tbgr,mappedTexture:l},e)}loadStrokePrimitiveList(t){const e=t.getStrokes(this.tolerance);if(e!==void 0)for(const n of e)this.loadStrokesPrimitive(n,t.feature)}loadStrokesPrimitive(t,e){const{displayParams:n,isDisjoint:i,isPlanar:s,strokes:r}=t,o=i?We.Point:We.Polyline;this.getBuilder(n,o,!1,s).addStrokePointLists(r,i,n.lineColor.tbgr,e)}getBuilder(t,e,n,i){const{facetAreaTolerance:s,tolerance:r,is2d:o,range:a}=this,c=this.getKey(t,e,n,i);return this.getBuilderFromKey(c,{displayParams:t,type:e,range:a,quantizePositions:!1,is2d:o,isPlanar:i,tolerance:r,areaTolerance:s,features:this.features,isVolumeClassifier:this._isVolumeClassifier})}getKey(t,e,n,i){const s=new Bi.Key(t,e,n,i);return this.options.preserveOrder&&(s.order=++this._keyOrder),s}getBuilderFromKey(t,e){let n=this.get(t);return n===void 0&&(n=So.create(e),this.set(t,n)),n}}(function(u){class t{order=0;params;type;hasNormals;isPlanar;constructor(n,i,s,r){this.params=n,this.type=i,this.hasNormals=s,this.isPlanar=r}static createFromMesh(n){return new t(n.displayParams,n.type,n.normals.length!==0,n.isPlanar)}compare(n){let i=Et(this.order,n.order);return i===0&&(i=Et(this.type,n.type),i===0&&(i=Mn(this.isPlanar,n.isPlanar),i===0&&(i=Mn(this.hasNormals,n.hasNormals),i===0&&(i=this.params.compareForMerge(n.params))))),i}equals(n){return this.compare(n)===0}}u.Key=t})(Bi||(Bi={}));class bl{_list=[];get first(){return this._list[0]}get isEmpty(){return this._list.length===0}get length(){return this._list.length}push(t){return this._list.push(t)}append(t){return this._list.push(...t._list),this}clear(){this._list.length=0}computeRange(){const t=J.createNull(),e=n=>t.extendRange(n.tileRange);return this._list.forEach(e),t}computeQuantizationParams(){return rn.fromRange(this.computeRange())}[Symbol.iterator](){return this._list[Symbol.iterator]()}}class Zi{displayParams;_polyface;displayEdges;isPlanar;get indexedPolyface(){return this._polyface}static create(t,e,n=!0,i=!1){return new Zi(t,e,n,i)}constructor(t,e,n,i){this.displayParams=t,this._polyface=e,this.displayEdges=n,this.isPlanar=i}clone(){return new Zi(this.displayParams,this._polyface.clone(),this.displayEdges,this.isPlanar)}transform(t){return this._polyface.tryTransformInPlace(t)}}class wo extends Array{constructor(...t){super(...t)}}class Ao{points;constructor(t=[]){this.points=[...t]}}class vr extends Array{constructor(...t){super(...t)}}class us{displayParams;isDisjoint;isPlanar;strokes;static create(t,e,n){return new us(t,e,n)}constructor(t,e,n){this.displayParams=t,this.strokes=new vr,this.isDisjoint=e,this.isPlanar=n}transform(t){for(const e of this.strokes)t.multiplyPoint3dArrayInPlace(e.points)}}class Co extends Array{constructor(...t){super(...t)}}class an{transform;tileRange;displayParams;feature;constructor(t,e,n,i){this.transform=t,this.tileRange=e,this.displayParams=n,this.feature=i}static createFromPointString(t,e,n,i,s){return new Dl(t,e,n,i,s)}static createFromLineString(t,e,n,i,s){return new Xl(t,e,n,i,s)}static createFromLoop(t,e,n,i,s,r){return new Yl(t,e,n,i,s,r)}static createFromSolidPrimitive(t,e,n,i,s){return new zl(t,e,n,i,s)}static createFromPath(t,e,n,i,s,r){return new fs(t,e,n,i,s,r)}static createFromPolyface(t,e,n,i,s){return new Nl(t,e,n,i,s)}getPolyfaces(t){const e=Zt.createForFacets();return e.chordTol=t,this.displayParams.isTextured&&(e.needParams=!0),this.displayParams.ignoreLighting||(e.needNormals=!0),this._getPolyfaces(e)}getStrokes(t){const e=Zt.createForCurves();return e.chordTol=t,this._getStrokes(e)}get hasTexture(){return this.displayParams.isTextured}doDecimate(){return!1}doVertexCluster(){return!0}part(){}}class fs extends an{path;isDisjoint;constructor(t,e,n,i,s,r){super(e,n,i,r),this.path=t,this.isDisjoint=s}_getPolyfaces(t){}_getStrokes(t){return fs.getStrokesForLoopOrPath(this.path,t,this.displayParams,this.isDisjoint,this.transform)}static getStrokesForLoopOrPath(t,e,n,i,s){const r=new Co;if(!t.isAnyRegionType||n.wantRegionOutline){const o=new vr;if(fs.collectCurveStrokes(o,t,e,s),o.length>0){const a=t.isAnyRegionType;n.wantRegionOutline;const c=us.create(n,i,a);c.strokes=o,r.push(c)}}return r}static collectCurveStrokes(t,e,n,i){const s=e.getPackedStrokes(n);if(s!==void 0){const r=s.getPoint3dArray();i.multiplyPoint3dArrayInPlace(r),t.push(new Ao(r))}}}class Dl extends an{pts;constructor(t,e,n,i,s){super(e,n,i,s),this.pts=t}_getPolyfaces(t){}_getStrokes(t){const e=new Co,n=new vr(new Ao(this.pts)),i=us.create(this.displayParams,!0,!1);return i.strokes=n,i.transform(this.transform),e.push(i),e}}class Xl extends an{pts;constructor(t,e,n,i,s){super(e,n,i,s),this.pts=t}_getPolyfaces(t){}_getStrokes(t){const e=new Co,n=new vr(new Ao(this.pts)),i=us.create(this.displayParams,!1,!1);return i.strokes=n,i.transform(this.transform),e.push(i),e}}class Yl extends an{loop;isDisjoint;constructor(t,e,n,i,s,r){super(e,n,i,r),this.loop=t,this.isDisjoint=s}_getPolyfaces(t){if(!this.loop.isAnyRegionType)return;const e=Cn.createForLinearSweep(this.loop);if(e!==void 0){const n=it.create(t);e.emitFacets(n,!1,this.transform);const i=n.claimPolyface(),s=kt.RegionEdgeType.Default===this.displayParams.regionEdgeType,r=!0;return new wo(Zi.create(this.displayParams,i,s,r))}}_getStrokes(t){return fs.getStrokesForLoopOrPath(this.loop,t,this.displayParams,this.isDisjoint,this.transform)}}class Nl extends an{polyface;constructor(t,e,n,i,s){super(e,n,i,s),this.polyface=e.isIdentity?t:t.cloneTransformed(e)}_getPolyfaces(t){return this.hasTexture||(this.polyface.data.param&&this.polyface.data.param.clear(),this.polyface.data.paramIndex&&(this.polyface.data.paramIndex=[])),t.needNormals?(!this.polyface.data.normal||this.polyface.data.normal.length===0)&&St.buildAverageNormals(this.polyface):(this.polyface.data.normal&&this.polyface.data.normal.clear(),this.polyface.data.normalIndex&&(this.polyface.data.normalIndex=[])),new wo(Zi.create(this.displayParams,this.polyface))}_getStrokes(t){}}class zl extends an{_primitive;constructor(t,e,n,i,s){super(e,n,i,s);const r=e.isIdentity?t:t.cloneTransformed(e);this._primitive=r!==void 0?r:t}_getStrokes(){}_getPolyfaces(t){const e=it.create(t);return e.addGeometryQuery(this._primitive),new wo(Zi.create(this.displayParams,e.claimPolyface()))}}class Vl{_transform;_surfacesOnly;_analysisDisplacement;tileRange;geometries=new bl;currentFeature;get surfacesOnly(){return this._surfacesOnly}get transform(){return this._transform}get isEmpty(){return this.geometries.isEmpty}get haveTransform(){return!this._transform.isIdentity}constructor(t){this.tileRange=t?.tileRange??J.createNull(),this._surfacesOnly=t?.surfacesOnly===!0,this._transform=t?.transform??X.createIdentity(),this._analysisDisplacement=t?.analysisStyleDisplacement,this.currentFeature=t?.feature}getPrimitiveRange(t){const e=new J;return t.range(void 0,e),e.isNull?void 0:e}calculateTransform(t,e){return this.haveTransform&&(t=this._transform.multiplyTransformTransform(t)),t.multiplyRange(e,e),t}addLoop(t,e,n,i){const s=this.getPrimitiveRange(t);if(!s)return!1;const r=this.calculateTransform(n,s);return this.addGeometry(an.createFromLoop(t,r,s,e,i,this.currentFeature))}addLineString(t,e,n){const i=J.createNull();if(i.extendArray(t,void 0),i.isNull)return!1;const s=this.calculateTransform(n,i);return this.addGeometry(an.createFromLineString(t,s,i,e,this.currentFeature))}addPointString(t,e,n){const i=J.createNull();if(i.extendArray(t,void 0),i.isNull)return!1;const s=this.calculateTransform(n,i);return this.addGeometry(an.createFromPointString(t,s,i,e,this.currentFeature))}addPath(t,e,n,i){const s=this.getPrimitiveRange(t);if(!s)return!1;const r=this.calculateTransform(n,s);return this.addGeometry(an.createFromPath(t,r,s,e,i,this.currentFeature))}addPolyface(t,e,n){let i;const s=this._analysisDisplacement;if(s){const a=t.data.auxData?.channels.find(c=>c.name===s.channelName)?.computeDisplacementRange(s.scale);if(a&&!a.isNull){i=J.createNull();const c=new y;for(let l=0;l<t.data.point.length;l++)t.data.point.getPoint3dAtUncheckedPointIndex(l,c),i.extendXYZ(c.x+a.low.x,c.y+a.low.y,c.z+a.low.z),i.extendXYZ(c.x+a.high.x,c.y+a.high.y,c.z+a.high.z)}}if(!i&&!(i=this.getPrimitiveRange(t)))return!1;const r=this.calculateTransform(n,i);return this.addGeometry(an.createFromPolyface(t,r,i,e,this.currentFeature))}addSolidPrimitive(t,e,n){const i=this.getPrimitiveRange(t);if(!i)return!1;const s=this.calculateTransform(n,i);return this.addGeometry(an.createFromSolidPrimitive(t,s,i,e,this.currentFeature))}addGeometry(t){return this.geometries.push(t),!0}clear(){this.geometries.clear()}toMeshBuilderMap(t,e,n){const{geometries:i}=this,s=i.computeRange(),r=!s.isNull&&s.isAlmostZeroZ;return Bi.createFromGeometries(i,e,s,r,t,n)}toMeshes(t,e,n){return this.geometries.isEmpty?new qa:this.toMeshBuilderMap(t,e,n).toMeshes()}}class Ol{[ge];_graphicParams=new Ai;placement;type;pickable;preserveOrder;wantNormals;wantEdges;analysisStyle;constructor(t){this.placement=t.placement?.clone()??X.createIdentity(),this.type=t.type,this.pickable=t.pickable,this.wantEdges=t.wantEdges,this.preserveOrder=t.preserveOrder,this.wantNormals=t.wantNormals,this.analysisStyle=t.analysisStyle,this[ge]=new Vl({analysisStyleDisplacement:this.analysisStyle?.displacement}),this.pickable&&this.activateFeature(new cs(this.pickable.id,this.pickable.subCategoryId,this.pickable.geometryClass))}get isViewCoordinates(){return this.type===Ye.ViewBackground||this.type===Ye.ViewOverlay}get isWorldCoordinates(){return!this.isViewCoordinates}get isSceneGraphic(){return this.type===Ye.Scene}get isViewBackground(){return this.type===Ye.ViewBackground}get isOverlay(){return this.type===Ye.ViewOverlay||this.type===Ye.WorldOverlay}activateGraphicParams(t){t.clone(this._graphicParams)}activateFeature(t){this.pickable,this.pickable&&(this[ge].currentFeature=t)}activatePickableId(t){const e=this.pickable;this.activateFeature(new cs(t,e?.subCategoryId,e?.geometryClass))}addLineString(t){t.length===2&&t[0].isAlmostEqual(t[1])?this[ge].addPointString(t,this.getLinearDisplayParams(),this.placement):this[ge].addLineString(t,this.getLinearDisplayParams(),this.placement)}addLineString2d(t,e){const n=To(t,e);this.addLineString(n)}addPointString(t){this[ge].addPointString(t,this.getLinearDisplayParams(),this.placement)}addPointString2d(t,e){const n=To(t,e);this.addPointString(n)}addShape(t){const e=tt.create(F.create(t));this[ge].addLoop(e,this.getMeshDisplayParams(),this.placement,!1)}addShape2d(t,e){const n=To(t,e);this.addShape(n)}addArc(t,e,n){let i;if(e||n?i=tt.create(t):i=Pt.create(t),n&&!e&&!t.sweep.isFullCircle){const r=U.create(t.startPoint(),t.endPoint());i.children.push(r)}const s=i.isAnyRegionType?this.getMeshDisplayParams():this.getLinearDisplayParams();i instanceof tt?this[ge].addLoop(i,s,this.placement,!1):this[ge].addPath(i,s,this.placement,!1)}addArc2d(t,e,n,i){if(i===0)this.addArc(t,e,n);else{const s=t;s.center.z=i,this.addArc(s,e,n)}}addPath(t){this[ge].addPath(t,this.getLinearDisplayParams(),this.placement,!1)}addLoop(t){this[ge].addLoop(t,this.getMeshDisplayParams(),this.placement,!1)}addCurvePrimitive(t){switch(t.curvePrimitiveType){case"lineString":this.addLineString(t.points);break;case"lineSegment":this.addLineString([t.startPoint(),t.endPoint()]);break;case"arc":this.addArc(t,!1,!1);break;default:const e=new Pt;e.tryAddChild(t)&&this.addPath(e);break}}addPolyface(t,e=!1){this[ge].addPolyface(t,this.getMeshDisplayParams(),this.placement)}addSolidPrimitive(t){this[ge].addSolidPrimitive(t,this.getMeshDisplayParams(),this.placement)}addPrimitive(t){switch(t.type){case"linestring":this.addLineString(t.points);break;case"linestring2d":this.addLineString2d(t.points,t.zDepth);break;case"pointstring":this.addPointString(t.points);break;case"pointstring2d":this.addPointString2d(t.points,t.zDepth);break;case"shape":this.addShape(t.points);break;case"shape2d":this.addShape2d(t.points,t.zDepth);break;case"arc":this.addArc(t.arc,t.isEllipse===!0,t.filled===!0);break;case"arc2d":this.addArc2d(t.arc,t.isEllipse===!0,t.filled===!0,t.zDepth);break;case"path":this.addPath(t.path);break;case"loop":this.addLoop(t.loop);break;case"polyface":this.addPolyface(t.polyface,t.filled===!0);break;case"solidPrimitive":this.addSolidPrimitive(t.solidPrimitive);break}}addRangeBox(t,e=!1){if(!e){this.addFrustum(ls.fromRange(t));return}const n=ai.createRange(t,!0);n&&this.addSolidPrimitive(n)}addFrustum(t){this.addRangeBoxFromCorners(t.points)}addFrustumSides(t){this.addRangeBoxSidesFromCorners(t.points)}addRangeBoxFromCorners(t){this.addLineString([t[b.LeftBottomFront],t[b.LeftTopFront],t[b.RightTopFront],t[b.RightBottomFront],t[b.RightBottomRear],t[b.RightTopRear],t[b.LeftTopRear],t[b.LeftBottomRear],t[b.LeftBottomFront].clone(),t[b.RightBottomFront].clone()]),this.addLineString([t[b.LeftTopFront].clone(),t[b.LeftTopRear].clone()]),this.addLineString([t[b.RightTopFront].clone(),t[b.RightTopRear].clone()]),this.addLineString([t[b.LeftBottomRear].clone(),t[b.RightBottomRear].clone()])}addRangeBoxSidesFromCorners(t){this.addShape([t[b.LeftBottomFront].clone(),t[b.LeftTopFront].clone(),t[b.RightTopFront].clone(),t[b.RightBottomFront].clone(),t[b.LeftBottomFront].clone()]),this.addShape([t[b.RightTopRear].clone(),t[b.LeftTopRear].clone(),t[b.LeftBottomRear].clone(),t[b.RightBottomRear].clone(),t[b.RightTopRear].clone()]),this.addShape([t[b.RightTopRear].clone(),t[b.LeftTopRear].clone(),t[b.LeftTopFront].clone(),t[b.RightTopFront].clone(),t[b.RightTopRear].clone()]),this.addShape([t[b.RightTopRear].clone(),t[b.RightBottomRear].clone(),t[b.RightBottomFront].clone(),t[b.RightTopFront].clone(),t[b.RightTopRear].clone()]),this.addShape([t[b.LeftBottomRear].clone(),t[b.RightBottomRear].clone(),t[b.RightBottomFront].clone(),t[b.LeftBottomFront].clone(),t[b.LeftBottomRear].clone()]),this.addShape([t[b.LeftBottomRear].clone(),t[b.LeftTopRear].clone(),t[b.LeftTopFront].clone(),t[b.LeftBottomFront].clone(),t[b.LeftBottomRear].clone()])}setSymbology(t,e,n,i=Hn.Solid){this.activateGraphicParams(Ai.fromSymbology(t,e,n,i))}setBlankingFill(t){this.activateGraphicParams(Ai.fromBlankingFill(t))}getMeshDisplayParams(){return kt.createForMesh(this._graphicParams,!this.wantNormals,t=>this.resolveGradient(t))}getLinearDisplayParams(){return kt.createForLinear(this._graphicParams)}add(t){this[ge].addGeometry(t)}}function To(u,t){const e=[];for(const n of u)e.push(y.create(n.x,n.y,t));return e}function ce(u,t){t&&u.add(t.buffer)}function Ll(u,t){if(t.type==="pattern"){ce(u,t.params.xyOffsets);return}switch(ce(u,t.params.vertices.data),t.modifier?.type==="instances"&&(ce(u,t.modifier.transforms),ce(u,t.modifier.featureIds),ce(u,t.modifier.symbologyOverrides)),t.type){case"point":ce(u,t.params.indices);break;case"polyline":ce(u,t.params.polyline.indices),ce(u,t.params.polyline.prevIndices),ce(u,t.params.polyline.nextIndicesAndParams);break;case"mesh":ce(u,t.params.surface.indices);const e=t.params.edges;e&&(ce(u,e.segments?.indices),ce(u,e.segments?.endPointAndQuadIndices),ce(u,e.silhouettes?.indices),ce(u,e.silhouettes?.endPointAndQuadIndices),ce(u,e.silhouettes?.normalPairs),ce(u,e.polylines?.indices),ce(u,e.polylines?.prevIndices),ce(u,e.polylines?.nextIndicesAndParams),ce(u,e.indexed?.indices),ce(u,e.indexed?.edges.data));break}}function ko(u,t,e,n){const i=Math.ceil(u*t)+e;if(i<=n)return{width:i,height:1};let s=Math.ceil(Math.sqrt(i));const r=s%t;r!==0&&(s+=t-r);const o=Math.ceil(i/s);return{width:s,height:o}}class Fo{name;inputs;indices;constructor(t){this.name=t.name,this.inputs=t.inputs,this.indices=t.indices}toJSON(){return{name:this.name,inputs:this.inputs,indices:this.indices}}}class Ul extends Fo{qOrigin;qScale;constructor(t){super(t),this.qOrigin=Float32Array.from(t.qOrigin),this.qScale=Float32Array.from(t.qScale)}toJSON(){return{...super.toJSON(),qOrigin:Array.from(this.qOrigin),qScale:Array.from(this.qScale)}}}class Bl extends Fo{qOrigin;qScale;constructor(t){super(t),this.qOrigin=t.qOrigin[0],this.qScale=t.qScale[0]}toJSON(){return{...super.toJSON(),qOrigin:[this.qOrigin],qScale:[this.qScale]}}}class Sr{data;width;height;numVertices;numBytesPerVertex;displacements;normals;params;constructor(t,e,n,i){this.data=t.data,this.width=t.width,this.height=t.height,this.numVertices=t.count,this.numBytesPerVertex=t.numBytesPerVertex,this.displacements=e,this.normals=n,this.params=i}static fromJSON(t){let e,n,i;if(t.displacements!==void 0&&0<t.displacements.length){e=[];for(const s of t.displacements)e.push(new Ul(s))}if(t.normals!==void 0&&0<t.normals.length){n=[];for(const s of t.normals)n.push(new Fo(s))}if(t.params!==void 0&&0<t.params.length){i=[];for(const s of t.params)i.push(new Bl(s))}return e!==void 0||n!==void 0||i!==void 0?new Sr(t,e,n,i):void 0}toJSON(){return{data:this.data,width:this.width,height:this.height,count:this.numVertices,numBytesPerVertex:this.numBytesPerVertex,displacements:this.displacements?.map(t=>t.toJSON()),normals:this.normals?.map(t=>t.toJSON()),params:this.params?.map(t=>t.toJSON())}}static fromChannels(t,e,n){return Mo.buildAuxChannelTable(t,e,n)}}function Wa(u){return u!==0&&(u=1/u),u}class Mo{_view;_props;_numBytesPerVertex;constructor(t,e){this._props=t,this._numBytesPerVertex=e,this._view=new DataView(t.data.buffer)}static buildAuxChannelTable(t,e,n){const i=t.reduce((d,h)=>d+Ga(h),0);if(!i)return;const s=Math.floor((i+3)/4),r=s*4-i;let o;r!==0?o=ko(Math.floor((e+1)/2),i/2,0,n):o=ko(e,s,0,n);const c={data:new Uint8Array(o.width*o.height*4),width:o.width,height:o.height,count:e,numBytesPerVertex:i};return new Mo(c,i).build(t),Sr.fromJSON(c)}build(t){let e=0;for(const n of t)Te.Normal===n.dataType?this.addNormals(n,e):Te.Vector===n.dataType?this.addDisplacements(n,e):this.addParams(n,e),e+=Ga(n)}addNormals(t,e){const n=[],i=[],s=new P;for(let o=0;o<t.data.length;o++){let a=e+o*2;i.push(a/2);const c=t.data[o];n.push(c.input);for(let l=0;l<c.values.length;l+=3){s.x=c.values[l],s.y=c.values[l+1],s.z=c.values[l+2],s.normalizeInPlace();const d=Ci.encode(s);this._view.setUint16(a,d,!0),a+=this._numBytesPerVertex}}(this._props.normals??(this._props.normals=[])).push({name:t.name??"",inputs:n,indices:i})}addParams(t,e){const n=[],i=[],s=ct.createNull();for(const a of t.data)n.push(a.input),s.extendArray(a.values);const r=dt.computeScale(s.high-s.low);for(let a=0;a<t.data.length;a++){let c=e+a*2;i.push(c/2);for(const l of t.data[a].values){const d=dt.quantize(l,s.low,r);this._view.setUint16(c,d,!0),c+=this._numBytesPerVertex}}(this._props.params??(this._props.params=[])).push({inputs:n,indices:i,name:t.name??"",qOrigin:[s.low],qScale:[Wa(r)]})}addDisplacements(t,e){const n=[],i=[],s=new y,r=J.createNull();for(const l of t.data){n.push(l.input);for(let d=0;d<l.values.length;d+=3)s.set(l.values[d],l.values[d+1],l.values[d+2]),r.extend(s)}const o=rn.fromRange(r),a=new Jn;for(let l=0;l<t.data.length;l++){let d=e+l*6;i.push(d/2);const h=t.data[l];for(let g=0;g<h.values.length;g+=3)s.set(h.values[g],h.values[g+1],h.values[g+2]),a.init(s,o),this._view.setUint16(d+0,a.x,!0),this._view.setUint16(d+2,a.y,!0),this._view.setUint16(d+4,a.z,!0),d+=this._numBytesPerVertex}(this._props.displacements??(this._props.displacements=[])).push({inputs:n,indices:i,name:t.name??"",qOrigin:o.origin.toArray(),qScale:o.scale.toArray().map(l=>Wa(l))})}}function Ga(u){const t=u.data.length;switch(u.dataType){case Te.Vector:return 6*t;case Te.Normal:case Te.Distance:case Te.Scalar:return 2*t}}var cn;(function(u){u[u.Unlit=0]="Unlit",u[u.Lit=1]="Lit",u[u.Textured=2]="Textured",u[u.TexturedLit=3]="TexturedLit",u[u.VolumeClassifier=4]="VolumeClassifier"})(cn||(cn={}));function Zl(u){if(u!==void 0)return{isAtlas:!1,material:u}}class Kn{data;constructor(t){this.data=t,this.data.length%3}get length(){return this.data.length/3}static fromArray(t){const e=new Uint8Array(t.length*3);for(let n=0;n<t.length;n++)this.encodeIndex(t[n],e,n*3);return new Kn(e)}static encodeIndex(t,e,n){n+2<e.length,e[n+0]=t&255,e[n+1]=(t&65280)>>8,e[n+2]=(t&16711680)>>16}setNthIndex(t,e){Kn.encodeIndex(e,this.data,t*3)}decodeIndex(t){t<this.length;const e=t*3;return this.data[e]|this.data[e+1]<<8|this.data[e+2]<<16}decodeIndices(){const t=[];for(let e=0;e<this.length;e++)t.push(this.decodeIndex(e));return t}[Symbol.iterator](){function*t(e){for(let n=0;n<e.length;n++)yield e.decodeIndex(n)}return t(this)}}function ql(u){return gs.create(u).tesselate()}class Ha{isSegmentStart=!1;isPolylineStartOrEnd=!1;vertexIndex=0;prevIndex=0;nextIndex=0;constructor(){}init(t,e,n,i,s){this.isSegmentStart=t,this.isPolylineStartOrEnd=e,this.vertexIndex=n,this.prevIndex=i,this.nextIndex=s}computeParam(t,e=!1,n=!1,i=!1){if(n)return 12;let s;i?s=96:e?s=9:s=this.isPolylineStartOrEnd?3:6;let r=0;return t&&(r=24),this.isSegmentStart||(r+=48),s+r}}class gs{_polylines;_doJoints;_numIndices=0;_vertIndex=[];_prevIndex=[];_nextIndex=[];_nextParam=[];_position=[];constructor(t,e,n){if(this._polylines=t,e instanceof on)for(const i of e.list)this._position.push(i.unquantize(e.params));else this._position=e;this._doJoints=n}static fromPolyline(t){return new gs(t.polylines,t.points,Eo(t.width,!!t.flags.is2d))}static create(t){return new gs(t.polylines.map(e=>e.indices),t.points,Eo(t.width,t.is2d))}tesselate(){this._tesselate();const t=Kn.fromArray(this._vertIndex),e=Kn.fromArray(this._prevIndex),n=new Uint8Array(this._numIndices*4);for(let i=0;i<this._numIndices;i++){const s=this._nextIndex[i],r=i*4;Kn.encodeIndex(s,n,r),n[r+3]=this._nextParam[i]&255}return{indices:t,prevIndices:e,nextIndicesAndParams:n}}_tesselate(){const t=new Ha,e=new Ha,n=-.7;for(const i of this._polylines){if(i.length<2)continue;const s=i.length-1,r=i[0]===i[s];for(let o=0;o<s;++o){const a=i[o],c=i[o+1],l=o===0,d=s-1===o,h=l?r?i[s-1]:a:i[o-1],g=d?r?i[1]:c:i[o+2];t.init(!0,l&&!r,a,h,c),e.init(!1,d&&!r,c,g,a);const m=this._doJoints&&(r||!l)&&this._dotProduct(t)>n,p=this._doJoints&&(r||!d)&&this._dotProduct(e)>n;m||p?(this._addVertex(t,t.computeParam(!0,m,!1,!1)),this._addVertex(e,e.computeParam(!1,p,!1,!1)),this._addVertex(t,t.computeParam(!1,m,!1,!0)),this._addVertex(t,t.computeParam(!1,m,!1,!0)),this._addVertex(e,e.computeParam(!1,p,!1,!1)),this._addVertex(e,e.computeParam(!1,p,!1,!0)),this._addVertex(t,t.computeParam(!1,m,!1,!0)),this._addVertex(e,e.computeParam(!1,p,!1,!0)),this._addVertex(t,t.computeParam(!1,m,!1,!1)),this._addVertex(t,t.computeParam(!1,m,!1,!1)),this._addVertex(e,e.computeParam(!1,p,!1,!0)),this._addVertex(e,e.computeParam(!0,p,!1,!1)),m&&this.addJointTriangles(t,t.computeParam(!1,!0,!1,!0),t),p&&this.addJointTriangles(e,e.computeParam(!1,!0,!1,!0),e)):(this._addVertex(t,t.computeParam(!0)),this._addVertex(e,e.computeParam(!1)),this._addVertex(t,t.computeParam(!1)),this._addVertex(t,t.computeParam(!1)),this._addVertex(e,e.computeParam(!1)),this._addVertex(e,e.computeParam(!0)))}}}addJointTriangles(t,e,n){const i=n.computeParam(!1,!1,!0);for(let s=0;s<3;s++)this._addVertex(t,e),this._addVertex(n,i+s+1),this._addVertex(n,i+s)}_dotProduct(t){const e=this._position[t.vertexIndex],n=P.createStartEnd(this._position[t.prevIndex],e),i=P.createStartEnd(this._position[t.nextIndex],e);return n.dotProduct(i)}_addVertex(t,e){this._vertIndex[this._numIndices]=t.vertexIndex,this._prevIndex[this._numIndices]=t.prevIndex,this._nextIndex[this._numIndices]=t.nextIndex,this._nextParam[this._numIndices]=e,this._numIndices++}}function Wl(u,t){u.flags.isDisjoint;const e=wr.buildFromPolylines(u,t);if(e===void 0)return;const n=gs.fromPolyline(u);if(n!==void 0)return{vertices:e,polyline:n.tesselate(),isPlanar:!!u.flags.isPlanar,type:u.flags.type??ds.Normal,weight:u.width,linePixels:u.linePixels,hasCumulativeDistances:(u.cumulativeDistances?.length??0)>0}}function Eo(u,t){return t||u>=3}function Gl(u,t,e){let n=Math.ceil(1.5*u+2.5*t);const i=u*6;let s=0,r=n,o=1;if(n>=e){r=Math.ceil(Math.sqrt(n));const a=r%15;a!==0&&(r+=15-a),t>0&&u>0&&(s=(60-i%60)%10,n+=Math.ceil(s/4)),o=Math.ceil(n/r),r*o<n&&o++}return{width:r,height:o,silhouettePadding:s,silhouetteStartByteIndex:i}}function Hl(u,t,e){const n=u.edges?.edges,i=u.silhouettes,s=n?.length??0,r=i?.edges?.length??0,o=t?t.reduce((v,S)=>v+Math.max(0,S.length-1),0):0,a=s+o,c=a+r;if(c===0)return;const l=new Kn(new Uint8Array(c*6*3));for(let v=0;v<c;v++)for(let S=0;S<6;S++)l.setNthIndex(v*6+S,v);const{width:d,height:h,silhouettePadding:g,silhouetteStartByteIndex:m}=Gl(a,r,e),p=new Uint8Array(d*h*4);function x(v,S){p[v+0]=S&255,p[v+1]=(S&65280)>>>8,p[v+2]=(S&16711680)>>>16}function _(v,S,w){const T=v*6;x(T,S),x(T+3,w)}let I=0;if(n)for(const v of n)_(I++,v.indices[0],v.indices[1]);if(t)for(const v of t){const S=v.length-1;for(let w=0;w<S;w++){const T=v[w],R=v[w+1];T<R?_(I++,T,R):_(I++,R,T)}}if(i?.edges){let v=function(S,w,T,R){const L=m+g+S*10;x(L,w),x(L+3,T),p[L+6]=R.first.value&255,p[L+7]=(R.first.value&65280)>>>8,p[L+8]=R.second.value&255,p[L+9]=(R.second.value&65280)>>>8};i.normals,i.normals.length,i.edges.length,I=0;for(let S=0;S<i.edges.length;S++)v(I++,i.edges[S].indices[0],i.edges[S].indices[1],i.normals[S])}return{indices:l,edges:{data:p,width:d,height:h,numSegments:a,silhouettePadding:g},appearance:{width:u.width,linePixels:u.linePixels,color:u.color}}}function Jl(u){const{meshArgs:t,maxWidth:e}=u,n=t.edges;if(!n)return;const i=n.polylines.groups?.length===1&&n.polylines.groups[0].appearance===void 0&&!Eo(n.width,t.is2d===!0)?n.polylines.groups[0].polylines.map(c=>c.indices):void 0;let s,r,o;o=Hl(n,i,e);let a;if(!i&&n.polylines.groups)for(const c of n.polylines.groups){const l=ql({points:u.meshArgs.points,polylines:c.polylines,width:c.appearance?.width??n.width,is2d:u.meshArgs.is2d===!0});a||(a=[]),a.push({polyline:l,appearance:c.appearance})}if(!(!a&&!o))return{weight:n.width,linePixels:n.linePixels,segments:s,silhouettes:r,polylineGroups:a,indexed:o}}const Ja=new Uint32Array(1),Kl=new Float32Array(Ja.buffer);function Ka(u){return Kl[0]=u,Ja[0]}function Qa(u){if(u.cumulativeDistances!==void 0)return u.cumulativeDistances;const t=[];if(u.points instanceof on){t.length=u.points.length;for(let n=0;n<u.points.length;n++)t[n]=u.points.list[n].unquantize(u.points.params)}else{t.length=u.points.length;for(let n=0;n<u.points.length;n++)t[n]=u.points[n]}const e=new Float32Array(t.length);e.fill(Number.NaN);for(const n of u.polylines){if(n.length<2)continue;let i=0;for(let s=0;s<n.length;s++){const r=n[s];if(s>0){const o=t[n[s-1]],a=t[r];i+=o.distance(a)}Number.isNaN(e[r])&&(e[r]=i)}}for(let n=0;n<e.length;n++)Number.isNaN(e[n])&&(e[n]=0);return e}function Ql(u,t,e){const n=$l(u),i=n.build(u.colors,u.features,t),s=Kn.fromArray(u.vertIndices),r={type:n.type,indices:s,fillFlags:u.fillFlags??xn.ByView,hasBakedLighting:u.hasBakedLighting===!0,textureMapping:u.textureMapping!==void 0?{texture:u.textureMapping.texture,alwaysDisplayed:!1}:void 0,material:Zl(u.material)},o=u.auxChannels!==void 0?Sr.fromChannels(u.auxChannels,i.numVertices,t):void 0,a=Jl({meshArgs:u,maxWidth:t});return{vertices:i,surface:r,edges:a,isPlanar:!!u.isPlanar,auxChannels:o}}class wr{data;_curIndex=0;get uvParams(){}appendColorTable(t){if(t.nonUniform!==void 0)for(const e of t.nonUniform.colors)this.appendColor(e)}advance(t){this._curIndex+=t,this.data,this._curIndex<=this.data.length}append8(t){ln(this.data)[this._curIndex]=t,this.advance(1)}append16(t){this.append8(t&255),this.append8(t>>>8)}append32(t){this.append16(t&65535),this.append16(t>>>16)}appendColor(t){const e=lt.getColors(t);switch(e.t=255-e.t,e.t){case 0:e.r=e.g=e.b=0;break;case 255:break;default:{const n=e.t/255;e.r=Math.floor(e.r*n+.5),e.g=Math.floor(e.g*n+.5),e.b=Math.floor(e.b*n+.5);break}}this.append8(e.r),this.append8(e.g),this.append8(e.b),this.append8(e.t)}build(t,e,n){const{numVertices:i,numRgbaPerVertex:s}=this,r=t.isUniform?0:t.numColors,o=ko(i,s,r,n);o.width%s===0||0<r&&o.height;const a=new Uint8Array(o.width*o.height*4);this.data=a;for(let c=0;c<i;c++)this.appendVertex(c);return this.appendColorTable(t),this.data=void 0,{data:a,qparams:this.qparams,usesUnquantizedPositions:this.usesUnquantizedPositions,width:o.width,height:o.height,hasTranslucency:t.hasAlpha,uniformColor:t.uniform,numVertices:i,numRgbaPerVertex:s,uvParams:this.uvParams,featureIndexType:e.type,uniformFeatureID:e.type===kn.Uniform?e.featureID:void 0}}static buildFromPolylines(t,e){return t.polylines.length===0?void 0:jl(t).build(t.colors,t.features,e)}}var ms;(function(u){class t extends wr{args;_qpoints;constructor(a){super(),this._qpoints=a.points,this.args=a,this.args.points}get numVertices(){return this.args.points.length}get numRgbaPerVertex(){return 3}get usesUnquantizedPositions(){return!1}get qparams(){return this._qpoints.params}appendVertex(a){this.appendPosition(a),this.appendColorIndex(a),this.appendFeatureIndex(a)}appendPosition(a){this.append16(this._qpoints.list[a].x),this.append16(this._qpoints.list[a].y),this.append16(this._qpoints.list[a].z)}appendColorIndex(a){this.args.colors.nonUniform!==void 0?this.append16(this.args.colors.nonUniform.indices[a]):this.advance(2)}appendFeatureIndex(a){this.args.features.featureIDs!==void 0?this.append32(this.args.features.featureIDs[a]):this.advance(4)}}u.SimpleBuilder=t;class e extends t{_cumDist;constructor(a){super(a),this._cumDist=Qa(a)}get numRgbaPerVertex(){return 4}appendVertex(a){super.appendVertex(a),this.appendCumulativeDistance(a)}appendCumulativeDistance(a){const c=a<this._cumDist.length?this._cumDist[a]:0;this.append32(Ka(c))}}u.PolylineBuilder=e;class n extends t{type;constructor(a,c){super(a),this.type=c}static create(a){if(a.isVolumeClassifier)return new n(a,cn.VolumeClassifier);const c=a.normals!==void 0&&0<a.normals.length,l=a.textureMapping!==void 0;let d;if(a.textureMapping){const h=Rt.createNull(),g=a.textureMapping.uvParams,m=new D;if(g!==void 0&&g.length>0)for(let p=0;p<a.points.length;p++)h.extendPoint(D.create(g[p].x,g[p].y,m));d=di.fromRange(h)}return c?l?new s(a,d):new r(a):l?new i(a,d):new n(a,cn.Unlit)}}u.MeshBuilder=n;class i extends n{_qparams;_qpoint=new hi;constructor(a,c,l=cn.Textured){super(a,l),this._qparams=c,a.textureMapping}get numRgbaPerVertex(){return 4}get uvParams(){return this._qparams}appendVertex(a){this.appendPosition(a),this.appendNormal(a),this.appendFeatureIndex(a),this.appendUVParams(a)}appendNormal(a){this.advance(2)}appendUVParams(a){this._qpoint.init(ln(this.args.textureMapping).uvParams[a],this._qparams),this.append16(this._qpoint.x),this.append16(this._qpoint.y)}}class s extends i{constructor(a,c){super(a,c,cn.TexturedLit),a.normals}appendNormal(a){this.append16(ln(this.args.normals)[a].value)}}class r extends n{constructor(a){super(a,cn.Lit),a.normals}get numRgbaPerVertex(){return 4}appendVertex(a){super.appendVertex(a),this.append16(ln(this.args.normals)[a].value),this.advance(2)}}})(ms||(ms={}));var ps;(function(u){const t=new Uint32Array(1),e=new Float32Array(t.buffer);class n extends wr{args;_points;_qparams3d;constructor(l){super(),l.points instanceof on,this._qparams3d=rn.fromRange(l.points.range),this.args=l,this._points=l.points}get numVertices(){return this._points.length}get numRgbaPerVertex(){return 5}get usesUnquantizedPositions(){return!0}get qparams(){return this._qparams3d}appendVertex(l){this.appendTransposePosAndFeatureNdx(l),this.appendColorIndex(l)}appendFloat32(l){e[0]=l,this.append32(t[0])}convertFloat32(l){return e[0]=l,t[0]}appendTransposePosAndFeatureNdx(l){const d=this._points[l],h=this.convertFloat32(d.x),g=this.convertFloat32(d.y),m=this.convertFloat32(d.z),p=this.args.features.featureIDs?this.args.features.featureIDs[l]:0;this.append8(h&255),this.append8(g&255),this.append8(m&255),this.append8(p&255),this.append8(h>>>8&255),this.append8(g>>>8&255),this.append8(m>>>8&255),this.append8(p>>>8&255),this.append8(h>>>16&255),this.append8(g>>>16&255),this.append8(m>>>16&255),this.append8(p>>>16&255),this.append8(h>>>24),this.append8(g>>>24),this.append8(m>>>24),this.append8(p>>>24)}appendPosition(l){const d=this._points[l];this.appendFloat32(d.x),this.appendFloat32(d.y),this.appendFloat32(d.z)}appendFeatureIndex(l){this.args.features.featureIDs?this.append32(this.args.features.featureIDs[l]):this.advance(4)}_appendColorIndex(l){this.args.colors.nonUniform!==void 0?this.append16(this.args.colors.nonUniform.indices[l]):this.advance(2)}appendColorIndex(l){this._appendColorIndex(l),this.advance(2)}}u.SimpleBuilder=n;class i extends n{_cumDist;constructor(l){super(l),this._cumDist=Qa(l)}get numRgbaPerVertex(){return 6}appendVertex(l){super.appendVertex(l),this.appendCumulativeDistance(l)}appendCumulativeDistance(l){const d=l<this._cumDist.length?this._cumDist[l]:0;this.append32(Ka(d))}}u.PolylineBuilder=i;class s extends n{type;constructor(l,d){super(l),this.type=d}static create(l){if(l.isVolumeClassifier)return new s(l,cn.VolumeClassifier);const d=l.normals!==void 0&&0<l.normals.length,h=l.textureMapping!==void 0;let g;if(l.textureMapping){const m=Rt.createNull(),p=l.textureMapping.uvParams,x=new D;if(p!==void 0&&p.length>0)for(let _=0;_<l.points.length;_++)m.extendPoint(D.create(p[_].x,p[_].y,x));g=di.fromRange(m)}return d?h?new o(l,g):new a(l):h?new r(l,g):new s(l,cn.Unlit)}}u.MeshBuilder=s;class r extends s{_qparams;_qpoint=new hi;constructor(l,d,h=cn.Textured){super(l,h),this._qparams=d,l.textureMapping}get uvParams(){return this._qparams}appendVertex(l){super.appendVertex(l),this._qpoint.init(ln(this.args.textureMapping).uvParams[l],this._qparams),this.append16(this._qpoint.x),this.append16(this._qpoint.y)}appendColorIndex(){}}class o extends r{constructor(l,d){super(l,d,cn.TexturedLit),l.normals}get numRgbaPerVertex(){return 6}appendVertex(l){super.appendVertex(l),this.append16(ln(this.args.normals)[l].value),this.advance(2)}}class a extends s{constructor(l){super(l,cn.Lit),l.normals}appendColorIndex(l){super._appendColorIndex(l)}appendVertex(l){super.appendVertex(l),this.append16(ln(this.args.normals)[l].value)}}})(ps||(ps={}));function $l(u){return u.points instanceof on?ms.MeshBuilder.create(u):ps.MeshBuilder.create(u)}function jl(u){const t=u.points instanceof on;return u.flags.isDisjoint?t?new ms.SimpleBuilder(u):new ps.SimpleBuilder(u):t?new ms.PolylineBuilder(u):new ps.PolylineBuilder(u)}function td(u,t){if(!u.flags.isDisjoint)return;const e=wr.buildFromPolylines(u,t);if(e===void 0)return;const n=u.polylines;let i=n[0];if(1<n.length){i=[];for(const r of n)for(const o of r)i.push(o)}const s=Kn.fromArray(i);return s.length,i.length,{vertices:e,indices:s,weight:u.width}}function ed(u){return{...u,segments:u.segments?{...u.segments,indices:u.segments.indices.data}:void 0,silhouettes:u.silhouettes?{...u.silhouettes,indices:u.silhouettes.indices.data}:void 0,polylines:u.polylineGroups?.length===1?{...u.polylineGroups[0].polyline,indices:u.polylineGroups[0].polyline.indices.data,prevIndices:u.polylineGroups[0].polyline.prevIndices.data}:void 0,indexed:u.indexed?{indices:u.indexed.indices.data,edges:u.indexed.edges}:void 0}}class Ro extends ui{index;source;constructor(t,e){let n=ui.Type.Normal;if(!(e instanceof ci.Symb)&&e.type!==void 0&&(n=e.type),super(n),this.index=t,e instanceof ci.Symb)this.source={gradient:e};else{const i=e.transparency;e.source instanceof URL?this.source={transparency:i,url:e.source.toString()}:e.source instanceof al?this.source={transparency:i,imageSource:e.source.data,format:e.source.format}:this.source={transparency:i,imageBuffer:e.source.data,format:e.source.format,width:e.source.width}}}dispose(){}get bytesUsed(){return 0}toProps(t){const e=this.source.gradient?{...this.source,gradient:this.source.gradient.toJSON()}:this.source,n=e.imageBuffer??e.imageSource;return n instanceof Uint8Array&&t.add(n.buffer),{type:this.type,source:e}}}function $a(u){return u instanceof lt||(u=mr.fromJSON(u).toColorDef()),u?.toJSON()}class ja extends ml{params;constructor(t){let e;t.textureMapping&&(e=new Ti(t.textureMapping.texture,new Ti.Params({textureMat2x3:t.textureMapping.transform,mapMode:t.textureMapping.mode,textureWeight:t.textureMapping.weight,worldMapping:t.textureMapping.worldMapping,useConstantLod:t.textureMapping.useConstantLod,constantLodProps:t.textureMapping.constantLodProps})),e.normalMapParams=t.textureMapping.normalMapParams),super({textureMapping:e}),this.params=t}toImdl(){let t;this.params.diffuse&&(t={weight:this.params.diffuse.weight,color:$a(this.params.diffuse.color)});let e;return this.params.specular&&(e={weight:this.params.specular.weight,exponent:this.params.specular.exponent,color:$a(this.params.specular.color)}),{isAtlas:!1,material:{alpha:this.params.alpha,diffuse:t,specular:e}}}}class nd{[hs]=void 0;constraints;transientIds;textures=[];materials=[];constructor(t){const e=t;if(typeof e.transientIds!="object"||typeof e.constraints!="object")throw new Error("Invalid WorkerGraphicDescriptionContextProps");this.constraints=e.constraints,this.transientIds=Is.fromJSON(e.transientIds)}createMaterial(t){const e=new ja(t);return this.materials.push(e),e}createTexture(t){const e=new Ro(this.textures.length,t);return this.textures.push(e),e}createGradientTexture(t){const e=this.textures.find(i=>i.source.gradient&&i.source.gradient.equals(t));if(e)return e;const n=new Ro(this.textures.length,t);return this.textures.push(n),n}toProps(t){return{[hs]:void 0,transientIds:this.transientIds.toJSON(),textures:this.textures.map(e=>e.toProps(t))}}}class id extends Ol{[hs]=void 0;_computeChordTolerance;_context;_viewIndependentOrigin;constructor(t){const e=t.type,n=t.placement??X.createIdentity(),i=t.generateEdges??e===Ye.Scene,s=i||e===Ye.Scene,r=e===Ye.ViewOverlay||e===Ye.WorldOverlay||e===Ye.ViewBackground;if(super({...t,[hs]:void 0,type:e,placement:n,wantEdges:i,wantNormals:s,preserveOrder:r}),this._computeChordTolerance=t.computeChordTolerance,this._viewIndependentOrigin=t.viewIndependentOrigin?.clone(),this._context=t.context,!(this._context.transientIds instanceof Is))throw new Error("Invalid WorkerGraphicDescriptionContext")}finish(){const t={[hs]:void 0,type:this.type,primitives:[]};if(this[ge].isEmpty)return t;const e=this._computeChordTolerance({builder:this,computeRange:()=>this[ge].geometries.computeRange()}),n=this[ge].toMeshes(this,e,this.pickable);if(n.length===0)return t;let i,s=!1;for(const o of n){const a=o.points;i?a instanceof on?(i.isAlmostEqual(a.params.origin),a.params.origin.setZero()):(a.range.center.isAlmostZero,void 0):a instanceof on?(i=a.params.origin.clone(),a.params.origin.setZero()):(i=a.range.center,s||(n.range?.low.subtractInPlace(i),n.range?.high.subtractInPlace(i),s=!0));const c=this.createPrimitive(o);if(c){const l=this._viewIndependentOrigin;l&&(c.modifier={type:"viewIndependentOrigin",origin:{x:l.x,y:l.y,z:l.z}}),t.primitives.push(c)}}this[ge].clear(),i&&(t.translation={x:i.x,y:i.y,z:i.z});const r=this.pickable&&n.features?.anyDefined?n.features:void 0;if(r){this.pickable;const o=pr.pack(r),a=n.range??new J;t.batch={...this.pickable,range:a.toJSON(),modelId:this.pickable.modelId??this.pickable.id,featureTable:{multiModel:!1,data:o.data,numFeatures:o.numFeatures,animationNodeIds:o.animationNodeIds}}}return t}createPrimitive(t){const e=t.toMeshArgs();if(e)return this.createMeshPrimitive(e);const n=t.toPolylineArgs();if(n)return n.flags.isDisjoint?this.createPointStringPrimitive(n):this.createPolylinePrimitive(n)}createMeshPrimitive(t){const e=Ql(t,this._context.constraints.maxTextureSize);let n;const i=e.surface.material;i&&(i.isAtlas===!1&&i.material instanceof ja,n=i.material.toImdl());let s;const r=e.surface.textureMapping;return r&&(r.texture instanceof Ro,s={alwaysDisplayed:!1,texture:r.texture.index.toString(10)}),{type:"mesh",params:{...e,vertices:bo(e.vertices),auxChannels:e.auxChannels?.toJSON(),edges:e.edges?ed(e.edges):void 0,surface:{...e.surface,indices:e.surface.indices.data,material:n,textureMapping:s}}}}createPolylinePrimitive(t){const e=Wl(t,this._context.constraints.maxTextureSize);if(e)return{type:"polyline",params:{...e,vertices:bo(e.vertices),polyline:{indices:e.polyline.indices.data,prevIndices:e.polyline.prevIndices.data,nextIndicesAndParams:e.polyline.nextIndicesAndParams}}}}createPointStringPrimitive(t){const e=td(t,this._context.constraints.maxTextureSize);if(e)return{type:"point",params:{indices:e.indices.data,vertices:bo(e.vertices),weight:e.weight}}}resolveGradient(t){return this._context.createGradientTexture(t)}}function bo(u){return{...u,qparams:u.qparams.toJSON(),uvParams:u.uvParams?.toJSON(),uniformColor:u.uniformColor?.toJSON()}}function sd(u){const t=u;return typeof t=="object"&&Array.isArray(t.primitives)&&typeof t.type=="number"}function rd(u,t){if(!sd(t))throw new Error("Invalid GraphicDescription");for(const e of t.primitives)Ll(u,e)}var tc;(function(u){function t(e,n){return rd(e,n)}u.collectTransferables=t})(tc||(tc={}));var Do;(function(u){function t(e){return new id(e)}u.create=t})(Do||(Do={}));var Xo;(function(u){function t(e){return new nd(e)}u.fromProps=t})(Xo||(Xo={}));function od(u){onmessage=async t=>{const e=t.data,n=e.msgId;try{typeof e=="object"&&"operation"in e&&"payload"in e&&"msgId"in e;const i=u[e.operation];let s=i(e.payload);s instanceof Promise&&(s=await s),typeof s=="object"&&"transfer"in s?postMessage({result:s.result,msgId:n},{transfer:s.transfer}):postMessage({result:s,msgId:n})}catch(i){const s=i instanceof Error?i:new Error("Unknown worker error");postMessage({error:s,msgId:n})}}}let ec=!1;function Yo(u){return ec?{result:u,transfer:[]}:u}let No=0;async function nc(u){let t=0;for(;++t<u;)await new Promise(e=>setTimeout(e,1))}od({zero:()=>Yo("zero"),one:u=>Yo(u),two:u=>Yo(u[0]+u[1]),throwError:()=>{throw new Error("ruh-roh")},throwString:()=>{throw"not an error"},setTransfer:u=>{ec=u},createGraphic:u=>{const t=Xo.fromProps(u),e=Do.create({type:Ye.Scene,context:t,computeChordTolerance:()=>0,viewIndependentOrigin:new y(0,1,2),pickable:{id:t.transientIds.getNext(),geometryClass:Tn.Construction,modelId:t.transientIds.getNext(),subCategoryId:t.transientIds.getNext()}});e.addPointString([new y(1,1,1)]),e.activateFeature(new cs(t.transientIds.getNext(),"0x123",Tn.Primary)),e.addShape2d([new D(0,0),new D(10,0),new D(10,5),new D(0,5)],2),e.activateFeature(new cs("0x456",t.transientIds.getNext())),e.addLineString2d([new D(0,0),new D(1,20)],-4);const n=e.finish(),i=new Set;return{result:{description:n,context:t.toProps(i)},transfer:Array.from(i)}},someVeryLongRunningAsyncOperation:async()=>(await nc(10),{result:++No,transfer:[]}),someLongRunningAsyncOperation:async()=>(await nc(5),++No),someFastSynchronousOperation:()=>++No})})();