@itwin/core-frontend 5.15.0-dev.1 → 5.15.0-dev.3
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.
- package/CHANGELOG.md +20 -1
- package/lib/public/scripts/parse-imdl-worker.js +1 -1
- package/lib/test-public/scripts/checkbrowser.js +24 -0
- package/lib/test-public/scripts/draco_encoder.js +52 -0
- package/lib/test-public/scripts/draco_wasm_wrapper.js +117 -0
- package/lib/test-public/scripts/parse-imdl-worker.js +2 -0
- package/lib/test-public/test-worker.js +1 -0
- package/package.json +20 -21
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){"use strict";function _l(l,e){}var Ba;(function(l){l[l.Readonly=1]="Readonly",l[l.ReadWrite=2]="ReadWrite"})(Ba||(Ba={}));var Ua;(function(l){l[l.Delete=9]="Delete",l[l.Insert=18]="Insert",l[l.Update=23]="Update"})(Ua||(Ua={}));var z;(function(l){l[l.BE_SQLITE_OK=0]="BE_SQLITE_OK",l[l.BE_SQLITE_ERROR=1]="BE_SQLITE_ERROR",l[l.BE_SQLITE_INTERNAL=2]="BE_SQLITE_INTERNAL",l[l.BE_SQLITE_PERM=3]="BE_SQLITE_PERM",l[l.BE_SQLITE_ABORT=4]="BE_SQLITE_ABORT",l[l.BE_SQLITE_BUSY=5]="BE_SQLITE_BUSY",l[l.BE_SQLITE_LOCKED=6]="BE_SQLITE_LOCKED",l[l.BE_SQLITE_NOMEM=7]="BE_SQLITE_NOMEM",l[l.BE_SQLITE_READONLY=8]="BE_SQLITE_READONLY",l[l.BE_SQLITE_INTERRUPT=9]="BE_SQLITE_INTERRUPT",l[l.BE_SQLITE_IOERR=10]="BE_SQLITE_IOERR",l[l.BE_SQLITE_CORRUPT=11]="BE_SQLITE_CORRUPT",l[l.BE_SQLITE_NOTFOUND=12]="BE_SQLITE_NOTFOUND",l[l.BE_SQLITE_FULL=13]="BE_SQLITE_FULL",l[l.BE_SQLITE_CANTOPEN=14]="BE_SQLITE_CANTOPEN",l[l.BE_SQLITE_PROTOCOL=15]="BE_SQLITE_PROTOCOL",l[l.BE_SQLITE_EMPTY=16]="BE_SQLITE_EMPTY",l[l.BE_SQLITE_SCHEMA=17]="BE_SQLITE_SCHEMA",l[l.BE_SQLITE_TOOBIG=18]="BE_SQLITE_TOOBIG",l[l.BE_SQLITE_CONSTRAINT_BASE=19]="BE_SQLITE_CONSTRAINT_BASE",l[l.BE_SQLITE_MISMATCH=20]="BE_SQLITE_MISMATCH",l[l.BE_SQLITE_MISUSE=21]="BE_SQLITE_MISUSE",l[l.BE_SQLITE_NOLFS=22]="BE_SQLITE_NOLFS",l[l.BE_SQLITE_AUTH=23]="BE_SQLITE_AUTH",l[l.BE_SQLITE_FORMAT=24]="BE_SQLITE_FORMAT",l[l.BE_SQLITE_RANGE=25]="BE_SQLITE_RANGE",l[l.BE_SQLITE_NOTADB=26]="BE_SQLITE_NOTADB",l[l.BE_SQLITE_ROW=100]="BE_SQLITE_ROW",l[l.BE_SQLITE_DONE=101]="BE_SQLITE_DONE",l[l.BE_SQLITE_IOERR_READ=266]="BE_SQLITE_IOERR_READ",l[l.BE_SQLITE_IOERR_SHORT_READ=522]="BE_SQLITE_IOERR_SHORT_READ",l[l.BE_SQLITE_IOERR_WRITE=778]="BE_SQLITE_IOERR_WRITE",l[l.BE_SQLITE_IOERR_FSYNC=1034]="BE_SQLITE_IOERR_FSYNC",l[l.BE_SQLITE_IOERR_DIR_FSYNC=1290]="BE_SQLITE_IOERR_DIR_FSYNC",l[l.BE_SQLITE_IOERR_TRUNCATE=1546]="BE_SQLITE_IOERR_TRUNCATE",l[l.BE_SQLITE_IOERR_FSTAT=1802]="BE_SQLITE_IOERR_FSTAT",l[l.BE_SQLITE_IOERR_UNLOCK=2058]="BE_SQLITE_IOERR_UNLOCK",l[l.BE_SQLITE_IOERR_RDLOCK=2314]="BE_SQLITE_IOERR_RDLOCK",l[l.BE_SQLITE_IOERR_DELETE=2570]="BE_SQLITE_IOERR_DELETE",l[l.BE_SQLITE_IOERR_BLOCKED=2826]="BE_SQLITE_IOERR_BLOCKED",l[l.BE_SQLITE_IOERR_NOMEM=3082]="BE_SQLITE_IOERR_NOMEM",l[l.BE_SQLITE_IOERR_ACCESS=3338]="BE_SQLITE_IOERR_ACCESS",l[l.BE_SQLITE_IOERR_CHECKRESERVEDLOCK=3594]="BE_SQLITE_IOERR_CHECKRESERVEDLOCK",l[l.BE_SQLITE_IOERR_LOCK=3850]="BE_SQLITE_IOERR_LOCK",l[l.BE_SQLITE_IOERR_CLOSE=4106]="BE_SQLITE_IOERR_CLOSE",l[l.BE_SQLITE_IOERR_DIR_CLOSE=4362]="BE_SQLITE_IOERR_DIR_CLOSE",l[l.BE_SQLITE_IOERR_SHMOPEN=4618]="BE_SQLITE_IOERR_SHMOPEN",l[l.BE_SQLITE_IOERR_SHMSIZE=4874]="BE_SQLITE_IOERR_SHMSIZE",l[l.BE_SQLITE_IOERR_SHMLOCK=5130]="BE_SQLITE_IOERR_SHMLOCK",l[l.BE_SQLITE_IOERR_SHMMAP=5386]="BE_SQLITE_IOERR_SHMMAP",l[l.BE_SQLITE_IOERR_SEEK=5642]="BE_SQLITE_IOERR_SEEK",l[l.BE_SQLITE_IOERR_DELETE_NOENT=5898]="BE_SQLITE_IOERR_DELETE_NOENT",l[l.BE_SQLITE_ERROR_FileExists=16777226]="BE_SQLITE_ERROR_FileExists",l[l.BE_SQLITE_ERROR_AlreadyOpen=33554442]="BE_SQLITE_ERROR_AlreadyOpen",l[l.BE_SQLITE_ERROR_NoPropertyTable=50331658]="BE_SQLITE_ERROR_NoPropertyTable",l[l.BE_SQLITE_ERROR_FileNotFound=67108874]="BE_SQLITE_ERROR_FileNotFound",l[l.BE_SQLITE_ERROR_NoTxnActive=83886090]="BE_SQLITE_ERROR_NoTxnActive",l[l.BE_SQLITE_ERROR_BadDbProfile=100663306]="BE_SQLITE_ERROR_BadDbProfile",l[l.BE_SQLITE_ERROR_InvalidProfileVersion=117440522]="BE_SQLITE_ERROR_InvalidProfileVersion",l[l.BE_SQLITE_ERROR_ProfileUpgradeFailed=134217738]="BE_SQLITE_ERROR_ProfileUpgradeFailed",l[l.BE_SQLITE_ERROR_ProfileTooOldForReadWrite=150994954]="BE_SQLITE_ERROR_ProfileTooOldForReadWrite",l[l.BE_SQLITE_ERROR_ProfileTooOld=167772170]="BE_SQLITE_ERROR_ProfileTooOld",l[l.BE_SQLITE_ERROR_ProfileTooNewForReadWrite=184549386]="BE_SQLITE_ERROR_ProfileTooNewForReadWrite",l[l.BE_SQLITE_ERROR_ProfileTooNew=201326602]="BE_SQLITE_ERROR_ProfileTooNew",l[l.BE_SQLITE_ERROR_ChangeTrackError=218103818]="BE_SQLITE_ERROR_ChangeTrackError",l[l.BE_SQLITE_ERROR_InvalidChangeSetVersion=234881034]="BE_SQLITE_ERROR_InvalidChangeSetVersion",l[l.BE_SQLITE_ERROR_SchemaUpgradeRequired=251658250]="BE_SQLITE_ERROR_SchemaUpgradeRequired",l[l.BE_SQLITE_ERROR_SchemaTooNew=268435466]="BE_SQLITE_ERROR_SchemaTooNew",l[l.BE_SQLITE_ERROR_SchemaTooOld=285212682]="BE_SQLITE_ERROR_SchemaTooOld",l[l.BE_SQLITE_ERROR_SchemaLockFailed=301989898]="BE_SQLITE_ERROR_SchemaLockFailed",l[l.BE_SQLITE_ERROR_SchemaUpgradeFailed=318767114]="BE_SQLITE_ERROR_SchemaUpgradeFailed",l[l.BE_SQLITE_ERROR_SchemaImportFailed=335544330]="BE_SQLITE_ERROR_SchemaImportFailed",l[l.BE_SQLITE_ERROR_CouldNotAcquireLocksOrCodes=352321546]="BE_SQLITE_ERROR_CouldNotAcquireLocksOrCodes",l[l.BE_SQLITE_ERROR_SchemaUpgradeRecommended=369098762]="BE_SQLITE_ERROR_SchemaUpgradeRecommended",l[l.BE_SQLITE_ERROR_DataTransformRequired=385875978]="BE_SQLITE_ERROR_DataTransformRequired",l[l.BE_SQLITE_ERROR_DataDeletionRequired=402653194]="BE_SQLITE_ERROR_DataDeletionRequired",l[l.BE_SQLITE_ERROR_NOTOPEN=16777217]="BE_SQLITE_ERROR_NOTOPEN",l[l.BE_SQLITE_ERROR_PropagateChangesFailed=33554433]="BE_SQLITE_ERROR_PropagateChangesFailed",l[l.BE_SQLITE_LOCKED_SHAREDCACHE=262]="BE_SQLITE_LOCKED_SHAREDCACHE",l[l.BE_SQLITE_BUSY_RECOVERY=261]="BE_SQLITE_BUSY_RECOVERY",l[l.BE_SQLITE_CANTOPEN_NOTEMPDIR=270]="BE_SQLITE_CANTOPEN_NOTEMPDIR",l[l.BE_SQLITE_CANTOPEN_ISDIR=526]="BE_SQLITE_CANTOPEN_ISDIR",l[l.BE_SQLITE_CANTOPEN_FULLPATH=782]="BE_SQLITE_CANTOPEN_FULLPATH",l[l.BE_SQLITE_CORRUPT_VTAB=267]="BE_SQLITE_CORRUPT_VTAB",l[l.BE_SQLITE_READONLY_RECOVERY=264]="BE_SQLITE_READONLY_RECOVERY",l[l.BE_SQLITE_READONLY_CANTLOCK=520]="BE_SQLITE_READONLY_CANTLOCK",l[l.BE_SQLITE_READONLY_ROLLBACK=776]="BE_SQLITE_READONLY_ROLLBACK",l[l.BE_SQLITE_ABORT_ROLLBACK=516]="BE_SQLITE_ABORT_ROLLBACK",l[l.BE_SQLITE_CONSTRAINT_CHECK=275]="BE_SQLITE_CONSTRAINT_CHECK",l[l.BE_SQLITE_CONSTRAINT_COMMITHOOK=531]="BE_SQLITE_CONSTRAINT_COMMITHOOK",l[l.BE_SQLITE_CONSTRAINT_FOREIGNKEY=787]="BE_SQLITE_CONSTRAINT_FOREIGNKEY",l[l.BE_SQLITE_CONSTRAINT_FUNCTION=1043]="BE_SQLITE_CONSTRAINT_FUNCTION",l[l.BE_SQLITE_CONSTRAINT_NOTNULL=1299]="BE_SQLITE_CONSTRAINT_NOTNULL",l[l.BE_SQLITE_CONSTRAINT_PRIMARYKEY=1555]="BE_SQLITE_CONSTRAINT_PRIMARYKEY",l[l.BE_SQLITE_CONSTRAINT_TRIGGER=1811]="BE_SQLITE_CONSTRAINT_TRIGGER",l[l.BE_SQLITE_CONSTRAINT_UNIQUE=2067]="BE_SQLITE_CONSTRAINT_UNIQUE",l[l.BE_SQLITE_CONSTRAINT_VTAB=2323]="BE_SQLITE_CONSTRAINT_VTAB"})(z||(z={}));var yt;(function(l){l[l.Success=0]="Success",l[l.ServerUnavailable=86017]="ServerUnavailable",l[l.LockAlreadyHeld=86018]="LockAlreadyHeld",l[l.SyncError=86019]="SyncError",l[l.InvalidResponse=86020]="InvalidResponse",l[l.PendingTransactions=86021]="PendingTransactions",l[l.LockUsed=86022]="LockUsed",l[l.CannotCreateChangeSet=86023]="CannotCreateChangeSet",l[l.InvalidRequest=86024]="InvalidRequest",l[l.ChangeSetRequired=86025]="ChangeSetRequired",l[l.CodeUnavailable=86026]="CodeUnavailable",l[l.CodeNotReserved=86027]="CodeNotReserved",l[l.CodeUsed=86028]="CodeUsed",l[l.LockNotHeld=86029]="LockNotHeld",l[l.RepositoryIsLocked=86030]="RepositoryIsLocked",l[l.ChannelConstraintViolation=86031]="ChannelConstraintViolation"})(yt||(yt={}));var K;(function(l){function e(p,x=!1){return u(p)?x:!!p}l.asBool=e;function t(p,x=0){return typeof p=="number"?Math.trunc(p):x}l.asInt=t;function n(p,x=0){return typeof p=="number"?p:x}l.asDouble=n;function i(p,x=""){return u(p)?x:p.toString()}l.asString=i;function s(p){return Array.isArray(p)?p:void 0}l.asArray=s;function r(p){return typeof p=="object"?p:void 0}l.asObject=r;function a(p,x,_,I){_===I?delete p[x]:p[x]=_}l.setOrRemoveNumber=a;function o(p,x,_,I){_===I?delete p[x]:p[x]=_}l.setOrRemoveBoolean=o;function c(p){return p!==null&&typeof p=="object"}l.isObject=c;function d(p){return c(p)&&Object.keys(p).length===0}l.isEmptyObject=d;function h(p){return p===void 0||d(p)}l.isEmptyObjectOrUndefined=h;function u(p){return p==null}function g(p){return!h(p)}l.isNonEmptyObject=g;function m(p){if(typeof p=="boolean"||typeof p=="number"||typeof p=="string")return p;if(typeof p!="object")return;if(typeof p.toJSON<"u")return m(p.toJSON());if(Array.isArray(p)){const _=new Array(p.length);return p.forEach((I,S)=>_[S]=m(I)),_}const x={};return Object.getOwnPropertyNames(p).forEach(_=>{const I=m(p[_]);I!==void 0&&(x[_]=I)}),x}l.toObject=m})(K||(K={}));var Er;(function(l){function e(i){const s=new Error(i.message);return Object.assign(s,i),s.name=i.iTwinErrorId.key,s}l.create=e;function t(i){throw e(i)}l.throwError=t;function n(i,s,r){return K.isObject(i)&&"iTwinErrorId"in i&&K.isObject(i.iTwinErrorId)&&i.iTwinErrorId.scope===s&&(r===void 0||i.iTwinErrorId.key===r)}l.isError=n})(Er||(Er={}));var vs;(function(l){l[l.SUCCESS=0]="SUCCESS",l[l.ERROR=32768]="ERROR"})(vs||(vs={}));var j;(function(l){l[l.IMODEL_ERROR_BASE=65536]="IMODEL_ERROR_BASE",l[l.Success=0]="Success",l[l.AlreadyLoaded=65537]="AlreadyLoaded",l[l.AlreadyOpen=65538]="AlreadyOpen",l[l.BadArg=65539]="BadArg",l[l.BadElement=65540]="BadElement",l[l.BadModel=65541]="BadModel",l[l.BadRequest=65542]="BadRequest",l[l.BadSchema=65543]="BadSchema",l[l.CannotUndo=65544]="CannotUndo",l[l.CodeNotReserved=65545]="CodeNotReserved",l[l.DeletionProhibited=65546]="DeletionProhibited",l[l.DuplicateCode=65547]="DuplicateCode",l[l.DuplicateName=65548]="DuplicateName",l[l.ElementBlockedChange=65549]="ElementBlockedChange",l[l.FileAlreadyExists=65550]="FileAlreadyExists",l[l.FileNotFound=65551]="FileNotFound",l[l.FileNotLoaded=65552]="FileNotLoaded",l[l.ForeignKeyConstraint=65553]="ForeignKeyConstraint",l[l.IdExists=65554]="IdExists",l[l.InDynamicTransaction=65555]="InDynamicTransaction",l[l.InvalidCategory=65556]="InvalidCategory",l[l.InvalidCode=65557]="InvalidCode",l[l.InvalidCodeSpec=65558]="InvalidCodeSpec",l[l.InvalidId=65559]="InvalidId",l[l.InvalidName=65560]="InvalidName",l[l.InvalidParent=65561]="InvalidParent",l[l.InvalidProfileVersion=65562]="InvalidProfileVersion",l[l.IsCreatingChangeSet=65563]="IsCreatingChangeSet",l[l.LockNotHeld=65564]="LockNotHeld",l[l.Mismatch2d3d=65565]="Mismatch2d3d",l[l.MismatchGcs=65566]="MismatchGcs",l[l.MissingDomain=65567]="MissingDomain",l[l.MissingHandler=65568]="MissingHandler",l[l.MissingId=65569]="MissingId",l[l.NoGeometry=65570]="NoGeometry",l[l.NoMultiTxnOperation=65571]="NoMultiTxnOperation",l[l.NotEnabled=65573]="NotEnabled",l[l.NotFound=65574]="NotFound",l[l.NotOpen=65575]="NotOpen",l[l.NotOpenForWrite=65576]="NotOpenForWrite",l[l.NotSameUnitBase=65577]="NotSameUnitBase",l[l.NothingToRedo=65578]="NothingToRedo",l[l.NothingToUndo=65579]="NothingToUndo",l[l.ParentBlockedChange=65580]="ParentBlockedChange",l[l.ReadError=65581]="ReadError",l[l.ReadOnly=65582]="ReadOnly",l[l.ReadOnlyDomain=65583]="ReadOnlyDomain",l[l.RepositoryManagerError=65584]="RepositoryManagerError",l[l.SQLiteError=65585]="SQLiteError",l[l.TransactionActive=65586]="TransactionActive",l[l.UnitsMissing=65587]="UnitsMissing",l[l.UnknownFormat=65588]="UnknownFormat",l[l.UpgradeFailed=65589]="UpgradeFailed",l[l.ValidationFailed=65590]="ValidationFailed",l[l.VersionTooNew=65591]="VersionTooNew",l[l.VersionTooOld=65592]="VersionTooOld",l[l.ViewNotFound=65593]="ViewNotFound",l[l.WriteError=65594]="WriteError",l[l.WrongClass=65595]="WrongClass",l[l.WrongIModel=65596]="WrongIModel",l[l.WrongDomain=65597]="WrongDomain",l[l.WrongElement=65598]="WrongElement",l[l.WrongHandler=65599]="WrongHandler",l[l.WrongModel=65600]="WrongModel",l[l.ConstraintNotUnique=65601]="ConstraintNotUnique",l[l.NoGeoLocation=65602]="NoGeoLocation",l[l.ServerTimeout=65603]="ServerTimeout",l[l.NoContent=65604]="NoContent",l[l.NotRegistered=65605]="NotRegistered",l[l.FunctionNotFound=65606]="FunctionNotFound",l[l.NoActiveCommand=65607]="NoActiveCommand",l[l.Aborted=65608]="Aborted"})(j||(j={}));var Nn;(function(l){l[l.BRIEFCASE_STATUS_BASE=131072]="BRIEFCASE_STATUS_BASE",l[l.CannotAcquire=131072]="CannotAcquire",l[l.CannotDownload=131073]="CannotDownload",l[l.CannotUpload=131074]="CannotUpload",l[l.CannotCopy=131075]="CannotCopy",l[l.CannotDelete=131076]="CannotDelete",l[l.VersionNotFound=131077]="VersionNotFound",l[l.CannotApplyChanges=131078]="CannotApplyChanges",l[l.DownloadCancelled=131079]="DownloadCancelled",l[l.ContainsDeletedChangeSets=131080]="ContainsDeletedChangeSets"})(Nn||(Nn={}));var kr;(function(l){l[l.Success=0]="Success",l[l.RPC_INTERFACE_ERROR_BASE=135168]="RPC_INTERFACE_ERROR_BASE",l[l.IncompatibleVersion=135168]="IncompatibleVersion"})(kr||(kr={}));var Ue;(function(l){l[l.Success=0]="Success",l[l.CHANGESET_ERROR_BASE=90112]="CHANGESET_ERROR_BASE",l[l.ApplyError=90113]="ApplyError",l[l.ChangeTrackingNotEnabled=90114]="ChangeTrackingNotEnabled",l[l.CorruptedChangeStream=90115]="CorruptedChangeStream",l[l.FileNotFound=90116]="FileNotFound",l[l.FileWriteError=90117]="FileWriteError",l[l.HasLocalChanges=90118]="HasLocalChanges",l[l.HasUncommittedChanges=90119]="HasUncommittedChanges",l[l.InvalidId=90120]="InvalidId",l[l.InvalidVersion=90121]="InvalidVersion",l[l.InDynamicTransaction=90122]="InDynamicTransaction",l[l.IsCreatingChangeSet=90123]="IsCreatingChangeSet",l[l.IsNotCreatingChangeSet=90124]="IsNotCreatingChangeSet",l[l.MergePropagationError=90125]="MergePropagationError",l[l.NothingToMerge=90126]="NothingToMerge",l[l.NoTransactions=90127]="NoTransactions",l[l.ParentMismatch=90128]="ParentMismatch",l[l.SQLiteError=90129]="SQLiteError",l[l.WrongDgnDb=90130]="WrongDgnDb",l[l.CouldNotOpenDgnDb=90131]="CouldNotOpenDgnDb",l[l.MergeSchemaChangesOnOpen=90132]="MergeSchemaChangesOnOpen",l[l.ReverseOrReinstateSchemaChanges=90133]="ReverseOrReinstateSchemaChanges",l[l.ProcessSchemaChangesOnOpen=90134]="ProcessSchemaChangesOnOpen",l[l.CannotMergeIntoReadonly=90135]="CannotMergeIntoReadonly",l[l.CannotMergeIntoMaster=90136]="CannotMergeIntoMaster",l[l.CannotMergeIntoReversed=90137]="CannotMergeIntoReversed",l[l.DownloadCancelled=90138]="DownloadCancelled"})(Ue||(Ue={}));var Ri;(function(l){l[l.Success=0]="Success",l[l.Info=94209]="Info",l[l.Redirection=94210]="Redirection",l[l.ClientError=94211]="ClientError",l[l.ServerError=94212]="ServerError"})(Ri||(Ri={}));var de;(function(l){l[l.Success=0]="Success",l[l.IMODELHUBERROR_BASE=102400]="IMODELHUBERROR_BASE",l[l.IMODELHUBERROR_REQUESTERRORBASE=102656]="IMODELHUBERROR_REQUESTERRORBASE",l[l.Unknown=102401]="Unknown",l[l.MissingRequiredProperties=102402]="MissingRequiredProperties",l[l.InvalidPropertiesValues=102403]="InvalidPropertiesValues",l[l.UserDoesNotHavePermission=102404]="UserDoesNotHavePermission",l[l.UserDoesNotHaveAccess=102405]="UserDoesNotHaveAccess",l[l.InvalidBriefcase=102406]="InvalidBriefcase",l[l.BriefcaseDoesNotExist=102407]="BriefcaseDoesNotExist",l[l.BriefcaseDoesNotBelongToUser=102408]="BriefcaseDoesNotBelongToUser",l[l.AnotherUserPushing=102409]="AnotherUserPushing",l[l.ChangeSetAlreadyExists=102410]="ChangeSetAlreadyExists",l[l.ChangeSetDoesNotExist=102411]="ChangeSetDoesNotExist",l[l.FileIsNotUploaded=102412]="FileIsNotUploaded",l[l.iModelIsNotInitialized=102413]="iModelIsNotInitialized",l[l.ChangeSetPointsToBadSeed=102414]="ChangeSetPointsToBadSeed",l[l.OperationFailed=102415]="OperationFailed",l[l.PullIsRequired=102416]="PullIsRequired",l[l.MaximumNumberOfBriefcasesPerUser=102417]="MaximumNumberOfBriefcasesPerUser",l[l.MaximumNumberOfBriefcasesPerUserPerMinute=102418]="MaximumNumberOfBriefcasesPerUserPerMinute",l[l.DatabaseTemporarilyLocked=102419]="DatabaseTemporarilyLocked",l[l.iModelIsLocked=102420]="iModelIsLocked",l[l.CodesExist=102421]="CodesExist",l[l.LocksExist=102422]="LocksExist",l[l.iModelAlreadyExists=102423]="iModelAlreadyExists",l[l.iModelDoesNotExist=102424]="iModelDoesNotExist",l[l.FileDoesNotExist=102425]="FileDoesNotExist",l[l.FileAlreadyExists=102426]="FileAlreadyExists",l[l.LockDoesNotExist=102427]="LockDoesNotExist",l[l.LockOwnedByAnotherBriefcase=102428]="LockOwnedByAnotherBriefcase",l[l.CodeStateInvalid=102429]="CodeStateInvalid",l[l.CodeReservedByAnotherBriefcase=102430]="CodeReservedByAnotherBriefcase",l[l.CodeDoesNotExist=102431]="CodeDoesNotExist",l[l.EventTypeDoesNotExist=102432]="EventTypeDoesNotExist",l[l.EventSubscriptionDoesNotExist=102433]="EventSubscriptionDoesNotExist",l[l.EventSubscriptionAlreadyExists=102434]="EventSubscriptionAlreadyExists",l[l.ITwinIdIsNotSpecified=102435]="ITwinIdIsNotSpecified",l[l.FailedToGetITwinPermissions=102436]="FailedToGetITwinPermissions",l[l.FailedToGetITwinMembers=102437]="FailedToGetITwinMembers",l[l.ChangeSetAlreadyHasVersion=102438]="ChangeSetAlreadyHasVersion",l[l.VersionAlreadyExists=102439]="VersionAlreadyExists",l[l.JobSchedulingFailed=102440]="JobSchedulingFailed",l[l.ConflictsAggregate=102441]="ConflictsAggregate",l[l.FailedToGetITwinById=102442]="FailedToGetITwinById",l[l.DatabaseOperationFailed=102443]="DatabaseOperationFailed",l[l.SeedFileInitializationFailed=102444]="SeedFileInitializationFailed",l[l.FailedToGetAssetPermissions=102445]="FailedToGetAssetPermissions",l[l.FailedToGetAssetMembers=102446]="FailedToGetAssetMembers",l[l.ITwinDoesNotExist=102447]="ITwinDoesNotExist",l[l.LockChunkDoesNotExist=102449]="LockChunkDoesNotExist",l[l.CheckpointAlreadyExists=102450]="CheckpointAlreadyExists",l[l.CheckpointDoesNotExist=102451]="CheckpointDoesNotExist",l[l.UndefinedArgumentError=102657]="UndefinedArgumentError",l[l.InvalidArgumentError=102658]="InvalidArgumentError",l[l.MissingDownloadUrlError=102659]="MissingDownloadUrlError",l[l.NotSupportedInBrowser=102660]="NotSupportedInBrowser",l[l.FileHandlerNotSet=102661]="FileHandlerNotSet",l[l.FileNotFound=102662]="FileNotFound",l[l.InitializationTimeout=102663]="InitializationTimeout"})(de||(de={}));var On;(function(l){l[l.Success=0]="Success",l[l.GEOSERVICESTATUS_BASE=147456]="GEOSERVICESTATUS_BASE",l[l.NoGeoLocation=65602]="NoGeoLocation",l[l.OutOfUsefulRange=147457]="OutOfUsefulRange",l[l.OutOfMathematicalDomain=147458]="OutOfMathematicalDomain",l[l.NoDatumConverter=147459]="NoDatumConverter",l[l.VerticalDatumConvertError=147460]="VerticalDatumConvertError",l[l.CSMapError=147461]="CSMapError",l[l.Pending=147462]="Pending"})(On||(On={}));var Fr;(function(l){l[l.Success=0]="Success",l[l.REALITYDATA_ERROR_BASE=151552]="REALITYDATA_ERROR_BASE",l[l.InvalidData=151553]="InvalidData"})(Fr||(Fr={}));class nt extends Error{errorNumber;static iTwinErrorScope="bentley-error";_metaData;constructor(e,t,n){super(t),this.errorNumber=e,this.errorNumber=e,this._metaData=n,this.name=this._initName()}get iTwinErrorId(){return{scope:nt.iTwinErrorScope,key:this.name}}get loggingMetadata(){return this.getMetaData()}static isError(e,t){return Er.isError(e,nt.iTwinErrorScope)&&typeof e.errorNumber=="number"&&(t===void 0||e.errorNumber===t)}get hasMetaData(){return this._metaData!==void 0}getMetaData(){return nt.getMetaData(this._metaData)}static getMetaData(e){return typeof e=="function"?e():e}_initName(){return nt.getErrorKey(this.errorNumber)}static getErrorKey(e){switch(e){case j.AlreadyLoaded:return"Already Loaded";case j.AlreadyOpen:return"Already Open";case j.BadArg:return"Bad Arg";case j.BadElement:return"Bad Element";case j.BadModel:return"Bad Model";case j.BadRequest:return"Bad Request";case j.BadSchema:return"Bad Schema";case j.CannotUndo:return"Can not Undo";case j.CodeNotReserved:return"Code Not Reserved";case j.DeletionProhibited:return"Deletion Prohibited";case j.DuplicateCode:return"Duplicate Code";case j.DuplicateName:return"Duplicate Name";case j.ElementBlockedChange:return"Element Blocked Change";case j.FileAlreadyExists:return"File Already Exists";case j.FileNotFound:return"File Not Found";case j.FileNotLoaded:return"File Not Loaded";case j.ForeignKeyConstraint:return"ForeignKey Constraint";case j.IdExists:return"Id Exists";case j.InDynamicTransaction:return"InDynamicTransaction";case j.InvalidCategory:return"Invalid Category";case j.InvalidCode:return"Invalid Code";case j.InvalidCodeSpec:return"Invalid CodeSpec";case j.InvalidId:return"Invalid Id";case j.InvalidName:return"Invalid Name";case j.InvalidParent:return"Invalid Parent";case j.InvalidProfileVersion:return"Invalid Profile Version";case j.IsCreatingChangeSet:return"IsCreatingChangeSet";case j.LockNotHeld:return"Lock Not Held";case j.Mismatch2d3d:return"Mismatch 2d3d";case j.MismatchGcs:return"Mismatch Gcs";case j.MissingDomain:return"Missing Domain";case j.MissingHandler:return"Missing Handler";case j.MissingId:return"Missing Id";case j.NoGeometry:return"No Geometry";case j.NoMultiTxnOperation:return"NoMultiTxnOperation";case j.NotEnabled:return"Not Enabled";case j.NotFound:return"Not Found";case j.NotOpen:return"Not Open";case j.NotOpenForWrite:return"Not Open For Write";case j.NotSameUnitBase:return"Not Same Unit Base";case j.NothingToRedo:return"Nothing To Redo";case j.NothingToUndo:return"Nothing To Undo";case j.ParentBlockedChange:return"Parent Blocked Change";case j.ReadError:return"Read Error";case j.ReadOnly:return"ReadOnly";case j.ReadOnlyDomain:return"ReadOnlyDomain";case j.RepositoryManagerError:return"RepositoryManagerError";case j.SQLiteError:return"SQLiteError";case j.TransactionActive:return"Transaction Active";case j.UnitsMissing:return"Units Missing";case j.UnknownFormat:return"Unknown Format";case j.UpgradeFailed:return"Upgrade Failed";case j.ValidationFailed:return"Validation Failed";case j.VersionTooNew:return"Version Too New";case j.VersionTooOld:return"Version Too Old";case j.ViewNotFound:return"View Not Found";case j.WriteError:return"Write Error";case j.WrongClass:return"Wrong Class";case j.WrongIModel:return"Wrong IModel";case j.WrongDomain:return"Wrong Domain";case j.WrongElement:return"Wrong Element";case j.WrongHandler:return"Wrong Handler";case j.WrongModel:return"Wrong Model";case z.BE_SQLITE_ERROR:return"BE_SQLITE_ERROR";case z.BE_SQLITE_INTERNAL:return"BE_SQLITE_INTERNAL";case z.BE_SQLITE_PERM:return"BE_SQLITE_PERM";case z.BE_SQLITE_ABORT:return"BE_SQLITE_ABORT";case z.BE_SQLITE_BUSY:return"Db is busy";case z.BE_SQLITE_LOCKED:return"Db is Locked";case z.BE_SQLITE_NOMEM:return"BE_SQLITE_NOMEM";case z.BE_SQLITE_READONLY:return"Readonly";case z.BE_SQLITE_INTERRUPT:return"BE_SQLITE_INTERRUPT";case z.BE_SQLITE_IOERR:return"BE_SQLITE_IOERR";case z.BE_SQLITE_CORRUPT:return"BE_SQLITE_CORRUPT";case z.BE_SQLITE_NOTFOUND:return"Not Found";case z.BE_SQLITE_FULL:return"BE_SQLITE_FULL";case z.BE_SQLITE_CANTOPEN:return"Can't open";case z.BE_SQLITE_PROTOCOL:return"BE_SQLITE_PROTOCOL";case z.BE_SQLITE_EMPTY:return"BE_SQLITE_EMPTY";case z.BE_SQLITE_SCHEMA:return"BE_SQLITE_SCHEMA";case z.BE_SQLITE_TOOBIG:return"BE_SQLITE_TOOBIG";case z.BE_SQLITE_MISMATCH:return"BE_SQLITE_MISMATCH";case z.BE_SQLITE_MISUSE:return"BE_SQLITE_MISUSE";case z.BE_SQLITE_NOLFS:return"BE_SQLITE_NOLFS";case z.BE_SQLITE_AUTH:return"BE_SQLITE_AUTH";case z.BE_SQLITE_FORMAT:return"BE_SQLITE_FORMAT";case z.BE_SQLITE_RANGE:return"BE_SQLITE_RANGE";case z.BE_SQLITE_NOTADB:return"Not a Database";case z.BE_SQLITE_IOERR_READ:return"BE_SQLITE_IOERR_READ";case z.BE_SQLITE_IOERR_SHORT_READ:return"BE_SQLITE_IOERR_SHORT_READ";case z.BE_SQLITE_IOERR_WRITE:return"BE_SQLITE_IOERR_WRITE";case z.BE_SQLITE_IOERR_FSYNC:return"BE_SQLITE_IOERR_FSYNC";case z.BE_SQLITE_IOERR_DIR_FSYNC:return"BE_SQLITE_IOERR_DIR_FSYNC";case z.BE_SQLITE_IOERR_TRUNCATE:return"BE_SQLITE_IOERR_TRUNCATE";case z.BE_SQLITE_IOERR_FSTAT:return"BE_SQLITE_IOERR_FSTAT";case z.BE_SQLITE_IOERR_UNLOCK:return"BE_SQLITE_IOERR_UNLOCK";case z.BE_SQLITE_IOERR_RDLOCK:return"BE_SQLITE_IOERR_RDLOCK";case z.BE_SQLITE_IOERR_DELETE:return"BE_SQLITE_IOERR_DELETE";case z.BE_SQLITE_IOERR_BLOCKED:return"BE_SQLITE_IOERR_BLOCKED";case z.BE_SQLITE_IOERR_NOMEM:return"BE_SQLITE_IOERR_NOMEM";case z.BE_SQLITE_IOERR_ACCESS:return"BE_SQLITE_IOERR_ACCESS";case z.BE_SQLITE_IOERR_CHECKRESERVEDLOCK:return"BE_SQLITE_IOERR_CHECKRESERVEDLOCK";case z.BE_SQLITE_IOERR_LOCK:return"BE_SQLITE_IOERR_LOCK";case z.BE_SQLITE_IOERR_CLOSE:return"BE_SQLITE_IOERR_CLOSE";case z.BE_SQLITE_IOERR_DIR_CLOSE:return"BE_SQLITE_IOERR_DIR_CLOSE";case z.BE_SQLITE_IOERR_SHMOPEN:return"BE_SQLITE_IOERR_SHMOPEN";case z.BE_SQLITE_IOERR_SHMSIZE:return"BE_SQLITE_IOERR_SHMSIZE";case z.BE_SQLITE_IOERR_SHMLOCK:return"BE_SQLITE_IOERR_SHMLOCK";case z.BE_SQLITE_IOERR_SHMMAP:return"BE_SQLITE_IOERR_SHMMAP";case z.BE_SQLITE_IOERR_SEEK:return"BE_SQLITE_IOERR_SEEK";case z.BE_SQLITE_IOERR_DELETE_NOENT:return"BE_SQLITE_IOERR_DELETE_NOENT";case z.BE_SQLITE_ERROR_DataTransformRequired:return"Schema update require to transform data";case z.BE_SQLITE_ERROR_DataDeletionRequired:return"Schema update would destroy existing data";case z.BE_SQLITE_ERROR_FileExists:return"File Exists";case z.BE_SQLITE_ERROR_AlreadyOpen:return"Already Open";case z.BE_SQLITE_ERROR_NoPropertyTable:return"No Property Table";case z.BE_SQLITE_ERROR_FileNotFound:return"File Not Found";case z.BE_SQLITE_ERROR_NoTxnActive:return"No Txn Active";case z.BE_SQLITE_ERROR_BadDbProfile:return"Bad Db Profile";case z.BE_SQLITE_ERROR_InvalidProfileVersion:return"Invalid Profile Version";case z.BE_SQLITE_ERROR_ProfileUpgradeFailed:return"Profile Upgrade Failed";case z.BE_SQLITE_ERROR_ProfileTooOldForReadWrite:return"Profile Too Old For ReadWrite";case z.BE_SQLITE_ERROR_ProfileTooOld:return"Profile Too Old";case z.BE_SQLITE_ERROR_ProfileTooNewForReadWrite:return"Profile Too New For ReadWrite";case z.BE_SQLITE_ERROR_ProfileTooNew:return"Profile Too New";case z.BE_SQLITE_ERROR_ChangeTrackError:return"ChangeTrack Error";case z.BE_SQLITE_ERROR_InvalidChangeSetVersion:return"Invalid ChangeSet Version";case z.BE_SQLITE_ERROR_SchemaUpgradeRequired:return"Schema Upgrade Required";case z.BE_SQLITE_ERROR_SchemaTooNew:return"Schema Too New";case z.BE_SQLITE_ERROR_SchemaTooOld:return"Schema Too Old";case z.BE_SQLITE_ERROR_SchemaLockFailed:return"Schema Lock Failed";case z.BE_SQLITE_ERROR_SchemaUpgradeFailed:return"Schema Upgrade Failed";case z.BE_SQLITE_ERROR_SchemaImportFailed:return"Schema Import Failed";case z.BE_SQLITE_ERROR_CouldNotAcquireLocksOrCodes:return"Could Not Acquire Locks Or Codes";case z.BE_SQLITE_ERROR_SchemaUpgradeRecommended:return"Recommended that the schemas found in the database be upgraded";case z.BE_SQLITE_LOCKED_SHAREDCACHE:return"BE_SQLITE_LOCKED_SHAREDCACHE";case z.BE_SQLITE_BUSY_RECOVERY:return"BE_SQLITE_BUSY_RECOVERY";case z.BE_SQLITE_CANTOPEN_NOTEMPDIR:return"SQLite No Temp Dir";case z.BE_SQLITE_CANTOPEN_ISDIR:return"BE_SQLITE_CANTOPEN_ISDIR";case z.BE_SQLITE_CANTOPEN_FULLPATH:return"BE_SQLITE_CANTOPEN_FULLPATH";case z.BE_SQLITE_CORRUPT_VTAB:return"BE_SQLITE_CORRUPT_VTAB";case z.BE_SQLITE_READONLY_RECOVERY:return"BE_SQLITE_READONLY_RECOVERY";case z.BE_SQLITE_READONLY_CANTLOCK:return"BE_SQLITE_READONLY_CANTLOCK";case z.BE_SQLITE_READONLY_ROLLBACK:return"BE_SQLITE_READONLY_ROLLBACK";case z.BE_SQLITE_ABORT_ROLLBACK:return"BE_SQLITE_ABORT_ROLLBACK";case z.BE_SQLITE_CONSTRAINT_CHECK:return"BE_SQLITE_CONSTRAINT_CHECK";case z.BE_SQLITE_CONSTRAINT_COMMITHOOK:return"CommitHook Constraint Error";case z.BE_SQLITE_CONSTRAINT_FOREIGNKEY:return"Foreign Key Constraint Error";case z.BE_SQLITE_CONSTRAINT_FUNCTION:return"Function Constraint Error";case z.BE_SQLITE_CONSTRAINT_NOTNULL:return"NotNull Constraint Error";case z.BE_SQLITE_CONSTRAINT_PRIMARYKEY:return"Primary Key Constraint Error";case z.BE_SQLITE_CONSTRAINT_TRIGGER:return"Trigger Constraint Error";case z.BE_SQLITE_CONSTRAINT_UNIQUE:return"Unique Constraint Error";case z.BE_SQLITE_CONSTRAINT_VTAB:return"VTable Constraint Error";case vs.ERROR:return"Error";case Nn.CannotAcquire:return"CannotAcquire";case Nn.CannotDownload:return"CannotDownload";case Nn.CannotCopy:return"CannotCopy";case Nn.CannotDelete:return"CannotDelete";case Nn.VersionNotFound:return"VersionNotFound";case Nn.DownloadCancelled:return"DownloadCancelled";case Nn.ContainsDeletedChangeSets:return"ContainsDeletedChangeSets";case kr.IncompatibleVersion:return"RpcInterfaceStatus.IncompatibleVersion";case Ue.ApplyError:return"Error applying a change set";case Ue.ChangeTrackingNotEnabled:return"Change tracking has not been enabled. The ChangeSet API mandates this";case Ue.CorruptedChangeStream:return"Contents of the change stream are corrupted and does not match the ChangeSet";case Ue.FileNotFound:return"File containing the changes was not found";case Ue.FileWriteError:return"Error writing the contents of the change set to the backing change stream file";case Ue.HasLocalChanges:return"Cannot perform the operation since the Db has local changes";case Ue.HasUncommittedChanges:return"Cannot perform the operation since current transaction has uncommitted changes";case Ue.InvalidId:return"Invalid ChangeSet Id";case Ue.InvalidVersion:return"Invalid version of the change set";case Ue.InDynamicTransaction:return"Cannot perform the operation since system is in the middle of a dynamic transaction";case Ue.IsCreatingChangeSet:return"Cannot perform operation since system is in the middle of a creating a change set";case Ue.IsNotCreatingChangeSet:return"Cannot perform operation since the system is not creating a change set";case Ue.MergePropagationError:return"Error propagating the changes after the merge";case Ue.NothingToMerge:return"No change sets to merge";case Ue.NoTransactions:return"No transactions are available to create a change set";case Ue.ParentMismatch:return"Parent change set of the Db does not match the parent id of the change set";case Ue.SQLiteError:return"Error performing a SQLite operation on the Db";case Ue.WrongDgnDb:return"ChangeSet originated in a different Db";case Ue.CouldNotOpenDgnDb:return"Could not open the DgnDb to merge change set";case Ue.MergeSchemaChangesOnOpen:return"Cannot merge changes in in an open DgnDb. Close the DgnDb, and process the operation when it is opened";case Ue.ReverseOrReinstateSchemaChanges:return"Cannot reverse or reinstate schema changes.";case Ue.ProcessSchemaChangesOnOpen:return"Cannot process changes schema changes in an open DgnDb. Close the DgnDb, and process the operation when it is opened";case Ue.CannotMergeIntoReadonly:return"Cannot merge changes into a Readonly DgnDb";case Ue.CannotMergeIntoMaster:return"Cannot merge changes into a Master DgnDb";case Ue.CannotMergeIntoReversed:return"Cannot merge changes into a DgnDb that has reversed change sets";case Ue.DownloadCancelled:return"ChangeSet(s) download was cancelled.";case yt.ServerUnavailable:return"ServerUnavailable";case yt.LockAlreadyHeld:return"LockAlreadyHeld";case yt.SyncError:return"SyncError";case yt.InvalidResponse:return"InvalidResponse";case yt.PendingTransactions:return"PendingTransactions";case yt.LockUsed:return"LockUsed";case yt.CannotCreateChangeSet:return"CannotCreateChangeSet";case yt.InvalidRequest:return"InvalidRequest";case yt.ChangeSetRequired:return"ChangeSetRequired";case yt.CodeUnavailable:return"CodeUnavailable";case yt.CodeNotReserved:return"CodeNotReserved";case yt.CodeUsed:return"CodeUsed";case yt.LockNotHeld:return"LockNotHeld";case yt.RepositoryIsLocked:return"RepositoryIsLocked";case yt.ChannelConstraintViolation:return"ChannelConstraintViolation";case Ri.Info:return"HTTP Info";case Ri.Redirection:return"HTTP Redirection";case Ri.ClientError:return"HTTP Client error";case Ri.ServerError:return"HTTP Server error";case de.Unknown:return"Unknown error";case de.MissingRequiredProperties:return"Missing required properties";case de.InvalidPropertiesValues:return"Invalid properties values";case de.UserDoesNotHavePermission:return"User does not have permission";case de.UserDoesNotHaveAccess:return"User does not have access";case de.InvalidBriefcase:return"Invalid briefcase";case de.BriefcaseDoesNotExist:return"Briefcase does not exist";case de.BriefcaseDoesNotBelongToUser:return"Briefcase does not belong to user";case de.AnotherUserPushing:return"Another user pushing";case de.ChangeSetAlreadyExists:return"ChangeSet already exists";case de.ChangeSetDoesNotExist:return"ChangeSet does not exist";case de.FileIsNotUploaded:return"File is not uploaded";case de.iModelIsNotInitialized:return"iModel is not initialized";case de.ChangeSetPointsToBadSeed:return"ChangeSet points to a bad seed file";case de.OperationFailed:return"iModelHub operation has failed";case de.PullIsRequired:return"Pull is required";case de.MaximumNumberOfBriefcasesPerUser:return"Limit of briefcases per user was reached";case de.MaximumNumberOfBriefcasesPerUserPerMinute:return"Limit of briefcases per user per minute was reached";case de.DatabaseTemporarilyLocked:return"Database is temporarily locked";case de.iModelIsLocked:return"iModel is locked";case de.CodesExist:return"Code already exists";case de.LocksExist:return"Lock already exists";case de.iModelAlreadyExists:return"iModel already exists";case de.iModelDoesNotExist:return"iModel does not exist";case de.LockDoesNotExist:return"Lock does not exist";case de.LockChunkDoesNotExist:return"Lock chunk does not exist";case de.LockOwnedByAnotherBriefcase:return"Lock is owned by another briefcase";case de.CodeStateInvalid:return"Code state is invalid";case de.CodeReservedByAnotherBriefcase:return"Code is reserved by another briefcase";case de.CodeDoesNotExist:return"Code does not exist";case de.FileDoesNotExist:return"File does not exist";case de.FileAlreadyExists:return"File already exists";case de.EventTypeDoesNotExist:return"Event type does not exist";case de.EventSubscriptionDoesNotExist:return"Event subscription does not exist";case de.EventSubscriptionAlreadyExists:return"Event subscription already exists";case de.ITwinIdIsNotSpecified:return"ITwin Id is not specified";case de.FailedToGetITwinPermissions:return"Failed to get iTwin permissions";case de.FailedToGetITwinMembers:return"Failed to get iTwin members";case de.FailedToGetAssetPermissions:return"Failed to get asset permissions";case de.FailedToGetAssetMembers:return"Failed to get asset members";case de.ChangeSetAlreadyHasVersion:return"ChangeSet already has version";case de.VersionAlreadyExists:return"Version already exists";case de.JobSchedulingFailed:return"Failed to schedule a background job";case de.ConflictsAggregate:return"Codes or locks are owned by another briefcase";case de.FailedToGetITwinById:return"Failed to query iTwin by its id";case de.DatabaseOperationFailed:return"Database operation has failed";case de.ITwinDoesNotExist:return"ITwin does not exist";case de.UndefinedArgumentError:return"Undefined argument";case de.InvalidArgumentError:return"Invalid argument";case de.MissingDownloadUrlError:return"Missing download url";case de.NotSupportedInBrowser:return"Not supported in browser";case de.FileHandlerNotSet:return"File handler is not set";case de.FileNotFound:return"File not found";case On.NoGeoLocation:return"No GeoLocation";case On.OutOfUsefulRange:return"Out of useful range";case On.OutOfMathematicalDomain:return"Out of mathematical domain";case On.NoDatumConverter:return"No datum converter";case On.VerticalDatumConvertError:return"Vertical datum convert error";case On.CSMapError:return"CSMap error";case On.Pending:return"Pending";case Fr.InvalidData:return"Invalid or unknown data";case z.BE_SQLITE_OK:case z.BE_SQLITE_ROW:case z.BE_SQLITE_DONE:case vs.SUCCESS:return"Success";default:return`Error (${e})`}}static getErrorMessage(e){if(typeof e=="string")return e;if(e instanceof Error)return e.toString();if(K.isObject(e)){if(typeof e.message=="string")return e.message;if(typeof e.msg=="string")return e.msg;if(e.toString()!=="[object Object]")return e.toString()}return""}static getErrorStack(e){if(K.isObject(e)&&typeof e.stack=="string")return e.stack}static getErrorMetadata(e){if(K.isObject(e)&&typeof e.getMetaData=="function"){const t=e.getMetaData();if(typeof t=="object"&&t!==null)return t}}static getErrorProps(e){const t={message:nt.getErrorMessage(e)},n=nt.getErrorStack(e);n&&(t.stack=n);const i=nt.getErrorMetadata(e);return i&&(t.metadata=i),t}}var Mi;(function(l){l.Performance="Performance"})(Mi||(Mi={}));var bt;(function(l){l[l.Trace=0]="Trace",l[l.Info=1]="Info",l[l.Warning=2]="Warning",l[l.Error=3]="Error",l[l.None=4]="None"})(bt||(bt={}));class ue{static _logError;static _logWarning;static _logInfo;static _logTrace;static _onLogLevelChanged;static _staticMetaData=new Map;static get onLogLevelChanged(){return ue._onLogLevelChanged===void 0&&(ue._onLogLevelChanged=new hc),ue._onLogLevelChanged}static _categoryFilter={};static get categoryFilter(){return this._categoryFilter}static _minLevel;static get minLevel(){return this._minLevel}static logExceptionCallstacks=!1;static get staticMetaData(){return this._staticMetaData}static initialize(e,t,n,i){ue._logError=e,ue._logWarning=t,ue._logInfo=n,ue._logTrace=i,ue.turnOffLevelDefault(),ue.turnOffCategories()}static initializeToConsole(){const e=t=>(n,i,s)=>console.log(`${t} | ${n} | ${i} ${ue.stringifyMetaData(s)}`);ue.initialize(e("Error"),e("Warning"),e("Info"),e("Trace"))}static getMetaData(e){const t={};for(const n of this._staticMetaData){const i=nt.getMetaData(n[1]);i&&Object.assign(t,i)}return Object.assign(t,nt.getMetaData(e)),t}static stringifyMetaData(e){const t=this.getMetaData(e);return Object.keys(t).length>0?JSON.stringify(t):""}static setLevelDefault(e){this._minLevel=e,this.onLogLevelChanged.raiseEvent()}static setLevel(e,t){ue._categoryFilter[e]=t,this.onLogLevelChanged.raiseEvent()}static parseLogLevel(e){switch(e.toUpperCase()){case"EXCEPTION":return bt.Error;case"FATAL":return bt.Error;case"ERROR":return bt.Error;case"WARNING":return bt.Warning;case"INFO":return bt.Info;case"TRACE":return bt.Trace;case"DEBUG":return bt.Trace}return bt.None}static configureLevels(e){if(ue.validateProps(e),e.defaultLevel!==void 0&&this.setLevelDefault(ue.parseLogLevel(e.defaultLevel)),e.categoryLevels!==void 0)for(const t of e.categoryLevels)this.setLevel(t.category,ue.parseLogLevel(t.logLevel))}static isLogLevel(e){return bt.hasOwnProperty(e)}static validateProps(e){const t=["defaultLevel","categoryLevels"];for(const n of Object.keys(e)){if(!t.includes(n))throw new nt(j.BadArg,`LoggerLevelsConfig - unrecognized property: ${n}`);if(n==="defaultLevel"){if(!ue.isLogLevel(e.defaultLevel))throw new nt(j.BadArg,`LoggerLevelsConfig.defaultLevel must be a LogLevel. Invalid value: ${JSON.stringify(e.defaultLevel)}`)}else if(n==="categoryLevels"){const i=e[n];if(!Array.isArray(i))throw new nt(j.BadArg,`LoggerLevelsConfig.categoryLevels must be an array. Invalid value: ${JSON.stringify(i)}`);for(const s of e[n]){if(!s.hasOwnProperty("category")||!s.hasOwnProperty("logLevel"))throw new nt(j.BadArg,`LoggerLevelsConfig.categoryLevels - each item must be a LoggerCategoryAndLevel {category: logLevel:}. Invalid value: ${JSON.stringify(s)}`);if(!ue.isLogLevel(s.logLevel))throw new nt(j.BadArg,`LoggerLevelsConfig.categoryLevels - each item's logLevel property must be a LogLevel. Invalid value: ${JSON.stringify(s.logLevel)}`)}}}}static getLevel(e){const t=ue.categoryFilter[e];if(t!==void 0)return t;const n=e.lastIndexOf(".");return n!==-1?ue.getLevel(e.slice(0,n)):ue.minLevel}static turnOffLevelDefault(){ue._minLevel=void 0}static turnOffCategories(){ue._categoryFilter={}}static isEnabled(e,t){const n=ue.getLevel(e);return n!==void 0&&t>=n}static logError(e,t,n){ue._logError&&ue.isEnabled(e,bt.Error)&&(typeof t=="string"?ue._logError(e,t,n):nt.isError(t)?ue._logError(e,ue.getExceptionMessage(t),()=>({...nt.getErrorMetadata(t),exceptionType:t?.constructor?.name??"<Unknown>",...nt.getMetaData(n)})):ue._logError(e,ue.getExceptionMessage(t),ue.getExceptionMetaData(t,n)))}static getExceptionMessage(e){if(e===void 0)return"Error: error is undefined.";if(e===null)return"Error: error is null.";const t=ue.logExceptionCallstacks?`
|
|
2
|
+
${nt.getErrorStack(e)}`:"";return nt.getErrorMessage(e)+t}static getExceptionMetaData(e,t){const n=e?.constructor?.name??"<Unknown>";return t===void 0?()=>({exceptionType:n,...e}):()=>({exceptionType:n,...e,...nt.getMetaData(t)})}static logException(e,t,n=(i,s,r)=>ue.logError(i,s,r)){n(e,ue.getExceptionMessage(t),()=>nt.isError(t)?{...nt.getErrorMetadata(t),exceptionType:t?.constructor?.name??"<Unknown>"}:{...t})}static logWarning(e,t,n){ue._logWarning&&ue.isEnabled(e,bt.Warning)&&ue._logWarning(e,t,n)}static logInfo(e,t,n){ue._logInfo&&ue.isEnabled(e,bt.Info)&&ue._logInfo(e,t,n)}static logTrace(e,t,n){ue._logTrace&&ue.isEnabled(e,bt.Trace)&&ue._logTrace(e,t,n)}}class Rr{static _severity=bt.Info;_operation;_metaData;_startTimeStamp;constructor(e,t){if(this._operation=e,this._metaData=t,!ue.isEnabled(Mi.Performance,Rr._severity)){this._startTimeStamp=0;return}ue.logInfo(Mi.Performance,`${this._operation},START`,this._metaData),this._startTimeStamp=new Date().getTime()}logMessage(){const e=new Date().getTime();ue.isEnabled(Mi.Performance,Rr._severity)&&ue.logInfo(Mi.Performance,`${this._operation},END`,()=>({...this._metaData?nt.getMetaData(this._metaData):{},TimeElapsed:e-this._startTimeStamp}))}[Symbol.dispose](){this.logMessage()}dispose(){this[Symbol.dispose]()}}class lc{static reThrowImmediate=e=>{throw e};static reThrowDeferred=e=>setTimeout(()=>{throw e},0);static consoleLog=e=>console.error(e);static errorLog=e=>ue.logError("unhandled",e);static _telemetry=[];static _handler=this.errorLog;constructor(){}static addTelemetry(e){return this._telemetry.push(e),()=>this._telemetry.splice(this._telemetry.indexOf(e),1)}static handle(e,t=!0){this._handler(e),t&&this._telemetry.forEach(n=>{try{n(e)}catch{}})}static setHandler(e){const t=this._handler;return this._handler=e,t}}class hc{_listeners=[];_emitDepth=0;get numberOfListeners(){return this._listeners.length}addListener(e,t){return this._listeners.push({listener:e,scope:t,once:!1}),()=>this.removeListener(e,t)}addOnce(e,t){return this._listeners.push({listener:e,scope:t,once:!0}),()=>this.removeListener(e,t)}removeListener(e,t){const n=this._listeners;for(let i=0;i<n.length;++i){const s=n[i];if(s.listener===e&&s.scope===t)return this._emitDepth>0?s.listener=void 0:n.splice(i,1),!0}return!1}raiseEvent(...e){this._emitDepth++;const t=this._listeners,n=t.length;let i=!1;for(let s=0;s<n;++s){const r=t[s];if(!r.listener)i=!0;else{try{r.listener.apply(r.scope,e)}catch(a){lc.handle(a)}r.listener?r.once&&(r.listener=void 0,i=!0):i=!0}}this._emitDepth--,i&&this._emitDepth===0&&(this._listeners=this._listeners.filter(s=>s.listener!==void 0))}has(e,t){for(const n of this._listeners)if(n.listener===e&&n.scope===t)return!0;return!1}clear(){this._listeners.length=0}}function Ss(l){const e=parseInt(l,16);return Number.isNaN(e)?0:e}function uc(l,e){return Va(l,e,!1)}function Va(l,e,t=!0){const n=l.charCodeAt(e);return n>=(t?48:49)&&n<=57||n>=97&&n<=102}function qa(l,e,t){if(t===0||!uc(l,e))return!1;for(let n=1;n<t;n++)if(!Va(l,e+n))return!1;return!0}var te;(function(l){function e(F){if(G(F))return 0;const R=F.length,V=R>12?R-10:2;return Ss(F.slice(V))}l.getLocalId=e;function t(F){if(G(F))return 0;const R=F.length;return R<=12?0:Ss(F.slice(2,R-10))}l.getBriefcaseId=t;function n(F){return typeof F=="string"?l.fromString(F):l.invalid}l.fromJSON=n;function i(F){if(typeof F!="string")return l.invalid;if(l.isId64(F))return F;F=F.toLowerCase().trim();const R=F.length;if(R<2||F[0]!=="0"||F[1]!=="x")return l.invalid;let V=0,ne=0,Xe=2;return R>12&&(Xe=R-10,ne=Ss(F.slice(2,Xe))),V=Ss(F.slice(Xe)),r(V,ne)}l.fromString=i;const s=["0000000000","000000000","00000000","0000000","000000","00000","0000","000","00","0",""];function r(F,R){if(typeof F!="number"||typeof R!="number"||(F=Math.floor(F),F===0))return l.invalid;R=Math.floor(R);const V=F.toString(16);return`0x${R===0?V:R.toString(16)+(s[V.length]+V)}`}l.fromLocalAndBriefcaseIds=r;const a=[48,120,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48];function o(F){return F+(F<10?48:87)}function c(F){return F-(F>=87?87:48)}function d(F,R,V){let ne=0;for(let Xe=R;Xe<V;Xe++){const dt=c(F.charCodeAt(Xe)),Gt=V-Xe-1<<2,ni=dt<<Gt;ne=(ne|ni)>>>0}return ne}function h(F,R){const V=F>>>0,ne=(R&255)*4294967296;if(V+ne===0)return l.invalid;const dt=a;let Gt=2;for(let ni=7;ni>=0;ni--){const Ps=ni<<2,za=15<<Ps,Is=(R&za)>>>Ps;(Gt>2||Is!==0)&&(dt[Gt++]=o(Is))}for(let ni=7;ni>=0;ni--){const Ps=ni<<2,za=15<<Ps,Is=(F&za)>>>Ps;(Gt>2||Is!==0)&&(dt[Gt++]=o(Is))}return dt.length!==Gt&&(dt.length=Gt),String.fromCharCode(...a)}l.fromUint32Pair=h;function u(F){return h(F.lower,F.upper)}l.fromUint32PairObject=u;function g(F,R){return F!==0||(R&255)!==0}l.isValidUint32Pair=g;function m(F,R){return R||(R={lower:0,upper:0}),R.lower=p(F),R.upper=x(F),R}l.getUint32Pair=m;function p(F){if(G(F))return 0;const R=F.length,V=R>10?R-8:2;return d(F,V,R)}l.getLowerUint32=p;function x(F){const R=F.length;return R<=10||G(F)?0:d(F,2,R-8)}l.getUpperUint32=x;function _(F,R=!1){if(F instanceof Set)return R?new Set(F):F;const V=new Set;return typeof F=="string"?V.add(F):Array.isArray(F)&&F.forEach(ne=>{typeof ne=="string"&&V.add(ne)}),V}l.toIdSet=_;function*I(F){if(typeof F=="string")yield F;else for(const R of F)yield R}l.iterator=I;function S(F){return typeof F=="string"?[F]:F}l.iterable=S;function A(F){return typeof F=="string"?F:(Array.isArray(F)?F[0]:F.values().next().value)??l.invalid}l.getFirst=A;function w(F){return typeof F=="string"?1:Array.isArray(F)?F.length:F.size}l.sizeOf=w;function k(F,R){return typeof F=="string"?F===R:Array.isArray(F)?F.indexOf(R)!==-1:F.has(R)}l.has=k,l.invalid="0";function D(F){return F.length===18&&F.startsWith("0xffffff")}l.isTransient=D;function P(F){return M(F)&&D(F)}l.isTransientId64=P;function b(F){const R=F.length;if(R===0||18<R||F[0]!=="0")return!1;if(R===1)return!0;if(R===2||F[1]!=="x")return!1;let V=2;if(R>12){if(V=R-10,!qa(F,2,V-2))return!1;for(let ne=V;ne<R&&F.charCodeAt(ne)===48;ne++)V++;if(V>=R)return!1}return qa(F,V,R-V)}l.isId64=b;function C(F){return l.invalid!==F}l.isValid=C;function M(F){return l.invalid!==F&&l.isId64(F)}l.isValidId64=M;function G(F){return l.invalid===F}l.isInvalid=G;class ae{_map=new Map;constructor(R){R!==void 0&&this.addIds(R)}equals(R){if(this===R)return!0;if(this.size!==R.size)return!1;for(const[V,ne]of this._map){const Xe=R._map.get(V);if(!Xe||ne.size!==Xe.size)return!1;for(const dt of ne)if(!Xe.has(dt))return!1}return!0}clear(){this._map.clear()}addId(R){this.add(l.getLowerUint32(R),l.getUpperUint32(R))}addIds(R){for(const V of l.iterable(R))this.addId(V)}hasId(R){return this.has(l.getLowerUint32(R),l.getUpperUint32(R))}add(R,V){let ne=this._map.get(V);ne===void 0&&(ne=new Set,this._map.set(V,ne)),ne.add(R)}deleteId(R){this.delete(l.getLowerUint32(R),l.getUpperUint32(R))}deleteIds(R){for(const V of l.iterable(R))this.deleteId(V)}delete(R,V){const ne=this._map.get(V);ne!==void 0&&(ne.delete(R),ne.size===0&&this._map.delete(V))}has(R,V){const ne=this._map.get(V);return ne!==void 0&&ne.has(R)}hasPair(R){return this.has(R.lower,R.upper)}get isEmpty(){return this._map.size===0}get size(){let R=0;for(const V of this._map)R+=V[1].size;return R}toId64Array(){const R=[];for(const V of this._map)for(const ne of V[1])R.push(l.fromUint32Pair(ne,V[0]));return R}toId64Set(){const R=new Set;for(const V of this._map)for(const ne of V[1])R.add(l.fromUint32Pair(ne,V[0]));return R}forEach(R){for(const V of this._map)for(const ne of V[1])R(ne,V[0])}}l.Uint32Set=ae;class ye{_map=new Map;clear(){this._map.clear()}getById(R){return this.get(l.getLowerUint32(R),l.getUpperUint32(R))}setById(R,V){this.set(l.getLowerUint32(R),l.getUpperUint32(R),V)}set(R,V,ne){let Xe=this._map.get(V);Xe===void 0&&(Xe=new Map,this._map.set(V,Xe)),Xe.set(R,ne)}get(R,V){const ne=this._map.get(V);return ne!==void 0?ne.get(R):void 0}get isEmpty(){return this._map.size===0}get size(){let R=0;for(const V of this._map)R+=V[1].size;return R}forEach(R){for(const V of this._map)for(const ne of V[1])R(ne[0],V[0],ne[1])}}l.Uint32Map=ye})(te||(te={}));var As;(function(l){const e=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}$");l.empty="00000000-0000-0000-0000-000000000000";function t(r){return e.test(r)}l.isGuid=t;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)}l.isV4Guid=n;function i(){return crypto.randomUUID()}l.createValue=i;function s(r){const a=r.toLowerCase().trim();if(t(a))return a;const o=a.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(o)?o.replace(c,(d,h,u,g,m,p)=>`${h}-${u}-${g}-${m}-${p}`):r}l.normalize=s})(As||(As={}));class ws{_view;_byteOffset;_curPos=0;constructor(e,t){t!==void 0?(this._view=new DataView(e,t.byteOffset,t.byteLength),this._byteOffset=t.byteOffset):(this._view=new DataView(e),this._byteOffset=0)}static fromUint8Array(e){const{byteOffset:t,byteLength:n}=e;return new ws(e.buffer,{byteOffset:t,byteLength:n})}static fromArrayBuffer(e,t){return new ws(e,t)}get length(){return this._view.byteLength}get remainingLength(){return this.length-this.curPos}get isPastTheEnd(){return this.curPos>this.length}get isAtTheEnd(){return this.curPos===this.length}get curPos(){return this._curPos}set curPos(e){this._curPos=e,this.isPastTheEnd}advance(e){return this.curPos=this.curPos+e,!this.isPastTheEnd}rewind(e){return this.curPos-e<0?!1:(this.curPos=this.curPos-e,!0)}reset(){this.curPos=0}readUint8(){return this.read(1,e=>e.getUint8(this.curPos))}readUint16(){return this.read(2,e=>e.getUint16(this.curPos,!0))}readUint32(){return this.read(4,e=>e.getUint32(this.curPos,!0))}readInt32(){return this.read(4,e=>e.getInt32(this.curPos,!0))}readFloat32(){return this.read(4,e=>e.getFloat32(this.curPos,!0))}readFloat64(){return this.read(8,e=>e.getFloat64(this.curPos,!0))}readId64(){return te.fromUint32Pair(this.readUint32(),this.readUint32())}readUint24(){return this.readUint8()|this.readUint8()<<8|this.readUint8()<<16}nextBytes(e){const t=new Uint8Array(this.arrayBuffer,this.curPos+this._byteOffset,e);return this.advance(e),t}readBytes(e,t){return new Uint8Array(this.arrayBuffer,e+this._byteOffset,t)}nextUint32s(e){const t=e*4,n=new Uint32Array(this.arrayBuffer,this.curPos+this._byteOffset,e);return this.advance(t),n}get arrayBuffer(){return this._view.buffer}read(e,t){const n=t(this._view);return this.advance(e),n}}function fc(l,e,t=.1){return l<e-t?-1:l>e+t?1:0}function Pe(l,e){return l-e}function Pt(l,e){return l!==e?l<e?-1:1:0}function ii(l,e){return l===e?0:l<e?-1:1}function Qt(l,e,t){return e===void 0?t===void 0?0:-1:t===void 0?1:l(e,t)}function gc(l,e){return Qt(ii,l,e)}function mc(l,e){return Qt(Pe,l,e)}function Za(l,e){return Qt(Pt,l,e)}var bs;(function(l){function e(g,m){return g.length!==m.length?g.length<m.length?-1:1:g!==m?g<m?-1:1:0}l.compare=e;function t(g){return g.sort((m,p)=>e(m,p)),g}l.sortArray=t;function n(g,m){const p=r(g),x=r(m);let _=p.next(),I=x.next();for(;!_.done&&!I.done;){const S=_.value,A=I.value;if(e(S,A)!==0)return!1;_=p.next(),I=x.next()}return!!(_.done&&I.done)}l.areEqualSets=n;function i(g){return typeof g=="string"?g==="":g[Symbol.iterator]().next().done===!0}l.isEmptySet=i;function s(g){return{[Symbol.iterator]:()=>r(g)}}l.unique=s;function*r(g){const m=g[Symbol.iterator]();let p=m.next(),x;for(;!p.done;){const _=p.value;p=m.next(),_!==x&&(x=_,yield _)}}l.uniqueIterator=r;function a(g,m){return{[Symbol.iterator]:()=>d(g,m)}}l.union=a;function o(g,m){return{[Symbol.iterator]:()=>h(g,m)}}l.intersection=o;function c(g,m){return{[Symbol.iterator]:()=>u(g,m)}}l.difference=c;function*d(g,m){const p=g[Symbol.iterator](),x=m[Symbol.iterator]();let _=p.next(),I=x.next(),S;for(;!_.done||!I.done;){const A=_.done?void 0:_.value,w=I.done?void 0:I.value;if(A===void 0&&w===void 0)break;let k;if(A===void 0)k=w,I=x.next();else if(w===void 0)k=A,_=p.next();else{const D=e(A,w);D<=0?(k=A,_=p.next(),D===0&&(I=x.next())):(k=w,I=x.next())}S!==k&&(S=k,yield k)}}l.unionIterator=d;function*h(g,m){const p=g[Symbol.iterator](),x=m[Symbol.iterator]();let _=p.next(),I=x.next(),S;for(;!_.done&&!I.done;){const A=_.value;if(_=p.next(),A===S)continue;S=A;let w=I.value,k=e(A,w);for(;k>0;){if(I=x.next(),I.done)return;w=I.value,k=e(A,w)}k===0&&(yield A)}}l.intersectionIterator=h;function*u(g,m){const p=g[Symbol.iterator](),x=m[Symbol.iterator]();let _=p.next(),I=x.next(),S;for(;!_.done;){const A=_.value;if(_=p.next(),A===S)continue;if(I.done){yield S=A;continue}let w=I.value,k=e(A,w);for(;k>0&&!I.done;){if(I=x.next(),I.done){yield S=A;continue}w=I.value,k=e(A,w)}k<0&&(yield S=A)}}l.differenceIterator=u})(bs||(bs={}));function si(l){return l}function Mr(l,e,t){return Wa(e,n=>t(l,n))}function Wa(l,e){let t=0,n=l.length;for(;t<n;){const i=Math.floor((t+n)/2),s=e(l[i]);if(s===0)return{index:i,equal:!0};s<0?n=i:t=i+1}return{index:t,equal:!1}}var Xn;(function(l){l[l.Allow=0]="Allow",l[l.Retain=1]="Retain",l[l.Replace=2]="Replace"})(Xn||(Xn={}));class Dr{_array=[];_compare;_clone;_duplicatePolicy;constructor(e,t=!1,n=si){this._compare=e,this._clone=n,typeof t=="boolean"&&(t=t?Xn.Allow:Xn.Retain),this._duplicatePolicy=t}get length(){return this._array.length}get isEmpty(){return this.length===0}[Symbol.iterator](){return this._array[Symbol.iterator]()}indexOf(e){const t=this.lowerBound(e);return t.equal?t.index:-1}contains(e){return this.indexOf(e)!==-1}findEqual(e){const t=this.indexOf(e);return t!==-1?this._array[t]:void 0}findEquivalent(e){const t=this.indexOfEquivalent(e);return t!==-1?this._array[t]:void 0}indexOfEquivalent(e){const t=Wa(this._array,n=>0-e(n));return t.equal?t.index:-1}get(e){return e<this.length?this._array[e]:void 0}forEach(e){for(let t=0;t<this.length;t++)e(this._array[t])}slice(e,t){const n=new Dr(this._compare,this._duplicatePolicy,this._clone);return n._array=this._array.slice(e,t),n}lowerBound(e){return Mr(e,this._array,this._compare)}_clear(){this._array.length=0}_extractArray(){const e=this._array;return this._array=[],e}_insert(e,t){const n=this.lowerBound(e);if(n.equal)switch(this._duplicatePolicy){case Xn.Retain:return n.index;case Xn.Replace:return this._array[n.index]=this._clone(e),t&&t(e),n.index}return this._array.splice(n.index,0,this._clone(e)),t!==void 0&&t(e),n.index}_remove(e){const t=this.lowerBound(e);return t.equal?(this._array.splice(t.index,1),t.index):-1}}class pi extends Dr{constructor(e,t=!1,n=si){super(e,t,n)}clear(){this._clear()}extractArray(){return this._extractArray()}insert(e,t){return this._insert(e,t)}remove(e){return this._remove(e)}slice(e,t){const n=new pi(this._compare,this._duplicatePolicy,this._clone);return n._array=this._array.slice(e,t),n}}var Ts;(function(l){function e(g){return typeof g=="string"&&(g.length===0||g[0]==="+")}l.isValid=e;function t(g){return g>=48&&g<=57||g>=65&&g<=70}function n(g,m){const p=`+${g.toString()}`;if(m<=1)return p;const x=m.toString(16).toUpperCase();return`${p}*${x}`}function i(g){return s(g)}l.compressSet=i;function s(g){const m=typeof g=="string"?[g]:Array.from(g);return bs.sortArray(m),r(m)}l.sortAndCompress=s;function r(g){return a(g)}l.compressArray=r;function a(g){if(typeof g=="string")return g;let m="";const p=new o,x=new o;let _=0;const I=new o,S=new o;for(const A of g){if(!te.isValidId64(A))continue;I.setFromId(A),S.setFromDifference(I,p);const w=p.compare(I);if(w!==0){if(w>0)throw new Error("CompressedId64Set.compressArray requires a sorted array as input");p.copyFrom(I),_===0?(x.copyFrom(S),_=1):S.equals(x)?++_:(m+=n(x,_),x.copyFrom(S),_=1)}}return 0<_&&(m+=n(x,_)),m}l.compressIds=a;class o{lower;upper;static _base=4294967296;static assertUint32(m){}assertConstraints(){o.assertUint32(this.lower),o.assertUint32(this.upper)}constructor(m=0,p=0){this.lower=m,this.upper=p,this.assertConstraints()}compare(m){const p=this.upper-m.upper;return p===0?this.lower-m.lower:p}equals(m){return this.compare(m)===0}isLessThan(m){return this.compare(m)<0}isGreaterThan(m){return this.compare(m)>0}get isZero(){return this.lower===0&&this.upper===0}setFromDifference(m,p){p.isGreaterThan(m),this.lower=m.lower-p.lower,this.upper=m.upper-p.upper,this.lower<0&&(this.lower+=o._base,this.upper-=1)}add(m){let p=m.lower,x=m.upper;p+this.lower>=o._base&&(p-=o._base,x+=1),this.lower+=p,this.upper+=x,this.assertConstraints()}setFromId(m){te.getUint32Pair(m,this)}copyFrom(m){this.lower=m.lower,this.upper=m.upper}toString(){if(this.upper===0)return this.lower.toString(16).toUpperCase();const m=this.upper.toString(16),p=this.lower.toString(16).padStart(8,"0");return p.length,`${m}${p}`.toUpperCase()}toId64String(){return te.fromUint32Pair(this.lower,this.upper)}}function*c(g){if(g.length===0)return;if(g[0]!=="+")throw new Error("Invalid CompressedId64Set");let m=1;const p=new o;function x(){let S=0,A=0;for(;m<g.length&&A<8;){++A;const w=g.charCodeAt(m);if(!t(w))break;S<<=4,S|=w>=65?w-65+10:w-48,S=S>>>0,++m}return S}function _(S){let A=0,w=0;const k=m,D=x();if(m-k===8&&m+1<g.length&&t(g.charCodeAt(m+1))){const b=m,C=x(),M=m-b,G=8-M;w=D>>>4*G;const ae=D-(w<<4*G>>>0);A=(C|ae<<4*M>>>0)>>>0}else A=D;S.lower=A,S.upper=w}const I=new o;for(;m<g.length;){let S=1;if(_(I),I.isZero)throw new Error("Invalid CompressedId64Set");if(m<g.length)switch(g[m++]){case"*":if(S=x(),S===0)throw new Error("Invalid CompressedId64Set");if(m!==g.length&&g[m++]!=="+")return;break;case"+":break;default:throw new Error("Invalid CompressedId64Set")}for(let A=0;A<S;A++)p.add(I),yield p.toId64String()}}l.iterator=c;function d(g){return{[Symbol.iterator]:()=>c(g)}}l.iterable=d;function h(g,m){const p=m??new Set;for(const x of d(g))p.add(x);return p}l.decompressSet=h;function u(g,m){const p=m??[];for(const x of d(g))p.push(x);return p}l.decompressArray=u})(Ts||(Ts={}));class pc{_keys;_values;_curIndex=-1;constructor(e,t){this._keys=e,this._values=t}next(){return++this._curIndex>=this._keys.length?{done:!0}:{value:{key:this._keys[this._curIndex],value:this._values[this._curIndex]},done:!1}}}class xc{_keys=[];_compareKeys;_cloneKey;_values=[];_cloneValue;constructor(e,t=si,n=si){this._compareKeys=e,this._cloneKey=t,this._cloneValue=n}get size(){return this._keys.length}[Symbol.iterator](){return new pc(this._keys,this._values)}keys(){function*e(t){for(const n of t)yield n.key}return{[Symbol.iterator]:()=>e(this)}}values(){function*e(t){for(const n of t)yield n.value}return{[Symbol.iterator]:()=>e(this)}}clear(){this._keys=[],this._values=[]}get(e){const t=this.lowerBound(e);return t.equal?this._values[t.index]:void 0}has(e){return this.lowerBound(e).equal}delete(e){const t=this.lowerBound(e);return t.equal?(this._values.splice(t.index,1),this._keys.splice(t.index,1),!0):!1}insert(e,t){return this.findOrInsert(e,t).inserted}findOrInsert(e,t){const n=this.lowerBound(e);return n.equal?{value:this._values[n.index],inserted:!1}:(t=this._cloneValue(t),this._keys.splice(n.index,0,this._cloneKey(e)),this._values.splice(n.index,0,this._cloneValue(t)),{value:t,inserted:!0})}set(e,t){t=this._cloneValue(t);const n=this.lowerBound(e);n.equal?this._values[n.index]=t:(this._keys.splice(n.index,0,this._cloneKey(e)),this._values.splice(n.index,0,t))}extractPairs(){const e=[];for(let t=0;t<this.size;t++)e.push({key:this._keys[t],value:this._values[t]});return this.clear(),e}extractArrays(){const e={keys:this._keys,values:this._values};return this.clear(),e}forEach(e){for(let t=0;t<this.size;t++)e(this._keys[t],this._values[t])}lowerBound(e){return Mr(e,this._keys,this._compareKeys)}}function Nr(l,e){if(l===void 0)throw new Error("Expected value to be defined, but it was undefined.");return l}class Ga{value;index;constructor(e,t){this.value=e,this.index=t}}class _c{_array=[];_compareValues;_clone;_maximumSize;constructor(e,t=Number.MAX_SAFE_INTEGER,n=si){this._compareValues=e,this._clone=n,this._maximumSize=t}get length(){return this._array.length}get isFull(){return this.length>=this._maximumSize}get isEmpty(){return this.length===0}clear(){this._array=[]}insert(e,t){const n=this.lowerBound(e);if(n.equal)return this._array[n.index].index;if(this.isFull)return-1;const i=new Ga(this._clone(e),this._array.length);return t!==void 0&&t(i.value),this._array.splice(n.index,0,i),i.index}indexOf(e){const t=this.lowerBound(e);return t.equal?this._array[t.index].index:-1}lowerBound(e){return Mr(e,this._array,(t,n)=>this._compareValues(t,n.value))}toArray(){const e=[];for(const t of this._array)e[t.index]=t.value;return e}}class yc{_array;constructor(e,t=si){this._array=new pi(e,!1,t)}get size(){return this._array.length}has(e){return this._array.indexOf(e)!==-1}[Symbol.iterator](){return this._array[Symbol.iterator]()}}class Di extends yc{constructor(e,t=si){super(e,t)}clear(){this._array.clear()}add(e){return this._array.insert(e),this}delete(e){return this._array.remove(e)!==-1}}class Pc{_array=[];_compare;_clone;constructor(e,t=si){this._compare=e,this._clone=t}get length(){return this._array.length}get isEmpty(){return this.length===0}[Symbol.iterator](){return this._array[Symbol.iterator]()}_swap(e,t){const n=this._array[e];this._array[e]=this._array[t],this._array[t]=n}_heapify(e){let t=-1;for(;;){const n=2*(e+1),i=n-1;if(i<this.length&&this._compare(this._array[i],this._array[e])<0?t=i:t=e,n<this.length&&this._compare(this._array[n],this._array[t])<0&&(t=n),t!==e)this._swap(t,e),e=t;else break}}sort(){for(let e=Math.ceil(this.length/2);e>=0;e--)this._heapify(e)}push(e){const t=this._clone(e);let n=this.length;for(this._array.push(t);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 t}append(e){const t=this._clone(e);return this._array.push(t),t}get front(){return this._peek(0)}pop(){return this._pop(0)}clear(){this._array.length=0}_pop(e){if(e<0||e>=this.length)return;const t=this._array[e];return this._swap(e,this.length-1),this._array.length--,this._heapify(e),t}_peek(e){if(!(e<0||e>=this.length))return this._array[e]}}function Ic(l){return new TextDecoder("utf-8").decode(l)}class Qa{_constructor;_data;_length;growthFactor;constructor(e,t){this._constructor=e,this._data=new e(t?.initialCapacity??0),this.growthFactor=Math.max(1,t?.growthFactor??1.5),this._length=0}get length(){return this._length}get capacity(){return this._data.length}at(e){return e<0&&(e=this.length-e),this._data[e]}ensureCapacity(e){if(this.capacity>=e)return this.capacity;this.growthFactor>=1,e=Math.ceil(e*this.growthFactor);const t=this._data;return this._data=new this._constructor(e),this._data.set(t,0),this.capacity,this.capacity}push(e){this.ensureCapacity(this.length+1),this._data[this.length]=e,++this._length}append(e){const t=this.length+e.length;this.ensureCapacity(t),this._data.set(e,this.length),this._length=t}toTypedArray(e=!1){if(e)return this._data;const t=this._data.subarray(0,this.length);return t instanceof this._constructor,t.buffer,this._data.buffer,t}}class Or extends Qa{constructor(e){super(Uint8Array,e)}}class Ni extends Qa{constructor(e){super(Uint32Array,e)}toUint8Array(e=!1){return e?new Uint8Array(this._data.buffer):new Uint8Array(this._data.buffer,0,this.length*4)}}class Ja{x;y;set(e=0,t=0){this.x=e,this.y=t}setZero(){this.x=0,this.y=0}constructor(e=0,t=0){this.x=e,this.y=t}setFrom(e){e?(this.x=e.x,this.y=e.y):(this.x=0,this.y=0)}freeze(){return Object.freeze(this)}isAlmostEqual(e,t){return f.isSameCoordinate(this.x,e.x,t)&&f.isSameCoordinate(this.y,e.y,t)}isAlmostEqualXY(e,t,n){return f.isSameCoordinate(this.x,e,n)&&f.isSameCoordinate(this.y,t,n)}toJSON(){return[this.x,this.y]}toJSONXY(){return{x:this.x,y:this.y}}setFromJSON(e){if(Array.isArray(e)){this.set(e[0]||0,e[1]||0);return}if(e){this.set(e.x||0,e.y||0);return}this.set(0,0)}distance(e){const t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)}distanceSquared(e){const t=e.x-this.x,n=e.y-this.y;return t*t+n*n}maxDiff(e){return Math.max(Math.abs(this.x-e.x),Math.abs(this.y-e.y))}at(e){return e<.5?this.x:this.y}setAt(e,t){e<.5?this.x=t:this.y=t}indexOfMaxAbs(){let e=0;const t=Math.abs(this.x);return Math.abs(this.y)>t&&(e=1),e}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(e){return this.x===e.x&&this.y===e.y}isAlmostEqualMetric(e,t=f.smallMetricDistance){return this.maxDiff(e)<=t}vectorTo(e,t){return $.create(e.x-this.x,e.y-this.y,t)}unitVectorTo(e,t){return this.vectorTo(e,t).normalize(t)}static crossProductToPoints(e,t,n){return f.crossProductXYXY(t.x-e.x,t.y-e.y,n.x-e.x,n.y-e.y)}scaleInPlace(e){return this.x*=e,this.y*=e,this}}class L extends Ja{constructor(e=0,t=0){super(e,t)}clone(e){return L.create(this.x,this.y,e)}static create(e=0,t=0,n){return n?(n.x=e,n.y=t,n):new L(e,t)}static createInterpolated(e,t,n){return new L(f.interpolate(e.x,t,n.x),f.interpolate(e.y,t,n.y))}static fromJSON(e){const t=new L;return t.setFromJSON(e),t}static createFrom(e,t){return e?L.create(e.x,e.y,t):L.create(0,0,t)}static createZero(e){return L.create(0,0,e)}addForwardLeft(e,t,n,i){const s=n.x,r=n.y;return L.create(this.x+e*s-t*r,this.y+e*r+t*s,i)}forwardLeftInterpolate(e,t,n){const i=n.x-this.x,s=n.y-this.y;return L.create(this.x+e*i-t*s,this.y+e*s+t*i)}interpolate(e,t,n){if(e<=.5)return L.create(this.x+e*(t.x-this.x),this.y+e*(t.y-this.y),n);const i=e-1;return L.create(t.x+i*(t.x-this.x),t.y+i*(t.y-this.y),n)}interpolateXY(e,t,n,i){return L.create(f.interpolate(this.x,e,n.x),f.interpolate(this.y,t,n.y),i)}minus(e,t){return L.create(this.x-e.x,this.y-e.y,t)}plus(e,t){return L.create(this.x+e.x,this.y+e.y,t)}plusXY(e=0,t=0,n){return L.create(this.x+e,this.y+t,n)}plusScaled(e,t,n){return L.create(this.x+e.x*t,this.y+e.y*t,n)}plus2Scaled(e,t,n,i,s){return L.create(this.x+e.x*t+n.x*i,this.y+e.y*t+n.y*i,s)}plus3Scaled(e,t,n,i,s,r,a){return L.create(this.x+e.x*t+n.x*i+s.x*r,this.y+e.y*t+n.y*i+s.y*r,a)}static createAdd2Scaled(e,t,n,i,s){return L.create(e.x*t+n.x*i,e.y*t+n.y*i,s)}static createAdd2ScaledXY(e,t,n,i,s,r,a){return L.create(e*n+i*r,t*n+s*r,a)}static createAdd3Scaled(e,t,n,i,s,r,a){return L.create(e.x*t+n.x*i+s.x*r,e.y*t+n.y*i+s.y*r,a)}static createAdd3ScaledXY(e,t,n,i,s,r,a,o,c,d){return L.create(e*n+i*r+a*c,t*n+s*r+o*c,d)}dotVectorsToTargets(e,t){return(e.x-this.x)*(t.x-this.x)+(e.y-this.y)*(t.y-this.y)}crossProductToPoints(e,t){const n=e.x-this.x,i=e.y-this.y,s=t.x-this.x,r=t.y-this.y;return n*r-i*s}fractionOfProjectionToLine(e,t,n=0){const i=e.distanceSquared(t);return i<f.smallMetricDistanceSquared?n:e.dotVectorsToTargets(t,this)/i}}class $ extends Ja{constructor(e=0,t=0){super(e,t)}clone(e){return $.create(this.x,this.y,e)}static create(e=0,t=0,n){return n?(n.x=e,n.y=t,n):new $(e,t)}static unitX(e=1){return new $(e,0)}static unitY(e=1){return new $(0,e)}static createZero(e){return $.create(0,0,e)}static createFrom(e,t){return e instanceof Float64Array?e.length>=2?$.create(e[0],e[1]):e.length>=1?$.create(e[0],0):$.create(0,0):$.create(e.x,e.y,t)}static fromJSON(e){const t=new $;return t.setFromJSON(e),t}static createPolar(e,t){return $.create(e*t.cos(),e*t.sin())}static createStartEnd(e,t,n){return $.create(t.x-e.x,t.y-e.y,n)}static createOffsetBisector(e,t,n){let i=e.plus(t);if(i=i.normalize(),i){const s=i.dotProduct(e);return i.scale(n,i),i.safeDivideOrNull(s)}}static createAdd2Scaled(e,t,n,i,s){return $.create(e.x*t+n.x*i,e.y*t+n.y*i,s)}static createAdd2ScaledXY(e,t,n,i,s,r,a){return $.create(e*n+i*r,t*n+s*r,a)}static createAdd3Scaled(e,t,n,i,s,r,a){return $.create(e.x*t+n.x*i+s.x*r,e.y*t+n.y*i+s.y*r,a)}static createAdd3ScaledXY(e,t,n,i,s,r,a,o,c,d){return $.create(e*n+i*r+a*c,t*n+s*r+o*c,d)}safeDivideOrNull(e,t){if(e!==0)return this.scale(1/e,t)}normalize(e){const t=f.correctSmallFraction(this.magnitude());return e=e||new $,this.safeDivideOrNull(t,e)}fractionOfProjectionToVector(e,t){const n=e.magnitudeSquared();return n<f.smallMetricDistanceSquared?t||0:this.dotProduct(e)/n}negate(e){return e=e||new $,e.x=-this.x,e.y=-this.y,e}rotate90CCWXY(e){e=e||new $;const t=this.x,n=this.y;return e.x=-n,e.y=t,e}rotate90CWXY(e){e=e||new $;const t=this.x,n=this.y;return e.x=n,e.y=-t,e}unitPerpendicularXY(e){e=e||new $;const t=this.x,n=this.y;e.x=-n,e.y=t;const i=t*t+n*n;if(i!==0){const s=1/Math.sqrt(i);e.x*=s,e.y*=s}return e}rotateXY(e,t){const n=e.sin(),i=e.cos(),s=this.x,r=this.y;return t=t||new $,t.x=s*i-r*n,t.y=s*n+r*i,t}interpolate(e,t,n){if(n=n||new $,e<=.5)n.x=this.x+e*(t.x-this.x),n.y=this.y+e*(t.y-this.y);else{const i=e-1;n.x=t.x+i*(t.x-this.x),n.y=t.y+i*(t.y-this.y)}return n}plus(e,t){return t=t||new $,t.x=this.x+e.x,t.y=this.y+e.y,t}minus(e,t){return t=t||new $,t.x=this.x-e.x,t.y=this.y-e.y,t}plusScaled(e,t,n){return n=n||new $,n.x=this.x+e.x*t,n.y=this.y+e.y*t,n}plus2Scaled(e,t,n,i,s){return s=s||new $,s.x=this.x+e.x*t+n.x*i,s.y=this.y+e.y*t+n.y*i,s}plus3Scaled(e,t,n,i,s,r,a){return a=a||new $,a.x=this.x+e.x*t+n.x*i+s.x*r,a.y=this.y+e.y*t+n.y*i+s.y*r,a}scale(e,t){return t=t||new $,t.x=this.x*e,t.y=this.y*e,t}scaleToLength(e,t){const n=f.correctSmallFraction(this.magnitude());if(n!==0)return this.scale(e/n,t)}dotProduct(e){return this.x*e.x+this.y*e.y}dotProductStartEnd(e,t){return this.x*(t.x-e.x)+this.y*(t.y-e.y)}crossProduct(e){return this.x*e.y-this.y*e.x}radiansTo(e){return Math.atan2(this.crossProduct(e),this.dotProduct(e))}angleTo(e){return T.createRadians(this.radiansTo(e))}isParallelTo(e,t=!1,n=!1,i){const s=i?.radianSquaredTol??f.smallAngleRadiansSquared,r=i?.distanceSquaredTol??f.smallMetricDistanceSquared,a=this.magnitudeSquared(),o=e.magnitudeSquared();if(a<r||o<r)return n;if(this.dotProduct(e)<0&&!t)return!1;const d=this.crossProduct(e);return d*d<=s*a*o}isPerpendicularTo(e,t=!1,n){const i=n?.radianSquaredTol??f.smallAngleRadiansSquared,s=n?.distanceSquaredTol??f.smallMetricDistanceSquared,r=this.magnitudeSquared(),a=e.magnitudeSquared();if(r<s||a<s)return t;const o=this.dotProduct(e);return o*o<=i*r*a}}var Cs;(function(l){function e(t,n,i){return f.isSameCoordinate(t.x,n.x,i)&&f.isSameCoordinate(t.y,n.y,i)}l.almostEqual=e})(Cs||(Cs={}));var Es;(function(l){function e(t,n,i){return f.isSameCoordinate(t.x,n.x,i)&&f.isSameCoordinate(t.y,n.y,i)&&f.isSameCoordinate(t.z,n.z,i)}l.almostEqual=e})(Es||(Es={}));class Ln{x;y;z;set(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}setZero(){this.x=0,this.y=0,this.z=0}constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}static isXAndY(e){return e.x!==void 0&&e.y!==void 0}static hasZ(e){return e.z!==void 0}static isXYAndZ(e){return this.isXAndY(e)&&this.hasZ(e)}static isAnyImmediatePointType(e){return y.isXAndY(e)||f.isNumberArray(e,2)}static accessX(e,t){return e.x!==void 0?e.x:Array.isArray(e)&&e.length>0&&Number.isFinite(e[0])?e[0]:t}static accessY(e,t){return e.y!==void 0?e.y:Array.isArray(e)&&e.length>1&&Number.isFinite(e[1])?e[1]:t}static accessZ(e,t){return e.z!==void 0?e.z:Array.isArray(e)&&e.length>2&&Number.isFinite(e[2])?e[2]:t}setFrom(e){e===void 0?this.setZero():Ln.isXAndY(e)?(this.x=e.x,this.y=e.y,this.z=Ln.hasZ(e)?e.z:0):(this.x=e[0],this.y=e[1],this.z=e[2])}setFromPoint3d(e){e?(this.x=e.x,this.y=e.y,this.z=e.z):this.setZero()}setFromVector3d(e){e?(this.x=e.x,this.y=e.y,this.z=e.z):this.setZero()}isAlmostEqual(e,t){return Es.almostEqual(this,e,t)}isAlmostEqualXYZ(e,t,n,i){return f.isSameCoordinate(this.x,e,i)&&f.isSameCoordinate(this.y,t,i)&&f.isSameCoordinate(this.z,n,i)}isAlmostEqualPointPlusScaledVector(e,t,n,i){return f.isSameCoordinate(this.x,e.x+t.x*n,i)&&f.isSameCoordinate(this.y,e.y+t.y*n,i)&&f.isSameCoordinate(this.z,e.z+t.z*n,i)}isAlmostEqualXY(e,t){return f.isSameCoordinate(this.x,e.x,t)&&f.isSameCoordinate(this.y,e.y,t)}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(e){if(Array.isArray(e)){this.set(e[0]||0,e[1]||0,e[2]||0);return}if(e){this.set(e.x||0,e.y||0,e.z||0);return}this.set(0,0,0)}distance(e){const t=e.x-this.x,n=e.y-this.y,i=e.z-this.z;return Math.sqrt(t*t+n*n+i*i)}distanceSquared(e){const t=e.x-this.x,n=e.y-this.y,i=e.z-this.z;return t*t+n*n+i*i}distanceXY(e){const t=e.x-this.x,n=e.y-this.y;return Math.sqrt(t*t+n*n)}distanceSquaredXY(e){const t=e.x-this.x,n=e.y-this.y;return t*t+n*n}maxDiff(e){return Math.max(Math.abs(this.x-e.x),Math.abs(this.y-e.y),Math.abs(this.z-e.z))}at(e){return e<.5?this.x:e>1.5?this.z:this.y}setAt(e,t){e<.5?this.x=t:e>1.5?this.z=t:this.y=t}indexOfMaxAbs(){let e=0,t=Math.abs(this.x),n=Math.abs(this.y);return n>t&&(e=1,t=n),n=Math.abs(this.z),n>t&&(e=2),e}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(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}isAlmostEqualMetric(e){return this.maxDiff(e)<=f.smallMetricDistance}addInPlace(e){this.x+=e.x,this.y+=e.y,this.z+=e.z}subtractInPlace(e){this.x-=e.x,this.y-=e.y,this.z-=e.z}addScaledInPlace(e,t){this.x+=t*e.x,this.y+=t*e.y,this.z+=t*e.z}scaleInPlace(e){return this.x*=e,this.y*=e,this.z*=e,this}addXYZInPlace(e=0,t=0,n=0){this.x+=e,this.y+=t,this.z+=n}cloneAsPoint3d(){return y.create(this.x,this.y,this.z)}vectorTo(e,t){return v.create(e.x-this.x,e.y-this.y,e.z-this.z,t)}scaledVectorTo(e,t,n){return v.create(t*(e.x-this.x),t*(e.y-this.y),t*(e.z-this.z),n)}unitVectorTo(e,t){return this.vectorTo(e,t).normalize(t)}freeze(){return Object.freeze(this)}static x(e,t=0){return e===void 0?t:Array.isArray(e)?e[0]:e.x!==void 0?e.x:t}static y(e,t=0){return e===void 0?t:Array.isArray(e)?e[1]:e.y!==void 0?e.y:t}static z(e,t=0){return e===void 0?t:Array.isArray(e)?e[2]:e.z!==void 0?e.z:t}}class y extends Ln{constructor(e=0,t=0,n=0){super(e,t,n)}static fromJSON(e){const t=new y;return t.setFromJSON(e),t}clone(e){return y.create(this.x,this.y,this.z,e)}static create(e=0,t=0,n=0,i){return i?(i.x=e,i.y=t,i.z=n,i):new y(e,t,n)}static createFrom(e,t){if(e instanceof Float64Array){let n=0,i=0,s=0;return e.length>0&&(n=e[0]),e.length>1&&(i=e[1]),e.length>2&&(s=e[2]),y.create(n,i,s,t)}return y.create(e.x,e.y,Ln.hasZ(e)?e.z:0,t)}static createFromPacked(e,t,n){const i=t*3;if(i>=0&&i+2<e.length)return y.create(e[i],e[i+1],e[i+2],n)}static createFromPackedXYZW(e,t,n){const i=t*4;if(i>=0&&i+3<e.length){const s=e[i+3];if(!f.isSmallMetricDistance(s)){const r=1/s;return y.create(r*e[i],r*e[i+1],r*e[i+2],n)}}}static createArrayFromPackedXYZ(e){const t=[];for(let n=0;n+2<e.length;n+=3)t.push(new y(e[n],e[n+1],e[n+2]));return t}static createZero(e){return y.create(0,0,0,e)}crossProductToPoints(e,t,n){return v.createCrossProduct(e.x-this.x,e.y-this.y,e.z-this.z,t.x-this.x,t.y-this.y,t.z-this.z,n)}crossProductToPointsMagnitude(e,t){return f.crossProductMagnitude(e.x-this.x,e.y-this.y,e.z-this.z,t.x-this.x,t.y-this.y,t.z-this.z)}tripleProductToPoints(e,t,n){return f.tripleProduct(e.x-this.x,e.y-this.y,e.z-this.z,t.x-this.x,t.y-this.y,t.z-this.z,n.x-this.x,n.y-this.y,n.z-this.z)}crossProductToPointsXY(e,t){return f.crossProductXYXY(e.x-this.x,e.y-this.y,t.x-this.x,t.y-this.y)}interpolate(e,t,n){if(e<=.5)return y.create(this.x+e*(t.x-this.x),this.y+e*(t.y-this.y),this.z+e*(t.z-this.z),n);const i=e-1;return y.create(t.x+i*(t.x-this.x),t.y+i*(t.y-this.y),t.z+i*(t.z-this.z),n)}interpolateXYZ(e,t,n,i,s){return y.create(f.interpolate(this.x,e,i.x),f.interpolate(this.y,t,i.y),f.interpolate(this.z,n,i.z),s)}interpolatePerpendicularXY(e,t,n,i){i=i||new y;const s=t.minus(this);return this.interpolate(e,t,i),i.x-=n*s.y,i.y+=n*s.x,i}minus(e,t){return y.create(this.x-e.x,this.y-e.y,this.z-e.z,t)}plus(e,t){return y.create(this.x+e.x,this.y+e.y,this.z+e.z,t)}plusXYZ(e=0,t=0,n=0,i){return y.create(this.x+e,this.y+t,this.z+n,i)}plusScaled(e,t,n){return y.create(this.x+e.x*t,this.y+e.y*t,this.z+e.z*t,n)}plus2Scaled(e,t,n,i,s){return y.create(this.x+e.x*t+n.x*i,this.y+e.y*t+n.y*i,this.z+e.z*t+n.z*i,s)}plus3Scaled(e,t,n,i,s,r,a){return y.create(this.x+e.x*t+n.x*i+s.x*r,this.y+e.y*t+n.y*i+s.y*r,this.z+e.z*t+n.z*i+s.z*r,a)}static createScale(e,t,n){return y.create(e.x*t,e.y*t,e.z*t,n)}static createAdd2Scaled(e,t,n,i,s){return y.create(e.x*t+n.x*i,e.y*t+n.y*i,e.z*t+n.z*i,s)}static createAdd3Scaled(e,t,n,i,s,r,a){return y.create(e.x*t+n.x*i+s.x*r,e.y*t+n.y*i+s.y*r,e.z*t+n.z*i+s.z*r,a)}dotVectorsToTargets(e,t){return(e.x-this.x)*(t.x-this.x)+(e.y-this.y)*(t.y-this.y)+(e.z-this.z)*(t.z-this.z)}fractionOfProjectionToLine(e,t,n=0){const i=e.distanceSquared(t);return i<f.smallMetricDistanceSquared?n:e.dotVectorsToTargets(t,this)/i}}class v extends Ln{constructor(e=0,t=0,n=0){super(e,t,n)}static createArrayFromPackedXYZ(e){const t=[];for(let n=0;n+2<e.length;n+=3)t.push(new v(e[n],e[n+1],e[n+2]));return t}clone(e){return v.create(this.x,this.y,this.z,e)}static create(e=0,t=0,n=0,i){return i?(i.x=e,i.y=t,i.z=n,i):new v(e,t,n)}static createCrossProduct(e,t,n,i,s,r,a){return v.create(t*r-n*s,n*i-e*r,e*s-t*i,a)}addCrossProductToTargetsInPlace(e,t,n,i,s,r,a,o,c){const d=i-e,h=s-t,u=r-n,g=a-e,m=o-t,p=c-n;this.x+=h*p-u*m,this.y+=u*g-d*p,this.z+=d*m-h*g}static createCrossProductToPoints(e,t,n,i){return v.createCrossProduct(t.x-e.x,t.y-e.y,t.z-e.z,n.x-e.x,n.y-e.y,n.z-e.z,i)}static createUnitCrossProductToPoints(e,t,n,i){return v.createCrossProduct(t.x-e.x,t.y-e.y,t.z-e.z,n.x-e.x,n.y-e.y,n.z-e.z,i).normalize()}static createPolar(e,t,n){return v.create(e*t.cos(),e*t.sin(),n)}static createSpherical(e,t,n){const i=n.cos();return v.create(i*e*t.cos(),i*e*t.sin(),e*n.sin())}static fromJSON(e){const t=new v;return t.setFromJSON(e),t}static createFrom(e,t){if(e instanceof Float64Array){let n=0,i=0,s=0;return e.length>0&&(n=e[0]),e.length>1&&(i=e[1]),e.length>2&&(s=e[2]),v.create(n,i,s,t)}else if(Array.isArray(e))return v.create(e[0],e[1],e.length>2?e[2]:0);return v.create(e.x,e.y,Ln.hasZ(e)?e.z:0,t)}static createStartEnd(e,t,n){const i=Ln.accessZ(e,0),r=Ln.accessZ(t,0)-i;return n?(n.set(t.x-e.x,t.y-e.y,r),n):new v(t.x-e.x,t.y-e.y,r)}static createStartEndXYZXYZ(e,t,n,i,s,r,a){return this.create(i-e,s-t,r-n,a)}static createRotateVectorAroundVector(e,t,n){const i=t.normalize();if(i){const s=i.crossProduct(e);let r,a;return n?(r=n.cos(),a=n.sin()):(r=0,a=1),v.createAdd3Scaled(e,r,s,a,i,i.dotProduct(e)*(1-r))}}setStartEnd(e,t){this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z}static createZero(e){return v.create(0,0,0,e)}static unitX(e=1){return new v(e,0,0)}static unitY(e=1){return new v(0,e,0)}static unitZ(e=1){return new v(0,0,e)}safeDivideOrNull(e,t){if(e!==0)return this.scale(1/e,t)}normalizeWithLength(e){const t=this.magnitude(),n=f.correctSmallFraction(t);return e=e||new v,{v:this.safeDivideOrNull(n,e),mag:t}}normalize(e){return this.normalizeWithLength(e).v}normalizeInPlace(){return this.normalizeWithLength(this).v!==void 0}static createNormalized(e=0,t=0,n=0,i){if(i===void 0?i=v.create(e,t,n):i.set(e,t,n),i.normalizeInPlace())return i}static createNormalizedStartEnd(e,t,n){if(n=v.createStartEnd(e,t,n),n.normalizeInPlace())return n}fractionOfProjectionToVector(e,t=0){const n=e.magnitudeSquared();return n<f.smallMetricDistanceSquared?t:this.dotProduct(e)/n}negate(e){return e=e||new v,e.x=-this.x,e.y=-this.y,e.z=-this.z,e}rotate90CCWXY(e){e=e||new v;const t=this.x,n=this.y;return e.x=-n,e.y=t,e.z=this.z,e}rotate90CWXY(e){e=e||new v;const t=this.x,n=this.y;return e.x=n,e.y=-t,e.z=this.z,e}unitPerpendicularXY(e){e=e||new v;const t=this.x,n=this.y;e.x=-n,e.y=t,e.z=0;const i=t*t+n*n;if(i!==0){const s=1/Math.sqrt(i);e.x*=s,e.y*=s}return e}rotateXY(e,t){const n=e.sin(),i=e.cos(),s=this.x,r=this.y;return t=t||new v,t.x=s*i-r*n,t.y=s*n+r*i,t.z=this.z,t}rotate90Towards(e,t){const n=this.crossProduct(e).normalize();return n?n.crossProduct(this,t):void 0}rotate90Around(e,t){const n=e.normalize();return n?n.crossProduct(this).plusScaled(n,n.dotProduct(this),t):void 0}interpolate(e,t,n){if(n=n||new v,e<=.5)n.x=this.x+e*(t.x-this.x),n.y=this.y+e*(t.y-this.y),n.z=this.z+e*(t.z-this.z);else{const i=e-1;n.x=t.x+i*(t.x-this.x),n.y=t.y+i*(t.y-this.y),n.z=t.z+i*(t.z-this.z)}return n}plus(e,t){return t=t||new v,t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t}minus(e,t){return t=t||new v,t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t}plusScaled(e,t,n){return n=n||new v,n.x=this.x+e.x*t,n.y=this.y+e.y*t,n.z=this.z+e.z*t,n}plus2Scaled(e,t,n,i,s){return s=s||new v,s.x=this.x+e.x*t+n.x*i,s.y=this.y+e.y*t+n.y*i,s.z=this.z+e.z*t+n.z*i,s}plus3Scaled(e,t,n,i,s,r,a){return a=a||new v,a.x=this.x+e.x*t+n.x*i+s.x*r,a.y=this.y+e.y*t+n.y*i+s.y*r,a.z=this.z+e.z*t+n.z*i+s.z*r,a}static createAdd2Scaled(e,t,n,i,s){return v.create(e.x*t+n.x*i,e.y*t+n.y*i,e.z*t+n.z*i,s)}static createAdd2ScaledXYZ(e,t,n,i,s,r,a,o,c){return v.create(e*i+s*o,t*i+r*o,n*i+a*o,c)}static createAdd3Scaled(e,t,n,i,s,r,a){return v.create(e.x*t+n.x*i+s.x*r,e.y*t+n.y*i+s.y*r,e.z*t+n.z*i+s.z*r,a)}scale(e,t){return t=t||new v,t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t}scaleToLength(e,t){const n=f.correctSmallFraction(this.magnitude());if(n!==0)return this.scale(e/n,t)}unitCrossProduct(e,t){return this.crossProduct(e,t).normalize(t)}unitCrossProductWithDefault(e,t,n,i,s){const r=this.crossProduct(e,s).normalize(s);return r===void 0?v.create(t,n,i,s):r}normalizeWithDefault(e,t,n,i){const s=this.normalize(i);return s||(i=v.create(e,t,n,i),i.normalizeInPlace()?i:v.create(1,0,0,i))}tryNormalizeInPlace(e=f.smallFraction){const t=this.magnitude();return t<=Math.abs(e)?!1:(this.scaleInPlace(1/t),!0)}sizedCrossProduct(e,t,n){if(n=this.crossProduct(e,n),n.tryNormalizeInPlace())return n.scaleInPlace(t),n}crossProductMagnitudeSquared(e){const t=this.y*e.z-this.z*e.y,n=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return t*t+n*n+i*i}crossProductMagnitude(e){return Math.sqrt(this.crossProductMagnitudeSquared(e))}dotProduct(e){return this.x*e.x+this.y*e.y+this.z*e.z}static dotProductAsXYAndZ(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}dotProductStartEnd(e,t){return this.x*(t.x-e.x)+this.y*(t.y-e.y)+this.z*(t.z-e.z)}dotProductStart3dEnd4d(e,t){const n=t.w;return this.x*(t.x-e.x*n)+this.y*(t.y-e.y*n)+this.z*(t.z-e.z*n)}crossProductStartEnd(e,t,n){return v.createCrossProduct(this.x,this.y,this.z,t.x-e.x,t.y-e.y,t.z-e.z,n)}crossProductStartEndXY(e,t){return f.crossProductXYXY(this.x,this.y,t.x-e.x,t.y-e.y)}dotProductStartEndXYZ(e,t,n,i){return this.x*(t-e.x)+this.y*(n-e.y)+this.z*(i-e.z)}dotProductStartEndXY(e,t){return this.x*(t.x-e.x)+this.y*(t.y-e.y)}dotProductStartEndXYZW(e,t,n,i,s){if(f.isSmallMetricDistance(s))return 0;const r=1/s;return this.x*(r*t-e.x)+this.y*(r*n-e.y)+this.z*(r*i-e.z)}dotProductXY(e){return this.x*e.x+this.y*e.y}dotProductXYZ(e,t,n=0){return this.x*e+this.y*t+this.z*n}tripleProduct(e,t){return f.tripleProduct(this.x,this.y,this.z,e.x,e.y,e.z,t.x,t.y,t.z)}crossProductXY(e){return this.x*e.y-this.y*e.x}crossProduct(e,t){return v.createCrossProduct(this.x,this.y,this.z,e.x,e.y,e.z,t)}crossProductXYZ(e,t,n,i){return v.createCrossProduct(this.x,this.y,this.z,e,t,n,i)}radiansTo(e){return Math.atan2(this.crossProductMagnitude(e),this.dotProduct(e))}angleTo(e){return T.createRadians(this.radiansTo(e))}angleFromPerpendicular(e){return T.createAtan2(this.dotProduct(e),this.crossProductMagnitude(e))}radiansFromPerpendicular(e){return Math.atan2(this.dotProduct(e),this.crossProductMagnitude(e))}angleToXY(e){return T.createAtan2(this.crossProductXY(e),this.dotProductXY(e))}signedRadiansTo(e,t){const n=this.crossProduct(e),i=Math.atan2(n.magnitude(),this.dotProduct(e));return t.dotProduct(n)<0?-i:i}signedAngleTo(e,t){return T.createRadians(this.signedRadiansTo(e,t))}planarRadiansTo(e,t){const n=t.dotProduct(t);if(n===0)return 0;const i=1/n,s=this.plusScaled(t,-this.dotProduct(t)*i),r=e.plusScaled(t,-e.dotProduct(t)*i);return s.signedRadiansTo(r,t)}planarAngleTo(e,t){return T.createRadians(this.planarRadiansTo(e,t))}smallerUnorientedRadiansTo(e){const t=this.dotProduct(e),n=this.crossProductMagnitude(e);return Math.atan2(Math.abs(n),Math.abs(t))}smallerUnorientedAngleTo(e){return T.createRadians(this.smallerUnorientedRadiansTo(e))}isParallelTo(e,t=!1,n=!1,i){const s=i?.radianSquaredTol??f.smallAngleRadiansSquared,r=i?.distanceSquaredTol??f.smallMetricDistanceSquared,a=this.magnitudeSquared(),o=e.magnitudeSquared();return a<r||o<r?n:this.dotProduct(e)<0&&!t?!1:this.crossProductMagnitudeSquared(e)<=s*a*o}isPerpendicularTo(e,t=!1,n){const i=n?.radianSquaredTol??f.smallAngleRadiansSquared,s=n?.distanceSquaredTol??f.smallMetricDistanceSquared,r=this.magnitudeSquared(),a=e.magnitudeSquared();if(r<s||a<s)return t;const o=this.dotProduct(e);return o*o<=i*r*a}}var ve;(function(l){l[l.XYZ=0]="XYZ",l[l.YZX=1]="YZX",l[l.ZXY=2]="ZXY",l[l.XZY=4]="XZY",l[l.YXZ=5]="YXZ",l[l.ZYX=6]="ZYX"})(ve||(ve={}));var Jt;(function(l){l[l.X=0]="X",l[l.Y=1]="Y",l[l.Z=2]="Z"})(Jt||(Jt={}));var Tn;(function(l){l[l.Top=1]="Top",l[l.Bottom=2]="Bottom",l[l.Left=3]="Left",l[l.Right=4]="Right",l[l.Front=5]="Front",l[l.Back=6]="Back",l[l.Iso=7]="Iso",l[l.RightIso=8]="RightIso"})(Tn||(Tn={}));var Ki;(function(l){l[l.Unit=0]="Unit",l[l.LongestRangeDirection=1]="LongestRangeDirection",l[l.NonUniformRangeContainment=2]="NonUniformRangeContainment"})(Ki||(Ki={}));var we;(function(l){l[l.Unknown=0]="Unknown",l[l.OnPolygonVertex=1]="OnPolygonVertex",l[l.OnPolygonEdgeInterior=2]="OnPolygonEdgeInterior",l[l.InsidePolygon=3]="InsidePolygon",l[l.InsidePolygonProjectsToVertex=4]="InsidePolygonProjectsToVertex",l[l.InsidePolygonProjectsToEdgeInterior=5]="InsidePolygonProjectsToEdgeInterior",l[l.OutsidePolygon=6]="OutsidePolygon",l[l.OutsidePolygonProjectsToVertex=7]="OutsidePolygonProjectsToVertex",l[l.OutsidePolygonProjectsToEdgeInterior=8]="OutsidePolygonProjectsToEdgeInterior"})(we||(we={}));class f{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-f.smallAngleRadians;static largeFractionResult=1e10;static largeCoordinateResult=1e13;static hugeCoordinate=1e12;static isLargeCoordinateResult(e){return e>=this.largeCoordinateResult||e<=-this.largeCoordinateResult}static isHugeCoordinate(e){return f.isLargeCoordinateResult(e)}static isOdd(e){return(e&1)===1}static correctSmallMetricDistance(e,t=0){return e===void 0||Math.abs(e)<=f.smallMetricDistance?t:e}static correctSmallFraction(e,t=0){return e===void 0||Math.abs(e)<=f.smallFraction?t:e}static inverseMetricDistance(e){return Math.abs(e)<=f.smallMetricDistance?void 0:1/e}static inverseMetricDistanceSquared(e){return Math.abs(e)<=f.smallMetricDistanceSquared?void 0:1/e}static isSameCoordinate(e,t,n=f.smallMetricDistance){let i=e-t;return i<0&&(i=-i),i<=n}static isSameFraction(e,t,n=f.smallFraction){return this.isSameCoordinate(e,t,n)}static isSameCoordinateWithToleranceFactor(e,t,n){return f.isSameCoordinate(e,t,n*f.smallMetricDistance)}static isSameCoordinateXY(e,t,n,i,s=f.smallMetricDistance){let r=n-e;return r<0&&(r=-r),r>s?!1:(r=i-t,r<0&&(r=-r),r<=s)}static isSameCoordinateSquared(e,t,n=f.smallMetricDistance){return Math.abs(Math.sqrt(e)-Math.sqrt(t))<=n}static isSamePoint3d(e,t,n=f.smallMetricDistance){return e.distance(t)<=n}static isSameXYZ(e,t,n=f.smallMetricDistance){return e.distance(t)<=n}static isSamePoint3dXY(e,t,n=f.smallMetricDistance){return e.distanceXY(t)<=n}static isSameVector3d(e,t,n=f.smallMetricDistance){return e.distance(t)<=n}static isSamePoint2d(e,t,n=f.smallMetricDistance){return e.distance(t)<=n}static isSameVector2d(e,t,n=f.smallMetricDistance){return e.distance(t)<=n}static lexicalXYLessThan(e,t){return e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:e.y>t.y?1:0}static lexicalYXLessThan(e,t){return e.y<t.y?-1:e.y>t.y?1:e.x<t.x?-1:e.x>t.x?1:0}static lexicalXYZLessThan(e,t){return e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:e.y>t.y?1:e.z<t.z?-1:e.z>t.z?1:0}static compareXYZ(e=f.smallMetricDistance){return(t,n)=>{if(Es.almostEqual(t,n,e))return 0;if(!f.isSameCoordinate(t.x,n.x,e)){if(t.x<n.x)return-1;if(t.x>n.x)return 1}if(!f.isSameCoordinate(t.y,n.y,e)){if(t.y<n.y)return-1;if(t.y>n.y)return 1}if(!f.isSameCoordinate(t.z,n.z,e)){if(t.z<n.z)return-1;if(t.z>n.z)return 1}return 0}}static compareXY(e=f.smallMetricDistance){return(t,n)=>{if(Cs.almostEqual(t,n,e))return 0;if(!f.isSameCoordinate(t.x,n.x,e)){if(t.x<n.x)return-1;if(t.x>n.x)return 1}if(!f.isSameCoordinate(t.y,n.y,e)){if(t.y<n.y)return-1;if(t.y>n.y)return 1}return 0}}static isSmallRelative(e){return Math.abs(e)<=f.smallFraction}static isSmallAngleRadians(e){return Math.abs(e)<=f.smallAngleRadians}static isSmallAngleRadiansSquared(e){return Math.abs(e)<=f.smallAngleRadiansSquared}static isAlmostEqualOptional(e,t,n){if(e!==void 0&&t!==void 0){if(Math.abs(e-t)>n)return!1}else if(e!==void 0||t!==void 0)return!1;return!0}static isAlmostEqualNumber(e,t,n=f.smallAngleRadians){const i=1+Math.abs(e)+Math.abs(t);return Math.abs(e-t)<=n*i}static isAlmostEqualEitherNumber(e,t,n,i=f.smallAngleRadians){return this.isAlmostEqualNumber(e,t,i)||this.isAlmostEqualNumber(e,n,i)}static isAlmostEqualAnyNumber(e,t,n=f.smallAngleRadians){const i=Array.isArray(t)?s=>t[s]:t.iter;for(let s=0;s<t.length;s++)if(this.isAlmostEqualNumber(e,i(s),n))return!0;return!1}static isAlmostEqualXAndY(e,t,n=f.smallAngleRadians){const i=n*(1+Math.abs(e.x)+Math.abs(t.x)+Math.abs(e.y)+Math.abs(t.y));return Math.abs(e.x-t.x)<=i&&Math.abs(e.y-t.y)<=i}static isDistanceWithinTol(e,t=f.smallMetricDistance){return Math.abs(e)<=t}static isSmallMetricDistance(e){return Math.abs(e)<=f.smallMetricDistance}static isSmallMetricDistanceSquared(e){return Math.abs(e)<=f.smallMetricDistanceSquared}static cyclic3dAxis(e){if(e>=0)return e<3?e:e<6?e-3:e%3;const t=e+3;return t>=0?t:2-(-e-1)%3}static axisIndexToRightHandedAxisOrder(e){return e===0?ve.XYZ:e===1?ve.YZX:e===2?ve.ZXY:f.axisIndexToRightHandedAxisOrder(f.cyclic3dAxis(e))}static maxXYZ(e,t,n){let i=e;return t>i&&(i=t),n>i&&(i=n),i}static minXYZ(e,t,n){let i=e;return t<i&&(i=t),n<i&&(i=n),i}static maxXY(e,t){let n=e;return t>n&&(n=t),n}static minXY(e,t){let n=e;return t<n&&(n=t),n}static maxAbsXYZ(e,t,n){return f.maxXYZ(Math.abs(e),Math.abs(t),Math.abs(n))}static maxAbsXY(e,t){return f.maxXY(Math.abs(e),Math.abs(t))}static maxAbsDiff(e,t,n){return Math.max(Math.abs(e-t),Math.abs(e-n))}static split3WaySign(e,t,n,i){return e<0?t:e>0?i:n}static split3Way01(e,t=f.smallMetricDistance){return e>t?1:e<-t?-1:0}static square(e){return e*e}static hypotenuseXY(e,t){return Math.sqrt(e*e+t*t)}static hypotenuseSquaredXY(e,t){return e*e+t*t}static hypotenuseXYZ(e,t,n){return Math.sqrt(e*e+t*t+n*n)}static hypotenuseSquaredXYZ(e,t,n){return e*e+t*t+n*n}static hypotenuseXYZW(e,t,n,i){return Math.sqrt(e*e+t*t+n*n+i*i)}static hypotenuseSquaredXYZW(e,t,n,i){return e*e+t*t+n*n+i*i}static distanceXYXY(e,t,n,i){return f.hypotenuseXY(n-e,i-t)}static distanceSquaredXYXY(e,t,n,i){return f.hypotenuseSquaredXY(n-e,i-t)}static distanceXYZXYZ(e,t,n,i,s,r){return f.hypotenuseXYZ(i-e,s-t,r-n)}static tripleProduct(e,t,n,i,s,r,a,o,c){return e*(s*c-r*o)+t*(r*a-i*c)+n*(i*o-s*a)}static determinant4x4(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p,x){return e*this.tripleProduct(r,a,o,d,h,u,m,p,x)-s*this.tripleProduct(t,n,i,d,h,u,m,p,x)+c*this.tripleProduct(t,n,i,r,a,o,m,p,x)-g*this.tripleProduct(t,n,i,r,a,o,d,h,u)}static tripleProductXYW(e,t,n,i,s,r){return f.tripleProduct(e.x,n.x,s.x,e.y,n.y,s.y,t,i,r)}static tripleProductPoint4dXYW(e,t,n){return f.tripleProduct(e.x,t.x,n.x,e.y,t.y,n.y,e.w,t.w,n.w)}static crossProductXYXY(e,t,n,i){return e*i-t*n}static crossProductXYZXYZ(e,t,n,i,s,r,a){return v.create(t*r-n*s,n*i-e*r,e*s-t*i,a)}static crossProductToPointsXY(e,t,n){return this.crossProductXYXY(t.x-e.x,t.y-e.y,n.x-e.x,n.y-e.y)}static crossProductMagnitude(e,t,n,i,s,r){return f.hypotenuseXYZ(t*r-n*s,n*i-e*r,e*s-t*i)}static dotProductXYXY(e,t,n,i){return e*n+t*i}static dotProductXYZXYZ(e,t,n,i,s,r){return e*i+t*s+n*r}static fractionOfProjectionToVectorXYXY(e,t,n,i,s=0){const r=n*n+i*i;return r<f.smallMetricDistanceSquared?s:(e*n+t*i)/r}static meanCurvatureOfRadii(e,t){return .5*(this.safeDivideFraction(1,e,0)+this.safeDivideFraction(1,t,0))}static curvatureMagnitude(e,t,n,i,s,r){let a=t*r-n*s,o=a*a;a=n*i-e*r,o+=a*a,a=e*s-t*i,o+=a*a;const c=Math.sqrt(o),d=Math.sqrt(e*e+t*t+n*n),h=d*d*d;return h>f.smallAngleRadians*c?c/h:0}static clampToStartEnd(e,t,n){return t>n?f.clampToStartEnd(e,n,t):e<t?t:n<e?n:e}static clamp(e,t,n){return Math.max(t,Math.min(n,e))}static resolveNumber(e,t=0){return e!==void 0?e:t}static resolveValue(e,t){return e!==void 0?e:t}static resolveToUndefined(e,t){return e===t?void 0:e}static interpolate(e,t,n){return t<=.5?e+t*(n-e):n-(1-t)*(n-e)}static interpolateByte(e,t,n,i){return e=e>>>i&255,n=n>>>i&255,(Math.floor(e+t*(n-e))&255)<<i}static interpolateColor(e,t,n){t=f.clamp(t,0,1);const i=this.interpolateByte(e,t,n,0),s=this.interpolateByte(e,t,n,8),r=this.interpolateByte(e,t,n,16),a=this.interpolateByte(e,t,n,24);return i|s|r|a}static axisOrderToAxis(e,t){const n=e<=ve.ZXY?e+t:e-ve.XZY-t;return f.cyclic3dAxis(n)}static modulo(e,t){if(t<=0)return t===0?e:-f.modulo(-e,-t);if(e>=0){if(e<t)return e;if(e<2*t)return e-t}else if(e+=t,e>0)return e;const n=Math.floor(e/t);return e-n*t}static defined01(e){return e===void 0?0:1}static conditionalDivideFraction(e,t){if(t!==0&&Math.abs(t)*f.largeFractionResult>=Math.abs(e))return e/t}static safeDivideFraction(e,t,n){const i=f.conditionalDivideFraction(e,t);return i!==void 0?i:n}static conditionalDivideCoordinate(e,t,n=f.largeCoordinateResult){if(t!==0&&Math.abs(t*n)>=Math.abs(e))return e/t}static solveTrigForm(e,t,n){const i=t*t+n*n,s=e*e;let r;if(i>0){const a=1/i,c=1-s*a;if(c<-f.smallMetricDistanceSquared)return r;const d=-e*a,h=d*t,u=d*n;if(c<=f.smallMetricDistanceSquared)r=[$.create(h,u)];else{const g=Math.sqrt(c*a);r=[$.create(h-g*n,u+g*t),$.create(h+g*n,u-g*t)]}}return r}static inverseInterpolate(e,t,n,i,s=0,r){const a=f.conditionalDivideFraction(s-t,i-t);return a!==void 0?f.interpolate(e,a,n):r}static inverseInterpolate01(e,t,n=0){return f.conditionalDivideFraction(n-e,t-e)}static isNumber(e){return Number.isFinite(e)}static isNumberArray(e,t=0){if(Array.isArray(e)&&e.length>=t){let n;for(n of e)if(!Number.isFinite(n))return!1;return!0}return!1}static isArrayOfNumberArray(e,t,n=0){if(Array.isArray(e)&&e.length>=t){let i;for(i of e)if(!f.isNumberArray(i,n))return!1;return!0}return!1}static stepCount(e,t,n=1,i=101){if(e<=0||(t=Math.abs(t),e>=t))return n;const s=Math.floor((t+.999999*e)/e);return s<n?n:s>i?i:s}static isIn01(e,t=!0){return t?e>=0&&e<=1:!0}static isIn01WithTolerance(e,t){return t=Math.abs(t),e+t>=0&&e-t<=1}static restrictToInterval(e,t,n){return t<=n?e<t?t:e>n?n:e:e<n?n:e>t?t:e}static equalStringNoCase(e,t){return e.toUpperCase()===t.toUpperCase()}static exactEqualNumberArrays(e,t){if(Array.isArray(e)&&e.length===0&&(e=void 0),Array.isArray(t)&&t.length===0&&(t=void 0),e===void 0&&t===void 0)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return!1}static almostEqualArrays(e,t,n){if(Array.isArray(e)&&e.length===0&&(e=void 0),Array.isArray(t)&&t.length===0&&(t=void 0),e===void 0&&t===void 0)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!n(e[i],t[i]))return!1;return!0}return!1}static almostEqualNumberArrays(e,t,n){if(Array.isArray(e)&&e.length===0&&(e=void 0),Array.isArray(t)&&t.length===0&&(t=void 0),e===void 0&&t===void 0)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!n(e[i],t[i]))return!1;return!0}return!1}static areEqualAllowUndefined(e,t,n=!0){return e===void 0&&t===void 0?n:e!==void 0&&t!==void 0?e===t:!1}static cloneMembers(e){if(e===void 0)return;const t=[];for(const n of e)t.push(n.clone());return t}static cloneArray(e){if(e===void 0)return;const t=[];for(const n of e)t.push(n.clone());return t}}class T{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/T.piOver4Radians;static radiansPerDegree=T.piOver4Radians/45;_radians;_degrees;constructor(e=0,t){this._radians=e,this._degrees=t}clone(){return new T(this._radians,this._degrees)}freeze(){return Object.freeze(this)}static createDegrees(e){return new T(T.degreesToRadians(e),e)}static createRadians(e){return new T(e)}static createSmallAngle(){return new T(f.smallAngleRadians)}static createInterpolate(e,t,n){return new T(f.interpolate(e.radians,t,n.radians))}cloneScaled(e){return new T(this.radians*e)}setRadians(e){this._radians=e,this._degrees=void 0}setDegrees(e){this._radians=T.degreesToRadians(e),this._degrees=e}static create360(){return new T(Math.PI*2,360)}static createAtan2(e,t){return new T(Math.atan2(e,t))}setFrom(e){this._radians=e._radians,this._degrees=e._degrees}setFromJSON(e,t){this._radians=t||0,e&&(typeof e=="number"?this.setDegrees(e):typeof e.degrees=="number"?this.setDegrees(e.degrees):typeof e._degrees=="number"?this.setDegrees(e._degrees):typeof e.radians=="number"?this.setRadians(e.radians):typeof e._radians=="number"&&this.setRadians(e._radians))}static fromJSON(e,t){const n=new T;return n.setFromJSON(e,t),n}toJSON(){return this.degrees}toJSONRadians(){return{radians:this.radians}}get radians(){return this._radians}get degrees(){return this._degrees!==void 0?this._degrees:T.radiansToDegrees(this._radians)}static degreesToRadians(e){return e*Math.PI/180}static radiansToDegrees(e){if(e<0)return-T.radiansToDegrees(-e);const t=Math.PI,n=180/t;return e<=.25*t?n*e:e<.75*t?90+180*((e-.5*t)/t):e<=1.25*t?180+180*((e-t)/t):e<=1.75*t?270+180*((e-1.5*t)/t):360+180*((e-2*t)/t)}cos(){return Math.cos(this._radians)}sin(){return Math.sin(this._radians)}tan(){return Math.tan(this._radians)}static isFullCircleRadians(e){return Math.abs(e)>=f.fullCircleRadiansMinusSmallAngle}static isHalfCircleRadians(e){return Math.abs(Math.abs(e)-Math.PI)<=f.smallAngleRadians}get isFullCircle(){return T.isFullCircleRadians(this._radians)}get isHalfCircle(){return T.isHalfCircleRadians(this._radians)}static adjustDegrees0To360(e){if(e>=0){if(e<360)return e;const n=Math.floor(e/360);return e-n*360}else if(e<0)return 360-T.adjustDegrees0To360(-e);return 0}static adjustDegreesSigned180(e){if(Math.abs(e)<=180)return e;if(e>=0){const n=1+Math.floor((e-180)/360);return e-n*360}else if(e<0)return-T.adjustDegreesSigned180(-e);return 0}static adjustRadians0To2Pi(e){if(e>=0){const t=Math.PI*2;if(e<t)return e;const n=Math.floor(e/t);return e-n*t}else if(e<0)return Math.PI*2-T.adjustRadians0To2Pi(-e);return 0}static adjustRadians0ToLessThan2Pi(e){return T.isAlmostEqualRadiansAllowPeriodShift(e,0)&&(e=0),this.adjustRadians0To2Pi(e)}static adjustRadiansMinusPiPlusPi(e){if(Math.abs(e)<=Math.PI)return e;if(e>=0){const t=Math.PI*2,n=1+Math.floor((e-Math.PI)/t);return e-n*t}else if(e<0)return-T.adjustRadiansMinusPiPlusPi(-e);return 0}static zero(){return new T(0)}get isExactZero(){return this.radians===0}get isAlmostZero(){return Math.abs(this.radians)<f.smallAngleRadians}get isAlmostNorthOrSouthPole(){return T.isHalfCircleRadians(this.radians*2)}static createDegreesAdjustPositive(e){return T.createDegrees(T.adjustDegrees0To360(e))}static createDegreesAdjustSigned180(e){return T.createDegrees(T.adjustDegreesSigned180(e))}static isAlmostEqualRadiansAllowPeriodShift(e,t,n=f.smallAngleRadians){const i=Math.abs(e-t);if(i<=n)return!0;const s=Math.PI*2;if(Math.abs(i-s)<=n)return!0;const r=Math.round(i/s),a=i-r*s;return Math.abs(a)<=n}isMagnitudeLessThanOrEqual(e){return Math.abs(this.radians)<=Math.abs(e.radians)}isAlmostEqualAllowPeriodShift(e,t=f.smallAngleRadians){return T.isAlmostEqualRadiansAllowPeriodShift(this._radians,e._radians,t)}static isAlmostEqualRadiansNoPeriodShift(e,t,n=f.smallAngleRadians){return Math.abs(e-t)<n}isAlmostEqualNoPeriodShift(e,t=f.smallAngleRadians){return T.isAlmostEqualRadiansNoPeriodShift(this._radians,e._radians,t)}isAlmostEqual(e,t=f.smallAngleRadians){return this.isAlmostEqualNoPeriodShift(e,t)}static isPerpendicularDotSet(e,t,n){return e>f.smallMetricDistanceSquared&&t>f.smallMetricDistanceSquared&&n*n<=f.smallAngleRadiansSquared*e*t}static trigValuesToHalfAngleTrigValues(e,t){const n=f.hypotenuseXY(e,t);if(n<f.smallMetricDistance)return{c:1,s:0,radians:0};{let i,s=0;const r=e/n,a=t/n;return r>=0?(i=Math.sqrt(.5*(1+r)),s=a/(2*i)):(a>0?s=Math.sqrt(.5*(1-r)):s=-Math.sqrt(.5*(1-r)),i=a/(2*s)),{c:i,s,radians:Math.atan2(s,i)}}}static cleanupTrigValue(e,t=f.smallFloatingPoint){const n=Math.abs(e);if(n<=t)return 0;let i=Math.abs(n-.5);return i<=t?e<0?-.5:.5:(i=Math.abs(n-1),i<=t?e<0?-1:1:e)}static dotProductsToHalfAngleTrigValues(e,t,n,i=!0){const s=e-t,r=2*n;return i&&Math.abs(r)<f.smallAngleRadians*(Math.abs(e)+Math.abs(t))?{c:1,s:0,radians:0}:T.trigValuesToHalfAngleTrigValues(s,r)}static radiansBetweenVectorsXYZ(e,t,n,i,s,r){const a=e*i+t*s+n*r;return Math.atan2(f.crossProductMagnitude(e,t,n,i,s,r),a)}static orientedRadiansBetweenVectorsXYZ(e,t,n,i,s,r,a,o,c,d=!1){const h=e*i+t*s+n*r,u=t*r-n*s,g=n*i-e*r,m=e*s-t*i,p=a*u+o*g+c*m,x=f.hypotenuseXYZ(u,g,m);return p<0?d?Math.PI+Math.atan2(x,-h):-Math.atan2(x,h):Math.atan2(x,h)}addMultipleOf2PiInPlace(e){this._degrees!==void 0?(this._degrees+=e*360,this._radians=T.degreesToRadians(this._degrees)):this._radians+=e*T.pi2Radians}}class me{_radians0;_radians1;get startDegrees(){return T.radiansToDegrees(this._radians0)}get endDegrees(){return T.radiansToDegrees(this._radians1)}get sweepDegrees(){return T.radiansToDegrees(this.sweepRadians)}get startRadians(){return this._radians0}get endRadians(){return this._radians1}get sweepRadians(){return this._radians1-this._radians0}get isEmpty(){return T.isAlmostEqualRadiansNoPeriodShift(0,this.sweepRadians)}get startAngle(){return T.createRadians(this._radians0)}get endAngle(){return T.createRadians(this._radians1)}static create(e){return e instanceof me?e.clone():e instanceof T?new me(0,e.radians):me.create360()}constructor(e=0,t=0){this._radians0=e,this._radians1=t}setStartEndRadians(e=0,t=2*Math.PI){const n=t-e;T.isFullCircleRadians(n)&&(t=e+(n>0?2:-2)*Math.PI),this._radians0=e,this._radians1=t}setStartEndDegrees(e=0,t=360){this.setStartEndRadians(T.degreesToRadians(e),T.degreesToRadians(t))}static createStartEndRadians(e=0,t=2*Math.PI,n){return n=n||new me,n.setStartEndRadians(e,t),n}clonePlusRadians(e){return new me(this._radians0+e,this._radians1+e)}cloneMinusRadians(e){return this.clonePlusRadians(-e)}static createStartEndDegrees(e=0,t=360,n){return me.createStartEndRadians(T.degreesToRadians(e),T.degreesToRadians(t),n)}static createStartEnd(e,t,n){return n=n||new me,n.setStartEndRadians(e.radians,t.radians),n}static createStartSweepRadians(e=0,t=Math.PI,n){return n=n||new me,n.setStartEndRadians(e,e+t),n}static createStartSweepDegrees(e=0,t=360,n){return me.createStartEndRadians(T.degreesToRadians(e),T.degreesToRadians(e+t),n)}static createStartSweep(e,t,n){return me.createStartSweepRadians(e.radians,t.radians,n)}interpolate(e,t){return new me(f.interpolate(this._radians0,e,t._radians0),f.interpolate(this._radians1,e,t._radians1))}setFrom(e){this._radians0=e._radians0,this._radians1=e._radians1}static create360(e,t){e=e||0;const n=e+2*Math.PI;return t?(t.setStartEndRadians(e,n),t):new me(e,n)}static createFullLatitude(){return me.createStartEndRadians(-.5*Math.PI,.5*Math.PI)}reverseInPlace(){const e=this._radians0;this._radians0=this._radians1,this._radians1=e}cloneComplement(e=!1,t){const n=this.sweepRadians>=0?2:-2;return e?me.createStartEndRadians(this.startRadians,this.endRadians-n*Math.PI,t):me.createStartEndRadians(this.endRadians,this.startRadians+n*Math.PI,t)}capLatitudeInPlace(){const e=.5*Math.PI;this._radians0=f.clampToStartEnd(this._radians0,-e,e),this._radians1=f.clampToStartEnd(this._radians1,-e,e)}clampToFullCircle(e){e=e??new me;const t=f.clampToStartEnd(this.sweepRadians,-6.283185307179586,T.pi2Radians);return e.setStartEndRadians(this._radians0,this._radians0+t),e}get isCCW(){return this._radians1>=this._radians0}get isFullCircle(){return T.isFullCircleRadians(this.sweepRadians)}get isFullLatitudeSweep(){const e=Math.PI*.5;return T.isAlmostEqualRadiansNoPeriodShift(this._radians0,-e)&&T.isAlmostEqualRadiansNoPeriodShift(this._radians1,e)}clone(){return new me(this._radians0,this._radians1)}fractionToRadians(e){return e<.5?this._radians0+e*this.sweepRadians:this._radians1+(e-1)*this.sweepRadians}fractionToAngle(e){return T.createRadians(this.fractionToRadians(e))}fractionPeriod(){return this.isEmpty?1:T.pi2Radians/Math.abs(this.sweepRadians)}angleToUnboundedFraction(e){return this.isEmpty?1:(e.radians-this._radians0)/this.sweepRadians}static fractionToSignedPeriodicFractionStartEnd(e,t,n,i){const s=n-t;if(T.isAlmostEqualRadiansNoPeriodShift(0,s)||f.isIn01(e))return e;const r=T.pi2Radians/Math.abs(s);if(e=e%r,e+r<1&&(e+=r),f.isIn01(e))return e;if(i===!0)return e<0?e:e-r;if(i===!1)return e>1?e:e+r;const a=e<0?-e:e-1,o=e<0?e+r:e-r,c=o<0?-o:o-1;return a<c?e:o}fractionToSignedPeriodicFraction(e,t){return me.fractionToSignedPeriodicFractionStartEnd(e,this._radians0,this._radians1,t)}static radiansToPositivePeriodicFractionStartEnd(e,t,n,i=0){const s=f.largeCoordinateResult;let r=this.radiansToSignedPeriodicFractionStartEnd(e,t,n,s);if(r===s)return i;if(r<0){const a=T.pi2Radians/Math.abs(n-t);r+=a}return r}radiansToPositivePeriodicFraction(e,t=0){return me.radiansToPositivePeriodicFractionStartEnd(e,this._radians0,this._radians1,t)}angleToPositivePeriodicFraction(e,t=0){return this.radiansToPositivePeriodicFraction(e.radians,t)}radiansArrayToPositivePeriodicFractions(e){const t=e.length;for(let n=0;n<t;n++)e.reassign(n,this.radiansToPositivePeriodicFraction(e.atUncheckedIndex(n)))}static radiansToSignedPeriodicFractionStartEnd(e,t,n,i=0){const s=n-t;if(T.isAlmostEqualRadiansNoPeriodShift(0,s))return i;if(T.isAlmostEqualRadiansAllowPeriodShift(t,n)){if(T.isAlmostEqualRadiansNoPeriodShift(e,t))return 0;if(T.isAlmostEqualRadiansNoPeriodShift(e,n))return 1}else{if(T.isAlmostEqualRadiansAllowPeriodShift(e,t))return 0;if(T.isAlmostEqualRadiansAllowPeriodShift(e,n))return 1}const r=(e-t)/s;return this.fractionToSignedPeriodicFractionStartEnd(r,t,n,r<0)}radiansToSignedPeriodicFraction(e,t=0){return me.radiansToSignedPeriodicFractionStartEnd(e,this._radians0,this._radians1,t)}angleToSignedPeriodicFraction(e,t=0){return this.radiansToSignedPeriodicFraction(e.radians,t)}static radiansToSignedFractionStartEnd(e,t,n,i=!1,s=0){const r=f.largeCoordinateResult;let a=this.radiansToSignedPeriodicFractionStartEnd(e,t,n,r);if(a===r)return s;if(i&&a>1||!i&&a<0){let o=T.pi2Radians/Math.abs(n-t);i&&(o=-o),a+=o}return a}radiansToSignedFraction(e,t=!1,n=0){return me.radiansToSignedFractionStartEnd(e,this._radians0,this._radians1,t,n)}angleToSignedFraction(e,t=!1,n=0){return this.radiansToSignedFraction(e.radians,t,n)}static isRadiansInStartEnd(e,t,n,i=!0){const s=e-t,r=e-n;return s*r<=0?!0:t===n?i?T.isAlmostEqualRadiansAllowPeriodShift(e,t):T.isAlmostEqualRadiansNoPeriodShift(e,t):i?this.radiansToPositivePeriodicFractionStartEnd(e,t,n,1e3)<=1:!1}isRadiansInSweep(e,t=!0){return me.isRadiansInStartEnd(e,this.startRadians,this.endRadians,t)}isAngleInSweep(e){return this.isRadiansInSweep(e.radians)}setFromJSON(e){e?e instanceof me?this.setFrom(e):f.isNumberArray(e.degrees,2)?this.setStartEndDegrees(e.degrees[0],e.degrees[1]):f.isNumberArray(e.radians,2)?this.setStartEndRadians(e.radians[0],e.radians[1]):f.isNumberArray(e,2)?this.setStartEndDegrees(e[0],e[1]):this.setStartEndRadians():this.setStartEndRadians()}static fromJSON(e){const t=me.create360();return t.setFromJSON(e),t}toJSON(){return[this.startDegrees,this.endDegrees]}isAlmostEqualAllowPeriodShift(e,t=f.smallAngleRadians){return this.isCCW===e.isCCW&&T.isAlmostEqualRadiansAllowPeriodShift(this._radians0,e._radians0,t)&&T.isAlmostEqualRadiansAllowPeriodShift(this.sweepRadians,e.sweepRadians,t)}isAlmostEqualNoPeriodShift(e,t=f.smallAngleRadians){return T.isAlmostEqualRadiansNoPeriodShift(this._radians0,e._radians0,t)&&T.isAlmostEqualRadiansNoPeriodShift(this.sweepRadians,e.sweepRadians,t)}isAlmostEqual(e){return this.isAlmostEqualNoPeriodShift(e)}}class ks{isPointInPlane(e,t=f.smallMetricDistance){return Math.abs(this.altitude(e))<=t}classifyAltitude(e,t=f.smallMetricDistance){return f.split3Way01(this.altitude(e),t)}classifyAltitudeXYZ(e,t,n,i=f.smallMetricDistance){return f.split3Way01(this.altitudeXYZ(e,t,n),i)}getUnitNormal(e){return v.createNormalized(this.normalX(),this.normalY(),this.normalZ(),e)}getAnyPointOnPlane(e){return this.projectXYZToPlane(0,0,0,e)}projectXYZToPlane(e,t,n,i){const s=y.create(e,t,n,i);return this.projectPointToPlane(s,s)}}class vc{_collection;_curIndex=-1;constructor(e){this._collection=e}next(){return++this._curIndex>=this._collection.length?{done:!0}:{value:this._collection.getPoint3dAtUncheckedPointIndex(this._curIndex),done:!1}}[Symbol.iterator](){return this}}class gt{vectorUncheckedIndexIndex(e,t,n){return v.createStartEndXYZXYZ(this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(e),this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(t),n)}vectorXYAndZUncheckedIndex(e,t,n){return v.createStartEndXYZXYZ(e.x,e.y,e.z,this.getXAtUncheckedPointIndex(t),this.getYAtUncheckedPointIndex(t),this.getZAtUncheckedPointIndex(t),n)}vectorIndexXYAndZ(e,t,n){const i=this.vectorXYAndZIndex(t,e,n);return i?.negate(i)}dotProductIndexIndexIndex(e,t,n){if(e<0||e>=this.length||t<0||t>=this.length||n<0||n>=this.length)return;const i=this.getXAtUncheckedPointIndex(e),s=this.getYAtUncheckedPointIndex(e),r=this.getZAtUncheckedPointIndex(e);return(this.getXAtUncheckedPointIndex(t)-i)*(this.getXAtUncheckedPointIndex(n)-i)+(this.getYAtUncheckedPointIndex(t)-s)*(this.getYAtUncheckedPointIndex(n)-s)+(this.getZAtUncheckedPointIndex(t)-r)*(this.getZAtUncheckedPointIndex(n)-r)}dotProductIndexIndexXYAndZ(e,t,n){if(!(e<0||e>=this.length||t<0||t>=this.length))return this.dotProductUncheckedIndexIndexXYAndZ(e,t,n)}dotProductUncheckedIndexIndexXYAndZ(e,t,n){const i=this.getXAtUncheckedPointIndex(e),s=this.getYAtUncheckedPointIndex(e),r=this.getZAtUncheckedPointIndex(e);return(this.getXAtUncheckedPointIndex(t)-i)*(n.x-i)+(this.getYAtUncheckedPointIndex(t)-s)*(n.y-s)+(this.getZAtUncheckedPointIndex(t)-r)*(n.z-r)}crossProductIndexIndexXYAndZ(e,t,n,i){if(!(e<0||e>=this.length||t<0||t>=this.length))return this.crossProductUncheckedIndexIndexXYAndZ(e,t,n,i)}crossProductUncheckedIndexIndexXYAndZ(e,t,n,i){const s=this.getXAtUncheckedPointIndex(e),r=this.getYAtUncheckedPointIndex(e),a=this.getZAtUncheckedPointIndex(e);return v.createCrossProduct(this.getXAtUncheckedPointIndex(t)-s,this.getYAtUncheckedPointIndex(t)-r,this.getZAtUncheckedPointIndex(t)-a,n.x-s,n.y-r,n.z-a,i)}crossProductUncheckedIndexIndexIndex(e,t,n,i){const s=this.getXAtUncheckedPointIndex(e),r=this.getYAtUncheckedPointIndex(e),a=this.getZAtUncheckedPointIndex(e);return v.createCrossProduct(this.getXAtUncheckedPointIndex(t)-s,this.getYAtUncheckedPointIndex(t)-r,this.getZAtUncheckedPointIndex(t)-a,this.getXAtUncheckedPointIndex(n)-s,this.getYAtUncheckedPointIndex(n)-r,this.getZAtUncheckedPointIndex(n)-a,i)}distanceSquaredUncheckedIndexIndex(e,t){return f.hypotenuseSquaredXYZ(this.getXAtUncheckedPointIndex(t)-this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(t)-this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(t)-this.getZAtUncheckedPointIndex(e))}distanceSquaredIndexXYAndZ(e,t){if(!(e<0||e>=this.length))return this.distanceSquaredUncheckedIndexXYAndZ(e,t)}distanceSquaredUncheckedIndexXYAndZ(e,t){return f.hypotenuseSquaredXYZ(t.x-this.getXAtUncheckedPointIndex(e),t.y-this.getYAtUncheckedPointIndex(e),t.z-this.getZAtUncheckedPointIndex(e))}distanceUncheckedIndexIndex(e,t){return f.hypotenuseXYZ(this.getXAtUncheckedPointIndex(t)-this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(t)-this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(t)-this.getZAtUncheckedPointIndex(e))}isIndexValid(e){return e>=0&&e<this.length}cyclicIndex(e){return f.modulo(e,this.length)}getRange(e,t){let n=t;n?n.setNull():n=ie.createNull();const i=this.length,s=y.create();for(let r=0;r<i;r++)this.getPoint3dAtUncheckedPointIndex(r,s),n.extendPoint(s,e);return n}findOrderedDuplicates(e=f.smallMetricDistance,t=!1){const n=[];if(this.length>1){for(let i=0;i<this.length-1;){let s=i+1;for(;this.almostEqualIndexIndex(i,s,e);++s)n.push(s);i=s}if(t&&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(e,t){const n=Math.min(this.length,e.length),i=t instanceof v?v.createZero(t):y.createZero(t);for(let s=0;s<n;++s)i.x+=e[s]*this.getXAtUncheckedPointIndex(s),i.y+=e[s]*this.getYAtUncheckedPointIndex(s),i.z+=e[s]*this.getZAtUncheckedPointIndex(s);return i}interpolateIndexIndex(e,t,n,i){if(!(e<0||e>=this.length||n<0||n>=this.length))return this.interpolateUncheckedIndexIndex(e,t,n,i)}interpolateUncheckedIndexIndex(e,t,n,i){return y.create(f.interpolate(this.getXAtUncheckedPointIndex(e),t,this.getXAtUncheckedPointIndex(n)),f.interpolate(this.getYAtUncheckedPointIndex(e),t,this.getYAtUncheckedPointIndex(n)),f.interpolate(this.getZAtUncheckedPointIndex(e),t,this.getZAtUncheckedPointIndex(n)),i)}get points(){return new vc(this)}getArray(){const e=[];for(const t of this.points)e.push(t);return e}front(e){if(this.length!==0)return this.getPoint3dAtUncheckedPointIndex(0,e)}back(e){if(this.length!==0)return this.getPoint3dAtUncheckedPointIndex(this.length-1,e)}almostEqualIndexIndex(e,t,n=f.smallMetricDistance){if(!(e<0||e>=this.length||t<0||t>=this.length))return this.almostEqualUncheckedIndexIndex(e,t,n)}almostEqualUncheckedIndexIndex(e,t,n=f.smallMetricDistance){return f.isSameCoordinate(this.getXAtUncheckedPointIndex(e),this.getXAtUncheckedPointIndex(t),n)&&f.isSameCoordinate(this.getYAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(t),n)&&f.isSameCoordinate(this.getZAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(t),n)}almostEqualXYIndexIndex(e,t,n=f.smallMetricDistance){if(!(e<0||e>=this.length||t<0||t>=this.length))return this.almostEqualXYUncheckedIndexIndex(e,t,n)}almostEqualXYUncheckedIndexIndex(e,t,n=f.smallMetricDistance){return f.isSameCoordinate(this.getXAtUncheckedPointIndex(e),this.getXAtUncheckedPointIndex(t),n)&&f.isSameCoordinate(this.getYAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(t),n)}evaluateUncheckedIndexPlaneAltitude(e,t){return t.altitudeXYZ(this.getXAtUncheckedPointIndex(e),this.getYAtUncheckedPointIndex(e),this.getZAtUncheckedPointIndex(e))}}class Fs extends gt{pushIndexedXYZCollection(e){for(let t=0;t<e.length;t++)this.pushXYZ(e.getXAtUncheckedPointIndex(t),e.getYAtUncheckedPointIndex(t),e.getZAtUncheckedPointIndex(t));return e.length}}class J extends Fs{_data;_xyzInUse;_xyzCapacity;_growthFactor;constructor(e,t,n){super(),n?(this._xyzCapacity=n.length/3,this._xyzInUse=Math.min(e??1/0,this._xyzCapacity),this._data=n):(this._xyzCapacity=e??8,this._xyzInUse=0,this._data=new Float64Array(3*this._xyzCapacity)),this._growthFactor=t!==void 0&&t>=1?t:1.5}copyData(e,t,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=t!==void 0?t*3:e.length;return s>0&&(s>e.length&&(s=e.length),i+s>this._data.length&&(s=this._data.length-i),s%3!==0&&(s-=s%3)),s<=0?{count:0,offset:0}:(s===e.length?this._data.set(e,i):e instanceof Float64Array?this._data.set(e.subarray(0,s),i):this._data.set(e.slice(0,s),i),{count:s/3,offset:i/3})}get length(){return this._xyzInUse}set length(e){this.resize(e,!0)}get float64Length(){return this._xyzInUse*3}float64Data(){return this._data}ensureCapacity(e,t=!0){if(e>this._xyzCapacity){t&&(e=Math.trunc(e*this._growthFactor));const n=this._data;this._data.buffer instanceof ArrayBuffer?this._data=new Float64Array(new ArrayBuffer(e*3*this._data.BYTES_PER_ELEMENT)):this._data=new Float64Array(new SharedArrayBuffer(e*3*this._data.BYTES_PER_ELEMENT)),this.copyData(n,this._xyzInUse),this._xyzCapacity=e}}resize(e,t){e>=0&&e<this._xyzInUse?this._xyzInUse=e:e>this._xyzInUse&&(this.ensureCapacity(e,!1),(t??!1)&&this._data.fill(0,this._xyzInUse*3),this._xyzInUse=e)}clone(e){return e?(e.length!==this.length&&e.clear(),e.resize(this.length)):e=new J(this.length),e.copyData(this._data,this.length),e._xyzInUse=this.length,e}static createCompressed(e,t=f.smallMetricDistance,n){const i=e.findOrderedDuplicates(t,!0),s=e.length-i.length;n||(n=new J(s)),n!==e&&(n.clear(),n.resize(s,!0));for(let r=0,a=0,o=0;r<e.length;++r)o<i.length&&r===i[o]?++o:n.transferFromGrowableXYZArray(a++,e,r);return n.resize(s),n}cloneCompressed(e=f.smallMetricDistance,t){return J.createCompressed(this,e,t)}compressInPlace(e=f.smallMetricDistance){return J.createCompressed(this,e,this)}static create(e,t){if(t)t.clear();else{const n=typeof e[0]=="number"?e.length/3:e.length;t=new J(n)}return t.pushFrom(e),t}static createCapture(e){return new J(0,void 0,e)}static createArrayOfGrowableXYZArray(e){const t=new Ha;return Yn.streamXYZ(e,t),t.claimArrayOfGrowableXYZArray()}push(e){this.pushXYZ(e.x,e.y,e.z)}pushAll(e){this.ensureCapacity(this._xyzInUse+e.length,!1);for(const t of e)this.push(t)}pushFrom(e){if(e instanceof y)this.pushXYZ(e.x,e.y,e.z);else if(e instanceof J)this.pushFromGrowableXYZArray(e);else if(e instanceof L)this.pushXYZ(e.x,e.y,0);else if(f.isNumberArray(e,4)||e instanceof Float64Array){const t=Math.trunc(e.length/3);this.ensureCapacity(this._xyzInUse+t,!1),this.copyData(e,t,this._xyzInUse),this._xyzInUse+=t}else if(f.isNumberArray(e,3))this.pushXYZ(e[0],e[1],e[2]);else if(f.isNumberArray(e,2))this.pushXYZ(e[0],e[1],0);else if(Array.isArray(e))for(const t of e)this.pushFrom(t);else y.isXYAndZ(e)?this.pushXYZ(e.x,e.y,e.z):y.isXAndY(e)?this.pushXYZ(e.x,e.y,0):e instanceof gt&&this.pushIndexedXYZCollection(e)}pushWrap(e){if(this._xyzInUse>=e){this.ensureCapacity(this._xyzInUse+e,!1);for(let t=0;t<e;t++){const n=3*t;this.pushXYZ(this._data[n],this._data[n+1],this._data[n+2])}}}pushXYZ(e,t,n){this.ensureCapacity(this._xyzInUse+1);const i=this._xyzInUse*3;this._data[i]=e,this._data[i+1]=t,this._data[i+2]=n,this._xyzInUse++}shiftForward(e){if(e<=0)return;this.ensureCapacity(this._xyzInUse+e);const t=3*e,n=this._xyzInUse*3;this._data.copyWithin(t,0,n),this._xyzInUse+=e}pushFrontXYZ(e,t,n){this.shiftForward(1),this._data[0]=e,this._data[1]=t,this._data[2]=n}pushFront(e){this.pushFrontXYZ(e.x,e.y,e.z)}moveIndexToIndex(e,t){if(this.isIndexValid(e)&&this.isIndexValid(t)){let n=e*3,i=t*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(e,t){const n=3*e;return y.create(this._data[n],this._data[n+1],this._data[n+2],t)}getPoint2dAtUncheckedPointIndex(e,t){const n=3*e;return L.create(this._data[n],this._data[n+1],t)}getVector3dAtUncheckedVectorIndex(e,t){const n=3*e;return v.create(this._data[n],this._data[n+1],this._data[n+2],t)}getPoint3dAtCheckedPointIndex(e,t){if(this.isIndexValid(e)){const n=3*e;return y.create(this._data[n],this._data[n+1],this._data[n+2],t)}}getXAtUncheckedPointIndex(e){const t=3*e;return this._data[t]}getYAtUncheckedPointIndex(e){const t=3*e;return this._data[t+1]}getZAtUncheckedPointIndex(e){const t=3*e;return this._data[t+2]}getPoint2dAtCheckedPointIndex(e,t){if(this.isIndexValid(e)){const n=3*e;return L.create(this._data[n],this._data[n+1],t)}}getVector3dAtCheckedVectorIndex(e,t){if(this.isIndexValid(e)){const n=3*e;return v.create(this._data[n],this._data[n+1],this._data[n+2],t)}}transferFromGrowableXYZArray(e,t,n){if(this.isIndexValid(e)&&t.isIndexValid(n)){const i=e*3;return this._data[i]=t.getXAtUncheckedPointIndex(n),this._data[i+1]=t.getYAtUncheckedPointIndex(n),this._data[i+2]=t.getZAtUncheckedPointIndex(n),!0}return!1}pushFromGrowableXYZArray(e,t){if(t===void 0){const n=e.length;return this.ensureCapacity(this.length+n,!1),this.copyData(e._data,n,this.length),this._xyzInUse+=n,n}if(e.isIndexValid(t)){const n=t*3;return this.pushXYZ(e._data[n],e._data[n+1],e._data[n+2]),1}return 0}pushIndexedXYZCollection(e){return e instanceof J?this.pushFromGrowableXYZArray(e):(this.ensureCapacity(this._xyzInUse+e.length,!1),super.pushIndexedXYZCollection(e))}setAtCheckedPointIndex(e,t){if(!this.isIndexValid(e))return!1;let n=e*3;return this._data[n++]=t.x,this._data[n++]=t.y,this._data[n]=t.z,!0}setXYZAtCheckedPointIndex(e,t,n,i){if(!this.isIndexValid(e))return!1;let s=e*3;return this._data[s++]=t,this._data[s++]=n,this._data[s]=i,!0}getPoint3dArray(){const e=3*this._xyzInUse,t=[],n=this._data;for(let i=0;i<e;i+=3)t.push(y.create(n[i],n[i+1],n[i+2]));return t}static multiplyTransformInPlace(e,t){if(Array.isArray(t))for(const n of t)n.multiplyTransformInPlace(e);else t.multiplyTransformInPlace(e)}multiplyTransformInPlace(e){const t=this._data,n=this.float64Length,i=e.matrix.coffs,s=e.origin,r=s.x,a=s.y,o=s.z;let c=0,d=0,h=0;for(let u=0;u+2<=n;u+=3)c=t[u],d=t[u+1],h=t[u+2],t[u]=i[0]*c+i[1]*d+i[2]*h+r,t[u+1]=i[3]*c+i[4]*d+i[5]*h+a,t[u+2]=i[6]*c+i[7]*d+i[8]*h+o}reverseInPlace(){const e=this.length;let t,n,i;const s=this._data;for(let r=0,a=e-1;r<a;r++,a--)t=3*r,n=3*a,i=s[t],s[t]=s[n],s[n]=i,t++,n++,i=s[t],s[t]=s[n],s[n]=i,t++,n++,i=s[t],s[t]=s[n],s[n]=i}multiplyMatrix3dInPlace(e){const t=this._data,n=this.float64Length,i=e.coffs;let s=0,r=0,a=0;for(let o=0;o+2<=n;o+=3)s=t[o],r=t[o+1],a=t[o+2],t[o]=i[0]*s+i[1]*r+i[2]*a,t[o+1]=i[3]*s+i[4]*r+i[5]*a,t[o+2]=i[6]*s+i[7]*r+i[8]*a}multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(e){const t=this._data,n=this.float64Length;if(!e.computeCachedInverse(!0))return!1;const i=e.inverseCoffs,s=f.smallFloatingPoint;let r=0,a=0,o=0,c,d,h,u,g,m=0;for(let p=0;p+2<=n;p+=3)r=t[p],a=t[p+1],o=t[p+2],c=i[0]*r+i[3]*a+i[6]*o,d=i[1]*r+i[4]*a+i[7]*o,h=i[2]*r+i[5]*a+i[8]*o,g=c*c+d*d+h*h,g<s?(c=r,d=a,h=o,m++):Math.abs(g-1)>s&&(u=1/Math.sqrt(g),c*=u,d*=u,h*=u),t[p]=c,t[p+1]=d,t[p+2]=h;return m===0}multiplyMatrix4dAndQuietRenormalizeMatrix4d(e){const t=this._data,n=this.float64Length,i=y.create();for(let s=0;s+2<=n;s+=3)e.multiplyXYZWQuietRenormalize(t[s],t[s+1],t[s+2],1,i),t[s]=i.x,t[s+1]=i.y,t[s+2]=i.z}tryTransformInverseInPlace(e){const t=this._data,n=this.float64Length,i=e.matrix;i.computeCachedInverse(!0);const s=i.inverseCoffs;if(!s)return!1;const r=e.origin,a=r.x,o=r.y,c=r.z;let d=0,h=0,u=0;for(let g=0;g+2<n;g+=3)d=t[g]-a,h=t[g+1]-o,u=t[g+2]-c,t[g]=s[0]*d+s[1]*h+s[2]*u,t[g+1]=s[3]*d+s[4]*h+s[5]*u,t[g+2]=s[6]*d+s[7]*h+s[8]*u;return!0}extendRange(e,t){const n=this.float64Length,i=this._data;if(t)for(let s=0;s+2<n;s+=3)e.extendTransformedXYZ(t,i[s],i[s+1],i[s+2]);else for(let s=0;s+2<n;s+=3)e.extendXYZ(i[s],i[s+1],i[s+2])}getRange(e,t){let n=t;return n?n.setNull():n=ie.createNull(),this.extendRange(n,e),n}setRange(e,t){e.setNull(),this.extendRange(e,t)}sumLengths(){let e=0;const t=3*(this._xyzInUse-1),n=this._data;for(let i=0;i<t;i+=3)e+=f.hypotenuseXYZ(n[i+3]-n[i],n[i+4]-n[i+1],n[i+5]-n[i+2]);return e}scaleInPlace(e){if(this._data){const t=this.float64Length;for(let n=0;n<t;n++)this._data[n]=this._data[n]*e}}isCloseToPlane(e,t=f.smallMetricDistance){const n=3*this._xyzInUse,i=this._data;for(let s=0;s<n;s+=3)if(Math.abs(e.altitudeXYZ(i[s],i[s+1],i[s+2]))>t)return!1;return!0}forceClosure(e=f.smallMetricDistance){const t=this.distanceIndexIndex(0,this.length-1);if(t!==void 0){if(t>e)this.pushXYZ(this._data[0],this._data[1],this._data[2]);else if(t>0){const n=this._data.length-3;for(let i=0;i<3;i++)this._data[n+i]=this._data[i]}}}interpolate(e,t,n,i){if(this.isIndexValid(e)&&this.isIndexValid(n)){const s=1-t,r=this._data;return e=3*e,n=3*n,y.create(s*r[e]+t*r[n],s*r[e+1]+t*r[n+1],s*r[e+2]+t*r[n+2],i)}}pushInterpolatedFromGrowableXYZArray(e,t,n,i){if(e.isIndexValid(t)&&e.isIndexValid(i)){const s=1-n,r=e._data;t=3*t,i=3*i,this.pushXYZ(s*r[t]+n*r[i],s*r[t+1]+n*r[i+1],s*r[t+2]+n*r[i+2])}}areaXY(){let e=0;const t=3*this._xyzInUse;if(t>6){const n=this._data[t-3],i=this._data[t-2];let s=this._data[0]-n,r=this._data[1]-i,a=0,o=0;for(let c=3;c<t;c+=3,s=a,r=o)a=this._data[c]-n,o=this._data[c+1]-i,e+=f.crossProductXYXY(s,r,a,o)}return .5*e}vectorIndexIndex(e,t,n){if(!(!this.isIndexValid(e)||!this.isIndexValid(t)))return this.vectorUncheckedIndexIndex(e,t,n)}vectorUncheckedIndexIndex(e,t,n){const i=this._data;return e=3*e,t=3*t,v.create(i[t]-i[e],i[t+1]-i[e+1],i[t+2]-i[e+2],n)}vectorXYAndZIndex(e,t,n){if(this.isIndexValid(t))return this.vectorXYAndZUncheckedIndex(e,t,n)}vectorXYAndZUncheckedIndex(e,t,n){const i=this._data;return t=3*t,v.create(i[t]-e.x,i[t+1]-e.y,i[t+2]-e.z,n)}crossProductIndexIndexIndex(e,t,n,i){if(this.isIndexValid(e)&&this.isIndexValid(t)&&this.isIndexValid(n))return this.crossProductUncheckedIndexIndexIndex(e,t,n,i)}crossProductUncheckedIndexIndexIndex(e,t,n,i){const s=e*3,r=t*3,a=n*3,o=this._data;return f.crossProductXYZXYZ(o[r]-o[s],o[r+1]-o[s+1],o[r+2]-o[s+2],o[a]-o[s],o[a+1]-o[s+1],o[a+2]-o[s+2],i)}crossProductUncheckedIndexIndexXYAndZ(e,t,n,i){const s=e*3,r=t*3,a=this._data;return f.crossProductXYZXYZ(a[r]-a[s],a[r+1]-a[s+1],a[r+2]-a[s+2],n.x-a[s],n.y-a[s+1],n.z-a[s+2],i)}evaluateUncheckedIndexDotProductXYZ(e,t,n,i){const s=e*3,r=this._data;return r[s]*t+r[s+1]*n+r[s+2]*i}evaluateUncheckedIndexPlaneAltitude(e,t){const n=e*3,i=this._data;return t.altitudeXYZ(i[n],i[n+1],i[n+2])}accumulateCrossProductIndexIndexIndex(e,t,n,i){if(this.isIndexValid(e)&&this.isIndexValid(t)&&this.isIndexValid(n)){const s=e*3,r=t*3,a=n*3,o=this._data;i.addCrossProductToTargetsInPlace(o[s],o[s+1],o[s+2],o[r],o[r+1],o[r+2],o[a],o[a+1],o[a+2])}}accumulateScaledXYZ(e,t,n){if(this.isIndexValid(e)){const i=e*3,s=this._data;n.x+=t*s[i],n.y+=t*s[i+1],n.z+=t*s[i+2]}}crossProductXYAndZIndexIndex(e,t,n,i){if(this.isIndexValid(t)&&this.isIndexValid(n)){const s=t*3,r=n*3,a=this._data;return f.crossProductXYZXYZ(a[s]-e.x,a[s+1]-e.y,a[s+2]-e.z,a[r]-e.x,a[r+1]-e.y,a[r+2]-e.z,i)}}distanceIndexToPoint(e,t){if(this.isIndexValid(e)){const n=3*e;return f.hypotenuseXYZ(t.x-this._data[n],t.y-this._data[n+1],t.z-this._data[n+2])}}distanceSquaredIndexIndex(e,t){if(this.isIndexValid(e)&&this.isIndexValid(t))return this.distanceSquaredUncheckedIndexIndex(e,t)}distanceSquaredUncheckedIndexIndex(e,t){const n=3*e,i=3*t;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(e,t){if(this.isIndexValid(e)&&this.isIndexValid(t))return this.distanceUncheckedIndexIndex(e,t)}distanceUncheckedIndexIndex(e,t){const n=3*e,i=3*t;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(e,t,n,i){if(e.isIndexValid(t)&&n.isIndexValid(i)){const s=3*t,r=3*i;return f.hypotenuseXYZ(n._data[r]-e._data[s],n._data[r+1]-e._data[s+1],n._data[r+2]-e._data[s+2])}}static isAlmostEqual(e,t){if(e&&t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e.getPoint3dAtUncheckedPointIndex(n).isAlmostEqual(t.getPoint3dAtUncheckedPointIndex(n)))return!1;return!0}return!e&&!t}sortIndicesLexical(){const e=this._xyzInUse,t=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n;return t.sort((n,i)=>this.compareLexicalBlock(n,i)),t}compareLexicalBlock(e,t){let n=0,i=0;for(let s=0;s<3;s++){if(n=this._data[e*3+s],i=this._data[t*3+s],n>i)return 1;if(n<i)return-1}return e-t}component(e,t){return this._data[3*e+t]}addSteppedPoints(e,t,n,i){const s=e._data;let r=t*3;const a=e.length*3;let o=0;for(this.ensureCapacity(this._xyzInUse+i,!1);r>=0&&r+2<a&&o<i;)this.pushXYZ(s[r],s[r+1],s[r+2]),r+=n*3,o++}static distanceRangeBetweenCorrespondingPoints(e,t){const n=e._data,i=t._data,s=Math.min(e.length,t.length);let r=0,a;const o=fe.createNull();for(;r<s;)a=3*r,o.extendX(f.hypotenuseXYZ(n[a]-i[a],n[a+1]-i[a+1],n[a+2]-i[a+2])),r++;return o}static removeClosure(e,t=f.smallMetricDistance){for(;e.length>1&&e.distanceUncheckedIndexIndex(0,e.length-1)<t;)e.pop()}fillLocalXYTriangleFrame(e,t,n,i){if(this.isIndexValid(e)&&this.isIndexValid(t)&&this.isIndexValid(n)){let s=e*3;const r=this._data,a=r[s++],o=r[s++],c=r[s++];s=t*3;const d=r[s++]-a,h=r[s++]-o,u=r[s++]-c;s=n*3;const g=r[s++]-a,m=r[s++]-o,p=r[s++]-c;return i=X.createRowValues(d,g,0,a,h,m,0,o,u,p,1,c,i),i.computeCachedInverse()?i:void 0}}mapComponent(e,t){const n=this._data.length;let i;for(let s=0;s+2<n;s+=3)i=t(this._data[s],this._data[s+1],this._data[s+2]),this._data[s+e]=i}mapPoint(e){const t=this._data.length;let n;for(let i=0;i+2<t;i+=3)n=e(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 Xr{startChain(e,t){}handleXYZ(e,t,n){}endChain(e,t){}}class Sc extends Xr{_x0;_y0;_z0;handleXYZ(e,t,n){this._x0!==void 0&&this._y0!==void 0&&this._z0!==void 0&&this.handleXYZXYZ(this._x0,this._y0,this._z0,e,t,n),this._x0=e,this._y0=t,this._z0=n}startChain(e,t){this._x0=this._y0=this._z0=void 0}handleXYZXYZ(e,t,n,i,s,r){}}class Ha extends Xr{_pointArrays;_currentData;startChain(e,t){this._currentData=void 0}handleXYZ(e,t,n){this._currentData||(this._currentData=new J),this._currentData.pushXYZ(e,t,n)}endChain(e,t){this._currentData!==void 0&&(this._pointArrays===void 0&&(this._pointArrays=[]),this._pointArrays.push(this._currentData),this._currentData=void 0)}claimArrayOfGrowableXYZArray(){const e=this._pointArrays;return this._pointArrays=void 0,e}}class Ac extends Xr{_range;_transform;constructor(e,t){super(),e&&(this._transform=e),t&&(this._range=t)}handleXYZ(e,t,n){this._range||(this._range=ie.createNull()),this._transform?this._range.extendTransformedXYZ(this._transform,e,t,n):this._range.extendXYZ(e,t,n)}claimResult(){const e=this._range;return this._range=void 0,e||ie.createNull()}}class Ka{_resultStack;_xyzFunction;constructor(e){this._xyzFunction=e,this._resultStack=[],this._resultStack.push([])}startChain(e,t){this._resultStack.push([])}handleXYZ(e,t,n){this._resultStack[this._resultStack.length-1].push(this._xyzFunction(e,t,n))}endChain(e,t){const n=this._resultStack[this._resultStack.length-1];this._resultStack.pop(),this._resultStack[this._resultStack.length-1].push(n)}claimResult(){const e=this._resultStack[0];return e.length===1?e[0]:e}}class Yn{static _workPoint;static streamXYZ(e,t){let n=0;if(Array.isArray(e))if(e.length>0&&y.isAnyImmediatePointType(e[0])){t.startChain(e,!0);for(const i of e){const s=y.accessX(i),r=y.accessY(i),a=y.accessZ(i,0);s!==void 0&&r!==void 0&&t.handleXYZ(s,r,a),n++}t.endChain(e,!0)}else{t.startChain(e,!1);for(const i of e)n+=this.streamXYZ(i,t);t.endChain(e,!1)}else if(e instanceof gt){t.startChain(e,!0);const i=Yn._workPoint=y.create(0,0,0,Yn._workPoint);for(let s=0;s<e.length;s++)e.getPoint3dAtCheckedPointIndex(s,i),n++,t.handleXYZ(i.x,i.y,i.z);t.endChain(e,!0)}return n}}class H{static _EXTREME_POSITIVE=1e200;static _EXTREME_NEGATIVE=-1e200;static npcScaleFactor(e,t){return t<=e?0:1/(t-e)}static isExtremeValue(e){return Math.abs(e)>=H._EXTREME_POSITIVE}static isExtremePoint3d(e){return H.isExtremeValue(e.x)||H.isExtremeValue(e.y)||H.isExtremeValue(e.z)}static isExtremePoint2d(e){return H.isExtremeValue(e.x)||H.isExtremeValue(e.y)}static rangeToRangeAbsoluteDistance(e,t,n,i){return t<e||i<n?H._EXTREME_POSITIVE:i<e?e-i:i<=t||n<=t?0:n-t}static coordinateToRangeAbsoluteDistance(e,t,n){return n<t?H._EXTREME_POSITIVE:e<t?t-e:e>n?e-n:0}static multiplyIfPositive(e,t,n=0){return e>0?t*e:n}}class ie extends H{low;high;setNull(){this.low.x=H._EXTREME_POSITIVE,this.low.y=H._EXTREME_POSITIVE,this.low.z=H._EXTREME_POSITIVE,this.high.x=H._EXTREME_NEGATIVE,this.high.y=H._EXTREME_NEGATIVE,this.high.z=H._EXTREME_NEGATIVE}freeze(){return this.low.freeze(),this.high.freeze(),Object.freeze(this)}static toFloat64Array(e){return Float64Array.of(e.low.x,e.low.y,e.low.z,e.high.x,e.high.y,e.high.z)}toFloat64Array(){return ie.toFloat64Array(this)}static fromFloat64Array(e){if(e.length!==6)throw new Error("invalid array");return new this(e[0],e[1],e[2],e[3],e[4],e[5])}static fromArrayBuffer(e){return this.fromFloat64Array(new Float64Array(e))}constructor(e=H._EXTREME_POSITIVE,t=H._EXTREME_POSITIVE,n=H._EXTREME_POSITIVE,i=H._EXTREME_NEGATIVE,s=H._EXTREME_NEGATIVE,r=H._EXTREME_NEGATIVE){super(),this.low=y.create(e,t,n),this.high=y.create(i,s,r)}isAlmostEqual(e,t){return this.low.isAlmostEqual(e.low,t)&&this.high.isAlmostEqual(e.high,t)||this.isNull&&e.isNull}setFrom(e){this.low.setFrom(e.low),this.high.setFrom(e.high)}static createFrom(e,t){return t?(t.setFrom(e),t):this.createXYZXYZOrCorrectToNull(e.low.x,e.low.y,e.low.z,e.high.x,e.high.y,e.high.z,t)}setFromJSON(e){if(!e)return;if(this.setNull(),Array.isArray(e)){const i=y.create();for(const s of e)i.setFromJSON(s),this.extendPoint(i);return}const t=y.fromJSON(e.low),n=y.fromJSON(e.high);!H.isExtremePoint3d(t)&&!H.isExtremePoint3d(n)&&(this.extendPoint(t),this.extendPoint(n))}toJSON(){return{low:this.low.toJSON(),high:this.high.toJSON()}}static fromJSON(e){const t=new this;return t.setFromJSON(e),t}setDirect(e,t,n,i,s,r,a){this.low.x=e,this.low.y=t,this.low.z=n,this.high.x=i,this.high.y=s,this.high.z=r,a&&(this.low.x>this.high.x||this.low.y>this.high.y||this.low.z>this.high.z)&&this.setNull()}clone(e){return e=e||new this.constructor,e.setDirect(this.low.x,this.low.y,this.low.z,this.high.x,this.high.y,this.high.z,!1),e}cloneTranslated(e,t){return t=t||new this.constructor,this.isNull||t.setDirect(this.low.x+e.x,this.low.y+e.y,this.low.z+e.z,this.high.x+e.x,this.high.y+e.y,this.high.z+e.z,!1),t}static createNull(e){return e=e||new this,e.setNull(),e}extend(...e){for(const t of e)this.extendPoint(t)}static create(...e){const t=ie.createNull();for(const n of e)t.extendPoint(n);return t}static createFromVariantData(e,t,n){n&&n.setNull();const i=new Ac(t,n);return Yn.streamXYZ(e,i),i.claimResult()}static createTransformed(e,...t){const n=this.createNull();for(const i of t)n.extendTransformedXYZ(e,i.x,i.y,i.z);return n}static createTransformedArray(e,t){const n=this.createNull();return n.extendArray(t,e),n}static createInverseTransformedArray(e,t){const n=this.createNull();return n.extendInverseTransformedArray(t,e),n}setXYZ(e,t,n){this.low.x=this.high.x=e,this.low.y=this.high.y=t,this.low.z=this.high.z=n}static createXYZ(e,t,n,i){return i=i||new this,i.setDirect(e,t,n,e,t,n,!1),i}static createXYZXYZ(e,t,n,i,s,r,a){return a=a||new this,a.setDirect(Math.min(e,i),Math.min(t,s),Math.min(n,r),Math.max(e,i),Math.max(t,s),Math.max(n,r),!1),a}static createXYZXYZOrCorrectToNull(e,t,n,i,s,r,a){return a=a||new this,e>i||t>s||n>r?this.createNull(a):(a.setDirect(Math.min(e,i),Math.min(t,s),Math.min(n,r),Math.max(e,i),Math.max(t,s),Math.max(n,r),!0),a)}static createRange2d(e,t=0,n){const i=n||new this;return i.setNull(),i.extendXYZ(e.low.x,e.low.y,t),i.extendXYZ(e.high.x,e.high.y,t),i}static createArray(e,t){t=t||new this,t.setNull();let n;for(n of e)t.extendPoint(n);return t}extendArray(e,t){if(Array.isArray(e))if(t)for(const n of e)this.extendTransformedXYZ(t,n.x,n.y,n.z);else for(const n of e)this.extendXYZ(n.x,n.y,n.z);else if(t)for(let n=0;n<e.length;n++)this.extendTransformedXYZ(t,e.getXAtUncheckedPointIndex(n),e.getYAtUncheckedPointIndex(n),e.getZAtUncheckedPointIndex(n));else for(let n=0;n<e.length;n++)this.extendXYZ(e.getXAtUncheckedPointIndex(n),e.getYAtUncheckedPointIndex(n),e.getZAtUncheckedPointIndex(n))}extendInverseTransformedArray(e,t){if(Array.isArray(e))for(const n of e)this.extendInverseTransformedXYZ(t,n.x,n.y,n.z);else for(let n=0;n<e.length;n++)this.extendInverseTransformedXYZ(t,e.getXAtUncheckedPointIndex(n),e.getYAtUncheckedPointIndex(n),e.getZAtUncheckedPointIndex(n))}extendTransformedXYZ(e,t,n,i){const s=e.origin,r=e.matrix.coffs;this.extendXYZ(s.x+r[0]*t+r[1]*n+r[2]*i,s.y+r[3]*t+r[4]*n+r[5]*i,s.z+r[6]*t+r[7]*n+r[8]*i)}extendTransformedXYZW(e,t,n,i,s){const r=e.origin,a=e.matrix.coffs;this.extendXYZW(r.x*s+a[0]*t+a[1]*n+a[2]*i,r.y*s+a[3]*t+a[4]*n+a[5]*i,r.z*s+a[6]*t+a[7]*n+a[8]*i,s)}extendInverseTransformedXYZ(e,t,n,i){const s=e.origin;if(!e.matrix.computeCachedInverse(!0))return!1;const r=e.matrix.inverseCoffs,a=t-s.x,o=n-s.y,c=i-s.z;return this.extendXYZ(r[0]*a+r[1]*o+r[2]*c,r[3]*a+r[4]*o+r[5]*c,r[6]*a+r[7]*o+r[8]*c),!0}extendTransformTransformedXYZ(e,t,n,i,s){const r=t.origin,a=t.matrix.coffs;this.extendTransformedXYZ(e,r.x+a[0]*n+a[1]*i+a[2]*s,r.y+a[3]*n+a[4]*i+a[5]*s,r.z+a[6]*n+a[7]*i+a[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(e){return e.high.x<e.low.x||e.high.y<e.low.y||e.high.z<e.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 e=this.high.x-this.low.x;return e>0?e:0}yLength(){const e=this.high.y-this.low.y;return e>0?e:0}zLength(){const e=this.high.z-this.low.z;return e>0?e:0}maxLength(){return Math.max(this.xLength(),this.yLength(),this.zLength())}diagonal(e){return this.low.vectorTo(this.high,e)}diagonalLength(e=!1){return e?this.low.distanceXY(this.high):this.low.distance(this.high)}diagonalLengthSquared(e=!1){return e?this.low.distanceSquaredXY(this.high):this.low.distanceSquared(this.high)}diagonalFractionToPoint(e,t){return this.low.interpolate(e,this.high,t)}fractionToPoint(e,t,n=0,i){return this.low.interpolateXYZ(e,t,n,this.high,i)}localXYZToWorld(e,t,n,i){if(!this.isNull)return this.low.interpolateXYZ(e,t,n,this.high,i)}localToWorld(e,t){return this.localXYZToWorld(e.x,e.y,e.z,t)}localToWorldArrayInPlace(e){if(this.isNull)return!1;for(const t of e)this.low.interpolateXYZ(t.x,t.y,t.z,this.high,t);return!1}worldToLocal(e,t){const n=H.npcScaleFactor(this.low.x,this.high.x),i=H.npcScaleFactor(this.low.y,this.high.y),s=H.npcScaleFactor(this.low.z,this.high.z);if(!(n===0||i===0||s===0))return y.create((e.x-this.low.x)*n,(e.y-this.low.y)*i,(e.z-this.low.z)*s,t)}worldToLocalArrayInPlace(e){const t=H.npcScaleFactor(this.low.x,this.high.x),n=H.npcScaleFactor(this.low.y,this.high.y),i=H.npcScaleFactor(this.low.z,this.high.z);if(t===0||n===0||i===0)return!1;for(const s of e)y.create((s.x-this.low.x)*t,(s.y-this.low.y)*n,(s.z-this.low.z)*i,s);return!0}corners(e){return e!==void 0&&e.length>=8?(e[0].set(this.low.x,this.low.y,this.low.z),e[1].set(this.high.x,this.low.y,this.low.z),e[2].set(this.low.x,this.high.y,this.low.z),e[3].set(this.high.x,this.high.y,this.low.z),e[4].set(this.low.x,this.low.y,this.high.z),e[5].set(this.high.x,this.low.y,this.high.z),e[6].set(this.low.x,this.high.y,this.high.z),e[7].set(this.high.x,this.high.y,this.high.z),e.length=8,e):[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(e){return e===0?[0,4,6,2]:e===1?[1,3,7,5]:e===2?[0,1,5,4]:e===3?[3,2,6,7]:e===4?[0,2,3,1]:[4,5,7,6]}rectangleXY(e=0,t=!0,n=!0){if(this.isNull)return;const i=[this.fractionToPoint(0,0,e),this.fractionToPoint(1,0,e),this.fractionToPoint(1,1,e),this.fractionToPoint(0,1,e)];return n&&i.push(i[0].clone()),t||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(e,t,n){return e>=this.low.x&&t>=this.low.y&&n>=this.low.z&&e<=this.high.x&&t<=this.high.y&&n<=this.high.z}containsXY(e,t){return e>=this.low.x&&t>=this.low.y&&e<=this.high.x&&t<=this.high.y}containsPoint(e){return this.containsXYZ(e.x,e.y,e.z)}containsPointXY(e){return e.x>=this.low.x&&e.y>=this.low.y&&e.x<=this.high.x&&e.y<=this.high.y}containsRange(e){return e.low.x>=this.low.x&&e.low.y>=this.low.y&&e.low.z>=this.low.z&&e.high.x<=this.high.x&&e.high.y<=this.high.y&&e.high.z<=this.high.z}intersectsRange(e,t){return t?!(this.low.x>e.high.x+t||this.low.y>e.high.y+t||this.low.z>e.high.z+t||e.low.x>this.high.x+t||e.low.y>this.high.y+t||e.low.z>this.high.z+t):!(this.low.x>e.high.x||this.low.y>e.high.y||this.low.z>e.high.z||e.low.x>this.high.x||e.low.y>this.high.y||e.low.z>this.high.z)}intersectsRangeXY(e,t){return t?!(this.low.x>e.high.x+t||this.low.y>e.high.y+t||e.low.x>this.high.x+t||e.low.y>this.high.y+t):!(this.low.x>e.high.x||this.low.y>e.high.y||e.low.x>this.high.x||e.low.y>this.high.y)}distanceToPoint(e){return this.isNull?H._EXTREME_POSITIVE:Math.min(f.hypotenuseXYZ(H.coordinateToRangeAbsoluteDistance(e.x,this.low.x,this.high.x),H.coordinateToRangeAbsoluteDistance(e.y,this.low.y,this.high.y),H.coordinateToRangeAbsoluteDistance(e.z,this.low.z,this.high.z)),H._EXTREME_POSITIVE)}distanceToPointXY(e){return this.isNull?H._EXTREME_POSITIVE:Math.min(f.hypotenuseXY(H.coordinateToRangeAbsoluteDistance(e.x,this.low.x,this.high.x),H.coordinateToRangeAbsoluteDistance(e.y,this.low.y,this.high.y)),H._EXTREME_POSITIVE)}distanceToRange(e){return Math.min(f.hypotenuseXYZ(H.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,e.low.x,e.high.x),H.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,e.low.y,e.high.y),H.rangeToRangeAbsoluteDistance(this.low.z,this.high.z,e.low.z,e.high.z)),H._EXTREME_POSITIVE)}distanceToRangeXY(e){return Math.min(f.hypotenuseXY(H.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,e.low.x,e.high.x),H.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,e.low.y,e.high.y)),H._EXTREME_POSITIVE)}extendXYZ(e,t,n){e<this.low.x&&(this.low.x=e),e>this.high.x&&(this.high.x=e),t<this.low.y&&(this.low.y=t),t>this.high.y&&(this.high.y=t),n<this.low.z&&(this.low.z=n),n>this.high.z&&(this.high.z=n)}extendInterpolated(e,t,n){if(t<.5)this.extendXYZ(e.x+t*(n.x-e.x),e.y+t*(n.y-e.y),e.z+t*(n.z-e.z));else{const i=1-t;this.extendXYZ(n.x+i*(e.x-n.x),n.y+i*(e.y-n.y),n.z+i*(e.z-n.z))}}extendXOnly(e){e<this.low.x&&(this.low.x=e),e>this.high.x&&(this.high.x=e)}extendYOnly(e){e<this.low.y&&(this.low.y=e),e>this.high.y&&(this.high.y=e)}extendZOnly(e){e<this.low.z&&(this.low.z=e),e>this.high.z&&(this.high.z=e)}extendSingleAxis(e,t){t===Jt.X&&this.extendXOnly(e),t===Jt.Y&&this.extendYOnly(e),t===Jt.Z&&this.extendZOnly(e)}extendXYZW(e,t,n,i){f.isSmallMetricDistance(i)||this.extendXYZ(e/i,t/i,n/i)}extendPoint(e,t){t?this.extendTransformedXYZ(t,e.x,e.y,e.z):this.extendXYZ(e.x,e.y,e.z)}extendTransformedPoint(e,t){this.extendTransformedXYZ(e,t.x,t.y,t.z)}extendRange(e){ie.isNull(e)||(this.extendXYZ(e.low.x,e.low.y,e.low.z),this.extendXYZ(e.high.x,e.high.y,e.high.z))}extendWhenLarger(e,t){!ie.isNull(e)&&!ie.isNull(this)&&(this.high.x+=H.multiplyIfPositive(this.high.x-e.high.x,t),this.high.y+=H.multiplyIfPositive(this.high.y-e.high.y,t),this.high.z+=H.multiplyIfPositive(this.high.z-e.high.z,t),this.low.x-=H.multiplyIfPositive(e.low.x-this.low.x,t),this.low.y-=H.multiplyIfPositive(e.low.y-this.low.y,t),this.low.z-=H.multiplyIfPositive(e.low.z-this.low.z,t))}intersect(e,t){return this.intersectsRange(e)?ie.createXYZXYZOrCorrectToNull(Math.max(this.low.x,e.low.x),Math.max(this.low.y,e.low.y),Math.max(this.low.z,e.low.z),Math.min(this.high.x,e.high.x),Math.min(this.high.y,e.high.y),Math.min(this.high.z,e.high.z),t):ie.createNull(t)}union(e,t){return this.isNull?e.clone(t):e.isNull?this.clone(t):ie.createXYZXYZOrCorrectToNull(Math.min(this.low.x,e.low.x),Math.min(this.low.y,e.low.y),Math.min(this.low.z,e.low.z),Math.max(this.high.x,e.high.x),Math.max(this.high.y,e.high.y),Math.max(this.high.z,e.high.z),t)}scaleAboutCenterInPlace(e){if(!this.isNull){e=Math.abs(e);const t=.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(t,e,this.high.x),this.high.y=f.interpolate(n,e,this.high.y),this.high.z=f.interpolate(i,e,this.high.z),this.low.x=f.interpolate(t,e,this.low.x),this.low.y=f.interpolate(n,e,this.low.y),this.low.z=f.interpolate(i,e,this.low.z)}}expandInPlace(e){this.setDirect(this.low.x-e,this.low.y-e,this.low.z-e,this.high.x+e,this.high.y+e,this.high.z+e,!0)}getLocalToWorldTransform(e){return X.createOriginAndMatrix(y.create(this.low.x,this.low.y,this.low.z),E.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),e)}getNpcToWorldRangeTransform(e){const t=this.getLocalToWorldTransform(e),n=t.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),t}ensureMinLengths(e=.001){let t=(e-this.xLength())/2;t>0&&(this.low.x-=t,this.high.x+=t),t=(e-this.yLength())/2,t>0&&(this.low.y-=t,this.high.y+=t),t=(e-this.zLength())/2,t>0&&(this.low.z-=t,this.high.z+=t)}}class fe extends H{low;high;setNull(){this.low=H._EXTREME_POSITIVE,this.high=H._EXTREME_NEGATIVE}setDirect(e,t,n=!1){this.low=e,this.high=t,n&&e>t&&this.setNull()}constructor(e=H._EXTREME_POSITIVE,t=H._EXTREME_NEGATIVE){super(),this.low=e,this.high=t,this.setDirect(e,t)}isAlmostEqual(e){return f.isSameCoordinate(this.low,e.low)&&f.isSameCoordinate(this.high,e.high)||this.isNull&&e.isNull}setFrom(e){this.low=e.low,this.high=e.high}setFromJSON(e){if(this.setNull(),Array.isArray(e)){let t;for(t of e)Number.isFinite(t)&&this.extendX(t)}else e.low!==void 0&&Number.isFinite(e.low)&&e.high!==void 0&&Number.isFinite(e.high)&&(this.extendX(e.low),this.extendX(e.high))}static fromJSON(e){const t=new this;return e&&t.setFromJSON(e),t}toJSON(){return this.isNull?new Array:[this.low,this.high]}clone(e){return e=e||new this.constructor,e.setDirect(this.low,this.high),e}static createFrom(e,t){return t=t||new this,t.setDirect(e.low,e.high),t}static createNull(e){return e=e||new this,e.setNull(),e}cloneTranslated(e,t){return t=t||this.clone(),t.isNull||(t.low+=e,t.high+=e),t}setX(e){this.low=this.high=e}static createX(e,t){return t=t||new this,t.setDirect(e,e),t}setXXUnordered(e,t){e<=t?(this.low=e,this.high=t):(this.low=t,this.high=e)}get isExact01(){return this.low===0&&this.high===1}static createXX(e,t,n){return n=n||new this,n.setDirect(Math.min(e,t),Math.max(e,t)),n}static createXXOrCorrectToNull(e,t,n){return t<e?fe.createNull(n):(n=n||new this,n.setDirect(Math.min(e,t),Math.max(e,t)),n)}static createArray(e,t){t=t||new this;let n;for(n of e)t.extendX(n);return t}extendArray(e){let t;for(t of e)this.extendX(t)}extendArraySubset(e,t,n){const i=t+n;for(let s=t;s<i;s++)this.extendX(e[s])}get isNull(){return this.high<this.low}get isSinglePoint(){return this.high===this.low}length(){const e=this.high-this.low;return e>0?e:0}fractionToPoint(e){return f.interpolate(this.low,e,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(e){return e>=this.low&&e<=this.high}containsXOpen(e){return e>this.low&&e<this.high}containsRange(e){return e.low>=this.low&&e.high<=this.high}intersectsRange(e){return!(this.low>e.high||e.low>this.high)}intersectRangeXXInPlace(e,t){t<e||t<this.low||e>this.high?this.setNull():(t<this.high&&(this.high=t),e>this.low&&(this.low=e))}distanceToRange(e){return H.rangeToRangeAbsoluteDistance(this.low,this.high,e.low,e.high)}distanceToX(e){return this.isNull?H._EXTREME_POSITIVE:H.coordinateToRangeAbsoluteDistance(e,this.low,this.high)}extendX(e){e<this.low&&(this.low=e),e>this.high&&(this.high=e)}extendRange(e){e.isNull||(this.extendX(e.low),this.extendX(e.high))}extendLow(e){return this.isNull||e<this.low?(this.low=e,!0):!1}extendHigh(e){return this.isNull||e>this.high?(this.high=e,!0):!1}intersect(e,t){return this.intersectsRange(e)?fe.createXXOrCorrectToNull(Math.max(this.low,e.low),Math.min(this.high,e.high),t):fe.createNull(t)}union(e,t){return fe.createXX(Math.min(this.low,e.low),Math.max(this.high,e.high),t)}scaleAboutCenterInPlace(e){if(!this.isNull){e=Math.abs(e);const t=.5*(this.low+this.high);this.high=f.interpolate(t,e,this.high),this.low=f.interpolate(t,e,this.low)}}expandInPlace(e){this.setDirect(this.low-e,this.high+e,!0)}clipLinearMapToInterval(e,t,n,i){if(i<n||this.high<this.low)return!1;const s=f.conditionalDivideFraction(n-e,t),r=f.conditionalDivideFraction(i-e,t);return s===void 0||r===void 0?n<=e&&e<=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 ze extends H{low;high;setNull(){this.low.x=H._EXTREME_POSITIVE,this.low.y=H._EXTREME_POSITIVE,this.high.x=H._EXTREME_NEGATIVE,this.high.y=H._EXTREME_NEGATIVE}static toFloat64Array(e){return Float64Array.of(e.low.x,e.low.y,e.high.x,e.high.y)}toFloat64Array(){return ze.toFloat64Array(this)}static fromFloat64Array(e){if(e.length!==4)throw new Error("invalid array");return new this(e[0],e[1],e[2],e[3])}static fromArrayBuffer(e){return this.fromFloat64Array(new Float64Array(e))}constructor(e=ze._EXTREME_POSITIVE,t=ze._EXTREME_POSITIVE,n=ze._EXTREME_NEGATIVE,i=ze._EXTREME_NEGATIVE){super(),this.low=L.create(e,t),this.high=L.create(n,i)}isAlmostEqual(e){return this.low.isAlmostEqual(e.low)&&this.high.isAlmostEqual(e.high)||this.isNull&&e.isNull}setFrom(e){this.low.set(e.low.x,e.low.y),this.high.set(e.high.x,e.high.y)}static createFrom(e,t){return t?(t.setFrom(e),t):this.createXYXYOrCorrectToNull(e.low.x,e.low.y,e.high.x,e.high.y,t)}setFromJSON(e){if(this.setNull(),Array.isArray(e)){const i=L.create();for(const s of e)i.setFromJSON(s),this.extendPoint(i);return}const t=L.fromJSON(e.low),n=L.fromJSON(e.high);!H.isExtremePoint2d(t)&&!H.isExtremePoint2d(n)&&(this.extendPoint(t),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(e){const t=new this;return e&&t.setFromJSON(e),t}setDirect(e,t,n,i,s){this.low.x=e,this.low.y=t,this.high.x=n,this.high.y=i,s&&(this.low.x>this.high.x||this.low.y>this.high.y)&&this.setNull()}clone(e){return e=e||new this.constructor,e.setDirect(this.low.x,this.low.y,this.high.x,this.high.y,!1),e}cloneTranslated(e,t){return t=t||new this.constructor,this.isNull||t.setDirect(this.low.x+e.x,this.low.y+e.y,this.high.x+e.x,this.high.y+e.y,!1),t}static createNull(e){return e=e||new this,e.setNull(),e}setXY(e,t){this.low.x=this.high.x=e,this.low.y=this.high.y=t}static createXY(e,t,n){return n=n||new this,n.setDirect(e,t,e,t,!1),n}static createXYXY(e,t,n,i,s){return s=s||new this,s.setDirect(Math.min(e,n),Math.min(t,i),Math.max(e,n),Math.max(t,i),!1),s}static createXYXYXY(e,t,n,i,s,r,a){return a=a||new this,a.setDirect(Math.min(e,n,s),Math.min(t,i,r),Math.max(e,n,s),Math.max(t,i,r),!1),a}static createXYXYOrCorrectToNull(e,t,n,i,s){return e>n||t>i?this.createNull(s):(s=s||new this,s.setDirect(Math.min(e,n),Math.min(t,i),Math.max(e,n),Math.max(t,i),!0),s)}static createArray(e,t){t=t||new this;let n;for(n of e)t.extendPoint(n);return t}get isNull(){return this.high.x<this.low.x||this.high.y<this.low.y}static isNull(e){return e.high.x<e.low.x||e.high.y<e.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 e=this.high.x-this.low.x;return e>0?e:0}yLength(){const e=this.high.y-this.low.y;return e>0?e:0}diagonal(e){return this.low.vectorTo(this.high,e)}diagonalLength(){return this.low.distance(this.high)}diagonalLengthSquared(){return this.low.distanceSquared(this.high)}diagonalFractionToPoint(e,t){return this.low.interpolate(e,this.high,t)}fractionToPoint(e,t,n){return this.low.interpolateXY(e,t,this.high,n)}corners3d(e=!1,t=0){return e?[y.create(this.low.x,this.low.y,t),y.create(this.high.x,this.low.y,t),y.create(this.high.x,this.high.y,t),y.create(this.low.x,this.high.y,t),y.create(this.low.x,this.low.y,t)]:[y.create(this.low.x,this.low.y,t),y.create(this.high.x,this.low.y,t),y.create(this.low.x,this.high.y,t),y.create(this.high.x,this.high.y,t)]}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(e,t){return e>=this.low.x&&t>=this.low.y&&e<=this.high.x&&t<=this.high.y}containsPoint(e){return this.containsXY(e.x,e.y)}containsRange(e){return e.low.x>=this.low.x&&e.low.y>=this.low.y&&e.high.x<=this.high.x&&e.high.y<=this.high.y}intersectsRange(e){return!(this.low.x>e.high.x||this.low.y>e.high.y||e.low.x>this.high.x||e.low.y>this.high.y)}distanceToPoint(e){return this.isNull?ze._EXTREME_POSITIVE:Math.min(f.hypotenuseXY(H.coordinateToRangeAbsoluteDistance(e.x,this.low.x,this.high.x),H.coordinateToRangeAbsoluteDistance(e.y,this.low.y,this.high.y)),ze._EXTREME_POSITIVE)}distanceToRange(e){return Math.min(f.hypotenuseXY(H.rangeToRangeAbsoluteDistance(this.low.x,this.high.x,e.low.x,e.high.x),H.rangeToRangeAbsoluteDistance(this.low.y,this.high.y,e.low.y,e.high.y)),ze._EXTREME_POSITIVE)}extendXY(e,t){e<this.low.x&&(this.low.x=e),e>this.high.x&&(this.high.x=e),t<this.low.y&&(this.low.y=t),t>this.high.y&&(this.high.y=t)}extendTransformedXY(e,t,n){const i=e.multiplyComponentXYZ(0,t,n,0),s=e.multiplyComponentXYZ(1,t,n,0);this.extendXY(i,s)}extendPoint(e){this.extendXY(e.x,e.y)}extendRange(e){ze.isNull(e)||(this.extendXY(e.low.x,e.low.y),this.extendXY(e.high.x,e.high.y))}intersect(e,t){return this.intersectsRange(e)?ze.createXYXY(Math.max(this.low.x,e.low.x),Math.max(this.low.y,e.low.y),Math.min(this.high.x,e.high.x),Math.min(this.high.y,e.high.y),t):ze.createNull(t)}union(e,t){return this.isNull?ze.createFrom(e,t):ze.isNull(e)?this.clone(t):ze.createXYXY(Math.min(this.low.x,e.low.x),Math.min(this.low.y,e.low.y),Math.max(this.high.x,e.high.x),Math.max(this.high.y,e.high.y),t)}scaleAboutCenterInPlace(e){if(!this.isNull){e=Math.abs(e);const t=.5*(this.low.x+this.high.x),n=.5*(this.low.y+this.high.y);this.high.x=f.interpolate(t,e,this.high.x),this.high.y=f.interpolate(n,e,this.high.y),this.low.x=f.interpolate(t,e,this.low.x),this.low.y=f.interpolate(n,e,this.low.y)}}expandInPlace(e){this.setDirect(this.low.x-e,this.low.y-e,this.high.x+e,this.high.y+e,!0)}worldToLocal(e,t){const n=H.npcScaleFactor(this.low.x,this.high.x),i=H.npcScaleFactor(this.low.y,this.high.y);if(!(n===0||i===0))return L.create((e.x-this.low.x)*n,(e.y-this.low.y)*i,t)}}class X{_origin;_matrix;constructor(e,t){this._origin=e,this._matrix=t}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(e){this._origin.setFrom(e._origin),this._matrix.setFrom(e._matrix)}setIdentity(){this._origin.setZero(),this._matrix.setIdentity()}setFromJSON(e){if(e){if(e instanceof Object&&e.origin&&e.matrix){this._origin.setFromJSON(e.origin),this._matrix.setFromJSON(e.matrix);return}if(f.isArrayOfNumberArray(e,3,4)){this._matrix.setRowValues(e[0][0],e[0][1],e[0][2],e[1][0],e[1][1],e[1][2],e[2][0],e[2][1],e[2][2]),this._origin.set(e[0][3],e[1][3],e[2][3]);return}if(f.isNumberArray(e,12)){this._matrix.setRowValues(e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]),this._origin.set(e[3],e[7],e[11]);return}}this.setIdentity()}isAlmostEqual(e){return this===e||this.origin.isAlmostEqual(e.origin)&&this.matrix.isAlmostEqual(e.matrix)}isAlmostEqualAllowZRotation(e){return this._origin.isAlmostEqual(e._origin)&&this._matrix.isAlmostEqualAllowZRotation(e._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(e){const t=X.createIdentity();return t.setFromJSON(e),t}clone(e){return e?(e._matrix.setFrom(this._matrix),e._origin.setFrom(this._origin),e):new X(y.createFrom(this._origin),this._matrix.clone())}cloneRigid(e=ve.XYZ){const t=E.createRigidFromMatrix3d(this.matrix,e);if(t)return new X(this.origin.cloneAsPoint3d(),t)}static createRefs(e,t,n){return e||(e=y.createZero()),n?(n._origin=e,n._matrix=t,n):new X(e,t)}static createRowValues(e,t,n,i,s,r,a,o,c,d,h,u,g){return g?(g._origin.set(i,o,u),g._matrix.setRowValues(e,t,n,s,r,a,c,d,h),g):new X(y.create(i,o,u),E.createRowValues(e,t,n,s,r,a,c,d,h))}static createZero(e){return X.createRowValues(0,0,0,0,0,0,0,0,0,0,0,0,e)}static createTranslationXYZ(e=0,t=0,n=0,i){return X.createRefs(v.create(e,t,n),E.createIdentity(),i)}static createTranslation(e,t){return X.createRefs(e,E.createIdentity(),t)}get matrix(){return this._matrix}get origin(){return this._origin}getOrigin(){return y.createFrom(this._origin)}getTranslation(){return v.createFrom(this._origin)}getMatrix(){return this._matrix.clone()}get isIdentity(){return this._matrix.isIdentity&&this._origin.isAlmostZero}static createIdentity(e){return e?(e._origin.setZero(),e._matrix.setIdentity(),e):X.createRefs(y.createZero(),E.createIdentity())}static createOriginAndMatrix(e,t,n){return n?(n._origin.setFromPoint3d(e),n._matrix.setFrom(t),n):X.createRefs(e?e.cloneAsPoint3d():y.createZero(),t===void 0?E.createIdentity():t.clone(),n)}setOriginAndMatrixColumns(e,t,n,i){e!==void 0&&this._origin.setFrom(e),this._matrix.setColumns(t,n,i)}static createOriginAndMatrixColumns(e,t,n,i,s){return s?s.setOriginAndMatrixColumns(e,t,n,i):s=X.createRefs(v.createFrom(e),E.createColumns(t,n,i)),s}static createRigidFromOriginAndColumns(e,t,n,i,s){const r=E.createRigidFromColumns(t,n,i,s?._matrix);if(r)return s?(s._origin.setFrom(e),s):X.createRefs(e?.cloneAsPoint3d(),r)}static createRigidFromOriginAndVector(e,t,n=ve.ZXY,i){const s=E.createRigidHeadsUp(t,n,i?._matrix);if(s)return i?(i._origin.setFrom(e),i):X.createRefs(e?.cloneAsPoint3d(),s)}static createFixedPointAndMatrix(e,t,n){if(e){const i=E.xyzMinusMatrixTimesXYZ(e,t,e);return X.createRefs(i,t.clone(),n)}return X.createRefs(void 0,t.clone())}static createMatrixPickupPutdown(e,t,n,i){const s=E.xyzMinusMatrixTimesXYZ(n,e,t);return X.createRefs(s,e.clone(),i)}static createScaleAboutPoint(e,t,n){const i=E.createScale(t,t,t),s=E.xyzMinusMatrixTimesXYZ(e,i,e);return X.createRefs(s,i,n)}static createFlattenAlongVectorToPlane(e,t,n){const i=E.createFlattenAlongVectorToPlane(e,n);if(i!==void 0)return X.createFixedPointAndMatrix(t,i)}multiplyPoint2d(e,t){return E.xyPlusMatrixTimesXY(this._origin,this._matrix,e,t)}multiplyPoint3d(e,t){return E.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,e,t)}multiplyXYAndZInPlace(e){return E.xyzPlusMatrixTimesXYZInPlace(this._origin,this._matrix,e)}multiplyXYZ(e,t,n=0,i){return E.xyzPlusMatrixTimesCoordinates(this._origin,this._matrix,e,t,n,i)}multiplyComponentXYZ(e,t,n,i=0){const s=this._matrix.coffs,r=3*e;return this.origin.at(e)+s[r]*t+s[r+1]*n+s[r+2]*i}multiplyComponentXYZW(e,t,n,i,s){const r=this._matrix.coffs,a=3*e;return this.origin.at(e)*s+r[a]*t+r[a+1]*n+r[a+2]*i}multiplyXYZW(e,t,n,i,s){return E.xyzPlusMatrixTimesWeightedCoordinates(this._origin,this._matrix,e,t,n,i,s)}multiplyXYZWToFloat64Array(e,t,n,i,s){return E.xyzPlusMatrixTimesWeightedCoordinatesToFloat64Array(this._origin,this._matrix,e,t,n,i,s)}multiplyXYZToFloat64Array(e,t,n,i){return E.xyzPlusMatrixTimesCoordinatesToFloat64Array(this._origin,this._matrix,e,t,n,i)}multiplyTransposeXYZW(e,t,n,i,s){const r=this._matrix.coffs,a=this._origin;return Z.create(e*r[0]+t*r[3]+n*r[6],e*r[1]+t*r[4]+n*r[7],e*r[2]+t*r[5]+n*r[8],e*a.x+t*a.y+n*a.z+i,s)}multiplyPoint3dArrayInPlace(e){let t;for(t of e)E.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,t,t)}multiplyPoint3dArrayArrayInPlace(e){for(const t of e)this.multiplyPoint3dArrayInPlace(t)}multiplyInversePoint3d(e,t){return this._matrix.multiplyInverseXYZAsPoint3d(e.x-this._origin.x,e.y-this._origin.y,e.z-this._origin.z,t)}multiplyInversePoint3dAsPoint2d(e,t){return this._matrix.multiplyInverseXYZAsPoint2d(e.x-this._origin.x,e.y-this._origin.y,e.z-this._origin.z,t)}multiplyInversePoint4d(e,t){const n=e.w;return this._matrix.multiplyInverseXYZW(e.x-n*this.origin.x,e.y-n*this.origin.y,e.z-n*this.origin.z,n,t)}multiplyInverseXYZ(e,t,n,i){return this._matrix.multiplyInverseXYZAsPoint3d(e-this._origin.x,t-this._origin.y,n-this._origin.z,i)}computeCachedInverse(e=!0){return this._matrix.computeCachedInverse(e)}static matchArrayLengths(e,t,n){const i=e.length,s=t.length;if(i>s)for(let r=s;r<i;r++)t.push(n());else s>i&&(t.length=i);return i}multiplyInversePoint3dArray(e,t){if(!this._matrix.computeCachedInverse(!0))return;const n=this.origin.x,i=this.origin.y,s=this.origin.z;t||(t=[]);const r=X.matchArrayLengths(e,t,()=>y.createZero());for(let a=0;a<r;a++)this._matrix.multiplyInverseXYZAsPoint3d(e[a].x-n,e[a].y-i,e[a].z-s,t[a]);return t}multiplyInversePoint3dArrayInPlace(e){if(!this._matrix.computeCachedInverse(!0))return!1;for(const t of e)this._matrix.multiplyInverseXYZAsPoint3d(t.x-this.origin.x,t.y-this.origin.y,t.z-this.origin.z,t);return!0}multiplyPoint2dArray(e,t){if(t){const n=X.matchArrayLengths(e,t,()=>L.createZero());for(let i=0;i<n;i++)E.xyPlusMatrixTimesXY(this._origin,this._matrix,e[i],t[i]);return t}t=[];for(const n of e)t.push(E.xyPlusMatrixTimesXY(this._origin,this._matrix,n));return t}multiplyPoint3dArray(e,t){if(t){const n=X.matchArrayLengths(e,t,()=>y.createZero());for(let i=0;i<n;i++)E.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,e[i],t[i]);return t}t=[];for(const n of e)t.push(E.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,n));return t}multiplyVector(e,t){return this._matrix.multiplyVector(e,t)}multiplyVectorInPlace(e){this._matrix.multiplyVectorInPlace(e)}multiplyVectorXYZ(e,t,n,i){return this._matrix.multiplyXYZ(e,t,n,i)}setMultiplyTransformTransform(e,t){E.xyzPlusMatrixTimesXYZ(e._origin,e._matrix,t._origin,this._origin),e._matrix.multiplyMatrixMatrix(t._matrix,this._matrix)}multiplyTransformTransform(e,t){return t?(t.setMultiplyTransformTransform(this,e),t):X.createRefs(E.xyzPlusMatrixTimesXYZ(this._origin,this._matrix,e._origin),this._matrix.multiplyMatrixMatrix(e._matrix))}multiplyTransformMatrix3d(e,t){return t?(this._matrix.multiplyMatrixMatrix(e,t._matrix),t._origin.setFrom(this._origin),t):X.createRefs(this._origin.cloneAsPoint3d(),this._matrix.multiplyMatrixMatrix(e))}multiplyRange(e,t){if(e.isNull)return e.clone(t);const n=e.low.x,i=e.low.y,s=e.low.z,r=e.high.x,a=e.high.y,o=e.high.z;return t=ie.createNull(t),t.extendTransformedXYZ(this,n,i,s),t.extendTransformedXYZ(this,r,i,s),t.extendTransformedXYZ(this,n,a,s),t.extendTransformedXYZ(this,r,a,s),t.extendTransformedXYZ(this,n,i,o),t.extendTransformedXYZ(this,r,i,o),t.extendTransformedXYZ(this,n,a,o),t.extendTransformedXYZ(this,r,a,o),t}inverse(e){const t=this._matrix.inverse(e?e._matrix:void 0);if(t)return e?(t.multiplyXYZ(-this._origin.x,-this._origin.y,-this._origin.z,e._origin),e):X.createRefs(t.multiplyXYZ(-this._origin.x,-this._origin.y,-this._origin.z),t)}static initFromRange(e,t,n,i){const s=t.minus(e);s.x===0&&(s.x=1),s.y===0&&(s.y=1),s.z===0&&(s.z=1);const r=new E;if(n&&(E.createScale(s.x,s.y,s.z,r),X.createOriginAndMatrix(e,r,n)),i){const a=new y(-e.x/s.x,-e.y/s.y,-e.z/s.z);E.createScale(1/s.x,1/s.y,1/s.z,r),X.createOriginAndMatrix(a,r,i)}}}class pe extends ks{_origin;_normal;constructor(e,t){super(),this._origin=e,this._normal=t}static _create(e,t,n,i,s,r){return new pe(y.create(e,t,n),v.create(i,s,r))}static createXYPlane(e){return e?pe._create(e.x,e.y,e.z,0,0,1):pe._create(0,0,0,0,0,1)}static createYZPlane(e){return e?pe._create(e.x,e.y,e.z,1,0,0):pe._create(0,0,0,1,0,0)}static createZXPlane(e){return e?pe._create(e.x,e.y,e.z,0,1,0):pe._create(0,0,0,0,1,0)}static create(e,t,n){if(n)return t.normalize(n._normal)===void 0?void 0:(e.clone(n._origin),n);const i=t.normalize();if(i!==void 0)return new pe(e.clone(),i)}static createFrom(e,t){if(e instanceof pe)return e.clone(t);if(t)return e.getUnitNormal(t._normal)===void 0?void 0:(e.getAnyPointOnPlane(t._origin),t);const n=e.getUnitNormal();if(n===void 0)return;const i=e.getAnyPointOnPlane();return new pe(i,n)}static createXYZUVW(e,t,n,i,s,r,a){const o=f.hypotenuseXYZ(i,s,r);if(!(o<=f.smallFraction))return a?(a._origin.set(e,t,n),a._normal.set(i/o,s/o,r/o),a):new pe(y.create(e,t,n),v.create(i/o,s/o,r/o))}static createOriginAndTargetXY(e,t,n){const i=t.x-e.x,s=t.y-e.y;return this.createXYZUVW(e.x,e.y,0,s,-i,0,n)}static createXYAngle(e,t,n,i){return i?(i._origin.set(e,t,0),i._normal.set(n.cos(),n.sin(),0),i):new pe(y.create(e,t,0),v.create(n.cos(),n.sin()))}static createPointPointVectorInPlane(e,t,n){const i=n.crossProductStartEnd(e,t);if(i.tryNormalizeInPlace())return new pe(e,i)}static createOriginAndTargets(e,t,n){const i=e.crossProductToPoints(t,n);if(i.tryNormalizeInPlace())return new pe(e,i)}static createOriginAndVectors(e,t,n){const i=t.crossProduct(n);if(i.tryNormalizeInPlace())return new pe(e,i)}isAlmostEqual(e){return this._origin.isAlmostEqual(e._origin)&&this._normal.isAlmostEqual(e._normal)}setFromJSON(e){e?(this._origin.setFromJSON(e.origin),this._normal.setFromJSON(e.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(e){const t=pe.createXYPlane();return t.setFromJSON(e),t}getOriginRef(){return this._origin}getNormalRef(){return this._normal}getLocalToWorld(){const e=E.createRigidHeadsUp(this._normal,ve.ZXY);return X.createRefs(this._origin.clone(),e)}getProjectionToPlane(){const e=E.createIdentity();return e.addScaledOuterProductInPlace(this._normal,this._normal,-1),e.markSingular(),X.createFixedPointAndMatrix(this._origin,e)}set(e,t){this._origin.setFrom(e),this._normal.setFrom(t)}clone(e){return e?(e.set(this._origin,this._normal),e):new pe(this._origin.clone(),this._normal.clone())}cloneTransformed(e,t=!1){const n=this.clone();if(t){if(e.multiplyInversePoint3d(n._origin,n._origin),e.matrix.multiplyTransposeVector(n._normal,n._normal)!==void 0&&n._normal.normalizeInPlace())return n}else if(e.multiplyPoint3d(n._origin,n._origin),e.matrix.multiplyInverseTranspose(n._normal,n._normal)!==void 0&&n._normal.normalizeInPlace())return n}setFrom(e){this.set(e._origin,e._normal)}altitude(e){return this._normal.dotProductStartEnd(this._origin,e)}altitudeXY(e,t){return(e-this._origin.x)*this._normal.x+(t-this._origin.y)*this._normal.y}normalX(){return this._normal.x}normalY(){return this._normal.y}normalZ(){return this._normal.z}getUnitNormal(e){return this._normal.clone(e)}getAnyPointOnPlane(e){return this._origin.clone(e)}weightedAltitude(e){return this._normal.dotProductStart3dEnd4d(this._origin,e)}altitudeToPoint(e,t){return this._origin.plusScaled(this._normal,e,t)}velocityXYZ(e,t,n){return this._normal.dotProductXYZ(e,t,n)}velocity(e){return this._normal.dotProduct(e)}altitudeXYZ(e,t,n){return this._normal.dotProductStartEndXYZ(this._origin,e,t,n)}altitudeXYZW(e,t,n,i){return this._normal.dotProductStartEndXYZW(this._origin,e,t,n,i)}projectPointToPlane(e,t){return this.projectXYZToPlane(e.x,e.y,e.z,t)}projectXYZToPlane(e,t,n,i){const s=-this._normal.dotProductStartEndXYZ(this._origin,e,t,n);return y.create(e+s*this._normal.x,t+s*this._normal.y,n+s*this._normal.z,i)}isPointInPlane(e,t=f.smallMetricDistance){const n=this._normal.dotProductStartEnd(this._origin,e);return Math.abs(n)<=t}}var Fe;(function(l){l[l.isolated=0]="isolated",l[l.isolatedAtVertex=1]="isolatedAtVertex",l[l.intervalStart=10]="intervalStart",l[l.intervalInterior=11]="intervalInterior",l[l.intervalEnd=12]="intervalEnd"})(Fe||(Fe={}));var Yt;(function(l){l[l.error=0]="error",l[l.success=1]="success",l[l.stoppedAtBoundary=2]="stoppedAtBoundary"})(Yt||(Yt={}));function Rs(l,e){return l?l.clone(e):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(e){this.intervalRole=e}captureFractionPoint(e,t){this.fraction=e,this.point=t}captureFraction1Point1(e,t){this.fraction1=e,this.point1=t}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===Fe.isolated||this.intervalRole===Fe.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(e){return e===this||(e=e||new Y,e.curve=this.curve,e.fraction=this.fraction,e.fraction1=this.fraction1,e.point1=Rs(this.point1,e.point1),e.point.setFromPoint3d(this.point),e.vectorInCurveLocationDetail=Rs(this.vectorInCurveLocationDetail,e.vectorInCurveLocationDetail),e.a=this.a,e.childDetail=Rs(this.childDetail,e.childDetail),e.curveSearchStatus=this.curveSearchStatus),e}setFP(e,t,n,i=0){this.fraction=e,this.point.setFromPoint3d(t),this.vectorInCurveLocationDetail=Rs(n,this.vectorInCurveLocationDetail),this.a=i}setFR(e,t,n=0){return this.setFP(e,t.origin,t.direction,n)}setCurve(e){this.curve=e}setDistanceTo(e){this.a=this.point.distance(e)}static create(e,t){return t=t||new Y,t.curve=e,t}static createCurveFractionPoint(e,t,n,i){return i=i||new Y,i.curve=e,i.fraction=t,i.point.setFromPoint3d(n),i.vectorInCurveLocationDetail=void 0,i.a=0,i.childDetail=void 0,i.curveSearchStatus=void 0,i}static createRayFractionPoint(e,t,n,i){return i=i||new Y,i.fraction=t,i.ray=e,i.point.setFromPoint3d(n),i}static createCurveFractionPointDistanceCurveSearchStatus(e,t,n,i,s,r){return r=r||new Y,r.curve=e,r.fraction=t,r.point.setFromPoint3d(n),r.vectorInCurveLocationDetail=void 0,r.a=i,r.childDetail=void 0,r.curveSearchStatus=s,r}static createConditionalMoveSignedDistance(e,t,n,i,s,r){let a=s,o=Yt.success;return!e&&!f.isIn01(i)&&(i<0?(a=-t.curveLengthBetweenFractions(n,0),i=0,o=Yt.stoppedAtBoundary):i>1&&(i=1,a=t.curveLengthBetweenFractions(n,1),o=Yt.stoppedAtBoundary)),r=r||new Y,r.curve=t,r.fraction=i,t.fractionToPoint(i,r.point),r.vectorInCurveLocationDetail=void 0,r.a=a,r.childDetail=void 0,r.curveSearchStatus=o,r}static createCurveEvaluatedFraction(e,t,n){return n=n||new Y,n.curve=e,n.fraction=t,e.fractionToPoint(t,n.point),n.vectorInCurveLocationDetail=void 0,n.a=0,n.childDetail=void 0,n.curveSearchStatus=void 0,n}static createCurveEvaluatedFractionPointAndDerivative(e,t,n){n=n||new Y,n.curve=e,n.fraction=t;const i=e.fractionToPointAndDerivative(t);return n.point.setFromPoint3d(i.origin),n.vectorInCurveLocationDetail=i.direction,n.a=0,n.childDetail=void 0,n.curveSearchStatus=void 0,n}static createCurveEvaluatedFractionFraction(e,t,n,i){return i=i||new Y,i.curve=e,i.fraction=t,e.fractionToPoint(t,i.point),i.fraction1=n,i.point1=e.fractionToPoint(n,i.point1),i.vectorInCurveLocationDetail=void 0,i.a=0,i.childDetail=void 0,i.curveSearchStatus=void 0,i}static createCurveFractionPointDistance(e,t,n,i,s){return s=s||new Y,s.curve=e,s.fraction=t,s.point.setFromPoint3d(n),s.vectorInCurveLocationDetail=void 0,s.a=i,s.childDetail=void 0,s.curveSearchStatus=void 0,s}updateIfCloserCurveFractionPointDistance(e,t,n,i){return this.a<i?!1:(Y.createCurveFractionPointDistance(e,t,n,i,this),!0)}swapFractionsAndPoints(){if(this.fraction1!==void 0){const e=this.fraction;this.fraction=this.fraction1,this.fraction1=e}if(this.point1!==void 0){const e=this.point;this.point=this.point1,this.point1=e}}inverseInterpolateFraction(e,t=0){if(this.fraction1===void 0)return t;const n=f.inverseInterpolate01(this.fraction,this.fraction1,e);return n===void 0?t:n}static chooseSmallerA(e,t){return e?t?e.a<=t.a?e:t:e:t}isSameCurveAndFraction(e,t){return this.curve===e.curve&&f.isAlmostEqualNumber(this.fraction,e.fraction,t)}tryTransformInPlace(e){return this.curve&&!this.curve.tryTransformInPlace(e)||(this.ray&&this.ray.transformInPlace(e),this.curve?this.curve.fractionToPoint(this.fraction,this.point):e.multiplyXYAndZInPlace(this.point),this.vectorInCurveLocationDetail&&e.multiplyVectorInPlace(this.vectorInCurveLocationDetail),this.childDetail&&this.childDetail!==this&&!this.childDetail.tryTransformInPlace(e))?!1:(this.point1&&(this.curve&&this.fraction1?this.curve.fractionToPoint(this.fraction1,this.point1):e.multiplyXYAndZInPlace(this.point1)),!0)}}var zn;(function(l){l[l.Intersection=0]="Intersection",l[l.PerpendicularChord=1]="PerpendicularChord",l[l.CoincidentGeometry=2]="CoincidentGeometry",l[l.ParallelGeometry=3]="ParallelGeometry"})(zn||(zn={}));class Ze{detailA;detailB;approachType;constructor(e,t){this.detailA=e||new Y,this.detailB=t||new Y}static createCapture(e,t,n){return n=n||new Ze,n.detailA=e,n.detailB=t,n}static createCaptureOptionalReverse(e,t,n,i){return i=i||new Ze,i.detailA=e,i.detailB=t,i}clone(e){return e=e||new Ze,e.detailA=this.detailA.clone(),e.detailB=this.detailB.clone(),e.approachType=this.approachType,e}swapDetails(){const e=this.detailA;this.detailA=this.detailB,this.detailB=e}static removeAdjacentDuplicates(e,t=0){return e.flatMap((n,i,s)=>i>=t&&i>0&&!n.detailA.hasFraction1&&!n.detailB.hasFraction1&&n.detailA.isSameCurveAndFraction(s[i-1].detailA)&&n.detailB.isSameCurveAndFraction(s[i-1].detailB)?[]:[n])}tryTransformInPlace(e){return this.detailA.tryTransformInPlace(e)&&this.detailB.tryTransformInPlace(e)}static comparePairsByFractions(e=f.smallFraction,t=f.smallMetricDistance,n=!1,i=!1){return(s,r)=>{const a=s.detailA.curve,o=s.detailB.curve;let c=s.detailA.fraction,d=s.detailB.fraction,h=r.detailA.fraction,u=r.detailB.fraction;i&&(a?.isPhysicallyClosedCurve(t,n)&&(f.isAlmostEqualEitherNumber(s.detailA.fraction,0,1,e)&&(c=0),f.isAlmostEqualEitherNumber(r.detailA.fraction,0,1,e)&&(h=0)),o?.isPhysicallyClosedCurve(t,n)&&(f.isAlmostEqualEitherNumber(s.detailB.fraction,0,1,e)&&(d=0),f.isAlmostEqualEitherNumber(r.detailB.fraction,0,1,e)&&(u=0)));const g=f.isAlmostEqualNumber(c,h,e);return g&&f.isAlmostEqualNumber(d,u,e)||(n?s.detailA.point.isAlmostEqualXY(r.detailA.point,t):s.detailA.point.isAlmostEqual(r.detailA.point,t))&&(n?s.detailB.point.isAlmostEqualXY(r.detailB.point,t):s.detailB.point.isAlmostEqual(r.detailB.point,t))?0:g?d-u:c-h}}static comparePairsByPoints(e=f.smallMetricDistance,t=!1){return(n,i)=>{const s=t?f.compareXY(e):f.compareXYZ(e),r=s(n.detailA.point,i.detailA.point),a=s(n.detailB.point,i.detailB.point),o=r===0;return o&&a===0?0:o?a:r}}}class Me{_data;_inUse;_growthFactor;constructor(e=8,t){this._data=new Float64Array(e),this._inUse=0,this._growthFactor=t!==void 0&&t>=1?t:1.5}copyData(e,t,n){let i=n??0;if(i<0&&(i=0),i>=this._data.length)return{count:0,offset:0};let s=t??e.length;return s>0&&(s>e.length&&(s=e.length),i+s>this._data.length&&(s=this._data.length-i)),s<=0?{count:0,offset:0}:(s===e.length?this._data.set(e,i):e instanceof Float64Array?this._data.set(e.subarray(0,s),i):this._data.set(e.slice(0,s),i),{count:s,offset:i})}static create(e){const t=new Me(e.length);return t.copyData(e),t._inUse=e.length,t}static compare(e,t){return e-t}clone(e=!1){const t=new Me(e?this.capacity():this._inUse);return t.copyData(this._data,this._inUse),t._inUse=this._inUse,t}get length(){return this._inUse}setAtUncheckedIndex(e,t){this._data[e]=t}move(e,t){this._data[t]=this._data[e]}swap(e,t){const n=this._data[e];this._data[e]=this._data[t],this._data[t]=n}push(e){this.ensureCapacity(this._inUse+1),this._data[this._inUse]=e,this._inUse++}pushArray(e){this.ensureCapacity(this._inUse+e.length),this.copyData(e,e.length,this._inUse),this._inUse+=e.length}pushBlockCopy(e,t){e>=0&&e<this._inUse&&t>0&&e+t<=this._inUse&&(this.ensureCapacity(this._inUse+t),this._data.copyWithin(this._inUse,e,e+t),this._inUse+=t)}clear(){this._inUse=0}capacity(){return this._data.length}ensureCapacity(e,t=!0){if(e>this.capacity()){t&&(e*=this._growthFactor);const n=this._data;this._data=new Float64Array(e),this.copyData(n,this._inUse)}}resize(e,t=0){e>=0&&e<this._inUse?this._inUse=e:e>this._inUse&&(this.ensureCapacity(e,!1),this._data.fill(t,this._inUse),this._inUse=e)}pop(){this._inUse>0&&this._inUse--}isIndexValid(e){return e>=0&&e<this.length}atUncheckedIndex(e){return this._data[e]}atIndex(e){if(this.isIndexValid(e))return this.atUncheckedIndex(e)}front(){return this._data[0]}back(){return this._data[this._inUse-1]}reassign(e,t){this._data[e]=t}sort(e=(t,n)=>Me.compare(t,n)){for(let t=0;t<this._inUse;t++)for(let n=t+1;n<this._inUse;n++){const i=this._data[t],s=this._data[n];e(i,s)>0&&(this._data[t]=s,this._data[n]=i)}}restrictToInterval(e,t){const n=this._data,i=n.length;let s=0,r=0;for(let a=0;a<i;a++)r=n[a],r>=e&&r<=t&&(n[s++]=r);this._inUse=s}compressAdjacentDuplicates(e=0){const t=this._data,n=this._inUse;if(n===0)return;let i=1,s=t[0],r;for(let a=1;a<n;a++)r=t[a],Math.abs(r-s)>e&&(t[i++]=r,s=r);this._inUse=i}reverseInPlace(){this._data.reverse()}}class Ms{coffs;constructor(e=0,t=0,n=0){this.coffs=[e,t,n]}static solveQuadratic(e,t,n){const i=f.conditionalDivideFraction(t,e),s=f.conditionalDivideFraction(n,e);if(i!==void 0&&s!==void 0){const a=i*i-4*s;if(a>0){const c=Math.sqrt(a);return[.5*(-i-c),.5*(-i+c)]}if(a<0)return;const o=-.5*i;return[o,o]}const r=f.conditionalDivideFraction(-n,t);if(r!==void 0)return[r]}addConstant(e){this.coffs[0]+=e}addSquaredLinearTerm(e,t,n=1){this.coffs[0]+=n*(e*e),this.coffs[1]+=n*(2*e*t),this.coffs[2]+=n*(t*t)}realRoots(){const e=Ms.solveQuadratic(this.coffs[2],this.coffs[1],this.coffs[0]);if(e&&e.length>1&&e[0]>e[1]){const t=e[0];e[0]=e[1],e[1]=t}return e}evaluate(e){return this.coffs[0]+e*(this.coffs[1]+e*this.coffs[2])}evaluateDerivative(e){return this.coffs[1]+2*e*this.coffs[2]}tryGetVertexFactorization(){const e=f.conditionalDivideFraction(-this.coffs[1],2*this.coffs[2]);if(e!==void 0){const t=this.evaluate(e);return{c:this.coffs[2],x0:e,y0:t}}}static fromRootsAndC2(e,t,n=1){return new Ms(n*e*t,-n*(e+t),n)}}class Bn{static _EQN_EPS=1e-9;static _safeDivideFactor=1e-14;static isZero(e){return Math.abs(e)<this._EQN_EPS}static isSmallRatio(e,t,n=1e-9,i=8e-16){return Math.abs(e)<=n||Math.abs(e)<i*Math.abs(t)}static cbrt(e){return e>0?Math.pow(e,1/3):e<0?-Math.pow(-e,1/3):0}static safeDivide(e,t,n,i=0,s){return Math.abs(n)>this._safeDivideFactor*Math.abs(t)?(e[s]=t/n,!0):(e[s]=i,!1)}static checkRootProximity(e,t){return t===0?e.atUncheckedIndex(t)<e.atUncheckedIndex(t+1):t>0&&t+1<e.length?e.atUncheckedIndex(t)>e.atUncheckedIndex(t-1)&&e.atUncheckedIndex(t)<e.atUncheckedIndex(t+1):e.atUncheckedIndex(t)>e.atUncheckedIndex(t-1)}static newtonMethodAdjustment(e,t,n){let i=e[n],s=0;for(let r=n-1;r>=0;r--)s=i+t*s,i=e[r]+t*i;if(Math.abs(s)>=1e-14*(1+Math.abs(t)))return i/s}static improveRoots(e,t,n,i){for(let r=0;r<n.length;r++){let a=this.newtonMethodAdjustment(e,n.atUncheckedIndex(r),t);if(a===void 0||a===0)continue;const o=n.atUncheckedIndex(r);let c=0,d=0;for(;a!==void 0&&a!==0&&c<12;){if(Math.abs(a)<1e-10*(1+Math.abs(n.atUncheckedIndex(r)))){if(++d>1)break}else d=0;const h=n.atUncheckedIndex(r)-a;if(n.reassign(r,h),i&&!this.checkRootProximity(n,r)){n.reassign(r,o);break}a=this.newtonMethodAdjustment(e,n.atUncheckedIndex(r),t),c++}}}static appendSolution(e,t){e!==void 0&&t.push(e)}static append2Solutions(e,t,n){n.push(e),n.push(t)}static appendLinearRoot(e,t,n){Bn.appendSolution(f.conditionalDivideFraction(-e,t),n)}static mostDistantFromMean(e){if(!e||e.length===0)return 0;let t=0;for(let s=0;s<e.length;s++)t+=e.atUncheckedIndex(s);t/=e.length;let n=0,i=e.atUncheckedIndex(0);for(let s=0;s<e.length;s++){const r=Math.abs(e.atUncheckedIndex(s)-t);r>n&&(n=r,i=e.atUncheckedIndex(s))}return i}static appendQuadraticRoots(e,t){const n=f.conditionalDivideFraction(1,e[2]);if(!n){this.appendLinearRoot(e[0],e[1],t);return}const i=.5*e[1]*n,s=e[0]*n,r=i*i-s;if(this.isZero(r)){this.appendSolution(-i,t);return}else{if(r<0)return;if(r>0){const a=Math.sqrt(r);this.append2Solutions(a-i,-a-i,t);return}}}static addConstant(e,t){for(let n=0;n<t.length;n++)t.reassign(n,t.atUncheckedIndex(n)+e)}static signedCubeRoot(e){return e>=0?Math.pow(e,1/3):-Math.pow(-e,1/3)}static appendFullCubicSolutions(e,t,n,i,s){const r=t*t-3*e*n,a=e*e,o=r/(9*a),c=-t/(3*e),d=i+c*(n+c*(t+c*e)),h=d*d,u=4*e*e*o*o*o,g=h-u;if(g>0){const m=Math.sqrt(g),p=.5/e;s.push(c+this.signedCubeRoot(p*(-d+m))+this.signedCubeRoot(p*(-d-m)))}else if(g<0){let m=Math.sqrt(u);e<0&&(m=-m);const p=Math.acos(-d/m)/3,x=2*Math.sqrt(o),_=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*d/e),p=c+m;s.push(c-2*m),s.push(p),s.push(p)}}static appendCubicRoots(e,t){f.conditionalDivideCoordinate(1,e[3])!==void 0?(this.appendFullCubicSolutions(e[3],e[2],e[1],e[0],t),this.improveRoots(e,3,t,!1)):this.appendQuadraticRoots(e,t),t.sort()}static appendQuarticRoots(e,t){const n=new Float64Array(4);let i,s;const r=new Float64Array(1);if(!this.safeDivide(r,1,e[4],0,0)){this.appendCubicRoots(e,t);return}const a=e[3]*r[0],o=e[2]*r[0],c=e[1]*r[0],d=e[0]*r[0],h=-.25*a,u=a*a,g=-.375*u+o,m=.125*u*a-.5*a*o+c,p=-.01171875*u*u+.0625*u*o-.25*a*c+d,x=new Me;if(this.isZero(p)){n[0]=m,n[1]=g,n[2]=0,n[3]=1,this.appendCubicRoots(n,t),t.push(0),this.addConstant(h,t);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,t),n[0]=_+i,n[1]=m<0?s:-s,n[2]=1,this.appendQuadraticRoots(n,t)}this.addConstant(h,t),t.sort(),this.improveRoots(e,4,t,!0)}static appendCosSinRadians(e,t,n,i,s){n&&n.push(e),i&&i.push(t),s&&s.push(Math.atan2(t,e))}static appendImplicitLineUnitCircleIntersections(e,t,n,i,s,r,a=1e-14){let o;const c=t*t+n*n,d=e*e;let h=0;if(a<0?o=0:o=2*a,c<=0)h=e===0?-2:-1;else{const u=-e/c,m=1-d/c;if(m<-o){const p=Math.sqrt(c),x=e<0?1/p:-1/p;this.appendCosSinRadians(t*x,n*x,i,s,r),this.appendCosSinRadians(u*t,u*n,i,s,r),h=0}else if(m<o){const p=Math.sqrt(c),x=e<0?1/p:-1/p;this.appendCosSinRadians(t*x,n*x,i,s,r),this.appendCosSinRadians(u*t,u*n,i,s,r),h=1}else{const p=Math.sqrt(m/c),x=u*t,_=u*n;this.appendCosSinRadians(x-p*n,_+p*t,i,s,r),this.appendCosSinRadians(x+p*n,_-p*t,i,s,r),h=2}}return h}}class Rt{static degreeKnownEvaluate(e,t,n){if(t<0)return 0;let i=e[t];for(let s=t-1;s>=0;s--)i=n*i+e[s];return i}static evaluate(e,t){const n=e.length-1;return this.degreeKnownEvaluate(e,n,t)}static accumulate(e,t,n){let i=e.length-1;const s=t.length-1;for(let r=0;r<=s;r++)e[r]+=n*t[r];for(;i>=0&&e[i]===0;)i--;return i}static zero(e){for(let t=0;t<e.length;t++)e[t]=0}}class Oi{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(e,t,n,i){let s=Math.abs(n),r;i.length=0;const a=this._smallAngle;for(let h=0;h<=t;h++)r=Math.abs(e[h]),r>s&&(s=r);const o=a*s;let c=t;for(;c>0&&Math.abs(e[c])<=o;)c--;const d=new Me;if(c!==-1){if(c===0||(c===1?d.push(-e[0]/e[1]):c===2?Bn.appendQuadraticRoots(e,d):c===3?Bn.appendCubicRoots(e,d):c===4&&Bn.appendQuarticRoots(e,d)),d.length>0)for(let h=0;h<d.length;h++){const u=Rt.evaluate(this.S,d.atUncheckedIndex(h)),g=Rt.evaluate(this.C,d.atUncheckedIndex(h));i.push(Math.atan2(u,g))}c<t&&i.push(-.5*Math.PI)}return i.length>0}static _coefficientRelTolSquared=1e-24;static solveUnitCircleImplicitQuadricIntersection(e,t,n,i,s,r,a){const o=new Float64Array(5);Rt.zero(o);let c;const d=f.hypotenuseSquaredXYZ(i,s,r),h=f.hypotenuseSquaredXYZ(e,t,n);if(h<=Oi._coefficientRelTolSquared*d)Rt.accumulate(o,this.C,i),Rt.accumulate(o,this.S,s),Rt.accumulate(o,this.W,r),c=2;else if(h-2*e*n<=2*Oi._coefficientRelTolSquared*h){const m=.5*(e+n);Rt.accumulate(o,this.C,i),Rt.accumulate(o,this.S,s),Rt.accumulate(o,this.W,r+m),c=2}else Rt.accumulate(o,this.CW,i),Rt.accumulate(o,this.SW,s),Rt.accumulate(o,this.WW,r),Rt.accumulate(o,this.SS,n),Rt.accumulate(o,this.CC,e),Rt.accumulate(o,this.SC,t),c=4;const u=Math.max(Math.abs(e),Math.abs(n),Math.abs(t),Math.abs(i),Math.abs(s),Math.abs(r));return this.solveAngles(o,c,u,a)}static solveUnitCircleEllipseIntersection(e,t,n,i,s,r,a,o){o.length=0;const c=n*n+i*i,d=2*(n*s+i*r),h=s*s+r*r,u=2*(n*e+i*t),g=2*(s*e+r*t),m=e*e+t*t-1,p=this.solveUnitCircleImplicitQuadricIntersection(c,d,h,u,g,m,a);for(const x of a){const _=Math.cos(x),I=Math.sin(x),S=e+n*_+s*I,A=t+i*_+r*I;o.push(Math.atan2(A,S))}return p}static solveUnitCircleHomogeneousEllipseIntersection(e,t,n,i,s,r,a,o,c,d,h){h.length=0;const u=i*i+s*s-r*r,g=2*(i*a+s*o-r*c),m=a*a+o*o-c*c,p=2*(i*e+s*t-r*n),x=2*(a*e+o*t-c*n),_=e*e+t*t-n*n,I=this.solveUnitCircleImplicitQuadricIntersection(u,g,m,p,x,_,d);for(const S of d){const A=Math.cos(S),w=Math.sin(S),k=e+i*A+a*w,D=t+s*A+o*w;h.push(Math.atan2(D,k))}return I}}class Ds{a;b;c;d;constructor(e,t,n,i){this.a=e,this.b=t,this.c=n,this.d=i}evaluate(e,t){return this.a+this.b*e+t*(this.c+this.d*e)}static createUnitSquareValues(e,t,n,i){return new Ds(e,t,t,i-t-n)}static solveBilinearPair(e,t,n,i,s,r,a,o){const c=f.crossProductXYXY(e,s,n,a),d=f.crossProductXYXY(t,r,n,a)+f.crossProductXYXY(e,s,i,o),h=f.crossProductXYXY(t,r,i,o),u=Ms.solveQuadratic(h,d,c);if(u===void 0)return;const g=[];for(const m of u){const p=f.conditionalDivideFraction(-(e+t*m),n+i*m),x=f.conditionalDivideFraction(-(s+r*m),a+o*m);p!==void 0?g.push(L.create(m,p)):x!==void 0&&g.push(L.create(m,x))}return g}static solvePair(e,t,n,i){return Ds.solveBilinearPair(e.a-t,e.b,e.c,e.d,n.a-i,n.b,n.c,n.d)}}class ja{a;cosineCoff;sineCoff;constructor(e,t,n){this.a=e,this.cosineCoff=t,this.sineCoff=n}set(e,t,n){this.a=e,this.cosineCoff=t,this.sineCoff=n}evaluateRadians(e){return this.a+this.cosineCoff*Math.cos(e)+this.sineCoff*Math.sin(e)}range(e){const t=f.hypotenuseXY(this.cosineCoff,this.sineCoff);return fe.createXX(this.a-t,this.a+t,e)}rangeInStartEndRadians(e,t,n){if(T.isFullCircleRadians(t-e))return this.range(n);n=fe.createXX(this.evaluateRadians(e),this.evaluateRadians(t),n);const i=Math.atan2(this.sineCoff,this.cosineCoff),s=i+Math.PI;return me.isRadiansInStartEnd(i,e,t)&&n.extendX(this.evaluateRadians(i)),me.isRadiansInStartEnd(s,e,t)&&n.extendX(this.evaluateRadians(s)),n}rangeInSweep(e,t){return this.rangeInStartEndRadians(e.startRadians,e.endRadians,t)}referenceMinMaxRadians(){return Math.atan2(this.sineCoff,this.cosineCoff)}}class Le{static lineXYUVTransverseIntersection(e,t,n,i){const s=n.x-e.x,r=n.y-e.y,a=f.crossProductXYXY(t.x,t.y,i.x,i.y),o=f.crossProductXYXY(s,r,i.x,i.y),c=f.crossProductXYXY(s,r,t.x,t.y),d=f.conditionalDivideFraction(o,a),h=f.conditionalDivideFraction(c,a);if(d!==void 0&&h!==void 0)return{x:d,y:h}}static lineSegment2dXYTransverseIntersectionUnbounded(e,t,n,i,s){const r=t.x-e.x,a=t.y-e.y,o=i.x-n.x,c=i.y-n.y;return this.lineSegmentXYUVTransverseIntersectionUnbounded(e.x,e.y,r,a,n.x,n.y,o,c,s)}static lineSegmentXYUVTransverseIntersectionUnbounded(e,t,n,i,s,r,a,o,c){const d=this.lineXYUVTransverseIntersection({x:e,y:t},{x:n,y:i},{x:s,y:r},{x:a,y:o});return d?(c.set(d.x,d.y),!0):(c.set(0,0),!1)}static lineSegment3dXYTransverseIntersectionUnbounded(e,t,n,i,s){const r=t.x-e.x,a=t.y-e.y,o=i.x-n.x,c=i.y-n.y;return this.lineSegmentXYUVTransverseIntersectionUnbounded(e.x,e.y,r,a,n.x,n.y,o,c,s)}static lineSegmentXYUVOverlapUnbounded(e,t,n,i,s=f.smallMetricDistance){const r=s*s,a=(x,_,I)=>{const S=f.dotProductXYXY(I.x,I.y,I.x,I.y),A=f.dotProductXYXY(x.x-_.x,x.y-_.y,I.x,I.y),w=f.safeDivideFraction(A,S,0);return{f:w,p:{x:_.x+w*I.x,y:_.y+w*I.y}}},o=a(e,n,i);if(f.distanceSquaredXYXY(e.x,e.y,o.p.x,o.p.y)>r)return;const c=e.x+t.x,d=e.y+t.y,h=a({x:c,y:d},n,i);if(f.distanceSquaredXYXY(c,d,h.p.x,h.p.y)>r)return;const u=a(n,e,t);if(f.distanceSquaredXYXY(n.x,n.y,u.p.x,u.p.y)>r)return;const g=n.x+i.x,m=n.y+i.y,p=a({x:g,y:m},e,t);if(!(f.distanceSquaredXYXY(g,m,p.p.x,p.p.y)>r))return u.f>p.f&&([u.f,p.f]=[p.f,u.f]),o.f>h.f&&([o.f,h.f]=[h.f,o.f]),{f0:{x:u.f,y:o.f},f1:{x:p.f,y:h.f}}}static lineSegmentXYUVIntersectionUnbounded(e,t,n,i,s=f.smallMetricDistance){const r=this.lineSegmentXYUVOverlapUnbounded(e,t,n,i,s);if(r)return r;const a=this.lineXYUVTransverseIntersection(e,t,n,i);if(a)return{f0:a}}static lineSegment3dHXYTransverseIntersectionUnbounded(e,t,n,i,s){const r=f.tripleProduct(e.x,t.x,n.x,e.y,t.y,n.y,e.w,t.w,n.w),a=f.tripleProduct(e.x,t.x,i.x,e.y,t.y,i.y,e.w,t.w,i.w),o=f.conditionalDivideFraction(-r,a-r);if(o!==void 0){const c=f.tripleProduct(n.x,i.x,e.x,n.y,i.y,e.y,n.w,i.w,e.w),d=f.tripleProduct(n.x,i.x,t.x,n.y,i.y,t.y,n.w,i.w,t.w),h=f.conditionalDivideFraction(-c,d-c);if(h!==void 0)return $.create(h,o,s)}}static lineSegment3dHXYClosestPointUnbounded(e,t,n){const i=t.x*e.w-e.x*t.w,s=t.y*e.w-e.y*t.w,r=f.tripleProduct(e.x,-s,n.x,e.y,i,n.y,e.w,0,n.w),a=f.tripleProduct(t.x,-s,n.x,t.y,i,n.y,t.w,0,n.w);return f.conditionalDivideFraction(-r,a-r)}static lineSegment3dXYClosestPointUnbounded(e,t,n){const i=t.x-e.x,s=t.y-e.y,r=i*i+s*s,a=n.x-e.x,o=n.y-e.y,c=i*a+s*o;return f.conditionalDivideFraction(c,r)}static lineSegment3dClosestPointUnbounded(e,t,n){const i=t.x-e.x,s=t.y-e.y,r=t.z-e.z,a=i*i+s*s+r*r,o=n.x-e.x,c=n.y-e.y,d=n.z-e.z,h=i*o+s*c+r*d;return f.conditionalDivideFraction(h,a)}static lineSegment3dClosestApproachUnbounded(e,t,n,i,s){return this.ray3dXYZUVWClosestApproachUnbounded(e.x,e.y,e.z,t.x-e.x,t.y-e.y,t.z-e.z,n.x,n.y,n.z,i.x-n.x,i.y-n.y,i.z-n.z,s)}static ray3dXYZUVWClosestApproachUnbounded(e,t,n,i,s,r,a,o,c,d,h,u,g){const m=a-e,p=o-t,x=c-n,_=f.hypotenuseSquaredXYZ(i,s,r),I=f.hypotenuseSquaredXYZ(d,h,u),S=f.dotProductXYZXYZ(i,s,r,d,h,u),A=f.dotProductXYZXYZ(m,p,x,i,s,r),w=f.dotProductXYZXYZ(m,p,x,d,h,u);return Le.linearSystem2d(_,-S,S,-I,A,w,g)}static linearSystem2d(e,t,n,i,s,r,a){const o=f.crossProductXYXY(e,n,t,i),c=f.crossProductXYXY(s,r,t,i),d=f.crossProductXYXY(e,n,s,r),h=f.conditionalDivideFraction(c,o),u=f.conditionalDivideFraction(d,o);return h!==void 0&&u!==void 0?(a.set(h,u),!0):(a.set(0,0),!1)}static linearSystem3d(e,t,n,i,s,r,a,o,c,d,h,u,g){const m=f.tripleProduct(e,i,a,t,s,o,n,r,c),p=f.tripleProduct(d,h,u,t,s,o,n,r,c),x=f.tripleProduct(e,i,a,d,h,u,n,r,c),_=f.tripleProduct(e,i,a,t,s,o,d,h,u),I=f.conditionalDivideFraction(p,m),S=f.conditionalDivideFraction(x,m),A=f.conditionalDivideFraction(_,m);if(I!==void 0&&S!==void 0&&A!==void 0)return v.create(I,S,A,g)}static intersect3Planes(e,t,n,i,s,r,a){return this.linearSystem3d(t.x,t.y,t.z,i.x,i.y,i.z,r.x,r.y,r.z,f.dotProductXYZXYZ(e.x,e.y,e.z,t.x,t.y,t.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),a)}static eliminateFromPivot(e,t,n,i){const s=e.length;let r=f.conditionalDivideFraction(n[t],e[t]);if(r===void 0)return!1;r*=i;for(let a=t+1;a<s;a++)n[a]+=r*e[a];return!0}static solveBilinearPair(e,t,n,i,s,r,a,o){return Ds.solveBilinearPair(e,t,n,i,s,r,a,o)}}class q{origin;direction;a;static _workVector0;static _workVector1;static _workVector2;static _workVector3;static _workVector4;static _workMatrix;constructor(e,t){this.origin=e,this.direction=t,this.a=void 0}static _create(e,t,n,i,s,r){return new q(y.create(e,t,n),v.create(i,s,r))}static createXAxis(){return q._create(0,0,0,1,0,0)}static createYAxis(){return q._create(0,0,0,0,1,0)}static createZAxis(){return q._create(0,0,0,0,0,1)}static createZero(e){return e?(e.origin.setZero(),e.direction.setZero(),e):new q(y.createZero(),v.createZero())}isAlmostEqual(e,t=f.smallMetricDistance){return this.origin.isAlmostEqual(e.origin,t)&&this.direction.isAlmostEqual(e.direction,t)}dotProductToPoint(e){return this.direction.dotProductStartEnd(this.origin,e)}dotProductToPointXY(e){return this.direction.dotProductStartEndXY(this.origin,e)}pointToFraction(e){return f.safeDivideFraction(this.dotProductToPoint(e),this.direction.magnitudeSquared(),0)}projectPointToRay(e){return this.origin.plusScaled(this.direction,this.pointToFraction(e))}isAlmostEqualPointSet(e,t){if(!this.direction.isParallelTo(e.direction,!0,!1,t))return!1;const n=t?.distanceSquaredTol??f.smallMetricDistanceSquared;let i=this.projectPointToRay(e.origin);return!(e.origin.distanceSquared(i)>n||(i=e.projectPointToRay(this.origin),this.origin.distanceSquared(i)>n))}static create(e,t,n){return n?(n.set(e,t),n):new q(e.clone(),t.clone())}static createWeightedDerivative(e,t,n){const i=e[3],s=t[3],r=e[0],a=e[1],o=e[2],c=t[0]*i-e[0]*s,d=t[1]*i-e[1]*s,h=t[2]*i-e[2]*s;if(f.isSmallMetricDistance(i))return;const u=1/i,g=u*u;return q.createXYZUVW(r*u,a*u,o*u,c*g,d*g,h*g,n)}static createXYZUVW(e,t,n,i,s,r,a){return a?(a.getOriginRef().set(e,t,n),a.getDirectionRef().set(i,s,r),a):new q(y.create(e,t,n),v.create(i,s,r))}static createCapture(e,t){return new q(e,t)}static createPointVectorNumber(e,t,n,i){return i?(i.origin.setFrom(e),i.direction.setFrom(t),i.a=n,i):(i=new q(e.clone(),t.clone()),i.a=n,i)}static createStartEnd(e,t,n){return n?(n.origin.setFrom(e),n.direction.setStartEnd(e,t),n):new q(e.clone(),v.createStartEnd(e,t))}getOriginRef(){return this.origin}getDirectionRef(){return this.direction}set(e,t){this.origin.setFrom(e),this.direction.setFrom(t)}clone(e){return e?(e.set(this.origin.clone(),this.direction.clone()),e):new q(this.origin.clone(),this.direction.clone())}cloneTransformed(e,t){return q.create(e.multiplyPoint3d(this.origin,t?.origin),e.multiplyVector(this.direction,t?.direction),t)}cloneInverseTransformed(e,t){if(!e.computeCachedInverse(!0))return;const n=e.multiplyInversePoint3d(this.origin,t?.origin),i=e.matrix.multiplyInverseXYZAsVector3d(this.direction.x,this.direction.y,this.direction.z,t?.direction);return q.create(n,i,t)}transformInPlace(e){e.multiplyPoint3d(this.origin,this.origin),e.multiplyVector(this.direction,this.direction)}setFrom(e){this.set(e.origin,e.direction)}fractionToPoint(e,t){return this.origin.plusScaled(this.direction,e,t)}toRigidZFrame(e){const t=q._workMatrix=E.createRigidHeadsUp(this.direction,ve.ZXY,q._workMatrix);return X.createOriginAndMatrix(this.origin,t,e)}setFromJSON(e){if(!e){this.origin.set(0,0,0),this.direction.set(0,0,1);return}this.origin.setFromJSON(e.origin),this.direction.setFromJSON(e.direction)}toJSON(){return{origin:this.origin.toJSON(),direction:this.direction.toJSON()}}static fromJSON(e){const t=q.createXAxis();return t.setFromJSON(e),t}trySetDirectionMagnitudeInPlace(e=1){return this.direction.tryNormalizeInPlace()?(this.direction.scaleInPlace(e),!0):(this.direction.setZero(),this.a=0,!1)}tryNormalizeInPlaceWithAreaWeight(e){const t=f.smallMetricDistanceSquared;return this.a=e,Math.abs(e)>t&&this.direction.tryNormalizeInPlace(t)?!0:(this.direction.setZero(),this.a=0,!1)}distance(e){const t=this.direction.magnitudeSquared(),n=this.dotProductToPoint(e),i=f.inverseMetricDistanceSquared(t);return Math.sqrt(i?this.origin.distanceSquared(e)-n*n*i:this.origin.distanceSquared(e))}intersectionWithPlane(e,t){const n=v.createStartEnd(e.getOriginRef(),this.origin),i=this.direction.dotProduct(e.getNormalRef()),s=this.direction.magnitudeSquared(),r=n.dotProduct(e.getNormalRef()),a=f.conditionalDivideFraction(-r,i);if(!(a===void 0||f.conditionalDivideFraction(s,i)===void 0))return t&&this.origin.plusScaled(this.direction,a,t),a}intersectionWithRange3d(e,t){if(e.isNull)return fe.createNull(t);const n=fe.createXX(-f.largeCoordinateResult,f.largeCoordinateResult,t);return n.clipLinearMapToInterval(this.origin.x,this.direction.x,e.low.x,e.high.x),n.clipLinearMapToInterval(this.origin.y,this.direction.y,e.low.y,e.high.y),n.clipLinearMapToInterval(this.origin.z,this.direction.z,e.low.z,e.high.z),n}intersectionWithTriangle(e,t,n,i,s,r){(i===void 0||i<0)&&(i=f.smallMetricDistance),(s===void 0||s<0)&&(s=f.smallFloatingPoint);const a=q._workVector0=v.createStartEnd(e,t,q._workVector0),o=q._workVector1=v.createStartEnd(e,n,q._workVector1),c=q._workVector2=this.direction.crossProduct(o,q._workVector2),d=a.dotProduct(c);if(d>=-i&&d<=i)return;const h=1/d,u=q._workVector3=v.createStartEnd(e,this.origin,q._workVector3);let g=h*u.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=q._workVector4=u.crossProduct(a,q._workVector4);let p=h*this.direction.dotProduct(m);if(p<0)if(p>=-s)p=0;else return;else if(g+p>1+s)return;const x=h*o.dotProduct(m);if(!(x<-i))return this.origin.plusScaled(this.direction,x,r)}perpendicularPartOfVectorToTarget(e,t){const n=v.createStartEnd(this.origin,e),i=this.direction.magnitudeSquared(),s=this.direction.dotProductStartEnd(this.origin,e),r=f.safeDivideFraction(s,i,0);return n.plusScaled(this.direction,-r,t)}static closestApproachRay3dRay3d(e,t){const n=$.create();let i,s,r,a,o;Le.ray3dXYZUVWClosestApproachUnbounded(e.origin.x,e.origin.y,e.origin.z,e.direction.x,e.direction.y,e.direction.z,t.origin.x,t.origin.y,t.origin.z,t.direction.x,t.direction.y,t.direction.z,n)?(i=n.x,s=n.y,r=e.fractionToPoint(i),a=t.fractionToPoint(s),o=r.isAlmostEqualMetric(a)?zn.Intersection:zn.PerpendicularChord):(s=0,i=e.pointToFraction(t.origin),r=e.fractionToPoint(i),a=t.fractionToPoint(s),o=r.isAlmostEqualMetric(a)?zn.CoincidentGeometry:zn.ParallelGeometry);const c=Ze.createCapture(Y.createRayFractionPoint(e,i,e.fractionToPoint(i)),Y.createRayFractionPoint(t,s,t.fractionToPoint(s)));return c.approachType=o,c}static interpolatePointAndTangent(e,t,n,i,s){s=s??q.createZero();const r=n.x-e.x,a=n.y-e.y,o=n.z-e.z;if(s.direction.set(i*r,i*a,i*o),t<=.5)s.origin.set(e.x+t*r,e.y+t*a,e.z+t*o);else{const c=t-1;s.origin.set(n.x+c*r,n.y+c*a,n.z+c*o)}return s}}class ke extends ks{origin;vectorU;vectorV;constructor(e,t,n){super(),this.origin=e,this.vectorU=t,this.vectorV=n}static createOriginAndVectors(e,t,n,i){return i?(i.origin.setFrom(e),i.vectorU.setFrom(t),i.vectorV.setFrom(n),i):new ke(e.clone(),t.clone(),n.clone())}clone(e){return e!==void 0&&e.setOriginAndVectors(this.origin,this.vectorU,this.vectorV),new ke(this.origin.clone(),this.vectorU.clone(),this.vectorV.clone())}static createFrom(e,t){if(e instanceof ke)return e.clone(t);const n=e.getUnitNormal();if(n===void 0)return;const i=e.getAnyPointOnPlane(),s=E.createPerpendicularVectorFavorXYPlane(n);if(s.tryNormalizeInPlace()){const r=n.unitCrossProduct(s);if(r!==void 0)return new ke(i,s,r)}}static createFromTransformColumnsXYAndLengths(e,t,n,i){return i?(i.origin.setFrom(e.getOrigin()),e.matrix.columnX(i.vectorU),e.matrix.columnY(i.vectorV)):i=new ke(e.getOrigin(),e.matrix.columnX(),e.matrix.columnY()),t!==void 0&&i.vectorU.scaleToLength(t,i.vectorU),n!==void 0&&i.vectorV.scaleToLength(n,i.vectorV),i}static createCapture(e,t,n,i){return i?(i.origin=e,i.vectorU=t,i.vectorV=n,i):new ke(e,t,n)}setOriginAndVectorsXYZ(e,t,n,i,s,r,a,o,c){return this.origin.set(e,t,n),this.vectorU.set(i,s,r),this.vectorV.set(a,o,c),this}setOriginAndVectors(e,t,n){return this.origin.setFrom(e),this.vectorU.setFrom(t),this.vectorV.setFrom(n),this}static createOriginAndVectorsXYZ(e,t,n,i,s,r,a,o,c,d){return d?d.setOriginAndVectorsXYZ(e,t,n,i,s,r,a,o,c):new ke(y.create(e,t,n),v.create(i,s,r),v.create(a,o,c))}static createOriginAndTargets(e,t,n,i){return ke.createOriginAndVectorsXYZ(e.x,e.y,e.z,t.x-e.x,t.y-e.y,t.z-e.z,n.x-e.x,n.y-e.y,n.z-e.z,i)}static createXYPlane(e){return ke.createOriginAndVectorsXYZ(0,0,0,1,0,0,0,1,0,e)}static createOriginAndVectorsArrays(e,t,n,i){return ke.createOriginAndVectorsXYZ(e[0],e[1],e[2],t[0],t[1],t[2],n[0],n[1],n[2],i)}static createOriginAndVectorsWeightedArrays(e,t,n,i){const s=e[3];if(i=ke.createXYPlane(i),f.isSmallMetricDistance(s))return i;const r=1/s,a=t[3]*r*r,o=n[3]*r*r;return i.origin.set(e[0]*r,e[1]*r,e[2]*r),v.createAdd2ScaledXYZ(t[0],t[1],t[2],r,e[0],e[1],e[2],-a,i.vectorU),v.createAdd2ScaledXYZ(n[0],n[1],n[2],r,e[0],e[1],e[2],-o,i.vectorV),i}fractionToPoint(e,t,n){return this.origin.plus2Scaled(this.vectorU,e,this.vectorV,t,n)}fractionToVector(e,t,n){return v.createAdd2Scaled(this.vectorU,e,this.vectorV,t,n)}setFromJSON(e){!e||!e.origin||!e.vectorV?(this.origin.set(0,0,0),this.vectorU.set(1,0,0),this.vectorV.set(0,1,0)):(this.origin.setFromJSON(e.origin),this.vectorU.setFromJSON(e.vectorU),this.vectorV.setFromJSON(e.vectorV))}toJSON(){return{origin:this.origin.toJSON(),vectorU:this.vectorU.toJSON(),vectorV:this.vectorV.toJSON()}}static fromJSON(e){const t=ke.createXYPlane();return t.setFromJSON(e),t}isAlmostEqual(e){return this.origin.isAlmostEqual(e.origin)&&this.vectorU.isAlmostEqual(e.vectorU)&&this.vectorV.isAlmostEqual(e.vectorV)}normalizeInPlace(){const e=this.vectorU.normalizeInPlace(),t=this.vectorV.normalizeInPlace();return e&&t}getUnitNormal(e){return this.vectorU.unitCrossProduct(this.vectorV,e)}unitNormal(e){return this.vectorU.unitCrossProduct(this.vectorV,e)}getAnyPointOnPlane(e){return this.origin.clone(e)}static _workVector;unitNormalRay(e){ke._workVector||(ke._workVector=v.create());const t=this.vectorU.unitCrossProduct(this.vectorV,ke._workVector);if(t!==void 0)return q.create(this.origin,t,e)}toRigidFrame(e){return X.createRigidFromOriginAndColumns(this.origin,this.vectorU,this.vectorV,ve.XYZ,e)}transformInPlace(e){e.multiplyPoint3d(this.origin,this.origin),e.multiplyVector(this.vectorU,this.vectorU),e.multiplyVector(this.vectorV,this.vectorV)}normalX(){const e=this.vectorU.unitCrossProduct(this.vectorV);return e!==void 0?e.x:0}normalY(){const e=this.vectorU.unitCrossProduct(this.vectorV);return e!==void 0?e.y:0}normalZ(){const e=this.vectorU.unitCrossProduct(this.vectorV);return e!==void 0?e.z:0}altitude(e){const t=this.vectorU.unitCrossProduct(this.vectorV);return t===void 0?0:f.dotProductXYZXYZ(e.x-this.origin.x,e.y-this.origin.y,e.z-this.origin.z,t.x,t.y,t.z)}altitudeXYZ(e,t,n){const i=this.vectorU.unitCrossProduct(this.vectorV);return i===void 0?0:f.dotProductXYZXYZ(e-this.origin.x,t-this.origin.y,n-this.origin.z,i.x,i.y,i.z)}velocity(e){const t=this.vectorU.unitCrossProduct(this.vectorV);return t===void 0?0:f.dotProductXYZXYZ(e.x,e.y,e.z,t.x,t.y,t.z)}velocityXYZ(e,t,n){const i=this.vectorU.unitCrossProduct(this.vectorV);return i===void 0?0:f.dotProductXYZXYZ(e,t,n,i.x,i.y,i.z)}weightedAltitude(e){const t=e.w;return f.tripleProduct(e.x-this.origin.x*t,e.y-this.origin.y*t,e.z-this.origin.z*t,this.vectorU.x,this.vectorU.y,this.vectorU.z,this.vectorV.x,this.vectorV.y,this.vectorV.z)}projectPointToPlane(e,t){return this.projectXYZToPlane(e.x,e.y,e.z,t)}projectXYZToPlane(e,t,n,i){const s=this.vectorU.unitCrossProduct(this.vectorV);if(s!==void 0){const o=-s.dotProductStartEndXYZ(this.origin,e,t,n);return y.create(e+o*s.x,t+o*s.y,n+o*s.z,i)}const r=this.vectorU.magnitudeSquared(),a=this.vectorV.magnitudeSquared();if(r>=a){const o=this.vectorU.dotProductStartEndXYZ(this.origin,e,t,n),c=f.conditionalDivideCoordinate(o,r,0);if(c!==void 0)return y.create(e+c*this.vectorU.x,t+c*this.vectorU.y,n+c*this.vectorU.z,i)}else{const o=this.vectorV.dotProductStartEndXYZ(this.origin,e,t,n),c=f.conditionalDivideCoordinate(o,a,0);if(c!==void 0)return y.create(e+c*this.vectorV.x,t+c*this.vectorV.y,n+c*this.vectorV.z,i)}return this.origin.clone(i)}}function Lr(l,e,t,n,i,s){return s*(l-2*i*e-n*t)}class Z extends ks{xyzw;set(e=0,t=0,n=0,i=0){return this.xyzw[0]=e,this.xyzw[1]=t,this.xyzw[2]=n,this.xyzw[3]=i,this}setComponent(e,t){e>=0&&e<4&&(this.xyzw[e]=t)}get x(){return this.xyzw[0]}set x(e){this.xyzw[0]=e}get y(){return this.xyzw[1]}set y(e){this.xyzw[1]=e}get z(){return this.xyzw[2]}set z(e){this.xyzw[2]=e}get w(){return this.xyzw[3]}set w(e){this.xyzw[3]=e}constructor(e=0,t=0,n=0,i=0){super(),this.xyzw=new Float64Array(4),this.xyzw[0]=e,this.xyzw[1]=t,this.xyzw[2]=n,this.xyzw[3]=i}static create(e=0,t=0,n=0,i=0,s){return s?s.set(e,t,n,i):new Z(e,t,n,i)}static createPlaneFrom(e){return new Z(e.normalX(),e.normalY(),e.normalZ(),e.altitudeXYZ(0,0,0))}setFrom(e){return this.xyzw[0]=e.xyzw[0],this.xyzw[1]=e.xyzw[1],this.xyzw[2]=e.xyzw[2],this.xyzw[3]=e.xyzw[3],this}clone(e){return e?e.setFrom(this):new Z(this.xyzw[0],this.xyzw[1],this.xyzw[2],this.xyzw[3])}setFromJSON(e){f.isNumberArray(e,4)?this.set(e[0],e[1],e[2],e[3]):this.set(0,0,0,0)}static fromJSON(e){const t=new Z;return t.setFromJSON(e),t}isAlmostEqual(e,t=f.smallMetricDistance){return f.isSameCoordinate(this.x,e.x,t)&&f.isSameCoordinate(this.y,e.y,t)&&f.isSameCoordinate(this.z,e.z,t)&&f.isSameCoordinate(this.w,e.w,t)}isAlmostEqualXYZW(e,t,n,i,s=f.smallMetricDistance){return f.isSameCoordinate(this.x,e,s)&&f.isSameCoordinate(this.y,t,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(e){return f.hypotenuseXYZW(e.xyzw[0]-this.xyzw[0],e.xyzw[1]-this.xyzw[1],e.xyzw[2]-this.xyzw[2],e.xyzw[3]-this.xyzw[3])}distanceSquaredXYZW(e){return f.hypotenuseSquaredXYZW(e.xyzw[0]-this.xyzw[0],e.xyzw[1]-this.xyzw[1],e.xyzw[2]-this.xyzw[2],e.xyzw[3]-this.xyzw[3])}realDistanceXY(e){const t=this.w,n=e.w;if(!(f.isSmallMetricDistance(t)||f.isSmallMetricDistance(n)))return f.hypotenuseXY(e.xyzw[0]/n-this.xyzw[0]/t,e.xyzw[1]/n-this.xyzw[1]/t)}realDistanceSquaredXY(e){const t=this.w,n=e.w;if(!(f.isSmallMetricDistance(t)||f.isSmallMetricDistance(n)))return f.hypotenuseSquaredXY(e.xyzw[0]/n-this.xyzw[0]/t,e.xyzw[1]/n-this.xyzw[1]/t)}maxDiff(e){return Math.max(Math.abs(e.xyzw[0]-this.xyzw[0]),Math.abs(e.xyzw[1]-this.xyzw[1]),Math.abs(e.xyzw[2]-this.xyzw[2]),Math.abs(e.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(e,t){return Z.create(this.xyzw[0]-e.xyzw[0],this.xyzw[1]-e.xyzw[1],this.xyzw[2]-e.xyzw[2],this.xyzw[3]-e.xyzw[3],t)}crossWeightedMinus(e,t){const n=this.xyzw[3],i=e.xyzw[3];return v.create(i*this.xyzw[0]-n*e.xyzw[0],i*this.xyzw[1]-n*e.xyzw[1],i*this.xyzw[2]-n*e.xyzw[2],t)}crossWeightedMinusPoint3d(e,t){const n=this.xyzw[3];return v.create(this.xyzw[0]-n*e.x,this.xyzw[1]-n*e.y,this.xyzw[2]-n*e.z,t)}plus(e,t){return Z.create(this.xyzw[0]+e.xyzw[0],this.xyzw[1]+e.xyzw[1],this.xyzw[2]+e.xyzw[2],this.xyzw[3]+e.xyzw[3],t)}get isAlmostZero(){return f.isSmallMetricDistance(this.maxAbs())}static createZero(){return new Z(0,0,0,0)}static createPlanePointPointZ(e,t,n){return Z.create(e.y*t.w-e.w*t.y,e.w*t.x-e.x*t.w,0,e.x*t.y-e.y*t.x,n)}static createFromPackedXYZ(e,t=0,n){if(t>=0&&t+2<e.length)return Z.create(e[t],e[t+1],e[t+2],1,n)}static createFromPacked(e,t=0,n){if(t>=0&&t+3<e.length)return Z.create(e[t],e[t+1],e[t+2],e[t+3],n)}static createFromPackedXYZW(e,t=0,n){return Z.create(e[t],e[t+1],e[t+2],e[t+3],n)}static createFromPointAndWeight(e,t){return new Z(e.x,e.y,e.z,t)}static createFromPoint(e){if(e instanceof L)return new Z(e.x,e.y,0,1);if(e instanceof y)return new Z(e.x,e.y,e.z,1);if(e instanceof Z)return e.clone();if(Array.isArray(e)){const r=e.length>0?e[0]:0,a=e.length>1?e[1]:0,o=e.length>2?e[2]:0,c=e.length>3?e[3]:1;return new Z(r,a,o,c)}const t=e.x,n=e.y,i=e.hasOwnProperty("z")?e.z:0,s=e.hasOwnProperty("w")?e.w:1;return new Z(t,n,i,s)}plusScaled(e,t,n){return Z.create(this.xyzw[0]+e.xyzw[0]*t,this.xyzw[1]+e.xyzw[1]*t,this.xyzw[2]+e.xyzw[2]*t,this.xyzw[3]+e.xyzw[3]*t,n)}interpolate(e,t,n){const i=1-e;return Z.create(this.xyzw[0]*i+t.xyzw[0]*e,this.xyzw[1]*i+t.xyzw[1]*e,this.xyzw[2]*i+t.xyzw[2]*e,this.xyzw[3]*i+t.xyzw[3]*e,n)}plus2Scaled(e,t,n,i,s){return Z.create(this.xyzw[0]+e.xyzw[0]*t+n.xyzw[0]*i,this.xyzw[1]+e.xyzw[1]*t+n.xyzw[1]*i,this.xyzw[2]+e.xyzw[2]*t+n.xyzw[2]*i,this.xyzw[3]+e.xyzw[3]*t+n.xyzw[3]*i,s)}plus3Scaled(e,t,n,i,s,r,a){return Z.create(this.xyzw[0]+e.xyzw[0]*t+n.xyzw[0]*i+s.xyzw[0]*r,this.xyzw[1]+e.xyzw[1]*t+n.xyzw[1]*i+s.xyzw[1]*r,this.xyzw[2]+e.xyzw[2]*t+n.xyzw[2]*i+s.xyzw[2]*r,this.xyzw[3]+e.xyzw[3]*t+n.xyzw[3]*i+s.xyzw[3]*r,a)}static createAdd2Scaled(e,t,n,i,s){return Z.create(e.xyzw[0]*t+n.xyzw[0]*i,e.xyzw[1]*t+n.xyzw[1]*i,e.xyzw[2]*t+n.xyzw[2]*i,e.xyzw[3]*t+n.xyzw[3]*i,s)}static createAdd3Scaled(e,t,n,i,s,r,a){return Z.create(e.xyzw[0]*t+n.xyzw[0]*i+s.xyzw[0]*r,e.xyzw[1]*t+n.xyzw[1]*i+s.xyzw[1]*r,e.xyzw[2]*t+n.xyzw[2]*i+s.xyzw[2]*r,e.xyzw[3]*t+n.xyzw[3]*i+s.xyzw[3]*r,a)}dotVectorsToTargets(e,t){return(e.xyzw[0]-this.xyzw[0])*(t.xyzw[0]-this.xyzw[0])+(e.xyzw[1]-this.xyzw[1])*(t.xyzw[1]-this.xyzw[1])+(e.xyzw[2]-this.xyzw[2])*(t.xyzw[2]-this.xyzw[2])+(e.xyzw[3]-this.xyzw[3])*(t.xyzw[3]-this.xyzw[3])}dotProduct(e){return this.xyzw[0]*e.xyzw[0]+this.xyzw[1]*e.xyzw[1]+this.xyzw[2]*e.xyzw[2]+this.xyzw[3]*e.xyzw[3]}dotProductXYZW(e,t,n,i){return this.xyzw[0]*e+this.xyzw[1]*t+this.xyzw[2]*n+this.xyzw[3]*i}altitude(e){return this.xyzw[0]*e.x+this.xyzw[1]*e.y+this.xyzw[2]*e.z+this.xyzw[3]}altitudeXYZ(e,t,n){return this.xyzw[0]*e+this.xyzw[1]*t+this.xyzw[2]*n+this.xyzw[3]}weightedAltitude(e){return this.xyzw[0]*e.x+this.xyzw[1]*e.y+this.xyzw[2]*e.z+this.xyzw[3]*e.w}velocity(e){return this.xyzw[0]*e.x+this.xyzw[1]*e.y+this.xyzw[2]*e.z}velocityXYZ(e,t,n){return this.xyzw[0]*e+this.xyzw[1]*t+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(e,t){if(e!==0)return this.scale(1/e,t)}projectPointToPlane(e,t){return this.projectXYZToPlane(e.x,e.y,e.z,t)}projectXYZToPlane(e,t,n,i){const s=this.altitudeXYZ(e,t,n),r=this.magnitudeSquaredXYZ(),a=f.conditionalDivideCoordinate(-s,r,f.largeFractionResult*f.largeFractionResult);return a===void 0?y.create(e,t,n,i):y.create(e+a*this.x,t+a*this.y,n+a*this.z,i)}scale(e,t){return t=t||new Z,t.xyzw[0]=this.xyzw[0]*e,t.xyzw[1]=this.xyzw[1]*e,t.xyzw[2]=this.xyzw[2]*e,t.xyzw[3]=this.xyzw[3]*e,t}negate(e){return e=e||new Z,e.xyzw[0]=-this.xyzw[0],e.xyzw[1]=-this.xyzw[1],e.xyzw[2]=-this.xyzw[2],e.xyzw[3]=-this.xyzw[3],e}normalizeWeight(e){const t=f.correctSmallFraction(this.xyzw[3]);return e=e||new Z,this.safeDivideOrNull(t,e)}realPoint(e){const t=f.correctSmallFraction(this.xyzw[3]);if(t===0)return;const n=1/t;return y.create(this.xyzw[0]*n,this.xyzw[1]*n,this.xyzw[2]*n,e)}realPointOrVector(){const e=f.correctSmallFraction(this.xyzw[3]);if(e===0)return v.create(this.x,this.y,this.z);const t=1/e;return y.create(this.x*t,this.y*t,this.z*t)}static createRealPoint3dDefault000(e,t,n,i,s){const r=f.correctSmallFraction(i),a=r===0?0:1/r;return y.create(e*a,t*a,n*a,s)}static createRealDerivativeRay3dDefault000(e,t,n,i,s,r,a,o,c){const d=f.correctSmallFraction(i),h=d===0?0:1/d,u=h*h;return q.createXYZUVW(e*h,t*h,n*h,(s*i-o*e)*u,(r*i-o*t)*u,(a*i-o*n)*u,c)}static createRealDerivativePlane3dByOriginAndVectorsDefault000(e,t,n,i,s,r,a,o,c,d,h,u,g){const m=f.correctSmallFraction(i),p=m===0?0:1/m,x=p*p,_=e*p,I=t*p,S=n*p,A=(s*i-o*e)*x,w=(r*i-o*t)*x,k=(a*i-o*n)*x;return ke.createOriginAndVectorsXYZ(_,I,S,A,w,k,Lr(c,o,u,_,A,p),Lr(d,o,u,I,w,p),Lr(h,o,u,S,k,p),g)}realPointDefault000(e){const t=f.correctSmallFraction(this.xyzw[3]);if(t===0)return y.create(0,0,0,e);e=e||new y;const n=1/t;return y.create(this.xyzw[0]*n,this.xyzw[1]*n,this.xyzw[2]*n,e)}normalizeXYZW(e){const t=f.correctSmallFraction(this.magnitudeXYZW());return e=e||new Z,this.safeDivideOrNull(t,e)}static determinantIndexed3X3(e,t,n,i,s,r){return f.tripleProduct(e.xyzw[i],e.xyzw[s],e.xyzw[r],t.xyzw[i],t.xyzw[s],t.xyzw[r],n.xyzw[i],n.xyzw[s],n.xyzw[r])}static perpendicularPoint4dPlane(e,t,n){return Z.create(Z.determinantIndexed3X3(e,t,n,1,2,3),-Z.determinantIndexed3X3(e,t,n,2,3,0),Z.determinantIndexed3X3(e,t,n,3,0,1),-Z.determinantIndexed3X3(e,t,n,0,1,2))}toPlane3dByOriginAndUnitNormal(e){return pe.createFrom(this,e)}normalizeQuaternion(){const e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(e>0){const t=1/e;this.x*=t,this.y*=t,this.z*=t,this.w*=t}return e}static interpolateQuaternions(e,t,n,i){i||(i=new Z);const s=.9995;if(t===0)return i=e,i;if(t===1)return i=n,i;if(t===.5)return e.plus(n,i),i.normalizeQuaternion(),i;const r=e.clone(),a=n.clone();let o=e.dotProduct(n);if(o<0&&(a.negate(a),o=-o),o>s)return r.interpolate(t,a,i),i.normalizeQuaternion(),i;o<-1?o=-1:o>1&&(o=1);const c=new Z;a.plusScaled(r,-o,c),c.normalizeQuaternion();const h=Math.acos(o)*t;return i=Z.createAdd2Scaled(r,Math.cos(h),c,Math.sin(h)),i}radiansToPoint4dXYZW(e){const t=this.magnitudeXYZW(),n=e.magnitudeXYZW(),i=this.dotProduct(e),s=f.conditionalDivideFraction(i,t*n);if(s!==void 0)return Math.acos(s)}}class We{static loadMatrix(e,t,n,i,s,r,a,o,c,d){e[0]=t,e[1]=n,e[2]=i,e[3]=s,e[4]=r,e[5]=a,e[6]=o,e[7]=c,e[8]=d}static multiplyMatrixMatrix(e,t,n){return(!n||n.length<9)&&(n=new Float64Array(9)),We.loadMatrix(n,e[0]*t[0]+e[1]*t[3]+e[2]*t[6],e[0]*t[1]+e[1]*t[4]+e[2]*t[7],e[0]*t[2]+e[1]*t[5]+e[2]*t[8],e[3]*t[0]+e[4]*t[3]+e[5]*t[6],e[3]*t[1]+e[4]*t[4]+e[5]*t[7],e[3]*t[2]+e[4]*t[5]+e[5]*t[8],e[6]*t[0]+e[7]*t[3]+e[8]*t[6],e[6]*t[1]+e[7]*t[4]+e[8]*t[7],e[6]*t[2]+e[7]*t[5]+e[8]*t[8]),n}static multiplyMatrixMatrixTranspose(e,t,n){return(!n||n.length<9)&&(n=new Float64Array(9)),We.loadMatrix(n,e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[0]*t[3]+e[1]*t[4]+e[2]*t[5],e[0]*t[6]+e[1]*t[7]+e[2]*t[8],e[3]*t[0]+e[4]*t[1]+e[5]*t[2],e[3]*t[3]+e[4]*t[4]+e[5]*t[5],e[3]*t[6]+e[4]*t[7]+e[5]*t[8],e[6]*t[0]+e[7]*t[1]+e[8]*t[2],e[6]*t[3]+e[7]*t[4]+e[8]*t[5],e[6]*t[6]+e[7]*t[7]+e[8]*t[8]),n}static multiplyMatrixTransposeMatrix(e,t,n){return(!n||n.length<9)&&(n=new Float64Array(9)),We.loadMatrix(n,e[0]*t[0]+e[3]*t[3]+e[6]*t[6],e[0]*t[1]+e[3]*t[4]+e[6]*t[7],e[0]*t[2]+e[3]*t[5]+e[6]*t[8],e[1]*t[0]+e[4]*t[3]+e[7]*t[6],e[1]*t[1]+e[4]*t[4]+e[7]*t[7],e[1]*t[2]+e[4]*t[5]+e[7]*t[8],e[2]*t[0]+e[5]*t[3]+e[8]*t[6],e[2]*t[1]+e[5]*t[4]+e[8]*t[7],e[2]*t[2]+e[5]*t[5]+e[8]*t[8]),n}static transposeInPlace(e){let t=e[1];e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t}static copyTransposed(e,t){return t===e?We.transposeInPlace(t):((!t||t.length<9)&&(t=new Float64Array(9)),t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8]),t}static copy(e,t){return t!==e&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8]),t}}var se;(function(l){l[l.unknown=0]="unknown",l[l.inverseStored=1]="inverseStored",l[l.singular=2]="singular"})(se||(se={}));class E{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=E.createIdentity(),this._identity.freeze()),this._identity}freeze(){return this.computeCachedInverse(!0),Object.freeze(this)}constructor(e){this.coffs=e&&e.length>=9?e:new Float64Array(9),this.inverseCoffs=void 0,this.inverseState=se.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(e){if(this.inverseCoffs=void 0,!e){this.setRowValues(0,0,0,0,0,0,0,0,0);return}if(!Array.isArray(e)){e instanceof E&&this.setFrom(e);return}if(f.isArrayOfNumberArray(e,3,3)){this.setRowValues(e[0][0],e[0][1],e[0][2],e[1][0],e[1][1],e[1][2],e[2][0],e[2][1],e[2][2]);return}if(e.length===9){this.setRowValues(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8]);return}else if(e.length===4){this.setRowValues(e[0],e[1],0,e[2],e[3],0,0,0,1);return}this.setRowValues(0,0,0,0,0,0,0,0,0)}static fromJSON(e){const t=E.createIdentity();return t.setFromJSON(e),t}isAlmostEqual(e,t){return f.isDistanceWithinTol(this.maxDiff(e),t)}isAlmostEqualColumn(e,t,n){const i=f.maxAbsXYZ(this.coffs[e]-t.coffs[e],this.coffs[e+3]-t.coffs[e+3],this.coffs[e+6]-t.coffs[e+6]);return f.isDistanceWithinTol(i,n)}isAlmostEqualColumnXYZ(e,t,n,i,s){const r=f.maxAbsXYZ(this.coffs[e]-t,this.coffs[e+3]-n,this.coffs[e+6]-i);return f.isDistanceWithinTol(r,s)}isAlmostEqualAllowZRotation(e,t){if(this.isAlmostEqual(e,t))return!0;if(!this.isAlmostEqualColumn(Jt.Z,e,t))return!1;const n=this.columnX(),i=this.columnY(),s=this.columnZ(),r=n.signedAngleTo(e.columnX(),s);let a=v.createRotateVectorAroundVector(n,s,r);return!(!a||!e.isAlmostEqualColumnXYZ(0,a.x,a.y,a.z,t)||(a=v.createRotateVectorAroundVector(i,s,r),!a)||!e.isAlmostEqualColumnXYZ(1,a.x,a.y,a.z,t))}isExactEqual(e){return this.maxDiff(e)===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(e){return e||new E}static createRowValues(e,t,n,i,s,r,a,o,c,d){return d=d||new E,d.inverseState=se.unknown,d.coffs[0]=e,d.coffs[1]=t,d.coffs[2]=n,d.coffs[3]=i,d.coffs[4]=s,d.coffs[5]=r,d.coffs[6]=a,d.coffs[7]=o,d.coffs[8]=c,d}static createCapture(e,t){const n=new E(e);return t&&t.length>=9?(n.inverseCoffs=t,n.inverseState=se.inverseStored):n.inverseState=se.unknown,n}static createColumnsInAxisOrder(e,t,n,i,s){return s||(s=new E),e===ve.YZX?s.setColumns(i,t,n):e===ve.ZXY?s.setColumns(n,i,t):e===ve.XZY?s.setColumns(t,i,n):e===ve.YXZ?s.setColumns(n,t,i):e===ve.ZYX?s.setColumns(i,n,t):s.setColumns(t,n,i),s}createInverseCoffsWithZeros(){return this.inverseCoffs||(this.inverseState=se.unknown,this.inverseCoffs=new Float64Array(9)),this.inverseCoffs!==void 0}setupInverseTranspose(){const e=this.coffs;this.inverseState=se.inverseStored,this.inverseCoffs=Float64Array.from([e[0],e[3],e[6],e[1],e[4],e[7],e[2],e[5],e[8]])}setRowValues(e,t,n,i,s,r,a,o,c){this.coffs[0]=e,this.coffs[1]=t,this.coffs[2]=n,this.coffs[3]=i,this.coffs[4]=s,this.coffs[5]=r,this.coffs[6]=a,this.coffs[7]=o,this.coffs[8]=c,this.inverseState=se.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=se.singular}setFrom(e){if(e===void 0){this.setIdentity();return}if(e!==this){for(let t=0;t<9;t++)this.coffs[t]=e.coffs[t];if(e.inverseState===se.inverseStored&&e.inverseCoffs!==void 0){if(this.createInverseCoffsWithZeros()){for(let t=0;t<9;t++)this.inverseCoffs[t]=e.inverseCoffs[t];this.inverseState=se.inverseStored}}else e.inverseState!==se.inverseStored?this.inverseState=e.inverseState:this.inverseState=se.unknown}}clone(e){return e=e||new E,e.setFrom(this),e}static createZero(){const e=new E;return e.inverseState=se.singular,e}static createIdentity(e){return e=e||new E,e.setIdentity(),e}static createScale(e,t,n,i){return i?i.setZero():i=new E,i.coffs[0]=e,i.coffs[4]=t,i.coffs[8]=n,e===0||t===0||n===0?i.inverseState=se.singular:(i.inverseState=se.inverseStored,i.inverseCoffs=Float64Array.from([1/e,0,0,0,1/t,0,0,0,1/n])),i}static createUniformScale(e){return E.createScale(e,e,e)}static createPerpendicularVectorFavorXYPlane(e,t){const s=e.magnitude()/64;return Math.abs(e.x)<s&&Math.abs(e.y)<s?v.createCrossProduct(e.x,e.y,e.z,0,-1,0,t):v.createCrossProduct(0,0,1,e.x,e.y,e.z,t)}static createPerpendicularVectorFavorPlaneContainingZ(e,t){return t=E.createPerpendicularVectorFavorXYPlane(e,t),e.crossProduct(t,t)}static createShuffledColumns(e,t,n,i,s){const r=E._create(s);return r.setColumn(f.axisOrderToAxis(i,0),e),r.setColumn(f.axisOrderToAxis(i,1),t),r.setColumn(f.axisOrderToAxis(i,2),n),r.inverseState=se.unknown,r}static createRigidFromColumns(e,t,n,i){const s=e.normalize();if(s){const r=s.unitCrossProduct(t);if(r){const a=r.unitCrossProduct(e);if(a){const o=E.createShuffledColumns(s,a,r,n,i);return o.setupInverseTranspose(),o}}}}static createRigidHeadsUp(e,t=ve.ZXY,n){const i=E.createPerpendicularVectorFavorXYPlane(e),s=E.createRigidFromColumns(e,i,t,n);return s?(s.setupInverseTranspose(),s):E.createIdentity(n)}static createRotationAroundVector(e,t,n){const i=t.cos(),s=t.sin(),r=1-i,a=e.normalize();if(a){const o=E.createRowValues(a.x*a.x*r+i,a.x*a.y*r-s*a.z,a.x*a.z*r+s*a.y,a.y*a.x*r+s*a.z,a.y*a.y*r+i,a.y*a.z*r-s*a.x,a.z*a.x*r-s*a.y,a.z*a.y*r+s*a.x,a.z*a.z*r+i,n);return o.setupInverseTranspose(),o}}static createRotationAroundAxisIndex(e,t,n){const i=t.cos(),s=t.sin();let r;return e===Jt.X?r=E.createRowValues(1,0,0,0,i,-s,0,s,i,n):e===Jt.Y?r=E.createRowValues(i,0,s,0,1,0,-s,0,i,n):r=E.createRowValues(i,-s,0,s,i,0,0,0,1,n),r.setupInverseTranspose(),r}applyGivensRowOp(e,t,n,i){let s=3*e,r=3*t;const a=s+3;for(;s<a;s++,r++){const o=this.coffs[s],c=this.coffs[r];this.coffs[s]=o*n+c*i,this.coffs[r]=-o*i+c*n}}applyGivensColumnOp(e,t,n,i){const s=e+9;for(;e<s;e+=3,t+=3){const r=this.coffs[e],a=this.coffs[t];this.coffs[e]=r*n+a*i,this.coffs[t]=-r*i+a*n}}static createColumns(e,t,n,i){return E.createRowValues(e.x,t.x,n.x,e.y,t.y,n.y,e.z,t.z,n.z,i)}static createColumnsXYW(e,t,n,i,s,r,a){return E.createRowValues(e.x,n.x,s.x,e.y,n.y,s.y,t,i,r,a)}static createViewedAxes(e,t,n=0,i=0){const s=e.crossProduct(t);if(s.normalizeInPlace()){const r=E.createColumns(e,t,s);if(n!==0){let a=Math.sqrt(.5),o=n<0?-a:a;if(Math.abs(n)!==1){const c=T.degreesToRadians(45*n);a=Math.cos(c),o=Math.sin(c)}r.applyGivensColumnOp(2,0,a,o)}if(i!==0){const a=i*Math.atan(Math.sqrt(.5)),o=Math.cos(a),c=Math.sin(a);r.applyGivensColumnOp(1,2,o,-c)}return r}}static createStandardWorldToView(e,t=!1,n){switch(e){case Tn.Bottom:n=E.createRowValues(1,0,0,0,-1,0,0,0,-1);break;case Tn.Left:n=E.createRowValues(0,-1,0,0,0,1,-1,0,0);break;case Tn.Right:n=E.createRowValues(0,1,0,0,0,1,1,0,0);break;case Tn.Front:n=E.createRowValues(1,0,0,0,0,1,0,-1,0);break;case Tn.Back:n=E.createRowValues(-1,0,0,0,0,1,0,1,0);break;case Tn.Iso:n=E.createRowValues(.707106781186548,-.7071067811865476,0,.408248290463863,.408248290463863,.816496580927726,-.577350269189626,-.5773502691896257,.5773502691896257);break;case Tn.RightIso:n=E.createRowValues(.707106781186548,.7071067811865476,0,-.408248290463863,.408248290463863,.816496580927726,.577350269189626,-.5773502691896257,.5773502691896257);break;case Tn.Top:default:n=E.createIdentity(n)}return t&&n.transposeInPlace(),n}applySymmetricJacobi(e,t,n,i){const s=i.at(e,e),r=i.at(t,t),a=i.at(e,t);if(Math.abs(a)<f.smallFloatingPoint*(s+r))return 0;const o=T.trigValuesToHalfAngleTrigValues(s-r,2*a),c=o.c,d=o.s;return Math.abs(d)<2e-15?0:(i.applyGivensRowOp(e,t,c,d),i.applyGivensColumnOp(e,t,c,d),n.applyGivensColumnOp(e,t,c,d),Math.abs(a))}symmetricEigenvalues(e,t){const n=this.clone();e.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,e,n)+this.applySymmetricJacobi(0,2,e,n)+this.applySymmetricJacobi(1,2,e,n)<i)return t.set(n.at(0,0),n.at(1,1),n.at(2,2)),!0;return!1}applyFastSymmetricJacobi(e,t,n,i){const s=4*e,r=4*t,a=3*e+t,o=3*t+e,c=3*e+n,d=3*n+e,h=3*t+n,u=3*n+t,g=this.coffs[s],m=this.coffs[r],p=this.coffs[a];if(Math.abs(p)<f.smallFloatingPoint*(g+m))return 0;const x=T.trigValuesToHalfAngleTrigValues(g-m,2*p),_=x.c,I=x.s,S=_*_,A=I*I,w=2*_*I;this.coffs[s]=S*g+w*p+A*m,this.coffs[r]=A*g-w*p+S*m,this.coffs[a]=0,this.coffs[o]=0;const k=this.coffs[c],D=this.coffs[h];return this.coffs[c]=_*k+I*D,this.coffs[h]=-I*k+_*D,this.coffs[d]=this.coffs[c],this.coffs[u]=this.coffs[h],i.applyGivensColumnOp(e,t,_,I),Math.abs(p)}fastSymmetricEigenvalues(e,t){const n=this.clone();e.setIdentity();const i=1e-12*this.sumSquares(),s=7;for(let r=0;r<s;r++)if(n.applyFastSymmetricJacobi(0,1,2,e)+n.applyFastSymmetricJacobi(0,2,1,e)+n.applyFastSymmetricJacobi(1,2,0,e)<i)return t.set(n.at(0,0),n.at(1,1),n.at(2,2)),!0;return!1}getAxisAndAngleOfRotation(){const e=this.coffs[0]+this.coffs[4]+this.coffs[8],t=this.coffs[3]-this.coffs[1],n=this.coffs[7]-this.coffs[5],i=this.coffs[2]-this.coffs[6],s=(e-1)/2,r=f.hypotenuseXYZ(t,n,i)/2,a=s*s+r*r-1;if(Math.abs(a)>f.smallAngleRadians)return{axis:v.create(0,0,1),angle:T.createRadians(0),ok:!1};if(Math.abs(r)<f.smallAngleRadians){if(s>0)return{axis:v.create(0,0,1),angle:T.createRadians(0),ok:!0};const d=this.coffs[0],h=this.coffs[4],u=this.coffs[8];if(f.isAlmostEqualNumber(-1,h)&&f.isAlmostEqualNumber(-1,u))return{axis:v.create(1,0,0),angle:T.createDegrees(180),ok:!0};if(f.isAlmostEqualNumber(-1,d)&&f.isAlmostEqualNumber(-1,u))return{axis:v.create(0,1,0),angle:T.createDegrees(180),ok:!0};if(f.isAlmostEqualNumber(-1,d)&&f.isAlmostEqualNumber(-1,h))return{axis:v.create(0,0,1),angle:T.createDegrees(180),ok:!0};const g=E.createIdentity(),m=v.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:T.createDegrees(180),ok:!0}}return{axis:v.create(0,0,1),angle:T.createRadians(0),ok:!1}}return{axis:v.create(0,0,1),angle:T.createRadians(0),ok:!1}}const o=1/(2*r);return{axis:v.create(n*o,i*o,t*o),angle:T.createAtan2(r,s),ok:!0}}applyJacobiColumnRotation(e,t,n){const i=this.coffs[e]*this.coffs[e]+this.coffs[e+3]*this.coffs[e+3]+this.coffs[e+6]*this.coffs[e+6],s=this.coffs[t]*this.coffs[t]+this.coffs[t+3]*this.coffs[t+3]+this.coffs[t+6]*this.coffs[t+6],r=this.coffs[e]*this.coffs[t]+this.coffs[e+3]*this.coffs[t+3]+this.coffs[e+6]*this.coffs[t+6],a=T.trigValuesToHalfAngleTrigValues(i-s,2*r),o=a.c,c=a.s;return Math.abs(c)<2e-15?0:(this.applyGivensColumnOp(e,t,o,c),n.applyGivensRowOp(e,t,o,c),Math.abs(r))}factorPerpendicularColumns(e,t){e.setFrom(this),t.setIdentity();const n=1e-12*this.sumSquares(),i=7;for(let s=0;s<i;s++)if(e.applyJacobiColumnRotation(0,1,t)+e.applyJacobiColumnRotation(0,2,t)+e.applyJacobiColumnRotation(1,2,t)<n)return!0;return!1}factorOrthogonalScaleOrthogonal(e,t,n){const i=E.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)),t.set(s[0].magnitude(),s[1].magnitude(),s[2].magnitude()),i.determinant()<0&&(t.z=-t.z);const a=f.smallFloatingPoint,o=Math.abs(t.x)<a,c=Math.abs(t.y)<a,d=Math.abs(t.z)<a;return!o&&!c&&!d?e=i.scaleColumns(1/t.x,1/t.y,1/t.z,e):!o&&!c?(s[0].scaleInPlace(1/t.x),s[1].scaleInPlace(1/t.y),s[0].unitCrossProduct(s[1],s[2]),e.setColumns(s[0],s[1],s[2])):o?e.setIdentity():e=E.createRigidHeadsUp(s[0],ve.XYZ,e),!0}static createPartialRotationVectorToVector(e,t,n,i){let s=e.unitCrossProduct(n);if(s)return E.createRotationAroundVector(s,T.createRadians(t*e.planarAngleTo(n,s).radians),i);if(!(f.isSmallMetricDistance(e.magnitude())||f.isSmallMetricDistance(n.magnitude())))return e.dotProduct(n)>0?E.createIdentity(i):(s=E.createPerpendicularVectorFavorPlaneContainingZ(e,s),E.createRotationAroundVector(s,T.createRadians(t*Math.PI),i))}static createRotationVectorToVector(e,t,n){return this.createPartialRotationVectorToVector(e,1,t,n)}static create90DegreeRotationAroundAxis(e){if(e=f.cyclic3dAxis(e),e===0){const t=E.createRowValues(1,0,0,0,0,-1,0,1,0);return t.setupInverseTranspose(),t}else if(e===1){const t=E.createRowValues(0,0,1,0,1,0,-1,0,0);return t.setupInverseTranspose(),t}else{const t=E.createRowValues(0,-1,0,1,0,0,0,0,1);return t.setupInverseTranspose(),t}}columnX(e){return v.create(this.coffs[0],this.coffs[3],this.coffs[6],e)}columnY(e){return v.create(this.coffs[1],this.coffs[4],this.coffs[7],e)}columnZ(e){return v.create(this.coffs[2],this.coffs[5],this.coffs[8],e)}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(e){return f.crossProductXYZXYZ(this.coffs[0],this.coffs[3],this.coffs[6],this.coffs[1],this.coffs[4],this.coffs[7],e)}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(e,t,n,i){return this.coffs[e]*t+this.coffs[e+3]*n+this.coffs[e+6]*i}rowX(e){return v.create(this.coffs[0],this.coffs[1],this.coffs[2],e)}rowY(e){return v.create(this.coffs[3],this.coffs[4],this.coffs[5],e)}rowZ(e){return v.create(this.coffs[6],this.coffs[7],this.coffs[8],e)}dotColumnX(e){return e.x*this.coffs[0]+e.y*this.coffs[3]+e.z*this.coffs[6]}dotColumnY(e){return e.x*this.coffs[1]+e.y*this.coffs[4]+e.z*this.coffs[7]}dotColumnZ(e){return e.x*this.coffs[2]+e.y*this.coffs[5]+e.z*this.coffs[8]}dotRowX(e){return e.x*this.coffs[0]+e.y*this.coffs[1]+e.z*this.coffs[2]}dotRowY(e){return e.x*this.coffs[3]+e.y*this.coffs[4]+e.z*this.coffs[5]}dotRowZ(e){return e.x*this.coffs[6]+e.y*this.coffs[7]+e.z*this.coffs[8]}dotRowXXYZ(e,t,n){return e*this.coffs[0]+t*this.coffs[1]+n*this.coffs[2]}dotRowYXYZ(e,t,n){return e*this.coffs[3]+t*this.coffs[4]+n*this.coffs[5]}dotRowZXYZ(e,t,n){return e*this.coffs[6]+t*this.coffs[7]+n*this.coffs[8]}columnZCrossVector(e,t){return f.crossProductXYZXYZ(this.coffs[2],this.coffs[5],this.coffs[8],e.x,e.y,e.z,t)}setColumnsPoint4dXYZ(e,t,n){this.inverseState=se.unknown,this.setRowValues(e.x,t.x,n.x,e.y,t.y,n.y,e.z,t.z,n.z)}setColumn(e,t){const n=f.cyclic3dAxis(e);this.inverseState=se.unknown,t?(this.coffs[n]=t.x,this.coffs[n+3]=t.y,this.coffs[n+6]=t.z):(this.coffs[n]=0,this.coffs[n+3]=0,this.coffs[n+6]=0)}setColumns(e,t,n){this.setColumn(0,e),this.setColumn(1,t),this.setColumn(2,n)}setRow(e,t){const n=3*f.cyclic3dAxis(e);this.coffs[n]=t.x,this.coffs[n+1]=t.y,this.coffs[n+2]=t.z,this.inverseState=se.unknown}getColumn(e,t){const n=f.cyclic3dAxis(e);return v.create(this.coffs[n],this.coffs[n+3],this.coffs[n+6],t)}getRow(e,t){const n=3*f.cyclic3dAxis(e);return v.create(this.coffs[n],this.coffs[n+1],this.coffs[n+2],t)}static createRows(e,t,n,i){return E.createRowValues(e.x,e.y,e.z,t.x,t.y,t.z,n.x,n.y,n.z,i)}static createDirectionalScale(e,t,n){const i=e.normalize();if(i){const s=i.x,r=i.y,a=i.z,o=t-1;return E.createRowValues(1+o*s*s,o*s*r,o*s*a,o*r*s,1+o*r*r,o*r*a,o*a*s,o*a*r,1+o*a*a,n)}return E.createUniformScale(t)}static createFlattenAlongVectorToPlane(e,t){const n=E.createIdentity(),i=e.dotProduct(t),s=f.conditionalDivideCoordinate(1,-i);if(s!==void 0)return n.addScaledOuterProductInPlace(e,t,s),n}multiplyPoint(e,t){const n=e.x,i=e.y,s=e.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,t)}multiplyVector(e,t){const n=e.x,i=e.y,s=e.z;return v.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,t)}multiplyVectorArrayInPlace(e){for(const t of e)t.set(this.coffs[0]*t.x+this.coffs[1]*t.y+this.coffs[2]*t.z,this.coffs[3]*t.x+this.coffs[4]*t.y+this.coffs[5]*t.z,this.coffs[6]*t.x+this.coffs[7]*t.y+this.coffs[8]*t.z)}static xyzMinusMatrixTimesXYZ(e,t,n,i){const s=n.x,r=n.y,a=n.z;return y.create(e.x-(t.coffs[0]*s+t.coffs[1]*r+t.coffs[2]*a),e.y-(t.coffs[3]*s+t.coffs[4]*r+t.coffs[5]*a),e.z-(t.coffs[6]*s+t.coffs[7]*r+t.coffs[8]*a),i)}static xyPlusMatrixTimesXY(e,t,n,i){const s=n.x,r=n.y;return L.create(e.x+t.coffs[0]*s+t.coffs[1]*r,e.y+t.coffs[3]*s+t.coffs[4]*r,i)}static xyzPlusMatrixTimesXYZ(e,t,n,i){const s=n.x,r=n.y,a=n.z;return y.create(e.x+t.coffs[0]*s+t.coffs[1]*r+t.coffs[2]*a,e.y+t.coffs[3]*s+t.coffs[4]*r+t.coffs[5]*a,e.z+t.coffs[6]*s+t.coffs[7]*r+t.coffs[8]*a,i)}static xyzPlusMatrixTimesXYZInPlace(e,t,n){const i=n.x,s=n.y,r=n.z;n.x=e.x+t.coffs[0]*i+t.coffs[1]*s+t.coffs[2]*r,n.y=e.y+t.coffs[3]*i+t.coffs[4]*s+t.coffs[5]*r,n.z=e.z+t.coffs[6]*i+t.coffs[7]*s+t.coffs[8]*r}static xyzPlusMatrixTimesCoordinates(e,t,n,i,s,r){return y.create(e.x+t.coffs[0]*n+t.coffs[1]*i+t.coffs[2]*s,e.y+t.coffs[3]*n+t.coffs[4]*i+t.coffs[5]*s,e.z+t.coffs[6]*n+t.coffs[7]*i+t.coffs[8]*s,r)}static xyzPlusMatrixTimesWeightedCoordinates(e,t,n,i,s,r,a){return Z.create(t.coffs[0]*n+t.coffs[1]*i+t.coffs[2]*s+e.x*r,t.coffs[3]*n+t.coffs[4]*i+t.coffs[5]*s+e.y*r,t.coffs[6]*n+t.coffs[7]*i+t.coffs[8]*s+e.z*r,r,a)}static xyzPlusMatrixTimesWeightedCoordinatesToFloat64Array(e,t,n,i,s,r,a){return(!a||a.length<4)&&(a=new Float64Array(4)),a[0]=t.coffs[0]*n+t.coffs[1]*i+t.coffs[2]*s+e.x*r,a[1]=t.coffs[3]*n+t.coffs[4]*i+t.coffs[5]*s+e.y*r,a[2]=t.coffs[6]*n+t.coffs[7]*i+t.coffs[8]*s+e.z*r,a[3]=r,a}static xyzPlusMatrixTimesCoordinatesToFloat64Array(e,t,n,i,s,r){return(!r||r.length<3)&&(r=new Float64Array(3)),r[0]=t.coffs[0]*n+t.coffs[1]*i+t.coffs[2]*s+e.x,r[1]=t.coffs[3]*n+t.coffs[4]*i+t.coffs[5]*s+e.y,r[2]=t.coffs[6]*n+t.coffs[7]*i+t.coffs[8]*s+e.z,r}multiplyTransposeVector(e,t){t=t||new v;const n=e.x,i=e.y,s=e.z;return t.x=this.coffs[0]*n+this.coffs[3]*i+this.coffs[6]*s,t.y=this.coffs[1]*n+this.coffs[4]*i+this.coffs[7]*s,t.z=this.coffs[2]*n+this.coffs[5]*i+this.coffs[8]*s,t}multiplyXYZ(e,t,n,i){return i=i||new v,i.x=this.coffs[0]*e+this.coffs[1]*t+this.coffs[2]*n,i.y=this.coffs[3]*e+this.coffs[4]*t+this.coffs[5]*n,i.z=this.coffs[6]*e+this.coffs[7]*t+this.coffs[8]*n,i}multiplyXYZtoXYZ(e,t){const n=e.x,i=e.y,s=e.z;return t.x=this.coffs[0]*n+this.coffs[1]*i+this.coffs[2]*s,t.y=this.coffs[3]*n+this.coffs[4]*i+this.coffs[5]*s,t.z=this.coffs[6]*n+this.coffs[7]*i+this.coffs[8]*s,t}multiplyXY(e,t,n){return n=n||new v,n.x=this.coffs[0]*e+this.coffs[1]*t,n.y=this.coffs[3]*e+this.coffs[4]*t,n.z=this.coffs[6]*e+this.coffs[7]*t,n}originPlusMatrixTimesXY(e,t,n,i){return y.create(e.x+this.coffs[0]*t+this.coffs[1]*n,e.y+this.coffs[3]*t+this.coffs[4]*n,e.z+this.coffs[6]*t+this.coffs[7]*n,i)}multiplyVectorInPlace(e){const t=e.x,n=e.y,i=e.z;e.x=this.coffs[0]*t+this.coffs[1]*n+this.coffs[2]*i,e.y=this.coffs[3]*t+this.coffs[4]*n+this.coffs[5]*i,e.z=this.coffs[6]*t+this.coffs[7]*n+this.coffs[8]*i}multiplyTransposeVectorInPlace(e){const t=e.x,n=e.y,i=e.z;e.x=this.coffs[0]*t+this.coffs[3]*n+this.coffs[6]*i,e.y=this.coffs[1]*t+this.coffs[4]*n+this.coffs[7]*i,e.z=this.coffs[2]*t+this.coffs[5]*n+this.coffs[8]*i}multiplyTransposeXYZ(e,t,n,i){return i=i||new v,i.x=this.coffs[0]*e+this.coffs[3]*t+this.coffs[6]*n,i.y=this.coffs[1]*e+this.coffs[4]*t+this.coffs[7]*n,i.z=this.coffs[2]*e+this.coffs[5]*t+this.coffs[8]*n,i}multiplyInverse(e,t){if(this.computeCachedInverse(!0),this.inverseCoffs){const n=e.x,i=e.y,s=e.z;return v.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,t)}}multiplyInverseTranspose(e,t){if(this.computeCachedInverse(!0),this.inverseCoffs){const n=e.x,i=e.y,s=e.z;return v.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,t)}}multiplyInverseXYZAsVector3d(e,t,n,i){if(this.computeCachedInverse(!0),this.inverseCoffs)return v.create(this.inverseCoffs[0]*e+this.inverseCoffs[1]*t+this.inverseCoffs[2]*n,this.inverseCoffs[3]*e+this.inverseCoffs[4]*t+this.inverseCoffs[5]*n,this.inverseCoffs[6]*e+this.inverseCoffs[7]*t+this.inverseCoffs[8]*n,i)}multiplyInverseXYZW(e,t,n,i,s){if(this.computeCachedInverse(!0),this.inverseCoffs)return Z.create(this.inverseCoffs[0]*e+this.inverseCoffs[1]*t+this.inverseCoffs[2]*n,this.inverseCoffs[3]*e+this.inverseCoffs[4]*t+this.inverseCoffs[5]*n,this.inverseCoffs[6]*e+this.inverseCoffs[7]*t+this.inverseCoffs[8]*n,i,s)}multiplyInverseXYZAsPoint3d(e,t,n,i){if(this.computeCachedInverse(!0),this.inverseCoffs)return y.create(this.inverseCoffs[0]*e+this.inverseCoffs[1]*t+this.inverseCoffs[2]*n,this.inverseCoffs[3]*e+this.inverseCoffs[4]*t+this.inverseCoffs[5]*n,this.inverseCoffs[6]*e+this.inverseCoffs[7]*t+this.inverseCoffs[8]*n,i)}multiplyInverseXYZAsPoint2d(e,t,n,i){if(this.computeCachedInverse(!0))return L.create(this.inverseCoffs[0]*e+this.inverseCoffs[1]*t+this.inverseCoffs[2]*n,this.inverseCoffs[3]*e+this.inverseCoffs[4]*t+this.inverseCoffs[5]*n,i)}finishInverseCoffs(e,t,n){t&&n&&this.createInverseCoffsWithZeros()?(this.inverseState=se.inverseStored,e(t,n,this.inverseCoffs)):this.inverseState=se.unknown}multiplyMatrixMatrix(e,t){return t=t||new E,We.multiplyMatrixMatrix(this.coffs,e.coffs,t.coffs),this.inverseState===se.inverseStored&&e.inverseState===se.inverseStored?t.finishInverseCoffs((n,i,s)=>We.multiplyMatrixMatrix(n,i,s),e.inverseCoffs,this.inverseCoffs):this.inverseState===se.singular||e.inverseState===se.singular?t.inverseState=se.singular:t.inverseState=se.unknown,t}multiplyMatrixMatrixInverse(e,t){if(e.computeCachedInverse(!0))return t=t||new E,We.multiplyMatrixMatrix(this.coffs,e.inverseCoffs,E._productBuffer),this.inverseState===se.inverseStored?t.finishInverseCoffs((n,i,s)=>We.multiplyMatrixMatrix(n,i,s),e.coffs,this.inverseCoffs):t.inverseState=se.unknown,We.copy(E._productBuffer,t.coffs),t}multiplyMatrixInverseMatrix(e,t){if(this.computeCachedInverse(!0))return We.multiplyMatrixMatrix(this.inverseCoffs,e.coffs,E._productBuffer),t=t||new E,e.inverseState===se.inverseStored?t.finishInverseCoffs((n,i,s)=>We.multiplyMatrixMatrix(n,i,s),e.inverseCoffs,this.coffs):t.inverseState=se.unknown,We.copy(E._productBuffer,t.coffs),t}multiplyMatrixMatrixTranspose(e,t){return t=t||new E,We.multiplyMatrixMatrixTranspose(this.coffs,e.coffs,t.coffs),this.inverseState===se.inverseStored&&e.inverseState===se.inverseStored?t.finishInverseCoffs((n,i,s)=>We.multiplyMatrixTransposeMatrix(n,i,s),e.inverseCoffs,this.inverseCoffs):this.inverseState===se.singular||e.inverseState===se.singular?t.inverseState=se.singular:t.inverseState=se.unknown,t}multiplyMatrixTransposeMatrix(e,t){return t=t||new E,We.multiplyMatrixTransposeMatrix(this.coffs,e.coffs,t.coffs),this.inverseState===se.inverseStored&&e.inverseState===se.inverseStored?t.finishInverseCoffs((n,i,s)=>We.multiplyMatrixMatrixTranspose(n,i,s),e.inverseCoffs,this.inverseCoffs):this.inverseState===se.singular||e.inverseState===se.singular?t.inverseState=se.singular:t.inverseState=se.unknown,t}multiplyMatrixTransform(e,t){return t?(this.multiplyXYZtoXYZ(e.origin,t.origin),this.multiplyMatrixMatrix(e.matrix,t.matrix),t):X.createRefs(this.multiplyXYZ(e.origin.x,e.origin.y,e.origin.z),this.multiplyMatrixMatrix(e.matrix))}transpose(e){return e||(e=new E),We.copyTransposed(this.coffs,e.coffs),this.inverseCoffs!==void 0?(e.inverseState=se.inverseStored,e.inverseCoffs=We.copyTransposed(this.inverseCoffs,e.inverseCoffs)):(e.inverseState=this.inverseState,e.inverseCoffs=void 0),e}transposeInPlace(){We.transposeInPlace(this.coffs),this.inverseCoffs&&We.transposeInPlace(this.inverseCoffs)}inverse(e){if(this.computeCachedInverse(!0))return e===this?(We.copy(this.coffs,E._productBuffer),We.copy(this.inverseCoffs,this.coffs),We.copy(E._productBuffer,this.inverseCoffs),e):(e===void 0&&(e=E.createIdentity()),e.createInverseCoffsWithZeros(),e.inverseCoffs,We.copy(this.coffs,e.inverseCoffs),We.copy(this.inverseCoffs,e.coffs),e.inverseState=this.inverseState,e)}static rowColumnDot(e,t,n,i){return e[t]*n[i]+e[t+1]*n[i+3]+e[t+2]*n[i+6]}static indexedRowCrossProduct(e,t,n,i,s){i[s]=e[t+1]*e[n+2]-e[t+2]*e[n+1],i[s+3]=e[t+2]*e[n]-e[t]*e[n+2],i[s+6]=e[t]*e[n+1]-e[t+1]*e[n]}indexedColumnCrossProductInPlace(e,t,n){const i=this.coffs;i[n]=i[e+3]*i[t+6]-i[e+6]*i[t+3],i[n+3]=i[e+6]*i[t]-i[e]*i[t+6],i[n+6]=i[e]*i[t+3]-i[e+3]*i[t]}axisOrderCrossProductsInPlace(e){switch(e){case ve.XYZ:{this.indexedColumnCrossProductInPlace(0,1,2),this.indexedColumnCrossProductInPlace(2,0,1);break}case ve.YZX:{this.indexedColumnCrossProductInPlace(1,2,0),this.indexedColumnCrossProductInPlace(0,1,2);break}case ve.ZXY:{this.indexedColumnCrossProductInPlace(2,0,1),this.indexedColumnCrossProductInPlace(1,2,0);break}case ve.XZY:{this.indexedColumnCrossProductInPlace(0,2,1),this.indexedColumnCrossProductInPlace(1,0,2);break}case ve.YXZ:{this.indexedColumnCrossProductInPlace(1,0,2),this.indexedColumnCrossProductInPlace(2,1,0);break}case ve.ZYX:{this.indexedColumnCrossProductInPlace(2,1,0),this.indexedColumnCrossProductInPlace(0,2,1);break}}}normalizeColumnsInPlace(e){const t=this.columnXMagnitude(),n=this.columnYMagnitude(),i=this.columnZMagnitude();return e&&e.set(t,n,i),f.isSmallMetricDistance(t)||f.isSmallMetricDistance(n)||f.isSmallMetricDistance(i)?!1:(this.scaleColumns(1/t,1/n,1/i,this),!0)}normalizeRowsInPlace(e){const t=this.rowXMagnitude(),n=this.rowYMagnitude(),i=this.rowZMagnitude();return e&&e.set(t,n,i),f.isSmallMetricDistance(t)||f.isSmallMetricDistance(n)||f.isSmallMetricDistance(i)?!1:(this.scaleRows(1/t,1/n,1/i,this),!0)}isSingular(){return!this.computeCachedInverse(!0)}markSingular(){this.inverseState=se.singular}computeCachedInverse(e){if(e&&E.useCachedInverse&&this.inverseState!==se.unknown)return E.numUseCache++,this.inverseState===se.inverseStored;if(this.inverseState=se.unknown,this.createInverseCoffsWithZeros()){const t=this.coffs,n=this.inverseCoffs;E.indexedRowCrossProduct(t,3,6,n,0),E.indexedRowCrossProduct(t,6,0,n,1),E.indexedRowCrossProduct(t,0,3,n,2),E.numComputeCache++;const i=E.rowColumnDot(t,0,n,0);if(i===0)this.inverseState=se.singular;else{const s=1/i;for(let r=0;r<9;r++)n[r]*=s;return this.inverseState=se.inverseStored,!0}}return this.inverseCoffs=void 0,!1}static flatIndexOf(e,t){return 3*f.cyclic3dAxis(e)+f.cyclic3dAxis(t)}indexedColumnWithWeight(e,t,n){return e=f.cyclic3dAxis(e),Z.create(this.coffs[e],this.coffs[e+3],this.coffs[e+6],t,n)}at(e,t){return this.coffs[E.flatIndexOf(e,t)]}setAt(e,t,n){this.coffs[E.flatIndexOf(e,t)]=n,this.inverseState=se.unknown}scale(e,t){return E.createRowValues(this.coffs[0]*e,this.coffs[1]*e,this.coffs[2]*e,this.coffs[3]*e,this.coffs[4]*e,this.coffs[5]*e,this.coffs[6]*e,this.coffs[7]*e,this.coffs[8]*e,t)}scaleColumns(e,t,n,i){return E.createRowValues(this.coffs[0]*e,this.coffs[1]*t,this.coffs[2]*n,this.coffs[3]*e,this.coffs[4]*t,this.coffs[5]*n,this.coffs[6]*e,this.coffs[7]*t,this.coffs[8]*n,i)}scaleColumnsInPlace(e,t,n){if(this.coffs[0]*=e,this.coffs[1]*=t,this.coffs[2]*=n,this.coffs[3]*=e,this.coffs[4]*=t,this.coffs[5]*=n,this.coffs[6]*=e,this.coffs[7]*=t,this.coffs[8]*=n,this.inverseState===se.inverseStored&&this.inverseCoffs!==void 0){const i=f.conditionalDivideFraction(1,e),s=f.conditionalDivideFraction(1,t),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=se.singular}}scaleRows(e,t,n,i){return E.createRowValues(this.coffs[0]*e,this.coffs[1]*e,this.coffs[2]*e,this.coffs[3]*t,this.coffs[4]*t,this.coffs[5]*t,this.coffs[6]*n,this.coffs[7]*n,this.coffs[8]*n,i)}scaleRowsInPlace(e,t,n){if(this.coffs[0]*=e,this.coffs[1]*=e,this.coffs[2]*=e,this.coffs[3]*=t,this.coffs[4]*=t,this.coffs[5]*=t,this.coffs[6]*=n,this.coffs[7]*=n,this.coffs[8]*=n,this.inverseState===se.inverseStored&&this.inverseCoffs!==void 0){const i=f.conditionalDivideFraction(1,e),s=f.conditionalDivideFraction(1,t),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=se.singular}}addScaledInPlace(e,t){for(let n=0;n<9;n++)this.coffs[n]+=t*e.coffs[n];this.inverseState=se.unknown}addScaledOuterProductInPlace(e,t,n){this.coffs[0]+=n*e.x*t.x,this.coffs[1]+=n*e.x*t.y,this.coffs[2]+=n*e.x*t.z,this.coffs[3]+=n*e.y*t.x,this.coffs[4]+=n*e.y*t.y,this.coffs[5]+=n*e.y*t.z,this.coffs[6]+=n*e.z*t.x,this.coffs[7]+=n*e.z*t.y,this.coffs[8]+=n*e.z*t.z,this.inverseState=se.unknown}static createRigidViewAxesZTowardsEye(e,t,n,i){i=E.createIdentity(i);const s=f.hypotenuseXY(e,t);if(f.isSmallMetricDistance(s))n<0&&i.scaleColumnsInPlace(1,-1,-1);else{const r=e/s,a=t/s;if(i.setRowValues(-a,0,r,r,0,a,0,1,0),n!==0){const o=f.hypotenuseXYZ(e,t,n),c=n/o,d=s/o;i.applyGivensColumnOp(1,2,d,-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 e=Math.abs(this.determinant()),t=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(e,t,0)}sumSquares(){let e=0;for(let t=0;t<9;t++)e+=this.coffs[t]*this.coffs[t];return e}sumDiagonalSquares(){let e=0;for(let t=0;t<9;t+=4)e+=this.coffs[t]*this.coffs[t];return e}sumDiagonal(){return this.coffs[0]+this.coffs[4]+this.coffs[8]}maxAbs(){let e=0;for(let t=0;t<9;t++)e=Math.max(e,Math.abs(this.coffs[t]));return e}maxDiff(e){let t=0;for(let n=0;n<9;n++)t=Math.max(t,Math.abs(this.coffs[n]-e.coffs[n]));return t}get isIdentity(){return this.maxDiff(E.identity)<f.smallAngleRadians}get isDiagonal(){const e=this.sumSquares(),t=this.sumDiagonalSquares(),n=Math.abs(e-t);return Math.sqrt(n)<=f.smallAngleRadians*(1+Math.sqrt(e))}sumSkewSquares(){return f.hypotenuseSquaredXYZ(this.coffs[1]-this.coffs[3],this.coffs[2]-this.coffs[6],this.coffs[5]-this.coffs[7])}isSymmetric(){const e=this.sumSkewSquares();return Math.sqrt(e)<=f.smallAngleRadians*(1+Math.sqrt(this.sumSquares()))}get hasCachedInverse(){return this.inverseState===se.inverseStored&&this.inverseCoffs!==void 0}get isUpperTriangular(){const e=this.sumSquares(),t=f.hypotenuseSquaredXYZ(this.coffs[3],this.coffs[6],this.coffs[7]);return Math.sqrt(t)<=f.smallAngleRadians*(1+Math.sqrt(e))}get isLowerTriangular(){const e=this.sumSquares(),t=f.hypotenuseSquaredXYZ(this.coffs[1],this.coffs[2],this.coffs[5]);return Math.sqrt(t)<=f.smallAngleRadians*(1+Math.sqrt(e))}sameDiagonalScale(){const e=this.sumSquares(),t=this.sumDiagonalSquares(),n=Math.abs(e-t);if(Math.sqrt(n)<=f.smallAngleRadians*(1+Math.sqrt(e))&&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(e=!1){return this.testPerpendicularUnitRowsAndColumns()&&(e||this.determinant()>0)}factorRigidWithSignedScale(e){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,e),scale:i}}factorRigidSkew(e,t,n=ve.XYZ){return E.createRigidFromMatrix3d(this,n,e)?(e.multiplyMatrixTransposeMatrix(this,t),!0):(e.setIdentity(),t.setFrom(this),!1)}get isSignedPermutation(){let e=0;for(let t=0;t<3;t++)for(let n=0;n<3;n++){const i=this.at(t,n);if(i!==0)if(i===1||i===-1){if(e++,this.at(t+1,n)!==0||this.at(t+2,n)!==0||this.at(t,n+1)!==0||this.at(t,n+2)!==0)return!1}else return!1}return e===3}makeRigid(e=ve.XYZ){const t=this.maxAbs();if(f.isSmallMetricDistance(t))return!1;const n=1/t;return this.scaleColumnsInPlace(n,n,n),this.axisOrderCrossProductsInPlace(e),this.normalizeColumnsInPlace()}static createRigidFromMatrix3d(e,t=ve.XYZ,n){if(n=e.clone(n),n.makeRigid(t))return n}static createFromQuaternion(e){const t=e.x*e.x,n=e.y*e.y,i=e.z*e.z,s=e.w*e.w,r=t+n+i+s;if(r===0)return E.createIdentity();{const a=1/r;return E.createRowValues(a*(s+t-n-i),2*a*(e.w*e.z+e.x*e.y),2*a*(e.x*e.z-e.w*e.y),2*a*(e.x*e.y-e.w*e.z),a*(s-t+n-i),2*a*(e.w*e.x+e.y*e.z),2*a*(e.x*e.z+e.w*e.y),2*a*(e.y*e.z-e.w*e.x),a*(s-t-n+i))}}static computeQuatTerm(e,t,n,i){let s;return i>.5?(s=.5*Math.sqrt(i),t*e<0&&(s=-s)):s=e*n,s}toQuaternion(){const e=Z.createZero(),t=[[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=t[0][0],i=t[1][1],s=t[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 a,o=0;for(let c=1;c<=3;c++)r[c]>r[o]&&(o=c);return o===0?(e.x=.5*Math.sqrt(r[0]),a=1/(4*e.x),e.y=E.computeQuatTerm(t[0][1]+t[1][0],e.x,a,r[1]),e.z=E.computeQuatTerm(t[0][2]+t[2][0],e.x,a,r[2]),e.w=E.computeQuatTerm(t[2][1]-t[1][2],e.x,a,r[3])):o===1?(e.y=.5*Math.sqrt(r[1]),a=1/(4*e.y),e.x=E.computeQuatTerm(t[0][1]+t[1][0],e.y,a,r[0]),e.z=E.computeQuatTerm(t[1][2]+t[2][1],e.y,a,r[2]),e.w=E.computeQuatTerm(t[0][2]-t[2][0],e.y,a,r[3])):o===2?(e.z=.5*Math.sqrt(r[2]),a=1/(4*e.z),e.x=E.computeQuatTerm(t[0][2]+t[2][0],e.z,a,r[0]),e.y=E.computeQuatTerm(t[1][2]+t[2][1],e.z,a,r[1]),e.w=E.computeQuatTerm(t[1][0]-t[0][1],e.z,a,r[3])):(e.w=.5*Math.sqrt(r[3]),a=1/(4*e.w),e.x=E.computeQuatTerm(t[2][1]-t[1][2],e.w,a,r[0]),e.y=E.computeQuatTerm(t[0][2]-t[2][0],e.w,a,r[1]),e.z=E.computeQuatTerm(t[1][0]-t[0][1],e.w,a,r[2])),e}}class ji{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(e){return e===void 0?e=new ji:e.invalidate(),e}copyContentsFrom(e){this.world.setFrom(e.world),this.local.setFrom(e.local),this.a=e.a,this.closestEdgeIndex=e.closestEdgeIndex,this.closestEdgeParam=e.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 we.Unknown;if(this.isInsideOrOn){let e=0;return Math.abs(this.local.x)===0&&++e,Math.abs(this.local.y)===0&&++e,Math.abs(this.local.z)===0&&++e,e===2?we.OnPolygonVertex:e===1?we.OnPolygonEdgeInterior:we.InsidePolygonProjectsToEdgeInterior}return this.closestEdgeParam===0?we.OutsidePolygonProjectsToVertex:we.OutsidePolygonProjectsToEdgeInterior}}class Ie{points;edgeLength2;static _workPoint;static _workVector0;static _workVector1;static _workRay;static _workMatrix;constructor(e,t,n){this.points=[],this.points.push(e),this.points.push(t),this.points.push(n),this.edgeLength2=[],this.edgeLength2.push(t.distanceSquared(n)),this.edgeLength2.push(e.distanceSquared(n)),this.edgeLength2.push(e.distanceSquared(t))}set(e,t,n){this.points[0].setFromPoint3d(e),this.points[1].setFromPoint3d(t),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(e){for(let t=0;t<3;++t)this.points[t].setFromPoint3d(e.points[t]),this.edgeLength2[t]=e.edgeLength2[t]}static createXYZXYZXYZ(e,t,n,i,s,r,a,o,c,d){return d?(d.points[0].set(e,t,n),d.points[1].set(i,s,r),d.points[2].set(a,o,c),d):new this(y.create(e,t,n),y.create(i,s,r),y.create(a,o,c))}static create(e,t,n,i){return i?(i.set(e,t,n),i):new this(e.clone(),t.clone(),n.clone())}clone(e){return Ie.create(this.points[0],this.points[1],this.points[2],e)}cloneTransformed(e,t){return Ie.create(e.multiplyPoint3d(this.points[0],t?.points[0]),e.multiplyPoint3d(this.points[1],t?.points[1]),e.multiplyPoint3d(this.points[2],t?.points[2]),t)}get area(){return .5*this.points[0].crossProductToPointsMagnitude(this.points[1],this.points[2])}edgeLengthSquared(e){return this.edgeLength2[f.cyclic3dAxis(e)]}edgeLength(e){return Math.sqrt(this.edgeLengthSquared(e))}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(e){const t=this.points[0].crossProductToPoints(this.points[1],this.points[2],e);if(t.tryNormalizeInPlace())return t}fractionToPoint(e,t,n,i){return y.createAdd3Scaled(this.points[0],e,this.points[1],t,this.points[2],n,i)}pointToFraction(e,t){const n=Ie._workVector0=this.normal(Ie._workVector0);if(n===void 0)return ji.create(t);const i=Ie._workRay=q.create(e,n,Ie._workRay);return this.intersectRay3d(i,t)}static edgeOppositeVertexIndexToStartVertexIndex(e){return f.cyclic3dAxis(e+1)}static edgeStartVertexIndexToOppositeVertexIndex(e){return f.cyclic3dAxis(e-1)}static isInsideTriangle(e,t,n){return e>0&&t>0&&n>0}static isInsideOrOnTriangle(e,t,n){return e>=0&&t>=0&&n>=0}static isInRegionBeyondEdge(e,t,n){return e<0&&t>=0&&n>=0?0:e>=0&&t<0&&n>=0?1:e>=0&&t>=0&&n<0?2:-1}static isInRegionBeyondVertex(e,t,n){return t<0&&n<0?0:e<0&&n<0?1:e<0&&t<0?2:-1}static isOnVertex(e,t,n){return e===1&&t===0&&n===0?0:e===0&&t===1&&n===0?1:e===0&&t===0&&n===1?2:-1}static isOnBoundedEdge(e,t,n){return e===0&&t>0&&n>0?0:e>0&&t===0&&n>0?1:e>0&&t>0&&n===0?2:-1}static indexOfMinimum(e){let t=0,n=e(0);const i=e(1);return n>i&&(t=1,n=i),n>e(2)&&(t=2),t}distanceSquared(e,t,n,i,s,r){return-this.edgeLengthSquared(0)*(s-t)*(r-n)-this.edgeLengthSquared(1)*(r-n)*(i-e)-this.edgeLengthSquared(2)*(i-e)*(s-t)}closestVertexIndex(e,t,n){return Ie.indexOfMinimum(i=>{const s=Ie._workPoint=y.createZero(Ie._workPoint);return s.setAt(i,1),this.distanceSquared(s.x,s.y,s.z,e,t,n)})}dotProductOfEdgeVectorsAtVertex(e){const t=f.cyclic3dAxis(e),n=f.cyclic3dAxis(t+1),i=f.cyclic3dAxis(n+1);return f.dotProductXYZXYZ(this.points[n].x-this.points[t].x,this.points[n].y-this.points[t].y,this.points[n].z-this.points[t].z,this.points[i].x-this.points[t].x,this.points[i].y-this.points[t].y,this.points[i].z-this.points[t].z)}computeProjectionToEdge(e,t){e=f.cyclic3dAxis(e);const n=f.cyclic3dAxis(e+1),i=f.cyclic3dAxis(n+1);return t[i]+t[e]*this.dotProductOfEdgeVectorsAtVertex(n)/this.edgeLengthSquared(e)}closestPoint(e,t,n){const i=[e,t,n];let s=-1,r=0;return Ie.isInsideTriangle(e,t,n)?(s=Ie.indexOfMinimum(a=>i[a]*i[a]/this.edgeLengthSquared(a)),r=this.computeProjectionToEdge(s,i)):(s=Ie.isInRegionBeyondVertex(e,t,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=Ie.edgeStartVertexIndexToOppositeVertexIndex(this.closestVertexIndex(e,t,n))))):(s=Ie.isInRegionBeyondEdge(e,t,n))>=0?(r=this.computeProjectionToEdge(s,i),r<0?r=0:r>1&&(r=0,s=f.cyclic3dAxis(s+1))):(s=Ie.isOnBoundedEdge(e,t,n))>=0?r=1-i[Ie.edgeOppositeVertexIndexToStartVertexIndex(s)]:(s=Ie.isOnVertex(e,t,n))>=0&&(r=0,s=Ie.edgeStartVertexIndexToOppositeVertexIndex(s)),{closestEdgeIndex:s<0?-1:Ie.edgeOppositeVertexIndexToStartVertexIndex(s),closestEdgeParam:r}}intersectRay3d(e,t){t=ji.create(t);const n=e.origin,i=e.direction,s=Ie._workVector0=v.createStartEnd(this.points[0],this.points[1],Ie._workVector0),r=Ie._workVector1=v.createStartEnd(this.points[0],this.points[2],Ie._workVector1),a=i.tripleProduct(s,r);if(a*a<=s.dotProduct(s)*r.dotProduct(r)*i.dotProduct(i)*f.smallAngleRadiansSquared)return t;const o=Ie._workMatrix=E.createColumns(s,r,i,Ie._workMatrix),c=v.createStartEnd(this.points[0],n,Ie._workVector0),d=Ie._workVector1;if(o.multiplyInverse(c,d)===void 0)return t;t.a=-d.z,e.fractionToPoint(t.a,t.world),t.local.set(1-d.x-d.y,d.x,d.y);const h=this.closestPoint(t.local.x,t.local.y,t.local.z);return t.closestEdgeIndex=h.closestEdgeIndex,t.closestEdgeParam=h.closestEdgeParam,t}intersectSegment(e,t,n){return Ie._workRay=q.createStartEnd(e,t,Ie._workRay),this.intersectRay3d(Ie._workRay,n)}snapLocationToEdge(e,t=f.smallMetricDistance,n=f.smallFloatingPoint){if(!e.isValid)return!1;if(n>0){let i=0,s=0;for(let r=0;r<3;r++){const a=Math.abs(e.local.at(r));a>0&&a<n&&(e.local.setAt(r,0),i++),s+=e.local.at(r)}if(i>0&&s>0)return e.local.scaleInPlace(1/s),i===1?(e.closestEdgeIndex=Ie.edgeOppositeVertexIndexToStartVertexIndex(Ie.isOnBoundedEdge(e.local.x,e.local.y,e.local.z)),e.closestEdgeParam=1-e.local.at(e.closestEdgeIndex)):(e.closestEdgeIndex=Ie.isOnVertex(e.local.x,e.local.y,e.local.z),e.closestEdgeParam=0),this.fractionToPoint(e.local.x,e.local.y,e.local.z,e.world),!0}if(t>0){const i=e.closestEdgeIndex,s=(i+1)%3,r=(s+1)%3,a=Ie._workPoint=this.points[i].interpolate(e.closestEdgeParam,this.points[s],Ie._workPoint),o=e.world.distance(a);if(o>0&&o<t)return e.local.setAt(i,1-e.closestEdgeParam),e.local.setAt(s,e.closestEdgeParam),e.local.setAt(r,0),e.world.setFrom(a),!0}return!1}dotProductOfCrossProductsFromOrigin(e){return Ie._workVector0=this.points[0].crossProductToPoints(this.points[1],this.points[2],Ie._workVector0),Ie._workVector1=e.points[0].crossProductToPoints(e.points[1],e.points[2],Ie._workVector1),Ie._workVector0.dotProduct(Ie._workVector1)}centroid(e){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,e)}incenter(e){const t=this.edgeLength(0),n=this.edgeLength(1),i=this.edgeLength(2),s=f.safeDivideFraction(1,t+n+i,0);return this.fractionToPoint(s*t,s*n,s*i,e)}circumcenter(e){const t=this.edgeLengthSquared(0),n=this.edgeLengthSquared(1),i=this.edgeLengthSquared(2),s=t*(n+i-t),r=n*(i+t-n),a=i*(t+n-i),o=f.safeDivideFraction(1,s+r+a,0);return this.fractionToPoint(o*s,o*r,o*a,e)}isAlmostEqual(e,t){return this.points[0].isAlmostEqual(e.points[0],t)&&this.points[1].isAlmostEqual(e.points[1],t)&&this.points[2].isAlmostEqual(e.points[2],t)}}class Ns{surface;uv;point;a;constructor(e,t,n){this.surface=e,this.point=n||y.createZero(),this.uv=t||L.createZero(),this.a=0}static createSurfaceUVPoint(e,t,n){const i=new Ns(e);return t&&i.uv.setFrom(t),i.point.setFromPoint3d(n),i}static createSurfaceUVNumbersPoint(e,t,n,i){const s=new Ns(e);return s.uv.x=t,s.uv.y=n,s.point.setFromPoint3d(i),s}}class wc{curveDetail;surfaceDetail;constructor(e,t){this.curveDetail=e,this.surfaceDetail=t}}class nn{point00;point10;point01;point11;constructor(e,t,n,i){this.point00=e,this.point10=t,this.point01=n,this.point11=i}static create(e,t,n,i){return new nn(e.clone(),t.clone(),n.clone(),i.clone())}static createXYZ(e,t,n,i,s,r,a,o,c,d,h,u){return new nn(y.create(e,t,n),y.create(i,s,r),y.create(a,o,c),y.create(d,h,u))}clone(){return new nn(this.point00.clone(),this.point10.clone(),this.point01.clone(),this.point11.clone())}isAlmostEqual(e){return this.point00.isAlmostEqual(e.point00)&&this.point10.isAlmostEqual(e.point10)&&this.point01.isAlmostEqual(e.point01)&&this.point11.isAlmostEqual(e.point11)}tryTransformInPlace(e){return e.multiplyPoint3d(this.point00,this.point00),e.multiplyPoint3d(this.point10,this.point10),e.multiplyPoint3d(this.point01,this.point01),e.multiplyPoint3d(this.point11,this.point11),!0}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}extendRange(e,t){t?(e.extendTransformedPoint(t,this.point00),e.extendTransformedPoint(t,this.point10),e.extendTransformedPoint(t,this.point01),e.extendTransformedPoint(t,this.point11)):(e.extendPoint(this.point00),e.extendPoint(this.point10),e.extendPoint(this.point01),e.extendPoint(this.point11))}uvFractionToPoint(e,t,n){const i=(1-e)*(1-t),s=e*(1-t),r=(1-e)*t,a=e*t;return y.create(i*this.point00.x+s*this.point10.x+r*this.point01.x+a*this.point11.x,i*this.point00.y+s*this.point10.y+r*this.point01.y+a*this.point11.y,i*this.point00.z+s*this.point10.z+r*this.point01.z+a*this.point11.z,n)}uvFractionToPointAndTangents(e,t,n){const i=1-e,s=1-t,r=i*s,a=e*s,o=i*t,c=e*t;return ke.createOriginAndVectorsXYZ(r*this.point00.x+a*this.point10.x+o*this.point01.x+c*this.point11.x,r*this.point00.y+a*this.point10.y+o*this.point01.y+c*this.point11.y,r*this.point00.z+a*this.point10.z+o*this.point01.z+c*this.point11.z,s*(this.point10.x-this.point00.x)+t*(this.point11.x-this.point01.x),s*(this.point10.y-this.point00.y)+t*(this.point11.y-this.point01.y),s*(this.point10.z-this.point00.z)+t*(this.point11.z-this.point01.z),i*(this.point01.x-this.point00.x)+e*(this.point11.x-this.point10.x),i*(this.point01.y-this.point00.y)+e*(this.point11.y-this.point10.y),i*(this.point01.z-this.point00.z)+e*(this.point11.z-this.point10.z),n)}static conditionalPivot(e,t,n,i){if(Math.abs(t[i][e])>Math.abs(t[n][e])){const s=t[n];t[n]=t[i],t[i]=s}}intersectRay(e){const t=this.point10.minus(this.point00),n=this.point01.minus(this.point00),i=this.point11.minus(this.point10);i.subtractInPlace(n);const s=[new Float64Array([-e.direction.x,this.point00.x-e.origin.x,t.x,n.x,i.x]),new Float64Array([-e.direction.y,this.point00.y-e.origin.y,t.y,n.y,i.y]),new Float64Array([-e.direction.z,this.point00.z-e.origin.z,t.z,n.z,i.z])];nn.conditionalPivot(0,s,0,1),nn.conditionalPivot(0,s,0,2),Le.eliminateFromPivot(s[0],0,s[1],-1),Le.eliminateFromPivot(s[0],0,s[2],-1);const r=Le.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 a=[];for(const o of r){const c=-(s[0][1]+s[0][2]*o.x+(s[0][3]+s[0][4]*o.x)*o.y)/s[0][0],d=e.fractionToPoint(c);a.push(new wc(Y.createRayFractionPoint(e,c,d),Ns.createSurfaceUVPoint(this,o,d)))}return a}}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 Os{static oneMillimeter=.001;static oneCentimeter=.01;static oneMeter=1;static oneKilometer=1e3;static diameterOfEarth=12742*Os.oneKilometer;static circumferenceOfEarth=40075*Os.oneKilometer;static earthRadiusWGS84={polar:63567523142e-4,equator:6378137}}var je;(function(l){l[l.None=0]="None",l[l.OnTangent=1]="OnTangent",l[l.OnCurve=2]="OnCurve"})(je||(je={}));class Ge{static resolveVariantCurveExtendParameterToCurveExtendMode(e,t){return e??=!1,e===!1?je.None:e===!0?je.OnCurve:Array.isArray(e)?e.length>t?e[t]:je.None:e}static correctFraction(e,t){return e??=!1,t<0?Ge.resolveVariantCurveExtendParameterToCurveExtendMode(e,0)===je.None&&(t=0):t>1&&Ge.resolveVariantCurveExtendParameterToCurveExtendMode(e,1)===je.None&&(t=1),t}static resolveRadiansToValidSweepFraction(e,t,n){e??=!1;let i=n.radiansToSignedPeriodicFraction(t),s=!0;if(!n.isRadiansInSweep(t)){const r=n.fractionPeriod(),a=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(e,0),o=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(e,1);a!==je.None?o===je.None&&i>1&&(i-=r):o!==je.None?i<0&&(i+=r):(i=f.clamp(i,0,1),s=!1)}return{fraction:i,isValid:s}}static resolveRadiansToSweepFraction(e,t,n){return this.resolveRadiansToValidSweepFraction(e,t,n).fraction}}class pn{numStroke;curveLength;a0;a1;componentData;primitive;componentIndex;constructor(e,t,n,i,s){this.numStroke=e,this.curveLength=t,this.a0=n,this.a1=i,this.componentData=s}static createWithCurvePrimitive(e,t,n,i,s,r){const a=new pn(t,n,i,s,r);return a.primitive=e,a}static createWithComponentIndex(e=0,t=0,n=0,i=0,s=0){const r=new pn(t,n,i,s);return r.componentIndex=e,r}static createWithCurvePrimitiveAndOptionalParent(e,t,n){const i=t?t.a1:0,s=new pn(0,0,i,i,n);return s.primitive=e,s}addToCountAndLength(e,t){const n=this.a1+t;this.componentData&&this.componentData.push(new pn(e,t,this.a1,n)),this.numStroke+=e,this.curveLength+=t,this.a1=n}isCompatibleComponentStructure(e,t){if(t&&this.numStroke!==e.numStroke)return!1;if(this.componentData===void 0&&e.componentData===void 0)return!0;if(this.componentData&&e.componentData){if(this.componentData.length!==e.componentData.length)return!1;const n=this.componentData.length;for(let i=0;i<n;i++)if(!this.componentData[i].isCompatibleComponentStructure(e.componentData[i],t))return!1;return!0}return!1}clone(){const e=new pn(this.numStroke,this.curveLength,this.a0,this.a1);if(this.componentData){e.componentData=[];for(const t of this.componentData)e.componentData.push(t.clone())}return e}fractionToA(e){return f.interpolate(this.a0,e,this.a1)}}class Mt{range(e,t){t&&t.setNull();const n=t||ie.createNull();return this.extendRange(n,e),n}tryTranslateInPlace(e,t=0,n=0){return this.tryTransformInPlace(X.createTranslationXYZ(e,t,n))}get children(){}isAlmostEqual(e){if(this.isSameGeometryClass(e)){const t=this.children,n=e.children;if(t&&n){if(t.length!==n.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].isAlmostEqual(n[i]))return!1;return!0}else return!(t||n)}return!1}static areAlmostEqual(e,t){return e instanceof Mt&&t instanceof Mt?e.isAlmostEqual(t):e===void 0&&t===void 0}static computeScaledTolerance(e,t){const n=Math.abs(t?.relativeTolerance??f.smallMetricDistance),i=Math.abs(t?.minimumTolerance??f.smallMetricDistanceSquared),s=ie.createNull();(Array.isArray(e)?e:[e]).forEach(a=>a.extendRange(s,t?.transform));const r=s.isNull?0:t?.xyOnly?s.maxAbsXY():s.maxAbs();return i+n*r}static scaleToleranceForGeometry(e,t,n){if(t>0){const i=ie.createNull();if((Array.isArray(e)?e:[e]).forEach(s=>s.extendRange(i,n?.transform)),!i.isNull){const s=n?.xyOnly?i.maxAbsXY():i.maxAbs();if(s>0){const a=Math.floor(Math.log10(s/t));a>10&&(t*=Math.pow(10,a-10))}}}return t}}class $a{constructor(e=f.smallNewtonStep,t=2,n=15){this._stepSizeTolerance=e,this._successiveConvergenceTarget=t,this._maxIterations=n}_numAccepted=0;_successiveConvergenceTarget;_stepSizeTolerance;_maxIterations;numIterations=0;get stepSizeTolerance(){return this._stepSizeTolerance}_leastDelta=Number.MAX_VALUE;testConvergence(e){return this.cacheCandidate&&e<this._leastDelta&&this.numIterations>.5*this._maxIterations&&(this._leastDelta=e,this.cacheCandidate()),Math.abs(e)<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 bc{currentF}class Yr extends bc{_parentCurvePrimitive;constructor(){super(),this._parentCurvePrimitive=void 0}startParentCurvePrimitive(e){this._parentCurvePrimitive=e}endParentCurvePrimitive(e){this._parentCurvePrimitive=void 0}}class zr extends $a{_func;_currentStep;_currentX;derivativeH;constructor(e,t){super(void 0,void 0,t),this._func=e,this.derivativeH=1e-8}setX(e){this._currentX=e}getX(){return this._currentX}applyCurrentStep(){this.setX(this._currentX-this._currentStep)}computeStep(){if(this._func.evaluate(this._currentX)){const e=this._func.currentF;if(this._func.evaluate(this._currentX+this.derivativeH)){const t=this._func.currentF,n=f.conditionalDivideFraction(e,(t-e)/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 eo{currentF;constructor(){this.currentF=ke.createXYPlane()}}class Xs extends $a{_func;_currentStep;_currentUV;constructor(e,t,n){super(n,void 0,t),this._func=e,this._currentStep=$.createZero(),this._currentUV=L.createZero()}setUV(e,t){this._currentUV.set(e,t)}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 e=this._func.currentF,t=e.vectorU,n=e.vectorV,i=e.origin;return!!Le.linearSystem2d(t.x,n.x,t.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 to extends eo{_curveP;_curveQ;_rayP;_rayQ;constructor(e,t){super(),this._curveP=e,this._curveQ=t,this._rayP=q.createZero(),this._rayQ=q.createZero()}evaluate(e,t){return this._curveP.fractionToPointAndDerivative(e,this._rayP),this._curveQ.fractionToPointAndDerivative(t,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 no extends eo{_curveP;_curveQ;_planeP;_planeQ;constructor(e,t){super(),this._curveP=e,this._curveQ=t,this._planeP=ke.createXYPlane(),this._planeQ=ke.createXYPlane()}evaluate(e,t){this._curveP.fractionToPointAnd2Derivatives(e,this._planeP),this._curveQ.fractionToPointAnd2Derivatives(t,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,a=this._planeQ.vectorU.x,o=this._planeQ.vectorU.y,c=this._planeP.vectorV.x,d=this._planeP.vectorV.y,h=this._planeQ.vectorV.x,u=this._planeQ.vectorV.y;return this.currentF.setOriginAndVectorsXYZ(s*n+r*i,a*n+o*i,0,c*n+d*i+s*s+r*r,a*s+o*r,0,-(s*a+r*o),h*n+u*i-a*a-o*o,0),!0}}class io extends Yr{_curve;_announceTangent;_spacePoint;_vectorToEye;_distanceTol;_distanceTolSquared;_fractionA=0;_functionA=0;_fractionB=0;_functionB=0;_numThisCurve=0;_fractionMRU;_curveMRU;_workRay;_workDetail;_newtonSolver;constructor(e,t,n){super(),this._announceTangent=t,this._spacePoint=e,this._vectorToEye=n?.vectorToEye??v.unitZ(),this._distanceTol=n?.distanceTol??f.smallMetricDistance,this._distanceTolSquared=this._distanceTol*this._distanceTol,this._workRay=q.createZero(),this.startCurvePrimitive(void 0),this._newtonSolver=new zr(this)}needPrimaryGeometryForStrokes(){return!0}startCurvePrimitive(e){this._curve=e,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(e,t,n,i){this.startCurvePrimitive(e),t<1&&(t=1);const s=1/t;for(let r=0;r<=t;r++){const a=f.interpolate(n,r*s,i);e.fractionToPointAndDerivative(a,this._workRay),this.announceRay(a,this._workRay)}}announceCandidate(e,t,n){this._parentCurvePrimitive&&(e=this._parentCurvePrimitive),!(this._curveMRU===e&&f.isAlmostEqualOptional(this._fractionMRU,t,f.smallFloatingPoint))&&(this._workDetail=Y.createCurveFractionPoint(e,t,n,this._workDetail),this._announceTangent(this._workDetail),this._fractionMRU=t,this._curveMRU=e)}announceSegmentInterval(e,t,n,i,s,r){let a,o;const c=this._spacePoint.distanceSquared(t),d=this._spacePoint.distanceSquared(n);c<d?(a=s,o=t):(a=r,o=n);const h=this.evaluateFunction(void 0,(s+r)/2,e);h!==void 0&&f.isDistanceWithinTol(h,this._distanceTol)&&this.announceCandidate(e,a,o)}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 e=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);e&&(this._newtonSolver.setX(e),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}announceSolutionFraction(e){this._curve&&this.announceCandidate(this._curve,e,this._curve.fractionToPoint(e))}evaluateFunction(e,t,n){if(e)this._workRay.setFrom(e);else if(t!==void 0&&n)this._workRay=n.fractionToPointAndDerivative(t,this._workRay);else return;const i=this._vectorToEye.unitCrossProduct(this._workRay.direction);return i?i.dotProductStartEnd(this._workRay.origin,this._spacePoint):void 0}evaluate(e){const t=this._parentCurvePrimitive??this._curve,n=this.evaluateFunction(void 0,e,t);return n===void 0?!1:(this.currentF=n,!0)}announceRay(e,t){const n=this.evaluateFunction(t);n!==void 0&&(this._functionB=n,this._fractionB=e,this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB)}announcePointTangent(e,t,n){}}class Be{static _allRows=[];static getRow(e){const t=Be._allRows;for(t.length===0&&(t.push(new Float64Array([1])),t.push(new Float64Array([1,1])),t.push(new Float64Array([1,2,1])),t.push(new Float64Array([1,3,3,1])),t.push(new Float64Array([1,4,6,4,1])),t.push(new Float64Array([1,5,10,10,5,1])),t.push(new Float64Array([1,6,15,20,15,6,1])),t.push(new Float64Array([1,7,21,35,35,21,7,1])));t.length<=e;){const n=t.length,i=t[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,t.push(s)}return t[e]}static getBezierBasisValues(e,t,n){const i=e-1,s=Be.getRow(i);(n===void 0||n.length<e)&&(n=new Float64Array(e));for(let o=0;o<e;o++)n[o]=s[o];let r=t;for(let o=1;o<e;o++,r*=t)n[o]*=r;const a=1-t;r=a;for(let o=e-2;o>=0;o--,r*=a)n[o]*=r;return n}static getBezierBasisDerivatives(e,t,n){(n===void 0||n.length<e)&&(n=new Float64Array(e)),n=this.getBezierBasisValues(e-1,t,n);const i=e-1;n[e-1]=i*n[e-2];for(let s=e-2;s>0;s--)n[s]=i*(n[s-1]-n[s]);return n[0]=-i*n[0],n}}class so{coffs;constructor(e){if(e instanceof Float64Array)this.coffs=e.slice();else if(Array.isArray(e)){this.coffs=new Float64Array(e.length);let t=0;for(const n of e)this.coffs[t++]=n}else this.coffs=new Float64Array(e)}allocateToOrder(e){this.coffs.length!==e?this.coffs=new Float64Array(e):this.coffs.fill(0)}createPeer(){return new it(this.order)}get order(){return this.coffs.length}copyFrom(e){if(this.order===e.order)for(let t=0;t<this.coffs.length;t++)this.coffs[t]=e.coffs[t];else this.coffs=e.coffs.slice()}scaleInPlace(e){for(let t=0;t<this.coffs.length;t++)this.coffs[t]*=e}addInPlace(e){for(let t=0;t<this.coffs.length;t++)this.coffs[t]+=e}roots(e,t){const n=it.create(this);n.addInPlace(-e),n.clampZero();const i=it.deflateRoots(n);return this.filter01(i,!0)}filter01(e,t=!1){if(!e||!t)return e;let n=!1;for(const i of e)if(f.isIn01(i)){n=!0;break}if(n){const i=[];for(const s of e)f.isIn01(s)&&i.push(s);return i}}zero(){this.coffs.fill(0)}subdivide(e,t,n){const i=this.order;if(t.order!==i||n.order!==i)return!1;const s=1-e;n.copyFrom(this);let r=i-1;for(let a=0;a<i;a++){t.coffs[a]=n.coffs[0];for(let o=0;o<r;o++)n.coffs[o]=s*n.coffs[o]+e*n.coffs[o+1];r--}return!0}static maxAbsDiff(e,t){const n=e.order;if(t.order!==n)return;let i=0,s;for(let r=0;r<n;r++)s=Math.abs(e.coffs[r]-t.coffs[r]),s>i&&(i=s);return i}clampZero(e=f.smallFloatingPoint){if(e>0)for(let t=0;t<this.coffs.length;++t){const n=this.coffs[t];n&&Math.abs(n)<e&&(this.coffs[t]=0)}}}class Ht{static accumulateScaledShiftedComponentTimesComponentDelta(e,t,n,i,s,r,a,o){const c=i-1,d=i,h=i+c-1;if(e.length!==h)return;const u=Be.getRow(d-1),g=Be.getRow(c-1),m=Be.getRow(h-1);let p;for(let x=0;x<d;x++){p=s*(a+t[r+x*n])*u[x];for(let _=0,I=o;_<c;_++,I+=n)e[x+_]+=p*g[_]*(t[I+n]-t[I])/m[x+_]}}static scaledComponentSum(e,t,n,i,s,r,a,o){const c=i;if(e.length===c)for(let d=0,h=0;d<c;d++,h+=n)e[d]=r*t[h+s]+o*t[h+a]}static componentDifference(e,t,n,i,s){const a=i-1;if(e.length===a)for(let o=0,c=s;o<a;c+=n,o++)e[o]=t[c+n]-t[c]}static accumulateProduct(e,t,n,i=1){const s=t.length,r=n.length,a=s+r-1;if(e.length!==a)return;let o,c,d;const h=Be.getRow(s-1),u=Be.getRow(r-1),g=Be.getRow(a-1);for(o=0;o<s;o++)for(d=i*h[o]*t[o],c=0;c<r;c++)e[o+c]+=d*u[c]*n[c]/g[o+c]}static accumulateProductWithDifferences(e,t,n,i=1){const s=t.length-1,r=n.length,a=s+r-1;if(e.length!==a)return;let o,c,d;const h=Be.getRow(s-1),u=Be.getRow(r-1),g=Be.getRow(a-1);for(o=0;o<s;o++)for(d=i*h[o]*(t[o+1]-t[o]),c=0;c<r;c++)e[o+c]+=d*u[c]*n[c]/g[o+c]}static univariateDifference(e,t){const n=t.length;if(t.length+1!==n)for(let i=0;i<n;i++)t[i]=e[i+1]-e[i]}static accumulate(e,t,n){if(n.length===t)for(let i=0;i<t;i++)n[i]+=e[i]}}class it extends so{_order;get order(){return this._order}constructor(e){super(e),this._order=super.order}allocateOrder(e){this._order!==e&&(super.allocateToOrder(e),this._order=e),this.coffs.fill(0)}clone(e=!1){if(e){const n=new it(this.order);return n.coffs=this.coffs.slice(0,this.order),n}const t=new it(this.coffs.length);return t._order=this._order,t.coffs=this.coffs.slice(),t}static create(e){const t=new it(e.order);return t.coffs=e.coffs.slice(),t}static createCoffs(e){return new it(e)}static createArraySubset(e,t,n,i){i?i.order!==n&&i.allocateToOrder(n):i=new it(n);for(let s=0;s<n;s++)i.coffs[s]=e[t+s];return i}static createProduct(e,t){const n=new it(e.order+t.order-1),i=Be.getRow(e.order-1),s=Be.getRow(t.order-1),r=Be.getRow(e.order+t.order-2);for(let a=0;a<e.order;a++){const o=e.coffs[a]*i[a];for(let c=0;c<t.order;c++){const d=t.coffs[c]*s[c],h=a+c,u=r[h];n.coffs[h]+=o*d/u}}return n}addSquaredSquaredBezier(e,t){const n=e.length,i=this.order;if(n*2!==i+1)return!1;const s=Be.getRow(n-1),r=Be.getRow(i-1),a=this.coffs;for(let o=0;o<n;o++){const c=e[o]*s[o]*t;for(let d=0;d<n;d++){const h=e[d]*s[d],u=o+d,g=r[u];a[u]+=c*h/g}}return!0}addConstant(e){for(let t=0;t<this.coffs.length;t++)this.coffs[t]+=e}_basisValues;basisFunctions(e,t){this._basisValues=Be.getBezierBasisValues(this.order,e,this._basisValues),(!t||t.length<this.order)&&(t=new Float64Array(this.order));let n=0;for(const i of this._basisValues)t[n++]=i;return t}static sumWeightedBlocks(e,t,n,i,s){for(let o=0;o<i;o++)s[o]=0;let r=0,a;for(let o=0;o<t;o++){const c=e[o];for(a=0;a<i;a++)s[a]+=c*n[r++]}}sumBasisFunctions(e,t,n,i){return(!i||i.length<n)&&(i=new Float64Array(n)),this._basisValues=Be.getBezierBasisValues(this.order,e,this._basisValues),it.sumWeightedBlocks(this._basisValues,this.order,t,n,i),i}sumBasisFunctionDerivatives(e,t,n,i){return(!i||i.length<n)&&(i=new Float64Array(n)),this._basisValues=Be.getBezierBasisDerivatives(this.order,e,this._basisValues),it.sumWeightedBlocks(this._basisValues,this.order,t,n,i),i}evaluate(e){this._basisValues=Be.getBezierBasisValues(this.order,e,this._basisValues);let t=0;for(let n=0;n<this.order;n++)t+=this._basisValues[n]*this.coffs[n];return t}deflateLeft(){const e=this.order,t=e-1,n=Be.getRow(t-1),i=Be.getRow(e-1);let s;for(let r=0;r<t;r++)s=this.coffs[r+1],this.coffs[r]=s*i[r+1]/n[r];this._order--}deflateRight(){const e=this.order,t=e-1,n=Be.getRow(t-1),i=Be.getRow(e-1);let s,r;for(let a=0;a<t;a++)s=this.coffs[a],r=s*i[a]/n[a],this.coffs[a]=r;this._order--}deflateRoot(e){const t=this.order,n=t-1;if(t===1)return this._order=0,this.coffs[0];if(t<1)return this._order=0,0;const i=Be.getRow(t-1),s=Be.getRow(n-1),r=-e,a=1-e;let o=0;if(e>.5){let c=this.coffs[0]/r,d;this.coffs[0]=c;let h;for(let u=1;u<n;u++)h=this.coffs[u]*i[u],d=(h-c*a)/r,this.coffs[u]=d/s[u],c=d;o=this.coffs[t-1]-c*a}else{let c=this.coffs[t-1]/a,d;this.coffs[t-1]=c;let h;for(let u=t-2;u>0;u--)h=this.coffs[u]*i[u],d=(h-c*r)/a,this.coffs[u]=d/s[u-1],c=d;o=this.coffs[0]-c*r;for(let u=0;u<n;u++)this.coffs[u]=this.coffs[u+1]}return this._order=n,o}static _basisBuffer;static _basisBuffer1;runNewton(e,t=f.smallNewtonStep){const n=this.order-1;let i=0,s=e,r,a;const o=10,c=this.order,d=this.coffs,h=c-1,u=20;for(let g=0;g<u;g++){it._basisBuffer=Be.getBezierBasisValues(c,s,it._basisBuffer),r=0;for(let p=0;p<c;p++)r+=d[p]*it._basisBuffer[p];it._basisBuffer1=Be.getBezierBasisValues(h,s,it._basisBuffer1),a=0;for(let p=0;p<h;p++)a+=(d[p+1]-d[p])*it._basisBuffer1[p];if(a*=n,Math.abs(r)>o*Math.abs(a))return;const m=r/a;if(Math.abs(m)<t){if(i++,i>=2)return s-m}else i=0;s-=m}}static deflateRoots(e){const t=[],n=e.coffs;let i,s,r,a,o;for(;e.order>1;){const c=e.order;if(n[0]===0){e.deflateLeft(),t.push(0);continue}let d=0,h=0;for(let u=1;u<c;u++)if(i=n[u-1],s=n[u],i*s<=0&&(d++,r=-i/(s-i),a=(u-1+r)/(c-1),o=e.runNewton(a,1e-10),o!==void 0)){t.push(o),e.deflateRoot(o),h++;break}if(!h){if(d===0)break;break}}return t.length>0?t:void 0}}class Ls extends so{constructor(e=0,t=0){super(2),this.coffs[0]=e,this.coffs[1]=t}clone(){return new Ls(this.coffs[0],this.coffs[1])}static solveCoffs(e,t){return f.conditionalDivideFraction(-e,t-e)}basisFunctions(e,t){return(!t||t.length<2)&&(t=new Float64Array(2)),t[0]=1-e,t[1]=e,t}sumBasisFunctions(e,t,n,i){(!i||i.length<n)&&(i=new Float64Array(n));const s=1-e;for(let r=0;r<n;r++)i[r]=s*t[r]+e*t[r+n];return i}sumBasisFunctionDerivatives(e,t,n,i){(!i||i.length<n)&&(i=new Float64Array(n));for(let s=0;s<n;s++)i[s]=t[s+n]-t[s];return i}evaluate(e){return(1-e)*this.coffs[0]+e*this.coffs[1]}solve(e){const t=this.coffs[1]-this.coffs[0];return f.conditionalDivideFraction(e-this.coffs[0],t)}roots(e,t){const n=this.solve(e);if(n!==void 0&&(!t||f.isIn01(n)))return[n]}}class Tc extends Yr{_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(e,t){super(),this._plane=e,this._intersections=t,this.startCurvePrimitive(void 0),this._ray=q.createZero(),this._newtonSolver=new zr(this)}startCurvePrimitive(e){this._curve=e,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(e,t,n,i){this.startCurvePrimitive(e),t<1&&(t=1);const s=1/t;for(let r=0;r<=t;r++){const a=f.interpolate(n,r*s,i);e.fractionToPointAndDerivative(a,this._ray),this.announcePointTangent(this._ray.origin,a,this._ray.direction)}}announceSegmentInterval(e,t,n,i,s,r){const a=this._plane.altitude(t),o=this._plane.altitude(n);if(a*o>0)return;const c=Ls.solveCoffs(a,o);if(c!==void 0){const d=f.interpolate(s,c,r);this._newtonSolver.setX(d),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX())}}announceSolutionFraction(e){const t=this.effectiveCurve();t&&(this._ray=t.fractionToPointAndDerivative(e,this._ray),this._intersections.push(Y.createCurveFractionPoint(t,e,this._ray.origin)))}evaluate(e){const t=this.effectiveCurve();return t?(this.currentF=this._plane.altitude(t.fractionToPoint(e)),!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 e=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);e&&(this._newtonSolver.setX(e),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}evaluateB(e,t,n){this._functionB=this._plane.altitude(e),this._derivativeB=this._plane.velocity(n),this._fractionB=t}announcePointTangent(e,t,n){this.evaluateB(e,t,n),this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB}}class ro extends Yr{_curve;_closestPoint;_spacePoint;_extend;_xyOnly;_fractionA=0;_functionA=0;_fractionB=0;_functionB=0;_numThisCurve=0;_workPoint;_workRay;_newtonSolver;constructor(e,t,n,i){super(),this._spacePoint=e,this._workPoint=y.create(),this._workRay=q.createZero(),this._closestPoint=n,this._closestPoint&&(this._closestPoint.a=f.largeCoordinateResult),this._extend=t??!1,this._xyOnly=i??!1,this.startCurvePrimitive(void 0),this._newtonSolver=new zr(this)}claimResult(){if(this._closestPoint&&(this._newtonSolver.setX(this._closestPoint.fraction),this._curve=this._closestPoint.curve,this._newtonSolver.runIterations())){let e=this._newtonSolver.getX();e=Ge.correctFraction(this._extend,e),this.announceSolutionFraction(e)}return this._closestPoint}needPrimaryGeometryForStrokes(){return!0}startCurvePrimitive(e){this._curve=e,this._fractionA=0,this._numThisCurve=0,this._functionA=0}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(e,t,n,i){this.startCurvePrimitive(e),this.announceSolutionFraction(0),this.announceSolutionFraction(1),t<1&&(t=1);const s=1/t;for(let r=0;r<=t;r++){const a=f.interpolate(n,r*s,i);e.fractionToPointAndDerivative(a,this._workRay),this.announceRay(a,this._workRay)}}announceCandidate(e,t,n){const i=this._xyOnly?this._spacePoint.distanceXY(n):this._spacePoint.distance(n);this._closestPoint&&i>this._closestPoint.a||(this._closestPoint=Y.createCurveFractionPoint(e,t,n,this._closestPoint),this._closestPoint.a=i,this._parentCurvePrimitive!==void 0&&(this._closestPoint.curve=this._parentCurvePrimitive))}announceSegmentInterval(e,t,n,i,s,r){let a=0;this._xyOnly?a=Le.lineSegment3dXYClosestPointUnbounded(t,n,this._spacePoint)??0:a=this._spacePoint.fractionOfProjectionToLine(t,n,0);const o=s===0?Ge.resolveVariantCurveExtendParameterToCurveExtendMode(this._extend,0):je.None,c=r===1?Ge.resolveVariantCurveExtendParameterToCurveExtendMode(this._extend,1):je.None;a=Ge.correctFraction([o,c],a),this._workPoint=t.interpolate(a,n);const d=f.interpolate(s,a,r);this.announceCandidate(e,d,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 e=f.inverseInterpolate(this._fractionA,this._functionA,this._fractionB,this._functionB);e&&(this._newtonSolver.setX(e),this._newtonSolver.runIterations()&&this.announceSolutionFraction(this._newtonSolver.getX()))}}announceSolutionFraction(e){this._curve&&this.announceCandidate(this._curve,e,this._curve.fractionToPoint(e))}evaluateFunction(e,t,n){if(e)this._workRay.setFrom(e);else if(t!==void 0&&n)this._workRay=n.fractionToPointAndDerivative(t,this._workRay);else return;return this._xyOnly?this._workRay.dotProductToPointXY(this._spacePoint):this._workRay.dotProductToPoint(this._spacePoint)}evaluate(e){let t=this._curve;this._parentCurvePrimitive&&(t=this._parentCurvePrimitive);const n=this.evaluateFunction(void 0,e,t);return n===void 0?!1:(this.currentF=n,!0)}announceRay(e,t){const n=this.evaluateFunction(t);this._functionB=n,this._fractionB=e,this._numThisCurve++>0&&this.searchInterval(),this._functionA=this._functionB,this._fractionA=this._fractionB}announcePointTangent(e,t,n){this._workRay.set(e,n),this.announceRay(t,this._workRay)}}class ct{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(e,t,n,i,s,r){const a=n.length;for(let o=0;o<a;o++)s[o]=e+t*n[o],r[o]=t*i[o];return a}static setupGauss1(e,t,n,i){return ct.mapWeights(e,t-e,ct.gaussX1Interval01,ct.gaussW1Interval01,n,i)}static setupGauss2(e,t,n,i){return ct.mapWeights(e,t-e,ct.gaussX2Interval01,ct.gaussW2Interval01,n,i)}static setupGauss3(e,t,n,i){return ct.mapWeights(e,t-e,ct.gaussX3Interval01,ct.gaussW3Interval01,n,i)}static setupGauss5(e,t,n,i){return ct.mapWeights(e,t-e,ct.gaussX5Interval01,ct.gaussW5Interval01,n,i)}static setupGauss4(e,t,n,i){return ct.mapWeights(e,t-e,ct.gaussX4Interval01,ct.gaussW4Interval01,n,i)}static sum1(e,t,n,i){let s=0;for(let r=0;r<n;r++)s+=t[r]*i(e[r]);return s}static doGaussIntegral(e,t,n,i,s=5){const r=new Br(s);i<1&&(i=1);const a=1/i;let o=0;for(let c=1;c<=i;c++){const d=f.interpolate(e,(c-1)*a,t),h=c===i?t:f.interpolate(e,c*a,t),u=r.mapXAndW(d,h);for(let g=0;g<u;g++)o+=r.gaussW[g]*n(r.gaussX[g])}return o}}class Br{gaussX;gaussW;mapXAndWFunction;mapXAndW(e,t){return this.mapXAndWFunction(e,t,this.gaussX,this.gaussW)}constructor(e){switch(this.gaussX=new Float64Array(7),this.gaussW=new Float64Array(7),(e>5||e<1)&&(e=5),e){case 1:this.mapXAndWFunction=(n,i,s,r)=>ct.setupGauss1(n,i,s,r);break;case 2:this.mapXAndWFunction=(n,i,s,r)=>ct.setupGauss2(n,i,s,r);break;case 3:this.mapXAndWFunction=(n,i,s,r)=>ct.setupGauss3(n,i,s,r);break;case 4:this.mapXAndWFunction=(n,i,s,r)=>ct.setupGauss4(n,i,s,r);break;default:this.mapXAndWFunction=(n,i,s,r)=>ct.setupGauss5(n,i,s,r);break}}}class Ur{_curve;_summedLength;_ray;_fraction0;_fraction1;_gaussMapper;tangentMagnitude(e){return this._ray=this._curve.fractionToPointAndDerivative(e,this._ray),this._ray.direction.magnitude()}get getFraction0(){return this._fraction0}get getFraction1(){return this._fraction1}getSum(){return this._summedLength}constructor(e=0,t=1,n=5){this.startCurvePrimitive(void 0),this._summedLength=0,this._ray=q.createZero(),e<t?(this._fraction0=e,this._fraction1=t):(this._fraction0=t,this._fraction1=e),this._gaussMapper=new Br(n)}startCurvePrimitive(e){this._curve=e}startParentCurvePrimitive(e){}endParentCurvePrimitive(e){}endCurvePrimitive(){}announceIntervalForUniformStepStrokes(e,t,n,i){const s=fe.createXX(n,i);if(s.intersectRangeXXInPlace(this._fraction0,this._fraction1),!s.isNull){this.startCurvePrimitive(e),t<1&&(t=1);const r=1/t;for(let a=1;a<=t;a++){const o=s.fractionToPoint((a-1)*r),c=a===t?s.high:s.fractionToPoint(a*r),d=this._gaussMapper.mapXAndW(o,c);for(let h=0;h<d;h++)this._summedLength+=this._gaussMapper.gaussW[h]*this.tangentMagnitude(this._gaussMapper.gaussX[h])}}}announceSegmentInterval(e,t,n,i,s,r){const a=t.distance(n);if(this._fraction0<=s&&r<=this._fraction1)this._summedLength+=a;else{const o=fe.createXX(s,r);o.intersectRangeXXInPlace(this._fraction0,this._fraction1),o.isNull||(this._summedLength+=a*o.length()/(r-s))}}announcePointTangent(e,t,n){}}class le extends Mt{geometryCategory="curvePrimitive";constructor(){super()}strokeData;startCut;endCut;parent;fractionToPointAndUnitTangent(e,t){const n=this.fractionToPointAndDerivative(e,t);return n.trySetDirectionMagnitudeInPlace(1),n}fractionToCurvature(e){const t=this.fractionToPointAnd2Derivatives(e);if(!t)return;const i=t.vectorU.crossProduct(t.vectorV).magnitude(),s=t.vectorU.magnitude();return f.conditionalDivideFraction(i,s*s*s)}fractionToFrenetFrame(e,t){const n=this.fractionToPointAnd2Derivatives(e);if(!n)return;let i=E.createRigidFromColumns(n.vectorU,n.vectorV,ve.XYZ);if(i)return X.createRefs(n.origin,i,t);const s=E.createPerpendicularVectorFavorXYPlane(n.vectorU,n.vectorV);if(i=E.createRigidFromColumns(n.vectorU,s,ve.XYZ),i)return X.createRefs(n.origin,i,t)}fractionToSignedXYRadiusOfCurvature(e){const t=this.fractionToPointAnd2Derivatives(e);if(!t)return 0;const n=t.vectorU.crossProductXY(t.vectorV),i=t.vectorU.magnitude();if(i===0)return 0;const s=f.conditionalDivideCoordinate(i*i*i,n);return s!==void 0?s:0}fractionAndDistanceToPointOnTangent(e,t){return this.fractionToPointAndUnitTangent(e).fractionToPoint(t)}curveLength(){const e=new Ur;return this.emitStrokableParts(e),e.getSum()}curveLengthBetweenFractions(e,t){if(e===t)return 0;if(this.getFractionToDistanceScale()!==void 0){const s=this.curveLength();return Math.abs((t-e)*s)}const i=new Ur(e,t);return this.emitStrokableParts(i),Math.abs(i.getSum())}rangeBetweenFractions(e,t,n){return this.rangeBetweenFractionsByClone(e,t,n)}rangeBetweenFractionsByClone(e,t,n){if(e===t)return ie.create(this.fractionToPoint(e));const i=this.clonePartialCurve(e,t);return i?i.range(n):ie.createNull()}rangeBetweenFractionsByCount(e,t,n,i,s=0){const r=ie.createNull(),a=y.create();r.extendPoint(this.startPoint(a)),r.extendPoint(this.endPoint(a));const o=(d,h,u)=>{let g=d;for(let m=0;m<u;m++,g+=h)this.fractionToPoint(g,a),i?r.extendTransformedPoint(i,a):r.extendPoint(a)},c=n-2;if(c>0){const h=1/(c+1)*(t-e);o(e+h,h,c)}if(s>0){const d=r.clone(),h=c+1,g=2*(.5/h)*(t-e);o(e+g*.5,g,h),r.extendWhenLarger(d,s)}return r}curveLengthWithFixedIntervalCountQuadrature(e,t,n,i=5){if(e>t){const r=e;e=t,t=r}const s=new Ur(e,t,i);return s.announceIntervalForUniformStepStrokes(this,n,e,t),Math.abs(s.getSum())}moveSignedDistanceFromFraction(e,t,n,i){if(this.getFractionToDistanceScale()!==void 0){const r=this.curveLength(),a=f.conditionalDivideFraction(t,r);return a===void 0?Y.createCurveFractionPointDistanceCurveSearchStatus(this,e,this.fractionToPoint(e),0,Yt.error):Y.createConditionalMoveSignedDistance(n,this,e,e+a,t,i)}return this.moveSignedDistanceFromFractionGeneric(e,t,n,i)}moveSignedDistanceFromFractionGeneric(e,t,n,i){let s;if(t===0)return Y.createCurveEvaluatedFraction(this,e,i);t>0?(s=1,e>=1&&(t+=this.curveLengthBetweenFractions(.9,e),e=.9)):(s=0,e<=0&&(t-=this.curveLengthBetweenFractions(e,.1),e=.1));const a=this.curveLengthBetweenFractions(e,s),o=Math.abs(t);if(a<o&&!n)return Y.createConditionalMoveSignedDistance(n,this,e,s,t,i);const c=f.conditionalDivideCoordinate(o,a);if(c===void 0)return i=Y.createCurveEvaluatedFraction(this,e,i),i.curveSearchStatus=Yt.error,i;const d=t<0?-1:1;let h=f.interpolate(e,c,s),u=e,g=0;const m=1e-12*a;let p=0;const x=q.createXAxis();for(let _=0;_<10;_++){const I=this.curveLengthBetweenFractions(u,h),S=h>u?d:-d,A=g+S*I,w=o-A;if(Math.abs(w)<m){if(p++,p>1)break}else p=0;this.fractionToPointAndDerivative(h,x);const k=x.direction.magnitude();if(u=h,h=u+d*w/k,u===h){p=100;break}g=A}return p>1?Y.createConditionalMoveSignedDistance(n,this,e,h,t,i):(i=Y.createCurveEvaluatedFraction(this,e,i),i.curveSearchStatus=Yt.error,i)}get isExtensibleFractionSpace(){return!1}closestPoint(e,t=!1,n){const i=new ro(e,t,n);return this.emitStrokableParts(i),i.claimResult()}closestPointXY(e,t=!1,n){const i=new ro(e,t,n,!0);return this.emitStrokableParts(i),i.claimResult()}emitTangents(e,t,n){const i=new io(e,t,n);this.emitStrokableParts(i,n?.strokeOptions)}allTangents(e,t){const n=[];return this.emitTangents(e,i=>n.push(i.clone()),t),n.length===0?void 0:n}closestTangent(e,t){const n=t?.hintPoint??e;let i;t?.vectorToEye&&!t.vectorToEye.isExactEqual({x:0,y:0,z:1})&&(i=E.createRigidViewAxesZTowardsEye(t.vectorToEye.x,t.vectorToEye.y,t.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,a=f.largeCoordinateResult;const o=c=>{const d=s(c.point);(!r||d<a)&&(r=c.clone(r),a=d)};return this.emitTangents(e,o,t),r}announceClipIntervals(e,t){return e.announceClippedCurveIntervals?.(this,t)??!1}clonePartialCurve(e,t){}getFractionToDistanceScale(){}reverse(){return this.reverseInPlace(),this}appendPlaneIntersectionPoints(e,t){const n=new Tc(e,t),i=t.length;return this.emitStrokableParts(n),t.length-i}static snapAndRestrictDetails(e,t=!0,n=!1,i=f.smallAngleRadians,s=f.smallMetricDistance){const r=e.length;let a=0;const o=y.create(),c=y.create();let d;for(let h=0;h<r;h++){d=void 0;const u=e[h];let g=u.fraction,m=t||f.isIn01(g);u.curve&&(u.curve.startPoint(o),u.curve.endPoint(c)),i>0&&(Math.abs(g)<i&&(g=0,m=!0,u.intervalRole=Fe.isolatedAtVertex,d=o),Math.abs(g-1)<i&&(g=1,m=!0,u.intervalRole=Fe.isolatedAtVertex,d=c,u.curve&&(d=u.curve.startPoint(c)))),s>0&&u.curve!==void 0&&(u.point.distance(o)<=s?(g=0,u.intervalRole=Fe.isolatedAtVertex,d=o):u.point.distance(c)<=s&&(g=1,u.intervalRole=Fe.isolatedAtVertex,d=c)),m&&(n&&(u.fraction=g,d!==void 0&&u.point.setFrom(d)),a<h&&(e[a]=u),a++)}a<r&&(e.length=a)}startPoint(e){return this.fractionToPoint(0,e)}endPoint(e){return this.fractionToPoint(1,e)}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){const n=this.startPoint(),i=this.endPoint();return n!==void 0&&i!==void 0&&(t?n.isAlmostEqualXY(i,e):n.isAlmostEqual(i,e))}computeAndAttachRecursiveStrokeCounts(e,t){const n=this.computeStrokeCountForOptions(e),i=this.curveLength();le.installStrokeCountMap(this,pn.createWithCurvePrimitive(this,n,i,0,i),t)}addMappedStrokesToLineString3D(e,t){const n=t.numPoints();if(e.primitive&&e.primitive===this&&e.numStroke>0)for(let i=0;i<=e.numStroke;i++){const s=i/e.numStroke;t.appendFractionToPoint(this,s)}return t.numPoints()-n}static installStrokeCountMap(e,t,n){n&&n.addToCountAndLength(t.numStroke,t.curveLength),e.strokeData=t}collectCurvePrimitivesGo(e,t,n=!1){e.push(this)}collectCurvePrimitives(e,t=!1,n=!1){const i=e===void 0?[]:e;return this.collectCurvePrimitivesGo(i,t,n),i}projectedParameterRange(e,t){}}class Qe extends Fs{data;constructor(e){super(),this.data=e}isValidIndex(e){return this.isIndexValid(e)}getPoint3dAtCheckedPointIndex(e,t){if(this.isValidIndex(e)){const n=this.data[e];return y.create(n.x,n.y,n.z,t)}}getPoint3dAtUncheckedPointIndex(e,t){const n=this.data[e];return y.create(n.x,n.y,n.z,t)}getVector3dAtCheckedVectorIndex(e,t){if(this.isValidIndex(e)){const n=this.data[e];return v.create(n.x,n.y,n.z,t)}}getXAtUncheckedPointIndex(e){return this.data[e].x}getYAtUncheckedPointIndex(e){return this.data[e].y}getZAtUncheckedPointIndex(e){return this.data[e].z}vectorIndexIndex(e,t,n){if(this.isValidIndex(e)&&this.isValidIndex(t))return this.vectorUncheckedIndexIndex(e,t,n)}vectorUncheckedIndexIndex(e,t,n){return v.createStartEnd(this.data[e],this.data[t],n)}vectorXYAndZIndex(e,t,n){if(this.isValidIndex(t))return this.vectorXYAndZUncheckedIndex(e,t,n)}vectorXYAndZUncheckedIndex(e,t,n){return v.createStartEnd(e,this.data[t],n)}crossProductXYAndZIndexIndex(e,t,n,i){if(this.isValidIndex(t)&&this.isValidIndex(n))return v.createCrossProductToPoints(e,this.data[t],this.data[n],i)}crossProductIndexIndexIndex(e,t,n,i){if(this.isValidIndex(e)&&this.isValidIndex(t)&&this.isValidIndex(n))return this.crossProductUncheckedIndexIndexIndex(e,t,n,i)}crossProductUncheckedIndexIndexIndex(e,t,n,i){return v.createCrossProductToPoints(this.data[e],this.data[t],this.data[n],i)}crossProductUncheckedIndexIndexXYAndZ(e,t,n,i){return v.createCrossProductToPoints(this.data[e],this.data[t],n,i)}accumulateCrossProductIndexIndexIndex(e,t,n,i){const s=this.data;this.isValidIndex(e)&&this.isValidIndex(t)&&this.isValidIndex(n)&&i.addCrossProductToTargetsInPlace(s[e].x,s[e].y,s[e].z,s[t].x,s[t].y,s[t].z,s[n].x,s[n].y,s[n].z)}accumulateScaledXYZ(e,t,n){if(this.isValidIndex(e)){const i=this.data[e];n.x+=t*i.x,n.y+=t*i.y,n.z+=t*i.z}}get length(){return this.data.length}push(e){this.data.push(e.clone())}pushXYZ(e,t,n){this.data.push(y.create(e===void 0?0:e,t===void 0?0:t,n===void 0?0:n))}back(e){if(this.data.length>0)return this.data[this.data.length-1].clone(e)}front(e){if(this.data.length>0)return this.data[0].clone(e)}pop(){this.data.length>0&&this.data.pop()}clear(){this.data.length=0}reverseInPlace(){this.data.reverse()}distanceSquaredIndexIndex(e,t){const n=this.data.length;if(e>=0&&e<n&&t>=0&&t<n)return this.distanceSquaredUncheckedIndexIndex(e,t)}distanceSquaredUncheckedIndexIndex(e,t){return this.data[e].distanceSquared(this.data[t])}distanceIndexIndex(e,t){const n=this.data.length;if(e>=0&&e<n&&t>=0&&t<n)return this.distanceUncheckedIndexIndex(e,t)}distanceUncheckedIndexIndex(e,t){return this.data[e].distance(this.data[t])}cyclicIndex(e){return e%this.data.length}}function ao(l,e,t){if(e!==void 0){const n=e*t;if(n>=0&&n<=l)return n}return l}class Tt{static preciseSum(e){const t=e.length;if(t===0)return 0;let n=e[0],i=0,s,r;for(let a=1;a<t;a++)s=e[a]-i,r=n+s,i=r-n-s,n=r;return n}static isExactEqual(e,t){if(e&&t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return e===void 0&&t===void 0}static isAlmostEqual(e,t,n=f.smallMetricDistance){if(e&&t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(Math.abs(e[i]-t[i])>n)return!1;return!0}return e===void 0&&t===void 0}static sum(e){let t=0;for(const n of e)t+=n;return t}static isCoordinateInArray(e,t){if(t){for(const n of t)if(f.isSameCoordinate(e,n))return!0}return!1}static maxAbsArray(e){const t=e.length;if(t===0)return 0;let n=Math.abs(e[0]);for(let i=1;i<t;i++){const s=Math.abs(e[i]);n<s&&(n=s)}return n}static maxAbsTwo(e,t){return e=Math.abs(e),t=Math.abs(t),e>t?e:t}static maxAbsDiff(e,t){let n=0;const i=Math.min(e.length,t.length);for(let s=0;s<i;s++)n=Math.max(n,Math.abs(e[s]-t[s]));return n}static maxAbsDiffFloat64(e,t){let n=0;const i=Math.min(e.length,t.length);for(let s=0;s<i;s++)n=Math.max(n,Math.abs(e[s]-t[s]));return n}static createArrayWithMaxStepSize(e,t,n){if(e===t)return[e];const i=t-e,s=Math.max(1,Math.floor(Math.abs(i/n))),r=[];r.push(e);for(let a=1;a<s;a++)r.push(e+a/s*i);return r.push(t),r}static create(e){const t=[];for(const n of e)t.push(n);return t}static copy2d(e){const t=[];for(const n of e){const i=[];for(const s of n)i.push(s);t.push(i)}return t}static copy3d(e){const t=[];for(const n of e){const i=[];for(const s of n){const r=[];for(const a of s)r.push(a);i.push(r)}t.push(i)}return t}static unpack2d(e,t){if(!(t<1))return lt.unpackNumbersToNestedArrays(e,t)}static unpack3d(e,t,n){if(!(n<1||t<1))return lt.unpackNumbersToNestedArraysIJK(e,n,t)}static pack(e){const t=e.length;let n=0,i=0,s=0;t>0&&(s=t,Array.isArray(e[0])&&(n=e[0].length,n>0&&(s*=n,Array.isArray(e[0][0])&&(i=e[0][0].length,i>0&&(s*=i)))));const r=new Float64Array(s);if(i>0){const a=e;for(let o=0,c=0;o<t;++o)for(let d=0;d<n;++d)for(let h=0;h<i;++h)r[c++]=a[o][d][h]}else if(n>0){const a=e;for(let o=0,c=0;o<t;++o)for(let d=0;d<n;++d)r[c++]=a[o][d]}else if(t>0){const a=e;for(let o=0,c=0;o<t;++o)r[c++]=a[o]}return r}static cloneWithStartAndEndMultiplicity(e,t,n){const i=[];if(e===void 0||e.length===0)return i;let s=1;const r=e[0],a=e[e.length-1];for(;s<e.length&&e[s]===r;)s++;let o=1;const c=e.length-1;for(;c-o>=0&&e[c-o]===a;)o++;for(let d=0;d<t;d++)i.push(r);for(let d=s;d+o<e.length;d++)i.push(e[d]);for(let d=0;d<n;d++)i.push(a);return i}static linearCombination(e,t){const n=Math.min(e.length,t.length);let i=0;for(let s=0;s<n;++s)i+=t[s]*e[s];return i}static linearCombinationOfColors(e,t){const n=Math.min(e.length,t.length),i=[0,0,0,0];for(let s=0,r=0;s<4;++s,r+=8){for(let a=0;a<n;++a){const o=f.clamp(t[a],0,1),c=e[a]>>>r&255;i[s]+=o*c}i[s]=(Math.floor(i[s])&255)<<r}return i[0]|i[1]|i[2]|i[3]}static searchStrictlyIncreasingNumbers(e,t){const n=e.length-1;if(n<=0||t<0||t>=e[n])return;let i=Math.floor(t*n/e[n]);for(;e[i]>t;)i--;for(;e[i+1]<=t;)i++;return i}}class oo{static packPointsAndWeightsToFloat64Array(e,t,n){if(Array.isArray(e)&&e[0]instanceof y){const a=e;if(a.length!==t.length)return;const o=4*a.length;(!n||n.length<o)&&(n=new Float64Array(o));for(let c=0,d=0;d<a.length;d++)n[c++]=a[d].x,n[c++]=a[d].y,n[c++]=a[d].z,n[c++]=t[d];return n}const i=e,s=t.length;if(i.length!==3*s)return;const r=4*s;(!n||n.length<r)&&(n=new Float64Array(r));for(let a=0,o=0;o<s;o++){const c=3*o;n[a++]=i[c],n[a++]=i[c+1],n[a++]=i[c+2],n[a++]=t[o]}return n}static packToFloat64Array(e,t){const n=4*e.length;(!t||t.length<n)&&(t=new Float64Array(n));let i=0;for(const s of e)t[i++]=s.x,t[i++]=s.y,t[i++]=s.z,t[i++]=s.w;return t}static unpackToPoint4dArray(e){const t=[];for(let n=0;n+3<e.length;n+=4)t.push(Z.create(e[n],e[n+1],e[n+2],e[n+3]));return t}static unpackFloat64ArrayToPointsAndWeights(e,t,n,i=(s,r,a)=>y.create(s,r,a)){t.length=0,n.length=0;for(let s=0;s+3<e.length;s+=4)t.push(i(e[s],e[s+1],e[s+2])),n.push(e[s+3])}static _workPoint4d=Z.create();static multiplyInPlace(e,t){const n=t.length,i=oo._workPoint4d;for(let s=0;s+3<n;s+=4)e.multiplyXYZW(t[s],t[s+1],t[s+2],t[s+3],i),t[s]=i.x,t[s+1]=i.y,t[s+2]=i.z,t[s+3]=i.w}static isAlmostEqual(e,t,n=f.smallMetricDistance){if(e&&t){if(e instanceof Float64Array&&t instanceof Float64Array){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!f.isSameCoordinate(e[i],t[i],n))return!1}else if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].isAlmostEqual(t[i],n))return!1}else{const i=e instanceof Float64Array?t:e,s=e instanceof Float64Array?e:t;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 e===void 0&&t===void 0}static isCloseToPlane(e,t,n=f.smallMetricDistance){if(Array.isArray(e)){for(const i of e)if(Math.abs(t.altitudeXYZW(i.x,i.y,i.z,i.w))>n)return!1}else if(e instanceof Float64Array){const i=e.length;for(let s=0;s+2<i;s+=4)if(Math.abs(t.altitudeXYZW(e[s],e[s+1],e[s+2],e[s+3]))>n)return!1}return!0}}class lt{static packToFloat64Array(e,t){const n=3*e.length;(!t||t.length<n)&&(t=new Float64Array(n));let i=0;for(const s of e)t[i++]=s.x,t[i++]=s.y,t[i++]=s.z;return t}static packToNumberArray(e,t){const n=3*e.length;t||(t=Array(n)),t.length=n;let i=0;for(const s of e)t[i++]=s.x,t[i++]=s.y,t[i++]=s.z;return t}static evaluateTrilinearWeights(e,t,n,i,s,r,a){e[0]=t*i*r,e[1]=n*i*r,e[2]=t*s*r,e[3]=n*s*r,e[4]=t*i*a,e[5]=n*i*a,e[6]=t*s*a,e[7]=n*s*a}static sumWeightedX(e,t){let n=0;const i=e.length;for(let s=0;s<i;s++)n+=e[s]*t[s].x;return n}static sumWeightedY(e,t){let n=0;const i=e.length;for(let s=0;s<i;s++)n+=e[s]*t[s].y;return n}static sumWeightedZ(e,t){let n=0;const i=e.length;for(let s=0;s<i;s++)n+=e[s]*t[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(e,t,n,i,s){s||(s=y.create(0,0,0)),this.evaluateTrilinearWeights(this._weightUVW,1-t,t,1-n,n,1-i,i);let r;for(let a=0;a<8;a++)r=this._weightUVW[a],s.x+=r*e[a].x,s.y+=r*e[a].y,s.z+=r*e[a].z;return s}static evaluateTrilinearDerivativeTransform(e,t,n,i,s){return this.evaluateTrilinearWeights(this._weightUVW,1-t,t,1-n,n,1-i,i),this.evaluateTrilinearWeights(this._weightDU,-1,1,1-n,n,1-i,i),this.evaluateTrilinearWeights(this._weightDV,1-t,t,-1,1,1-i,i),this.evaluateTrilinearWeights(this._weightDW,1-t,t,1-n,n,-1,1),X.createRowValues(this.sumWeightedX(this._weightDU,e),this.sumWeightedX(this._weightDV,e),this.sumWeightedX(this._weightDW,e),this.sumWeightedX(this._weightUVW,e),this.sumWeightedY(this._weightDU,e),this.sumWeightedY(this._weightDV,e),this.sumWeightedY(this._weightDW,e),this.sumWeightedY(this._weightUVW,e),this.sumWeightedZ(this._weightDU,e),this.sumWeightedZ(this._weightDV,e),this.sumWeightedZ(this._weightDW,e),this.sumWeightedZ(this._weightUVW,e),s)}static unpackNumbersToPoint3dArray(e){const t=[];for(let n=0;n+2<e.length;n+=3)t.push(y.create(e[n],e[n+1],e[n+2]));return t}static unpackNumbersToNestedArrays(e,t){const n=[],i=e.length;let s=0,r=0;for(;s<i;){const a=[];for(r=s+t,r>i&&(r=i);s<r;s++)a.push(e[s]);n.push(a)}return n}static unpackNumbersToNestedArraysIJK(e,t,n){const i=[],s=e.length;let r=0,a=0,o;for(;r<s;){const c=[];for(o=r+t*n;r<o;){const d=[];for(a=r+t,a>s&&(a=s);r<a;r++)d.push(e[r]);c.push(d)}i.push(c)}return i}static multiplyInPlace(e,t){const n=y.create(),i=t.length;for(let s=0;s+2<i;s+=3)e.multiplyXYZ(t[s],t[s+1],t[s+2],n),t[s]=n.x,t[s+1]=n.y,t[s+2]=n.z}static isAlmostEqual(e,t,n=f.smallMetricDistance){if(e&&t){if(e instanceof Float64Array&&t instanceof Float64Array){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!f.isSameCoordinate(e[i],t[i],n))return!1}else if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].isAlmostEqual(t[i],n))return!1}else{const i=e instanceof Float64Array?t:e,s=e instanceof Float64Array?e:t;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 e===void 0&&t===void 0}static centroid(e,t){if(e instanceof gt){t=y.create(0,0,0,t);const i=y.create();if(e.length>0){for(let s=0;s<e.length;s++)e.getPoint3dAtCheckedPointIndex(s,i),t.x+=i.x,t.y+=i.y,t.z+=i.z;t.scaleInPlace(1/e.length)}return t}const n=new Qe(e);return this.centroid(n)}static indexOfMostDistantPoint(e,t,n){if(e.length===0)return;let i=-1,s,r=-1;for(let a=0;a<e.length;a++)s=t.distance(e[a]),s>i&&(t.vectorTo(e[a],n),i=s,r=a);return r}static indexOfPointWithMaxCrossProductMagnitude(e,t,n,i){if(e.length===0)return;let s=-1,r,a=-1,o;for(let c=0;c<e.length;c++)o=t.vectorTo(e[c],o),r=o.crossProductMagnitude(n),r>s&&(i.setFrom(o),s=r,a=c);return a}static closestPointIndex(e,t){let n=-1,i=Number.MAX_VALUE,s;const r=t.x,a=t.y,o=t.z;for(let c=0;c<e.length;c++)s=f.distanceXYZXYZ(r,a,o,e[c].x,e[c].y,e[c].z),s<i&&(n=c,i=s);return n}static isCloseToPlane(e,t,n=f.smallMetricDistance){if(Array.isArray(e)){let i;for(i of e)if(Math.abs(t.altitude(i))>n)return!1}else if(e instanceof Float64Array){const i=e.length;for(let s=0;s+2<i;s+=3)if(Math.abs(t.altitudeXYZ(e[s],e[s+1],e[s+2]))>n)return!1}return!0}static sumEdgeLengths(e,t=!1,n){let i=0;if(Array.isArray(e)){const s=ao(e.length,n,1)-1;for(let r=0;r<s;r++)i+=e[r].distance(e[r+1]);t&&s>0&&(i+=e[0].distance(e[s]))}else if(e instanceof Float64Array){const s=ao(e.length,n,3);let r=0;for(;r+5<s;r+=3)i+=f.hypotenuseXYZ(e[r+3]-e[r],e[r+4]-e[r+1],e[r+5]-e[r+2]);t&&r>=3&&(i+=f.hypotenuseXYZ(e[0]-e[r],e[1]-e[r+1],e[2]-e[r+2]))}return i}static countNonDuplicates(e,t=f.smallMetricDistance){let n=e.length;for(;n>1&&e[0].isAlmostEqual(e[n-1],t);)n--;for(let i=0;i+1<n;i++)if(e[i].isAlmostEqual(e[i+1],t))return 0;return n}static clonePoint3dArray(e){const t=[];if(e.length===0)return t;if(e instanceof Float64Array){for(let n=0;n+2<e.length;n+=3)t.push(y.create(e[n],e[n+1],e[n+2]));return t}for(const n of e)Array.isArray(n)?t.push(y.create(n[0],n[1],n[2])):t.push(y.create(n.x,n.y,n.z));return t}static clonePoint2dArray(e){return e.map(t=>L.create(t.x,t.y))}static cloneWithMaxEdgeLength(e,t){if(e.length===0)return[];const n=[e[0]];for(let i=1;i<e.length;i++){const s=e[i-1].distance(e[i]),r=f.stepCount(t,s,1);for(let a=1;a<r;a++)n.push(e[i-1].interpolate(a/r,e[i]));n.push(e[i])}return n}static xyzToArray(e,t,n){return[e,t,n]}static cloneDeepJSONNumberArrays(e){const t=new Ka((n,i,s)=>this.xyzToArray(n,i,s));return Yn.streamXYZ(e,t),t.claimResult()}static cloneXYZPropsAsNumberArray(e){const t=[];for(const n of e)if(n instanceof y)t.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;t.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;t.push([i,s,r])}return t}static cloneXYZPropsAsFloat64Array(e){const t=new Float64Array(e.length*3);let n=0;for(const i of e)i instanceof y?(t[n++]=i.x,t[n++]=i.y,t[n++]=i.z):Array.isArray(i)?(t[n++]=i.length>0?i[0]:0,t[n++]=i.length>1?i[1]:0,t[n++]=i.length>2?i[2]:0):(t[n++]=i.x!==void 0?i.x:0,t[n++]=i.y!==void 0?i.y:0,t[n++]=i.z!==void 0?i.z:0);return t}static cloneDeepXYZPoint3dArrays(e){const t=new Ka((n,i,s)=>y.create(n,i,s));return Yn.streamXYZ(e,t),t.claimResult()}static distanceIndexedPointBToSegmentAC(e,t,n,i,s){const r=v.createStartEnd(e[t],e[i]),a=v.createStartEnd(e[t],e[n]),o=r.dotProduct(r),c=r.dotProduct(a),d=f.conditionalDivideFraction(c,o);if(d===void 0)return a.magnitude();if(!s){if(d>1)return e[n].distance(e[i]);if(d<0)return a.magnitude()}const h=a.magnitudeSquared()-d*d*o;return h<=0?0:Math.sqrt(h)}static computeConvexHullXY(e,t,n,i=!1){t.length=0,n.length=0;let s=e.length;const r=e.slice(0,s);if(r.sort((c,d)=>f.lexicalXYLessThan(c,d)),s<3){for(const c of r)t.push(c);i&&r.length>0&&t.push(r[0]);return}t.push(r[0]),t.push(r[1]);let a=0;for(let c=2;c<s;c++){const d=r[c];let h=t.length-1;for(;h>=1&&t[h-1].crossProductToPointsXY(t[h],d)<=0;)r[a++]=t[h],h--,t.pop();t.push(d)}const o=t.length-1;r.length=a,r.push(t[0]),r.sort((c,d)=>f.lexicalXYLessThan(c,d)),s=r.length,t.push(r[s-1]);for(let c=s-1;c-- >0;){const d=r[c];let h=t.length-1;for(;h>o&&t[h-1].crossProductToPointsXY(t[h],d)<=0;)n.push(t[h]),h--,t.pop();c>0&&t.push(d)}i&&t.push(t[0])}static minMaxPoints(e){if(e.length===0)return;const t={minXPoint:e[0].clone(),maxXPoint:e[0].clone(),minYPoint:e[0].clone(),maxYPoint:e[0].clone()};let n;for(let i=1;i<e.length;i++)n=e[i],n.x<t.minXPoint.x&&t.minXPoint.setFromPoint3d(n),n.x>t.maxXPoint.x&&t.maxXPoint.setFromPoint3d(n),n.y<t.minYPoint.y&&t.minYPoint.setFromPoint3d(n),n.y>t.maxYPoint.y&&t.maxYPoint.setFromPoint3d(n);return t}}class co{static decomposeLU(e,t,n){const i=e-1,s=Math.floor(t/2);let r;for(let a=0;a<=i;a++){const o=Math.min(i,a+s);for(let c=a;c<=o;c++){const d=Math.max(0,c-s);r=0;for(let h=d;h<a;h++)r+=n[a*t+h-a+s]*n[h*t+c-h+s];n[a*t+c-a+s]-=r}for(let c=a+1;c<=o;c++){const d=Math.max(0,c-s);r=0;for(let h=d;h<a;h++)r+=n[c*t+h-c+s]*n[h*t+a-h+s];if(Math.abs(n[a*t+s])<1e-9)return!1;n[c*t+a-c+s]=(n[c*t+a-c+s]-r)/n[a*t+s]}}return!0}static arrayAddScaledBlock(e,t,n,i){const s=e.length;let r=s*n;for(let a=0;a<s;a++,r++)e[a]+=t[r]*i}static blockAssignBlockMinusArray(e,t,n,i,s){const r=s.length;let a=t*r,o=i*r;for(let c=0;c<r;c++,o++,a++)e[a]=n[o]-s[c]}static blockSumOfScaledBlockScaledArray(e,t,n,i,s,r,a){const o=r.length;let c=t*o,d=i*o;for(let h=0;h<o;h++,d++,c++)e[c]=n[d]*s+r[h]*a}static solveBandedSystemMultipleRHS(e,t,n,i,s){if(!this.decomposeLU(e,t,n))return;const r=e-1,a=Math.floor(t/2),o=new Float64Array(i),c=new Float64Array(i*e),d=new Float64Array(i*e);for(let h=0;h<=r;h++){o.fill(0);const u=Math.max(0,h-a);for(let g=u;g<h;g++)this.arrayAddScaledBlock(o,c,g,n[h*t+g-h+a]);this.blockAssignBlockMinusArray(c,h,s,h,o)}for(let h=r;h>=0;h--){const u=f.conditionalDivideCoordinate(1,n[h*t+a]);if(u===void 0)return;o.fill(0);const g=Math.min(r,h+a);for(let m=h+1;m<=g;m++)this.arrayAddScaledBlock(o,d,m,n[h*t+m-h+a]);this.blockSumOfScaledBlockScaledArray(d,h,c,h,u,o,-u)}return d}static multiplyBandedTimesFull(e,t,n,i,s){const r=new Float64Array(s.length),a=Math.floor(t/2);let o,c,d,h;for(let u=0;u<e;u++){c=u-a,c<0&&(c=0),d=u+a+1,d>e&&(d=e),h=a+u*(t-1);for(let g=0;g<i;g++){o=0;for(let m=c;m<d;m++)o+=n[h+m]*s[m*i+g];r[u*i+g]=o}}return r}}class Un{static _workPoint;getXAtUncheckedPointIndex(e){const t=this.getPoint2dAtCheckedPointIndex(e,Un._workPoint);return Un._workPoint===void 0&&(Un._workPoint=t),t?t.x:0}getYAtUncheckedPointIndex(e){const t=this.getPoint2dAtCheckedPointIndex(e,Un._workPoint);return Un._workPoint===void 0&&(Un._workPoint=t),t?t.y:0}linearCombination(e,t){const n=Math.min(this.length,e.length),i=t instanceof $?$.createZero(t):L.createZero(t);for(let s=0;s<n;++s)i.x+=e[s]*this.getXAtUncheckedPointIndex(s),i.y+=e[s]*this.getYAtUncheckedPointIndex(s);return i}}class Cc extends Un{}class Ct extends Cc{_data;_xyInUse;_xyCapacity;_growthFactor;constructor(e,t,n){super(),n?(this._xyCapacity=n.length/2,this._xyInUse=Math.min(e??1/0,this._xyCapacity),this._data=n):(this._xyCapacity=e??8,this._xyInUse=0,this._data=new Float64Array(2*this._xyCapacity)),this._growthFactor=t!==void 0&&t>=1?t:1.5}copyData(e,t,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=t!==void 0?t*2:e.length;return s>0&&(s>e.length&&(s=e.length),i+s>this._data.length&&(s=this._data.length-i),s%2!==0&&(s-=s%2)),s<=0?{count:0,offset:0}:(s===e.length?this._data.set(e,i):e instanceof Float64Array?this._data.set(e.subarray(0,s),i):this._data.set(e.slice(0,s),i),{count:s/2,offset:i/2})}get length(){return this._xyInUse}set length(e){this.resize(e,!0)}get float64Length(){return this._xyInUse*2}float64Data(){return this._data}ensureCapacity(e,t=!0){if(e>this._xyCapacity){t&&(e=Math.trunc(e*this._growthFactor));const n=this._data;this._data.buffer instanceof ArrayBuffer?this._data=new Float64Array(new ArrayBuffer(e*2*this._data.BYTES_PER_ELEMENT)):this._data=new Float64Array(new SharedArrayBuffer(e*2*this._data.BYTES_PER_ELEMENT)),this.copyData(n,this._xyInUse),this._xyCapacity=e}}resize(e,t){e>=0&&e<this._xyInUse?this._xyInUse=e:e>this._xyInUse&&(this.ensureCapacity(e,!1),(t??!1)&&this._data.fill(0,this._xyInUse*2),this._xyInUse=e)}clone(){const e=new Ct(this.length);return e.copyData(this._data,this.length),e._xyInUse=this.length,e}static create(e,t){if(t)t.clear();else{const n=typeof e[0]=="number"?e.length/2:e.length;t=new Ct(n)}return t.pushFrom(e),t}static createCapture(e){return new Ct(0,void 0,e)}static createArrayOfGrowableXYZArray(e){return J.createArrayOfGrowableXYZArray(e)}push(e){this.pushXY(e.x,e.y)}pushAll(e){this.ensureCapacity(this._xyInUse+e.length,!1);for(const t of e)this.push(t)}pushAllXYAndZ(e){if(this.ensureCapacity(this._xyInUse+e.length,!1),e instanceof J){const t=e.float64Data(),n=e.length*3;for(let i=0;i+2<n;i+=3)this.pushXY(t[i],t[i+1])}else for(const t of e)this.pushXY(t.x,t.y)}pushFrom(e){if(e instanceof y)this.pushXY(e.x,e.y);else if(e instanceof J)this.pushAllXYAndZ(e);else if(e instanceof L)this.pushXY(e.x,e.y);else if(f.isNumberArray(e,3)||e instanceof Float64Array){const t=Math.trunc(e.length/2);this.ensureCapacity(this._xyInUse+t,!1),this.copyData(e,t,this._xyInUse),this._xyInUse+=t}else if(f.isNumberArray(e,2))this.pushXY(e[0],e[1]);else if(Array.isArray(e))for(const t of e)this.pushFrom(t);else if(y.isXAndY(e))this.pushXY(e.x,e.y);else if(e instanceof Un){const t=e.length;this.ensureCapacity(this._xyInUse+t,!1);for(let n=0;n<t;n++)this.pushXY(e.getXAtUncheckedPointIndex(n),e.getYAtUncheckedPointIndex(n))}}pushWrap(e){if(this._xyInUse>=e){this.ensureCapacity(this._xyInUse+e,!1);for(let t=0;t<e;t++){const n=2*t;this.pushXY(this._data[n],this._data[n+1])}}}pushXY(e,t){this.ensureCapacity(this._xyInUse+1);const n=this._xyInUse*2;this._data[n]=e,this._data[n+1]=t,this._xyInUse++}pop(){this._xyInUse>0&&this._xyInUse--}isIndexValid(e){return!(e>=this._xyInUse||e<0)}clear(){this._xyInUse=0}getPoint2dAtUncheckedPointIndex(e,t){const n=2*e;return L.create(this._data[n],this._data[n+1],t)}getXAtUncheckedPointIndex(e){return this._data[2*e]}getYAtUncheckedPointIndex(e){return this._data[2*e+1]}getPoint2dArray(){const e=2*this._xyInUse,t=[],n=this._data;for(let i=0;i<e;i+=2)t.push(L.create(n[i],n[i+1]));return t}getPoint2dAtCheckedPointIndex(e,t){if(this.isIndexValid(e)){const n=2*e;return L.create(this._data[n],this._data[n+1],t)}}getVector2dAtCheckedVectorIndex(e,t){if(this.isIndexValid(e)){const n=2*e;return $.create(this._data[n],this._data[n+1],t)}}transferFromGrowableXYArray(e,t,n){if(this.isIndexValid(e)&&t.isIndexValid(n)){const i=e*2,s=n*2;return this._data[i]=t._data[s],this._data[i+1]=t._data[s+1],!0}return!1}pushFromGrowableXYArray(e,t){if(t===void 0){const n=e.length;return this.ensureCapacity(this.length+n,!1),this.copyData(e._data,n,this.length),this._xyInUse+=n,n}if(e.isIndexValid(t)){const n=t*2;return this.pushXY(e._data[n],e._data[n+1]),1}return 0}pushInterpolatedFromGrowableXYArray(e,t,n,i){if(e.isIndexValid(t)&&e.isIndexValid(i)){const s=1-n,r=e._data;t=2*t,i=2*i,this.pushXY(s*r[t]+n*r[i],s*r[t+1]+n*r[i+1])}}static createFromGrowableXYZArray(e,t,n){const i=e.length;if(n?(n.ensureCapacity(i,!1),n.clear()):n=new Ct(i),t){const s=e.float64Data(),r=3*i;let a,o,c;for(let d=0;d<r;d+=3)a=s[d],o=s[d+1],c=s[d+2],n.pushXY(t.multiplyComponentXYZ(0,a,o,c),t.multiplyComponentXYZ(1,a,o,c))}else n.pushAllXYAndZ(e);return n}front(e){if(this._xyInUse!==0)return this.getPoint2dAtUncheckedPointIndex(0,e)}back(e){if(!(this._xyInUse<1))return this.getPoint2dAtUncheckedPointIndex(this._xyInUse-1,e)}setAtCheckedPointIndex(e,t){if(!this.isIndexValid(e))return!1;const n=e*2;return this._data[n]=t.x,this._data[n+1]=t.y,!0}setXYAtCheckedPointIndex(e,t,n){if(!this.isIndexValid(e))return!1;const i=e*2;return this._data[i]=t,this._data[i+1]=n,!0}getPoint3dArray(e=0){const t=2*this._xyInUse,n=[],i=this._data;for(let s=0;s<t;s+=2)n.push(y.create(i[s],i[s+1],e));return n}reverseInPlace(){const e=this.length;let t,n,i;const s=this._data;for(let r=0,a=e-1;r<a;r++,a--)t=2*r,n=2*a,i=s[t],s[t]=s[n],s[n]=i,t++,n++,i=s[t],s[t]=s[n],s[n]=i}multiplyTransformInPlace(e){const t=this._data,n=this.float64Length,i=e.matrix.coffs,s=e.origin,r=s.x,a=s.y;let o=0,c=0;for(let d=0;d+1<n;d+=2)o=t[d],c=t[d+1],t[d]=i[0]*o+i[1]*c+r,t[d+1]=i[3]*o+i[4]*c+a}multiplyMatrix3dInPlace(e){const t=this._data,n=this.float64Length,i=e.coffs;let s=0,r=0;for(let a=0;a+1<n;a+=2)s=t[a],r=t[a+1],t[a]=i[0]*s+i[1]*r,t[a+1]=i[3]*s+i[4]*r}tryTransformInverseInPlace(e){const t=this._data,n=this.float64Length,i=e.matrix;i.computeCachedInverse(!0);const s=i.inverseCoffs;if(!s)return!1;const r=e.origin,a=r.x,o=r.y;let c=0,d=0;for(let h=0;h+1<n;h+=2)c=t[h]-a,d=t[h+1]-o,t[h]=s[0]*c+s[1]*d,t[h+1]=s[3]*c+s[4]*d;return!0}extendRange(e,t){const n=this.float64Length,i=this._data;if(t)for(let s=0;s+1<n;s+=2)e.extendTransformedXY(t,i[s],i[s+1]);else for(let s=0;s+1<n;s+=2)e.extendXY(i[s],i[s+1])}sumLengths(){let e=0;const t=2*(this._xyInUse-1),n=this._data;for(let i=0;i<t;i+=2)e+=f.hypotenuseXY(n[i+2]-n[i],n[i+3]-n[i+1]);return e}scaleInPlace(e){if(this._data){const t=this.float64Length;for(let n=0;n<t;n++)this._data[n]=this._data[n]*e}}interpolate(e,t,n,i){if(this.isIndexValid(e)&&this.isIndexValid(n)){const s=1-t,r=this._data;return e=2*e,n=2*n,L.create(s*r[e]+t*r[n],s*r[e+1]+t*r[n+1],i)}}areaXY(){let e=0;const t=2*this._xyInUse;if(t>4){const n=this._data[t-2],i=this._data[t-1];let s=this._data[0]-n,r=this._data[1]-i,a=0,o=0;for(let c=2;c<t;c+=2,s=a,r=o)a=this._data[c]-n,o=this._data[c+1]-i,e+=f.crossProductXYXY(s,r,a,o)}return .5*e}vectorIndexIndex(e,t,n){if(!this.isIndexValid(e)||!this.isIndexValid(t))return;const i=this._data;return e=2*e,t=2*t,$.create(i[t]-i[e],i[t+1]-i[e+1],n)}vectorXAndYIndex(e,t,n){if(this.isIndexValid(t)){const i=this._data;return t=2*t,$.create(i[t]-e.x,i[t+1]-e.y,n)}}crossProductIndexIndexIndex(e,t,n){if(this.isIndexValid(e)&&this.isIndexValid(t)&&this.isIndexValid(n)){const i=e*2,s=t*2,r=n*2,a=this._data;return f.crossProductXYXY(a[s]-a[i],a[s+1]-a[i+1],a[r]-a[i],a[r+1]-a[i+1])}}crossProductXAndYIndexIndex(e,t,n){if(this.isIndexValid(t)&&this.isIndexValid(n)){const i=t*2,s=n*2,r=this._data;return f.crossProductXYXY(r[i]-e.x,r[i+1]-e.y,r[s]-e.x,r[s+1]-e.y)}}distance(e,t){if(this.isIndexValid(e)&&this.isIndexValid(t)){const n=2*e,i=2*t;return f.hypotenuseXY(this._data[i]-this._data[n],this._data[i+1]-this._data[n+1])}}distanceIndexToPoint(e,t){if(this.isIndexValid(e)){const n=2*e;return f.hypotenuseXY(t.x-this._data[n],t.y-this._data[n+1])}}static isAlmostEqual(e,t){if(e&&t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e.getPoint2dAtUncheckedPointIndex(n).isAlmostEqual(t.getPoint2dAtUncheckedPointIndex(n)))return!1;return!0}return!e&&!t}sortIndicesLexical(){const e=this._xyInUse,t=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n;return t.sort((n,i)=>this.compareLexicalBlock(n,i)),t}compareLexicalBlock(e,t){let n=0,i=0;for(let s=0;s<2;s++){if(n=this._data[e*2+s],i=this._data[t*2+s],n>i)return 1;if(n<i)return-1}return e-t}component(e,t){return this._data[2*e+t]}isAlmostEqual(e,t=f.smallMetricDistance){const n=this._xyInUse;if(e._xyInUse!==n)return!1;const i=this._data,s=e._data;for(let r=0;r<2*n;r++)if(Math.abs(i[r]-s[r])>t)return!1;return!0}}class st{chordTol;angleTol;maxEdgeLength;needConvexFacets;minStrokesPerPrimitive;shouldTriangulate=!1;_needNormals;_needTwoSided;_needParams;get needParams(){return this._needParams!==void 0?this._needParams:!1}set needParams(e){this._needParams=e}get needNormals(){return this._needNormals!==void 0?this._needNormals:!1}set needNormals(e){this._needNormals=e}get needTwoSided(){return this._needTwoSided!==void 0?this._needTwoSided:!0}set needTwoSided(e){this._needTwoSided=e}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(e){this._maximizeConvexFacets=e,e&&(this.shouldTriangulate=e)}clone(){const e=new st;return e.chordTol=this.chordTol,e.angleTol=this.angleTol?.clone(),e.maxEdgeLength=this.maxEdgeLength,e.minStrokesPerPrimitive=this.minStrokesPerPrimitive,e.shouldTriangulate=this.shouldTriangulate,e._needNormals=this._needNormals,e._needTwoSided=this._needTwoSided,e._needParams=this._needParams,e.needColors=this.needColors,e.defaultCircleStrokes=this.defaultCircleStrokes,e._maximizeConvexFacets=this._maximizeConvexFacets,e}applyMaxEdgeLength(e,t){return t=Math.abs(t),this.maxEdgeLength&&this.maxEdgeLength>0&&e*this.maxEdgeLength<t&&(e=f.stepCount(this.maxEdgeLength,t,e)),e}applyAngleTol(e,t,n){return st.applyAngleTol(this,e,t,n)}static applyAngleTol(e,t,n,i){n=Math.abs(n);let s=i||Math.PI/8;return e&&e.angleTol&&e.angleTol.radians>0&&(s=e.angleTol.radians),t*s<n&&(t=f.stepCount(s,n,t)),t}static applyMaxEdgeLength(e,t,n){return n<0&&(n=-n),t<1&&(t=1),e&&e.maxEdgeLength&&e.maxEdgeLength*t<n&&(t=f.stepCount(e.maxEdgeLength,n,t)),t}applyTolerancesToArc(e,t=Math.PI*2){let n=1;return n=this.applyAngleTol(n,t,Math.PI*.25),n=this.applyMaxEdgeLength(n,t*e),n=this.applyChordTol(n,e,t),n=this.applyMinStrokesPerPrimitive(n),n}applyChordTol(e,t,n){if(this.chordTol&&this.chordTol>0&&this.chordTol<t){const i=this.chordTol,s=2*Math.acos(1-i/t);e=f.stepCount(s,n,e)}return e}applyChordTolToLengthAndRadians(e,t,n){if(this.chordTol&&this.chordTol>0){const i=f.conditionalDivideFraction(t,n);if(i!==void 0)return this.applyChordTol(e,i,n)}return e}applyMinStrokesPerPrimitive(e){return this.minStrokesPerPrimitive!==void 0&&Number.isFinite(this.minStrokesPerPrimitive)&&this.minStrokesPerPrimitive>e&&(e=this.minStrokesPerPrimitive),e}static createForCurves(){const e=new st;return e.angleTol=T.createDegrees(15),e}static createForFacets(){const e=new st;return e.angleTol=T.createDegrees(22.5),e}}class Xi{minArcDegrees=180;maxChamferTurnDegrees=91;allowSharpestCorners=!1;leftOffsetDistance=0;preserveEllipticalArcs=!1;constructor(e,t=180,n=91,i=!1,s=!1){this.leftOffsetDistance=e,this.minArcDegrees=t,this.maxChamferTurnDegrees=n,this.preserveEllipticalArcs=i,this.allowSharpestCorners=s}clone(){return new Xi(this.leftOffsetDistance,this.minArcDegrees,this.maxChamferTurnDegrees,this.preserveEllipticalArcs,this.allowSharpestCorners)}setFrom(e){this.leftOffsetDistance=e.leftOffsetDistance,this.minArcDegrees=e.minArcDegrees,this.maxChamferTurnDegrees=e.maxChamferTurnDegrees,this.preserveEllipticalArcs=e.preserveEllipticalArcs,this.allowSharpestCorners=e.allowSharpestCorners}static create(e){return e instanceof Xi?e:new Xi(e)}needArc(e){return Math.abs(e.degrees)>=this.minArcDegrees-f.smallAngleDegrees}numChamferPoints(e){const t=Math.abs(e.degrees),n=10;let i=120;this.allowSharpestCorners&&(i=this.maxChamferTurnDegrees);const s=f.clamp(this.maxChamferTurnDegrees,n,i);return t<=s+f.smallAngleDegrees?1:Math.ceil(t/s)}}class Kt{jointOptions;strokeOptions;constructor(e,t){this.jointOptions=Xi.create(e),this.strokeOptions=t!==void 0?t:st.createForCurves()}get minArcDegrees(){return this.jointOptions.minArcDegrees}set minArcDegrees(e){this.jointOptions.minArcDegrees=e}get maxChamferTurnDegrees(){return this.jointOptions.maxChamferTurnDegrees}set maxChamferTurnDegrees(e){this.jointOptions.maxChamferTurnDegrees=e}get allowSharpestCorners(){return this.jointOptions.allowSharpestCorners}set allowSharpestCorners(e){this.jointOptions.allowSharpestCorners=e}get leftOffsetDistance(){return this.jointOptions.leftOffsetDistance}set leftOffsetDistance(e){this.jointOptions.leftOffsetDistance=e}get preserveEllipticalArcs(){return this.jointOptions.preserveEllipticalArcs}set preserveEllipticalArcs(e){this.jointOptions.preserveEllipticalArcs=e}static create(e){return e instanceof Kt?e:new Kt(e)}static getOffsetDistance(e){return typeof e=="number"?e:e.leftOffsetDistance}clone(){return new Kt(this.jointOptions.clone(),this.strokeOptions.clone())}}class Q extends le{curvePrimitiveType="lineSegment";isSameGeometryClass(e){return e instanceof Q}_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(e,t){super(),this._point0=e,this._point1=t}setRefs(e,t){this._point0=e,this._point1=t}set(e,t){this._point0=e.clone(),this._point1=t.clone()}setFrom(e){this._point0.setFrom(e._point0),this._point1.setFrom(e._point1)}startPoint(e){return e?(e.setFrom(this._point0),e):this._point0.clone()}endPoint(e){return e?(e.setFrom(this._point1),e):this._point1.clone()}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){return!1}fractionToPointAndDerivative(e,t){return t=t||q.createZero(),t.direction.setStartEnd(this._point0,this._point1),this._point0.interpolate(e,this._point1,t.origin),t}fractionToPointAnd2Derivatives(e,t){return t=t||ke.createXYPlane(),t.vectorU.setStartEnd(this._point0,this._point1),t.vectorV.set(0,0,0),this._point0.interpolate(e,this._point1,t.origin),t}clone(){return Q.create(this._point0,this._point1)}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}static create(e,t,n){return n?(n.set(e,t),n):new Q(e.clone(),t.clone())}static createCapture(e,t){return new Q(e,t)}static createXYXY(e,t,n,i,s=0,r){return r?(r._point0.set(e,t,s),r._point1.set(n,i,s),r):new Q(y.create(e,t,s),y.create(n,i,s))}static createXYZXYZ(e,t,n,i,s,r,a){return a?(a._point0.set(e,t,n),a._point1.set(i,s,r),a):new Q(y.create(e,t,n),y.create(i,s,r))}fractionToPoint(e,t){return this._point0.interpolate(e,this._point1,t)}curveLength(){return this._point0.distance(this._point1)}curveLengthBetweenFractions(e,t){return Math.abs(t-e)*this._point0.distance(this._point1)}quickLength(){return this.curveLength()}closestPoint(e,t=!1,n){let i=e.fractionOfProjectionToLine(this._point0,this._point1,0);return i=Ge.correctFraction(t,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(e),n}static closestApproach(e,t,n,i,s){const r=$.create();if(s===void 0&&(s=Ze.createCapture(Y.create(),Y.create())),Le.lineSegment3dClosestApproachUnbounded(e._point0,e._point1,n._point0,n._point1,r)){const d=Ge.correctFraction(t,r.x),h=Ge.correctFraction(i,r.y);if(d===r.x&&h===r.y)return Y.createCurveEvaluatedFraction(e,d,s.detailA),Y.createCurveEvaluatedFraction(n,h,s.detailB),s.detailA.a=s.detailB.a=s.detailA.point.distance(s.detailB.point),s;if(d!==r.x&&h!==r.y){const u=d<.5?e._point0:e._point1,g=h<.5?n._point0:n._point1;n.closestPoint(u,i,s.detailB),e.closestPoint(g,t,s.detailA),s.detailA.a<=s.detailB.a?Y.createCurveFractionPoint(n,h,g,s.detailB):Y.createCurveFractionPoint(e,d,u,s.detailA)}else if(h!==r.y){const u=h<.5?n._point0:n._point1;e.closestPoint(u,t,s.detailA),s.detailB.setCurve(n),s.detailB.point.setFrom(u),s.detailB.fraction=h}else{const u=d<.5?e._point0:e._point1;n.closestPoint(u,i,s.detailB),s.detailA.setCurve(e),s.detailA.point.setFrom(u),s.detailA.fraction=d}return s.detailA.a=s.detailB.a=s.detailA.point.distance(s.detailB.point),s}const a=[e.closestPoint(n._point0,t),e.closestPoint(n._point1,t),n.closestPoint(e._point0,i),n.closestPoint(e._point1,i)];let o=a[0].a,c=0;for(let d=1;d<4;d++)a[d].a<o&&(c=d,o=a[d].a);return c===0?(a[0].clone(s.detailA),Y.createCurveEvaluatedFraction(n,0,s.detailB),s.detailB.a=s.detailA.a):c===1?(a[1].clone(s.detailA),Y.createCurveEvaluatedFraction(n,1,s.detailB),s.detailB.a=s.detailA.a):c===2?(a[2].clone(s.detailB),Y.createCurveEvaluatedFraction(e,0,s.detailA),s.detailA.a=s.detailB.a):(a[3].clone(s.detailB),Y.createCurveEvaluatedFraction(e,1,s.detailA),s.detailA.a=s.detailB.a),s}reverseInPlace(){const e=this._point0;this._point0=this._point1,this._point1=e}tryTransformInPlace(e){return this._point0=e.multiplyPoint3d(this._point0,this._point0),this._point1=e.multiplyPoint3d(this._point1,this._point1),!0}isInPlane(e){return f.isSmallMetricDistance(e.altitude(this._point0))&&f.isSmallMetricDistance(e.altitude(this._point1))}appendPlaneIntersectionPoints(e,t){const n=e.altitude(this._point0),i=e.altitude(this._point1),s=Ls.solveCoffs(n,i);let r=0;if(s!==void 0){r++;const a=Y.createCurveFractionPoint(this,s,this.fractionToPoint(s));a.intervalRole=Fe.isolated,t.push(a)}return r}extendRange(e,t){t?(e.extendTransformedPoint(t,this._point0),e.extendTransformedPoint(t,this._point1)):(e.extendPoint(this._point0),e.extendPoint(this._point1))}setFromJSON(e){if(e)e.startPoint&&e.endPoint?(this._point0.setFromJSON(e.startPoint),this._point1.setFromJSON(e.endPoint)):Array.isArray(e)&&e.length>1&&(this._point0.setFromJSON(e[0]),this._point1.setFromJSON(e[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(e){const t=new Q(y.createZero(),y.create());return t.setFromJSON(e),t}isAlmostEqual(e){if(e instanceof Q){const t=e;return this._point0.isAlmostEqual(t._point0)&&this._point1.isAlmostEqual(t._point1)}return!1}emitStrokes(e,t){const n=this.computeStrokeCountForOptions(t);e.appendFractionalStrokePoints(this,n,0,1)}emitStrokableParts(e,t){e.startCurvePrimitive(this);const n=this.computeStrokeCountForOptions(t);e.announceSegmentInterval(this,this._point0,this._point1,n,0,1),e.endCurvePrimitive(this)}computeStrokeCountForOptions(e){let t=1;return e&&(e.maxEdgeLength&&(t=e.applyMaxEdgeLength(t,this.curveLength())),t=e.applyMinStrokesPerPrimitive(t)),t}dispatchToGeometryHandler(e){return e.handleLineSegment3d(this)}announceClipIntervals(e,t){return e.announceClippedSegmentIntervals(0,1,this._point0,this._point1,t?(n,i)=>t(n,i,this):void 0)}clonePartialCurve(e,t){return Q.create(this.fractionToPoint(e),this.fractionToPoint(t))}rangeBetweenFractions(e,t,n){if(!n){const r=ie.create();return r.extendInterpolated(this._point0,e,this._point1),r.extendInterpolated(this._point0,t,this._point1),r}const i=this.fractionToPoint(e),s=this.fractionToPoint(t);return n&&(n.multiplyPoint3d(i,i),n.multiplyPoint3d(s,s)),ie.create(i,s)}constructOffsetXY(e){const t=v.createStartEnd(this._point0,this._point1);if(t.normalizeInPlace()){t.rotate90CCWXY(t);const n=Kt.getOffsetDistance(e);return Q.create(this._point0.plusScaled(t,n),this._point1.plusScaled(t,n))}}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}}function Ys(l,e,t,n,i,s,r){const a=l.length;if(n>0){for(let o=t;o+1<a;o++)if(l.vectorIndexIndex(o,o+1,r),e.crossProduct(r,r),r.normalizeInPlace())return s.addScaledInPlace(r,i),s.isAlmostEqualXYZ(0,0,0,f.smallFraction)&&r.scale(-i,s),!0}else{t+1>=a&&(t=a-2);for(let o=t;o>=0;o--)if(l.vectorIndexIndex(o,o+1,r),r.crossProduct(e,r),r.normalizeInPlace())return s.addScaledInPlace(r,i),s.isAlmostEqualXYZ(0,0,0,f.smallFraction)&&r.scale(-i,s),!0}return!1}class N extends le{curvePrimitiveType="lineString";static _workPointA=y.create();static _workPointB=y.create();static _workPointC=y.create();static _workRay=q.createXAxis();isSameGeometryClass(e){return e instanceof N}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(e){super(),e?this._points=e:this._points=new J}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}static create(...e){const t=new N;return t.addPoints(e),t}static createCapture(e){return new N(e)}static createXY(e,t,n=!1){const i=new N,s=i._points;for(const r of e)s.pushXYZ(r.x,r.y,t);return n&&s.length>1&&s.almostEqualUncheckedIndexIndex(0,s.length-1)&&s.transferFromGrowableXYZArray(s.length-1,s,0),i}addPoints(...e){this._points.pushFrom(e)}addSteppedPoints(e,t,n,i){this._points.addSteppedPoints(e,t,n,i)}addPoint(e){this._points.push(e)}addPointXYZ(e,t,n=0){this._points.pushXYZ(e,t,n)}addFraction(e){this._fractions||(this._fractions=new Me),this._fractions.push(e)}ensureEmptyFractions(){const e=this.numPoints();return this._fractions?(this._fractions.clear(),this._fractions.ensureCapacity(e),this._fractions):(this._fractions=new Me(e),this._fractions)}ensureEmptyUVParams(){const e=this.numPoints();return this._uvParams?(this._uvParams.clear(),this._uvParams.ensureCapacity(e),this._uvParams):(this._uvParams=new Ct(e),this._uvParams)}ensureEmptySurfaceNormals(){const e=this.numPoints();return this._surfaceNormals?(this._surfaceNormals.clear(),this._surfaceNormals.ensureCapacity(e),this._surfaceNormals):(this._surfaceNormals=new J(e),this._surfaceNormals)}ensureEmptyDerivatives(){const e=this.numPoints();return this._derivatives?(this._derivatives.clear(),this._derivatives.ensureCapacity(e),this._derivatives):(this._derivatives=new J(e),this._derivatives)}ensureEmptyNormalIndices(){const e=this.numPoints();return this._normalIndices?(this._normalIndices.clear(),this._normalIndices.ensureCapacity(e),this._normalIndices):(this._normalIndices=new Me(e),this._normalIndices)}ensureEmptyUVIndices(){const e=this.numPoints();return this._uvIndices?(this._uvIndices.clear(),this._uvIndices.ensureCapacity(e),this._uvIndices):(this._uvIndices=new Me(e),this._uvIndices)}ensureEmptyPointIndices(){const e=this.numPoints();return this._pointIndices?(this._pointIndices.clear(),this._pointIndices.ensureCapacity(e),this._pointIndices):(this._pointIndices=new Me(e),this._pointIndices)}addUVParam(e){this._uvParams||(this._uvParams=new Ct),this._uvParams.pushXY(e.x,e.y)}addUVParamAsUV(e,t){this._uvParams||(this._uvParams=new Ct),this._uvParams.pushXY(e,t)}addDerivative(e){this._derivatives||(this._derivatives=new J),this._derivatives.push(e)}addSurfaceNormal(e){this._surfaceNormals||(this._surfaceNormals=new J),this._surfaceNormals.push(e)}addClosurePoint(){const e=this._points.distanceIndexIndex(0,this._points.length-1);e!==void 0&&!f.isSameCoordinate(e,0)&&this._points.pushWrap(1)}popPoint(){this._points.pop()}computeUVFromXYZTransform(e){this._uvParams=Ct.createFromGrowableXYZArray(this._points,e)}static createRectangleXY(e,t,n,i=!0){const s=N.create(),r=e.x,a=e.x+t,o=e.y,c=e.y+n,d=e.z;return s.addPointXYZ(r,o,d),s.addPointXYZ(a,o,d),s.addPointXYZ(a,c,d),s.addPointXYZ(r,c,d),i&&s.addClosurePoint(),s}static createRegularPolygonXY(e,t,n,i=!0){t<3&&(t=3);const s=N.create(),r=i?0:-1,a=Math.PI/t;let o,c,d;i||(n=n/Math.cos(a));for(let h=0;h<t;h++)d=(r+2*h)*a,o=T.cleanupTrigValue(Math.cos(d)),c=T.cleanupTrigValue(Math.sin(d)),s.addPointXYZ(e.x+n*o,e.y+n*c,e.z);return s.addClosurePoint(),s}setFrom(e){this._points=e._points.clone(this._points),e._derivatives?this._derivatives=e._derivatives.clone(this._derivatives):this._derivatives=void 0,e._fractions?this._fractions=e._fractions.clone(!1):this._fractions=void 0,e._surfaceNormals?this._surfaceNormals=e._surfaceNormals.clone(this._surfaceNormals):this._surfaceNormals=void 0,e._uvParams?this._uvParams=e._uvParams.clone():this._uvParams=void 0}static createPoints(e){const t=new N;let n;for(n of e)t._points.push(n);return t}static createIndexedPoints(e,t,n=!1){const i=new N;for(const s of t)i._points.push(e[s]);return n&&t.length>1&&i._points.push(e[t[0]]),i}static createFloat64Array(e){const t=new N;for(let n=0;n+3<=e.length;n+=3)t._points.push(y.create(e[n],e[n+1],e[n+2]));return t}clone(){const e=new N;return e.setFrom(this),e}setFromJSON(e){if(this._points.clear(),Array.isArray(e)){let t;for(t of e)this._points.push(y.fromJSON(t))}}toJSON(){const e=[];let t=0;for(;this._points.isIndexValid(t);)e.push(this._points.getPoint3dAtUncheckedPointIndex(t).toJSON()),t++;return e}static fromJSON(e){const t=new N;return t.setFromJSON(e),t}fractionToPoint(e,t){const n=this._points.length;if(n<=0)return y.createZero();if(n===1)return y.createFrom(this._points.getPoint3dAtUncheckedPointIndex(0),t);const i=1/(n-1);if(e<=i)return this._points.interpolateUncheckedIndexIndex(0,e/i,1,t);if(e+i>=1)return this._points.interpolateUncheckedIndexIndex(n-1,(1-e)/i,n-2,t);const s=Math.floor(e/i);return this._points.interpolateUncheckedIndexIndex(s,(e-s*i)/i,s+1,t)}fractionToPointAndDerivative(e,t){t=t||q.createZero();const n=this._points.length;if(n<=1)return t.direction.setZero(),n===1?t.origin.setFrom(this._points.getPoint3dAtUncheckedPointIndex(0)):t.origin.setZero(),t;const s=1/(n-1);if(e<=s)return t=t||q.createZero(),this._points.interpolate(0,e/s,1,t.origin),this._points.vectorIndexIndex(0,1,t.direction),t.direction.scaleInPlace(1/s),t;if(e+s>=1)return t=t||q.createZero(),this._points.interpolate(n-2,1-(1-e)/s,n-1,t.origin),this._points.vectorIndexIndex(n-2,n-1,t.direction),t.direction.scaleInPlace(1/s),t;t=t||q.createZero();const r=Math.floor(e/s),a=(e-r*s)/s;return this._points.interpolate(r,a,r+1,t.origin),this._points.vectorIndexIndex(r,r+1,t.direction),t.direction.scaleInPlace(1/s),t}fractionToPointAnd2Derivatives(e,t){const n=this.fractionToPointAndDerivative(e);return t=ke.createCapture(n.origin,n.direction,v.createZero(),t),t}static mapLocalToGlobalFraction(e,t,n){return n<1?0:(e+t)/n}segmentIndexAndLocalFractionToGlobalFraction(e,t){return N.mapLocalToGlobalFraction(e,t,this._points.length-1)}static mapGlobalToLocalFraction(e,t){if(t<1)return{index:0,fraction:0};const n=e*t;let i;return e<=0?i=0:e>=1?i=t-1:i=Math.floor(n),{index:i,fraction:n-i}}globalFractionToSegmentIndexAndLocalFraction(e){return N.mapGlobalToLocalFraction(e,this._points.length-1)}fractionToFrenetFrame(e,t){const n=this._points.length;if(n<=1)return n===1?X.createTranslation(this._points.getPoint3dAtUncheckedPointIndex(0),t):X.createIdentity(t);if(n===2){const g=E.createRigidHeadsUp(this._points.vectorUncheckedIndexIndex(0,1),ve.XYZ);return X.createOriginAndMatrix(this._points.interpolate(0,e,1),g,t)}const i=n-1,s=1/i;let r=0,a=0;e<=s?(a=e/s,r=0):e+s>=1?(r=n-2,a=1-(1-e)/s):(r=Math.floor(e/s),a=e*i-r);const o=this._points.interpolateUncheckedIndexIndex(r,a,r+1),c=this._points.vectorUncheckedIndexIndex(r,r+1),d=v.create(),h=v.create();r===0?Ys(this._points,c,r+1,1,1,d,h):r+2>=n?Ys(this._points,c,r-1,-1,1,d,h):(Ys(this._points,c,r-1,-1,1-a,d,h),Ys(this._points,c,r+1,1,a,d,h));const u=E.createRigidFromColumns(d,c,ve.ZXY);return u?X.createOriginAndMatrix(o,u,t):X.createTranslation(o,t)}startPoint(e){return this._points.length===0?y.createZero(e):this._points.getPoint3dAtUncheckedPointIndex(0,e)}pointAt(e,t){if(this._points.isIndexValid(e))return this.pointAtUnchecked(e,t)}pointAtUnchecked(e,t){return this._points.getPoint3dAtUncheckedPointIndex(e,t)}vectorBetween(e,t,n){return this._points.vectorIndexIndex(e,t,n)}derivativeAt(e,t){if(this._derivatives&&this._derivatives.isIndexValid(e))return this._derivatives.getVector3dAtCheckedVectorIndex(e,t)}surfaceNormalAt(e,t){if(this._surfaceNormals&&this._surfaceNormals.isIndexValid(e))return this._surfaceNormals.getVector3dAtCheckedVectorIndex(e,t)}numPoints(){return this._points.length}numEdges(){return this._points.length>0?this._points.length-1:0}endPoint(e){return this._points.length===0?y.createZero(e):this._points.getPoint3dAtUncheckedPointIndex(this._points.length-1,e)}reverseInPlace(){if(this._points.length>=2){if(this._points.reverseInPlace(),this._fractions){this._fractions.reverseInPlace();for(let e=0;e<this._fractions.length;++e)this._fractions.reassign(e,1-this._fractions.atUncheckedIndex(e))}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(e){return this._points.multiplyTransformInPlace(e),this._derivatives&&this._derivatives.multiplyMatrix3dInPlace(e.matrix),this._surfaceNormals&&this._surfaceNormals.multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(e.matrix),!0}curveLength(){return this._points.sumLengths()}curveLengthBetweenFractions(e,t){const i=this._points.length-1;if(t===e||i<1)return 0;if(t<e)return this.curveLengthBetweenFractions(t,e);const s=e*i,r=t*i,a=Math.max(1,Math.ceil(s)),o=Math.min(Math.floor(r),i-1);if(a>o)return Math.abs(r-s)*this._points.distanceUncheckedIndexIndex(o,a);const c=a-s,d=r-o;let h=c*this._points.distanceUncheckedIndexIndex(a-1,a);for(let u=a;u<o;u++)h+=this._points.distanceUncheckedIndexIndex(u,u+1);return h+=d*this._points.distanceUncheckedIndexIndex(o,o+1),h}rangeBetweenFractions(e,t,n){const i=ie.create();if(this.points.length<1)return i;if(t<e)return this.rangeBetweenFractions(t,e,n);const s=this._points.length-1,r=e*s,a=Math.max(0,Math.floor(r)),o=r-a,c=y.create();if(this._points.interpolate(a,o,a+1,c),i.extendPoint(c,n),t===e)return i;const d=t*s,h=Math.min(Math.floor(d),s-1),u=d-h;this._points.interpolate(h,u,h+1,c),i.extendPoint(c,n);for(let g=a+1;g<=h;g++)this._points.getPoint3dAtUncheckedPointIndex(g,c),i.extendPoint(c,n);return i}moveSignedDistanceFromFraction(e,t,n,i){const r=this._points.length-1,a=e*r;let o=f.restrictToInterval(Math.floor(a),0,r-1);const c=a-o,d=this._points.interpolateUncheckedIndexIndex(o,c,o+1,N._workPointA),h=N._workPointB,u=new Ec(d,e,t);if(t>0){for(;o<=r;)if(o++,this._points.getPoint3dAtCheckedPointIndex(o,h),u.announcePoint(h,o/r))return Y.createCurveFractionPointDistanceCurveSearchStatus(this,u.fraction0,u.point0,t,Yt.success,i);return n&&u.announceExtrapolation(this._points,r-1,r,(r-1)/r,1),Y.createCurveFractionPointDistanceCurveSearchStatus(this,u.fraction0,u.point0,t,u.distanceStatus(),i)}else{for(c<=0&&o--;o>=0;o--)if(this._points.getPoint3dAtCheckedPointIndex(o,h),u.announcePoint(h,o/r))return Y.createCurveFractionPointDistanceCurveSearchStatus(this,u.fraction0,u.point0,t,Yt.success,i);return n&&u.announceExtrapolation(this._points,1,0,1/r,0),Y.createCurveFractionPointDistanceCurveSearchStatus(this,u.fraction0,u.point0,-u.distance0,u.distanceStatus(),i)}}quickLength(){return this.curveLength()}quickUnitNormal(e){let t=Math.floor(this._points.length/3);if(t<1&&(t=1),e=this._points.crossProductIndexIndexIndex(0,t,t+t),e&&e.normalizeInPlace())return e}closestPoint(e,t=!1,n){n=Y.create(this,n);const i=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,0),s=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,1),r=this._points.length;if(r>0){const a=r-1;if(n.setFP(1,this._points.getPoint3dAtUncheckedPointIndex(a),void 0),n.setDistanceTo(e),r>1){let o=0,c=0;for(let d=1;d<r;d++)o=e.fractionOfProjectionToLine(this._points.getPoint3dAtUncheckedPointIndex(d-1),this._points.getPoint3dAtUncheckedPointIndex(d)),o<0?(!i||d>1)&&(o=0):o>1&&(!s||d<a)&&(o=1),this._points.getPoint3dAtUncheckedPointIndex(d-1).interpolate(o,this._points.getPoint3dAtUncheckedPointIndex(d),n.pointQ),c=n.pointQ.distance(e),c<n.a&&n.setFP(this.segmentIndexAndLocalFractionToGlobalFraction(d-1,o),n.pointQ,void 0,c)}}return n}isInPlane(e){return this._points.isCloseToPlane(e,f.smallMetricDistance)}static pushVertexHit(e,t,n,i,s){const r=Y.createCurveFractionPoint(n,i,s);e.push(r),t===0?r.setIntervalRole(Fe.isolatedAtVertex):t===1?(e[e.length-2].setIntervalRole(Fe.intervalStart),r.setIntervalRole(Fe.intervalEnd)):(e[e.length-2].setIntervalRole(Fe.intervalInterior),r.setIntervalRole(Fe.intervalEnd))}appendPlaneIntersectionPoints(e,t){if(this._points.length<1)return 0;const n=t.length,i=this._points.length,s=i===1?1:i-1,r=N._workPointA,a=N._workPointB,o=N._workPointC;this._points.getPoint3dAtUncheckedPointIndex(0,r);let c=0,d=0,h=0,u=0;for(let g=0;g<this._points.length;g++,r.setFrom(a),h=c)if(this._points.getPoint3dAtUncheckedPointIndex(g,a),c=f.correctSmallMetricDistance(e.altitude(a)),c===0)N.pushVertexHit(t,d++,this,g/s,a);else if(h*c<0){u=h/(h-c),r.interpolate(u,a,o);const m=Y.createCurveFractionPoint(this,(g-1+u)/s,o);m.setIntervalRole(Fe.isolated),t.push(m),d=0}return t.length-n}extendRange(e,t){this._points.extendRange(e,t)}isAlmostEqual(e){return!(!(e instanceof N)||!J.isAlmostEqual(this._points,e._points))}appendStrokePoint(e,t){const n=this._points.length;let i=!0;n>0&&(t!==void 0&&this._fractions&&f.isSmallRelative(t-this._fractions.back())||e.isAlmostEqual(this._points.getPoint3dAtUncheckedPointIndex(n-1)))&&(i=!1),i&&(this._points.push(e),t!==void 0&&this.addFraction(t))}removeDuplicatePoints(e=f.smallMetricDistance){const t=this._points.length;if(t<2)return;let n=1;for(let i=1;i<t;i++){const s=this._points.distanceIndexIndex(i,n-1);s!==void 0&&s>e&&(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(e,t){let n,i;const s=this._points.length;this._derivatives?(n=e.fractionToPointAndDerivative(t,N._workRay),i=n.origin):i=e.fractionToPoint(t,N._workPointA),!(s>0&&i.isAlmostEqual(this._points.getPoint3dAtUncheckedPointIndex(s-1)))&&(n&&this._derivatives?.push(n.direction),this._fractions&&this._fractions.push(t),this._points.push(i))}clear(){this._points.clear(),this._fractions&&this._fractions.clear(),this._derivatives&&this._derivatives.clear()}static createForStrokes(e=0,t){const n=N.create();return e>0&&n._points.ensureCapacity(e),t&&(t.needParams&&(n._fractions=new Me(e),n._uvParams=new Ct(e)),t.needNormals&&(n._derivatives=new J(e),n._surfaceNormals=new J(e))),n}appendFractionalStrokePoints(e,t,n=0,i=1,s=!0){let r=1,a=t-1;if(s&&(r=0,a=t),t>=1){const o=(i-n)/t;for(let c=r;c<=a;c++)this.appendFractionToPoint(e,n+c*o)}}appendInterpolatedStrokePoints(e,t,n,i){if(i&&this.appendStrokePoint(t,0),e>1){const s=1/e;for(let r=1;r<e;r++){const a=r*s;this.appendStrokePoint(t.interpolate(a,n),a)}}i&&this.appendStrokePoint(n,1)}emitStrokes(e,t){const n=this._points.length,i=N._workPointA,s=N._workPointB;if(n>0)if(t&&t.hasMaxEdgeLength){e.appendStrokePoint(this._points.getPoint3dAtUncheckedPointIndex(0));for(let r=1;r<n;r++){this._points.getPoint3dAtUncheckedPointIndex(r-1,i),this._points.getPoint3dAtUncheckedPointIndex(r,s);const a=t.applyMaxEdgeLength(1,i.distance(s));a>1&&e.appendInterpolatedStrokePoints(a,i,s,!1),e.appendStrokePoint(s)}}else for(let r=0;r<n;r++)e.appendStrokePoint(this._points.getPoint3dAtUncheckedPointIndex(r))}emitStrokableParts(e,t){const n=this._points.length;if(e.startCurvePrimitive(this),n>1){const i=1/(n-1);if(t&&t.hasMaxEdgeLength)for(let s=1;s<n;s++){const r=t.applyMaxEdgeLength(1,this._points.getPoint3dAtUncheckedPointIndex(s-1).distance(this._points.getPoint3dAtUncheckedPointIndex(s)));e.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++)e.announceSegmentInterval(this,this._points.getPoint3dAtUncheckedPointIndex(s-1),this._points.getPoint3dAtUncheckedPointIndex(s),1,(s-1)*i,s*i)}e.endCurvePrimitive(this)}computeStrokeCountForOptions(e){const t=this._points.length;let n=t-1;if(e&&e.hasMaxEdgeLength){n=0;for(let i=1;i<t;i++)n+=e.applyMaxEdgeLength(1,this._points.distanceUncheckedIndexIndex(i-1,i))}return n}computeAndAttachRecursiveStrokeCounts(e,t){const n=this._points.length,i=e!==void 0&&e.hasMaxEdgeLength,s=pn.createWithCurvePrimitiveAndOptionalParent(this,t,[]);for(let r=1;r<n;r++){const a=this._points.distanceUncheckedIndexIndex(r-1,r),o=i?e.applyMaxEdgeLength(1,a):1;s.addToCountAndLength(o,a)}le.installStrokeCountMap(this,s,t)}dispatchToGeometryHandler(e){return e.handleLineString3d(this)}announceClipIntervals(e,t){const n=this._points.length;if(n<2)return!1;let i=0,s=1;const r=(d,h)=>{t&&t(f.interpolate(i,d,s),f.interpolate(i,h,s),this)},a=N._workPointA,o=N._workPointB;this._points.getPoint3dAtUncheckedPointIndex(0,a);let c=!1;for(let d=1;d<n;d++,a.setFrom(o),i=s)this._points.getPoint3dAtUncheckedPointIndex(d,o),s=d/(n-1),e.announceClippedSegmentIntervals(0,1,a,o,r)&&(c=!0);return c}static _indexPoint=y.create();addResolvedPoint(e,t,n){const i=this._points.length;if(i!==0){if(i===1){this._points.getPoint3dAtUncheckedPointIndex(0,N._indexPoint),n.push(N._indexPoint);return}e<0&&(e=0),e>i-2&&(e=i-2,t+=1),this._points.interpolate(e,t,e+1,N._indexPoint),n.push(N._indexPoint)}}clonePartialCurve(e,t){if(t<e){const c=this.clonePartialCurve(t,e);return c&&c.reverseInPlace(),c}const n=this._points.length;if(n<2)return this.clone();n>2&&this.isPhysicallyClosed&&(e<0&&(e=0),t>1&&(t=1));let i,s;const r=this.globalFractionToSegmentIndexAndLocalFraction(e),a=this.globalFractionToSegmentIndexAndLocalFraction(t);e<0?i=1:0<=e&&e<=1?i=f.isSmallRelative(1-r.fraction)?r.index+2:r.index+1:i=n,t<0?s=-1:0<=t&&t<=1?s=f.isSmallRelative(a.fraction)?a.index-1:a.index:s=n-2;const o=N.create();this.addResolvedPoint(r.index,r.fraction,o._points);for(let c=i;c<=s;c++)this._points.isIndexValid(c)&&o._points.pushFromGrowableXYZArray(this._points,c);return this.addResolvedPoint(a.index,a.fraction,o._points),o}getIndexedSegment(e,t){if(e>=0&&e<this.numEdges())return this.getUncheckedIndexedSegment(e,t)}getUncheckedIndexedSegment(e,t){return Q.create(this._points.getPoint3dAtUncheckedPointIndex(e),this._points.getPoint3dAtUncheckedPointIndex(e+1),t)}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){return this._points.length?t?this._points.almostEqualXYUncheckedIndexIndex(0,this._points.length-1,e):this._points.almostEqualUncheckedIndexIndex(0,this._points.length-1,e):!1}get isPhysicallyClosed(){return this.isPhysicallyClosedCurve()}addMappedStrokesToLineString3D(e,t){const n=t.numPoints(),i=this._points,s=N._workPointA,r=N._workPointB,a=N._workPointC,o=i.length;if(e.primitive&&e.primitive===this&&e.componentData&&e.componentData.length+1===o){i.getPoint3dAtUncheckedPointIndex(0,s);for(let c=0;c+1<o;c++,s.setFromPoint3d(r)){i.getPoint3dAtUncheckedPointIndex(c+1,r);const d=e.componentData[c],h=d.numStroke,u=s.vectorTo(r);u.scale(h);for(let g=0;g<=h;g++){const m=g/h,p=d.fractionToA(m);t.addPoint(s.interpolate(m,r,a)),t._fractions&&t._fractions.push(p),t._derivatives&&t._derivatives.push(u)}}}return t.numPoints()-n}static createArrayOfLineString3d(e){const t=new Ha;Yn.streamXYZ(e,t);const n=t.claimArrayOfGrowableXYZArray(),i=[];if(n!==void 0)for(const s of n)i.push(N.createCapture(s));return i}collectCurvePrimitivesGo(e,t,n=!1){if(n){let i;for(let s=0;(i=this.getIndexedSegment(s))!==void 0;s++)e.push(i)}else e.push(this)}constructOffsetXY(e){const t=Kt.create(e),n=[];for(const i of this.collectCurvePrimitives(void 0,!0,!0)){const s=i.constructOffsetXY(t);s!==void 0&&(s instanceof le?n.push(s):Array.isArray(s)&&s.forEach(r=>n.push(r)))}return n}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}static convertLocalToGlobalDetail(e,t,n,i,s){return e.childDetail=e.clone(s),e.childDetail.a=t,e.fraction=this.mapLocalToGlobalFraction(t,e.fraction,n),e.curve=i,e}}class Ec{distance0;point0;fraction0;targetDistance;constructor(e,t,n){this.point0=e,this.distance0=0,this.targetDistance=Math.abs(n),this.fraction0=t}distanceStatus(){return f.isSameCoordinate(this.distance0,this.targetDistance)?Yt.success:Yt.stoppedAtBoundary}announcePoint(e,t){const n=this.point0.distance(e),i=this.distance0+n;if(i<this.targetDistance&&!f.isSameCoordinate(i,this.targetDistance))return this.point0.setFromPoint3d(e),this.distance0=i,this.fraction0=t,!1;const s=this.targetDistance-this.distance0,r=f.safeDivideFraction(s,n,0);return this.point0.interpolate(r,e,this.point0),this.fraction0=f.interpolate(this.fraction0,r,t),this.distance0=this.targetDistance,!0}announceExtrapolation(e,t,n,i,s){const r=this.targetDistance-this.distance0,a=e.distanceIndexIndex(t,n);if(!a)return!1;const o=f.conditionalDivideFraction(r,a);return o===void 0?!1:(e.interpolate(n,-o,t,this.point0),this.distance0=this.targetDistance,this.fraction0=f.interpolate(s,-o,i),!0)}}class lo{handleCurveCollection(e){}handlePath(e){return this.handleCurveCollection(e)}handleLoop(e){return this.handleCurveCollection(e)}handleParityRegion(e){return this.handleCurveCollection(e)}handleUnionRegion(e){return this.handleCurveCollection(e)}handleBagOfCurves(e){return this.handleCurveCollection(e)}handleCurveChainWithDistanceIndex(e){return this.handlePath(e.path)}}class zs extends lo{handleLineSegment3d(e){}handleLineString3d(e){}handleArc3d(e){}handleCurveCollection(e){}handleCurveChainWithDistanceIndex(e){}handleBSplineCurve3d(e){}handleInterpolationCurve3d(e){}handleAkimaCurve3d(e){}handleBSplineCurve3dH(e){}handleBSplineSurface3d(e){}handleCoordinateXYZ(e){}handleBSplineSurface3dH(e){}handleIndexedPolyface(e){}handleTransitionSpiral(e){}handlePath(e){}handleLoop(e){}handleParityRegion(e){}handleUnionRegion(e){}handleBagOfCurves(e){}handleSphere(e){}handleCone(e){}handleBox(e){}handleTorusPipe(e){}handleLinearSweep(e){}handleRotationalSweep(e){}handleRuledSweep(e){}handlePointString3d(e){}handleBezierCurve3d(e){}handleBezierCurve3dH(e){}}class $i extends lo{handleLineSegment3d(e){}handleLineString3d(e){}handleArc3d(e){}handleBSplineCurve3d(e){}handleInterpolationCurve3d(e){}handleAkimaCurve3d(e){}handleBSplineCurve3dH(e){}handleBSplineSurface3d(e){}handleCoordinateXYZ(e){}handleBSplineSurface3dH(e){}handleIndexedPolyface(e){}handleTransitionSpiral(e){}handleChildren(e){const t=e.children;if(t)for(const n of t)n.dispatchToGeometryHandler(this)}handleCurveCollection(e){return this.handleChildren(e)}handleSphere(e){}handleCone(e){}handleBox(e){}handleTorusPipe(e){}handleLinearSweep(e){}handleRotationalSweep(e){}handleRuledSweep(e){}handlePointString3d(e){}handleBezierCurve3d(e){}handleBezierCurve3dH(e){}}class kc{_curve;_fractions;constructor(e,t=f.smallFraction){this._curve=void 0,e&&this.startCurvePrimitive(e),this._fractions=new Di((n,i)=>fc(n,i,t))}startParentCurvePrimitive(e){}startCurvePrimitive(e){this._curve=e}announcePointTangent(e,t,n){this._fractions.add(t)}announceIntervalForUniformStepStrokes(e,t,n,i){t<1&&(t=1),this._fractions.add(n);const s=1/t;for(let r=1;r<t;r++)this._fractions.add(f.interpolate(n,r*s,i));this._fractions.add(i)}needPrimaryGeometryForStrokes(){return!0}announceSegmentInterval(e,t,n,i,s,r){this._fractions.add(s),this._fractions.add(r)}endCurvePrimitive(e){}endParentCurvePrimitive(e){}claimFractions(e=!1){return e&&(this._fractions.delete(0),this._fractions.delete(1)),[...this._fractions]}claimLineString(e){if(!this._curve)return;e??=N.create();const t=y.create();for(const n of this._fractions)e.addPoint(this._curve.fractionToPoint(n,t)),e.addFraction(n);return e}}class jt extends $i{plane;range;lowPoint;highPoint;constructor(e){super(),this.plane=e,this.range=fe.createNull(),this.resetRange()}resetRange(){this.range.setNull()}announcePoint(e){const t=this.plane.altitude(e);this.range.extendLow(t)&&(this.lowPoint=e.clone(this.lowPoint)),this.range.extendHigh(t)&&(this.highPoint=e.clone(this.highPoint))}announcePoints(e){for(let t=0;t<e.length;t++){const n=e.evaluateUncheckedIndexPlaneAltitude(t,this.plane);this.range.extendLow(n)&&(this.lowPoint=e.getPoint3dAtUncheckedPointIndex(t,this.lowPoint)),this.range.extendHigh(n)&&(this.highPoint=e.getPoint3dAtUncheckedPointIndex(t,this.highPoint))}}static createCapture(e){return new jt(e)}handleLineSegment3d(e){this.announcePoint(e.point0Ref),this.announcePoint(e.point1Ref)}handleLineString3d(e){this.announcePoints(e.packedPoints)}_strokeOptions;initStrokeOptions(){this._strokeOptions===void 0&&(this._strokeOptions=new st,this._strokeOptions.angleTol=T.createDegrees(1))}handleBSplineCurve3d(e){this.initStrokeOptions();const t=N.create();e.emitStrokes(t,this._strokeOptions),this.handleLineString3d(t)}handleBSplineCurve3dH(e){this.initStrokeOptions();const t=N.create();e.emitStrokes(t,this._strokeOptions),this.handleLineString3d(t)}_sineCosinePolynomial;_workPoint;handleArc3d(e){this._sineCosinePolynomial=e.getPlaneAltitudeSineCosinePolynomial(this.plane,this._sineCosinePolynomial);let t=this._sineCosinePolynomial.referenceMinMaxRadians();e.sweep.isRadiansInSweep(t)&&this.announcePoint(this._workPoint=e.radiansToPoint(t,this._workPoint)),t+=Math.PI,e.sweep.isRadiansInSweep(t)&&this.announcePoint(this._workPoint=e.radiansToPoint(t,this._workPoint)),this.announcePoint(this._workPoint=e.startPoint(this._workPoint)),this.announcePoint(this._workPoint=e.endPoint(this._workPoint))}static findExtremesInDirection(e,t){const n=t instanceof q?t.origin:y.createZero(),i=t instanceof q?t.direction:t,s=pe.create(n,i);if(s){const r=new jt(s);if(e instanceof Mt)e.dispatchToGeometryHandler(r);else if(e instanceof J)r.announcePoints(e);else for(const a of e)r.announcePoint(a);return r}}static findExtremePointsInDirection(e,t,n){const i=this.findExtremesInDirection(e,t);if(i&&i.highPoint&&i.lowPoint)return Q.create(i.lowPoint,i.highPoint,n)}static findExtremeAltitudesInDirection(e,t,n){const i=this.findExtremesInDirection(e,t);if(i&&!i.range.isNull)return fe.createFrom(i.range,n)}static findExtremeFractionsAlongDirection(e,t,n){const i=this.findExtremeAltitudesInDirection(e,t,n);if(i!==void 0){const s=t instanceof v?t.magnitude():t.direction.magnitude(),r=f.conditionalDivideCoordinate(1,s);if(r!==void 0)return i.low*=r,i.high*=r,i}}}class Je{x0;x1;constructor(e,t){this.x0=e,this.x1=t}set(e,t){this.x0=e,this.x1=t}shift(e){this.x0+=e,this.x1+=e}static create(e=0,t=1,n){return n?(n.set(e,t),n):new Je(e,t)}setFrom(e){this.x0=e.x0,this.x1=e.x1}clone(){return new Je(this.x0,this.x1)}get isIn01(){return f.isIn01(this.x0)&&f.isIn01(this.x1)}fractionToPoint(e){return f.interpolate(this.x0,e,this.x1)}signedDelta(){return this.x1-this.x0}absoluteDelta(){return Math.abs(this.x1-this.x0)}reverseInPlace(){const e=this.x0;this.x0=this.x1,this.x1=e}reverseIfNeededForDeltaSign(e=1){e*(this.x1-this.x0)<0&&this.reverseInPlace()}isAlmostEqual(e){return f.isSameCoordinate(this.x0,e.x0)&&f.isSameCoordinate(this.x1,e.x1)}get isExact01(){return this.x0===0&&this.x1===1}get isExact01Reversed(){return this.x0===1&&this.x1===0}clipBy01FunctionValuesPositive(e,t){const n=t-e,i=e+this.x0*n,s=e+this.x1*n,r=s-i;if(i>0){if(s>=0)return!0;const a=-i/r;return this.x1=this.x0+a*(this.x1-this.x0),!0}else if(i<0){if(s<0)return!1;const a=-i/r;return this.x0=this.x0+a*(this.x1-this.x0),!0}return s>0}clampDirectedTo01(e=!0,t=!0,n=!1){let i=this.x0,s=this.x1;if(s>i){if(i<0&&e&&(i=0),s>1&&t&&(s=1),i>s||i===s&&!n)return!1}else if(i>1&&t&&(i=1),s<0&&e&&(s=0),i<s||i===s&&!n)return!1;return this.set(i,s),!0}}var Dt;(function(l){l[l.None=0]="None",l[l.OpenByAddingControlPoints=1]="OpenByAddingControlPoints",l[l.OpenByRemovingKnots=2]="OpenByRemovingKnots"})(Dt||(Dt={}));class $e{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?Dt.None:this._wrapMode}set wrappable(e){this._wrapMode=e}get numSpans(){return this.rightKnotIndex-this.leftKnotIndex}constructor(e,t,n){if(this.degree=t,this._wrapMode=n,this._knot0=0,this._knot1=1,Array.isArray(e))this.knots=new Float64Array(e.length),this.setKnots(e),this.setupFixedValues();else if(e instanceof Float64Array)this.knots=e.slice(),this.setupFixedValues();else{const i=e;this.knots=new Float64Array(i)}}clone(){return new $e(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(e){e===void 0&&(e=this.wrappable);const t=this.degree,n=this.leftKnotIndex,i=this.rightKnotIndex;if(e===Dt.OpenByAddingControlPoints){const s=this.rightKnot-this.leftKnot,r=i-n;for(let a=0;a<n+t;a++){const o=a+r;if(Math.abs(this.knots[a]+s-this.knots[o])>=$e.knotTolerance)return!1}return!0}if(e===Dt.OpenByRemovingKnots){const s=t-1,r=this.leftKnot,a=this.rightKnot;for(let o=0;o<s;o++)if(Math.abs(r-this.knots[n-o-1])>=$e.knotTolerance||Math.abs(a-this.knots[i+o+1])>=$e.knotTolerance)return!1;return!0}return!1}isAlmostEqual(e){return this.degree!==e.degree?!1:Tt.isAlmostEqual(this.knots,e.knots,$e.knotTolerance)}getKnotMultiplicity(e){let t=0;for(const n of this.knots)if(Math.abs(n-e)<$e.knotTolerance)++t;else if(e<n)break;return t}getKnotMultiplicityAtIndex(e){let t=0;if(e>=0&&e<this.knots.length){const n=this.knots[e];++t;for(let i=e-1;i>=0;--i){const s=this.knots[i];if(Math.abs(s-n)<$e.knotTolerance)++t;else if(n>s)break}for(let i=e+1;i<this.knots.length;++i){const s=this.knots[i];if(Math.abs(s-n)<$e.knotTolerance)++t;else if(n<s)break}}return t}normalize(){if(this.knotLength01<$e.knotTolerance)return!1;const e=1/this.knotLength01,t=this.leftKnot;for(let n=0;n<this.knots.length;++n)this.knots[n]=(this.knots[n]-t)*e;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(e,t){const n=t?e.length-2:e.length;if(n!==this.knots.length&&(this.knots=new Float64Array(n)),t)for(let i=1;i+1<e.length;i++)this.knots[i-1]=e[i];else for(let i=0;i<e.length;i++)this.knots[i]=e[i];this.setupFixedValues()}setKnotsCapture(e){this.knots=e,this.setupFixedValues()}static createUniformClamped(e,t,n,i){const s=new $e(e+t-1,t);let r=0;for(let o=0;o<t;o++)s.knots[r++]=n;const a=1/(e-t);for(let o=1;o+t<e;o++)s.knots[r++]=n+o*a*(i-n);for(let o=0;o<t;o++)s.knots[r++]=i;return s.setupFixedValues(),s}static createUniformWrapped(e,t,n,i){const s=new $e(e+2*t-1,t),r=1/e;for(let a=1-t,o=0;a<e+t;a++,o++)s.knots[o]=f.interpolate(n,a*r,i);return s.setupFixedValues(),s}static create(e,t,n){const i=n?e.length-2:e.length,s=new $e(i,t);return s.setKnots(e,n),s}grevilleKnot(e){if(e<0)return this.leftKnot;if(e>this.rightKnotIndex)return this.rightKnot;e=Math.floor(e);let t=0;for(let n=e;n<e+this.degree;n++)t+=this.knots[n];return t/this.degree}createBasisArray(){return new Float64Array(this.degree+1)}baseKnotFractionToKnot(e,t){const n=this.knots[e];return t=f.clamp(t,0,1),n+t*(this.knots[e+1]-n)}spanFractionToKnot(e,t){const n=this.spanIndexToLeftKnotIndex(e);return t=f.clamp(t,0,1),this.knots[n]+t*(this.knots[n+1]-this.knots[n])}spanFractionToFraction(e,t){return(this.spanFractionToKnot(e,t)-this.leftKnot)/(this.rightKnot-this.leftKnot)}fractionToKnot(e){return e=f.clamp(e,0,1),f.interpolate(this.knots[this.degree-1],e,this.knots[this.knots.length-this.degree])}isKnotInValidSpan(e,t){const n=e>=this.degree-1&&e+this.degree<this.knots.length,i=this.knots[e]<=t&&t<=this.knots[e+1];return n&&i}evaluateBasisFunctions(e,t,n){if(n.length<this.degree+1)return!1;if(n[0]=1,this.degree<1)return!0;const i=this.knots[e],s=this.knots[e+1];if(n[1]=(t-i)/(s-i),n[0]=1-n[1],this.degree<2)return!0;for(let r=1;r<this.degree;r++){let a=e-r,o=e+1,c=0;for(let d=0;d<=r;d++){const h=this.knots[a++],u=this.knots[o++],g=(t-h)/(u-h),m=n[d]*g,p=n[d]*(1-g);n[d]=c+p,c=m}n[r+1]=c}return!0}evaluateBasisFunctions1(e,t,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[e];let o=1/(this.knots[e+1]-r);if(n[1]=(t-r)*o,n[0]=1-n[1],i[0]=-o,i[1]=o,s&&(s[0]=0,s[1]=0),this.degree<2)return!0;for(let c=1;c<this.degree;c++){let d=e-c,h=d+c+1,u=0,g=0,m=0;for(let p=0;p<=c;p++){const x=this.knots[d++];o=1/(this.knots[h++]-x);const I=(t-x)*o,S=1-I,A=n[p]*I,w=n[p]*S,k=i[p]*I+n[p]*o,D=i[p]*S-n[p]*o,P=2*i[p]*o;if(n[p]=u+w,i[p]=g+D,u=A,g=k,s){const b=s[p]*I+P,C=s[p]*S-P;s[p]=m+C,m=b}}n[c+1]=u,i[c+1]=g,s&&(s[c+1]=m)}return!0}knotToLeftKnotIndex(e){for(let t=this.leftKnotIndex;t<this.rightKnotIndex;++t)if(e<this.knots[t+1])return t;for(let t=this.rightKnotIndex;t>this.leftKnotIndex;--t)if(this.knots[t]-this.knots[t-1]>=$e.knotTolerance)return t-1;return this.rightKnotIndex-1}spanIndexToLeftKnotIndex(e){const t=this.degree;return e<=0?t-1:Math.min(e+t-1,this.knots.length-t-1)}spanIndexToSpanLength(e){const t=this.spanIndexToLeftKnotIndex(e);return this.knots[t+1]-this.knots[t]}isIndexOfRealSpan(e){return e>=0&&e<this.numSpans?!f.isSmallMetricDistance(this.spanIndexToSpanLength(e)):!1}reflectKnots(){const e=this.leftKnot,t=this.rightKnot,n=this.knots.length;for(let i=0;i<n;i++)this.knots[i]=e+(t-this.knots[i]);this.knots.reverse()}static copyKnots(e,t,n,i){const s=n&&i===Dt.OpenByAddingControlPoints,r=t-1,a=e.length-t,o=e[r],d=e[a]-o,h=[];n&&(s?h.push(e[a-t]-d):h.push(e[0]));for(const u of e)h.push(u);return n&&(s?h.push(e[r+t]+d):h.push(e[e.length-1])),h}copyKnots(e){const t=e&&this.testClosable()?this.wrappable:void 0;return $e.copyKnots(this.knots,this.degree,e,t)}}class xi{_packedData;_order;_blockSize;_basis;constructor(e,t){this._blockSize=e,this._order=Math.floor(t.length/e),this._packedData=t,this._basis=new it(this._order)}clonePolygon(e){const t=this._packedData.length;if(!e||e.length!==t)return this._packedData.slice();for(let n=0;n<t;n++)e[n]=this._packedData[n];return e}get order(){return this._order}get packedData(){return this._packedData}static create(e){if(!(e.length<1)){if(e[0]instanceof y){const t=new Float64Array(e.length*3);let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=i.z;return new xi(3,t)}else if(e[0]instanceof Z){const t=new Float64Array(e.length*4);let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=i.z,t[n++]=i.w;return new xi(4,t)}else if(e[0]instanceof L){const t=new Float64Array(e.length*2);let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y;return new xi(2,t)}}}evaluate(e,t){return this._basis.sumBasisFunctions(e,this._packedData,this._blockSize,t)}evaluateDerivative(e,t){return this._basis.sumBasisFunctionDerivatives(e,this._packedData,this._blockSize,t)}getPolygonPoint(e,t){if((!t||t.length<this._blockSize)&&(t=new Float64Array(this._blockSize)),e>=0&&e<this._order){const n=this._blockSize*e;for(let i=0;i<this._blockSize;i++)t[i]=this._packedData[n+i];return t}}setPolygonPoint(e,t){if(e>=0&&e<this._order){const n=this._blockSize*e;for(let i=0;i<this._blockSize;i++)this._packedData[n+i]=t[i]}}loadSpanPoles(e,t){let n=t*this._blockSize;for(let i=0;i<this._packedData.length;i++)this._packedData[i]=e[n++]}loadSpanPolesWithWeight(e,t,n,i){let s=0;const r=this._order;let a=n*t;for(let o=0;o<r;o++){for(let c=0;c<t;c++)this._packedData[s++]=e[a++];this._packedData[s++]=i}}unpackToJsonArrays(){return lt.unpackNumbersToNestedArrays(this._packedData,this._blockSize)}isAlmostEqual(e){if(e instanceof xi){if(this._blockSize!==e._blockSize||this._order!==e._order||this._packedData.length!==e._packedData.length)return!1;for(let t=0;t<this._packedData.length;t++)if(!f.isSameCoordinate(this._packedData[t],e._packedData[t]))return!1;return!0}return!1}reverseInPlace(){const e=this._blockSize,t=this._order;let n,i,s;for(n=0,i=(t-1)*e;n<i;n+=e,i-=e)for(let r=0;r<e;r++)s=this._packedData[n+r],this._packedData[n+r]=this._packedData[i+r],this._packedData[i+r]=s}interpolatePoleInPlace(e,t,n){let i=e*this._blockSize,s=n*this._blockSize;const r=this._packedData;for(let a=0;a<this._blockSize;a++,i++,s++)r[i]+=t*(r[s]-r[i])}saturateInPlace(e,t){const n=e.degree,i=t+n-1,s=i+1;if(t<0||t>=e.numSpans)return!1;const r=e.knots,a=r[i],o=r[s];if(this.setInterval(a,o),o<=a+$e.knotTolerance)return!1;for(let c=n-1;c>0;c--){let d=i-c;if(r[d]<a){let h=s;for(let u=0;u<c;u++,d++,h++){const g=r[d],m=r[h],p=(a-g)/(m-g);this.interpolatePoleInPlace(u,p,u+1)}}}for(let c=n-1;c>0;c--){let d=s+c;if(r[d]>o)for(let h=0;h<c;h++,d--){const u=r[d],g=(o-u)/(a-u);this.interpolatePoleInPlace(n-h,g,n-h-1)}}return!0}static saturate1dInPlace(e,t,n){const i=t.degree,s=n+i-1,r=s+1;if(n<0||n>=t.numSpans)return!1;const a=t.knots,o=a[s],c=a[r];if(c<=o+$e.knotTolerance)return!1;for(let d=i-1;d>0;d--){let h=s-d;if(a[h]<o){let u=r;for(let g=0;g<d;g++,h++,u++){const m=a[h],p=a[u],x=(o-m)/(p-m);e[g]=e[g]+x*(e[g+1]-e[g])}}}for(let d=i-1;d>0;d--){let h=r+d,u;if(a[h]>c)for(let g=0;g<d;g++,h--){const m=a[h],p=(c-m)/(o-m);u=i-g,e[u]+=p*(e[u-1]-e[u])}}return!0}subdivideInPlaceKeepLeft(e){if(f.isAlmostEqualNumber(e,1))return!0;if(f.isAlmostEqualNumber(e,0))return!1;const t=1-e,n=this.order;for(let i=1;i<n;i++)for(let s=n-1;s>=i;s--)this.interpolatePoleInPlace(s,t,s-1);return!0}subdivideInPlaceKeepRight(e){if(f.isAlmostEqualNumber(e,0))return!0;if(f.isAlmostEqualNumber(e,1))return!1;const t=this.order;for(let n=1;n<t;n++)for(let i=0;i+n<t;i++)this.interpolatePoleInPlace(i,e,i+1);return!0}subdivideToIntervalInPlace(e,t){return f.isAlmostEqualNumber(e,t)?!1:t<e?(this.subdivideToIntervalInPlace(t,e),this.reverseInPlace(),!0):(this.subdivideInPlaceKeepLeft(t),this.subdivideInPlaceKeepRight(e/t),!0)}interval;setInterval(e,t){this.interval=Je.create(e,t,this.interval)}fractionToParentFraction(e){return this.interval?this.interval.fractionToPoint(e):e}}class ho extends le{curvePrimitiveType="bezierCurve";_polygon;_workData0;_workData1;_workPoint0;_workPoint1;constructor(e,t){super(),this._polygon=new xi(e,t),this._workPoint0=y.create(),this._workPoint1=y.create(),this._workData0=new Float64Array(e),this._workData1=new Float64Array(e)}reverseInPlace(){this._polygon.reverseInPlace()}saturateInPlace(e,t){const n=this._polygon.saturateInPlace(e,t);return n&&this.setInterval(e.spanFractionToFraction(t,0),e.spanFractionToFraction(t,1)),n}get degree(){return this._polygon.order-1}get order(){return this._polygon.order}get numPoles(){return this._polygon.order}setInterval(e,t){this._polygon.setInterval(e,t)}fractionToParentFraction(e){return this._polygon.fractionToParentFraction(e)}emitStrokes(e,t){const n=this.computeStrokeCountForOptions(t),i=1/n;for(let s=0;s<=n;s++){const r=s*i;this.fractionToPoint(r,this._workPoint0),e.appendStrokePoint(this._workPoint0)}}emitStrokableParts(e,t){const n=this.computeStrokeCountForOptions(t);e.announceIntervalForUniformStepStrokes(this,n,0,1)}copyPolesAsJsonArray(){return this._polygon.unpackToJsonArrays()}isInPlane(e){let t=this._workPoint0;for(let n=0;;n++){if(t=this.getPolePoint3d(n,t),!t)return!0;if(!e.isPointInPlane(t))break}return!1}polygonLength(){if(!this.getPolePoint3d(0,this._workPoint0))return 0;let e=0,t=0;for(;this.getPolePoint3d(++e,this._workPoint1);)t+=this._workPoint0.distance(this._workPoint1),this._workPoint0.setFrom(this._workPoint1);return t}startPoint(e){return this.getPolePoint3d(0,e)??y.createZero()}endPoint(e){return this.getPolePoint3d(this.order-1,e)??y.createZero()}quickLength(){return this.polygonLength()}_workBezier;_workCoffsA;_workCoffsB;allocateAndZeroBezierWorkData(e,t,n){e>0&&(this._workBezier!==void 0&&this._workBezier.order===e?this._workBezier.zero():this._workBezier=new it(e)),t>0&&(this._workCoffsA!==void 0&&this._workCoffsA.length===t?this._workCoffsA.fill(0):this._workCoffsA=new Float64Array(t)),n>0&&(this._workCoffsB!==void 0&&this._workCoffsB.length===n?this._workCoffsB.fill(0):this._workCoffsB=new Float64Array(n))}computeStrokeCountForOptions(e){this.getPolePoint3d(0,this._workPoint0),this.getPolePoint3d(1,this._workPoint1);let t=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,a,o,c=0,d=f.hypotenuseXYZ(n,i,s);this._workPoint1.setFromPoint3d(this._workPoint0);let h=d,u=d,g=0,m;for(let A=2;this.getPolePoint3d(A,this._workPoint1);A++)r=this._workPoint1.x-this._workPoint0.x,a=this._workPoint1.y-this._workPoint0.y,o=this._workPoint1.z-this._workPoint0.z,m=T.radiansBetweenVectorsXYZ(n,i,s,r,a,o),c+=m,g=f.maxAbsXY(m,g),d=f.hypotenuseXYZ(r,a,o),h+=d,u=f.maxXY(u,d),n=r,i=a,s=o,this._workPoint0.setFrom(this._workPoint1);const p=u*this.degree,x=Math.sqrt(p*h);let _=g*(this.degree-1);this.degree<3&&(_*=3);const I=Math.sqrt(_*c),S=this.degree;t=st.applyAngleTol(e,st.applyMaxEdgeLength(e,S,x),I,.1),e&&(t=e.applyChordTolToLengthAndRadians(t,h,_))}return t}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}constructOffsetXY(e){const t=Kt.create(e),n=new Vs(this,t.leftOffsetDistance);return this.emitStrokableParts(n,t.strokeOptions),n.claimResult()}clonePartialCurve(e,t){const n=this.clone();return n._polygon.subdivideToIntervalInPlace(e,t),n}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}}class Cn extends ho{isSameGeometryClass(e){return e instanceof Cn}tryTransformInPlace(e){const t=this._workData0;for(let n=0;n<this._polygon.order;n++)this._polygon.getPolygonPoint(n,t),e.multiplyXYZToFloat64Array(t[0],t[1],t[2],t),this._polygon.setPolygonPoint(n,t);return!0}_workRay0;_workRay1;getPolePoint3d(e,t){const n=this._polygon.getPolygonPoint(e,this._workData0);if(n)return y.create(n[0],n[1],n[2],t)}getPolePoint4d(e,t){const n=this._polygon.getPolygonPoint(e,this._workData0);if(n)return Z.create(n[0],n[1],n[2],1,t)}constructor(e){super(3,e),this._workRay0=q.createXAxis(),this._workRay1=q.createXAxis()}copyPointsAsLineString(){const e=N.create(),t=y.createZero();for(let n=0;n<this._polygon.order;n++)this.getPolePoint3d(n,t),e.addPoint(t);return e}static create(e){if(e.length<1)return;const t=new Float64Array(e.length*3);if(e[0]instanceof y){let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=i.z;return new Cn(t)}else if(e[0]instanceof L){let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=0;return new Cn(t)}}static createOrder(e){const t=new Float64Array(e*3);return new Cn(t)}loadSpanPoles(e,t){this._polygon.loadSpanPoles(e,t)}clone(){return new Cn(this._polygon.clonePolygon())}fractionToPoint(e,t){return this._polygon.evaluate(e,this._workData0),y.create(this._workData0[0],this._workData0[1],this._workData0[2],t)}fractionToPointAndDerivative(e,t){return this._polygon.evaluate(e,this._workData0),this._polygon.evaluateDerivative(e,this._workData1),q.createXYZUVW(this._workData0[0],this._workData0[1],this._workData0[2],this._workData1[0],this._workData1[1],this._workData1[2],t)}fractionToPointAnd2Derivatives(e,t){t||(t=ke.createXYPlane());const s=this.fractionToPointAndDerivative(e,this._workRay0);t.origin.setFrom(s.origin),t.vectorU.setFrom(s.direction);const r=this.fractionToPointAndDerivative(e-1e-8,this._workRay0),a=this.fractionToPointAndDerivative(e+1e-8,this._workRay1);return v.createAdd2Scaled(r.direction,-5e7,a.direction,5e7,t.vectorV),t}isAlmostEqual(e){return e instanceof Cn?this._polygon.isAlmostEqual(e._polygon):!1}dispatchToGeometryHandler(e){return e.handleBezierCurve3d(this)}extendRange(e,t){const n=this.order;if(n<2)return;const i=n-1;if(t){this.allocateAndZeroBezierWorkData(i,n,0);const s=this._workBezier,r=this._workCoffsA;this.getPolePoint3d(0,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0);const a=this._polygon.packedData;for(let o=0;o<3;o++){for(let d=0,h=0;d<n;d++,h+=3)r[d]=t.multiplyComponentXYZ(o,a[h],a[h+1],a[h+2]);Ht.univariateDifference(r,s.coffs);const c=s.roots(0,!0);if(c&&c.length>0)for(const d of c)this.fractionToPoint(d,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0)}}else{this.allocateAndZeroBezierWorkData(i,0,0);const s=this._workBezier;this.getPolePoint3d(0,this._workPoint0),e.extend(this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),e.extend(this._workPoint0);for(let r=0;r<3;r++){Ht.componentDifference(s.coffs,this._polygon.packedData,3,n,r);const a=s.roots(0,!0);if(a)for(const o of a)this.fractionToPoint(o,this._workPoint0),e.extend(this._workPoint0)}}}}class En extends ho{isSameGeometryClass(e){return e instanceof En}tryTransformInPlace(e){const t=this._workData0;for(let n=0;n<this._polygon.order;n++)this._polygon.getPolygonPoint(n,t),e.multiplyXYZWToFloat64Array(t[0],t[1],t[2],t[3],t),this._polygon.setPolygonPoint(n,t);return!0}tryMultiplyMatrix4dInPlace(e){e.multiplyBlockedFloat64ArrayInPlace(this._polygon.packedData)}_workRay0;_workRay1;getPolePoint4d(e,t){const n=this._polygon.getPolygonPoint(e,this._workData0);if(n)return Z.create(n[0],n[1],n[2],n[3],t)}getPolePoint3d(e,t){const n=this._polygon.getPolygonPoint(e,this._workData0);if(n)return y.createFromPackedXYZW(n,0,t)}isUnitWeight(e){e===void 0&&(e=f.smallAngleRadians);const t=1-e,n=1+e,i=this._polygon.packedData,s=i.length;let r;for(let a=3;a<s;a+=4)if(r=i[a],r<t||r>n)return!1;return!0}constructor(e){super(4,e),this._workRay0=q.createXAxis(),this._workRay1=q.createXAxis()}static create(e){if(e.length<1)return;const t=new Float64Array(e.length*4);if(e[0]instanceof y){let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=i.z,t[n++]=1;return new En(t)}else if(e[0]instanceof Z){let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=i.z,t[n++]=i.w;return new En(t)}else if(e[0]instanceof L){let n=0;for(const i of e)t[n++]=i.x,t[n++]=i.y,t[n++]=0,t[n++]=1;return new En(t)}}static createOrder(e){const t=new Float64Array(e*4);return new En(t)}loadSpan3dPolesWithWeight(e,t,n){this._polygon.loadSpanPolesWithWeight(e,3,t,n)}loadSpan4dPoles(e,t){this._polygon.loadSpanPoles(e,t)}clone(){return new En(this._polygon.clonePolygon())}fractionToPoint(e,t){return this._polygon.evaluate(e,this._workData0),t=y.createFromPackedXYZW(this._workData0,0,t),t||y.createZero()}fractionToPoint4d(e,t){return this._polygon.evaluate(e,this._workData0),t=Z.createFromPacked(this._workData0,0,t),t||Z.createZero()}fractionToPointAndDerivative(e,t){return this._polygon.evaluate(e,this._workData0),this._polygon.evaluateDerivative(e,this._workData1),t=q.createWeightedDerivative(this._workData0,this._workData1,t),t||q.createXAxis()}fractionToPointAnd2Derivatives(e,t){t||(t=ke.createXYPlane());const s=this.fractionToPointAndDerivative(e,this._workRay0);t.origin.setFrom(s.origin),t.vectorU.setFrom(s.direction);const r=this.fractionToPointAndDerivative(e-1e-8,this._workRay0),a=this.fractionToPointAndDerivative(e+1e-8,this._workRay1);return v.createAdd2Scaled(r.direction,-5e7,a.direction,5e7,t.vectorV),t}isAlmostEqual(e){return e instanceof En?this._polygon.isAlmostEqual(e._polygon):!1}dispatchToGeometryHandler(e){return e.handleBezierCurve3dH(this)}poleProductsXYZW(e,t,n,i,s){const r=this.numPoles,a=this._polygon.packedData;for(let o=0,c=0;o<r;o++,c+=4)e[o]=t*a[c]+n*a[c+1]+i*a[c+2]+s*a[c+3]}updateClosestPointByTruePerpendicular(e,t,n=!1,i=!1){let s=0,r;if(this.order<2)return!1;if(this.isUnitWeight()){const a=2*this.order-2;this.allocateAndZeroBezierWorkData(a,0,0);const o=this._workBezier;Ht.accumulateScaledShiftedComponentTimesComponentDelta(o.coffs,this._polygon.packedData,4,this.order,1,0,-e.x,0),Ht.accumulateScaledShiftedComponentTimesComponentDelta(o.coffs,this._polygon.packedData,4,this.order,1,1,-e.y,1),Ht.accumulateScaledShiftedComponentTimesComponentDelta(o.coffs,this._polygon.packedData,4,this.order,1,2,-e.z,2),r=o.roots(0,!0)}else{const a=this.order,o=2*this.order-2,c=a+o-1;this.allocateAndZeroBezierWorkData(c,a,o);const d=this._workBezier,h=this._workCoffsA,u=this._workCoffsB,g=this._polygon.packedData;for(let m=0;m<3;m++){for(let p=0;p<h.length;p++)h[p]=0;for(let p=0;p<u.length;p++)u[p]=0;Ht.scaledComponentSum(h,g,4,a,3,e.at(m),m,-1),Ht.accumulateScaledShiftedComponentTimesComponentDelta(u,g,4,a,1,3,0,m),Ht.accumulateScaledShiftedComponentTimesComponentDelta(u,g,4,a,-1,m,0,3),Ht.accumulateProduct(d.coffs,h,u)}r=d.roots(0,!0)}if(r)for(const a of r){const o=this.fractionToPoint(a),c=o.distance(e);s+=t.updateIfCloserCurveFractionPointDistance(this,a,o,c)?1:0}return n&&(s+=this.updateDetailAtFraction(t,0,e)?1:0),i&&(s+=this.updateDetailAtFraction(t,1,e)?1:0),s>0}updateDetailAtFraction(e,t,n){const i=this.fractionToPoint(t),s=i.distance(n);return e.updateIfCloserCurveFractionPointDistance(this,t,i,s)}extendRange(e,t){const n=this.order;if(n<2)return;const i=n*2-2;if(t){this.allocateAndZeroBezierWorkData(i,n,n);const s=this._workBezier,r=this._workCoffsA,a=this._workCoffsB;this.getPolePoint3d(0,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0);const o=this._polygon.packedData;let c;for(let d=0;d<3;d++){s.zero();for(let u=0,g=0;u<n;u++,g+=4)c=o[g+3],r[u]=t.multiplyComponentXYZW(d,o[g],o[g+1],o[g+2],c),a[u]=c;Ht.accumulateProductWithDifferences(s.coffs,r,a,1),Ht.accumulateProductWithDifferences(s.coffs,a,r,-1);const h=s.roots(0,!0);if(h&&h.length>0)for(const u of h)this.fractionToPoint(u,this._workPoint0),e.extendTransformedPoint(t,this._workPoint0)}}else{this.allocateAndZeroBezierWorkData(i,0,0);const s=this._workBezier,r=this._polygon.packedData;this.getPolePoint3d(0,this._workPoint0),e.extend(this._workPoint0),this.getPolePoint3d(n-1,this._workPoint0),e.extend(this._workPoint0);for(let a=0;a<3;a++){s.zero(),Ht.accumulateScaledShiftedComponentTimesComponentDelta(s.coffs,r,4,n,1,a,0,3),Ht.accumulateScaledShiftedComponentTimesComponentDelta(s.coffs,r,4,n,-1,3,0,a);const o=s.roots(0,!0);if(o)for(const c of o)this.fractionToPoint(c,this._workPoint0),e.extend(this._workPoint0)}}}}class Vr{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(e,t){return y.createFromPacked(this.packedData,e,t)}basisBuffer;basisBuffer1;basisBuffer2;poleBuffer;poleBuffer1;poleBuffer2;constructor(e,t,n,i){this.knots=i,this.packedData=new Float64Array(e*t),this.poleLength=t,this.basisBuffer=new Float64Array(n),this.basisBuffer1=new Float64Array(n),this.basisBuffer2=new Float64Array(n),this.poleBuffer=new Float64Array(t),this.poleBuffer1=new Float64Array(t),this.poleBuffer2=new Float64Array(t)}static create(e,t,n,i){return new Vr(e,t,n,i)}spanFractionToKnot(e,t){return this.knots.spanFractionToKnot(e,t)}evaluateBasisFunctionsInSpan(e,t,n,i,s){e<0&&(e=0),e>=this.numSpan&&(e=this.numSpan-1);const r=e+this.degree-1,a=this.knots.baseKnotFractionToKnot(r,t);return i?this.knots.evaluateBasisFunctions1(r,a,n,i,s):this.knots.evaluateBasisFunctions(r,a,n)}sumPoleBufferForSpan(e){this.poleBuffer.fill(0);let t=e*this.poleLength;for(const n of this.basisBuffer)for(let i=0;i<this.poleLength;i++)this.poleBuffer[i]+=n*this.packedData[t++]}sumPoleBuffer1ForSpan(e){this.poleBuffer1.fill(0);let t=e*this.poleLength;for(const n of this.basisBuffer1)for(let i=0;i<this.poleLength;i++)this.poleBuffer1[i]+=n*this.packedData[t++]}sumPoleBuffer2ForSpan(e){this.poleBuffer2.fill(0);let t=e*this.poleLength;for(const n of this.basisBuffer2)for(let i=0;i<this.poleLength;i++)this.poleBuffer2[i]+=n*this.packedData[t++]}evaluateBuffersInSpan(e,t){this.evaluateBasisFunctionsInSpan(e,t,this.basisBuffer),this.sumPoleBufferForSpan(e)}evaluateBuffersInSpan1(e,t){this.evaluateBasisFunctionsInSpan(e,t,this.basisBuffer,this.basisBuffer1),this.sumPoleBufferForSpan(e),this.sumPoleBuffer1ForSpan(e)}evaluateBuffersAtKnot(e,t=0){const n=this.knots.knotToLeftKnotIndex(e);t<1?(this.knots.evaluateBasisFunctions(n,e,this.basisBuffer),this.sumPoleBufferForSpan(n-this.degree+1)):t===1?(this.knots.evaluateBasisFunctions1(n,e,this.basisBuffer,this.basisBuffer1),this.sumPoleBufferForSpan(n-this.degree+1),this.sumPoleBuffer1ForSpan(n-this.degree+1)):(this.knots.evaluateBasisFunctions1(n,e,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 e=this.poleLength,t=this.packedData;for(let n=0,i=e*(this.numPoles-1);n<i;n+=e,i-=e)for(let s=0;s<e;s++)[t[n+s],t[i+s]]=[t[i+s],t[n+s]];this.knots.reflectKnots()}testCloseablePolygon(e){return this.testClosablePolygon(e)}testClosablePolygon(e){e===void 0&&(e=this.knots.wrappable);let t=0;if(e===Dt.OpenByAddingControlPoints)t=this.degree;else if(e===Dt.OpenByRemovingKnots)t=1;else return!1;const n=this.poleLength,i=(this.numPoles-t)*n,s=t*n;for(let r=0;r<s;r++)if(!f.isSameCoordinate(this.packedData[r],this.packedData[r+i]))return!1;return!0}addKnot(e,t){if(e<this.knots.leftKnot||e>this.knots.rightKnot)return!1;let n=this.knots.knotToLeftKnotIndex(e);if(Math.abs(e-this.knots.knots[n])<$e.knotTolerance)e=this.knots.knots[n];else if(Math.abs(e-this.knots.knots[n+1])<$e.knotTolerance){if(n+=this.knots.getKnotMultiplicityAtIndex(n+1),n>this.knots.rightKnotIndex)return!0;e=this.knots.knots[n]}const i=Math.min(t,this.degree)-this.knots.getKnotMultiplicity(e);if(i<=0)return!0;let s=this.knots.knots.length;const r=new Float64Array(s+i);for(let d=0;d<s;++d)r[d]=this.knots.knots[d];let a=this.numPoles;const o=new Float64Array(this.packedData.length+i*this.poleLength);for(let d=0;d<this.packedData.length;++d)o[d]=this.packedData[d];const c=new Float64Array(this.degree*this.poleLength);for(let d=0;d<i;++d){let h=0;const u=n-this.degree+2;for(let m=u;m<u+this.degree;++m){const p=(e-r[m-1])/(r[m+this.degree-1]-r[m-1]);for(let x=m*this.poleLength;x<(m+1)*this.poleLength;++x)c[h++]=f.interpolate(o[x-this.poleLength],p,o[x])}o.copyWithin((u+this.degree)*this.poleLength,(u+this.degree-1)*this.poleLength,a*this.poleLength);let g=u*this.poleLength;for(const m of c)o[g++]=m;r.copyWithin(n+2,n+1,s),r[n+1]=e,++n,++s,++a}return this.knots.setKnotsCapture(r),this.packedData=o,!0}}class Bs extends le{curvePrimitiveType="bsplineCurve";_bcurve;_definitionData;set definitionData(e){this._definitionData=e}get definitionData(){return this._definitionData}constructor(e,t,n,i){super(),this._bcurve=Vr.create(t,e,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(e){return this._bcurve.knots.copyKnots(e)}getWrappable(){return this._bcurve.knots.wrappable}setWrappable(e){this._bcurve.knots.wrappable=e}get isClosableCurve(){const e=this._bcurve.knots.wrappable;return e===Dt.None||!this._bcurve.knots.testClosable(e)||!this._bcurve.testClosablePolygon(e)?Dt.None:e}fractionToPoint(e,t){return this.knotToPoint(this._bcurve.knots.fractionToKnot(e),t)}fractionToPointAndDerivative(e,t){const n=this._bcurve.knots.fractionToKnot(e);return t=this.knotToPointAndDerivative(n,t),t.direction.scaleInPlace(this._bcurve.knots.knotLength01),t}fractionToPointAnd2Derivatives(e,t){const n=this._bcurve.knots.fractionToKnot(e);t=this.knotToPointAnd2Derivatives(n,t);const i=this._bcurve.knots.knotLength01;return t.vectorU.scaleInPlace(i),t.vectorV.scaleInPlace(i*i),t}startPoint(e){return this.evaluatePointInSpan(0,0,e)}endPoint(e){return this.evaluatePointInSpan(this.numSpan-1,1,e)}reverseInPlace(){this._bcurve.reverseInPlace()}collectBezierSpans(e){const t=[],n=this.numSpan;for(let i=0;i<n;i++)if(this._bcurve.knots.isIndexOfRealSpan(i)){const s=this.getSaturatedBezierSpan3dOr3dH(i,e);s&&t.push(s)}return t}poleIndexToDataIndex(e){if(e>=0&&e<this.numPoles)return e*this._bcurve.poleLength}closestPoint(e,t=!1,n){const i=this.fractionToPoint(0);n=Y.createCurveFractionPointDistance(this,0,i,i.distance(e),n);let s;const r=this.numSpan;for(let a=0;a<r;a++)this._bcurve.knots.isIndexOfRealSpan(a)&&(s=this.getSaturatedBezierSpan3dOr3dH(a,!0,s),s&&s.updateClosestPointByTruePerpendicular(e,n,!1,!0)&&(n.curve=this,n.fraction=s.fractionToParentFraction(n.fraction)));return n}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}clonePartialCurve(e,t){let n;if(e>t)return n=this.clonePartialCurve(t,e),n.reverseInPlace(),n;n=this.clone();const i=n._bcurve.knots.knots.length;let s=n._bcurve.knots.fractionToKnot(e),r=n._bcurve.knots.fractionToKnot(t);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 a=n._bcurve.knots.knotToLeftKnotIndex(s)-n.degree+1,o=a*n._bcurve.poleLength,c=n._bcurve.knots.knotToLeftKnotIndex(r);let d=c-n._bcurve.knots.getKnotMultiplicityAtIndex(c)+1;n._bcurve.knots.knots[c]<r&&(d=c+1);const h=(d+1)*n._bcurve.poleLength,u=d+n.degree;return n._bcurve.knots.setKnotsCapture(n._bcurve.knots.knots.slice(a,u)),n._bcurve.packedData=n._bcurve.packedData.slice(o,h),n.setWrappable(Dt.None),n}appendPlaneIntersectionPoints(e,t){const n=this.numPoles,i=this.order,s=new Float64Array(n),r=this.numSpan,a=Z.create(),o=fe.createNull();for(let u=0;u<n;u++)this.getPolePoint4d(u,a),s[u]=e.weightedAltitude(a),o.extendX(s[u]);let c,d=0,h=-1e3;if(o.containsX(0)){for(let u=0;u<r;u++)if(this._bcurve.knots.isIndexOfRealSpan(u)&&(o.setNull(),o.extendArraySubset(s,u,i),o.containsX(0))){c=it.createArraySubset(s,u,i,c),xi.saturate1dInPlace(c.coffs,this._bcurve.knots,u);const g=c.roots(0,!0);if(g)for(const m of g){d++;const p=this._bcurve.knots.spanFractionToFraction(u,m);if(!f.isAlmostEqualNumber(p,h)){const x=Y.createCurveEvaluatedFraction(this,p);x.intervalRole=Fe.isolated,t.push(x),h=p}}}}return d}constructOffsetXY(e){const t=Kt.create(e),n=new Vs(this,t.leftOffsetDistance);return this.emitStrokableParts(n,t.strokeOptions),n.claimResult()}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}}class It extends Bs{_workBezier;initializeWorkBezier(){return this._workBezier===void 0&&(this._workBezier=Cn.createOrder(this.order)),this._workBezier}constructor(e,t,n){super(3,e,t,n)}isSameGeometryClass(e){return e instanceof It}tryTransformInPlace(e){return lt.multiplyInPlace(e,this._bcurve.packedData),!0}getPolePoint3d(e,t){const n=this.poleIndexToDataIndex(e);if(n!==void 0){const i=this._bcurve.packedData;return y.create(i[n],i[n+1],i[n+2],t)}}getPolePoint4d(e,t){const n=this.poleIndexToDataIndex(e);if(n!==void 0){const i=this._bcurve.packedData;return Z.create(i[n],i[n+1],i[n+2],1,t)}}spanFractionToKnot(e,t){return this._bcurve.spanFractionToKnot(e,t)}copyPoints(){return lt.unpackNumbersToNestedArrays(this._bcurve.packedData,3)}copyPointsFloat64Array(){return this._bcurve.packedData.slice()}copyKnots(e){return this._bcurve.knots.copyKnots(e)}static createUniformKnots(e,t){const n=e instanceof Float64Array?e.length/3:e.length;if(t<2||n<t)return;const i=$e.createUniformClamped(n,t-1,0,1),s=new It(n,t,i);if(e instanceof Float64Array)for(let r=0;r<3*n;r++)s._bcurve.packedData[r]=e[r];else if(e instanceof J)s._bcurve.packedData=e.float64Data().slice(0,3*n);else{let r=0;for(const a of e)s._bcurve.packedData[r++]=a.x,s._bcurve.packedData[r++]=a.y,s._bcurve.packedData[r++]=a.z}return s}static createPeriodicUniformKnots(e,t){if(t<2)return;let n=e instanceof Float64Array?e.length/3:e.length;if(n<2)return;const i=y.createZero(),s=y.createZero();let r=!1;do e instanceof Float64Array?(i.set(e[0],e[1],e[2]),s.set(e[3*n-3],e[3*n-2],e[3*n-1])):e instanceof J?(e.getPoint3dAtUncheckedPointIndex(0,i),e.getPoint3dAtUncheckedPointIndex(n-1,s)):(i.setFromPoint3d(e[0]),s.setFromPoint3d(e[n-1])),(r=i.isAlmostEqual(s))&&--n;while(r&&n>1);if(n<t)return;const a=t-1,o=n,c=$e.createUniformWrapped(o,a,0,1);c.wrappable=Dt.OpenByAddingControlPoints;const d=new It(n+a,t,c);if(e instanceof Float64Array){let h=0;for(let u=0;u<3*n;u++)d._bcurve.packedData[h++]=e[u];for(let u=0;u<3*a;u++)d._bcurve.packedData[h++]=e[u]}else if(e instanceof J){let h=0;for(let u=0;u<3*n;u++)d._bcurve.packedData[h++]=e.float64Data()[u];for(let u=0;u<3*a;u++)d._bcurve.packedData[h++]=e.float64Data()[u]}else{let h=0;for(let u=0;u<n;u++)d._bcurve.packedData[h++]=e[u].x,d._bcurve.packedData[h++]=e[u].y,d._bcurve.packedData[h++]=e[u].z;for(let u=0;u<a;u++)d._bcurve.packedData[h++]=e[u].x,d._bcurve.packedData[h++]=e[u].y,d._bcurve.packedData[h++]=e[u].z}return d}static createFromInterpolationCurve3dOptions(e){return Vn.createThroughPointsC2Cubic(e)}static createFromAkimaCurve3dOptions(e){return Vn.createThroughPoints(e.fitPoints,4)}static create(e,t,n){if(n<2)return;let i=e.length;if(e instanceof Float64Array&&(i=Math.floor(i/3)),i<n)return;const s=t.length,r=i+n===s;if(!r&&i+n!==s+2)return;const a=$e.create(t,n-1,r),o=new It(i,n,a);let c=0;if(e instanceof Float64Array)for(const d of e)o._bcurve.packedData[c++]=d;else if(e[0]instanceof y)for(const d of e)o._bcurve.packedData[c++]=d.x,o._bcurve.packedData[c++]=d.y,o._bcurve.packedData[c++]=d.z;else if(Array.isArray(e[0])&&e[0].length===3)for(const d of e)for(const h of d)o._bcurve.packedData[c++]=h;else return;return o}clone(){const e=this._bcurve.knots.clone(),t=new It(this.numPoles,this.order,e);return t._bcurve.packedData=this._bcurve.packedData.slice(),t}evaluatePointInSpan(e,t,n){return this._bcurve.evaluateBuffersInSpan(e,t),y.createFrom(this._bcurve.poleBuffer,n)}evaluatePointAndDerivativeInSpan(e,t){return this._bcurve.evaluateBuffersInSpan1(e,t),q.createCapture(y.createFrom(this._bcurve.poleBuffer),v.createFrom(this._bcurve.poleBuffer1))}knotToPoint(e,t){return this._bcurve.evaluateBuffersAtKnot(e),y.createFrom(this._bcurve.poleBuffer,t)}knotToPointAndDerivative(e,t){return this._bcurve.evaluateBuffersAtKnot(e,1),t?(t.origin.setFrom(this._bcurve.poleBuffer),t.direction.setFrom(this._bcurve.poleBuffer1),t):q.createCapture(y.createFrom(this._bcurve.poleBuffer),v.createFrom(this._bcurve.poleBuffer1))}knotToPointAnd2Derivatives(e,t){return this._bcurve.evaluateBuffersAtKnot(e,2),ke.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],t)}isAlmostEqual(e){return e instanceof It?this._bcurve.knots.isAlmostEqual(e._bcurve.knots)&<.isAlmostEqual(this._bcurve.packedData,e._bcurve.packedData):!1}isInPlane(e){return lt.isCloseToPlane(this._bcurve.packedData,e)}quickLength(){return lt.sumEdgeLengths(this._bcurve.packedData)}emitStrokableParts(e,t){const n=this.initializeWorkBezier(),i=this.numSpan;let s;for(let r=0;r<i;r++){const a=this.getSaturatedBezierSpan3dOr3dH(r,!1,n);a&&(s=a.computeStrokeCountForOptions(t),e.announceBezierCurve?e.announceBezierCurve(a,s,this,r,this._bcurve.knots.spanFractionToFraction(r,0),this._bcurve.knots.spanFractionToFraction(r,1)):e.announceIntervalForUniformStepStrokes(this,s,this._bcurve.knots.spanFractionToFraction(r,0),this._bcurve.knots.spanFractionToFraction(r,1)))}}computeStrokeCountForOptions(e){const t=this.initializeWorkBezier(),n=this.numSpan;let i=0;for(let s=0;s<n;s++){const r=this.getSaturatedBezierSpan3d(s,t);r&&(i+=r.computeStrokeCountForOptions(e))}return i}computeAndAttachRecursiveStrokeCounts(e,t){const n=this.initializeWorkBezier(),i=this.numSpan,s=pn.createWithCurvePrimitiveAndOptionalParent(this,t,[]);for(let r=0;r<i;r++)if(this.getSaturatedBezierSpan3d(r,n)){const o=n.curveLength(),c=n.computeStrokeCountForOptions(e);s.addToCountAndLength(c,o)}le.installStrokeCountMap(this,s,t)}emitStrokes(e,t){const n=this.initializeWorkBezier(),i=this.numSpan;for(let s=0;s<i;s++){const r=this.getSaturatedBezierSpan3d(s,n);r&&r.emitStrokes(e,t)}}get isClosable(){return this.isClosableCurve}getSaturatedBezierSpan3dOr3dH(e,t,n){return t?this.getSaturatedBezierSpan3dH(e,n):this.getSaturatedBezierSpan3d(e,n)}getSaturatedBezierSpan3d(e,t){if(e<0||e>=this.numSpan)return;const n=this.order;(t===void 0||!(t instanceof Cn)||t.order!==n)&&(t=Cn.createOrder(n));const i=t;if(i.loadSpanPoles(this._bcurve.packedData,e),i.saturateInPlace(this._bcurve.knots,e))return i}getSaturatedBezierSpan3dH(e,t){if(e<0||e>=this.numSpan)return;const n=this.order;(t===void 0||!(t instanceof En)||t.order!==n)&&(t=En.createOrder(n));const i=t;if(i.loadSpan3dPolesWithWeight(this._bcurve.packedData,e,1),i.saturateInPlace(this._bcurve.knots,e))return i}dispatchToGeometryHandler(e){return e.handleBSplineCurve3d(this)}extendRange(e,t){const n=this._bcurve.packedData,i=n.length-2;if(t)for(let s=0;s<i;s+=3)e.extendTransformedXYZ(t,n[s],n[s+1],n[s+2]);else for(let s=0;s<i;s+=3)e.extendXYZ(n[s],n[s+1],n[s+2])}}class Vn{static createThroughPoints(e,t){const n=e.length;if(t>n||t<2)return;const i=t-1,s=1+2*i,r=new Float64Array(s*n),a=new Float64Array(t),o=new J,c=$e.createUniformClamped(n,t-1,0,1),d=y.create();for(let u=0;u<n;u++){const g=c.grevilleKnot(u),m=c.knotToLeftKnotIndex(g);c.evaluateBasisFunctions(m,g,a);let p=0;for(let I=1;I<t;I++)a[I]>a[p]&&(p=I);const x=i-p,_=u*s;for(let I=0;I<t;I++){const S=u-i+x+I;_+S>=0&&S<n&&(r[_+x+I]=a[I])}e instanceof gt?o.push(e.getPoint3dAtUncheckedPointIndex(u,d)):o.push(e[u].clone())}const h=co.solveBandedSystemMultipleRHS(n,s,r,3,o.float64Data());if(h)return It.create(h,c.knots,t)}static createThroughPointsC2Cubic(e){const t=e.clone();if(!this.C2CubicFit.validateOptions(t))return;const n=this.C2CubicFit.constructPoles(t);if(n===void 0)return;const i=this.C2CubicFit.convertFitParamsToCubicKnotVector(t.knots,t.closed);if(i===void 0)return;const s=It.create(n,i,t.order);return t.closed&&s?.setWrappable(Dt.OpenByAddingControlPoints),s}}(function(l){class e{static normalizeKnots(n){if(n===void 0||n.length<2)return n=void 0,!1;const i=$e.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=$e.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 Qe(n.fitPoints).findOrderedDuplicates(void 0,!0);if(s.length>0){let r=0;for(let a=0,o=0;a<n.fitPoints.length;++a)o<s.length&&a===s[o]?++o:(n.fitPoints[r]=n.fitPoints[a],n.knots&&(n.knots[r]=n.knots[a]),++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,a,o,c,d){let h=1/(d+c+o);n[r]=o*o*h,i[r]=o*(d+c)*h,h=1/(c+o+a),i[r]+=c*(o+a)*h,s[r]=c*c*h,h=1/(c+o),n[r]*=h,i[r]*=h,s[r]*=h}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,a,o){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,d=0,h=0,u=0,g=0,m=0;return a?(n[0]=0,d=r.knots[1]-r.knots[0],c=r.knots[2]-r.knots[1],g=d+c,m=1/g,i[0]=(d+g)*m,s[0]=-d*m):(n[0]=s[0]=0,i[0]=1),h=r.knots[1]-r.knots[0],d=r.knots[2]-r.knots[1],m=1/(h+d),m*=m,n[1]=d*d*m,i[1]=2*(d*h)*m,s[1]=h*h*m,o?(h=r.knots[2]-r.knots[1],u=r.knots[1]-r.knots[0],g=u+h,m=1/g,n[2]=-h*m,i[2]=(h+g)*m,s[2]=0):(n[2]=s[2]=0,i[2]=1),!0}static setUpSystem4PointsOrMore(n,i,s,r,a,o){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,d=c-1;let h=0,u=0,g=0,m=0,p=0,x=0;r.closed?(u=r.knots[1]-r.knots[0],m=r.knots[d]-r.knots[d-1],g=r.knots[d+1]-r.knots[d],h=r.knots[2]-r.knots[1],this.computeAlphaBetaGamma(n,i,s,0,h,u,g,m),m=g,g=u,u=r.knots[2]-r.knots[1],h=r.knots[3]-r.knots[2],this.computeAlphaBetaGamma(n,i,s,1,h,u,g,m),h=g,u=r.knots[d+1]-r.knots[d],m=r.knots[d-1]-r.knots[d-2],g=r.knots[d]-r.knots[d-1],this.computeAlphaBetaGamma(n,i,s,d,h,u,g,m)):(a?(n[0]=0,u=r.knots[1]-r.knots[0],h=r.knots[2]-r.knots[1],p=u+h,x=1/p,i[0]=(u+p)*x,s[0]=-u*x):(n[0]=s[0]=0,i[0]=1),u=r.knots[2]-r.knots[1],g=r.knots[1]-r.knots[0],m=0,h=r.knots[3]-r.knots[2],this.computeAlphaBetaGamma(n,i,s,1,h,u,g,m),u=r.knots[d+1]-r.knots[d],g=r.knots[d]-r.knots[d-1],m=r.knots[d-1]-r.knots[d-2],h=0,this.computeAlphaBetaGamma(n,i,s,d,h,u,g,m),o?(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;_<d;++_)u=r.knots[_+1]-r.knots[_],m=r.knots[_-1]-r.knots[_-2],g=r.knots[_]-r.knots[_-1],h=r.knots[_+2]-r.knots[_+1],this.computeAlphaBetaGamma(n,i,s,_,h,u,g,m);return!0}static setUpSystem(n,i,s,r){let a=!1,o=!1;r.isNaturalTangents&&!r.closed&&(a=r.startTangent===void 0,o=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,a,o):4<=r.fitPoints.length&&(c=this.setUpSystem4PointsOrMore(n,i,s,r,a,o)),c}static setBesselEndCondition(n,i,s){if(n.length!==i.fitPoints.length+2||i.knots===void 0)return!1;const r=1/3,a=i.fitPoints.length-1;if(a===1)return s?n[0].interpolate(r,n[3],n[1]):n[3].interpolate(r,n[0],n[2]),!0;if(a===2){const o=(i.knots[2]-i.knots[1])/(i.knots[2]-i.knots[0]),c=1-o,d=n[2].plus2Scaled(n[0],-o*o,n[4],-c*c);return s?y.createAdd2Scaled(d,1/(2*o),n[0],o).interpolate(r,n[0],n[1]):y.createAdd2Scaled(d,1/(2*c),n[4],c).interpolate(r,n[4],n[3]),!0}if(s){const o=(i.knots[2]-i.knots[1])/(i.knots[2]-i.knots[0]),c=1-o,d=n[2].plus2Scaled(n[0],-o*o,n[3],-c*c);y.createAdd2Scaled(d,1/(2*o),n[0],o).interpolate(r,n[0],n[1])}else{const o=(i.knots[a]-i.knots[a-1])/(i.knots[a]-i.knots[a-2]),c=1-o,d=n[a].plus2Scaled(n[a-1],-o*o,n[a+2],-c*c);y.createAdd2Scaled(d,1/(2*c),n[a+2],c).interpolate(r,n[a+2],n[a+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 a=0,o=0,c=0;const d=i.fitPoints.length-1;d===1?s?(a=0,o=1,c=3):(a=3,o=2,c=0):s?(a=0,o=1,c=2):(a=d+2,o=d+1,c=d);const h=n[c].distance(n[a]);return n[a].plusScaled(r,h/3,n[o]),!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 a=i.fitPoints.length-1,o=s?0:a+2,c=s?1:a+1;return n[o].plusScaled(r,n[o].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=v.createStartEnd(n[1],n[0]).normalize();if(r!==void 0){const a=n[s+2].distance(n[s+1]);n[s+2].plusScaled(r,a,n[s+1])}}else if(i.endTangent!==void 0){const r=v.createStartEnd(n[s+1],n[s+2]).normalize();if(r!==void 0){const a=n[0].distance(n[1]);n[0].plusScaled(r,a,n[1])}}else{const r=v.createStartEnd(n[s+1],n[1]).normalize();if(r!==void 0){const a=n[0].distance(n[1]);n[0].plusScaled(r,a,n[1]);const o=n[s+2].distance(n[s+1]);n[s+2].plusScaled(r,-o,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 a=!1;return i.startTangent===void 0?i.isNaturalTangents?a=this.setNaturalEndCondition(n,i,!0):a=this.setBesselEndCondition(n,i,!0):i.isChordLenTangents?a=this.setChordLengthScaledEndCondition(n,i,!0):a=this.setBesselLengthScaledEndCondition(n,i,!0),i.endTangent===void 0?i.isNaturalTangents?a=this.setNaturalEndCondition(n,i,!1):a=this.setBesselEndCondition(n,i,!1):i.isChordLenTangents?a=this.setChordLengthScaledEndCondition(n,i,!1):a=this.setBesselLengthScaledEndCondition(n,i,!1),a&&(a=this.setPhysicallyClosedEndCondition(n,i)),a}static solveNearTridiagonal(n,i,s,r){if(i.length!==s.length||i.length!==r.length||i.length!==n.length)return;const a=[],o=n.length-1,c=n.slice(0,-1);let d=0;for(let h=1;h<o;++h){if((d=f.conditionalDivideFraction(-i[h],s[h-1]))===void 0)return;s[h]+=d*r[h-1],i[h]=d*i[h-1],c[h].addScaledInPlace(c[h-1],d)}if((d=f.conditionalDivideFraction(1,s[o-1]+i[o-1]))!==void 0){r[o-1]*=d,c[o-1].scaleInPlace(d);for(let h=o-2;h>=0;--h){if((d=f.conditionalDivideFraction(1,s[h]))===void 0)return;y.createScale(c[h].plus2Scaled(c[h+1],-r[h],c[o-1],-i[h]),d,c[h]),r[h]=-(r[h]*r[h+1]+i[h]*r[o-1])*d}if((d=f.conditionalDivideFraction(1,1+r[0]))!==void 0){a.push(y.createScale(c[0],d));for(let h=1;h<o;++h)a.push(c[h].plusScaled(a[0],-r[h]));return a}}}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 a=r.length-i;switch(a){case 0:break;case 4:case 6:{for(let o=0;o<a/2;++o)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 a=s?6:4;if(i){const o=r.length-2;for(let c=2;c<=a;c+=2)r.unshift(r[o]-1),r.push(1+r[c])}else for(let o=0;o<a/2;++o)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(lt.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),a=Array(i);if(!this.setUpSystem(s,r,a,n))return;let o=[];if(n.closed){if((o=this.solveNearTridiagonal(n.fitPoints,s,r,a))!==void 0&&o.length>2){const c=o.pop();o.unshift(c);for(let d=0;d<n.order-1;++d)o.push(o[d].clone())}}else{const c=n.fitPoints.slice();if(!this.setEndConditions(c,n)||c.length!==i+2)return;const d=new Float64Array(i*3),h=new Float64Array(i*3);for(let m=0,p=0,x=0;m<i;++m)d[p++]=s[m],d[p++]=r[m],d[p++]=a[m],h[x++]=c[m+1].x,h[x++]=c[m+1].y,h[x++]=c[m+1].z;const u=co.solveBandedSystemMultipleRHS(i,3,d,3,h);if(u===void 0)return;o=new Float64Array(3+u.length+3);let g=0;o[g++]=n.fitPoints[0].x,o[g++]=n.fitPoints[0].y,o[g++]=n.fitPoints[0].z;for(let m=0;m<u.length;)o[g++]=u[m++];o[g++]=n.fitPoints[n.fitPoints.length-1].x,o[g++]=n.fitPoints[n.fitPoints.length-1].y,o[g++]=n.fitPoints[n.fitPoints.length-1].z}return o}}l.C2CubicFit=e})(Vn||(Vn={}));class qr extends le{dispatchToGeometryHandler(e){return this._proxyCurve.dispatchToGeometryHandler(e)}_proxyCurve;constructor(e){super(),this._proxyCurve=e}get proxyCurve(){return this._proxyCurve}computeStrokeCountForOptions(e){return this._proxyCurve.computeStrokeCountForOptions(e)}emitStrokableParts(e,t){this._proxyCurve.emitStrokableParts(e,t)}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}clonePartialCurve(e,t){return this._proxyCurve.clonePartialCurve(e,t)}emitStrokes(e,t){this._proxyCurve.emitStrokes(e,t)}extendRange(e,t){this._proxyCurve.extendRange(e,t)}range(e,t){return this._proxyCurve.range(e,t)}fractionToPoint(e,t){return this._proxyCurve.fractionToPoint(e,t)}fractionToPointAndDerivative(e,t){return this._proxyCurve.fractionToPointAndDerivative(e,t)}fractionToPointAnd2Derivatives(e,t){return this._proxyCurve.fractionToPointAnd2Derivatives(e,t)}isInPlane(e){return this._proxyCurve.isInPlane(e)}quickLength(){return this._proxyCurve.quickLength()}constructOffsetXY(e){return this._proxyCurve.constructOffsetXY(e)}projectedParameterRange(e,t){return this._proxyCurve.projectedParameterRange(e,t)}}class Us{constructor(e,t){this._fitPoints=e||[],this._knots=t}_order;_closed;_isChordLenKnots;_isColinearTangents;_isChordLenTangents;_isNaturalTangents;_startTangent;_endTangent;_fitPoints;_knots;get order(){return f.resolveNumber(this._order,4)}set order(e){this._order=e}get closed(){return f.resolveValue(this._closed,!1)}set closed(e){this._closed=e}get isChordLenKnots(){return f.resolveNumber(this._isChordLenKnots,0)}set isChordLenKnots(e){this._isChordLenKnots=e}get isColinearTangents(){return f.resolveNumber(this._isColinearTangents,0)}set isColinearTangents(e){this._isColinearTangents=e}get isChordLenTangents(){return f.resolveNumber(this._isChordLenTangents,0)}set isChordLenTangents(e){this._isChordLenTangents=e}get isNaturalTangents(){return f.resolveNumber(this._isNaturalTangents,0)}set isNaturalTangents(e){this._isNaturalTangents=e}get startTangent(){return this._startTangent}set startTangent(e){this._startTangent=e}get endTangent(){return this._endTangent}set endTangent(e){this._endTangent=e}get fitPoints(){return this._fitPoints}set fitPoints(e){this._fitPoints=e}get knots(){return this._knots}set knots(e){this._knots=e}captureOptionalProps(e,t,n,i,s,r,a,o){this._order=f.resolveToUndefined(e,0),this._closed=f.resolveToUndefined(t,!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=a,this._endTangent=o}cloneAsInterpolationCurve3dProps(){const e={fitPoints:lt.cloneDeepJSONNumberArrays(this.fitPoints),knots:this._knots?.slice()};return this._order!==void 0&&(e.order=this._order),this._closed!==void 0&&(e.closed=this._closed),this._isChordLenKnots!==void 0&&(e.isChordLenKnots=this._isChordLenKnots),this._isColinearTangents!==void 0&&(e.isColinearTangents=this._isColinearTangents),this._isChordLenTangents!==void 0&&(e.isChordLenTangents=this._isChordLenTangents),this._isNaturalTangents!==void 0&&(e.isNaturalTangents=this._isNaturalTangents),this._startTangent!==void 0&&(e.startTangent=this._startTangent?.toArray()),this._endTangent!==void 0&&(e.endTangent=this._endTangent?.toArray()),e}clone(){const e=new Us(lt.clonePoint3dArray(this.fitPoints),this.knots?.slice());return e._order=this.order,e._closed=this.closed,e._isChordLenKnots=this.isChordLenKnots,e._isColinearTangents=this.isColinearTangents,e._isChordLenTangents=this.isChordLenTangents,e._isNaturalTangents=this.isNaturalTangents,e._startTangent=this._startTangent?.clone(),e._endTangent=this._endTangent?.clone(),e}static create(e){const t=new Us(lt.clonePoint3dArray(e.fitPoints),e.knots?.slice());return t._order=e.order,t._closed=e.closed,t._isChordLenKnots=e.isChordLenKnots,t._isColinearTangents=e.isColinearTangents,t._isChordLenTangents=e.isChordLenTangents,t._isNaturalTangents=e.isNaturalTangents,t._startTangent=e.startTangent?v.fromJSON(e.startTangent):void 0,t._endTangent=e.endTangent?v.fromJSON(e.endTangent):void 0,t}static areAlmostEqualAllow000AsUndefined(e,t){return e!==void 0&&e.maxAbs()===0&&(e=void 0),t!==void 0&&t.maxAbs()===0&&(t=void 0),e!==void 0&&t!==void 0?e.isAlmostEqual(t):e===void 0&&t===void 0}static areAlmostEqual(e,t){if(e===void 0&&t===void 0)return!0;if(e!==void 0&&t!==void 0&&f.areEqualAllowUndefined(e.order,t.order)&&f.areEqualAllowUndefined(e.closed,t.closed)&&f.areEqualAllowUndefined(e.isChordLenKnots,t.isChordLenKnots)&&f.areEqualAllowUndefined(e.isColinearTangents,t.isColinearTangents)&&f.areEqualAllowUndefined(e.isNaturalTangents,t.isNaturalTangents)&&this.areAlmostEqualAllow000AsUndefined(e.startTangent,t.startTangent)&&this.areAlmostEqualAllow000AsUndefined(e.endTangent,t.endTangent)&&f.almostEqualArrays(e.fitPoints,t.fitPoints,(n,i)=>n.isAlmostEqual(i))){if(f.almostEqualNumberArrays(e.knots,t.knots,(s,r)=>s===r)||e.knots===void 0&&t.knots===void 0)return!0;let n=e.knots,i=t.knots;return e.knots===void 0?n=Vn.C2CubicFit.constructFitParametersFromPoints(e.fitPoints,e.isChordLenKnots,e.closed):t.knots===void 0&&(i=Vn.C2CubicFit.constructFitParametersFromPoints(t.fitPoints,t.isChordLenKnots,t.closed)),n=Vn.C2CubicFit.convertCubicKnotVectorToFitParams(n,e.fitPoints.length,!1),i=Vn.C2CubicFit.convertCubicKnotVectorToFitParams(i,t.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 e=this._startTangent;this._startTangent=this.endTangent,this._endTangent=e}}class Vs{_offsetDistance;_fitOptions;_p0=y.createZero();_p1=y.createZero();_v0=v.createZero();_v1=v.createZero();_r0=q.createZero();constructor(e,t){this._offsetDistance=t,this._fitOptions=new Us;const n=e.fractionToPointAndUnitTangent(0,this._r0).direction.clone(),i=e.fractionToPointAndUnitTangent(1,this._r0).direction.negate();this._fitOptions.startTangent=n,this._fitOptions.endTangent=i,(this._fitOptions.closed=e.startPoint(this._p0).isAlmostEqual(e.endPoint(this._p1))&&n.isParallelTo(i,!0))&&(this._fitOptions.isChordLenKnots=1)}pushOffsetPoint(e,t){(!f.isSmallMetricDistance(t.x)||!f.isSmallMetricDistance(t.y))&&this._fitOptions.fitPoints.push(e.plusScaled(t.unitPerpendicularXY(this._v0),this._offsetDistance))}needPrimaryGeometryForStrokes(){return!0}startParentCurvePrimitive(e){}startCurvePrimitive(e){}endCurvePrimitive(e){}endParentCurvePrimitive(e){}announceIntervalForUniformStepStrokes(e,t,n,i){for(let s=0;s<=t;++s){const r=f.interpolate(n,s/t,i),a=e.fractionToPointAndDerivative(r,this._r0);this.pushOffsetPoint(a.origin,a.direction)}}announceSegmentInterval(e,t,n,i,s,r){if(i>0){const a=v.createStartEnd(t,n,this._v1);for(let o=0;o<=i;++o)this.pushOffsetPoint(t.interpolate(o/i,n,this._p0),a)}}announcePointTangent(e,t,n){this.pushOffsetPoint(e,n)}claimResult(){return Vn.createThroughPointsC2Cubic(this._fitOptions)}}class Zr{constructor(){}announceUnexpected(e,t){}announceCurvePrimitive(e,t=-1){}announcePath(e,t=-1){let n=0;for(const i of e.children)this.announceCurvePrimitive(i,n++)}announceLoop(e,t=-1){let n=0;for(const i of e.children)this.announceCurvePrimitive(i,n++)}announceParityRegion(e,t=-1){let n=0;for(const i of e.children)this.announceLoop(i,n++)}announceUnionRegion(e,t=-1){let n=0;for(const i of e.children)i.curveCollectionType==="loop"?this.announceLoop(i,n++):this.announceParityRegion(i,n++)}announceBagOfCurves(e,t=-1){for(const n of e.children)n instanceof le?this.announceCurvePrimitive(n):n.announceToCurveProcessor(this)}}class Wr extends Zr{_stack;constructor(){super(),this._stack=[]}enter(e){this._stack.push(e)}leave(){return this._stack.pop()}announceUnexpected(e,t){}announceCurvePrimitive(e,t=-1){}announcePath(e,t=-1){this.enter(e),super.announcePath(e,t),this.leave()}announceLoop(e,t=-1){this.enter(e),super.announceLoop(e,t),this.leave()}announceParityRegion(e,t=-1){this.enter(e);let n=0;for(const i of e.children)this.announceLoop(i,n++);this.leave()}announceUnionRegion(e,t=-1){this.enter(e);let n=0;for(const i of e.children)i.curveCollectionType==="loop"?this.announceLoop(i,n++):this.announceParityRegion(i,n++);this.leave()}announceBagOfCurves(e,t=-1){this.enter(e);let n=0;for(const i of e.children)i instanceof le?this.announceCurvePrimitive(i,n++):i.announceToCurveProcessor(this);this.leave()}}class Li extends Wr{_result;_transform;constructor(e){super(),this._transform=e,this._result=void 0}static clone(e,t){const n=new Li(t);return e.announceToCurveProcessor(n),n._result}enter(e){e instanceof _e&&super.enter(e.cloneEmptyPeer())}leave(){const e=super.leave();return e&&(this._stack.length===0?this._result=e:this._stack[this._stack.length-1].tryAddChild(e)),e}doClone(e){return this._transform?e.cloneTransformed(this._transform):e.clone()}announceCurvePrimitive(e,t){const n=this.doClone(e);if(n!==void 0&&this._stack.length>0){const i=this._stack[this._stack.length-1];if(i instanceof mt||i instanceof zt)if(Array.isArray(n))for(const s of n)i.tryAddChild(s);else i.tryAddChild(n)}}}class Gr extends Li{constructor(){super(void 0)}doClone(e){if(e instanceof N&&e.numPoints()>1){const t=e.packedPoints,n=t.length,i=[];for(let s=0;s+1<n;s++)i.push(Q.createCapture(t.getPoint3dAtUncheckedPointIndex(s),t.getPoint3dAtUncheckedPointIndex(s+1)));return i}return e.clone()}static clone(e){const t=new Gr;return e.announceToCurveProcessor(t),t._result}}class Qr extends Wr{numLineSegment;numLineString;numOther;constructor(){super(),this.numLineSegment=0,this.numLineString=0,this.numOther=0}static hasNonLinearPrimitives(e){const t=new Qr;return e.announceToCurveProcessor(t),t.numOther>0}announceCurvePrimitive(e,t){e instanceof Q?this.numLineSegment++:e instanceof N?this.numLineString++:this.numOther++}}class Jr extends Wr{maxGap;constructor(){super(),this.maxGap=0}static maxGap(e){const t=new Jr;return e.announceToCurveProcessor(t),t.maxGap}announceCurvePrimitive(e,t){if(this._stack.length>0){const n=this._stack[this._stack.length-1];if(n instanceof mt){const s=n.cyclicCurvePrimitive(t+1);e!==void 0&&s!==void 0&&(this.maxGap=Math.max(this.maxGap,e.endPoint().distance(s.startPoint())))}}}}class Hr extends Zr{_sum;constructor(){super(),this._sum=0}static sumLengths(e){const t=new Hr;return e.announceToCurveProcessor(t),t._sum}announceCurvePrimitive(e,t){this._sum+=e.curveLength()}}class Kr extends Zr{transform;constructor(e){super(),this.transform=e}static tryTransformInPlace(e,t){const n=new Kr(t);return e.announceToCurveProcessor(n),!0}announceCurvePrimitive(e,t){e.tryTransformInPlace(this.transform)}}class _e extends Mt{geometryCategory="curveCollection";sumLengths(){return Hr.sumLengths(this)}computeClosestPoint(e,t=!1,n,i=!1){let s;const r=new Y;let a=this.isAnyRegion()?!1:t;for(let o=0;o<this.children.length;o++){const c=this.children[o];if(this.isPath()){const h=o===0?Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,0):je.None,u=o===this.children.length-1?Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,1):je.None;a=[h,u]}(i?c.closestPointXY(e,a,r):c.closestPoint(e,a,r))&&(s=n=Y.chooseSmallerA(s,r).clone(n))}return s}closestPoint(e,t=!1,n){return this.computeClosestPoint(e,t,n)}closestPointXY(e,t=!1,n){return this.computeClosestPoint(e,t,n,!0)}emitTangents(e,t,n){const i=new io(e,t,n);if(this.children!==void 0)for(const s of this.children)s instanceof le?s.emitStrokableParts(i,n?.strokeOptions):s instanceof _e&&s.emitTangents(e,t,n)}allTangents(e,t){const n=[];return this.emitTangents(e,i=>n.push(i.clone()),t),n.length===0?void 0:n}closestTangent(e,t){const n=t?.hintPoint??e;let i;t?.vectorToEye&&!t.vectorToEye.isExactEqual({x:0,y:0,z:1})&&(i=E.createRigidViewAxesZTowardsEye(t.vectorToEye.x,t.vectorToEye.y,t.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,a=f.largeCoordinateResult;const o=c=>{const d=s(c.point);(!r||d<a)&&(r=c.clone(r),a=d)};return this.emitTangents(e,o,t),r}reverseInPlace(){for(const e of this.children)e.reverseInPlace()}reverse(){return this.reverseInPlace(),this}maxGap(){return Jr.maxGap(this)}checkForNonLinearPrimitives(){return Qr.hasNonLinearPrimitives(this)}tryTransformInPlace(e){return Kr.tryTransformInPlace(this,e)}clone(){return Li.clone(this)}cloneTransformed(e){return Li.clone(this,e)}cloneWithExpandedLineStrings(){return Gr.clone(this)}collectCurvePrimitivesGo(e,t,n=!1){if(this.children)for(const i of this.children)(i instanceof le||i instanceof _e)&&i.collectCurvePrimitivesGo(e,t,n)}collectCurvePrimitives(e,t=!1,n=!1){const i=e===void 0?[]:e;return this.collectCurvePrimitivesGo(i,t,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(e,t){const n=this.children;if(n)for(const i of n)i.extendRange(e,t)}static createCurveLocationDetailOnAnyCurvePrimitive(e,t=.5){if(e){if(e instanceof le)return Y.createCurveEvaluatedFraction(e,t);if(e instanceof _e&&e.children!==void 0)for(const n of e.children){const i=this.createCurveLocationDetailOnAnyCurvePrimitive(n,t);if(i)return i}}}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}findParentOfDescendant(e){for(const t of this.children){if(t===e)return this;if(t instanceof _e){const n=t.findParentOfDescendant(e);if(n)return n}}}isInPlane(e){if(this.children.length===0)return!1;for(const t of this.children)if(!(t instanceof _e&&t.children.length===0)&&!t.isInPlane(e))return!1;return!0}}class mt extends _e{_curves;constructor(){super(),this._curves=[]}get children(){return this._curves}startPoint(e){const t=this.getChild(0);if(t)return t.fractionToPoint(0,e)}endPoint(e){const t=this.getChild(this._curves.length-1);if(t)return t.fractionToPoint(1,e)}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){const n=this.startPoint(),i=this.endPoint();return n!==void 0&&i!==void 0&&(t?n.isAlmostEqualXY(i,e):n.isAlmostEqual(i,e))}startPointAndDerivative(e){const t=this.getChild(0);if(t)return t.fractionToPointAndDerivative(0,e)}endPointAndDerivative(e){const t=this.getChild(this._curves.length-1);if(t)return t.fractionToPointAndDerivative(1,e)}cyclicCurvePrimitive(e,t=!0){const n=this.children.length;if(n!==0){if(e>=0&&e<n)return this.children[e];if(t){const i=f.modulo(e,n);return this.children[i]}}}getPackedStrokes(e){const t=this.cloneStroked(e);if(t instanceof mt){const n=t.children;if(n.length===1){const i=n[0];if(i instanceof N)return i.packedPoints}}}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(e){return e&&e instanceof le?(this._curves.push(e),!0):!1}getChild(e){if(e<this._curves.length)return this._curves[e]}extendRange(e,t){for(const n of this._curves)n.extendRange(e,t)}reverseChildrenInPlace(){for(const e of this._curves)e.reverseInPlace();this._curves.reverse()}reverseInPlace(){this.reverseChildrenInPlace()}childIndex(e,t){for(let n=0;n<this._curves.length;n++)if(this._curves[n]===e)return n;if(t??!1)for(let n=0;n<this._curves.length;n++){const i=this._curves[n];if(i instanceof qr&&i.proxyCurve===e)return n}}primitiveIndexAndFractionToCurveLocationDetailPointAndDerivative(e,t,n=!1,i){const s=this.cyclicCurvePrimitive(e,n);if(s)return Y.createCurveEvaluatedFractionPointAndDerivative(s,t,i)}}class zt extends _e{curveCollectionType="bagOfCurves";isSameGeometryClass(e){return e instanceof zt}_children;constructor(){super(),this._children=[]}get children(){return this._children}static create(...e){const t=new zt;for(const n of e)t.tryAddChild(n);return t}dgnBoundaryType(){return 0}announceToCurveProcessor(e,t=-1){return e.announceBagOfCurves(this,t)}cloneStroked(e){const t=new zt;let n;for(n of this.children)if(n instanceof le){const i=N.create();n.emitStrokes(i,e),i&&t.children.push(i)}else if(n instanceof _e){const i=n.cloneStroked(e);i&&t.children.push(i)}return t}cloneEmptyPeer(){return new zt}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(e){return e&&this._children.push(e),!0}getChild(e){if(e<this._children.length)return this._children[e]}dispatchToGeometryHandler(e){return e.handleBagOfCurves(this)}}class Te extends mt{curveCollectionType="path";isSameGeometryClass(e){return e instanceof Te}announceToCurveProcessor(e,t=-1){return e.announcePath(this,t)}constructor(){super()}static create(...e){const t=new Te;for(const n of e)n instanceof Se?t.children.push(...n.path.children):n instanceof le?t.children.push(n):Array.isArray(n)&&n.length>0&&n[0]instanceof y&&t.children.push(N.create(n));return t}static createArray(e){return this.create(...e)}cloneStroked(e){const t=N.create();for(const n of this.children)n.emitStrokes(t,e);return Te.create(t)}dgnBoundaryType(){return 1}cloneEmptyPeer(){return new Te}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}dispatchToGeometryHandler(e){return e.handlePath(this)}}class qs{chainDistance0;chainDistance1;childFraction0;childFraction1;childCurve;range;a;constructor(e,t,n,i,s,r){this.childFraction0=e,this.childFraction1=t,this.chainDistance0=n,this.chainDistance1=i,this.childCurve=s,this.range=r,this.a=0}containsChainDistance(e){return e>=this.chainDistance0&&e<=this.chainDistance1}quickMinDistanceToChildCurve(e){if(this.range)return this.range.distanceToPoint(e);const t=this.childCurve.closestPoint(e,!1);return t?t.a:0}static collectSortedQuickMinDistances(e,t){const n=[];for(const i of e)i.a=i.quickMinDistanceToChildCurve(t),n.push(i);return n.sort((i,s)=>i.a-s.a),n}containsChildCurveAndChildFraction(e,t){return this.childCurve===e&&t>=this.childFraction0&&t<=this.childFraction1}chainDistanceToInterpolatedChildFraction(e){return f.inverseInterpolate(this.childFraction0,this.chainDistance0,this.childFraction1,this.chainDistance1,e,this.childFraction0)}chainDistanceToAccurateChildFraction(e,t){return this.childCurve.moveSignedDistanceFromFraction(this.childFraction0,e-this.chainDistance0,t??!1).fraction}fractionScaleFactor(e){return e*(this.childFraction1-this.childFraction0)/(this.chainDistance1-this.chainDistance0)}reverseFractionsAndDistances(e){const t=this.childFraction0,n=this.childFraction1,i=this.chainDistance0,s=this.chainDistance1;this.childFraction0=1-n,this.childFraction1=1-t,this.chainDistance0=e-s,this.chainDistance1=e-i}childFractionToChainDistance(e){let t=this.childCurve.curveLengthBetweenFractions(this.childFraction0,e);return e<this.childFraction0&&(t=-t),this.chainDistance0+t}}class jr{_fragments;_accumulatedDistance;constructor(){this._accumulatedDistance=0,this._fragments=[]}startParentCurvePrimitive(e){}startCurvePrimitive(e){}endParentCurvePrimitive(e){}endCurvePrimitive(e){}announcePointTangent(e,t,n){}announceSegmentInterval(e,t,n,i,s,r){const a=t.clone(),o=n.clone();let c=this._accumulatedDistance;if(i<=1)this._accumulatedDistance+=t.distance(n),this._fragments.push(new qs(s,r,c,this._accumulatedDistance,e,ie.create(a,o)));else{let d;for(let h=1,u=s;h<=i;h++,u=d)d=f.interpolate(s,h/i,r),t.interpolate(d,n,o),c=this._accumulatedDistance,this._accumulatedDistance+=Math.abs(d-u)*t.distance(n),this._fragments.push(new qs(u,d,c,this._accumulatedDistance,e,ie.create(a,o))),a.setFrom(o)}}announceIntervalForUniformStepStrokes(e,t,n,i){let s,r,a;for(let o=1,c=n;o<=t;o++,c=s){s=f.interpolate(n,o/t,i),r=e.curveLengthBetweenFractions(c,s),a=this._accumulatedDistance,this._accumulatedDistance+=r;const d=e.rangeBetweenFractions(c,s);this._fragments.push(new qs(c,s,a,this._accumulatedDistance,e,d))}}needPrimaryGeometryForStrokes(){return!0}static createPathFragmentIndex(e,t){const n=new jr;for(const s of e.children)s.emitStrokableParts(n,t);return n._fragments}}class Se extends le{curvePrimitiveType="curveChainWithDistanceIndex";_path;_fragments;_totalLength;static _numCalls=0;static _numTested=0;static _numAssigned=0;static _numCandidate=0;isSameGeometryClass(e){return e instanceof Se}constructor(e,t){super(),this._path=e instanceof Te?e:Te.create(...e.children),this._fragments=t,this._totalLength=t.length>0?t[t.length-1].chainDistance1:0}cloneTransformed(e,t){return Se.createCapture(this._path.cloneTransformed(e),t)}get path(){return this._path}get fragments(){return this._fragments}clone(e){return Se.createCapture(this._path.clone(),e)}clonePartialCurve(e,t,n){const i=e instanceof Y,s=t instanceof Y;let r=i?e.fraction:e,a=s?t.fraction:t;if(r===a)return;const o=r>a;o&&([r,a]=[a,r]);const c=r*this._totalLength,d=a*this._totalLength,h=this.chainDistanceToFragment(c,!0);if(!h)return;const u=this.chainDistanceToFragment(d,!0);if(!u)return;const g=this._path.childIndex(h.childCurve,!0);if(g===void 0)return;const m=this._path.childIndex(u.childCurve,!0);if(m===void 0)return;const p=i&&e.childDetail?e.childDetail.fraction:h.chainDistanceToAccurateChildFraction(c,!0),x=s&&t.childDetail?t.childDetail.fraction:u.chainDistanceToAccurateChildFraction(d,!0),_=Te.create(),I=(S,A,w,k)=>{if(A===w)return!1;let D;return A===0&&w===1?(D=S.clone(),k&&D.reverseInPlace()):D=k?S.clonePartialCurve(w,A):S.clonePartialCurve(A,w),D?(_.children.push(D),!0):!1};if(h.childCurve===u.childCurve)return I(h.childCurve,p,x,o)?Se.createCapture(_,n):void 0;I(this._path.children[g],p,1,o);for(let S=g+1;S<m;S++)I(this._path.children[S],0,1,o);return I(this._path.children[m],0,x,o),o&&_.children.reverse(),Se.createCapture(_,n)}isInPlane(e){for(const t of this._path.children)if(!t.isInPlane(e))return!1;return!0}startPoint(e){return this._path.cyclicCurvePrimitive(0)?.startPoint(e)??y.createZero(e)}endPoint(e){return this._path.cyclicCurvePrimitive(-1)?.endPoint(e)??y.createZero(e)}emitStrokes(e,t){for(const n of this._path.children)n.emitStrokes(e,t)}emitStrokableParts(e,t){for(const n of this._path.children)n.emitStrokableParts(e,t)}computeStrokeCountForOptions(e){let t=0;for(const n of this._path.children)t+=n.computeStrokeCountForOptions(e);return t}collectCurvePrimitivesGo(e,t=!1,n=!1){if(t)for(const i of this._path.children)i.collectCurvePrimitivesGo(e,t,n);else e.push(this)}computeAndAttachRecursiveStrokeCounts(e,t){const n=pn.createWithCurvePrimitiveAndOptionalParent(this,t);for(const i of this._path.children)i.computeAndAttachRecursiveStrokeCounts(e,n);le.installStrokeCountMap(this,n,t)}dispatchToGeometryHandler(e){return e.handleCurveChainWithDistanceIndex(this)}extendRange(e,t){this._path.extendRange(e,t)}curveLengthBetweenFractions(e,t){return Math.abs(t-e)*this._totalLength}static flattenNestedChains(e){if(e.children.findIndex(i=>i instanceof Se)===-1)return e;const t=e.clone(),n=t.children.flatMap(i=>i instanceof Se?i.path.children:i);return t.children.splice(0,1/0,...n),t}static createCapture(e,t){e=this.flattenNestedChains(e);const n=jr.createPathFragmentIndex(e,t);return new Se(e,n)}chainDistanceToFragment(e,t=!1){const n=this.chainDistanceToFragmentIndex(e,t);if(n!==void 0)return this._fragments[n]}chainDistanceToFragmentIndex(e,t=!1){const n=this._fragments,i=n.length;if(i>0){if(e<0)return t?0:void 0;if(e>this._totalLength)return t?i-1:void 0;for(let s=0;s<i;s++)if(n[s].containsChainDistance(e))return s}}chainDistanceToChainFraction(e){return e/this._totalLength}curveAndChildFractionToFragment(e,t){const n=this._fragments.length,i=this._fragments;if(n>0){if(t<0)return i[0];if(t>1)return i[n-1];for(const s of i)if(s.containsChildCurveAndChildFraction(e,t))return s}}curveLength(){return this._totalLength}quickLength(){return this._totalLength}fractionToPoint(e,t){const n=e*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(i){const s=i.chainDistanceToAccurateChildFraction(n,!0);return i.childCurve.fractionToPoint(s,t)}return y.createZero(t)}fractionToPointAndDerivative(e,t){t=q.createZero(t);const n=e*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return t;const s=i.chainDistanceToAccurateChildFraction(n,!0);t=i.childCurve.fractionToPointAndDerivative(s,t);const r=f.safeDivideFraction(this._totalLength,t.direction.magnitude(),0);return t.direction.scaleInPlace(r),t}fractionToPointAndUnitTangent(e,t){t=q.createZero(t);const n=e*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return t;const s=i.chainDistanceToAccurateChildFraction(n,!0);return t=i.childCurve.fractionToPointAndDerivative(s,t),t.direction.normalizeInPlace(),t}fractionToPointAnd2Derivatives(e,t){const n=e*this._totalLength,i=this.chainDistanceToFragment(n,!0);if(!i)return;const s=i.chainDistanceToAccurateChildFraction(n,!0);if(t=i.childCurve.fractionToPointAnd2Derivatives(s,t),!t)return;const r=t.vectorU.magnitude(),a=r*r,o=t.vectorU.dotProduct(t.vectorV),c=f.safeDivideFraction(-o,a,0);t.vectorV.addScaledInPlace(t.vectorU,c);const d=f.safeDivideFraction(this._totalLength,r,0);return t.vectorU.scaleInPlace(d),t.vectorV.scaleInPlace(d*d),t}tryTransformInPlace(e){return this._path.tryTransformInPlace(e)}reverseInPlace(){this._path.reverseChildrenInPlace();for(const e of this._fragments)e.reverseFractionsAndDistances(this._totalLength);this._fragments.reverse()}isAlmostEqual(e){return e instanceof Se?f.isSameCoordinate(this._totalLength,e._totalLength)&&this._path.isAlmostEqual(e._path):!1}moveSignedDistanceFromFraction(e,t,n,i){const r=e*this._totalLength+t,a=this.chainDistanceToFragment(r,!0);if(!a)return i=Y.create(void 0,i),i.curveSearchStatus=Yt.error,i;const o=a.childCurve.moveSignedDistanceFromFraction(a.childFraction0,r-a.chainDistance0,n,i?.childDetail),c=e+t/this._totalLength,d=Y.createConditionalMoveSignedDistance(n,this,e,c,t,i);return d.childDetail=o,d}static getClosestPointTestCounts(e=!0){const t={numCalls:this._numCalls,numTested:this._numTested,numAssigned:this._numAssigned,numCandidate:this._numCandidate};return e&&(this._numTested=this._numAssigned=this._numCandidate=0),t}computeClosestPoint(e,t=!1,n,i=!1){let s,r=Number.MAX_VALUE;if(this.path.children.length===1)s=i?this.path.children[0].closestPointXY(e,t):this.path.children[0].closestPoint(e,t);else{const o=qs.collectSortedQuickMinDistances(this._fragments,e),c=[Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,0),je.None],d=[je.None,Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,1)],h=this._fragments[0],u=this._fragments[this._fragments.length-1];Se._numCalls++,Se._numCandidate+=o.length;let g;for(const m of o){if(m.a>r)break;Se._numTested++;const p=m.childCurve;t=p===h.childCurve?c:p===u.childCurve?d:!1,g=i?p.closestPointXY(e,t,g):p.closestPoint(e,t,g),g&&g.a<r&&(r=g.a,s=g.clone(s),Se._numAssigned++)}}if(s)return this.computeChainDetail(s,n)}closestPoint(e,t=!1,n){return this.computeClosestPoint(e,t,n)}closestPointXY(e,t=!1,n){return this.computeClosestPoint(e,t,n,!0)}constructOffsetXY(e){const t=Kt.create(e),n=[];for(const i of this.collectCurvePrimitives(void 0,!0,!0)){const s=i.constructOffsetXY(t);s!==void 0&&(s instanceof le?n.push(s):Array.isArray(s)&&s.forEach(r=>n.push(r)))}return n}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}computeChainDetail(e,t){if(!e.curve)return;const n=this.curveAndChildFractionToFragment(e.curve,e.fraction);if(n){const i=n.childFractionToChainDistance(e.fraction),s=this.chainDistanceToChainFraction(i),r=Y.createCurveFractionPoint(this,s,e.point,t);return r.childDetail=e,r.a=e.a,r}}static convertChildDetailToChainDetailSingle(e,t,n){if(t){const i=t.computeChainDetail(e.detailA);i&&(e.detailA=i)}if(n){const i=n.computeChainDetail(e.detailB);i&&(e.detailB=i)}return e}static convertChildDetailToChainDetail(e,t,n,i,s){for(let r=t;r<e.length;++r)e[r]=this.convertChildDetailToChainDetailSingle(e[r],n,i);return s&&(e=Ze.removeAdjacentDuplicates(e,t)),e}}class oe extends mt{curveCollectionType="loop";isInner=!1;isSameGeometryClass(e){return e instanceof oe}constructor(){super()}static create(...e){const t=new oe;for(const n of e)n instanceof Se?t.children.push(...n.path.children):t.children.push(n);return t}static createArray(e){return this.create(...e)}static createPolygon(e){const t=N.create(e);return t.addClosurePoint(),oe.create(t)}cloneStroked(e){const t=N.create();for(const n of this.children)n.emitStrokes(t,e);return t.removeDuplicatePoints(),t.isPhysicallyClosed&&(t.popPoint(),t.addClosurePoint()),oe.create(t)}dgnBoundaryType(){return 2}announceToCurveProcessor(e,t=-1){return e.announceLoop(this,t)}cloneEmptyPeer(){const e=new oe;return e.isInner=this.isInner,e}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}dispatchToGeometryHandler(e){return e.handleLoop(this)}isAlmostEqual(e){return super.isAlmostEqual(e)?this.isInner===e.isInner:!1}}class uo{loopA;curveA;loopB;curveB;constructor(e,t,n,i){this.loopA=e,this.curveA=t,this.loopB=n,this.curveB=i}setA(e,t){this.loopA=e,this.curveA=t}setB(e,t){this.loopB=e,this.curveB=t}}class es{_vectorU;_vectorV;_point0;_point1;_tolerance;get tolerance(){return this._tolerance}constructor(e=f.smallMetricDistance){this._tolerance=e}static create(e=f.smallMetricDistance){return new es(e)}static assignDetailInterpolatedFractionsAndPoints(e,t,n,i,s,r=!1){r?(e.fraction=n,e.fraction1=t):(e.fraction=t,e.fraction1=n),e.point=i.interpolate(e.fraction,s,e.point),e.point1=i.interpolate(e.fraction1,s,e.point1)}projectPointToSegmentXY(e,t,n){this._vectorU=v.createStartEnd(t,n,this._vectorU),this._vectorV=v.createStartEnd(t,e,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,t.interpolate(r,n))}clampCoincidentOverlapToSegmentBounds(e,t,n,i,s,r=!1,a=!1,o=!1,c=!1){const d=Je.create(e.detailA.fraction,e.detailA.hasFraction1?e.detailA.fraction1:e.detailA.fraction),h=Je.create(e.detailB.fraction,e.detailB.hasFraction1?e.detailB.fraction1:e.detailB.fraction),u=d.signedDelta()<0,g=()=>{const S=d.x0,A=d.x1,w=h.x0,k=h.x1;return es.assignDetailInterpolatedFractionsAndPoints(e.detailA,S,A,t,n,S>A),es.assignDetailInterpolatedFractionsAndPoints(e.detailB,w,k,i,s,w>k),e},m=d.clampDirectedTo01(!r,!a,!1),p=h.clampDirectedTo01(!o,!c,!1);if(m&&p){if(f.isAlmostEqualNumber(d.absoluteDelta(),h.absoluteDelta(),f.smallFraction))return g();if(d.clampDirectedTo01(!0,!0,!1)&&h.clampDirectedTo01(!0,!0,!1))return g()}const x=(S,A,w,k)=>(S.clone(e.detailA.point),A.clone(e.detailB.point),e.detailA.fraction=w?0:1,e.detailB.fraction=k?0:1,e.detailA.collapseToStart(),e.detailB.collapseToStart(),e),_=d.clampDirectedTo01(!0,!0,!0),I=h.clampDirectedTo01(!0,!0,!0);if(_&&I){const S=e.detailA.point1??e.detailA.point;if(u){if(e.detailA.point.isAlmostEqual(t,this.tolerance))return x(t,i,!0,!0);if(S.isAlmostEqual(n,this.tolerance))return x(n,s,!1,!1)}else{if(S.isAlmostEqual(t,this.tolerance))return x(t,s,!0,!1);if(e.detailA.point.isAlmostEqual(n,this.tolerance))return x(n,i,!1,!0)}}}coincidentSegmentRangeXY(e,t,n,i){const s={x:t.x-e.x,y:t.y-e.y},r={x:i.x-n.x,y:i.y-n.y},a=Le.lineSegmentXYUVOverlapUnbounded(e,s,n,r,this._tolerance);if(!a||!a.f1)return;const o=Y.createCurveFractionPoint(void 0,a.f0.x,e.interpolate(a.f0.x,t));o.captureFraction1Point1(a.f1.x,e.interpolate(a.f1.x,t));const c=Y.createCurveFractionPoint(void 0,a.f0.y,n.interpolate(a.f0.y,i));return c.captureFraction1Point1(a.f1.y,n.interpolate(a.f1.y,i)),Ze.createCapture(o,c)}createDetailPair(e,t,n,i,s,r){const a=s-i,o=f.conditionalDivideFraction(n.x0-i,a),c=f.conditionalDivideFraction(n.x1-i,a);if(o!==void 0&&c!==void 0){const d=Y.createCurveEvaluatedFractionFraction(e,n.x0,n.x1),h=Y.createCurveEvaluatedFractionFraction(t,o,c);return r&&d.swapFractionsAndPoints(),Ze.createCapture(d,h)}}appendDetailPair(e,t){return t===void 0?e:e===void 0?[t]:(e.push(t),e)}coincidentArcIntersectionXY(e,t,n=!0){let i;if(e.center.isAlmostEqual(t.center,this.tolerance)){const s=e.matrixRef.multiplyMatrixInverseMatrix(t.matrixRef);if(s){const r=s.at(0,0),a=s.at(1,0),o=s.at(0,1),c=s.at(1,1),d=f.hypotenuseXY(r,a),h=f.hypotenuseXY(o,c),u=f.dotProductXYXY(r,a,o,c),g=f.crossProductXYXY(r,a,o,c);if(f.isAlmostEqualNumber(d,1)&&f.isAlmostEqualNumber(h,1)&&f.isAlmostEqualNumber(0,u)){const m=Math.atan2(a,r),p=g>0?1:-1,x=m+p*t.sweep.startRadians,_=m+p*t.sweep.endRadians,I=p*e.sweep.sweepRadians*t.sweep.sweepRadians<0,S=me.createStartEndRadians(x,_),A=e.sweep,w=A.fractionPeriod(),k=A.radiansToPositivePeriodicFraction(S.startRadians),D=S.sweepRadians/A.sweepRadians,P=k+D,b=Je.create(k,P),C=(M,G)=>{const ae=i?i.length:0,ye=M.x0,F=M.x1;if(M.clampDirectedTo01()&&!f.isSmallRelative(M.absoluteDelta()))i=this.appendDetailPair(i,this.createDetailPair(e,t,M,ye,F,I));else{const R=I?G:!G,V=this._point0=G?e.startPoint(this._point0):e.endPoint(this._point0),ne=this._point1=R?t.startPoint(this._point1):t.endPoint(this._point1);if(V.isAlmostEqual(ne,this.tolerance)){const Xe=Y.createCurveFractionPoint(e,G?0:1,V),dt=Y.createCurveFractionPoint(t,R?0:1,ne);i=this.appendDetailPair(i,Ze.createCapture(Xe,dt))}}return i!==void 0&&i.length>ae};C(b,!1),P>=w?C(Je.create(k-w,P-w),!0):k===0&&C(Je.create(k+w,P+w),!0)}}}return i}}class De extends le{_spiralType;_designProperties;_localToWorld;_activeFractionInterval;get activeFractionInterval(){return this._activeFractionInterval}get localToWorld(){return this._localToWorld}constructor(e,t,n,i){super(),this._spiralType=e||"unknownSpiralType",this._designProperties=i,this._localToWorld=t,this._activeFractionInterval=n||Je.create(0,1)}get spiralType(){return this._spiralType}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){return!1}static radiusToCurvature(e){return e===0?0:1/e}static curvatureToRadius(e){return Math.abs(e)<f.smallAngleRadians?0:1/e}clonePartialCurve(e,t){const n=this.clone(),i=this._activeFractionInterval.fractionToPoint(e),s=this._activeFractionInterval.fractionToPoint(t);return n._activeFractionInterval.set(i,s),n.refreshComputedProperties(),n}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}static averageCurvature(e){return .5*(De.radiusToCurvature(e.x0)+De.radiusToCurvature(e.x1))}static averageCurvatureR0R1(e,t){return .5*(De.radiusToCurvature(e)+De.radiusToCurvature(t))}static interpolateCurvatureR0R1(e,t,n){return f.interpolate(De.radiusToCurvature(e),t,De.radiusToCurvature(n))}static radiusRadiusSweepRadiansToArcLength(e,t,n){return Math.abs(n/De.averageCurvatureR0R1(e,t))}static radiusRadiusLengthToSweepRadians(e,t,n){return De.averageCurvatureR0R1(e,t)*n}static radius0LengthSweepRadiansToRadius1(e,t,n){return De.curvatureToRadius(2*n/t-De.radiusToCurvature(e))}static radius1LengthSweepRadiansToRadius0(e,t,n){return De.curvatureToRadius(2*n/t-De.radiusToCurvature(e))}get designProperties(){return this._designProperties}applyRigidPartOfTransform(e){const t=e.matrix.factorRigidWithSignedScale();if(t!==void 0){const n=e.multiplyTransformTransform(this.localToWorld),i=t.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);return this._localToWorld=X.createOriginAndMatrix(n.origin,i),this.designProperties&&this.designProperties.applyScaleFactor(t.scale),t}}constructOffsetXY(e){const t=Kt.create(e),n=new Vs(this,t.leftOffsetDistance);return this.emitStrokableParts(n,t.strokeOptions),n.claimResult()}extendRange(e,t){e.extendRange(this.rangeBetweenFractions(0,1,t))}rangeBetweenFractions(e,t,n){const i=this.activeStrokes;if(i===void 0)return ie.createNull();let s=Math.ceil(i.numPoints()*Math.abs(t-e));return s=f.clamp(5,s,30),this.rangeBetweenFractionsByCount(e,t,s,n,.5)}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}}class Ve extends $i{_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(e,t,n,i,s=f.smallMetricDistance){super(),this._extendA0=t,this._extendA1=t,this._geometryB=n instanceof qr?n.proxyCurve:n,this._extendB0=i,this._extendB1=i,this._worldToLocalPerspective=void 0,this._worldToLocalAffine=void 0,e!==void 0&&!e.isIdentity()&&(this._worldToLocalAffine=e.asTransform,this._worldToLocalAffine||(this._worldToLocalPerspective=e.clone())),this._coincidentGeometryContext=es.create(s),this._results=[]}resetGeometryA(e,t){e!==void 0&&(this._extendA0=e),t!==void 0&&(this._extendA1=t)}resetGeometryB(e,t,n){e&&(this._geometryB=e),t!==void 0&&(this._extendB0=t),n!==void 0&&(this._extendB1=n)}acceptFraction(e,t,n,i=1e-12){return!(!e&&t<-i||!n&&t>1+i)}acceptFractionOnLine(e,t,n,i,s){if(!e&&t<0)return f.isDistanceWithinTol(t*t*i.distanceSquaredXY(s),this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance);if(!n&&t>1){const r=t-1;return f.isDistanceWithinTol(r*r*i.distanceSquaredXY(s),this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance)}return!0}grabPairedResults(e=!1){const t=this._results;return e&&(this._results=[]),t}recordPointWithLocalFractions(e,t,n,i,s,r,a,o,c,d,h){let u,g,m,p,x=!1;d&&d.detailA.isInterval()&&d.detailB.isInterval()?(x=!0,u=f.interpolate(n,d.detailA.fraction,i),g=f.interpolate(a,d.detailB.fraction,o),m=f.interpolate(n,d.detailA.fraction1,i),p=f.interpolate(a,d.detailB.fraction1,o)):(u=m=f.interpolate(n,e,i),g=p=f.interpolate(a,s,o));const _=this._results.length;if(_>0&&!x){const A=this._results[_-1].detailA,w=this._results[_-1].detailB;if(c){if(w.isSameCurveAndFraction({curve:t,fraction:u},h)&&A.isSameCurveAndFraction({curve:r,fraction:g},h))return}else if(A.isSameCurveAndFraction({curve:t,fraction:u},h)&&w.isSameCurveAndFraction({curve:r,fraction:g},h))return}const I=Y.createCurveFractionPoint(t,u,t.fractionToPoint(u)),S=Y.createCurveFractionPoint(r,g,r.fractionToPoint(g));x?(I.captureFraction1Point1(m,t.fractionToPoint(m)),S.captureFraction1Point1(p,r.fractionToPoint(p))):(I.setIntervalRole(Fe.isolated),S.setIntervalRole(Fe.isolated)),c?this._results.push(new Ze(S,I)):this._results.push(new Ze(I,S))}recordPairs(e,t,n,i){if(n!==void 0)for(const s of n)this.recordPointWithLocalFractions(s.detailA.fraction,e,0,1,s.detailB.fraction,t,0,1,i,s)}computeSegmentSegment3D(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p){const x={x:s.x-n.x,y:s.y-n.y},_={x:u.x-d.x,y:u.y-d.y},I=Le.lineSegmentXYUVIntersectionUnbounded(n,x,d,_,this._coincidentGeometryContext.tolerance);if(I)if(I.f1){const S=Y.createCurveFractionPoint(void 0,I.f0.x,n.interpolate(I.f0.x,s));S.captureFraction1Point1(I.f1.x,n.interpolate(I.f1.x,s));const A=Y.createCurveFractionPoint(void 0,I.f0.y,d.interpolate(I.f0.y,u));A.captureFraction1Point1(I.f1.y,d.interpolate(I.f1.y,u));const w=Ze.createCapture(S,A);this._coincidentGeometryContext.clampCoincidentOverlapToSegmentBounds(w,n,s,d,u,t,a,c,m)&&this.recordPointWithLocalFractions(w.detailA.fraction,e,i,r,w.detailB.fraction,o,h,g,p,w)}else this.acceptFractionOnLine(t,I.f0.x,a,n,s)&&this.acceptFractionOnLine(c,I.f0.y,m,d,u)&&this.recordPointWithLocalFractions(I.f0.x,e,i,r,I.f0.y,o,h,g,p)}computeSegmentSegment3DH(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p){if(this._worldToLocalPerspective===void 0)return;const x=Ve._workPointA0H,_=Ve._workPointA1H,I=Ve._workPointB0H,S=Ve._workPointB1H;this._worldToLocalPerspective.multiplyPoint3d(n,1,x),this._worldToLocalPerspective.multiplyPoint3d(s,1,_),this._worldToLocalPerspective.multiplyPoint3d(d,1,I),this._worldToLocalPerspective.multiplyPoint3d(u,1,S);const A=Le.lineSegment3dHXYTransverseIntersectionUnbounded(x,_,I,S);if(A!==void 0){const w=A.x,k=A.y;this.acceptFraction(t,w,a)&&this.acceptFraction(c,k,m)&&this.recordPointWithLocalFractions(w,e,i,r,k,o,h,g,p)}}dispatchSegmentSegment(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p){this._worldToLocalAffine?(Ve.setTransformedWorkPoints(this._worldToLocalAffine,n,s,d,u),this.computeSegmentSegment3D(e,t,Ve._workPointA0,i,Ve._workPointA1,r,a,o,c,Ve._workPointB0,h,Ve._workPointB1,g,m,p)):this._worldToLocalPerspective?this.computeSegmentSegment3DH(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p):this.computeSegmentSegment3D(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p)}computeSegmentArc(e,t,n,i,s,r,a,o,c,d,h){const u=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance,g=new Me(2),m=new Me(2),p=new Me(2),x=(G,ae,ye)=>f.isDistanceWithinTol(ye,u)?(this.recordPointWithLocalFractions(G,e,i,r,ae,o,0,1,h),!0):!1,_=o.toTransformedVectors(this._worldToLocalAffine);let I=n,S=s;const A=o.startPoint(),w=o.endPoint();this._worldToLocalAffine&&(I=this._worldToLocalAffine.multiplyPoint3d(n),S=this._worldToLocalAffine.multiplyPoint3d(s),this._worldToLocalAffine.multiplyXYAndZInPlace(A),this._worldToLocalAffine.multiplyXYAndZInPlace(w));const k=f.tripleProductXYW(I,1,S,1,_.center,1),D=f.tripleProductXYW(I,1,S,1,_.vector0,0),P=f.tripleProductXYW(I,1,S,1,_.vector90,0);let b=Bn.appendImplicitLineUnitCircleIntersections(k,D,P,g,m,p,u);const C=b===0;C&&(b=1);const M=[];for(let G=0;G<b;G++){const ae=_.center.plus2Scaled(_.vector0,g.atUncheckedIndex(G),_.vector90,m.atUncheckedIndex(G)),ye=_.sweep.radiansToSignedFraction(p.atUncheckedIndex(G),c),F=_.sweep.fractionToSignedPeriodicFraction(ye,void 0),R=Le.lineSegment3dXYClosestPointUnbounded(I,S,ae);if(R!==void 0){const V=I.interpolate(R,S);M.push({fArc:ye,fArcNearest01:F,fLine:R,arcPt:ae,linePt:V})}}for(const G of M){const{fArc:ae,fArcNearest01:ye,fLine:F,arcPt:R,linePt:V}=G;if(C&&!f.isDistanceWithinTol(R.distanceSquaredXY(V),u))continue;if(this.acceptFraction(t,F,a)&&this.acceptFraction(c,ae,d)){this.recordPointWithLocalFractions(F,e,i,r,ae,o,0,1,h);continue}const ne=c||d||f.isIn01(ae),Xe=t&&F<0||a&&F>1||f.isIn01(F);let dt=!1;ne&&!Xe?dt=x(F<0?0:1,ae,(F<0?I:S).distanceSquaredXY(R)):!ne&&Xe&&(dt=x(F,ye<0?0:1,V.distanceSquaredXY(ye<0?A:w))),dt||x(F<.5?0:1,ye<.5?0:1,(F<.5?I:S).distanceSquaredXY(ye<.5?A:w))}}computeSegmentArcHomogeneous(e,t,n,i,s,r,a,o,c,d,h){if(!this._worldToLocalPerspective)return;const u=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance,g=new Me(2),m=new Me(2),p=new Me(2),x=(G,ae,ye)=>ye===void 0||!f.isDistanceWithinTol(ye,u)?!1:(this.recordPointWithLocalFractions(G,e,i,r,ae,o,0,1,h),!0),_=o.toTransformedPoint4d(this._worldToLocalPerspective),I=this._worldToLocalPerspective.multiplyPoint3d(n,1),S=this._worldToLocalPerspective.multiplyPoint3d(s,1),A=this._worldToLocalPerspective.multiplyPoint3d(o.startPoint(),1),w=this._worldToLocalPerspective.multiplyPoint3d(o.endPoint(),1),k=f.tripleProductPoint4dXYW(I,S,_.center),D=f.tripleProductPoint4dXYW(I,S,_.vector0),P=f.tripleProductPoint4dXYW(I,S,_.vector90);let b=Bn.appendImplicitLineUnitCircleIntersections(k,D,P,g,m,p,u);const C=b===0;C&&(b=1);const M=[];for(let G=0;G<b;G++){const ae=_.center.plus2Scaled(_.vector0,g.atUncheckedIndex(G),_.vector90,m.atUncheckedIndex(G)),ye=_.sweep.radiansToSignedFraction(p.atUncheckedIndex(G),c),F=_.sweep.fractionToSignedPeriodicFraction(ye,void 0),R=Le.lineSegment3dHXYClosestPointUnbounded(I,S,ae);if(R!==void 0){const V=I.interpolate(R,S);M.push({fArc:ye,fArcNearest01:F,fLine:R,arcPt:ae,linePt:V})}}for(const G of M){const{fArc:ae,fArcNearest01:ye,fLine:F,arcPt:R,linePt:V}=G;if(C){const Gt=R.realDistanceSquaredXY(V);if(Gt===void 0||!f.isDistanceWithinTol(Gt,u))continue}if(this.acceptFraction(t,F,a)&&this.acceptFraction(c,ae,d)){this.recordPointWithLocalFractions(F,e,i,r,ae,o,0,1,h);continue}const ne=c||d||f.isIn01(ae),Xe=t&&F<0||a&&F>1||f.isIn01(F);let dt=!1;ne&&!Xe?dt=x(F<0?0:1,ae,(F<0?I:S).realDistanceSquaredXY(R)):!ne&&Xe&&(dt=x(F,ye<0?0:1,V.realDistanceSquaredXY(ye<0?A:w))),dt||x(F<.5?0:1,ye<.5?0:1,(F<.5?I:S).realDistanceSquaredXY(ye<.5?A:w))}}dispatchSegmentArc(e,t,n,i,s,r,a,o,c,d,h){this._worldToLocalPerspective?this.computeSegmentArcHomogeneous(e,t,n,i,s,r,a,o,c,d,h):this.computeSegmentArc(e,t,n,i,s,r,a,o,c,d,h)}dispatchArcArcThisOrder(e,t,n,i,s,r,a,o,c){const d=t.inverse();if(d){const h=d.multiplyMatrixMatrix(r),u=[],g=[];Oi.solveUnitCircleHomogeneousEllipseIntersection(h.coffs[2],h.coffs[5],h.coffs[8],h.coffs[0],h.coffs[3],h.coffs[6],h.coffs[1],h.coffs[4],h.coffs[7],u,g);const m=this._coincidentGeometryContext.tolerance*this._coincidentGeometryContext.tolerance;for(let p=0;p<u.length;p++){let x=e.sweep.radiansToSignedFraction(g[p],n),_=s.sweep.radiansToSignedFraction(u[p],a);if(this.acceptFraction(n,x,i)&&this.acceptFraction(a,_,o))this.recordPointWithLocalFractions(x,e,0,1,_,s,0,1,c);else{x=e.sweep.fractionToSignedPeriodicFraction(x)<.5?0:1,_=s.sweep.fractionToSignedPeriodicFraction(_)<.5?0:1;const I=e.fractionToPoint(x,Ve._workPointAA0),S=s.fractionToPoint(_,Ve._workPointBB0),A=I.distanceSquaredXY(S);f.isDistanceWithinTol(A,m)&&this.recordPointWithLocalFractions(x,e,0,1,_,s,0,1,c)}}}}dispatchArcArc(e,t,n,i,s,r,a){if(this._coincidentGeometryContext&&!this._worldToLocalPerspective&&!this._worldToLocalAffine){const u=this._coincidentGeometryContext.coincidentArcIntersectionXY(e,i,!0);if(u){this.recordPairs(e,i,u,a);return}}let o,c;if(this._worldToLocalPerspective){const u=e.toTransformedPoint4d(this._worldToLocalPerspective),g=i.toTransformedPoint4d(this._worldToLocalPerspective);o=E.createColumnsXYW(u.vector0,u.vector0.w,u.vector90,u.vector90.w,u.center,u.center.w),c=E.createColumnsXYW(g.vector0,g.vector0.w,g.vector90,u.vector90.w,g.center,g.center.w)}else{const u=e.toTransformedVectors(this._worldToLocalAffine),g=i.toTransformedVectors(this._worldToLocalAffine);o=E.createColumnsXYW(u.vector0,0,u.vector90,0,u.center,1),c=E.createColumnsXYW(g.vector0,0,g.vector90,0,g.center,1)}const d=o.conditionNumber(),h=c.conditionNumber();d>h?this.dispatchArcArcThisOrder(e,o,t,n,i,c,s,r,a):this.dispatchArcArcThisOrder(i,c,s,r,e,o,t,n,!a)}dispatchArcBsplineCurve3d(e,t,n,i,s,r,a){let o;if(this._worldToLocalPerspective){const d=e.toTransformedPoint4d(this._worldToLocalPerspective);o=E.createColumnsXYW(d.vector0,d.vector0.w,d.vector90,d.vector90.w,d.center,d.center.w)}else{const d=e.toTransformedVectors(this._worldToLocalAffine);o=E.createColumnsXYW(d.vector0,0,d.vector90,0,d.center,1)}const c=o.inverse();if(c){const d=i.order,h=2*d-1,u=new Float64Array(d),g=new it(h),m=c.at(0,0),p=c.at(0,1),x=0,_=c.at(0,2),I=c.at(1,0),S=c.at(1,1),A=0,w=c.at(1,2),k=c.at(2,0),D=c.at(2,1),P=0,b=c.at(2,2);let C;for(let M=0;C=i.getSaturatedBezierSpan3dH(M,C),!!C;M++){this._worldToLocalPerspective?C.tryMultiplyMatrix4dInPlace(this._worldToLocalPerspective):this._worldToLocalAffine&&C.tryTransformInPlace(this._worldToLocalAffine),g.zero(),C.poleProductsXYZW(u,m,p,x,_),g.addSquaredSquaredBezier(u,1),C.poleProductsXYZW(u,I,S,A,w),g.addSquaredSquaredBezier(u,1),C.poleProductsXYZW(u,k,D,P,b),g.addSquaredSquaredBezier(u,-1);const G=g.roots(0,!0);if(G)for(const ae of G){const ye=C.fractionToParentFraction(ae),F=C.fractionToPoint4d(ae),R=F.dotProductXYZW(m,p,x,_),V=F.dotProductXYZW(I,S,A,w),ne=e.sweep.radiansToSignedFraction(Math.atan2(V,R),t);this.acceptFraction(t,ne,n)&&this.acceptFraction(s,ye,r)&&this.recordPointWithLocalFractions(ne,e,0,1,ye,i,0,1,a)}}}}transformBeziers(e){if(this._worldToLocalAffine)for(const t of e)t.tryTransformInPlace(this._worldToLocalAffine);else if(this._worldToLocalPerspective)for(const t of e)t.tryMultiplyMatrix4dInPlace(this._worldToLocalPerspective)}getRanges(e){const t=[];t.length=0;for(const n of e)t.push(n.range());return t}dispatchBezierBezierStrokeFirst(e,t,n,i,s,r,a,o){this._xyzwA0||(this._xyzwA0=Z.create()),this._xyzwA1||(this._xyzwA1=Z.create()),this._xyzwPlane||(this._xyzwPlane=Z.create()),this._xyzwB||(this._xyzwB=Z.create()),e.fractionToPoint4d(0,this._xyzwA0);let c=0,d;const h=1e-5,u=1/n;for(let g=1;g<=n;g++,c=d,this._xyzwA0.setFrom(this._xyzwA1)){d=g*u,e.fractionToPoint4d(d,this._xyzwA1),Z.createPlanePointPointZ(this._xyzwA0,this._xyzwA1,this._xyzwPlane),i.poleProductsXYZW(a.coffs,this._xyzwPlane.x,this._xyzwPlane.y,this._xyzwPlane.z,this._xyzwPlane.w);const m=a.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=Le.lineSegment3dHXYClosestPointUnbounded(this._xyzwA0,this._xyzwA1,this._xyzwB);if(I!==void 0&&f.isIn01WithTolerance(I,h)){let S=f.interpolate(c,I,d);const A=new to(e,i),w=new Xs(A);w.setUV(S,_);let k=w.runIterations();S=w.getU(),_=w.getV();const D=e.fractionToParentFraction(S),P=i.fractionToParentFraction(_);if(this.acceptFraction(!1,D,!1)&&this.acceptFraction(!1,P,!1)){const b=e.fractionToPoint(S,Ve._workPointA0),C=i.fractionToPoint(_,Ve._workPointB0);k||(k=b.isAlmostEqualXY(C,p)),k&&this.recordPointWithLocalFractions(D,t,0,1,P,s,0,1,o)}}}}}}dispatchBSplineCurve3dBSplineCurve3d(e,t,n){const i=e.collectBezierSpans(!0),s=t.collectBezierSpans(!0),r=i.length,a=s.length;this.transformBeziers(i),this.transformBeziers(s);const o=this.getRanges(i),c=this.getRanges(s),d=e.order,h=t.order,u=new it(d),g=new it(h);for(let m=0;m<r;m++)for(let p=0;p<a;p++)if(o[m].intersectsRangeXY(c[p])){const x=i[m].computeStrokeCountForOptions(),_=s[p].computeStrokeCountForOptions();x<_?this.dispatchBezierBezierStrokeFirst(i[m],e,x,s[p],t,_,g,n):this.dispatchBezierBezierStrokeFirst(s[p],t,_,i[m],e,x,u,!n)}}projectPoint(e,t=1){return this._worldToLocalPerspective?this._worldToLocalPerspective.multiplyPoint3d(e,t):this._worldToLocalAffine?this._worldToLocalAffine.multiplyXYZW(e.x,e.y,e.z,t):Z.createFromPointAndWeight(e,t)}mapNPCPlaneToWorld(e,t){this._worldToLocalAffine?this._worldToLocalAffine.multiplyTransposeXYZW(e.x,e.y,e.z,e.w,t):this._worldToLocalPerspective?this._worldToLocalPerspective.multiplyTransposePoint4d(e,t):e.clone(t)}dispatchSegmentBsplineCurve(e,t,n,i,s,r,a,o,c,d,h){const u=this.projectPoint(n),g=this.projectPoint(s),m=Z.createPlanePointPointZ(u,g);this.mapNPCPlaneToWorld(m,m);const p=[];o.appendPlaneIntersectionPoints(m,p);for(const x of p){const _=x.fraction,I=x.point,S=this.projectPoint(I),A=Le.lineSegment3dHXYClosestPointUnbounded(u,g,S);A!==void 0&&this.acceptFraction(t,A,a)&&this.acceptFraction(c,_,d)&&this.recordPointWithLocalFractions(A,e,i,r,_,o,0,1,h)}}dispatchLineStringBSplineCurve(e,t,n,i,s,r,a){const o=e.numPoints();if(o>1){const c=1/(o-1);let d,h;d=0;const u=Ve._workPointA0,g=Ve._workPointA1;e.pointAt(0,u);for(let m=1;m<o;m++,u.setFrom(g),d=h)e.pointAt(m,g),h=m*c,this.dispatchSegmentBsplineCurve(e,m===1&&t,u,d,g,h,m+1===o&&n,i,s,r,a)}}computeSegmentLineString(e,t,n,i,s,r,a){const o=e.point0Ref,c=e.point1Ref,d=Ve._workPointBB0,h=Ve._workPointBB1,u=i.numPoints();if(u>1){const g=1/(u-1);let m,p;m=0,i.pointAt(0,d);for(let x=1;x<u;x++,d.setFrom(h),m=p)i.pointAt(x,h),p=x*g,this.dispatchSegmentSegment(e,t,o,0,c,1,n,i,x===1&&s,d,m,h,p,x+1===u&&r,a)}}computeArcLineString(e,t,n,i,s,r,a){const o=Ve._workPointBB0,c=Ve._workPointBB1,d=i.numPoints();if(d>1){const h=1/(d-1);let u,g;u=0,i.pointAt(0,o);for(let m=1;m<d;m++,o.setFrom(c),u=g)i.pointAt(m,c),g=m*h,this.dispatchSegmentArc(i,m===1&&s,o,u,c,g,m+1===d&&r,e,t,n,!a)}}computeLineStringLineString(e,t,n,i,s,r,a){const o=Ve._workPointAA0,c=Ve._workPointAA1,d=Ve._workPointBB0,h=Ve._workPointBB1,u=e.numPoints(),g=i.numPoints();if(u>1&&g>1){e.pointAt(0,o);const m=1/(u-1),p=1/(g-1);let x=0,_,I,S;e.pointAt(0,o);for(let A=1;A<u;A++,o.setFrom(c),x=I){I=A*m,_=0,e.pointAt(A,c),i.pointAt(0,d);for(let w=1;w<g;w++,d.setFrom(h),_=S)i.pointAt(w,h),S=w*p,this.dispatchSegmentSegment(e,A===1&&t,o,x,c,I,A+1===u&&n,i,w===1&&s,d,_,h,S,w+1===g&&r,a)}}}static setTransformedWorkPoints(e,t,n,i,s){e.multiplyPoint3d(t,this._workPointA0),e.multiplyPoint3d(n,this._workPointA1),e.multiplyPoint3d(i,this._workPointB0),e.multiplyPoint3d(s,this._workPointB1)}dispatchCurveCollection(e,t){const n=this._geometryB;if(!n||!n.children||!(n instanceof _e))return;const i=n.children,s=this._extendB0,r=this._extendB1;for(let a=0;a<i.length;a++){let o=s,c=r;n instanceof Te&&i.length>1?a===0?c=!1:a===i.length-1?o=!1:o=c=!1:n instanceof oe&&(o=c=!1),this.resetGeometryB(i[a],o,c),t(e)}this.resetGeometryB(n,s,r)}dispatchCurveChainWithDistanceIndex(e,t){if(!this._geometryB||!(this._geometryB instanceof Se))return;const n=this._results.length,i=this._geometryB;this.resetGeometryB(i.path),this.dispatchCurveCollection(e,t),this.resetGeometryB(i),this._results=Se.convertChildDetailToChainDetail(this._results,n,void 0,i,!0)}refineSpiralResultsByNewton(e,t,n,i=!1){if(n>=this._results.length)return;const s=new to(e,t),r=50,a=new Xs(s,r),o=2*a.stepSizeTolerance,c=Ze.comparePairsByFractions(o,this._coincidentGeometryContext.tolerance,!0),d=new pi(c,Xn.Retain),h=(g,m,p,x,_,I)=>{const S=Y.createCurveFractionPoint(g,m,p),A=Y.createCurveFractionPoint(x,_,I);S.setIntervalRole(Fe.isolated),A.setIntervalRole(Fe.isolated),d.insert(new Ze(i?A:S,i?S:A))},u=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 N;const _=i?this._extendB0:this._extendA0,I=i?this._extendB1:this._extendA1;a.setUV(p.fraction,x.fraction);let S=a.runIterations();const A=a.getU(),w=a.getV();if(this.acceptFraction(_,A,I)&&this.acceptFraction(!1,w,!1,f.smallFraction)){const k=e.fractionToPoint(A,Ve._workPointA0),D=t.fractionToPoint(w,Ve._workPointB0);S||(S=k.isAlmostEqualXY(D,u)),S&&h(e,A,k,t,w,D)}}this._results.splice(n,this._results.length-n,...d.extractArray())}strokeCurve(e,t,n){const i=n||N.create();return e.emitStrokes(i,t),i}computeMaxSpiralStrokeError(e,t,n,i){let s=0;if(t.numEdges()>0){const r=e.fractionToCurvature(0),a=e.fractionToCurvature(1),o=r!==void 0&&a!==void 0&&Math.abs(r)>Math.abs(a)?0:t.numEdges()-1,c=y.create(),d=Y.create();if(t.packedPoints.interpolateIndexIndex(o,.5,o+1,c)&&e.closestPoint(c,!1,d)&&(s=d.a),n&&n instanceof De&&i&&i instanceof N){const h=this.computeMaxSpiralStrokeError(n,i);h>s&&(s=h)}}return s}appendDiscreteIntersectionResults(e,t,n,i,s){const r=this._results.length,a=this._geometryB,o=this._extendB0,c=this._extendB1;if(this.resetGeometryA(!1,!1),this.resetGeometryB(e,t,n),this.handleLineString3d(i),!s)for(let d=r;d<this._results.length;d++)this._results[d].swapDetails();return this.resetGeometryA(t,n),this.resetGeometryB(a,o,c),this._results.length-r}appendDiscreteCloseApproachResults(e,t,n,i){const s=this._results.length,r=sn.closeApproachProjectedXYPairs(i?t:e,i?e:t,n);return r.sort((a,o)=>a.detailA.a-o.detailA.a),this._results.push(...r),this._results.length-s}dispatchCurveSpiral(e,t,n,i,s){let r=e;e instanceof De&&(r=this.strokeCurve(e),t=n=!1);const a=this.strokeCurve(i),o=1.01*this.computeMaxSpiralStrokeError(i,a,e,r),c=this._results.length;this.appendDiscreteIntersectionResults(r,t,n,a,s),this.appendDiscreteCloseApproachResults(r,a,o,s),this.refineSpiralResultsByNewton(e,i,c,s)}handleChildren(e){const t=e.children;if(!t)return;const n=this._extendA0,i=this._extendA1;for(let s=0;s<t.length;s++){let r=n,a=i;e instanceof Te&&t.length>1?s===0?a=!1:s===t.length-1?r=!1:r=a=!1:e instanceof oe&&(r=a=!1),this.resetGeometryA(r,a),t[s].dispatchToGeometryHandler(this)}this.resetGeometryA(n,i)}handleLineSegment3d(e){if(this._geometryB instanceof Q){const t=this._geometryB;this.dispatchSegmentSegment(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,t,this._extendB0,t.point0Ref,0,t.point1Ref,1,this._extendB1,!1)}else this._geometryB instanceof N?this.computeSegmentLineString(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof B?this.dispatchSegmentArc(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof It?this.dispatchSegmentBsplineCurve(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof De?this.dispatchCurveSpiral(e,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineSegment3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineSegment3d.bind(this))}handleLineString3d(e){if(this._geometryB instanceof N){const t=this._geometryB;this.computeLineStringLineString(e,this._extendA0,this._extendA1,t,this._extendB0,this._extendB1,!1)}else this._geometryB instanceof Q?this.computeSegmentLineString(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof B?this.computeArcLineString(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof It?this.dispatchLineStringBSplineCurve(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof De?this.dispatchCurveSpiral(e,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineString3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineString3d.bind(this))}handleArc3d(e){this._geometryB instanceof Q?this.dispatchSegmentArc(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.computeArcLineString(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof B?this.dispatchArcArc(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof It?this.dispatchArcBsplineCurve3d(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof De?this.dispatchCurveSpiral(e,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleArc3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleArc3d.bind(this))}handleBSplineCurve3d(e){this._geometryB instanceof Q?this.dispatchSegmentBsplineCurve(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.dispatchLineStringBSplineCurve(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof B?this.dispatchArcBsplineCurve3d(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof Bs?this.dispatchBSplineCurve3dBSplineCurve3d(e,this._geometryB,!1):this._geometryB instanceof De?this.dispatchCurveSpiral(e,this._extendA0,this._extendA1,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleBSplineCurve3d.bind(this))}handleTransitionSpiral(e){this._geometryB instanceof Se?this.dispatchCurveChainWithDistanceIndex(e,this.handleTransitionSpiral.bind(this)):this._geometryB instanceof le?this.dispatchCurveSpiral(this._geometryB,this._extendB0,this._extendB1,e,!0):this._geometryB instanceof _e&&this.dispatchCurveCollection(e,this.handleTransitionSpiral.bind(this))}handleCurveChainWithDistanceIndex(e){super.handleCurveChainWithDistanceIndex(e),this._results=Se.convertChildDetailToChainDetail(this._results,0,e,void 0,!0)}handleBSplineCurve3dH(e){}}class xn extends $i{_extendA0;_extendA1;_geometryB;_extendB0;_extendB1;_results;static _workVector2dA=$.create();static _workPointAA0=y.create();static _workPointAA1=y.create();static _workPointBB0=y.create();static _workPointBB1=y.create();constructor(e,t,n){super(),this._extendA0=e,this._extendA1=e,this._geometryB=t,this._extendB0=n,this._extendB1=n,this._results=[]}resetGeometry(e){this._geometryB=e}grabPairedResults(e=!1){const t=this._results;return e&&(this._results=[]),t}acceptFraction(e,t,n,i=1e-12){return!(!e&&t<-i||!n&&t>1+i)}recordPointWithLocalFractions(e,t,n,i,s,r,a,o,c){const d=f.interpolate(n,e,i),h=f.interpolate(a,s,o),u=this._results.length;if(u>0){const _=this._results[u-1].detailA,I=this._results[u-1].detailB;if(c){if(I.isSameCurveAndFraction({curve:t,fraction:d})&&_.isSameCurveAndFraction({curve:r,fraction:h}))return}else if(_.isSameCurveAndFraction({curve:t,fraction:d})&&I.isSameCurveAndFraction({curve:r,fraction:h}))return}const g=t.fractionToPoint(d),m=r.fractionToPoint(h);if(!g.isAlmostEqualMetric(m))return;const p=Y.createCurveFractionPoint(t,d,g);p.setIntervalRole(Fe.isolated);const x=Y.createCurveFractionPoint(r,h,m);if(x.setIntervalRole(Fe.isolated),c){const _=new Ze(x,p);this._results.push(_)}else{const _=new Ze(p,x);this._results.push(_)}}computeSegmentSegment3D(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p){const x=xn._workVector2dA;Le.lineSegment3dClosestApproachUnbounded(n,s,d,u,x)&&this.acceptFraction(t,x.x,a)&&this.acceptFraction(c,x.y,m)&&this.recordPointWithLocalFractions(x.x,e,i,r,x.y,o,h,g,p)}dispatchSegmentSegment(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p){this.computeSegmentSegment3D(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p)}createPlaneWithPreferredPerpendicular(e,t,n,i,s){n=f.restrictToInterval(Math.abs(n),0,1-f.smallFraction);const r=t.magnitudeSquared(),a=i.magnitudeSquared(),o=Math.abs(t.dotProduct(i)),c=t.unitCrossProduct(o*o<=n*n*r*a?i:s);if(c)return pe.create(e,c)}dispatchSegmentArc(e,t,n,i,s,r,a,o,c,d,h){const u=v.createStartEnd(n,s),m=this.createPlaneWithPreferredPerpendicular(n,u,.94,o.perpendicularVector,o.vector0);if(m!==void 0){const p=[];o.appendPlaneIntersectionPoints(m,p);let x,_;for(const I of p){const S=o.sweep.fractionToSignedPeriodicFraction(I.fraction,c);this.acceptFraction(c,S,d)&&(x=Le.lineSegment3dClosestPointUnbounded(n,s,I.point),x!==void 0&&(_=n.interpolate(x,s,_),_.isAlmostEqualMetric(I.point)&&this.acceptFraction(t,x,a)&&this.recordPointWithLocalFractions(x,e,i,r,S,o,0,1,h)))}}}dispatchArcArcInPlane(e,t,n,i,s,r,a){const o=e.otherArcAsLocalVectors(i);if(o!==void 0){const c=[],d=[];Oi.solveUnitCircleHomogeneousEllipseIntersection(o.center.x,o.center.y,1,o.vector0.x,o.vector0.y,0,o.vector90.x,o.vector90.y,0,c,d);for(let h=0;h<c.length;h++){const u=e.sweep.radiansToSignedFraction(d[h],t),g=i.sweep.radiansToSignedFraction(c[h],s);this.acceptFraction(t,u,n)&&this.acceptFraction(s,g,r)&&this.recordPointWithLocalFractions(u,e,0,1,g,i,0,1,a)}}}dispatchArcArc(e,t,n,i,s,r,a){const o=pe.create(e.center,e.perpendicularVector),c=pe.create(i.center,i.perpendicularVector);if(!(o===void 0||c===void 0))if(o.getNormalRef().isParallelTo(c.getNormalRef()))o.isPointInPlane(c.getOriginRef())&&c.isPointInPlane(o.getOriginRef())&&this.dispatchArcArcInPlane(e,t,n,i,s,r,a);else{const d=[];i.appendPlaneIntersectionPoints(o,d);const h=[];e.appendPlaneIntersectionPoints(c,h);for(const u of d)for(const g of h)if(g.point.isAlmostEqual(u.point)){const m=e.sweep.fractionToSignedPeriodicFraction(g.fraction,t),p=i.sweep.fractionToSignedPeriodicFraction(u.fraction,s);this.acceptFraction(t,m,n)&&this.acceptFraction(s,p,r)&&this.recordPointWithLocalFractions(m,e,0,1,p,i,0,1,a)}}}dispatchArcBsplineCurve3d(e,t,n,i,s,r,a){}dispatchBSplineCurve3dBSplineCurve3d(e,t,n){}dispatchSegmentBsplineCurve(e,t,n,i,s,r,a,o,c,d,h){}dispatchLineStringBSplineCurve(e,t,n,i,s,r,a){}computeSegmentLineString(e,t,n,i,s,r,a){const o=e.point0Ref,c=e.point1Ref,d=xn._workPointBB0,h=xn._workPointBB1,u=i.numPoints();if(u>1){const g=1/(u-1);let m,p;m=0,i.pointAt(0,d);for(let x=1;x<u;x++,d.setFrom(h),m=p)i.pointAt(x,h),p=x*g,this.dispatchSegmentSegment(e,t,o,0,c,1,n,i,x===1&&s,d,m,h,p,x+1===u&&r,a)}}computeArcLineString(e,t,n,i,s,r,a){const o=xn._workPointBB0,c=xn._workPointBB1,d=i.numPoints();if(d>1){const h=1/(d-1);let u,g;u=0,i.pointAt(0,o);for(let m=1;m<d;m++,o.setFrom(c),u=g)i.pointAt(m,c),g=m*h,this.dispatchSegmentArc(i,m===1&&s,o,u,c,g,m+1===d&&r,e,t,n,!a)}}computeLineStringLineString(e,t,n){const i=xn._workPointAA0,s=xn._workPointAA1,r=xn._workPointBB0,a=xn._workPointBB1,o=e.numPoints(),c=t.numPoints();if(o>1&&c>1){e.pointAt(0,i);const d=1/(o-1),h=1/(c-1);let u=0,g,m,p;e.pointAt(0,i);for(let x=1;x<o;x++,i.setFrom(s),u=m){m=x*d,g=0,e.pointAt(x,s),t.pointAt(0,r);for(let _=1;_<c;_++,r.setFrom(a),g=p)t.pointAt(_,a),p=_*h,this.dispatchSegmentSegment(e,x===1&&this._extendA0,i,u,s,m,x+1===o&&this._extendA1,t,_===1&&this._extendB0,r,g,a,p,_+1===c&&this._extendB1,n)}}}dispatchCurveCollection(e,t){const n=this._geometryB;if(!n||!n.children||!(n instanceof _e))return;const i=n.children,s=this._extendB0,r=this._extendB1;for(let a=0;a<i.length;a++)this.resetGeometry(i[a]),n instanceof Te&&i.length>1?a===0?this._extendB1=!1:a===i.length-1?this._extendB0=!1:this._extendB0=this._extendB1=!1:n instanceof oe&&(this._extendB0=this._extendB1=!1),t(e),this._extendB0=s,this._extendB1=r;this.resetGeometry(n)}dispatchCurveChainWithDistanceIndex(e,t){if(!this._geometryB||!(this._geometryB instanceof Se))return;const n=this._results.length,i=this._geometryB;this.resetGeometry(i.path),this.dispatchCurveCollection(e,t),this.resetGeometry(i),this._results=Se.convertChildDetailToChainDetail(this._results,n,void 0,i,!0)}handleChildren(e){const t=e.children,n=this._extendA0,i=this._extendA1;if(t)for(let s=0;s<t.length;s++)e instanceof Te&&t.length>1?s===0?this._extendA1=!1:s===t.length-1?this._extendA0=!1:this._extendA0=this._extendA1=!1:e instanceof oe&&(this._extendA0=this._extendA1=!1),t[s].dispatchToGeometryHandler(this),this._extendA0=n,this._extendA1=i}handleLineSegment3d(e){if(this._geometryB instanceof Q){const t=this._geometryB;this.dispatchSegmentSegment(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,t,this._extendB0,t.point0Ref,0,t.point1Ref,1,this._extendB1,!1)}else this._geometryB instanceof N?this.computeSegmentLineString(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof B?this.dispatchSegmentArc(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof It?this.dispatchSegmentBsplineCurve(e,this._extendA0,e.point0Ref,0,e.point1Ref,1,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineSegment3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineSegment3d.bind(this))}handleLineString3d(e){if(this._geometryB instanceof N){const t=this._geometryB;this.computeLineStringLineString(e,t,!1)}else this._geometryB instanceof Q?this.computeSegmentLineString(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof B?this.computeArcLineString(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof It?this.dispatchLineStringBSplineCurve(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineString3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineString3d.bind(this))}handleArc3d(e){this._geometryB instanceof Q?this.dispatchSegmentArc(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.computeArcLineString(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof B?this.dispatchArcArc(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof It?this.dispatchArcBsplineCurve3d(e,this._extendA0,this._extendA1,this._geometryB,this._extendB0,this._extendB1,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleArc3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleArc3d.bind(this))}handleBSplineCurve3d(e){this._geometryB instanceof Q?this.dispatchSegmentBsplineCurve(this._geometryB,this._extendB0,this._geometryB.point0Ref,0,this._geometryB.point1Ref,1,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof N?this.dispatchLineStringBSplineCurve(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof B?this.dispatchArcBsplineCurve3d(this._geometryB,this._extendB0,this._extendB1,e,this._extendA0,this._extendA1,!0):this._geometryB instanceof Bs?this.dispatchBSplineCurve3dBSplineCurve3d(e,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleBSplineCurve3d.bind(this))}handleCurveChainWithDistanceIndex(e){super.handleCurveChainWithDistanceIndex(e),this._results=Se.convertChildDetailToChainDetail(this._results,0,e,void 0,!0)}handleBSplineCurve3dH(e){}}class sn{static intersectionXYPairs(e,t,n,i,s=f.smallMetricDistance){return sn.intersectionProjectedXYPairs(void 0,e,t,n,i,s)}static intersectionProjectedXYPairs(e,t,n,i,s,r=f.smallMetricDistance){const a=new Ve(e,n,i,s,r);return t.dispatchToGeometryHandler(a),a.grabPairedResults()}static intersectionXYZPairs(e,t,n,i){const s=new xn(t,n,i);return e.dispatchToGeometryHandler(s),s.grabPairedResults()}static allIntersectionsAmongPrimitivesXY(e,t=f.smallMetricDistance){const n=new Ve(void 0,!1,void 0,!1,t);for(let i=0;i<e.length;i++){const s=e[i];for(let r=i+1;r<e.length;r++)n.resetGeometryB(e[r]),s.dispatchToGeometryHandler(n)}return n.grabPairedResults()}static closeApproachProjectedXYPairs(e,t,n=f.largeCoordinateResult){const i=f.isNumber(n),s=i?n:n.maxDistance??f.largeCoordinateResult,r=i?void 0:n.xyTolerance,a=i?void 0:n.newtonTolerance,o=i?void 0:n.maxIterations,c=new Bt(t,r,a,o);return c.maxDistanceToAccept=s,e.dispatchToGeometryHandler(c),c.grabPairedResults()}static closestApproachProjectedXYPair(e,t,n){n===void 0&&(n={maxDistance:f.largeCoordinateResult});const i=this.closeApproachProjectedXYPairs(e,t,n);if(!i.length)return;let s=0,r=f.largeCoordinateResult;for(let a=0;a<i.length;++a){const o=i[a].detailA.a;o<r&&(s=a,r=o)}return i[s]}}class Bt extends $i{_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(e,t=f.smallMetricDistance,n=f.smallNewtonStep,i=50){super(),this._geometryB=e instanceof qr?e.proxyCurve:e,this._maxDistanceSquared=f.smallMetricDistanceSquared,this._xyTolerance=t,this._newtonTolerance=n,this._maxIterations=i;const s=Ze.comparePairsByPoints(t,!0);this._results=new pi(s,Xn.Retain)}set maxDistanceToAccept(e){e===void 0?(this._maxDistanceToAccept=void 0,this._maxDistanceSquared=f.smallMetricDistanceSquared):(this._maxDistanceToAccept=Math.abs(e),this._maxDistanceSquared=e*e)}get maxDistanceToAccept(){return this._maxDistanceToAccept}get isMaxDistanceSet(){return this._maxDistanceToAccept!==void 0&&this._maxDistanceToAccept>0}resetGeometry(e){e&&(this._geometryB=e)}acceptFraction(e,t=1e-12){return!(e<-t||e>1+t)}grabPairedResults(){return this._results.extractArray()}testAndRecordPointPair(e,t,n,i,s,r,a){n||(n=e.fractionToPoint(t)),r||(r=i.fractionToPoint(s));const o=n.distanceSquaredXY(r);if(o<=this._maxDistanceSquared){const c=Math.sqrt(o),d=Y.createCurveFractionPointDistance(e,t,n,c),h=Y.createCurveFractionPointDistance(i,s,r,c);d.setIntervalRole(Fe.isolated),h.setIntervalRole(Fe.isolated);const u=Ze.createCapture(d,h);a&&u.swapDetails(),this._results.insert(u)}}testAndRecordPair(e,t){const n=e.detailA.point.distanceSquaredXY(e.detailB.point);if(n>this._maxDistanceSquared)return;const i=Math.sqrt(n);e.detailA.a=e.detailB.a=i,e.detailA.setIntervalRole(Fe.isolated),e.detailB.setIntervalRole(Fe.isolated),t&&e.swapDetails(),this._results.insert(e)}testAndRecordLocalPair(e,t,n,i,s,r,a,o){const c=f.interpolate(n,e.detailA.fraction,i),d=f.interpolate(r,e.detailB.fraction,a),h=t.fractionToPoint(c),u=s.fractionToPoint(d),g=h.distanceSquaredXY(u);if(g>this._maxDistanceSquared)return;const m=Math.sqrt(g);Y.createCurveFractionPointDistance(t,c,h,m,e.detailA),Y.createCurveFractionPointDistance(s,d,u,m,e.detailB),e.detailA.setIntervalRole(Fe.isolated),e.detailB.setIntervalRole(Fe.isolated),o&&e.swapDetails(),this._results.insert(e)}static updatePointToSegmentDistance(e,t,n,i,s,r,a){let o=!1;i<0?i=0:i>1&&(i=1);const c=s.interpolate(i,r,this._workPointB),d=c.distanceSquaredXY(n);return d<=Math.min(a,e.detailA.a)&&(e.detailA.setFP(t,n,void 0,d),e.detailB.setFP(i,c,void 0,d),o=!0),o}static segmentSegmentBoundedApproach(e,t,n,i,s){const r=t.x-e.x,a=t.y-e.y,o=i.x-n.x,c=i.y-n.y,d=n.x-e.x,h=n.y-e.y,u=i.x-e.x,g=i.y-e.y,m=n.x-t.x,p=n.y-t.y,x=f.crossProductXYXY(r,a,d,h),_=f.crossProductXYXY(r,a,u,g),I=-f.crossProductXYXY(o,c,d,h),S=-f.crossProductXYXY(o,c,m,p);if(x*_<0&&I*S<0){const P=-I/(S-I),b=-x/(_-x);return Ze.createCapture(Y.createCurveFractionPoint(void 0,P,e.interpolate(P,t)),Y.createCurveFractionPoint(void 0,b,n.interpolate(b,i)))}const A=new Ze;A.detailA.a=2*s;let w=!1;const k=f.hypotenuseSquaredXY(r,a);if(x*x<=s*k){const P=f.safeDivideFraction(f.dotProductXYXY(r,a,d,h),k,0);this.updatePointToSegmentDistance(A,0,n,P,e,t,s)&&(w=!0)}if(_*_<=s*k){const P=f.safeDivideFraction(f.dotProductXYXY(r,a,u,g),k,0);this.updatePointToSegmentDistance(A,1,i,P,e,t,s)&&(w=!0)}const D=f.hypotenuseSquaredXY(o,c);if(I*I<=s*D){const P=f.safeDivideFraction(-f.dotProductXYXY(o,c,d,h),D,0);this.updatePointToSegmentDistance(A,0,e,P,n,i,s)&&(w=!1)}if(S*S<=s*D){const P=f.safeDivideFraction(-f.dotProductXYXY(o,c,m,p),D,0);this.updatePointToSegmentDistance(A,1,t,P,n,i,s)&&(w=!1)}if(!(A.detailA.a>s))return w&&A.swapDetails(),A}testAndRecordEndPointApproaches(e,t,n){const i=Bt._workPointB,s=r=>r instanceof B&&r.sweep.isFullCircle;s(e)||(this.testAndRecordProjection(e,0,e.startPoint(i),t,n),this.testAndRecordProjection(e,1,e.endPoint(i),t,n)),s(t)||(this.testAndRecordProjection(t,0,t.startPoint(i),e,!n),this.testAndRecordProjection(t,1,t.endPoint(i),e,!n))}testAndRecordProjection(e,t,n,i,s){const r=i.closestPointXY(n);r&&this.testAndRecordPointPair(e,t,n,i,r.fraction,r.point,s)}computeSegmentSegment(e,t,n,i,s,r,a,o,c,d,h){const u=Bt.segmentSegmentBoundedApproach(t,i,a,c,this._maxDistanceSquared);u&&(u.detailA.setCurve(e),u.detailB.setCurve(r),this.testAndRecordLocalPair(u,e,n,s,r,o,d,h))}announceAllPerpendicularsSegmentArcBounded(e,t,n,i){const s=n.vector0.crossProductStartEndXY(e,t),r=n.vector90.crossProductStartEndXY(e,t),a=Math.atan2(r,s);for(const o of[a,a+Math.PI]){const c=n.radiansToPoint(o),d=n.sweep.radiansToSignedPeriodicFraction(o);if(this.acceptFraction(d)){const h=Le.lineSegment3dXYClosestPointUnbounded(e,t,c);h!==void 0&&this.acceptFraction(h)&&i(h,void 0,d,c)}}}computeSegmentArc(e,t,n){let i=!1;const s=t.toTransformedVectors(),r=f.tripleProductXYW(e.point0Ref,1,e.point1Ref,1,s.center,1),a=f.tripleProductXYW(e.point0Ref,1,e.point1Ref,1,s.vector0,0),o=f.tripleProductXYW(e.point0Ref,1,e.point1Ref,1,s.vector90,0),c=new Me(2),d=new Me(2),h=new Me(2),u=Bn.appendImplicitLineUnitCircleIntersections(r,a,o,c,d,h);for(let g=0;g<u;g++){const m=s.center.plus2Scaled(s.vector0,c.atUncheckedIndex(g),s.vector90,d.atUncheckedIndex(g)),p=s.sweep.radiansToSignedPeriodicFraction(h.atUncheckedIndex(g));if(this.acceptFraction(p)){const x=Le.lineSegment3dXYClosestPointUnbounded(e.point0Ref,e.point1Ref,m);x!==void 0&&this.acceptFraction(x)&&(this.testAndRecordPointPair(e,x,void 0,t,p,m,n),i=!0)}}i||(this.testAndRecordEndPointApproaches(e,t,n),this.announceAllPerpendicularsSegmentArcBounded(e.point0Ref,e.point1Ref,t,(g,m,p,x)=>this.testAndRecordPointPair(e,g,m,t,p,x,n)))}allPerpendicularsArcArcBounded(e,t,n=!1){const i=new no(e,t),s=1/10,r=s/2,a=new Xs(i,100);for(let o=r;o<1;o+=s)for(let c=r;c<1;c+=s)if(a.setUV(o,c),a.runIterations()){const d=a.getU(),h=a.getV();this.acceptFraction(d)&&this.acceptFraction(h)&&this.testAndRecordPointPair(e,d,void 0,t,h,void 0,n)}}dispatchArcArc(e,t,n){const i=e.range(),s=t.range();this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),s.intersectsRangeXY(i)&&(this.testAndRecordEndPointApproaches(e,t,n),this.allPerpendicularsArcArcBounded(e,t,n))}computeSegmentLineString(e,t,n){const i=t.numPoints(),s=f.safeDivideFraction(1,i-1,0),r=e.point0Ref,a=e.point1Ref,o=Bt._workPointBB0,c=Bt._workPointBB1;for(let d=0;d<i-1;++d){const h=d*s,u=d+1===i-1?1:(d+1)*s;t.packedPoints.getPoint3dAtUncheckedPointIndex(d,o),t.packedPoints.getPoint3dAtUncheckedPointIndex(d+1,c),this.computeSegmentSegment(e,r,0,a,1,t,o,h,c,u,n)}}computeArcLineString(e,t,n){const i=e.range(),s=t.range();if(this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),!s.intersectsRangeXY(i))return;const r=Bt._workPointBB0,a=Bt._workPointBB1,o=sn.intersectionXYPairs(e,!1,t,!1,this._xyTolerance);for(const d of o)this.testAndRecordPair(d,n);const c=f.safeDivideFraction(1,t.numEdges(),0);for(let d=1;d<t.numEdges();++d)this.testAndRecordProjection(t,d*c,t.pointAtUnchecked(d,r),e,!n);this.testAndRecordEndPointApproaches(e,t,n),t.startPoint(r);for(let d=0;d<t.numEdges();++d,r.setFrom(a))t.pointAtUnchecked(d+1,a),this.announceAllPerpendicularsSegmentArcBounded(r,a,e,(h,u,g,m)=>{const p=t.segmentIndexAndLocalFractionToGlobalFraction(d,h);this.testAndRecordPointPair(e,g,m,t,p,u,n)})}classifyBitsPointRangeXY(e,t,n){let i=0;return e<n.low.x?i=1:e>n.high.x&&(i=2),t<n.low.y?i|=4:t>n.high.y&&(i|=8),i}computeLineStringLineString(e,t,n){const i=e.range(),s=t.range();if(this._maxDistanceToAccept&&i.expandInPlace(this._maxDistanceToAccept),!s.intersectsRangeXY(i))return;let r,a;const o=ie.createNull(),c=Bt._workPointAA0,d=Bt._workPointAA1,h=Bt._workPointBB0,u=Bt._workPointBB1,g=e.numPoints(),m=t.numPoints();if(g>1&&m>1){const p=1/(g-1),x=1/(m-1);let _=0,I,S,A;e.pointAt(0,c);for(let w=1;w<g;w++,c.setFrom(d),_=I)if(I=w*p,S=0,e.pointAt(w,d),o.setNull(),o.extendPoint(c),o.extendPoint(d),this._maxDistanceToAccept&&o.expandInPlace(this._maxDistanceToAccept),o.intersectsRangeXY(s)){t.pointAt(0,h),r=this.classifyBitsPointRangeXY(h.x,h.y,o);for(let k=1;k<m;k++,h.setFrom(u),S=A,r=a)t.pointAt(k,u),a=this.classifyBitsPointRangeXY(u.x,u.y,o),A=k*x,(r&a)===0&&this.computeSegmentSegment(e,c,_,d,I,t,h,S,u,A,n)}}}dispatchCurveCollection(e,t){const n=this._geometryB;if(!(!n||!n.children||!(n instanceof _e))){for(const i of n.children)this.resetGeometry(i),t(e);this._geometryB=n}}dispatchCurveChainWithDistanceIndex(e,t){if(!this._geometryB||!(this._geometryB instanceof Se))return;const n=this.grabPairedResults(),i=this._geometryB;for(const r of i.path.children)this.resetGeometry(r),t(e);this.resetGeometry(i),this._results.extractArray().forEach(r=>{Se.convertChildDetailToChainDetailSingle(r,void 0,i),this._results.insert(r)}),n.forEach(r=>this._results.insert(r))}needsStroking(e){return e instanceof Bs||e instanceof De}refineStrokedResultsByNewton(e,t,n,i,s,r=!1){const a=new no(t,i),o=new Xs(a,this._maxIterations,this._newtonTolerance);for(const c of e){const d=r?c.detailB:c.detailA,h=r?c.detailA:c.detailB;h.curve instanceof N;const u=n?t.closestPointXY(d.point)?.fraction??d.fraction:d.fraction,g=s?i.closestPointXY(h.point)?.fraction??h.fraction:h.fraction;if(o.setUV(u,g),o.runIterations()){const m=o.getU(),p=o.getV();this.acceptFraction(m)&&this.acceptFraction(p)&&this.testAndRecordPointPair(t,m,void 0,i,p,void 0,r)}}}strokeCurve(e,t,n){const i=n||N.create();return e.emitStrokes(i,t),i}computeDiscreteCloseApproachResults(e,t,n){const i=this.maxDistanceToAccept,s=this.grabPairedResults(),r=this._geometryB;if(this.maxDistanceToAccept=i?i*1.2:void 0,this.resetGeometry(e),this.handleLineString3d(t),!n)for(const o of this._results)o.swapDetails();this.resetGeometry(r),this.maxDistanceToAccept=i;const a=this._results.extractArray();return s.forEach(o=>this._results.insert(o)),a}dispatchCurveStrokedCurve(e,t,n){const i=sn.intersectionXYPairs(e,!1,t,!1,this._xyTolerance);for(const c of i)this.testAndRecordPair(c,n);const s=this.needsStroking(e),r=s?this.strokeCurve(e):e,a=this.strokeCurve(t),o=this.computeDiscreteCloseApproachResults(r,a,n);if(this.refineStrokedResultsByNewton(o,e,s,t,!0,n),e instanceof N){const c=f.safeDivideFraction(1,e.numEdges(),0),d=Bt._workPointBB0;for(let h=1;h<e.numEdges();++h)this.testAndRecordProjection(e,h*c,e.pointAtUnchecked(h,d),t,n)}this.testAndRecordEndPointApproaches(e,t,n)}handleLineSegment3d(e){if(this._geometryB instanceof Q){const t=this._geometryB;this.computeSegmentSegment(e,e.point0Ref,0,e.point1Ref,1,t,t.point0Ref,0,t.point1Ref,1,!1)}else this._geometryB instanceof N?this.computeSegmentLineString(e,this._geometryB,!1):this._geometryB instanceof B?this.computeSegmentArc(e,this._geometryB,!1):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(e,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineSegment3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineSegment3d.bind(this))}handleLineString3d(e){this._geometryB instanceof Q?this.computeSegmentLineString(this._geometryB,e,!0):this._geometryB instanceof N?this.computeLineStringLineString(e,this._geometryB,!1):this._geometryB instanceof B?this.computeArcLineString(this._geometryB,e,!0):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(e,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleLineString3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleLineString3d.bind(this))}handleArc3d(e){this._geometryB instanceof Q?this.computeSegmentArc(this._geometryB,e,!0):this._geometryB instanceof N?this.computeArcLineString(e,this._geometryB,!1):this._geometryB instanceof B?this.dispatchArcArc(e,this._geometryB,!1):this.needsStroking(this._geometryB)?this.dispatchCurveStrokedCurve(e,this._geometryB,!1):this._geometryB instanceof _e?this.dispatchCurveCollection(e,this.handleArc3d.bind(this)):this._geometryB instanceof Se&&this.dispatchCurveChainWithDistanceIndex(e,this.handleArc3d.bind(this))}handleBSplineCurve3d(e){this._geometryB instanceof Se?this.dispatchCurveChainWithDistanceIndex(e,this.handleBSplineCurve3d.bind(this)):this._geometryB instanceof le?this.dispatchCurveStrokedCurve(this._geometryB,e,!0):this._geometryB instanceof _e&&this.dispatchCurveCollection(e,this.handleBSplineCurve3d.bind(this))}handleTransitionSpiral(e){this._geometryB instanceof Se?this.dispatchCurveChainWithDistanceIndex(e,this.handleTransitionSpiral.bind(this)):this._geometryB instanceof le?this.dispatchCurveStrokedCurve(this._geometryB,e,!0):this._geometryB instanceof _e&&this.dispatchCurveCollection(e,this.handleTransitionSpiral.bind(this))}handleCurveChainWithDistanceIndex(e){super.handleCurveChainWithDistanceIndex(e),this._results.extractArray().forEach(n=>{Se.convertChildDetailToChainDetailSingle(n,e,void 0),this._results.insert(n)})}handleBSplineCurve3dH(e){}}function ts(l,e){return f.isAlmostEqualNumber(l,e,f.smallFraction)?0:l<e?-1:1}function Fc(l,e){return f.isAlmostEqualNumber(l,e,f.smallFraction)?0:l<e?1:-1}class ri{_quadrant;_fractions;_interpolateStartTangent;_interpolateEndTangent;_averageAdded;constructor(e,t,n,i){this._quadrant=e,this._fractions=t,this._interpolateStartTangent=n,this._interpolateEndTangent=i,this._averageAdded=!1}static create(e,t=[],n=!0,i=!0){return new ri(e,t,n,i)}get quadrant(){return this._quadrant}get fractions(){return this._fractions}set fractions(e){this._fractions=e}get interpolateStartTangent(){return this._interpolateStartTangent}set interpolateStartTangent(e){this._interpolateStartTangent=e}get interpolateEndTangent(){return this._interpolateEndTangent}set interpolateEndTangent(e){this._interpolateEndTangent=e}get averageAdded(){return this._fractions.length===3?this._averageAdded:!1}set averageAdded(e){this._averageAdded=e}static getQuadrantRadians(e,t){if(me.isRadiansInStartEnd(e,0,T.piOver2Radians)&&me.isRadiansInStartEnd(t,0,T.piOver2Radians))return{quadrant:1,angle0:0,angle1:T.piOver2Radians};if(me.isRadiansInStartEnd(e,T.piOver2Radians,T.piRadians)&&me.isRadiansInStartEnd(t,T.piOver2Radians,T.piRadians))return{quadrant:2,angle0:T.piOver2Radians,angle1:T.piRadians};if(me.isRadiansInStartEnd(e,T.piRadians,T.pi3Over2Radians)&&me.isRadiansInStartEnd(t,T.piRadians,T.pi3Over2Radians))return{quadrant:3,angle0:T.piRadians,angle1:T.pi3Over2Radians};if(me.isRadiansInStartEnd(e,T.pi3Over2Radians,T.pi2Radians)&&me.isRadiansInStartEnd(t,T.pi3Over2Radians,T.pi2Radians))return{quadrant:4,angle0:T.pi3Over2Radians,angle1:T.pi2Radians}}static getQ1FractionalRange(e){const n=.5*Math.PI;let i=e.radiansToSignedPeriodicFraction(0),s=e.radiansToSignedPeriodicFraction(n);return e.isCCW||([i,s]=[s,i]),s<i&&(s+=1),fe.createXX(i,s)}reverse(){this._fractions.reverse(),[this._interpolateStartTangent,this._interpolateEndTangent]=[this._interpolateEndTangent,this._interpolateStartTangent]}}class Zs{announceQuadrantBegin(e,t){return!0}announceArc(e,t,n,i){}announceQuadrantEnd(e,t){}}class Yi extends Zs{_ellipticalArc;_maxPerpendicular;constructor(e){super(),this._ellipticalArc=e,this._maxPerpendicular=void 0}static create(e){return new Yi(e)}get ellipticalArc(){return this._ellipticalArc}static computePrimitiveErrorXY(e,t,n,i){const s=new Bt;s.maxDistanceToAccept=e.quickLength()/2;const r=n!==void 0&&i!==void 0,a=r?t.clonePartialCurve(n,i):t;s.allPerpendicularsArcArcBounded(e,a);let o;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 d=c.detailA.point.distanceXY(c.detailB.point);(!o||o.detailA.a<d)&&(r&&(c.detailB.fraction=f.interpolate(n,c.detailB.fraction,i),c.detailB.setCurve(t)),c.detailA.a=c.detailB.a=d,o=c)}return o}get maxPerpendicular(){return this._maxPerpendicular}set maxPerpendicular(e){this._maxPerpendicular=e}updateMaxPerpendicular(e,t,n){const i=Yi.computePrimitiveErrorXY(e,this.ellipticalArc,t,n);i&&(!this.maxPerpendicular||this.maxPerpendicular.detailA.a<i.detailA.a)&&(this.maxPerpendicular=i)}announceArc(e,t,n,i){this.updateMaxPerpendicular(e,n,i)}}class $r extends Zs{_fullEllipseXY;_f;_bracket0;_bracket1;_error0;_error1;constructor(e,t,n,i){super(),this._fullEllipseXY=e,this._bracket0=t,this._f=n,this._bracket1=i,this._error0=this._error1=f.largeCoordinateResult}static create(e,t,n,i){return new $r(e,t,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(e,t){return e.quadrant,e.fractions.length===4||e.fractions.length===3&&e.interpolateStartTangent,this._error0=this._error1=f.largeCoordinateResult,!0}announceArc(e,t,n,i){if(f.isAlmostEqualEitherNumber(this.f,n,i,0)){const s=Yi.computePrimitiveErrorXY(e,this.fullEllipseXY,n,i);s&&(this.f===i?this._error0=s.detailA.a:this._error1=s.detailA.a)}}announceQuadrantEnd(e,t){if(f.isLargeCoordinateResult(this._error0)||f.isLargeCoordinateResult(this._error1)||this.isConverged)return;const n=e.fractions.length;this._error0<this._error1?this._bracket0=this._f:this._bracket1=this._f,this._f=e.fractions[n-2]=f.interpolate(this._bracket0,.5,this._bracket1)}}class Ws extends Zs{_fullEllipseXY;_fractionRangeQ1;_refinement;_maxError;_originalRefinementCount;static _maxIters=50;constructor(e,t){super(),this._fullEllipseXY=e,this._fractionRangeQ1=ri.getQ1FractionalRange(e.sweep),this._maxError=t>0?t:zi.defaultMaxError,this._originalRefinementCount=0}static create(e,t){return new Ws(e,t)}get fullEllipseXY(){return this._fullEllipseXY}get isRefined(){return this._refinement===void 0||this._refinement.length===0?!1:this._originalRefinementCount<this._refinement.length}announceQuadrantBegin(e,t){e.quadrant,this._refinement=new pi(t?Fc:ts,!1);for(const n of e.fractions)this._fractionRangeQ1.containsX(n)&&this._refinement.insert(n);return 2<=(this._originalRefinementCount=this._refinement.length)}getPreviousFraction(e){if(this._refinement===void 0)return;const t=this._refinement.indexOf(e);return t>=1?this._refinement.get(t-1):void 0}announceArc(e,t,n,i){if(this._refinement===void 0)return;if(this._originalRefinementCount>2){const u=Yi.computePrimitiveErrorXY(e,this.fullEllipseXY,n,i);if(!u||u.detailA.a<=this._maxError)return}const s=f.interpolate(n,.5,i),r=f.isAlmostEqualEitherNumber(n,this._fractionRangeQ1.low,this._fractionRangeQ1.high,0),a=f.isAlmostEqualEitherNumber(i,this._fractionRangeQ1.low,this._fractionRangeQ1.high,0);!r&&t===void 0&&(t=this.getPreviousFraction(n));const o=t===void 0?[n,s,i]:[t,n,s,i],c=[ri.create(1,o,r,a)],d=$r.create(this.fullEllipseXY,n,s,i);let h=0;do _i.processQuadrantFractions(this.fullEllipseXY,c,d);while(h++<Ws._maxIters&&!d.isConverged);this._refinement.insert(d.f)}announceQuadrantEnd(e,t){this._refinement&&(e.fractions=[...this._refinement])}getRefinedInteriorQ1Angles(e){if(e?e.length=0:e=[],this._refinement)for(const t of this._refinement)this._fractionRangeQ1.containsXOpen(t)&&e.push(this.fullEllipseXY.sweep.fractionToRadians(t));return e}}class ea{_context;_options;constructor(e,t){this._context=e,this._options=t}static create(e,t){return new ea(e,t)}computeRadiansStrictlyInsideQuadrant1(e){if(e||(e=[]),this._context.isValidEllipticalArc){const t=T.piOver2Radians/(this._options.numSamplesInQuadrant-1);for(let n=1;n<this._options.numSamplesInQuadrant-1;++n)e.push(n*t)}return e}}class Gs{_context;_options;_xMag2;_yMag2;_curvatureRange;constructor(e,t){this._context=e,this._options=t,this._xMag2=e.ellipticalArc.matrixRef.columnXMagnitudeSquared(),this._yMag2=e.ellipticalArc.matrixRef.columnYMagnitudeSquared(),this._curvatureRange=fe.createXX(Math.sqrt(this._xMag2)/this._yMag2,Math.sqrt(this._yMag2)/this._xMag2)}static create(e,t){return new Gs(e,t)}curvatureToRadians(e){if(!this._curvatureRange.containsX(e))return;const t=Math.cbrt(this._xMag2*this._yMag2/(e*e)),n=Math.sqrt(Math.abs((t-this._xMag2)/(this._yMag2-this._xMag2)));return Math.acos(n)}computeRadiansStrictlyInsideQuadrant1(e){if(e||(e=[]),this._context.isValidEllipticalArc){const t=1/(this._options.numSamplesInQuadrant-1);for(let n=1;n<this._options.numSamplesInQuadrant-1;++n){const i=this._options.remapFunction(n*t),s=(1-i)*this._curvatureRange.low+i*this._curvatureRange.high,r=this.curvatureToRadians(s);r!==void 0&&e.push(r)}}return e}}class ta extends Gs{constructor(e,t){super(e,t.clone()),this._options.remapFunction=n=>n}static create(e,t){return new ta(e,t)}}class na{_context;_options;_fullEllipseXY;constructor(e,t){this._context=e,this._options=t,this._fullEllipseXY=e.cloneLocalArc(!0)??B.createUnitCircle()}static create(e,t){return new na(e,t)}get fullEllipseXY(){return this._fullEllipseXY}computeRadiansStrictlyInsideQuadrant1(e){if(!this._context.isValidEllipticalArc)return[];const t=ri.getQ1FractionalRange(this.fullEllipseXY.sweep),n=[ri.create(1,[t.low,t.high],!0,!0)],i=Ws.create(this.fullEllipseXY,this._options.maxError);do _i.processQuadrantFractions(this.fullEllipseXY,n,i);while(i.isRefined);return i.getRefinedInteriorQ1Angles(e)}}class ia extends Zs{_chain;_quadrantChain;constructor(e,t){super(),this._chain=e.sweep.isFullCircle&&!t?oe.create():Te.create()}static create(e,t=!1){return new ia(e,t)}get chain(){return this._chain.children.length>0?this._chain:void 0}announceQuadrantBegin(e,t){return this._quadrantChain=void 0,!0}announceArc(e,t,n,i){this._quadrantChain||(this._quadrantChain=Te.create()),this._quadrantChain.tryAddChild(e)}announceQuadrantEnd(e,t){if(this._quadrantChain){t&&this._quadrantChain.reverseChildrenInPlace();for(const n of this._quadrantChain.children)this._chain.tryAddChild(n)}}}class _i{_ellipticalArc;_localToWorld;_isValidEllipticalArc;static workPt0=y.createZero();static workPt1=y.createZero();static workPt2=y.createZero();static workRay=q.createZero();constructor(e){this._isValidEllipticalArc=!1;const t=e.toScaledMatrix3d();if(this._ellipticalArc=B.createScaledXYColumns(t.center,t.axes,t.r0,t.r90,t.sweep),this._localToWorld=X.createRefs(t.center,t.axes),this._localToWorld.matrix.isSingular()||this._ellipticalArc.sweep.isEmpty)return;const n=e.matrixRef.columnXMagnitudeSquared(),i=e.matrixRef.columnYMagnitudeSquared();f.isSmallMetricDistanceSquared(n)||f.isSmallMetricDistanceSquared(i)||f.isSameCoordinateSquared(n,i)||(this._isValidEllipticalArc=!0)}static create(e){return new _i(e)}get ellipticalArc(){return this._ellipticalArc}get localToWorld(){return this._localToWorld}get isValidEllipticalArc(){return this._isValidEllipticalArc}cloneLocalArc(e){if(!this.isValidEllipticalArc)return;const t=this.localToWorld.inverse();if(!t)return;const n=this.ellipticalArc.cloneTransformed(t);if(e){let i=2*Math.PI;n.sweep.isCCW||(i=-i),n.sweep.setStartEndRadians(n.sweep.startRadians,n.sweep.startRadians+i)}return n}static processQuadrantFractions(e,t,n){const i=this.workPt0,s=this.workPt1,r=this.workPt2,a=this.workRay,o=(m,p,x)=>{const _=B.createCircularStartTangentEnd(m.origin,m.direction,p);if(_ instanceof B)return x&&_.reverseInPlace(),_},c=(m,p,x)=>{const _=B.createCircularStartMiddleEnd(m,p,x);if(!(_ instanceof B))return;const I=_.vector0.signedAngleTo(v.createStartEnd(_.center,p),_.matrixRef.columnZ());return _.sweep.setStartEndRadians(I.radians,_.sweep.endRadians),_},d=(m,p)=>{e.fractionToPointAndDerivative(m,a),e.fractionToPoint(p,s),m>p&&a.direction.scaleInPlace(-1);const x=o(a,s,!1);x&&n.announceArc(x,void 0,m,p)},h=(m,p,x)=>{let _=m;n.getPreviousFraction&&(_=n.getPreviousFraction(p)??m),e.fractionToPoint(_,i),e.fractionToPoint(p,s),e.fractionToPoint(x,r);const I=c(i,s,r);I&&n.announceArc(I,_,p,x)},u=(m,p)=>{e.fractionToPoint(m,i),e.fractionToPointAndDerivative(p,a),p>m&&a.direction.scaleInPlace(-1);const x=o(a,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 _=e.vector0.magnitudeSquared()>e.vector90.magnitudeSquared()?m.quadrant===2||m.quadrant===4:m.quadrant===1||m.quadrant===3,S=!(m.fractions[0]>m.fractions[p-1])&&_===e.sweep.isCCW;return S&&m.reverse(),S};for(const m of t){const p=m.fractions.length;if(p<2)continue;const x=g(m);if(n.announceQuadrantBegin(m,x)){m.interpolateStartTangent&&d(m.fractions[0],m.fractions[1]);for(let _=0;_+2<p-1;++_)h(m.fractions[_],m.fractions[_+1],m.fractions[_+2]);p>2&&(m.interpolateEndTangent?u(m.fractions[p-2],m.fractions[p-1]):h(m.fractions[p-3],m.fractions[p-2],m.fractions[p-1])),n.announceQuadrantEnd(m,x),x&&m.reverse()}}}computeApproximationError(e){const t=this.cloneLocalArc();if(!t)return;const n=Yi.create(t);_i.processQuadrantFractions(t,e,n);const i=n.maxPerpendicular;return i&&i.tryTransformInPlace(this.localToWorld)?i:void 0}computeSampleFractions(e,t=!1){if(!this.isValidEllipticalArc)return[];const n=(u,g)=>f.isAlmostEqualNumber(u,g,f.smallAngleRadians)?0:u<g?-1:1,i=(u,g)=>f.isAlmostEqualNumber(u,g,f.smallAngleRadians)?0:u<g?1:-1,s=(u,g)=>ts(u.fractions[u.fractions.length-1],g.fractions[0])<=0?-1:ts(g.fractions[g.fractions.length-1],u.fractions[0])<=0?1:0,r=(u,g)=>{const m=g.isRadiansInSweep(u,!0);if(m){const p=g.radiansToSignedPeriodicFraction(u);f.isIn01(p)&&(u=g.fractionToRadians(p))}return{angle:u,inSweep:m}},a=(u,g,m,p,x)=>{if(p===void 0&&(p=0),x===void 0&&(x=1),p>x)return a(u,g,m,x,p);const _=m.radiansToSignedPeriodicFraction(g);if(!(_<p-f.smallFraction||x+f.smallFraction<_))return f.restrictToInterval(_,0,1),u.add(_),_},o=(u,g,m,p)=>{if(g>m)return o(u,m,g,p);if(T.isAlmostEqualRadiansNoPeriodShift(g,m))return;const x=ri.getQuadrantRadians(g,m);if(x===void 0)return;const _=new Di(ts),I=a(_,g,p),S=a(_,m,p);if(I===void 0||S===void 0)return;for(const k of u){let D=k;x.quadrant===2?D=T.piRadians-D:x.quadrant===3?D=T.piRadians+D:x.quadrant===4&&(D=T.pi2Radians-D),a(_,D,p,I,S)}const A=ri.create(x.quadrant,[..._]);return A.fractions.length===2&&(A.fractions.splice(1,0,f.interpolate(A.fractions[0],.5,A.fractions[1])),A.averageAdded=!0),A},c=(u,g)=>{const m=new Di(g.isCCW?n:i);m.add(g.endRadians);for(const _ of[0,T.piOver2Radians,T.piRadians,T.pi3Over2Radians,T.pi2Radians]){const I=r(_,g);I.inSweep&&m.add(I.angle)}const p=new Di(s);let x=g.startRadians;for(const _ of m){const I=o(u,x,_,g);I&&p.add(I),x=_}return[...p]},d=(u,g)=>{const m=new Di(ts);m.add(0),m.add(1);for(const p of[0,T.piOver2Radians,T.piRadians,T.pi3Over2Radians])a(m,p,g);for(const p of u)for(const x of[p,T.piRadians-p,T.piRadians+p,T.pi2Radians-p])a(m,x,g);return[...m]},h=[];switch(e.sampleMethod){case yi.UniformParameter:{ea.create(this,e).computeRadiansStrictlyInsideQuadrant1(h);break}case yi.UniformCurvature:{ta.create(this,e).computeRadiansStrictlyInsideQuadrant1(h);break}case yi.NonUniformCurvature:{Gs.create(this,e).computeRadiansStrictlyInsideQuadrant1(h);break}case yi.AdaptiveSubdivision:{na.create(this,e).computeRadiansStrictlyInsideQuadrant1(h);break}}return t?c(h,this.ellipticalArc.sweep):d(h,this.ellipticalArc.sweep)}constructCircularArcChainApproximation(e){if(!this.isValidEllipticalArc)return;e||(e=zi.create());const t=this.computeSampleFractions(e,!0),n=ia.create(this.ellipticalArc,e.forcePath);return _i.processQuadrantFractions(this.ellipticalArc,t,n),n.chain}}var yi;(function(l){l[l.UniformParameter=0]="UniformParameter",l[l.UniformCurvature=1]="UniformCurvature",l[l.NonUniformCurvature=2]="NonUniformCurvature",l[l.AdaptiveSubdivision=3]="AdaptiveSubdivision"})(yi||(yi={}));class zi{_sampleMethod;_numSamplesInQuadrant;_maxError;_remapFunction;_forcePath;static defaultMaxError=Os.oneCentimeter;constructor(e,t,n,i,s){this._sampleMethod=e,this._numSamplesInQuadrant=t,this._maxError=n,this._remapFunction=i,this._forcePath=s}static create(e=yi.AdaptiveSubdivision,t=4,n=this.defaultMaxError,i=r=>r*r,s=!1){return t<2&&(t=2),n<=0&&(n=this.defaultMaxError),new zi(e,t,n,i,s)}clone(){return new zi(this.sampleMethod,this.numSamplesInQuadrant,this.maxError,this.remapFunction,this.forcePath)}get sampleMethod(){return this._sampleMethod}set sampleMethod(e){this._sampleMethod=e}get numSamplesInQuadrant(){return this._numSamplesInQuadrant}set numSamplesInQuadrant(e){this._numSamplesInQuadrant=e}get maxError(){return this._maxError}set maxError(e){this._maxError=e}get remapFunction(){return this._remapFunction}set remapFunction(e){this._remapFunction=e}get forcePath(){return this._forcePath}set forcePath(e){this._forcePath=e}}class B extends le{curvePrimitiveType="arc";isSameGeometryClass(e){return e instanceof B}_center;_matrix;_sweep;static _workPointA=y.create();static _workPointB=y.create();static _workPointC=y.create();static _workVectorU=v.create();static _workVectorV=v.create();static _workVectorW=v.create();static _workRay0=q.createZero();static _workRay1=q.createZero();static _workRay2=q.createZero();get center(){return this._center.clone()}set center(e){this._center.setFrom(e)}get centerRef(){return this._center}get vector0(){return this._matrix.columnX()}get vector90(){return this._matrix.columnY()}binormalVector(e){const t=this.fractionToPointAnd2Derivatives(0);return t.vectorU.crossProduct(t.vectorV,e)}get perpendicularVector(){return this._matrix.columnZ()}matrixClone(){return this._matrix.clone()}get matrixRef(){return this._matrix}get sweep(){return this._sweep}set sweep(e){this._sweep.setFrom(e)}get isExtensibleFractionSpace(){return!0}constructor(e,t,n){super(),this._center=e,this._matrix=t,this._sweep=n.clampToFullCircle(n)}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}setRefs(e,t,n){this._center=e,this._matrix=t,n.clampToFullCircle(this._sweep)}set(e,t,n){return e?this._center.setFrom(e):this._center.setZero(),t?this._matrix.setFrom(t):this._matrix.setIdentity(),n?n.clampToFullCircle(this._sweep):me.create360(0,this._sweep),this}setFrom(e){this._center.setFrom(e._center),this._matrix.setFrom(e._matrix),this._sweep.setFrom(e._sweep)}clone(){return new B(this._center.clone(),this._matrix.clone(),this._sweep.clone())}static createRefs(e,t,n,i){return i?i.set(e,t,n):new B(e??y.createZero(),t??E.createIdentity(),n??me.create360())}static createScaledXYColumns(e,t,n,i,s,r){const a=t.columnX(),o=t.columnY();return B.create(e,a.scale(n,a),o.scale(i,o),s,r)}static createCenterNormalRadius(e,t,n,i){const s=E.createRigidHeadsUp(t);return B.createScaledXYColumns(e,s,n,n,void 0,i)}static create(e,t,n,i,s){const r=t.unitCrossProductWithDefault(n,0,0,0),a=E.createColumns(t,n,r,s?._matrix);return s?s.set(e,a,i):this.createRefs(e?.clone(),a,i?.clone())}static createStartMiddleEnd(e,t,n,i,s){const r=y.createAdd2Scaled(e,.5,n,.5),a=v.createStartEnd(r,e),o=v.createStartEnd(r,t),c=a.dotProduct(o),d=a.magnitudeSquared();if(Math.abs(c)>=d)return;const u=a.crossProduct(o).unitCrossProductWithDefault(a,0,0,0),g=o.dotProduct(u),m=f.safeDivideFraction(d*g,Math.sqrt(d*d-c*c),0);if(!f.isSmallMetricDistanceSquared(m))return u.scaleInPlace(m),B.create(r,a,u,i,s)}static createCircularStartTangentEnd(e,t,n,i){const s=v.createStartEnd(e,n),r=E.createRigidFromColumns(t,s,ve.XYZ);if(r!==void 0){const a=s.dotProduct(s),o=r.dotColumnY(s),c=f.conditionalDivideCoordinate(a,2*o);if(c!==void 0){const d=r.columnY();d.scaleInPlace(-c);const h=r.columnX();h.scaleInPlace(c);const u=d.plus(s);let m=d.angleTo(u).radians;t.dotProduct(u)<0&&(m=2*Math.PI-m);const p=e.plusScaled(d,-1),x=me.createStartEndRadians(0,m);return B.create(p,d,h,x,i)}}return Q.create(e,n)}static createCircularStartTangentRadius(e,t,n,i,s){i===void 0&&(i=v.unitZ());const r=i.unitCrossProduct(t);if(r===void 0)return;const a=e.plusScaled(r,n);r.scaleInPlace(-n);const o=t.scaleToLength(Math.abs(n));return o!==void 0?B.create(a,r,o,me.create(s)):void 0}static createCircularStartEndRadius(e,t,n,i,s){const r=.25*e.distanceSquared(t),a=n*n;if(a<r)return;const o=Math.sqrt(a-r),c=v.createZero(this._workVectorU),d=v.createZero(this._workVectorV);if(i instanceof y?e.crossProductToPoints(i,t,c):c.setFrom(i),!c.normalizeInPlace()||!c.crossProductStartEnd(e,t,d).scaleToLength(o,d))return;const h=y.createZero(s?.centerRef);e.interpolate(.5,t,h).addInPlace(d);const u=v.createStartEnd(h,e,this._workVectorW),g=v.createStartEnd(h,t,this._workVectorV),m=me.createStartEndRadians(0,u.signedRadiansTo(g,c),s?.sweep),p=c.crossProduct(u,this._workVectorV),x=E.createColumns(u,p,c,s?.matrixRef);return this.createRefs(h,x,m,s)}cloneAtZ(e){return e===void 0&&(e=this._center.z),B.createXYZXYZXYZ(this._center.x,this._center.y,e,this._matrix.coffs[0],this._matrix.coffs[3],0,this._matrix.coffs[1],this._matrix.coffs[4],0,this._sweep)}static createXYZXYZXYZ(e,t,n,i,s,r,a,o,c,d,h){return B.create(y.create(e,t,n),v.create(i,s,r),v.create(a,o,c),d,h)}quickEccentricity(){const e=this._matrix.columnXMagnitude(),t=this._matrix.columnYMagnitude(),n=this._matrix.columnXYCrossProductMagnitude(),i=f.maxXY(e,t);return n/(i*i)}static createCircularStartMiddleEnd(e,t,n,i){const s=v.createStartEnd(e,t),r=v.createStartEnd(e,n),a=s.magnitudeSquared(),o=r.magnitudeSquared(),c=s.sizedCrossProduct(r,Math.sqrt(Math.sqrt(a*o)));if(c){const d=Le.linearSystem3d(c.x,c.y,c.z,s.x,s.y,s.z,r.x,r.y,r.z,0,.5*a,.5*o);if(d){const h=y.create(e.x,e.y,e.z).plus(d),u=v.createStartEnd(h,e),g=v.createRotateVectorAroundVector(u,c,T.createDegrees(90));if(g){const m=v.createStartEnd(h,n),p=u.signedAngleTo(m,c);return p.radians<0&&p.addMultipleOf2PiInPlace(1),B.create(h,u,g,me.createStartEndRadians(0,p.radians),i)}}}return N.create(e,t,n)}getFractionToDistanceScale(){const e=this.circularRadius();if(e!==void 0)return Math.abs(e*this._sweep.sweepRadians)}fractionToPoint(e,t){const n=this._sweep.fractionToRadians(e);return this._matrix.originPlusMatrixTimesXY(this._center,Math.cos(n),Math.sin(n),t)}fractionAndRadialFractionToPoint(e,t,n){const i=this._sweep.fractionToRadians(e);return this._matrix.originPlusMatrixTimesXY(this._center,t*Math.cos(i),t*Math.sin(i),n)}fractionToPointAndDerivative(e,t){return t=this.radiansToPointAndDerivative(this._sweep.fractionToRadians(e),t),t.direction.scaleInPlace(this._sweep.sweepRadians),t}fractionToPointAnd2Derivatives(e,t){const n=this._sweep.fractionToRadians(e);t||(t=ke.createXYPlane());const i=Math.cos(n),s=Math.sin(n);this._matrix.originPlusMatrixTimesXY(this._center,i,s,t.origin);const r=this._sweep.sweepRadians;this._matrix.multiplyXY(-r*s,r*i,t.vectorU);const a=r*r;return this._matrix.multiplyXY(-a*i,-a*s,t.vectorV),t}radiansToPointAndDerivative(e,t){t=t||q.createZero();const n=Math.cos(e),i=Math.sin(e);return this._matrix.originPlusMatrixTimesXY(this._center,n,i,t.origin),this._matrix.multiplyXY(-i,n,t.direction),t}radiansToPoint(e,t){t=t||y.create();const n=Math.cos(e),i=Math.sin(e);return this._matrix.originPlusMatrixTimesXY(this._center,n,i,t),t}radiansToRotatedBasis(e,t){t=t||ke.createXYPlane();const n=Math.cos(e),i=Math.sin(e);return t.origin.setFromPoint3d(this.center),this._matrix.multiplyXY(n,i,t.vectorU),this._matrix.multiplyXY(-i,n,t.vectorV),t}angleToPointAndDerivative(e,t){t=t||q.createZero();const n=e.cos(),i=e.sin();return this._matrix.originPlusMatrixTimesXY(this._center,n,i,t.origin),this._matrix.multiplyXY(-i,n,t.direction),t}startPoint(e){return this.fractionToPoint(0,e)}isPhysicallyClosedCurve(e=f.smallMetricDistance,t=!1){return this.sweep.isFullCircle?!0:super.isPhysicallyClosedCurve(e,t)}endPoint(e){return this.fractionToPoint(1,e)}curveLength(){return this.curveLengthBetweenFractions(0,1)}static quadratureGuassCount=5;static quadratureGaussCount=5;static quadratureIntervalAngleDegrees=10;curveLengthBetweenFractions(e,t){const n=this.getFractionToDistanceScale();if(n!==void 0)return n*Math.abs(t-e);let i=e,s=t;e>t&&(i=t,s=e);const r=(s-i)*this._sweep.sweepDegrees;let a=this.quickEccentricity();a<1e-5&&(a=1e-5);let o=Math.ceil(r/(a*B.quadratureIntervalAngleDegrees));return o>400&&(o=400),o<1&&(o=1),super.curveLengthWithFixedIntervalCountQuadrature(i,s,o,B.quadratureGaussCount)}quickLength(){const e=Math.abs(this._sweep.sweepRadians);let t=Math.ceil(4*e/Math.PI);t<1&&(t=1),t<4?t+=3:t<6&&(t+=2);const n=B._workPointA,i=B._workPointB;let s=0;this.fractionToPoint(0,n);for(let o=1;o<=t;o++)this.fractionToPoint(o/t,i),s+=n.distance(i),n.setFromPoint3d(i);const r=e/t,a=r/(2*Math.sin(.5*r));return s*a}moveSignedDistanceFromFraction(e,t,n,i){if(!this.isCircular)return super.moveSignedDistanceFromFractionGeneric(e,t,n,i);const s=this.curveLength(),r=f.conditionalDivideFraction(t,s);return r===void 0?Y.createCurveFractionPointDistanceCurveSearchStatus(this,e,this.fractionToPoint(e),0,Yt.error):Y.createConditionalMoveSignedDistance(n,this,e,e+r,t,i)}allPerpendicularAngles(e,t=!0,n=!1){const i=[],s=e.vectorTo(this.center),r=this._matrix.columnXMagnitudeSquared(),a=this._matrix.columnXDotColumnY(),o=this._matrix.columnYMagnitudeSquared();return Oi.solveUnitCircleImplicitQuadricIntersection(a,o-r,-a,this._matrix.dotColumnY(s),-this._matrix.dotColumnX(s),0,i),n&&(i.push(this.sweep.startRadians),i.push(this.sweep.endRadians)),i}closestPoint(e,t=!1,n){n=Y.create(this,n);const i=this.allPerpendicularAngles(e,!0,!1);if(!this._sweep.isFullCircle){const r=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,0),a=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,1);r===je.None&&a===je.None&&(i.push(this._sweep.startRadians),i.push(this._sweep.endRadians))}const s=q.createZero();if(i.length===0)n.setFR(0,this.radiansToPointAndDerivative(this._sweep.startRadians,s),e.distance(n.point));else{let r=Number.MAX_VALUE,a=0;for(const o of i){const c=Ge.resolveRadiansToValidSweepFraction(t,o,this.sweep);c.isValid&&(this.fractionToPointAndDerivative(c.fraction,s),a=e.distance(s.origin),a<r&&(r=a,n.setFR(c.fraction,s,a)))}}return n}closestPointXY(e,t=!1,n){const i=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,0),s=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(t,1);return t=i!==je.None||s!==je.None,super.closestPointXY(e,t,n)}emitTangents(e,t,n){const i=v.createStartEnd(this.centerRef,e);let s;if(n?.vectorToEye?s=E.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 a=Math.sqrt(r-1),o=Math.atan2(s.y,s.x),c=Math.atan2(a,1),d=f.isSmallAngleRadians(c)?[o]:[o+c,o-c];for(const h of d){const u=Ge.resolveRadiansToValidSweepFraction(n?.extend??!1,h,this.sweep);if(u.isValid){const g=Y.createCurveFractionPoint(this,u.fraction,this.fractionToPoint(u.fraction));t(g)}}}}}reverseInPlace(){this._sweep.reverseInPlace()}tryTransformInPlace(e){return this._center=e.multiplyPoint3d(this._center,this._center),this._matrix=e.matrix.multiplyMatrixMatrix(this._matrix,this._matrix),this.setVector0Vector90(this._matrix.columnX(),this._matrix.columnY()),!0}isInPlane(e){const t=e.getNormalRef();return f.isSmallMetricDistance(e.altitude(this._center))&&f.isSmallMetricDistance(this._matrix.dotColumnX(t))&&f.isSmallMetricDistance(this._matrix.dotColumnY(t))}get isCircular(){const e=this._matrix.columnXMagnitudeSquared(),t=this._matrix.columnYMagnitudeSquared(),n=this._matrix.columnXDotColumnY();return T.isPerpendicularDotSet(e,t,n)&&f.isSameCoordinateSquared(e,t)}get isCircularXY(){const e=this._matrix.columnX(),t=this._matrix.columnY(),n=e.magnitudeSquaredXY(),i=t.magnitudeSquaredXY(),s=e.dotProductXY(t);return T.isPerpendicularDotSet(n,i,s)&&f.isSameCoordinateSquared(n,i)}get isDegenerateCircle(){return f.isSmallMetricDistanceSquared(this._matrix.columnXMagnitudeSquared())&&f.isSmallMetricDistanceSquared(this._matrix.columnYMagnitudeSquared())}circularRadiusXY(){const e=this._matrix.at(0,0),t=this._matrix.at(1,0),n=this._matrix.at(0,1),i=this._matrix.at(1,1),s=f.dotProductXYXY(e,t,e,t),r=f.dotProductXYXY(n,i,n,i),a=f.dotProductXYXY(e,t,n,i);if(T.isPerpendicularDotSet(s,r,a)&&f.isSameCoordinateSquared(s,r))return f.hypotenuseXY(e,t)}circularRadius(){return this.isCircular?this._matrix.columnXMagnitude():void 0}maxVectorLength(){return Math.max(this._matrix.columnXMagnitude(),this._matrix.columnYMagnitude())}appendPlaneIntersectionPoints(e,t){const n=e.altitude(this._center),i=this._matrix.coffs,s=e.velocityXYZ(i[0],i[3],i[6]),r=e.velocityXYZ(i[1],i[4],i[7]),a=f.solveTrigForm(n,s,r);let o=0;if(a!==void 0){o=a.length;let c;for(c of a){const d=Math.atan2(c.y,c.x),h=this._sweep.radiansToPositivePeriodicFraction(d),u=Y.createCurveFractionPoint(this,h,this.fractionToPoint(h));u.intervalRole=Fe.isolated,(T.isAlmostEqualRadiansAllowPeriodShift(d,this._sweep.startRadians)||T.isAlmostEqualRadiansAllowPeriodShift(d,this._sweep.endRadians))&&(u.intervalRole=Fe.isolatedAtVertex),t.push(u)}}return o}extendRange(e,t){this.extendRangeInSweep(e,this._sweep,t)}extendRangeInSweep(e,t,n){const i=new ja(0,0,0),s=this._center.clone(B._workPointA),r=this._matrix.columnX(B._workVectorU),a=this._matrix.columnY(B._workVectorV);n&&(n.multiplyPoint3d(s,s),n.multiplyVector(r,r),n.multiplyVector(a,a));const o=B._workPointB,c=B._workPointC,d=fe.createNull();for(let h=0;h<3;h++)i.set(s.at(h),r.at(h),a.at(h)),i.rangeInSweep(t,d),o.setAt(h,d.low),c.setAt(h,d.high);e.extend(o),e.extend(c)}rangeBetweenFractions(e,t,n){const i=me.createStartEndRadians(this.sweep.fractionToRadians(e),this.sweep.fractionToRadians(t)),s=ie.create();return this.extendRangeInSweep(s,i,n),s}getPlaneAltitudeSineCosinePolynomial(e,t){return t||(t=new ja(0,0,0)),t.set(e.altitude(this._center),e.velocityXYZ(this._matrix.coffs[0],this._matrix.coffs[3],this._matrix.coffs[6]),e.velocityXYZ(this._matrix.coffs[1],this._matrix.coffs[4],this._matrix.coffs[7])),t}static createUnitCircle(e){return B.createRefs(void 0,void 0,void 0,e)}static createXY(e,t,n,i){const s=E.createScale(t,t,1,i?.matrixRef);return i?i.set(e,s,n):B.createRefs(e.clone(),s,n?.clone())}static createXYEllipse(e,t,n,i,s){const r=E.createScale(t,n,1,s?.matrixRef);return s?s.set(e,r,i):B.createRefs(e.clone(),r,i?.clone())}setVector0Vector90(e,t){this._matrix.setColumns(e,t,e.unitCrossProductWithDefault(t,0,0,0))}toScaledMatrix3d(){const e=T.dotProductsToHalfAngleTrigValues(this._matrix.columnXMagnitudeSquared(),this._matrix.columnYMagnitudeSquared(),this._matrix.columnXDotColumnY(),!0),t=this._matrix.multiplyXY(e.c,e.s),n=this._matrix.multiplyXY(-e.s,e.c),i=E.createRigidFromColumns(t,n,ve.XYZ);return{center:this._center.clone(),axes:i||E.createIdentity(),r0:t.magnitude(),r90:n.magnitude(),sweep:this.sweep.cloneMinusRadians(e.radians)}}toVectors(){return{center:this.center.clone(),vector0:this._matrix.columnX(),vector90:this._matrix.columnY(),sweep:this.sweep.clone()}}toTransformedVectors(e){return e?{center:e.multiplyPoint3d(this._center),vector0:e.multiplyVector(this._matrix.columnX()),vector90:e.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(e){return{center:e.multiplyPoint3d(this._center,1),vector0:e.multiplyPoint3d(this._matrix.columnX(),0),vector90:e.multiplyPoint3d(this._matrix.columnY(),0),sweep:this.sweep.clone()}}setFromJSON(e){if(e&&e.center&&e.vector0&&e.vector90&&e.sweep){this._center.setFromJSON(e.center);const t=v.create(),n=v.create();t.setFromJSON(e.vector0),n.setFromJSON(e.vector90),this.setVector0Vector90(t,n),this._sweep.setFromJSON(e.sweep)}else this._center.set(0,0,0),this._matrix.setFrom(E.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(e,t=f.smallMetricDistance,n=f.smallAngleRadians){if(e instanceof B){const i=e;return this._center.isAlmostEqual(i._center,t)&&this._matrix.isAlmostEqual(i._matrix,t)&&this._sweep.isAlmostEqualAllowPeriodShift(i._sweep,n)}return!1}emitStrokes(e,t){const n=this.computeStrokeCountForOptions(t);e.appendFractionalStrokePoints(this,n,0,1,!0)}emitStrokableParts(e,t){const n=this.computeStrokeCountForOptions(t);e.startCurvePrimitive(this),e.announceIntervalForUniformStepStrokes(this,n,0,1),e.endCurvePrimitive(this)}computeStrokeCountForOptions(e){let t;if(e){const n=this.maxVectorLength();t=e.applyTolerancesToArc(n,this._sweep.sweepRadians)}else t=st.applyAngleTol(void 0,1,this._sweep.sweepRadians);return t}dispatchToGeometryHandler(e){return e.handleArc3d(this)}clonePartialCurve(e,t){if(t<e){const i=this.clonePartialCurve(t,e);return i.reverseInPlace(),i}const n=this.clone();return n.sweep.setStartEndRadians(this.sweep.fractionToRadians(e),this.sweep.fractionToRadians(t)),n}cloneInRotatedBasis(e){const t=e.cos(),n=e.sin(),i=this._matrix.multiplyXY(t,n),s=this._matrix.multiplyXY(-n,t),r=me.createStartEndRadians(this._sweep.startRadians-e.radians,this._sweep.endRadians-e.radians);return B.create(this._center.clone(),i,s,r)}cloneAxisAligned(){const e=pe.create(this.center,this.perpendicularVector.crossProduct(v.unitX()));if(!e)return;const t=[];if(this.appendPlaneIntersectionPoints(e,t)!==2)return;const n=e.getNormalRef().dotProduct(this.perpendicularVector.crossProductStartEnd(this.center,t[0].point))>0?0:1,i=this.sweep.fractionToAngle(t[n].fraction),s=this.cloneInRotatedBasis(i);if(this.perpendicularVector.dotProduct(v.unitZ())<-f.smallAngleRadians){if(this.matrixRef.isSingular())return;const r=E.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(e,t){return e.announceClippedArcIntervals(this,t)}otherArcAsLocalVectors(e){const t=this._matrix.multiplyInverseXYZAsPoint3d(e.center.x-this.center.x,e.center.y-this.center.y,e.center.z-this.center.z),n=this._matrix.multiplyInverse(e.vector0),i=this._matrix.multiplyInverse(e.vector90);if(t&&n&&i)return{center:t,vector0:n,vector90:i,sweep:this.sweep.clone()}}static createFilletArc(e,t,n,i){const s=v.createStartEnd(t,e),r=v.createStartEnd(t,n),a=s.magnitude(),o=r.magnitude();if(s.normalizeInPlace()&&r.normalizeInPlace()){const c=s.plus(r);if(c.normalizeInPlace()){const d=r.minus(s),h=d.magnitude(),u=.5*h;if(!f.isSmallAngleRadians(u)){const g=Math.sqrt(1-u*u),m=u/g,p=Math.acos(u),x=i/u,_=i/m,I=_/a,S=_/o,A=t.plusScaled(c,x);return c.scaleInPlace(-i),d.scaleInPlace(i/h),{arc:B.create(A,c,d,me.createStartEndRadians(-p,p)),fraction10:I,fraction12:S,point:t.clone()}}}}return{fraction10:0,fraction12:0,point:t.clone()}}scaleAboutCenterInPlace(e){this._matrix.scaleColumnsInPlace(e,e,1)}areaToChordXY(e,t){const n=f.crossProductXYXY(this._matrix.coffs[0],this._matrix.coffs[3],this._matrix.coffs[1],this._matrix.coffs[4]),i=this._sweep.fractionToRadians(e),r=.5*(this._sweep.fractionToRadians(t)-i),a=Math.cos(r)*Math.sin(r);return(r-a)*n}constructOffsetXY(e){const t=Kt.create(e);if(this.isCircular||t.preserveEllipticalArcs){const i=this.cloneAtZ(),s=i.sweep.sweepRadians*i.matrixRef.coffs[8]>=0?1:-1,r=i.matrixRef.columnXMagnitude(),a=r-s*t.leftOffsetDistance,o=this.isCircular?r:i.matrixRef.columnYMagnitude(),c=this.isCircular?a:o-s*t.leftOffsetDistance;if(!f.isSmallMetricDistance(a)&&r*a>0&&(this.isCircular||!f.isSmallMetricDistance(c)&&o*c>0)){const d=a/r,h=this.isCircular?d:c/o;return i.matrixRef.scaleColumnsInPlace(d,h,1),i}return}const n=new Vs(this,t.leftOffsetDistance);return this.emitStrokableParts(n,t.strokeOptions),n.claimResult()}projectedParameterRange(e,t){return jt.findExtremeFractionsAlongDirection(this,e,t)}constructCircularArcChainApproximation(e){e||(e=zi.create());const n=_i.create(this).constructCircularArcChainApproximation(e);return!n&&this.isCircular?this.sweep.isFullCircle&&e.forcePath?Te.create(this):this:n}computeTangentIntersection(e=0,t=1,n){const i=this.fractionToPointAndDerivative(e,B._workRay0),s=this.fractionToPointAndDerivative(t,B._workRay1);if(i.direction.isParallelTo(s.direction,!0,!0))return;const r=i.clone(B._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 a=Le.lineXYUVTransverseIntersection(i.origin,i.direction,s.origin,s.direction);if(a)return r.fractionToPoint(a.x,n)}}}class Ne{_coffs;constructor(){this._coffs=new Float64Array(16)}setFrom(e){for(let t=0;t<16;t++)this._coffs[t]=e._coffs[t]}clone(e){if(e===this)return this;e===void 0&&(e=new Ne);for(let t=0;t<16;t++)e._coffs[t]=this._coffs[t];return e}setZero(){for(let e=0;e<16;e++)this._coffs[e]=0}setIdentity(){for(let e=0;e<16;e++)this._coffs[e]=0;this._coffs[0]=this._coffs[5]=this._coffs[10]=this._coffs[15]=1}static is1000(e,t,n,i,s){return Math.abs(e-1)<=s&&Math.abs(t)<=s&&Math.abs(n)<=s&&Math.abs(i)<=s}isIdentity(e=1e-10){return Ne.is1000(this._coffs[0],this._coffs[1],this._coffs[2],this._coffs[3],e)&&Ne.is1000(this._coffs[5],this._coffs[6],this._coffs[7],this._coffs[4],e)&&Ne.is1000(this._coffs[10],this._coffs[11],this._coffs[8],this._coffs[9],e)&&Ne.is1000(this._coffs[15],this._coffs[12],this._coffs[13],this._coffs[14],e)}static createZero(e){return e?(e.setZero(),e):new Ne}static createRowValues(e,t,n,i,s,r,a,o,c,d,h,u,g,m,p,x,_){return _=_||new Ne,_._coffs[0]=e,_._coffs[1]=t,_._coffs[2]=n,_._coffs[3]=i,_._coffs[4]=s,_._coffs[5]=r,_._coffs[6]=a,_._coffs[7]=o,_._coffs[8]=c,_._coffs[9]=d,_._coffs[10]=h,_._coffs[11]=u,_._coffs[12]=g,_._coffs[13]=m,_._coffs[14]=p,_._coffs[15]=x,_}static createRows(e,t,n,i,s){return this.createRowValues(e.x,e.y,e.z,e.w,t.x,t.y,t.z,t.w,n.x,n.y,n.z,n.w,i.x,i.y,i.z,i.w,s)}setOriginAndVectors(e,t,n,i){this._coffs[0]=t.x,this._coffs[1]=n.x,this._coffs[2]=i.x,this._coffs[3]=e.x,this._coffs[4]=t.y,this._coffs[5]=n.y,this._coffs[6]=i.y,this._coffs[7]=e.y,this._coffs[8]=t.z,this._coffs[9]=n.z,this._coffs[10]=i.z,this._coffs[11]=e.z,this._coffs[12]=0,this._coffs[13]=0,this._coffs[14]=0,this._coffs[15]=1}static createTransform(e,t){const n=e.matrix,i=e.origin;return Ne.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,t)}static createIdentity(e){return e=Ne.createZero(e),e._coffs[0]=1,e._coffs[5]=1,e._coffs[10]=1,e._coffs[15]=1,e}static createTranslationXYZ(e,t,n,i){return i=Ne.createZero(i),i._coffs[0]=1,i._coffs[5]=1,i._coffs[10]=1,i._coffs[15]=1,i._coffs[3]=e,i._coffs[7]=t,i._coffs[11]=n,i}plusScaled(e,t,n){n=this.clone(n);for(let i=0;i<16;i++)n._coffs[i]+=t*e._coffs[i];return n}static createTranslationAndScaleXYZ(e,t,n,i,s,r,a){return Ne.createRowValues(i,0,0,e,0,s,0,t,0,0,r,n,0,0,0,1,a)}static createBoxToBox(e,t,n,i,s){const r=t.x-e.x,a=t.y-e.y,o=t.z-e.z,c=i.x-n.x,d=i.y-n.y,h=i.z-n.z,u=f.conditionalDivideFraction(c,r),g=f.conditionalDivideFraction(d,a),m=f.conditionalDivideFraction(h,o);if(u!==void 0&&g!==void 0&&m!==void 0)return Ne.createTranslationAndScaleXYZ(n.x-u*e.x,n.y-g*e.y,n.z-m*e.z,u,g,m,s)}setFromJSON(e){if(f.isArrayOfNumberArray(e,4,4))for(let t=0;t<4;++t)for(let n=0;n<4;++n)this._coffs[t*4+n]=e[t][n];else this.setZero()}maxDiff(e){let t=0;for(let n=0;n<16;n++)t=Math.max(t,Math.abs(this._coffs[n]-e._coffs[n]));return t}maxAbs(){let e=0;for(let t=0;t<16;t++)e=Math.max(e,Math.abs(this._coffs[t]));return e}isAlmostEqual(e){return f.isSmallMetricDistance(this.maxDiff(e))}isExactEqual(e){return this.maxDiff(e)===0}toJSON(){const e=[];for(let t=0;t<4;++t){const n=t*4;e.push([this._coffs[n],this._coffs[n+1],this._coffs[n+2],this._coffs[n+3]])}return e}static fromJSON(e){const t=new Ne;return t.setFromJSON(e),t}getSteppedPoint(e,t,n){return Z.create(this._coffs[e],this._coffs[e+t],this._coffs[e+2*t],this._coffs[e+3*t],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 E.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(e){const t=X.createIdentity(e);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++)t.matrix.setAt(s,r,i*this.atIJ(s,r));t.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:t,isValid:n}}multiplyMatrixMatrix(e,t){t=t&&t!==this&&t!==e?t:new Ne;for(let n=0;n<16;n+=4)for(let i=0;i<4;i++)t._coffs[n+i]=this._coffs[n]*e._coffs[i]+this._coffs[n+1]*e._coffs[i+4]+this._coffs[n+2]*e._coffs[i+8]+this._coffs[n+3]*e._coffs[i+12];return t}multiplyMatrixMatrixTranspose(e,t){t=t&&t!==this&&t!==e?t:new Ne;let n=0;for(let i=0;i<16;i+=4)for(let s=0;s<16;s+=4)t._coffs[n++]=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];return t}multiplyMatrixTransposeMatrix(e,t){t=t&&t!==this&&t!==e?t:new Ne;let n=0;for(let i=0;i<4;i+=1)for(let s=0;s<4;s+=1)t._coffs[n++]=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];return t}cloneTransposed(e){return Ne.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],e)}multiplyXYZW(e,t,n,i,s){return s=s||Z.createZero(),s.set(this._coffs[0]*e+this._coffs[1]*t+this._coffs[2]*n+this._coffs[3]*i,this._coffs[4]*e+this._coffs[5]*t+this._coffs[6]*n+this._coffs[7]*i,this._coffs[8]*e+this._coffs[9]*t+this._coffs[10]*n+this._coffs[11]*i,this._coffs[12]*e+this._coffs[13]*t+this._coffs[14]*n+this._coffs[15]*i)}multiplyBlockedFloat64ArrayInPlace(e){const t=e.length;let n,i,s,r;for(let a=0;a+3<t;a+=4)n=e[a],i=e[a+1],s=e[a+2],r=e[a+3],e[a]=this._coffs[0]*n+this._coffs[1]*i+this._coffs[2]*s+this._coffs[3]*r,e[a+1]=this._coffs[4]*n+this._coffs[5]*i+this._coffs[6]*s+this._coffs[7]*r,e[a+2]=this._coffs[8]*n+this._coffs[9]*i+this._coffs[10]*s+this._coffs[11]*r,e[a+3]=this._coffs[12]*n+this._coffs[13]*i+this._coffs[14]*s+this._coffs[15]*r}multiplyPoint3d(e,t,n){return this.multiplyXYZW(e.x,e.y,e.z,t,n)}multiplyPoint3dArray(e,t,n=1){e.forEach((i,s)=>{t[s]=this.multiplyXYZW(i.x,i.y,i.z,n,t[s])})}multiplyTransposeXYZW(e,t,n,i,s){return s=s||Z.createZero(),s.set(this._coffs[0]*e+this._coffs[4]*t+this._coffs[8]*n+this._coffs[12]*i,this._coffs[1]*e+this._coffs[5]*t+this._coffs[9]*n+this._coffs[13]*i,this._coffs[2]*e+this._coffs[6]*t+this._coffs[10]*n+this._coffs[14]*i,this._coffs[3]*e+this._coffs[7]*t+this._coffs[11]*n+this._coffs[15]*i)}rowDotColumn(e,t,n){const i=e*4,s=n;return this._coffs[i]*t._coffs[s]+this._coffs[i+1]*t._coffs[s+4]+this._coffs[i+2]*t._coffs[s+8]+this._coffs[i+3]*t._coffs[s+12]}rowDotXYZW(e,t,n,i,s){const r=e*4;return this._coffs[r]*t+this._coffs[r+1]*n+this._coffs[r+2]*i+this._coffs[r+3]*s}rowDotRow(e,t,n){const i=e*4,s=n*4;return 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]}columnDotColumn(e,t,n){const i=e,s=n;return 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]}columnDotRow(e,t,n){const i=e,s=4*n;return this._coffs[i]*t._coffs[s]+this._coffs[i+4]*t._coffs[s+1]+this._coffs[i+8]*t._coffs[s+2]+this._coffs[i+12]*t._coffs[s+3]}atIJ(e,t){return this._coffs[e*4+t]}setAtIJ(e,t,n){this._coffs[e*4+t]=n}multiplyXYZWQuietRenormalize(e,t,n,i,s){s=s||y.createZero(),s.set(this._coffs[0]*e+this._coffs[1]*t+this._coffs[2]*n+this._coffs[3]*i,this._coffs[4]*e+this._coffs[5]*t+this._coffs[6]*n+this._coffs[7]*i,this._coffs[8]*e+this._coffs[9]*t+this._coffs[10]*n+this._coffs[11]*i);const r=this._coffs[12]*e+this._coffs[13]*t+this._coffs[14]*n+this._coffs[15]*i,a=f.conditionalDivideCoordinate(s.x,r),o=f.conditionalDivideCoordinate(s.y,r),c=f.conditionalDivideCoordinate(s.z,r);return a!==void 0&&o!==void 0&&c!==void 0&&(s.x=a,s.y=o,s.z=c),s}multiplyPoint4dArrayQuietRenormalize(e,t){e.forEach((n,i)=>{t[i]=this.multiplyXYZWQuietRenormalize(n.x,n.y,n.z,n.w,t[i])})}multiplyPoint4d(e,t){return this.multiplyXYZW(e.xyzw[0],e.xyzw[1],e.xyzw[2],e.xyzw[3],t)}multiplyTransposePoint4d(e,t){return this.multiplyTransposeXYZW(e.xyzw[0],e.xyzw[1],e.xyzw[2],e.xyzw[3],t)}multiplyPoint3dQuietNormalize(e,t){return this.multiplyXYZWQuietRenormalize(e.x,e.y,e.z,1,t)}multiplyPoint3dArrayQuietNormalize(e){e.forEach(t=>this.multiplyXYZWQuietRenormalize(t.x,t.y,t.z,1,t))}addMomentsInPlace(e,t,n,i){this._coffs[0]+=e*e,this._coffs[1]+=e*t,this._coffs[2]+=e*n,this._coffs[3]+=e*i,this._coffs[4]+=t*e,this._coffs[5]+=t*t,this._coffs[6]+=t*n,this._coffs[7]+=t*i,this._coffs[8]+=n*e,this._coffs[9]+=n*t,this._coffs[10]+=n*n,this._coffs[11]+=n*i,this._coffs[12]+=i*e,this._coffs[13]+=i*t,this._coffs[14]+=i*n,this._coffs[15]+=i*i}addScaledInPlace(e,t=1){for(let n=0;n<16;n++)this._coffs[n]+=t*e._coffs[n]}rowOperation(e,t,n,i){if(i===0)return;let s=e*4+n,r=t*4+n;for(let a=n;a<4;a++,s++,r++)this._coffs[r]+=i*this._coffs[s]}determinant(){const e=this._coffs;return f.determinant4x4(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15])}createInverse(e){let t=this.columnX().maxAbs();if(t===0)return;const n=1/t;if(t=this.columnY().maxAbs(),t===0)return;const i=1/t;if(t=this.columnZ().maxAbs(),t===0)return;const s=1/t;if(t=this.columnW().maxAbs(),t===0)return;const r=1/t,a=this.columnX(),o=this.columnY(),c=this.columnZ(),d=this.columnW();a.scale(n,a),o.scale(i,o),c.scale(s,c),d.scale(r,d);const h=Z.perpendicularPoint4dPlane(o,c,d),u=Z.perpendicularPoint4dPlane(a,d,c),g=Z.perpendicularPoint4dPlane(d,a,o),m=Z.perpendicularPoint4dPlane(c,o,a);e=Ne.createRows(h,u,g,m,e);const p=h.dotProduct(a),x=u.dotProduct(o),_=g.dotProduct(c),I=m.dotProduct(d),S=e.maxAbs();if(p*x>0&&p*_>0&&p*I>0){if(f.conditionalDivideCoordinate(S,p)!==void 0){const w=1/p;return e.scaleRowsInPlace(n*w,i*w,s*w,r*w),e}}else return}rowArrays(e){return e?[[e(this._coffs[0]),e(this._coffs[1]),e(this._coffs[2]),e(this._coffs[3])],[e(this._coffs[4]),e(this._coffs[5]),e(this._coffs[6]),e(this._coffs[7])],[e(this._coffs[8]),e(this._coffs[9]),e(this._coffs[10]),e(this._coffs[11])],[e(this._coffs[12]),e(this._coffs[13]),e(this._coffs[14]),e(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(e,t,n,i){for(let s=0;s<4;s++)this._coffs[s]*=e;for(let s=4;s<8;s++)this._coffs[s]*=t;for(let s=8;s<12;s++)this._coffs[s]*=n;for(let s=12;s<16;s++)this._coffs[s]*=i}addScaledOuterProductInPlace(e,t,n){let i=e.x*n;this._coffs[0]+=i*t.x,this._coffs[1]+=i*t.y,this._coffs[2]+=i*t.z,this._coffs[3]+=i*t.w,i=e.y*n,this._coffs[4]+=i*t.x,this._coffs[5]+=i*t.y,this._coffs[6]+=i*t.z,this._coffs[7]+=i*t.w,i=e.z*n,this._coffs[8]+=i*t.x,this._coffs[9]+=i*t.y,this._coffs[10]+=i*t.z,this._coffs[11]+=i*t.w,i=e.w*n,this._coffs[12]+=i*t.x,this._coffs[13]+=i*t.y,this._coffs[14]+=i*t.z,this._coffs[15]+=i*t.w}addTranslationSandwichInPlace(e,t,n,i,s){const r=e._coffs[3],a=e._coffs[7],o=e._coffs[11],c=e._coffs[12],d=e._coffs[13],h=e._coffs[14],u=e._coffs[15],g=t*u,m=n*u,p=i*u;this._coffs[0]+=s*(e._coffs[0]+t*r+c*t+t*g),this._coffs[1]+=s*(e._coffs[1]+n*r+d*t+t*m),this._coffs[2]+=s*(e._coffs[2]+i*r+h*t+t*p),this._coffs[3]+=s*(r+g),this._coffs[4]+=s*(e._coffs[4]+t*a+c*n+n*g),this._coffs[5]+=s*(e._coffs[5]+n*a+d*n+n*m),this._coffs[6]+=s*(e._coffs[6]+i*a+h*n+n*p),this._coffs[7]+=s*(a+m),this._coffs[8]+=s*(e._coffs[8]+t*o+c*i+i*g),this._coffs[9]+=s*(e._coffs[9]+n*o+d*i+i*m),this._coffs[10]+=s*(e._coffs[10]+i*o+h*i+i*p),this._coffs[11]+=s*(o+p),this._coffs[12]+=s*(c+g),this._coffs[13]+=s*(d+m),this._coffs[14]+=s*(h+p),this._coffs[15]+=s*u}multiplyTranslationSandwichInPlace(e,t,n){const i=this._coffs[3],s=this._coffs[7],r=this._coffs[11],a=this._coffs[12],o=this._coffs[13],c=this._coffs[14],d=this._coffs[15],h=e*d,u=t*d,g=n*d;this._coffs[0]+=e*i+a*e+e*h,this._coffs[1]+=t*i+o*e+e*u,this._coffs[2]+=n*i+c*e+e*g,this._coffs[3]+=h,this._coffs[4]+=e*s+a*t+t*h,this._coffs[5]+=t*s+o*t+t*u,this._coffs[6]+=n*s+c*t+t*g,this._coffs[7]+=u,this._coffs[8]+=e*r+a*n+n*h,this._coffs[9]+=t*r+o*n+n*u,this._coffs[10]+=n*r+c*n+n*g,this._coffs[11]+=g,this._coffs[12]+=h,this._coffs[13]+=u,this._coffs[14]+=g}}class sa{xTest;yTest;u0;v0;u1;v1;numLeftCrossing;numRightCrossing;numHit;constructor(e,t){this.xTest=e,this.yTest=t,this.u0=this.v0=this.u1=this.v1=0,this.numLeftCrossing=this.numRightCrossing=0,this.numHit=0}tryStartEdge(e,t,n,i){return t!==this.yTest?(this.u0=e-this.xTest,this.v0=t-this.yTest,this.u1=n-this.xTest,this.v1=i-this.yTest,!0):!1}updateUV01(e,t){return this.u0=this.u1,this.v0=this.v1,this.u1=e,this.v1=t,!0}advance(e,t){const n=e-this.xTest,i=t-this.yTest,s=i*this.v1;if(s>0)return this.updateUV01(n,i);if(s<0){const a=-this.v1/(i-this.v1),o=this.u1+a*(n-this.u1);return o===0?(this.numHit++,!1):(o>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 rt{constructor(e,t,n){this._toleranceSquared=n*n,this._source=e,this._dest=t}_source;_dest;_toleranceSquared;acceptPointByIndex(e){const t=this._source.getPoint3dAtCheckedPointIndex(this._source.cyclicIndex(e));t&&this._dest.push(t)}static _vector01=v.create();static _vectorQ=v.create();indexOfMaxCrossProduct(e,t){let n=0,i,s;for(let r=e;r<=t;r++){const a=this._source.cyclicIndex(r),o=this._source.cyclicIndex(r+1),c=this._source.cyclicIndex(r+2);this._source.crossProductIndexIndexIndex(a,o,c,rt._vectorQ),i=rt._vectorQ.magnitudeSquared(),i>n&&(n=i,s=r)}return s}indexOfMaxDeviation(e,t){const n=this._source.cyclicIndex(e),i=this._source.cyclicIndex(t);let s=this._toleranceSquared,r,a,o,c,d;this._source.vectorUncheckedIndexIndex(n,i,rt._vector01);const h=rt._vector01.magnitudeSquared();for(let u=e+1;u<t;u++)d=this._source.cyclicIndex(u),this._source.vectorIndexIndex(n,d,rt._vectorQ),a=rt._vector01.dotProduct(rt._vectorQ),a<=0?o=rt._vectorQ.magnitudeSquared():a>h?(this._source.vectorIndexIndex(i,d,rt._vectorQ),o=rt._vectorQ.magnitudeSquared()):(c=a/h,o=rt._vectorQ.magnitudeSquared()-h*c*c),o>s&&(s=o,r=u);return r}recursiveCompressByChordErrorGo(e,t){if(t===e+1){this.acceptPointByIndex(t);return}const n=this.indexOfMaxDeviation(e,t);n===void 0?this.acceptPointByIndex(t):(this.recursiveCompressByChordErrorGo(e,n),this.recursiveCompressByChordErrorGo(n,t))}static compressPoint3dArrayByChordError(e,t=f.smallMetricDistance,n=!1){const i=new Qe(e),s=new Qe([]);return this.compressCollectionByChordError(i,s,t,n),s.data}static compressCollectionByChordError(e,t,n=f.smallMetricDistance,i=!1){t.clear();const s=e.length;if(s===1){t.push(e.getPoint3dAtUncheckedPointIndex(0));return}const r=new rt(e,t,n);let a=0,o=s-1;if(s>2&&!i&&e.distanceUncheckedIndexIndex(0,s-1)<=n){const c=r.indexOfMaxCrossProduct(0,s-1);c!==void 0&&(a=c+1,o=a+s)}r.acceptPointByIndex(a),r.recursiveCompressByChordErrorGo(a,o)}static compressInPlaceByShortEdgeLength(e,t){const n=e.length;if(n<2)return;let i=0,s=n-1;for(;s>0&&e.distanceUncheckedIndexIndex(s-1,n-1)<=t;)s--;if(s===0){e.length=1;return}s<n-1&&e.moveIndexToIndex(n-1,s);let r=i+1;for(;r<=s;)e.distanceUncheckedIndexIndex(i,r)>t&&(e.moveIndexToIndex(r,i+1),i++),r++;e.length=i+1}static compressInPlaceBySmallTriangleArea(e,t){const n=e.length;if(n<3)return;let i=0;const s=v.create();for(let r=1;r+1<n;r++)e.crossProductIndexIndexIndex(i,r,r+1,s),.5*s.magnitude()>t&&e.moveIndexToIndex(r,++i);e.moveIndexToIndex(n-1,++i),e.length=i+1}static compressInPlaceByPerpendicularDistance(e,t,n=1.0001){const i=e.length;if(i<3)return;let s=0;const r=rt._vector01,a=rt._vectorQ;let o;const c=t*t;let d,h=1;for(;h+1<i;h++){e.vectorIndexIndex(s,h+1,r),e.vectorIndexIndex(s,h,a),d=r.magnitudeSquared();const u=f.conditionalDivideFraction(a.dotProduct(r),d);if(u!==void 0&&u>=0&&u<=n&&(o=rt._vectorQ.magnitudeSquared()-d*u*u,o<=c)){e.moveIndexToIndex(h+1,++s),h=h+1;continue}e.moveIndexToIndex(h,++s)}h<i&&e.moveIndexToIndex(h,++s),e.length=s+1}static compressColinearWrapInPlace(e,t,n){const i=e.length-1;if(i>=3&&e[0].distance(e[i])<t){const s=i-1,r=0,o=v.createStartEnd(e[s],e[1]),c=v.createStartEnd(e[s],e[r]),d=o.dotProduct(o),h=o.dotProduct(c),u=f.conditionalDivideFraction(h,d);if(u!==void 0&&u>0&&u<1){const g=c.magnitudeSquared()-u*u*d;Math.sqrt(Math.abs(g))<n&&(e[0]=e[s],e.pop())}}}}class He extends _e{curveCollectionType="parityRegion";isSameGeometryClass(e){return e instanceof He}_children;get children(){return this._children}constructor(){super(),this._children=[]}addLoops(e){if(e!==void 0){if(e instanceof oe)this.children.push(e);else if(Array.isArray(e))for(const t of e)t instanceof oe?this.children.push(t):Array.isArray(t)&&this.addLoops(t)}}static createLoops(e){if(e instanceof oe)return e;const t=new He;return t.addLoops(e),t}static create(...e){const t=new He;for(const n of e)t.children.push(n);return t}dgnBoundaryType(){return 4}announceToCurveProcessor(e,t=-1){return e.announceParityRegion(this,t)}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}cloneStroked(e){const t=new He;let n;for(n of this.children){const i=n.cloneStroked(e);i&&t.children.push(i)}return t}cloneEmptyPeer(){return new He}tryAddChild(e){return e&&e instanceof oe?(this._children.push(e),!0):!1}getChild(e){if(e<this._children.length)return this._children[e]}dispatchToGeometryHandler(e){return e.handleParityRegion(this)}}class Et extends _e{curveCollectionType="unionRegion";isSameGeometryClass(e){return e instanceof Et}_children;get children(){return this._children}constructor(){super(),this._children=[]}static create(...e){const t=new Et;for(const n of e)t.tryAddChild(n);return t}dgnBoundaryType(){return 5}announceToCurveProcessor(e,t=-1){return e.announceUnionRegion(this,t)}cloneStroked(e){const t=new Et;let n;for(n of this._children){const i=n.cloneStroked(e);i&&t.children.push(i)}return t}cloneEmptyPeer(){return new Et}clone(){return super.clone()}cloneTransformed(e){return super.cloneTransformed(e)}cloneWithExpandedLineStrings(){return super.cloneWithExpandedLineStrings()}tryAddChild(e){return e&&(e instanceof He||e instanceof oe)?(this._children.push(e),!0):!1}getChild(e){if(e<this._children.length)return this._children[e]}dispatchToGeometryHandler(e){return e.handleUnionRegion(this)}}class fo{searchFractions=[.2349,.4142,.6587,.8193];constructInteriorPoint(e){if(e.direction.z=0,!e.direction.normalizeInPlace())return;e.direction.rotate90CCWXY(e.direction),this.signedArea<0&&e.direction.scaleInPlace(-1);const t=Math.sqrt(Math.abs(this.signedArea)),n=y.create();for(let i=1e-5;i<3;i*=5)if(e.fractionToPoint(i*t,n),this.classifyPointXY(n)===1)return n}}class Rc extends fo{data;_signedArea;get signedArea(){return this._signedArea}constructor(e){super(),this.data=e,this._signedArea=re.areaXY(e)}classifyPointXY(e){return re.classifyPointInPolygonXY(e.x,e.y,this.data)}getAnyInteriorPoint(){for(let e=0;e<this.data.length;e++)for(const t of this.searchFractions){const n=this.constructInteriorPointNearEdge(e,t);if(n!==void 0)return n}}grabPolygon(){return this.data}grabLoop(){return oe.createPolygon(this.data)}reverseForAreaSign(e){e*this._signedArea<0&&(this.data.reverseInPlace(),this._signedArea*=-1)}constructInteriorPointNearEdge(e,t){if(0<=e&&e+1<this.data.length){const n=q.createCapture(this.data.interpolateUncheckedIndexIndex(e,t,e+1),this.data.vectorUncheckedIndexIndex(e,e+1));return this.constructInteriorPoint(n)}}}class Mc extends fo{data;_signedArea;get signedArea(){return this._signedArea}constructor(e){super(),this.data=e;const t=ge.computeXYAreaMoments(e);this._signedArea=t!==void 0?t.quantitySum:0}classifyPointXY(e){return ge.testPointInOnOutRegionXY(this.data,e.x,e.y)}constructInteriorPointNearChild(e,t){if(e<this.data.children.length){const n=this.data.children[e].fractionToPointAndDerivative(t);return this.constructInteriorPoint(n)}}getAnyInteriorPoint(){for(let e=0;e<this.data.children.length;e++)for(const t of this.searchFractions){const n=this.constructInteriorPointNearChild(e,t);if(n!==void 0)return n}}grabPolygon(){const e=this.data.cloneStroked(),t=N.create();for(const n of e.children)n.emitStrokes(t);return t.packedPoints}grabLoop(){return this.data}reverseForAreaSign(e){e*this._signedArea<0&&(this.data.reverseChildrenInPlace(),this._signedArea*=-1)}}class ai{_loopCarrier;anyPoint;sortKey;range;parentIndex;isHole;outputSetIndex;constructor(e,t){e instanceof Fs?this._loopCarrier=new Rc(e):this._loopCarrier=new Mc(e),this.range=t,this.sortKey=Math.abs(this._loopCarrier.signedArea),this.isHole=!1}static pushPolygon(e,t){const n=t.getRange(),i=new ai(t,n);return i.sortKey>0?(e.push(i),!0):!1}static pushLoop(e,t){const n=t.range(),i=new ai(t,n);return i.sortKey>0?(e.push(i),!0):!1}static assignParentsAndDepth(e){e.sort((t,n)=>n.sortKey-t.sortKey);for(let t=e.length;t-- >0;){const n=e[t],i=n._loopCarrier.getAnyInteriorPoint();if(i!==void 0){n.parentIndex=n.outputSetIndex=void 0;for(let s=t;s-- >0;){const r=e[s];if(r.range.containsXY(i.x,i.y)&&r._loopCarrier.classifyPointXY(i)===1){n.parentIndex=s;break}}}}}static assemblePolygonSet(e){const t=[];for(const n of e){n.isHole=!1;const i=n.parentIndex;if(i!==void 0&&(n.isHole=!e[i].isHole),!n.isHole)n._loopCarrier.reverseForAreaSign(1),n.outputSetIndex=t.length,t.push([]),t[n.outputSetIndex].push(n._loopCarrier.grabPolygon());else{n._loopCarrier.reverseForAreaSign(-1);const s=e[i].outputSetIndex;t[s].push(n._loopCarrier.grabPolygon())}}return t}static assembleLoopSet(e){const t=[],n=e.length;for(let i=0;i<n;i++){const s=e[i],r=s.parentIndex;if(s.isHole=r!==void 0?!e[r].isHole:!1,!s.isHole){s._loopCarrier.reverseForAreaSign(1);const a=s._loopCarrier.grabLoop();let o;for(let c=i+1;c<n;c++){const d=e[c];d.parentIndex===i&&(o===void 0?(o=He.create(),o.tryAddChild(a),d._loopCarrier.reverseForAreaSign(-1),o.tryAddChild(d._loopCarrier.grabLoop())):(d._loopCarrier.reverseForAreaSign(-1),o.tryAddChild(d._loopCarrier.grabLoop())))}o!==void 0?t.push(o):t.push(a)}}return t}static sortAsAnyRegion(e){this.assignParentsAndDepth(e);const t=this.assembleLoopSet(e);if(t.length===1)return t[0];{const n=Et.create();for(const i of t)n.tryAddChild(i);return n}}static sortAsArrayOfArrayOfPolygons(e){return this.assignParentsAndDepth(e),this.assemblePolygonSet(e)}grabPolygon(){return this._loopCarrier.grabPolygon()}grabLoop(){return this._loopCarrier.grabLoop()}reverseForAreaSign(e){this._loopCarrier.reverseForAreaSign(e)}getAnyInteriorPoint(){return this._loopCarrier.getAnyInteriorPoint()}}class Ye{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=Ne.createZero(),this.localToWorldMap=X.createIdentity(),this.radiusOfGyration=v.create(),this.absoluteQuantity=.1,this.absoluteQuantity=void 0}get quantitySum(){return this.sums.weight()}signFactor(e){return e*this.quantitySum>0?1:-1}setOriginIfNeeded(e){this.needOrigin&&(this.origin.setFromPoint3d(e),this.needOrigin=!1)}setOriginFromGrowableXYZArrayIfNeeded(e){this.needOrigin&&e.length>0&&(e.getPoint3dAtCheckedPointIndex(0,this.origin),this.needOrigin=!1)}setOriginXYZIfNeeded(e,t,n){this.needOrigin&&(this.origin.set(e,t,n),this.needOrigin=!1)}static create(e,t=!1){const n=new Ye;return n.needOrigin=t,e&&(n.origin.setFromPoint3d(e),n.needOrigin=!1),n}static momentTensorFromInertiaProducts(e){const t=e.sumDiagonal(),n=E.createScale(t,t,t);return n.addScaledInPlace(e,-1),n}static sortColumnsForIncreasingMoments(e,t){const n=[e.indexedColumnWithWeight(0,t.x),e.indexedColumnWithWeight(1,t.y),e.indexedColumnWithWeight(2,t.z)].sort((i,s)=>i.w<s.w?-1:i.w>s.w?1:0);e.setColumnsPoint4dXYZ(n[0],n[1],n[2]),e.determinant()<0&&e.scaleColumnsInPlace(-1,-1,-1),e.at(0,0)<0&&e.scaleColumnsInPlace(-1,-1,1),e.at(2,2)<0&&e.scaleColumnsInPlace(1,-1,-1),t.set(n[0].w,n[1].w,n[2].w)}static pointsToPrincipalAxes(e){const t=new Ye;return e.length===0?t:(t.clearSums(e[0]),t.accumulatePointMomentsFromOrigin(e),this.inertiaProductsToPrincipalAxes(t.origin,t.sums))}static inertiaProductsToPrincipalAxes(e,t){const n=new Ye;if(n.sums.setFrom(t),n.origin.setFrom(e),!n.shiftOriginAndSumsToCentroidOfSums())return;const i=n.sums.matrixPart(),s=n.sums.weight();s<0&&i.scaleColumnsInPlace(-1,-1,-1);const r=Ye.momentTensorFromInertiaProducts(i),a=v.create(),o=E.createZero();if(r.fastSymmetricEigenvalues(o,a),!(a.x<0))return Ye.sortColumnsForIncreasingMoments(o,a),s<0&&o.scaleColumnsInPlace(1,-1,-1),n.localToWorldMap=X.createOriginAndMatrix(n.origin,o),n.radiusOfGyration.set(Math.sqrt(Math.abs(a.x)),Math.sqrt(Math.abs(a.y)),Math.sqrt(Math.abs(a.z))),n.radiusOfGyration.scaleInPlace(1/Math.sqrt(Math.abs(s))),n.absoluteQuantity=Math.abs(s),n}static areEquivalentPrincipalAxes(e,t){if(e&&t&&f.isSameCoordinate(e.quantitySum,t.quantitySum)&&e.localToWorldMap.getOrigin().isAlmostEqual(t.localToWorldMap.getOrigin())&&e.radiusOfGyration.isAlmostEqual(t.radiusOfGyration)){if(f.isSameCoordinate(e.radiusOfGyration.x,e.radiusOfGyration.y)){if(f.isSameCoordinate(e.radiusOfGyration.x,e.radiusOfGyration.z))return!0;const s=e.localToWorldMap.matrix.columnZ(),r=t.localToWorldMap.matrix.columnZ();return!!s.isParallelTo(r,!0)}const n=v.create(),i=v.create();for(let s=0;s<3;s++)if(e.localToWorldMap.matrix.getColumn(s,n),t.localToWorldMap.matrix.getColumn(s,i),!n.isParallelTo(i,!0))return!1;return!0}return!1}clearSums(e){this.sums.setZero(),e?this.origin.setFrom(e):this.origin.setZero()}accumulatePointMomentsFromOrigin(e){for(const t of e)this.sums.addMomentsInPlace(t.x-this.origin.x,t.y-this.origin.y,t.z-this.origin.z,1)}shiftOriginAndSumsToCentroidOfSums(){const e=this.sums.columnW().realPoint();return e?(this.shiftOriginAndSumsByXYZ(e.x,e.y,e.z),!0):!1}shiftOriginAndSumsByXYZ(e,t,n){this.origin.addXYZInPlace(e,t,n),this.sums.multiplyTranslationSandwichInPlace(-e,-t,-n)}shiftOriginAndSumsToNewOrigin(e){this.shiftOriginAndSumsByXYZ(e.x-this.origin.x,e.y-this.origin.y,e.z-this.origin.z)}accumulateTriangleMomentsXY(e,t,n){this.setOriginXYZIfNeeded(t.x,t.y,0);const i=this.origin.x,s=this.origin.y,r=Ye._vectorA=e!==void 0?Z.create(e.x-i,e.y-s,0,1,Ye._vectorA):Z.create(0,0,0,1,Ye._vectorA),a=Ye._vectorB=Z.create(t.x-i,t.y-s,0,1,Ye._vectorB),o=Ye._vectorC=Z.create(n.x-i,n.y-s,0,1,Ye._vectorC),c=f.crossProductXYXY(a.x-r.x,a.y-r.y,o.x-r.x,o.y-r.y);if(c!==0){const d=c/12,h=c/24;this.sums.addScaledOuterProductInPlace(r,r,d),this.sums.addScaledOuterProductInPlace(r,a,h),this.sums.addScaledOuterProductInPlace(r,o,h),this.sums.addScaledOuterProductInPlace(a,r,h),this.sums.addScaledOuterProductInPlace(a,a,d),this.sums.addScaledOuterProductInPlace(a,o,h),this.sums.addScaledOuterProductInPlace(o,r,h),this.sums.addScaledOuterProductInPlace(o,a,h),this.sums.addScaledOuterProductInPlace(o,o,d)}}accumulateScaledOuterProduct(e,t){this.setOriginXYZIfNeeded(e.x,e.y,0);const n=Ye._vectorA=Z.create(e.x-this.origin.x,e.y-this.origin.y,e.z-this.origin.z,1,Ye._vectorA);this.sums.addScaledOuterProductInPlace(n,n,t)}accumulateLineMomentsXYZ(e,t){this.setOriginXYZIfNeeded(e.x,e.y,e.z);const n=this.origin.x,i=this.origin.y,s=this.origin.z,r=Ye._vectorA=Z.create(e.x-n,e.y-i,e.z-s,1,Ye._vectorA),a=Ye._vectorB=Z.create(t.x-n,t.y-i,t.z-s,1,Ye._vectorB),o=e.distance(t),c=o/3,d=o/6;this.sums.addScaledOuterProductInPlace(r,r,c),this.sums.addScaledOuterProductInPlace(r,a,d),this.sums.addScaledOuterProductInPlace(a,r,d),this.sums.addScaledOuterProductInPlace(a,a,c)}accumulateTriangleToLineStringMomentsXY(e,t){const n=t.length;if(n>1){t.getPoint3dAtUncheckedPointIndex(0,this._point0);for(let i=1;i<n;i++)t.getPoint3dAtUncheckedPointIndex(i,this._point1),this.accumulateTriangleMomentsXY(e,this._point0,this._point1),this._point0.setFromPoint3d(this._point1)}}accumulateXYProductsInCentroidalFrame(e,t,n,i,s,r,a){const o=Ne.createRowValues(e,t,0,0,t,n,0,0,0,0,0,0,0,0,0,i),c=f.crossProductXYXY(r.x,a.x,r.y,a.y),d=Ne.createRowValues(r.x,a.x,0,s.x-this.origin.x,r.y,a.y,0,s.y-this.origin.y,0,0,0,0,0,0,0,1),u=d.multiplyMatrixMatrix(o).multiplyMatrixMatrixTranspose(d);this.sums.addScaledInPlace(u,c)}accumulateProducts(e,t){this.setOriginIfNeeded(e.origin),this.sums.addTranslationSandwichInPlace(e.sums,this.origin.x-e.origin.x,this.origin.y-e.origin.y,this.origin.z-e.origin.z,t)}accumulateProductsFromOrigin(e,t,n){this.setOriginIfNeeded(e),this.sums.addTranslationSandwichInPlace(t,this.origin.x-e.x,this.origin.y-e.y,this.origin.z-e.z,n)}toJSON(){return{origin:this.origin,sums:this.sums.toJSON(),radiusOfGyration:this.radiusOfGyration.toJSON(),localToWorld:this.localToWorldMap.toJSON()}}}class Qs extends zs{_geometry1;_fraction;constructor(e,t,n){super(),this._geometry1=n,this._fraction=t}handleLineSegment3d(e){if(this._geometry1 instanceof Q){const t=this._geometry1;return Q.create(e.startPoint().interpolate(this._fraction,t.startPoint()),e.endPoint().interpolate(this._fraction,t.endPoint()))}}handleLineString3d(e){if(this._geometry1 instanceof N){const t=this._geometry1;if(e.numPoints()===t.numPoints()){const n=e.numPoints(),i=N.create(),s=y.create(),r=y.create(),a=y.create(),o=this._fraction;for(let c=0;c<n;c++)e.pointAt(c,r),t.pointAt(c,a),r.interpolate(o,a,s),i.addPoint(s);if(e.fractions&&t.fractions)for(let c=0;c<n;c++)i.addFraction(f.interpolate(e.fractions.atUncheckedIndex(c),o,t.fractions.atUncheckedIndex(c)));if(e.strokeData&&t.strokeData&&(i.strokeData=e.strokeData.clone()),e.packedDerivatives&&t.packedDerivatives){const c=v.create(),d=v.create();for(let h=0;h<n;h++)e.packedDerivatives.getVector3dAtCheckedVectorIndex(h,c),t.packedDerivatives.getVector3dAtCheckedVectorIndex(h,d),i.addDerivative(c.interpolate(o,d))}return i}}}handleArc3d(e){if(this._geometry1 instanceof B){const t=this._geometry1;return B.create(e.center.interpolate(this._fraction,t.center),e.vector0.interpolate(this._fraction,t.vector0),e.vector90.interpolate(this._fraction,t.vector90),e.sweep.interpolate(this._fraction,t.sweep))}}static interpolateBetween(e,t,n){const i=new Qs(e,t,n);return e.dispatchToGeometryHandler(i)}}class ra extends Mt{geometryCategory="solid";_capped;constructor(e){super(),this._capped=e}get capped(){return this._capped}set capped(e){this._capped=e}get isSkew(){return!1}}class Pi extends ra{solidPrimitiveType="cone";_localToWorld;_radiusA;_radiusB;_maxRadius;constructor(e,t,n,i){super(i),this._localToWorld=e,this._radiusA=t,this._radiusB=n,this._maxRadius=Math.max(this._radiusA,this._radiusB)}clone(){return new Pi(this._localToWorld.clone(),this._radiusA,this._radiusB,this.capped)}getConstructiveFrame(){return this._localToWorld.cloneRigid()}tryTransformInPlace(e){return e.matrix.isSingular()?!1:(e.multiplyTransformTransform(this._localToWorld,this._localToWorld),e.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(e){const t=this.clone();return t.tryTransformInPlace(e)?t:void 0}static createAxisPoints(e,t,n,i,s){const r=e.vectorTo(t),a=r.magnitude();if(f.isSmallMetricDistance(a)||(n=f.correctSmallMetricDistance(n),i=f.correctSmallMetricDistance(i),n*i<0)||n+i===0)return;const o=E.createRigidHeadsUp(r);o.scaleColumns(1,1,a,o);const c=X.createOriginAndMatrix(e,o);return new Pi(c,n,i,s??!1)}static createBaseAndTarget(e,t,n,i,s,r,a){s=Math.abs(f.correctSmallMetricDistance(s)),r=Math.abs(f.correctSmallMetricDistance(r));const o=e.vectorTo(t),c=X.createOriginAndMatrixColumns(e,n,i,o);return new Pi(c,s,r,a??!1)}static createDgnCone(e,t,n,i,s,r,a){const o=E.createRigidFromColumns(n,i,ve.XYZ);if(o){const c=n.magnitude();return this.createBaseAndTarget(e,t,o.columnX(),o.columnY(),s*c,r*c,a)}}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(e){return f.interpolate(this._radiusA,e,this._radiusB)}isSameGeometryClass(e){return e instanceof Pi}isAlmostEqual(e){return e instanceof Pi?this.capped!==e.capped||!this._localToWorld.isAlmostEqualAllowZRotation(e._localToWorld)?!1:f.isSameCoordinate(this._radiusA,e._radiusA)&&f.isSameCoordinate(this._radiusB,e._radiusB):!1}dispatchToGeometryHandler(e){return e.handleCone(this)}strokeConstantVSection(e,t,n){let i=16;t!==void 0?i=t:n!==void 0&&(i=n.defaultCircleStrokes),i=f.clampToStartEnd(i,4,64);const s=this.vFractionToRadius(e),r=N.createForStrokes(t,n),a=Math.PI*2,o=a/i;let c=0;const d=r.fractions,h=r.packedDerivatives,u=r.packedUVParams,g=r.packedSurfaceNormals,m=y.create(),p=v.create(),x=v.create(),_=v.create(),I=this._localToWorld;let S,A,w,k;for(let D=0;D<=i;D++)D*2<=i?c=D*o:c=(D-i)*o,w=Math.cos(c),k=Math.sin(c),S=s*w,A=s*k,I.multiplyXYZ(S,A,e,m),r.addPoint(m),d&&d.push(D/i),h&&(I.matrix.multiplyXYZ(-A*a,S*a,0,p),h.push(p)),g&&(I.matrix.multiplyXYZ(-k,w,0,p),I.matrix.multiplyXYZ(0,0,1,x),p.unitCrossProduct(x,_),g.push(_)),u&&u.pushXY(D/i,e);return r}constantVSection(e){const t=this.vFractionToRadius(e),n=this._localToWorld,i=n.multiplyXYZ(0,0,e),s=n.matrix.multiplyXYZ(t,0,0),r=n.matrix.multiplyXYZ(0,t,0);return oe.create(B.create(i,s,r))}extendRange(e,t){const n=this.constantVSection(0),i=this.constantVSection(1);n.extendRange(e,t),i.extendRange(e,t)}uvFractionToPoint(e,t,n){const i=e*Math.PI*2,s=f.interpolate(this._radiusA,t,this._radiusB),r=Math.cos(i),a=Math.sin(i);return this._localToWorld.multiplyXYZ(s*r,s*a,t,n)}uvFractionToPointAndTangents(e,t,n){const i=e*Math.PI*2,s=f.interpolate(this._radiusA,t,this._radiusB),r=this._radiusB-this._radiusA,a=Math.cos(i),o=Math.sin(i),c=2*Math.PI;return ke.createOriginAndVectors(this._localToWorld.multiplyXYZ(s*a,s*o,t),this._localToWorld.multiplyVectorXYZ(-s*o*c,s*a*c,0),this._localToWorld.multiplyVectorXYZ(r*a,r*o,1),n)}get isSkew(){return!this._localToWorld.matrix.columnZ().isParallelTo(this._localToWorld.matrix.columnXCrossColumnY(),!0,!0)}cylinderRadius(e=!1){let t=0;if(e||!this.isSkew){const n=this._localToWorld.matrix.columnXMagnitude(),i=this._localToWorld.matrix.columnYMagnitude();f.isSameCoordinate(n,i)&&f.isSameCoordinate(this._radiusA,this._radiusB)&&(t=Math.abs(n*this._radiusA))}return t}get isClosedVolume(){return this.capped}maxIsoParametricDistance(){const e=this._localToWorld.matrix.columnX(),t=this._localToWorld.matrix.columnY(),n=e.unitCrossProduct(t);if(!n)return $.createZero();const i=this._localToWorld.matrix.columnZ(),s=n.dotProduct(i),a=i.plusScaled(n,s).magnitudeXY();return $.create(Math.PI*2*Math.max(this._radiusA,this._radiusB),f.hypotenuseXY(Math.abs(this._radiusB-this._radiusA)+a,s))}}class Dc{_cachedObjects;_numDrop;_numCreate;_numReuse;constructor(){this._cachedObjects=[],this._numDrop=0,this._numCreate=0,this._numReuse=0}dropToCache(e){e&&(this._numDrop++,this.clearForCache(e),this._cachedObjects.push(e))}grabFromCache(){let e=this._cachedObjects.pop();return e===void 0?(e=this.createForCache(),this._numCreate++):this._numReuse++,e}dropAllToCache(e){for(;e.length>0;)this.dropToCache(e.pop())}}class aa extends Dc{constructor(){super()}createForCache(e=10,t=1.5){return new J(e,t)}clearForCache(e){e.length=0}grabAndFill(e){const t=this.grabFromCache();return t.pushFrom(e),t}}class Js{_data;_inUse;_blockSize;_growthFactor;constructor(e,t=8,n){this._data=new Float64Array(t*e),this._inUse=0,this._blockSize=e>0?e:1,this._growthFactor=n!==void 0&&n>=1?n:1.5}copyData(e,t,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=t!==void 0?t*this.numPerBlock:e.length;return s>0&&(s>e.length&&(s=e.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===e.length?this._data.set(e,i):e instanceof Float64Array?this._data.set(e.subarray(0,s),i):this._data.set(e.slice(0,s),i),{count:s/this.numPerBlock,offset:i/this.numPerBlock})}clone(){const e=new Js(this.numPerBlock,this.numBlocks,this._growthFactor);return e.copyData(this._data,this.numBlocks),e._inUse=this.numBlocks,e}get length(){return this._inUse}get numBlocks(){return this._inUse}get numPerBlock(){return this._blockSize}getWithinBlock(e,t){return this._data[e*this._blockSize+t]}clear(){this._inUse=0}blockCapacity(){return this._data.length/this._blockSize}ensureBlockCapacity(e,t=!0){if(e>this.blockCapacity()){t&&(e*=this._growthFactor);const n=this._data;this._data=new Float64Array(e*this._blockSize),this.copyData(n,this._inUse)}}addBlock(e){const t=this.newBlockIndex();let n=e.length;n>this._blockSize&&(n=this._blockSize);for(let i=0;i<n;i++)this._data[t+i]=e[i]}newBlockIndex(){const e=this._blockSize*this._inUse;e+1>this._data.length&&this.ensureBlockCapacity(1+this._inUse),this._inUse++;for(let t=e;t<e+this._blockSize;t++)this._data[t]=0;return e}popBlock(){this._inUse>0&&this._inUse--}blockIndexToDoubleIndex(e){return this._blockSize*e}checkedComponent(e,t){if(!(e>=this._inUse||e<0||t<0||t>=this._blockSize))return this._data[this._blockSize*e+t]}component(e,t){return this._data[this._blockSize*e+t]}static compareLexicalBlock(e,t,n,i){let s=0,r=0;for(let a=0;a<t;a++){if(s=e[n+a],r=e[i+a],s>r)return 1;if(s<r)return-1}return n-i}sortIndicesLexical(e=(t,n,i,s)=>Js.compareLexicalBlock(t,n,i,s)){const t=this._inUse,n=new Uint32Array(t),i=this._data,s=this._blockSize;for(let r=0;r<t;r++)n[r]=r;return n.sort((r,a)=>e(i,s,r*s,a*s)),n}distanceBetweenBlocks(e,t){let n=0,i=this.blockIndexToDoubleIndex(e),s=this.blockIndexToDoubleIndex(t),r=0;const a=this._data;for(let o=0;o<this._blockSize;o++)r=a[i++]-a[s++],n+=r*r;return Math.sqrt(n)}distanceBetweenSubBlocks(e,t,n,i){let s=0;const r=this.blockIndexToDoubleIndex(e),a=this.blockIndexToDoubleIndex(t);let o=0;const c=this._data;for(let d=n;d<i;d++)o=c[r+d]-c[a+d],s+=o*o;return Math.sqrt(s)}}class Re extends Js{static _vectorFactor=.8732;static sortVectorComponent(e){let t=1;for(let n=1;n<e;n++)t*=Re._vectorFactor;return t}_numCoordinatePerPoint;_numExtraDataPerPoint;constructor(e,t,n){super(1+e+t,n),this._numExtraDataPerPoint=t,this._numCoordinatePerPoint=e}addBlock(e){const t=this.newBlockIndex()+1,n=Math.min(this.numPerBlock-1,e.length);for(let i=0;i<n;i++)this._data[t+i]=e[i]}addDirect(e,t,n,i,s){const r=this.newBlockIndex();this._data[r+1]=e,t!==void 0&&(this._data[r+2]=t),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(e,t,n,i){const s=this.newBlockIndex();this._data[s+1]=e.x,this._data[s+2]=e.y,t!==void 0&&(this._data[s+3]=t),n!==void 0&&(this._data[s+4]=n),i!==void 0&&(this._data[s+5]=i)}addPoint3d(e,t,n,i){const s=this.newBlockIndex();this._data[s+1]=e.x,this._data[s+2]=e.y,this._data[s+3]=e.z,t!==void 0&&(this._data[s+4]=t),n!==void 0&&(this._data[s+5]=n),i!==void 0&&(this._data[s+6]=i)}getPoint2d(e,t){const n=this.blockIndexToDoubleIndex(e);return L.create(this._data[n+1],this._data[n+2],t)}getPoint3d(e,t){const n=this.blockIndexToDoubleIndex(e);return y.create(this._data[n+1],this._data[n+2],this._data[n+3],t)}getExtraData(e,t){const n=this.blockIndexToDoubleIndex(e);return this._data[n+1+this._numCoordinatePerPoint+t]}getData(e,t){const n=this.blockIndexToDoubleIndex(e);return this._data[n+t]}setExtraData(e,t,n){const i=this.blockIndexToDoubleIndex(e);this._data[i+1+this._numCoordinatePerPoint+t]=n}static clusterTerminator=4294967295;static isClusterTerminator(e){return e===Re.clusterTerminator}clusterIndicesLexical(e=f.smallMetricDistance){this.setupPrimaryClusterSort();const t=this.sortIndicesLexical(),n=new Uint32Array(2*t.length);let i=0;const s=this.numBlocks;let r=0,a=0,o=0,c=0,d=0;const h=1,u=1+this._numCoordinatePerPoint;for(c=0;c<s;c++)if(r=t[c],!Re.isClusterTerminator(r)){for(n[i++]=r,o=this.component(r,0)+e,t[c]=Re.clusterTerminator,d=c+1;d<s;d++)if(a=t[d],a!==Re.clusterTerminator){if(this.component(a,0)>o)break;this.distanceBetweenSubBlocks(r,a,h,u)<=e&&(n[i++]=a,t[d]=Re.clusterTerminator)}n[i++]=Re.clusterTerminator}return n.slice(0,i)}setupPrimaryClusterSort(){const e=this.numBlocks,t=this._numCoordinatePerPoint,n=new Float64Array(t);n[0]=1;for(let a=1;a<t;a++)n[a]=n[a-1]*Re._vectorFactor;let i=0,s=0;const r=this._data;for(let a=0;a<e;a++){i=this.blockIndexToDoubleIndex(a),s=0;for(let o=0;o<t;o++)s+=n[o]*r[i+1+o];r[i]=s}}toJSON(){const e=[];for(let t=0;t<this.numBlocks;t++){let n=this.blockIndexToDoubleIndex(t);const i=[t,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++]);e.push(i)}return e}createIndexBlockToClusterIndex(e){const t=this.numBlocks,n=new Uint32Array(t);n.fill(Re.clusterTerminator);let i=0;for(const s of e)s>=t?i++:n[s]=i;return n}createIndexBlockToClusterStart(e){const t=e.length,n=this.numBlocks,i=new Uint32Array(n),s=Re.clusterTerminator;i.fill(s);let r=0;for(let a=0;a<t;a++){const o=e[a];o>n?r=a+1:i[o]=r}return i}countClusters(e){let t=0;const n=Re.clusterTerminator;for(const i of e)i===n&&t++;return t}createIndexClusterToClusterStart(e){let t=this.countClusters(e);const n=new Uint32Array(t),i=Re.clusterTerminator;n.fill(i);const s=e.length;let r=0;for(let a=0;a<s;a++)e[a]===i?r=a+1:a===r&&(n[t++]=r);return n}sortSubsetsBySingleKey(e,t){const n=1+t;let i=0,s,r,a;const o=e.length;for(let c=0;c<o;c++)if(e[c]===Re.clusterTerminator){for(let d=i;d+1<c;d++){r=this.getWithinBlock(e[d],n);for(let h=d+1;h<c;h++)a=this.getWithinBlock(e[h],n),a<r&&(s=e[d],e[d]=e[h],e[h]=s,r=a)}i=c+1}}static clusterPoint3dArray(e,t=f.smallMetricDistance){const n=new Re(3,0,e.length);e.forEach(o=>{n.addDirect(o.x,o.y,o.z)});const i=n.clusterIndicesLexical(t),s=new ns(e.length,0);let r=0,a=0;return i.forEach(o=>{Re.isClusterTerminator(o)?(r++,a=0):(a===0&&s.packedPoints.push(e[o].clone()),s.oldToNew[o]=r,a++)}),s}static clusterNumberArray(e,t=f.smallMetricDistance){const n=new Re(1,0,e.length);e.forEach(o=>{n.addDirect(o)});const i=n.clusterIndicesLexical(t),s=new Nc(e.length);let r=0,a=0;return i.forEach(o=>{Re.isClusterTerminator(o)?(r++,a=0):(a===0&&s.packedNumbers.push(e[o]),s.oldToNew[o]=r,a++)}),s}static clusterGrowablePoint2dArray(e,t=f.smallMetricDistance){const n=new Re(2,0,e.length),i=L.create(),s=e.length;for(let h=0;h<s;h++)e.getPoint2dAtUncheckedPointIndex(h,i),n.addDirect(i.x,i.y);const r=n.clusterIndicesLexical(t),a=n.countClusters(r),o=new ca(e.length,a);let c=0,d=0;return r.forEach(h=>{Re.isClusterTerminator(h)?(c++,d=0):(d===0&&o.growablePackedPoints.pushFromGrowableXYArray(e,h),o.oldToNew[h]=c,d++)}),o}static clusterGrowablePoint3dArray(e,t=f.smallMetricDistance){const n=new Re(3,0,e.length),i=y.create(),s=e.length;for(let h=0;h<s;h++)e.getPoint3dAtUncheckedPointIndex(h,i),n.addDirect(i.x,i.y,i.z);const r=n.clusterIndicesLexical(t),a=n.countClusters(r),o=new ns(e.length,a);let c=0,d=0;return r.forEach(h=>{Re.isClusterTerminator(h)?(c++,d=0):(d===0&&o.growablePackedPoints.pushFromGrowableXYZArray(e,h),o.oldToNew[h]=c,d++)}),o}}function oa(l,e){let t=0;return l.forEach((n,i,s)=>{n<e.length?s[i]=e[n]:t++}),t===0}class ns{packedPoints;growablePackedPoints;oldToNew;static invalidIndex=4294967295;constructor(e,t){this.packedPoints=[],this.growablePackedPoints=new J(t),this.oldToNew=new Uint32Array(e);for(let n=0;n<e;n++)this.oldToNew[n]=ns.invalidIndex}updateIndices(e){return oa(e,this.oldToNew)}}class ca{growablePackedPoints;oldToNew;static invalidIndex=4294967295;constructor(e,t){this.growablePackedPoints=new Ct(t),this.oldToNew=new Uint32Array(e);for(let n=0;n<e;n++)this.oldToNew[n]=ca.invalidIndex}updateIndices(e){return oa(e,this.oldToNew)}}class Nc{packedNumbers;oldToNew;static invalidIndex=4294967295;constructor(e){this.packedNumbers=[],this.oldToNew=new Uint32Array(e);for(let t=0;t<e;t++)this.oldToNew[t]=ns.invalidIndex}updateIndices(e){return oa(e,this.oldToNew)}}var Nt;(function(l){l[l.Scalar=0]="Scalar",l[l.Distance=1]="Distance",l[l.Vector=2]="Vector",l[l.Normal=3]="Normal"})(Nt||(Nt={}));class da{input;values;constructor(e,t){if(this.input=e,t instanceof Float64Array){this.values=[];for(const n of t)this.values.push(n)}else this.values=t}copyValues(e,t,n,i){for(let s=0;s<i;s++)this.values[t*i+s]=e.values[n*i+s]}clone(){return new da(this.input,this.values.slice())}isAlmostEqual(e,t){const n=t||1e-8;return Math.abs(this.input-e.input)<n&&Tt.isAlmostEqual(this.values,e.values,n)}}let Oc=class Cr{data;dataType;name;inputName;constructor(e,t,n,i){this.data=e,this.dataType=t,this.name=n,this.inputName=i}clone(){const e=[];for(const t of this.data)e.push(t.clone());return new Cr(e,this.dataType,this.name,this.inputName)}isAlmostEqual(e,t){if(this.dataType!==e.dataType||this.name!==e.name||this.inputName!==e.inputName||this.data.length!==e.data.length)return!1;for(let n=0;n<this.data.length;n++)if(!this.data[n].isAlmostEqual(e.data[n],t))return!1;return!0}static isScalar(e){return e===Nt.Distance||e===Nt.Scalar}get isScalar(){return Cr.isScalar(this.dataType)}static entriesPerValue(e){return this.isScalar(e)?1:3}get entriesPerValue(){return Cr.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 e=fe.createNull();for(const t of this.data)e.extendArray(t.values);return e}computeDisplacementRange(e=1,t){if(t=ie.createNull(t),Nt.Vector===this.dataType)for(const n of this.data){const i=n.values;for(let s=0;s<i.length;s+=3)t.extendXYZ(i[s]*e,i[s+1]*e,i[s+2]*e)}return t}};class Hs{channels;indices;constructor(e,t){this.channels=e,this.indices=t}clone(){const e=this.channels.map(t=>t.clone());return new Hs(e,this.indices.slice())}isAlmostEqual(e,t){if(!Tt.isExactEqual(this.indices,e.indices)||this.channels.length!==e.channels.length)return!1;for(let n=0;n<this.channels.length;n++)if(!this.channels[n].isAlmostEqual(e.channels[n],t))return!1;return!0}static isAlmostEqual(e,t,n){return e===t?!0:e&&t?e.isAlmostEqual(t,n):!1}createForVisitor(){const e=[];for(const t of this.channels){const n=[];for(const i of t.data)n.push(new da(i.input,[]));e.push(new Oc(n,t.dataType,t.name,t.inputName))}return new Hs(e,[])}tryTransformInPlace(e){let t;const n=e.matrix,i=n.determinant(),s=Math.pow(Math.abs(i),1/3)*(i>=0?1:-1);for(const r of this.channels)for(const a of r.data)switch(r.dataType){case Nt.Scalar:continue;case Nt.Distance:{for(let o=0;o<a.values.length;o++)a.values[o]*=s;break}case Nt.Normal:{if(t=t??n.inverse(),!t)return!1;go(a.values,o=>{t.multiplyTransposeVectorInPlace(o);const c=o.magnitudeSquared(),d=1e-15;if(c>d&&Math.abs(c-1)>d){const h=1/Math.sqrt(c);o.scaleInPlace(h)}});break}case Nt.Vector:{go(a.values,o=>n.multiplyVectorInPlace(o));break}}return!0}}function go(l,e){const t=new y;for(let n=0;n<l.length;n+=3)t.set(l[n],l[n+1],l[n+2]),e(t),l[n]=t.x,l[n+1]=t.y,l[n+2]=t.z}var mo;(function(l){(function(e){e[e.SubdivisionSurface=-1e3]="SubdivisionSurface"})(l.TaggedNumericTagType||(l.TaggedNumericTagType={})),(function(e){e[e.ChooseBasedOnFacets=0]="ChooseBasedOnFacets",e[e.CatmullClark=1]="CatmullClark",e[e.Loop=2]="Loop",e[e.DooSabin=3]="DooSabin"})(l.SubdivisionMethod||(l.SubdivisionMethod={})),(function(e){e[e.FixedDepth=-100]="FixedDepth",e[e.AbsoluteTolerance=-101]="AbsoluteTolerance",e[e.FractionOfRangeBoxTolerance=-102]="FractionOfRangeBoxTolerance"})(l.SubdivisionControlCode||(l.SubdivisionControlCode={}))})(mo||(mo={}));class la{tagA;tagB;constructor(e=0,t=0,n,i){this.tagA=e,this.tagB=t,n&&(this.intData=n),i&&(this.doubleData=i)}intData;doubleData;pushIntPair(e,t){this.intData||(this.intData=[]),this.intData.push(e),this.intData.push(t)}pushIndexedDouble(e,t){this.intData||(this.intData=[]),this.doubleData||(this.doubleData=[]),this.intData.push(e),this.intData.push(this.doubleData.length),this.doubleData.push(t)}tagToInt(e,t,n,i){if(this.intData){for(let s=0;s+1<this.intData.length;s+=2)if(this.intData[s]===e)return Math.min(Math.max(this.intData[s+1],t),n)}return i}tagToIndexedDouble(e,t,n,i){if(this.intData){for(let s=0;s+1<this.intData.length;s+=2)if(this.intData[s]===e)return f.clamp(this.getDoubleData(this.intData[s+1],i),t,n)}return i}getDoubleData(e,t){return this.doubleData&&0<=e&&e<this.doubleData.length?this.doubleData[e]:t}isAlmostEqual(e){return e===void 0||this.tagA!==e.tagA||this.tagB!==e.tagB?!1:f.exactEqualNumberArrays(this.intData,e.intData)&&f.almostEqualArrays(this.doubleData,e.doubleData,(t,n)=>f.isAlmostEqualNumber(t,n))}static areAlmostEqual(e,t){return e===void 0&&t===void 0?!0:e!==void 0&&t!==void 0?e.isAlmostEqual(t):!1}clone(e){return e||(e=new la(this.tagA,this.tagB)),this.intData&&(e.intData=this.intData.slice()),this.doubleData&&(e.doubleData=this.doubleData.slice()),e}}class ot{static planarityLocalRelTol=1e-13;point;pointIndex;normal;normalIndex;param;paramIndex;color;colorIndex;face;auxData;taggedNumericData;edgeVisible;_twoSided;_expectedClosure;edgeMateIndex;edgeIndexToEdgeMateIndex(e){if(e!==void 0&&this.edgeMateIndex!==void 0&&e>=0&&e<this.edgeMateIndex.length)return this.edgeMateIndex[e]}isValidEdgeIndex(e){return e!==void 0&&e>=0&&e<this.pointIndex.length}constructor(e=!1,t=!1,n=!1,i=!0){this.point=new J,this.pointIndex=[],e&&(this.normal=new J,this.normalIndex=[]),t&&(this.param=new Ct,this.paramIndex=[]),n&&(this.color=[],this.colorIndex=[]),this.face=[],this.edgeVisible=[],this._twoSided=i,this._expectedClosure=0}clone(){const e=new ot;return e.point=this.point.clone(),e.pointIndex=this.pointIndex.slice(),this.normal&&(e.normal=this.normal.clone()),this.normalIndex&&(e.normalIndex=this.normalIndex.slice()),this.param&&(e.param=this.param.clone()),this.paramIndex&&(e.paramIndex=this.paramIndex.slice()),this.color&&(e.color=this.color.slice()),this.colorIndex&&(e.colorIndex=this.colorIndex.slice()),e.face=this.face.slice(),this.auxData&&(e.auxData=this.auxData.clone()),this.taggedNumericData&&(e.taggedNumericData=this.taggedNumericData.clone()),e.edgeVisible=this.edgeVisible.slice(),e.twoSided=this.twoSided,e.expectedClosure=this.expectedClosure,this.edgeMateIndex&&(e.edgeMateIndex=this.edgeMateIndex.slice()),e}isAlmostEqual(e){return!(!J.isAlmostEqual(this.point,e.point)||!Tt.isExactEqual(this.pointIndex,e.pointIndex)||!J.isAlmostEqual(this.normal,e.normal)||!Tt.isExactEqual(this.normalIndex,e.normalIndex)||!Ct.isAlmostEqual(this.param,e.param)||!Tt.isExactEqual(this.paramIndex,e.paramIndex)||!Tt.isExactEqual(this.color,e.color)||!Tt.isExactEqual(this.colorIndex,e.colorIndex)||!Hs.isAlmostEqual(this.auxData,e.auxData)||!la.areAlmostEqual(this.taggedNumericData,e.taggedNumericData)||!Tt.isExactEqual(this.edgeVisible,e.edgeVisible)||this.twoSided!==e.twoSided||this.expectedClosure!==e.expectedClosure||!Tt.isExactEqual(this.edgeMateIndex,e.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(e,t){return this.point.getPoint3dAtCheckedPointIndex(e,t)}getNormal(e,t){return this.normal?this.normal.getVector3dAtCheckedVectorIndex(e,t):void 0}getParam(e,t){return this.param?this.param.getPoint2dAtCheckedPointIndex(e,t):void 0}getColor(e){return this.color?this.color[e]:0}getEdgeVisible(e){return this.edgeVisible[e]}get twoSided(){return this._twoSided}set twoSided(e){this._twoSided=e}get expectedClosure(){return this._expectedClosure}set expectedClosure(e){this._expectedClosure=e}setTaggedNumericData(e){this.taggedNumericData=e}copyPointTo(e,t){this.point.getPoint3dAtUncheckedPointIndex(e,t)}copyNormalTo(e,t){this.normal&&this.normal.getVector3dAtUncheckedVectorIndex(e,t)}copyParamTo(e,t){this.param&&this.param.getPoint2dAtUncheckedPointIndex(e,t)}isAlmostEqualParamIndexUV(e,t,n){return this.param!==void 0&&e>=0&&e<this.param.length?f.isSameCoordinate(t,this.param.getXAtUncheckedPointIndex(e))&&f.isSameCoordinate(n,this.param.getYAtUncheckedPointIndex(e)):!1}gatherIndexedData(e,t,n,i){const s=n-t;i>s&&(i=s);const r=s+i;this.resizeAllArrays(r);for(let a=0;a<s;a++)this.point.transferFromGrowableXYZArray(a,e.point,e.pointIndex[t+a]);for(let a=0;a<i;a++)this.point.transferFromGrowableXYZArray(s+a,this.point,a);for(let a=0;a<s;a++)this.pointIndex[a]=e.pointIndex[t+a];for(let a=0;a<i;a++)this.pointIndex[s+a]=this.pointIndex[a];if(this.normal&&this.normalIndex&&e.normal&&e.normalIndex){for(let a=0;a<s;a++)this.normal.transferFromGrowableXYZArray(a,e.normal,e.normalIndex[t+a]);for(let a=0;a<i;a++)this.normal.transferFromGrowableXYZArray(s+a,this.normal,a);for(let a=0;a<s;a++)this.normalIndex[a]=e.normalIndex[t+a];for(let a=0;a<i;a++)this.normalIndex[s+a]=this.normalIndex[a]}if(this.param&&this.paramIndex&&e.param&&e.paramIndex){for(let a=0;a<s;a++)this.param.transferFromGrowableXYArray(a,e.param,e.paramIndex[t+a]);for(let a=0;a<i;a++)this.param.transferFromGrowableXYArray(s+a,this.param,a);for(let a=0;a<s;a++)this.paramIndex[a]=e.paramIndex[t+a];for(let a=0;a<i;a++)this.paramIndex[s+a]=this.paramIndex[a]}if(this.color&&this.colorIndex&&e.color&&e.colorIndex){for(let a=0;a<s;a++)this.color[a]=e.color[e.colorIndex[t+a]];for(let a=0;a<i;a++)this.color[s+a]=this.color[a];for(let a=0;a<s;a++)this.colorIndex[a]=e.colorIndex[t+a];for(let a=0;a<i;a++)this.colorIndex[s+a]=this.colorIndex[a]}for(let a=0;a<s;a++)this.edgeVisible[a]=e.edgeVisible[t+a];for(let a=0;a<i;a++)this.edgeVisible[s+a]=this.edgeVisible[a];if(this.auxData&&e.auxData&&this.auxData.channels.length===e.auxData.channels.length){for(let a=0;a<this.auxData.channels.length;a++){const o=this.auxData.channels[a],c=e.auxData.channels[a],d=o.entriesPerValue;if(o.data.length===c.data.length)for(let h=0;h<o.data.length;h++){const u=o.data[h],g=c.data[h];for(let m=0;m<s;m++)u.copyValues(g,m,e.auxData.indices[t+m],d);for(let m=0;m<i;m++)u.copyValues(u,e.auxData.indices[s+m],m,d)}}for(let a=0;a<s;a++)this.auxData.indices[a]=e.auxData.indices[t+a];for(let a=0;a<i;a++)this.auxData.indices[s+a]=this.auxData.indices[a]}if(this.edgeMateIndex&&e.edgeMateIndex){for(let a=0;a<s;a++)this.edgeMateIndex[a]=e.edgeMateIndex[t+a];for(let a=0;a<i;a++)this.edgeMateIndex[s+a]=this.edgeMateIndex[a]}}static trimArray(e,t){e&&t<e.length&&(e.length=t)}trimAllIndexArrays(e){if(ot.trimArray(this.pointIndex,e),ot.trimArray(this.paramIndex,e),ot.trimArray(this.normalIndex,e),ot.trimArray(this.colorIndex,e),ot.trimArray(this.edgeVisible,e),this.auxData){ot.trimArray(this.auxData.indices,e);for(const t of this.auxData.channels)for(const n of t.data)ot.trimArray(n.values,t.entriesPerValue*e)}ot.trimArray(this.edgeMateIndex,e)}resizeAllArrays(e){if(e>this.point.length){for(;this.point.length<e;)this.point.push(y.create());for(;this.pointIndex.length<e;)this.pointIndex.push(-1);if(this.normal)for(;this.normal.length<e;)this.normal.push(v.create());if(this.normalIndex)for(;this.normalIndex.length<e;)this.normalIndex.push(-1);if(this.param)for(;this.param.length<e;)this.param.push(L.create());if(this.paramIndex)for(;this.paramIndex.length<e;)this.paramIndex.push(-1);if(this.color)for(;this.color.length<e;)this.color.push(0);if(this.colorIndex)for(;this.colorIndex.length<e;)this.colorIndex.push(-1);for(;this.edgeVisible.length<e;)this.edgeVisible.push(!1);if(this.auxData){for(const t of this.auxData.channels)for(const n of t.data)for(;n.values.length<e*t.entriesPerValue;)n.values.push(0);this.auxData.indices&&this.auxData.indices.push(-1)}if(this.edgeMateIndex)for(;this.edgeMateIndex.length<e;)this.edgeMateIndex.push(void 0)}else if(e<this.point.length){if(this.point.resize(e),this.pointIndex.length=e,this.normal&&this.normal.resize(e),this.normalIndex&&(this.normalIndex.length=e),this.param&&this.param.resize(e),this.paramIndex&&(this.paramIndex.length=e),this.color&&(this.color.length=e),this.colorIndex&&(this.colorIndex.length=e),this.edgeVisible.length=e,this.auxData){for(const t of this.auxData.channels)for(const n of t.data)n.values.length=e*t.entriesPerValue;this.auxData.indices&&(this.auxData.indices.length=e)}this.edgeMateIndex&&(this.edgeMateIndex.length=e)}}resizeAllDataArrays(e){if(e>this.point.length){for(;this.point.length<e;)this.point.push(y.create());for(;this.pointIndex.length<e;)this.pointIndex.push(-1);for(;this.edgeVisible.length<e;)this.edgeVisible.push(!1);if(this.normal)for(;this.normal.length<e;)this.normal.push(v.create());if(this.param)for(;this.param.length<e;)this.param.push(L.create());if(this.color)for(;this.color.length<e;)this.color.push(0);if(this.auxData)for(const t of this.auxData.channels)for(const n of t.data)for(;n.values.length<e*t.entriesPerValue;)n.values.push(0)}else if(e<this.point.length&&(this.point.resize(e),this.edgeVisible.length=e,this.pointIndex.length=e,this.normal&&this.normal.resize(e),this.param&&this.param.resize(e),this.color&&(this.color.length=e),this.auxData))for(const t of this.auxData.channels)for(const n of t.data)n.values.length=e*t.entriesPerValue}range(e,t){const n=ie.createNull(e);return this.extendRange(n,t),n}extendRange(e,t){e.extendArray(this.point,t)}tryTransformInPlace(e){if(this.point.multiplyTransformInPlace(e),this.normal&&!e.matrix.isIdentity&&this.normal.multiplyAndRenormalizeMatrix3dInverseTransposeInPlace(e.matrix),this.face.length>0){const t=Math.cbrt(Math.abs(e.matrix.determinant()));for(const n of this.face)n.scaleDistances(t)}return this.auxData&&this.auxData.tryTransformInPlace(e),!0}compress(e=f.smallMetricDistance){const t=Re.clusterGrowablePoint3dArray(this.point,e);if(this.point=t.growablePackedPoints,t.updateIndices(this.pointIndex),this.normalIndex&&this.normal){const n=Re.clusterGrowablePoint3dArray(this.normal);this.normal=n.growablePackedPoints,n.updateIndices(this.normalIndex)}if(this.paramIndex&&this.param){const n=Re.clusterGrowablePoint2dArray(this.param);this.param=n.growablePackedPoints,n.updateIndices(this.paramIndex)}if(this.colorIndex&&this.color){const n=Re.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=Re.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=J.create(this.auxData.channels[0].data[0].values),s=Re.clusterGrowablePoint3dArray(i);this.auxData.channels[0].data[0].values=Tt.create(s.growablePackedPoints.float64Data()),s.updateIndices(this.auxData.indices)}}}static isValidFacetStartIndexArray(e){if(e.length===0)return!1;for(let t=0;t+1<e.length;t++)if(e[t]>=e[t+1])return!1;return!0}static reverseIndices(e,t,n){if(!t||t.length===0)return!0;if(t.length>0&&e[e.length-1]===t.length){for(let i=0;i+1<e.length;i++){let s=e[i],r=e[i+1];if(n)for(;r>s+2;){r--,s++;const a=t[s];t[s]=t[r],t[r]=a}else for(;r>s+1;){r--;const a=t[s];t[s]=t[r],t[r]=a,s++}}return!0}return!1}static reverseIndicesSingleFacet(e,t,n,i){if(!n||n.length===0)return!0;if(n.length>0&&t[t.length-1]===n.length&&e>=0&&e+1<t.length){let s=t[e],r=t[e+1];if(i)for(;r>s+2;){r--,s++;const a=n[s];n[s]=n[r],n[r]=a}else for(;r>s+1;){r--;const a=n[s];n[s]=n[r],n[r]=a,s++}return!0}return!1}reverseIndices(e){e&&ot.isValidFacetStartIndexArray(e)&&(ot.reverseIndices(e,this.pointIndex,!0),this.normalIndex!==this.pointIndex&&ot.reverseIndices(e,this.normalIndex,!0),this.paramIndex!==this.pointIndex&&ot.reverseIndices(e,this.paramIndex,!0),this.colorIndex!==this.pointIndex&&ot.reverseIndices(e,this.colorIndex,!0),ot.reverseIndices(e,this.edgeVisible,!1))}reverseIndicesSingleFacet(e,t){ot.reverseIndicesSingleFacet(e,t,this.pointIndex,!0),this.normalIndex!==this.pointIndex&&ot.reverseIndicesSingleFacet(e,t,this.normalIndex,!0),this.paramIndex!==this.pointIndex&&ot.reverseIndicesSingleFacet(e,t,this.paramIndex,!0),this.colorIndex!==this.pointIndex&&ot.reverseIndicesSingleFacet(e,t,this.colorIndex,!0),ot.reverseIndicesSingleFacet(e,t,this.edgeVisible,!1)}reverseNormals(){this.normal&&this.normal.scaleInPlace(-1)}}class Bi extends ot{_currentFacetIndex;_nextFacetIndex;_numWrap;_numEdges;_polyface;constructor(e,t){super(e.data.normalCount>0,e.data.paramCount>0,e.data.colorCount>0,e.twoSided),this._polyface=e,this._numWrap=t,e.data.auxData&&(this.auxData=e.data.auxData.createForVisitor()),e.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(e){this._numWrap=e}get numEdgesThisFacet(){return this._numEdges}static create(e,t){return new Bi(e,t)}moveToReadIndex(e){if(!this._polyface.isValidFacetIndex(e))return!1;const t=this._polyface.numEdgeInFacet(e);return(this._currentFacetIndex!==e||t+this._numWrap!==this.pointCount)&&(this._currentFacetIndex=e,this._numEdges=t,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=e+1,!0}moveToNextFacet(){return this._nextFacetIndex!==this._currentFacetIndex?this.moveToReadIndex(this._nextFacetIndex):(this._nextFacetIndex++,!0)}reset(){this.moveToReadIndex(0),this._nextFacetIndex=0}tryGetDistanceParameter(e,t){if(e<0||e>=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(e),this.param.getYAtUncheckedPointIndex(e),t)}tryGetNormalizedParameter(e,t){if(e<0||e>=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(e),this.param.getYAtUncheckedPointIndex(e),t)}currentReadIndex(){return this._currentFacetIndex}clientPointIndex(e){return this.pointIndex[e]}clientParamIndex(e){return this.paramIndex?this.paramIndex[e]:-1}clientNormalIndex(e){return this.normalIndex?this.normalIndex[e]:-1}clientColorIndex(e){return this.colorIndex?this.colorIndex[e]:-1}clientAuxIndex(e){return this.auxData?this.auxData.indices[e]:-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(e,t){this.point.pushFromGrowableXYZArray(e.point,t),this.edgeVisible.push(e.edgeVisible[t]),this.param&&e.param&&t<e.param.length&&this.param.pushFromGrowableXYArray(e.param,t),this.normal&&e.normal&&t<e.normal.length&&this.normal.pushFromGrowableXYZArray(e.normal,t),this.color&&e.color&&t<e.color.length&&this.color.push(e.color[t])}pushInterpolatedDataFrom(e,t,n,i){t>i&&this.pushInterpolatedDataFrom(e,i,1-n,t),this.point.pushInterpolatedFromGrowableXYZArray(e.point,t,n,i);const s=(t+1)%e.edgeVisible.length===i?e.edgeVisible[t]:!1;this.edgeVisible.push(s),this.param&&e.param&&t<e.param.length&&i<e.param.length&&this.param.pushInterpolatedFromGrowableXYArray(e.param,t,n,i),this.normal&&e.normal&&t<e.normal.length&&i<e.normal.length&&this.normal.pushInterpolatedFromGrowableXYZArray(e.normal,t,n,i),this.color&&e.color&&t<e.color.length&&i<e.color.length&&this.color.push(f.interpolateColor(e.color[t],n,e.color[i]))}createSubsetVisitor(e,t=0){return is.createSubsetVisitor(this._polyface,e,t)}}class is extends Bi{_facetIndices;_currentSubsetIndex;_nextSubsetIndex;constructor(e,t,n){super(e,n),this._facetIndices=t.slice(),this._currentSubsetIndex=-1,this._nextSubsetIndex=0,this.reset()}isValidSubsetIndex(e){return e>=0&&e<this._facetIndices.length}static createSubsetVisitor(e,t,n=0){return new is(e,t,n)}moveToReadIndex(e){return this.isValidSubsetIndex(e)?(this._currentSubsetIndex=e,this._nextSubsetIndex=e+1,super.moveToReadIndex(this._facetIndices[e])):!1}moveToNextFacet(){return this._nextSubsetIndex!==this._currentSubsetIndex?this.moveToReadIndex(this._nextSubsetIndex):(this._nextSubsetIndex++,!0)}reset(){this._facetIndices&&(this.moveToReadIndex(0),this._nextSubsetIndex=0)}parentFacetIndex(e){return e===void 0&&(e=this._currentSubsetIndex),this.isValidSubsetIndex(e)?this._facetIndices[e]:void 0}getVisitableFacetCount(){return this._facetIndices.length}static createNormalComparison(e,t=v.unitZ(),n=T.createSmallAngle(),i=0){if(e instanceof _n)return this.createNormalComparison(e.createVisitor(),t,n,i);const s=e,r=[],a=v.createZero();for(s.reset();s.moveToNextFacet();)re.unitNormal(s.point,a)&&(a.dotProduct(t)<0||a.angleFromPerpendicular(t).isMagnitudeLessThanOrEqual(n)||r.push(s.currentReadIndex()));return is.createSubsetVisitor(s.clientPolyface(),r,i)}}class Ks{_paramDistanceRange;_paramRange;get paramDistanceRange(){return this._paramDistanceRange}get paramRange(){return this._paramRange}constructor(e,t){this._paramDistanceRange=e,this._paramRange=t}static createNull(){return new Ks(ze.createNull(),ze.createNull())}clone(e){return e?(this._paramDistanceRange.clone(e._paramDistanceRange),this._paramRange.clone(e._paramRange),e):new Ks(this._paramDistanceRange.clone(),this._paramRange.clone())}setNull(){this._paramDistanceRange.setNull(),this._paramRange.setNull()}convertParamXYToDistance(e,t,n){n=n||L.create();const i=this._paramRange.high.minus(this._paramRange.low);return n.x=i.x===0?e:this._paramDistanceRange.low.x+(e-this._paramRange.low.x)*(this._paramDistanceRange.high.x-this._paramDistanceRange.low.x)/i.x,n.y=i.y===0?t:this.paramDistanceRange.low.y+(t-this._paramRange.low.y)*(this._paramDistanceRange.high.y-this._paramDistanceRange.low.y)/i.y,n}convertParamXYToNormalized(e,t,n){n=n||L.create();const i=this._paramRange.high.minus(this._paramRange.low);return n.x=i.x===0?e:(e-this._paramRange.low.x)/i.x,n.y=i.y===0?t:(t-this._paramRange.low.y)/i.y,n}convertParamToDistance(e,t){return this.convertParamXYToDistance(e.x,e.y,t)}convertParamToNormalized(e,t){return this.convertParamXYToNormalized(e.x,e.y,t)}scaleDistances(e){this._paramDistanceRange.low.x*=e,this._paramDistanceRange.low.y*=e,this._paramDistanceRange.high.x*=e,this._paramDistanceRange.high.y*=e}setParamDistanceRangeFromNewFaceData(e,t,n){const i=L.create(),s=L.create();this.setNull();let r=0;const a=Bi.create(e,0);if(!a.moveToReadIndex(t)||n<=t)return!1;do{const o=a.numEdgesThisFacet,c=a.point,d=[],h=a.param,u=[];if(!h)return!1;h.extendRange(this._paramRange);const g=$.create(),m=$.create();for(let p=0;p<o;p++){if(d[2]=p,u[2]=p,p>1){h.vectorIndexIndex(u[1],u[0],g),h.vectorIndexIndex(u[1],u[2],m);const x=c.getPoint3dAtUncheckedPointIndex(d[0]).minus(c.getPoint3dAtUncheckedPointIndex(d[1])),_=c.getPoint3dAtUncheckedPointIndex(d[1]).minus(c.getPoint3dAtUncheckedPointIndex(d[2])),I=Math.abs(g.x*m.y-m.x*g.y);if(I){const S=y.createFrom(x);S.scaleInPlace(m.y),S.addScaledInPlace(_,-g.y);const A=y.createFrom(_);A.scaleInPlace(g.x),A.addScaledInPlace(x,-m.x);const w=L.create(S.magnitude()/I,A.magnitude()/I);i.x+=w.x,i.y+=w.y,s.x+=w.x*w.x,s.y+=w.y*w.y,r++}}u[0]=u[1],u[1]=u[2],d[0]=d[1],d[1]=d[2]}}while(a.moveToNextFacet()&&a.currentReadIndex()<n);if(r!==0){const o=L.create(i.x/r,i.y/r),c=L.create(Math.sqrt(Math.abs(s.x/r-o.x*o.x)),Math.sqrt(Math.abs(s.y/r-o.y*o.y)));this._paramDistanceRange.low.set(0,0),this._paramDistanceRange.high.set((o.x+c.x)*(this._paramRange.high.x-this._paramRange.low.x),(o.y+c.y)*(this._paramRange.high.y-this._paramRange.low.y))}return!0}}class be extends Mt{geometryCategory="polyface";data;constructor(e){super(),this.data=e}get twoSided(){return this.data.twoSided}set twoSided(e){this.data.twoSided=e}get expectedClosure(){return this.data.expectedClosure}set expectedClosure(e){this.data.expectedClosure=e}static areIndicesValid(e,t,n,i,s){if(e===void 0&&i===void 0)return!0;if(e===void 0||i===void 0||t<0||t>=e.length||n<=t||n>e.length)return!1;for(let r=t;r<n;r++)if(e[r]<0||e[r]>=s)return!1;return!0}get facetCount(){}}class _n extends be{_facetStart;_facetToFaceData;constructor(e,t,n){super(e),t?this._facetStart=t.slice():(this._facetStart=[],this._facetStart.push(0)),n?this._facetToFaceData=n.slice():this._facetToFaceData=[]}edgeIndexToFacetIndex(e){if(e!==void 0)return Tt.searchStrictlyIncreasingNumbers(this._facetStart,e)}edgeIndexToFaceLoop(e){const t=this.edgeIndexToFacetIndex(e);if(t!==void 0)return fe.createXX(this.facetIndex0(t),this.facetIndex1(t))}isSameGeometryClass(e){return e instanceof _n}isAlmostEqual(e){return e instanceof _n?this.data.isAlmostEqual(e.data)&&Tt.isExactEqual(this._facetStart,e._facetStart)&&Tt.isExactEqual(this._facetToFaceData,e._facetToFaceData):!1}get isEmpty(){return this.data.pointCount===0||this.data.pointIndex.length===0}tryTransformInPlace(e){return this.data.tryTransformInPlace(e),e.matrix.determinant()<0&&this.reverseIndices(),!0}reverseSingleFacet(e){this.data.reverseIndicesSingleFacet(e,this._facetStart)}clone(){return new _n(this.data.clone(),this._facetStart.slice(),this._facetToFaceData.slice())}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e),t}reverseIndices(){this.data.reverseIndices(this._facetStart)}reverseNormals(){this.data.reverseNormals()}tryGetFaceData(e){if(e<0||e>=this._facetToFaceData.length)return;const t=this._facetToFaceData[e];if(!(t<0||t>=this.data.face.length))return this.data.face[t]}addIndexedPolyface(e,t,n){const i=e.facetCount,s=this.data.point.length,r=y.create();for(let a=0;a<e.data.point.length;a++)e.data.point.getPoint3dAtUncheckedPointIndex(a,r),n?(n.multiplyPoint3d(r,r),this.addPoint(r)):this.addPoint(r);for(let a=0;a<i;a++){const o=e._facetStart[a],c=e._facetStart[a+1];if(t)for(let d=c;d-- >o;)this.addPointIndex(s+e.data.pointIndex[d],e.data.edgeVisible[d>o?d-1:c-1]);else for(let d=o;d<c;d++)this.addPointIndex(s+e.data.pointIndex[d],e.data.edgeVisible[d]);this.terminateFacet(!1)}if(this.data.param!==void 0&&e.data.param!==void 0&&e.data.paramIndex!==void 0){const a=this.data.param.length;this.data.param.pushFromGrowableXYArray(e.data.param);for(let o=0;o<i;o++){const c=e._facetStart[o],d=e._facetStart[o+1];if(t)for(let h=d;h-- >c;)this.addParamIndex(a+e.data.paramIndex[h]);else for(let h=c;h<d;h++)this.addParamIndex(a+e.data.paramIndex[h])}}if(this.data.normal!==void 0&&e.data.normal!==void 0&&e.data.normalIndex!==void 0){const a=this.data.normal.length;for(let o=0;o<e.data.normal.length;o++){const c=e.data.normal.getVector3dAtUncheckedVectorIndex(o);n&&n.multiplyVector(c,c),t&&c.scaleInPlace(-1),this.addNormal(c)}for(let o=0;o<i;o++){const c=e._facetStart[o],d=e._facetStart[o+1];if(t)for(let h=d;h-- >c;)this.addNormalIndex(a+e.data.normalIndex[h]);else for(let h=c;h<d;h++)this.addNormalIndex(a+e.data.normalIndex[h])}}if(this.data.color!==void 0&&e.data.color!==void 0&&e.data.colorIndex!==void 0){const a=this.data.color.length;for(const o of e.data.color)this.addColor(o);for(let o=0;o<i;o++){const c=e._facetStart[o],d=e._facetStart[o+1];if(t)for(let h=d;h-- >c;)this.addColorIndex(a+e.data.colorIndex[h]);else for(let h=c;h<d;h++)this.addColorIndex(a+e.data.colorIndex[h])}}if(e.data.face.length!==0){const a=this.data.face.length;for(const o of e.data.face){const c=o.clone();this.data.face.push(c)}for(const o of e._facetToFaceData)this._facetToFaceData.push(a+o)}}get zeroTerminatedIndexCount(){return this.data.pointIndex.length+this._facetStart.length-1}static create(e=!1,t=!1,n=!1,i=!0){return new _n(new ot(e,t,n,i))}addPoint(e,t){if(t!==void 0){const n=this.data.point.distanceIndexToPoint(t,e);if(n!==void 0&&f.isSmallMetricDistance(n))return t}return this.data.point.pushXYZ(e.x,e.y,e.z),this.data.point.length-1}addPointXYZ(e,t,n){return this.data.point.pushXYZ(e,t,n),this.data.point.length-1}addParam(e){return this.data.param||(this.data.param=new Ct),this.data.param.push(e),this.data.param.length-1}addParamUV(e,t,n,i){return this.data.param||(this.data.param=new Ct),n!==void 0&&this.data.isAlmostEqualParamIndexUV(n,e,t)?n:i!==void 0&&this.data.isAlmostEqualParamIndexUV(i,e,t)?i:(this.data.param.pushXY(e,t),this.data.param.length-1)}addNormal(e,t,n){const i=(s,r)=>{const a=s.distanceIndexToPoint(r,e);return a!==void 0&&f.isSmallMetricDistance(a)};if(this.data.normal){if(t!==void 0&&i(this.data.normal,t))return t;if(n!==void 0&&i(this.data.normal,n))return n;if(t!==void 0||n!==void 0){const s=this.data.normal.length-1;if(i(this.data.normal,s))return s}}return this.addNormalXYZ(e.x,e.y,e.z)}addNormalXYZ(e,t,n){return this.data.normal||(this.data.normal=new J),this.data.normal.pushXYZ(e,t,n),this.data.normal.length-1}addColor(e){return this.data.color||(this.data.color=[]),this.data.color.push(e),this.data.color.length-1}addPointIndex(e,t=!0){this.data.pointIndex.push(e),this.data.edgeVisible.push(t)}addNormalIndex(e){this.data.normalIndex||(this.data.normalIndex=[]),this.data.normalIndex.push(e)}addParamIndex(e){this.data.paramIndex||(this.data.paramIndex=[]),this.data.paramIndex.push(e)}addColorIndex(e){this.data.colorIndex||(this.data.colorIndex=[]),this.data.colorIndex.push(e)}cleanupOpenFacet(){this.data.trimAllIndexArrays(this.data.pointIndex.length)}validateAllIndices(e=0,t){const n=this.data.pointIndex.length,i=t??[];return n===0?(i.push("empty pointIndex array"),!1):e<0||e>=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"),be.areIndicesValid(this.data.pointIndex,e,n,this.data.point,this.data.point?this.data.point.length:0)||i.push("invalid point index encountered"),be.areIndicesValid(this.data.normalIndex,e,n,this.data.normal,this.data.normal?this.data.normal.length:0)||i.push("invalid normal index encountered"),be.areIndicesValid(this.data.paramIndex,e,n,this.data.param,this.data.param?this.data.param.length:0)||i.push("invalid param index encountered"),be.areIndicesValid(this.data.colorIndex,e,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(e=!0){const t=this._facetStart.length-1,n=this._facetStart[t],i=this.data.pointIndex.length;if(e){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(e){return e>=0&&e<this.facetCount}numEdgeInFacet(e){return this.isValidFacetIndex(e)?this._facetStart[e+1]-this._facetStart[e]:0}facetIndex0(e){return this._facetStart[e]}facetIndex1(e){return this._facetStart[e+1]}get facetStart(){return this._facetStart}createVisitor(e=0){return Bi.create(this,e)}extendRange(e,t){this.data.extendRange(e,t)}getFaceDataByFacetIndex(e){return this.data.face[this._facetToFaceData[e]]}setNewFaceData(e=0){const t=this._facetToFaceData.length;if(t>=this._facetStart.length)return!1;e===0&&(e=this._facetStart.length);const n=Bi.create(this,0);if(!n.moveToReadIndex(t))return!1;const i=Ks.createNull();if(this.data.param&&this.data.param.length>0){do n.param?.extendRange(i.paramRange);while(n.moveToNextFacet()&&n.currentReadIndex()<e);i.setParamDistanceRangeFromNewFaceData(this,t,e)}this.data.face.push(i);const s=this.data.face.length-1;for(let r=this._facetToFaceData.length;r<e;r++)this._facetToFaceData.push(this._facetStart[r]===0?0:s);return!0}dispatchToGeometryHandler(e){return e.handleIndexedPolyface(this)}static hasEdgeMateIndex(e){let t;if(e instanceof be?e instanceof _n&&(t=e):e.clientPolyface()&&e.clientPolyface()instanceof _n&&(t=e.clientPolyface()),t){const n=t.data.edgeMateIndex;if(n&&n.length>0&&n.length===t.data.indexCount)return{parent:t,edgeMateIndex:n}}}}class po{_parentArray;constructor(e=0){this._parentArray=[];for(let t=0;t<e;t++)this._parentArray.push(t)}get length(){return this._parentArray.length}isValidIndex(e){return 0<=e&&e<this._parentArray.length}addLeaf(){const e=this._parentArray.length;return this._parentArray.push(e),e}findRoot(e){if(!this.isValidIndex(e))return e;let t=e,n=this._parentArray[e];for(;n!==t;)t=n,n=this._parentArray[t];const i=t;for(t=e;t!==i;)n=this._parentArray[t],this._parentArray[t]=i,t=n;return i}mergeSubsets(e,t){if(!this.isValidIndex(e)||!this.isValidIndex(t))return e;const n=this.findRoot(e),i=this.findRoot(t);return n!==i&&(this._parentArray[n]=i),this.findRoot(e)}askParent(e){return this.isValidIndex(e)?this._parentArray[e]:e}countRoots(){let e=0;const t=this._parentArray.length;for(let n=0;n<t;n++)this._parentArray[n]===n&&e++;return e}countNonTrivialPaths(){let e=0;const t=this._parentArray.length;for(let n=0;n<t;n++){const i=this._parentArray[n];i!==n&&this._parentArray[i]!==i&&e++}return e}collectRootIndices(){const e=[],t=this._parentArray.length;for(let n=0;n<t;n++)this._parentArray[n]===n&&e.push(n);return e}}class ha{_freeMasks;_originalFreeMasks;_firstFreeMask;constructor(e,t){this._freeMasks=e,this._originalFreeMasks=e,this._firstFreeMask=t}static create(e){let t=0,n=1;for(let i=0;i<32;i++){if((n&e)!==0){t=n;break}n=n<<1}if(t!==0)return new ha(e,t)}grabMask(){if(!this.hasFreeMask)return 0;let e=this._firstFreeMask;for(;!(e&this._freeMasks);)e=e<<1;return this._freeMasks&=~e,e}dropMask(e){e&=this._originalFreeMasks,this._freeMasks|=e}get hasFreeMask(){return this._freeMasks!==0}}var O;(function(l){l[l.EXTERIOR=1]="EXTERIOR",l[l.BOUNDARY_EDGE=2]="BOUNDARY_EDGE",l[l.PRIMARY_EDGE=4]="PRIMARY_EDGE",l[l.BRIDGE_EDGE=8]="BRIDGE_EDGE",l[l.REGULARIZED_EDGE=16]="REGULARIZED_EDGE",l[l.TRIANGULATED_FACE=256]="TRIANGULATED_FACE",l[l.NULL_FACE=512]="NULL_FACE",l[l.VISITED=65536]="VISITED",l[l.NULL_MASK=0]="NULL_MASK",l[l.ALL_GRAB_DROP_MASKS=4293918720]="ALL_GRAB_DROP_MASKS",l[l.ALL_MASK=4294967295]="ALL_MASK"})(O||(O={}));class U{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(e=0,t=0,n=0,i=0){this._id=U._totalNodesCreated++,Number.isSafeInteger(U._totalNodesCreated)||(U._totalNodesCreated=0),this.i=i,this.maskBits=0,this.x=e,this.y=t,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(e){let t=this;if(e>0)for(let n=0;n<e;n++)t=t.faceSuccessor;else if(e<0)for(let n=0;n>e;n--)t=t.facePredecessor;return t.y}static createHalfEdgePair(e){const t=new U,n=new U;return e&&(e.push(t),e.push(n)),U.setFaceLinks(t,n),U.setFaceLinks(n,t),U.setEdgeMates(t,n),t}static createHalfEdgePairWithCoordinates(e=0,t=0,n=0,i=0,s=0,r=0,a=0,o=0,c){const d=U.createHalfEdgePair(c),h=d._edgeMate;return d.x=e,d.y=t,d.z=n,d.i=i,h.x=s,h.y=r,h.z=a,h.i=o,d}static setFaceLinks(e,t){e._faceSuccessor=t,t._facePredecessor=e}static setEdgeMates(e,t){e._edgeMate=t,t._edgeMate=e}static splitEdge(e,t=0,n=0,i=0,s=0,r){const a=new U(t,n,i,s),o=new U(t,n,i,s);if(r&&(r.push(a),r.push(o)),e===void 0)a._faceSuccessor=a._facePredecessor=a,o._faceSuccessor=o._facePredecessor=o,U.setEdgeMates(a,o);else{const c=e._faceSuccessor,d=e._edgeMate,h=d._faceSuccessor;U.setFaceLinks(a,c),U.setFaceLinks(e,a),U.setFaceLinks(d,o),U.setFaceLinks(o,h),U.setEdgeMates(a,d),U.setEdgeMates(o,e),this.transferEdgeProperties(e,a),this.transferEdgeProperties(d,o)}return a}static healEdge(e,t=!0){if(e.isIsolatedEdge)return;const n=e.vertexSuccessor;if(n.vertexSuccessor!==e||t&&!e.vectorToFaceSuccessor().isParallelTo(e.facePredecessor.vectorToFaceSuccessor(),!1,!0))return;const i=e.facePredecessor,s=e.faceSuccessor,r=n.facePredecessor,a=n.faceSuccessor;return this.setFaceLinks(i,s),this.setFaceLinks(r,a),this.setEdgeMates(i,r),this.setFaceLinks(e,n),this.setFaceLinks(n,e),this.setEdgeMates(e,n),i}static splitEdgeCreateSliverFace(e,t){const n=e.edgeMate,i=new U,s=new U;return t&&(t.push(i),t.push(s)),i._faceSuccessor=i._facePredecessor=s,s._faceSuccessor=s._facePredecessor=i,U.setEdgeMates(i,n),U.setEdgeMates(s,e),i.copyDataFrom(e,!0,!0,!1,!1),s.copyDataFrom(n,!0,!0,!1,!1),i}static _edgePropertyMasks=[O.EXTERIOR,O.BOUNDARY_EDGE,O.PRIMARY_EDGE,O.BRIDGE_EDGE,O.REGULARIZED_EDGE,O.NULL_FACE];static transferEdgeProperties(e,t){t.edgeTag=e.edgeTag;for(const n of this._edgePropertyMasks)e.getMask(n)?t.setMask(n):t.clearMask(n)}get vertexSuccessor(){return this.facePredecessor.edgeMate}get vertexPredecessor(){return this.edgeMate.faceSuccessor}setMask(e){this.maskBits|=e}getMask(e){return this.maskBits&e}clearMask(e){this.maskBits&=~e}applyMask(e,t=!1){t?this.clearMask(e):this.setMask(e)}setMaskAroundVertex(e){let t=this;do t.setMask(e),t=t.vertexSuccessor;while(t!==this)}setXYZAroundVertex(e,t,n){let i=this;do i.x=e,i.y=t,i.z=n,i=i.vertexSuccessor;while(i!==this)}setMaskAroundFace(e){let t=this;do t.setMask(e),t=t.faceSuccessor;while(t!==this)}setMaskAroundEdge(e){this.setMask(e),this.edgeMate.setMask(e)}clearMaskAroundEdge(e){this.clearMask(e),this.edgeMate.clearMask(e)}countEdgesAroundFace(){let e=0,t=this;do e++,t=t.faceSuccessor;while(t!==this);return e}findAroundVertex(e){let t=this;do{if(t===e)return!0;t=t.vertexSuccessor}while(t!==this);return!1}findAroundFace(e){let t=this;do{if(t===e)return!0;t=t.faceSuccessor}while(t!==this);return!1}isMaskedAroundFace(e,t=!0){let n=this;if(t)do{if(!n.isMaskSet(e))return!1;n=n.faceSuccessor}while(n!==this);else do{if(n.isMaskSet(e))return!1;n=n.faceSuccessor}while(n!==this);return!0}setMaskAndEdgeTagAroundFace(e,t,n=!1){let i=this;do{if(i.setMask(e),i.edgeTag=t,n){const s=i.edgeMate;s.setMask(e),s.edgeTag=t}i=i.faceSuccessor}while(i!==this)}countEdgesAroundVertex(){let e=0,t=this;do e++,t=t.vertexSuccessor;while(t!==this);return e}countMaskAroundFace(e,t=!0){let n=0,i=this;if(t)do i.isMaskSet(e)&&n++,i=i.faceSuccessor;while(i!==this);else do i.isMaskSet(e)||n++,i=i.faceSuccessor;while(i!==this);return n}countMaskAroundVertex(e,t=!0){let n=0,i=this;if(t)do i.isMaskSet(e)&&n++,i=i.vertexSuccessor;while(i!==this);else do i.isMaskSet(e)||n++,i=i.vertexSuccessor;while(i!==this);return n}findMaskAroundVertex(e,t=!0,n=!1){let i=this;do{if(i.isMaskSet(e)===t)return i;i=n?i.vertexPredecessor:i.vertexSuccessor}while(i!==this)}findMaskAroundFace(e,t=!0){let n=this;do{if(n.isMaskSet(e)===t)return n;n=n.faceSuccessor}while(n!==this)}findMaskAroundEdge(e,t=!0){if(this.isMaskSet(e)===t)return this;const n=this.edgeMate;if(n.isMaskSet(e)===t)return n}testAndSetMask(e){const t=this.maskBits&e;return this.maskBits|=e,t}setXYZFrom(e){this.x=e.x,this.y=e.y,this.z=e.z}setXYZ(e){this.x=e.x,this.y=e.y,this.z=e.z}isMaskSet(e){return(this.maskBits&e)!==0}static filterIsMaskOn(e,t){return e.isMaskSet(t)}static filterIsMaskOff(e,t){return!e.isMaskSet(t)}static createEdgeXYXY(e,t,n,i){const s=new U(e,t),r=new U(n,i);return s._faceSuccessor=s._facePredecessor=s._edgeMate=r,r._faceSuccessor=r._facePredecessor=r._edgeMate=s,s}static pinch(e,t){if(e!==t){const n=e._facePredecessor,i=t._facePredecessor;t._facePredecessor=n,e._facePredecessor=i,i._faceSuccessor=e,n._faceSuccessor=t}}get isDangling(){return this.edgeMate.faceSuccessor===this}yankFromVertexLoop(){const e=this.edgeMate.faceSuccessor;if(e!==this)return U.pinch(this,e),e}decommission(){this._facePredecessor=void 0,this._faceSuccessor=void 0,this._edgeMate=void 0}static nodeToSelf(e){return e}static nodeToId(e){return e.id}static nodeToIdString(e){return e.id.toString()}static nodeToIdMaskXY(e){return{id:e.id,mask:U.nodeToMaskString(e),xy:[e.x,e.y]}}static nodeToIdXYString(e){return`${e.id.toString()}+${U.nodeToMaskString(e)}[${e.x},${e.y}]`}static nodeToIdXYZString(e){return`[${e.id.toString()}: ${e.x},${e.y},${e.z}]`}static nodeToMaskString(e){let t="";return e.isMaskSet(O.BOUNDARY_EDGE)&&(t+="B"),e.isMaskSet(O.PRIMARY_EDGE)&&(t+="P"),e.isMaskSet(O.EXTERIOR)&&(t+="X"),e.isMaskSet(O.NULL_FACE)&&(t+="N"),t}static nodeToXY(e){return[e.x,e.y]}vectorToFaceSuccessorXY(e){return $.create(this.faceSuccessor.x-this.x,this.faceSuccessor.y-this.y,e)}vectorToFaceSuccessor(e){const t=this.faceSuccessor;return v.create(t.x-this.x,t.y-this.y,t.z-this.z,e)}vectorToFacePredecessor(e){const t=this.facePredecessor;return v.create(t.x-this.x,t.y-this.y,t.z-this.z,e)}static isNodeVisibleInSector(e,t){if(t.vertexSuccessor===t)return!0;const n=t.faceSuccessor,i=t.facePredecessor,s=this.crossProductXYToTargets(t,n,e),r=this.crossProductXYToTargets(i,t,e);if(s>0&&r>0)return!0;const a=this.crossProductXYToTargets(i,t,n);return r<=0&&s<=0?r===0&&s===0&&a===0?i===n&&t.vertexSuccessor!==t?e===n:U.dotProductNodeToNodeVectorsXY(i,t,t,e)>0:!1:a===0&&r!==0&&s!==0?i!==n:a<0}static crossProductXYToTargets(e,t,n){return f.crossProductXYXY(t.x-e.x,t.y-e.y,n.x-e.x,n.y-e.y)}static dotProductNodeToNodeVectorsXY(e,t,n,i){return f.dotProductXYXY(t.x-e.x,t.y-e.y,i.x-n.x,i.y-n.y)}static crossProductXYAlongChain(e,t,n){return f.crossProductXYXY(t.x-e.x,t.y-e.y,n.x-t.x,n.y-t.y)}static isSectorConvex(e,t,n,i=0){const s=.5*U.crossProductXYAlongChain(e,t,n);return i=i??0,Math.abs(s)<=Math.abs(i)?U.dotProductNodeToNodeVectorsXY(e,t,t,n)>0:s>-i}isSectorConvex(e){return e===void 0&&(e=f.smallMetricDistanceSquared*this.signedFaceArea()),U.isSectorConvex(this.facePredecessor,this,this.faceSuccessor,e)}isFaceConvex(e=f.smallMetricDistanceSquared){let t=this;const n=e>0?e*t.signedFaceArea():0;do{if(!t.isSectorConvex(n))return!1;t=t.faceSuccessor}while(t!==this);return!0}isolateEdge(){const e=this.edgeMate;this.yankFromVertexLoop(),e.yankFromVertexLoop()}get isIsolatedEdge(){return this===this.vertexSuccessor&&this.edgeMate===this.edgeMate.vertexSuccessor}belowYX(e){return this.y<e.y?!0:this.y>e.y?!1:this.x<e.x}static testNodeMaskNotExterior(e){return!e.isMaskSet(O.EXTERIOR)}static testMateMaskExterior(e){return e.edgeMate.isMaskSet(O.EXTERIOR)}static sectorSweepRadiansXYZ(e,t){const n=e.faceSuccessor,i=e.facePredecessor;return T.orientedRadiansBetweenVectorsXYZ(n.x-e.x,n.y-e.y,n.z-e.z,i.x-e.x,i.y-e.y,i.z-e.z,t.x,t.y,t.z,!0)}static testFacePositiveAreaXY(e){return e.countEdgesAroundFace()>2&&e.signedFaceArea()>0}isEqualXY(e){return this.x===e.x&&this.y===e.y}distanceXY(e){return f.distanceXYXY(this.x,this.y,e.x,e.y)}distanceXYZ(e){return f.distanceXYZXYZ(this.x,this.y,this.z,e.x,e.y,e.z)}collectMaskedEdgesAroundFace(e,t=!0,n){n===void 0?n=[]:n.length=0;let i=this;do i.isMaskSet(e)===t&&n.push(i),i=i.faceSuccessor;while(i!==this);return n}announceEdgesInFace(e){let t=this;do e(t),t=t.faceSuccessor;while(t!==this)}announceEdgesInSuperFace(e,t,n){let s=0;const r=e instanceof Function?e:d=>d.isMaskSet(e),a=d=>{let h=d;do{if(!r(h))return h;n?.(h),h=h.vertexPredecessor}while(h!==d)},o=a(this);if(!o)return!1;let c=o;do if(t(c),c=a(c.faceSuccessor),!c)return!1;while(c!==o&&s++<1e4);return s<1e4}collectAroundFace(e){const t=[];let n=this;do t.push(e?e(n):n),n=n.faceSuccessor;while(n!==this);return t}collectMaskedEdgesAroundVertex(e,t=!0,n){n===void 0?n=[]:n.length=0;let i=this;do i.isMaskSet(e)===t&&n.push(i),i=i.vertexSuccessor;while(i!==this);return n}collectAroundVertex(e){const t=[];let n=this;do t.push(e?e(n):n),n=n.vertexSuccessor;while(n!==this);return t}announceEdgesAroundVertex(e){let t=this;do e(t),t=t.vertexSuccessor;while(t!==this)}sumAroundFace(e){let t=this,n=0;do n+=e(t),t=t.faceSuccessor;while(t!==this);return n}sumAroundVertex(e){let t=this,n=0;do n+=e(t),t=t.vertexSuccessor;while(t!==this);return n}clearMaskAroundFace(e){let t=this;do t.clearMask(e),t=t.faceSuccessor;while(t!==this)}clearMaskAroundVertex(e){let t=this;do t.clearMask(e),t=t.vertexSuccessor;while(t!==this)}signedFaceArea(){let e=0,t=this.x,n=0;const i=this.y;let s=0,r=0,a,o=this;do a=o.faceSuccessor,n=a.x,r=a.y-i,e+=(t-n)*(s+r),t=n,s=r,o=a;while(o!==this);return .5*e}fractionToPoint2d(e,t){const n=this.faceSuccessor;return L.create(this.x+(n.x-this.x)*e,this.y+(n.y-this.y)*e,t)}fractionToPoint3d(e,t){const n=this.faceSuccessor;return y.create(this.x+(n.x-this.x)*e,this.y+(n.y-this.y)*e,this.z+(n.z-this.z)*e,t)}fractionAlongAndPerpendicularToPoint2d(e,t,n){const i=this.faceSuccessor,s=i.x-this.x,r=i.y-this.y;return L.create(this.x+s*e-r*t,this.y+r*e+s*t,n)}getPoint3d(e){return y.create(this.x,this.y,this.z,e)}getPoint2d(e){return L.create(this.x,this.y,e)}getVector3dAlongEdge(e){const t=this.faceSuccessor;return v.create(t.x-this.x,t.y-this.y,t.z-this.z,e)}getVector2dAlongEdge(e){const t=this.faceSuccessor;return $.create(t.x-this.x,t.y-this.y,e)}fractionToX(e){const t=this.faceSuccessor;return this.x+(t.x-this.x)*e}fractionToY(e){const t=this.faceSuccessor;return this.y+(t.y-this.y)*e}fractionToZ(e){const t=this.faceSuccessor;return this.z+(t.z-this.z)*e}static transverseIntersectionFractions(e,t,n){const i=e.faceSuccessor,s=t.faceSuccessor;if(n||(n=$.create()),Le.linearSystem2d(i.x-e.x,t.x-s.x,i.y-e.y,t.y-s.y,t.x-e.x,t.y-e.y,n))return n}static horizontalScanFraction(e,t){const n=e.faceSuccessor,i=n.y-e.y;if(f.isSameCoordinate(t,e.y)&&f.isSameCoordinate(t,n.y))return e;if(!f.isSameCoordinate(i,0))return f.conditionalDivideFraction(t-e.y,i)}static horizontalScanFraction01(e,t){const n=e.faceSuccessor,i=n.y-e.y;if(f.isSameCoordinate(t,e.y)&&f.isSameCoordinate(t,n.y)||f.isSameCoordinate(i,0))return;const s=f.conditionalDivideFraction(t-e.y,i);if(s!==void 0&&s>=0&&s<=1)return s}copyDataFrom(e,t,n,i,s){t&&(this.x=e.x,this.y=e.y,this.z=e.z),n&&(this.i=e.i),i&&U.transferEdgeProperties(e,this),s&&(this.faceTag=e.faceTag)}isSplitWasherFace(e=O.BRIDGE_EDGE){if(!this.countMaskAroundFace(e))return!1;const t=new Di((i,s)=>i.id-s.id);let n=this;do n.isMaskSet(e)&&t.add(n),n=n.faceSuccessor;while(n!==this);if(t.size===0)return!1;for(const i of t)if(!t.has(i.edgeMate)||!i.edgeMate.isMaskSet(e))return!1;return!0}}class Ut{allHalfEdges;_maskManager;constructor(){this.allHalfEdges=[],this._maskManager=ha.create(O.ALL_GRAB_DROP_MASKS)}grabMask(e=!0){const t=this._maskManager.grabMask();return e&&this.clearMask(t),t}dropMask(e){this._maskManager.dropMask(e)}get hasFreeMask(){return this._maskManager.hasFreeMask}createEdgeXYZXYZ(e=0,t=0,n=0,i=0,s=0,r=0,a=0,o=0){return U.createHalfEdgePairWithCoordinates(e,t,n,i,s,r,a,o,this.allHalfEdges)}createEdgeIdId(e=0,t=0){return U.createHalfEdgePairWithCoordinates(0,0,0,e,0,0,0,t,this.allHalfEdges)}createEdgeXYZHalfEdge(e=0,t=0,n=0,i=0,s,r=0){const a=U.createHalfEdgePairWithCoordinates(e,t,n,i,s.x,s.y,s.z,r,this.allHalfEdges),o=a.faceSuccessor;return U.pinch(s,o),a}createEdgeHalfEdgeHalfEdge(e,t,n,i=0){const s=U.createHalfEdgePairWithCoordinates(e.x,e.y,e.z,t,n.x,n.y,n.z,i,this.allHalfEdges),r=s.faceSuccessor;return U.pinch(e,s),U.pinch(n,r),s}createEdgeXYAndZ(e,t,n,i){return U.createHalfEdgePairWithCoordinates(e.x,e.y,e.z,t,n.x,n.y,n.z,i,this.allHalfEdges)}splitEdge(e,t=0,n=0,i=0,s=0){return U.splitEdge(e,t,n,i,s,this.allHalfEdges)}splitEdgeCreateSliverFace(e){return U.splitEdgeCreateSliverFace(e,this.allHalfEdges)}splitEdgeAtFraction(e,t){return U.splitEdge(e,e.fractionToX(t),e.fractionToY(t),e.fractionToZ(t),0,this.allHalfEdges)}decommission(){for(const e of this.allHalfEdges)e.decommission();this.allHalfEdges.length=0,this.allHalfEdges=void 0}addEdgeXY(e,t,n,i,s,r,a,o){const c=U.createEdgeXYXY(e,t,n,i),d=c.faceSuccessor;return c.edgeTag=s,c.faceTag=a,d.edgeTag=r,d.faceTag=o,this.allHalfEdges.push(c,d),c}clearMask(e){for(const t of this.allHalfEdges)t.maskBits&=~e}setMask(e){for(const t of this.allHalfEdges)t.maskBits|=e}reverseMask(e){for(const t of this.allHalfEdges)t.maskBits^=e}countMask(e){let t=0;for(const n of this.allHalfEdges)n.isMaskSet(e)&&t++;return t}collectSegments(){const e=[];for(const t of this.allHalfEdges)t.id<t.edgeMate.id&&e.push(Q.createXYXY(t.x,t.y,t.faceSuccessor.x,t.faceSuccessor.y));return e}countVertexLoops(){let e=0;return this.announceVertexLoops((t,n)=>(e++,!0)),e}countFaceLoops(){let e=0;return this.announceFaceLoops((t,n)=>(e++,!0)),e}countFaceLoopsWithMaskFilter(e,t){let n=0;return this.announceFaceLoops((i,s)=>(e(s,t)&&n++,!0)),n}collectVertexLoops(){const e=[];return this.announceVertexLoops((t,n)=>(e.push(n),!0)),e}collectFaceLoops(){const e=[];return this.announceFaceLoops((t,n)=>(e.push(n),!0)),e}announceVertexLoops(e){this.clearMask(O.VISITED);for(const t of this.allHalfEdges)if(!t.getMask(O.VISITED)&&(t.setMaskAroundVertex(O.VISITED),!e(this,t)))break}announceFaceLoops(e){this.clearMask(O.VISITED);for(const t of this.allHalfEdges)if(!t.getMask(O.VISITED)&&(t.setMaskAroundFace(O.VISITED),!e(this,t)))break}announceEdges(e){this.clearMask(O.VISITED);for(const t of this.allHalfEdges){if(t.getMask(O.VISITED))continue;const n=t.edgeMate;if(t.setMask(O.VISITED),n.setMask(O.VISITED),!e(this,t))break}}announceNodes(e){for(const t of this.allHalfEdges)if(!e(this,t))break}countNodes(){return this.allHalfEdges.length}transformInPlace(e){for(const t of this.allHalfEdges)e.multiplyXYAndZInPlace(t)}yankAndDeleteEdges(e){const t=this.allHalfEdges.length;let n=0;for(let s=0;s<t;s++){const r=this.allHalfEdges[s];e(r)?r.yankFromVertexLoop():this.allHalfEdges[n++]=r}const i=t-n;return this.allHalfEdges.length=n,i}deleteIsolatedEdges(){const e=this.allHalfEdges.length;let t=0;for(let i=0;i<e;i++){const s=this.allHalfEdges[i];s.isIsolatedEdge||(this.allHalfEdges[t++]=s)}const n=e-t;return this.allHalfEdges.length=t,n}constructIdToVertexIndexMap(){const e=new Map;return this.allHalfEdges.forEach((t,n)=>e.set(t.id,n)),this.announceVertexLoops((t,n)=>{let i=this.allHalfEdges.length;return n.announceEdgesAroundVertex(s=>{const r=e.get(s.id);r!==void 0&&r<i&&(i=r)}),n.announceEdgesAroundVertex(s=>e.set(s.id,i)),!0}),e}constructIdToFaceIndexMap(){const e=new Map;return this.allHalfEdges.forEach((t,n)=>e.set(t.id,n)),this.announceFaceLoops((t,n)=>{let i=this.allHalfEdges.length;return n.announceEdgesInFace(s=>{const r=e.get(s.id);r!==void 0&&r<i&&(i=r)}),n.announceEdgesInFace(s=>e.set(s.id,i)),!0}),e}}class Xc{priorityQueue;activeEdges;constructor(e=(t,n)=>qe.compareNodesYXUp(t,n)){this.priorityQueue=new Pc(e),this.activeEdges=[]}popQueueToArray(){if(this.priorityQueue.isEmpty)return;const e=this.priorityQueue.pop();return this.activeEdges.push(e),e}popArrayToArrayIndex(e){const t=this.activeEdges.length;if(0<=e&&e<t-1&&t>0){const n=this.activeEdges.pop();this.activeEdges[e]=n}}removeArrayMembersWithY1Below(e){let t=0;const n=this.activeEdges.length;for(let i=0;i<n;i++){const s=this.activeEdges[i];s.faceSuccessor.y>=e&&(t<i&&(this.activeEdges[t]=s),t++)}this.activeEdges.length=t}}class Ui{static announceEdge;constructor(e){this.graph=e,this.upEdges=[],this.downEdges=[],this.bottomPeaks=[],this.topPeaks=[],this.localMin=[],this.localMax=[]}graph;upEdges;downEdges;topPeaks;bottomPeaks;localMin;localMax;collectVerticalEventsAroundFace(e){let t=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;do n=t.faceSuccessor,i=n.faceSuccessor,s=qe.compareNodesYXUp(t,n)<0,r=qe.compareNodesYXUp(n,i)<0,s?(this.upEdges.push(t),r||(qe.crossProductToTargets(n,t,i)<0?this.localMax.push(n):this.topPeaks.push(n))):(this.downEdges.push(t),r&&(qe.crossProductToTargets(n,t,i)>0?this.bottomPeaks.push(n):this.localMin.push(n))),t=n;while(t!==e)}collectVerticalEventFromEdgesInAndArray(e){let 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;for(t of e)n=t.faceSuccessor,i=n.faceSuccessor,s=qe.compareNodesYXUp(t,n)<0,r=qe.compareNodesYXUp(n,i)<0,s?(this.upEdges.push(t),r||(qe.crossProductToTargets(n,t,i)<0?this.localMax.push(n):this.topPeaks.push(n))):(this.downEdges.push(t),r&&(qe.crossProductToTargets(n,t,i)>0?this.bottomPeaks.push(n):this.localMin.push(n)))}swapArrays(){let e=this.downEdges;this.downEdges=this.upEdges,this.upEdges=e,e=this.localMax,this.localMax=this.localMin,this.localMin=e,e=this.topPeaks,this.topPeaks=this.bottomPeaks,this.bottomPeaks=e}findTopVisibleEdge(e,t,n){const i=e.y,s=e.x;let r,a=Number.MAX_SAFE_INTEGER,o;for(const c of t){const d=c.faceSuccessor;if(c===e||d===e)continue;const h=qe.compareNodesYXUp(e,c),u=qe.compareNodesYXUp(e,d);if(h*u>=0)continue;const g=U.horizontalScanFraction01(c,i);g!==void 0&&(r=n*(c.fractionToX(g)-s),r>0&&r<a&&(o=c,a=r))}return o}highestUpPeakConnection(e,t,n){let i;for(const s of this.topPeaks){const r=s.y,a=s.x;if(!(i!==void 0&&qe.compareNodesYXUp(s,i)<0)&&qe.compareNodesYXUp(s,e)<0){if(t){const o=U.horizontalScanFraction01(t,r);if(o===void 0||a<=t.fractionToX(o))continue}if(n){const o=U.horizontalScanFraction01(n,r);if(o===void 0||n.fractionToX(o)<=a)continue}i=s}}return i}updateMaxNode(e,t,n){return e?t&&n(e,t)<0?t:e:t}negateXY(){for(const e of this.graph.allHalfEdges)e.x*=-1,e.y*=-1}downwardConnectionFromBottomPeak(e){let t;const n=(a,o)=>qe.compareNodesYXUp(a,o),i=this.findTopVisibleEdge(e,this.upEdges,1),s=this.findTopVisibleEdge(e,this.downEdges,-1);t=this.updateMaxNode(t,i,n),s&&(t=this.updateMaxNode(t,s.faceSuccessor,n));const r=this.highestUpPeakConnection(e,s,i);return r!==void 0&&(t=this.updateMaxNode(t,r,n)),t}findVisibleSector(e,t){let n=e;do{if(U.isNodeVisibleInSector(t,n))return n;n=n.vertexSuccessor}while(n!==e)}joinNodes(e,t,n){const i=this.graph.createEdgeXYZXYZ(e.x,e.y,e.z,0,t.x,t.y,t.z,0),s=this.findVisibleSector(e,t),r=this.findVisibleSector(t,e);if(s!==void 0&&r!==void 0)return U.pinch(s,i),U.pinch(r,i.edgeMate),i.setMaskAroundEdge(O.REGULARIZED_EDGE),Ui.announceEdge&&Ui.announceEdge(this.graph,i,i.edgeMate,n),i}runRegularization(e=!0,t=!0){if(e){this.bottomPeaks.sort((n,i)=>qe.compareNodesYXUp(n,i));for(const n of this.bottomPeaks){if(!qe.isDownPeak(n))continue;const i=this.downwardConnectionFromBottomPeak(n);i!==void 0&&this.joinNodes(n,i,1)}}if(t){this.negateXY(),this.swapArrays(),this.bottomPeaks.sort((n,i)=>qe.compareNodesYXUp(n,i));for(const n of this.bottomPeaks){if(!qe.isDownPeak(n))continue;const i=this.downwardConnectionFromBottomPeak(n);i!==void 0&&this.joinNodes(n,i,-1)}this.negateXY(),this.swapArrays()}}regularizeFace(e,t=!0,n=!0){this.collectVerticalEventsAroundFace(e),this.runRegularization(t,n)}regularizeGraph(e=!0,t=!0){this.collectVerticalEventFromEdgesInAndArray(this.graph.allHalfEdges),this.runRegularization(e,t)}static isMonotoneFace(e){let t=0,n=0,i,s=e;do{const r=s.faceSuccessor,a=r.faceSuccessor,o=qe.compareNodesYXUp(s,r),c=qe.compareNodesYXUp(r,a);o*c<=0&&(o>0&&(t++,i=r),c>0&&n++)}while((s=s.faceSuccessor)!==e);return t===1&&n===1?i:void 0}static collectMappedFaceRepresentatives(e,t,n,i,s){i&&(i.length=0),s&&(s.length=0);const r=O.VISITED;e.clearMask(r);for(const a of e.allHalfEdges)if(!a.getMask(r)&&(a.setMaskAroundFace(r),!t||a.signedFaceArea()>0)){const o=n(a);o?i&&i.push(o):s&&s.push(a)}}}class Lc{_graph;_candidates;_mask;constructor(e,t){this._graph=e,this._candidates=[],this._mask=t,this._graph.clearMask(t)}clear(){for(;this.chooseAndRemoveAny()!==void 0;);}getLength(){let e=0;for(const t of this._candidates)t.isMaskSet(this._mask)&&e++;return e}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 e=this._candidates.length;if(e===0)return;const t=this._candidates[e-1];return this._candidates.pop(),t}getAtIndex(e){if(e>=0&&e<this._candidates.length){const t=this._candidates[e];if(t.isMaskSet(this._mask))return t}}addToSet(e){return e.isMaskSet(this._mask)?!1:(this._candidates.push(e),this.setMaskInScope(e),!0)}isCandidateInSet(e){return e.isMaskSet(this._mask)}removeFromSet(e){return e.isMaskSet(this._mask)?(this.clearMaskInScope(e),!0):!1}chooseAndRemoveAny(){for(;;){const e=this.popAndReturn();if(!e)return;if(this.removeFromSet(e))return e}}[Symbol.iterator](){return new Yc(this)}addAroundFace(e){let t=e;do this.addToSet(t),t=t.faceSuccessor;while(t!==e)}addAroundVertex(e){let t=e;do this.addToSet(t),t=t.vertexSuccessor;while(t!==e)}}class js extends Lc{constructor(e,t){super(e,t)}static create(e){const t=e.grabMask();if(t!==O.NULL_MASK)return new js(e,t)}setMaskInScope(e){e.setMaskAroundEdge(this._mask)}clearMaskInScope(e){e.clearMaskAroundEdge(this._mask)}countHalfEdgesAroundCandidate(e){return e?2:0}}class Yc{_markSet;_nextReadIndex;constructor(e){this._markSet=e,this._nextReadIndex=0}next(){const e=this._markSet.getNumCandidates();for(;this._nextReadIndex<e;){const t=this._markSet.getAtIndex(this._nextReadIndex++);if(t!==void 0)return{done:!1,value:t}}return{done:!0,value:void 0}}[Symbol.iterator](){return this}}class qn{_node;_x;_y;_z;_u;_v;constructor(e,t,n,i,s,r){this._x=t,this._y=n,this._z=i,this._u=s,this._v=r,this._node=e}set(e,t,n,i,s,r){return this._x=t,this._y=n,this._z=i,this._u=s,this._v=r,this._node=e,this}setFrom(e){this._x=e.x,this._y=e.y,this._z=e.z,this._u=e.u,this._v=e.v,this._node=e.node}static createNodeAndRayOrigin(e,t,n){const i=e.x,s=e.y,r=e.z,a=i-t.origin.x,o=s-t.origin.y,c=f.dotProductXYXY(a,o,t.direction.x,t.direction.y),d=f.crossProductXYXY(t.direction.x,t.direction.y,a,o);return n?n.set(e,i,s,r,c,d):new qn(e,i,s,r,c,d)}static create(e,t=0,n=0,i=0,s=0,r=0){return new qn(e,t,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(e){return y.create(this._x,this._y,this._z,e)}getUVAsPoint2d(e){return L.create(this._u,this._v,e)}classifyU(e,t){const n=this.u-e;return Math.abs(n)<=t?0:n>=0?1:-1}classifyV(e,t){const n=e-this._v;return Math.abs(n)<=t?0:n>=0?1:-1}}var Ot;(function(l){l[l.None=0]="None",l[l.Vertex=1]="Vertex",l[l.Edge=2]="Edge",l[l.Face=3]="Face",l[l.ExteriorFace=4]="ExteriorFace"})(Ot||(Ot={}));class $t{_node;x;y;z;_edgeFraction;_topo;_iTag;_dTag;_isExteriorTarget;constructor(e,t,n,i,s,r,a,o,c){this._node=e,this.x=t,this.y=n,this.z=i,this._topo=s,this._edgeFraction=r,this._iTag=a,this._dTag=o,this._isExteriorTarget=c}setFrom(e){this._node=e._node,this.x=e.x,this.y=e.y,this.z=e.z,this._topo=e._topo,this._edgeFraction=e._edgeFraction,this._iTag=e._iTag,this._dTag=e._dTag}resetAsUnknown(){this._node=void 0,this._topo=Ot.None}static create(){return new $t(void 0,0,0,0,Ot.None)}get iTag(){return this._iTag}set iTag(e){this._iTag=e}get dTag(){return this._dTag}set dTag(e){this._dTag=e}hasDTag(){return this._dTag!==void 0}get topo(){return this._topo}static createEdgeAtFraction(e,t){const n=e.faceSuccessor,i=f.interpolate(e.x,t,n.x),s=f.interpolate(e.y,t,n.y),r=f.interpolate(e.z,t,n.z);return new $t(e,i,s,r,Ot.Edge,t)}resetAsFace(e,t){return this._topo=Ot.Face,e&&(this._node=e),t&&(this.x=t.x,this.y=t.y,this.z=t.z),this._isExteriorTarget=void 0,this}resetAsUndefinedWithTag(e){return this._topo=Ot.None,this._dTag=0,this._iTag=0,this._dTag=e,this._node=void 0,this._isExteriorTarget=void 0,this}resetAtEdgeAndFraction(e,t){this._topo=Ot.Edge,this._node=e;const n=e.faceSuccessor;return this._edgeFraction=t,this.x=f.interpolate(e.x,t,n.x),this.y=f.interpolate(e.y,t,n.y),this.z=f.interpolate(e.z,t,n.z),this._isExteriorTarget=void 0,this}static createVertex(e){return new $t(e,e.x,e.y,e.z,Ot.Vertex)}resetAsVertex(e){return this._topo=Ot.Vertex,this._node=e,this._edgeFraction=0,this.setXYZFromNode(e),this._isExteriorTarget=void 0,this}setIsExteriorTarget(e){this._isExteriorTarget=e}setXYZFromNode(e){this.x=e.x,this.y=e.y,this.z=e.z}get edgeFraction(){return this._edgeFraction}get isExteriorTarget(){return this._isExteriorTarget!==void 0?this._isExteriorTarget:!1}isFace(){return this._topo===Ot.Face&&this._node!==void 0}isEdge(){return this._topo===Ot.Edge&&this._node!==void 0&&this._edgeFraction!==void 0}isVertex(){return this._topo===Ot.Vertex&&this._node!==void 0}get isUnclassified(){return this._topo===Ot.None}get node(){return this._node}clonePoint(e){return y.create(this.x,this.y,this.z,e)}isAtXY(e,t,n=f.smallMetricDistance){return this._topo!==Ot.None&&f.isSameCoordinateXY(this.x,this.y,e,t,n)}}var Vt;(function(l){l[l.NoHits=0]="NoHits",l[l.TargetOnVertex=1]="TargetOnVertex",l[l.TargetOnEdge=2]="TargetOnEdge",l[l.Bracket=3]="Bracket",l[l.TargetBefore=4]="TargetBefore",l[l.TargetAfter=5]="TargetAfter"})(Vt||(Vt={}));class ua{_tol;constructor(e){this._tol=e}static create(e=f.smallMetricDistance){return new ua(e)}panic(){return $t.create()}reAimFromEdge(e,t,n){if(!e.isEdge())return this.panic();const i=e.node,s=qn.createNodeAndRayOrigin(i,t),r=qn.createNodeAndRayOrigin(i.edgeMate,t),a=-s.classifyV(0,this._tol),o=-r.classifyV(0,this._tol);let c;if(a*o<0)a>0?c=e.resetAsFace(s.node):c=e.resetAsFace(r.node);else if(a===0||o===0){const d=s.classifyU(n,this._tol),h=r.classifyU(n,this._tol);if(a===0&&d===0)c=e.resetAsVertex(s.node),c.iTag=1;else if(o===0&&h===0)c=e.resetAsVertex(r.node),c.iTag=1;else if(a===0&&o===0)if(d*h<0){const u=(n-s.u)/(r.u-s.u);c=e.resetAtEdgeAndFraction(s.node,u),c.iTag=1}else d<0&&h<0?s.u>r.u?c=e.resetAsVertex(s.node):c=e.resetAsVertex(r.node):(e.resetAsUnknown(),c=this.panic());else a===0?s.classifyU(0,this._tol)===0?c=e.resetAsVertex(s.node):c=e.resetAsFace(o>0?r.node:s.node):r.classifyU(0,this._tol)===0?c=e.resetAsVertex(r.node):c=e.resetAsFace(a>0?s.node:r.node)}else e.resetAsUnknown(),c=this.panic();return c}reAimFromVertex(e,t,n){if(!e.isVertex())return this.panic();t.origin.isExactEqual(e);const i=e.node;let s=i;const r=a=>{if(Math.abs(a-n)<=this._tol)e.resetAsVertex(s.faceSuccessor).iTag=1;else if(a>n)e.resetAtEdgeAndFraction(s,n/a);else if(a>this._tol)e.resetAsVertex(s.faceSuccessor);else return!1;return!0};do{const a=qn.createNodeAndRayOrigin(s.faceSuccessor,t),o=qn.createNodeAndRayOrigin(s.facePredecessor,t),c=a.u,d=o.u,h=a.v,u=o.v;if(Math.abs(h)<=this._tol){if(r(c))return e;if(Math.abs(c)<=this._tol&&h<=0&&u>this._tol&&(c>=0||c<0&&d>this._tol))return e.resetAsFace(s,s)}else if(h<-this._tol){if(u>this._tol)return e.resetAsFace(s,s);if(u>=-this._tol){if(Math.abs(d)<=this._tol){if(u>0&&(d>=0||c>this._tol&&d<0))return e.resetAsFace(s,s)}else if(c>this._tol&&d<0)return e.resetAsVertex(s.faceSuccessor)}}s=s.vertexSuccessor}while(s!==i);return this.panic()}reAimAroundFace(e,t,n,i,s){e.isMaskSet(O.EXTERIOR),i.resetAsUndefinedWithTag(-Number.MAX_VALUE),s.resetAsUndefinedWithTag(Number.MAX_VALUE);const r=qn.createNodeAndRayOrigin(e,t);let a,o=e;do{const c=o.faceSuccessor;a=qn.createNodeAndRayOrigin(c,t,a);const d=r.u,h=a.u,u=r.v,g=a.v;if(Math.abs(g)<this._tol){const m=$t.createVertex(c);if(m.dTag=h,Math.abs(h-n)<this._tol)return s.setFrom(m),i.setFrom(m),Vt.TargetOnVertex;s.hasDTag()&&i.hasDTag(),h>n&&h<s.dTag&&s.setFrom(m),h<n&&h>i.dTag&&i.setFrom(m)}else if(u*g<0){const m=-u/(g-u),p=f.interpolate(d,m,h),x=$t.createEdgeAtFraction(r.node,m);if(x.dTag=p,Math.abs(p-n)<=this._tol)return s.setFrom(x),i.setFrom(x),Vt.TargetOnEdge;s.hasDTag()&&i.hasDTag(),p>n&&p<s.dTag&&s.setFrom(x),p<n&&p>i.dTag&&i.setFrom(x)}r.setFrom(a),o=o.faceSuccessor}while(o!==e);return s.iTag=0,i.iTag=0,i.isUnclassified?s.isUnclassified?Vt.NoHits:Vt.TargetBefore:s.isUnclassified?Vt.TargetAfter:Vt.Bracket}setSearchRay(e,t,n){n.origin.setFromPoint3d(e),v.createStartEnd(n.origin,t,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 oi;(function(l){l[l.Ignore=0]="Ignore",l[l.Replace=1]="Replace",l[l.ReplaceIfLarger=2]="ReplaceIfLarger",l[l.ReplaceIfSmaller=3]="ReplaceIfSmaller"})(oi||(oi={}));class fa{_graph;_edgeSet;_searcher;_tolerance;constructor(e,t){this._graph=e;const n=js.create(e);this._edgeSet=n,this._searcher=$t.create(),this._tolerance=t}static create(e,t=f.smallMetricDistance){return e.hasFreeMask?new fa(e,t):void 0}get graph(){return this._graph}retriangulateFromBaseVertex(e){const t=e.countEdgesAroundFace();if(t<4||e.isMaskSet(O.EXTERIOR))return;this._edgeSet.addAroundFace(e);const n=t-3;let i=e.faceSuccessor,s=e;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=$t.create()}get currentPosition(){return this._searcher}searchForNearestEdgeOrVertex(e){const t=$t.create();t.dTag=Number.MAX_VALUE;const n=y.create();let i,s;for(const r of this._graph.allHalfEdges){const a=r.faceSuccessor;i=Le.lineSegment3dXYClosestPointUnbounded(r,a,e),i!==void 0&&(i>1?(s=e.distanceXY(a),s<t.dTag&&(t.resetAsVertex(a),t.dTag=s)):i<0?(s=e.distanceXY(r),s<t.dTag&&(t.resetAsVertex(r),t.dTag=s)):(r.fractionToPoint3d(i,n),s=e.distanceXY(n),s<t.dTag&&t.resetAtEdgeAndFraction(r,i)))}return t}searchForNearestVertex(e){const t=$t.create();t.dTag=Number.MAX_VALUE;let n;for(const i of this._graph.allHalfEdges)n=e.distanceXY(i),n<t.dTag&&(t.resetAsVertex(i),t.dTag=n);return t}resetSearch(e,t){t?this._searcher=this.searchForNearestEdgeOrVertex(e):this._searcher=this.searchForNearestVertex(e)}reclassifyFaceHit(e){if(this._searcher.node===void 0||!this._searcher.isFace()||this._searcher.node.isMaskSet(O.EXTERIOR))return!1;const t=y.create(e.x,e.y),n=this._searcher.node.collectAroundFace(a=>{const o=y.create(a.x,a.y);return o.node=a,o}),i=re.closestPointOnBoundary(n,t,this._tolerance);if(i.code,we.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(e){if(this._searcher.node===void 0||!this._searcher.isEdge()||this._searcher.node.isMaskSet(O.BOUNDARY_EDGE))return!1;const t=y.create(e.x,e.y),n=[];for(let a=this._searcher.node.faceSuccessor;a!==this._searcher.node;a=a.faceSuccessor){const o=y.create(a.x,a.y);o.node=a,n.push(o)}for(let a=this._searcher.node.vertexPredecessor;a!==this._searcher.node.edgeMate;a=a.faceSuccessor){const o=y.create(a.x,a.y);o.node=a,n.push(o)}const i=re.closestPointOnBoundary(n,t,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===we.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(e,t,n){oi.Ignore!==n&&(oi.ReplaceIfLarger===n&&t.z<=e.z||oi.ReplaceIfSmaller===n&&t.z>=e.z||e.setXYZAroundVertex(e.x,e.y,t.z))}insertAndRetriangulate(e,t){if(this.moveToPoint(this._searcher,e),this._searcher.node===void 0)return!1;if(this.reclassifyFaceHit(e)||this.reclassifyEdgeHit(e),this._searcher.isFace()){if(!this._searcher.node.isMaskSet(O.EXTERIOR)){const n=this._graph.createEdgeXYZHalfEdge(e.x,e.y,e.z,0,this._searcher.node,0);this.retriangulateFromBaseVertex(n),W.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,e,oi.Replace),this.retriangulateFromBaseVertex(n),this.retriangulateFromBaseVertex(i),W.flipTrianglesInEdgeSet(this._graph,this._edgeSet),this._searcher.resetAsVertex(n)}else this._searcher.isVertex()&&this.updateZAroundVertex(this._searcher.node,e,t);return!0}moveToPoint(e,t,n){const i=ua.create(this._tolerance);if(e.iTag=0,e.isUnclassified&&(zc(this.graph,e,.5,O.NULL_MASK),e.isUnclassified))return!1;let s=0;const r=q.createXAxis();for(;e.iTag===0&&s<2&&!(n!==void 0&&!n(e));){if(!i.setSearchRay(e,t,r))return!1;if(r.a,e.isFace()){const a=$t.create(),o=$t.create();switch(i.reAimAroundFace(e.node,r,r.a,a,o)){case Vt.NoHits:{e.resetAsUnknown();break}case Vt.TargetOnVertex:{e.setFrom(a),e.iTag=1;break}case Vt.TargetOnEdge:{e.setFrom(a),e.iTag=1;break}case Vt.Bracket:{e.resetAsFace(a.node,t),e.iTag=1;break}case Vt.TargetBefore:{e.resetAsFace(e.node,t),e.iTag=1;break}case Vt.TargetAfter:{e.node===a.node&&e.isFace()&&(a.isEdge()||a.isVertex())?s++:s=0,e.setFrom(a);break}}}else if(e.isEdge()){if(i.reAimFromEdge(e,r,r.a),e.isUnclassified)break}else if(e.isVertex()&&(i.reAimFromVertex(e,r,r.a),e.isUnclassified))break}return e.isAtXY(t.x,t.y,this._tolerance)?!0:(s>1&&e.node!==void 0&&e.setIsExteriorTarget(!0),!1)}}function zc(l,e,t,n){for(const i of l.allHalfEdges)if(!i.isMaskSet(n))return e.resetAtEdgeAndFraction(i,t),!0;return!1}class W{static flipEdgeBetweenTriangles(e,t,n,i,s,r){U.pinch(e,s),U.pinch(n,i),U.pinch(r,n),U.pinch(s,t),s.x=t.x,s.y=t.y,s.z=t.z,s.i=t.i,n.i=r.i,n.x=r.x,n.y=r.y,n.z=r.z}static computeCircumcircleDeterminantIsStrongPositive(e){const t=e.faceSuccessor,n=t.faceSuccessor;if(n.faceSuccessor!==e)return!1;const i=e.edgeMate,r=i.faceSuccessor.faceSuccessor;if(r.faceSuccessor!==i)return!1;const a=t.x-e.x,o=t.y-e.y,c=n.x-e.x,d=n.y-e.y;if(f.crossProductXYXY(a,o,c,d)<0)return!1;const h=r.x-e.x,u=r.y-e.y,g=h*h+u*u,m=c*c+d*d,p=a*a+o*o,x=f.tripleProduct(h,u,g,c,d,m,a,o,p);if(x<0)return!1;const _=Math.abs(h*d*p)+Math.abs(u*m*a)+Math.abs(g*c*o)+Math.abs(h*m*o)+Math.abs(u*c*p)+Math.abs(g*d*a);return x>1e-12*_}static flipTriangles(e){const t=js.create(e);if(!t)return 0;for(const i of e.allHalfEdges)t.addToSet(i);const n=this.flipTrianglesInEdgeSet(e,t);return t.teardown(),n}static flipTrianglesInEdgeSet(e,t){const n=O.EXTERIOR|O.PRIMARY_EDGE|O.BOUNDARY_EDGE,s=10*e.allHalfEdges.length;let r=0,a=0,o;for(;(o=t.chooseAndRemoveAny())!==void 0&&!(!o.isMaskSet(n)&&(W.computeCircumcircleDeterminantIsStrongPositive(o)?(W.flipEdgeBetweenTriangles(o.edgeMate.faceSuccessor,o.edgeMate.facePredecessor,o.edgeMate,o.faceSuccessor,o,o.facePredecessor),t.addAroundFace(o),t.addAroundFace(o.edgeMate),r++):a++,r+a>s)););return r}static createTriangulatedGraphFromPoints(e,t=oi.ReplaceIfLarger,n=f.smallMetricDistance){if(e.length<3)return;const i=[],s=[];lt.computeConvexHullXY(e,i,s,!0);const r=new Ut,a=fa.create(r,n),o=W.createFaceLoopFromCoordinates(r,i,!0,!0);if(o!==void 0){for(const c of s)a.insertAndRetriangulate(c,t);return o.countEdgesAroundFace()>3?W.createTriangulatedGraphFromSingleLoop(i):r}}static createTriangulatedGraphFromLoops(e){if(e.length<1)return;const t=O.BOUNDARY_EDGE|O.PRIMARY_EDGE,n=new Ut,i=[];let s=-1e4,r=-1;for(let c=0;c<e.length;c++){let d=W.directCreateFaceLoopFromCoordinates(n,e[c]);if(d){d=d.faceSuccessor;const h=d.vertexSuccessor;d.setMaskAroundFace(t),h.setMaskAroundFace(t);const u=d.signedFaceArea(),g=Math.abs(u);i.push(u>=0?d:h),(c===0||g>s)&&(s=g,r=c)}}if(i.length===0)return;const a=i[r];i[r]=i[i.length-1],i.pop(),a.vertexSuccessor.setMaskAroundFace(O.EXTERIOR);for(let c=0;c<i.length;c++){const d=i[c];d.setMaskAroundFace(O.EXTERIOR),i[c]=this.getLeftmost(d.vertexSuccessor)}const o=W.spliceLeftMostNodesOfHoles(n,a,i);if(o&&W.triangulateSingleFace(n,o))return n}static triangulateAllPositiveAreaFaces(e){const t=e.collectFaceLoops();let n=0;for(const i of t)i.countEdgesAroundFace()>3&&i.signedFaceArea()>0&&(W.triangulateSingleFace(e,i)||n++);return n===0}static _workTransform;static triangulateAllInteriorFaces(e,t,n){const i=e.collectFaceLoops(),s=t?e.grabMask():O.NULL_MASK;n=t||n;let r,a,o=0,c=0;for(const d of i)if(d.countEdgesAroundFace()>3){if(d.getMask(O.EXTERIOR))continue;if(t&&(o=e.countNodes(),a=d.collectAroundFace(),r=this._workTransform=tt.createRightHandedLocalToWorld(a,this._workTransform),r?.multiplyInversePoint3dArrayInPlace(a)),W.triangulateSingleFace(e,d,n)||c++,r&&a){for(let h=o;h<e.countNodes();++h)a.push(e.allHalfEdges[h]);r.multiplyPoint3dArrayInPlace(a)}}return e.dropMask(s),c===0}static createTriangulatedGraphFromSingleLoop(e){const t=new Ut,n=W.createFaceLoopFromCoordinates(t,e,!0,!0);if(!(!n||t.countNodes()<6)&&W.triangulateSingleFace(t,n))return W.flipTriangles(t),t}static interiorEdgeSplit(e,t,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 a=n;a.hasOwnProperty("x")&&(i=a.x),a.hasOwnProperty("y")&&(s=a.y),a.hasOwnProperty("z")&&(r=a.z)}return t&&W.isAlmostEqualXAndYXY(t,i,s)?t:e.splitEdge(t,i,s,r)}static getUnwrappedLength(e){let t=e.length,n,i,s,r;for(;t>1&&(e instanceof gt?(n=e.getXAtUncheckedPointIndex(0),i=e.getYAtUncheckedPointIndex(0),s=e.getXAtUncheckedPointIndex(t-1),r=e.getYAtUncheckedPointIndex(t-1)):f.isArrayOfNumberArray(e,t,2)?(n=e[0][0],i=e[0][1],s=e[t-1][0],r=e[t-1][1]):(n=e[0].x,i=e[0].y,s=e[t-1].x,r=e[t-1].y),f.isAlmostEqualNumber(n,s)&&f.isAlmostEqualNumber(i,r));)--t;return t}static directCreateFaceLoopFromCoordinates(e,t){const n=this.getUnwrappedLength(t);let i;if(t instanceof gt){const s=y.create();for(let r=0;r<n;r++)t.getPoint3dAtCheckedPointIndex(r,s),i=W.interiorEdgeSplit(e,i,s)}else for(let s=0;s<n;s++)i=W.interiorEdgeSplit(e,i,t[s]);return i}static directCreateChainsFromCoordinates(e,t,n=0){const i=new Bc(e,n);return Yn.streamXYZ(t,i),i.claimSeeds()}static maskAndOrientNewFaceLoop(e,t,n,i,s){if(t){t=t.faceSuccessor;const r=t.signedFaceArea(),a=t.edgeMate;i!==O.NULL_MASK&&(t.setMaskAroundFace(i),a.setMaskAroundFace(i));let o=t;n&&r<0&&(o=a);const c=o.vertexSuccessor;return s!==O.NULL_MASK&&c.setMaskAroundFace(s),o}}static createFaceLoopFromCoordinates(e,t,n,i){const s=W.directCreateFaceLoopFromCoordinates(e,t);return W.maskAndOrientNewFaceLoop(e,s,n,O.BOUNDARY_EDGE|O.PRIMARY_EDGE,i?O.EXTERIOR:O.NULL_MASK)}static createFaceLoopFromCoordinatesAndMasks(e,t,n,i,s){const r=W.directCreateFaceLoopFromCoordinates(e,t);return W.maskAndOrientNewFaceLoop(e,r,n,i,s)}static joinNeighborsOfEar(e,t){const n=e.createEdgeXYZXYZ(t.facePredecessor.x,t.facePredecessor.y,t.facePredecessor.z,t.facePredecessor.i,t.faceSuccessor.x,t.faceSuccessor.y,t.faceSuccessor.z,t.faceSuccessor.i),i=n.edgeMate;U.pinch(t.faceSuccessor,i),U.pinch(t.facePredecessor,n),t.setMaskAroundFace(O.TRIANGULATED_FACE)}static isInteriorTriangle(e){if(!e.isMaskSet(O.TRIANGULATED_FACE)||e.isMaskSet(O.EXTERIOR))return!1;const t=e.faceSuccessor;if(!t.isMaskSet(O.TRIANGULATED_FACE)||t.isMaskSet(O.EXTERIOR))return!1;const n=t.faceSuccessor;return!n.isMaskSet(O.TRIANGULATED_FACE)||n.isMaskSet(O.EXTERIOR)?!1:n.faceSuccessor===e}static doPostCutFlips(e){let t=e,n=t.facePredecessor,i=n.edgeMate;for(;W.isInteriorTriangle(n)&&W.isInteriorTriangle(i)&&W.computeCircumcircleDeterminantIsStrongPositive(n);){const r=i.faceSuccessor;W.flipEdgeBetweenTriangles(r,r.faceSuccessor,r.facePredecessor,t,t.facePredecessor,t.faceSuccessor),t=n,n=t.facePredecessor,i=n.edgeMate}return t}static triangulateSingleFace(e,t,n=!1){if(!t)return W.setDebugGraph(e),!1;let i,s,r,a=t.countEdgesAroundFace(),o=0;for(t.clearMaskAroundFace(O.TRIANGULATED_FACE);!t.isMaskSet(O.TRIANGULATED_FACE);){if(r=t?.facePredecessor,i=t.faceSuccessor,s=i.faceSuccessor,i===t||s===t)return!0;if(s.faceSuccessor===t)return t.setMaskAroundFace(O.TRIANGULATED_FACE),!0;if(W.isAlmostEqualXAndYXY(s,r.x,r.y)&&!s.findAroundVertex(r)){const c=s.faceSuccessor;if(this.nodeInTriangle(r,t,i,c)){const h=s.vertexPredecessor;U.pinch(r.vertexSuccessor,h)}else U.pinch(r,s),t.setMaskAroundFace(O.TRIANGULATED_FACE);t=s;continue}if(++o>a)return W.setDebugGraph(e),!1;if(W.isEar(t)){a--,o=0,t.faceSuccessor.faceSuccessor!==t.facePredecessor?(W.joinNeighborsOfEar(e,t),n||(t=W.doPostCutFlips(t)),t=t.faceSuccessor.edgeMate.faceSuccessor):(t.setMaskAroundFace(O.TRIANGULATED_FACE),t=i.faceSuccessor);continue}t=i}return!0}static sDebugGraph;static sEnableDebugGraphCapture=!1;static claimDebugGraph(){const e=W.sDebugGraph;return W.sDebugGraph=void 0,W.sEnableDebugGraphCapture=!1,e}static setDebugGraph(e){W.sEnableDebugGraphCapture&&(W.sDebugGraph=e)}static clearAndEnableDebugGraphCapture(e){W.sEnableDebugGraphCapture=e,W.sDebugGraph=void 0}static findAroundOrAtVertex(e,t){return e.findAroundVertex(t)?!0:W.isAlmostEqualXAndYXY(e,t.x,t.y)}static _edgeInterval=fe.createNull();static _earRange=ze.createNull();static _edgeRange=ze.createNull();static _planes=[pe.createXYPlane(),pe.createXYPlane(),pe.createXYPlane()];static isEar(e){const t=e.facePredecessor,n=e,i=e.faceSuccessor,s=W.signedTolerancedCCWTriangleArea(t,n,i);if(s<=0)return!1;const r=this._planes;if(!pe.createOriginAndTargetXY(t,n,r[0])||!pe.createOriginAndTargetXY(n,i,r[1])||!pe.createOriginAndTargetXY(i,t,r[2]))return!1;const a=this._earRange,o=this._edgeRange,c=this._edgeInterval;ze.createXYXYXY(t.x,t.y,n.x,n.y,i.x,i.y,a),a.expandInPlace(f.smallMetricDistance);let d=i;const h=1e-8,u=-h,g=1+h,m=1-h,p=1e-10*s;for(;d!==t;){const x=d.faceSuccessor;if(ze.createXYXY(d.x,d.y,x.x,x.y,o),a.intersectsRange(o)&&(fe.createXX(u,g,c),at.clipSegmentBelowPlanesXY(r,d,x,c,p),!c.isNull)){if(c.low>m){if(!this.findAroundOrAtVertex(t,x)&&!this.findAroundOrAtVertex(n,x)&&!this.findAroundOrAtVertex(i,x))return!1}else if(c.high<h){if(!this.findAroundOrAtVertex(t,d)&&!this.findAroundOrAtVertex(n,d)&&!this.findAroundOrAtVertex(i,d))return!1}else if(!(this.findAroundOrAtVertex(n,x)&&this.findAroundOrAtVertex(i,d))){if(!(this.findAroundOrAtVertex(t,x)&&this.findAroundOrAtVertex(n,d)))return!1}}d=d.faceSuccessor}return!0}static spliceLeftMostNodesOfHoles(e,t,n){n.sort((s,r)=>W.compareX(s,r));let i=0;for(const s of n)W.eliminateHole(e,s,t)||i++;return i===0?t:void 0}static compareX(e,t){return e.x-t.x}static eliminateHole(e,t,n){const i=W.findHoleBridge(t,n);return i?W.splitFace(e,i,t)!==void 0:!1}static findHoleBridge(e,t){let n=t;if(!n)return;const i=e.x,s=e.y;let r=-1/0,a;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}a=n.x<n.faceSuccessor.x?n:n.faceSuccessor}}n=n.faceSuccessor}while(n!==t);if(!a)return;if(i===r)return a.facePredecessor;const o=a,c=a.x,d=a.y;let h=1/0,u;for(n=a.faceSuccessor;n!==o;)i>=n.x&&n.x>=c&&i!==n.x&&W.pointInTriangle(s<d?i:r,s,c,d,s<d?r:i,s,n.x,n.y)&&(u=Math.abs(s-n.y)/(i-n.x),(u<h||u===h&&n.x>a.x)&&W.locallyInside(n,e)&&(a=n,h=u)),n=n.faceSuccessor;return a}static getLeftmost(e){let t=e,n=e;do t.x<n.x&&(n=t),t=t.faceSuccessor;while(t!==e);return n}static pointInTriangle(e,t,n,i,s,r,a,o){return(s-a)*(t-o)-(e-a)*(r-o)>=0&&(e-a)*(i-o)-(n-a)*(t-o)>=0&&(n-a)*(r-o)-(s-a)*(i-o)>=0}static nodeInTriangle(e,t,n,i){return W.signedTolerancedCCWTriangleArea(e,t,i)>0&&W.signedTolerancedCCWTriangleArea(t,n,i)>0&&W.signedTolerancedCCWTriangleArea(n,e,i)>0}static signedCWTriangleArea(e,t,n){return .5*((t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y))}static signedTolerancedCCWTriangleArea(e,t,n,i=1e-12){const s=t.x-e.x,r=t.y-e.y,a=n.x-e.x,o=n.y-e.y,c=.5*(s*o-r*a);if(c<0)return c;const d=s*s+r*r,h=a*a+o*o;return c<i*(d+h)?0:c}static isAlmostEqualXAndYXY(e,t,n){return f.isAlmostEqualNumber(e.x,t)&&f.isAlmostEqualNumber(e.y,n)}static locallyInside(e,t){return W.signedCWTriangleArea(e.facePredecessor,e,e.faceSuccessor)<0?W.signedCWTriangleArea(e,t,e.faceSuccessor)>=0&&W.signedCWTriangleArea(e,e.facePredecessor,t)>=0:W.signedCWTriangleArea(e,t,e.facePredecessor)<0||W.signedCWTriangleArea(e,e.faceSuccessor,t)<0}static splitFace(e,t,n){if(U.isNodeVisibleInSector(t,n)&&U.isNodeVisibleInSector(n,t)){const i=e.createEdgeXYZXYZ(t.x,t.y,t.z,t.i,n.x,n.y,n.z,n.i),s=i.faceSuccessor;return U.pinch(t,i),U.pinch(n,s),i}}static triangulateSingleMonotoneFace(e,t){let n=t.facePredecessor,i=t.faceSuccessor,s;for(;n!==i&&i!==t&&i.faceSuccessor!==n;){if(U.crossProductXYAlongChain(n,t,i)<=0||!t.belowYX(n)||!t.belowYX(i))return!1;if(n.belowYX(i)){let r=n,a=t,o=i;for(;r!==o&&r.belowYX(i);){for(;o!==i&&o!==r&&o!==a&&U.crossProductXYAlongChain(r,a,o)>0;){if(s=W.splitFace(e,r,o),s===void 0)return!1;r=s,a=r.faceSuccessor,o=a.faceSuccessor}o=a,a=r,r=r.facePredecessor}for(n=a,o=i,a=o.facePredecessor,r=a.facePredecessor;o.faceSuccessor!==r&&r!==n;){if(s=W.splitFace(e,r,o),s===void 0)return!1;a=s,r=a.facePredecessor}if(o.faceSuccessor!==r){if(s=W.splitFace(e,r,o),s===void 0)return!1;r=s}t=r,i=t.faceSuccessor,n=t.facePredecessor}else{let r=n,a=t,o=i;for(;r!==o&&o.belowYX(n);){for(;r!==n&&o!==r&&o!==a&&U.crossProductXYAlongChain(r,a,o)>0;){if(s=W.splitFace(e,r,o),s===void 0)return!1;r=s.facePredecessor,a=s}r=a,a=o,o=o.faceSuccessor}for(i=a,r=n,a=r.faceSuccessor,o=a.faceSuccessor;o.faceSuccessor!==r&&o!==i;){if(s=W.splitFace(e,r,o),s===void 0)return!1;r=s,o=o.faceSuccessor}if(o.faceSuccessor!==r&&W.splitFace(e,r,o)===void 0)return!1;t=i,i=t.faceSuccessor,n=t.facePredecessor}}return!0}}class Bc extends Sc{_seeds;_baseNode;_nodeB;_nodeC;_graph;_id;constructor(e,t){super(),this._graph=e,this._id=t}startChain(e,t){super.startChain(e,t),this._baseNode=void 0,this._nodeB=void 0}handleXYZXYZ(e,t,n,i,s,r){this._nodeC=this._graph.createEdgeXYZXYZ(e,t,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&&(U.pinch(this._nodeB,this._nodeC),this._nodeB=this._nodeC.faceSuccessor))}endChain(e,t){super.endChain(e,t),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 Uc{numUpEdge=0;numIntersectionTest=0;numSplit=0;numPopOut=0;numA0B0=0;numA0B1=0;constructor(){}}class xo{index;radiusOfCurvature;node;radians;constructor(e,t,n,i){this.index=e,this.radiusOfCurvature=t,this.node=n,this.radians=i}}class qe{static compareNodesYXUp(e,t){return e.y<t.y?-1:e.y>t.y?1:e.x<t.x?-1:e.x>t.x?1:0}static isDownPeak(e){const t=e.facePredecessor,n=e.faceSuccessor;return this.compareNodesYXUp(e,t)<0&&this.compareNodesYXUp(e,n)<0&&this.crossProductToTargets(e,t,n)>0}static crossProductToTargets(e,t,n){return f.crossProductXYXY(t.x-e.x,t.y-e.y,n.x-e.x,n.y-e.y)}static graphRange(e){const t=ie.create();for(const n of e.allHalfEdges)t.extendXYZ(n.x,n.y,n.z);return t}static graphRangeXY(e){const t=ze.createNull();for(const n of e.allHalfEdges)t.extendXY(n.x,n.y);return t}static segmentArrayToGraphEdges(e,t,n){const i=[];let s=0;for(const r of e){const a=t.createEdgeXYZXYZ(r.point0Ref.x,r.point0Ref.y,r.point0Ref.z,s,r.point1Ref.x,r.point1Ref.y,r.point1Ref.z,s+1),o=a.edgeMate;s+=2,a.setMaskAroundFace(n),i.push(a),i.push(o)}return i}static isolateAllEdges(e){for(const t of e.allHalfEdges){const n=t.vertexPredecessor;U.pinch(t,n)}}static isSectorConvexAfterEdgeRemoval(e,t,n,i=0){let s=e;do{if(s.isMaskSet(n)||s.edgeMate.isMaskSet(n))break;s=s.vertexSuccessor}while(s!==e&&s.isMaskSet(t));if(s===e)return!1;let r=e;do{if(r.isMaskSet(n)||r.edgeMate.isMaskSet(n))break;r=r.vertexPredecessor}while(r!==e&&r.isMaskSet(t));return r===e?!1:U.isSectorConvex(s.edgeMate,e,r.faceSuccessor,i)}static markRemovableEdgesToExpandConvexFaces(e,t,n=O.BOUNDARY_EDGE){if(O.NULL_MASK===t)return 0;const i=e.grabMask(!0);let s=0;for(const r of e.allHalfEdges){if(!r.isMaskSet(i)&&!r.isMaskSet(n)&&!r.edgeMate.isMaskSet(n)){const a=f.smallMetricDistanceSquared*(r.signedFaceArea()+r.edgeMate.signedFaceArea());this.isSectorConvexAfterEdgeRemoval(r,t,n,a)&&this.isSectorConvexAfterEdgeRemoval(r.edgeMate,t,n,a)&&(r.setMaskAroundEdge(t),++s)}r.setMaskAroundEdge(i)}return e.dropMask(i),s}static collectRemovableEdgesToExpandConvexFaces(e,t=O.BOUNDARY_EDGE){const n=[],i=e.grabMask(!0);if(0<this.markRemovableEdgesToExpandConvexFaces(e,i,t)){const s=e.grabMask(!0);for(const r of e.allHalfEdges)r.isMaskSet(i)&&!r.isMaskSet(s)&&(r.setMaskAroundEdge(s),n.push(r));e.dropMask(s)}return e.dropMask(i),n}static expandConvexFaces(e,t=O.BOUNDARY_EDGE){const n=e.grabMask(!0),i=this.markRemovableEdgesToExpandConvexFaces(e,n,t);return i>0&&.5*e.yankAndDeleteEdges(s=>s.getMask(n)),e.dropMask(n),i}static isEveryFaceConvex(e,t=O.EXTERIOR){const n=e.collectFaceLoops();for(const i of n)if(!i.isMaskedAroundFace(t)&&!i.isFaceConvex())return!1;return!0}}class rn{static getCommonThetaEndIndex(e,t,n,i,s=f.smallAngleRadians){let r=n+1;const a=e.getExtraData(t[n],0);for(;r<i;){const o=e.getExtraData(t[r],0);if(!T.isAlmostEqualRadiansAllowPeriodShift(a,o,s))return r;r++}return r}static _announceVertexNeighborhoodFunction;static set announceVertexNeighborhoodFunction(e){this._announceVertexNeighborhoodFunction=e}static doAnnounceVertexNeighborhood(e,t,n,i,s){if(this._announceVertexNeighborhoodFunction){const r=[];for(let a=i;a<s;a++){const o=e.getExtraData(t[a],1),c=e.getExtraData(t[a],0),d=n[o],h=this.curvatureSortKey(d);r.push(new xo(t[a],h,d,c))}this._announceVertexNeighborhoodFunction(r)}}static secondarySortAroundVertex(e,t,n,i,s,r=f.smallAngleRadians){const a=[];for(let o=i;o<s;){const c=this.getCommonThetaEndIndex(e,t,o,s,r);if(o+1<c){a.length=0;for(let d=o;d<c;d++){const h=e.getExtraData(t[d],1),u=n[h],g=this.curvatureSortKey(u);a.push(new xo(t[d],g,u))}a.sort((d,h)=>d.radiusOfCurvature-h.radiusOfCurvature);for(let d=0;d<a.length;d++)t[o+d]=a[d].index}o=c}}static curvatureSortKey(e){if(e.edgeTag!==void 0&&e.edgeTag instanceof Y){const t=e.edgeTag;if(t.curve!==void 0){const n=e.sortData!==void 0&&e.sortData<0,i=n&&t.fraction1!==void 0?t.fraction1:t.fraction,s=t.curve.fractionToSignedXYRadiusOfCurvature(i);return n?-s:s}}return 0}static isNullFace(e){return e.isMaskSet(O.NULL_FACE)&&e.faceSuccessor.isMaskSet(O.NULL_FACE)&&e===e.faceSuccessor.faceSuccessor}static clusterAndMergeXYTheta(e,t,n=f.smallMetricDistance,i=f.smallAngleRadians){const s=e.allHalfEdges,r=s.length;e.clearMask(O.NULL_FACE);const a=new Re(2,2,r);for(let m=0;m<r;m++){const p=s[m],x=p.x,_=p.y;U.pinch(p,p.vertexSuccessor),a.addDirect(x,_,0,m)}const o=a.clusterIndicesLexical(n);let c=0;const d=o.length;for(let m=0;m<d;m++)if(o[m]===Re.clusterTerminator){if(m>c){const p=a.getExtraData(o[c],1),x=s[p];for(let _=c+1;_<m;_++){const I=a.getExtraData(o[_],1),S=s[I];S.x=x.x,S.y=x.y}}c=m+1}for(const m of o)if(m!==Re.clusterTerminator){const p=s[m],x=p.faceSuccessor;let _=t;if(_){const S=p.edgeTag;(S===void 0||S.curve===void 0||S.curve instanceof Q)&&(_=void 0)}let I=_?_(p):Math.atan2(x.y-p.y,x.x-p.x);T.isAlmostEqualRadiansAllowPeriodShift(I,-Math.PI,i)&&(I=Math.PI),a.setExtraData(m,0,I)}a.sortSubsetsBySingleKey(o,2);const h=[];c=0;let u,g;for(let m=0;m<d;m++)if(o[m]===Re.clusterTerminator){if(m>c){m>c+1&&this.secondarySortAroundVertex(a,o,s,c,m,i),this.doAnnounceVertexNeighborhood(a,o,s,c,m);const p=a.getExtraData(o[c],1);u=a.getExtraData(o[c],0);let _=s[p];for(let I=c+1;I<m;I++){const S=a.getExtraData(o[I],1);g=a.getExtraData(o[I],0);const A=s[S];if(_.isMaskSet(O.NULL_FACE)){const w=h.findIndex(k=>_===k);w>=0&&(h[w]=h[h.length-1],h.pop()),_=A,u=g}else if(A.isMaskSet(O.NULL_FACE)){const w=h.findIndex(k=>A===k);w>=0&&(h[w]=h[h.length-1],h.pop())}else{if(U.pinch(_,A),T.isAlmostEqualRadiansAllowPeriodShift(u,g,i)){const w=_.faceSuccessor,k=A.edgeMate;if(w.isEqualXY(k)){const D=this.curvatureSortKey(_),P=this.curvatureSortKey(A);f.isSameCoordinate(D,P,n)&&(U.pinch(w,k),_.setMask(O.NULL_FACE),k.setMask(O.NULL_FACE),h.push(k))}}_=A,u=g}}}c=m+1}}static buildVerticalSweepPriorityQueue(e){const t=new Xc;for(const n of e.allHalfEdges)qe.compareNodesYXUp(n,n.faceSuccessor)<0&&t.priorityQueue.push(n);return t}static computeIntersectionFractionsOnEdges(e,t,n=f.smallMetricDistance){const i=e.faceSuccessor,s={x:i.x-e.x,y:i.y-e.y},r=t.faceSuccessor,a={x:r.x-t.x,y:r.y-t.y};let o=Le.lineSegmentXYUVIntersectionUnbounded(e,s,t,a,n);if(o){const c=(d,h,u)=>{const g=f.interpolate(h.x,d,u.x),m=f.interpolate(h.y,d,u.y);return f.isSameCoordinateXY(g,m,h.x,h.y,n)?0:f.isSameCoordinateXY(g,m,u.x,u.y,n)?1:d};o.f0.x=c(o.f0.x,e,i),o.f0.y=c(o.f0.y,t,r),o.f1&&(o.f1.x=c(o.f1.x,e,i),o.f1.y=c(o.f1.y,t,r)),o.f1&&!(f.isIn01(o.f1.x)&&f.isIn01(o.f1.y))&&(o.f1=void 0),f.isIn01(o.f0.x)&&f.isIn01(o.f0.y)||(o.f1?(o.f0=o.f1,o.f1=void 0):o=void 0)}return o}static splitIntersectingEdges(e,t=f.smallMetricDistance,n=1e-8){const i=new Uc,s=this.buildVerticalSweepPriorityQueue(e);let r,a;const o=n,c=1-o;let d,h;for(;(r=s.priorityQueue.pop())!==void 0;){i.numUpEdge++;const u=s.activeEdges.length;for(s.removeArrayMembersWithY1Below(r.y-t),i.numPopOut+=u-s.activeEdges.length,d=0;d<s.activeEdges.length;d++)if(h=s.activeEdges[d],a=h.faceSuccessor,f.isSameCoordinateXY(r.x,r.y,h.x,h.y,t))i.numA0B0++;else if(f.isSameCoordinateXY(a.x,a.y,r.x,r.y,t))i.numA0B1++;else{i.numIntersectionTest++;const g=this.computeIntersectionFractionsOnEdges(r,h,t);if(g){const m=(p,x)=>{if(x!==void 0&&x>o&&x<c){const _=e.splitEdgeAtFraction(p,x);s.priorityQueue.push(_),i.numSplit++}};m(r,g.f0.x),m(r,g.f1?.x),m(h,g.f0.y),m(h,g.f1?.y)}}s.activeEdges.push(r)}return i}static formGraphFromSegments(e){const t=new Ut;return qe.segmentArrayToGraphEdges(e,t,O.BOUNDARY_EDGE),this.splitIntersectingEdges(t),this.clusterAndMergeXYTheta(t),t}static formGraphFromChains(e,t=!0,n=O.PRIMARY_EDGE){if(e.length<1)return;const i=new Ut,s=W.directCreateChainsFromCoordinates(i,e);for(const r of s)r.setMaskAroundFace(n);return this.splitIntersectingEdges(i),this.clusterAndMergeXYTheta(i),t&&new Ui(i).regularizeGraph(!0,!0),i}}class Zn{tolerance;static _defaultPrimarySortDirection=v.create(.294234298,.72391399,.45234328798);primarySortDirection;static createPrimarySortVector(e){return e===void 0&&(e=this._defaultPrimarySortDirection.clone()),e.normalizeWithDefault(Zn._defaultPrimarySortDirection.x,Zn._defaultPrimarySortDirection.y,Zn._defaultPrimarySortDirection.z)}constructor(e,t){this.tolerance=e,this.primarySortDirection=t}static createFromUnValidated(e){const t=new Zn(f.smallMetricDistance,Zn.createPrimarySortVector());return e!==void 0&&(e.tolerance!==void 0&&(t.tolerance=e.tolerance),e.primarySortDirection!==void 0&&(t.primarySortDirection=Zn.createPrimarySortVector())),t}clone(){return new Zn(this.tolerance,this.primarySortDirection)}}class an{_graph;_options;_plane;_convexClipper;constructor(e){this._graph=new Ut,this._options=e}set plane(e){this._plane=e}get plane(){return this._plane}set convexClipper(e){this._convexClipper=e}get convexClipper(){return this._convexClipper}static create(e){const t=Zn.createFromUnValidated(e);return new an(t)}addSegment(e,t){this._graph.createEdgeXYZXYZ(e.x,e.y,e.z,0,t.x,t.y,t.z,0)}addLineSegment3dArray(e){for(const t of e)this.addSegment(t.point0Ref,t.point1Ref)}addSegmentsOnPlane(e,t=!1){if(!this._plane)return;const n=this._plane;let i=t?e.length-1:0,s=e.evaluateUncheckedIndexPlaneAltitude(i,n),r=t?0:1,a;for(;r<e.length;i=r++,s=a)a=e.evaluateUncheckedIndexPlaneAltitude(r,n),f.isSmallMetricDistance(s)&&f.isSmallMetricDistance(a)&&this._graph.createEdgeXYZXYZ(e.getXAtUncheckedPointIndex(i),e.getYAtUncheckedPointIndex(i),e.getZAtUncheckedPointIndex(i),0,e.getXAtUncheckedPointIndex(r),e.getYAtUncheckedPointIndex(r),e.getZAtUncheckedPointIndex(r),0)}primarySortKey(e){return this._options.primarySortDirection.dotProductXYZ(e.x,e.y,e.z)}static nodeCompareSortData(e,t){return e.sortData!==void 0&&t.sortData,e.sortData-t.sortData}static isIsolatedEnd(e){return e.vertexSuccessor===e}static isChainInteriorVertex(e){const t=e.vertexSuccessor;return t!==e&&t.vertexSuccessor===e}clusterAndMergeVerticesXYZ(){qe.isolateAllEdges(this._graph);for(const i of this._graph.allHalfEdges)i.sortData=this.primarySortKey(i);const e=this._graph.allHalfEdges.slice();e.sort((i,s)=>an.nodeCompareSortData(i,s));const t=this._options.tolerance,n=e.length;for(let i=0;i<n;i++){const s=e[i],a=s.sortData+t;if(an.isIsolatedEnd(s))for(let o=i+1;o<n;o++){const c=e[o];if(an.isIsolatedEnd(c)){if(c.sortData,c.sortData>a)break;s.distanceXYZ(c)<=t&&(U.pinch(s,c),c.setXYZFrom(s))}}}}collectMaximalLineString3dFromStartNode(e,t,n){if(!t.isMaskSet(n)){const i=N.create();for(i.addPointXYZ(t.x,t.y,t.z);t.setMask(n),t.edgeMate.setMask(n),t=t.faceSuccessor,i.addPointXYZ(t.x,t.y,t.z),!(t.isMaskSet(n)||!an.isChainInteriorVertex(t)););e.push(i)}}collectMaximalGrowableXYXArrayFromStartNode(e,t,n){if(!t.isMaskSet(n)){const i=new J;for(i.pushXYZ(t.x,t.y,t.z);t.setMask(n),t.edgeMate.setMask(n),t=t.faceSuccessor,i.pushXYZ(t.x,t.y,t.z),!(t.isMaskSet(n)||!an.isChainInteriorVertex(t)););i.length>0&&e.push(i)}}exciseAndMarkSlingEdges(e){let t=0;for(const n of this._graph.allHalfEdges)if(n.distanceXYZ(n.edgeMate)<this._options.tolerance&&!n.isMaskSet(e)){const i=n.edgeMate;U.pinch(n,n.vertexPredecessor),U.pinch(i,i.vertexPredecessor),n.setMask(e),i.setMask(e),t++}return t}collectMaximalChains(){const e=[],t=O.VISITED;this.exciseAndMarkSlingEdges(t),this._graph.clearMask(t);for(const n of this._graph.allHalfEdges)an.isChainInteriorVertex(n)||this.collectMaximalLineString3dFromStartNode(e,n,t);for(const n of this._graph.allHalfEdges)this.collectMaximalLineString3dFromStartNode(e,n,t);return e}collectMaximalGrowableXYZArrays(){const e=[],t=O.VISITED;this.exciseAndMarkSlingEdges(t),this._graph.clearMask(t);for(const n of this._graph.allHalfEdges)an.isChainInteriorVertex(n)||this.collectMaximalGrowableXYXArrayFromStartNode(e,n,t);for(const n of this._graph.allHalfEdges)this.collectMaximalGrowableXYXArrayFromStartNode(e,n,t);return e}}class _o{constructor(){this._unmatchedEdges=new Map,this._graph=new Ut,this._halfEdgesAroundCurrentLoop=[]}_unmatchedEdges;_graph;get graph(){return this._graph}_halfEdgesAroundCurrentLoop;indexPairToString(e,t){return`${e.toString()},${t.toString()}`}insertLoop(e,t){const n=e.length;if(n>2){let i=e[n-1];this._halfEdgesAroundCurrentLoop.length=0;for(const r of e){const a=this.indexPairToString(i,r),o=this._unmatchedEdges.get(a);if(o===void 0){const c=this.indexPairToString(r,i),d=this._graph.createEdgeIdId(i,r);t!==void 0&&t(d),this._unmatchedEdges.set(c,d.edgeMate),this._halfEdgesAroundCurrentLoop.push(d),d.edgeMate.setMask(O.EXTERIOR)}else this._halfEdgesAroundCurrentLoop.push(o),o.clearMask(O.EXTERIOR);i=r}let s=this._halfEdgesAroundCurrentLoop[this._halfEdgesAroundCurrentLoop.length-1];for(const r of this._halfEdgesAroundCurrentLoop){const a=s.faceSuccessor;U.pinch(r,a),s=r}return this._halfEdgesAroundCurrentLoop[0]}}}class Vc{positiveSum;numPositive;negativeSum;numNegative;numZero;largestPositiveItem;largestNegativeItem;largestPositiveValue;largestNegativeValue;negativeItemArray;zeroItemArray;positiveItemArray;constructor(e){this.positiveSum=this.negativeSum=0,this.numPositive=this.numNegative=this.numZero=0,this.largestPositiveValue=this.largestNegativeValue=0,e&&(this.negativeItemArray=[],this.positiveItemArray=[],this.zeroItemArray=[])}announceItem(e,t){t<0?(this.numNegative++,this.negativeSum+=t,this.negativeItemArray&&this.negativeItemArray.push(e),t<this.largestNegativeValue&&(this.largestNegativeValue=t,this.largestNegativeItem=e)):t>0?(this.numPositive++,this.positiveSum+=t,this.positiveItemArray&&this.positiveItemArray.push(e),t>this.largestPositiveValue&&(this.largestPositiveValue=t,this.largestPositiveItem=e)):(this.numZero++,this.zeroItemArray&&this.zeroItemArray.push(e))}}class qc{_targetMask;_targetValue;constructor(e,t=!0){this._targetMask=e,this._targetValue=t}testEdge(e){return e.isMaskSet(this._targetMask)===this._targetValue}}let Wn=class Dn{static signedFaceArea(e){return e.signedFaceArea()}static collectFaceAreaSummary(e,t=!1,n=i=>Dn.signedFaceArea(i)){const i=new Vc(t);let s;e instanceof Ut?s=e.collectFaceLoops():s=e;for(const r of s){const a=n(r);i.announceItem(r,a)}return i}static findMinimumAreaFace(e,t){return Dn.collectFaceAreaSummary(e,!1,t).largestNegativeItem}static isTriangulatedCCW(e,t=!0,n=0){let i;e instanceof Ut?i=e.collectFaceLoops():i=e;let s=0,r=0;for(const a of i){const o=a.countEdgesAroundFace();if(o>=3){if(a.signedFaceArea()>0){if(o>3&&(r++,r>n))return!1}else if(s++,s>1&&!t)return!1}}return!0}static pushAndMaskAllNodesInFace(e,t,n,i){i.push(e),e.collectAroundFace(s=>{s.setMask(t),n.push(s)})}static parityFloodFromSeed(e,t,n,i){const s=[];if(e.isMaskSet(t))return s;const r=i|t,a=[];for(Dn.pushAndMaskAllNodesInFace(e,r,a,s);a.length>0;){const o=a.pop(),c=o.edgeMate;if(c&&!c.isMaskSet(t)){let d=o.isMaskSet(i);(!n||n.testEdge(o))&&(d=!d),Dn.pushAndMaskAllNodesInFace(c,d?r:t,a,s)}}return s}static correctParityInSingleComponent(e,t){const n=Dn.findMinimumAreaFace(t);if(n){if(!n.isMaskSet(e))for(const i of t)i.isMaskSet(e)?i.clearMaskAroundFace(e):i.setMaskAroundFace(e)}}static correctParityInComponentArrays(e,t){if(e!==O.NULL_MASK)for(const n of t)Dn.correctParityInSingleComponent(e,n)}static collectConnectedComponentsWithExteriorParityMasks(e,t,n=O.NULL_MASK){const i=[],s=O.VISITED,r=n|s;e.clearMask(r);for(const a of e.allHalfEdges)if(!a.isMaskSet(s)){const o=Dn.parityFloodFromSeed(a,s,t,n);i.push(o)}return Dn.correctParityInComponentArrays(n,i),i}static exploreComponent(e,t,n=O.EXTERIOR,i=1/0,s){i<=0&&(i=1/0);const r=t|n;let a=0;const o=[],c=s||[];for(o.push(e);o.length>0&&a<i;){const h=o.shift();h&&!h.isMaskSet(r)&&(c.push(h),++a,h.collectAroundFace(u=>{u.setMask(t);const g=u.vertexSuccessor;g.isMaskSet(r)||o.push(g)}))}if(o.length===0)return{faces:c,nextSeed:void 0};let d=o[0];for(const h of o)if(h.vertexSuccessor.isMaskSet(n)||h.edgeMate.isMaskSet(n)){d=h;break}return{faces:c,nextSeed:d}}static collectConnectedComponents(e,t=1/0,n=O.EXTERIOR){const i=[];e.countMask(n)===0&&(n=O.NULL_MASK);const s=O.VISITED;e.clearMask(s);const r=s|n,a=o=>{for(let c=o;c<e.countNodes();++c)if(!e.allHalfEdges[c].isMaskSet(r)&&e.allHalfEdges[c].edgeMate.isMaskSet(r)){o=c;break}return o};for(let o=0;o<e.countNodes();++o){if(e.allHalfEdges[o].isMaskSet(r))continue;const c=a(o);let d=e.allHalfEdges[c];do{const h=Dn.exploreComponent(d,s,n,t);d=h.nextSeed,h.faces.length>0&&i.push(h.faces)}while(d!==void 0);e.allHalfEdges[o].isMaskSet(s)||--o}return i}static pointInOrOnFaceXY(e,t,n){const i=new sa(t,n);let s=e,r=e.faceSuccessor;for(;!i.tryStartEdge(s.x,s.y,r.x,r.y);s=r){if(r===e)return fe.createXX(r.x,r.faceSuccessor.x).containsX(t)?0:-1;r=s.faceSuccessor}let a=r.faceSuccessor;for(;;){if(!i.advance(a.x,a.y))return i.classifyCounts();if(a===r)break;a=a.faceSuccessor}return i.classifyCounts()}static collectExtendedBoundaryLoopFromSeed(e,t,n,i){let s=0;for(;!e.getMask(t)&&n(e);){i(e,s++),e.setMask(t);const r=e.faceSuccessor;let a=r;for(;;){if(a.getMask(t))return;if(n(a)){e=a;break}if(a=a.vertexPredecessor,a===r)break}}}static collectExtendedBoundaryLoopsInGraph(e,t){const n=[],i=e.grabMask(!0),s=a=>a.getMask(t)===0&&a.edgeMate.getMask(t)!==0,r=(a,o)=>{o===0&&n.push([]),n[n.length-1].push(a)};for(const a of e.allHalfEdges)this.collectExtendedBoundaryLoopFromSeed(a,i,s,r);return e.dropMask(i),n}};class Zc{static spaceTriangleAspectRatio(e,t,n){const s=.5*e.crossProductToPoints(t,n).magnitude(),r=e.distanceSquared(t)+t.distanceSquared(n)+n.distanceSquared(e);return f.safeDivideFraction(s,r,0)}static spaceQuadDiagonalAspectRatio(e,t,n,i){const s=this.spaceTriangleAspectRatio(e,t,n),r=this.spaceTriangleAspectRatio(e,n,i);return Math.max(s,r)}static triangulateGreedyEarCut(e,t){const n=re.areaNormal(e),i=[],s=e.slice();for(In.removeClosurePoint(s);s.length>2;){let r=-1,a=0,o=s.length-2,c=s.length-1,d;for(d=0;d<s.length;o=c,c=d,d++){const u=this.spaceTriangleAspectRatio(s[o],s[c],s[d]);s[o].crossProductToPoints(s[c],s[d]).dotProduct(n)>0&&u>r&&(r=u,a=o)}if(r<=0)return!1;o=a,c=(o+1)%s.length,d=(c+1)%s.length;const h=[];h.push(s[o],s[c],s[d]),s.splice(c,1),i.push(h)}return t(e,i),!0}static triangulateSimplestSpaceLoopGo(e,t,n){const i=lt.countNonDuplicates(e);if(n!==void 0&<.sumEdgeLengths(e,!0,i)>n||i<3)return!1;if(i===3)return this.spaceTriangleAspectRatio(e[0],e[1],e[2])===0?!1:(t(e,[e.slice()]),!0);if(i===4){const s=this.spaceQuadDiagonalAspectRatio(e[0],e[1],e[2],e[3]),r=this.spaceQuadDiagonalAspectRatio(e[1],e[2],e[3],e[0]);return s===0&&r===0?!1:s>r?(t(e,[[e[0],e[1],e[2]],[e[2],e[3],e[0]]]),!0):(t(e,[[e[0],e[1],e[3]],[e[3],e[1],e[2]]]),!0)}return this.triangulateGreedyEarCut(e,t)}static triangulateSimplestSpaceLoop(e,t,n){return e instanceof N?this.triangulateSimplestSpaceLoopGo(e.points,t,n):this.triangulateSimplestSpaceLoopGo(e,t,n)}}class ga{detailA;detailB;constructor(e,t){this.detailA=e,this.detailB=t}static create(e,t){return new ga(e,t)}}class ss{_facetIndex;_detail;_normal;_param;_color;constructor(e=-1,t){this._facetIndex=e,this._detail=t||ji.create()}invalidate(e=!0){this._facetIndex=-1,e&&this._detail.invalidate(),this._normal=void 0,this._param=void 0,this._color=void 0}static create(e=-1,t,n){return n?n.invalidate(!1):n=new ss,n._facetIndex=e,t!==void 0&&n._detail!==t&&n._detail.copyContentsFrom(t),n}static createCapture(e,t){return new ss(e,t)}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 e=new ss;return e.copyContentsFrom(this),e}copyContentsFrom(e){this._facetIndex=e._facetIndex,this._detail.copyContentsFrom(e._detail),this._normal=e._normal?.clone(),this._param=e._param?.clone(),this._color=e._color}getNormal(e){if(this._detail.isValid&&this._normal===void 0&&e!==void 0){this._normal=v.create();const t=[this._detail.local.x,this._detail.local.y,this._detail.local.z];e.linearCombination(t,this._normal)}return this._normal}getParam(e){if(this._detail.isValid&&this._param===void 0&&e!==void 0){this._param=L.create();const t=[this._detail.local.x,this._detail.local.y,this._detail.local.z];e.linearCombination(t,this._param)}return this._param}getColor(e){if(this._detail.isValid&&this._color===void 0&&e!==void 0){const t=[this._detail.local.x,this._detail.local.y,this._detail.local.z];this._color=Tt.linearCombinationOfColors(e,t)}return this._color}getBarycentricCoordinates(){return[this._detail.local.x,this._detail.local.y,this._detail.local.z]}}class Gn{_facetIndex;_edgeCount;_detail;constructor(e=-1,t=0,n){this._facetIndex=e,this._edgeCount=t,this._detail=n||hn.create()}invalidate(e=!0){this._facetIndex=-1,this._edgeCount=0,e&&this._detail.invalidate()}static create(e=-1,t=0,n,i){return i?i.invalidate(!1):i=new Gn,i._facetIndex=e,i._edgeCount=t,n!==void 0&&i._detail!==n&&i._detail.copyContentsFrom(n),i}static createCapture(e,t,n){return new Gn(e,t,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 e=new Gn;return e.copyContentsFrom(this),e}copyContentsFrom(e){this._facetIndex=e._facetIndex,this._edgeCount=e._edgeCount,this._detail.copyContentsFrom(e._detail)}getNormal(){}getParam(){}getColor(){}getBarycentricCoordinates(){}}class ci extends Gn{_normal;_param;_color;_barycentricCoordinates;constructor(e=-1,t=0,n){super(e,t,n)}invalidate(e=!0){super.invalidate(e),this._normal=void 0,this._param=void 0,this._color=void 0,this._barycentricCoordinates=void 0}static create(e=-1,t=0,n,i){return i?i.invalidate(!1):i=new ci,super.create(e,t,n,i)}static createCapture(e,t,n){return new ci(e,t,n)}get isConvex(){return!0}clone(){const e=new ci;return e.copyContentsFrom(this),e}copyContentsFrom(e){super.copyContentsFrom(e),this._normal=e._normal?.clone(),this._param=e._param?.clone(),this._color=e._color,this._barycentricCoordinates=e._barycentricCoordinates?.slice()}getNormal(e,t,n=f.smallMetricDistance){if(this._detail.isValid&&this._normal===void 0&&e!==void 0){const i=this.getBarycentricCoordinates(t,n);i!==void 0&&(this._normal=v.create(),e.linearCombination(i,this._normal))}return this._normal}getParam(e,t,n=f.smallMetricDistance){if(this._detail.isValid&&this._param===void 0&&e!==void 0){const i=this.getBarycentricCoordinates(t,n);i!==void 0&&(this._param=L.create(),e.linearCombination(i,this._param))}return this._param}getColor(e,t,n=f.smallMetricDistance){if(this._detail.isValid&&this._color===void 0&&e!==void 0){const i=this.getBarycentricCoordinates(t,n);i!==void 0&&(this._color=Tt.linearCombinationOfColors(e,i))}return this._color}getBarycentricCoordinates(e,t=f.smallMetricDistance){return this._detail.isValid&&this._barycentricCoordinates===void 0&&e!==void 0&&(this._barycentricCoordinates=re.convexBarycentricCoordinates(e,this._detail.point,t)),this._barycentricCoordinates}}class Xt{_v;_a;constructor(e,t,n){this._v=[e,t],this._a=n}clone(){return new Xt(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(e,t){return e._v[0]===t._v[0]&&e._v[1]===t._v[1]}static areDirectedPartners(e,t){return e._v[0]===t._v[1]&&e._v[1]===t._v[0]}static areUndirectedPartners(e,t){return this.areSameEdge(e,t)||this.areDirectedPartners(e,t)}static relativeOrientation(e,t){return this.areSameEdge(e,t)?1:this.areDirectedPartners(e,t)?-1:0}get isNullEdge(){return this._v[0]===this._v[1]}static lessThan(e,t){const n=e.lowVertex,i=t.lowVertex;if(n<i)return-1;if(i<n)return 1;const s=e.highVertex,r=t.highVertex;return s<r?-1:r<s?1:e.startVertex-t.startVertex}toJSON(){return[this._v[0],this._v[1],this._a]}static clusterToJSON(e){if(e instanceof Xt)return e.toJSON();const t=[];for(const n of e)t.push(n.toJSON())}static clusterArrayToJSON(e){const t=[];for(const n of e)t.push(Xt.clusterToJSON(n));return t}}class $s{edges;constructor(){this.edges=[]}addEdge(e,t,n){const i=new Xt(e,t,n);return this.edges.push(i),i}addPath(e,t,n){if(e.length===0)return;const i=e.length-1;for(let s=0;s<i;s++)this.addEdge(e[s],e[s+1],t);n&&this.addEdge(e[i],e[0],t)}sort(){this.edges.sort((e,t)=>Xt.lessThan(e,t))}collectSortableEdgeCluster(e,t,n){if(n!==void 0&&t>e)if(t===e+1)n.push(this.edges[e]);else{const i=[];for(let s=e;s<t;s++)i.push(this.edges[s]);n.push(i)}}sortAndCollectClusters(e,t,n,i){this.sort(),e&&(e.length=0),t&&(t.length=0),n&&(n.length=0),i&&(i.length=0);const s=this.edges.length;let r;for(let a=0;a<s;a+=r){const o=this.edges[a];r=1;for(let c=a+1;c<s&&Xt.areUndirectedPartners(o,this.edges[c]);c++)r++;this.edges[a].isNullEdge?this.collectSortableEdgeCluster(a,a+r,n):r===2&&Xt.areDirectedPartners(o,this.edges[a+1])?this.collectSortableEdgeCluster(a,a+r,e):r===1?this.collectSortableEdgeCluster(a,a+1,t):this.collectSortableEdgeCluster(a,a+r,i)}}}class Wc{numPositive;numNegative;firstEdgeIndex;constructor(e){this.numPositive=this.numNegative=0,this.firstEdgeIndex=e}recordOrientation(e){e>0?this.numPositive++:e<0&&this.numNegative++}}class di{_edges;_edgeToPartnerEdge;_edgeToEdgeInComponent;_facetToFirstEdgeInComponent;_facetOrientation;_components;_visitor;_mesh;constructor(e){this._visitor=e.createVisitor(1),this._edges=Ee.createIndexedEdges(this._visitor),this._edgeToPartnerEdge=[],this._edgeToEdgeInComponent=[],this._facetToFirstEdgeInComponent=[],this._facetOrientation=[],this._components=[],this._mesh=e}edgeIdToFacetOrientation(e){const t=this._edges.edges[e].facetIndex;return this._facetOrientation[t]}setupUnoriented(){this._edges.sort();const e=this._edges.edges;let t=-1;const n=this._edges.edges.length;for(let i=0;i<n;i++){const s=this._edges.edges[i].facetIndex;s>t&&(t=s),this._edgeToEdgeInComponent.push(i),this._edgeToPartnerEdge.push(i)}for(let i=0;i<=t;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:di.swapEntries(this._edgeToEdgeInComponent,i,r)}for(let i=0;i<n;i++){let s=i+1;for(;s<n&&Xt.areUndirectedPartners(e[i],e[s]);)di.swapEntries(this._edgeToPartnerEdge,i,s),s++;if(s>i+2)return!1}return!0}recordFacetInComponent(e,t){const n=this._components[this._components.length-1];this._facetOrientation[e]=t,n.recordOrientation(t)}initializeComponent(e){const t=this._edges.edges[e].facetIndex;this._components.push(new Wc(e)),this.recordFacetInComponent(t,1)}_workArray=[];pushFacetEdgesOnStack(e,t){di.extractCyclicIndices(this._edgeToEdgeInComponent,e,this._workArray);for(const n of this._workArray)t.push(n)}doFlood(){const e=[],t=this._edges.edges,n=t.length,i=[];for(let s=0;s<n;s++)if(this.edgeIdToFacetOrientation(s)===0){e.length=0,this.initializeComponent(s),this.pushFacetEdgesOnStack(s,e);let r;for(;(r=e.pop())!==void 0;){const a=t[r].facetIndex,o=this._facetOrientation[a];di.extractCyclicIndices(this._edgeToPartnerEdge,r,i);for(const c of i)if(c!==r){const d=t[c].facetIndex,h=this._facetOrientation[d];if(h===0){const u=Xt.areDirectedPartners(t[r],t[c])?o:-o;this.recordFacetInComponent(d,u),this.pushFacetEdgesOnStack(c,e),di.swapEntries(this._edgeToEdgeInComponent,r,c)}else if(Xt.relativeOrientation(t[r],t[c])*o*h>0)return!1}}}return!0}doFacetReversals(){let e=0;for(this._visitor.reset();this._visitor.moveToNextFacet();){const t=this._visitor.currentReadIndex();this._facetOrientation[t]<0&&(e++,this._mesh.reverseSingleFacet(t))}return e}static doFixup(e){const t=new di(e);if(!t.setupUnoriented())return!1;const n=t.doFlood();return n&&t.doFacetReversals(),n}static swapEntries(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}static extractCyclicIndices(e,t,n){n.length=0;let i=t;do n.push(i),i=e[i];while(i!==t)}}class yo{constructor(e,t,n){this.index=e,this.area=t,this.normal=n}index;area;normal;addWeightedNormal(e,t){this.area+=e,this.normal.addScaledInPlace(t,e)}divideNormalByArea(){this.area>0,this.area>0&&this.normal.scaleInPlace(1/this.area)}}class rs{constructor(e,t,n){this.facetData=e,this.sectorClusterData=void 0,this.sectorIndex=t,this.vertexIndex=n}facetData;sectorIndex;vertexIndex;sectorClusterData;static cbSectorSort(e,t){return e.sectorIndex-t.sectorIndex}static cbVertexSort(e,t){return e.vertexIndex-t.vertexIndex}static pushToArray(e,t,n,i){e.push(new rs(t,n,i))}}class Po{static buildFastAverageNormals(e,t){const n=e.createVisitor(0),i=v.create(0,0,1),s=f.smallMetricDistanceSquared,r=[];let a=0,o=0;for(;n.moveToNextFacet();){let u=re.areaNormalGo(n.point),g=0;u?(g=u.magnitude(),g<s?(u.setFromVector3d(i),g=0):u.scaleInPlace(1/g)):(u=i.clone(),g=0);const m=new yo(a++,g,u);for(let p=0;p<n.pointCount;p++)rs.pushToArray(r,m,o++,n.clientPointIndex(p))}r.sort((u,g)=>rs.cbVertexSort(u,g));const c=[];let d=t.radians;d<1e-4&&(d=1e-4);let h=0;for(let u=0;u<r.length;u++){const g=r[u],m=g.vertexIndex,p=g.facetData;if(g.sectorClusterData===void 0){const x=new yo(h++,0,v.createZero());c.push(x);for(let _=u;_<r.length;_++){const I=r[_];if(I.vertexIndex!==m)break;I.facetData.normal.angleTo(p.normal).radians>d||I.sectorClusterData===void 0&&(x.addWeightedNormal(1,I.facetData.normal),I.sectorClusterData=x)}}}r.sort((u,g)=>rs.cbSectorSort(u,g)),e.data.normalIndex=[],e.data.normal=new J(r.length);for(const u of c)u.divideNormalByArea(),u.index=e.data.normal.length,e.data.normal.push(u.normal);for(const u of r)u.sectorClusterData,u.sectorClusterData&&e.data.normalIndex.push(u.sectorClusterData.index)}static buildPerFaceNormals(e){const t=e.createVisitor(0),n=v.create(0,0,1),i=v.create(0,0,1),s=new J(e.faceCount),r=[];for(;t.moveToNextFacet();){const a=s.length;re.unitNormal(t.point,n)?s.push(n):s.push(i);for(let o=0;o<t.pointCount;o++)r.push(a)}e.data.normalIndex=r,e.data.normal=s}}function er(l){return l===void 0?!1:l}class Gc{constructor(){this.numActiveSectors=0,this.numInactiveSectors=0,this.averageNormal=v.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(e,t,n){if(e.isMaskSet(n))this.numInactiveSectors++;else{const i=U.sectorSweepRadiansXYZ(e,t);this.averageNormal.addScaledInPlace(t,i),this.radiansSum+=i,this.numActiveSectors++}}finishNormalAveraging(){return!!(this.numActiveSectors>0&&this.averageNormal.normalizeInPlace())}recordDeviation(e,t){if(t){const n=this.averageNormal.radiansTo(e);this.maxDeviationRadiansFromAverage=Math.max(Math.abs(this.maxDeviationRadiansFromAverage),n)}}get maxDeviationRadians(){return this.maxDeviationRadiansFromAverage}}function Qc(l){Ae.stringDebugFunction!==void 0&&(Ae.stringDebugFunction(` Sector xyz ${l.xyz.x},${l.xyz.y},${l.xyz.z} `),Ae.stringDebugFunction(` normal ${l.normal.x},${l.normal.y},${l.normal.z} `))}class ma{constructor(e,t){this.facetIndex=e,this.facetNormal=t}facetIndex;facetNormal}class pt{constructor(e,t){this.xyz=t,this.normal=e,this.count=0}normal;xyz;count;static edgeHasLargeExteriorAngleBetweenNormals(e,t,n,i,s=Math.PI*.5){const r=e.edgeTag,o=e.edgeMate.edgeTag;if(r!==void 0&&o!==void 0){e.vectorToFaceSuccessor(t);const c=r.normal.signedRadiansTo(o.normal,t);if(f.split3WaySign(i,-1,1,1)*c>=s&&(v.createAdd2Scaled(r.normal,1,o.normal,1,n),n.normalizeInPlace()))return!0}return!1}static almostEqualNormals(e,t,n=f.smallAngleRadians){return e.normal.radiansTo(t.normal)<=n}static radiansBetweenNormals(e,t){return e.normal.radiansTo(t.normal)}setOffsetPointAtDistanceAtHalfEdge(e,t){e.getPoint3d(this.xyz),this.xyz.addScaledInPlace(this.normal,t)}static setXYZAtHalfEdge(e,t){const n=e.edgeTag;n!==void 0&&t!==void 0&&n.xyz.set(t.x,t.y,t.z)}setXYAndZ(e){this.xyz.set(e.x,e.y,e.z)}static setNormalAtHalfEdge(e,t,n){const i=e.edgeTag;i!==void 0&&(i.normal.set(t.x,t.y,t.z),n!==void 0&&i.setOffsetPointAtDistanceAtHalfEdge(e,n))}static sweepRadiansAroundNormal(e,t){const n=e.edgeTag,i=e.vertexSuccessor.edgeTag;if(n!==void 0&&i!==void 0)return n.normal.planarRadiansTo(i.normal,t)}static getSectorPointAtHalfEdge(e,t,n){const i=e.edgeTag;return i!==void 0?(t!==void 0&&t.setFromPoint3d(i.xyz),n!==void 0&&n.push(i.xyz),!0):!1}static pushXYZ(e,t){const n=t.edgeTag;return n!==void 0&&e.push(n.xyz),n}static accumulateScaledNormalAtHalfEdge(e,t,n){const i=e.edgeTag;i!==void 0&&n.addScaledInPlace(i.normal,t)}}class Ae{constructor(e,t,n){this._basePolyface=e,this._baseGraph=t,this._breakMaskA=t.grabMask(),this._breakMaskB=t.grabMask(),this._insideOfChamferFace=t.grabMask(),this._outsideOfChamferFace=t.grabMask(),this._insideChamferSling=t.grabMask(),this._outsideEndOfChamferFace=t.grabMask(),this._exteriorMask=O.EXTERIOR,this._offsetCoordinatesReassigned=t.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(e){this._baseGraph.announceNodes((t,n)=>{const i=n.edgeTag;return i!==void 0&&i.setOffsetPointAtDistanceAtHalfEdge(n,e),!0})}static buildOffsetMeshWithEdgeChamfers(e,t,n,i){const s=this.buildBaseGraph(e);if(s!==void 0){const r=new Ae(e,s,i);r.applyFaceNormalOffsetsToSectorData(n),Ae.graphDebugFunction!==void 0&&Ae.graphDebugFunction("BaseGraph",s,r._breakMaskA,r._breakMaskB);const a=i.outputSelector?i.outputSelector:{outputOffsetsFromFaces:!0,outputOffsetsFromEdges:!0,outputOffsetsFromVertices:!0};er(a.outputOffsetsFromFacesBeforeChamfers)&&r.announceFacetsWithSectorCoordinatesAroundFaces(t),r.addChamferTopologyToAllEdges(i,n),r.computeOffsetFacetIntersections(n),Ae.graphDebugFunction!==void 0&&Ae.graphDebugFunction("after computeEdgeChamfers",s,r._breakMaskA,r._breakMaskB),er(a.outputOffsetsFromFaces)&&r.announceFacetsWithSectorCoordinatesAroundFaces(t),er(a.outputOffsetsFromEdges)&&r.announceFacetsWithSectorCoordinatesAroundEdges(t),er(a.outputOffsetsFromVertices)&&r.announceFacetsWithSectorCoordinatesAroundVertices(t)}}announceSimpleOffsetFromFaces(e,t){const n=new J,i=y.create(),s=v.create(),r=a=>(a.getPoint3d(i),i.addInPlace(s),n.push(i),0);this._baseGraph.announceFaceLoops((a,o)=>{if(!o.isMaskSet(O.EXTERIOR)){const c=o.faceTag;s.setFromVector3d(c.facetNormal.direction),s.scaleInPlace(t),n.length=0,o.sumAroundFace(r),e.addPolygonGrowableXYZArray(n)}return!0})}announceFacetsWithSectorCoordinatesAroundFaces(e){const t=new J,n=i=>{const s=i.edgeTag;return s!==void 0&&t.push(s.xyz),0};this._baseGraph.announceFaceLoops((i,s)=>(s.isMaskSet(O.EXTERIOR)||(t.length=0,s.sumAroundFace(n),t.length>2&&e.addPolygonGrowableXYZArray(t)),!0))}countBits(e){let t=0,n=e;for(;n!==0;)n&1&&t++,n=n>>1;return t}announceFacetsWithSectorCoordinatesAroundEdges(e){const t=new J,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 a=r.faceSuccessor,o=r.edgeMate;if(!o.isMaskSet(i)){const c=o.faceSuccessor;t.clear(),pt.getSectorPointAtHalfEdge(r,void 0,t),pt.getSectorPointAtHalfEdge(a,void 0,t),pt.getSectorPointAtHalfEdge(o,void 0,t),pt.getSectorPointAtHalfEdge(c,void 0,t),rt.compressInPlaceByShortEdgeLength(t,n),t.length>2&&e.addPolygonGrowableXYZArray(t)}}return!0})}getCoordinateString(e,t=!0,n=!1){return t?n?`${U.nodeToIdXYZString(e)} ==> ${U.nodeToIdXYZString(e.faceSuccessor)}`:`${U.nodeToIdXYZString(e)}`:n?`==> ${U.nodeToIdXYZString(e.faceSuccessor)}`:""}inspectMasks(e,t=!0,n=!1){return"[".concat(e.id.toString(),e.isMaskSet(this._exteriorMask)?"X":"",e.isMaskSet(this.breakMaskA)?"A":"",e.isMaskSet(this.breakMaskB)?"B":"",e.isMaskSet(this.insideChamferSling)?"(sling)":"",e.isMaskSet(this.insideOfChamferFace)?"(in chamfer)":"",e.isMaskSet(this.outsideEndOfChamferFace)?"(@sling)":"",e.isMaskSet(this.outsideOfChamferFace)?"(@chamfer)":"",this.getCoordinateString(e,t,n),"]")}announceFacetsWithSectorCoordinatesAroundVertices(e){const t=new J,n=f.smallMetricDistance;this._baseGraph.announceVertexLoops((i,s)=>(s.findMaskAroundVertex(this._exteriorMask)||(t.length=0,s.sumAroundVertex(r=>(r.isMaskSet(this._insideChamferSling)||pt.getSectorPointAtHalfEdge(r,void 0,t),0)),rt.compressInPlaceByShortEdgeLength(t,n),t.length>2&&e.addPolygonGrowableXYZArray(t)),!0))}static buildBaseGraph(e){const t=new _o,n=e.createVisitor(),i=y.create(),s=y.create();for(n.reset();n.moveToNextFacet();){const r=re.centroidAreaNormal(n.point);if(r!==void 0){const a=t.insertLoop(n.pointIndex,c=>{const d=c.edgeMate;e.data.getPoint(c.i,i),c.setXYZ(i),e.data.getPoint(d.i,s),d.setXYZ(s)}),o=new ma(n.currentReadIndex(),r);a!==void 0&&a.sumAroundFace(c=>(c.faceTag=o,c.edgeTag=new pt(r.direction.clone(),c.getPoint3d()),0))}}return t.graph}setOffsetAtDistanceAroundVertex(e,t,n=!1){e.sumAroundVertex(i=>{const s=i.edgeTag;return s!==void 0&&(n&&this.isInsideChamferOrSling(e)||s.setOffsetPointAtDistanceAtHalfEdge(i,t)),0})}setOffsetXYAndZAroundVertex(e,t){e.sumAroundVertex(n=>{const i=n.edgeTag;return i!==void 0&&(i.setXYAndZ(t),n.setMask(this._offsetCoordinatesReassigned)),0})}announceNodeAndSectorPropertiesInSmoothSector(e,t){let n=0;for(let i=e;;i=i.vertexSuccessor){const s=i.edgeTag;if(s!==void 0&&(t(i,s),n++),i.isMaskSet(this._breakMaskB)||i.isMaskSet(this._exteriorMask)||i===e&&n===0)return n}}computeAverageNormalAndMaxDeviationAroundVertex(e,t){t.clear();const n=this._exteriorMask|this._insideChamferSling;if(e.sumAroundVertex(i=>{const s=i.edgeTag;return s&&t.accumulateNormal(i,s.normal,n),0}),!!t.finishNormalAveraging())return e.sumAroundVertex(i=>{const s=i.edgeTag;return s&&t.recordDeviation(s.normal,!i.isMaskSet(n)),0}),t.maxDeviationRadians}assignOffsetByAverageNormalAroundVertex(e,t,n,i){const s=this.computeAverageNormalAndMaxDeviationAroundVertex(e,n);return Ae.stringDebugFunction&&(Ae.stringDebugFunction(`XYZ ${U.nodeToIdXYZString(e)} Average Normal ${JSON.stringify(n.averageNormal.toJSON())}`),Ae.stringDebugFunction(` angle ratio ${n.radiansSum/(2*Math.PI)} maxDeviation ${n.maxDeviationRadiansFromAverage}`)),s!==void 0&&s<=t?(e.sumAroundVertex(r=>(pt.setNormalAtHalfEdge(r,n.averageNormal,i),0)),!0):!1}markBreakEdgesAndSaveAverageNormalsAroundVertex(e){e.clearMaskAroundVertex(this._breakMaskA),e.clearMaskAroundVertex(this._breakMaskB);const t=this._smoothRadiansBetweenNormals,n=this._smoothAccumulatedRadiansBetweenNormals;let i=0,s=e,r=0;do{const o=s.edgeMate,c=o.faceSuccessor;s.isMaskSet(this._exteriorMask)?o.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)):o.isMaskSet(this._exteriorMask)?(i++,s.setMask(this._breakMaskA)):pt.almostEqualNormals(s.edgeTag,c.edgeTag,t)?r++:(s.setMask(this._breakMaskA),i++,c.setMask(this._breakMaskB))),s=s.vertexSuccessor}while(s!==e);Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` numSkip ${r} `),i===0&&(e.setMask(this._breakMaskA),e.vertexPredecessor.setMask(this._breakMaskB),i=1);const a=s.findMaskAroundVertex(this._breakMaskA);if(a!==void 0){s=a;do if(s.isMaskSet(this._breakMaskA)&&!s.isMaskSet(this._breakMaskB)){let o=0;do{const c=s.vertexSuccessor;o+=pt.radiansBetweenNormals(s.edgeTag,c.edgeTag),o>n&&(s.setMask(this._breakMaskB),c.setMask(this._breakMaskA),i++,o=0),s=c}while(!s.isMaskSet(this._breakMaskB))}else s=s.vertexSuccessor;while(s!==a)}if(i>0&&a!==void 0){s=a;const o=v.create(),c=v.create(),d=v.create();o.setZero();do{if(s.isMaskSet(this._breakMaskA)&&!s.isMaskSet(this._breakMaskB)){let h=s;for(o.setZero();;){h.vectorToFaceSuccessor(c),h.vectorToFacePredecessor(d);let u=c.signedRadiansTo(d,h.faceTag.facetNormal.direction);if(u<0&&(u+=Math.PI*2),pt.accumulateScaledNormalAtHalfEdge(h,u,o),h.isMaskSet(this._breakMaskB))break;h=h.vertexSuccessor}if(o.normalizeInPlace())for(h=s;pt.setNormalAtHalfEdge(h,o),!h.isMaskSet(this._breakMaskB);)h=h.vertexSuccessor}s=s.vertexSuccessor}while(s!==a)}}compute3SectorIntersection(e,t,n,i){const s=e.edgeTag,r=t.edgeTag,a=n.edgeTag;return Le.intersect3Planes(s.xyz,s.normal,r.xyz,r.normal,a.xyz,a.normal,i)}compute3SectorIntersectionDebug(e,t,n,i){const s=e.edgeTag,r=t.edgeTag,a=n.edgeTag;if(Ae.stringDebugFunction!==void 0){Ae.stringDebugFunction(`compute3${this.inspectMasks(e)}${this.inspectMasks(t)}${this.inspectMasks(n)} `);for(const c of[s,r,a])Qc(c)}const o=Le.intersect3Planes(s.xyz,s.normal,r.xyz,r.normal,a.xyz,a.normal,i);return Ae.stringDebugFunction!==void 0&&(o===void 0?Ae.stringDebugFunction(" NO INTERSECTION"):Ae.stringDebugFunction(` ComputedVector ${o.x},${o.y},${o.z} `)),o}compute2SectorIntersection(e,t,n){const i=e.edgeTag,s=t.edgeTag,r=i.normal.crossProduct(s.normal);return Le.intersect3Planes(i.xyz,i.normal,s.xyz,s.normal,s.xyz,r,n)}addChamferTopologyToAllEdges(e,t){const n=[],i=e.chamferAngleBetweenNormals.radians,s=y.create(),r=v.create(),a=v.create(),o=v.create();this._baseGraph.announceEdges((c,d)=>(pt.edgeHasLargeExteriorAngleBetweenNormals(d,r,o,t,i)&&n.push(d),!0));for(const c of n)if(pt.edgeHasLargeExteriorAngleBetweenNormals(c,r,o,i)){const d=this._baseGraph.splitEdgeCreateSliverFace(c),h=d.facePredecessor,u=d.getPoint3d();u.addScaledInPlace(o,t);const g=q.createCapture(u,o.clone()),m=new ma(-1,g);let p=-1;for(const x of[d,h]){r.scale(p,a),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),U.pinch(x,_);const S=q.create(s,a),A=new ma(-1,S);I.faceTag=A,x.edgeTag=new pt(o.clone(),u.clone()),_.edgeTag=new pt(o.clone(),u.clone()),I.edgeTag=new pt(a.clone(),s.clone());const w=this.compute3SectorIntersection(x,x.edgeMate,I),k=this.compute3SectorIntersection(_,_.vertexSuccessor,I);pt.setXYZAtHalfEdge(x,w),pt.setXYZAtHalfEdge(_,k),p*=-1}}}computeOffsetFacetIntersections(e){Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction("***** recompute intersections");const t=[],n=y.create(),i=y.create(),s=2*e,r=new Gc,a=T.degreesToRadians(25);this._baseGraph.announceVertexLoops((o,c)=>{let d=c.findMaskAroundVertex(this._outsideEndOfChamferFace);if(d===void 0&&(d=c.findMaskAroundVertex(this._breakMaskA)),d===void 0&&(d=c),Ae.stringDebugFunction!==void 0){const h=Ae.stringDebugFunction;h(""),h(` VERTEX LOOP ${JSON.stringify(d.getPoint3d().toJSON())} `),d.announceEdgesAroundVertex(u=>h(this.inspectMasks(u,!1,!0)))}if(this.assignOffsetByAverageNormalAroundVertex(d,a,r,e))return!0;if(this.markBreakEdgesAndSaveAverageNormalsAroundVertex(d),this.setOffsetAtDistanceAroundVertex(d,e,!0),d.collectMaskedEdgesAroundVertex(this._breakMaskA,!0,t),Ae.stringDebugFunction!==void 0){Ae.stringDebugFunction(` BREAK EDGES from ${this.inspectMasks(d,!0,!1)}`);for(const h of t)Ae.stringDebugFunction(this.inspectMasks(h,!1,!0))}if(!(t.length<=1))if(t.length===2){const h=this.compute2SectorIntersection(t[0],t[1]);h!==void 0&&this.setOffsetXYAndZAroundVertex(d,h)}else if(t.length===3){Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` Vertex Update just ${t.length} `);const h=this.compute3SectorIntersection(t[0],t[1],t[2]);h!==void 0&&this.setOffsetXYAndZAroundVertex(d,h)}else{Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` Vertex Update breakEdges ${t.length} `),d.getPoint3d(n);for(let h=0;h<t.length;h++){const u=h,g=(u+1)%t.length,m=(g+1)%t.length;if(t[u].isMaskSet(this._outsideEndOfChamferFace)&&t[g].isMaskSet(this._outsideOfChamferFace)&&t[m].isMaskSet(this._insideOfChamferFace)){Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` ChamferChamfer Fixup ${this.inspectMasks(t[u])} ${this.inspectMasks(t[g])} ${this.inspectMasks(t[m])} `);const p=this.compute3SectorIntersection(t[u],t[g],t[m]);if(p!==void 0){for(const x of[u,g,m])this.announceNodeAndSectorPropertiesInSmoothSector(t[x],(_,I)=>{I.setXYAndZ(p),_.setMask(this._offsetCoordinatesReassigned)});h+=2}}}for(let h=0;h<t.length;h++){const u=h,g=(u+1)%t.length;this.isInsideSling(t[u],t[g])||(!this.isOffsetAssigned(t[u])&&t[g].isMaskSet(this.insideOfChamferFace)?this.transferXYZFromNodeToSmoothSector(t[g],t[u],"push left from chamfer",i):!this.isOffsetAssigned(t[g])&&t[u].isMaskSet(this.outsideEndOfChamferFace)&&this.transferXYZFromNodeToSmoothSector(t[u],t[g],"push right from chamfer",i))}for(let h=0;h<t.length;h++){const u=h,g=(u+1)%t.length,m=(g+1)%t.length;if(this.isInsideSling(t[u],t[g],t[m])||this.isOffsetAssigned(t[g]))continue;Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` Intersection Fixup ${this.inspectMasks(t[u])} ${this.inspectMasks(t[g])} ${this.inspectMasks(t[m])} `);const p=this.compute3SectorIntersection(t[u],t[g],t[m]);p!==void 0&&n.distance(p)<s&&this.announceNodeAndSectorPropertiesInSmoothSector(t[g],(x,_)=>{_.setXYAndZ(p),x.setMask(this._offsetCoordinatesReassigned)})}}if(Ae.stringDebugFunction!==void 0){const h=d.countMaskAroundVertex(this._offsetCoordinatesReassigned,!1),g=` **** Vertex offset mask counts(TRUE ${d.countMaskAroundVertex(this._offsetCoordinatesReassigned,!0)})(FALSE ${h})`;Ae.stringDebugFunction(g)}return!0})}isInsideSling(e,t,n){return e.isMaskSet(this._insideChamferSling)||t!==void 0&&t.isMaskSet(this._insideChamferSling)||n!==void 0&&n.isMaskSet(this._insideChamferSling)}isInsideChamferOrSling(e){return e.isMaskSet(this._insideChamferSling)||e.isMaskSet(this._insideOfChamferFace)||e.isMaskSet(this._outsideEndOfChamferFace)}isOffsetAssigned(e,t,n){return e.isMaskSet(this._offsetCoordinatesReassigned)||t!==void 0&&t.isMaskSet(this._offsetCoordinatesReassigned)||n!==void 0&&n.isMaskSet(this._offsetCoordinatesReassigned)}transferXYZFromNodeToSmoothSector(e,t,n,i){Ae.stringDebugFunction!==void 0&&Ae.stringDebugFunction(` ${n} ${this.inspectMasks(e)} to ${this.inspectMasks(t)}} `),pt.getSectorPointAtHalfEdge(e,i,void 0),this.announceNodeAndSectorPropertiesInSmoothSector(t,(s,r)=>{r.setXYAndZ(i),s.setMask(this._offsetCoordinatesReassigned)})}}class tr{_spacePoints;_spacePointsRange;_numSpacePoints;constructor(e){this._spacePoints=e,this._spacePointsRange=e.getRange(),this._numSpacePoints=this._spacePoints.length}static create(e){if(e.length>1)return new tr(e)}_segmentPoint0=y.create();_segmentPoint1=y.create();_localSegmentPoint0=y.create();_localSegmentPoint1=y.create();_clipFractions=Je.create(0,1);_localFrame=X.createIdentity();_polygonRange=ie.create();projectToPolygon(e,t,n,i){e.setRange(this._polygonRange);let s=0;if(!this._polygonRange.intersectsRangeXY(this._spacePointsRange))return s;for(let r=1;r+1<e.length;r++){s++;const a=e.fillLocalXYTriangleFrame(0,r,r+1,this._localFrame);if(a){for(let o=1;o<this._numSpacePoints;o++)if(s++,this._spacePoints.getPoint3dAtCheckedPointIndex(o-1,this._segmentPoint0),this._spacePoints.getPoint3dAtCheckedPointIndex(o,this._segmentPoint1),a.multiplyInversePoint3d(this._segmentPoint0,this._localSegmentPoint0),a.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),d=this._localSegmentPoint0.interpolate(this._clipFractions.x1,this._localSegmentPoint1),h=this._localFrame.multiplyPoint3d(c),u=this._localFrame.multiplyPoint3d(d),g=this._localFrame.multiplyXYZ(c.x,c.y,0),m=this._localFrame.multiplyXYZ(d.x,d.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();t(this._spacePoints,o-1,n,i,[h,x,g],2,1),t(this._spacePoints,o-1,n,i,[u,_,m],1,2)}else this._localSegmentPoint0.z>0?t(this._spacePoints,o-1,n,i,[h,u,m,g],3,2):t(this._spacePoints,o-1,n,i,[u,h,g,m],2,3)}}}return s}}class as{edgePlane;clip;_crossingPoints;constructor(e,t){this.edgePlane=e,this.clip=t,this._crossingPoints=[]}static createPointPointSweep(e,t,n){const i=v.createStartEnd(e,t),s=i.fractionOfProjectionToVector(n),r=i.plusScaled(n,-s),a=ee.createNormalAndPoint(r,e),o=ee.createNormalAndPoint(r,t),c=ee.createOriginAndVectors(e,i,n);if(a!==void 0&&o!==void 0&&c!==void 0){o.negateInPlace();const d=Ce.createPlanes([a,o]);return new as(c,d)}}processPolygon(e,t){this._crossingPoints.length=0,Array.isArray(e)?Id.polygonPlaneCrossings(this.edgePlane,e,this._crossingPoints):un.polygonPlaneCrossings(this.edgePlane,e,this._crossingPoints),this._crossingPoints.length===2&&this.clip.announceClippedSegmentIntervals(0,1,this._crossingPoints[0],this._crossingPoints[1],(n,i)=>{t(this._crossingPoints[0].interpolate(n,this._crossingPoints[1]),this._crossingPoints[0].interpolate(i,this._crossingPoints[1]))})}}class pa{_edgeClippers;_localToWorld;_worldToLocal;_localRange;constructor(e,t){this._edgeClippers=e,t!==void 0&&(this._localToWorld=t.localToWorld,this._worldToLocal=t.worldToLocal,this._localRange=t.localRange)}static create(e,t){if(t===void 0&&(t=v.create(0,0,1)),e.length>1){const n=y.createZero(),i=y.createZero(),s=[];e.getPoint3dAtUncheckedPointIndex(0,n);const r=X.createRigidFromOriginAndVector(n,t)??X.createIdentity(),a=r.inverse(),o=e.getRange(a);for(let c=1;c<e.length;c++){e.getPoint3dAtUncheckedPointIndex(c,i);const d=as.createPointPointSweep(n,i,t);d!==void 0&&(n.setFrom(i),s.push(d))}return new pa(s,{localToWorld:r,worldToLocal:a,localRange:o})}}processPolygon(e,t){if(!(this._worldToLocal!==void 0&&this._localRange!==void 0&&!ie.createTransformedArray(this._worldToLocal,e).intersectsRangeXY(this._localRange)))for(const n of this._edgeClippers)n.processPolygon(e,t)}}class xa{_range;_numXEdge;_numYEdge;_data;constructor(e,t,n){this._range=e,this._numXEdge=Math.max(t,1),this._numYEdge=Math.max(n,1),this._data=[];for(let i=0;i<n;i++){const s=[];for(let r=0;r<t;r++)s.push(void 0);this._data.push(s)}}get numXEdge(){return this._numXEdge}get numYEdge(){return this._numYEdge}xIndex(e){const t=(e-this._range.low.x)/(this._range.high.x-this._range.low.x),n=Math.floor(t*this._numXEdge);return n<0?0:n>this._numXEdge-1?this._numXEdge-1:n}yIndex(e){const t=(e-this._range.low.y)/(this._range.high.y-this._range.low.y),n=Math.floor(t*this._numYEdge);return n<0?0:n>this._numYEdge-1?this._numYEdge-1:n}static createWithEstimatedCounts(e,t,n){if(e.low.x>=e.high.x||e.low.y>=e.high.y)return;const i=ze.createXYXY(e.low.x,e.low.y,e.high.x,e.high.y),s=i.xLength(),r=i.yLength();let a,o;return r>s?(o=Math.ceil(Math.sqrt(r*t/(n*s))),a=Math.ceil(t/o)):(a=Math.ceil(Math.sqrt(s*t/(n*r))),o=Math.ceil(t/(a*n))),new xa(i,a,o)}addDataAtXY(e,t,n){const i=this.xIndex(e),s=this.yIndex(t);let r=this._data[s][i];r||(r=[],this._data[s][i]=r),r.push(n)}getDataAtXY(e,t){const n=this.xIndex(e),i=this.yIndex(t);return this._data[i][n]}getDataAtIndex(e,t){if(!(e<0)&&!(e>=this._numXEdge)&&!(t<0)&&!(t>=this._numYEdge))return this._data[t][e]}isValidIndex(e,t){return!(e<0||e>=this._numXEdge||t<0||t>=this._numYEdge)}}class _a{_points;_buckets;get indexGrid(){return this._buckets}constructor(e,t){this._points=e,this._buckets=t}static create(e,t){const n=e.length;if(n<1)return;const i=e.getRange();i.expandInPlace(f.smallMetricDistance*1e3);const s=xa.createWithEstimatedCounts(i,n,t);if(s===void 0)return;const r=new _a(e,s);for(let a=0;a<n;a++)s.addDataAtXY(e.getXAtUncheckedPointIndex(a),e.getYAtUncheckedPointIndex(a),a);return r}announcePointsInRange(e,t){const n=this._buckets.xIndex(e.low.x),i=this._buckets.xIndex(e.high.x),s=this._buckets.yIndex(e.low.y),r=this._buckets.yIndex(e.high.y),a=this._points.length;for(let o=n;o<=i;o++)for(let c=s;c<=r;c++){const d=this._buckets.getDataAtIndex(o,c);if(d!==void 0){for(const h of d)if(h<a){const u=this._points.getXAtUncheckedPointIndex(h),g=this._points.getYAtUncheckedPointIndex(h),m=this._points.getZAtUncheckedPointIndex(h);if(e.containsXY(u,g)&&!t(h,u,g,m))return}}}}}class os{_count;_sumX;_sumXX;_minMax;_origin;constructor(e=0){this._minMax=fe.createNull(),this._count=this._sumX=this._sumXX=0,this._origin=e}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 e=this.mean,t=this._sumXX,n=this._sumX;return Math.sqrt((t-2*e*n+this._count*e*e)/this._count)}clearSums(){this._count=this._sumX=this._sumXX=0,this._minMax.setNull()}get origin(){return this._origin}setOrigin(e){this._origin=e}shiftOriginAndSums(e){const t=e-this._origin;this._origin=e,this._sumXX=this._sumXX-2*t*this._sumX+this._count*t*t,this._sumX=this._sumX-this._count*t,this._minMax.cloneTranslated(-t,this._minMax)}accumulate(e){e=e-this._origin,this._count+=1,this._sumX+=e,this._sumXX+=e*e,this._minMax.extendX(e)}accumulateArray(e){for(const t of e)this.accumulate(t)}clone(e){return e||(e=new os),this._minMax.clone(e._minMax),e._count=this._count,e._origin=this._origin,e._sumX=this._sumX,e._sumXX=this._sumXX,e}isAlmostEqual(e){return f.isAlmostEqualNumber(this._sumX,e._sumX)&&f.isAlmostEqualNumber(this._sumXX,e._sumXX)&&f.isAlmostEqualNumber(this._origin,e._origin)&&this._count===e._count&&this._minMax.isAlmostEqual(e._minMax)}}class Jc{range;xSums;ySums;zSums;constructor(){this.range=ie.createNull(),this.xSums=new os,this.ySums=new os,this.zSums=new os,this._workRange=ie.createNull()}_workRange;accumulateGrowableXYZArrayRange(e){e.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 nr{vectorToEye;collectOnForwardFacets;collectOnSideFacets;collectOnRearFacets;sideAngle;assembleChains;searcher;constructor(e,t,n,i,s,r,a){this.vectorToEye=e,this.sideAngle=t,this.assembleChains=n,this.collectOnForwardFacets=i,this.collectOnSideFacets=s,this.collectOnRearFacets=r,this.searcher=a}static create(e,t,n,i,s,r,a){return new nr(!e||a?v.unitZ():e.clone(),t?.clone()??T.createRadians(f.smallAngleRadians),n??!0,i??!0,s??!0,r??!0,a)}get collectAll(){return this.collectOnForwardFacets&&this.collectOnSideFacets&&this.collectOnRearFacets}collectFromThisFacetNormal(e){return e===void 0?!1:e.angleFromPerpendicular(this.vectorToEye).isMagnitudeLessThanOrEqual(this.sideAngle)?this.collectOnSideFacets:e.dotProduct(this.vectorToEye)>0?this.collectOnForwardFacets:this.collectOnRearFacets}}class ya{smoothSingleAngleBetweenNormals;smoothAccumulatedAngleBetweenNormals;chamferAngleBetweenNormals;outputSelector;constructor(e=T.createDegrees(25),t=T.createDegrees(60),n=T.createDegrees(90)){this.smoothSingleAngleBetweenNormals=e.clone(),this.smoothAccumulatedAngleBetweenNormals=t.clone(),this.chamferAngleBetweenNormals=n.clone()}static create(e=T.createDegrees(25),t=T.createDegrees(60),n=T.createDegrees(120)){const i=e.clone(),s=t.clone(),r=n.clone();return i.degrees<1&&s.setDegrees(1),s.degrees<1&&s.setDegrees(1),s.degrees<15&&s.setDegrees(15),new ya(i,s,r)}}var cs;(function(l){l[l.SelectNone=0]="SelectNone",l[l.SelectAny=1]="SelectAny",l[l.SelectAll=2]="SelectAll",l[l.SelectOneByParity=3]="SelectOneByParity"})(cs||(cs={}));class Ee{static visitorToLoop(e){const t=N.createPoints(e.point.getPoint3dArray());return oe.create(t)}static indexedPolyfaceToLoops(e){const t=zt.create(),n=e.createVisitor(1);for(;n.moveToNextFacet();){const i=Ee.visitorToLoop(n);t.tryAddChild(i)}return t}static sumFacetAreas(e,t){let n=0;e instanceof be?e=e.createVisitor(1):e.setNumWrap(1);let i;for(t!==void 0&&(i=t.normalize()),e.reset();e.moveToNextFacet();){const s=re.areaNormal(e.point.getPoint3dArray());n+=i?s.dotProduct(i):s.magnitude()}return n}static sumTetrahedralVolumes(e,t){let n=0;if(e instanceof be)return Ee.sumTetrahedralVolumes(e.createVisitor(0),t);let i=t;const s=y.create(),r=y.create(),a=y.create();for(e.reset();e.moveToNextFacet();){i===void 0&&(i=e.point.getPoint3dAtUncheckedPointIndex(0)),e.point.getPoint3dAtUncheckedPointIndex(0,s);for(let o=1;o+1<e.point.length;o++)e.point.getPoint3dAtUncheckedPointIndex(o,r),e.point.getPoint3dAtUncheckedPointIndex(o+1,a),n+=i.tripleProductToPoints(s,r,a)}return n/6}static sumVolumeBetweenFacetsAndPlane(e,t,n){const i=e instanceof be?e.createVisitor(0):e;i.setNumWrap(0);const s=y.create(),r=y.create(),a=v.create(),o=Ne.createZero();let c=0;const d=n?void 0:Ye.create(void 0,!0),h=n?void 0:Ye.create(void 0,!0),u={skipMoments:n,p0:s,p1:r,v0:a,m0:o};for(i.reset();i.moveToNextFacet();){const g=re.volumeBetweenPolygonAndPlane(i.point,t,u);c+=g.volume6,d&&h&&g.origin&&g.products&&(g.area2>0?d.accumulateProductsFromOrigin(g.origin,g.products,1):h.accumulateProductsFromOrigin(g.origin,g.products,1))}return{volume:c/6,positiveProjectedFacetAreaMoments:d?Ye.inertiaProductsToPrincipalAxes(d.origin,d.sums):void 0,negativeProjectedFacetAreaMoments:h?Ye.inertiaProductsToPrincipalAxes(h.origin,h.sums):void 0}}static sumFacetSecondAreaMomentProducts(e,t){if(e instanceof be)return Ee.sumFacetSecondAreaMomentProducts(e.createVisitor(0),t);const n=Ne.createZero();for(e.reset();e.moveToNextFacet();)re.addSecondMomentAreaProducts(e.point,t,n);return n}static sumFacetSecondVolumeMomentProducts(e,t){if(e instanceof be)return Ee.sumFacetSecondVolumeMomentProducts(e.createVisitor(0),t);const n=Ne.createZero();for(e.reset();e.moveToNextFacet();)re.addSecondMomentVolumeProducts(e.point,t,n);return n}static computePrincipalAreaMoments(e){const t=e.data.getPoint(0);if(!t)return;const n=Ee.sumFacetSecondAreaMomentProducts(e,t);return Ye.inertiaProductsToPrincipalAxes(t,n)}static computePrincipalVolumeMoments(e){const t=e.data.getPoint(0);if(!t)return;const n=Ee.sumFacetSecondVolumeMomentProducts(e,t);return Ye.inertiaProductsToPrincipalAxes(t,n)}static areFacetsConvex(e){if(e instanceof be)return this.areFacetsConvex(e.createVisitor(0));for(e.setNumWrap(0),e.reset();e.moveToNextFacet();)if(e.pointCount>3&&!re.isConvex(e.point))return!1;return!0}static dihedralAngleSummary(e,t=!1){const n=new $s,i=e instanceof be?e.data.point:void 0,s=e instanceof be?e.createVisitor(1):e;s.setNumWrap(1);const r=[];let a=0;for(s.reset();s.moveToNextFacet();){const m=s.pointCount-1,p=re.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),a);i||(_.edgeVector=v.createStartEnd(s.point.getPoint3dAtUncheckedPointIndex(x),s.point.getPoint3dAtUncheckedPointIndex(x+1)))}a++}}const o=[],c=[];if(n.sortAndCollectClusters(c,t?void 0:o,void 0,o),o.length>0)return-2;let d=0,h=0,u=0;const g=v.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],S=_.signedAngleTo(I,g);S.isAlmostZero?h++:S.radians>0?d++:u++}return d>0&&u===0?1:u>0&&d===0?-1:h>0&&d===0&&u===0?0:-2}static isConvexByDihedralAngleCount(e,t=!1){return this.dihedralAngleSummary(e,t)>0}static isSubsetVisitor(e){if(e instanceof be)return!1;const t=e.clientPolyface()?.facetCount,n=e.getVisitableFacetCount?.();return t===void 0||n===void 0?!1:t>n}static isPolyfaceManifoldFast(e,t){if(t)return;if(this.isSubsetVisitor(e))return!1;const n=_n.hasEdgeMateIndex(e);if(n){for(const i of n.edgeMateIndex)if(i===void 0)return!1;return!0}}static isPolyfaceManifold(e,t=!1){const n=this.isPolyfaceManifoldFast(e,t);if(n!==void 0)return n;const i=[];return this.createIndexedEdges(e).sortAndCollectClusters(void 0,t?void 0:i,void 0,i),i.length===0}static isPolyfaceClosedByEdgePairing(e){return this.isPolyfaceManifold(e,!1)}static announceBoundaryEdgesFast(e,t,n,i,s){if(n!==i)return!1;if(!n&&!s)return!0;if(this.isSubsetVisitor(e))return!1;const r=_n.hasEdgeMateIndex(e);if(!r)return!1;const a=y.create(),o=y.create();for(let c=0;c<r.edgeMateIndex.length;c++){const d=r.edgeMateIndex[c];if(n&&d===void 0||s&&d===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,a),r.parent.data.getPoint(x,o),t(a,o,m,x,g)}}}return!0}static announceBoundaryEdges(e,t,n=!0,i=!0,s=!0){if(this.announceBoundaryEdgesFast(e,t,n,i,s)||!n&&!i&&!s)return;const r=e instanceof be?e.data.point:void 0,a=e instanceof be?e.createVisitor(1):e;a.setNumWrap(1);const o=new $s;for(a.reset();a.moveToNextFacet();){const p=a.pointCount-1;for(let x=0;x<p;x++){const _=o.addEdge(a.clientPointIndex(x),a.clientPointIndex(x+1),a.currentReadIndex());r||(_.pointA=a.point.getPoint3dAtUncheckedPointIndex(x),_.pointB=a.point.getPoint3dAtUncheckedPointIndex(x+1))}}const c=[],d=n?c:void 0,h=s?c:void 0,u=i?c:void 0;if(o.sortAndCollectClusters(void 0,d,h,u),c.length===0)return;const g=y.create(),m=y.create();for(const p of c){const x=p instanceof Xt?p:p[0],_=x.startVertex,I=x.endVertex;r?(r.getPoint3dAtUncheckedPointIndex(_,g),r.getPoint3dAtUncheckedPointIndex(I,m)):(g.setFrom(x.pointA),m.setFrom(x.pointB)),t(g,m,_,I,x.facetIndex)}}static boundaryEdges(e,t=!0,n=!0,i=!0){const s=new zt,r=(a,o,c,d,h)=>{s.tryAddChild(Q.create(a,o))};if(Ee.announceBoundaryEdges(e,r,t,n,i),s.children.length!==0)return s}static collectBoundaryEdges(e,t=!0,n=!0,i=!0){const s=new St(f.smallMetricDistance,f.smallMetricDistance),r=(a,o)=>s.captureCurve(Q.create(a,o));return Ee.announceBoundaryEdges(e,r,t,n,i),s.grabResult(!0)}static createIndexedEdges(e){const t=new $s,n=e instanceof be?e.createVisitor(1):e;for(n.setNumWrap(1),n.reset();n.moveToNextFacet();)t.addPath(n.pointIndex,n.currentReadIndex(),!1);return t}static announceSilhouetteEdges(e,t,n,i=T.createSmallAngle()){if(e instanceof be)return this.announceSilhouetteEdges(e.createVisitor(1),t,n,i);const s=e.clientPolyface();if(s===void 0)return;e.setNumWrap(1);const r=this.createIndexedEdges(e),a=[];r.sortAndCollectClusters(a);const o=i.radians<0?-i.radians:i.radians,c=y.create(),d=y.create(),h=v.create(),u=g=>{if(!Ee.computeFacetUnitNormal(e,g,h))return{isSideFace:!1,perpAngle:0};const m=h.radiansFromPerpendicular(n);return{isSideFace:Math.abs(m)<=o,perpAngle:m}};for(const g of a){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,d))continue;const x=u(g[0].facetIndex);if(x.isSideFace){t(c,d,m,p,g[0].facetIndex);continue}const _=u(g[1].facetIndex);if(_.isSideFace){t(d,c,p,m,g[1].facetIndex);continue}if(x.perpAngle*_.perpAngle<0){t(c,d,m,p,g[0].facetIndex);continue}}}static collectSilhouetteEdges(e,t,n=T.createSmallAngle()){const i=new St(f.smallMetricDistance,f.smallMetricDistance);return Ee.announceSilhouetteEdges(e,(s,r)=>i.captureCurve(Q.create(s,r)),t,n),i.grabResult(!0)}static announceSweepLinestringToConvexPolyfaceXY(e,t,n){const i=tr.create(e);if(i){const s=t.createVisitor(0);for(s.reset();s.moveToNextFacet();)i.projectToPolygon(s.point,n,t,s.currentReadIndex())}}static _asyncWorkLimit=1e6;static setAsyncWorkLimit(e){const t=this._asyncWorkLimit;return this._asyncWorkLimit=e,t}static get asyncWorkLimit(){return this._asyncWorkLimit}static awaitBlockCount=0;static async continueAnnounceSweepLinestringToConvexPolyfaceXY(e,t,n,i){let s=0;for(;s<this.asyncWorkLimit&&n.moveToNextFacet();)s+=e.projectToPolygon(n.point,i,t,n.currentReadIndex());return s}static async asyncAnnounceSweepLinestringToConvexPolyfaceXY(e,t,n){const i=tr.create(e);this.awaitBlockCount=0;let s=0;if(i){const r=t.createVisitor(0);let a;for(;0<(a=await Promise.resolve(Ee.continueAnnounceSweepLinestringToConvexPolyfaceXY(i,t,r,n)));)s+=a,this.awaitBlockCount++}return s}static partitionFacetIndicesByVertexConnectedComponent(e){if(e instanceof be)return this.partitionFacetIndicesByVertexConnectedComponent(e.createVisitor(0));const t=new po(this.visitorClientPointCount(e));for(e.reset();e.moveToNextFacet();){const r=e.pointIndex[0];for(const a of e.pointIndex)t.mergeSubsets(r,a)}const n=t.collectRootIndices(),i=[],s=n.length;for(let r=0;r<s;r++)i.push([]);for(e.reset();e.moveToNextFacet();){const r=e.pointIndex[0],a=t.findRoot(r);for(let o=0;o<s;o++)if(n[o]===a){i[o].push(e.currentReadIndex());break}}return i}static partitionFacetIndicesByVisibilityVector(e,t,n){if(e instanceof be)return this.partitionFacetIndicesByVisibilityVector(e.createVisitor(0),t,n);const i=[];for(let c=0;c<3;c++)i.push([]);const s=i[0],r=i[1],a=i[2],o=Math.max(n.radians,1e-8);for(e.reset();e.moveToNextFacet();){const c=re.areaNormalGo(e.point),d=e.currentReadIndex();if(c){const h=c.angleFromPerpendicular(t);Math.abs(h.radians)<o?a.push(d):c.dotProduct(t)<0?r.push(d):s.push(d)}}return i}static boundaryOfVisibleSubset(e,t,n,i=T.createDegrees(.001)){const s=e instanceof be?e.createVisitor(0):e;if(!s.createSubsetVisitor)return;const r=this.partitionFacetIndicesByVisibilityVector(e,n,i);if(r[t].length===0)return;const a=s.createSubsetVisitor(r[t],1);return this.boundaryEdges(a,!0,!1,!1)}static announceBoundaryChainsAsLineString3d(e,t){const n=new St(f.smallMetricDistance),i=(s,r)=>n.captureCurve(Q.create(s,r));Ee.announceBoundaryEdges(e,i,!0,!1,!1),n.announceChainsAsLineString3d(t)}static cloneWithMaximalPlanarFacets(e,t){if(e instanceof be)return this.cloneWithMaximalPlanarFacets(e.createVisitor(0),t);const n=Ee.visitorClientFacetCount(e),i=Ee.collectEdgesByDihedralAngle(e,t),s=Ee.partitionFacetIndicesBySortableEdgeClusters(i,n),r=ce.create(),a=e,o=[],c=[],d=v.createZero();for(const x of s)if(x.length===1)a.moveToReadIndex(x[0])&&r.addFacetFromVisitor(a);else if(x.length>1){const _=v.createZero(),I=y.createZero();a.moveToReadIndex(x[0])&&a.point.getPoint3dAtCheckedPointIndex(0,I);for(const S of x)a.moveToReadIndex(S)&&re.areaNormalGo(a.point,d)&&_.addInPlace(d);c.push(q.createCapture(I,_)),o.push(x)}const h=Ee.clonePartitions(e,o);o.length,c.length,o.length,h.length;const u=1e-4,g=1e-4,m=X.createIdentity(),p=X.createIdentity();for(let x=0;x<h.length;++x){const _=h[x],I=[],S=[];Ee.announceBoundaryEdges(_,(w,k,D,P)=>{I.push(Q.create(w,k)),S.push([w.clone(),k.clone()])},!0,!1,!1);const A=$n.collectChains(I,u,g);if(A&&(c[x].toRigidZFrame(m),m.inverse(p))){p.multiplyPoint3dArrayArrayInPlace(S);const w=!(A instanceof oe),k=rn.formGraphFromChains(S,w,O.BOUNDARY_EDGE);if(k){Wn.collectConnectedComponentsWithExteriorParityMasks(k,new qc(O.BOUNDARY_EDGE),O.EXTERIOR);const D=ce.graphToPolyface(k);r.addIndexedPolyface(D,!1,m)}}}return r.claimPolyface(!0)}static fillSimpleHoles(e,t,n){if(e instanceof be)return this.fillSimpleHoles(e.createVisitor(0),t,n);const i=ce.create(),s=[];Ee.announceBoundaryChainsAsLineString3d(e,r=>{r.reverseInPlace(),s.push(r)});for(const r of s){const a=r.points;let o=!1;r.isPhysicallyClosed?(t.maxEdgesAroundHole!==void 0&&a.length>t.maxEdgesAroundHole||t.maxPerimeter!==void 0&<.sumEdgeLengths(a,!1)>t.maxPerimeter||t.upVector!==void 0&&re.sumTriangleAreasPerpendicularToUpVector(a,t.upVector)<=0)&&(o=!0):o=!0,!o&&Zc.triangulateSimplestSpaceLoop(a,(c,d)=>{for(const h of d)i.addPolygon(h)})||(o=!0),o&&n!==void 0&&n.push(r)}if(t.includeOriginalMesh!==void 0&&t.includeOriginalMesh)for(e.reset();e.moveToNextFacet();)i.addFacetFromVisitor(e);return i.claimPolyface(!0)}static clonePartitions(e,t){if(e instanceof be)return this.clonePartitions(e.createVisitor(0),t);e.setNumWrap(0);const n=[],i=st.createForFacets();i.needNormals=e.normal!==void 0,i.needParams=e.param!==void 0,i.needColors=e.color!==void 0,i.needTwoSided=e.twoSided;for(const s of t){const r=ce.create(i);e.reset();for(const a of s)e.moveToReadIndex(a),r.addFacetFromVisitor(e);n.push(r.claimPolyface(!0))}return n}static cloneFiltered(e,t){if(e instanceof be)return this.cloneFiltered(e.createVisitor(0),t);e.setNumWrap(0);const n=st.createForFacets();n.needNormals=e.normal!==void 0,n.needParams=e.param!==void 0,n.needColors=e.color!==void 0,n.needTwoSided=e.twoSided;const i=ce.create(n);for(e.reset();e.moveToNextFacet();)t(e)&&i.addFacetFromVisitor(e);return i.claimPolyface(!0)}static cloneWithDanglingEdgesRemoved(e){if(e instanceof be)return this.cloneWithDanglingEdgesRemoved(e.createVisitor(0));const t=st.createForFacets();t.needNormals=e.normal!==void 0,t.needParams=e.param!==void 0,t.needColors=e.color!==void 0,t.needTwoSided=e.twoSided;const n=ce.create(t),i=(s,r)=>{const a=s.length;for(let o=0;o<a;++o){let c=1,d=o,h=o;for(;c+2<=a;){const u=d===0?a-1:d-1,g=h===a-1?0:h+1;if(r[s[u]]!==r[s[g]])break;d=u,h=g,c+=2}if(c>1)return d<h?s.splice(d,c-1):d>h&&(s.splice(d),s.splice(0,h)),!0}return!1};for(e.setNumWrap(0),e.reset();e.moveToNextFacet();){const s=[...Array(e.pointIndex.length).keys()];for(;i(s,e.pointIndex););n.addFacetFromIndexedVisitor(e,s)}return n.claimPolyface(!0)}static visitorClientPointCount(e){if(e instanceof be)return e.data.point.length;const t=e.clientPolyface();if(t!==void 0)return t.data.point.length;const n=e.currentReadIndex();e.reset();let i=-1;for(;e.moveToNextFacet();)for(const s of e.pointIndex)s>i&&(i=s);return e.moveToReadIndex(n),i+1}static visitorClientFacetCount(e){if(e instanceof be){if(e.facetCount!==void 0)return e.facetCount;e=e.createVisitor(0)}if(e.getVisitableFacetCount)return e.getVisitableFacetCount();const t=e.clientPolyface();if(t!==void 0&&t.facetCount!==void 0)return t.facetCount;const n=e.currentReadIndex();let i=0;for(e.reset();e.moveToNextFacet();)++i;return e.moveToReadIndex(n),i}static partitionFacetIndicesBySortableEdgeClusters(e,t){const n=new po(t);for(const a of e)if(!(a instanceof Xt)){const o=a[0];for(let c=1;c<a.length;c++)n.mergeSubsets(o.facetIndex,a[c].facetIndex)}const i=n.collectRootIndices(),s=[],r=i.length;for(let a=0;a<r;a++)s.push([]);for(let a=0;a<t;a++){const o=n.findRoot(a);for(let c=0;c<r;c++)if(i[c]===o){s[c].push(a);break}}return s}static partitionFacetIndicesByEdgeConnectedComponent(e,t=!1){if(e instanceof be)return this.partitionFacetIndicesByEdgeConnectedComponent(e.createVisitor(0),t);e.setNumWrap(1);const n=new $s;e.reset();let i=0;for(;e.moveToNextFacet();){const r=e.pointCount-1;i++;for(let a=0;a<r;a++)t&&e.edgeVisible[a]||n.addEdge(e.clientPointIndex(a),e.clientPointIndex(a+1),e.currentReadIndex())}const s=[];return n.sortAndCollectClusters(s,s,s,s),this.partitionFacetIndicesBySortableEdgeClusters(s,i)}static sweepLineStringToFacetsXYReturnSweptFacets(e,t){const n=ce.create();return this.announceSweepLinestringToConvexPolyfaceXY(e,t,(i,s,r,a,o)=>{o.length===4?n.addQuadFacet(o):o.length===3&&n.addTriangleFacet(o)}),n.claimPolyface(!0)}static sweepLinestringToFacetsXYreturnSweptFacets(e,t){return this.sweepLineStringToFacetsXYReturnSweptFacets(e,t)}static sweepLineStringToFacets(e,t,n){let i=[];n===void 0&&(n=nr.create());let s;n.assembleChains&&(s=an.create());const r=s?(c,d)=>s.addSegment(c,d):(c,d)=>i.push(Q.create(c,d)),a=v.createZero(),o=t instanceof be?t.createVisitor(0):t;if(o.setNumWrap(0),n.searcher&&n.vectorToEye.isParallelTo(v.unitZ())){const c=ie.createNull(),d=y.createZero(),h=y.createZero();let u;const g=(m,p)=>(o.moveToReadIndex(p)&&(n.collectAll||n.collectFromThisFacetNormal(re.areaNormalGo(o.point,a)))&&u?.processPolygon(o.point,(x,_)=>r(x,_)),!0);for(let m=1;m<e.length;m++)e.getPoint3dAtUncheckedPointIndex(m-1,d),e.getPoint3dAtUncheckedPointIndex(m,h),(u=as.createPointPointSweep(d,h,n.vectorToEye))&&(c.setNull(),c.extend(d,h),n.searcher.searchRange2d(c,g))}else{const c=pa.create(e,n.vectorToEye);if(c)for(o.reset();o.moveToNextFacet();)(n.collectAll||n.collectFromThisFacetNormal(re.areaNormalGo(o.point,a)))&&c.processPolygon(o.point.getArray(),r)}return s&&(s.clusterAndMergeVerticesXYZ(),i=s.collectMaximalChains()),i}static sweepLineStringToFacetsXY(e,t,n){const i=an.create(),s=v.unitZ(),r=ie.create(),a=y.createZero(),o=y.createZero(),c=t instanceof be?t.createVisitor(0):t;c.setNumWrap(0);let d;const h=(g,m)=>(c.moveToReadIndex(m)&&d?.processPolygon(c.point,(p,x)=>i.addSegment(p,x)),!0),u=Array.isArray(e)?new Qe(e):e;for(let g=1;g<u.length;g++)u.getPoint3dAtUncheckedPointIndex(g-1,a),u.getPoint3dAtUncheckedPointIndex(g,o),(d=as.createPointPointSweep(a,o,s))&&(r.setNull(),r.extend(a,o),n.searchRange2d(r,h));return i.clusterAndMergeVerticesXYZ(),i.collectMaximalChains()}static sweepLinestringToFacetsXYReturnLines(e,t){const n=nr.create(v.unitZ(),T.createSmallAngle(),!1,!0,!0,!0);return Ee.sweepLineStringToFacets(e,t,n)}static sweepLinestringToFacetsXYReturnChains(e,t){return Ee.sweepLineStringToFacets(e,t)}static async asyncSweepLinestringToFacetsXYReturnChains(e,t){const n=an.create();return await Promise.resolve(this.asyncAnnounceSweepLinestringToConvexPolyfaceXY(e,t,(s,r,a,o,c,d,h)=>{n.addSegment(c[d],c[h])})),n.clusterAndMergeVerticesXYZ(),n.collectMaximalChains()}static collectRangeLengthData(e){if(e instanceof be)return this.collectRangeLengthData(e.createVisitor(0));const t=new Jc;for(e.reset();e.moveToNextFacet();)t.accumulateGrowableXYZArrayRange(e.point);return t}static cloneWithTVertexFixup(e){const t=e.createVisitor(1),n=e.createVisitor(0),i=_a.create(e.data.point,30),s=ce.create();if(!i)return s.addFacetsFromVisitor(t),s.claimPolyface(!1);const r=ie.createNull(),a=y.create(),o=y.create(),c=y.create(),d=Q.create(a,o);for(t.reset();t.moveToNextFacet();){n.clearArrays();for(let h=0;h+1<t.point.length;h++){t.point.getPoint3dAtUncheckedPointIndex(h,a),t.point.getPoint3dAtUncheckedPointIndex(h+1,o),n.pushDataFrom(t,h),r.setNull(),Q.create(a,o,d);let u;if(r.extend(a),r.extend(o),r.ensureMinLengths(f.smallMetricDistance),i.announcePointsInRange(r,(g,m,p,x)=>{e.data.point.getPoint3dAtUncheckedPointIndex(g,c);const _=d.closestPoint(c,!1);return _!==void 0&&_.fraction>0&&_.fraction<1&&!_.point.isAlmostEqual(a)&&!_.point.isAlmostEqual(o)&&c.isAlmostEqual(_.point)&&(u===void 0&&(u=[]),_.a=g,u.push(_)),!0}),u!==void 0){u.sort((g,m)=>g.fraction-m.fraction);for(const g of u)n.pushInterpolatedDataFrom(t,h,g.fraction,h+1)}}s.addFacetFromGrowableArrays(n.point,n.normal,n.param,n.color,n.edgeVisible)}return s.claimPolyface()}static compareFacetIndexAndVertexIndices(e,t){if(e.length!==t.length)return e.length-t.length;for(let n=1;n<e.length;n++)if(e[n]!==t[n])return e[n]-t[n];return 0}static announceDuplicateFacetIndices(e,t){const n=e.createVisitor(0),i=[];for(n.reset();n.moveToNextFacet();){const d=[n.currentReadIndex()],h=n.pointIndex,u=h.length;let g=0;for(let m=1;m<n.pointIndex.length;m++)h[m]<h[g]&&(g=m);if(h[(g+1)%u]<h[(g+u-1)%u])for(let m=0;m<u;m++)d.push(h[(g+m)%u]);else for(let m=0;m<u;m++)d.push(h[(g+u-m)%u]);i.push(d)}i.sort((c,d)=>this.compareFacetIndexAndVertexIndices(c,d));let s,r;const a=i.length,o=[];for(s=0;s<a;s=r){for(r=s+1,o.length=0,o.push(i[s][0]);r<a&&this.compareFacetIndexAndVertexIndices(i[s],i[r])===0;)o.push(i[r][0]),r++;t(o)}}static collectDuplicateFacetIndices(e,t=!1){const n=[];return this.announceDuplicateFacetIndices(e,i=>{(t||i.length>1)&&n.push(i.slice())}),n}static cloneByFacetDuplication(e,t,n){const i=ce.create(),s=e.createVisitor(0);return this.announceDuplicateFacetIndices(e,r=>{let a=0;r.length===1?t&&(a=1):r.length>1&&(n===cs.SelectAny?a=1:n===cs.SelectAll?a=r.length:n===cs.SelectOneByParity&&(a=(r.length&1)===1?1:0));for(let o=0;o<a;o++)s.moveToReadIndex(r[o]),i.addFacetFromVisitor(s)}),i.claimPolyface()}static cloneWithColinearEdgeFixup(e){const t=e.createVisitor(2),n=e.createVisitor(0),i=ce.create(),s=v.create(),r=v.create(),a=e.data.point.length,o=new Int32Array(a);for(t.reset();t.moveToNextFacet();)for(let c=0;c+2<t.point.length;c++){t.point.vectorIndexIndex(c,c+1,s),t.point.vectorIndexIndex(c+1,c+2,r);const d=t.clientPointIndex(c+1);o[d]>=0&&(s.angleTo(r).isAlmostZero?o[d]++:o[d]=-1)}for(t.reset();t.moveToNextFacet();){n.clearArrays();for(let c=0;c+2<t.point.length;c++){const d=t.clientPointIndex(c);o[d]<0&&n.pushDataFrom(t,c)}n.point.length>2&&i.addFacetFromGrowableArrays(n.point,n.normal,n.param,n.color,n.edgeVisible)}return i.claimPolyface()}static setEdgeVisibility(e,t,n){for(const i of t)if(i instanceof Xt)this.setSingleEdgeVisibility(e,i.facetIndex,i.startVertex,n);else if(Array.isArray(i))for(const s of i)this.setSingleEdgeVisibility(e,s.facetIndex,s.startVertex,n)}static setSingleEdgeVisibility(e,t,n,i){const s=e.data,r=e.facetIndex0(t),a=e.facetIndex1(t);for(let o=r;o<a;o++)s.pointIndex[o]===n&&(s.edgeVisible[o]=i)}static getSingleEdgeVisibility(e,t,n){const i=e.data,s=e.facetIndex0(t),r=e.facetIndex1(t);for(let a=s;a<r;a++)if(i.pointIndex[a]===n)return i.edgeVisible[a]}static collectEdgesByDihedralAngle(e,t,n=!1){if(e instanceof be)return this.collectEdgesByDihedralAngle(e.createVisitor(1),t,n);e.setNumWrap(1);const i=this.createIndexedEdges(e),s=[];i.sortAndCollectClusters(s),(t===void 0||t.radians<0)&&(t=T.createRadians(f.smallAngleRadians));const r=[],a=v.create(),o=v.create();for(const c of s)if(Array.isArray(c)&&c.length===2){const d=c[0],h=c[1];if(Ee.computeFacetUnitNormal(e,d.facetIndex,a)!==void 0&&Ee.computeFacetUnitNormal(e,h.facetIndex,o)!==void 0){const u=a.smallerUnorientedAngleTo(o);n?u.radians>t.radians&&r.push(c):u.radians<=t.radians&&r.push(c)}}return r}static markPairedEdgesInvisible(e,t){const n=e.createVisitor(1),i=this.createIndexedEdges(n),s=[],r=[];if(i.sortAndCollectClusters(s,r,r,r),this.markAllEdgeVisibility(e,!1),this.setEdgeVisibility(e,r,!0),t!==void 0){const a=v.create(),o=v.create();for(const c of s)if(Array.isArray(c)&&c.length===2){const d=c[0],h=c[1];Ee.computeFacetUnitNormal(n,d.facetIndex,a)!==void 0&&Ee.computeFacetUnitNormal(n,h.facetIndex,o)!==void 0&&a.smallerUnorientedAngleTo(o).radians>t.radians&&(this.setSingleEdgeVisibility(e,d.facetIndex,d.startVertex,!0),this.setSingleEdgeVisibility(e,h.facetIndex,h.startVertex,!0))}}}static computeFacetUnitNormal(e,t,n){if(n||(n=v.create()),e.moveToReadIndex(t)&&re.unitNormal(e.point,n))return n}static markAllEdgeVisibility(e,t){const n=e.data;for(let i=0;i<n.edgeVisible.length;i++)n.edgeVisible[i]=t}static convertToHalfEdgeGraph(e){const t=new _o,n=e.createVisitor(0),i=y.create();for(n.reset();n.moveToNextFacet();)t.insertLoop(n.pointIndex,s=>{e.data.getPoint(s.i,i),s.setXYZ(i),e.data.getPoint(s.edgeMate.i,i),s.edgeMate.setXYZ(i)});return t.graph}static reorientVertexOrderAroundFacetsForConsistentOrientation(e){return di.doFixup(e)}static buildPerFaceNormals(e){Po.buildPerFaceNormals(e)}static buildAverageNormals(e,t=T.createDegrees(31)){Po.buildFastAverageNormals(e,t)}static cloneOffset(e,t,n=ya.create()){const i=st.createForFacets(),s=ce.create(i);return Ae.buildOffsetMeshWithEdgeChamfers(e,s,t,n),s.claimPolyface()}static _workTriangle;static _workTriDetail;static _workPolyDetail;static _workFacetDetail3;static _workFacetDetailC;static _workFacetDetailNC;static intersectRay3d(e,t,n){if(e instanceof be)return Ee.intersectRay3d(e.createVisitor(0),t,n);let i;const s=n?[n.distanceTolerance,n.parameterTolerance]:void 0;for(e.setNumWrap(0);e.moveToNextFacet();){const r=e.pointCount,a=e.point;if(r===3){const o=this._workTriangle=Ie.create(a.getPoint3dAtUncheckedPointIndex(0),a.getPoint3dAtUncheckedPointIndex(1),a.getPoint3dAtUncheckedPointIndex(2),this._workTriangle),c=this._workTriDetail=o.intersectRay3d(t,this._workTriDetail);o.snapLocationToEdge(c,n?.distanceTolerance,n?.parameterTolerance),i=this._workFacetDetail3=ss.create(e.currentReadIndex(),c,this._workFacetDetail3)}else{const o=this._workPolyDetail=re.intersectRay3d(a,t,s,this._workPolyDetail);re.isConvex(a)?i=this._workFacetDetailC=ci.create(e.currentReadIndex(),r,o,this._workFacetDetailC):i=this._workFacetDetailNC=Gn.create(e.currentReadIndex(),r,o,this._workFacetDetailNC)}if(i.isInsideOrOn){if(n?.needNormal&&e.normal&&i.getNormal(e.normal,a,n?.distanceTolerance),n?.needParam&&e.param&&i.getParam(e.param,a,n?.distanceTolerance),n?.needColor&&e.color&&i.getColor(e.color,a,n?.distanceTolerance),n?.needBarycentricCoordinates&&i.getBarycentricCoordinates(a,n?.distanceTolerance),n?.acceptIntersection&&!n.acceptIntersection(i,e))continue;return i}}}}class Ce{static hugeVal=1e37;_planes;constructor(e){this._planes=e||[]}get planes(){return this._planes}toJSON(){const e=[];for(const t of this._planes)e.push(t.toJSON());return e}static fromJSON(e,t){if(t=t||new Ce,t._planes.length=0,!Array.isArray(e))return t;for(const n of e){const i=ee.fromJSON(n);i&&t._planes.push(i)}return t}isAlmostEqual(e){if(this._planes.length!==e._planes.length)return!1;for(let t=0;t<this._planes.length;t++)if(!this._planes[t].isAlmostEqual(e._planes[t]))return!1;return!0}static createPlanes(e,t){t=t||new Ce;for(const n of e)if(n instanceof ee)t._planes.push(n);else if(n instanceof pe){const i=ee.createPlane(n);t._planes.push(i)}return t}static createRange3dPlanes(e,t=!0,n=!0,i=!0,s=!0,r=!0,a=!0){const o=Ce.createEmpty();return t&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(1,0,0,e.low.x,0,0)),n&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(-1,0,0,e.high.x,0,0)),i&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(0,1,0,0,e.low.y,0)),s&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(0,-1,0,0,e.high.y,0)),r&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(0,0,1,0,0,e.low.z)),a&&o.addPlaneToConvexSet(ee.createNormalAndPointXYZXYZ(0,0,-1,0,0,e.high.z)),o}static createEmpty(e){return e?(e._planes.length=0,e):new Ce}negateAllPlanes(){for(const e of this._planes)e.negateInPlace()}static createXYBox(e,t,n,i,s){s=s||new Ce,s._planes.length=0;const r=ee.createNormalAndDistance(v.create(-1,0,0),-n,!1,!0),a=ee.createNormalAndDistance(v.create(1,0,0),e,!1,!0),o=ee.createNormalAndDistance(v.create(0,-1,0),-i,!1,!0),c=ee.createNormalAndDistance(v.create(0,1,0),t,!1,!0);return r&&a&&o&&c&&s._planes.push(r,a,o,c),s}static createXYPolyLine(e,t,n,i){i=i||new Ce,i._planes.length=0;for(let s=0;s+1<e.length;s++){const a=v.createStartEnd(e[s],e[s+1]).unitPerpendicularXY();if(a.z=0,n||a.scaleInPlace(-1),a.normalize()){const c=t!==void 0?t[s]:!1,d=ee.createNormalAndPoint(a,e[s],c,c);d&&i._planes.push(d)}}return i}static createXYPolyLineInsideLeft(e,t){t=t||new Ce,t._planes.length=0;for(let n=0;n+1<e.length;n++){const s=v.createStartEnd(e[n],e[n+1]).unitPerpendicularXY();if(s.z=0,s.normalize()){const a=ee.createNormalAndPoint(s,e[n],!1,!1);a&&t._planes.push(a)}}return t}static setPlaneAndXYLoopCCW(e,t,n){const i=e.length-1,s=e.length;let r=e.getXAtUncheckedPointIndex(i),a=e.getYAtUncheckedPointIndex(i),o,c,d,h;n._planes.length=0;const u=e.getZAtUncheckedPointIndex(i),g=e.crossProductIndexIndexIndex(0,2,1);if(g?.normalizeInPlace()){ee.createNormalAndPointXYZXYZ(g.x,g.y,g.z,r,a,u,!1,!1,t);for(let m=0;m<s;m++,r=o,a=c){o=e.getXAtUncheckedPointIndex(m),c=e.getYAtUncheckedPointIndex(m),d=-(c-a),h=o-r;const p=ee.createNormalAndPointXYZXYZ(d,h,0,o,c,u);p&&n._planes.push(p)}}}clone(e){e=e||new Ce,e._planes.length=0;for(const t of this._planes)e._planes.push(t.clone());return e}hasIntersectionWithRay(e,t,n=f.smallMetricDistance){let i=-f.largeCoordinateResult,s=f.largeCoordinateResult;t&&t.setNull();const r=1e-13;for(const a of this._planes){const o=a.velocity(e.direction),c=a.altitude(e.origin);if(Math.abs(o)<=r){if(c<-n)return!1}else{const d=-c/o;o<0?d<s&&(s=d):d>i&&(i=d)}}return s<i?!1:(t&&(t.extendX(i),t.extendX(s)),!0)}multiplyPlanesByMatrix4d(e,t=!0,n=!0){if(t){const i=e.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._planes)i.multiplyPlaneByMatrix4d(e,!1,n);return!0}isPointInside(e){for(const t of this._planes)if(!t.isPointInside(e))return!1;return!0}isPointOnOrInside(e,t=f.smallMetricDistance){const n=Math.abs(t);for(const i of this._planes)if(!i.isPointOnOrInside(e,i.interior?n:t))return!1;return!0}isSphereInside(e,t){const n=Math.abs(t)+f.smallMetricDistance;for(const i of this._planes)if(!i.isPointOnOrInside(e,n))return!1;return!0}announceClippedSegmentIntervals(e,t,n,i,s){let r;if(t<e)return!1;for(const a of this._planes){const o=-a.altitude(n),c=-a.altitude(i);if(r=f.conditionalDivideFraction(-o,c-o),r===void 0){if(o>0)return!1}else if(c>o){if(r<e)return!1;r<t&&(t=r)}else if(o>c){if(r>t)return!1;r>e&&(e=r)}else if(o>0)return!1}return t>=e?(s&&s(e,t),!0):!1}static _clipFractionArray=new Me;announceClippedArcIntervals(e,t){const n=Ce._clipFractionArray;n.clear();for(const i of this.planes)i.appendIntersectionRadians(e,n);return e.sweep.radiansArrayToPositivePeriodicFractions(n),at.selectIntervals01(e,n,this,t)}announceClippedCurveIntervals(e,t){const n=Ce._clipFractionArray;n.clear();const i=[];for(const s of this.planes)e.appendPlaneIntersectionPoints(s,i);for(const s of i)n.push(s.fraction);return at.selectIntervals01(e,n,this,t)}clipUnboundedSegment(e,t,n){return this.announceClippedSegmentIntervals(-Number.MAX_VALUE,Number.MAX_VALUE,e,t,n)}transformInPlace(e){for(const t of this._planes)t.transformInPlace(e)}clipConvexPolygonInPlace(e,t,n=f.smallMetricDistance){for(const i of this._planes)if(i.clipConvexPolygonInPlace(e,t,!0,n),e.length<3)return}clipInsidePushOutside(e,t,n){const i=fe.createNull();let s=n.grabFromCache(),r=n.grabFromCache(),a=n.grabFromCache();a.pushFrom(e);for(const o of this._planes)if(un.splitConvexPolygonInsideOutsidePlane(o,a,s,r,i),r.length>0){if(t&&at.captureOrDrop(r,3,t,n),r=n.grabFromCache(),s.length<3){a.length=0;break}n.dropToCache(a),a=s,s=n.grabFromCache()}if(n.dropToCache(s),n.dropToCache(r),a.length>0)return a;n.dropToCache(a)}classifyPointContainment(e,t){let n=!0;const i=t?1e-8:-1e-8,s=1e-8;for(const r of this._planes){let a=0;for(const o of e)r.altitude(o)<(r.interior?s:i)&&(a++,n=!1);if(a===e.length)return ht.StronglyOutside}return n?ht.StronglyInside:ht.Ambiguous}static createSweptPolyline(e,t,n){const i=Ce.createEmpty();let s=!1;e.length>3&&e[0].isAlmostEqual(e[e.length-1])&&re.areaNormal(e).dotProduct(t)>0&&(s=!0);for(let r=0;r+1<e.length;r++)if(s){const a=ee.createEdgeAndUpVector(e[r+1],e[r],t,n);if(a)i.addPlaneToConvexSet(a);else return}else{const a=ee.createEdgeAndUpVector(e[r],e[r+1],t,n);if(a)i.addPlaneToConvexSet(a);else return}return i}addPlaneToConvexSet(e){e instanceof ee?this._planes.push(e):e instanceof pe&&this._planes.push(ee.createPlane(e))}clipPointsOnOrInside(e,t,n){t.length=0,n.length=0;for(const i of e)this.isPointOnOrInside(i,0)?t.push(i):n.push(i)}polygonClip(e,t,n,i,s=f.smallMetricDistance){e instanceof J?e.clone(t):J.create(e,t),n||(n=new J);for(const r of this._planes)if(i!==r){if(t.length===0)break;r.clipConvexPolygonInPlace(t,n,!0,s)}}reloadSweptPolygon(e,t,n){this._planes.length=0;const i=e.length;if(i<=2)return 0;const s=re.areaNormal(e),r=t.dotProduct(s)>0,a=r?1:i-1;for(let o=0;o<i;o++){const c=(o+a)%i,d=e[o],h=e[c];if(d.isAlmostEqual(h))continue;const u=v.createStartEnd(d,h),m=v.createCrossProduct(t.x,t.y,t.z,u.x,u.y,u.z).normalize();let p;if(m){p=m.dotProduct(d);const x=ee.createNormalAndDistance(m,p,!1,!1);x&&this._planes.push(x)}}if(n!==0){let o=s.normalize();if(o){t.dotProduct(o)*n<0&&(o=o.negate());const d=e[0],h=o.dotProduct(d),u=ee.createNormalAndDistance(o,h,!1,!1);u&&this._planes.push(u)}}return r?1:-1}computePlanePlanePlaneIntersections(e,t,n,i=!0){const s=E.createIdentity(),r=this._planes,a=y.createZero(),o=r.length;let c=0;for(let d=0;d<o;d++)for(let h=d+1;h<o;h++)for(let u=h+1;u<o;u++)E.createRowValues(r[d].inwardNormalRef.x,r[d].inwardNormalRef.y,r[d].inwardNormalRef.z,r[h].inwardNormalRef.x,r[h].inwardNormalRef.y,r[h].inwardNormalRef.z,r[u].inwardNormalRef.x,r[u].inwardNormalRef.y,r[u].inwardNormalRef.z,s),s.computeCachedInverse(!1)&&(s.multiplyInverseXYZAsPoint3d(r[d].distance,r[h].distance,r[u].distance,a),(!i||this.isPointOnOrInside(a,f.smallMetricDistance))&&(c++,n&&n.multiplyPoint3d(a,a),e&&e.push(a.clone()),t&&t.extendPoint(a)));return c}setInvisible(e){for(const t of this._planes)t.setInvisible(e)}addZClipPlanes(e,t,n){t!==void 0&&this.addPlaneToConvexSet(ee.createNormalAndDistance(v.create(0,0,1),t,e)),n!==void 0&&this.addPlaneToConvexSet(ee.createNormalAndDistance(v.create(0,0,-1),-n,e))}appendPolygonClip(e,t,n,i){const s=this.clipInsidePushOutside(e,n,i);s&&t.push(s)}static createConvexPolyface(e,t){t=this.createEmpty(t);let n=0;Ee.isPolyfaceClosedByEdgePairing(e)&&(n=Ee.sumTetrahedralVolumes(e));const i=n>0?-1:1,s=y.createZero(),r=v.createZero(),a=pe.createXYPlane(),o=e instanceof be?e.createVisitor(0):e;for(o.setNumWrap(0),o.reset();o.moveToNextFacet();)re.areaNormalGo(o.point,r)&&(r.scaleInPlace(i),o.point.front(s),t.addPlaneToConvexSet(pe.create(s,r,a)));return{clipper:t,volume:n}}}class xt{_convexSets;get convexSets(){return this._convexSets}constructor(){this._convexSets=[]}toJSON(){const e=[];for(const t of this._convexSets)e.push(t.toJSON());return e}static fromJSON(e,t){if(t=t||new xt,t._convexSets.length=0,!Array.isArray(e))return t;for(const n of e)t._convexSets.push(Ce.fromJSON(n));return t}static createEmpty(e){return e?(e._convexSets.length=0,e):new xt}isAlmostEqual(e){if(this._convexSets.length!==e._convexSets.length)return!1;for(let t=0;t<this._convexSets.length;t++)if(!this._convexSets[t].isAlmostEqual(e._convexSets[t]))return!1;return!0}static createConvexSets(e,t){t=t||new xt;for(const n of e)t._convexSets.push(n);return t}clone(e){e=e||new xt,e._convexSets.length=0;for(const t of this._convexSets)e._convexSets.push(t.clone());return e}addConvexSet(e){e&&this._convexSets.push(e)}hasIntersectionWithRay(e,t){if(t===void 0){for(const i of this._convexSets)if(i.hasIntersectionWithRay(e))return!0;return!1}t.setNull();const n=fe.createNull();for(const i of this._convexSets)i.hasIntersectionWithRay(e,n)&&t.extendRange(n);return!t.isNull}isPointInside(e){for(const t of this._convexSets)if(t.isPointInside(e))return!0;return!1}isPointOnOrInside(e,t=f.smallMetricDistance){for(const n of this._convexSets)if(n.isPointOnOrInside(e,t))return!0;return!1}isSphereInside(e,t){for(const n of this._convexSets)if(n.isSphereInside(e,t))return!0;return!1}isAnyPointInOrOnFromSegment(e){for(const t of this._convexSets)if(t.announceClippedSegmentIntervals(0,1,e.point0Ref,e.point1Ref))return!0;return!1}appendIntervalsFromSegment(e,t){for(const n of this._convexSets)n.announceClippedSegmentIntervals(0,1,e.point0Ref,e.point1Ref,(i,s)=>t.push(Je.create(i,s)))}transformInPlace(e){for(const t of this._convexSets)t.transformInPlace(e)}classifyPointContainment(e,t){for(const n of this._convexSets){const i=n.classifyPointContainment(e,t);if(i!==ht.StronglyOutside)return i}return ht.StronglyOutside}polygonClip(e,t,n,i,s=f.smallMetricDistance){t.length=0,Array.isArray(e)&&(e=J.create(e)),n||(n=new J);for(const r of this._convexSets){const a=new J;r.polygonClip(e,a,n,i,s),a.length!==0&&t.push(a)}}announceClippedSegmentIntervals(e,t,n,i,s){let r=0;for(const a of this._convexSets)a.announceClippedSegmentIntervals(e,t,n,i,s)&&r++;return r>0}static _clipFractionArray=new Me;announceClippedArcIntervals(e,t){const n=xt._clipFractionArray;n.clear();for(const i of this._convexSets)for(const s of i.planes)s.appendIntersectionRadians(e,n);return e.sweep.radiansArrayToPositivePeriodicFractions(n),at.selectIntervals01(e,n,this,t)}announceClippedCurveIntervals(e,t){const n=xt._clipFractionArray;n.clear();const i=[];for(const s of this._convexSets)for(const r of s.planes)e.appendPlaneIntersectionPoints(r,i);for(const s of i)n.push(s.fraction);return at.selectIntervals01(e,n,this,t)}computePlanePlanePlaneIntersectionsInAllConvexSets(e,t,n,i=!0){let s=0;for(const r of this._convexSets)s+=r.computePlanePlanePlaneIntersections(e,t,n,i);return s}multiplyPlanesByMatrix4d(e,t=!0,n=!0){if(t){const i=e.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._convexSets)i.multiplyPlanesByMatrix4d(e,!1,n);return!0}setInvisible(e){for(const t of this._convexSets)t.setInvisible(e)}addOutsideZClipSets(e,t,n){if(t){const i=Ce.createEmpty();i.addZClipPlanes(e,void 0,t),this._convexSets.push(i)}if(n){const i=Ce.createEmpty();i.addZClipPlanes(e,n),this._convexSets.push(i)}}takeConvexSets(e){let t;for(;(t=e._convexSets.pop())!==void 0;)this._convexSets.push(t)}appendPolygonClip(e,t,n,i){const s=n.length,r=t.length;let a=[i.grabAndFill(e)],o=[],c,d;for(const h of this._convexSets){for(;(d=a.pop())!==void 0;)h.appendPolygonClip(d,t,o,i),i.dropToCache(d);c=o,o=a,a=c}for(;(d=a.pop())!==void 0;)n.push(d);n.length===s?at.restoreSingletonInPlaceOfMultipleShards(t,r,e,i):t.length===r&&at.restoreSingletonInPlaceOfMultipleShards(n,s,e,i)}}class on{_origin;_direction;constructor(e,t){this._origin=e,this._direction=t}set(e,t){this._origin.setFrom(e),this._direction.setFrom(t)}static createZero(e){return e?(e.origin.setZero(),e.direction.setZero(),e):new on(L.createZero(),$.createZero())}static createOriginAndTarget(e,t,n){return n?(n._origin.setFrom(e),n._direction.set(t.x-e.x,t.y-e.y),n):new on(L.createFrom(e),$.createStartEnd(e,t))}static createOriginAndDirection(e,t,n){return n?(n.set(e,t),n):new on(L.createFrom(e),$.createFrom(t))}static createOriginAndDirectionCapture(e,t,n){return n?(n._origin=e,n._direction=t,n):new on(e,t)}get origin(){return this._origin}get direction(){return this._direction}parallelRay(e,t){return t?(this._origin.addForwardLeft(0,e,this._direction,t._origin),t._direction.setFrom(this._direction),t):new on(this._origin.addForwardLeft(0,e,this._direction),this._direction.clone())}ccwPerpendicularRay(e){return e?(e._origin.setFrom(this._origin),this._direction.rotate90CCWXY(e._direction),e):new on(this._origin.clone(),this._direction.rotate90CCWXY())}cwPerpendicularRay(e){return e?(e._origin.setFrom(this._origin),this._direction.rotate90CWXY(e._direction),e):new on(this._origin.clone(),this._direction.rotate90CWXY())}normalizeDirectionInPlace(e=1,t=0){return this._direction.normalize(this._direction)?!0:(this._direction.x=e,this._direction.y=t,!1)}intersectUnboundedLine(e,t){const n=$.createStartEnd(e,t),s=$.createStartEnd(e,this._origin).crossProduct(n),r=this._direction.crossProduct(n),a=f.conditionalDivideFraction(-s,r),o=a!==void 0;return{hasIntersection:o,fraction:o?a:0,cross:r}}intersectionWithRange2d(e,t){if(e.isNull)return fe.createNull(t);const n=fe.createXX(-f.largeCoordinateResult,f.largeCoordinateResult,t);return n.clipLinearMapToInterval(this.origin.x,this.direction.x,e.low.x,e.high.x),n.clipLinearMapToInterval(this.origin.y,this.direction.y,e.low.y,e.high.y),n}projectionFraction(e){return this._origin.vectorTo(e).fractionOfProjectionToVector(this._direction)}perpendicularProjectionFraction(e){const t=this._direction.crossProduct(this._origin.vectorTo(e)),n=this._direction.magnitudeSquared();return f.safeDivideFraction(t,n,0)}fractionToPoint(e,t){return this._origin.plusScaled(this._direction,e,t)}}class et{_voronoiGraph;_inputGraph;_inputGraphIsTriangulation;_inputGraphRange;_idToIndexMap;_circumcenterMap;_circumcenterRange;_isCurveBased;_superFaceMask;static _workXY0=L.createZero();static _workXY1=L.createZero();static _workRay=on.createZero();static _workArc=B.createUnitCircle();constructor(e,t=!1){this._voronoiGraph=new Ut,this._inputGraph=e,this._inputGraphRange=qe.graphRangeXY(e),this._idToIndexMap=e.constructIdToVertexIndexMap(),this._circumcenterMap=new Map,this._inputGraphIsTriangulation=t?!1:this.populateCircumcenters(this._circumcenterMap),this._circumcenterRange=ze.createArray(Array.from(this._circumcenterMap.values())),this._isCurveBased=!1,this._superFaceMask=O.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(e,t,n,i,s){return e.addEdgeXY(t.x,t.y,n.x,n.y,i,s)}static addEdgeWithFaceTags(e,t,n,i,s){return e.addEdgeXY(t.x,t.y,n.x,n.y,void 0,void 0,i,s)}getTriangleId(e){return e!==e.faceSuccessor.faceSuccessor.faceSuccessor?-1:Math.min(e.id,e.faceSuccessor.id,e.facePredecessor.id)}populateCircumcenters(e){e.clear();let t=!0;const n=y.createZero(),i=y.createZero(),s=y.createZero();return this._inputGraph.announceFaceLoops((r,a)=>{if(a.isMaskSet(O.EXTERIOR))return!0;if(a.countEdgesAroundFace()!==3)return t=!1;a.getPoint3d(n),a.faceSuccessor.getPoint3d(i),a.facePredecessor.getPoint3d(s),n.z=i.z=s.z=0;const o=B.createCircularStartMiddleEnd(n,i,s,et._workArc);return o instanceof B&&e.set(this.getTriangleId(a),o.center),!0}),t||e.clear(),t}getTriangleEdgeBisector(e,t,n){const i=e,s=e.faceSuccessor,r=e.facePredecessor,a=1/3,o=L.createAdd2ScaledXY(i.x,i.y,.5,s.x,s.y,.5),c=L.createAdd3ScaledXY(i.x,i.y,a,s.x,s.y,a,r.x,r.y,a),d=$.createStartEnd(t,o);o.dotVectorsToTargets(t,c)<0&&d.negate(d);const h=on.createOriginAndDirectionCapture(L.createFrom(t),d,et._workRay),u=n.intersect(h);if(!(u!==void 0&&u.length===2)||u[0]<=0&&u[1]<=0||u[0]>=1&&u[1]>=1)return;const m=h.fractionToPoint(f.clamp(u[0],0,1),et._workXY0),p=h.fractionToPoint(u[1],et._workXY1);return{start:m,end:p}}addVoronoiEdgeForDelaunayBoundaryEdge(e,t){const n=this.getTriangleId(e);if(n<0)return!1;const i=this._circumcenterMap.get(n);if(!i)return!0;const s=this.getTriangleEdgeBisector(e,i,t);if(!s)return!0;const r=this._idToIndexMap.get(e.edgeMate.id),a=this._idToIndexMap.get(e.id);return et.addEdgeWithFaceTags(this._voronoiGraph,s.start,s.end,r,a),!0}addVoronoiEdgeForDelaunayInteriorEdge(e,t,n){const i=this.getTriangleId(e),s=this.getTriangleId(e.edgeMate);if(i<0||s<0)return!1;const r=this._circumcenterMap.get(i),a=this._circumcenterMap.get(s);if(!r&&!a)return!0;if(!r||!a)return!r&&e.findMaskAroundFace(O.BOUNDARY_EDGE)?this.addVoronoiEdgeForDelaunayBoundaryEdge(e.edgeMate,t):!a&&e.edgeMate.findMaskAroundFace(O.BOUNDARY_EDGE)?this.addVoronoiEdgeForDelaunayBoundaryEdge(e,t):!1;if(Cs.almostEqual(r,a,n))return!0;const o=on.createOriginAndTarget(r,a,et._workRay),c=t.intersect(o);if(!(c!==void 0&&c.length===2)||c[0]<=0&&c[1]<=0||c[0]>=1&&c[1]>=1)return!0;const h=o.fractionToPoint(f.clamp(c[0],0,1),et._workXY0),u=o.fractionToPoint(f.clamp(c[1],0,1),et._workXY1),g=this._idToIndexMap.get(e.edgeMate.id),m=this._idToIndexMap.get(e.id);return et.addEdgeWithFaceTags(this._voronoiGraph,h,u,g,m),!0}populateMasksAndFaceTags(){this._voronoiGraph.announceFaceLoops((e,t)=>{let n,i=t;do n=i.faceTag,i=i.faceSuccessor;while(n===void 0&&i!==t);return n!==void 0?t.announceEdgesInFace(s=>s.faceTag=n):t.announceEdgesInFace(s=>{s.setMask(O.EXTERIOR),s.setMaskAroundEdge(O.BOUNDARY_EDGE)}),!0})}static createFromDelaunayGraph(e,t=f.smallMetricDistance,n){const i=new et(e);if(!i.isValid)return;let s=!0;const r=new Io(i._inputGraphRange,n||i._circumcenterRange);if(i._inputGraph.announceEdges((a,o)=>o.isMaskSet(O.BOUNDARY_EDGE)?(o.isMaskSet(O.EXTERIOR)&&(o=o.edgeMate),s=i.addVoronoiEdgeForDelaunayBoundaryEdge(o,r)):s=i.addVoronoiEdgeForDelaunayInteriorEdge(o,r,t)),!!s)return r.addEdgesToGraph(i._voronoiGraph),rn.splitIntersectingEdges(i._voronoiGraph,t),rn.clusterAndMergeXYTheta(i._voronoiGraph,void 0,t),i.populateMasksAndFaceTags(),i}static createColinearXYGraph(e){const t=new Ut;let n;if(Array.isArray(e)||(n=Array.from(e.values()),e=Array.from(e.keys())),e.length<2)return t;let i=this.addEdgeWithEdgeTags(t,e[0],e[1],n?n[0]:0,n?n[1]:0);for(let s=1;s<e.length-1;s++){const r=this.addEdgeWithEdgeTags(t,e[s],e[s+1],n?n[s]:0,n?n[s+1]:0);U.pinch(i.faceSuccessor,r),i=r}return t.setMask(O.EXTERIOR|O.BOUNDARY_EDGE),t}static getEdgeBisector(e,t){const n=e,i=e.faceSuccessor,s=L.createAdd2ScaledXY(n.x,n.y,.5,i.x,i.y,.5),r=$.createStartEnd(n,i);[r.x,r.y]=[-r.y,r.x];const a=on.createOriginAndDirectionCapture(s,r),o=t.intersect(a);return o!==void 0&&o.length>1&&o[0]<0&&o[1]>0?{start:a.fractionToPoint(o[0]),end:a.fractionToPoint(o[1])}:void 0}static createFromColinearGraph(e,t=f.smallMetricDistance,n){const i=new et(e,!0);if(!i.isValid)return;let s=!0;const r=new Io(i._inputGraphRange,n);if(i._inputGraph.announceEdges((a,o)=>{const c=et.getEdgeBisector(o,r);if(!c)return s=!1;const d=i._idToIndexMap.get(o.id),h=i._idToIndexMap.get(o.edgeMate.id);return this.addEdgeWithFaceTags(i._voronoiGraph,c.start,c.end,d,h),!0}),!!s)return r.addEdgesToGraph(i._voronoiGraph),rn.splitIntersectingEdges(i._voronoiGraph,t),rn.clusterAndMergeXYTheta(i._voronoiGraph,void 0,t),i.populateMasksAndFaceTags(),i}static createFromPoints(e,t=f.smallMetricDistance,n){const i=new pi(f.compareXY(t),Xn.Retain,r=>r.clone());e.forEach(r=>i.insert(r));const s=i.extractArray();if(!(s.length<2))if(In.isColinear(s,t,!0)){const r=et.createColinearXYGraph(s);return r?et.createFromColinearGraph(r,t,n):void 0}else{const r=W.createTriangulatedGraphFromPoints(s,void 0,t);return r?et.createFromDelaunayGraph(r,t,n):void 0}}static pushInteriorStrokePoints(e,t,n,i,s){const r=N.create();t.emitStrokes(r,i);let a;const o=r.numPoints();for(let h=1;h<o-1;++h)(a=r.pointAt(h,s))&&e.insert(a,n);const c=(o>2?r.pointAt(1):void 0)??t.fractionToPoint(.5),d=(o>2?r.pointAt(o-2):void 0)??c;return{p0:c,p1:d}}static computeCircleIntersection(e,t,n,i){const s=sn.intersectionProjectedXYPairs(void 0,e,!1,t,!1,i);if(s.length)return s.length>1&&(n?s.sort((r,a)=>r.detailB.fraction-a.detailB.fraction):s.sort((r,a)=>a.detailB.fraction-r.detailB.fraction)),s[0].detailB.point}static pushSymmetricPointPairAtJoint=(e,t,n,i,s)=>{const r=B.createUnitCircle(s),a=n.cp.startPoint(r.centerRef),o=.5*Math.min(t.pt.distance(a),n.pt.distance(a));r.matrixRef.setAt(0,0,o),r.matrixRef.setAt(1,1,o);const c=this.computeCircleIntersection(r,t.cp,!1,i),d=this.computeCircleIntersection(r,n.cp,!0,i);return!c||!d?!1:(e.set(c,t.i),e.set(d,n.i),!0)};static createStrokePointsWithIndices(e,t,n=f.smallMetricDistance){const i=e.children;if(!i)return;const s=i.length;if(s<2)return;t=t?.clone()??st.createForCurves(),(!t.minStrokesPerPrimitive||t.minStrokesPerPrimitive<2)&&(t.minStrokesPerPrimitive=2);const r=y.createZero(),a=B.createUnitCircle(et._workArc),o=Q.createXYXY(0,0,0,0),c=q.createZero();let d,h,u;const g=(x,_)=>x instanceof N?x.getIndexedSegment(_,o):_?void 0:x,m=new xc(f.compareXY(n),x=>x.clone()),p=e.isPhysicallyClosedCurve(n,!0);p||(e.startPoint(r)&&m.insert(r,0),e.endPoint(r)&&m.insert(r,s-1));for(let x=0;x<s;x++){let _=i[x];$n.isColinear(_,{colinearRay:c,xyColinear:!0,maxDeviation:n})&&(_=Q.createCapture(_.startPoint(),_.endPoint()));let I=0;for(let S;S=g(_,I);I++){u=this.pushInteriorStrokePoints(m,S,x,t,r);const A={pt:u.p0,cp:S,i:x};h&&this.pushSymmetricPointPairAtJoint(m,h,A,n,a),d=p&&x===0&&I===0?A:d,h={pt:u.p1,cp:S,i:x}}}return h&&d&&this.pushSymmetricPointPairAtJoint(m,h,d,n,a),m}static createGraphFromPointsWithIndices(e,t){if(e.size<2)return;let n,i=!1;const s=y.createZero(),r=Array.from(e.keys());return In.isColinear(r,t,!0)?(n=et.createColinearXYGraph(e),i=!1):(n=W.createTriangulatedGraphFromPoints(r,void 0,.1*t),(i=n!==void 0)&&n.announceVertexLoops((a,o)=>{const c=e.get(o.getPoint3d(s));return c!==void 0&&o.announceEdgesAroundVertex(d=>d.edgeTag=c),!0})),n?{graph:n,isTriangulation:i}:void 0}static createFromCurveChain(e,t,n=f.smallMetricDistance,i){const s=et.createStrokePointsWithIndices(e,t);if(!s)return;const r=et.createGraphFromPointsWithIndices(s,n);if(!r)return;const a=r.isTriangulation?et.createFromDelaunayGraph(r.graph,n,i):et.createFromColinearGraph(r.graph,n,i);return a&&(a._isCurveBased=!0),a}isEdgeInVoronoiSuperFace(e,t){if(!this._isCurveBased||e.faceTag===void 0)return!1;const n=this._inputGraph.allHalfEdges[e.faceTag].edgeTag;if(e.edgeMate.isMaskSet(O.EXTERIOR))return t===void 0?!0:t===n;if(e.edgeMate.faceTag===void 0)return!1;const i=this._inputGraph.allHalfEdges[e.edgeMate.faceTag].edgeTag;return t!==void 0?n===t&&i!==t:n!==i}findNextVoronoiSuperFaceStart(){if(!this._isCurveBased)return;let e;return this._voronoiGraph.announceEdges((t,n)=>n.isMaskSet(O.EXTERIOR)||n.isMaskSet(this._superFaceMask)||!this.isEdgeInVoronoiSuperFace(n)?!0:(e=n,!1)),e}collectVoronoiSuperFace(e){if(!this._isCurveBased||e.faceTag===void 0)return;const t=[],n=this._inputGraph.allHalfEdges[e.faceTag].edgeTag;return e.announceEdgesInSuperFace(s=>!this.isEdgeInVoronoiSuperFace(s,n),s=>{t.push(s),s.setMask(this._superFaceMask)})&&t.length>2?t:void 0}computeVoronoiSuperFaces(e){if(!this._isCurveBased||e<1)return;const t=[];this._superFaceMask===O.NULL_MASK&&(this._superFaceMask=this._voronoiGraph.grabMask(!1)),this._voronoiGraph.clearMask(this._superFaceMask);for(let n=0;n<e;n++){const i=this.findNextVoronoiSuperFaceStart();if(!i)break;const s=this.collectVoronoiSuperFace(i);if(!s)return;t.push(s)}return t.sort((n,i)=>{const s=this._inputGraph.allHalfEdges[n[0].faceTag].edgeTag,r=this._inputGraph.allHalfEdges[i[0].faceTag].edgeTag;return s-r}),t.length>0?t:void 0}generateClippersFromVoronoiSuperFaces(e){if(!this._isCurveBased||this._superFaceMask===O.NULL_MASK)return;const t=[],n=this._voronoiGraph.grabMask(),i=this._voronoiGraph.grabMask(),s=(r,a)=>r.announceEdgesInSuperFace(o=>!o.isMaskSet(this._superFaceMask),o=>o.edgeMate.applyMask(n,a));W.triangulateAllInteriorFaces(this._voronoiGraph,!1,!0),qe.expandConvexFaces(this._voronoiGraph,this._superFaceMask);for(const r of e){if(r.length<3){t.length=0;break}const a=[];if(!s(r[0],!1)){t.length=0;break}Wn.exploreComponent(r[0],i,n,void 0,a),s(r[0],!0);const o=[];for(const c of a){const d=[];c.announceEdgesInFace(h=>{if(!h.isMaskSet(O.BOUNDARY_EDGE)){const u=ee.createMidPointEdgeXY(h,h.faceSuccessor);u&&d.push(u)}}),d.length===c.countMaskAroundFace(O.BOUNDARY_EDGE,!1)&&o.push(Ce.createPlanes(d))}o.length===a.length&&t.push(xt.createConvexSets(o))}return this._voronoiGraph.dropMask(i),this._voronoiGraph.dropMask(n),t.length===e.length?t:void 0}}et||(et={});class Io{bbox;constructor(e,t){if(this.bbox=ze.createFrom(e),t&&this.bbox.union(t,this.bbox),!this.bbox.isNull&&!this.bbox.isSinglePoint){const n=.02473*(this.bbox.xLength()+this.bbox.yLength());this.bbox.expandInPlace(n)}}intersect(e){const t=e.intersectionWithRange2d(this.bbox);if(!t.isNull)return t.isSinglePoint?[t.low]:[t.low,t.high]}addEdgesToGraph(e){e.addEdgeXY(this.bbox.low.x,this.bbox.low.y,this.bbox.high.x,this.bbox.low.y),e.addEdgeXY(this.bbox.high.x,this.bbox.low.y,this.bbox.high.x,this.bbox.high.y),e.addEdgeXY(this.bbox.high.x,this.bbox.high.y,this.bbox.low.x,this.bbox.high.y),e.addEdgeXY(this.bbox.low.x,this.bbox.high.y,this.bbox.low.x,this.bbox.low.y)}}class en{static advanceIntervalDifference(e,t,n,i){const s=t.length;let r=e.low,a=e.high;for(;n<s;){const o=t[n];if(o.high<r)n++;else if(o.high<=a)o.low>r&&i.push(fe.createXX(r,o.low)),r=o.high,n++;else{o.low<a&&(a=o.low);break}}return r<a&&i.push(fe.createXX(r,a)),i}static differenceSorted(e,t){const n=e.length,i=0,s=[];for(let r=0;r<n;r++)en.advanceIntervalDifference(e[r],t,i,s);return s}static advanceIntervalIntersection(e,t,n){return t.low>e.high?!0:t.high>=e.high?(n.push(fe.createXX(t.low,e.high)),!0):(n.push(fe.createXX(t.low,t.high)),!1)}static intersectSorted(e,t){let n=0,i=0;const s=e.length,r=t.length,a=[];for(;n<s&&i<r;){const o=e[n],c=t[i];o.low<=c.low?en.advanceIntervalIntersection(o,c,a)?n++:i++:en.advanceIntervalIntersection(c,o,a)?i++:n++}return a}static advanceIntervalUnion(e,t,n){if(n>=t.length)return!1;const i=t[n];return i.low>e.high?!1:(i.high>e.high&&(e.high=i.high),!0)}static unionSorted(e,t){const n=e.length,i=t.length;let s=0,r=0;const a=[];for(;s<n&&r<i;){const o=e[s],c=t[r];let d;o.low<=c.low?(d=o.clone(),s++):(d=c.clone(),r++);let h=!0;do{const u=en.advanceIntervalUnion(d,e,s),g=en.advanceIntervalUnion(d,t,r);u&&s++,g&&r++,u||g||(h=!1)}while(h);a.push(d)}for(;s<n;)a.push(e[s++]);for(;r<i;)a.push(t[r++]);return a}static paritySorted(e,t){const n=[];for(const i of e)n.push(i.clone());for(const i of t)n.push(i.clone());return n.sort(Pa),en.simplifySortParity(n,!0),n}static sort(e){e.sort(Pa)}static simplifySortUnion(e,t=!1){if(e.length<2)return;e.sort(Pa);let n=0;for(let i=1;i<e.length;i++)e[i].low<=e[n].high?e[i].high>e[n].high&&(e[n].high=e[i].high):(n++,e[n].setFrom(e[i]));if(e.length=n+1,t){n=-1;for(let i=0;i<e.length;i++)e[i].low<e[i].high&&n<i&&e[++n].setFrom(e[i])}}static simplifySortParity(e,t=!1){const n=[];for(const o of e)o.low!==o.high&&(n.push(o.low),n.push(o.high));const i=n.length;n.sort((o,c)=>o<c?-1:o>c?1:0);let s=0,r,a;for(let o=0;o<i;o+=2)if(r=n[o],a=n[o+1],!t)fe.createXX(r,a,e[s++]);else{for(;o+2<i&&n[o+2]===a;)o+=2,a=n[o+1];a>r&&fe.createXX(r,a,e[s++])}e.length=s}static testUnion(e,t){return this.countContainingRanges(e,t)>0}static testParity(e,t){let n=!1;for(const i of e)i.containsX(t)&&(n=!n);return n}static countContainingRanges(e,t){let n=0;for(const i of e)i.containsX(t)&&n++;return n}static getBreaks(e,t,n=!1,i=!1,s=!0){t||(t=new Me(2*e.length)),s&&t.clear();for(const r of e)t.push(r.low),t.push(r.high);return n&&t.sort(),i&&t.compressAdjacentDuplicates(),t}static appendFractionalPoints(e,t,n,i,s,r,a,o){const c=e.length;if(c>0){t!==void 0&&o.push(e[0].fractionToPoint(t));for(let d=0;d<c;d++)n!==void 0&&(i||e[d].low!==e[d].high)&&o.push(e[d].fractionToPoint(n)),d>1&&s!==void 0&&(r||e[d].low!==e[d].high)&&o.push(f.interpolate(e[d-1].high,s,e[d].low));a!==void 0&&o.push(e[c-1].fractionToPoint(a))}return o}static firstLowToLastHigh(e){return e.length===0?fe.createNull():fe.createXX(e[0].low,e[e.length-1].high)}static sumLengths(e){let t=0;for(const n of e)t+=n.length();return t}static isSorted(e,t=!0){const n=e.length;if(t){for(let i=0;i+1<n;i++)if(e[i].high>=e[i+1].low)return!1}else for(let i=0;i+1<n;i++)if(e[i].high>e[i+1].low)return!1;return!0}}function Pa(l,e){return l.low<e.low?-1:l.low>e.low?1:l.high<e.high?-1:l.high>e.high?1:0}class Qn{points=[];planes=Ce.createEmpty();children=[];startIdx=-1;numPoints=-1;constructor(){}static createWithIndices(e,t,n){return n=n||new Qn,n.startIdx=e,n.numPoints=t,n.children.length=0,n}static createTreeForPolygon(e,t){return t=t||new Qn,t.empty(),ds.createPointsRef(e).buildHullTree(t),t}static createHullAndInletsForPolygon(e,t){return t=t||new Qn,t.empty(),ds.createPointsRef(e).buildHullAndInletsForPolygon(t),t}extractLoopsGo(e){e.push(lt.clonePoint3dArray(this.points));for(const t of this.children)t.extractLoopsGo(e)}extractLoops(){const e=[];return this.extractLoopsGo(e),e}empty(){this.points.length=0,this.planes.planes.length=0,this.children.length=0,this.startIdx=-1,this.numPoints=-1}clone(e){e=e||new Qn;for(const t of this.points)e.points.push(t.clone());e.planes=Ce.createEmpty();for(const t of this.planes.planes)e.planes.planes.push(t.clone());for(const t of this.children)e.children.push(t.clone());return e.startIdx=this.startIdx,e.numPoints=this.numPoints,e}addEmptyChild(e,t){const n=Qn.createWithIndices(e,t);this.children.push(n)}addPlane(e){this.planes.addPlaneToConvexSet(e)}isPointOnOrInside(e){if(!this.planes.isPointOnOrInside(e,0))return!1;for(const n of this.children)if(n.isPointOnOrInside(e))return!1;return!0}captureConvexClipPlaneSetAsVoid(e){this.children.push(e)}appendCurvePrimitiveClipIntervals(e,t,n){new ir().appendSingleClipPrimitive(this,e,t,n)}appendCurveCollectionClipIntervals(e,t,n){new ir().appendCurveCollectionClip(this,e,t,n)}appendPolygonClip(e,t,n,i){const s=n.length,r=this.planes.clipInsidePushOutside(e,n,i);if(r===void 0)at.restoreSingletonInPlaceOfMultipleShards(n,s,e,i);else{let a=[r],o=[],c,d;for(const h of this.children){for(o.length=0;(d=a.pop())!==void 0;)h.appendPolygonClip(d,n,o,i),i.dropToCache(d);c=o,o=a,a=c}for(;(d=a.pop())!==void 0;)t.push(d)}}depth(){let t=0;for(const n of this.children)t=Math.max(t,n.depth());return 1+t}}class ds{_points=[];_stack=[];constructor(){}static createPointsRef(e,t){return t=t||new ds,t._points=e,re.areaXY(e)<0&&t._points.reverse(),t._points[t._points.length-1].isAlmostEqualMetric(t._points[0])&&t._points.pop(),t}get period(){return this._points.length}indexAfter(e){return(e+1)%this._points.length}indexBefore(e){return(e+this._points.length-1)%this._points.length}pushIndex(e){this._stack.push(e)}static cross(e,t,n){return e.crossProductToPointsXY(t,n)}cyclicStackPoint(e){let t;const n=this._stack;return e>0?t=e:t=e+10*n.length,t=t%n.length,this._points[n[t]]}signFromStackTip(e,t){const n=this.cyclicStackPoint(-2),i=this.cyclicStackPoint(-1),s=this._points[e];return t*ds.cross(n,i,s)>=0?1:-1}get indexOfMaxX(){let e=0;const t=this._points,n=this._points.length;for(let i=1;i<n;i++)t[i].x>t[e].x&&(e=i);return e}extendHullChain(e,t,n){for(;this._stack.length>1&&this.signFromStackTip(e,t)<0;)this._stack.pop();n&&this.pushIndex(e)}collectHullChain(e,t,n){if(this._stack.length=0,t>2){let i=e;for(let s=0;s<t;s++)this.extendHullChain(i,n,!0),i=this.indexAfter(i)}}collectHullPointsInArray(e,t,n,i){if(e.length=0,n>2){let s=t;for(let r=0;r<n;r++)e.push(this._points[s]),s=this.indexAfter(s)}}buildHullTreeGo(e,t,n=!0){this.collectHullChain(e.startIdx,e.numPoints,t?1:-1),e.points.length=0;const i=this._stack,s=this._points,r=i.length;for(let a=0;a<r;a++){const o=i[a];if(e.points.push(s[o]),a+1<r){let c=i[a+1];if(c===this.indexAfter(o)){const d=ee.createEdgeAndUpVector(s[o],s[c],v.create(0,0,1),T.createRadians(0));d!==void 0&&(t&&d.negateInPlace(),e.addPlane(d))}else c<o&&(c+=this.period),e.addEmptyChild(o,c-o+1)}}if(n)for(const a of e.children)this.buildHullTreeGo(a,!t);else for(const a of e.children)this.collectHullPointsInArray(a.points,a.startIdx,a.numPoints,t?-1:1);return!0}buildHullAndInletsForPolygon(e){return Qn.createWithIndices(this.indexOfMaxX,this.period+1,e),this.buildHullTreeGo(e,!0,!1)}buildHullTree(e){return Qn.createWithIndices(this.indexOfMaxX,this.period+1,e),this.buildHullTreeGo(e,!0)}}class ir{_curve;_intervalStack;_stackDepth;constructor(){this._stackDepth=0,this._intervalStack=[]}setCurveRef(e){this._curve=e}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(e){const t=this._stackDepth;t>0&&(this._intervalStack[t-1]=e)}stackEntry(e){return e<=this._stackDepth?this._intervalStack[this._stackDepth-1-e]:[]}isTopOfStackEmpty(){return this._topOfStack.length===0}static _fractionIntervals=[];appendSingleClipToStack(e,t){const n=ir._fractionIntervals;if(this._curve instanceof Q){const i=this._curve;let s=0,r=0;return i.announceClipIntervals(e,(a,o,c)=>{s=a,r=o})&&t.push(fe.createXX(s,r)),!0}else if(this._curve instanceof B){const i=this._curve;n.length=0,i.announceClipIntervals(e,(s,r,a)=>{n.push(s),n.push(r)});for(let s=0;s<n.length;s+=2)t.push(fe.createXX(n[s],n[s+1]));return!0}else if(this._curve instanceof N&&this._curve.points.length>1){const i=this._curve;let s=0,r=0;const a=i.points.length,o=1/(a-1);for(let c=0;c<a-1;c++)Q.create(i.points[c],i.points[c+1]).announceClipIntervals(e,(h,u,g)=>{s=h,r=u})&&t.push(fe.createXX((c+s)*o,(c+r)*o));return!0}else if(this._curve instanceof It){const i=this._curve;n.length=0,i.announceClipIntervals(e,(s,r,a)=>{n.push(s),n.push(r)});for(let s=0;s<n.length;s+=2)t.push(fe.createXX(n[s],n[s+1]));return!0}return!1}recurse(e){if(this.pushEmptySegmentFrame(),this.appendSingleClipToStack(e.planes,this._topOfStack),en.sort(this._topOfStack),!this.isTopOfStackEmpty())for(const t of e.children){if(this.recurse(t),this.isTopOfStackEmpty())this.popSegmentFrame();else{const n=en.differenceSorted(this.stackEntry(1),this.stackEntry(0));this.popSegmentFrame(),this._topOfStack=n}if(this.isTopOfStackEmpty())break}}appendSingleClipPrimitive(e,t,n,i){if(this.setCurveRef(t),this.clearSegmentStack(),this.recurse(e),this._stackDepth!==1)return;const s=this._topOfStack;for(const r of s){const a=r.low,o=r.high,c=t.fractionToPoint(a),d=t.fractionToPoint(o);n.push(Ze.createCapture(Y.createCurveFractionPoint(t,a,c),Y.createCurveFractionPoint(t,o,d)))}this.popSegmentFrame()}appendCurveCollectionClip(e,t,n,i){for(const s of t.children)s instanceof le?this.appendSingleClipPrimitive(e,s,n,i):s instanceof _e&&this.appendCurveCollectionClip(e,s,n,i)}}var kn;(function(l){l[l.None=0]="None",l[l.XLow=1]="XLow",l[l.XHigh=2]="XHigh",l[l.YLow=4]="YLow",l[l.YHigh=8]="YHigh",l[l.ZLow=16]="ZLow",l[l.ZHigh=32]="ZHigh",l[l.XAndY=15]="XAndY",l[l.All=63]="All"})(kn||(kn={}));class Fn{_clipPlanes;_invisible;fetchClipPlanesRef(){return this.ensurePlaneSets(),this._clipPlanes}get invisible(){return this._invisible}constructor(e,t=!1){this._clipPlanes=e,this._invisible=t}static createCapture(e,t=!1){let n;return e instanceof xt&&(n=e),e instanceof Ce&&(n=xt.createConvexSets([e])),new Fn(n,t)}toJSON(){const e={};return this._clipPlanes&&(e.clips=this._clipPlanes.toJSON()),this._invisible&&(e.invisible=!0),{planes:e}}arePlanesDefined(){return this._clipPlanes!==void 0}clone(){const e=this._clipPlanes?this._clipPlanes.clone():void 0;return new Fn(e,this._invisible)}ensurePlaneSets(){}pointInside(e,t=f.smallMetricDistanceSquared){this.ensurePlaneSets();let n=!0;return this._clipPlanes&&(n=this._clipPlanes.isPointOnOrInside(e,t)),n}isPointOnOrInside(e,t=f.smallMetricDistanceSquared){this.ensurePlaneSets();let n=!0;return this._clipPlanes&&(n=this._clipPlanes.isPointOnOrInside(e,t)),n}announceClippedSegmentIntervals(e,t,n,i,s){this.ensurePlaneSets();let r=!1;return this._clipPlanes&&(r=this._clipPlanes.announceClippedSegmentIntervals(e,t,n,i,s)),r}announceClippedArcIntervals(e,t){this.ensurePlaneSets();let n=!1;return this._clipPlanes&&(n=this._clipPlanes.announceClippedArcIntervals(e,t)),n}announceClippedCurveIntervals(e,t){this.ensurePlaneSets();let n=!1;return this._clipPlanes&&(n=this._clipPlanes.announceClippedCurveIntervals(e,t)),n}multiplyPlanesByMatrix4d(e,t=!0,n=!0){if(t){const i=e.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}return this._clipPlanes&&this._clipPlanes.multiplyPlanesByMatrix4d(e),!0}transformInPlace(e){return this._clipPlanes&&this._clipPlanes.transformInPlace(e),!0}setInvisible(e){this._invisible=e}containsZClip(){const e=this.fetchClipPlanesRef();if(e!==void 0){for(const t of e.convexSets)for(const n of t.planes)if(Math.abs(n.inwardNormalRef.z)>1e-6&&Math.abs(n.distance)!==Number.MAX_VALUE)return!0}return!1}classifyPointContainment(e,t=!0){this.ensurePlaneSets();const n=this._clipPlanes;let i=ht.StronglyInside;return n&&(i=n.classifyPointContainment(e,!1)),i}static fromJSON(e){if(!e)return;const t=Rn.fromClipShapeJSON(e);return t||Fn.fromJSONClipPrimitive(e)}static fromJSONClipPrimitive(e){const t=e?.planes;if(!t)return;const n=t.clips?xt.fromJSON(t.clips):void 0,i=t.invisible!==void 0?t.invisible:!1;return new Fn(n,i)}}class Ia{pointA;pointB;normal;constructor(e,t,n,i){this.pointA=y.create(e.x,e.y,i),this.pointB=y.create(t.x,t.y,i),this.normal=n}static makeUnitPerpendicularToBisector(e,t,n){let i=t.normal.minus(e.normal);if(!(i.normalize(i)===void 0&&(i=v.createStartEnd(e.pointA,t.pointB),i.normalize(i)===void 0)))return n&&i.scale(-1,i),i}}class Rn extends Fn{_polygon;_zLow;_zHigh;_isMask;_transformFromClip;_transformToClip;constructor(e=[],t,n,i,s=!1,r=!1){super(void 0,r),this._isMask=!1,this._polygon=e,this.initSecondaryProps(s,t,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(e){e[0].isAlmostEqual(e[e.length-1])||e.push(e[0].clone()),this._polygon=e}ensurePlaneSets(){this._clipPlanes===void 0&&(this._clipPlanes=xt.createEmpty(),this.parseClipPlanes(this._clipPlanes),this._transformFromClip&&this._clipPlanes.transformInPlace(this._transformFromClip))}initSecondaryProps(e,t,n,i){this._isMask=e,this._zLow=t,this._zHigh=n,i!==void 0?(this._transformFromClip=i,this._transformToClip=i.inverse()):(this._transformFromClip=X.createIdentity(),this._transformToClip=X.createIdentity())}toJSON(){const e={points:this._polygon.map(t=>t.toJSON())};return this.invisible&&(e.invisible=!0),this._transformFromClip&&!this._transformFromClip.isIdentity&&(e.trans=this._transformFromClip.toJSON()),this.isMask&&(e.mask=!0),typeof this.zLow<"u"&&this.zLow!==-Number.MAX_VALUE&&(e.zlow=this.zLow),typeof this.zHigh<"u"&&this.zHigh!==Number.MAX_VALUE&&(e.zhigh=this.zHigh),{shape:e}}static fromClipShapeJSON(e,t){const n=e?.shape;if(!n)return;const i=n.points?n.points.map(d=>y.fromJSON(d)):[],s=n.trans?X.fromJSON(n.trans):void 0,r=typeof n.zlow=="number"?n.zlow:void 0,a=typeof n.zhigh=="number"?n.zhigh:void 0,o=typeof n.mask=="boolean"&&n.mask,c=typeof n.invisible=="boolean"&&n.invisible;return Rn.createShape(i,r,a,s,o,c,t)}static createFrom(e,t){const n=Rn.createEmpty(!1,!1,void 0,t);n._invisible=e._invisible;for(const i of e._polygon)n._polygon.push(i.clone());return n._isMask=e._isMask,n._zLow=e._zLow,n._zHigh=e._zHigh,n._transformToClip=e._transformToClip?e._transformToClip.clone():void 0,n._transformFromClip=e._transformFromClip?e._transformFromClip.clone():void 0,n}static createShape(e=[],t,n,i,s=!1,r=!1,a){if(e.length<3)return;const o=e.slice(0);return o[0].isAlmostEqual(o[o.length-1])?o[0].clone(o[o.length-1]):o.push(o[0].clone()),a?(a._clipPlanes=void 0,a._invisible=r,a._polygon=o,a.initSecondaryProps(s,t,n,i),a):new Rn(o,t,n,i,s,r)}static createBlock(e,t,n=!1,i=!1,s,r){const a=e.low,o=e.high,c=[];for(let h=0;h<5;h++)c.push(y.create());return c[0].x=c[3].x=c[4].x=a.x,c[1].x=c[2].x=o.x,c[0].y=c[1].y=c[4].y=a.y,c[2].y=c[3].y=o.y,Rn.createShape(c,kn.None!==(t&kn.ZLow)?a.z:void 0,kn.None!==(t&kn.ZHigh)?o.z:void 0,s,n,i,r)}static createEmpty(e=!1,t=!1,n,i){return i?(i._clipPlanes=void 0,i._invisible=t,i._polygon.length=0,i.initSecondaryProps(e,void 0,void 0,n),i):new Rn([],void 0,void 0,n,e,t)}get isValidPolygon(){return!(this._polygon.length<3||!this._polygon[0].isExactEqual(this._polygon[this._polygon.length-1]))}clone(e){return Rn.createFrom(this,e)}parseClipPlanes(e){const t=this._polygon;if(t.length===3&&!this._isMask&&t[0].isExactEqual(t[t.length-1]))return this.parseLinearPlanes(e,this._polygon[0],this._polygon[1]),!0;if(!this.isMask){const n=re.testXYPolygonTurningDirections(this.polygon);if(n!==0)return this.parseConvexPolygonPlanes(e,this._polygon,n,!1),!0}return this.parsePolygonPlanes(e,this._polygon,this.isMask),!0}parseLinearPlanes(e,t,n,i){const s=$.createStartEnd(t,n);if(!s.normalize(s))return!1;i===0&&(i=void 0);const r=Ce.createEmpty();if(i===void 0){const a=$.create(-s.y,s.x);r.addPlaneToConvexSet(ee.createNormalAndPoint(v.create(s.x,s.y),t,this._invisible)),r.addPlaneToConvexSet(ee.createNormalAndPoint(v.create(-s.x,-s.y),n,this._invisible)),r.addPlaneToConvexSet(ee.createNormalAndPoint(v.create(a.x,a.y),t,this._invisible)),r.addPlaneToConvexSet(ee.createNormalAndPoint(v.create(-a.x,-a.y),t,this._invisible))}else{const a=v.create(t.x,t.y,-i),o=v.create(n.x,n.y,-i),c=v.createZero(),d=v.createZero();o.crossProduct(a,c).normalize(c),a.crossProduct(c,d).normalize(d),r.addPlaneToConvexSet(ee.createNormalAndDistance(c,0,this._invisible)),r.addPlaneToConvexSet(ee.createNormalAndDistance(d,0,this._invisible)),c.negate(c),o.crossProduct(c,d).normalize(d),r.addPlaneToConvexSet(ee.createNormalAndDistance(c,0,this._invisible)),r.addPlaneToConvexSet(ee.createNormalAndDistance(d,0,this._invisible))}return r.addZClipPlanes(this._invisible,this._zLow,this._zHigh),e.addConvexSet(r),!0}parseConvexPolygonPlanes(e,t,n,i,s){const r=[],a=n<0;s===0&&(s=void 0);const o=s===void 0?0:-s;for(let c=0;c<t.length-1;c++){const d=$.createStartEnd(t[c],t[c+1]);if(d.normalize(d)){const h=v.create(a?d.y:-d.y,a?-d.x:d.x);r.push(new Ia(t[c],t[c+1],h,o))}}if(r.length<3)return!1;if(i){const c=r.length-1;for(let d=0;d<=c;d++){const h=r[d],u=r[d?d-1:c],g=r[d===c?0:d+1],m=Ce.createEmpty(),p=Ia.makeUnitPerpendicularToBisector(u,h,!a),x=Ia.makeUnitPerpendicularToBisector(h,g,a);p&&m.addPlaneToConvexSet(ee.createNormalAndPoint(p,h.pointA,this._invisible,!0)),m.addPlaneToConvexSet(ee.createNormalAndPoint(h.normal,h.pointB,this._invisible,!1)),x&&m.addPlaneToConvexSet(ee.createNormalAndPoint(x,g.pointA,this._invisible,!0)),e.addConvexSet(m)}e.addOutsideZClipSets(this._invisible,this._zLow,this._zHigh)}else{const c=Ce.createEmpty();if(s===void 0)for(const d of r)c.addPlaneToConvexSet(ee.createNormalAndPoint(d.normal,d.pointA));else{const d=v.createZero();if(a)for(const h of r)v.createFrom(h.pointA).crossProduct(v.createFrom(h.pointB),d).normalize(d),c.addPlaneToConvexSet(ee.createNormalAndDistance(d,0));else for(const h of r)v.createFrom(h.pointB).crossProduct(v.createFrom(h.pointA),d).normalize(d),c.addPlaneToConvexSet(ee.createNormalAndDistance(d,0))}c.addZClipPlanes(this._invisible,this._zLow,this._zHigh),e.addConvexSet(c)}return!0}parsePolygonPlanes(e,t,n,i){const s=In.compressDanglers(t,!0),r=(a,o)=>{if(!o.isMaskSet(O.EXTERIOR)){const c=o.collectAroundFace(h=>{if(!h.isMaskSet(O.EXTERIOR))return y.create(h.x,h.y,0)});c.push(c[0].clone());const d=re.testXYPolygonTurningDirections(c);this.parseConvexPolygonPlanes(e,c,d,!1,i)}return!0};if(n){const a=lt.clonePoint3dArray(s),c=Qn.createHullAndInletsForPolygon(a).extractLoops();if(c.length===0)return!1;const d=c[0],h=re.testXYPolygonTurningDirections(d);this.parseConvexPolygonPlanes(e,d,-h,!0,i);for(let u=1;u<c.length;u++){const g=W.createTriangulatedGraphFromSingleLoop(c[u]);g&&(W.flipTriangles(g),g.announceFaceLoops(r))}return!0}else{const a=W.createTriangulatedGraphFromSingleLoop(s);if(a===void 0)return!1;W.flipTriangles(a),a.announceFaceLoops(r)}return!0}multiplyPlanesByMatrix4d(e,t=!0,n=!0){return this.ensurePlaneSets(),super.multiplyPlanesByMatrix4d(e,t,n)}transformInPlace(e){return e.isIdentity||(super.transformInPlace(e),this._transformFromClip?e.multiplyTransformTransform(this._transformFromClip,this._transformFromClip):this._transformFromClip=e.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(e){this._transformToClip!==void 0&&this._transformToClip.multiplyPoint3d(e,e)}performTransformFromClip(e){this._transformFromClip!==void 0&&this._transformFromClip.multiplyPoint3d(e,e)}classifyPointContainment(e,t){this.ensurePlaneSets();const n=this._clipPlanes;let i=ht.StronglyInside;if(n&&(i=n.classifyPointContainment(e,!1)),this._isMask&&!t)switch(i){case ht.StronglyInside:return ht.StronglyOutside;case ht.StronglyOutside:return ht.StronglyInside;case ht.Ambiguous:return ht.Ambiguous}return i}}class Hc{_clippers;_intervalsA;_intervalsB;_keepInside;constructor(e){this._keepInside=e,this._clippers=[],this._intervalsA=[],this._intervalsB=[]}toJSON(){const e=[];for(const i of this._clippers){const s=i;s.toJSON&&e.push(s.toJSON())}const t=this.operationName,n={};return n[t]=e,n}captureChild(e){if(Array.isArray(e))for(const t of e)this.captureChild(t);else this._clippers.push(e)}toggleResult(){return this.selectResult(!this._keepInside)}selectResult(e){const t=this._keepInside;return this._keepInside=e,t}testedAnnounceNN(e,t,n){return e<t?(n&&n(e,t),1):0}testedAnnounceNNC(e,t,n,i){return e<t?(i&&i(e,t,n),1):0}swapAB(){const e=this._intervalsA;this._intervalsA=this._intervalsB,this._intervalsB=e}announcePartsNN(e,t,n,i,s){let r=0;if(e)for(const a of t)r+=this.testedAnnounceNN(a.low,a.high,s);else{let a=n;for(const o of t)r+=this.testedAnnounceNN(a,o.low,s),a=o.high;r+=this.testedAnnounceNN(a,i,s)}return r>0}announcePartsNNC(e,t,n,i,s,r){let a=0;if(e)for(const o of t)a+=this.testedAnnounceNNC(o.low,o.high,s,r);else{let o=n;for(const c of t)a+=this.testedAnnounceNNC(o,c.low,s,r),o=c.high;a+=this.testedAnnounceNNC(o,i,s,r)}return a>0}isPointOnOrInside(e){const t=this.isPointOnOrInsideChildren(e);return this._keepInside?t:!t}announceClippedSegmentIntervals(e,t,n,i,s){this._intervalsA.length=0;const r=(o,c)=>{this._intervalsB.push(fe.createXX(o,c))};let a=0;for(const o of this._clippers)this._intervalsB.length=0,o.announceClippedSegmentIntervals(e,t,n,i,r),en.simplifySortUnion(this._intervalsB),a===0?this.swapAB():this._intervalsA=this.combineIntervals(this._intervalsA,this._intervalsB),a++;return this.announcePartsNN(this._keepInside,this._intervalsA,e,t,s)}announceClippedArcIntervals(e,t){this._intervalsA.length=0;const n=(s,r)=>{this._intervalsB.push(fe.createXX(s,r))};let i=0;for(const s of this._clippers)this._intervalsB.length=0,s.announceClippedArcIntervals(e,n),en.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,e,t)}announceClippedCurveIntervals(e,t){this._intervalsA.length=0;const n=(s,r,a)=>{this._intervalsB.push(fe.createXX(s,r))};let i=0;for(const s of this._clippers)this._intervalsB.length=0,s.announceClippedCurveIntervals?.(e,n)??void 0,en.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,e,t)}}class Kc extends Hc{get operationName(){return this._keepInside?"AND":"NAND"}constructor(e){super(e)}isPointOnOrInsideChildren(e){for(const t of this._clippers)if(!t.isPointOnOrInside(e))return!1;return!0}combineIntervals(e,t){return en.intersectSorted(e,t)}appendPolygonClip(e,t,n,i){at.doPolygonClipSequence(e,this._clippers,this._keepInside?t:n,this._keepInside?n:t,void 0,cn.passToNextStep,cn.acceptOut,cn.acceptIn,i)}}class yn{_clips;boundingRange=ie.createNull();get clips(){return this._clips}constructor(e){this._clips=e||[]}get isValid(){return this._clips.length>0}static createEmpty(e){return e?(e._clips.length=0,e):new yn}static createCapture(e,t){return t?(t._clips=e,t):new yn(e)}static create(e,t){const n=[];for(const i of e)n.push(i.clone());return yn.createCapture(n,t)}clone(e){const t=e||new yn;t._clips.length=0;for(const n of this._clips)t._clips.push(n.clone());return t.boundingRange.setFrom(this.boundingRange),t}toJSON(){return this.isValid?this.clips.map(e=>e.toJSON()):[]}static fromJSON(e,t){if(t=t||new yn,t.clear(),!Array.isArray(e))return t;try{for(const n of e){const i=Fn.fromJSON(n);i&&t._clips.push(i)}}catch{t.clear()}return t}clear(){this._clips.length=0}appendClone(e){this._clips.push(e.clone())}appendReference(e){this._clips.push(e)}appendShape(e,t,n,i,s=!1,r=!1){const a=Rn.createShape(e,t,n,i,s,r);return a?(this._clips.push(a),!0):!1}pointInside(e,t=f.smallMetricDistanceSquared){return this.isPointOnOrInside(e,t)}isPointOnOrInside(e,t=f.smallMetricDistanceSquared){if(!this.boundingRange.isNull&&!this.boundingRange.containsPoint(e))return!1;for(const n of this._clips)if(!n.pointInside(e,t))return!1;return!0}_clipNodeProxy;ensureProxyClipNode(){if(this._clipNodeProxy)return!0;this._clipNodeProxy=new Kc(!0);let e=0;for(const t of this._clips){const n=t.fetchClipPlanesRef();n&&(e++,this._clipNodeProxy.captureChild(n))}return e>0}announceClippedSegmentIntervals(e,t,n,i,s){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedSegmentIntervals(e,t,n,i,s):!1}announceClippedArcIntervals(e,t){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedArcIntervals(e,t):!1}announceClippedCurveIntervals(e,t){return this.ensureProxyClipNode(),this._clipNodeProxy?this._clipNodeProxy.announceClippedCurveIntervals(e,t):!1}appendPolygonClip(e,t,n,i){this.ensureProxyClipNode(),this._clipNodeProxy&&this._clipNodeProxy.appendPolygonClip(e,t,n,i)}transformInPlace(e){for(const t of this._clips)if(t.transformInPlace(e)===!1)return!1;return this.boundingRange.isNull||e.multiplyRange(this.boundingRange,this.boundingRange),!0}extractBoundaryLoops(e,t){let n=kn.None,i=-Number.MAX_VALUE,s=Number.MAX_VALUE;const r=[];let a=0;if(this._clips.length===0)return r;let o;const c=X.createIdentity(),d=X.createIdentity(),h=X.createIdentity();for(const u of this._clips)if(u instanceof Rn&&(o!==void 0&&u!==o&&(c.setIdentity(),d.setIdentity(),o.hasTransformToClip()&&u.hasTransformFromClip()&&(u.transformFromClip.clone(c),o.transformToClip.clone(d)),h.setFrom(d.multiplyTransformTransform(c))),o||(o=u),e[a]=[],u.polygon!==void 0)){n=kn.XAndY,u.hasZHigh()&&(n=n|kn.ZHigh,s=u.zHigh),u.hasZLow()&&(n=n|kn.ZLow,i=u.zLow);for(const g of u.polygon)e[a].push(g.clone());h.multiplyPoint3dArray(e[a],e[a]),a++}return r.push(n),r.push(i),r.push(s),t&&o&&o.hasTransformFromClip()&&t.setFrom(o.transformFromClip),r}setInvisible(e){for(const t of this._clips)t.setInvisible(e)}parseClipPlanes(){for(const e of this._clips)e.fetchClipPlanesRef()}multiplyPlanesByMatrix4d(e,t=!0,n=!0){if(t){const i=e.createInverse();return i?this.multiplyPlanesByMatrix4d(i,!1,n):!1}for(const i of this._clips)i.multiplyPlanesByMatrix4d(e,!1,n);return!0}classifyPointContainment(e,t=!1){let n=ht.Ambiguous;for(const i of this._clips){const s=i.classifyPointContainment(e,t);if(ht.Ambiguous===s)return ht.Ambiguous;if(ht.Ambiguous===n)n=s;else if(n!==s)return ht.Ambiguous}return n}classifyRangeContainment(e,t){const n=e.corners();return this.classifyPointContainment(n,t)}isAnyLineStringPointInside(e){for(const t of this._clips){const n=t.fetchClipPlanesRef();if(n!==void 0)for(let i=0;i+1<e.length;i++){const s=Q.create(e[i],e[i+1]);if(n.isAnyPointInOrOnFromSegment(s))return!0}}return!1}sumSizes(e,t,n){let i=0;for(let s=t;s<n;s++)i+=e[s].x1-e[s].x0;return i}static _TARGET_FRACTION_SUM=.99999999;isLineStringCompletelyContained(e){const t=[];for(let n=0;n+1<e.length;n++){const i=Q.create(e[n],e[n+1]);let s=0,r=0;for(const a of this._clips){const o=a.fetchClipPlanesRef();if(o!==void 0){o.appendIntervalsFromSegment(i,t);const c=t.length;if(s+=this.sumSizes(t,r,c),r=c,s>=yn._TARGET_FRACTION_SUM)break}}if(s<yn._TARGET_FRACTION_SUM)return!1}return!0}toCompactString(){function e(o){return`${o.toString()}_`}function t(o){return`${e(o.x)}${e(o.y)}${e(o.z)}`}function n(o){const c=o.toString();return c.length,c}function i(o){let c=o.invisible?1:0;return c|=o.interior?2:0,`${n(c)}${t(o.inwardNormalRef)}${e(o.distance)}`}function s(o){let c="";for(const d of o.planes)c=`${c}${i(d)}`;return`${c}_`}function r(o){let d=(o.invisible?1:0).toString();d.length;const h=o.fetchClipPlanesRef();if(h)for(const u of h.convexSets)d=`${d}${s(u)}`;return`${d}_`}let a="";for(const o of this.clips)a=`${a}${r(o)}`;return`${a}_`}}var vo;(function(l){function e(t){if(!t||!t.isValid)return;const n=t;n.clipString===void 0&&(n.clipString=t.toCompactString());const i=n;return i.clipString,i}l.fromClipVector=e})(vo||(vo={}));class Mn{_positiveOffsetLeft;_positiveOffsetRight;_turnDegrees;constructor(e,t){this._positiveOffsetLeft=e,this._positiveOffsetRight=t,this._turnDegrees=60}static createUnit(e,t,n,i=!0){let s=t,r=t+1;const a=e.length-1;n?t<0?(s=a-1,r=a):t>=a&&(s=0,r=1):t===0?(s=0,r=1):r>a&&(s=a-1,r=a);const o=e.vectorIndexIndex(s,r);if(o)return i&&(o.z=0),o.normalize(o)}static createDirectedPlane(e,t,n,i,s=!1){return ee.createNormalAndPointXYZXYZ(t.x*i,t.y*i,t.z*i,e.x+n*t.x,e.y+n*t.y,e.z+n*t.z,s,s)}createChamferCut(e,t,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?e.addPlaneToConvexSet(Mn.createDirectedPlane(t,r,-this._positiveOffsetRight,1,!1)):e.addPlaneToConvexSet(Mn.createDirectedPlane(t,r,this._positiveOffsetLeft,-1,!1))}}createOffsetFromSegment(e,t,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 a=i.rotate90CCWXY(),o=i.interpolate(.5,s);o.normalizeInPlace();const c=Ce.createEmpty();return c.addPlaneToConvexSet(Mn.createDirectedPlane(e,a,this._positiveOffsetLeft,-1,!1)),c.addPlaneToConvexSet(Mn.createDirectedPlane(e,a,-this._positiveOffsetRight,1,!1)),c.addPlaneToConvexSet(Mn.createDirectedPlane(e,r,0,1,!0)),c.addPlaneToConvexSet(Mn.createDirectedPlane(t,o,0,-1,!0)),this.createChamferCut(c,e,n,i),this.createChamferCut(c,t,i,s),c}static createClipBetweenOffsets(e,t,n,i,s){const r=new Mn(t,n),a=xt.createEmpty();if(e.length>1){const o=e.almostEqualUncheckedIndexIndex(0,e.length-1);for(let c=0;c+1<e.length;c++){const d=this.createUnit(e,c-1,o),h=this.createUnit(e,c,o),u=this.createUnit(e,c+1,o),g=r.createOffsetFromSegment(e.getPoint3dAtUncheckedPointIndex(c),e.getPoint3dAtUncheckedPointIndex(c+1),d,h,u);g?.addZClipPlanes(!1,i,s),g&&a.addConvexSet(g)}}else{const o=Ce.createEmpty();o.addZClipPlanes(!1,i,s),o.planes.length>0&&a.addConvexSet(o)}return a}}var ht;(function(l){l[l.StronglyInside=1]="StronglyInside",l[l.Ambiguous=2]="Ambiguous",l[l.StronglyOutside=3]="StronglyOutside"})(ht||(ht={}));var cn;(function(l){l[l.acceptIn=1]="acceptIn",l[l.acceptOut=-1]="acceptOut",l[l.passToNextStep=0]="passToNextStep"})(cn||(cn={}));var Vi;(function(l){l[l.ClipRequired=0]="ClipRequired",l[l.TrivialReject=1]="TrivialReject",l[l.TrivialAccept=2]="TrivialAccept"})(Vi||(Vi={}));class at{static _workTransform;static _workRange;static _workClipper;static _selectIntervals01TestPoint=y.create();static selectIntervals01(e,t,n,i){t.push(0),t.push(1),t.sort();let s=t.atUncheckedIndex(0),r,a;const o=at._selectIntervals01TestPoint,c=t.length;for(let d=1;d<c;d++)if(r=t.atUncheckedIndex(d),r>s+f.smallFraction){if(a=.5*(s+r),a>=0&&a<=1&&(e.fractionToPoint(a,o),n.isPointOnOrInside(o)))if(i)i(s,r,e);else return!0;s=r}return!1}static announceNNC(e,t,n){if(n)for(const i of e)n(i.low,i.high,t);return e.length>0}static collectClippedCurves(e,t){const n=[];return e.announceClipIntervals(t,(i,s,r)=>{if(i!==s){const a=r.clonePartialCurve(i,s);a&&n.push(a)}}),n}static clipAnyRegion(e,t){let n;const i=at._workTransform=tt.createRightHandedFrame(void 0,e,at._workTransform);if(!i)return n;const s=i?.inverse();if(!s)return n;const r=e.cloneTransformed(s),a=at._workRange=r.range(),o=a.xLength(),c=a.yLength(),d=N.createRectangleXY(a.low,o,c,!0);d.tryTransformInPlace(i);const h=[],u=[],g=new aa;if(t.appendPolygonClip?.(d.packedPoints,h,u,g),h.length===0)return n;for(const m of h){const p=oe.createPolygon(m);p.tryTransformInPlace(s);const x=ge.regionBooleanXY(r,p,tn.Intersection);x&&(x.tryTransformInPlace(i),n||(n=x instanceof Et?x:Et.create(x)),x instanceof Et?n.children.push(...x.children):n.tryAddChild(x))}return n?ge.simplifyRegion(n):void 0}static clipAnyCurve(e,t){if(e instanceof le)return at.collectClippedCurves(e,t);if(e.isAnyRegion()){const i=at.clipAnyRegion(e,t);return i?[i]:[]}const n=[];if(e instanceof Te||e instanceof zt)for(const i of e.children){const s=at.clipAnyCurve(i,t);n.push(...s)}return n}static clipPolygonToClipShape(e,t){const n=this.clipPolygonToClipShapeReturnGrowableXYZArrays(e,t),i=[];for(const s of n)i.push(s.getPoint3dArray());return i}static clipPolygonToClipShapeReturnGrowableXYZArrays(e,t){const n=[],i=t.fetchClipPlanesRef();return i&&i.polygonClip(e,n),n}static pointSetSingleClipStatus(e,t,n){if(t.convexSets.length===0)return Vi.TrivialAccept;for(const i of t.convexSets){let s=!1,r=!1;for(const a of i.planes){let o=0,c=0;const d=a.distance-n,h=y.create(),u=v.create();for(let g=0;g<e.length;g++)e.getPoint3dAtUncheckedPointIndex(g,h),u.setFrom(h),u.dotProduct(a.inwardNormalRef)>d?o++:c++;if(r=c!==0?!0:r,o===0){s=!0;break}}if(!r)return Vi.TrivialAccept;if(!s)return Vi.ClipRequired}return Vi.TrivialReject}static announceLoopsOfConvexClipPlaneSetIntersectRange(e,t,n,i=!0,s=!0,r=!1){const a=new J;if(i){if(e instanceof Ce)for(const o of e.planes){if(r&&o.invisible)continue;const c=o.intersectRange(t,!0);if(c){const d=new J;e.polygonClip(c,d,a,o),d.length>0&&n(d)}}else if(!(r&&e.invisible)){const o=e.intersectRange(t,!0);o&&n(o)}}if(s){const o=t.corners();for(let c=0;c<6;c++){const d=ie.faceCornerIndices(c),h=new J,u=N.createIndexedPoints(o,d);e instanceof Ce?(e.polygonClip(u.packedPoints,h,a),h.length>0&&n(h)):(e.clipConvexPolygonInPlace(u.packedPoints,a),u.packedPoints.length>0&&n(u.packedPoints))}}}static loopsOfConvexClipPlaneIntersectionWithRange(e,t,n=!0,i=!0,s=!1){const r=[];if(e instanceof xt)for(const a of e.convexSets)this.announceLoopsOfConvexClipPlaneSetIntersectRange(a,t,o=>{o.length>0&&r.push(oe.createPolygon(o))},n,i,s);else(e instanceof Ce||e instanceof ee)&&this.announceLoopsOfConvexClipPlaneSetIntersectRange(e,t,a=>{a.length>0&&r.push(oe.createPolygon(a))},n,i,s);return r}static rangeOfConvexClipPlaneSetIntersectionWithRange(e,t){const n=ie.createNull();return this.announceLoopsOfConvexClipPlaneSetIntersectRange(e,t,i=>{i.length>0&&n.extendArray(i)},!0,!0,!1),n}static rangeOfClipperIntersectionWithRange(e,t,n=!0){if(e===void 0)return t.clone();if(e instanceof Ce)return this.rangeOfConvexClipPlaneSetIntersectionWithRange(e,t);if(e instanceof xt){const i=ie.createNull();for(const s of e.convexSets){const r=this.rangeOfConvexClipPlaneSetIntersectionWithRange(s,t);i.extendRange(r)}return i}if(e instanceof Fn)return n&&e.invisible?t.clone():this.rangeOfClipperIntersectionWithRange(e.fetchClipPlanesRef(),t);if(e instanceof yn){const i=t.clone();for(const s of e.clips)if(!(n&&s.invisible)){const r=this.rangeOfClipperIntersectionWithRange(s,t,n);i.intersect(r,i)}return i}return t.clone()}static doesClipperIntersectRange(e,t,n=!0){if(e===void 0)return!0;if(e instanceof Ce)return this.doesConvexClipPlaneSetIntersectRange(e,t);if(e instanceof xt){for(const i of e.convexSets)if(this.doesConvexClipPlaneSetIntersectRange(i,t))return!0;return!1}if(e instanceof Fn)return n&&e.invisible?!0:this.doesClipperIntersectRange(e.fetchClipPlanesRef(),t);if(e instanceof yn){const i=t.clone();for(const s of e.clips)if(!(n&&s.invisible)){const r=this.rangeOfClipperIntersectionWithRange(s,t,n);i.intersect(r,i)}return!i.isNull}return!1}static doesConvexClipPlaneSetIntersectRange(e,t,n=!0,i=!0,s=!1){const r=new J;if(n)for(const a of e.planes){if(s&&a.invisible)continue;const o=a.intersectRange(t,!0);if(o){const c=new J;if(e.polygonClip(o,c,r,a),c.length>0)return!0}}if(i){const a=t.corners();for(let o=0;o<6;o++){const c=ie.faceCornerIndices(o),d=new J,h=N.createIndexedPoints(a,c);if(e.polygonClip(h.packedPoints,d,r),d.length>0)return!0}}return!1}static createClipperFromTransformedRange3d(e,t,n){t||(t=X.createIdentity());const i=ce.create();i.addTransformedRangeMesh(t,e);const s=i.claimPolyface(),r=this._workClipper=Ce.createConvexPolyface(s,this._workClipper).clipper;if(r.planes.length>0)return r;if(n){s.data.point.length<=2;for(let a=0;a<2;++a){const o=s.data.point.getPoint3dAtCheckedPointIndex(a);o&&n.push(o)}}}static rangeIntersectPointOrSegment(e,t,n,i){const s=i?(a,o,c)=>{i.extendPoint(c.fractionToPoint(a),n),i.extendPoint(c.fractionToPoint(o),n)}:void 0;let r=!1;if(t.length>1){const a=Q.createCapture(t[0],t[1]),o=Ce.createRange3dPlanes(e);r=a.announceClipIntervals(o,s)}else t.length>0&&(r=e.containsPoint(t[0]),r&&i&&i.extendPoint(t[0],n));return r}static doLocalRangesIntersect(e,t,n,i,s){const r=this._workTransform=i.inverse(this._workTransform);if(!r)return!1;let a=n;s&&(a=this._workRange=n.clone(this._workRange),a.expandInPlace(s));const o=[],c=r.multiplyTransformTransform(t,r),d=this.createClipperFromTransformedRange3d(e,c,o);return d?this.doesClipperIntersectRange(d,a):this.rangeIntersectPointOrSegment(a,o,i)}static rangeOfIntersectionOfLocalRanges(e,t,n,i,s){const r=ie.createNull(s),a=this._workTransform=i.inverse(this._workTransform);if(!a)return r;const o=[],c=a.multiplyTransformTransform(t,a),d=this.createClipperFromTransformedRange3d(e,c,o);return d?this.announceLoopsOfConvexClipPlaneSetIntersectRange(d,n,h=>{h.extendRange(r,i)}):this.rangeIntersectPointOrSegment(n,o,i,r),r}static isClipper(e){return!!(e&&e.isPointOnOrInside&&e.announceClippedSegmentIntervals&&e.announceClippedArcIntervals)}static restoreSingletonInPlaceOfMultipleShards(e,t,n,i){if(e&&e.length>t+1){for(;e.length>t;){const s=e.pop();i.dropToCache(s)}e.push(i.grabAndFill(n))}}static createXYOffsetClipFromLineString(e,t,n,i,s){return Array.isArray(e)?Mn.createClipBetweenOffsets(new Qe(e),t,n,i,s):Mn.createClipBetweenOffsets(e,t,n,i,s)}static captureOrDrop(e,t,n,i){e.length>=t?n.push(e):i.dropToCache(e)}static clipSegmentToLLeftOfLineXY(e,t,n,i,s,r=1e-14){const a=t.x-e.x,o=t.y-e.y,c=-(a*(n.y-e.y)-o*(n.x-e.x)),d=-(a*(i.y-e.y)-o*(i.x-e.x));if(!(c<r&&d<r))if(c*d>0)c>0&&s.setNull();else if(c*d<0){const h=-c/(d-c);return c<0?s.intersectRangeXXInPlace(0,h):s.intersectRangeXXInPlace(h,1)}else c>0?s.intersectRangeXXInPlace(1,1):d>0&&s.intersectRangeXXInPlace(0,0)}static clipSegmentToCCWTriangleXY(e,t,n,i,s,r,a=1e-14){r.isNull||(this.clipSegmentToLLeftOfLineXY(e,t,i,s,r,a),r.isNull||(this.clipSegmentToLLeftOfLineXY(t,n,i,s,r,a),r.isNull||this.clipSegmentToLLeftOfLineXY(n,e,i,s,r,a)))}static clipSegmentBelowPlaneXY(e,t,n,i,s=1e-14){const r=e.altitudeXY(t.x,t.y),a=e.altitudeXY(n.x,n.y);if(!(r<s&&a<s))if(r*a>0)r>0&&i.setNull();else if(r*a<0){const o=-r/(a-r);return r<0?i.intersectRangeXXInPlace(0,o):i.intersectRangeXXInPlace(o,1)}else r>0?i.intersectRangeXXInPlace(1,1):a>0&&i.intersectRangeXXInPlace(0,0)}static clipSegmentBelowPlanesXY(e,t,n,i,s=1e-14){const r=e.length;for(let a=0;!i.isNull&&a<r;a++)this.clipSegmentBelowPlaneXY(e[a],t,n,i,s)}static announcePolylineClip(e,t,n){for(let i=0;i+1<t.length;i++)e.announceClippedSegmentIntervals(0,1,t[i],t[i+1],(s,r)=>{n(t[i].interpolate(s,t[i+1]),t[i].interpolate(r,t[i+1]))})}static sumPolylineClipLength(e,t){let n=0;for(let i=0;i+1<t.length;i++){const s=t[i].distance(t[i+1]);e.announceClippedSegmentIntervals(0,1,t[i],t[i+1],(r,a)=>{n+=Math.abs(a-r)*s})}return n}static doPolygonClipSequence(e,t,n,i,s,r,a,o,c){c===void 0&&(c=new aa);let d=[c.grabAndFill(e)],h=[];const u=[],g=[],m=n?n.length:0,p=i?i.length:0;let x;for(const _ of t)if(_.appendPolygonClip){for(;(x=d.pop())!==void 0;)_.appendPolygonClip(x,u,g,c),Ii(r,u,n,i,h,c),Ii(a,g,n,i,h,c),c.dropToCache(x);const I=d;d=h,h=I}Ii(o,d,n,i,s,c),i?.length===p&&at.restoreSingletonInPlaceOfMultipleShards(n,m,e,c),n?.length===m&&at.restoreSingletonInPlaceOfMultipleShards(i,p,e,c)}static doPolygonClipParitySequence(e,t,n,i,s){s===void 0&&(s=new aa);let r=[s.grabAndFill(e)],a=[],o=[],c=[];const d=[],h=[];let u;for(const g of t)if(g.appendPolygonClip){for(;(u=a.pop())!==void 0;)g.appendPolygonClip(u,d,h,s),Ii(cn.acceptOut,d,o,c,void 0,s),Ii(cn.acceptIn,h,o,c,void 0,s),s.dropToCache(u);for(;(u=r.pop())!==void 0;)g.appendPolygonClip(u,d,h,s),Ii(cn.acceptIn,d,o,c,void 0,s),Ii(cn.acceptOut,h,o,c,void 0,s),s.dropToCache(u);const m=a;a=o,o=m;const p=r;r=c,c=p}r.length===0?n?.push(s.grabAndFill(e)):r.length===0?i?.push(s.grabAndFill(e)):(So(a,n,s),So(r,i,s))}static createComplementaryClips(e){const t=e.planes,n=fe.createNull(),i=t.length,s=[];for(const r of t){const a=Ce.createEmpty();a.addPlaneToConvexSet(r.cloneNegated()),s.push(a)}for(let r=0;r<i;r++)for(let a=r+1;a<i;a++){const o=dn.planePlaneIntersectionRay(t[r],t[a]);if(o&&e.hasIntersectionWithRay(o,n)){const c=t[a].inwardNormalRef.minus(t[r].inwardNormalRef),d=ee.createNormalAndPoint(c,o.origin);if(d){const h=d.cloneNegated();s[r].addPlaneToConvexSet(d),s[a].addPlaneToConvexSet(h)}}}return xt.createConvexSets(s)}static createClippersForRegionsClosestToCurvePrimitivesXY(e,t,n=f.smallMetricDistance,i){const s=et.createFromCurveChain(e,t,n,i);if(!s)return;const r=s.computeVoronoiSuperFaces(e.children.length);if(!(r===void 0||r.length!==e.children.length))return s.generateClippersFromVoronoiSuperFaces(r)}}function So(l,e,t){if(e===void 0)t.dropAllToCache(l);else for(const n of l)e.push(n);l.length=0}function Ii(l,e,t,n,i,s){let r;if(l===cn.acceptIn?r=t:l===cn.acceptOut?r=n:l===cn.passToNextStep&&(r=i),r===void 0)s.dropAllToCache(e);else for(const a of e)r.push(a);e.length=0}class ee extends ks{_inwardNormal;_distanceFromOrigin;_invisible;_interior;constructor(e,t,n,i){super(),this._invisible=n,this._interior=i,this._inwardNormal=e,this._distanceFromOrigin=t}isAlmostEqual(e){return f.isSameCoordinate(this._distanceFromOrigin,e._distanceFromOrigin)&&this._inwardNormal.isAlmostEqual(e._inwardNormal)&&this._interior===e._interior&&this._invisible===e._invisible}clone(){return new ee(this._inwardNormal.clone(),this._distanceFromOrigin,this._invisible,this._interior)}cloneNegated(){const e=new ee(this._inwardNormal.clone(),this._distanceFromOrigin,this._invisible,this._interior);return e.negateInPlace(),e}static createPlane(e,t=!1,n=!1,i){const s=e.getNormalRef().dotProduct(e.getOriginRef());return i?(i._invisible=t,i._interior=n,i._inwardNormal=e.getNormalRef().clone(),i._distanceFromOrigin=s,i):new ee(e.getNormalRef().clone(),s,t,n)}static createNormalAndDistance(e,t,n=!1,i=!1,s){const r=e.normalize();if(r)return s&&(s._invisible=n,s._interior=i,s._inwardNormal=r,s._distanceFromOrigin=t),new ee(r,t,n,i)}static createNormalAndPoint(e,t,n=!1,i=!1,s){const r=e.normalize();if(r){const a=r.dotProduct(t);return s&&(s._invisible=n,s._interior=i,s._inwardNormal=r,s._distanceFromOrigin=a),new ee(r,a,n,i)}}static createOriginAndVectors(e,t,n,i=!1,s=!1,r){const a=n.crossProduct(t);return this.createNormalAndPoint(a,e,i,s,r)}static createNormalAndPointXYZXYZ(e,t,n,i,s,r,a=!1,o=!1,c){const d=f.hypotenuseXYZ(e,t,n),h=f.conditionalDivideFraction(1,d);if(h!==void 0){if(c)return c._inwardNormal.set(e*h,t*h,n*h),c._distanceFromOrigin=c._inwardNormal.dotProductXYZ(i,s,r),c._invisible=a,c._interior=o,c;const u=v.create(e*h,t*h,n*h);return new ee(u,u.dotProductXYZ(i,s,r),a,o)}}toJSON(){const e={normal:this.inwardNormalRef.toJSON(),dist:this.distance};return this.interior&&(e.interior=!0),this.invisible&&(e.invisible=!0),e}static fromJSON(e,t){return e&&e.normal&&e.dist!==void 0&&Number.isFinite(e.dist)?ee.createNormalAndDistance(v.fromJSON(e.normal),e.dist,!!e.invisible,!!e.interior):ee.createNormalAndDistance(v.unitZ(),0,!1,!1,t)}setFlags(e,t){this._invisible=e,this._interior=t}get distance(){return this._distanceFromOrigin}get inwardNormalRef(){return this._inwardNormal}get interior(){return this._interior}get invisible(){return this._invisible}static createEdgeAndUpVector(e,t,n,i,s){const r=v.createFrom(t.minus(e));let a=n.crossProduct(r).normalize();if(a){if(i!==void 0&&!i.isAlmostZero){const o=v.createRotateVectorAroundVector(a,r,i);o&&(a=o.clone())}return a.negate(a),ee.createNormalAndPoint(a,e,!1,!1,s)}}static createEdgeXY(e,t,n){const i=v.create(e.y-t.y,t.x-e.x);if(i.normalizeInPlace())return ee.createNormalAndPoint(i,e,!1,!1,n)}static createMidPointEdgeXY(e,t,n){return ee.createNormalAndPointXYZXYZ(e.y-t.y,t.x-e.x,0,.5*(e.x+t.x),.5*(e.y+t.y),0,!1,!1,n)}getPlane3d(){const e=this._distanceFromOrigin,t=y.create(this._inwardNormal.x*e,this._inwardNormal.y*e,this._inwardNormal.z*e),n=pe.createXYPlane();return pe.create(t,this._inwardNormal,n),n}getPlane4d(){return Z.create(this._inwardNormal.x,this._inwardNormal.y,this._inwardNormal.z,-this._distanceFromOrigin)}setPlane4d(e){const t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z),n=t===0?1:1/t;this._inwardNormal.x=n*e.x,this._inwardNormal.y=n*e.y,this._inwardNormal.z=n*e.z,this._distanceFromOrigin=-n*e.w}weightedAltitude(e){return e.x*this._inwardNormal.x+e.y*this._inwardNormal.y+e.z*this._inwardNormal.z-e.w*this._distanceFromOrigin}altitude(e){return e.x*this._inwardNormal.x+e.y*this._inwardNormal.y+e.z*this._inwardNormal.z-this._distanceFromOrigin}altitudeXYZ(e,t,n){return e*this._inwardNormal.x+t*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(e){return e.x*this._inwardNormal.x+e.y*this._inwardNormal.y+e.z*this._inwardNormal.z}velocityXYZ(e,t,n){return e*this._inwardNormal.x+t*this._inwardNormal.y+n*this._inwardNormal.z}dotProductPlaneNormalPoint(e){return e.x*this._inwardNormal.x+e.y*this._inwardNormal.y+e.z*this._inwardNormal.z}isPointOnOrInside(e,t=f.smallMetricDistance){let n=this.altitude(e);return t&&(n+=t),n>=0}isPointInside(e,t=f.smallMetricDistance){let n=this.altitude(e);return t&&(n-=t),n>0}isPointOn(e,t=f.smallMetricDistance){return Math.abs(this.altitude(e))<=t}appendIntersectionRadians(e,t){const n=e.toVectors(),i=this.altitude(e.center),s=this.velocity(n.vector0),r=this.velocity(n.vector90);Bn.appendImplicitLineUnitCircleIntersections(i,s,r,void 0,void 0,t)}static _clipFractionArray=new Me;announceClippedArcIntervals(e,t){const n=ee._clipFractionArray;return n.clear(),this.appendIntersectionRadians(e,n),e.sweep.radiansArrayToPositivePeriodicFractions(n),at.selectIntervals01(e,n,this,t)}announceClippedCurveIntervals(e,t){const n=ee._clipFractionArray;n.clear();const i=[];e.appendPlaneIntersectionPoints(this,i);for(const s of i)n.push(s.fraction);return at.selectIntervals01(e,n,this,t)}getBoundedSegmentSimpleIntersection(e,t){const n=this.altitude(e),i=this.altitude(t);if(!(n*i>0)&&!(n===0&&i===0))return-n/(i-n)}transformInPlace(e){const t=this.getPlane3d(),n=e.matrix,i=e.multiplyPoint3d(t.getOriginRef()),s=n.multiplyInverseTranspose(t.getNormalRef());if(!s)return!1;t.set(i,s);const r=t.getNormalRef().normalize();return r?(this._inwardNormal=r,this._distanceFromOrigin=this._inwardNormal.dotProduct(t.getOriginRef()),!0):!1}setInvisible(e){this._invisible=e}negateInPlace(){this._inwardNormal=this._inwardNormal.negate(),this._distanceFromOrigin=-this._distanceFromOrigin}offsetDistance(e){this._distanceFromOrigin+=e}clipConvexPolygonInPlace(e,t,n=!0,i=f.smallMetricDistance){return un.clipConvexPolygonInPlace(this,e,t,n,i)}multiplyPlaneByMatrix4d(e,t=!0,n=!0){const i=this.getPlane4d();if(t){const s=e.createInverse();return s?this.multiplyPlaneByMatrix4d(s,!1,n):!1}return n?e.multiplyTransposePoint4d(i,i):e.multiplyPoint4d(i,i),this.setPlane4d(i),!0}announceClippedSegmentIntervals(e,t,n,i,s){if(t<e)return!1;const r=-this.altitude(n),o=-this.altitude(i)-r,c=f.conditionalDivideFraction(-r,o);return c===void 0?r<=0?(s&&s(e,t),!0):!1:(o>0?c<t&&(t=c):c>e&&(e=c),t<e?!1:(s&&s(e,t),!0))}getFrame(){const e=this._distanceFromOrigin,t=y.create(this._inwardNormal.x*e,this._inwardNormal.y*e,this._inwardNormal.z*e),n=E.createRigidHeadsUp(this._inwardNormal,ve.ZXY);return X.createOriginAndMatrix(t,n)}intersectRange(e,t=!1){if(e.isNull)return;const n=e.corners(),i=this.getFrame();i.multiplyInversePoint3dArrayInPlace(n);const s=ie.createArray(n);if(s.low.z*s.high.z>0)return;const r=new J;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),un.intersectRangeConvexPolygonInPlace(e,r),r.length!==0)return t&&r.pushWrap(1),r}appendPolygonClip(e,t,n,i){const s=fe.createNull(),r=i.grabFromCache(),a=i.grabFromCache();un.splitConvexPolygonInsideOutsidePlane(this,e,r,a,s),at.captureOrDrop(r,3,t,i),at.captureOrDrop(a,3,n,i)}projectPointToPlane(e,t){return this.projectXYZToPlane(e.x,e.y,e.z,t)}projectXYZToPlane(e,t,n,i){const s=-this.altitudeXYZ(e,t,n);return y.create(e+s*this._inwardNormal.x,t+s*this._inwardNormal.y,n+s*this._inwardNormal.z,i)}}class Jn{curves;localToWorld;axis;_xyStrokes;_facets;constructor(e,t,n){if(e instanceof le){const i=e;e=e.startPoint().isAlmostEqual(e.endPoint())?new oe:new Te,e.tryAddChild(i)}this.curves=e,this.localToWorld=t,this.axis=n}static createForLinearSweep(e,t){const n=tt.createRightHandedFrame(t,e);if(n)return new Jn(e,n,void 0)}static createForPolygon(e,t){const n=tt.createRightHandedFrame(t,e);if(n){const i=N.createArrayOfLineString3d(e),s=[];for(const r of i)r.addClosurePoint(),s.push(oe.create(r));if(s.length===1)return new Jn(s[0],n,void 0);if(s.length>1)return new Jn(He.createLoops(s),n,void 0)}}static createForRotation(e,t){const n=tt.createRightHandedFrame(void 0,e,t);if(n)return new Jn(e,n,t.clone())}getCurves(){return this.curves}tryTransformInPlace(e){if(this.curves.tryTransformInPlace(e)){this.axis&&this.axis.transformInPlace(e);const t=this.axis!==void 0?tt.createRightHandedFrame(void 0,this.curves,this.axis):tt.createRightHandedFrame(void 0,this.curves);if(t)return this.localToWorld.setFrom(t),this._xyStrokes=void 0,!0}return!1}clone(){return new Jn(this.curves.clone(),this.localToWorld.clone(),this.axis)}cloneTransformed(e){const t=this.clone();if(t.tryTransformInPlace(e))return t}isAlmostEqual(e){if(!(e instanceof Jn)||!this.curves.isAlmostEqual(e.curves)||!this.localToWorld.isAlmostEqual(e.localToWorld))return!1;if(this.axis&&e.axis){if(!this.axis.isAlmostEqual(e.axis))return!1}else if(this.axis||e.axis)return!1;return!0}computeXYStrokes(e){this._xyStrokes=void 0;const t=this.localToWorld.inverse();if(t){const n=this.curves.cloneStroked(e);n.tryTransformInPlace(t)&&(this._xyStrokes=n)}}get xyStrokes(){return this._xyStrokes}buildFacets(e){if(this._facets||!this.curves.isAnyRegion())return;const t=this.localToWorld.inverse();if(!t)return;const n=this.curves.cloneTransformed(t);n&&(this._facets=ge.facetRegionXY(n,e))&&this._facets.tryTransformInPlace(this.localToWorld)}purgeFacets(){this._facets=void 0}emitFacets(e,t,n){this.buildFacets(e.options),this._facets&&e.addIndexedPolyface(this._facets,t,n)}announceFacets(e,t){this.buildFacets(t),this._facets&&e(this._facets)}sweepToUnionOfConvexClipPlaneSets(e,t=!1,n=!1,i){i||(i=st.createForFacets()),e||(t=n=!1,e=this.localToWorld.matrix.columnZ()),i.maximizeConvexFacets=!0,this.buildFacets(i);const s=this._facets;if(s){const r=y.create(),a=y.create(),o=xt.createEmpty(),c=s.createVisitor(1);for(c.reset();c.moveToNextFacet();){const d=c.point.length-1,h=Ce.createEmpty();for(let u=0;u<d;u++){c.point.getPoint3dAtUncheckedPointIndex(u,r),c.point.getPoint3dAtUncheckedPointIndex(u+1,a);const g=ee.createEdgeAndUpVector(a,r,e),m=c.edgeVisible[u];g?.setFlags(!m,!m),h.addPlaneToConvexSet(g)}o.addConvexSet(h)}if(t||n){const d=this.localToWorld.matrix.columnZ(),h=this.localToWorld.getOrigin(),u=h.plus(e),g=d.clone(),m=d.negate(),p=Ce.createEmpty();t&&p.addPlaneToConvexSet(ee.createNormalAndPoint(g,h)),n&&p.addPlaneToConvexSet(ee.createNormalAndPoint(m,u)),o.addConvexSet(p)}return o}}}class vi extends ra{solidPrimitiveType="ruledSweep";_contours;constructor(e,t){super(t),this._contours=e}static create(e,t){const n=[];for(const i of e){const s=Jn.createForLinearSweep(i);if(s===void 0)return;n.push(s)}return new vi(n,t)}sweepContoursRef(){return this._contours}cloneSweepContours(){const e=[];for(const t of this._contours)e.push(t.clone());return e}cloneContours(){const e=[];for(const t of this._contours)e.push(t.curves.clone());return e}clone(){return new vi(this.cloneSweepContours(),this.capped)}tryTransformInPlace(e){if(e.matrix.isSingular())return!1;for(const t of this._contours)if(!t.tryTransformInPlace(e))return!1;return e.matrix.determinant()<0&&this._contours.reverse(),!0}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e)?t:void 0}getConstructiveFrame(){if(this._contours.length!==0)return this._contours[0].localToWorld.cloneRigid()}isSameGeometryClass(e){return e instanceof vi}isAlmostEqual(e){if(e instanceof vi){if(this.capped!==e.capped||this._contours.length!==e._contours.length)return!1;for(let t=0;t<this._contours.length;t++)if(!this._contours[t].isAlmostEqual(e._contours[t]))return!1;return!0}return!1}dispatchToGeometryHandler(e){return e.handleRuledSweep(this)}constantVSection(e){const t=this._contours.length;if(t<2)return;const n=e*t;let i=0;e>=1?i=t-1:i=Math.floor(n),i+1>=t&&(i=t-2);const s=i+1,r=f.clampToStartEnd(n-i,0,1);return vi.mutatePartners(this._contours[i].curves,this._contours[s].curves,(a,o)=>{const c=Qs.interpolateBetween(a,r,o);if(c instanceof le)return c})}extendRange(e,t){for(const n of this._contours)n.curves.extendRange(e,t)}static mutatePartners(e,t,n){if(e.isSameGeometryClass(t)){if(e instanceof mt&&t instanceof mt){const i=e,s=t,r=i.cloneEmptyPeer(),a=i.children,o=s.children;if(a.length!==o.length)return;for(let c=0;c<a.length;c++){const d=n(a[c],o[c]);if(!d)return;r.children.push(d)}return r}else if(e instanceof _e&&t instanceof _e){const i=e.cloneEmptyPeer(),s=e.children,r=t.children,a=i.children;if(s===void 0||r===void 0||a===void 0||s.length!==r.length)return;for(let o=0;o<s.length;o++){const c=s[o],d=r[o];if(c instanceof le&&d instanceof le){const h=n(c,d);if(!h)return;a.push(h)}else if(c instanceof _e&&d instanceof _e){const h=this.mutatePartners(c,d,n);if(!h)return;h instanceof _e&&a.push(h)}}return i}}}get isClosedVolume(){const e=this._contours.length;return e>1&&(this.capped||this._contours[0].isAlmostEqual(this._contours[e-1]))}}class li extends ra{solidPrimitiveType="torusPipe";_localToWorld;_radiusA;_radiusB;_sweep;_isReversed;constructor(e,t,n,i,s){super(s),this._localToWorld=e,this._radiusA=t,this._radiusB=n,this._sweep=i,this._isReversed=!1}clone(){const e=new li(this._localToWorld.clone(),this._radiusA,this._radiusB,this._sweep.clone(),this.capped);return e._isReversed=this._isReversed,e}tryTransformInPlace(e){return e.matrix.isSingular()?!1:(e.multiplyTransformTransform(this._localToWorld,this._localToWorld),e.matrix.determinant()<0&&this._localToWorld.matrix.scaleColumnsInPlace(1,1,-1),!0)}cloneTransformed(e){const t=this.clone();return t.tryTransformInPlace(e)?t:void 0}static createInFrame(e,t,n,i,s){if(t=Math.abs(f.correctSmallMetricDistance(t)),n=Math.abs(f.correctSmallMetricDistance(n)),t<n||t===0||n===0||i.isAlmostZero)return;let r=1,a=1,o=!1;e.matrix.determinant()<0&&(a*=-1);const c=i.clone();i.radians<0&&(c.setRadians(-i.radians),a*=-1,r*=-1,o=!0);const d=e.clone();d.matrix.scaleColumnsInPlace(1,r,a);const h=new li(d,t,n,c,s);return h._isReversed=o,h}static createDgnTorusPipe(e,t,n,i,s,r,a){const o=t.unitCrossProductWithDefault(n,0,0,1),c=X.createOriginAndMatrixColumns(e,t,n,o);return li.createInFrame(c,i,s,r,a)}static createAlongArc(e,t,n){if(T.isAlmostEqualRadiansAllowPeriodShift(0,e.sweep.startRadians)||(e=e.cloneInRotatedBasis(e.sweep.startAngle)),!e.isCircular){const r=e.perpendicularVector.sizedCrossProduct(e.vector0,e.matrixRef.columnXMagnitude());if(!r)return;e=B.create(e.center,e.vector0,r,e.sweep)}const i=e.toScaledMatrix3d(),s=X.createOriginAndMatrix(e.center,i.axes);return li.createInFrame(s,i.r0,t,T.createRadians(e.sweep.sweepRadians),n)}getConstructiveFrame(){return this._localToWorld.cloneRigid()}cloneCenter(){return this._localToWorld.getOrigin()}cloneVectorX(){const e=this._localToWorld.matrix.columnX();return e.normalizeWithDefault(1,0,0,e)}cloneVectorY(){const e=this._localToWorld.matrix.columnY();return e.normalizeWithDefault(0,1,0,e)}cloneVectorZ(){const e=this._localToWorld.matrix.columnZ();return e.normalizeWithDefault(0,0,1,e)}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(e){return e instanceof li}isAlmostEqual(e){return e instanceof li?!(!this._sweep.isFullCircle&&this.capped!==e.capped||!this.cloneCenter().isAlmostEqual(e.cloneCenter())||!this.cloneVectorX().isAlmostEqual(e.cloneVectorX())||!this.cloneVectorY().isAlmostEqual(e.cloneVectorY())||!this.cloneVectorZ().isAlmostEqual(e.cloneVectorZ())||!f.isSameCoordinate(this.getMinorRadius(),e.getMinorRadius())||!f.isSameCoordinate(this.getMajorRadius(),e.getMajorRadius())||!this.getSweepAngle().isAlmostEqualNoPeriodShift(e.getSweepAngle())):!1}vFractionToRadians(e){return this._sweep.radians*e}dispatchToGeometryHandler(e){return e.handleTorusPipe(this)}constantVSection(e){const t=this.vFractionToRadians(e),n=Math.cos(t),i=Math.sin(t),s=this._radiusA,r=this._radiusB,a=this._localToWorld.multiplyXYZ(s*n,s*i,0),o=this._localToWorld.multiplyVectorXYZ(r*n,r*i,0),c=this._localToWorld.multiplyVectorXYZ(0,0,r);return oe.create(B.create(a,o,c))}constantUSection(e){const t=this._sweep.radians,n=e*2*Math.PI,i=this._radiusA,s=this._radiusB,a=this._localToWorld.matrix,o=this._localToWorld.multiplyXYZ(0,0,s*Math.sin(n)),c=i+s*Math.cos(n),d=a.multiplyXYZ(c,0,0),h=a.multiplyXYZ(0,c,0);return Te.create(B.create(o,d,h,me.createStartEndRadians(0,t)))}extendRange(e,t){const n=this._sweep.radians,i=this._radiusA,s=this._radiusB,r=this._localToWorld,a=Math.ceil(n/(Math.PI/16)),o=16;let c=0,d=0,h=0,u=0,g=0,m=0,p=0,x=0,_=0;const I=n/a;for(let S=0;S<=a;S++)if(u=S*I,g=Math.cos(u),m=Math.sin(u),S===0||S===a?(c=-Math.PI,d=2*Math.PI/o,h=o):(c=-.5*Math.PI,d=Math.PI/o,h=2*o-1),t)for(_=0;_<=h;_++)x=c+_*d,p=i+s*Math.cos(x),e.extendTransformTransformedXYZ(t,r,g*p,m*p,Math.sin(x)*s);else for(_=0;_<=h;_++)x=c+_*d,p=i+s*Math.cos(x),e.extendTransformedXYZ(r,g*p,m*p,Math.sin(x)*s)}uvFractionToPoint(e,t,n){const i=t*this._sweep.radians,s=e*Math.PI*2,r=Math.cos(i),a=Math.sin(i),o=this._radiusA,c=this._radiusB,d=o+Math.cos(s)*c;return this._localToWorld.multiplyXYZ(d*r,d*a,c*Math.sin(s),n)}uvFractionToPointAndTangents(e,t,n){const i=t*this._sweep.radians,s=e*Math.PI*2,r=this._sweep.radians,a=Math.PI*2,o=Math.cos(i),c=Math.sin(i),d=Math.sin(s),h=Math.cos(s),u=this._radiusA,g=this._radiusB,m=u+Math.cos(s)*g,p=g*d,x=g*h;return ke.createOriginAndVectors(this._localToWorld.multiplyXYZ(o*m,c*m,p),this._localToWorld.multiplyVectorXYZ(-o*p*a,-c*p*a,x*a),this._localToWorld.multiplyVectorXYZ(-m*c*r,m*o*r,0),n)}maxIsoParametricDistance(){const e=Math.abs(this.getMajorRadius()),t=Math.abs(this.getMinorRadius());return $.create(t*Math.PI*2,(e+t)*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 Si{constructor(){}static _clothoidEvaluator;static _biquadraticEvaluator;static _blossEvaluator;static _sineEvaluator;static _cosineEvaluator;static findEvaluator(e){if(e==="clothoid")return this._clothoidEvaluator?this._clothoidEvaluator:this._clothoidEvaluator=new jc;if(e==="bloss")return this._blossEvaluator?this._blossEvaluator:this._blossEvaluator=new $c;if(e==="biquadratic")return this._biquadraticEvaluator?this._biquadraticEvaluator:this._biquadraticEvaluator=new ed;if(e==="sine")return this._sineEvaluator?this._sineEvaluator:this._sineEvaluator=new td;if(e==="cosine")return this._cosineEvaluator?this._cosineEvaluator:this._cosineEvaluator=new nd}}class jc extends Si{constructor(){super()}fractionToCurvatureFraction(e){return e}fractionToCurvatureFractionDerivative(e){return 1}fractionToArea(e){return e*e*.5}}class $c extends Si{constructor(){super()}fractionToCurvatureFraction(e){return e*e*(3-2*e)}fractionToCurvatureFractionDerivative(e){return 6*e*(1-e)}fractionToArea(e){return e*e*e*(1-.5*e)}}class ed extends Si{constructor(){super()}integratedBasis(e){return e*e*e*(2/3)}basis(e){return 2*e*e}basisDerivative(e){return 4*e}fractionToCurvatureFraction(e){return e<=.5?this.basis(e):1-this.basis(1-e)}fractionToCurvatureFractionDerivative(e){return e<=.5?this.basisDerivative(e):this.basisDerivative(1-e)}fractionToArea(e){if(e<=.5)return this.integratedBasis(e);const t=1-e;return .5-t+this.integratedBasis(t)}}class td extends Si{constructor(){super()}fractionToCurvatureFraction(e){const t=2*Math.PI;return e-Math.sin(e*t)/t}fractionToCurvatureFractionDerivative(e){const t=2*Math.PI;return 1-Math.cos(e*t)}fractionToArea(e){const t=2*Math.PI;return .5*e*e+(Math.cos(e*t)-1)/(t*t)}}class nd extends Si{constructor(){super()}fractionToCurvatureFraction(e){return .5*(1-Math.cos(e*Math.PI))}fractionToCurvatureFractionDerivative(e){const t=Math.PI;return .5*t*Math.sin(e*t)}fractionToArea(e){const t=Math.PI;return .5*e-.5*Math.sin(e*t)/t}}class sr{radius0;radius1;bearing0;bearing1;curveLength;constructor(e,t,n,i,s){this.radius0=e,this.radius1=t,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 sr(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 e=De.radiusRadiusSweepRadiansToArcLength(this.radius0,this.radius1,this.bearing1.radians-this.bearing0.radians);return f.isSameCoordinate(this.curveLength,e)}return!1}tryResolveAnySingleUnknown(){if(this.getIsValidCompleteSet())return!0;if(this.bearing0&&this.bearing1){const e=this.bearing1.radians-this.bearing0.radians;return this.curveLength===void 0&&this.radius0!==void 0&&this.radius1!==void 0?(this.curveLength=De.radiusRadiusSweepRadiansToArcLength(this.radius0,this.radius1,e),!0):this.curveLength!==void 0&&this.radius0===void 0&&this.radius1!==void 0?(this.radius0=De.radius1LengthSweepRadiansToRadius0(this.radius1,this.curveLength,e),!0):this.curveLength!==void 0&&this.radius0!==void 0&&this.radius1===void 0?(this.radius1=De.radius0LengthSweepRadiansToRadius1(this.radius0,this.curveLength,e),!0):!1}return this.curveLength===void 0||this.radius0===void 0||this.radius1===void 0?!1:this.bearing0?(this.bearing1=T.createRadians(this.bearing0.radians+De.radiusRadiusLengthToSweepRadians(this.radius0,this.radius1,this.curveLength)),!0):this.bearing1?(this.bearing0=T.createRadians(this.bearing1.radians-De.radiusRadiusLengthToSweepRadians(this.radius0,this.radius1,this.curveLength)),!0):!1}almostEqualCoordinate(e,t){return e===void 0&&t===void 0?!0:e!==void 0&&t!==void 0?f.isSameCoordinate(e,t):!1}almostEqualBearing(e,t){return e===void 0&&t===void 0?!0:e!==void 0&&t!==void 0?e.isAlmostEqualNoPeriodShift(t):!1}isAlmostEqual(e){return!(!e||!this.almostEqualCoordinate(this.radius0,e.radius0)||!this.almostEqualCoordinate(this.radius1,e.radius1)||!this.almostEqualBearing(this.bearing0,e.bearing0)||!this.almostEqualBearing(this.bearing1,e.bearing1)||!this.almostEqualCoordinate(this.curveLength,e.curveLength))}applyScaleFactor(e){e!==0&&(this.radius0!==void 0&&(this.radius0*=e),this.radius1!==void 0&&(this.radius1*=e),this.curveLength!==void 0&&(this.curveLength*=e))}static areAlmostEqual(e,t){return e===void 0?t===void 0:e.isAlmostEqual(t)}}class ut extends De{curvePrimitiveType="transitionSpiral";radius01;bearing01;_globalStrokes;_activeStrokes;get activeStrokes(){return this._activeStrokes!==void 0?this._activeStrokes:this._globalStrokes}_evaluator;_arcLength01;_curvature01;constructor(e,t,n,i,s,r,a,o){super(e,r,s,o),this._evaluator=t,this.radius01=n,this.bearing01=i,this._arcLength01=a,this._globalStrokes=N.create(),this._curvature01=Je.create(0,1),this.refreshComputedProperties()}static defaultSpiralType="clothoid";globalFractionToBearingRadians(e){const t=this._evaluator.fractionToArea(e),n=this._arcLength01;return this.bearing01.startRadians+e*n*this._curvature01.x0+t*n*this._curvature01.signedDelta()}globalFractionToCurvature(e){const t=this._evaluator.fractionToCurvatureFraction(e);return this._curvature01.fractionToPoint(t)}fractionToBearingRadians(e){const t=this.activeFractionInterval.fractionToPoint(e);return this.bearing01.startRadians+t*this._arcLength01*(this._curvature01.x0+.5*t*(this._curvature01.x1-this._curvature01.x0))}fractionToCurvature(e){return this._curvature01.fractionToPoint(this.activeFractionInterval.fractionToPoint(e))}static _gaussFraction;static _gaussWeight;static _gaussMapper;static initWorkSpace(){ut._gaussFraction=new Float64Array(5),ut._gaussWeight=new Float64Array(5),ut._gaussMapper=(e,t,n,i)=>ct.setupGauss5(e,t,n,i)}fullSpiralIncrementalIntegral(e,t,n,i){const s=ut._gaussFraction,r=ut._gaussWeight,a=ut._gaussMapper(t,n,s,r),o=this._arcLength01;let c=0,d=0,h=0;for(let u=0;u<a;u++){const g=this.globalFractionToBearingRadians(s[u]);c=r[u]*o,d+=c*Math.cos(g),h+=c*Math.sin(g)}i?E.xyzPlusMatrixTimesXYZ(e,this.localToWorld.matrix,{x:d,y:h,z:0},e):e.addXYZInPlace(d,h,0)}refreshComputedProperties(){this._curvature01=Je.create(De.radiusToCurvature(this.radius01.x0),De.radiusToCurvature(this.radius01.x1)),this._globalStrokes.clear();const e=y.create();this._globalStrokes.appendStrokePoint(e);const t=16,n=1/t;for(let i=1;i<=t;i++){const s=(i-1)*n,r=i*n;this.fullSpiralIncrementalIntegral(e,s,r,!1),this._globalStrokes.appendStrokePoint(e)}if(this._globalStrokes.tryTransformInPlace(this.localToWorld),!this.activeFractionInterval.isExact01){this._activeStrokes===void 0&&(this._activeStrokes=N.create()),this._activeStrokes.clear();for(let i=0;i<=t;i++){const s=i*n;this._activeStrokes.addPoint(this.fractionToPoint(s))}}}static createRadiusRadiusBearingBearing(e,t,n,i,s){const r=De.radiusRadiusSweepRadiansToArcLength(e.x0,e.x1,t.sweepRadians);s===void 0&&(s="clothoid");const a=Si.findEvaluator(s);if(a)return new ut(s,a,e.clone(),t.clone(),n.clone(),i.clone(),r,new sr(e.x0,e.x1,t.startAngle.clone(),t.endAngle.clone(),void 0))}static createFrom4OutOf5(e,t,n,i,s,r,a,o){e===void 0&&(e="clothoid");const c=Si.findEvaluator(e);if(!c)return;const d=new sr(t,n,i,s,r),h=d.clone();if(d.tryResolveAnySingleUnknown())return a===void 0&&(a=Je.create(0,1)),new ut(e,c,Je.create(d.radius0,d.radius1),me.createStartEnd(d.bearing0,d.bearing1),a?a.clone():Je.create(0,1),o,d.curveLength,h)}setFrom(e){return this.localToWorld.setFrom(e.localToWorld),this.radius01.setFrom(e.radius01),this._curvature01.setFrom(e._curvature01),this.bearing01.setFrom(e.bearing01),this.localToWorld.setFrom(e.localToWorld),this.activeFractionInterval.setFrom(e.activeFractionInterval),this._arcLength01=e._arcLength01,this}clone(){return new ut(this._spiralType,this._evaluator,this.radius01.clone(),this.bearing01.clone(),this.activeFractionInterval.clone(),this.localToWorld.clone(),this._arcLength01,this._designProperties?.clone())}tryTransformInPlace(e){const t=this.applyRigidPartOfTransform(e);return t!==void 0&&(this._curvature01.x0/=t.scale,this._curvature01.x1/=t.scale,this.radius01.x0*=t.scale,this.radius01.x1*=t.scale,this._arcLength01*=t.scale),this.refreshComputedProperties(),!0}startPoint(e){return this.activeStrokes.startPoint(e)}endPoint(e){return this.activeStrokes.endPoint(e)}isInPlane(e){return e.isPointInPlane(this.localToWorld.origin)&&f.isSameCoordinate(0,this.localToWorld.matrix.dotColumnX(e.getNormalRef()))&&f.isSameCoordinate(0,this.localToWorld.matrix.dotColumnY(e.getNormalRef()))}quickLength(){return this.curveLength()}curveLength(){return this._arcLength01*this._activeFractionInterval.absoluteDelta()}curveLengthBetweenFractions(e,t){return this._arcLength01*(this._activeFractionInterval.absoluteDelta()*Math.abs(t-e))}isSameGeometryClass(e){return e instanceof De}emitStrokes(e,t){if(!t)this.activeStrokes.emitStrokes(e,t);else{const n=new kc(this);this.emitStrokableParts(n,t),n.claimLineString(e)}}emitStrokableParts(e,t){const n=this.computeStrokeCountForOptions(t);e.startParentCurvePrimitive(this);const i=this.activeStrokes;!(e.needPrimaryGeometryForStrokes===void 0?!1:e.needPrimaryGeometryForStrokes())&&n<=i.numPoints()?this.activeStrokes.emitStrokableParts(e,t):e.announceIntervalForUniformStepStrokes(this,n,0,1),e.endParentCurvePrimitive(this)}computeStrokeCountForOptions(e){let t;if(e){const n=Math.min(Math.abs(this.radius01.x0),Math.abs(this.radius01.x1));t=e.applyTolerancesToArc(n,this.bearing01.sweepRadians),t=e.applyMaxEdgeLength(t,this.curveLength()),t=e.applyMinStrokesPerPrimitive(t)}else t=st.applyAngleTol(void 0,4,this.bearing01.sweepRadians);return t}reverseInPlace(){this.activeFractionInterval.reverseInPlace(),this._activeStrokes===void 0&&(this._activeStrokes=this._globalStrokes.clone()),this._activeStrokes.reverseInPlace()}fractionToPoint(e,t){const n=this.activeFractionInterval.fractionToPoint(e),i=this._globalStrokes.packedPoints.length-1;if(i<1)return y.createZero(t);if(e>1){t=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(i,t);const s=1/i;let r=1,a=r+s;for(;a<n;)this.fullSpiralIncrementalIntegral(t,r,a,!0),r=a,a+=s;this.fullSpiralIncrementalIntegral(t,r,n,!0)}else if(e<0){t=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(0,t);const s=1/i;let r=0,a=r-s;for(;a>n;)this.fullSpiralIncrementalIntegral(t,r,a,!0),r=a,a-=s;this.fullSpiralIncrementalIntegral(t,r,n,!0)}else{const s=f.clampToStartEnd(n,0,1),r=Math.trunc(s*i),a=r/i;t=this._globalStrokes.packedPoints.getPoint3dAtUncheckedPointIndex(r,t),this.fullSpiralIncrementalIntegral(t,a,n,!0)}return t}fractionToPointAndDerivative(e,t){const n=this.activeFractionInterval.fractionToPoint(e);t=t||q.createZero(),this.fractionToPoint(e,t.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),t.direction),t}fractionToFrenetFrame(e,t){const n=this.activeFractionInterval.fractionToPoint(e);t=t||X.createIdentity(),t.origin.setFrom(this.fractionToPoint(e)),E.createRigidFromMatrix3d(this.localToWorld.matrix,ve.XYZ,t.matrix);const i=this.globalFractionToBearingRadians(n),s=Math.cos(i),r=Math.sin(i);return t.matrix.applyGivensColumnOp(0,1,s,r),t}fractionToPointAnd2Derivatives(e,t){const n=this.activeFractionInterval.fractionToPoint(e),i=this.fractionToPoint(e),s=this.globalFractionToBearingRadians(n),r=Math.cos(s),a=Math.sin(s),o=this._arcLength01*this.activeFractionInterval.signedDelta(),c=o,d=c*o,h=this.localToWorld.matrix.multiplyXY(c*r,c*a),u=this.localToWorld.matrix.multiplyXY(-d*a,d*r);return u.scaleInPlace(this.globalFractionToCurvature(n)),ke.createCapture(i,h,u,t)}dispatchToGeometryHandler(e){return e.handleTransitionSpiral(this)}isAlmostEqual(e){return e instanceof ut?this.radius01.isAlmostEqual(e.radius01)&&this.bearing01.isAlmostEqualAllowPeriodShift(e.bearing01)&&this.localToWorld.isAlmostEqual(e.localToWorld)&&f.isSameCoordinate(this._arcLength01,e._arcLength01)&&this.activeFractionInterval.isAlmostEqual(e.activeFractionInterval)&&this._curvature01.isAlmostEqual(e._curvature01):!1}}ut.initWorkSpace();var rr;(function(l){l[l.Sections=0]="Sections",l[l.AlsoRuledSweep=1]="AlsoRuledSweep",l[l.AlsoMesh=2]="AlsoMesh"})(rr||(rr={}));class dn{static addPartialSegment(e,t,n,i,s,r){(t||r>s)&&n!==void 0&&i!==void 0&&!f.isAlmostEqualNumber(s,r)&&e.tryAddChild(Q.create(n.interpolate(s,i),n.interpolate(r,i)))}static createArcPointTangentPoint(e,t,n){const i=B.createCircularStartTangentEnd(e,t,n);if(i instanceof B)return i}static createFilletsInLineString(e,t,n=!0){if(Array.isArray(e))return this.createFilletsInLineString(new Qe(e),t,n);if(e instanceof N)return this.createFilletsInLineString(e.packedPoints,t,n);const i=typeof n=="boolean",s=i?n:n.allowCusp??!0,r=i?!1:n.filletClosure??!1,a=i?f.smallMetricDistance:n.closureTolerance??f.smallMetricDistance,o=i?f.smallMetricDistance:n.cuspTolerance??f.smallMetricDistance,c=i?!0:n.cuspSegments??!0,d=i?!1:n.simplifyPath??!1;let h=e.length;if(r&&e.almostEqualIndexIndex(0,h-1,a)&&h--,h<=1)return;const u=y.create(),g=y.create(),m=y.create(),p=[];for(let b=0;b<h;b++){let C=Math.abs(Array.isArray(t)?b<t.length?t[b]:0:t);Number.isFinite(C)||(C=0),C===0||!r&&(b===0||b===h-1)?p.push({fraction10:0,fraction12:0,point:e.getPoint3dAtUncheckedPointIndex(b)}):(e.getPoint3dAtUncheckedPointIndex(f.modulo(b-1,h),u),e.getPoint3dAtUncheckedPointIndex(b,g),e.getPoint3dAtUncheckedPointIndex(f.modulo(b+1,h),m),p.push(B.createFilletArc(u,g,m,C)))}const x=(b,C)=>b.fraction12+C.fraction10>1,_=(b,C,M)=>e.distanceUncheckedIndexIndex(b,e.cyclicIndex(b+1))*(C.fraction12+M.fraction10-1),I=(b,C)=>C===0?b.fraction12>1:b.fraction10>1,S=(b,C,M)=>x(C,M)&&(!s||_(b,C,M)>o),A=b=>{b.fraction10=b.fraction12=0,b.arc=void 0};for(let b=0;b<(r?h:h-1);b++){const C=p[b],M=p[f.modulo(b+1,h)];if(S(b,C,M)){const G=I(C,0),ae=I(M,1);G&&!ae?A(C):!G&&ae||!G&&!ae?A(M):M.fraction10<C.fraction12?A(C):A(M),S(b,C,M)&&(A(C),A(M))}}const w=Te.create();for(let b=0;b<h;b++){const C=p[b];if(w.tryAddChild(C.arc),b+1<h||r){const M=p[f.modulo(b+1,h)];this.addPartialSegment(w,c,C.point,M.point,C.fraction12,1-M.fraction10)}}if(!d)return w;const k=a*a,D=w.children.filter(b=>b.range().diagonalLengthSquared(!0)>=k);if(D.length===0)return;const P=Te.create(...D);return ge.consolidateAdjacentPrimitives(P,{consolidateLoopSeam:!0,duplicatePointTolerance:a,colinearPointTolerance:a}),P}static validateOpenPathStartEnd(e){const t=e.children.length,n=e.children[0],i=e.children[t-1];if(n instanceof B){const s=n.startPoint();e=Te.create(Q.create(s,s),...e.children)}if(i instanceof B){const s=i.endPoint();e=Te.create(...e.children,Q.create(s,s))}return e}static splitAndAppendArc(e,t,n){const i=y.createZero();for(let s=0;s<n.length-1;s++)e.tryAddChild(t.clonePartialCurve(n[s],n[s+1])),s+1<n.length-1&&(t.fractionToPoint(n[s+1],i),e.tryAddChild(Q.create(i,i)))}static updatePathForRelaxedValidation(e,t,n){const i=new Te,s=e.children.length;for(let r=0;r<s;r++){const a=e.children[r],o=a instanceof B?Math.abs(a.sweep.sweepDegrees):void 0,c=f.smallAngleDegrees;if(o!==void 0&&o>360+c)return;if(!t&&r===0){i.tryAddChild(a);continue}const d=e.cyclicCurvePrimitive(r-1),h=a.fractionToPointAndDerivative(0).direction,u=d.fractionToPointAndDerivative(1).direction,m=!h.isParallelTo(u,!1,!0,n)&&(a instanceof B&&(d instanceof Q||d instanceof N)||d instanceof B&&(a instanceof Q||a instanceof N));if(a instanceof B&&d instanceof B||m){const x=a.startPoint();i.tryAddChild(Q.create(x,x))}o!==void 0&&o>120&&o<=240?dn.splitAndAppendArc(i,a,[0,.5,1]):o!==void 0&&o>240&&o<=360+c?dn.splitAndAppendArc(i,a,[0,1/3,2/3,1]):i.tryAddChild(a)}return i}static validateArcNeighbors(e,t,n){const i=e.getChild(t);if(!i||!(i instanceof B))return!1;const s=e.cyclicCurvePrimitive(t-1);if(!s||!(s instanceof Q)&&!(s instanceof N))return!1;const r=i.fractionToPointAndDerivative(0).direction,a=s.fractionToPointAndDerivative(1).direction;if(!r.isParallelTo(a,!1,!0,n))return!1;const o=e.cyclicCurvePrimitive(t+1);if(!o||!(o instanceof Q)&&!(o instanceof N))return!1;const c=i.fractionToPointAndDerivative(1).direction,d=o.fractionToPointAndDerivative(0).direction;return!!c.isParallelTo(d,!1,!0,n)}static validateFilletedLineString(e,t,n){if(e.children.length===0)return;const i=n?.relaxedValidation??!1;let s=e;if(t||(s=this.validateOpenPathStartEnd(s)),i&&(s=this.updatePathForRelaxedValidation(s,t,n?.parallelOptions)),s===void 0)return;const r=s.children.length;for(let a=0;a<r;a++){const o=s.children[a];if(!(o instanceof B)&&!(o instanceof Q)&&!(o instanceof N)||o instanceof B&&(o.circularRadius()===void 0||Math.abs(o.sweep.sweepDegrees)>180-f.smallAngleDegrees||!this.validateArcNeighbors(s,a,n?.parallelOptions)))return}return s}static addJointBetweenConnectedArcs(e,t,n,i){if(!n&&t<2)return;const s=e.getChild(t);if(!s||!(s instanceof B))return;const r=e.cyclicCurvePrimitive(t-1);if(!r||!(r instanceof Q)||r.curveLength()>0)return;const a=e.cyclicCurvePrimitive(t-2);!a||!(a instanceof B)||i.push([r.startPoint(),0])}static fromFilletedLineString(e,t){const n=e instanceof oe?Te.create(...e.children):e,i=n.isPhysicallyClosedCurve(t?.distanceTol),s=this.validateFilletedLineString(n,i,t);if(!s)return;const r=[],a=s.children.length,o=s.cyclicCurvePrimitive(-1);let c=i&&o&&o instanceof B;for(let d=0;d<a;d++){const h=s.children[d];if(h instanceof B){this.addJointBetweenConnectedArcs(s,d,i,r),c=!0;const u=h.computeTangentIntersection(),g=h.circularRadius();if(g!==void 0&&u!==void 0)r.push([u,g]);else return}else if(h instanceof Q)c?c=!1:r.push([h.startPoint(),0]);else if(h instanceof N){const u=c?1:0;c=!1;for(let g=u;g<h.numPoints()-1;g++)r.push([h.pointAtUnchecked(g),0])}}if(i)r.length>0&&!r[0][0].isAlmostEqual(r[r.length-1][0],t?.distanceTol)&&r.push(r[0]);else{const d=s.endPoint();d&&r.push([d,0])}return r}static createRectangleXY(e,t,n,i,s=0,r){let a=f.correctSmallMetricDistance(r);const o=Math.min(e,n),c=Math.max(e,n),d=Math.min(t,i),h=Math.max(t,i);if(a=Math.min(Math.abs(a),.5*(c-o),.5*(h-d)),a===0)return oe.createPolygon([y.create(o,d,s),y.create(c,d,s),y.create(c,h,s),y.create(o,h,s),y.create(o,d,s)]);{const u=v.create(a,0,0),g=v.create(0,a,0),m=o+a,p=d+a,x=c-a,_=h-a,I=[y.create(x,_,s),y.create(m,_,s),y.create(m,p,s),y.create(x,p,s)],S=oe.create();for(let A=0;A<4;A++){const w=I[A],k=I[(A+1)%4],D=v.createStartEnd(w,k),P=B.create(w,u,g,me.createStartEndDegrees(0,90));S.tryAddChild(P);const b=P.endPoint();D.isAlmostZero||S.tryAddChild(Q.create(b,b.plus(D))),u.rotate90CCWXY(u),g.rotate90CCWXY(g)}return S}}static appendToArcInPlace(e,t,n=!1,i=f.smallMetricDistance){if(e.center.isAlmostEqual(t.center,i)){const s=f.split3WaySign(e.sweep.sweepRadians*t.sweep.sweepRadians,-1,0,1),r=e.angleToPointAndDerivative(e.sweep.fractionToAngle(1));e.sweep.sweepRadians<0&&r.direction.scaleInPlace(-1);const a=t.angleToPointAndDerivative(t.sweep.fractionToAngle(0));if(t.sweep.sweepRadians<0&&a.direction.scaleInPlace(-1),r.isAlmostEqual(a,i))return e.sweep.setStartEndRadians(e.sweep.startRadians,e.sweep.startRadians+e.sweep.sweepRadians+s*t.sweep.sweepRadians),!0;if(n&&(a.direction.scaleInPlace(-1),r.isAlmostEqual(a,i)))return e.sweep.setStartEndRadians(e.sweep.startRadians,e.sweep.startRadians+e.sweep.sweepRadians-s*t.sweep.sweepRadians),!0}return!1}static assembleArcChainOnEllipsoid(e,t,n=.5){const i=Te.create();for(let s=0;s+1<t.length;s++){const r=e.sectionArcInPlaneOfInterpolatedNormal(t[s].toAngles(),n,t[s+1].toAngles());i.tryAddChild(r)}return i}static appendGeometryQueryArray(e,t){if(e instanceof Mt)t.push(e);else if(Array.isArray(e))for(const n of e)this.appendGeometryQueryArray(n,t)}static createPipeSegments(e,t){if(e instanceof Q)return Pi.createAxisPoints(e.startPoint(),e.endPoint(),t,t,!1);if(e instanceof B)return li.createAlongArc(e,t,!1);if(e instanceof le){const n=ce.create();return n.addMiteredPipes(e,t),n.claimPolyface()}else if(e instanceof mt){const n=[];for(const i of e.children){const s=this.createPipeSegments(i,t);this.appendGeometryQueryArray(s,n)}return n}}static startPointAndTangent(e){if(e instanceof le)return e.fractionToPointAndDerivative(0);if(e.length<2)return;Array.isArray(e)&&(e=new Qe(e));const t=q.createZero();return e.getPoint3dAtUncheckedPointIndex(0,t.origin),e.vectorIndexIndex(0,1,t.direction),t}static createArcFromSectionData(e,t){const n=dn.startPointAndTangent(e);if(!n)return;let i;if(t instanceof B)i=t.clone(),i.center=n.origin;else{const s=v.create(),r=v.create(),a=typeof t=="number"?t:t.x,o=typeof t=="number"?t:t.y,c=E.createRigidHeadsUp(n.direction,ve.ZXY);c.columnX(s).scaleInPlace(a),c.columnY(r).scaleInPlace(o),i=B.create(n.origin,s,r)}return i.binormalVector().dotProduct(n.direction)<0&&i.reverseInPlace(),i}static createMiteredPipeSections(e,t){const n=dn.createArcFromSectionData(e,t);if(!n)return[];const i=dn.createMiteredSweepSections(e,n);return i?i.sections:[]}static strokeSmoothCurve(e,t){let n,i;if(e instanceof le){n=e.fractionToPointAndDerivative(0).direction,i=e.fractionToPointAndDerivative(1).direction;const s=N.create();e.emitStrokes(s,t),e=s.packedPoints}else if(e instanceof mt){n=e.startPointAndDerivative()?.direction,i=e.endPointAndDerivative()?.direction;const s=e.getPackedStrokes(t);if(!s)return;e=s}else Array.isArray(e)&&(e=new Qe(e));return{strokes:e,startTangent:n,endTangent:i}}static alignFirstAndLastBisectorPlanes(e,t,n,i){const s=i?.startTangent??n?.startTangent??e.getNormalRef(),r=i?.endTangent??n?.endTangent??t.getNormalRef();if(i?.wrapIfPhysicallyClosed&&e.getOriginRef().isAlmostEqual(t.getOriginRef())){const a=s.plus(r);if(a.tryNormalizeInPlace()){e.getNormalRef().setFrom(a),t.getNormalRef().setFrom(a);return}}s.tryNormalizeInPlace()&&e.getNormalRef().setFrom(s),r.tryNormalizeInPlace()&&t.getNormalRef().setFrom(r)}static alignClosedCurveToPlane(e,t){let n;if(e instanceof le?e.startPoint().isAlmostEqual(e.endPoint())&&(n=oe.create(e)):e.isAnyRegion()&&(n=e),n){const i=E.createRigidHeadsUp(t).transpose(),s=n.cloneTransformed(X.createOriginAndMatrix(void 0,i)),r=ge.computeXYArea(s);r&&r<0&&e.reverseInPlace()}}static doSweepToPlane(e,t,n,i,s){const r=v.createStartEnd(t.getOriginRef(),n.getOriginRef()),a=X.createFlattenAlongVectorToPlane(r,i.getOriginRef(),i.getNormalRef());if(a===void 0)return s;const o=s.cloneTransformed(a);return o===void 0?s:(e.planes.push(i),e.sections.push(o),o)}static createMiteredSweepSections(e,t,n){n||(n={});const i=this.strokeSmoothCurve(e,n.strokeOptions);if(!i)return;const s=In.createBisectorPlanesForDistinctPoints(i.strokes);if(!s||s.length<2)return;this.alignFirstAndLastBisectorPlanes(s[0],s[s.length-1],i,n),this.alignClosedCurveToPlane(t,s[0].getNormalRef());const r={sections:[],planes:[]};let a=this.doSweepToPlane(r,s[0],s[1],s[0],t);for(let o=1;o<s.length;o++)a=this.doSweepToPlane(r,s[o-1],s[o],s[o],a);if(n.outputSelect){const o=vi.create(r.sections,n.capped??!1);if(o&&(r.ruledSweep=o,rr.AlsoMesh===n.outputSelect)){const c=ce.create(n.strokeOptions);c.addRuledSweep(o),r.mesh=c.claimPolyface()}}return r}static createArcPointTangentRadius(e,t,n,i,s){return B.createCircularStartTangentRadius(e,t,n,i,s)}static createLineSpiralSpiralLine(e,t,n,i){const s=v.createStartEnd(t,n),r=v.createStartEnd(n,i),a=s.magnitude(),o=Math.atan2(s.y,s.x),c=s.angleToXY(r),d=.5*c.radians,h=o+c.radians,u=E.createRotationAroundAxisIndex(Jt.Z,T.createRadians(o)),g=X.createRefs(t.clone(),u),m=ut.createFrom4OutOf5(e,0,void 0,T.createRadians(0),T.createRadians(d),a,void 0,g);if(m){const p=o+d,x=v.createPolar(1,T.createRadians(p)),_=x.dotProductStartEnd(t,n),I=x.dotProductStartEnd(t,m.endPoint()),S=_/I,A=ut.createFrom4OutOf5(e,0,void 0,T.createRadians(0),T.createRadians(d),a*S,void 0,g);if(A===void 0)return;const w=s.magnitude(),k=v.createStartEnd(n,i);k.scaleToLength(w,k);const D=n.plus(k),P=E.createRotationAroundAxisIndex(Jt.Z,T.createRadians(h+Math.PI)),b=X.createRefs(D,P),C=ut.createFrom4OutOf5(e,0,-A.radius01.x1,T.zero(),void 0,A.curveLength(),Je.create(1,0),b);return C===void 0?void 0:[A,C]}}static createLineSpiralSpiralLineWithSpiralLength(e,t,n,i,s){const r=v.createStartEnd(t,n),a=v.createStartEnd(n,i),o=Math.atan2(r.y,r.x),c=r.angleToXY(a),d=.5*c.radians,h=.5*(Math.PI-c.radians),u=Math.atan2(-a.y,-a.x),g=ut.createFrom4OutOf5(e,0,void 0,T.zero(),T.createRadians(d),s,void 0,X.createIdentity());if(g){const m=g.fractionToPoint(1),p=t.distance(n),x=i.distance(n),_=m.y/Math.tan(h),I=f.conditionalDivideFraction(p-_-m.x,p),S=f.conditionalDivideFraction(x-_-m.x,x);if(I!==void 0&&S!==void 0){const A=E.createRotationAroundAxisIndex(Jt.Z,T.createRadians(o)),w=t.interpolate(I,n),k=X.createRefs(w,A),D=ut.createFrom4OutOf5(e,0,void 0,T.zero(),T.createRadians(d),s,void 0,k);if(D===void 0)return;const P=E.createRotationAroundAxisIndex(Jt.Z,T.createRadians(u)),b=i.interpolate(S,n),C=X.createRefs(b,P),M=ut.createFrom4OutOf5(e,0,void 0,T.zero(),T.createRadians(-d),s,void 0,C);return M===void 0?void 0:[D,M]}}}static createLineSpiralArcSpiralLine(e,t,n,i,s,r,a){const o=v.createStartEnd(t,n);o.z=0;const c=v.createStartEnd(i,n);c.z=0;const d=o.normalize(),h=c.normalize();if(d===void 0||h===void 0)return;const u=d.unitPerpendicularXY(),g=h.unitPerpendicularXY(),m=o.angleToXY(c),p=f.split3WaySign(m.radians,1,-1,-1),x=-p,_=p*Math.abs(a),I=x*Math.abs(a),S=ut.createFrom4OutOf5(e,0,_,T.zero(),void 0,s,void 0,X.createIdentity()),A=ut.createFrom4OutOf5(e,0,I,T.zero(),void 0,r,void 0,X.createIdentity());if(S===void 0||A===void 0)return;const w=S.fractionToPointAndUnitTangent(1),k=A.fractionToPointAndUnitTangent(1),D=w.origin.x-_*w.direction.y,P=w.origin.y+_*w.direction.x,b=k.origin.x-I*k.direction.y,C=k.origin.y+I*k.direction.x,M=v.createAdd2Scaled(d,D,u,P),G=v.createAdd2Scaled(h,b,g,C),ae=$.create();if(Le.linearSystem2d(d.x,-h.x,d.y,-h.y,G.x-M.x,G.y-M.y,ae)){const ye=n.plusScaled(d,ae.x),F=n.plusScaled(h,ae.y),R=X.createOriginAndMatrixColumns(ye,d,u,v.unitZ()),V=X.createOriginAndMatrixColumns(F,h,g,v.unitZ());S.tryTransformInPlace(R),A.tryTransformInPlace(V);const ne=S.fractionToPointAndUnitTangent(1),Xe=A.fractionToPointAndUnitTangent(1);Xe.direction.scaleInPlace(-1);const dt=ne.direction.angleToXY(Xe.direction);_<0&&dt.setRadians(-dt.radians);const Gt=dn.createArcPointTangentRadius(ne.origin,ne.direction,_,void 0,dt);return Gt===void 0?void 0:[S,Gt,A]}}static planePlaneIntersectionRay(e,t){const n=e.altitudeXYZ(0,0,0),i=t.altitudeXYZ(0,0,0),s=e.normalX(),r=e.normalY(),a=e.normalZ(),o=t.normalX(),c=t.normalY(),d=t.normalZ(),h=f.crossProductXYXY(r,a,c,d),u=f.crossProductXYXY(a,s,d,o),g=f.crossProductXYXY(s,r,o,c),m=Le.linearSystem3d(s,r,a,o,c,d,h,u,g,-n,-i,0);if(m!==void 0)return q.createXYZUVW(m.x,m.y,m.z,h,u,g)}}class ar extends $i{_perpVector;_maxDistance;_localToWorld;constructor(e){super(),this._perpVector=v.createZero(),this._maxDistance=0,this._localToWorld=e.toRigidZFrame()}_localPoint=y.create();_worldPoint=y.create();announcePoint(e){this._localToWorld.multiplyInversePoint3d(e,this._localPoint);const t=this._localPoint.magnitudeXY();t>=this._maxDistance&&(this._maxDistance=t,this._perpVector.setFromPoint3d(this._localPoint),this._perpVector.z=0,this._localToWorld.matrix.multiplyXY(this._localPoint.x,this._localPoint.y,this._perpVector))}handleLineSegment3d(e){this.announcePoint(e.startPoint(this._worldPoint)),this.announcePoint(e.endPoint(this._worldPoint))}handleLineString3d(e){for(let t=0;t<e.numPoints();t++)e.pointAt(t,this._worldPoint),this.announcePoint(this._worldPoint)}handleArc3d(e){const t=st.applyAngleTol(void 0,3,e.sweep.sweepRadians,.1),n=1/t;for(let i=0;i<=t;i++)e.fractionToPoint(i*n,this._worldPoint),this.announcePoint(this._worldPoint)}static computeMaxVectorFromRay(e,t){const n=new ar(e);return t.dispatchToGeometryHandler(n),n._perpVector.clone()}static buildRotationalNormalsInLineStrings(e,t,n){if(e instanceof N){const i=e.packedPoints,s=e.packedDerivatives,r=e.ensureEmptySurfaceNormals();if(s&&r){const a=v.create(),o=v.create(),c=y.create(),d=i.length;for(let h=0;h<d;h++)i.getPoint3dAtUncheckedPointIndex(h,c),t.perpendicularPartOfVectorToTarget(c,a),a.isAlmostZero?t.direction.crossProduct(n,o):t.direction.crossProduct(a,o),e.packedDerivatives.getVector3dAtCheckedVectorIndex(h,a),a.crossProduct(o,o),o.normalizeInPlace(),r.push(o)}}else if(e.children){const i=e.children;for(const s of i)this.buildRotationalNormalsInLineStrings(s,t,n)}}}class Ao{startSweeps(e,t,n){return!0}endSweeps(e,t,n){return!0}}class id extends Ao{myMap;constructor(){super(),this.myMap=pn.createWithComponentIndex()}startPass(e){return e===0?(this.myMap.numStroke=0,!0):e===1}visit(e,t){return e===0?(t.numStroke>this.myMap.numStroke&&(this.myMap.numStroke=t.numStroke),!0):e===1?(t.numStroke=this.myMap.numStroke,!0):!1}endPass(e){return!0}}class sd extends Ao{maxCurveLength;constructor(){super(),this.maxCurveLength=0}startPass(e){return e===0?(this.maxCurveLength=0,!0):e===1}visit(e,t){return e===0?(this.maxCurveLength=f.maxXY(t.curveLength,this.maxCurveLength),!0):e===1?(t.a0=0,t.a1=this.maxCurveLength,!0):!1}endPass(e){return!0}}class or{maps;parent;options;constructor(e,t){this.parent=e,this.maps=[],this.options=t}static create(e,t){const n=new or(e,t);n.parent=e;for(const i of e.children)i.computeAndAttachRecursiveStrokeCounts(t),i.strokeData&&n.maps.push(i.strokeData);return n}getStrokes(){const e=N.create();this.options&&(this.options.needNormals||this.options.needParams)&&(e.ensureEmptyFractions(),e.ensureEmptyDerivatives(),e.ensureEmptyUVParams());for(const t of this.maps)t.primitive&&t.primitive.addMappedStrokesToLineString3D(t,e);return e}static applySummed01LimitsWithinArray(e,t){let n=t;for(const i of e)i.a0+=n,i.componentData?i.a1=this.applySummed01LimitsWithinArray(i.componentData,i.a0):i.a1+=n,n=i.a1;return n}applySummed01Limits(e){return or.applySummed01LimitsWithinArray(this.maps,e)}}class Hn{chains;parent;constructor(e){this.parent=e,this.chains=[]}static create(e,t){const n=new Hn(e),i=r=>n.chains.push(or.create(r,t)),s=r=>{for(const a of r.children)i(a)};if(e instanceof Et)for(const r of e.children)r instanceof He?s(r):i(r);else e instanceof He?s(e):e instanceof mt&&i(e);return n}static areSectionsCompatible(e,t){if(e.length<2)return!0;const n=e[0].chains.length;for(let i=1;i<e.length;i++){if(e[i].chains.length!==n)return!1;for(let s=0;s<n;s++){const r=e[0].chains[s].maps.length;if(e[i].chains[s].maps.length!==r)return!1;for(let a=0;a<r;a++)if(!e[0].chains[s].maps[a].isCompatibleComponentStructure(e[i].chains[s].maps[a],t))return!1}}return!0}static remapa0a1WithinEachChain(e){for(const t of e)for(const n of t.chains)n.applySummed01Limits(0)}static applyMultipassVisitorCallback(e,t,n,i,s){const r=e.length;if(!s.startSweeps(t,n,i))return!1;for(let a=0;s.startPass(a);a++){for(let o=0;o<r;o++){let c=e[o].chains[t].maps[n];if(c.componentData&&i!==void 0&&(c=c.componentData[i]),!s.visit(a,c))return!1}if(!s.endPass(a))return!1}return s.endSweeps(t,n,i)}static runMultiPassVisitorAtCorrespondingPrimitives(e,t){if(!Hn.areSectionsCompatible(e,!1))return!1;const i=e[0].chains.length;for(let s=0;s<i;s++){const r=e[0].chains[s].maps.length;for(let a=0;a<r;a++){const o=e[0].chains[s].maps[a].componentData?.length??0;if(o>0){for(let c=0;c<o;c++)if(!this.applyMultipassVisitorCallback(e,s,a,c,t))return!1}else if(!this.applyMultipassVisitorCallback(e,s,a,void 0,t))return!1}}return!0}static enforceStrokeCountCompatibility(e){if(e.length<2)return!0;const t=new id;return this.runMultiPassVisitorAtCorrespondingPrimitives(e,t)}static enforceCompatibleDistanceSums(e){if(e.length<2)return!0;const t=new sd;return this.runMultiPassVisitorAtCorrespondingPrimitives(e,t)?(this.remapa0a1WithinEachChain(e),!0):!1}getStrokes(){if(this.chains.length===1)return this.chains[0].getStrokes();{const e=He.create();for(const t of this.chains){const n=t.getStrokes();n instanceof N&&e.tryAddChild(oe.create(n))}return e}}static extendDistanceRangeBetweenStrokes(e,t,n){if(e instanceof N){if(t instanceof N&&e.numPoints()===t.numPoints()){const i=e.numPoints(),s=y.create(),r=y.create(),a=e.packedPoints,o=t.packedPoints;for(let c=0;c<i;c++)a.getPoint3dAtCheckedPointIndex(c,s),o.getPoint3dAtCheckedPointIndex(c,r),n.extendX(s.distance(r));return!0}}else if(e instanceof He){if(t instanceof He){const i=e.children,s=t.children,r=i.length;if(r===s.length){for(let a=0;a<r;a++)if(!this.extendDistanceRangeBetweenStrokes(i[a],s[a],n))return!1;return!0}}}else if(e instanceof mt&&t instanceof mt){const i=e.children,s=t.children,r=i.length;if(r===s.length){for(let a=0;a<r;a++)if(!this.extendDistanceRangeBetweenStrokes(i[a],s[a],n))return!1;return!0}}return!1}}class wo{static sampledRangeOfOffsetPatch(e,t,n,i){const s=ie.createNull();n=Math.ceil(f.clamp(n,2,500)),i=Math.ceil(f.clamp(i,2,500));const r=1/n,a=1/i,o=y.create(),c=ke.createXYPlane();let d,h;for(let u=0;u<=i;u++){h=u*a;for(let g=0;g<=n;g++)if(d=g*r,t!==void 0){e.uvFractionToPointAndTangents(d,h,c);const m=c.unitNormal();m!==void 0&&(c.origin.addScaledInPlace(m,t),s.extend(c.origin))}else e.uvFractionToPoint(d,h,o),s.extendXYZ(o.x,o.y,o.z)}return s}static sampledRangeOfOffsetEllipsoidPatch(e,t,n){const i=st.applyAngleTol(n,2,e.latitudeSweep.sweepRadians,T.degreesToRadians(5)),s=st.applyAngleTol(n,2,e.longitudeSweep.sweepRadians,T.degreesToRadians(5));return this.sampledRangeOfOffsetPatch(e,t,i,s)}constructor(){}static createLinestringOnUVLine(e,t,n,i,s,r,a=!1,o=!1){const c=N.create(),d=y.create();let h,u,g;const m=r+1;for(let p=0;p<m;p++)h=p/r,u=f.interpolate(t,h,i),g=f.interpolate(n,h,s),e.uvFractionToPoint(u,g,d),c.addPoint(d),a&&c.addUVParamAsUV(u,g),o&&c.addFraction(h);return c}}class cr{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 e=[];for(const t of this.points)e.push(t.clone());return e}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=[[cr.primaryCapId,0],[cr.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 rd{points;begin;end;constructor(e,t,n){this.points=e,this.begin=t,this.end=n}static createComplete(e){return new this(e,0,e.length)}static createBeginEnd(e,t,n){return new this(e,t,n)}static createBeginLength(e,t,n){return new this(e,t,t+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(e){if(e>=0){const t=this.begin+e;if(t<this.points.length)return t}}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(e){return this.begin=e.end-1,this.isNonEmpty}advanceToHead(e){return this.begin=e.begin,this.isNonEmpty}setFrom(e,t,n){this.points=e.points,this.begin=t===void 0?e.begin:t,this.end=n===void 0?e.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 dr extends rd{}class qt extends Ie{_quality;_isValid;id;constructor(e,t,n,i,s,r){super(e,t,n),this._isValid=r,this._quality=s,this.id=i}setFrom(e){return super.setFrom(e),this._isValid=e._isValid,this._quality=e._quality,this.id=e.id,this}static createFromIndexedXYZ(e,t,n,i,s,r,a,o){o||(o=new qt(y.create(),y.create(),y.create(),a,0,!1)),o.id=a;let c=0;return e.getPoint3dAtCheckedPointIndex(t,o.points[0])!==void 0&&c++,n.getPoint3dAtCheckedPointIndex(i,o.points[1])!==void 0&&c++,s.getPoint3dAtCheckedPointIndex(r,o.points[2])!==void 0&&c++,c===3?o.updateAspectRatio():o.markInvalid(),o}get isValid(){return this._isValid}markInvalid(e){this._isValid=!1,e!==void 0&&(this._quality=e)}updateAspectRatio(){this._quality=super.aspectRatio,this._isValid=this._quality>0}clone(e){return e?e.setFrom(this):new qt(this.points[0].clone(),this.points[1].clone(),this.points[2].clone(),this.id,this._quality,this._isValid)}static copyWithLowerQuality(e,t,n){if(n=e.clone(n),t.isValid){const i=e.dotProductOfCrossProductsFromOrigin(t);n._quality=f.minXY(e.aspectRatio,t.aspectRatio),i<0&&(n._quality-=1)}return n}static updateIfOtherHasHigherQuality(e,t){t.isValid&&t._quality>e._quality&&e.setFrom(t)}}class va{_vector1;constructor(e){this._turnRadians=e,this._xyzA=y.create(),this._xyzB=y.create(),this._forwardA=v.create(),this._forwardB=v.create(),this._vector1=v.create(),this._crossA=v.create(),this._crossB=v.create()}_turnRadians;isForwardVector(e,t,n){if(e.dotProduct(t)<=0)return!1;const i=e.angleFromPerpendicular(n);return!(Math.abs(i.radians)>this._turnRadians)}isPlanarBase(e,t,n,i,s,r,a,o,c,d){return t+1<e.length&&i+1<n.length&&(e.getPoint3dAtUncheckedPointIndex(t,s),n.getPoint3dAtUncheckedPointIndex(i,o),e.vectorXYAndZIndex(s,t+1,a),n.vectorXYAndZIndex(o,i+1,d),v.createStartEnd(s,o,this._vector1),this._vector1.crossProduct(a,r),this._vector1.crossProduct(d,c),!s.isAlmostEqual(o)&&r.angleTo(c).radians<this._turnRadians)}advanceToPlanarLimit(e,t,n,i,s,r,a,o){for(t.setFrom(e,e.begin,n);t.end<e.end&&(t.points.vectorXYAndZIndex(i,t.end,this._vector1),!(!this.isForwardVector(this._vector1,r,s)||!this.isForwardVector(this._vector1,o,a)||t.end>0&&(t.points.vectorIndexIndex(t.end-1,t.end,this._vector1),!this.isForwardVector(this._vector1,r,s))));)t.end++}_triangleA1;_triangleB1;_triangleA2;_triangleB2;_triangleA3;_triangleB3;_bestTriangle;_workTriangle;addGreedy(e,t,n,i=!1){for(e.restrictEnd(),t.restrictEnd();e.length>1&&t.length>1;)if(this._triangleA1=qt.createFromIndexedXYZ(e.points,e.begin,e.points,e.begin+1,t.points,t.begin,1,this._triangleA1),this._triangleA2=qt.createFromIndexedXYZ(e.points,e.begin+1,e.points,e.begin+2,t.points,t.begin,2,this._triangleA2),this._triangleA3=qt.createFromIndexedXYZ(e.points,e.begin,e.points,e.begin+1,t.points,t.begin+1,3,this._triangleA3),this._triangleB1=qt.createFromIndexedXYZ(t.points,t.begin+1,t.points,t.begin,e.points,e.begin,-1,this._triangleB1),this._triangleB2=qt.createFromIndexedXYZ(t.points,t.begin+2,t.points,t.begin+1,e.points,e.begin,-2,this._triangleB2),this._triangleB3=qt.createFromIndexedXYZ(t.points,t.begin+1,t.points,t.begin,e.points,e.begin+1,-3,this._triangleB3),this._bestTriangle=qt.copyWithLowerQuality(this._triangleA1,this._triangleB3,this._bestTriangle),this._workTriangle=qt.copyWithLowerQuality(this._triangleB1,this._triangleA3,this._workTriangle),qt.updateIfOtherHasHigherQuality(this._bestTriangle,this._workTriangle),this._bestTriangle.id>0){if(e.advanceBegin(),n(this._bestTriangle),i)return}else if(t.advanceBegin(),n(this._bestTriangle),i)return;if(e.isSingleton)for(;t.length>=2;)this._workTriangle=qt.createFromIndexedXYZ(t.points,t.begin+1,t.points,t.begin,e.points,e.begin,0,this._workTriangle),n(this._workTriangle),t.advanceBegin();if(t.isSingleton)for(;e.length>=2;)this._workTriangle=qt.createFromIndexedXYZ(e.points,e.begin,e.points,e.begin+1,t.points,t.begin,0,this._workTriangle),n(this._workTriangle),e.advanceBegin()}_xyzA;_xyzB;_forwardA;_forwardB;_crossA;_crossB;emitTriangles(e,t,n){this.emitTrianglesGo(bo(e),bo(t),n)}emitTrianglesGo(e,t,n){const i=dr.createComplete(e),s=dr.createComplete(t),r=dr.createComplete(e),a=dr.createComplete(t);for(;i.length>0&&s.length>0&&(i.length>1||s.length>1);)this.isPlanarBase(e,i.begin,t,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,a,s.begin+1,this._xyzB,this._crossB,this._forwardB,this._crossA,this._forwardA),this.addGreedy(r,a,n),i.advanceToTail(r),s.advanceToTail(a)):this.isPlanarBase(e,i.begin+1,t,s.begin,this._xyzA,this._crossA,this._forwardA,this._xyzB,this._crossB,this._forwardB)?(r.setFrom(i,i.begin,i.begin+2),a.setFrom(s,s.begin,s.begin+1),this.addGreedy(r,a,n),i.advanceToTail(r),s.advanceToTail(a)):this.isPlanarBase(e,i.begin,t,s.begin+1,this._xyzA,this._crossA,this._forwardA,this._xyzB,this._crossB,this._forwardB)?(r.setFrom(i,i.begin,i.begin+1),a.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,a,n),i.advanceToTail(r),s.advanceToTail(a)):i.length>1&&s.length>1?(r.setFrom(i,i.begin,i.begin+2),a.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,a,n,!0),i.advanceToHead(r),s.advanceToHead(a)):i.length>1?(r.setFrom(i,i.begin,i.begin+2),a.setFrom(s),this.addGreedy(r,a,n),i.advanceToTail(r),s.advanceToTail(a)):s.length>1&&(r.setFrom(i),a.setFrom(s,s.begin,s.begin+2),this.addGreedy(r,a,n),i.advanceToTail(r),s.advanceToTail(a));this.addGreedy(i,s,n)}static defaultNearColinearAngle=T.createDegrees(15);static createContext(e=this.defaultNearColinearAngle){return new va(e.radians)}}function bo(l,e=f.smallMetricDistance){let t=!1;const n=l.length;for(let r=0;r+1<n;r++)if(l.distanceUncheckedIndexIndex(r,r+1)<=e){t=!0;break}if(!t)return l;const i=new J(n);i.pushXYZ(l.getXAtUncheckedPointIndex(0),l.getYAtUncheckedPointIndex(0),l.getZAtUncheckedPointIndex(0));let s=0;for(let r=1;r<n;r++)l.distanceUncheckedIndexIndex(s,r)>e&&(i.pushXYZ(l.getXAtUncheckedPointIndex(r),l.getYAtUncheckedPointIndex(r),l.getZAtUncheckedPointIndex(r)),s=r);return l.distanceUncheckedIndexIndex(0,n-1)<=e&&(i.pop(),i.pushFromGrowableXYZArray(i,0)),i}function To(l,e){return Array.isArray(l)?l[e]:l(e)}function Kn(l,e){if(e!==void 0)if(Array.isArray(e)){if(l<e.length)return e[l]}else return e}function Co(l){return l!==void 0?Array.isArray(l)?l.length:1:0}class ad{getIsAborted(){return!1}}class od{getIsAborted(){return!1}getXYOnly(){return!1}}class cd extends od{isRangePairActive(e,t){const n=this.getCurrentDistance();return(this.getXYOnly()?e.distanceToRangeXY(t):e.distanceToRange(t))<=n}}let dd=0;class ls{_range;_appData;_children;_id;constructor(e,t,n){this._range=e,this._appData=t,this._children=n,this._id=dd++}static createCapture(e,t,n){return new ls(e,t,n)}setRange(e){this._range.setFrom(e)}getRange(e){return this._range.clone(e)}getRangeRef(){return this._range}getChildByIndex(e){return Kn(e,this._children)}getAppDataByIndex(e){return Kn(e,this._appData)}getAllChildren(){return this._children}getAllAppData(){return this._appData}getNumChildren(){return Co(this._children)}getNumAppData(){return Co(this._appData)}recurseIntoTree(e){if(e(this))if(Array.isArray(this._children))for(const n of this._children)n.recurseIntoTree(e);else this._children!==void 0&&this._children.recurseIntoTree(e)}searchTopDown(e){if(e.isRangeActive(this._range)){let t;for(let i=0;(t=this.getAppDataByIndex(i))!==void 0;i++)if(e.processAppData(t),e.getIsAborted())return;let n;for(let i=0;(n=this.getChildByIndex(i))!==void 0;i++)n.searchTopDown(e)}}static processAppDataAndAppDataStack(e,t,n,i){if(e!==void 0){let s,r;for(let a=t.length;a-- >0;){const o=t[a]._appData;for(let c=0;(r=Kn(c,o))!==void 0;c++)for(let d=0;(s=Kn(d,e))!==void 0;d++)if(n?i.processAppDataPair(r,s):i.processAppDataPair(s,r),i.getIsAborted())return}}}static processAppDataAndAppData(e,t,n,i){if(e!==void 0&&t!==void 0){let s,r;for(let a=0;(r=Kn(a,t))!==void 0;a++)for(let o=0;(s=Kn(o,e))!==void 0;o++)if(n?i.processAppDataPair(r,s):i.processAppDataPair(s,r),i.getIsAborted())return}}static pushPaths(e,t,n){t.push(e),e._appData!==void 0&&n.push(e)}static popPaths(e,t,n){t[t.length-1],t.pop(),e._appData!==void 0&&n.pop()}static recursivePairSearch(e,t,n,i,s,r,a){const o=e._appData!==void 0,c=i._appData!==void 0;let d,h;if(o&&r.length>0&&this.processAppDataAndAppDataStack(e._appData,r,!1,a),n.length>0&&c&&this.processAppDataAndAppDataStack(i._appData,n,!0,a),a.isRangePairActive(e._range,i._range))if(this.processAppDataAndAppData(e._appData,i._appData,!1,a),e._children!==void 0&&i._children!==void 0){this.pushPaths(e,t,n),this.pushPaths(i,s,r);for(let u=0;(d=Kn(u,e._children))!==void 0;u++)for(let g=0;(h=Kn(g,i._children))!==void 0;g++)this.recursivePairSearch(d,t,n,h,s,r,a);this.popPaths(e,t,n),this.popPaths(i,s,r)}else e._children!==void 0?this.leftRecursivePairSearch(e,i,r,!1,a):i._children!==void 0&&this.leftRecursivePairSearch(i,e,n,!0,a)}static leftRecursivePairSearch(e,t,n,i,s){t._children;let r;for(let a=0;(r=Kn(a,e._children))!==void 0;a++)s.isRangePairActive(r._range,t._range)&&(this.processAppDataAndAppData(r._appData,t._appData,i,s),this.processAppDataAndAppDataStack(r._appData,n,i,s),this.leftRecursivePairSearch(r,t,n,i,s))}static searchTwoTreesTopDown(e,t,n){this.recursivePairSearch(e,[],[],t,[],[],n)}}class lr{static getRecursiveNodeCount(e){let t=0;return e.recurseIntoTree(n=>(t++,!0)),t}static getRecursiveAppDataCount(e){let t=0;return e.recurseIntoTree(n=>(t+=n.getNumAppData(),!0)),t}static createLeafInIndexRange(e,t,n,i,s){const r=[],a=ie.createNull();i=Math.min(i,s);for(let o=n;o<i;o++)r.push(To(t,o)),a.extendRange(To(e,o));return ls.createCapture(a,r,void 0)}static createRecursiveByIndexSplits(e,t,n,i,s,r,a){i>s&&(i=s);const o=ie.createNull(),c=[],d=r*a;if(i<=n+d)for(let h=n+a;n<i;n=h,h=Math.min(h+a,i)){const u=lr.createLeafInIndexRange(e,t,n,h,s);u!==void 0&&(o.extendRange(u.getRangeRef()),c.push(u))}else{const h=Math.ceil((i-n)/r);for(let u=n+h;n<i;n=u,u=Math.min(u+h,i)){const g=this.createRecursiveByIndexSplits(e,t,n,u,s,r,a);g!==void 0&&(o.extendRange(g.getRangeRef()),c.push(g))}}return c.length>0?ls.createCapture(o,void 0,c):void 0}static createByIndexSplits(e,t,n,i=2,s=2){if(!(n<=0||Array.isArray(e)&&e.length!==n||Array.isArray(t)&&t.length!==n))return i<2&&(i=2),lr.createRecursiveByIndexSplits(e,t,0,n,n,i,s)}}class hr{itemAtMinValue;minValue;triggerForSavingToArray;savedItems=[];savedValues=[];constructor(e){this.resetMinValueAndItem(void 0,void 0),this.resetTriggerValueForSavingToArray(e,!1)}static create(e){return new hr(e)}resetMinValueAndItem(e=void 0,t=void 0){this.itemAtMinValue=e,this.minValue=t}resetTriggerValueForSavingToArray(e,t=!1){this.triggerForSavingToArray=e,t&&(this.savedItems=[],this.savedValues=[])}testAndSave(e,t){return this.doesValueTrigger(t)&&(this.savedValues.push(t),this.savedItems.push(e)),this.isNewMinValue(t)?(this.minValue=t,this.itemAtMinValue=e,!0):!1}doesValueTrigger(e){return this.triggerForSavingToArray!==void 0&&e<=this.triggerForSavingToArray}isNewMinValue(e){return this.minValue===void 0||e<this.minValue}isNewMinOrTrigger(e){return this.isNewMinValue(e)||this.doesValueTrigger(e)}}class ld extends ad{context;searchState;spacePoint;searchFacetInterior;constructor(e,t,n,i=!1){super(),this.context=t,n!==void 0&&n<0&&(n=void 0),this.searchState=hr.create(n),this.spacePoint=y.createFrom(e),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(e){const t=e.distanceToPoint(this.spacePoint);return this.searchState.isNewMinValue(t)?(this.context.numRangeTestTrue++,!0):(this.context.numRangeTestFalse++,!1)}processAppData(e){if(this.context.visitor.setNumWrap(0),this.context.visitor.moveToReadIndex(e)){let t;if(this.searchFacetInterior?t=re.closestPoint(this.context.visitor.point,this.spacePoint):t=re.closestPointOnBoundary(this.context.visitor.point,this.spacePoint),this.context.numFacetTest++,t&&this.searchState.isNewMinOrTrigger(t.a)){const n=this.context.visitor.pointCount,i=this.context.convexFacets?ci.createCapture(this.context.visitor.currentReadIndex(),n,t):Gn.createCapture(this.context.visitor.currentReadIndex(),n,t);this.searchState.testAndSave(i,t.a)}}}}class hd extends cd{contextA;contextB;searchState;searchFacetInterior;constructor(e,t,n,i=!1){super(),this.contextA=e,this.contextB=t,n!==void 0&&n<0&&(n=void 0),this.searchState=hr.create(n),this.searchFacetInterior=i&&e.convexFacets&&t.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 e=this.searchState.minValue;return e===void 0?Number.MAX_VALUE:e}processAppDataPair(e,t){if(this.contextA.visitor.setNumWrap(1),this.contextB.visitor.setNumWrap(1),this.contextA.visitor.moveToReadIndex(e)&&this.contextB.visitor.moveToReadIndex(t)){const n=re.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=ga.create(this.contextA.convexFacets?ci.createCapture(e,i,n.detailA):Gn.createCapture(e,i,n.detailA),this.contextB.convexFacets?ci.createCapture(t,s,n.detailB):Gn.createCapture(t,s,n.detailB));this.searchState.testAndSave(r,r.detailA.a)}}}}class Sa{visitor;convexFacets;numRangeTestTrue;numRangeTestFalse;numFacetTest;numSearch;_rangeTreeRoot;constructor(e,t,n=!1){this.visitor=t,this.convexFacets=n,this._rangeTreeRoot=e,this.numRangeTestTrue=0,this.numRangeTestFalse=0,this.numFacetTest=0,this.numSearch=0}static createCapture(e,t=4,n=4,i=!1){if(e instanceof be)return this.createCapture(e.createVisitor(0),t,n,i);const s=Ee.visitorClientFacetCount(e),r=lr.createByIndexSplits(a=>(e.moveToReadIndex(a),e.range()),a=>a,s,t,n);return r?new Sa(r,e,i):void 0}searchForClosestPoint(e,t,n=!1){const i=new ld(e,this,t,n);this.numSearch++;const s=Ee.visitorClientFacetCount(this.visitor),r=f.clamp(Math.floor(s/20),2,7),a=Math.floor(s/r);i.processAppData(0),i.processAppData(s-1);for(let o=a;o+1<s;o+=a)i.processAppData(o);return this._rangeTreeRoot.searchTopDown(i),i.searchState.savedItems.length<=1?i.getResult():i.getSavedItems()}static searchForClosestApproach(e,t,n,i=!1){const s=new hd(e,t,n,i);return ls.searchTwoTreesTopDown(e._rangeTreeRoot,t._rangeTreeRoot,s),s.searchState.savedItems.length<=1?s.getResult():s.getSavedItems()}}class ln{xyz;xyzIndex;normal;normalIndex;uv;uvIndex;sectionDerivative;constructor(e=!1,t=!1,n=!1){this.xyz=y.create(),this.normalIndex=-1,this.uvIndex=-1,this.xyzIndex=-1,e&&(this.normal=v.create()),t&&(this.uv=L.create(),this.uvIndex=-1),n&&(this.sectionDerivative=v.create())}copyContentsFrom(e){this.xyz.setFromPoint3d(e.xyz),this.xyzIndex=e.xyzIndex,this.normal&&this.normal.setFromVector3d(e.normal),this.normalIndex=e.normalIndex,this.uv&&this.uv.setFrom(e.uv),this.uvIndex=e.uvIndex,this.sectionDerivative&&this.sectionDerivative.setFrom(e.sectionDerivative)}loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(e,t,n,i,s){t.getPoint3dAtCheckedPointIndex(e,this.xyz),this.uv&&i&&s!==void 0&&this.uv.set(i.atUncheckedIndex(e),s),this.xyzIndex=-1,this.normalIndex=-1,this.uvIndex=-1,this.sectionDerivative!==void 0&&n!==void 0&&n.getVector3dAtCheckedVectorIndex(e,this.sectionDerivative)}static suppressSmallUnitVectorComponents(e){const t=f.smallFloatingPoint;Math.abs(e.x)<t&&(e.x=0),Math.abs(e.y)<t&&(e.y=0),Math.abs(e.z)<t&&(e.z=0)}static _edgeVector=v.create();static computeNormalsAlongRuleLine(e,t){if(e.sectionDerivative&&t.sectionDerivative&&e.normal&&t.normal){const n=ln._edgeVector;v.createStartEnd(e.xyz,t.xyz,n),e.sectionDerivative.crossProduct(n,e.normal),t.sectionDerivative.crossProduct(n,t.normal),e.normal.normalizeInPlace(),t.normal.normalizeInPlace(),ln.suppressSmallUnitVectorComponents(e.normal),ln.suppressSmallUnitVectorComponents(t.normal)}}}class ce extends zs{_polyface;_options;get options(){return this._options}_reversed;get reversedFlag(){return this._reversed}claimPolyface(e=!0,t=f.smallMetricDistance){return e&&this._polyface.data.compress(t),this._polyface}toggleReversedFacetFlag(){this._reversed=!this._reversed}constructor(e){super(),this._options=e||st.createForFacets(),this._polyface=_n.create(this._options.needNormals,this._options.needParams,this._options.needColors,this._options.needTwoSided),this._reversed=!1}static create(e){return new ce(e)}addTransformedUnitBox(e){this.addTransformedRangeMesh(e,ie.createXYZXYZ(0,0,0,1,1,1))}addTransformedRangeMesh(e,t,n){const i=this._polyface.data.pointCount,s=t.corners();for(const a of s)this._polyface.addPoint(e.multiplyPoint3d(a));let r=0;for(const a of cr.cornerIndexCCW){if(!n||r<n.length&&n[r]){const o=a.map(c=>c+i);this._reversed&&o.reverse(),this._options.shouldTriangulate?(this.addIndexedTrianglePointIndexes(o[0],o[1],o[2],!1),this.addIndexedTrianglePointIndexes(o[0],o[2],o[3],!1)):this.addIndexedQuadPointIndexes(o[0],o[1],o[3],o[2],!1),this._polyface.terminateFacet()}r++}}addTriangleFan(e,t,n){const i=t.numPoints();if(i>2){n&&this.toggleReversedFacetFlag();const s=this.addPoint(e);let r=this.findOrAddPointInLineStringUnchecked(t,0),a=0;for(let o=1;o<i;o++)a=this.findOrAddPointInLineStringUnchecked(t,o),this.addIndexedTrianglePointIndexes(s,r,a),r=a;n&&this.toggleReversedFacetFlag()}}addTrianglesInUncheckedConvexPolygon(e,t){const n=e.numPoints();if(n>2){t&&this.toggleReversedFacetFlag();let i,s;this._options.needNormals&&(i=e.quickUnitNormal(ce._workVectorFindOrAdd),i&&(t&&i.scaleInPlace(-1),s=this._polyface.addNormal(i)));const a=this._options.needParams?e.packedUVParams:void 0;let o=-1,c=-1,d=-1;a&&(o=this.addParamInGrowableXYArrayUnchecked(a,0),c=this.addParamInGrowableXYArrayUnchecked(a,1));const h=this.findOrAddPointInLineStringUnchecked(e,0);let u=this.findOrAddPointInLineStringUnchecked(e,1),g=0,m=n;e.isPhysicallyClosed&&m--;for(let p=2;p<m;p++,u=g,c=d)g=this.findOrAddPointInLineStringUnchecked(e,p),this.addIndexedTrianglePointIndexes(h,u,g,!1),s!==void 0&&this.addIndexedTriangleNormalIndexes(s,s,s),a&&(d=this.addParamInGrowableXYArrayUnchecked(a,p),this.addIndexedTriangleParamIndexes(o,c,d)),this._polyface.terminateFacet();t&&this.toggleReversedFacetFlag()}}addPoint(e){return this._polyface.addPoint(e)}addParamXY(e,t){return this._polyface.addParamUV(e,t)}static _workPointFindOrAddA=y.create();static _workVectorFindOrAdd=v.create();static _workUVFindOrAdd=L.create();findOrAddPointInLineStringUnchecked(e,t,n,i){const s=e.pointAtUnchecked(t,ce._workPointFindOrAddA);return n&&n.multiplyPoint3d(s,s),this._polyface.addPoint(s,i)}findOrAddPointInLineString(e,t,n,i){if(e.packedPoints.isIndexValid(t))return this.findOrAddPointInLineStringUnchecked(e,t,n,i)}findOrAddPointInGrowableXYZArrayUnchecked(e,t,n,i){const s=e.getPoint3dAtUncheckedPointIndex(t,ce._workPointFindOrAddA);return n&&n.multiplyPoint3d(s,s),this._polyface.addPoint(s,i)}findOrAddPointInGrowableXYZArray(e,t,n,i){if(e.isIndexValid(t))return this.findOrAddPointInGrowableXYZArrayUnchecked(e,t,n,i)}findOrAddNormalInGrowableXYZArrayUnchecked(e,t,n,i){const s=e.getVector3dAtUncheckedVectorIndex(t,ce._workVectorFindOrAdd);return n&&n.multiplyVector(s,s),this._polyface.addNormal(s,i)}findOrAddNormalInGrowableXYZArray(e,t,n,i){if(e.isIndexValid(t))return this.findOrAddNormalInGrowableXYZArrayUnchecked(e,t,n,i)}addParamInGrowableXYArrayUnchecked(e,t){const n=e.getPoint2dAtUncheckedPointIndex(t,ce._workUVFindOrAdd);return this._polyface.addParam(n)}addParamInGrowableXYArray(e,t){if(e.isIndexValid(t))return this.addParamInGrowableXYArrayUnchecked(e,t)}findOrAddParamInLineString(e,t,n,i,s){const r=e.fractions?.atIndex(t)??t/e.points.length;return this._polyface.addParamUV(r,n,i,s)}findOrAddNormalInLineString(e,t,n,i,s){const r=e.packedSurfaceNormals;if(r){const a=r.getVector3dAtCheckedVectorIndex(t,ce._workVectorFindOrAdd);if(a)return n&&n.multiplyVector(a,a),this._polyface.addNormal(a,i,s)}}addPointXYZ(e,t,n){return this._polyface.addPointXYZ(e,t,n)}static _workVector0;static _workVector1;getUVTransformForTriangleFacet(e,t,n,i){const s=ce._workVector0=e.vectorTo(t,ce._workVector0),r=ce._workVector1=e.vectorTo(n,ce._workVector1);return X.createRigidFromOriginAndColumns(e,s,r,ve.XYZ,i)}getNormalForTriangularFacet(e,t,n,i){const s=e.crossProductToPoints(t,n,i);return s.tryNormalizeInPlace()?s:v.createZero(i)}static _workUV0;static _workUV1;static _workUV2;static _workUV3;static _workNormal0;static _workNormal1;static _workNormal2;static _workNormal3;static _workTransform;addQuadFacet(e,t,n,i){if(e.length<4)return;e instanceof J&&(e=e.getPoint3dArray());const s=this.options.needParams,r=this.options.needNormals,a=this.options.needColors,o=ce._workUV0=L.createZero(ce._workUV0),c=ce._workUV1=L.createZero(ce._workUV1),d=ce._workUV2=L.createZero(ce._workUV2),h=ce._workUV3=L.createZero(ce._workUV3),u=ce._workNormal0=v.createZero(ce._workNormal0),g=ce._workNormal1=v.createZero(ce._workNormal1),m=ce._workNormal2=v.createZero(ce._workNormal2),p=ce._workNormal3=v.createZero(ce._workNormal3);let x=0,_=0,I=0,S=0;if(s)if(t&&t.length>3)o.setFrom(t[0]),c.setFrom(t[1]),d.setFrom(t[2]),h.setFrom(t[3]);else{const P=ce._workTransform=this.getUVTransformForTriangleFacet(e[0],e[1],e[3],ce._workTransform);P&&(P.multiplyInversePoint3dAsPoint2d(e[0],o),P.multiplyInversePoint3dAsPoint2d(e[1],c),P.multiplyInversePoint3dAsPoint2d(e[2],d),P.multiplyInversePoint3dAsPoint2d(e[3],h))}if(r&&(n&&n.length>3?(u.setFrom(n[0]),g.setFrom(n[1]),m.setFrom(n[2]),p.setFrom(n[3])):(this.getNormalForTriangularFacet(e[0],e[1],e[2],u),g.setFrom(u),m.setFrom(u),p.setFrom(u))),a&&i&&i.length>3&&(x=i[0],_=i[1],I=i[2],S=i[3]),this._options.shouldTriangulate){const P=e[0].distanceSquared(e[2]),b=e[1].distanceSquared(e[3]);P+f.smallFloatingPoint>=b?(this.addTriangleFacet([e[0],e[1],e[2]],s?[o,c,d]:void 0,r?[u,g,m]:void 0,a?[x,_,I]:void 0),this.addTriangleFacet([e[0],e[2],e[3]],s?[o,d,h]:void 0,r?[u,m,p]:void 0,a?[x,I,S]:void 0)):(this.addTriangleFacet([e[0],e[1],e[3]],s?[o,c,h]:void 0,r?[u,g,p]:void 0,a?[x,_,S]:void 0),this.addTriangleFacet([e[1],e[2],e[3]],s?[c,d,h]:void 0,r?[g,m,p]:void 0,a?[_,I,S]:void 0));return}let A,w,k,D;s&&(A=this._polyface.addParam(o),w=this._polyface.addParam(c),k=this._polyface.addParam(d),D=this._polyface.addParam(h),this.addIndexedQuadParamIndexes(A,w,D,k)),r&&(A=this._polyface.addNormal(u),w=this._polyface.addNormal(g),k=this._polyface.addNormal(m),D=this._polyface.addNormal(p),this.addIndexedQuadNormalIndexes(A,w,D,k)),a&&(A=this._polyface.addColor(x),w=this._polyface.addColor(_),k=this._polyface.addColor(I),D=this._polyface.addColor(S),this.addIndexedQuadColorIndexes(A,w,D,k)),A=this.addPoint(e[0]),w=this.addPoint(e[1]),k=this.addPoint(e[2]),D=this.addPoint(e[3]),this.addIndexedQuadPointIndexes(A,w,D,k)}addIndexedQuadPointIndexes(e,t,n,i,s=!0){this._reversed?(this._polyface.addPointIndex(e),this._polyface.addPointIndex(n),this._polyface.addPointIndex(i),this._polyface.addPointIndex(t)):(this._polyface.addPointIndex(e),this._polyface.addPointIndex(t),this._polyface.addPointIndex(i),this._polyface.addPointIndex(n)),s&&this._polyface.terminateFacet()}addIndexedQuadParamIndexes(e,t,n,i){this._reversed?(this._polyface.addParamIndex(e),this._polyface.addParamIndex(n),this._polyface.addParamIndex(i),this._polyface.addParamIndex(t)):(this._polyface.addParamIndex(e),this._polyface.addParamIndex(t),this._polyface.addParamIndex(i),this._polyface.addParamIndex(n))}addIndexedQuadNormalIndexes(e,t,n,i){this._reversed?(this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(n),this._polyface.addNormalIndex(i),this._polyface.addNormalIndex(t)):(this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(i),this._polyface.addNormalIndex(n))}addIndexedQuadColorIndexes(e,t,n,i){this._reversed?(this._polyface.addColorIndex(e),this._polyface.addColorIndex(n),this._polyface.addColorIndex(i),this._polyface.addColorIndex(t)):(this._polyface.addColorIndex(e),this._polyface.addColorIndex(t),this._polyface.addColorIndex(i),this._polyface.addColorIndex(n))}addTriangleFacet(e,t,n,i){if(e.length<3)return;e instanceof J&&(e=e.getPoint3dArray());let s,r,a;if(this.options.needParams){if(t&&t.length>2)s=this._polyface.addParam(t[0]),r=this._polyface.addParam(t[1]),a=this._polyface.addParam(t[2]);else{const o=ce._workUV0=L.createZero(ce._workUV0),c=ce._workTransform=this.getUVTransformForTriangleFacet(e[0],e[1],e[2],ce._workTransform);c?.multiplyInversePoint3dAsPoint2d(e[0],o),a=r=s=this._polyface.addParam(o),c&&(c.multiplyInversePoint3dAsPoint2d(e[1],o),r=this._polyface.addParam(o),c.multiplyInversePoint3dAsPoint2d(e[2],o),a=this._polyface.addParam(o))}this.addIndexedTriangleParamIndexes(s,r,a)}if(this.options.needNormals){if(n&&n.length>2)s=this._polyface.addNormal(n[0]),r=this._polyface.addNormal(n[1]),a=this._polyface.addNormal(n[2]);else{const o=ce._workNormal0=v.createZero(ce._workNormal0);this.getNormalForTriangularFacet(e[0],e[1],e[2],o),a=r=s=this._polyface.addNormal(o)}this.addIndexedTriangleNormalIndexes(s,r,a)}this.options.needColors&&(i&&i.length>2?(s=this._polyface.addColor(i[0]),r=this._polyface.addColor(i[1]),a=this._polyface.addColor(i[2])):a=r=s=this._polyface.addColor(0),this.addIndexedTriangleColorIndexes(s,r,a)),s=this.addPoint(e[0]),r=this.addPoint(e[1]),a=this.addPoint(e[2]),this.addIndexedTrianglePointIndexes(s,r,a,!0)}addIndexedTrianglePointIndexes(e,t,n,i=!0){this._reversed?(this._polyface.addPointIndex(e),this._polyface.addPointIndex(n),this._polyface.addPointIndex(t)):(this._polyface.addPointIndex(e),this._polyface.addPointIndex(t),this._polyface.addPointIndex(n)),i&&this._polyface.terminateFacet()}addIndexedTriangleParamIndexes(e,t,n){this._reversed?(this._polyface.addParamIndex(e),this._polyface.addParamIndex(n),this._polyface.addParamIndex(t)):(this._polyface.addParamIndex(e),this._polyface.addParamIndex(t),this._polyface.addParamIndex(n))}addIndexedTriangleNormalIndexes(e,t,n){this._reversed?(this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(n),this._polyface.addNormalIndex(t)):(this._polyface.addNormalIndex(e),this._polyface.addNormalIndex(t),this._polyface.addNormalIndex(n))}addIndexedTriangleColorIndexes(e,t,n){this._reversed?(this._polyface.addColorIndex(e),this._polyface.addColorIndex(n),this._polyface.addColorIndex(t)):(this._polyface.addColorIndex(e),this._polyface.addColorIndex(t),this._polyface.addColorIndex(n))}setSectorIndices(e){e.xyzIndex=this.addPoint(e.xyz),e.normal&&(e.normalIndex=this._polyface.addNormal(e.normal)),e.uv&&(e.uvIndex=this._polyface.addParam(e.uv))}addSectorTriangle(e,t,n){e.xyz.isAlmostEqual(t.xyz)||t.xyz.isAlmostEqual(n.xyz)||n.xyz.isAlmostEqual(e.xyz)||(this._options.needNormals&&this.addIndexedTriangleNormalIndexes(e.normalIndex,t.normalIndex,n.normalIndex),this._options.needParams&&this.addIndexedTriangleParamIndexes(e.uvIndex,t.uvIndex,n.uvIndex),this.addIndexedTrianglePointIndexes(e.xyzIndex,t.xyzIndex,n.xyzIndex,!0))}addSectorQuadA01B01(e,t,n,i){e.xyz.isAlmostEqual(t.xyz)&&n.xyz.isAlmostEqual(i.xyz)||(this._options.shouldTriangulate?(this.addSectorTriangle(e,t,i),this.addSectorTriangle(i,n,e)):(this._options.needNormals&&this.addIndexedQuadNormalIndexes(e.normalIndex,t.normalIndex,n.normalIndex,i.normalIndex),this._options.needParams&&this.addIndexedQuadParamIndexes(e.uvIndex,t.uvIndex,n.uvIndex,i.uvIndex),this.addIndexedQuadPointIndexes(e.xyzIndex,t.xyzIndex,n.xyzIndex,i.xyzIndex,!0)))}addBetweenLineStringsWithRuleEdgeNormals(e,t,n,i,s=!1){const r=e.packedPoints,a=n.packedPoints,o=e.packedDerivatives,c=n.packedDerivatives,d=e.fractions,h=n.fractions,u=this._options.needNormals,g=this._options.needParams,m=new ln(u,g,u),p=new ln(u,g,u),x=new ln(u,g,u),_=new ln(u,g,u),I=new ln(u,g,u),S=new ln(u,g,u),A=r.length;if(!(A<2||A!==a.length)){m.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(0,r,o,d,t),x.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(0,a,c,h,i),u&&ln.computeNormalsAlongRuleLine(m,x),this.setSectorIndices(m),this.setSectorIndices(x),I.copyContentsFrom(m),S.copyContentsFrom(x);for(let w=1;w<A;w++)p.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(w,r,o,d,t),_.loadIndexedPointAndDerivativeCoordinatesFromPackedArrays(w,a,o,h,i),ln.computeNormalsAlongRuleLine(p,_),this.setSectorIndices(p),this.setSectorIndices(_),this.addSectorQuadA01B01(m,p,x,_),m.copyContentsFrom(p),x.copyContentsFrom(_);s&&this.addSectorQuadA01B01(m,I,x,S)}}addBetweenLineStringsWithStoredIndices(e,t){const n=e.pointIndices,i=t.pointIndices;if(!n||!i||n.length<2||n.length!==i.length)return;const s=n.length;let r=e.normalIndices,a=t.normalIndices;(!this._options.needNormals||r&&a&&(r.length<s||a.length<s))&&(r=void 0,a=void 0);let o=e.paramIndices,c=t.paramIndices;(!this._options.needParams||o&&c&&(o.length<s||c.length<s))&&(o=void 0,c=void 0);for(let d=1;d<s;d++)this.options.shouldTriangulate?(ko(n.atUncheckedIndex(d-1),n.atUncheckedIndex(d),i.atUncheckedIndex(d))&&(this.addIndexedTrianglePointIndexes(n.atUncheckedIndex(d-1),n.atUncheckedIndex(d),i.atUncheckedIndex(d),!1),r&&a&&this.addIndexedTriangleNormalIndexes(r.atUncheckedIndex(d-1),r.atUncheckedIndex(d),a.atUncheckedIndex(d-1)),o&&c&&this.addIndexedTriangleParamIndexes(o.atUncheckedIndex(d-1),o.atUncheckedIndex(d),c.atUncheckedIndex(d-1))),ko(i.atUncheckedIndex(d),i.atUncheckedIndex(d-1),n.atUncheckedIndex(d-1))&&(this.addIndexedTrianglePointIndexes(n.atUncheckedIndex(d-1),i.atUncheckedIndex(d),i.atUncheckedIndex(d-1),!1),r&&a&&this.addIndexedTriangleNormalIndexes(r.atUncheckedIndex(d-1),a.atUncheckedIndex(d),a.atUncheckedIndex(d-1)),o&&c&&this.addIndexedTriangleParamIndexes(o.atUncheckedIndex(d-1),c.atUncheckedIndex(d),c.atUncheckedIndex(d-1)))):(n.atUncheckedIndex(d-1)!==n.atUncheckedIndex(d)||i.atUncheckedIndex(d-1)!==i.atUncheckedIndex(d))&&(this.addIndexedQuadPointIndexes(n.atUncheckedIndex(d-1),n.atUncheckedIndex(d),i.atUncheckedIndex(d-1),i.atUncheckedIndex(d),!1),r&&a&&this.addIndexedQuadNormalIndexes(r.atUncheckedIndex(d-1),r.atUncheckedIndex(d),a.atUncheckedIndex(d-1),a.atUncheckedIndex(d)),o&&c&&this.addIndexedQuadParamIndexes(o.atUncheckedIndex(d-1),o.atUncheckedIndex(d),c.atUncheckedIndex(d-1),c.atUncheckedIndex(d))),this._polyface.terminateFacet()}addBetweenTransformedLineStrings(e,t,n,i=!1){if(e instanceof N){const s=e.numPoints();if(s>1){let r=this.findOrAddPointInLineStringUnchecked(e,0,t),a=this.findOrAddPointInLineStringUnchecked(e,0,n);const o=r,c=a;let d=0,h=0;for(let u=1;u<s;u++)d=this.findOrAddPointInLineStringUnchecked(e,u,t),h=this.findOrAddPointInLineStringUnchecked(e,u,n),this.addIndexedQuadPointIndexes(r,d,a,h),r=d,a=h;i&&s>2&&this.addIndexedQuadPointIndexes(r,o,a,c)}}else{const s=e.children;if(s)for(const r of s)this.addBetweenTransformedLineStrings(r,t,n)}}addBetweenStrokeSetPair(e,t,n,i){if(e instanceof N&&n instanceof N)this.addBetweenLineStringsWithRuleEdgeNormals(e,t,n,i,!1);else if(e instanceof He&&n instanceof He){if(e.children.length===n.children.length)for(let s=0;s<e.children.length;s++)this.addBetweenStrokeSetPair(e.children[s],t,n.children[s],i)}else if(e instanceof mt&&n instanceof mt){const s=e.children,r=n.children;if(s.length===r.length)for(let a=0;a<s.length;a++){const o=s[a],c=r[a];o instanceof N&&c instanceof N&&this.addBetweenLineStringsWithRuleEdgeNormals(o,t,c,i)}}}addCone(e){let t=16;this._options&&(t=this._options.applyTolerancesToArc(e.getMaxRadius()));let n=1;const i=e.strokeConstantVSection(0,t,this._options),s=e.strokeConstantVSection(1,t,this._options);if(this._options){const a=J.distanceRangeBetweenCorrespondingPoints(i.packedPoints,s.packedPoints);n=this._options.applyMaxEdgeLength(1,a.low)}const r=e.maxIsoParametricDistance();this.addUVGridBody(e,t,n,Je.create(0,r.x),Je.create(0,r.y)),this.endFace(),e.capped&&(f.isSmallMetricDistance(e.getRadiusA())||(this.addTrianglesInUncheckedConvexPolygon(i,!0),this.endFace()),f.isSmallMetricDistance(e.getRadiusB())||(this.addTrianglesInUncheckedConvexPolygon(s,!1),this.endFace()))}addTorusPipe(e,t,n){const i=e.getThetaFraction();let s=f.clamp(f.resolveNumber(t,8),4,64),r=f.clamp(f.resolveNumber(n,Math.ceil(16*i)),2,64);this._options&&(s=this._options.applyTolerancesToArc(e.getMinorRadius()),r=this._options.applyTolerancesToArc(e.getMajorRadius(),e.getSweepAngle().radians)),this.toggleReversedFacetFlag();const a=e.maxIsoParametricDistance();this.addUVGridBody(e,s,r,Je.create(0,a.x),Je.create(0,a.y)),this.toggleReversedFacetFlag();const o=e.getConstructiveFrame();if(o&&e.capped&&i<1){const c=e.getMinorRadius(),d=e.getMajorRadius(),h=2*c,u=d-c,g=d+c,m=-c,p=X.createRowValues(h,0,0,u,0,0,-1,0,0,h,0,m),_=o.multiplyTransformTransform(p).inverse();if(_){const P=wo.createLinestringOnUVLine(e,0,0,1,0,s,!1,!0);P.computeUVFromXYZTransform(_),this.addTrianglesInUncheckedConvexPolygon(P,!1)}const I=e.getSweepAngle().radians,S=Math.cos(I),A=Math.sin(I),w=X.createRowValues(-S*h,0,-A,g*S,-A*h,0,S,g*A,0,h,0,m),D=o.multiplyTransformTransform(w).inverse();if(D){const P=wo.createLinestringOnUVLine(e,1,1,0,1,s,!1,!0);P.computeUVFromXYZTransform(D),this.addTrianglesInUncheckedConvexPolygon(P,!1)}}}addLinearSweepLineStringsXYZOnly(e,t){if(e instanceof N){let n=y.create(),i=y.create(),s=0,r=0,a=0,o=0;const c=e.numPoints();for(let d=0;d<c;d++)n=e.pointAtUnchecked(d,n),i=n.plus(t,i),r=this.addPoint(n),o=this.addPoint(i),d>0&&this.addIndexedQuadPointIndexes(s,r,a,o),s=r,a=o}else if(e instanceof mt)for(const n of e.children)this.addLinearSweepLineStringsXYZOnly(n,t)}addRotationalSweep(e){const t=e.getSweepContourRef(),i=Hn.create(t.getCurves(),this._options).getStrokes(),s=e.cloneAxisRay(),r=e.getSweep();r.radians<0&&(s.direction.scaleInPlace(-1),r.setRadians(-r.radians));const a=ar.computeMaxVectorFromRay(s,i),o=s.direction.crossProduct(a),c=t.localToWorld.matrix.dotColumnZ(o)>0;c||i.reverseInPlace(),this._options.needNormals&&ar.buildRotationalNormalsInLineStrings(i,s,o);const d=a.magnitude(),h=Math.abs(d*r.radians);let u=st.applyAngleTol(this._options,1,r.radians,void 0);u=st.applyMaxEdgeLength(this._options,u,h);for(let g=1;g<=u;g++){const m=e.getFractionalRotationTransform((g-1)/u),p=e.getFractionalRotationTransform(g/u);this.addBetweenRotatedStrokeSets(i,m,g-1,p,g)}if(e.capped){t.purgeFacets();const g=c;t.emitFacets(this,g,void 0),t.emitFacets(this,!g,e.getFractionalRotationTransform(1))}}addTriangulatedRegion(e){const t=Jn.createForLinearSweep(e);t&&t.emitFacets(this,this.reversedFlag,void 0)}applyStrokeCountsToCurvePrimitives(e){const t=this._options;if(e instanceof le)e.computeStrokeCountForOptions(t);else if(e instanceof _e){const n=e.children;if(n)for(const i of n)this.applyStrokeCountsToCurvePrimitives(i)}}addBetweenStrokeSetsWithRuledNormals(e,t,n){const i=[e],s=[0];for(let r=1;r<n;r++){const a=r/n,o=Qs.interpolateBetween(e,r/n,t);i.push(o),s.push(a)}i.push(t),s.push(1);for(let r=0;r<n;r++)this.addBetweenStrokeSetPair(i[r],s[r],i[r+1],s[r+1])}createIndicesInLineString(e,t,n){const i=e.numPoints();if(i<1)return;const s=e.ensureEmptyPointIndices(),r=this.findOrAddPointInLineStringUnchecked(e,0,n);if(s.push(r),i>1){let a=r,o;for(let c=1;c+1<i;c++)o=this.findOrAddPointInLineStringUnchecked(e,c,n,a),s.push(o),a=o;o=this.findOrAddPointInLineStringUnchecked(e,i-1,n,r),s.push(o)}if(this._options.needNormals&&e.packedSurfaceNormals&&e.packedSurfaceNormals.length>=i){const a=e.ensureEmptyNormalIndices(),o=this.findOrAddNormalInLineString(e,0,n);if(a.push(o),i>1){let c=o,d;for(let h=1;h+1<i;h++)d=this.findOrAddNormalInLineString(e,h,n,c),a.push(d),c=d;d=this.findOrAddNormalInLineString(e,i-1,n,o,c),a.push(d)}}if(this._options.needParams){const a=e.ensureEmptyUVIndices(),o=this.findOrAddParamInLineString(e,0,t);if(a.push(o),i>1){let c=o,d;for(let h=1;h+1<i;h++)d=this.findOrAddParamInLineString(e,h,t,c),a.push(d),c=d;d=this.findOrAddParamInLineString(e,i-1,t,c,o),a.push(d)}}}addBetweenRotatedStrokeSets(e,t,n,i,s){if(e instanceof N){const r=e.cloneTransformed(t);this.createIndicesInLineString(r,n);const a=e.cloneTransformed(i);this.createIndicesInLineString(a,s),this.addBetweenLineStringsWithStoredIndices(r,a)}else if(e instanceof He)for(const r of e.children)this.addBetweenRotatedStrokeSets(r,t,n,i,s);else if(e instanceof mt)for(const r of e.children)r instanceof N&&this.addBetweenRotatedStrokeSets(r,t,n,i,s)}addLinearSweep(e){const t=e.getCurvesRef(),i=Hn.create(t,this._options).getStrokes(),s=e.cloneSweepVector(),r=X.createTranslation(s),a=i.cloneTransformed(r),o=this._options.applyMaxEdgeLength(1,s.magnitude());if(this.addBetweenStrokeSetsWithRuledNormals(i,a,o),e.capped&&t.isAnyRegionType){const c=e.getSweepContourRef();c.purgeFacets();const d=c.localToWorld.matrix.dotColumnZ(s)>0;c.emitFacets(this,d,void 0),c.emitFacets(this,!d,r)}}addRuledSweep(e){const t=e.sweepContoursRef();let n,i;const s=[];for(const r of t)s.push(Hn.create(r.curves,this._options));if(Hn.enforceStrokeCountCompatibility(s)){Hn.enforceCompatibleDistanceSums(s);for(let r=0;r<t.length;r++){if(i=s[r].getStrokes(),i||(i=t[r].curves.cloneStroked()),r>0&&n&&i){const a=fe.createNull();if(Hn.extendDistanceRangeBetweenStrokes(n,i,a)&&!a.isNull){const o=this._options.applyMaxEdgeLength(1,a.high);this.addBetweenStrokeSetsWithRuledNormals(n,i,o)}}n=i}}return e.capped&&t[0].curves.isAnyRegionType&&(t[0].purgeFacets(),t[0].emitFacets(this,!0,void 0),t[t.length-1].purgeFacets(),t[t.length-1].emitFacets(this,!1,void 0)),!0}addSphere(e,t){let n=t||this.options.applyTolerancesToArc(e.maxAxisRadius());f.isOdd(n)&&(n+=1);const i=f.clampToStartEnd(Math.abs(n*e.latitudeSweepFraction),1,Math.ceil(n*.5)),s=e.strokeConstantVSection(0,n,this._options);e.capped&&!f.isSmallMetricDistance(s.quickLength())&&(this.addTrianglesInUncheckedConvexPolygon(s,!0),this.endFace());const r=e.maxIsoParametricDistance();this.addUVGridBody(e,n,i,Je.create(0,r.x),Je.create(0,r.y)),this.endFace();const a=e.strokeConstantVSection(1,n,this._options);e.capped&&!f.isSmallMetricDistance(a.quickLength())&&(this.addTrianglesInUncheckedConvexPolygon(a,!1),this.endFace())}addBox(e){const t=e.getCorners(),n=f.maxXY(e.getBaseX(),e.getBaseX()),i=f.maxXY(e.getBaseY(),e.getTopY());let s=0;for(let h=0;h<4;h++)s=f.maxXY(s,t[h].distance(t[h+4]));const r=this._options.applyMaxEdgeLength(1,n),a=this._options.applyMaxEdgeLength(1,i),o=this._options.applyMaxEdgeLength(1,s),c=Je.create(0,n),d=Je.create(0,s);this.addUVGridBody(nn.create(t[0],t[1],t[4],t[5]),r,o,c,d),c.shift(n),this.addUVGridBody(nn.create(t[1],t[3],t[5],t[7]),a,o,c,d),c.shift(i),this.addUVGridBody(nn.create(t[3],t[2],t[7],t[6]),r,o,c,d),c.shift(n),this.addUVGridBody(nn.create(t[2],t[0],t[6],t[4]),a,o,c,d),this.endFace(),e.capped&&(c.set(0,n),d.set(0,i),this.addUVGridBody(nn.create(t[4],t[5],t[6],t[7]),r,a,c,d),this.endFace(),c.set(0,n),d.set(0,i),this.addUVGridBody(nn.create(t[2],t[3],t[0],t[1]),r,a,c,d),this.endFace())}addPolygon(e,t){for(t===void 0&&(t=e.length);t>1&&e[t-1].isAlmostEqual(e[0]);)t--;let n=0;if(this._reversed)for(let i=t;--i>=0;)n=this.addPoint(e[i]),this._polyface.addPointIndex(n);else for(let i=0;i<t;i++)n=this.addPoint(e[i]),this._polyface.addPointIndex(n);this._polyface.terminateFacet()}addPolygonGrowableXYZArray(e){let t=e.length;for(;t>2&&f.isSmallMetricDistance(e.distanceUncheckedIndexIndex(0,t-1));)t--;for(;t>2&&f.isSmallMetricDistance(e.distanceUncheckedIndexIndex(t-2,t-1));)t--;if(t===3){const i=e.crossProductUncheckedIndexIndexIndex(0,1,2).magnitude(),s=e.distanceUncheckedIndexIndex(0,1)+e.distanceUncheckedIndexIndex(0,2)+e.distanceUncheckedIndexIndex(1,2);i<f.smallMetricDistance*s&&(t=0)}if(t>2){let n=0;if(this._reversed)for(let i=t;--i>=0;)n=this.findOrAddPointInGrowableXYZArrayUnchecked(e,i),this._polyface.addPointIndex(n);else for(let i=0;i<t;i++)n=this.findOrAddPointInGrowableXYZArrayUnchecked(e,i),this._polyface.addPointIndex(n);this._polyface.terminateFacet()}}addFacetFromGrowableArrays(e,t,n,i,s){let r=e.length;for(;r>1&&f.isSmallMetricDistance(e.distanceUncheckedIndexIndex(0,r-1));)r--;let a=0;if(t&&t.length<r&&(t=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 o=r;--o>=0;)a=this.findOrAddPointInGrowableXYZArrayUnchecked(e,o),this._polyface.addPointIndex(a),t&&(a=this.findOrAddNormalInGrowableXYZArrayUnchecked(t,o),this._polyface.addNormalIndex(a)),n&&(a=this.addParamInGrowableXYArrayUnchecked(n,o),this._polyface.addParamIndex(a)),i&&(a=this._polyface.addColor(i[o]),this._polyface.addColorIndex(a));else for(let o=0;o<r;o++)a=this.findOrAddPointInGrowableXYZArrayUnchecked(e,o),this._polyface.addPointIndex(a,s?s[o]:!0),t&&(a=this.findOrAddNormalInGrowableXYZArrayUnchecked(t,o),this._polyface.addNormalIndex(a)),n&&(a=this.addParamInGrowableXYArrayUnchecked(n,o),this._polyface.addParamIndex(a)),i&&(a=this._polyface.addColor(i[o]),this._polyface.addColorIndex(a));this._polyface.terminateFacet()}addFacetFromVisitor(e){this.addFacetFromGrowableArrays(e.point,e.normal,e.param,e.color,e.edgeVisible)}addFacetsFromVisitor(e){for(e.reset();e.moveToNextFacet();)this.addFacetFromVisitor(e)}addFacetFromIndexedVisitor(e,t){if(t.length>e.pointIndex.length)return!1;const n=new J(t.length),i=e.normal?new J(t.length):void 0,s=e.param?new Ct(t.length):void 0,r=e.color?new Array(t.length):void 0,a=e.edgeVisible?new Array(t.length):void 0;for(let o=0;o<t.length;++o){const c=t[o];if(c<0||c>=e.point.length)return!1;n.pushXYZ(e.point.getXAtUncheckedPointIndex(c),e.point.getYAtUncheckedPointIndex(c),e.point.getZAtUncheckedPointIndex(c)),e.normal&&i&&i.pushXYZ(e.normal.getXAtUncheckedPointIndex(c),e.normal.getYAtUncheckedPointIndex(c),e.normal.getZAtUncheckedPointIndex(c)),e.param&&s&&s.pushXY(e.param.getXAtUncheckedPointIndex(c),e.param.getYAtUncheckedPointIndex(c)),e.color&&r&&(r[o]=e.color[c]),e.edgeVisible&&a&&(a[o]=e.edgeVisible[c])}return this.addFacetFromGrowableArrays(n,i,s,r,a),!0}addIndexedPolyface(e,t=!1,n){this._polyface.addIndexedPolyface(e,t,n)}endFace(){return this._polyface.setNewFaceData()}handleCone(e){return this.addCone(e)}handleTorusPipe(e){return this.addTorusPipe(e)}handleSphere(e){return this.addSphere(e)}handleBox(e){return this.addBox(e)}handleLinearSweep(e){return this.addLinearSweep(e)}handleRotationalSweep(e){return this.addRotationalSweep(e)}handleRuledSweep(e){return this.addRuledSweep(e)}handleLoop(e){return this.addTriangulatedRegion(e)}handleParityRegion(e){return this.addTriangulatedRegion(e)}handleUnionRegion(e){return this.addTriangulatedRegion(e)}addGeometryQuery(e){e.dispatchToGeometryHandler(this)}addGraph(e,t=i=>U.testNodeMaskNotExterior(i),n=i=>U.testMateMaskExterior(i)){let i=0;const s=this._options.needNormals,r=this._options.needParams;let a=0;s&&(a=this._polyface.addNormalXYZ(0,0,1)),e.announceFaceLoops((o,c)=>{if(t(c)&&c.countEdgesAroundFace()>2){let d=c;do i=this.addPointXYZ(d.x,d.y,d.z),this._polyface.addPointIndex(i,n===void 0?!0:n(d)),r&&(i=this.addParamXY(d.x,d.y),this._polyface.addParamIndex(i)),s&&this._polyface.addNormalIndex(a),d=d.faceSuccessor;while(d!==c);this._polyface.terminateFacet()}return!0})}addGraphFaces(e){let t=0;for(const n of e){let i=n;do t=this.addPointXYZ(i.x,i.y,i.z),this._polyface.addPointIndex(t),i=i.faceSuccessor;while(i!==n);this._polyface.terminateFacet()}}static graphToPolyface(e,t,n=r=>U.testNodeMaskNotExterior(r),i=r=>U.testMateMaskExterior(r),s=f.smallMetricDistance){const r=ce.create(t);return r.addGraph(e,n,i),r.endFace(),r.claimPolyface(!0,s)}static graphFacesToPolyface(e){const t=ce.create();return t.addGraphFaces(e),t.endFace(),t.claimPolyface()}static polygonToTriangulatedPolyface(e,t){if(t||(t=tt.createFrameWithCCWPolygon(e)),t){const n=t.multiplyInversePoint3dArray(e);if(!n)return;re.areaXY(n)<0&&n.reverse();const s=W.createTriangulatedGraphFromSingleLoop(n);if(s){const r=this.graphToPolyface(s);return r.tryTransformInPlace(t),r}}}addCoordinateFacets(e,t,n,i=!1){for(let s=0;s<e.length;s++){const r=t?t[s]:void 0,a=n?n[s]:void 0;e[s].length===3?this.addTriangleFacet(e[s],r,a):e[s].length===4&&this.addQuadFacet(e[s],r,a)}i&&this.endFace()}addUVGridBody(e,t,n,i,s){let r=new Me(t),a=new Me(t),o,c,d,h;const u=this._reversed,g=this.options.needNormals;g&&(d=new Me(t),h=new Me(t));const m=this.options.needParams;m&&(o=new Me(t),c=new Me(t)),r.ensureCapacity(t),a.ensureCapacity(t);const p=L.create(),x=v.create(),_=1/t,I=1/n,S=ke.createXYPlane();for(let A=0;A<=n;A++){a.clear(),h&&h.clear(),c&&c.clear();for(let w=0;w<=t;w++){const k=w*_,D=A*I;e.uvFractionToPointAndTangents(k,D,S),a.push(this._polyface.addPoint(S.origin)),h&&(S.vectorU.crossProduct(S.vectorV,x),x.normalizeInPlace(),u&&x.scaleInPlace(-1),h.push(this._polyface.addNormal(x))),c&&c.push(this._polyface.addParam(L.create(i?i.fractionToPoint(k):k,s?s.fractionToPoint(D):D,p)))}if(A>0)for(let w=0;w<t;w++)this._options.shouldTriangulate?(this.addIndexedTrianglePointIndexes(r.atUncheckedIndex(w),r.atUncheckedIndex(w+1),a.atUncheckedIndex(w),!1),d&&h&&this.addIndexedTriangleNormalIndexes(d.atUncheckedIndex(w),d.atUncheckedIndex(w+1),h.atUncheckedIndex(w)),o&&c&&this.addIndexedTriangleParamIndexes(o.atUncheckedIndex(w),o.atUncheckedIndex(w+1),c.atUncheckedIndex(w)),this._polyface.terminateFacet(),this.addIndexedTrianglePointIndexes(a.atUncheckedIndex(w),r.atUncheckedIndex(w+1),a.atUncheckedIndex(w+1),!1),d&&h&&this.addIndexedTriangleNormalIndexes(h.atUncheckedIndex(w),d.atUncheckedIndex(w+1),h.atUncheckedIndex(w+1)),o&&c&&this.addIndexedTriangleParamIndexes(c.atUncheckedIndex(w),o.atUncheckedIndex(w+1),c.atUncheckedIndex(w+1)),this._polyface.terminateFacet()):(this.addIndexedQuadPointIndexes(r.atUncheckedIndex(w),r.atUncheckedIndex(w+1),a.atUncheckedIndex(w),a.atUncheckedIndex(w+1),!1),g&&d&&h&&this.addIndexedQuadNormalIndexes(d.atUncheckedIndex(w),d.atUncheckedIndex(w+1),h.atUncheckedIndex(w),h.atUncheckedIndex(w+1)),m&&o&&c&&this.addIndexedQuadParamIndexes(o.atUncheckedIndex(w),o.atUncheckedIndex(w+1),c.atUncheckedIndex(w),c.atUncheckedIndex(w+1)),this._polyface.terminateFacet());[r,a]=[a,r],m&&([o,c]=[c,o]),g&&([d,h]=[h,d])}r.clear(),a.clear()}static pointsToTriangulatedPolyface(e,t){const n=W.createTriangulatedGraphFromPoints(e,oi.ReplaceIfLarger,t?.chordTol);if(n)return ce.graphToPolyface(n,t)}addGreedyTriangulationBetweenLineStrings(e,t){va.createContext().emitTriangles(Eo(e),Eo(t),i=>{this.addTriangleFacet(i.points)})}addMiteredPipes(e,t,n=12,i=!1){const s=dn.createArcFromSectionData(e,t);if(!s)return;n<3&&(n=3);const r=N.create();r.appendFractionalStrokePoints(s,n,0,1,!0);const a=this._options.clone(),o=rr.AlsoMesh,c=t instanceof B?s.binormalVector():void 0,d={strokeOptions:a,capped:i,outputSelect:o,startTangent:c},h=dn.createMiteredSweepSections(e,r,d);h&&h.mesh&&this.addIndexedPolyface(h.mesh)}getEdgeIndices(e){let t=-1,n=-1;for(let i=this._polyface.facetIndex0(e.facetIndex);i<this._polyface.facetIndex1(e.facetIndex);++i)e.startVertex===this._polyface.data.pointIndex[i]?t=i:e.endVertex===this._polyface.data.pointIndex[i]&&(n=i);return t<0||n<0?void 0:{edgeIndexA:t,edgeIndexB:n}}addSweptFace(e,t){const n=this.getEdgeIndices(e);if(n===void 0)return!1;const i=t+e.facetIndex;if(!this._polyface.isValidFacetIndex(i))return!1;const s=this._polyface.numEdgeInFacet(e.facetIndex);if(s!==this._polyface.numEdgeInFacet(i))return!1;const r=this._polyface.facetIndex0(e.facetIndex),a=this._polyface.facetIndex0(i),o=n.edgeIndexA-r,c=n.edgeIndexB-r,d=s-1-o,h=s-1-c,u=[n.edgeIndexB,n.edgeIndexA,a+d,a+h],g=[];let m;this.options.needColors&&this._polyface.data.color&&this._polyface.data.colorIndex&&(m=[]);for(let p=0;p<4;++p){const x=u[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(e,t,n=!1){let i=!0;const s=Ee.sumFacetAreas(e,t);f.isAlmostEqualNumber(0,s)&&(i=!1);const r=Ee.partitionFacetIndicesByVisibilityVector(e,t,T.createDegrees(.001)),a=r[0].length,o=r[1].length;r[2].length>0&&(i=!1),a>0&&o>0&&(i=!1);const d=a>0,h=this._polyface.facetCount;this.addIndexedPolyface(e,d);const u=this._polyface.facetCount;this.addIndexedPolyface(e,!d,X.createTranslation(t));const g=u-h,m=Array.from({length:g},(S,A)=>h+A),p=is.createSubsetVisitor(this._polyface,m,1),x=Ee.createIndexedEdges(p),_=[];x.sortAndCollectClusters(void 0,_,void 0,void 0);const I=this._options.shouldTriangulate;this._options.shouldTriangulate=n;for(const S of _)if(S instanceof Xt)this.addSweptFace(S,g);else if(Array.isArray(S))for(const A of S)this.addSweptFace(A,g);return this._options.shouldTriangulate=I,i}}function Eo(l){return Array.isArray(l)?new Qe(l):l instanceof N?l.packedPoints:l}function ko(l,e,t){return l!==e&&e!==t&&t!==l}var Fo;(function(l){function e(t,n){const i=[],s=t.constructIdToFaceIndexMap(),r=[],a=h=>h.isMaskSet(O.EXTERIOR)?!1:(r.push(s.get(h.id)??-1),!0),o=f.smallFloatingPoint,c=ce.graphToPolyface(t,void 0,a,()=>!0,o);c.data.point.multiplyMatrix3dInPlace(E.createScale(1,1,0));const d=Sa.createCapture(c,void 0,void 0,!1);if(d){const h=Array.isArray(n)?n:[n];for(const u of h){let g;const m=d.searchForClosestPoint(u,void 0,!0);if(m&&m.a<f.smallFloatingPoint){const p=r[m.facetIndex];p>=0&&p<t.allHalfEdges.length&&(g=t.allHalfEdges[p])}i.push(g)}}return i.length===0?void 0:i.length===1?i[0]:i}l.findContainingFaceXY=e})(Fo||(Fo={}));class ud{_activeMomentData;_gaussMapper;constructor(e=5){this._activeMomentData=Ye.create(),this._activeMomentData.needOrigin=!0,this._gaussMapper=new Br(e)}get momentData(){return this._activeMomentData}startParentCurvePrimitive(e){}startCurvePrimitive(e){}endCurvePrimitive(e){}endParentCurvePrimitive(e){}announceIntervalForUniformStepStrokes(e,t,n,i){this.startCurvePrimitive(e),t<1&&(t=1);const s=1/t;let r,a;for(let o=1;o<=t;o++){const c=f.interpolate(n,(o-1)*s,i),d=o===t?i:f.interpolate(n,o*s,i),h=this._gaussMapper.mapXAndW(c,d);for(let u=0;u<h;u++){a=this._gaussMapper.gaussX[u];const g=e.fractionToPointAndDerivative(a);r=this._gaussMapper.gaussW[u]*g.direction.magnitude(),this._activeMomentData.accumulateScaledOuterProduct(g.origin,r)}}}announceSegmentInterval(e,t,n,i,s,r){this._activeMomentData.accumulateLineMomentsXYZ(t,n)}announcePointTangent(e,t,n){}visitLeaves(e){if(e instanceof le)e.emitStrokableParts(this);else if(e instanceof _e)for(const t of e.children)this.visitLeaves(t)}}class vt{_chains;_makeClones;static _staticPointA;static _staticPointB;pushNewChain(e){const t=[];e&&t.push(e),this._chains.push(t)}findOrCreateTailChain(){return this._chains.length===0&&this.pushNewChain(),this._chains[this._chains.length-1]}_xyzWork0;findAnyChainToConnect(e){for(let t=0;t<this._chains.length;t++){const n=this._chains[t];if(this._xyzWork1=n[n.length-1].endPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(e))return{chainIndex:t,atEnd:!0};if(this._xyzWork1=n[0].startPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(e))return{chainIndex:t,atEnd:!1}}}constructor(e){this._chains=[],this._makeClones=e}_xyzWork1;announceCurvePrimitive(e,t=!1){if(e){if(this._makeClones){const n=e.clone();if(!n||!(n instanceof le))return;this.transferMarkup(e,n),e=n}if(t){this._xyzWork0=e.startPoint(this._xyzWork0);let n=this.findAnyChainToConnect(this._xyzWork0);n?n.atEnd?this._chains[n.chainIndex].push(e):(e.reverseInPlace(),this._chains[n.chainIndex].splice(0,0,e)):(this._xyzWork0=e.endPoint(this._xyzWork0),n=this.findAnyChainToConnect(this._xyzWork0),n?n.atEnd?(e.reverseInPlace(),this._chains[n.chainIndex].push(e)):this._chains[n.chainIndex].splice(0,0,e):this._chains.push([e]))}else{const n=this.findOrCreateTailChain();n.length===0||!vt.needBreakBetweenPrimitives(n[n.length-1],e)?n.push(e):this.pushNewChain(e)}}}transferMarkup(e,t){e&&t&&(t.startCut=e.startCut,t.endCut=e.endCut)}promoteArrayToCurves(e,t){if(e.length!==0)return t&&(vt._staticPointA=e[0].startPoint(vt._staticPointA),vt._staticPointB=e[e.length-1].endPoint(vt._staticPointB),vt._staticPointA.isAlmostEqual(vt._staticPointB))?oe.createArray(e):e.length===1?e[0]:Te.createArray(e)}grabResult(e=!1){const t=this._chains;if(t.length===0)return;if(t.length===1)return this.promoteArrayToCurves(t[0],e);const n=zt.create();for(const i of t){const s=this.promoteArrayToCurves(i,e);n.tryAddChild(s)}return n}static needBreakBetweenPrimitives(e,t,n=!1){return e===void 0||t===void 0||e.endCut!==void 0||t.startCut!==void 0?!0:(vt._staticPointA=e.endPoint(vt._staticPointA),vt._staticPointB=t.startPoint(vt._staticPointB),n?!vt._staticPointA.isAlmostEqualXY(vt._staticPointB):!vt._staticPointA.isAlmostEqual(vt._staticPointB))}}var Pn;(function(l){l[l.Unknown=0]="Unknown",l[l.Cap=1]="Cap",l[l.Extend=2]="Extend",l[l.Trim=-1]="Trim",l[l.JustGeometry=3]="JustGeometry",l[l.Gap=4]="Gap"})(Pn||(Pn={}));class Ke{flexure;curve0;fraction0;curve1;fraction1;jointCurve;swingPoint;nextJoint;previousJoint;constructor(e,t,n){this.curve0=e,this.curve1=t,this.swingPoint=n,this.flexure=Pn.Unknown}static constructArc(e,t,n){if(t!==void 0&&f.isSameCoordinate(e.origin.distance(t),n.origin.distance(t))){const i=e.direction.angleToXY(n.direction),s=v.createStartEnd(t,e.origin),r=s.rotate90CCWXY();return B.create(t,s,r,me.createStartEndRadians(0,i.radians))}}shallowExtract(){return{curve0:this.curve0,curve1:this.curve1,fraction0:this.fraction0,fraction1:this.fraction1}}static link(e,t){e.nextJoint=t,t&&(t.previousJoint=e),e.curve1&&t&&!t.curve0?t.curve0=e.curve1:!e.curve1&&t&&t.curve0&&(e.curve1=t.curve0)}nextJointFraction0(e){return this.nextJoint&&this.nextJoint.fraction0!==void 0?this.nextJoint.fraction0:e}static addStrokes(e,t){t&&t.emitStrokes(e)}static addPoint(e,t){e.packedPoints.length>0&&(e.endPoint().isAlmostEqual(t)||e.packedPoints.push(t))}static collectStrokesFromChain(e,t,n=100){let i=-2*n;Ke.visitJointsOnChain(e,s=>{if(this.addStrokes(t,s.jointCurve),s.curve1&&s.fraction1!==void 0){const r=s.fraction1,a=s.nextJointFraction0(1);let o;r===0&&a===1?o=s.curve1.clone():r<a&&(o=s.curve1.clonePartialCurve(r,a)),o&&(s.jointCurve||this.addPoint(t,o.startPoint())),this.addStrokes(t,o)}return i++<n},n)}static collectPrimitive(e,t){if(t){if(e.length>0){const n=e[e.length-1].endPoint(),i=t.startPoint();n.isAlmostEqual(i)||e.push(Q.create(n,i))}e.push(t)}}static adjustJointToPrimitives(e){const t=e.jointCurve;if(t instanceof N){if(e.curve0){const n=e.curve0.endPoint(),i=t.startPoint();n.isAlmostEqual(i)||t.packedPoints.setAtCheckedPointIndex(0,n)}if(e.curve1){const n=e.curve1.startPoint(),i=t.endPoint();n.isAlmostEqual(i)||t.packedPoints.setAtCheckedPointIndex(t.packedPoints.length-1,n)}}}static collectCurvesFromChain(e,t,n=100){if(e===void 0)return;let i=-2*n;Ke.visitJointsOnChain(e,s=>{if(this.adjustJointToPrimitives(s),this.collectPrimitive(t,s.jointCurve),s.curve1&&s.fraction1!==void 0){const r=s.fraction1,a=s.nextJointFraction0(1);let o;r===0&&a===1?o=s.curve1.clone():r<a&&(o=s.curve1.clonePartialCurve(r,a)),this.collectPrimitive(t,o)}return i++<n},n)}static annotateChain(e,t,n=100){e&&Ke.visitJointsOnChain(e,i=>(i.annotateJointMode(t),!0),n)}static visitJointsOnChain(e,t,n=100){let i=e;if(i){let s=0;for(;i!==void 0;){if(s++>=n+5)return!0;if(!t(i))return!1;if(i=i.nextJoint,i===e)break}}return!0}annotateExtension(e){if(this.curve0&&this.curve1){const t=this.curve0.fractionToPointAndDerivative(1),n=this.curve1.fractionToPointAndDerivative(0);t.direction.z=n.direction.z=0;const i=q.closestApproachRay3dRay3d(t,n);if(i.approachType===zn.Intersection&&i.detailA.fraction>=0&&i.detailB.fraction<=0){this.fraction0=1,this.fraction1=0,this.flexure=Pn.Extend;const s=t.getDirectionRef().angleToXY(n.getDirectionRef());if(e.needArc(s)){const a=Ke.constructArc(t,this.curve0.baseCurveEnd,n);if(a){this.jointCurve=a;return}}const r=e.numChamferPoints(s);if(r<=1){this.jointCurve=N.create(t.origin,i.detailA.point,n.origin);return}if(r>1){const a=s.radians,o=2*r,c=a/o,d=Ke.constructArc(t,this.curve0.baseCurveEnd,n);if(d!==void 0){const h=1/Math.cos(c),u=N.create();this.jointCurve=u,u.addPoint(t.origin);for(let g=0;g<r;g++){const m=(1+2*g)/o;u.addPoint(d.fractionAndRadialFractionToPoint(m,h))}u.addPoint(n.origin);return}}}this.flexure=Pn.Gap,this.jointCurve=Q.create(this.curve0.fractionToPoint(1),this.curve1.fractionToPoint(0)),this.fraction0=1,this.fraction1=0}}selectIntersectionIndexByFraction(e,t,n){let i=-1,s=Number.MAX_VALUE;for(let r=0;r<n.length;r++){const a=Math.abs(n[r].detailA.fraction-e)+Math.abs(n[r].detailB.fraction-t);a<s&&(s=a,i=r)}return i}annotateJointMode(e){if(!this.curve0&&this.curve1)this.flexure=Pn.Cap,this.fraction1=0;else if(this.curve0&&!this.curve1)this.flexure=Pn.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=Pn.Trim;else if(this.curve0 instanceof Q&&this.curve1 instanceof Q){const t=this.curve0.fractionToPointAndDerivative(0),n=this.curve1.fractionToPointAndDerivative(0);t.direction.z=n.direction.z=0;const i=q.closestApproachRay3dRay3d(t,n);(i.approachType===zn.Intersection||i.approachType===zn.PerpendicularChord)&&(this.fraction0=i.detailA.fraction,this.fraction1=i.detailB.fraction,this.fraction0>=1&&this.fraction1<=0?this.annotateExtension(e):this.fraction0<1&&this.fraction1>0?this.flexure=Pn.Trim:this.fraction0>1&&this.fraction1>1&&(this.flexure=Pn.Gap,this.jointCurve=Q.create(this.curve0.fractionToPoint(1),this.curve1.fractionToPoint(0)),this.fraction0=1,this.fraction1=0))}else{const t=sn.intersectionXYPairs(this.curve0,!1,this.curve1,!1),n=this.selectIntersectionIndexByFraction(1,0,t);n>=0?(this.flexure=Pn.Trim,this.fraction0=t[n].detailA.fraction,this.fraction1=t[n].detailB.fraction):this.annotateExtension(e)}}static removeDegeneratePrimitives(e,t,n){let i=e,s=0,r=0;if(i)for(;i!==void 0&&r++<n;){const a=i.nextJoint;if(i&&a&&i.previousJoint&&a.nextJoint&&i.fraction1!==void 0&&a.fraction0!==void 0){const o=i.fraction1,c=a.fraction0,d=a.fraction1,h=a.nextJoint.fraction0,u=o>=c||o>1,g=d!==void 0&&d>1||d!==void 0&&h!==void 0&&d>=h;if(u&&g){const m=a.nextJoint,p=new Ke(i.curve0,m.curve1,void 0);Ke.link(i.previousJoint,p),Ke.link(p,m.nextJoint),p.annotateJointMode(t),p.previousJoint&&p.previousJoint.annotateJointMode(t),p.nextJoint&&p.nextJoint.annotateJointMode(t),s+=2,(i===e||a===e||m===e)&&(e=p),i=p}else if(u){const m=new Ke(i.curve0,a.curve1,void 0);Ke.link(i.previousJoint,m),Ke.link(m,a.nextJoint),m.annotateJointMode(t),m.previousJoint&&m.previousJoint.annotateJointMode(t),m.nextJoint&&m.nextJoint.annotateJointMode(t),s++,(i===e||a===e)&&(e=m),i=m}}if(i=i.nextJoint,i===e)break}return{newStart:e,numJointRemoved:s}}}class ur{constructor(){}static _unitAlong=v.create();static _unitPerp=v.create();static _offsetA=y.create();static _offsetB=y.create();static createOffsetSegment(e,t,n){if(v.createStartEnd(e,t,this._unitAlong),this._unitAlong.z=0,this._unitAlong.normalizeInPlace()){this._unitAlong.rotate90CCWXY(this._unitPerp);const i=Q.create(e.plusScaled(this._unitPerp,n,this._offsetA),t.plusScaled(this._unitPerp,n,this._offsetB));return Ai.applyBasePoints(i,e.clone(),t.clone()),i}}constructPolygonWireXYOffset(e,t,n){t&&!e[0].isAlmostEqual(e[e.length-1])&&(t=!1);const i=Xi.create(n),s=e.length;let r,a,o;for(let u=0;u+1<s;++u)if(!o)(r=ur.createOffsetSegment(e[u],e[u+1],i.leftOffsetDistance))&&(o=a=new Ke(void 0,r,e[u]));else{const g=ur.createOffsetSegment(e[u],e[u+1],i.leftOffsetDistance);if(g){const m=new Ke(r,g,e[u]);Ke.link(o,m),o=m,r=g}}if(!r||!o||!a)return;const c=t?a:new Ke(r,void 0,e[s-1]);Ke.link(o,c),Ke.annotateChain(a,i,s);for(let u=0;u++<5;){const g=Ke.removeDegeneratePrimitives(a,i,s);if(a=g.newStart,g.numJointRemoved===0)break}const d=N.create();Ke.collectStrokesFromChain(a,d,s);const h=d.packedPoints.length;if(h>1)return d.packedPoints.almostEqualUncheckedIndexIndex(0,h-1)?oe.create(d):Te.create(d)}}class Ai{constructor(){}static applyBasePoints(e,t,n){return e!==void 0&&(t!==void 0&&(e.baseCurveStart=t),n!==void 0&&(e.baseCurveEnd=n)),e}static createSingleOffsetPrimitiveXY(e,t){const n=e.constructOffsetXY(t);if(n!==void 0){if(Array.isArray(n)){const i=e.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,e.startPoint(),e.endPoint())}}static constructCurveXYOffset(e,t){const n=e instanceof oe,i=Kt.create(t),s=[];for(const u of e.children){const g=Ai.createSingleOffsetPrimitiveXY(u,i);if(g!==void 0){if(g instanceof le)s.push(g);else if(Array.isArray(g))for(const m of g)m instanceof le&&s.push(m)}}let r,a,o,c;for(const u of s)u&&(a=new Ke(r,u,u.fractionToPoint(0)),a!==void 0&&c===void 0&&(c=a),o&&Ke.link(o,a),o=a,r=u);c&&o&&e instanceof oe&&Ke.link(o,c);const d=s.length;if(Ke.annotateChain(c,i.jointOptions,d),c)for(let u=0;u++<5;){const g=Ke.removeDegeneratePrimitives(c,i.jointOptions,d);if(c=g.newStart,g.numJointRemoved===0)break}const h=[];return Ke.collectCurvesFromChain(c,h,d),ge.createLoopPathOrBagOfCurves(h,n,!0)}}class fr extends Li{constructor(){super(void 0)}doClone(e){return e instanceof B&&e.sweep.isFullCircle?[e.clonePartialCurve(0,.5),e.clonePartialCurve(.5,1)]:e}static clone(e){const t=new fr;return e.announceToCurveProcessor(t),t._result}}class fd extends zs{_consolidateLinearGeometry;_consolidateCompatibleArcs;_consolidateLoopSeam;_disableLinearCompression;_duplicatePointTolerance;_colinearPointTolerance;constructor(e){super(),this._consolidateLinearGeometry=e?.consolidateLinearGeometry??!0,this._consolidateCompatibleArcs=e?.consolidateCompatibleArcs??!0,this._consolidateLoopSeam=e?.consolidateLoopSeam??!1,this._disableLinearCompression=e?.disableLinearCompression??!1,this._duplicatePointTolerance=e?.duplicatePointTolerance??f.smallMetricDistance,this._colinearPointTolerance=e?.colinearPointTolerance??f.smallMetricDistance}handleCurveChain(e){const n=e.children.length,i=[];let s=0;for(let r=0;r<n;){const a=e.children[r];if(this._consolidateLinearGeometry&&(a instanceof Q||a instanceof N)){i.length=0;let o=r;for(;o<e.children.length;o++){const c=e.children[o];if(c instanceof Q)i.push(c.startPoint()),i.push(c.endPoint());else if(c instanceof N){const d=c.packedPoints;for(let h=0;h<d.length;h++)i.push(d.getPoint3dAtUncheckedPointIndex(h))}else break}if(i.length<=1)e.children[s++]=a;else if(this._disableLinearCompression){const c=In.compressShortEdges(i,f.smallFloatingPoint);e.children[s++]=N.createPoints(c)}else{const c=In.compressShortEdges(i,this._duplicatePointTolerance),d=In.compressByChordError(c,this._colinearPointTolerance,!0);r===0&&o===n&&this._consolidateLoopSeam&&rt.compressColinearWrapInPlace(d,this._duplicatePointTolerance,this._colinearPointTolerance),d.length<2?e.children[s++]=N.create(d[0]):d.length===2?e.children[s++]=Q.create(d[0],d[1]):e.children[s++]=N.createPoints(d)}r=o}else if(this._consolidateCompatibleArcs&&a instanceof B){for(;++r<e.children.length;){const o=e.children[r];if(!(o instanceof B)||!dn.appendToArcInPlace(a,o,!1,this._duplicatePointTolerance))break}e.children[s++]=a}else e.children[s++]=a,r++}e.children.length=s}handlePath(e){return this.handleCurveChain(e)}handleLoop(e){if(this.handleCurveChain(e),e.children.length>1&&this._consolidateLoopSeam){const t=e.children[e.children.length-1],n=e.children[0];if((t instanceof Q||t instanceof N)&&(n instanceof Q||n instanceof N)){if(this._consolidateLinearGeometry&&!this._disableLinearCompression){const i=t.points;i.pop(),e.children[0]=N.createPoints([...i,...n.points]),e.children.pop()}}else t instanceof B&&n instanceof B&&this._consolidateCompatibleArcs&&dn.appendToArcInPlace(t,n,!1,this._duplicatePointTolerance)&&(e.children[0]=t,e.children.pop())}}handleParityRegion(e){for(const t of e.children)t.dispatchToGeometryHandler(this)}handleUnionRegion(e){for(const t of e.children)t.dispatchToGeometryHandler(this)}}class Ro{fraction;otherCurveDetail;constructor(e,t){this.fraction=e,this.otherCurveDetail=t}setFrom(e,t){t&&this.isSameFraction(e)&&(this.otherCurveDetail=e.otherCurveDetail?e.otherCurveDetail:this.otherCurveDetail),this.fraction=e.fraction}isSameFraction(e){return f.isSmallAngleRadians(this.fraction-e.fraction)}set(e,t){this.fraction=e,this.otherCurveDetail=t}}class gr{static hasInteriorDetailAIntersections(e,t=f.smallAngleRadians){if(e.length===0)return!1;for(const n of e)if(n.detailA.fraction>t||n.detailA.fraction<1-t)return!0;return!1}collectFragmentAndAdvanceCut(e,t,n,i){if(!t.isSameFraction(n)){const s=e.clonePartialCurve(t.fraction,n.fraction);s!==void 0&&(s.startCut=t.otherCurveDetail,s.endCut=n.otherCurveDetail,i.push(s))}t.setFrom(n,!0)}collectSinglePrimitiveFragments(e,t,n){if(t===void 0||!gr.hasInteriorDetailAIntersections(t)){n.push(e.clone());return}t.sort((r,a)=>r.detailA.fraction-a.detailA.fraction);const i=new Ro(0,void 0),s=new Ro(1,void 0);for(const r of t)s.set(r.detailA.fraction,r.detailB),this.collectFragmentAndAdvanceCut(e,i,s,n);s.set(1,void 0),this.collectFragmentAndAdvanceCut(e,i,s,n)}static cloneCurvesWithXYSplits(e,t){const n=new gr;if(e instanceof le){const i=[],s=sn.intersectionXYPairs(e,!1,t,!1);return n.collectSinglePrimitiveFragments(e,s,i),i.length===1?i[0]:Te.createArray(i)}else if(e instanceof mt){const i=[];for(const s of e.children){const r=sn.intersectionXYPairs(s,!1,t,!1);n.collectSinglePrimitiveFragments(s,r,i)}return Te.createArray(i)}}}class gd{static testPointInOnOutLoopXY(e,t,n){let i;const s=y.create(t,n);for(let r=0;Math.abs(r)<6;r=-1.2313*(r+.3212897)){i=pe.createXYAngle(t,n,T.createRadians(r));const a=i.getNormalRef(),o=[];for(const x of e.children)x instanceof le&&x.appendPlaneIntersectionPoints(i,o);le.snapAndRestrictDetails(o,!1,!0);let c=0,d=0,h=0,u,g;for(const x of o){if(x.intervalRole!==Fe.isolated&&x.intervalRole!==void 0&&h++,u=x.point.x-t,g=x.point.y-n,f.isSameCoordinateXY(u,g,0,0))return 0;const _=f.crossProductXYXY(a.x,a.y,u,g);if(s.isAlmostEqualXY(x.point))return 0;_<0?c++:_>0&&d++}if(h!==0)continue;const m=c&1,p=d&1;if(m===p)return m===1?1:-1}return-1}static testPointInOnOutParityRegionXY(e,t,n){let i=-1;for(const s of e.children)if(s instanceof oe){const r=this.testPointInOnOutLoopXY(s,t,n);if(r===0)return 0;r>0&&(i=-i)}return i}static testPointInOnOutUnionRegionXY(e,t,n){for(const i of e.children){const s=this.testPointInOnOutRegionXY(i,t,n);if(s>=0)return s}return-1}static testPointInOnOutRegionXY(e,t,n){return e instanceof oe?this.testPointInOnOutLoopXY(e,t,n):e instanceof He?this.testPointInOnOutParityRegionXY(e,t,n):e instanceof Et?this.testPointInOnOutUnionRegionXY(e,t,n):-1}}class md{startComponent(e){return!0}finishComponent(e){return!0}enterFace(e,t){return!0}leaveFace(e,t){return!0}}class pd extends md{_faceSelectFunction;_inComponent;_exteriorMask;constructor(e,t){super(),this._inComponent=[!1,!1,!1],this._exteriorMask=t,this._faceSelectFunction=e}startComponent(e){return e.setMaskAroundFace(this._exteriorMask),!0}enterFace(e,t){const n=t.edgeTag;return(t.edgeTag===1||t.edgeTag===2)&&(this._inComponent[n]=!this._inComponent[n]),this._faceSelectFunction(this._inComponent[1],this._inComponent[2])||t.setMaskAroundFace(this._exteriorMask),!0}leaveFace(e,t){const n=t.edgeTag;return(t.edgeTag===1||t.edgeTag===2)&&(this._inComponent[n]=!this._inComponent[n]),!0}}class wi{static faceToFaceSearchFromOuterLoop(e,t,n,i){if(e.isMaskSet(t)||!i.startComponent(e))return;const s=[];e.setMaskAroundFace(t);let r=e;do{let a=r,o=r.edgeMate;if(!o.isMaskSet(t)){s.push(r),s.push(o);let c=o.faceSuccessor;if(o.setMaskAroundFace(t),a=o,i.enterFace(s,o))for(;;){if(o=c.edgeMate,!o.isMaskSet(t)){if(o.setMaskAroundFace(t),!i.enterFace(s,o))return;s.push(c),s.push(o),c=o,a=o}if(c.setMask(n),c=c.faceSuccessor,c===a){if(i.leaveFace(s,c),s.length<=2)break;s.pop(),c=s[s.length-1],s.pop(),a=s[s.length-1]}if(c.isMaskSet(n))return}}r=r.faceSuccessor}while(r!==e);i.finishComponent(e)}static doPolygonBoolean(e,t,n,i){const s=new Ut,r=O.BOUNDARY_EDGE|O.PRIMARY_EDGE,a=ge.addLoopsWithEdgeTagToGraph(s,e,r,1),o=ge.addLoopsWithEdgeTagToGraph(s,t,r,2);if(i&&i("unmerged loops",s,"U"),a||o){rn.splitIntersectingEdges(s),i&&i("After splitIntersectingEdges",s,"S"),rn.clusterAndMergeXYTheta(s),i&&i("After clusterAndMergeXYTheta",s,"M"),new Ui(s).regularizeGraph(!0,!0),i&&i("After regularize",s,"MR");const d=Wn.findMinimumAreaFace(s);if(d===void 0)return;const h=O.EXTERIOR,u=s.grabMask(),g=s.grabMask(),m=h|u|g;s.clearMask(m);const p=new pd(n,h);return this.faceToFaceSearchFromOuterLoop(d,u,g,p),i&&i("After faceToFaceSearchFromOuterLoop",s,"MRX"),s.dropMask(u),s.dropMask(g),s}}static doBinaryBooleanBetweenMultiLoopInputs(e,t,n,i,s,r){const a=new Ut,o=O.BOUNDARY_EDGE|O.PRIMARY_EDGE,c=jn.create(t,s);c.graph=a,c.faceAreaFunction=h=>Wn.signedFaceArea(h);for(const h of e)if(h.length>2){const u=new hi(h,c.groupA);ge.addLoopsWithEdgeTagToGraph(a,h,o,u)}for(const h of i)if(h.length>2){const u=new hi(h,c.groupB);ge.addLoopsWithEdgeTagToGraph(a,h,o,u)}return rn.splitIntersectingEdges(a),rn.clusterAndMergeXYTheta(a),new Ui(a).regularizeGraph(!0,!0),c.runClassificationSweep(n),r&&c.unmaskMaskedNullFaces(O.EXTERIOR),a}}var _t;(function(l){l[l.Union=0]="Union",l[l.Parity=1]="Parity",l[l.Intersection=2]="Intersection",l[l.NonBounding=-1]="NonBounding"})(_t||(_t={}));class hi{region;sweepState;parentGroup;constructor(e,t){this.region=e,this.parentGroup=t,this.sweepState=0}clearState(){this.sweepState=0}}class Aa{members;groupOpType;parent;_numIn;constructor(e,t){this.members=[],this.parent=e,this.groupOpType=t,this._numIn=0}clearState(){for(const e of this.members)e.clearState();this._numIn=0}range(){const e=ie.createNull();for(const t of this.members)if(t.region instanceof Mt)t.region.extendRange(e);else{const n=ie.createFromVariantData(t.region);e.extendRange(n)}return e}getInOut(){return this.groupOpType===_t.Union?this._numIn>0:this.groupOpType===_t.Parity?f.isOdd(this._numIn):this.groupOpType===_t.Intersection?this._numIn===this.members.length:!1}addMember(e,t=!1){if(e instanceof oe||e instanceof He){let n=e.clone();ge.consolidateAdjacentPrimitives(n),n=fr.clone(n),this.members.push(new hi(n,this))}else if(e instanceof Et)for(const n of e.children)this.addMember(n);else if(Array.isArray(e))for(const n of e)this.addMember(n);else t&&e instanceof Q&&this.members.push(new hi(e,this))}recordMemberStateChange(e,t){const n=f.isOdd(e),i=f.isOdd(t);!n&&i?this._numIn++:n&&!i&&this._numIn--}}class jn{groupA;groupB;extraGeometry;graph;faceAreaFunction;binaryOp;constructor(e,t){this.groupA=new Aa(this,e),this.groupB=new Aa(this,t),this.extraGeometry=new Aa(this,_t.NonBounding),this.binaryOp=tn.Union}static create(e,t){return new jn(e,t)}addMembers(e,t){this.groupA.addMember(e),this.groupB.addMember(t),this.addConnectives()}_workSegment;static _bridgeDirection=v.createNormalized(1,-.12328974132467);addConnectives(){const e=this.groupA.range(),t=this.groupB.range(),n=e.union(t);let i=.1;this._workSegment=jt.findExtremePointsInDirection(n.corners(),jn._bridgeDirection,this._workSegment),this._workSegment&&(i*=this._workSegment.point0Ref.distanceXY(this._workSegment.point1Ref));const s=[],r=ge.computeMinimumArea(),a=c=>{const d=ge.computeXYArea(c);d===void 0||Math.abs(d)<r||(this._workSegment=jt.findExtremePointsInDirection(c,jn._bridgeDirection,this._workSegment),this._workSegment&&s.push(this._workSegment.point1Ref))};for(const c of[this.groupA.members,this.groupB.members])for(const d of c)if(d.region instanceof oe)a(d.region);else if(d.region instanceof He)for(const h of d.region.children)a(h);const o=q.createZero();for(const c of s){const d=i+q.create(c,jn._bridgeDirection,o).intersectionWithRange3d(n).high,h=y.createAdd2Scaled(c,1,jn._bridgeDirection,d),u=Q.createXYXY(c.x,c.y,h.x,h.y);this.extraGeometry.addMember(u,!0)}}annotateAndMergeCurvesInGraph(e=f.smallMetricDistance){const t=[];for(const s of[this.groupA,this.groupB,this.extraGeometry])for(const r of s.members){let a=t.length;if(r.region instanceof Mt)for(ge.collectCurvePrimitives(r.region,t,!0,!0);a<t.length;a++)t[a].parent=r}const n=sn.allIntersectionsAmongPrimitivesXY(t,e),i=us.assembleHalfEdgeGraph(t,n,e);ge.removeExtraneousBridgeEdges(this.graph=i,void 0,this.faceAreaFunction=hs)}_announceFaceFunction;runClassificationSweep(e,t){this._announceFaceFunction=t,this.binaryOp=e,this.graph.clearMask(O.EXTERIOR);for(const r of[this.groupA,this.groupB])r.clearState();const n=this.graph.grabMask(),i=this.graph.grabMask(),s=wa.create(this.graph);for(const r of s.components){const a=r.faces[r.faceAreas.indexOf(Math.min(...r.faceAreas))],c=O.EXTERIOR|n|i;this.graph.clearMask(c),wi.faceToFaceSearchFromOuterLoop(a,n,i,this)}this.graph.dropMask(n),this.graph.dropMask(i)}unmaskMaskedNullFaces(e){for(const t of this.graph.allHalfEdges){const n=t.faceSuccessor;n.faceSuccessor===t&&t.getMask(e)&&n.getMask(e)&&(!t.edgeMate.getMask(e)||!n.edgeMate.getMask(e))&&(t.clearMask(e),n.clearMask(e))}}getInOut(){return this.binaryOp===tn.Union?this.groupA.getInOut()||this.groupB.getInOut():this.binaryOp===tn.Intersection?this.groupA.getInOut()&&this.groupB.getInOut():this.binaryOp===tn.AMinusB?this.groupA.getInOut()&&!this.groupB.getInOut():this.binaryOp===tn.BMinusA?!this.groupA.getInOut()&&this.groupB.getInOut():this.binaryOp===tn.Parity?this.groupA.getInOut()!==this.groupB.getInOut():!1}recordTransitionAcrossEdge(e,t){const n=s=>{if(s.parentGroup.groupOpType===_t.NonBounding)return s;if(t!==0){const r=s.sweepState;s.sweepState+=t,s.parentGroup.recordMemberStateChange(r,s.sweepState)}return s},i=e.edgeTag;if(i instanceof hi)return n(i);if(i instanceof Y&&i.curve){const s=i.curve.parent;if(s instanceof hi)return n(s)}}startComponent(e){return e.setMaskAroundFace(O.EXTERIOR),this._announceFaceFunction&&this._announceFaceFunction(this.graph,e,-1,hs(e)),!0}finishComponent(e){return!0}enterFace(e,t){this.recordTransitionAcrossEdge(t,1);const n=this.getInOut();return n||t.setMaskAroundFace(O.EXTERIOR),this._announceFaceFunction&&this._announceFaceFunction(this.graph,t,n?1:0,hs(t)),!0}leaveFace(e,t){return this.recordTransitionAcrossEdge(t,-1),!0}}function xd(l,e,t,n){let i;l&&l.point1?i=-(l.point1.x-l.point.x)*(.5*(l.point.y+l.point1.y)-n.y):i=-(t.x-e.x)*(.5*(e.y+t.y)-n.y);let s=0;if(l&&l.curve&&l.isInterval()&&!(l.curve instanceof Q))if(l.curve instanceof B)s=l.curve.areaToChordXY(l.fraction,l.fraction1);else{const r=l.curve.clonePartialCurve(l.fraction,l.fraction1);s=(r?ge.computeXYArea(oe.create(r,Q.create(l.point1,l.point))):0)??0}return i+s}function hs(l){let e=0,t=l;do e+=t.sortData*xd(t.edgeTag,t,t.faceSuccessor,l);while((t=t.faceSuccessor)!==l);return e}class _d{faces;faceAreas;range;constructor(e){this.faces=e,this.range=ze.createNull(),this.faceAreas=[]}buildFaceData(e,t){const n=i=>(e?e(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,t===hs&&!this.faces.every(i=>i.edgeTag instanceof Y)&&(t=void 0),t||(t=i=>Wn.signedFaceArea(i));for(const i of this.faces)this.faceAreas.push(t(i))}}class wa{components;graph;constructor(e){this.graph=e,this.components=[]}static create(e,t){const n=new wa(e),i=Wn.collectConnectedComponentsWithExteriorParityMasks(e,void 0);for(const s of i){const r=new _d(s);r.buildFaceData(t,hs),n.components.push(r)}return n}}class yd{primitiveToPair=new Map;primitiveToIndex=new Map;_numIndexedPrimitives=0;assignPrimitiveIndex(e){e!==void 0&&this.primitiveToIndex.get(e)===void 0&&this.primitiveToIndex.set(e,this._numIndexedPrimitives++)}insertPrimitiveToPair(e,t){if(e){const n=this.primitiveToPair.get(e);this.assignPrimitiveIndex(e),n?n.push(t):this.primitiveToPair.set(e,[t])}}insertPair(e){const t=e.detailA.curve;t&&this.insertPrimitiveToPair(t,e);const n=e.detailB.curve;n&&this.insertPrimitiveToPair(n,e)}splitAndAppendMissingClosedPrimitives(e,t=f.smallMetricDistance){for(const n of e){let i=!1;if(n instanceof B?i=n.sweep.isFullCircle:!(n instanceof Q)&&!(n instanceof N)&&(i=n.startPoint().isAlmostEqualXY(n.endPoint(),t)),i&&!this.primitiveToPair.has(n)){const s=n.clonePartialCurve(0,.5),r=n.clonePartialCurve(.5,1);s&&r&&(this.insertPair(Ze.createCapture(Y.createCurveEvaluatedFraction(s,0),Y.createCurveEvaluatedFraction(r,1))),this.insertPair(Ze.createCapture(Y.createCurveEvaluatedFraction(s,1),Y.createCurveEvaluatedFraction(r,0))))}}}}class us{static assembleHalfEdgeGraph(e,t,n=f.smallMetricDistance,i=f.smallAngleRadians){const s=new yd;for(const c of t)s.insertPair(c);e.length>s.primitiveToPair.size&&s.splitAndAppendMissingClosedPrimitives(e,n);const r=(c,d)=>c.detailA.curve===d?c.detailA.fraction:c.detailB.fraction,a=(c,d)=>c.detailA.curve===d?c.detailA:c.detailB,o=new Ut;for(const c of s.primitiveToPair.entries()){const d=c[0],h=c[1].reduce((g,m)=>{const p=a(m,d);if(p.isInterval()){const x=Y.createCurveFractionPoint(d,p.fraction,p.point),_=Y.createCurveFractionPoint(d,p.fraction1,p.point1);return[...g,Ze.createCapture(x,x),Ze.createCapture(_,_)]}return[...g,m]},[]);h.sort((g,m)=>{const p=r(g,d),x=r(m,d);return p-x});let u={point:d.startPoint(),fraction:0};for(const g of h){const m=a(g,d),p=f.restrictToInterval(m.fraction,0,1);u=this.addHalfEdge(o,d,u.point,u.fraction,m.point,p,n)}this.addHalfEdge(o,d,u.point,u.fraction,d.endPoint(),1,n)}return rn.clusterAndMergeXYTheta(o,c=>c.sortAngle??0,n,i),o}static isCurveTrivialXY(e,t,n,i,s,r){if(f.isSmallRelative(n-s))return!0;if(!(e instanceof Q)){const a=e.clonePartialCurve(n,s);if(a?.tryTransformInPlace(X.createRowValues(1,0,0,0,0,1,0,0,0,0,0,0)))return a.curveLength()<=r}return t.isAlmostEqualXY(i,r)}static addHalfEdge(e,t,n,i,s,r,a=f.smallMetricDistance){if(!this.isCurveTrivialXY(t,n,i,s,r,a)){const o=e.createEdgeXYAndZ(n,0,s,0);t.parent&&t.parent instanceof hi&&t.parent.parentGroup.groupOpType===_t.NonBounding&&o.setMaskAroundEdge(O.BRIDGE_EDGE);const c=Y.createCurveEvaluatedFractionFraction(t,i,r),d=o.edgeMate;o.edgeTag=c,o.sortData=1,d.edgeTag=c,d.sortData=-1;const h=(u,g)=>{const m=t.fractionToPointAndDerivative(u),p=g?-1:1;return Math.atan2(p*m.direction.y,p*m.direction.x)};o.sortAngle=h(i,!1),d.sortAngle=h(r,!0)}return{point:s,fraction:r}}static collectSignedLoop(e,t,n=1e-10,i){let s=i?0:ge.computeXYArea(e);return s===void 0&&(s=0),Math.abs(s)<n&&(s=0),e.computedAreaInPlanarSubdivision=s,s>0?t.positiveAreaLoops.push(e):s<0?t.negativeAreaLoops.push(e):t.slivers.push(e),s}static extractGeometryFromEdge(e){if(e.sortData!==void 0&&e.edgeTag&&e.edgeTag instanceof Y){const t=e.edgeTag;if(t.curve&&t.fraction1!==void 0){const n=e.sortData<0;return{detail:t,reversed:n}}}}static createCurveInEdge(e,t){let n;const i=this.extractGeometryFromEdge(e);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&&t!==void 0&&n.tryTransformInPlace(X.createRowValues(1,0,0,0,0,1,0,0,0,0,0,t))}return n}static createLoopInFace(e,t){const n=t?.announceEdge?!1:t?.compress??!1,i=oe.create(),s=r=>{const a=this.createCurveInEdge(r,t?.z);a&&(t?.announceEdge?.(r,a,i),i.tryAddChild(a))};if(Array.isArray(e)?e.forEach(s):e.announceEdgesInFace(s),n&&ge.consolidateAdjacentPrimitives(i,{consolidateLoopSeam:!0}),i.isPhysicallyClosedCurve(t?.closureTol,!0))return i}static createLoopOrParityRegionInFace(e,t){let n;const i=t?.visitMask??O.VISITED,s=t?.bridgeMask??O.BRIDGE_EDGE;let r;if(e.isSplitWasherFace(s)&&(r=e.findMaskAroundFace(s,!0))){const a=[],o=[],c=[r],d=g=>{g.setMask(i),o.push(g)},h=g=>{g.isMaskSet(i)||c.push(g)};e.clearMaskAroundFace(i);let u;for(;(u=c.pop())!==void 0;){u.setMask(i);const g=u.findMaskAroundFace(s,!1);if(g){if(g.isMaskSet(i))continue;if(o.length=0,g.announceEdgesInSuperFace(s,d,h)){const m=this.createLoopInFace(o,t);if(m){a.push(m);continue}}}}n=ge.sortOuterAndHoleLoopsXY(a),n=ge.simplifyRegion(n)}else n=this.createLoopInFace(e,t);return n&&(n instanceof oe||n instanceof He)?n:void 0}static isNullFace(e){const t=e.faceSuccessor.faceSuccessor===e;let n=!1;if(t){const i=rn.curvatureSortKey(e),s=rn.curvatureSortKey(e.faceSuccessor.edgeMate);f.isSameCoordinate(i,s)||(n=!0)}return t&&!n}static getNonNullEdgeMate(e,t){if(this.isNullFace(t))return;let n=t.edgeMate;for(;this.isNullFace(n);)if(n=n.faceSuccessor.edgeMate,n===t)return;return n}static collectSignedLoopSetsInHalfEdgeGraph(e,t=f.smallMetricDistance,n=1e-10){const i=Wn.collectConnectedComponentsWithExteriorParityMasks(e,void 0),s=[],r=new Map;for(const a of i){const o={positiveAreaLoops:[],negativeAreaLoops:[],slivers:[]},c=[];for(const d of a){const h=this.isNullFace(d),u=h?void 0:(m,p,x)=>{const _=this.getNonNullEdgeMate(e,m);if(_!==void 0){const I=r.get(_);if(I===void 0){const S=new uo(x,p,void 0,void 0);r.set(m,S)}else I instanceof uo&&(I.setB(x,p),c.push(I),r.delete(_))}},g=this.createLoopInFace(d,{announceEdge:u,closureTol:t});g&&this.collectSignedLoop(g,o,n,h)}o.edges=c,s.push(o),r.clear()}return s}}class Mo extends zs{_activeMomentData;_point0=y.create();_point1=y.create();handleArc3d(e){const t=this._activeMomentData;if(t===void 0)return;const n=e.sweep.sweepRadians,i=n*.5;let s=Math.sin(i),r=Math.cos(i),a=Math.sin(n);T.isFullCircleRadians(n)&&(s=0,r=-1,a=0);const o=2*s*s*s*r/(i-s*r),c=s*s*s,d=c*c,h=.5*(n-a),u=.25*h*(1-o/3),p=.25*h*(1+o)-4*d/(9*h),x=u,_=4*s*s*s/(3*(n-a)),I=e.sweep.fractionToRadians(.5),S=e.radiansToRotatedBasis(I),A=S.origin.plusScaled(S.vectorU,_);t.accumulateXYProductsInCentroidalFrame(p,0,x,h,A,S.vectorU,S.vectorV);const w=e.fractionToPoint(0),k=e.fractionToPoint(1);t.accumulateTriangleMomentsXY(void 0,w,k)}handleLineString3d(e){const t=this._activeMomentData;t!==void 0&&t.accumulateTriangleToLineStringMomentsXY(void 0,e.packedPoints)}handleLineSegment3d(e){const t=this._activeMomentData;t!==void 0&&(e.startPoint(this._point0),e.endPoint(this._point1),t.accumulateTriangleMomentsXY(void 0,this._point0,this._point1))}handleLoop(e){const t=this._activeMomentData=Ye.create();t.needOrigin=!1;for(const n of e.children)n.dispatchToGeometryHandler(this);return this._activeMomentData=void 0,t}handleAnyRegion(e){const t=ge.regionBooleanXY(e,void 0,tn.Union);if(!t)return;if(t instanceof oe)return this.handleLoop(t);const n=Ye.create();for(const i of t.children){const s=i.dispatchToGeometryHandler(this);if(s){const r=t instanceof He&&s.quantitySum<0?-1:1,a=s.signFactor(r);n.accumulateProducts(s,a)}}return n}handleParityRegion(e){return this.handleAnyRegion(e)}handleUnionRegion(e){return this.handleAnyRegion(e)}_strokeOptions;getStrokeOptions(){if(this._strokeOptions)return this._strokeOptions;const e=st.createForCurves();return e.angleTol=T.createDegrees(5),this._strokeOptions=e,e}handleCurvePrimitive(e){const t=N.create(),n=this.getStrokeOptions();e.emitStrokes(t,n),this.handleLineString3d(t)}handleBSplineCurve3d(e){this.handleCurvePrimitive(e)}handleBSplineCurve3dH(e){this.handleCurvePrimitive(e)}handleTransitionSpiral(e){this.handleCurvePrimitive(e)}}var tn;(function(l){l[l.Union=0]="Union",l[l.Parity=1]="Parity",l[l.Intersection=2]="Intersection",l[l.AMinusB=3]="AMinusB",l[l.BMinusA=4]="BMinusA"})(tn||(tn={}));class ge{static computeXYAreaMoments(e){const t=new Mo,n=e.dispatchToGeometryHandler(t);if(n instanceof Ye)return n.shiftOriginAndSumsToCentroidOfSums(),n}static computeXYAreaTolerance(e,t=f.smallMetricDistance){if(t===0)return f.smallFloatingPoint*10;const n=.5*Math.abs(t);return n*(e.xLength()+e.yLength()+n)}static computeMinimumArea(e=f.smallMetricDistance){const t=Math.PI*e*e,n=f.smallFloatingPoint*10;return t<n?n:t}static computeXYArea(e){const t=new Mo,n=e.dispatchToGeometryHandler(t);if(n instanceof Ye)return n.quantitySum}static computeXYZWireMomentSums(e){const t=new ud;t.visitLeaves(e);const n=t.momentData;return n.shiftOriginAndSumsToCentroidOfSums(),n}static centroidAreaNormal(e,t){const n=tt.createRightHandedFrame(void 0,e);if(!n)return;const i=n.matrix.columnZ(t?.direction),s=i.isParallelTo(v.unitZ(),!0);let r=e;if(!s){const d=n.inverse();r=e.cloneTransformed(d)}const a=ge.computeXYAreaMoments(r);if(!a)return;const o=a.origin.clone(t?.origin);s?n.origin.z!==0&&(o.z+=n.origin.z):n.multiplyPoint3d(o,o);let c=a.sums.weight();return c<0&&(c=-c,i.scale(-1,i)),t||(t=q.createCapture(o,i)),t.a=c,t}static addLoopsToGraph(e,t,n){if(t instanceof oe){const i=t.getPackedStrokes();i&&this.addLoopsToGraph(e,i,n)}else if(t instanceof He)for(const i of t.children){const s=i.getPackedStrokes();s&&this.addLoopsToGraph(e,s,n)}else if(t instanceof gt){const i=W.directCreateFaceLoopFromCoordinates(e,t);i!==void 0&&n(e,i)}else if(Array.isArray(t)&&t.length>0)if(y.isAnyImmediatePointType(t[0])){const i=W.directCreateFaceLoopFromCoordinates(e,t);i!==void 0&&n(e,i)}else if(t[0]instanceof gt)for(const i of t){const s=W.directCreateFaceLoopFromCoordinates(e,i);s!==void 0&&n(e,s)}else for(const i of t)Array.isArray(i)&&this.addLoopsToGraph(e,i,n)}static addLoopsWithEdgeTagToGraph(e,t,n,i){const s=[];if(this.addLoopsToGraph(e,t,(r,a)=>{a&&(s.push(a),a.setMaskAndEdgeTagAroundFace(n,i,!0))}),s.length>0)return s}static finishGraphToPolyface(e,t){if(e)return t&&(W.triangulateAllPositiveAreaFaces(e),W.flipTriangles(e)),ce.graphToPolyface(e)}static polygonXYAreaIntersectLoopsToPolyface(e,t,n=!1){const i=wi.doPolygonBoolean(e,t,(s,r)=>s&&r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static polygonXYAreaUnionLoopsToPolyface(e,t,n=!1){const i=wi.doPolygonBoolean(e,t,(s,r)=>s||r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static polygonXYAreaDifferenceLoopsToPolyface(e,t,n=!1){const i=wi.doPolygonBoolean(e,t,(s,r)=>s&&!r,this._graphCheckPointFunction);return this.finishGraphToPolyface(i,n)}static simplifyRegionType(e){if(e instanceof Et){if(e.children.length===1)return this.simplifyRegionType(e.children[0])}else if(e instanceof He&&e.children.length===1)return e.children[0];return e}static simplifyRegion(e){if(e instanceof oe)return e.children.length>0?e:void 0;for(let t=0;t<e.children.length;++t){const n=e.children[t],i=this.simplifyRegion(n);i?i!==n&&e.children.splice(t--,1,i):e.children.splice(t--,1)}if(e.children.length!==0)return e.children.length===1?e.children.splice(0,1)[0]:e}static getZCoordinate(e){const t=tt.createRightHandedFrame(void 0,e);return t?t.origin.z:0}static convertToRegionGroupOpType(e){return tn.Parity===e?_t.Parity:tn.Intersection===e?_t.Intersection:_t.Union}static regionBooleanXY(e,t,n,i=f.smallMetricDistance){const s=typeof i=="number",r=s?i:i.mergeTolerance??f.smallMetricDistance,a=s?!1:i.simplifyUnion??!1,o=s?_t.Union:ge.convertToRegionGroupOpType(i.operationGroupA),c=s?_t.Union:ge.convertToRegionGroupOpType(i.operationGroupB);let d;const h=jn.create(o,c);h.addMembers(e,t),h.annotateAndMergeCurvesInGraph(r);const u=O.BRIDGE_EDGE,g=h.graph.grabMask(!1),m=a?h.graph.grabMask(!1):O.NULL_MASK,p=a?[]:void 0;h.graph.clearMask(g|m);const x=this.computeMinimumArea(r),_=ge.getZCoordinate(n===tn.BMinusA?t:e),I={compress:!0,closureTol:r,bridgeMask:u,visitMask:g,z:_};let S=0;if(h.runClassificationSweep(n,(A,w,k,D)=>{if(!(w.countEdgesAroundFace()<2)&&!(Math.abs(D)<x)){if(a)k===1?S++:(w.setMaskAroundFace(m),p?.push(w));else if(k===1){const P=us.createLoopOrParityRegionInFace(w,I);P&&(d||(d=Et.create()),d.tryAddChild(P)&&S++)}}}),a&&S>0&&p&&p.length>0){h.graph.clearMask(g);const A=[];for(const w of p){const k=[],D=b=>b.isMaskSet(g)||!b.isMaskSet(m)||b.edgeMate.isMaskSet(m),P=b=>k.push(b);if(w.announceEdgesInSuperFace(D,P)){k.forEach(C=>C.setMask(g));const b=us.createLoopInFace(k,I);b&&A.push(b)}}d=this.sortOuterAndHoleLoopsXY(A)}return h.graph.dropMask(g|m),d?this.simplifyRegion(d):void 0}static polygonBooleanXYToPolyface(e,t,n,i=!1){const s=wi.doBinaryBooleanBetweenMultiLoopInputs(e,_t.Union,t,n,_t.Union,!0);return this.finishGraphToPolyface(s,i)}static polygonBooleanXYToLoops(e,t,n){const i=wi.doBinaryBooleanBetweenMultiLoopInputs(e,_t.Union,t,n,_t.Union,!0);if(!i)return;const s=Wn.collectExtendedBoundaryLoopsInGraph(i,O.EXTERIOR),r=[];for(const a of s){const o=new J;for(const d of a)o.pushXYZ(d.x,d.y,d.z);o.pushWrap(1);const c=oe.create();c.tryAddChild(N.createCapture(o)),r.push(c)}return ge.sortOuterAndHoleLoopsXY(r)}static constructPolygonWireXYOffset(e,t,n){return new ur().constructPolygonWireXYOffset(e,t,n)}static constructCurveXYOffset(e,t){const n=Kt.create(t);return $n.constructCurveXYOffset(e,n)}static testPointInOnOutRegionXY(e,t,n){return gd.testPointInOnOutRegionXY(e,t,n)}static createLoopPathOrBagOfCurves(e,t=!0,n=!1){const i=e.length;if(i===0)return;let s=0,r=!1;t&&(s=f.maxXY(s,e[0].startPoint().distance(e[i-1].endPoint())));for(let o=0;o+1<i;o++)s=f.maxXY(s,e[o].endPoint().distance(e[o+1].startPoint()));let a;f.isSmallMetricDistance(s)?(a=t?oe.create():Te.create(),r=!0):a=zt.create();for(const o of e)a.tryAddChild(o);return r&&n&&ge.consolidateAdjacentPrimitives(a),a}static _graphCheckPointFunction;static setCheckPointFunction(e){this._graphCheckPointFunction=e}static cloneCurvesWithXYSplits(e,t){return gr.cloneCurvesWithXYSplits(e,t)}static splitToPathsBetweenBreaks(e,t){if(e===void 0)return;if(e instanceof le)return e;const n=e.collectCurvePrimitives(),i=new vt(t);for(const s of n)i.announceCurvePrimitive(s);return i.grabResult()}static collectInsideAndOutsideOffsets(e,t,n){return $n.collectInsideAndOutsideXYOffsets(e,t,n)}static collectChains(e,t=f.smallMetricDistance){return $n.collectChains(e,t)}static splitPathsByRegionInOnOutXY(e,t){const n={insideParts:[],outsideParts:[],coincidentParts:[]},i=ge.cloneCurvesWithXYSplits(e,t),s=ge.splitToPathsBetweenBreaks(i,!0);if(s instanceof _e)for(const r of s.children){const a=_e.createCurveLocationDetailOnAnyCurvePrimitive(r);if(a){const o=ge.testPointInOnOutRegionXY(t,a.point.x,a.point.y);Do(r,o,n.outsideParts,n.coincidentParts,n.insideParts)}}else if(s instanceof le){const r=_e.createCurveLocationDetailOnAnyCurvePrimitive(s);if(r){const a=ge.testPointInOnOutRegionXY(t,r.point.x,r.point.y);Do(s,a,n.outsideParts,n.coincidentParts,n.insideParts)}}return n}static rectangleEdgeTransform(e,t=!0){if(e instanceof N)return this.rectangleEdgeTransform(e.packedPoints);if(e instanceof gt){let n;if(t&&e.length===5){if(!e.almostEqualUncheckedIndexIndex(0,4))return;n=e}else if(!t&&e.length===4)n=e;else{if(e.length<(t?5:4))return;if(n=J.create(e),rt.compressInPlaceByShortEdgeLength(n,f.smallMetricDistance),n.length<(t?5:4))return}n.length>=4;const i=n.vectorUncheckedIndexIndex(0,1),s=n.vectorUncheckedIndexIndex(0,3),r=n.vectorUncheckedIndexIndex(1,2),a=i.crossProduct(s);if(a.normalizeInPlace()&&r.isAlmostEqual(s)&&i.isPerpendicularTo(s))return X.createOriginAndMatrixColumns(n.getPoint3dAtUncheckedPointIndex(0),i,s,a)}else{if(Array.isArray(e))return this.rectangleEdgeTransform(new Qe(e),t);if(e instanceof oe&&e.children.length===1&&e.children[0]instanceof N)return this.rectangleEdgeTransform(e.children[0].packedPoints,!0);if(e instanceof Te&&e.children.length===1&&e.children[0]instanceof N)return this.rectangleEdgeTransform(e.children[0].packedPoints,t);if(e instanceof mt&&!e.checkForNonLinearPrimitives()){const n=e.getPackedStrokes();if(n)return this.rectangleEdgeTransform(n)}}}static consolidateAdjacentPrimitives(e,t){const n=new fd(t);e.dispatchToGeometryHandler(n)}static sortOuterAndHoleLoopsXY(e){const t=[];for(const n of e)if(n instanceof oe)ai.pushLoop(t,n);else if(n instanceof gt){const i=oe.createPolygon(n);ai.pushLoop(t,i)}return ai.sortAsAnyRegion(t)}static getEdgeGeometry(e,t){let n=!1,i=!1,s=!1,r=!1;return e.edgeTag instanceof Y&&e.edgeTag.curve!==void 0&&e.edgeTag.isInterval()&&e.sortData&&t.edgeTag instanceof Y&&t.edgeTag.curve!==void 0&&t.edgeTag.isInterval()&&t.sortData&&(n=e.edgeTag.curve===t.edgeTag.curve||e.edgeTag.curve.isAlmostEqual(t.edgeTag.curve),i=!n&&e.edgeTag.curve.isAlmostEqual(t.edgeTag.curve.clone().reverse()),s=e.sortData>0,r=t.sortData>0),{sameCurves:n,reversedCurves:i,senseEdge0:s,senseEdge1:r}}static areEdgesDiametric(e,t){let n=!1,i=!1,s=!1,r=!1;if(e!==t){const a=ge.getEdgeGeometry(e,t);i=a.reversedCurves,s=a.senseEdge0,r=a.senseEdge1,n=a.sameCurves&&s!==r||i&&s===r}return{diametric:n,reversedCurves:i,senseEdge0:s,senseEdge1:r}}static isHealableEdgeOrNullFace(e,t){if(t){if(!e.findAroundVertex(t))return!1}else if(t=e.vertexSuccessor,t.vertexSuccessor!==e)return!1;const n=ge.areEdgesDiametric(e,t);if(!n.diametric)return!1;const i=n.senseEdge0?e.edgeTag.fraction:e.edgeTag.fraction1;let s=n.senseEdge1?t.edgeTag.fraction:t.edgeTag.fraction1;return n.reversedCurves&&(s=1-s),f.isSmallRelative(i-s)}static isHealableNullFaceBundle(e){const t=[],n=[],i=o=>{const c=o.faceSuccessor;return c.faceSuccessor===o&&ge.areEdgesDiametric(o,c).diametric};e.announceEdgesAroundVertex(o=>{i(o)||t.push(n.length),n.push(o)});const s=n.length;if(s<4||t.length!==2||f.modulo(s,2)>0)return{isHealable:!1};const r=t[0];if(t[1]-r!==s/2)return{isHealable:!1};const a=[];for(let o=1;o<s/2;o++){const c=f.modulo(r+o,s),d=f.modulo(2*r-c,s);if(!ge.isHealableEdgeOrNullFace(n[c],n[d]))return{isHealable:!1};a.push([n[c],n[d]])}return{isHealable:!0,nullFacePairs:a}}static healSplitEdgeAndCurve(e){const t=e.vertexSuccessor,n=U.healEdge(e,!1);if(!n)return;const i=(s,r)=>{const a=ge.getEdgeGeometry(s,r);a.sameCurves||a.reversedCurves;let o=a.senseEdge0?s.edgeTag.fraction1:s.edgeTag.fraction;a.reversedCurves&&(o=1-o);const c=a.senseEdge0?s.edgeTag.point1:s.edgeTag.point;a.senseEdge1?r.edgeTag.captureFraction1Point1(o,c):r.edgeTag.captureFractionPoint(o,c)};i(e,n),i(t,n.edgeMate)}static isolateExtraneousBridgeEdges(e,t,n){const i=[],s=[],r=c=>{c.isDangling||i.push(c.vertexSuccessor),c.edgeMate.isDangling||i.push(c.edgeMate.vertexSuccessor),c.isolateEdge()};e.announceEdges((c,d)=>(t(d)&&(d.isDangling||d.edgeMate.isDangling||!d.findAroundFace(d.edgeMate)||n(d)<0?r(d):s.push(d)),!0));const a=c=>c.isIsolatedEdge?!1:n(c)<0?!0:c.findAroundFace(c.edgeMate)?!1:n(c.edgeMate)<0;let o;do{o=0;for(const c of s)a(c)&&(r(c),o++)}while(o>0);return i.filter(c=>!c.isIsolatedEdge)}static removeExtraneousBridgeEdges(e,t,n){n||(n=s=>Wn.signedFaceArea(s)),t||(t=s=>s.isMaskSet(O.BRIDGE_EDGE));const i=ge.isolateExtraneousBridgeEdges(e,t,n);for(const s of i){if(s.isDangling||s.isIsolatedEdge)continue;if(ge.isHealableEdgeOrNullFace(s)){ge.healSplitEdgeAndCurve(s);continue}const r=ge.isHealableNullFaceBundle(s);if(r.isHealable&&r.nullFacePairs){for(const[a,o]of r.nullFacePairs)U.pinch(a,o);for(const[a,o]of r.nullFacePairs)ge.healSplitEdgeAndCurve(a),ge.healSplitEdgeAndCurve(o)}}return e.deleteIsolatedEdges()}static collectRegionsAndClosedPrimitives(e,t,n=f.smallMetricDistance){const i=[];Array.isArray(e)||(e=[e]);for(const s of e)s instanceof oe||s instanceof He||s instanceof Et?i.push(s):s instanceof Te&&s.isPhysicallyClosedCurve(n)?i.push(oe.create(...s.children)):s instanceof le&&s.isPhysicallyClosedCurve(n)?i.push(oe.create(s)):t&&t.push(s);return i}static constructAllXYRegionLoops(e,t=f.smallMetricDistance,n=!0){t=Mt.scaleToleranceForGeometry(e,t,{xyOnly:!0});let i=ge.collectCurvePrimitives(e,void 0,!0,!0);i=fr.clone(zt.create(...i)).children;let s=!1;if(n){const d=jn.create(_t.Union,_t.Union),h=[],u=this.collectRegionsAndClosedPrimitives(e,h,t);s=h.length>0,u.length>0&&(d.addMembers(u,void 0),d.annotateAndMergeCurvesInGraph(t),d.graph.announceEdges((g,m)=>{if(m.isMaskSet(O.BRIDGE_EDGE)){const p=Q.create(m.getPoint3d(),m.faceSuccessor.getPoint3d());p.parent=new hi(p,d.extraGeometry),i.push(p)}return!0}))}const r=1e4*f.smallAngleRadians,a=sn.allIntersectionsAmongPrimitivesXY(i,t),o=us.assembleHalfEdgeGraph(i,a,t,r);n&&s&&ge.removeExtraneousBridgeEdges(o);const c=this.computeMinimumArea(t);return us.collectSignedLoopSetsInHalfEdgeGraph(o,t,c)}static collectCurvePrimitives(e,t,n=!1,i=!1){const s=t===void 0?[]:t;if(e instanceof le)e.collectCurvePrimitives(s,n,i);else if(e instanceof _e)e.collectCurvePrimitives(s,n,i);else if(Array.isArray(e))for(const r of e)this.collectCurvePrimitives(r,s,n,i);return s}static expandLineStrings(e){const t=[];for(const n of e)if(n instanceof N)for(let i=0;i+1<n.packedPoints.length;i++){const s=n.getIndexedSegment(i);s!==void 0&&t.push(s)}else t.push(n);return t}static curveArrayRange(e,t){const n=ie.create();if(e instanceof Mt)e.extendRange(n,t);else if(Array.isArray(e))for(const i of e)i instanceof Mt?i.extendRange(n,t):i instanceof y?n.extendPoint(i,t):i instanceof J?n.extendRange(i.getRange(t)):Array.isArray(i)&&n.extendRange(this.curveArrayRange(i,t));return n}static triangulateStrokedRegionComponent(e){let t;if(Array.isArray(e)){if(e.length===0)return;const n=e[0];if(y.isAnyImmediatePointType(n))t=W.createTriangulatedGraphFromSingleLoop(e);else if(e.length>1){let i;if(n instanceof Fs)i=e;else{i=[];for(const r of e)i.push(J.create(r))}const s=re.sortOuterAndHoleLoopsXY(i);s.length===1&&(t=W.createTriangulatedGraphFromLoops(s[0]))&&W.flipTriangles(t)}else t=W.createTriangulatedGraphFromSingleLoop(n)}else t=W.createTriangulatedGraphFromSingleLoop(e);return t||(t=wi.doPolygonBoolean(e,[],(n,i)=>n))&&W.triangulateAllPositiveAreaFaces(t)&&W.flipTriangles(t),t}static strokeRegionComponent(e,t){const n=e.cloneStroked(t),i=[];if(n instanceof oe)n.children.length>0&&n.children[0]instanceof N&&i.push(n.children[0].packedPoints);else if(n instanceof He)for(const s of n.children)s.children.length>0&&s.children[0]instanceof N&&i.push(s.children[0].packedPoints);return i}static triangulateRegionComponent(e,t){const n=this.strokeRegionComponent(e,t);return this.triangulateStrokedRegionComponent(n)}static facetRegionXY(e,t){let n;if(e instanceof Et)for(const i of e.children){const s=ge.triangulateRegionComponent(i,t);s&&(n?n.allHalfEdges.push(...s.allHalfEdges):n=s)}else n=this.triangulateRegionComponent(e,t);if(n)return t?.maximizeConvexFacets&&qe.expandConvexFaces(n),ce.graphToPolyface(n,t)}static convexDecomposePolygonXY(e,t=!0){const n=ge.triangulateStrokedRegionComponent(e);if(!n)return;t&&qe.expandConvexFaces(n);const i=[];return n.announceFaceLoops((s,r)=>(r.isMaskSet(O.EXTERIOR)||i.push(J.create(r.collectAroundFace(a=>a.getPoint3d()))),!0)),i}}function Do(l,e,t,n,i){e>0?i.push(l):e<0?t.push(l):n.push(l)}class St{_chains;_gapTolerance;_planeTolerance;static _staticPointA;static _staticPointB;_xyzWork0;_xyzWork1;constructor(e=f.smallMetricDistance,t){this._chains=[],this._gapTolerance=e,this._planeTolerance=t}findAnyChainToConnect(e,t=-1){for(let n=0;n<this._chains.length;n++){if(t===n)continue;const i=this._chains[n];if(this._xyzWork1=i[i.length-1].endPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(e,this._gapTolerance))return{chainIndex:n,atEnd:!0};if(this._xyzWork1=i[0].startPoint(this._xyzWork1),this._xyzWork1.isAlmostEqual(e,this._gapTolerance))return{chainIndex:n,atEnd:!1}}}captureCurvePrimitive(e){this.attachPrimitiveToAnyChain(e)||this._chains.push([e])}captureCurve(e){if(e instanceof le)this.captureCurvePrimitive(e);else if(e instanceof _e)for(const t of e.children)this.captureCurve(t)}simpleEndPointMove(e,t,n){if(e instanceof Q)return t?e.point1Ref.setFrom(n):e.point0Ref.setFrom(n),!0;if(e instanceof N&&e.numPoints()>0){const i=t?e.numPoints()-1:0;return e.packedPoints.setAtCheckedPointIndex(i,n),!0}return!1}moveHeadOrTail(e,t){const n=e.endPoint(),i=t.startPoint(),s=f.smallMetricDistance*.001;let r=n.distanceSquaredXY(i);if(r<=s*s)return!1;const a=this._gapTolerance*this._gapTolerance;if(r>a)return!1;if(this.simpleEndPointMove(t,!1,n)||this.simpleEndPointMove(e,!0,i))return!0;if(!(e instanceof B&&t instanceof B))return!1;const o=sn.intersectionXYPairs(e,!0,t,!0);let c=-1,d=1/0;for(let h=0;h<o.length;++h){const u=o[h].detailA.point.distanceSquaredXY(n),g=o[h].detailB.point.distanceSquaredXY(i);r=u+g,u<=a&&g<=a&&r<d&&(d=r,c=h)}if(c>=0){const h=e.sweep.fractionToRadians(o[c].detailA.fraction);e.sweep.setStartEndRadians(e.sweep.startRadians,h);const u=t.sweep.fractionToRadians(o[c].detailB.fraction);return t.sweep.setStartEndRadians(u,t.sweep.endRadians),!0}return!1}attachPrimitiveToAnyChain(e){if(e.curveLength()<this._gapTolerance)return!0;{this._xyzWork0=e.startPoint(this._xyzWork0);let t=this.findAnyChainToConnect(this._xyzWork0);if(t)if(t.atEnd){const n=this._chains[t.chainIndex],i=n.length-1;return this._chains[t.chainIndex].push(e),this.moveHeadOrTail(n[i],n[i+1]),this.searchAndMergeChainIndex(t.chainIndex),!0}else{e.reverseInPlace();const n=this._chains[t.chainIndex];return n.splice(0,0,e),this.moveHeadOrTail(n[0],n[1]),this.searchAndMergeChainIndex(t.chainIndex),!0}else if(this._xyzWork0=e.endPoint(this._xyzWork0),t=this.findAnyChainToConnect(this._xyzWork0),t)if(t.atEnd){e.reverseInPlace();const n=this._chains[t.chainIndex],i=n.length-1;return this._chains[t.chainIndex].push(e),this.moveHeadOrTail(n[i],n[i+1]),this.searchAndMergeChainIndex(t.chainIndex),!0}else{const n=this._chains[t.chainIndex];return n.splice(0,0,e),this.moveHeadOrTail(n[0],n[1]),this.searchAndMergeChainIndex(t.chainIndex),!0}}return!1}mergeChainsForwardForward(e,t){const n=this._chains[e],i=this._chains[t];for(const r of i)n.push(r);i.length=0;const s=this._chains.length-1;t!==s&&(this._chains[t]=this._chains[s]),this._chains.pop()}reverseChain(e){const t=this._chains[e];t.reverse();for(const n of t)n.reverseInPlace()}searchAndMergeChainIndex(e){const t=this._chains[e],n=t.length-1;this._xyzWork0=t[0].startPoint(this._xyzWork0);let i=this.findAnyChainToConnect(this._xyzWork0,e);if(i){i.atEnd||this.reverseChain(i.chainIndex),this.mergeChainsForwardForward(i.chainIndex,e);return}if(this._xyzWork0=t[n].endPoint(this._xyzWork0),i=this.findAnyChainToConnect(this._xyzWork0,e),i){i.atEnd&&this.reverseChain(i.chainIndex),this.mergeChainsForwardForward(e,i.chainIndex);return}}promoteArrayToCurves(e,t){if(e.length!==0){if(t){const n=e[0],i=e[e.length-1];if(St._staticPointA=n.startPoint(St._staticPointA),St._staticPointB=i.endPoint(St._staticPointB),this.moveHeadOrTail(i,n)&&(St._staticPointA=n.startPoint(St._staticPointA),St._staticPointB=i.endPoint(St._staticPointB)),St._staticPointA.isAlmostEqual(St._staticPointB,this._gapTolerance)){const s=tt.createRightHandedLocalToWorld(e);if(s){const r=s.inverse();if(r){const a=ge.curveArrayRange(e,r);if(this._planeTolerance!==void 0&&a.zLength()<=this._planeTolerance)return oe.createArray(e)}}return Te.createArray(e)}}return e.length===1?e[0]:Te.createArray(e)}}chainToLineString3d(e,t){if(e.length===0)return;const n=N.create();for(const i of e)i.emitStrokes(n,t);return n.removeDuplicatePoints(this._gapTolerance),n}grabResult(e=!1){const t=this._chains;if(t.length===0)return;if(t.length===1)return this.promoteArrayToCurves(t[0],e);const n=zt.create();for(const i of t){const s=this.promoteArrayToCurves(i,e);n.tryAddChild(s)}return n}announceChainsAsLineString3d(e,t){const n=this._chains;if(n.length===1){const i=this.chainToLineString3d(n[0],t);i&&e(i)}else if(n.length>1)for(const i of n){const s=this.chainToLineString3d(i,t);s&&e(s)}}}class $n{static sumLengths(e){let t=0;if(e instanceof le)t+=e.curveLength();else if(e instanceof _e)t+=e.sumLengths();else if(Array.isArray(e))for(const n of e)t+=this.sumLengths(n);return t}static extendRange(e,t,n){if(Array.isArray(t))for(const i of t)this.extendRange(e,i,n);else t.extendRange(e,n);return e}static appendXYOffsets(e,t,n){let i=0;if(e instanceof le){const s=Ai.constructCurveXYOffset(Te.create(e),t);s&&(i+=this.sumLengths(s),n.push(s))}else if(e instanceof oe||e instanceof Te){const s=Ai.constructCurveXYOffset(e,t);s&&(i+=this.sumLengths(s),n.push(s))}else if(e instanceof zt)for(const s of e.children)i+=this.appendXYOffsets(s,t,n);else if(Array.isArray(e))for(const s of e)i+=this.appendXYOffsets(s,t,n);return i}static collectInsideAndOutsideXYOffsets(e,t,n){const i=new St(n,n);for(const d of e)i.captureCurve(d);const s=i.grabResult(!0),r=[],a=[],o=$n.appendXYOffsets(s,t,r),c=$n.appendXYOffsets(s,-t,a);return o>c?{outsideOffsets:r,insideOffsets:a,chains:s}:{insideOffsets:r,outsideOffsets:a,chains:s}}static constructCurveXYOffset(e,t){return Ai.constructCurveXYOffset(e,t)}static createSingleOffsetPrimitiveXY(e,t){return Ai.createSingleOffsetPrimitiveXY(e,t)}static collectChains(e,t=f.smallMetricDistance,n){const i=new St(t,n);for(const s of e)i.captureCurve(s);return i.grabResult(!0)}static collectChainsAsLineString3d(e,t,n,i=f.smallMetricDistance,s){const r=new St(i);for(const a of e)r.captureCurve(a);r.announceChainsAsLineString3d(t,n)}static computeLocalRange(e,t,n){const i=[e];if(n&&i.push(n),n=tt.createRightHandedFrame(v.unitZ(),...i),!n)return!1;const s=n.inverse();return t.setNull(),Array.isArray(e)||!(e instanceof Mt)?ie.createFromVariantData(e,s,t):this.extendRange(t,e,s),!0}static isPlanar(e,t){const n=ie.create(),i=t?.localToWorld??X.createIdentity();if(!this.computeLocalRange(e,n,i))return;const s=t?.maxDeviation??f.smallMetricDistance;return n.zLength()<=Math.abs(s)?i:void 0}static isColinear(e,t){const n=ie.create(),i=t?.localToWorld??X.createIdentity();if(!this.computeLocalRange(e,n,i))return;const s=Math.abs(t?.maxDeviation??f.smallMetricDistance);if(n.zLength()>s)return;const r=t?.colinearRay??q.createZero();r.origin.setFrom(i.origin);const a=n.xLength(),o=n.yLength();if(a<=s&&o<=s)return r.direction.setZero(),r;if(o<=s)return i.matrix.columnX(r.direction),r;if(a<=s)return i.matrix.columnY(r.direction),r;if(!t?.xyColinear)return;const c=Math.abs(t?.radianTolerance??f.smallAngleRadians);if(!(Math.abs(i.matrix.columnDotXYZ(Jt.Z,0,0,1))>c))return a>o?i.matrix.columnX(r.direction):i.matrix.columnY(r.direction),r.direction.z=0,r}}class In{static edgeLengthRange(e){const t=fe.createNull();for(let n=1;n<e.length;n++)t.extendX(e[n-1].distance(e[n]));return t}static compressByChordError(e,t=f.smallMetricDistance,n=!1){return rt.compressPoint3dArrayByChordError(e,t,n)}static compressShortEdges(e,t){const n=J.create(e);return rt.compressInPlaceByShortEdgeLength(n,t),n.getPoint3dArray()}static compressSmallTriangles(e,t){const n=J.create(e);return rt.compressInPlaceBySmallTriangleArea(n,t),n.getPoint3dArray()}static compressByPerpendicularDistance(e,t,n=2){const i=J.create(e);let s=i.length;for(let r=0;r<n;r++){rt.compressInPlaceByPerpendicularDistance(i,t);const a=i.length;if(a===s)break;s=a}return i.getPoint3dArray()}static squaredDistanceToInterpolatedPoint(e,t,n,i){const s=1-n,r=e.x-(s*t.x+n*i.x),a=e.y-(s*t.y+n*i.y),o=e.z-(s*t.z+n*i.z);return r*r+a*a+o*o}static isDanglerConfiguration(e,t,n,i,s){if(t<0||t>=e.length)return!1;const r=e[t],a=r.distanceSquared(i);if(a<=s)return!0;if(n<0||n>=e.length)return!1;const o=e[n],c=r.dotVectorsToTargets(o,i);if(c<=0)return!1;const d=r.distanceSquared(o);let h;if(a>=d){const u=c/a;h=this.squaredDistanceToInterpolatedPoint(o,r,u,i)}else{const u=c/d;h=this.squaredDistanceToInterpolatedPoint(i,r,u,o)}return h<s}static compressDanglers(e,t=!1,n=f.smallMetricDistance){let i=e.length;const s=n*n;if(t)for(;i>1&&e[i-1].distanceSquared(e[0])<=s;)i--;const r=[];r.push(e[0].clone());for(let a=1;a<i;a++){const o=e[a];for(;this.isDanglerConfiguration(r,r.length-1,r.length-2,o,s);)r.pop();r.push(o.clone())}if(t){let a=0,o=r.length-1;for(;o>a+2;)if(this.isDanglerConfiguration(r,a,a+1,r[o],s))a++;else if(this.isDanglerConfiguration(r,o,o-1,r[a],s))o--;else break;o+1<r.length&&(r.length=o+1),a>0&&r.splice(0,a)}return r}static addClosurePoint(e){if(e.length===0)return;const t=e[0];if(Array.isArray(t)){for(const i of e)Array.isArray(i)&&this.addClosurePoint(i);return}const n=e[e.length-1];t instanceof y&&n instanceof y&&!t.isAlmostEqual(n)&&e.push(t.clone())}static removeClosurePoint(e){if(e.length===0)return;const t=e[0];if(Array.isArray(t)){for(const i of e)Array.isArray(i)&&this.removeClosurePoint(i);return}const n=e[e.length-1];t instanceof y&&n instanceof y&&t.isAlmostEqual(n)&&e.pop()}static createBisectorPlanesForDistinctPoints(e,t=!1){const n=In.compressShortEdges(e,f.smallMetricDistance);if(n.length<2)return;const i=[],s=n[0],r=n[1],a=v.createNormalizedStartEnd(s,r);if(!a)return;const o=pe.create(s,a),c=pe.createXYPlane();i.push(o.clone());for(let u=1;u+1<n.length;u++)if(v.createNormalizedStartEnd(n[u],n[u+1],a),pe.create(n[u],a,c)!==void 0){const g=o.getNormalRef().interpolate(.5,c.getNormalRef()),m=pe.create(n[u],g);m!==void 0&&i.push(m),o.setFrom(c)}const d=pe.create(n[n.length-1],o.getNormalRef());i.push(d);const h=i.length-1;if(h>0&&t){const u=i[0],g=i[h];if(f.isSamePoint3d(u.getOriginRef(),g.getOriginRef())){const m=u.getNormalRef().plus(g.getNormalRef()),p=pe.create(u.getOriginRef(),m);if(p!==void 0){i[0]=p;const x=pe.create(g.getOriginRef(),m);i[h]=x}}}return i.length>1?i:void 0}static _workSegmentA;static _workSegmentB;static _workLocalDetailPair;static closestApproach(e,t,n,i,s=Number.MAX_VALUE,r){Array.isArray(e)&&(e=new Qe(e)),Array.isArray(n)&&(n=new Qe(n));let a=s,o=!1;const c=e.length-1,d=n.length-1,h=[je.None,je.None],u=[je.None,je.None],g=(p,x,_,I)=>{p[0]=p[1]=je.None,_===0?p[0]=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(x,0):_===I-1&&(p[1]=Ge.resolveVariantCurveExtendParameterToCurveExtendMode(x,1))},m=(p,x,_)=>_===void 0?Q.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(e,p,this._workSegmentA),g(h,t,p,c);for(let x=0;x<d;x++)if(this._workSegmentB=m(n,x,this._workSegmentB),g(u,i,x,d),(this._workLocalDetailPair=Q.closestApproach(this._workSegmentA,h,this._workSegmentB,u,this._workLocalDetailPair))!==void 0){const _=this._workLocalDetailPair.detailA.a;if(_<a){const I=r?.detailA.childDetail,S=r?.detailB.childDetail;r=this._workLocalDetailPair.clone(r),N.convertLocalToGlobalDetail(r.detailA,p,c,void 0,I),N.convertLocalToGlobalDetail(r.detailB,x,d,void 0,S),r.detailA.childDetail&&r.detailB.childDetail&&(r.detailA.childDetail.curve=r.detailB.childDetail.curve=void 0),a=_,o=!0}}}return o?r:void 0}static isColinear(e,t=f.smallMetricDistance,n=!1){return e.length<3?!0:$n.isColinear(e,{maxDeviation:t,xyColinear:n})!==void 0}}class hn{point;a;v;code;closestEdgeIndex;closestEdgeParam;constructor(){this.point=new y,this.a=0,this.v=new v,this.code=we.Unknown,this.closestEdgeIndex=0,this.closestEdgeParam=0}invalidate(){this.point.setZero(),this.a=0,this.v.setZero(),this.code=we.Unknown,this.closestEdgeIndex=0,this.closestEdgeParam=0}static create(e){return e===void 0?e=new hn:e.invalidate(),e}copyContentsFrom(e){this.point.setFrom(e.point),this.a=e.a,this.v.setFrom(e.v),this.code=e.code,this.closestEdgeIndex=e.closestEdgeIndex,this.closestEdgeParam=e.closestEdgeParam}get isValid(){return this.code!==we.Unknown}get isInsideOrOn(){return this.code===we.InsidePolygon||this.code===we.OnPolygonVertex||this.code===we.OnPolygonEdgeInterior||this.code===we.InsidePolygonProjectsToVertex||this.code===we.InsidePolygonProjectsToEdgeInterior}static createAtVertexOrEdge(e,t,n=0){const i=new hn;return i.point.setFrom(e),i.closestEdgeIndex=t,i.closestEdgeParam=n,n=f.clamp(n,0,1),i.code=n>0&&n<1?we.OnPolygonEdgeInterior:we.OnPolygonVertex,i}}class mr{detailA;detailB;constructor(e,t){this.detailA=e||hn.create(),this.detailB=t||hn.create()}static create(e,t,n){return n?(n.detailA=e,n.detailB=t,n):new mr(e,t)}clone(e){return e=e||new mr,e.detailA.copyContentsFrom(this.detailA),e.detailB.copyContentsFrom(this.detailB),e}swapDetails(){const e=this.detailA;this.detailA=this.detailB,this.detailB=e}}class pr{xyz;edge;sortCoordinate0;sortCoordinate1;sortDelta;isNotch;constructor(e){this.xyz=e,this.edge=void 0,this.sortCoordinate0=this.sortCoordinate1=0,this.sortDelta=0,this.isNotch=!1}static createCaptureWithReturnEdge(e){const t=new pr(e);if(e.length>=2){const n=e.getPoint3dAtUncheckedPointIndex(0),i=e.getPoint3dAtUncheckedPointIndex(e.length-1);t.edge=q.createStartEnd(n,i)}return t}setSortCoordinates(e){if(!this.edge)return;this.sortDelta=this.edge.direction.dotProduct(e.direction);const t=e.dotProductToPoint(this.edge.origin);this.sortDelta>=0?(this.sortCoordinate0=t,this.sortCoordinate1=t+this.sortDelta):(this.sortCoordinate0=t+this.sortDelta,this.sortCoordinate1=t)}containsSortLimits(e){return e.sortCoordinate0>=this.sortCoordinate1||e.sortCoordinate0<=this.sortCoordinate0||e.sortCoordinate1<=this.sortCoordinate0||e.sortCoordinate1>=this.sortCoordinate1?0:this.sortDelta*e.sortDelta>0?1:-1}absorb(e){this.xyz.pushFromGrowableXYZArray(e.xyz),this.sortCoordinate0=e.sortCoordinate1}static sortFunction(e,t){return e.sortCoordinate0-t.sortCoordinate0>0?1:-1}}class Pd{inputLoops;outputLoops;constructor(){this.inputLoops=[],this.outputLoops=[]}mostDistantPoint(e,t,n){let i=-1;n.setZero();let s;for(const r of this.inputLoops)r.xyz.front(t)&&(s=t.distanceSquared(e),s>i&&(i=s,n.setFromPoint3d(t))),r.xyz.back(t)&&(s=t.distanceSquared(e),s>i&&(i=s,n.setFromPoint3d(t)))}sortInputs(){if(this.inputLoops.length>0&&this.inputLoops[0].xyz.length>0){const e=this.inputLoops[0].xyz.getPoint3dAtUncheckedPointIndex(0),t=y.create(),n=y.create();this.mostDistantPoint(e,t,n),this.mostDistantPoint(n,t,e);const i=q.createStartEnd(e,n);i.direction.normalizeInPlace();for(const s of this.inputLoops)s.setSortCoordinates(i);this.inputLoops.sort((s,r)=>pr.sortFunction(s,r))}}sortAndMergeLoops(){this.sortInputs();const e=this.inputLoops,t=this.outputLoops,n=[];t.length=0;for(const i of e){for(i.isNotch=!1;n.length>0;){const s=n[n.length-1],r=s.containsSortLimits(i);if(r===0){s.isNotch||t.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||t.push(i)}}class re{static sumTriangleAreas(e){let t=0;const n=e.length;if(Array.isArray(e)){if(n>=3){const s=e[0],r=s.vectorTo(e[1]);let a=v.create();for(let o=2;o<n;o++)a=s.vectorTo(e[o],a),t+=r.crossProductMagnitude(a),r.setFrom(a)}return t*.5}const i=v.create();for(let s=2;s<n;s++)e.crossProductIndexIndexIndex(0,s-1,s,i),t+=i.magnitude();return t*.5}static sumTriangleAreasPerpendicularToUpVector(e,t){let n=t.magnitude();n<f.smallMetricDistance&&(t=v.create(0,0,1),n=1);let i=0;const s=e.length;if(Array.isArray(e)){if(s>=3){const a=e[0],o=a.vectorTo(e[1]);let c=v.create();for(let d=2;d<s;d++)c=a.vectorTo(e[d],c),i+=o.tripleProduct(c,t),o.setFrom(c)}return i*.5/n}const r=v.create();for(let a=2;a<s;a++)e.crossProductIndexIndexIndex(0,a-1,a,r),i+=r.dotProduct(t);return i*.5/n}static sumTriangleAreasXY(e){let t=0;const n=e.length;if(n>=3){const i=e[0],s=i.vectorTo(e[1]);let r=v.create();for(let a=2;a<n;a++)r=i.vectorTo(e[a],r),t+=s.crossProductXY(r),s.setFrom(r)}return t*=.5,t}static _triangleMomentWeights=Ne.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=Ne.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=v.create();static _vector1=v.create();static _vector2=v.create();static _vectorOrigin=v.create();static _normal=v.create();static _matrixA=Ne.createIdentity();static _matrixB=Ne.createIdentity();static _matrixC=Ne.createIdentity();static areaNormalGo(e,t){t?t.setZero():t=new v;const n=e.length;if(n===3)e.crossProductIndexIndexIndex(0,1,2,t);else if(n>3)for(let i=2;i<n;i++)e.accumulateCrossProductIndexIndexIndex(0,i-1,i,t);return t.scaleInPlace(.5),t.isZero?void 0:t}static areaNormal(e,t){return t||(t=v.create()),re.areaNormalGo(new Qe(e),t),t}static area(e){return re.areaNormal(e).magnitude()}static areaXY(e){let t=0;if(e instanceof gt){if(e.length>2){const n=e.getXAtUncheckedPointIndex(0),i=e.getYAtUncheckedPointIndex(0);let s=e.getXAtUncheckedPointIndex(1)-n,r=e.getYAtUncheckedPointIndex(1)-i,a,o;for(let c=2;c<e.length;c++,s=a,r=o)a=e.getXAtUncheckedPointIndex(c)-n,o=e.getYAtUncheckedPointIndex(c)-i,t+=f.crossProductXYXY(s,r,a,o)}}else for(let n=1;n+1<e.length;n++)t+=e[0].crossProductToPointsXY(e[n],e[n+1]);return .5*t}static sumAreaXY(e){let t=0;for(const n of e)t+=this.areaXY(n);return t}static centroidAreaNormal(e,t){if(Array.isArray(e)){const i=new Qe(e);return this.centroidAreaNormal(i,t)}const n=e.length;if(n===3){const i=e.crossProductUncheckedIndexIndexIndex(0,1,2,t?.direction),s=.5*i.magnitude(),r=e.getPoint3dAtUncheckedPointIndex(0,t?.origin);return e.accumulateScaledXYZ(1,1,r),e.accumulateScaledXYZ(2,1,r),r.scaleInPlace(1/3),t||(t=q.createCapture(r,i)),t.tryNormalizeInPlaceWithAreaWeight(s)?t:void 0}if(n>=3){const i=v.createZero();for(let m=2;m<n;m++)e.accumulateCrossProductIndexIndexIndex(0,m-1,m,i);i.normalizeInPlace();const s=e.getPoint3dAtUncheckedPointIndex(0),r=v.create(),a=v.create();e.vectorXYAndZIndex(s,1,r);let o=v.create();const c=v.createZero(),d=v.createZero(t?.direction);let h;for(let m=2;m<n;m++){e.vectorXYAndZIndex(s,m,a),o=r.crossProduct(a,o),h=i.dotProduct(o),d.addInPlace(o);const p=h/6;c.plus2Scaled(r,p,a,p,c),r.setFrom(a)}const u=.5*d.magnitude(),g=f.conditionalDivideFraction(1,u);if(g!==void 0){const m=s.plusScaled(c,g,t?.origin);return t||(t=q.createCapture(m,d)),t.tryNormalizeInPlaceWithAreaWeight(u),t}}}static centroidAndAreaXY(e,t){let n=0;if(t.set(0,0),e.length<3)return;const i=e[0];let s=$.create(0,0),r=0;for(let o=1;o+1<e.length;o++){const c=i.vectorTo(e[o]),d=i.vectorTo(e[o+1]),h=c.crossProduct(d);s=s.plus(c.plus(d).scale(h)),r+=h}n=r*.5;const a=f.conditionalDivideFraction(1,6*n);if(a===void 0){t.setFrom(i);return}return t.setFrom(i.plusScaled(s,a)),n}static unitNormal(e,t){t.setZero();let n=e.length;return n>1&&e.getPoint3dAtUncheckedPointIndex(0).isExactEqual(e.getPoint3dAtUncheckedPointIndex(n-1))&&--n,n===3?(e.crossProductIndexIndexIndex(0,1,2,t),t.normalizeInPlace()):n===4?(e.vectorIndexIndex(0,2,re._vector0),e.vectorIndexIndex(1,3,re._vector1),re._vector0.crossProduct(re._vector1,t),t.normalizeInPlace()):(re.areaNormalGo(e,t),t.normalizeInPlace())}static addSecondMomentAreaProducts(e,t,n){this.addSecondMomentTransformedProducts(re._triangleMomentWeights,e,t,2,n)}static addSecondMomentVolumeProducts(e,t,n){this.addSecondMomentTransformedProducts(re._tetrahedralMomentWeights,e,t,3,n)}static addSecondMomentTransformedProducts(e,t,n,i,s){const r=re._normal;if(re.unitNormal(t,r)){const a=re._vector0,o=re._vector1,c=re._vector2,d=re._matrixA,h=re._matrixB,u=re._matrixC,g=t.vectorXYAndZUncheckedIndex(n,0,re._vectorOrigin),m=t.length;let p=0;for(let x=2;x<m;x++)i===2?(t.vectorIndexIndex(0,x-1,a),t.vectorIndexIndex(0,x,o),p=r.tripleProduct(a,o),d.setOriginAndVectors(g,a,o,r),d.multiplyMatrixMatrix(e,h),h.multiplyMatrixMatrixTranspose(d,u),s.addScaledInPlace(u,p)):i===3&&(t.vectorXYAndZIndex(n,0,a),t.vectorXYAndZIndex(n,x-1,o),t.vectorXYAndZIndex(n,x,c),p=a.tripleProduct(o,c),d.setOriginAndVectors(n,a,o,c),d.multiplyMatrixMatrix(e,h),h.multiplyMatrixMatrixTranspose(d,u),s.addScaledInPlace(u,p))}}static volumeBetweenPolygonAndPlane(e,t,n){let i,s,r=0,a=0;if(e.length>=3){const o=e.evaluateUncheckedIndexPlaneAltitude(0,t);for(let c=1;c+1<e.length;c++){const d=e.crossProductUncheckedIndexIndexIndex(0,c,c+1,n?.workVector),h=e.evaluateUncheckedIndexPlaneAltitude(c,t),u=e.evaluateUncheckedIndexPlaneAltitude(c+1,t),g=d.dotProductXYZ(t.normalX(),t.normalY(),t.normalZ());r+=g,a+=g*(o+h+u)}n?.skipMoments||(i=e.getPoint3dAtUncheckedPointIndex(0,n?.workPoint0),s=Ne.createZero(n?.workMatrix),e.mapPoint((c,d,h)=>t.projectXYZToPlane(c,d,h,n?.workPoint1)),re.addSecondMomentAreaProducts(e,i,s))}return{volume6:a,area2:r,origin:i,products:s}}static testXYPolygonTurningDirections(e){let t=e.length,n=t-1;for(;n>1&&e[n].x===e[0].x&&e[n].y===e[0].y;)t=n--;if(t>2){let i=L.create(e[n].x-e[n-1].x,e[n].y-e[n-1].y);const s=L.create(e[0].x-e[n].x,e[0].y-e[n].y),r=i.x*s.y-i.y*s.x;for(let a=1;a<t;a++)if(i=s.clone(),L.create(e[a].x-e[a-1].x,e[a].y-e[a-1].y,s),(i.x*s.y-i.y*s.x)*r<=0)return 0;return r>0?1:-1}return 0}static isConvex(e){if(!(e instanceof gt))return this.isConvex(new Qe(e));let t=e.length;t>1&&e.getPoint3dAtUncheckedPointIndex(0).isExactEqual(e.getPoint3dAtUncheckedPointIndex(t-1))&&--t;const n=v.create();if(!this.unitNormal(e,n))return!1;let i=0,s=0;const r=this._vector0;let a=v.createStartEnd(e.getPoint3dAtUncheckedPointIndex(t-1),e.getPoint3dAtUncheckedPointIndex(0),this._vector1);for(let o=1;o<=t;o++){r.setFromVector3d(a),a=v.createStartEnd(e.getPoint3dAtUncheckedPointIndex(o-1),e.getPoint3dAtUncheckedPointIndex(o%t),a);const c=n.tripleProduct(r,a);c>=0?i+=c:s+=c}return Math.abs(s)<f.smallMetricDistanceSquared*i}static classifyPointInPolygon(e,t,n){const i=new sa(e,t);let s=0;const r=n.length;let a,o=-1;for(s=0;s<r;s++)if(a=s+1,a>=r&&(a=0),i.tryStartEdge(n[s].x,n[s].y,n[a].x,n[a].y)){o=a;break}if(!(o<0)){for(let c=1;c<=r;c++)if(a=o+c,a>=r&&(a-=r),!i.advance(n[a].x,n[a].y))return i.classifyCounts();return i.classifyCounts()}}static classifyPointInPolygonXY(e,t,n){const i=new sa(e,t);let s=0;const r=n.length;let a,o=-1;for(s=0;s<r;s++)if(a=s+1,a>=r&&(a=0),i.tryStartEdge(n.getXAtUncheckedPointIndex(s),n.getYAtUncheckedPointIndex(s),n.getXAtUncheckedPointIndex(a),n.getYAtUncheckedPointIndex(a))){o=a;break}if(!(o<0)){for(let c=1;c<=r;c++)if(a=o+c,a>=r&&(a-=r),!i.advance(n.getXAtUncheckedPointIndex(a),n.getYAtUncheckedPointIndex(a)))return i.classifyCounts();return i.classifyCounts()}}static orientLoopsCCWForOutwardNormalInPlace(e,t){if(e instanceof gt)return this.orientLoopsCCWForOutwardNormalInPlace([e],t);const n=v.create();let i=0;for(const s of e)this.unitNormal(s,n)&&n.dotProduct(t)<0&&(s.reverseInPlace(),i++);return i}static sortOuterAndHoleLoopsXY(e){const t=[];for(const n of e)ai.pushPolygon(t,n);return ai.sortAsArrayOfArrayOfPolygons(t)}static sortOuterAndHoleLoops(e,t){const n=tt.createRightHandedFrame(t,e),i=n?.inverse(),s=[];if(i!==void 0)for(const o of e){const c=new J(o.length);for(const d of o.points)c.push(i.multiplyPoint3d(d));s.push(c)}const r=re.sortOuterAndHoleLoopsXY(s),a=[];if(n!==void 0)for(const o of r){const c=[];for(const d of o){const h=new J(d.length);for(const u of d.points)h.push(n.multiplyPoint3d(u));c.push(h)}a.push(c)}return a}static closestPointOnBoundary(e,t,n=f.smallMetricDistance,i){if(!(e instanceof gt))return this.closestPointOnBoundary(new Qe(e),t,n,i);const s=Array.isArray(n)?n[0]:n,r=Array.isArray(n)?Math.abs(n[1]):0,a=s*s;let o=e.length;for(;o>1&&!(e.distanceSquaredUncheckedIndexIndex(0,o-1)>a);)--o;if(i=hn.create(i),o===0)return i;const c=m=>(e.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=i.point.distance(t),i.v.setZero(),i.code=we.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i);if(o===1)return c(0);const d=m=>{let p=!1,x=0,_=0,I=0;if(m>=0&&m<o){let S=m+1;S===o&&(S=0),_=e.distanceSquaredUncheckedIndexIndex(m,S),_>a&&(I=e.distanceSquaredUncheckedIndexXYAndZ(m,t),x=e.dotProductUncheckedIndexIndexXYAndZ(m,S,t)/_,p=!0)}return{isValid:p,edgeParam:x,uDotU:_,vDotV:I}};let h=!1,u=o-1;for(;u>0;--u){const m=d(u);if(m.isValid){h=m.edgeParam>1+r;break}}if(u<=0)return c(0);let g=f.largeCoordinateResult;for(let m=0;m<o;++m){let p=m+1;p===o&&(p=0);const x=d(m);if(x.isValid){if(x.edgeParam<=r){const _=x.vDotV;if(_<=a)return e.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(_),i.v.setZero(),i.code=we.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i;_<g&&h&&(e.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(_),e.crossProductUncheckedIndexIndexIndex(m,u,p,i.v),i.code=we.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,g=_),h=!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(_<=a){const I=x.vDotV;if(x.edgeParam<=.5&&I<=a)return e.getPoint3dAtUncheckedPointIndex(m,i.point),i.a=Math.sqrt(I),i.v.setZero(),i.code=we.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=0,i;const S=_+(1-x.edgeParam)*(1-x.edgeParam)*x.uDotU;return x.edgeParam>.5&&S<=a?(e.getPoint3dAtUncheckedPointIndex(p,i.point),i.a=Math.sqrt(S),i.v.setZero(),i.code=we.OnPolygonVertex,i.closestEdgeIndex=p,i.closestEdgeParam=0,i):(e.interpolateIndexIndex(m,x.edgeParam,p,i.point),i.a=Math.sqrt(_),i.v.setZero(),i.code=we.OnPolygonEdgeInterior,i.closestEdgeIndex=m,i.closestEdgeParam=x.edgeParam,i)}_<g&&(e.interpolateIndexIndex(m,x.edgeParam,p,i.point),i.a=Math.sqrt(_),e.crossProductUncheckedIndexIndexXYAndZ(m,p,t,i.v),i.code=x.edgeParam<1?we.OnPolygonEdgeInterior:we.OnPolygonVertex,i.closestEdgeIndex=m,i.closestEdgeParam=x.edgeParam,g=_),h=!1}else h=!0;u=m}}return i}static closestPoint(e,t,n=f.smallMetricDistance,i){if(!(e instanceof gt))return this.closestPoint(new Qe(e),t,n,i);if(!this.unitNormal(e,this._normal))return hn.create(i);const s=this._workPlane=pe.createXYZUVW(e.getXAtUncheckedPointIndex(0),e.getYAtUncheckedPointIndex(0),e.getZAtUncheckedPointIndex(0),this._normal.x,this._normal.y,this._normal.z,this._workPlane),r=this._workXYZ=s.projectPointToPlane(t,this._workXYZ);return i=this.closestPointOnBoundary(e,r,n,i),i.isValid&&(i.v.dotProduct(this._normal)>0&&(i.point.setFrom(r),we.OnPolygonVertex===i.code?i.code=we.InsidePolygonProjectsToVertex:we.OnPolygonEdgeInterior===i.code&&(i.code=we.InsidePolygonProjectsToEdgeInterior)),i.a=t.distance(i.point),i.v.setZero()),i}static _workXYZ;static _workXY0;static _workXY1;static _workXY2;static _workRay;static _workMatrix3d;static _workPlane;static intersectRay3d(e,t,n=f.smallMetricDistance,i){if(!(e instanceof gt))return this.intersectRay3d(new Qe(e),t,n,i);if(!this.unitNormal(e,this._normal))return hn.create(i);this._workPlane=pe.createXYZUVW(e.getXAtUncheckedPointIndex(0),e.getYAtUncheckedPointIndex(0),e.getZAtUncheckedPointIndex(0),this._normal.x,this._normal.y,this._normal.z,this._workPlane),this._workPlane;const s=this._workXYZ=y.createZero(this._workXYZ),r=t.intersectionWithPlane(this._workPlane,s);if(r===void 0)return hn.create(i);if(i=this.closestPointOnBoundary(e,s,n,i),i.isValid){i.point.setFrom(s),i.a=r;const a=i.v.dotProduct(this._normal);a===0||(we.OnPolygonVertex===i.code?i.code=a>0?we.InsidePolygonProjectsToVertex:we.OutsidePolygonProjectsToVertex:we.OnPolygonEdgeInterior===i.code&&(i.code=a>0?we.InsidePolygonProjectsToEdgeInterior:we.OutsidePolygonProjectsToEdgeInterior))}return i}static intersectSegment(e,t,n,i=f.smallMetricDistance,s){return this._workRay=q.createStartEnd(t,n,this._workRay),this.intersectRay3d(e,this._workRay,i,s)}static computeEdgeDataXY(e,t,n,i,s=f.smallMetricDistance,r){const a=t%e.length,o=(a+1)%e.length;e.vectorUncheckedIndexIndex(a,o,i).unitPerpendicularXY(i).negate(i);const c=e.getXAtUncheckedPointIndex(a)-n.x,d=e.getYAtUncheckedPointIndex(a)-n.y;let h=f.dotProductXYXY(c,d,i.x,i.y);const u=f.crossProductXYXY(c,d,i.x,i.y),g=f.distanceXYXY(e.getXAtUncheckedPointIndex(a),e.getYAtUncheckedPointIndex(a),e.getXAtUncheckedPointIndex(o),e.getYAtUncheckedPointIndex(o));let m=f.safeDivideFraction(u,g,0);return f.isSameCoordinate(0,h,s)&&(h=0),f.isSameCoordinate(0,m,s)?m=0:f.isSameCoordinate(1,m,s)&&(m=1),L.create(h,m,r)}static convexBarycentricCoordinatesOnEdge(e,t,n,i,s,r,a,o){const c=!n.isZero&&i.x===0&&f.isIn01(i.y),d=!r.isZero&&a.x===0&&f.isIn01(a.y);if(c&&d)return o.fill(0),o[s]=1,o;const h=e.length;if(c){o.fill(0);const u=t,g=s,m=i.y;return o[u]=1-m,o[g]=m,o}if(d){o.fill(0);const u=s,g=(s+1)%h,m=a.y;return o[u]=1-m,o[g]=m,o}}static convexBarycentricCoordinates(e,t,n=f.smallMetricDistance){if(Array.isArray(e))return this.convexBarycentricCoordinates(new Qe(e),t);let i=e.length;for(;i>1&&e.getPoint3dAtUncheckedPointIndex(0).isExactEqual(e.getPoint3dAtUncheckedPointIndex(i-1));)--i;if(i<3||!re.unitNormal(e,this._normal))return;const s=this._workMatrix3d=E.createRigidHeadsUp(this._normal,ve.ZXY,this._workMatrix3d),r=new J(i);for(let _=0;_<i;++_){const I=this._workXYZ=s.multiplyInverseXYZAsPoint3d(e.getXAtUncheckedPointIndex(_),e.getYAtUncheckedPointIndex(_),e.getZAtUncheckedPointIndex(_),this._workXYZ);r.push(I)}this._workXYZ;const a=s.multiplyInverseXYZAsPoint3d(t.x,t.y,t.z,this._workXYZ);let o=i-1;const c=this._vector0,d=this._workXY0=this.computeEdgeDataXY(r,o,a,c,n,this._workXY0);if(d.x<0)return;const h=v.createFrom(c,this._vector1),u=this._workXY1=L.createFrom(d,this._workXY1),g=Array(e.length).fill(0),m=n>0?1/(n*n):f.largeCoordinateResult;let p=0;for(let _=0;_<i;++_){const I=v.createFrom(c,this._vector2),S=this._workXY2=_<i-1?this.computeEdgeDataXY(r,_,a,I,n,this._workXY2):L.createFrom(d,this._workXY2);if(S.x<0)return;if(this.convexBarycentricCoordinatesOnEdge(r,o,h,u,_,I,S,g)!==void 0)return g;if(I.x===0&&I.y===0||u.x===0||S.x===0)continue;const A=Math.abs(h.crossProductXY(I)),w=f.conditionalDivideCoordinate(A,u.x*S.x,m);g[_]=w,p+=w,h.setFrom(I),u.setFrom(S),o=_}const x=f.conditionalDivideCoordinate(1,p);for(let _=0;_<i;++_)g[_]*=x;return g}static forceClosure(e,t=f.smallMetricDistance){e.length>=2&&(e instanceof J?e.forceClosure(t):e[0].distance(e[e.length-1])>t?e.push(e[0].clone()):e[e.length-1].setFromPoint3d(e[0]))}static ensureClosed(e,t=f.smallMetricDistance){if(e.length>=2){let n=!1;if(e instanceof gt?n=!e.almostEqualIndexIndex(0,e.length-1,0):n=!e[0].isExactEqual(e[e.length-1]),n){const i=J.create(e);this.forceClosure(i,t),e=i}}return e}static _workCLDPair;static closestApproach(e,t,n=Number.MAX_VALUE,i=!1){let s;const r=this.ensureClosed(e),a=this.ensureClosed(t),o=this._workCLDPair=In.closestApproach(r,!1,a,!1,n,this._workCLDPair);return o&&o.detailA.childDetail&&o.detailB.childDetail&&(s=mr.create(hn.createAtVertexOrEdge(o.detailA.point,o.detailA.childDetail.a,o.detailA.childDetail.fraction),hn.createAtVertexOrEdge(o.detailB.point,o.detailB.childDetail.a,o.detailB.childDetail.fraction)),s.detailA.a=s.detailB.a=o.detailA.a),s}}class un{static _xyz0Work=y.create();static _xyz1Work=y.create();static _xyz2Work=y.create();static splitConvexPolygonInsideOutsidePlane(e,t,n,i,s){const r=un._xyz0Work,a=un._xyz1Work,o=un._xyz2Work,c=t.length;n.clear(),i.clear();const d=1e-8;if(c>2){t.back(r);let h=e.altitude(r),u=0,g=0;s.setX(h);for(let m=0;m<c;m++)t.getPoint3dAtUncheckedPointIndex(m,a),u=e.altitude(a),s.extendX(u),h*u<0?(g=-h/(u-h),g>1-d?(n.push(a),i.push(a)):g<d?u>0?(n.push(r),n.push(a)):(i.push(r),i.push(a)):(r.interpolate(g,a,o),n.push(o),i.push(o),u>0?n.push(a):i.push(a))):(u>=0&&n.push(a),u<=0&&i.push(a)),r.setFromPoint3d(a),h=u}}static clipConvexPolygonInPlace(e,t,n,i=!0,s=f.smallMetricDistance){for(;t.length>1&&t.getPoint3dAtUncheckedPointIndex(0).isExactEqual(t.getPoint3dAtUncheckedPointIndex(t.length-1));)t.pop();const r=t.length;if(r<3)return t.clear(),0;const a=i?1:-1,o=x=>{const _=a*t.evaluateUncheckedIndexPlaneAltitude(x,e);return Math.abs(_)<s?0:_},c=1e-8;let d=0,h=0,u=0;const g=n||new J;g.clear();let m,p=o(r-1);for(let x=r-1,_=0;_<r;p=m,x=_++){if(m=o(_),m<0&&d++,p*m<0){const I=-p/(m-p);if(!(I>1-c&&m>0)){const S=t.interpolateUncheckedIndexIndex(x,I,_,this._xyz0Work);g.pushXYZ(S.x,S.y,S.z),h++}}m>=0&&(g.pushXYZ(t.getXAtUncheckedPointIndex(_),t.getYAtUncheckedPointIndex(_),t.getZAtUncheckedPointIndex(_)),m===0&&p!==0&&u++),x=_,p=m}return d>0&&(t.clear(),t.pushIndexedXYZCollection(g)),g.clear(),h+u}static polygonPlaneCrossings(e,t,n){if(n.length=0,t.length>=2){const i=this._xyz0Work;t.getPoint3dAtUncheckedPointIndex(t.length-1,i);let s=e.altitude(i);const r=this._xyz1Work;for(let a=0;a<t.length;a++){t.getPoint3dAtUncheckedPointIndex(a,r);const o=e.altitude(r);if(s*o<0){const c=-s/(o-s);n.push(i.interpolate(c,r))}o===0&&n.push(r.clone()),i.setFromPoint3d(r),s=o}}}static gatherCutLoopsFromPlaneClip(e,t,n=3,i=f.smallMetricDistance){const s=new Pd;let r=0;const a=t.length;for(;r<a;r++){const c=t.evaluateUncheckedIndexPlaneAltitude(r,e);if(Math.abs(c)<=i)break}if(r===a)return s;let o=r;for(;o<a;){const c=new J;c.pushFromGrowableXYZArray(t,o);let d=o+1;for(;d<a;){c.pushFromGrowableXYZArray(t,d);const h=t.evaluateUncheckedIndexPlaneAltitude(d,e);if(Math.abs(h)<=i)break;d++}if(d===a)for(let h=0;h<=r;h++)c.pushFromGrowableXYZArray(t,h);c.length>=n&&s.inputLoops.push(pr.createCaptureWithReturnEdge(c)),o=d}return s}static reorderCutLoops(e){if(!(e.inputLoops.length<=1))if(e.inputLoops.length===2){const t=e.inputLoops[0].edge,n=e.inputLoops[1].edge;if(t&&n)if(t.direction.dotProduct(n.direction)>0)e.outputLoops.push(e.inputLoops[0]),e.outputLoops.push(e.inputLoops[1]);else{const i=e.inputLoops[1].xyz;e.inputLoops[0].xyz.pushFromGrowableXYZArray(i),e.outputLoops.push(e.inputLoops[0])}}else e.sortAndMergeLoops()}static intersectRangeConvexPolygonInPlace(e,t){if(e.isNull)return;const n=new J,i=Z.create();if(i.set(0,0,-1,e.high.z),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0&&(i.set(0,0,1,-e.low.z),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0&&(i.set(0,-1,0,e.high.y),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0&&(i.set(0,1,0,-e.low.y),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0&&(i.set(-1,0,0,e.high.x),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0&&(i.set(1,0,0,-e.low.x),this.clipConvexPolygonInPlace(i,t,n,!0),t.length!==0))))))return t}}class Id{static convexPolygonSplitInsideOutsidePlane(e,t,n,i,s){const r=new Qe(t),a=new Qe(n),o=new Qe(i);un.splitConvexPolygonInsideOutsidePlane(e,r,a,o,s)}static polygonPlaneCrossings(e,t,n){const i=new Qe(t);return un.polygonPlaneCrossings(e,i,n)}static convexPolygonClipInPlace(e,t,n,i=f.smallMetricDistance){const s=new Qe(t),r=n?new Qe(n):void 0;return un.clipConvexPolygonInPlace(e,s,r,!0,i)}}class tt{_origin;_vector0;_vector1;_vector2;static _workMatrix;static _workVector0;static _workVector1;static _workPoint;areStronglyIndependentVectors(e,t,n=f.smallAngleRadians){return e!==void 0&&t!==void 0?e.smallerUnorientedRadiansTo(t)>n:!1}clear(){this._origin=void 0,this._vector0=void 0,this._vector1=void 0,this._vector2=void 0}constructor(){this.clear()}getValidatedFrame(e=!1,t){if(this._origin&&this._vector0&&this._vector1){const n=(i,s)=>tt._workMatrix=E.createRigidFromColumns(i,s,ve.XYZ,tt._workMatrix);if(e){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,t);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,t);this._vector1=this._vector2=void 0}}}applyDefaultUpVector(e){e&&this._vector0&&!this._vector1&&!e.isParallelTo(this._vector0)&&(this._vector1=e.crossProduct(this._vector0))}get hasOrigin(){return this._origin!==void 0}savedVectorCount(){return this._vector0?this._vector1?this._vector2?3:2:1:0}announcePoint(e){return this._origin?this._origin.isAlmostEqual(e)?this.savedVectorCount():this.announceVector(this._origin.vectorTo(e)):(this._origin=y.createFrom(e),this.savedVectorCount())}announceVector(e){if(e.isAlmostZero)return this.savedVectorCount();if(!this._vector0)return this._vector0=e.clone(this._vector0),1;if(!this._vector1)return this.areStronglyIndependentVectors(e,this._vector0,1e-5)?(this._vector1=e.clone(this._vector1),2):1;if(!this._vector2){const t=this._vector0.unitCrossProduct(this._vector1);return t&&!f.isSameCoordinate(0,t.dotProduct(e))?(this._vector2=e.clone(this._vector2),3):2}return 3}announce(e){if(!(this.savedVectorCount()>1)&&e!==void 0)if(e instanceof y)this.announcePoint(e);else if(e instanceof v)this.announceVector(e);else if(f.isArrayOfNumberArray(e,1,3))for(const t of e)this.announcePoint({x:t[0],y:t[1],z:t[2]});else if(f.isArrayOfNumberArray(e,1,2))for(const t of e)this.announcePoint({x:t[0],y:t[1],z:0});else if(Array.isArray(e))for(const t of e){if(this.savedVectorCount()>1)break;this.announce(t)}else if(e instanceof le)if(e instanceof Q)this.announcePoint(e.startPoint()),this.announcePoint(e.endPoint());else if(e instanceof B){const t=e.fractionToPointAnd2Derivatives(0);this.announcePoint(t.origin),this.announceVector(t.vectorU),this.announceVector(t.vectorV)}else if(e instanceof N){for(const t of e.points)if(this.announcePoint(t),this.savedVectorCount()>1)break}else if(e instanceof It){const t=y.create();for(let n=0;this.savedVectorCount()<2&&e.getPolePoint3d(n,t)instanceof y;n++)this.announcePoint(t)}else{const t=e.fractionToFrenetFrame(0);t!==void 0&&(this.announcePoint(t.getOrigin()),this.announceVector(t.matrix.getColumn(0)),this.announceVector(t.matrix.getColumn(1)))}else if(e instanceof _e){if(e.children){for(const t of e.children)if(this.announce(t),this.savedVectorCount()>1)break}}else if(e instanceof gt){const t=y.create();for(let n=0;this.savedVectorCount()<2&&e.getPoint3dAtCheckedPointIndex(n,t)instanceof y;n++)this.announcePoint(t)}else e.hasOwnProperty("x")&&e.hasOwnProperty("y")&&e.hasOwnProperty("z")&&this.announcePoint(e)}static createRightHandedFrame(e,...t){let n=t.length>0&&t[t.length-1]instanceof X?t.pop():void 0;const i=a=>(e&&a.matrix.dotColumnZ(e)<0&&a.matrix.scaleColumnsInPlace(1,-1,-1),a),s=new tt;for(const a of t)if(s.announce(a),s.applyDefaultUpVector(e),n=s.getValidatedFrame(!1,n))return i(n);const r=(a,o)=>a.fractionToFrenetFrame(0,o);for(const a of t)if(a instanceof le){if(n=r(a,n))return i(n)}else if(a instanceof _e){const o=a.collectCurvePrimitives();for(const c of o)if(n=r(c,n))return i(n)}}static createRightHandedLocalToWorld(...e){return this.createRightHandedFrame(void 0,e)}static createFrameToDistantPoints(e,t){if(e.length>2){const n=e[0],i=tt._workVector0??v.create();lt.indexOfMostDistantPoint(e,e[0],i);const s=tt._workVector1??v.create();lt.indexOfPointWithMaxCrossProductMagnitude(e,n,i,s);const r=tt._workMatrix=E.createRigidFromColumns(i,s,ve.XYZ,tt._workMatrix);if(r)return X.createOriginAndMatrix(n,r,t)}}static createFrameWithCCWPolygon(e,t){if(e.length>2){const n=re.centroidAreaNormal(e);if(n)return n.toRigidZFrame(t)}}static createLocalToWorldTransformInRange(e,t=Ki.NonUniformRangeContainment,n=0,i=0,s=0,r=1,a){if(e.isNull)return X.createIdentity(a);let o=1,c=1,d=1;t===Ki.LongestRangeDirection?o=c=d=f.correctSmallMetricDistance(e.maxLength(),r):t===Ki.NonUniformRangeContainment&&(o=f.correctSmallMetricDistance(e.xLength(),r)*f.maxAbsDiff(n,0,1),c=f.correctSmallMetricDistance(e.yLength(),r)*f.maxAbsDiff(i,0,1),d=f.correctSmallMetricDistance(e.zLength(),r)*f.maxAbsDiff(s,0,1));const h=tt._workPoint=e.fractionToPoint(n,i,s,tt._workPoint),u=tt._workMatrix=E.createScale(o,c,d,tt._workMatrix);return X.createOriginAndMatrix(h,u,a)}}const fn={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 ba{h;s;l;constructor(e=0,t=0,n=0){this.h=e,this.s=t,this.l=n}clone(e,t,n){return new ba(e??this.h,t??this.s,n??this.l)}toColorDef(e=0){return he.fromHSL(this.h,this.s,this.l,e)}static fromColorDef(e){return e.toHSL()}}var qi;(function(l){l[l.VISIBILITY_GOAL=40]="VISIBILITY_GOAL",l[l.HSV_SATURATION_WEIGHT=4]="HSV_SATURATION_WEIGHT",l[l.HSV_VALUE_WEIGHT=2]="HSV_VALUE_WEIGHT"})(qi||(qi={}));class bi{h;s;v;constructor(e=0,t=0,n=0){this.h=e,this.s=t,this.v=n}clone(e,t,n){return new bi(e??this.h,t??this.s,n??this.v)}toColorDef(e=0){return he.fromHSV(this,e)}static fromColorDef(e){return e.toHSV()}adjusted(e,t){let n;if(e){if(n=t*qi.HSV_VALUE_WEIGHT,this.v>=n)return new bi(this.h,this.s,this.v-n);n-=this.v;const s=Math.min(this.s+n,100);return new bi(this.h,s,0)}if(n=t*qi.HSV_SATURATION_WEIGHT,this.s>=n)return new bi(this.h,this.s-n,this.v);n-=this.s;const i=Math.min(this.v+n,100);return new bi(this.h,0,i)}}const At=new Uint8Array(4),vn=new Uint32Array(At.buffer);class he{_tbgr;constructor(e){vn[0]=e,this._tbgr=vn[0]}static create(e){return this.fromTbgr(this.computeTbgr(e))}static computeTbgr(e){switch(typeof e){case"number":return e;case"string":return this.computeTbgrFromString(e);default:return 0}}toJSON(){return this._tbgr}static fromJSON(e){return this.create(e)}static from(e,t,n,i){return this.fromTbgr(this.computeTbgrFromComponents(e,t,n,i))}static computeTbgrFromComponents(e,t,n,i){return At[0]=e,At[1]=t,At[2]=n,At[3]=i||0,vn[0]}static fromTbgr(e){switch(e){case fn.black:return this.black;case fn.white:return this.white;case fn.red:return this.red;case fn.green:return this.green;case fn.blue:return this.blue;default:return new he(e)}}static fromAbgr(e){return this.fromTbgr(this.getAbgr(e))}static fromString(e){return this.fromTbgr(this.computeTbgrFromString(e))}static isValidColor(e){return typeof e=="number"?e>=0&&e<=4294967295&&Math.floor(e)===e:this.tryComputeTbgrFromString(e)!==void 0}static computeTbgrFromString(e){return this.tryComputeTbgrFromString(e)??0}static tryComputeTbgrFromString(e){if(typeof e!="string")return;e=e.toLowerCase();let t=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(e);if(t){let n;const i=t[1],s=t[2],r=c=>c[c.length-1]==="%",a=c=>{const d=parseFloat(c);return 255*f.clamp(r(c)?d/100:d,0,1)},o=c=>{const d=r(c)?parseFloat(c)/100*255:parseInt(c,10);return f.clamp(d,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(o(n[1]),o(n[2]),o(n[3]),typeof n[5]=="string"?255-a(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,d=parseInt(n[2],10)/100,h=parseInt(n[3],10)/100,u=typeof n[5]=="string"?255-a(n[5]):0;return this.computeTbgrFromHSL(c,d,h,u)}break}}else if(t=/^\#([a-f0-9]+)$/.exec(e)){const n=t[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(e&&e.length>0){for(const[n,i]of Object.entries(fn))if(n.toLowerCase()===e)return i}}get colors(){return he.getColors(this._tbgr)}static getColors(e){return vn[0]=e,{b:At[2],g:At[1],r:At[0],t:At[3]}}get tbgr(){return this._tbgr}getAbgr(){return he.getAbgr(this._tbgr)}static getAbgr(e){return vn[0]=e,At[3]=255-At[3],vn[0]}getRgb(){return he.getRgb(this._tbgr)}static getRgb(e){return vn[0]=e,(At[0]<<16)+(At[1]<<8)+At[2]}withAlpha(e){const t=he.withAlpha(this._tbgr,e);return t===this._tbgr?this:he.fromTbgr(t)}static withAlpha(e,t){return vn[0]=e,At[3]=255-(t|0),vn[0]}getAlpha(){return he.getAlpha(this._tbgr)}static getAlpha(e){return vn[0]=e,255-At[3]}get isOpaque(){return he.isOpaque(this._tbgr)}static isOpaque(e){return this.getAlpha(e)===255}getTransparency(){return he.getTransparency(this._tbgr)}static getTransparency(e){return vn[0]=e,At[3]}withTransparency(e){const t=he.withTransparency(this._tbgr,e);return t===this._tbgr?this:he.fromTbgr(t)}static withTransparency(e,t){return this.withAlpha(e,255-t)}get name(){return he.getName(this.tbgr)}static getName(e){for(const[t,n]of Object.entries(fn))if(n===e)return t}toHexString(){return he.toHexString(this.tbgr)}static toHexString(e){return`#${`000000${this.getRgb(e).toString(16)}`.slice(-6)}`}static getColorsString(e){const t=this.getColors(e);return`${t.r},${t.g},${t.b}`}toRgbString(){return he.toRgbString(this.tbgr)}static toRgbString(e){return`rgb(${this.getColorsString(e)})`}toRgbaString(){return he.toRgbaString(this.tbgr)}static toRgbaString(e){return`rgba(${this.getColorsString(e)},${this.getAlpha(e)/255})`}lerp(e,t){return he.fromTbgr(he.lerp(this.tbgr,e.tbgr,t))}static lerp(e,t,n){const i=this.getColors(e),s=this.getColors(t);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 he.fromTbgr(he.inverse(this.tbgr))}static inverse(e){const t=this.getColors(e);return this.computeTbgrFromComponents(255-t.r,255-t.g,255-t.b)}static fromHSL(e,t,n,i=0){return this.fromTbgr(this.computeTbgrFromHSL(e,t,n,i))}static computeTbgrFromHSL(e,t,n,i=0){const s=(d,h,u)=>(u<0&&(u+=1),u>1&&(u-=1),u<.16666666666666666?d+(h-d)*6*u:u<.5?h:u<.6666666666666666?d+(h-d)*6*(.6666666666666666-u):d),r=(d,h,u)=>Math.round(s(d,h,u)*255);if(e=((d,h)=>(d%h+h)%h)(e,1),t=f.clamp(t,0,1),n=f.clamp(n,0,1),t===0)return n*=255,this.computeTbgrFromComponents(n,n,n,i);const o=n<=.5?n*(1+t):n+t-n*t,c=2*n-o;return this.computeTbgrFromComponents(r(c,o,e+1/3),r(c,o,e),r(c,o,e-1/3),i)}toHSL(){const e=this.colors;e.r/=255,e.g/=255,e.b/=255;const t=Math.max(e.r,e.g,e.b),n=Math.min(e.r,e.g,e.b);let i=0,s;const r=(n+t)/2;if(n===t)s=0;else{const a=t-n;switch(s=r<=.5?a/(t+n):a/(2-t-n),t){case e.r:i=(e.g-e.b)/a+(e.g<e.b?6:0);break;case e.g:i=(e.b-e.r)/a+2;break;case e.b:i=(e.r-e.g)/a+4;break}i/=6}return new ba(i,s,r)}toHSV(){const{r:e,g:t,b:n}=this.colors;let i=e<t?e:t;n<i&&(i=n);let s=e>t?e:t;n>s&&(s=n);const r=Math.floor(s/255*100+.5),a=s-i,o=s!==0?Math.floor(a/s*100+.5):0;let c=0;if(o){const d=(s-e)/a,h=(s-t)/a,u=(s-n)/a;let g;e===s?g=u-h:t===s?g=2+d-u:g=4+h-d,g*=60,g<0&&(g+=360),c=Math.floor(g+.5),c>=360&&(c=0)}else c=0;return new bi(c,o,r)}static fromHSV(e,t=0){if(!e.s||e.h===-1){const p=255&Math.floor(255*e.v/100+.5+3e-14);return he.from(p,p,p,0)}let n=e.h,i=e.s,s=e.v;n===360&&(n=0),n/=60;const r=Math.floor(n),a=n-r;s/=100,i/=100;const o=255&Math.floor(s*(1-i)*255+.5),c=255&Math.floor(s*(1-i*a)*255+.5),d=255&Math.floor(s*(1-i*(1-a))*255+.5),h=255&Math.floor(s*255+.5);let u=0,g=0,m=0;switch(r){case 0:u=h,m=d,g=o;break;case 1:u=c,m=h,g=o;break;case 2:u=o,m=h,g=d;break;case 3:u=o,m=c,g=h;break;case 4:u=d,m=o,g=h;break;case 5:u=h,m=o,g=c;break}return he.from(u,m,g,t)}visibilityCheck(e){const t=this.colors,n=e.colors,i=Math.abs(t.r-n.r),s=Math.abs(t.g-n.g),r=Math.abs(t.b-n.b);return .3*i+.59*s+.11*r}adjustedForContrast(e,t){const n=this.visibilityCheck(e);if(qi.VISIBILITY_GOAL<=n)return t!==void 0?this.withAlpha(t):this;const i=Math.floor((qi.VISIBILITY_GOAL-n)/255*100);let s=this.toHSV(),r=s.clone();s=s.adjusted(!0,i),r=r.adjusted(!1,i),t===void 0&&(t=this.getAlpha());const a=he.fromHSV(s).withAlpha(t),o=he.fromHSV(r).withAlpha(t);return o.getRgb()===e.getRgb()?a:a.getRgb()===e.getRgb()||o.visibilityCheck(e)>=a.visibilityCheck(e)?o:a}equals(e){return this._tbgr===e._tbgr}static black=new he(fn.black);static white=new he(fn.white);static red=new he(fn.red);static green=new he(fn.green);static blue=new he(fn.blue)}var Zi;(function(l){l[l.Rgba=0]="Rgba",l[l.Rgb=2]="Rgb",l[l.Alpha=5]="Alpha"})(Zi||(Zi={}));class Wi{data;format;width;get numBytesPerPixel(){return Wi.getNumBytesPerPixel(this.format)}static getNumBytesPerPixel(e){switch(e){case Zi.Alpha:return 1;case Zi.Rgb:return 3;default:return 4}}get height(){return Wi.computeHeight(this.data,this.format,this.width)}static create(e,t,n){if(!this.isValidData(e,t,n))throw new Error("The number of bytes supplied for ImageBuffer do not match its width and format.");return new Wi(e,t,n)}static isValidData(e,t,n){const i=this.computeHeight(e,t,n);return n>0&&i>0&&Math.floor(n)===n&&Math.floor(i)===i}static computeHeight(e,t,n){return e.length/(n*this.getNumBytesPerPixel(t))}constructor(e,t,n){this.data=e,this.format=t,this.width=n}}var No;(function(l){l[l.Jpeg=0]="Jpeg",l[l.Png=2]="Png",l[l.Svg=3]="Svg"})(No||(No={}));var Ti;(function(l){let e;(function(r){r[r.None=0]="None",r[r.Invert=1]="Invert",r[r.Outline=2]="Outline"})(e=l.Flags||(l.Flags={}));let t;(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"})(t=l.Mode||(l.Mode={}));class n{value;color;constructor(a){this.value=a.value,this.color=he.fromJSON(a.color)}}l.KeyColor=n;function i(r,a){return r.value===a.value&&r.color.equals(a.color)}l.keyColorEquals=i;class s{mode=t.None;flags=e.None;angle;tint;shift=0;thematicSettings;keys=[];static fromJSON(a){const o=new s;return a&&(o.mode=a.mode,o.flags=a.flags===void 0?e.None:a.flags,o.angle=a.angle?T.fromJSON(a.angle):void 0,o.tint=a.tint,o.shift=a.shift?a.shift:0,a.keys.forEach(c=>o.keys.push(new n(c))),o.thematicSettings=a.thematicSettings===void 0?void 0:kt.fromJSON(a.thematicSettings)),o}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(a){const o=new s;if(o.mode=t.Thematic,o.thematicSettings=a,a.colorScheme<Sn.Custom)for(const c of l.Symb._fixedSchemeKeys[a.colorScheme])o.keys.push(new n({value:c[0],color:he.computeTbgrFromComponents(c[1],c[3],c[2])}));else if(a.customKeys.length>1,a.customKeys.length>1)a.customKeys.forEach(c=>o.keys.push(c));else for(const c of l.Symb._fixedCustomKeys)o.keys.push(new n({value:c[0],color:he.from(c[1],c[3],c[2]).toJSON()}));return o}toJSON(){return{...this,thematicSettings:this.thematicSettings?.toJSON(),keys:this.keys.map(a=>({value:a.value,color:a.color.toJSON()}))}}clone(){return s.fromJSON(this.toJSON())}equals(a){return s.compareSymb(this,a)===0}static compareSymb(a,o){if(a===o)return 0;if(a.mode!==o.mode)return a.mode-o.mode;if(a.flags!==o.flags)return a.flags===void 0?-1:o.flags===void 0?1:a.flags-o.flags;if(a.tint!==o.tint)return a.tint===void 0?-1:o.tint===void 0?1:a.tint-o.tint;if(a.shift!==o.shift)return a.shift===void 0?-1:o.shift===void 0?1:a.shift-o.shift;if(a.angle===void 0!=(o.angle===void 0))return a.angle===void 0?-1:1;if(a.angle&&!a.angle.isAlmostEqualNoPeriodShift(o.angle))return a.angle.radians-o.angle.radians;if(a.keys.length!==o.keys.length)return a.keys.length-o.keys.length;for(let c=0;c<a.keys.length;c++){if(a.keys[c].value!==o.keys[c].value)return a.keys[c].value-o.keys[c].value;if(!a.keys[c].color.equals(o.keys[c].color))return a.keys[c].color.tbgr-o.keys[c].color.tbgr}if(a.thematicSettings!==o.thematicSettings){if(a.thematicSettings===void 0)return-1;if(o.thematicSettings===void 0)return 1;{const c=kt.compare(a.thematicSettings,o.thematicSettings);if(c!==0)return c}}return 0}compare(a){return l.Symb.compareSymb(this,a)}roundToByte(a){return Math.min(a+.5,255)&255}mapColor(a){a<0?a=0:a>1&&(a=1),(this.flags&e.Invert)!==0&&(a=1-a);let o=0,c,d,h;if(this.keys.length<=2)d=1-a,h=a;else{for(;o<this.keys.length-2&&a>this.keys[o+1].value;)o++;c=this.keys[o+1].value-this.keys[o].value,h=c<1e-4?0:(a-this.keys[o].value)/c,d=1-h}const u=this.keys[o].color,g=this.keys[o+1].color,m=u.colors,p=g.colors,x=d*m.r+h*p.r,_=d*m.g+h*p.g,I=d*m.b+h*p.b,S=d*m.t+h*p.t;return he.from(this.roundToByte(x),this.roundToByte(_),this.roundToByte(I),this.roundToByte(S))}get hasTranslucency(){for(const a of this.keys)if(!a.color.isOpaque)return!0;return!1}get isOutlined(){return(this.flags&e.Outline)!==0}getThematicImageForRenderer(a){t.Thematic,this.mode;let o=this.thematicSettings;o===void 0&&(o=kt.defaults);const c=Math.min(o.stepCount,a),d=wt.Smooth===o.mode?a:c,h=new Uint8Array(1*d*4);let u=h.length-1;function g(p){h[u--]=p.getAlpha(),h[u--]=p.colors.b,h[u--]=p.colors.g,h[u--]=p.colors.r}switch(o.mode){case wt.Smooth:{for(let p=0;p<d;p++){const x=1-p/d;g(this.mapColor(x))}break}case wt.SteppedWithDelimiter:case wt.IsoLines:case wt.Stepped:{o.stepCount>1;for(let p=0;p<d;p++){const x=1-p/(d-1);g(this.mapColor(x))}break}}return Wi.create(h,Zi.Rgba,1)}getImage(a,o){return this.mode===t.Thematic&&(a=1),this.produceImage({width:a,height:o,includeThematicMargin:!0})}produceImage(a){const{width:o,height:c,includeThematicMargin:d}={...a},h=this.angle===void 0?0:this.angle.radians,u=Math.cos(h),g=Math.sin(h),m=new Uint8Array(o*c*4);let p=m.length-1;const x=Math.min(1,Math.abs(this.shift));switch(this.mode){case t.Linear:case t.Cylindrical:{const I=.5-.25*x*u,S=.5-.25*x*g;let A,w=A=0,k;for(let D=0;D<2;D++)for(let P=0;P<2;P++)k=(P-I)*u+(D-S)*g,k<w&&(w=k),k>A&&(A=k);for(let D=0;D<c;D++){const P=D/c-S;for(let b=0;b<o;b++){k=(b/o-I)*u+P*g;let M;this.mode===t.Linear?k>0?M=.5+.5*k/A:M=.5-.5*k/w:k>0?M=Math.sin(Math.PI/2*(1-k/A)):M=Math.sin(Math.PI/2*(1-k/w));const G=this.mapColor(M);m[p--]=G.getAlpha(),m[p--]=G.colors.b,m[p--]=G.colors.g,m[p--]=G.colors.r}}break}case t.Curved:{const I=.5+.5*g-.25*x*u,S=.5-.5*u-.25*x*g;for(let A=0;A<c;A++){const w=A/c-S;for(let k=0;k<o;k++){const D=k/o-I,P=.8*(D*u+w*g),b=w*u-D*g,C=Math.sin(Math.PI/2*(1-Math.sqrt(P*P+b*b))),M=this.mapColor(C);m[p--]=M.getAlpha(),m[p--]=M.colors.b,m[p--]=M.colors.g,m[p--]=M.colors.r}}break}case t.Spherical:{const I=.5+.125*Math.sin(2*h),S=.5*x*(u+g)*I,A=.5*x*(g-u)*I;for(let w=0;w<c;w++){const k=A+w/c-.5;for(let D=0;D<o;D++){const P=S+D/o-.5,b=Math.sin(Math.PI/2*(1-Math.sqrt(P*P+k*k)/I)),C=this.mapColor(b);m[p--]=C.getAlpha(),m[p--]=C.colors.b,m[p--]=C.colors.g,m[p--]=C.colors.r}}break}case t.Hemispherical:{const I=.5+.5*g-.5*x*u,S=.5-.5*u-.5*x*g;for(let A=0;A<c;A++){const w=A/c-S;for(let k=0;k<o;k++){const D=k/o-I,P=Math.sin(Math.PI/2*(1-Math.sqrt(D*D+w*w))),b=this.mapColor(P);m[p--]=b.getAlpha(),m[p--]=b.colors.b,m[p--]=b.colors.g,m[p--]=b.colors.r}}break}case t.Thematic:{const I=this.thematicSettings??kt.defaults;for(let S=0;S<c;S++){let A=1-S/c,w;if(d&&(A<kt.margin||A>kt.contentMax))w=I.marginColor;else switch(A=(A-kt.margin)/kt.contentRange,I.mode){case wt.SteppedWithDelimiter:case wt.IsoLines:case wt.Stepped:{if(I.stepCount>1){const k=Math.floor(A*I.stepCount-1e-5)/(I.stepCount-1);w=this.mapColor(k)}else throw new Error(`Thematic gradient mode ${String(I.mode)} requires at least two steps.`);break}case wt.Smooth:w=this.mapColor(A);break}for(let k=0;k<o;k++)m[p--]=w.getAlpha(),m[p--]=w.colors.b,m[p--]=w.colors.g,m[p--]=w.colors.r}}}return Wi.create(m,Zi.Rgba,o)}}l.Symb=s})(Ti||(Ti={}));var ui;(function(l){l[l.Opaque=0]="Opaque",l[l.Translucent=1]="Translucent",l[l.Mixed=2]="Mixed"})(ui||(ui={}));var wt;(function(l){l[l.Smooth=0]="Smooth",l[l.Stepped=1]="Stepped",l[l.SteppedWithDelimiter=2]="SteppedWithDelimiter",l[l.IsoLines=3]="IsoLines"})(wt||(wt={}));var fs;(function(l){l[l.SurfaceOnly=0]="SurfaceOnly",l[l.MultiplySurfaceAndGradient=1]="MultiplySurfaceAndGradient"})(fs||(fs={}));var Sn;(function(l){l[l.BlueRed=0]="BlueRed",l[l.RedBlue=1]="RedBlue",l[l.Monochrome=2]="Monochrome",l[l.Topographic=3]="Topographic",l[l.SeaMountain=4]="SeaMountain",l[l.Custom=5]="Custom"})(Sn||(Sn={}));class kt{mode;stepCount;marginColor;colorScheme;customKeys;colorMix;transparencyMode;static get margin(){return .001}static get contentRange(){return 1-2*kt.margin}static get contentMax(){return 1-kt.margin}static defaults=new kt({});static _defaultCustomKeys=[[0,255,255,255],[1,0,0,0]];get textureTransparency(){let e=ui.Opaque;if(Sn.Custom===this.colorScheme){let t=!1,n=!1;for(const i of this.customKeys){const s=i.color.isOpaque;t=t||s,n=n||!s}n&&(e=t?ui.Mixed:ui.Translucent)}return e!==ui.Mixed&&this.marginColor.isOpaque!==(e===ui.Opaque)&&(e=ui.Mixed),e}equals(e){return this.mode!==e.mode||this.stepCount!==e.stepCount||!this.marginColor.equals(e.marginColor)||this.colorScheme!==e.colorScheme||this.customKeys.length!==e.customKeys.length||this.colorMix!==e.colorMix||this.transparencyMode!==e.transparencyMode?!1:this.customKeys.every((t,n)=>Ti.keyColorEquals(t,e.customKeys[n]))}static compare(e,t){let n=0;if((n=Pe(e.mode,t.mode))!==0||(n=Pe(e.stepCount,t.stepCount))!==0||(n=Pe(e.marginColor.tbgr,t.marginColor.tbgr))!==0||(n=Pe(e.colorScheme,t.colorScheme))!==0||(n=Pe(e.colorMix,t.colorMix))!==0||(n=Pe(e.customKeys.length,t.customKeys.length))!==0||(n=Pe(e.transparencyMode,t.transparencyMode))!==0)return n;for(let i=0;i<e.customKeys.length;i++)if((n=Pe(e.customKeys[i].color.tbgr,t.customKeys[i].color.tbgr))!==0)return n;return n}constructor(e){if(this.customKeys=[],e===void 0)this.mode=wt.Smooth,this.stepCount=10,this.marginColor=he.fromJSON(),this.colorScheme=Sn.BlueRed,this.colorMix=0,this.transparencyMode=fs.SurfaceOnly;else{if(this.mode=e.mode!==void 0&&e.mode!==null?e.mode:wt.Smooth,(this.mode<wt.Smooth||this.mode>wt.IsoLines)&&(this.mode=wt.Smooth),this.stepCount=typeof e.stepCount=="number"?e.stepCount:10,this.stepCount<2&&(this.stepCount=2),this.marginColor=he.fromJSON(e.marginColor),this.colorScheme=e.colorScheme!==void 0&&e.colorScheme!==null?e.colorScheme:Sn.BlueRed,(this.colorScheme<Sn.BlueRed||this.colorScheme>Sn.Custom)&&(this.colorScheme=Sn.BlueRed),e.customKeys!==void 0&&e.customKeys!==null&&e.customKeys.forEach(t=>this.customKeys.push(new Ti.KeyColor(t))),this.colorScheme===Sn.Custom&&this.customKeys.length<2){this.customKeys=[];for(const t of kt._defaultCustomKeys)this.customKeys.push(new Ti.KeyColor({value:t[0],color:he.computeTbgrFromComponents(t[1],t[3],t[2])}))}this.colorMix=e.colorMix??0,this.transparencyMode=e.transparencyMode??fs.SurfaceOnly}}static fromJSON(e){return e?new kt(e):this.defaults}toJSON(){const e={};wt.Smooth!==this.mode&&(e.mode=this.mode),this.stepCount!==10&&(e.stepCount=this.stepCount);const t=this.marginColor.toJSON();return t!==0&&(e.marginColor=t),Sn.BlueRed!==this.colorScheme&&(e.colorScheme=this.colorScheme),this.colorMix!==0&&(e.colorMix=this.colorMix),fs.SurfaceOnly!==this.transparencyMode&&(e.transparencyMode=this.transparencyMode),this.customKeys.length>0&&(e.customKeys=this.customKeys.map(n=>({value:n.value,color:n.color.toJSON()}))),e}clone(e){if(e===void 0)return kt.fromJSON(this.toJSON());const t={mode:e.mode!==void 0?e.mode:this.mode,stepCount:e.stepCount!==void 0?e.stepCount:this.stepCount,marginColor:e.marginColor!==void 0?e.marginColor:this.marginColor.tbgr,colorScheme:e.colorScheme!==void 0?e.colorScheme:this.colorScheme,customKeys:e.customKeys!==void 0?e.customKeys:this.customKeys.map(n=>({value:n.value,color:n.color.tbgr})),colorMix:e.colorMix!==void 0?e.colorMix:this.colorMix,transparencyMode:e.transparencyMode??this.transparencyMode};return kt.fromJSON(t)}}var Oo;(function(l){l[l.Height=0]="Height",l[l.InverseDistanceWeightedSensors=1]="InverseDistanceWeightedSensors",l[l.Slope=2]="Slope",l[l.HillShade=3]="HillShade"})(Oo||(Oo={}));class Lt{r;g;b;constructor(e,t,n){this.r=e,this.g=t,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(e){const t=e.colors;return new Lt(t.r,t.g,t.b)}toColorDef(e=0){return he.from(this.r,this.g,this.b,e)}toJSON(){return{r:this.r,g:this.g,b:this.b}}static fromJSON(e){let t=255,n=255,i=255;return e!==void 0&&(typeof e.r=="number"&&(t=e.r),typeof e.g=="number"&&(n=e.g),typeof e.b=="number"&&(i=e.b)),new Lt(t,n,i)}equals(e){return this.r===e.r&&this.g===e.g&&this.b===e.b}compareTo(e){return Pe(this.r,e.r)||Pe(this.g,e.g)||Pe(this.b,e.b)}toHexString(){return this.toColorDef().toHexString()}}var gs;(function(l){l[l.Solid=0]="Solid",l[l.Code0=0]="Code0",l[l.Code1=2155905152]="Code1",l[l.Code2=4177066232]="Code2",l[l.Code3=4292935648]="Code3",l[l.Code4=4262526480]="Code4",l[l.Code5=3772834016]="Code5",l[l.Code6=4169726088]="Code6",l[l.Code7=4279828248]="Code7",l[l.HiddenLine=3435973836]="HiddenLine",l[l.Invisible=1]="Invisible",l[l.Invalid=-1]="Invalid"})(gs||(gs={}));var Xo;(function(l){l[l.Never=0]="Never",l[l.ByView=1]="ByView",l[l.Always=2]="Always",l[l.Blanking=3]="Blanking"})(Xo||(Xo={}));var Lo;(function(l){l[l.None=0]="None",l[l.Solid=1]="Solid",l[l.Outline=2]="Outline"})(Lo||(Lo={}));var An;(function(l){l[l.Primary=0]="Primary",l[l.Construction=1]="Construction",l[l.Dimension=2]="Dimension",l[l.Pattern=3]="Pattern"})(An||(An={}));class ms{data;batchModelId;batchModelIdPair;numFeatures;anyDefined;type;animationNodeIds;get byteLength(){return this.data.byteLength}constructor(e,t,n,i,s){switch(this.data=e,this.batchModelId=t,this.batchModelIdPair=te.getUint32Pair(t),this.numFeatures=n,this.type=i,this.animationNodeIds=s,this.numFeatures){case 0:this.anyDefined=!1;break;case 1:this.anyDefined=Ci.isDefined(this.getFeature(0,Ci.create()));break;default:this.anyDefined=!0;break}this.data.length>=this._subCategoriesOffset,this.animationNodeIds===void 0||(this.animationNodeIds.length,this.numFeatures)}static pack(e){const t=new Map;for(const r of e.getArray())t.get(r.value.subCategoryId.toString())===void 0&&t.set(r.value.subCategoryId,t.size);const n=3*e.length,i=n+2*t.size,s=new Uint32Array(i);for(const r of e.getArray()){const a=r.value,o=r.index*3;let c=Nr(t.get(a.subCategoryId));c|=a.geometryClass<<24,s[o+0]=te.getLowerUint32(a.elementId),s[o+1]=te.getUpperUint32(a.elementId),s[o+2]=c}return t.forEach((r,a,o)=>{const c=n+2*r;s[c+0]=te.getLowerUint32(a),s[c+1]=te.getUpperUint32(a)}),new ms(s,e.modelId,e.length,e.type)}getFeature(e,t){const n=this.getPackedFeature(e,Yo);return Ci.unpack(n,t,this.batchModelId)}findFeature(e,t){return e<this.numFeatures?this.getFeature(e,t):void 0}getElementIdPair(e,t){t=t??{lower:0,upper:0},e<this.numFeatures;const n=3*e;return t.lower=this.data[n],t.upper=this.data[n+1],t}getSubCategoryIdPair(e){const t=3*e;let n=this.data[t+2];return n=(n&16777215)>>>0,n=n*2+this._subCategoriesOffset,{lower:this.data[n],upper:this.data[n+1]}}getAnimationNodeId(e){return this.animationNodeIds!==void 0&&e<this.numFeatures?this.animationNodeIds[e]:0}getPackedFeature(e,t){e<this.numFeatures;const n=3*e;t.elementId.lower=this.data[n],t.elementId.upper=this.data[n+1];const i=this.data[n+2];t.geometryClass=i>>>24&255;let s=(i&16777215)>>>0;return s=s*2+this._subCategoriesOffset,t.subCategoryId.lower=this.data[s],t.subCategoryId.upper=this.data[s+1],t.animationNodeId=this.getAnimationNodeId(e),t.modelId.lower=this.batchModelIdPair.lower,t.modelId.upper=this.batchModelIdPair.upper,t}getModelIdPair(e,t){return t.lower=this.batchModelIdPair.lower,t.upper=this.batchModelIdPair.upper,t}findElementId(e){if(!(e>=this.numFeatures))return this.readId(3*e)}get isUniform(){return this.numFeatures===1}getUniform(e){return this.isUniform?this.getFeature(0,e):void 0}get isVolumeClassifier(){return gn.VolumeClassifier===this.type}get isPlanarClassifier(){return gn.VolumeClassifier===this.type}get isClassifier(){return this.isVolumeClassifier||this.isPlanarClassifier}unpack(){const e=new bd(this.numFeatures,this.batchModelId),t=Ci.create();for(let n=0;n<this.numFeatures;n++)this.getFeature(n,t),e.insertWithIndex(new wd(t.elementId,t.subCategoryId,t.geometryClass),n);return e}populateAnimationNodeIds(e,t){this.animationNodeIds,this.animationNodeIds=zo(this,e,t)}*iterator(e){for(let t=0;t<this.numFeatures;t++)this.getPackedFeature(t,e),e.index=t,yield e}iterable(e){return{[Symbol.iterator]:()=>this.iterator(e)}}get _subCategoriesOffset(){return this.numFeatures*3}readId(e){return te.fromUint32Pair(this.data[e],this.data[e+1])}}const vd={lastFeatureIndex:-1,idLower:-1,idUpper:-1};class Sd{_data;constructor(e){this._data=e,this._data.length%3}get length(){return this._data.length/3}get byteLength(){return this._data.byteLength}getLastFeatureIndex(e){return this._data[e*3]}getEntry(e,t){if(e>=this.length)return t.idLower=t.idUpper=0,t.lastFeatureIndex=Number.MAX_SAFE_INTEGER,t;const n=e*3;return t.lastFeatureIndex=this._data[n+0],t.idLower=this._data[n+1],t.idUpper=this._data[n+2],t}getModelIdPair(e,t){t?t.lower=t.upper=0:t={lower:0,upper:0};let n=0;const i=this.length;let s=i;for(;s>0;){const r=Math.floor(s/2),a=n+r,o=this.getLastFeatureIndex(a);e>o?(n=a+1,s-=r+1):s=r}return n<i&&(t.lower=this._data[n*3+1],t.upper=this._data[n*3+2]),t}}class Ta{_features;_models;constructor(e,t){this._features=e,this._models=t}static create(e,t,n,i,s){const r=3*n+2*s,a=e.subarray(0,r),o=new ms(a,t,n,i),c=e.subarray(r),d=new Sd(c);return new Ta(o,d)}get batchModelId(){return this._features.batchModelId}get batchModelIdPair(){return this._features.batchModelIdPair}get numFeatures(){return this._features.numFeatures}get type(){return this._features.type}get animationNodeIds(){return this._features.animationNodeIds}set animationNodeIds(e){this._features.animationNodeIds=e}get byteLength(){return this._features.byteLength+this._models.byteLength}getPackedFeature(e,t){return this._features.getPackedFeature(e,t),this._models.getModelIdPair(e,t.modelId),t}getFeature(e,t){const n=this.getPackedFeature(e,Yo);return Ci.unpack(n,t)}findFeature(e,t){return e<this.numFeatures?this.getFeature(e,t):void 0}getElementIdPair(e,t){return this._features.getElementIdPair(e,t)}getModelIdPair(e,t){return this._models.getModelIdPair(e,t),t}findElementId(e){return this._features.findElementId(e)}*iterator(e){let t=0;const n=this._models.getEntry(t,vd);for(let i=0;i<this.numFeatures;i++)i>n.lastFeatureIndex&&this._models.getEntry(++t,n),this._features.getPackedFeature(i,e),e.modelId.lower=n.idLower,e.modelId.upper=n.idUpper,e.index=i,yield e}iterable(e){return{[Symbol.iterator]:()=>this.iterator(e)}}getAnimationNodeId(e){return this._features.getAnimationNodeId(e)}populateAnimationNodeIds(e,t){this._features.animationNodeIds=zo(this,e,t)}}function Ad(){const l={upper:0,lower:0};return{modelId:{...l},elementId:{...l},subCategoryId:{...l},geometryClass:An.Primary,animationNodeId:0}}const Yo=Ad();function zo(l,e,t){let n;const i=Ca.createWithIndex();for(const s of l.iterable(i)){const r=e(s);if(r!==0){if(!n){const a=l.numFeatures;n=t<256?new Uint8Array(a):t<65536?new Uint16Array(a):new Uint32Array(a)}n[s.index]=r}}return n}class wd{elementId;subCategoryId;geometryClass;constructor(e=te.invalid,t=te.invalid,n=An.Primary){this.elementId=e,this.subCategoryId=t,this.geometryClass=n}get isDefined(){return!te.isInvalid(this.elementId)||!te.isInvalid(this.subCategoryId)||this.geometryClass!==An.Primary}get isUndefined(){return!this.isDefined}equals(e){return this.compare(e)===0}compare(e){if(this===e)return 0;let t=Pe(this.geometryClass,e.geometryClass);return t===0&&(t=ii(this.elementId,e.elementId),t===0&&(t=ii(this.subCategoryId,e.subCategoryId))),t}}var Ci;(function(l){function e(){return{modelId:te.invalid,elementId:te.invalid,subCategoryId:te.invalid,geometryClass:An.Primary}}l.create=e;function t(i){return!te.isInvalid(i.modelId)||!te.isInvalid(i.elementId)||!te.isInvalid(i.subCategoryId)||i.geometryClass!==An.Primary}l.isDefined=t;function n(i,s,r){return s.modelId=r??te.fromUint32PairObject(i.modelId),s.elementId=te.fromUint32PairObject(i.elementId),s.subCategoryId=te.fromUint32PairObject(i.subCategoryId),s.geometryClass=i.geometryClass,s}l.unpack=n})(Ci||(Ci={}));var Ca;(function(l){function e(){const n={upper:0,lower:0};return{modelId:{...n},elementId:{...n},subCategoryId:{...n},geometryClass:An.Primary,animationNodeId:0}}l.create=e;function t(){const n=e();return n.index=0,n}l.createWithIndex=t})(Ca||(Ca={}));var gn;(function(l){l[l.Primary=0]="Primary",l[l.VolumeClassifier=1]="VolumeClassifier",l[l.PlanarClassifier=2]="PlanarClassifier"})(gn||(gn={}));class bd extends _c{modelId;type;constructor(e,t=te.invalid,n=gn.Primary){super((i,s)=>i.compare(s),e),this.modelId=t,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 gn.VolumeClassifier===this.type}get isPlanarClassifier(){return gn.PlanarClassifier===this.type}findFeature(e){for(const t of this._array)if(t.index===e)return t.value}insertWithIndex(e,t){const n=this.lowerBound(e);n.equal,this.isFull;const i=new Ga(e,t);this._array.splice(n.index,0,i)}getArray(){return this._array}pack(){return ms.pack(this)}}function Bo(l,e){if(l.clear(),typeof e=="string")l.addId(e);else for(const t of e)l.addId(t)}function Td(l){return!l.rgb&&!l.lineRgb&&l.weight===void 0&&l.linePixels===void 0&&l.transparency===void 0&&l.lineTransparency===void 0&&!l.ignoresMaterial&&!l.nonLocatable&&!l.emphasized}function Uo(l,e){return l===e?!0:!l||!e?!1:l.equals(e)}function Cd(l,e){return l===e?!0:l instanceof Lt&&e instanceof Lt?Uo(l,e):!1}function Vo(l,e){return l===e?!0:l===void 0||e===void 0?!1:Math.floor(l*255)===Math.floor(e*255)}function Ed(l,e){return l===e?!0:typeof l=="number"&&typeof e=="number"?Vo(l,e):!1}function qo(l){if(l===void 0)return;l=Math.max(0,Math.min(l,1));const e=1e-4;return 1-l<e?l=1:l<e&&(l=0),l}class Zt{rgb;lineRgb;weight;transparency;lineTransparency;linePixels;ignoresMaterial;nonLocatable;emphasized;viewDependentTransparency;static defaults=new Zt({});static fromJSON(e){return!e||Td(e)?this.defaults:new Zt(e)}static fromRgb(e){return new Zt({rgb:Lt.fromColorDef(e)})}static fromRgba(e,t=!1){return new Zt({rgb:Lt.fromColorDef(e),transparency:e.colors.t/255,viewDependentTransparency:t?!0:void 0})}static fromTransparency(e,t=!1){return new Zt({transparency:e,viewDependentTransparency:t?!0:void 0})}static fromSubCategoryOverride(e){const t=e.color!==void 0?Lt.fromColorDef(e.color):void 0,n=e.transparency,i=e.weight,s=e.material!==void 0&&te.isValid(e.material)?!0:void 0;return this.fromJSON({rgb:t,transparency:n,weight:i,ignoresMaterial:s,viewDependentTransparency:!0})}get matchesDefaults(){return this.equals(Zt.defaults)}get overridesRgb(){return this.rgb!==void 0}get overridesTransparency(){return this.transparency!==void 0}get overridesLinePixels(){return this.linePixels!==void 0}get overridesWeight(){return this.weight!==void 0}getLineRgb(){return this.lineRgb!==!1?this.lineRgb??this.rgb:void 0}getLineTransparency(){return this.lineTransparency!==!1?this.lineTransparency??this.transparency:void 0}get overridesSymbology(){return this.overridesRgb||this.overridesTransparency||this.overridesWeight||this.overridesLinePixels||!!this.ignoresMaterial||this.emphasized||this.overridesNonLocatable||this.getLineRgb()!==void 0||this.getLineTransparency()!==void 0}get overridesNonLocatable(){return this.nonLocatable!==void 0}get isFullyTransparent(){const e=this.transparency??0,t=this.getLineTransparency()??0;return e>=1&&t>=1}get anyOverridden(){return this.overridesSymbology||this.overridesNonLocatable}equals(e){return this===e?!0:Uo(this.rgb,e.rgb)&&this.weight===e.weight&&Vo(this.transparency,e.transparency)&&this.linePixels===e.linePixels&&this.ignoresMaterial===e.ignoresMaterial&&this.nonLocatable===e.nonLocatable&&this.emphasized===e.emphasized&&this.viewDependentTransparency===e.viewDependentTransparency&&Ed(this.lineTransparency,e.lineTransparency)&&Cd(this.lineRgb,e.lineRgb)}toJSON(){const e={};return this.rgb&&(e.rgb=this.rgb.toJSON()),this.weight!==void 0&&(e.weight=this.weight),this.transparency!==void 0&&(e.transparency=this.transparency,this.viewDependentTransparency&&(e.viewDependentTransparency=!0)),this.linePixels!==void 0&&(e.linePixels=this.linePixels),this.ignoresMaterial===!0&&(e.ignoresMaterial=!0),this.nonLocatable===!0&&(e.nonLocatable=!0),this.emphasized===!0&&(e.emphasized=!0),this.lineTransparency!==void 0&&(e.lineTransparency=this.lineTransparency),this.lineRgb&&(e.lineRgb=this.lineRgb,this.viewDependentTransparency&&(e.viewDependentTransparency=!0)),e}cloneProps(e){return{...this.toJSON(),...e}}clone(e){return Zt.fromJSON(this.cloneProps(e))}extendAppearance(e){if(!this.overridesSymbology)return e;const t=e.toJSON();return t.rgb===void 0&&(t.rgb=this.rgb),t.transparency===void 0&&(t.transparency=this.transparency),t.linePixels===void 0&&(t.linePixels=this.linePixels),t.weight===void 0&&(t.weight=this.weight),t.ignoresMaterial===void 0&&this.ignoresMaterial&&(t.ignoresMaterial=!0),t.nonLocatable===void 0&&this.nonLocatable&&(t.nonLocatable=!0),t.emphasized===void 0&&this.emphasized&&(t.emphasized=!0),t.lineRgb||(t.lineRgb=this.lineRgb),t.lineTransparency===void 0&&(t.lineTransparency=this.lineTransparency),this.viewDependentTransparency&&(t.transparency!==void 0||t.lineTransparency!==void 0)&&(t.viewDependentTransparency=!0),Zt.fromJSON(t)}constructor(e){this.rgb=e.rgb!==void 0?Lt.fromJSON(e.rgb):void 0,this.lineRgb=typeof e.lineRgb=="object"?Lt.fromJSON(e.lineRgb):e.lineRgb===!1?!1:void 0,this.transparency=qo(e.transparency),this.lineTransparency=typeof e.lineTransparency=="number"?qo(e.lineTransparency):e.lineTransparency===!1?!1:void 0,this.weight=e.weight,this.linePixels=e.linePixels,this.ignoresMaterial=e.ignoresMaterial,this.nonLocatable=e.nonLocatable,this.emphasized=e.emphasized,this.weight!==void 0&&(this.weight=Math.max(1,Math.min(this.weight,32))),e.viewDependentTransparency&&(this.transparency!==void 0||this.getLineTransparency()!==void 0)&&(this.viewDependentTransparency=!0)}}const kd={elementId:{lower:0,upper:0},animationNodeId:0};class Zo{_ignoreAnimationOverrides=[];_neverDrawn=new te.Uint32Set;_alwaysDrawn=new te.Uint32Set;isAlwaysDrawnExclusive=!1;alwaysDrawnIgnoresSubCategory=!0;ignoreSubCategory=!1;_defaultOverrides=Zt.defaults;_constructions=!1;_dimensions=!1;_patterns=!1;_lineWeights=!0;_modelOverrides=new te.Uint32Map;_elementOverrides=new te.Uint32Map;_subCategoryOverrides=new te.Uint32Map;_visibleSubCategories=new te.Uint32Set;_subCategoryPriorities=new te.Uint32Map;_modelSubCategoryOverrides=new te.Uint32Map;neverDrawnAnimationNodes=new Set;animationNodeOverrides=new Map;ignoreAnimationOverrides(e){this._ignoreAnimationOverrides.push(e)}get defaultOverrides(){return this._defaultOverrides}get lineWeights(){return this._lineWeights}get neverDrawn(){return this._neverDrawn}get alwaysDrawn(){return this._alwaysDrawn}isNeverDrawn(e,t,n){return this._neverDrawn.has(e,t)?!0:this.neverDrawnAnimationNodes.has(n)}isAlwaysDrawn(e,t){return this._alwaysDrawn.has(e,t)}isSubCategoryVisible(e,t){return this._visibleSubCategories.has(e,t)}isSubCategoryVisibleInModel(e,t,n,i){if(this.ignoreSubCategory)return!0;let s=this.isSubCategoryVisible(e,t);const r=this._modelSubCategoryOverrides.get(n,i);return r!==void 0&&r.has(e,t)&&(s=!s),s}getModelOverrides(e,t){return this._modelOverrides.get(e,t)}getElementAnimationOverrides(e,t,n){if(this.animationNodeOverrides.size===0)return;const i=this.animationNodeOverrides.get(n);if(!i||n===0||this._ignoreAnimationOverrides.length===0)return i;const s=kd;return s.elementId.lower=e,s.elementId.upper=t,s.animationNodeId=n,this._ignoreAnimationOverrides.some(r=>r(s))?void 0:i}getElementOverrides(e,t,n){const i=this._elementOverrides.get(e,t),s=this.getElementAnimationOverrides(e,t,n);return i?s?s.extendAppearance(i):i:s}getSubCategoryOverrides(e,t){return this._subCategoryOverrides.get(e,t)}setVisibleSubCategory(e){this._visibleSubCategories.addId(e)}setNeverDrawn(e){this._neverDrawn.addId(e)}setAlwaysDrawn(e){this._alwaysDrawn.addId(e)}setAnimationNodeNeverDrawn(e){this.neverDrawnAnimationNodes.add(e)}setNeverDrawnSet(e){Bo(this._neverDrawn,e)}setAlwaysDrawnSet(e,t,n=!0){Bo(this._alwaysDrawn,e),this.isAlwaysDrawnExclusive=t,this.alwaysDrawnIgnoresSubCategory=n}getFeatureAppearance(e,t,n=gn.Primary,i=0){return this.getAppearance(te.getLowerUint32(e.elementId),te.getUpperUint32(e.elementId),te.getLowerUint32(e.subCategoryId),te.getUpperUint32(e.subCategoryId),e.geometryClass,te.getLowerUint32(t),te.getUpperUint32(t),n,i)}static _weight1Appearance=Zt.fromJSON({weight:1});getAppearance(e,t,n,i,s,r,a,o,c){if(gn.VolumeClassifier===o||gn.PlanarClassifier===o)return this.getClassifierAppearance(e,t,n,i,r,a,c);let d=this._lineWeights?Zt.defaults:Zo._weight1Appearance;const h=this.getModelOverrides(r,a);h!==void 0&&(d=h.extendAppearance(d));let u,g=!1;if(te.isValidUint32Pair(e,t)){if(this.isNeverDrawn(e,t,c)||(g=this.isAlwaysDrawn(e,t),!g&&this.isAlwaysDrawnExclusive))return;u=this.getElementOverrides(e,t,c),u!==void 0&&(d=h!==void 0?u.extendAppearance(d):u)}let m;if(!this.ignoreSubCategory&&te.isValidUint32Pair(n,i)){if((!g||!this.alwaysDrawnIgnoresSubCategory)&&!this.isSubCategoryVisibleInModel(n,i,r,a))return;m=this.getSubCategoryOverrides(n,i),m!==void 0&&(d=m.extendAppearance(d))}u===void 0&&h===void 0&&m===void 0&&(d=this._defaultOverrides.extendAppearance(d));let p=g||this.isClassVisible(s);return p&&d.isFullyTransparent&&(p=!1),p?d:void 0}getClassifierAppearance(e,t,n,i,s,r,a){let o=Zt.defaults;const c=this.getModelOverrides(s,r);c!==void 0&&(o=c.extendAppearance(o));const d=this.getElementOverrides(e,t,a);if(d!==void 0&&(o=c!==void 0?d.extendAppearance(o):d),!this.ignoreSubCategory&&te.isValidUint32Pair(n,i)){const h=this.getSubCategoryOverrides(n,i);h!==void 0&&(o=h.extendAppearance(o))}return d===void 0&&c===void 0&&(o=this._defaultOverrides.extendAppearance(o)),o}isClassVisible(e){switch(e){case An.Construction:return this._constructions;case An.Dimension:return this._dimensions;case An.Pattern:return this._patterns;default:return!0}}override(e){let t,n;e.elementId!==void 0?(t=e.elementId,n=this._elementOverrides):e.modelId!==void 0?(t=e.modelId,n=this._modelOverrides):(t=e.subCategoryId,n=this._subCategoryOverrides);let i=e.appearance;const s=te.getLowerUint32(t),r=te.getUpperUint32(t);if(e.elementId!==void 0&&this.isNeverDrawn(s,r,0))return;const o=e.onConflict==="replace"?void 0:n.get(s,r);if(o)switch(e.onConflict,e.onConflict){case"skip":return;case"extend":i=i.extendAppearance(o);break;default:i=o.extendAppearance(i);break}n.set(s,r,i)}overrideAnimationNode(e,t){this.animationNodeOverrides.set(e,t)}setDefaultOverrides(e,t=!0){(t||!e.overridesSymbology)&&(this._defaultOverrides=e)}getSubCategoryPriority(e,t){return this._subCategoryPriorities.get(e,t)??0}addInvisibleElementOverridesToNeverDrawn(){this._elementOverrides.forEach((e,t)=>{this.getElementOverrides(e,t,0)?.isFullyTransparent&&this._neverDrawn.add(e,t)})}constructor(){}isSubCategoryIdVisible(e){return this.isSubCategoryVisible(te.getLowerUint32(e),te.getUpperUint32(e))}getModelOverridesById(e){return this.getModelOverrides(te.getLowerUint32(e),te.getUpperUint32(e))}getElementOverridesById(e){return this.getElementOverrides(te.getLowerUint32(e),te.getUpperUint32(e),0)}getSubCategoryOverridesById(e){return this.getSubCategoryOverrides(te.getLowerUint32(e),te.getUpperUint32(e))}isFeatureVisible(e){const{elementId:t,subCategoryId:n,geometryClass:i}=e,r=!te.isInvalid(t)?te.getUint32Pair(t):void 0;if(r!==void 0&&this.isNeverDrawn(r.lower,r.upper,0))return!1;const a=r!==void 0&&this.isAlwaysDrawn(r.lower,r.upper);return a||this.isAlwaysDrawnExclusive?a:this.isSubCategoryIdVisible(n)?this.isClassVisible(i):!1}}var Wo;(function(l){function e(i,s){return{getAppearance:(r,a,o,c,d,h,u,g,m)=>s.getFeatureAppearance(i,r,a,o,c,d,h,u,g,m)}}function t(i){return{getFeatureAppearance:(s,r,a,o,c,d,h,u,g,m)=>{const p=s.getAppearance(r,a,o,c,d,h,u,g,m);return p&&i(p)}}}l.supplement=t;function n(i,s){return i===s?i:{getFeatureAppearance:(r,a,o,c,d,h,u,g,m,p)=>s.getFeatureAppearance(e(r,i),a,o,c,d,h,u,g,m,p)}}l.chain=n})(Wo||(Wo={}));var ei;(function(l){l[l.None=0]="None",l[l.ByView=1]="ByView",l[l.Always=2]="Always",l[l.Behind=4]="Behind",l[l.Blanking=6]="Blanking",l[l.Background=8]="Background"})(ei||(ei={}));const Go=new Uint16Array(1);function Fd(l,e,t){return l<e?e:l>t?t:l}function Qo(l){return Jo(.5+(Fd(l,-1,1)*.5+.5)*255)}function Jo(l){return Go[0]=l,Go[0]}function xr(l){return l<0?-1:1}class _r{value;constructor(e){this.value=Jo(e)}static encode(e){return this.encodeXYZ(e.x,e.y,e.z)}static encodeXYZ(e,t,n){const i=Math.abs(e)+Math.abs(t)+Math.abs(n);let s=e/i,r=t/i;if(n<0){const a=s,o=r;s=(1-Math.abs(o))*xr(a),r=(1-Math.abs(a))*xr(o)}return Qo(r)<<8|Qo(s)}static fromVector(e){return new _r(this.encode(e))}decode(){return _r.decodeValue(this.value)}static decodeValue(e,t){let n=e&255,i=e>>8;n=n/255*2-1,i=i/255*2-1;const s=1-(Math.abs(n)+Math.abs(i));let r;if(t===void 0?r=new v(n,i,s):(r=t,r.x=n,r.y=i,r.z=s),r.z<0){const a=r.x,o=r.y;r.x=(1-Math.abs(o))*xr(a),r.y=(1-Math.abs(a))*xr(o)}return r.normalizeInPlace(),r}}var xe;(function(l){l.rangeScale16=65535,l.rangeScale8=255;function e(a,o=l.rangeScale16){return a===0?a:o/a}l.computeScale=e;function t(a,o=l.rangeScale16){return a>=0&&a<o+1}l.isInRange=t;function n(a,o,c,d=l.rangeScale16){return Math.floor(Math.max(0,Math.min(d,.5+(a-o)*c)))}l.quantize=n;function i(a,o,c,d=l.rangeScale16){return t(n(a,o,c,d))}l.isQuantizable=i;function s(a,o,c){return c===0?o:o+a/c}l.unquantize=s;function r(a){return t(a)&&a===Math.floor(a)}l.isQuantized=r})(xe||(xe={}));class fi{origin=new L;scale=new L;constructor(e=0,t=0,n=0,i=0){this.setFrom(e,t,n,i)}setFrom(e,t,n,i){this.origin.x=e,this.origin.y=t,this.scale.x=n,this.scale.y=i}copyFrom(e){this.setFrom(e.origin.x,e.origin.y,e.scale.x,e.scale.y)}clone(e){const t=e!==void 0?e:new fi;return t.copyFrom(this),t}setFromRange(e,t=xe.rangeScale16){e.isNull?this.origin.x=this.origin.y=this.scale.x=this.scale.y=0:this.setFrom(e.low.x,e.low.y,xe.computeScale(e.high.x-e.low.x,t),xe.computeScale(e.high.y-e.low.y,t))}static fromRange(e,t,n=xe.rangeScale16){const i=t!==void 0?t:new fi;return i.setFromRange(e,n),i}unquantize(e,t,n){return n=n??new L,n.x=xe.unquantize(e,this.origin.x,this.scale.x),n.y=xe.unquantize(t,this.origin.y,this.scale.y),n}static fromNormalizedRange(e=xe.rangeScale16){return fi.fromRange(ze.createArray([L.create(-1,-1),L.create(1,1)]),void 0,e)}static fromZeroToOne(e=xe.rangeScale16){return fi.fromRange(ze.createArray([L.create(0,0),L.create(1,1)]),void 0,e)}static fromOriginAndScale(e,t,n,i){return new fi(e,t,n,i)}get rangeDiagonal(){return $.createFrom({x:this.scale.x===0?0:xe.rangeScale16/this.scale.x,y:this.scale.y===0?0:xe.rangeScale16/this.scale.y})}isQuantizable(e){return xe.isQuantizable(e.x,this.origin.x,this.scale.x)&&xe.isQuantizable(e.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(e){return this.fromOriginAndScale(e.origin.x,e.origin.y,e.scale.x,e.scale.y)}}class Gi{_x=0;_y=0;get x(){return this._x}set x(e){xe.isQuantized(e),this._x=e}get y(){return this._y}set y(e){xe.isQuantized(e),this._y=e}constructor(){}init(e,t){this.x=xe.quantize(e.x,t.origin.x,t.scale.x),this.y=xe.quantize(e.y,t.origin.y,t.scale.y)}static create(e,t){const n=new Gi;return n.init(e,t),n}copyFrom(e){this.x=e.x,this.y=e.y}clone(e){const t=e!==void 0?e:new Gi;return t.copyFrom(this),t}setFromScalars(e,t){this.x=e,this.y=t}static fromScalars(e,t){const n=new Gi;return n.setFromScalars(e,t),n}unquantize(e,t){const n=t!==void 0?t:new L;return n.x=xe.unquantize(this.x,e.origin.x,e.scale.x),n.y=xe.unquantize(this.y,e.origin.y,e.scale.y),n}}var Ho;(function(l){const e=new Gi;function t(i,s,r){const a=s*2,o=i[a+0],c=i[a+1];if(o===void 0||c===void 0)throw new Error("Index out of range");return r=r??new Gi,r.setFromScalars(o,c),r}l.getQPoint=t;function n(i,s,r){return t(i.points,s,e).unquantize(i.params,r)}l.unquantizePoint=n})(Ho||(Ho={}));class ti{origin=new y;scale=new y;constructor(e=0,t=0,n=0,i=0,s=0,r=0){this.setFrom(e,t,n,i,s,r)}setFrom(e,t,n,i,s,r){this.origin.x=e,this.origin.y=t,this.origin.z=n,this.scale.x=i,this.scale.y=s,this.scale.z=r}copyFrom(e){this.setFrom(e.origin.x,e.origin.y,e.origin.z,e.scale.x,e.scale.y,e.scale.z)}clone(e){const t=e!==void 0?e:new ti;return t.copyFrom(this),t}setFromOriginAndScale(e,t){this.setFrom(e.x,e.y,e.z,t.x,t.y,t.z)}setFromRange(e,t=xe.rangeScale16){e.isNull?(this.origin.x=this.origin.y=this.origin.z=0,this.scale.x=this.scale.y=this.scale.z=0):this.setFrom(e.low.x,e.low.y,e.low.z,xe.computeScale(e.high.x-e.low.x,t),xe.computeScale(e.high.y-e.low.y,t),xe.computeScale(e.high.z-e.low.z,t))}unquantize(e,t,n,i){const s=i!==void 0?i:new y;return s.x=xe.unquantize(e,this.origin.x,this.scale.x),s.y=xe.unquantize(t,this.origin.y,this.scale.y),s.z=xe.unquantize(n,this.origin.z,this.scale.z),s}static fromRange(e,t,n=xe.rangeScale16){const i=t!==void 0?t:new ti;return i.setFromRange(e,n),i}static fromOriginAndScale(e,t,n){const i=n!==void 0?n:new ti;return i.setFromOriginAndScale(e,t),i}static fromNormalizedRange(e=xe.rangeScale16){return ti.fromRange(ie.createArray([y.create(-1,-1,-1),y.create(1,1,1)]),void 0,e)}static fromZeroToOne(e=xe.rangeScale16){return ti.fromRange(ie.createArray([y.create(0,0,0),y.create(1,1,1)]),void 0,e)}get rangeDiagonal(){return v.createFrom({x:this.scale.x===0?0:xe.rangeScale16/this.scale.x,y:this.scale.y===0?0:xe.rangeScale16/this.scale.y,z:this.scale.z===0?0:xe.rangeScale16/this.scale.z})}isQuantizable(e){return xe.isQuantizable(e.x,this.origin.x,this.scale.x)&&xe.isQuantizable(e.y,this.origin.y,this.scale.y)&&xe.isQuantizable(e.z,this.origin.z,this.scale.z)}computeRange(e){const t=ie.createNull(e);return t.extendPoint(this.origin),t.extendPoint(this.origin.plus(this.rangeDiagonal)),t}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(e,t){return this.fromOriginAndScale(y.fromJSON(e.origin),y.fromJSON(e.scale),t)}}class Ei{_x=0;_y=0;_z=0;get x(){return this._x}set x(e){xe.isQuantized(e),this._x=e}get y(){return this._y}set y(e){xe.isQuantized(e),this._y=e}get z(){return this._z}set z(e){xe.isQuantized(e),this._z=e}constructor(){}init(e,t){this.x=xe.quantize(e.x,t.origin.x,t.scale.x),this.y=xe.quantize(e.y,t.origin.y,t.scale.y),this.z=xe.quantize(e.z,t.origin.z,t.scale.z)}static create(e,t){const n=new Ei;return n.init(e,t),n}copyFrom(e){this.x=e.x,this.y=e.y,this.z=e.z}clone(e){const t=e!==void 0?e:new Ei;return t.copyFrom(this),t}setFromScalars(e,t,n){this.x=e,this.y=t,this.z=n}static fromScalars(e,t,n,i){const s=i===void 0?new Ei:i;return s.setFromScalars(e,t,n),s}unquantize(e,t){const n=t!==void 0?t:new y;return n.x=xe.unquantize(this.x,e.origin.x,e.scale.x),n.y=xe.unquantize(this.y,e.origin.y,e.scale.y),n.z=xe.unquantize(this.z,e.origin.z,e.scale.z),n}equals(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}compare(e){let t=this.x-e.x;return t===0&&(t=this.y-e.y,t===0&&(t=this.z-e.z)),t}}var Ko;(function(l){const e=new Ei;function t(i,s,r){const a=s*3,o=i[a+0],c=i[a+1],d=i[a+2];if(o===void 0||c===void 0||d===void 0)throw new Error("Index out of range");return r=r??new Ei,r.setFromScalars(o,c,d),r}l.getQPoint=t;function n(i,s,r){return t(i.points,s,e).unquantize(i.params,r)}l.unquantizePoint=n})(Ko||(Ko={}));var ps;(function(l){l[l.Normal=0]="Normal",l[l.Edge=1]="Edge",l[l.Outline=2]="Outline"})(ps||(ps={}));class Rd{key;textureMapping;_guid;constructor(e){this.key=e.key,this.textureMapping=e.textureMapping,this._guid=As.createValue()}get hasTexture(){return this.textureMapping?.texture!==void 0}compare(e){return ii(this._guid,e._guid)}}function yr(l,e,t){return l+t*(e-l)}function Md(l,e,t){return new Lt(yr(l.r,e.r,t),yr(l.g,e.g,t),yr(l.b,e.b,t))}function gi(l,e){return Pe(l.x,e.x)||Pe(l.y,e.y)||Pe(l.z,e.z)}function Dd(l,e){return Pe(l.x,e.x)||Pe(l.y,e.y)||Pe(l.z,e.z)||Pe(l.w,e.w)}const Ea=new v,ka=new v;function Nd(l,e){return gi(l.columnX(Ea),e.columnX(ka))||gi(l.columnY(Ea),e.columnY(ka))||gi(l.columnZ(Ea),e.columnZ(ka))}function Fa(l,e){return Pe(l.low,e.low)||Pe(l.high,e.high)}var Pr;(function(l){let e;(function(D){D[D.Step=1]="Step",D[D.Linear=2]="Linear"})(e=l.Interpolation||(l.Interpolation={}));class t{time;interpolation;constructor(P){this.time=P.time,this.interpolation=P.interpolation===e.Linear?P.interpolation:e.Step}toJSON(){const P={time:this.time};return this.interpolation===e.Linear&&(P.interpolation=this.interpolation),P}compareTo(P){return Pe(this.interpolation,P.interpolation)||Pe(this.time,P.time)}equals(P){return this.compareTo(P)===0}}l.TimelineEntry=t;class n extends t{value;constructor(P){super(P),typeof P.value!="number"?this.value=100:this.value=Math.max(0,Math.min(100,P.value))}toJSON(){const P=super.toJSON();return this.value!==100&&(P.value=this.value),P}compareTo(P){return super.compareTo(P)||Pe(this.value,P.value)}}l.VisibilityEntry=n;class i extends t{value;constructor(P){super(P),P.value&&(this.value=new Lt(P.value.red,P.value.green,P.value.blue))}toJSON(){const P=super.toJSON();return this.value&&(P.value={red:this.value.r,green:this.value.g,blue:this.value.b}),P}compareTo(P){return super.compareTo(P)||Qt((b,C)=>b.compareTo(C),this.value,P.value)}}l.ColorEntry=i;class s{pivot;orientation;position;constructor(P,b,C){this.position=P,this.pivot=b,this.orientation=C}static fromJSON(P){if(P.pivot&&P.position&&P.orientation)return new s(v.fromJSON(P.position),v.fromJSON(P.pivot),Z.fromJSON(P.orientation))}toJSON(){return{position:[this.position.x,this.position.y,this.position.z],pivot:[this.pivot.x,this.pivot.y,this.pivot.z],orientation:[this.orientation.x,this.orientation.y,this.orientation.z,this.orientation.w]}}compareTo(P){return gi(this.pivot,P.pivot)||gi(this.position,P.position)||Dd(this.orientation,P.orientation)}equals(P){return this.pivot.isAlmostEqual(P.pivot)&&this.position.isAlmostEqual(P.position)&&this.orientation.isAlmostEqual(P.orientation)}}l.TransformComponents=s;class r extends t{value;components;constructor(P){super(P),this.value=P.value?X.fromJSON(P.value.transform):X.identity,P.value&&(this.components=s.fromJSON(P.value))}toJSON(){const P=super.toJSON();return this.components?(P.value=this.components.toJSON(),P.value.transform=this.value.toRows()):P.value={transform:this.value.toRows()},P}compareTo(P){const b=super.compareTo(P);return b!==0?b:this.components||P.components?!this.components||!P.components?this.components?1:-1:this.components.compareTo(P.components):gi(this.value.origin,P.value.origin)||Nd(this.value.matrix,P.value.matrix)}}l.TransformEntry=r;class a{position;direction;visible;hidden;constructor(P){this.position=y.fromJSON(P.position),this.direction=y.fromJSON(P.direction),this.hidden=P.hidden===!0,this.visible=P.visible===!0}toJSON(){const P={position:[this.position.x,this.position.y,this.position.z],direction:[this.direction.x,this.direction.y,this.direction.z]};return this.visible&&(P.visible=!0),this.hidden&&(P.hidden=!0),P}compareTo(P){return gi(this.position,P.position)||gi(this.direction,P.direction)||Pt(this.visible,P.visible)||Pt(this.hidden,P.hidden)}equals(P){return this.compareTo(P)===0}}l.CuttingPlane=a;class o extends t{value;constructor(P){super(P),P.value&&(this.value=new a(P.value))}toJSON(){const P=super.toJSON();return this.value&&(P.value=this.value.toJSON()),P}compareTo(P){return super.compareTo(P)||Qt((b,C)=>b.compareTo(C),this.value,P.value)}}l.CuttingPlaneEntry=o;class c{lowerIndex;upperIndex;fraction;constructor(P=0,b=0,C=0){this.init(P,b,C)}init(P=0,b=0,C=0){this.lowerIndex=P,this.upperIndex=b,this.fraction=C}}l.Interval=c;class d{_entries;duration;constructor(P,b){this.duration=fe.createNull(),this._entries=P.map(C=>{const M=new b(C);return this.duration.extendX(M.time),M})}get length(){return this._entries.length}[Symbol.iterator](){return this._entries[Symbol.iterator]()}getEntry(P){return this._entries[P]}getValue(P){return this.getEntry(P)?.value}toJSON(){return this._entries.map(P=>P.toJSON())}compareTo(P){let b=Pe(this._entries.length,P._entries.length)||Fa(this.duration,P.duration);if(b===0)for(let C=0;C<this.length&&(b=this._entries[C].compareTo(P._entries[C]))===0;C++);return b}equals(P){return this.compareTo(P)===0}findInterval(P,b){if(this.length===0)return;if(b=b??new c,P<this._entries[0].time)return b.init(0,0,0),b;const C=this.length-1;if(P>=this._entries[C].time)return b.init(C,C,0),b;for(let M=0;M<C;M++){const G=this._entries[M].time,ae=this._entries[M+1].time;if(G<=P&&ae>P){let ye;return e.Linear===this._entries[M].interpolation?ye=(P-G)/(ae-G):ye=0,b.init(M,M+1,ye),b}}}}l.TimelineEntryList=d;const h=new c;class u extends d{getValue(P){return super.getValue(P)??100}}l.VisibilityTimelineEntries=u;class g extends d{getValue(P){return super.getValue(P)??X.identity}}l.TransformTimelineEntries=g;class m{visibility;color;transform;cuttingPlane;duration;isEditingCommitted=!1;constructor(P){this.duration=fe.createNull(),P.visibilityTimeline&&(this.visibility=new u(P.visibilityTimeline,n),this.duration.extendRange(this.visibility.duration)),P.colorTimeline&&(this.color=new d(P.colorTimeline,i),this.duration.extendRange(this.color.duration)),P.transformTimeline&&(this.transform=new g(P.transformTimeline,r),this.duration.extendRange(this.transform.duration)),P.cuttingPlaneTimeline&&(this.cuttingPlane=new d(P.cuttingPlaneTimeline,o),this.duration.extendRange(this.cuttingPlane.duration))}toJSON(){return{visibilityTimeline:this.visibility?.toJSON(),colorTimeline:this.color?.toJSON(),transformTimeline:this.transform?.toJSON(),cuttingPlaneTimeline:this.cuttingPlane?.toJSON()}}compareTo(P){const b=Fa(this.duration,P.duration);return b!==0?b:!!this.visibility!=!!P.visibility?this.visibility?1:-1:!!this.color!=!!P.color?this.color?1:-1:!!this.transform!=!!P.transform?this.transform?1:-1:!!this.cuttingPlane!=!!P.cuttingPlane?this.cuttingPlane?1:-1:Qt((C,M)=>C.compareTo(M),this.visibility,P.visibility)||Qt((C,M)=>C.compareTo(M),this.color,P.color)||Qt((C,M)=>C.compareTo(M),this.transform,P.transform)||Qt((C,M)=>C.compareTo(M),this.cuttingPlane,P.cuttingPlane)}equals(P){return this.compareTo(P)===0}getVisibility(P){let b;if(!this.visibility||!(b=this.visibility.findInterval(P,h)))return 100;let C=this.visibility.getValue(b.lowerIndex)??100;return b.fraction>0&&(C=yr(C,this.visibility.getValue(b.upperIndex)??100,b.fraction)),C}getColor(P){let b;if(!this.color||!(b=this.color.findInterval(P,h)))return;const C=this.color.getValue(b.lowerIndex);if(C&&b.fraction>0){const M=this.color.getValue(b.upperIndex);if(M)return Md(C,M,b.fraction)}return C}getAnimationTransform(P){let b;if(!this.transform||!(b=this.transform.findInterval(P,h)))return X.identity;let C=this.transform.getValue(b.lowerIndex);if(b.fraction>0){const M=this.transform.getEntry(b.lowerIndex)?.components,G=this.transform.getEntry(b.upperIndex)?.components;if(M&&G){const ae=Z.interpolateQuaternions(M.orientation,b.fraction,G.orientation),ye=E.createFromQuaternion(ae),F=X.createTranslation(M.pivot),V=X.createTranslation(M.position.interpolate(b.fraction,G.position)).multiplyTransformMatrix3d(ye);V.multiplyTransformTransform(F,V),C=V}else{const ae=this.transform.getValue(b.upperIndex),ye=C.matrix.inverse()?.toQuaternion(),F=ae.matrix.inverse()?.toQuaternion();if(ye&&F){const R=Z.interpolateQuaternions(ye,b.fraction,F),V=E.createFromQuaternion(R),ne=v.createFrom(C.origin),Xe=v.createFrom(ae.origin);C=X.createRefs(ne.interpolate(b.fraction,Xe),V)}}}return C}getCuttingPlane(P){let b;if(!this.cuttingPlane||!(b=this.cuttingPlane.findInterval(P,h)))return;const C=this.cuttingPlane.getValue(b.lowerIndex);if(!C)return;const M=y.createFrom(C.position),G=v.createFrom(C.direction),ae=b.fraction>0?this.cuttingPlane.getValue(b.upperIndex):void 0;if(ae)M.interpolate(b.fraction,ae.position,M),G.interpolate(b.fraction,ae.direction,G);else if(C.hidden||C.visible)return;return G.negate(G),G.normalizeInPlace(),pe.create(M,G)}getClipVector(P){const b=this.getCuttingPlane(P);if(!b)return;const C=ee.createPlane(b),M=xt.createConvexSets([Ce.createPlanes([C])]),G=Fn.createCapture(M);return yn.createCapture([G])}getFeatureAppearance(P,b){const C=P<100?1-P/100:void 0,M=this.getColor(b);return M!==void 0||C!==void 0?Zt.fromJSON({rgb:M,transparency:C}):void 0}}l.Timeline=m;class p extends m{batchId;_elementIds;constructor(P){super(P),this.batchId=P.batchId,this._elementIds=P.elementIds}static fromJSON(P){return new p(P??{elementIds:[],batchId:0})}toJSON(){return{...super.toJSON(),batchId:this.batchId,elementIds:this._elementIds}}get containsElementIds(){return this._elementIds.length>0}compareElementIds(P){if(typeof this._elementIds==typeof P._elementIds){const M=Pe(this._elementIds.length,P._elementIds.length);if(M!==0)return M;if(typeof this._elementIds=="string")return P._elementIds,ii(this._elementIds,P._elementIds)}const b=this.elementIds[Symbol.iterator](),C=P.elementIds[Symbol.iterator]();for(;;){const M=b.next(),G=C.next();if(M.done!==G.done)return Pt(!!M.done,!!G.done);if(M.done)return 0;const ae=ii(M.value,G.value);if(ae!==0)return ae}}compareTo(P){return Pe(this.batchId,P.batchId)||this.compareElementIds(P)||super.compareTo(P)}static getElementIds(P){return typeof P=="string"?Ts.iterable(P):Array.isArray(P)?P:[]}get elementIds(){return p.getElementIds(this._elementIds)}get containsFeatureOverrides(){return this.visibility!==void 0||this.color!==void 0}get requiresBatching(){return this.cuttingPlane?!0:this.batchId!==0&&(this.color!==void 0||this.visibility!==void 0)}get containsTransform(){return this.transform!==void 0}addSymbologyOverrides(P,b){this.batchId;const C=this.getVisibility(b);if(C<=0){P.setAnimationNodeNeverDrawn(this.batchId);return}const M=this.getFeatureAppearance(C,b);M&&P.overrideAnimationNode(this.batchId,M)}}l.ElementTimeline=p;class x extends m{modelId;realityModelUrl;elementTimelines;transformBatchIds;containsFeatureOverrides;containsModelClipping;requiresBatching;containsTransform;omitsElementIds;_maxBatchId;_cachedComparisons=new WeakMap;_idPairToElementTimeline;_discreteBatchIds;constructor(P){super(P),this.modelId=P.modelId,this.realityModelUrl=P.realityModelUrl,this.containsModelClipping=this.cuttingPlane!==void 0;let b=this.visibility!==void 0||this.color!==void 0,C=!1,M=!1;const G=[],ae=[];let ye=!1;for(const F of P.elementTimelines){const R=p.fromJSON(F);ae.push(R),this.duration.extendRange(R.duration),R.containsTransform&&(M=!0,R.batchId&&G.push(R.batchId)),b||=R.containsFeatureOverrides,C||=R.requiresBatching,ye=ye||R.containsElementIds}this.elementTimelines=ae,this.transformBatchIds=G,this.omitsElementIds=ae.length>0&&!ye,this.containsFeatureOverrides=b,this.requiresBatching=C,this.containsTransform=M}static fromJSON(P){return new x(P??{elementTimelines:[],modelId:te.invalid})}toJSON(){return{...super.toJSON(),modelId:this.modelId,realityModelUrl:this.realityModelUrl,elementTimelines:this.elementTimelines.map(P=>P.toJSON())}}compareTo(P){if(this===P)return 0;const b=this._cachedComparisons.get(P);if(b!==void 0)return b;let C=ii(this.modelId,P.modelId)||gc(this.realityModelUrl,P.realityModelUrl)||Pe(this.elementTimelines.length,P.elementTimelines.length)||Pt(this.containsFeatureOverrides,P.containsFeatureOverrides)||Pt(this.containsModelClipping,P.containsModelClipping)||Pt(this.containsTransform,P.containsTransform)||super.compareTo(P);if(C===0)for(let M=0;M<this.elementTimelines.length&&(C=this.elementTimelines[M].compareTo(P.elementTimelines[M]))===0;M++);return this._cachedComparisons.set(P,C),P._cachedComparisons.set(this,-C),C}findByBatchId(P){return this.elementTimelines.find(b=>b.batchId===P)}addSymbologyOverrides(P,b){const C=this.getFeatureAppearance(this.getVisibility(b),b);C&&P.override({modelId:this.modelId,appearance:C});for(const M of this.elementTimelines)M.addSymbologyOverrides(P,b)}getTransform(P,b){return this.findByBatchId(P)?.getAnimationTransform(b)}get maxBatchId(){if(this._maxBatchId===void 0){this._maxBatchId=0;for(const P of this.elementTimelines)this._maxBatchId=Math.max(this._maxBatchId,P.batchId)}return this._maxBatchId}getTimelineForElement(P,b){if(!this._idPairToElementTimeline){this._idPairToElementTimeline=new te.Uint32Map;for(const C of this.elementTimelines)for(const M of C.elementIds)this._idPairToElementTimeline.setById(M,C)}return this._idPairToElementTimeline.get(P,b)}get discreteBatchIds(){if(!this._discreteBatchIds){this._discreteBatchIds=new Set(this.transformBatchIds);for(const P of this.elementTimelines)!P.containsTransform&&P.cuttingPlane!==void 0&&this._discreteBatchIds.add(P.batchId)}return this._discreteBatchIds}getBatchIdForFeature(P){return te.fromUint32PairObject(P.modelId),this.modelId,this.getTimelineForElement(P.elementId.lower,P.elementId.upper)?.batchId??0}}l.ModelTimeline=x;class _{modelTimelines;containsModelClipping;requiresBatching;containsTransform;containsFeatureOverrides;duration;transformBatchIds;_cachedComparisons=new WeakMap;_discreteBatchIds;_lastFeatureModelTimeline;_maxBatchId;compareTo(P){if(this===P)return 0;const b=this._cachedComparisons.get(P);if(b!==void 0)return b;let C=Pe(this.modelTimelines.length,P.modelTimelines.length)||Pt(this.containsModelClipping,P.containsModelClipping)||Pt(this.requiresBatching,P.requiresBatching)||Pt(this.containsTransform,P.containsTransform)||Pt(this.containsFeatureOverrides,P.containsFeatureOverrides)||Fa(this.duration,P.duration);if(C===0)for(let M=0;M<this.modelTimelines.length&&(C=this.modelTimelines[M].compareTo(P.modelTimelines[M]))===0;M++);return this._cachedComparisons.set(P,C),P._cachedComparisons.set(this,-C),C}equals(P){return this.compareTo(P)===0}constructor(P){this.duration=fe.createNull();const b=new Set,C=[];let M=!1,G=!1,ae=!1,ye=!1;for(const F of P){const R=x.fromJSON(F);C.push(R),this.duration.extendRange(R.duration),M||=R.containsModelClipping,G||=R.requiresBatching,ae||=R.containsTransform,ye||=R.containsFeatureOverrides;for(const V of R.transformBatchIds)b.add(V)}this.modelTimelines=C,this.containsModelClipping=M,this.containsTransform=ae,this.requiresBatching=G||this.containsTransform,this.containsFeatureOverrides=ye,this.transformBatchIds=b}static fromJSON(P){if(!(!Array.isArray(P)||P.length===0))return new _(P)}toJSON(){return this.modelTimelines.map(P=>P.toJSON())}find(P){return this.modelTimelines.find(b=>b.modelId===P)}getTransformBatchIds(P){return this.find(P)?.transformBatchIds}getTransform(P,b,C){return this.find(P)?.getTransform(b,C)}addSymbologyOverrides(P,b){for(const C of this.modelTimelines)C.addSymbologyOverrides(P,b)}discloseIds(P){for(const b of this.modelTimelines){P.addModel(b.modelId);for(const C of b.elementTimelines)for(const M of C.elementIds)P.addElement(M)}}modelRequiresBatching(P){return this.requiresBatching&&this.modelTimelines.some(b=>b.modelId===P&&b.requiresBatching)}get discreteBatchIds(){if(this._discreteBatchIds)return this._discreteBatchIds;this._discreteBatchIds=new Set;for(const P of this.modelTimelines)for(const b of P.discreteBatchIds)this._discreteBatchIds.add(b);return this._discreteBatchIds}getBatchIdForFeature(P){let b;const C=this._lastFeatureModelTimeline;if(C&&C.idLower===P.modelId.lower&&C.idUpper===P.modelId.upper)b=C.timeline;else{const M=te.fromUint32PairObject(P.modelId);b=this.find(M),this._lastFeatureModelTimeline={timeline:b,idLower:P.modelId.lower,idUpper:P.modelId.upper}}return b?.getBatchIdForFeature(P)??0}get maxBatchId(){return this._maxBatchId??(this._maxBatchId=this.modelTimelines.reduce((P,b)=>Math.max(P,b.maxBatchId),0))}static removeScheduleScriptElementIds(P){return P.forEach(b=>{b.elementTimelines.forEach(C=>{C.elementIds&&(C.elementIds="")})}),P}}l.Script=_;class I{sourceId;script;constructor(P,b){typeof P=="string"?(this.sourceId=P,this.script=b):(this.script=P,this.sourceId=te.invalid)}}l.ScriptReference=I;class S{visibility;color;transform;cuttingPlane;addVisibility(P,b,C=e.Linear){this.visibility||(this.visibility=[]),this.visibility.push({time:P,value:b,interpolation:C})}addColor(P,b,C=e.Linear){this.color||(this.color=[]);const M=b instanceof Lt?{red:b.r,green:b.g,blue:b.b}:b;this.color.push({time:P,value:M,interpolation:C})}addCuttingPlane(P,b,C=e.Linear){this.cuttingPlane||(this.cuttingPlane=[]);let M;b&&(M={position:[b.position.x,b.position.y,b.position.z],direction:[b.direction.x,b.direction.y,b.direction.z]},b.visible&&(M.visible=!0),b.hidden&&(M.hidden=!0)),this.cuttingPlane.push({time:P,value:M,interpolation:C})}addTransform(P,b,C,M=e.Linear){this.transform||(this.transform=[]);const G={transform:b?.toRows()};C&&(G.pivot=[C.pivot.x,C.pivot.y,C.pivot.z],G.orientation=C.orientation.toJSON(),G.position=[C.position.x,C.position.y,C.position.z]),this.transform.push({time:P,value:G,interpolation:M})}finish(){const P={};return this.visibility?.length&&(P.visibilityTimeline=this.visibility),this.color?.length&&(P.colorTimeline=this.color),this.transform?.length&&(P.transformTimeline=this.transform),this.cuttingPlane?.length&&(P.cuttingPlaneTimeline=this.cuttingPlane),P}}l.TimelineBuilder=S;class A extends S{batchId;elementIds;constructor(P,b){super(),this.batchId=P,this.elementIds=b}finish(){const P=super.finish();return P.batchId=this.batchId,P.elementIds=this.elementIds,P}}l.ElementTimelineBuilder=A;class w extends S{modelId;realityModelUrl;_obtainNextBatchId;_elements=[];constructor(P,b){super(),this.modelId=P,this._obtainNextBatchId=b}addElementTimeline(P){const b=this._obtainNextBatchId();let C;if(typeof P=="string"&&te.isValidId64(P)&&(P=[P]),typeof P=="string")C=P;else{const G=Array.from(P);bs.sortArray(G),C=Ts.compressIds(G)}const M=new A(b,C);return this._elements.push(M),M}finish(){const P=super.finish();return P.modelId=this.modelId,this.realityModelUrl!==void 0&&(P.realityModelUrl=this.realityModelUrl),P.elementTimelines=this._elements.map(b=>b.finish()),P}}l.ModelTimelineBuilder=w;class k{_nextBatchId=1;_models=[];addModelTimeline(P){const b=new w(P,()=>this._nextBatchId++);return this._models.push(b),b}finish(){return this._models.map(P=>P.finish())}}l.ScriptBuilder=k})(Pr||(Pr={}));class mn{type;_guid;get isTileSection(){return mn.Type.TileSection===this.type}get isGlyph(){return mn.Type.Glyph===this.type}get isSkyBox(){return mn.Type.SkyBox===this.type}constructor(e){this.type=e,this._guid=As.createValue()}[Symbol.dispose](){this.dispose()}compare(e){return ii(this._guid,e._guid)}}(function(l){(function(e){e[e.Normal=0]="Normal",e[e.Glyph=1]="Glyph",e[e.TileSection=2]="TileSection",e[e.SkyBox=3]="SkyBox",e[e.FilteredTileSection=4]="FilteredTileSection",e[e.ThematicGradient=5]="ThematicGradient"})(l.Type||(l.Type={}))})(mn||(mn={}));function Od(l,e){return Qt((t,n)=>t.compare(n),l.normalMap,e.normalMap)||Za(l.greenUp,e.greenUp)||mc(l.scale,e.scale)||Za(l.useConstantLod,e.useConstantLod)}class wn{texture;normalMapParams;params;constructor(e,t){this.texture=e,this.params=t}computeUVParams(e,t=X.createIdentity()){return this.params.computeUVParams(e,t)}compare(e){return this===e?0:this.texture.compare(e.texture)||this.params.compare(e.params)||Qt((t,n)=>Od(t,n),this.normalMapParams,e.normalMapParams)}}(function(l){let e;(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"})(e=l.Mode||(l.Mode={}));class t{transform;constructor(r=1,a=0,o=0,c=0,d=1,h=0){const u=new y(o,h,0),g=E.createRowValues(r,a,0,c,d,0,0,0,1);this.transform=X.createRefs(u,g)}static identity=new t;compare(r){if(this===r)return 0;const a=Pe(this.transform.origin.x,r.transform.origin.x)||Pe(this.transform.origin.y,r.transform.origin.y);if(a!==0)return a;for(const o of[0,1,3,4]){const c=Pe(this.transform.matrix.coffs[o],r.transform.matrix.coffs[o]);if(c!==0)return c}return 0}}l.Trans2x3=t;function n(s,r){return Pe(s.repetitions,r.repetitions)||Pe(s.offset.x,r.offset.x)||Pe(s.offset.y,r.offset.y)||Pe(s.minDistClamp,r.minDistClamp)||Pe(s.maxDistClamp,r.maxDistClamp)}class i{textureMatrix;weight;mode;worldMapping;useConstantLod;constantLodParams;constructor(r){this.textureMatrix=r?.textureMat2x3??t.identity,this.weight=r?.textureWeight??1,this.mode=r?.mapMode??e.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:Pe(this.weight,r.weight)||Pe(this.mode,r.mode)||Pt(this.worldMapping,r.worldMapping)||Pt(this.useConstantLod,r.useConstantLod)||this.textureMatrix.compare(r.textureMatrix)||n(this.constantLodParams,r.constantLodParams)}computeUVParams(r,a=X.createIdentity()){switch(this.mode){default:case l.Mode.Parametric:return this.computeParametricUVParams(r,this.textureMatrix.transform,!this.worldMapping);case l.Mode.Planar:{const o=r.normalIndex;return o?!this.worldMapping||r.normalIndex!==void 0&&(o[0]!==o[1]||o[0]!==o[2])?this.computeParametricUVParams(r,this.textureMatrix.transform,!this.worldMapping):this.computePlanarUVParams(r,this.textureMatrix.transform):void 0}case l.Mode.ElevationDrape:return this.computeElevationDrapeUVParams(r,this.textureMatrix.transform,a)}}computeParametricUVParams(r,a,o){const c=[];for(let d=0;d<r.numEdgesThisFacet;d++){let h=L.create();(o||!r.tryGetDistanceParameter(d,h))&&(r.tryGetNormalizedParameter(d,h)||(h=Nr(r.getParam(d)))),c.push(a.multiplyPoint2d(h))}return c}computePlanarUVParams(r,a){const o=[],c=r.point;let d;if(r.normal===void 0?d=c.getPoint3dAtUncheckedPointIndex(0).crossProductToPoints(c.getPoint3dAtUncheckedPointIndex(1),c.getPoint3dAtUncheckedPointIndex(2)):d=Nr(r.normal.getVector3dAtCheckedVectorIndex(0)),!d.normalize(d))return;d.scale(-1,d);const h=v.create(d.y,-d.x,0),u=h.magnitude();h.normalize(h),u<.001&&(d.set(0,0,-1),h.set(1,0,0));const g=h.crossProduct(d).normalize();if(!g)return;const m=r.numEdgesThisFacet;for(let p=0;p<m;p++){const x=v.createFrom(c.getPoint3dAtUncheckedPointIndex(p));o.push(L.create(x.dotProduct(h),x.dotProduct(g))),a.multiplyPoint2d(o[p],o[p])}return o}computeElevationDrapeUVParams(r,a,o){const c=[],d=r.numEdgesThisFacet;for(let h=0;h<d;h++){const u=r.point.getPoint3dAtUncheckedPointIndex(h);o!==void 0&&o.multiplyPoint3d(u,u),c.push(L.createFrom(u)),a.multiplyPoint2d(c[h],c[h])}return c}}l.Params=i})(wn||(wn={})),Object.freeze(wn.Trans2x3.identity);var Wt;(function(l){l[l.Unknown=0]="Unknown",l[l.B3dm=1835283298]="B3dm",l[l.Gltf=1179937895]="Gltf",l[l.Pnts=1937010288]="Pnts",l[l.IModel=1818512745]="IModel",l[l.Cmpt=1953525091]="Cmpt",l[l.I3dm=1835283305]="I3dm",l[l.A3x=5780289]="A3x"})(Wt||(Wt={}));function Xd(l){switch(l){case Wt.Unknown:case Wt.B3dm:case Wt.Gltf:case Wt.IModel:case Wt.Pnts:case Wt.Cmpt:case Wt.I3dm:case Wt.A3x:return!0;default:return!1}}function Ld(l){const e=l;return Xd(e)?e:Wt.Unknown}var bn;(function(l){l[l.Success=0]="Success",l[l.InvalidTileData=1]="InvalidTileData",l[l.InvalidHeader=2]="InvalidHeader",l[l.InvalidBatchTable=3]="InvalidBatchTable",l[l.InvalidScene=4]="InvalidScene",l[l.InvalidFeatureTable=5]="InvalidFeatureTable",l[l.NewerMajorVersion=6]="NewerMajorVersion",l[l.Canceled=7]="Canceled"})(bn||(bn={}));class jo{_format;version;constructor(e){this._format=Ld(e.readUint32()),this.version=e.readUint32()}get format(){return this._format}invalidate(){this._format=Wt.Unknown}}function $o(l,e){const t=l.readFloat64(),n=l.readFloat64(),i=l.readFloat64();return e===void 0?new y(t,n,i):(e.set(t,n,i),e)}var mi;(function(l){l[l.Version1=1]="Version1",l[l.Version2=2]="Version2",l[l.CurrentVersion=1]="CurrentVersion",l[l.Gltf1SceneFormat=0]="Gltf1SceneFormat"})(mi||(mi={}));var Ir;(function(l){l[l.JSON=1313821514]="JSON",l[l.Binary=5130562]="Binary"})(Ir||(Ir={}));class Yd extends jo{gltfLength;scenePosition=0;sceneStrLength=0;binaryPosition=0;get isValid(){return Wt.Gltf===this.format}constructor(e){super(e),this.gltfLength=e.readUint32(),this.sceneStrLength=e.readUint32();const t=e.readUint32();if(this.version===mi.Version2&&t===mi.Gltf1SceneFormat&&(this.version=mi.Version1),this.version===mi.Version1){const n=t;if(mi.Gltf1SceneFormat!==n){this.invalidate();return}this.scenePosition=e.curPos,this.binaryPosition=e.curPos+this.sceneStrLength}else if(this.version===mi.Version2){const n=t;this.scenePosition=e.curPos,e.curPos=e.curPos+this.sceneStrLength;const i=e.readUint32(),s=e.readUint32();if(Ir.JSON!==n||Ir.Binary!==s||i===0){this.invalidate();return}this.binaryPosition=e.curPos}else this.invalidate()}}var Ra;(function(l){l[l.None=0]="None",l[l.ContainsCurves=1]="ContainsCurves",l[l.Incomplete=4]="Incomplete",l[l.DisallowMagnification=8]="DisallowMagnification",l[l.MultiModelFeatureTable=16]="MultiModelFeatureTable"})(Ra||(Ra={}));var Ma;(function(l){l[l.Major=37]="Major",l[l.Minor=0]="Minor",l[l.Combined=2424832]="Combined"})(Ma||(Ma={}));class zd extends jo{headerLength;flags;contentRange;tolerance;numElementsIncluded;numElementsExcluded;tileLength;emptySubRanges;get versionMajor(){return this.version>>>16}get versionMinor(){return(this.version&65535)>>>0}get isValid(){return Wt.IModel===this.format}get isReadableVersion(){return this.versionMajor<=Ma.Major}constructor(e){super(e),this.headerLength=e.readUint32(),this.flags=e.readUint32(),this.contentRange=new ie,$o(e,this.contentRange.low),$o(e,this.contentRange.high),this.tolerance=e.readFloat64(),this.numElementsIncluded=e.readUint32(),this.numElementsExcluded=e.readUint32(),this.tileLength=e.readUint32(),this.emptySubRanges=this.versionMajor>=2?e.readUint32():0;const t=this.headerLength-e.curPos;e.advance(t),e.isPastTheEnd&&this.invalidate()}}class xs{length;numSubCategories;count;static readFrom(e){const t=e.readUint32(),n=e.readUint32(),i=e.readUint32();return e.isPastTheEnd?void 0:new xs(t,n,i)}static sizeInBytes=12;constructor(e,t,n){this.length=e,this.numSubCategories=t,this.count=n}}function Bd(l){return Math.max(0,Math.min(1,l))}class Qi{key;diffuseColor;specularColor;emissiveColor;reflectColor;textureMapping;diffuse=.6;specular=.4;specularExponent=13.5;reflect=0;refract=1;ambient=.3;shadows=!0;_alpha;constructor(e){this.key=e}static defaults=new Qi;get alpha(){return this._alpha}set alpha(e){this._alpha=e!==void 0?Bd(e):void 0}static fromColors(e,t,n,i,s,r){const a=new Qi;return a.key=e,a.diffuseColor=t,a.specularColor=n,a.emissiveColor=i,a.reflectColor=s,a.textureMapping=r,a}}Object.freeze(Qi.defaults);function ft(l,e){e&&l.add(e.buffer)}function Da(l,e){if(e.type==="pattern"){ft(l,e.params.xyOffsets);return}switch(ft(l,e.params.vertices.data),e.modifier?.type==="instances"&&(ft(l,e.modifier.transforms),ft(l,e.modifier.featureIds),ft(l,e.modifier.symbologyOverrides)),e.type){case"point":ft(l,e.params.indices);break;case"polyline":ft(l,e.params.polyline.indices),ft(l,e.params.polyline.prevIndices),ft(l,e.params.polyline.nextIndicesAndParams);break;case"mesh":ft(l,e.params.surface.indices);const t=e.params.edges;t&&(ft(l,t.segments?.indices),ft(l,t.segments?.endPointAndQuadIndices),ft(l,t.silhouettes?.indices),ft(l,t.silhouettes?.endPointAndQuadIndices),ft(l,t.silhouettes?.normalPairs),ft(l,t.polylines?.indices),ft(l,t.polylines?.prevIndices),ft(l,t.polylines?.nextIndicesAndParams),ft(l,t.indexed?.indices),ft(l,t.indexed?.edges.data));break}}function Ud(l){const e=new Set,t=n=>{n&&e.add(n.buffer)};t(l.binaryData),t(l.featureTable.data),t(l.featureTable.animationNodeIds);for(const n of l.nodes)if(n.groupId!==void 0)for(const i of n.nodes)for(const s of i.primitives)Da(e,s);else for(const i of n.primitives)Da(e,i);for(const n of l.patterns.values())for(const i of n)Da(e,i);return Array.from(e)}var Ji;(function(l){l[l.Mesh=0]="Mesh",l[l.Polyline=1]="Polyline",l[l.Point=2]="Point"})(Ji||(Ji={}));var ki;(function(l){l[l.Unlit=0]="Unlit",l[l.Lit=1]="Lit",l[l.Textured=2]="Textured",l[l.TexturedLit=3]="TexturedLit",l[l.VolumeClassifier=4]="VolumeClassifier"})(ki||(ki={}));function Vd(l){switch(l){case ki.Unlit:case ki.Lit:case ki.Textured:case ki.TexturedLit:case ki.VolumeClassifier:return!0;default:return!1}}function qd(l){if(l!==void 0)return{isAtlas:!1,material:l}}function Zd(l,e){return Qt((t,n)=>t.compare(n),l,e)}function Wd(l,e){return Qt((t,n)=>t.compare(n),l,e)}class Oe{static minTransparency=15;type=Oe.Type.Mesh;material;gradient;_textureMapping;lineColor;fillColor;width;linePixels;fillFlags;ignoreLighting;constructor(e,t,n,i=0,s=gs.Solid,r=ei.None,a,o,c=!1,d){this.type=e,this.material=a,this.gradient=o,this.lineColor=Oe.adjustTransparency(t),this.fillColor=Oe.adjustTransparency(n),this.width=i,this.linePixels=s,this.fillFlags=r,this.ignoreLighting=c,this._textureMapping=d}static createForType(e,t,n,i=!1){const s=Oe.adjustTransparency(t.lineColor);switch(e){case Oe.Type.Mesh:{let r;if(t.gradient!==void 0&&n!==void 0){const a=n(t.gradient);a!==void 0&&(r=new wn(a,new wn.Params))}return new Oe(e,s,Oe.adjustTransparency(t.fillColor),t.rasterWidth,t.linePixels,t.fillFlags,t.material,t.gradient,i,r)}case Oe.Type.Linear:return new Oe(e,s,s,t.rasterWidth,t.linePixels);default:return new Oe(e,s,s,0,gs.Solid,ei.Always,void 0,void 0,!0)}}static createForMesh(e,t,n){return Oe.createForType(Oe.Type.Mesh,e,n,t)}static createForLinear(e){return Oe.createForType(Oe.Type.Linear,e)}static createForText(e){return Oe.createForType(Oe.Type.Text,e)}get regionEdgeType(){return this.hasBlankingFill?Oe.RegionEdgeType.None:this.gradient!==void 0&&this.gradient.flags!==void 0?(this.gradient.flags&Ti.Flags.Outline)!==0||ei.None===(this.fillFlags&ei.Always)?Oe.RegionEdgeType.Outline:Oe.RegionEdgeType.None:this.fillColor.equals(this.lineColor)?Oe.RegionEdgeType.Default:Oe.RegionEdgeType.Outline}get wantRegionOutline(){return Oe.RegionEdgeType.Outline===this.regionEdgeType}get hasBlankingFill(){return ei.Blanking===(this.fillFlags&ei.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(e,t=Oe.ComparePurpose.Strict){return Oe.ComparePurpose.Merge===t?this.compareForMerge(e)===0:e===this?!0:!(this.type!==e.type||this.ignoreLighting!==e.ignoreLighting||this.width!==e.width||this.linePixels!==e.linePixels||this.fillFlags!==e.fillFlags||this.wantRegionOutline!==e.wantRegionOutline||this.material!==e.material||this.textureMapping!==e.textureMapping||!this.fillColor.equals(e.fillColor)||!this.lineColor.equals(e.lineColor))}compareForMerge(e){if(e===this)return 0;let t=Pe(this.type,e.type);return t===0&&(t=Pt(this.ignoreLighting,e.ignoreLighting),t===0&&(t=Pe(this.width,e.width),t===0&&(t=Pe(this.linePixels,e.linePixels),t===0&&(t=Pe(this.fillFlags,e.fillFlags),t===0&&(t=Pt(this.wantRegionOutline,e.wantRegionOutline),t===0&&(t=Pt(this.hasFillTransparency,e.hasFillTransparency),t===0&&(t=Pt(this.hasLineTransparency,e.hasLineTransparency),t===0&&(t=Zd(this.material,e.material),t===0&&this.material===void 0&&this.isTextured&&(t=Wd(this.textureMapping,e.textureMapping)))))))))),t}static adjustTransparency(e){return e.colors.t<Oe.minTransparency?e.withTransparency(0):e}}(function(l){(function(e){e[e.Mesh=0]="Mesh",e[e.Linear=1]="Linear",e[e.Text=2]="Text"})(l.Type||(l.Type={})),(function(e){e[e.None=0]="None",e[e.Default=1]="Default",e[e.Outline=2]="Outline"})(l.RegionEdgeType||(l.RegionEdgeType={})),(function(e){e[e.Merge=0]="Merge",e[e.Strict=1]="Strict"})(l.ComparePurpose||(l.ComparePurpose={}))})(Oe||(Oe={}));function Na(l,e,t,n){const i=Math.ceil(l*e)+t;if(i<=n)return{width:i,height:1};let s=Math.ceil(Math.sqrt(i));const r=s%e;r!==0&&(s+=e-r);const a=Math.ceil(i/s);return{width:s,height:a}}class Oa{name;inputs;indices;constructor(e){this.name=e.name,this.inputs=e.inputs,this.indices=e.indices}toJSON(){return{name:this.name,inputs:this.inputs,indices:this.indices}}}class Gd extends Oa{qOrigin;qScale;constructor(e){super(e),this.qOrigin=Float32Array.from(e.qOrigin),this.qScale=Float32Array.from(e.qScale)}toJSON(){return{...super.toJSON(),qOrigin:Array.from(this.qOrigin),qScale:Array.from(this.qScale)}}}class Qd extends Oa{qOrigin;qScale;constructor(e){super(e),this.qOrigin=e.qOrigin[0],this.qScale=e.qScale[0]}toJSON(){return{...super.toJSON(),qOrigin:[this.qOrigin],qScale:[this.qScale]}}}class vr{data;width;height;numVertices;numBytesPerVertex;displacements;normals;params;constructor(e,t,n,i){this.data=e.data,this.width=e.width,this.height=e.height,this.numVertices=e.count,this.numBytesPerVertex=e.numBytesPerVertex,this.displacements=t,this.normals=n,this.params=i}static fromJSON(e){let t,n,i;if(e.displacements!==void 0&&0<e.displacements.length){t=[];for(const s of e.displacements)t.push(new Gd(s))}if(e.normals!==void 0&&0<e.normals.length){n=[];for(const s of e.normals)n.push(new Oa(s))}if(e.params!==void 0&&0<e.params.length){i=[];for(const s of e.params)i.push(new Qd(s))}return t!==void 0||n!==void 0||i!==void 0?new vr(e,t,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(e=>e.toJSON()),normals:this.normals?.map(e=>e.toJSON()),params:this.params?.map(e=>e.toJSON())}}static fromChannels(e,t,n){return Xa.buildAuxChannelTable(e,t,n)}}function ec(l){return l!==0&&(l=1/l),l}class Xa{_view;_props;_numBytesPerVertex;constructor(e,t){this._props=e,this._numBytesPerVertex=t,this._view=new DataView(e.data.buffer)}static buildAuxChannelTable(e,t,n){const i=e.reduce((h,u)=>h+tc(u),0);if(!i)return;const s=Math.floor((i+3)/4),r=s*4-i;let a;r!==0?a=Na(Math.floor((t+1)/2),i/2,0,n):a=Na(t,s,0,n);const c={data:new Uint8Array(a.width*a.height*4),width:a.width,height:a.height,count:t,numBytesPerVertex:i};return new Xa(c,i).build(e),vr.fromJSON(c)}build(e){let t=0;for(const n of e)Nt.Normal===n.dataType?this.addNormals(n,t):Nt.Vector===n.dataType?this.addDisplacements(n,t):this.addParams(n,t),t+=tc(n)}addNormals(e,t){const n=[],i=[],s=new v;for(let a=0;a<e.data.length;a++){let o=t+a*2;i.push(o/2);const c=e.data[a];n.push(c.input);for(let d=0;d<c.values.length;d+=3){s.x=c.values[d],s.y=c.values[d+1],s.z=c.values[d+2],s.normalizeInPlace();const h=_r.encode(s);this._view.setUint16(o,h,!0),o+=this._numBytesPerVertex}}(this._props.normals??(this._props.normals=[])).push({name:e.name??"",inputs:n,indices:i})}addParams(e,t){const n=[],i=[],s=fe.createNull();for(const o of e.data)n.push(o.input),s.extendArray(o.values);const r=xe.computeScale(s.high-s.low);for(let o=0;o<e.data.length;o++){let c=t+o*2;i.push(c/2);for(const d of e.data[o].values){const h=xe.quantize(d,s.low,r);this._view.setUint16(c,h,!0),c+=this._numBytesPerVertex}}(this._props.params??(this._props.params=[])).push({inputs:n,indices:i,name:e.name??"",qOrigin:[s.low],qScale:[ec(r)]})}addDisplacements(e,t){const n=[],i=[],s=new y,r=ie.createNull();for(const d of e.data){n.push(d.input);for(let h=0;h<d.values.length;h+=3)s.set(d.values[h],d.values[h+1],d.values[h+2]),r.extend(s)}const a=ti.fromRange(r),o=new Ei;for(let d=0;d<e.data.length;d++){let h=t+d*6;i.push(h/2);const u=e.data[d];for(let g=0;g<u.values.length;g+=3)s.set(u.values[g],u.values[g+1],u.values[g+2]),o.init(s,a),this._view.setUint16(h+0,o.x,!0),this._view.setUint16(h+2,o.y,!0),this._view.setUint16(h+4,o.z,!0),h+=this._numBytesPerVertex}(this._props.displacements??(this._props.displacements=[])).push({inputs:n,indices:i,name:e.name??"",qOrigin:a.origin.toArray(),qScale:a.scale.toArray().map(d=>ec(d))})}}function tc(l){const e=l.data.length;switch(l.dataType){case Nt.Vector:return 6*e;case Nt.Normal:case Nt.Distance:case Nt.Scalar:return 2*e}}class Ft{data;constructor(e){this.data=e,this.data.length%3}get length(){return this.data.length/3}static fromArray(e){const t=new Uint8Array(e.length*3);for(let n=0;n<e.length;n++)this.encodeIndex(e[n],t,n*3);return new Ft(t)}static encodeIndex(e,t,n){n+2<t.length,t[n+0]=e&255,t[n+1]=(e&65280)>>8,t[n+2]=(e&16711680)>>16}setNthIndex(e,t){Ft.encodeIndex(t,this.data,e*3)}decodeIndex(e){e<this.length;const t=e*3;return this.data[t]|this.data[t+1]<<8|this.data[t+2]<<16}decodeIndices(){const e=[];for(let t=0;t<this.length;t++)e.push(this.decodeIndex(t));return e}[Symbol.iterator](){function*e(t){for(let n=0;n<t.length;n++)yield t.decodeIndex(n)}return e(this)}}function nc(l,e,t){let n=Math.ceil(1.5*l+2.5*e);const i=l*6;let s=0,r=n,a=1;if(n>=t){r=Math.ceil(Math.sqrt(n));const o=r%15;o!==0&&(r+=15-o),e>0&&l>0&&(s=(60-i%60)%10,n+=Math.ceil(s/4)),a=Math.ceil(n/r),r*a<n&&a++}return{width:r,height:a,silhouettePadding:s,silhouetteStartByteIndex:i}}class Hi{_builder;_index32=new Uint32Array(1);_index8=new Uint8Array(this._index32.buffer,0,3);constructor(e=3){this._builder=new Or({initialCapacity:e*3})}get numIndices(){return this._builder.length%3,this._builder.length/3}push(e){this._index32[0]=e,this._builder.append(this._index8)}toVertexIndices(){return new Ft(this._builder.toTypedArray())}}class Jd{_builder;_source;constructor(e){this._source=e,this._builder=new Ni({initialCapacity:3*e.numRgbaPerVertex})}get length(){return this._builder.length%this.vertexSize,this._builder.length/this.vertexSize}get vertexSize(){return this._source.numRgbaPerVertex}push(e){e.length,this.vertexSize,this._builder.append(e)}buildVertexTable(e,t,n){const i=this._source;t=t??i.uniformColor;const s=t instanceof Uint32Array?t.length:0,r=n instanceof Uint32Array?n.length:0,a=Na(this.length,this.vertexSize,s+r,e);let o=this._builder.toTypedArray();if(a.width*a.height>o.length){const d=o;o=new Uint32Array(a.width*a.height),o.set(d,0)}let c=this.vertexSize*this.length;return t instanceof Uint32Array&&(o.set(t,c),c+=t.length),n instanceof Uint32Array&&o.set(n,c),{data:new Uint8Array(o.buffer,o.byteOffset,o.byteLength),usesUnquantizedPositions:i.usesUnquantizedPositions,qparams:i.qparams,width:a.width,height:a.height,hasTranslucency:i.hasTranslucency,uniformColor:t instanceof he?t:void 0,featureIndexType:i.featureIndexType,uniformFeatureID:i.uniformFeatureID,numVertices:this.length,numRgbaPerVertex:i.numRgbaPerVertex,uvParams:i.uvParams}}}class Hd{_remappedIndices=new Map;_colorTable;colors=[];_32=new Uint32Array(1);_16=new Uint16Array(this._32.buffer);constructor(e){this._colorTable=e}remap(e,t){const n=t?4:1,i=t?0:1;this._32[0]=e[n];const s=this._16[i];let r=this._remappedIndices.get(s);if(r===void 0){r=this.colors.length,this._remappedIndices.set(s,r);const a=this._colorTable[s];this.colors.push(a)}this._16[i]=r,e[n]=this._32[0]}buildColorTable(){return this.colors.length>0,this.colors.length>1?new Uint32Array(this.colors):he.fromAbgr(this.colors[0])}}class Kd{_remappedIndices=new Map;_atlasTable;_createMaterial;materials=[];_32=new Uint32Array(1);_8=new Uint8Array(this._32.buffer);constructor(e,t){this._atlasTable=e,this._createMaterial=t}remap(e,t){const n=t?3:2;this._32[0]=e[n];const i=this._8[3];let s=this._remappedIndices.get(i);if(s===void 0){s=this.materials.length/4,this._remappedIndices.set(i,s);let r=i*4;this.materials.push(this._atlasTable[r++]),this.materials.push(this._atlasTable[r++]),this.materials.push(this._atlasTable[r++]),this.materials.push(this._atlasTable[r])}this._8[3]=s,e[n]=this._32[0]}unpackFloat(e){this._32[0]=e;const t=this._32[0],n=38,i=(t>>>24)/2;let s=Math.floor(i),r=(i-s)*2;r=-(r*2-1);const a=r*(t&16777215)/16777216;return s=s-n,a*Math.pow(10,s)}materialFromAtlasEntry(e){const t=(e[1]&16777216)!==0,i={alpha:(e[1]&33554432)!==0?(e[0]>>>24)/255:void 0,diffuse:{color:t?he.fromTbgr(e[0]&16777215):void 0,weight:(e[1]>>>8&255)/255},specular:{color:he.fromTbgr(e[2]),weight:(e[1]>>>16&255)/255,exponent:this.unpackFloat(e[3])}},s=this._createMaterial(i);return qd(s)}buildAtlasTable(){this.materials.length>0;const e=new Uint32Array(this.materials);return this.materials.length>4?e:this.materialFromAtlasEntry(e)}}class jd{vertices;remappedIndices=new Map;indices=new Hi;colors;atlas;usesUnquantizedPositions;constructor(e,t){if(this.vertices=new Jd(e),e.uniformColor===void 0&&(this.colors=new Hd(new Uint32Array(e.data.buffer,e.data.byteOffset+4*e.numVertices*e.numRgbaPerVertex))),t){const n=(e.numVertices*e.numRgbaPerVertex+t.offset)*4;this.atlas=new Kd(new Uint32Array(e.data.buffer,e.data.byteOffset+n),t.createMaterial)}this.usesUnquantizedPositions=e.usesUnquantizedPositions}addVertex(e,t){let n=this.remappedIndices.get(e);n===void 0&&(n=this.vertices.length,this.remappedIndices.set(e,n),this.colors?.remap(t,this.usesUnquantizedPositions),this.atlas?.remap(t,this.usesUnquantizedPositions),this.vertices.push(t)),this.indices.push(n)}buildOutput(e,t){const n=this.atlas?.buildAtlasTable();let i;if(n instanceof Uint32Array){const s=this.colors?.colors.length!==void 0&&this.colors?.colors.length>1?this.colors?.colors.length:0;i={isAtlas:!0,hasTranslucency:(t?.isAtlas&&t?.hasTranslucency)??!1,overridesAlpha:(t?.isAtlas&&t?.overridesAlpha)??!1,vertexTableOffset:s,numMaterials:n.length/4}}else i=n;return{indices:this.indices.toVertexIndices(),vertices:this.vertices.buildVertexTable(e,this.colors?.buildColorTable(),n),material:i}}}class _s{_input;_computeNodeId;_nodes=new Map;constructor(e,t){this._input=e,this._computeNodeId=t}static split(e,t){const n=new _s(e,t);return n.split(),n._nodes}split(){const e={featureIndex:-1,node:void 0},t=this._input.vertices.numRgbaPerVertex,n=new Uint32Array(t),i=new Uint32Array(this._input.vertices.data.buffer,this._input.vertices.data.byteOffset,this._input.vertices.numVertices*t);let s;if(this._input.vertices.usesUnquantizedPositions){const r=new Uint8Array(n.buffer);s=()=>r[3]|r[7]<<8|r[11]<<16}else s=()=>n[2]&16777215;for(const r of this._input.indices){const a=r*t;for(let c=0;c<n.length;c++)n[c]=i[a+c];const o=s();if(e.featureIndex!==o){e.featureIndex=o;const c=this._computeNodeId(o);let d=this._nodes.get(c);d===void 0&&this._nodes.set(c,d=new jd(this._input.vertices,this._input.atlasInfo)),e.node=d}e.node.addVertex(r,n)}}}function $d(l){const e=_s.split({indices:l.params.indices,vertices:l.params.vertices,featureTable:l.featureTable},l.computeNodeId),t=new Map;for(const[n,i]of e){const{vertices:s,indices:r}=i.buildOutput(l.maxDimension);t.set(n,{vertices:s,indices:r,weight:l.params.weight})}return t}class el{indices=new Hi;prevIndices=new Hi;nextIndicesAndParams=new Ni}function Sr(l,e,t){for(const[n,i]of t){const s=i.remappedIndices.get(e);if(s!==void 0)return l.index=s,l.node=i,l.id=n,!0}return!1}function ic(l,e,t,n){const i=e[l];if(!i)return;const s=new Uint32Array(i.endPointAndQuadIndices.buffer,i.endPointAndQuadIndices.byteOffset,i.endPointAndQuadIndices.length/4);let r;l==="silhouettes"&&(e.silhouettes,r=new Uint32Array(e.silhouettes.normalPairs.buffer,e.silhouettes.normalPairs.byteOffset,e.silhouettes.normalPairs.length/4));let a=0;const o={};for(const c of i.indices){if(Sr(o,c,t)){let d=s[a];const h=(d&16777215)>>>0,u=o.node.remappedIndices.get(h);d=d&4278190080|u;let g=n.get(o.id);g||n.set(o.id,g={}),r?(g.silhouettes||(g.silhouettes={indices:new Hi,endPointAndQuadIndices:new Ni,normalPairs:new Ni}),g.silhouettes.normalPairs.push(r[a])):g.segments||(g.segments={indices:new Hi,endPointAndQuadIndices:new Ni});const m=g[l];m.indices.push(o.index),m.endPointAndQuadIndices.push(d)}++a}}function tl(l,e,t){const n=new Uint32Array(l.nextIndicesAndParams.buffer,l.nextIndicesAndParams.byteOffset,l.nextIndicesAndParams.length/4),i=l.prevIndices[Symbol.iterator]();let s=0;const r={};for(const a of l.indices){if(Sr(r,a,e)){const o=i.next().value,c=r.node.remappedIndices.get(o);let d=n[s];const h=(d&16777215)>>>0,u=r.node.remappedIndices.get(h);d=d&4278190080|u;let g=t.get(r.id);g||t.set(r.id,g={}),g.polylines||(g.polylines=new el),g.polylines.indices.push(r.index),g.polylines.prevIndices.push(c),g.polylines.nextIndicesAndParams.push(d)}++s}}function nl(l,e,t){const n=l.edges.data,i=l.edges.numSegments,s=i*6+l.edges.silhouettePadding;function r(x){return[n[x+0]|n[x+1]<<8|n[x+2]<<16,n[x+3]|n[x+4]<<8|n[x+5]<<16]}function a(x,_,I){x.edges.push(_&255),x.edges.push((_&65280)>>>8),x.edges.push((_&16711680)>>>16),x.edges.push(I&255),x.edges.push((I&65280)>>>8),x.edges.push((I&16711680)>>>16)}function o(x){return[n[x+0]|n[x+1]<<8|n[x+2]<<16,n[x+3]|n[x+4]<<8|n[x+5]<<16,n[x+6]|n[x+7]<<8,n[x+8]|n[x+9]<<8]}function c(x,_,I,S,A){x.silhouettes.push(_&255),x.silhouettes.push((_&65280)>>>8),x.silhouettes.push((_&16711680)>>>16),x.silhouettes.push(I&255),x.silhouettes.push((I&65280)>>>8),x.silhouettes.push((I&16711680)>>>16),x.silhouettes.push(S&255),x.silhouettes.push((S&65280)>>>8),x.silhouettes.push(A&255),x.silhouettes.push((A&65280)>>>8)}let d=0;for(const x of l.indices)d=Math.max(x,d);const h={};let u=0,g=0,m=0,p=0;for(let x=0,_=0;x<=d;++x)if(x<i?([u,g]=r(_),_+=6):(_=s+(x-i)*10,[u,g,m,p]=o(_)),Sr(h,u,e)){let I=t.get(h.id);if(I||t.set(h.id,I={}),I.indexed||(I.indexed={edges:new Or,silhouettes:new Or}),x<i){const S=h.node.remappedIndices.get(u),A=h.node.remappedIndices.get(g);a(I.indexed,S,A)}else{const S=h.node.remappedIndices.get(u),A=h.node.remappedIndices.get(g);c(I.indexed,S,A,m,p)}}}function il(l,e,t){const n=new Map;ic("segments",l,e,n),ic("silhouettes",l,e,n),l.polylineGroups?.length===1&&tl(l.polylineGroups[0].polyline,e,n),l.indexed&&nl(l.indexed,e,n);const i=new Map;for(const[s,r]of n){if(!r.segments&&!r.silhouettes&&!r.indexed)continue;let a={},o={};if(r.indexed){const c=r.indexed.edges.length/6,d=r.indexed.silhouettes.length/10,{width:h,height:u,silhouettePadding:g,silhouetteStartByteIndex:m}=nc(c,d,t),p=new Uint8Array(h*u*4);p.set(r.indexed.edges.toTypedArray(),0),d>0&&p.set(r.indexed.silhouettes.toTypedArray(),m+g);const x=c+d;o=new Ft(new Uint8Array(x*6*3));for(let _=0;_<x;_++)for(let I=0;I<6;I++)o.setNthIndex(_*6+I,_);a={data:p,width:h,height:u,numSegments:c,silhouettePadding:g}}i.set(s,{weight:l.weight,linePixels:l.linePixels,segments:r.segments?{indices:r.segments.indices.toVertexIndices(),endPointAndQuadIndices:r.segments.endPointAndQuadIndices.toUint8Array()}:void 0,silhouettes:r.silhouettes?{indices:r.silhouettes.indices.toVertexIndices(),endPointAndQuadIndices:r.silhouettes.endPointAndQuadIndices.toUint8Array(),normalPairs:r.silhouettes.normalPairs.toUint8Array()}:void 0,polylineGroups:r.polylines?[{polyline:{indices:r.polylines.indices.toVertexIndices(),prevIndices:r.polylines.prevIndices.toVertexIndices(),nextIndicesAndParams:r.polylines.nextIndicesAndParams.toUint8Array()}}]:void 0,indexed:r.indexed?{indices:o,edges:a}:void 0})}return i}function sl(l){const e=new Map,t=l.params.surface.material,n=t!==void 0&&t.isAtlas?t.vertexTableOffset:void 0,i=n!==void 0?{offset:n,createMaterial:l.createMaterial}:void 0,s=_s.split({indices:l.params.surface.indices,vertices:l.params.vertices,featureTable:l.featureTable,atlasInfo:i},l.computeNodeId),r=l.params.edges?il(l.params.edges,s,l.maxDimension):void 0;for(const[a,o]of s){const{vertices:c,indices:d,material:h}=o.buildOutput(l.maxDimension,l.params.surface.material),u={vertices:c,surface:{type:l.params.surface.type,indices:d,fillFlags:l.params.surface.fillFlags,hasBakedLighting:l.params.surface.hasBakedLighting,textureMapping:l.params.surface.textureMapping,material:h!==void 0?h:l.params.surface.material},edges:r?.get(a),isPlanar:l.params.isPlanar,auxChannels:l.params.auxChannels};e.set(a,u)}return e}function rl(l){const e=_s.split({indices:l.params.polyline.indices,vertices:l.params.vertices,featureTable:l.featureTable},l.computeNodeId),t=l.params.polyline,n=new Uint32Array(t.nextIndicesAndParams.buffer,t.nextIndicesAndParams.byteOffset,t.nextIndicesAndParams.length/4);let i=0;const s={};for(const a of t.prevIndices){if(Sr(s,a,e)){const o=s.node;o.prevIndices?(o.nextIndicesAndParams,void 0):(o.nextIndicesAndParams,o.prevIndices=new Hi(o.indices.numIndices),o.nextIndicesAndParams=new Ni({initialCapacity:o.indices.numIndices})),o.prevIndices.push(s.index);let c=n[i];const d=(c&16777215)>>>0,h=s.node.remappedIndices.get(d);c=c&4278190080|h,o.nextIndicesAndParams.push(c)}++i}const r=new Map;for(const[a,o]of e){o.prevIndices!==void 0&&o.nextIndicesAndParams;const{vertices:c,indices:d}=o.buildOutput(l.maxDimension),h={...l.params,vertices:c,polyline:{indices:d,prevIndices:o.prevIndices.toVertexIndices(),nextIndicesAndParams:o.nextIndicesAndParams.toUint8Array()}};r.set(a,h)}return r}var Ar;(function(l){l[l.Untransformed=4294967295]="Untransformed"})(Ar||(Ar={}));var ys;(function(l){l[l.Hidden=0]="Hidden",l[l.Silhouette=1]="Silhouette",l[l.Visible=2]="Visible",l[l.VisibleDuplicate=3]="VisibleDuplicate"})(ys||(ys={}));function*al(l,e,t,n){let i=0,s=0,r=0;const a={index0:0,index1:1};for(let o=0;o<t;o++){const c=l[s]>>i&3;i+=2,i===8&&(i=0,s++),!(ys.Hidden===c||ys.VisibleDuplicate===c)&&(a.index0=n(o),a.index1=n(o%3===2?o-2:o+1),ys.Silhouette===c?a.normals=e[r++]:a.normals=void 0,yield a)}}function wr(l,e,t){l[e+0]=t&255,l[e+1]=(t&65280)>>>8,l[e+2]=(t&16711680)>>>16}function ol(l){const e=l.normalPairs?.length??0,t=l.numVisibleEdges+e;if(t<=0)return;const n=new Ft(new Uint8Array(t*6*3));for(let h=0;h<t;h++)for(let u=0;u<6;u++)n.setNthIndex(h*6+u,h);const{width:i,height:s,silhouettePadding:r,silhouetteStartByteIndex:a}=nc(l.numVisibleEdges,e,l.maxEdgeTableDimension),o=new Uint8Array(i*s*4);let c=0,d=0;for(const h of al(l.visibility,l.normalPairs,l.vertexIndices.length,u=>l.vertexIndices.decodeIndex(u)))if(h.normals===void 0){const g=c++*6;wr(o,g,h.index0),wr(o,g+3,h.index1)}else{const u=d++,g=a+r+u*10;wr(o,g,h.index0),wr(o,g+3,h.index1),o[g+6]=h.normals&255,o[g+7]=(h.normals&65280)>>>8,o[g+8]=(h.normals&16711680)>>>16,o[g+9]=(h.normals&4278190080)>>>24}return{indices:n.data,edges:{data:o,width:i,height:s,numSegments:l.numVisibleEdges,silhouettePadding:r}}}var br;(function(l){l.Package="core-frontend",l.IModelConnection="core-frontend.IModelConnection",l.NativeApp="core-frontend.NativeApp",l.Request="core-frontend.Request",l.FeatureTracking="core-frontend.FeatureTracking",l.RealityData="core-frontend.RealityData",l.Render="core-frontend.Render",l.Extensions="core-frontend.Extensions"})(br||(br={}));async function cl(){const l="b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq;d8Yqdbk:yzeHu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhlaicefhodnadTmbalc;WFbGglcjdalcjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfglcl4cifcd4hxdndndndnalc9WGgmTmbcbhPcehsawcjdfhzaohHinaraH9Rax6midnaraHaxfgo9RcK6mbczhlcbhOinalgic9WfgAawcj;cbffhldndndndndnaHaAco4fRbbaOcoG4ciGPlbedibkal9cb83ibalcwf9cb83ibxikalaoRblaoRbbgAco4gCaCciSgCE86bbawcj;cbfaifglcGfaoclfaCfgCRbbaAcl4ciGgXaXciSgXE86bbalcVfaCaXfgCRbbaAcd4ciGgXaXciSgXE86bbalc7faCaXfgCRbbaAciGgAaAciSgAE86bbalctfaCaAfgCRbbaoRbegAco4gXaXciSgXE86bbalc91faCaXfgCRbbaAcl4ciGgXaXciSgXE86bbalc4faCaXfgCRbbaAcd4ciGgXaXciSgXE86bbalc93faCaXfgCRbbaAciGgAaAciSgAE86bbalc94faCaAfgCRbbaoRbdgAco4gXaXciSgXE86bbalc95faCaXfgCRbbaAcl4ciGgXaXciSgXE86bbalc96faCaXfgCRbbaAcd4ciGgXaXciSgXE86bbalc97faCaXfgCRbbaAciGgAaAciSgAE86bbalc98faCaAfgARbbaoRbigoco4gCaCciSgCE86bbalc99faAaCfgARbbaocl4ciGgCaCciSgCE86bbalc9:faAaCfgARbbaocd4ciGgCaCciSgCE86bbalcufaAaCfglRbbaociGgoaociSgoE86bbalaofhoxdkalaoRbwaoRbbgAcl4gCaCcsSgCE86bbawcj;cbfaifglcGfaocwfaCfgCRbbaAcsGgAaAcsSgAE86bbalcVfaCaAfgARbbaoRbegCcl4gXaXcsSgXE86bbalc7faAaXfgARbbaCcsGgCaCcsSgCE86bbalctfaAaCfgARbbaoRbdgCcl4gXaXcsSgXE86bbalc91faAaXfgARbbaCcsGgCaCcsSgCE86bbalc4faAaCfgARbbaoRbigCcl4gXaXcsSgXE86bbalc93faAaXfgARbbaCcsGgCaCcsSgCE86bbalc94faAaCfgARbbaoRblgCcl4gXaXcsSgXE86bbalc95faAaXfgARbbaCcsGgCaCcsSgCE86bbalc96faAaCfgARbbaoRbvgCcl4gXaXcsSgXE86bbalc97faAaXfgARbbaCcsGgCaCcsSgCE86bbalc98faAaCfgARbbaoRbogCcl4gXaXcsSgXE86bbalc99faAaXfgARbbaCcsGgCaCcsSgCE86bbalc9:faAaCfgARbbaoRbrgocl4gCaCcsSgCE86bbalcufaAaCfglRbbaocsGgoaocsSgoE86bbalaofhoxekalao8Pbb83bbalcwfaocwf8Pbb83bbaoczfhokdnaiam9pmbaOcdfhOaiczfhlarao9RcL0mekkaiam6miaoTmidnakTmbawaPfRbbhOawcj;cbfhlazhiakhAinaialRbbgHce4cbaHceG9R7aOfgO86bbaiadfhialcefhlaAcufgAmbkkazcefhzaPcefgPad6hsaohHaPad9hmexvkkcbhoasceGmdxikaoaxad2fhXdnakTmbcbhmcehsawcjdfhCinarao9Rax6miaoTmdaoaxfhoawamfRbbhOawcj;cbfhlaChiakhAinaialRbbgHce4cbaHceG9R7aOfgO86bbaiadfhialcefhlaAcufgAmbkaCcefhCamcefgmad6hsamad9hmbkaXhoxikcbhlcehsinarao9Rax6mdaoTmeaoaxfhoalcefglad6hsadal9hmbkaXhoxdkcbhoasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqaombkc9:hoxekcbc99arao9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;xzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfalaDcu7gPcl4fcsGcitfgsydlhzasydbhHdnaDcsGgDak9pmbavaiaPfcsGcdtfydbaxaDEhsaDThDdndnadcd9hmbabarcetfgPaH87ebaPcdfaz87ebaPclfas87ebxekabarcdtfgPaHBdbaPclfazBdbaPcwfasBdbkaxaDfhxavc;abfalcitfgPasBdbaPazBdlavaicdtfasBdbavc;abfalcefcsGglcitfgPaHBdbaPasBdlaiaDfhialcefhlxdkdndnaDcsSmbamaDfaDc987fcefhmxekaocefhDao8SbbgscFeGhPdndnascu9mmbaDhoxekaocvfhoaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhokaPce4cbaPceG9R7amfhmkdndnadcd9hmbabarcetfgDaH87ebaDcdfaz87ebaDclfam87ebxekabarcdtfgDaHBdbaDclfazBdbaDcwfamBdbkavc;abfalcitfgDamBdbaDazBdlavaicdtfamBdbavc;abfalcefcsGglcitfgDaHBdbaDamBdlaicefhialcefhlxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHcdfaD87ebaHclfas87ebxekabarcdtfgHaxBdbaHclfaDBdbaHcwfasBdbkavaicdtfaxBdbavc;abfalcitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfalcefcsGcitfgHasBdbaHaDBdlavaiaPfcsGgicdtfasBdbavc;abfalcdfcsGglcitfgDaxBdbaDasBdlalcefhlaiaOfhiazaOfhxxekaxcbaoRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbaocefhDxekaocdfhDao8SbegPcFeGhsdnaPcu9kmbaocofhAascFbGhscrhodninaD8SbbgPcFbGaotasVhsaPcu9kmeaDcefhDaocrfgoc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbgocFeGhPdnaocu9kmbaDcvfhzaPcFbGhPcrhodninas8SbbgDcFbGaotaPVhPaDcu9kmeascefhsaocrfgoc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashoxekascefhoas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninao8SbbgscFbGaDtaPVhPascu9kmeaocefhoaDcrfgDc8J9hmbkaOhoxekaocefhokaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDcdfaz87ebaDclfaO87ebxekabarcdtfgDaABdbaDclfazBdbaDcwfaOBdbkavc;abfalcitfgDazBdbaDaABdlavaicdtfaABdbavc;abfalcefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfalcdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiarcifgrae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:flevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabaiavcefciGfcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabaiavcdfciGfcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabaiavcufciGfcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabaiavciGfcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2gdTmbinababydbgecwtcw91:Yaece91cjjj98Gcjjj;8if::NUdbabclfhbadcufgdmbkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb",e="b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;b9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;e8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincbhHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAcd0hHalhOaAcefgAclSmdxekkcbhlaHceGTmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblbg8Acep9Ta8AaQp9op9Hp9rg8ApmbzeHdOiAlCvXoQrLgEaoamfpblbg3cep9Ta3aQp9op9Hp9rg3aoaxfpblbg5cep9Ta5aQp9op9Hp9rg5pmbzeHdOiAlCvXoQrLg8EpmbezHdiOAlvCXorQLgQaQpmbedibedibedibediaYp9UgYp9AdbbaiadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaEa8EpmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwKDYq8AkEx3m5P8Es8FgLa3a5pmwKDYq8AkEx3m5P8Es8Fg8ApmbezHdiOAlvCXorQLgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfhiaXczfgXak6mbkkazclfgzad6mbkasavcjdfaqad2;8qbbavavcjdfaqcufad2fad;8qbbaqaDfhDc9:hoalmexikkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;kbf8Kjjjjbaokwbz:bjjjbk;tzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfalaDcu7gPcl4fcsGcitfgsydlhzasydbhHdnaDcsGgDak9pmbavaiaPfcsGcdtfydbaxaDEhsaDThDdndnadcd9hmbabarcetfgPaH87ebaPcdfaz87ebaPclfas87ebxekabarcdtfgPaHBdbaPclfazBdbaPcwfasBdbkaxaDfhxavc;abfalcitfgPasBdbaPazBdlavaicdtfasBdbavc;abfalcefcsGglcitfgPaHBdbaPasBdlaiaDfhialcefhlxdkdndnaDcsSmbamaDfaDc987fcefhmxekaocefhDao8SbbgscFeGhPdndnascu9mmbaDhoxekaocvfhoaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhokaPce4cbaPceG9R7amfhmkdndnadcd9hmbabarcetfgDaH87ebaDcdfaz87ebaDclfam87ebxekabarcdtfgDaHBdbaDclfazBdbaDcwfamBdbkavc;abfalcitfgDamBdbaDazBdlavaicdtfamBdbavc;abfalcefcsGglcitfgDaHBdbaDamBdlaicefhialcefhlxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHcdfaD87ebaHclfas87ebxekabarcdtfgHaxBdbaHclfaDBdbaHcwfasBdbkavaicdtfaxBdbavc;abfalcitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfalcefcsGcitfgHasBdbaHaDBdlavaiaPfcsGgicdtfasBdbavc;abfalcdfcsGglcitfgDaxBdbaDasBdlalcefhlaiaOfhiazaOfhxxekaxcbaoRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbaocefhDxekaocdfhDao8SbegPcFeGhsdnaPcu9kmbaocofhAascFbGhscrhodninaD8SbbgPcFbGaotasVhsaPcu9kmeaDcefhDaocrfgoc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbgocFeGhPdnaocu9kmbaDcvfhzaPcFbGhPcrhodninas8SbbgDcFbGaotaPVhPaDcu9kmeascefhsaocrfgoc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashoxekascefhoas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninao8SbbgscFbGaDtaPVhPascu9kmeaocefhoaDcrfgDc8J9hmbkaOhoxekaocefhokaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDcdfaz87ebaDclfaO87ebxekabarcdtfgDaABdbaDclfazBdbaDcwfaOBdbkavc;abfalcitfgDazBdbaDaABdlavaicdtfaABdbavc;abfalcefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfalcdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiarcifgrae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:flevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:wPliuo97eue978Jjjjjbca9Rhiaec98Ghldndnadcl9hmbdnalTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaipxbbbbbbbbbbbbbbbbgqpklbaiabalcdtfgdaeciGglcdtgv;8qbbdnalTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDaqp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkadaiav;8qbbskdnalTmbcbhvabhdinadczfgxaxpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgval6mbkkalae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabalcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbheabhdinadadpbbbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepkbbadczfhdaeclfgeav6mbkkdnaval9pmbaialciGgecdtgdVcbc;abad9R;8kbaiabavcdtfgvad;8qbbdnaeTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepklbkavaiad;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb",t=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),n=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if(typeof WebAssembly!="object"){ue.logError(br.Render,"WebAssembly is not supported in this environment");return}const i=WebAssembly.validate(t)?r(e):r(l);let s;try{s=(await WebAssembly.instantiate(i,{})).instance,s.exports.__wasm_call_ctors()}catch(d){ue.logError(br.Render,d);return}function r(d){const h=new Uint8Array(d.length);for(let g=0;g<d.length;++g){const m=d.charCodeAt(g);h[g]=m>96?m-97:m>64?m-39:m+4}let u=0;for(let g=0;g<d.length;++g)h[u++]=h[g]<60?n[h[g]]:(h[g]-60)*64+h[++g];return h.buffer.slice(0,u)}function a(d,h,u,g,m,p){const x=s.exports[d],_=s.exports.sbrk,I=u+3&-4,S=_(I*g),A=_(m.length),w=new Uint8Array(s.exports.memory.buffer);w.set(m,A);const k=x(S,u,g,A,m.length);if(k===0&&p&&p(S,I,g),h.set(w.subarray(S,S+u*g)),_(S-_(0)),k!==0)throw new Error(`Malformed buffer data: ${k}`)}const o={ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"},c={NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"};return{decodeVertexBuffer(d,h,u,g,m){a(o.ATTRIBUTES,d,h,u,g,m?s.exports[c[m]]:void 0)},decodeIndexBuffer(d,h,u,g){a(o.TRIANGLES,d,h,u,g)},decodeIndexSequence(d,h,u,g){a(o.INDICES,d,h,u,g)},decodeGltfBuffer(d,h,u,g,m,p){a(o[m],d,h,u,g,p?s.exports[c[p]]:void 0)}}}let sc=!1,rc;async function dl(){return sc||(rc=await cl(),sc=!0),rc}const ll=/Node_(.*)/;function hl(l){const e=l.match(ll);if(e&&e.length,!e||e.length!==2)return 0;const t=Number.parseInt(e[1],10);return Number.isNaN(t)?0:t}class Tr extends mn{constructor(e){super(e)}dispose(){}get bytesUsed(){return 0}}class ac extends Tr{_name;constructor(e,t){super(t),this._name=e}toImdl(){return this._name}}class oc extends Tr{_gradient;constructor(e){super(mn.Type.Normal),this._gradient=e}toImdl(){return this._gradient}}class Fi extends Rd{materialParams;toImdl(){return{isAtlas:!1,material:this.key??this.materialParams}}constructor(e,t){super(e),this.materialParams=t??{alpha:e.alpha,diffuse:{color:e.diffuseColor?.toJSON(),weight:e.diffuse},specular:{color:e.specularColor?.toJSON(),weight:e.specular,exponent:e.specularExponent}}}static create(e){const t=new Qi;return t.alpha=e.alpha,e.diffuse&&(e.diffuse.weight!==void 0&&(t.diffuse=e.diffuse?.weight),e.diffuse?.color&&(t.diffuseColor=e.diffuse.color instanceof he?e.diffuse.color:Lt.fromJSON(e.diffuse.color).toColorDef())),e.specular&&(e.specular.weight!==void 0&&(t.specular=e.specular.weight),e.specular.exponent!==void 0&&(t.specularExponent=e.specular.exponent),e.specular.color&&(t.specularColor=e.specular.color instanceof he?e.specular.color:Lt.fromJSON(e.specular.color).toColorDef())),new Fi(t)}}function La(l){return{...l,uniformColor:l.uniformColor!==void 0?he.fromJSON(l.uniformColor):void 0,qparams:ti.fromJSON(l.qparams),uvParams:l.uvParams?fi.fromJSON(l.uvParams):void 0}}function Ya(l){return{...l,uniformColor:l.uniformColor?.toJSON(),qparams:l.qparams.toJSON(),uvParams:l.uvParams?.toJSON()}}function ul(l){return{...l,segments:l.segments?{...l.segments,indices:new Ft(l.segments.indices)}:void 0,silhouettes:l.silhouettes?{...l.silhouettes,indices:new Ft(l.silhouettes.indices)}:void 0,polylineGroups:l.polylines?[{polyline:{...l.polylines,indices:new Ft(l.polylines.indices),prevIndices:new Ft(l.polylines.prevIndices)}}]:void 0,indexed:l.indexed?{indices:new Ft(l.indexed.indices),edges:l.indexed.edges}:void 0}}function fl(l){return{...l,segments:l.segments?{...l.segments,indices:l.segments.indices.data}:void 0,silhouettes:l.silhouettes?{...l.silhouettes,indices:l.silhouettes.indices.data}:void 0,polylines:l.polylineGroups?.length===1?{...l.polylineGroups[0].polyline,indices:l.polylineGroups[0].polyline.indices.data,prevIndices:l.polylineGroups[0].polyline.prevIndices.data}:void 0,indexed:l.indexed?{indices:l.indexed.indices.data,edges:l.indexed.edges}:void 0}}class gl{_document;_binaryData;_options;_featureTableInfo;_patterns=new Map;_stream;_timeline;_meshoptDecoder;constructor(e,t,n,i,s){this._document=e,this._binaryData=t,this._options=n,this._featureTableInfo=i,this._stream=s,this._timeline=n.timeline}async parse(){const e=this.parseFeatureTable();if(!e)return bn.InvalidFeatureTable;if(this.hasMeshoptCompression()&&(this._meshoptDecoder=await dl(),!this._meshoptDecoder))return bn.InvalidTileData;const t=this._document.rtcCenter?{x:this._document.rtcCenter[0]??0,y:this._document.rtcCenter[1]??0,z:this._document.rtcCenter[2]??0}:void 0,n=this.parseNodes(e),i=this.groupPrimitiveNodes(n,e);return{featureTable:e,nodes:i,rtcCenter:t,binaryData:this._binaryData,json:this._document,patterns:this._patterns}}hasMeshoptCompression(){let e=!1;for(const t of Object.keys(this._document.meshes))this._document.meshes[t]?.primitives?.forEach(i=>{if(i.type!=="areaPattern"){const s=i,r=s.vertices;r.compressedSize&&r.compressedSize>0&&(e=!0);const a=s.surface;a&&a.compressedIndexCount&&a.compressedIndexCount>0&&(e=!0)}});return e}parseFeatureTable(){this._stream.curPos=this._featureTableInfo.startPos;const e=xs.readFrom(this._stream);if(!e||e.length%4!==0)return;const t=(e.length-xs.sizeInBytes)/4,n=new Uint32Array(this._stream.nextUint32s(t));if(this._stream.isPastTheEnd)return;let i;if(this._featureTableInfo.multiModel)i={multiModel:!0,data:n,numFeatures:e.count,numSubCategories:e.numSubCategories};else{let s;const r=this._document.animationNodes;if(r!==void 0){const a=K.asInt(r.bytesPerId),o=K.asString(r.bufferView),c=this._document.bufferViews[o];if(c!==void 0){const d=K.asInt(c.byteOffset),h=K.asInt(c.byteLength),u=this._binaryData.subarray(d,d+h);switch(a){case 1:s=new Uint8Array(u);break;case 2:s=Uint16Array.from(new Uint16Array(u.buffer,u.byteOffset,u.byteLength/2));break;case 4:s=Uint32Array.from(new Uint32Array(u.buffer,u.byteOffset,u.byteLength/4));break}}}i={multiModel:!1,data:n,numFeatures:e.count,animationNodeIds:s}}return this._stream.curPos=this._featureTableInfo.startPos+e.length,i}parseNodes(e){const t=[],n=this._document.nodes,i=this._document.meshes;if(n.Node_Root===void 0)return t;for(const s of Object.keys(n)){const r=this._document.nodes[s],a=i[r],o=a?.primitives;if(!o)continue;const c=a.layer;s==="Node_Root"?this._timeline?this.parseAnimationBranches(t,a,e,this._timeline):this._options.createUntransformedRootNode?t.push({animationNodeId:Ar.Untransformed,primitives:this.parseNodePrimitives(o)}):t.push({primitives:this.parseNodePrimitives(o)}):c===void 0?t.push({animationNodeId:hl(s),animationId:`${this._options.batchModelId}_${s}`,primitives:this.parseNodePrimitives(o)}):t.push({layerId:c,primitives:this.parseNodePrimitives(o)})}return t}parseAnimationBranches(e,t,n,i){const s=t.primitives;if(!s)return;const r=s.map(u=>this.parseNodePrimitive(u)).filter(u=>u!==void 0);if(r.length===0)return;const a=new Map,o=u=>{u=u??Ar.Untransformed;let g=a.get(u);return g||(g={animationNodeId:u,animationId:`${this._options.batchModelId}_Node_${u}`,primitives:[]},a.set(u,g),e.push(g)),g};n.animationNodeIds;const c=cc(n,this._options.batchModelId);c.populateAnimationNodeIds(u=>i.getBatchIdForFeature(u),i.maxBatchId),n.animationNodeIds=c.animationNodeIds;const d=i.discreteBatchIds,h=u=>{const g=c.getAnimationNodeId(u);return g!==0&&d.has(g)?g:0};this.splitPrimitives(r,c,h,o)}splitPrimitives(e,t,n,i){const s={maxDimension:this._options.maxVertexTableSize,computeNodeId:n,featureTable:t},r=a=>{if(a){if(a.isAtlas)return a}else return;const o=typeof a.material=="string"?this.materialFromJson(a.material):Fi.create(ml(a.material));return o?{isAtlas:!1,material:o}:void 0};for(const a of e)switch(a.type){case"pattern":{i(void 0).primitives.push(a);break}case"mesh":{const o=a.params,c=o.surface.textureMapping,d={vertices:La(a.params.vertices),surface:{...a.params.surface,indices:new Ft(a.params.surface.indices),material:r(o.surface.material),textureMapping:c?{alwaysDisplayed:c.alwaysDisplayed,texture:typeof c.texture=="string"?new ac(c.texture,mn.Type.Normal):new oc(c.texture)}:void 0},edges:a.params.edges?ul(a.params.edges):void 0,isPlanar:a.params.isPlanar,auxChannels:a.params.auxChannels?vr.fromJSON(a.params.auxChannels):void 0},h=sl({...s,params:d,createMaterial:u=>Fi.create(u)});for(const[u,g]of h){let m;g.surface.material&&(g.surface.material.isAtlas?m=g.surface.material:(g.surface.material.material instanceof Fi,m=g.surface.material.material.toImdl())),g.surface.textureMapping===void 0||g.surface.textureMapping.texture instanceof Tr,i(u).primitives.push({type:"mesh",modifier:a.modifier,params:{vertices:Ya(g.vertices),surface:{...g.surface,indices:g.surface.indices.data,material:m,textureMapping:g.surface.textureMapping?.texture instanceof Tr?{texture:g.surface.textureMapping.texture.toImdl(),alwaysDisplayed:g.surface.textureMapping.alwaysDisplayed}:void 0},edges:g.edges?fl(g.edges):void 0,isPlanar:g.isPlanar,auxChannels:g.auxChannels?.toJSON()}})}break}case"point":{const o={vertices:La(a.params.vertices),indices:new Ft(a.params.indices),weight:a.params.weight},c=$d({...s,params:o});for(const[d,h]of c)i(d).primitives.push({type:"point",modifier:a.modifier,params:{vertices:Ya(h.vertices),indices:h.indices.data,weight:h.weight}});break}case"polyline":{const o={...a.params,vertices:La(a.params.vertices),polyline:{indices:new Ft(a.params.polyline.indices),prevIndices:new Ft(a.params.polyline.prevIndices),nextIndicesAndParams:a.params.polyline.nextIndicesAndParams}},c=rl({...s,params:o});for(const[d,h]of c)i(d).primitives.push({type:"polyline",modifier:a.modifier,params:{...h,vertices:Ya(h.vertices),polyline:{indices:h.polyline.indices.data,prevIndices:h.polyline.prevIndices.data,nextIndicesAndParams:h.polyline.nextIndicesAndParams},hasCumulativeDistances:h.hasCumulativeDistances}});break}}}groupPrimitiveNodes(e,t){const n=this._options.modelGroups;if(!n?.length)return e;const i=[];let s;const r=d=>{if(d<=n.length,d===n.length)return s??(s={groupId:d,nodes:[]});let h=i[d];return h||(i[d]=h={groupId:d,nodes:[]}),h},a=cc(t,this._options.batchModelId),o={lower:0,upper:0},c=d=>{a.getModelIdPair(d,o);const h=te.fromUint32PairObject(o);for(let u=0;u<n.length;u++)if(n[u].has(h))return u;return n.length};for(const d of e){const h=[],u=g=>{if(g=g??n.length,!h[g]){const m=h[g]={...d,primitives:[]};r(g).nodes.push(m)}return h[g]};this.splitPrimitives(d.primitives,a,c,u)}return i.filter(d=>d!==void 0)}parseTesselatedPolyline(e){const t=this.findBuffer(e.indices),n=this.findBuffer(e.prevIndices),i=this.findBuffer(e.nextIndicesAndParams);return t&&n&&i?{indices:t,prevIndices:n,nextIndicesAndParams:i}:void 0}parseSegmentEdges(e){const t=this.findBuffer(e.indices),n=this.findBuffer(e.endPointAndQuadIndices);return t&&n?{indices:t,endPointAndQuadIndices:n}:void 0}parseSilhouetteEdges(e){const t=this.parseSegmentEdges(e),n=this.findBuffer(e.normalPairs);return t&&n?{...t,normalPairs:n}:void 0}parseIndexedEdges(e){const t=this.findBuffer(e.indices),n=this.findBuffer(e.edges);if(!(!t||!n))return{indices:t,edges:{data:n,width:e.width,height:e.height,silhouettePadding:e.silhouettePadding,numSegments:e.numSegments}}}parseCompactEdges(e,t){const n=this.findBuffer(e.visibility);if(!n)return;const i=e.normalPairs!==void 0?this.findBuffer(e.normalPairs):void 0;return ol({numVisibleEdges:e.numVisible,visibility:n,vertexIndices:t,normalPairs:i?new Uint32Array(i.buffer,i.byteOffset,i.byteLength/4):void 0,maxEdgeTableDimension:this._options.maxVertexTableSize})}parseEdges(e,t,n){if(!e)return;const i=e.segments?this.parseSegmentEdges(e.segments):void 0,s=e.silhouettes?this.parseSilhouetteEdges(e.silhouettes):void 0,r=e.polylines?this.parseTesselatedPolyline(e.polylines):void 0;let a=e.indexed?this.parseIndexedEdges(e.indexed):void 0;if(!a&&e.compact&&(a=this.parseCompactEdges(e.compact,new Ft(n))),!(!i&&!s&&!a&&!r))return{segments:i,silhouettes:s,polylines:r,indexed:a,weight:t.width,linePixels:t.linePixels}}getPattern(e){let t=this._patterns.get(e);if(!t){const n=this._document.patternSymbols[e];t=n?this.parsePrimitives(n.primitives):[],this._patterns.set(e,t)}return t.length>0?t:void 0}parseAreaPattern(e){const t=this.getPattern(e.symbolName);if(!t||t.length===0)return;const n=this.findBuffer(e.xyOffsets);if(n)return{type:"pattern",params:{...e,xyOffsets:new Float32Array(n.buffer,n.byteOffset,n.byteLength/4)}}}parseNodePrimitives(e){const t=[];for(const n of e){const i=this.parseNodePrimitive(n);i&&t.push(i)}return t}parseNodePrimitive(e){return e.type==="areaPattern"?this.parseAreaPattern(e):this.parsePrimitive(e)}parsePrimitives(e){const t=[];for(const n of e){const i=this.parsePrimitive(n);i&&t.push(i)}return t}parsePrimitive(e){let t=this.parseInstances(e);if(!t&&e.viewIndependentOrigin){const c=y.fromJSON(e.viewIndependentOrigin);t={type:"viewIndependentOrigin",origin:{x:c.x,y:c.y,z:c.z}}}const n=e.material??"",i=n.length?K.asObject(this._document.materials[n]):void 0,s=i?this.parseDisplayParams(i):void 0;if(!s)return;const r=this.parseVertexTable(e);if(!r)return;let a;const o=!this._options.is3d||K.asBool(e.isPlanar);switch(e.type){case Ji.Mesh:{const c=this.parseSurface(e,s);c&&(a={type:"mesh",params:{vertices:r,surface:c,isPlanar:o,auxChannels:this.parseAuxChannelTable(e),edges:this.parseEdges(e.edges,s,c.indices)}});break}case Ji.Polyline:{const c=this.parseTesselatedPolyline(e);if(c){let d=ps.Normal;Oe.RegionEdgeType.Outline===s.regionEdgeType&&(d=!s.gradient||s.gradient.isOutlined?ps.Edge:ps.Outline),a={type:"polyline",params:{vertices:r,polyline:c,isPlanar:o,type:d,weight:s.width,linePixels:s.linePixels,hasCumulativeDistances:!1}}}break}case Ji.Point:{const c=this.findBuffer(e.indices),d=s.width;c&&(a={type:"point",params:{vertices:r,indices:c,weight:d}});break}}return a&&(a.modifier=t),a}parseSurface(e,t){const n=e.surface;if(!n)return;let i=this.findBuffer(n.indices);if(!i)return;if(n.compressedIndexCount&&n.compressedIndexCount>0){if(!this._meshoptDecoder)return;const h=new Uint8Array(n.compressedIndexCount*4);this._meshoptDecoder.decodeIndexSequence(h,n.compressedIndexCount,4,i),i=new Uint8Array(n.compressedIndexCount*3);for(let u=0;u<n.compressedIndexCount;u++){const g=u*4,m=u*3;i[m+0]=h[g+0],i[m+1]=h[g+1],i[m+2]=h[g+2]}}const s=n.type;if(!Vd(s))return;const r=t.textureMapping?.texture;let a;const o=e.vertices.materialAtlas,c=e.vertices.numColors;o&&c!==void 0?a={isAtlas:!0,hasTranslucency:K.asBool(o.hasTranslucency),overridesAlpha:K.asBool(o.overridesAlpha,!1),vertexTableOffset:K.asInt(c),numMaterials:K.asInt(o.numMaterials)}:t.material&&(t.material instanceof Fi,a=t.material.toImdl());let d;return r&&(d={texture:r.toImdl(),alwaysDisplayed:K.asBool(n.alwaysDisplayTexture)}),{type:s,indices:i,fillFlags:t.fillFlags,hasBakedLighting:!1,material:a,textureMapping:d}}parseAuxChannelTable(e){const t=e.auxChannels;if(t===void 0)return;const n=this.findBuffer(K.asString(t.bufferView));if(n!==void 0)return{data:n,width:t.width,height:t.height,count:t.count,numBytesPerVertex:t.numBytesPerVertex,displacements:t.displacements,normals:t.normals,params:t.params}}parseVertexTable(e){const t=e.vertices;if(!t)return;let n;if(t.compressedSize&&t.compressedSize>0){if(!this._meshoptDecoder)return;const d=this._document.bufferViews[K.asString(t.bufferView)];if(d===void 0)return;const h=K.asInt(d.byteOffset),u=K.asInt(d.byteLength);if(u===0)return;const g=this._binaryData.subarray(h,h+t.compressedSize);if(!g)return;n=new Uint8Array(t.width*t.height*4),this._meshoptDecoder.decodeVertexBuffer(n,t.count,t.numRgbaPerVertex*4,g);const m=u-t.compressedSize;if(m>0){const p=this._binaryData.subarray(h+t.compressedSize,h+u);if(!p)return;const x=t.count*t.numRgbaPerVertex*4;for(let _=0;_<m;_++)n[x+_]=p[_]}}else if(n=this.findBuffer(K.asString(t.bufferView)),!n)return;const i=t.featureID!==void 0?K.asInt(t.featureID):void 0,s=K.asArray(t.params.decodedMin),r=K.asArray(t.params.decodedMax);if(s===void 0||r===void 0)return;const a=ti.fromRange(ie.create(y.create(s[0],s[1],s[2]),y.create(r[0],r[1],r[2]))),o=t.uniformColor!==void 0?he.fromJSON(t.uniformColor):void 0;let c;if(Ji.Mesh===e.type&&e.surface&&e.surface.uvParams){const d=e.surface.uvParams.decodedMin,h=e.surface.uvParams.decodedMax,u=new ze(d[0],d[1],h[0],h[1]);c=fi.fromRange(u)}return{data:n,usesUnquantizedPositions:t.usesUnquantizedPositions===!0,qparams:a.toJSON(),width:t.width,height:t.height,hasTranslucency:t.hasTranslucency,uniformColor:o?.toJSON(),featureIndexType:t.featureIndexType,uniformFeatureID:i,numVertices:t.count,numRgbaPerVertex:t.numRgbaPerVertex,uvParams:c?.toJSON()}}parseInstances(e){const t=e.instances;if(!t)return;const n=K.asInt(t.count,0);if(n<=0)return;const i=K.asArray(t.transformCenter);if(i===void 0||i.length!==3)return;const s=y.create(i[0],i[1],i[2]),r=this.findBuffer(K.asString(t.featureIds));if(r===void 0)return;const a=this.findBuffer(K.asString(t.transforms));if(a===void 0)return;const o=a.byteLength/4,c=new Float32Array(a.buffer,a.byteOffset,o);let d;return t.symbologyOverrides!==void 0&&(d=this.findBuffer(K.asString(t.symbologyOverrides))),{type:"instances",count:n,transforms:c,transformCenter:s,featureIds:r,symbologyOverrides:d}}findBuffer(e){if(typeof e!="string"||e.length===0)return;const t=this._document.bufferViews[e];if(t===void 0)return;const n=K.asInt(t.byteOffset),i=K.asInt(t.byteLength);if(i!==0)return this._binaryData.subarray(n,n+i)}colorDefFromMaterialJson(e){return e!==void 0?he.from(e[0]*255+.5,e[1]*255+.5,e[2]*255+.5):void 0}materialFromJson(e){const t=this._document.renderMaterials[e];if(!t)return;const n=new Qi(e);return n.diffuseColor=this.colorDefFromMaterialJson(t.diffuseColor),t.diffuse!==void 0&&(n.diffuse=K.asDouble(t.diffuse)),n.specularColor=this.colorDefFromMaterialJson(t.specularColor),t.specular!==void 0&&(n.specular=K.asDouble(t.specular)),n.reflectColor=this.colorDefFromMaterialJson(t.reflectColor),t.reflect!==void 0&&(n.reflect=K.asDouble(t.reflect)),t.specularExponent!==void 0&&(n.specularExponent=t.specularExponent),t.transparency!==void 0&&(n.alpha=1-t.transparency),n.refract=K.asDouble(t.refract),n.shadows=K.asBool(t.shadows),n.ambient=K.asDouble(t.ambient),t.textureMapping!==void 0&&(n.textureMapping=this.textureMappingFromJson(t.textureMapping.texture)),new Fi(n)}parseNamedTexture(e,t){const n=K.asBool(e.isGlyph)?mn.Type.Glyph:K.asBool(e.isTileSection)?mn.Type.TileSection:mn.Type.Normal;return new ac(t,n)}parseConstantLodProps(e){if(e!==void 0)return{repetitions:K.asDouble(e.repetitions,1),offset:{x:e.offset?K.asDouble(e.offset[0]):0,y:e.offset?K.asDouble(e.offset[1]):0},minDistClamp:K.asDouble(e.minDistClamp,1),maxDistClamp:K.asDouble(e.maxDistClamp,4096*1024*1024)}}textureMappingFromJson(e){if(!e)return;const t=K.asString(e.name),n=t.length!==0?this._document.namedTextures[t]:void 0,i=n?this.parseNamedTexture(n,t):void 0;if(!i)return;const s=e.params,r=s.transform,a={textureMat2x3:new wn.Trans2x3(r[0][0],r[0][1],r[0][2],r[1][0],r[1][1],r[1][2]),textureWeight:K.asDouble(s.weight,1),mapMode:K.asInt(s.mode),worldMapping:K.asBool(s.worldMapping),useConstantLod:K.asBool(s.useConstantLod),constantLodProps:this.parseConstantLodProps(s.constantLodParams)},o=new wn(i,new wn.Params(a)),c=e.normalMapParams;if(c){const d=K.asString(c.textureName),h=d.length>0?this._document.namedTextures[d]:void 0,u=h?this.parseNamedTexture(h,d):void 0;u&&(o.normalMapParams={normalMap:u,greenUp:K.asBool(c.greenUp),scale:K.asDouble(c.scale,1),useConstantLod:K.asBool(c.useConstantLod)})}return o}parseDisplayParams(e){const t=K.asInt(e.type,Oe.Type.Mesh),n=he.create(K.asInt(e.lineColor)),i=he.create(K.asInt(e.fillColor)),s=K.asInt(e.lineWidth),r=K.asInt(e.linePixels,gs.Solid),a=K.asInt(e.fillFlags,ei.None),o=K.asBool(e.ignoreLighting),c=e.materialId,d=c!==void 0?this.materialFromJson(c):void 0;let h,u;if(!d){const g=e.texture;if(h=g!==void 0?this.textureMappingFromJson(g):void 0,h===void 0){const m=e.gradient;if(u=m!==void 0?Ti.Symb.fromJSON(m):void 0,u){const p=new oc(m);h=new wn(p,new wn.Params({textureMat2x3:new wn.Trans2x3(0,1,0,1,0,0)}))}}}return new Oe(t,n,i,s,r,a,d,u,o,h)}}function ml(l){const e={alpha:l.alpha};return l.diffuse&&(e.diffuse={weight:l.diffuse.weight,color:l.diffuse.color!==void 0?he.fromJSON(l.diffuse.color):void 0}),l.specular&&(e.specular={weight:l.specular.weight,exponent:l.specular.exponent,color:l.specular.color!==void 0?he.fromJSON(l.specular.color):void 0}),e}function cc(l,e){const t=l.multiModel?Ta.create(l.data,e,l.numFeatures,gn.Primary,l.numSubCategories):new ms(l.data,e,l.numFeatures,gn.Primary);return t.animationNodeIds=l.animationNodeIds,t}async function pl(l){const e=ws.fromUint8Array(l.data),t=new zd(e);if(t.isValid){if(!t.isReadableVersion)return bn.NewerMajorVersion}else return bn.InvalidHeader;const n=e.curPos,i=xs.readFrom(e);if(!i)return bn.InvalidFeatureTable;e.curPos=n+i.length;const s=new Yd(e);if(!s.isValid)return bn.InvalidTileData;e.curPos=s.scenePosition;const r=e.nextBytes(s.sceneStrLength),a=Ic(r);if(!a)return bn.InvalidScene;try{const o=JSON.parse(a),c={scene:K.asString(o.scene),scenes:K.asArray(o.scenes),animationNodes:K.asObject(o.animationNodes),bufferViews:K.asObject(o.bufferViews)??{},meshes:K.asObject(o.meshes),nodes:K.asObject(o.nodes)??{},materials:K.asObject(o.materials)??{},renderMaterials:K.asObject(o.renderMaterials)??{},namedTextures:K.asObject(o.namedTextures)??{},patternSymbols:K.asObject(o.patternSymbols)??{},rtcCenter:K.asArray(o.rtcCenter)};if(!c.meshes)return bn.InvalidTileData;const d=new Uint8Array(e.arrayBuffer,s.binaryPosition),h={startPos:n,multiModel:(t.flags&Ra.MultiModelFeatureTable)!==0};return await new gl(c,d,l,h,e).parse()}catch{return bn.InvalidTileData}}function xl(l){onmessage=async e=>{const t=e.data,n=t.msgId;try{typeof t=="object"&&"operation"in t&&"payload"in t&&"msgId"in t;const i=l[t.operation];let s=i(t.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 dc;xl({parse:async l=>{const e=await pl({...l,data:l.data,timeline:dc});return typeof e=="number"?e:{result:e,transfer:Ud(e)}},setTimeline:l=>{dc=Array.isArray(l)?Pr.Script.fromJSON(l):Pr.ModelTimeline.fromJSON(l)}})})();
|