@mountaya/studio 0.0.0-stage → 0.2.0
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 +69 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2600 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1237 -0
- package/dist/agent/index.d.ts +1237 -0
- package/dist/agent/index.js +2581 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-3Oi_Zrtm.js +9 -0
- package/dist/chunk-3Oi_Zrtm.js.map +1 -0
- package/dist/chunk-B18OPIu_.js +6 -0
- package/dist/chunk-B18OPIu_.js.map +1 -0
- package/dist/chunk-B5Uz3Qct.cjs +15 -0
- package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
- package/dist/chunk-BBEJwkd3.d.cts +839 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BKMFOe-N.js +171 -0
- package/dist/chunk-BKMFOe-N.js.map +1 -0
- package/dist/chunk-BP4uy7E1.d.ts +11583 -0
- package/dist/chunk-BSHTsFiB.js +1403 -0
- package/dist/chunk-BSHTsFiB.js.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BaPiaz5X.cjs +115 -0
- package/dist/chunk-BaPiaz5X.cjs.map +1 -0
- package/dist/chunk-BeCVpkYr.cjs +542 -0
- package/dist/chunk-BeCVpkYr.cjs.map +1 -0
- package/dist/chunk-BgngsvK8.cjs +6202 -0
- package/dist/chunk-BgngsvK8.cjs.map +1 -0
- package/dist/chunk-BhInd7CJ.d.cts +253 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-By9ZnkVI.js +60 -0
- package/dist/chunk-By9ZnkVI.js.map +1 -0
- package/dist/chunk-BzqPhxsz.cjs +367 -0
- package/dist/chunk-BzqPhxsz.cjs.map +1 -0
- package/dist/chunk-C2mMX81q.d.ts +443 -0
- package/dist/chunk-C2rr9Q0V.cjs +1402 -0
- package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
- package/dist/chunk-CDJCbwIQ.d.cts +78 -0
- package/dist/chunk-CLGvBOVH.d.cts +1654 -0
- package/dist/chunk-COdw1dc6.d.ts +525 -0
- package/dist/chunk-CQCJnT2i.d.ts +511 -0
- package/dist/chunk-CSyHY67q.cjs +353 -0
- package/dist/chunk-CSyHY67q.cjs.map +1 -0
- package/dist/chunk-CiK1Iqrv.js +950 -0
- package/dist/chunk-CiK1Iqrv.js.map +1 -0
- package/dist/chunk-CmJBgSwZ.cjs +24 -0
- package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
- package/dist/chunk-CnrsRK2u.cjs +83 -0
- package/dist/chunk-CnrsRK2u.cjs.map +1 -0
- package/dist/chunk-Co782_9r.js +326 -0
- package/dist/chunk-Co782_9r.js.map +1 -0
- package/dist/chunk-Csr3KDpZ.cjs +32 -0
- package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
- package/dist/chunk-CwkmccXv.js +89 -0
- package/dist/chunk-CwkmccXv.js.map +1 -0
- package/dist/chunk-D0Q4iL9B.cjs +255 -0
- package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
- package/dist/chunk-DFwiSzUS.cjs +72 -0
- package/dist/chunk-DFwiSzUS.cjs.map +1 -0
- package/dist/chunk-DIFayl2P.d.cts +443 -0
- package/dist/chunk-DIGF58ux.d.cts +525 -0
- package/dist/chunk-DKuuuld5.js +101 -0
- package/dist/chunk-DKuuuld5.js.map +1 -0
- package/dist/chunk-DMePkFEo.js +5054 -0
- package/dist/chunk-DMePkFEo.js.map +1 -0
- package/dist/chunk-DO5SIBgu.js +305 -0
- package/dist/chunk-DO5SIBgu.js.map +1 -0
- package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
- package/dist/chunk-DThaaNeb.d.cts +15 -0
- package/dist/chunk-DThaaNeb.d.ts +15 -0
- package/dist/chunk-DUQzjUJy.d.ts +78 -0
- package/dist/chunk-DX37IPhV.cjs +1903 -0
- package/dist/chunk-DX37IPhV.cjs.map +1 -0
- package/dist/chunk-Damps5Tk.cjs +155 -0
- package/dist/chunk-Damps5Tk.cjs.map +1 -0
- package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
- package/dist/chunk-De0vAASv.d.ts +253 -0
- package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
- package/dist/chunk-DjEvqvPA.cjs +43 -0
- package/dist/chunk-DjEvqvPA.cjs.map +1 -0
- package/dist/chunk-DkwDzwvu.d.cts +121 -0
- package/dist/chunk-DkwDzwvu.d.ts +121 -0
- package/dist/chunk-Dmszv9If.js +71 -0
- package/dist/chunk-Dmszv9If.js.map +1 -0
- package/dist/chunk-Dp_ftNWY.d.cts +511 -0
- package/dist/chunk-DsHQySz0.js +31 -0
- package/dist/chunk-DsHQySz0.js.map +1 -0
- package/dist/chunk-DwoUyHHh.js +281 -0
- package/dist/chunk-DwoUyHHh.js.map +1 -0
- package/dist/chunk-IaIDQflj.d.cts +2315 -0
- package/dist/chunk-IaIDQflj.d.ts +2315 -0
- package/dist/chunk-cVXLsZfL.d.ts +839 -0
- package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
- package/dist/chunk-nJQxbOwQ.cjs +8962 -0
- package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
- package/dist/chunk-o9jaxhCO.js +8852 -0
- package/dist/chunk-o9jaxhCO.js.map +1 -0
- package/dist/chunk-p-Tt_Lwz.js +14 -0
- package/dist/chunk-p-Tt_Lwz.js.map +1 -0
- package/dist/engines/index.cjs +2091 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2176 -0
- package/dist/engines/index.d.ts +2176 -0
- package/dist/engines/index.js +2075 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +53 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +403 -0
- package/dist/handlers/index.d.ts +403 -0
- package/dist/handlers/index.js +33 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +3511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3033 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +510 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +296 -0
- package/dist/plugins/index.d.ts +296 -0
- package/dist/plugins/index.js +489 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/seams/index.cjs +89 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +452 -0
- package/dist/seams/index.d.ts +452 -0
- package/dist/seams/index.js +49 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/strings/fr/index.cjs +2135 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +17 -0
- package/dist/strings/fr/index.d.ts +17 -0
- package/dist/strings/fr/index.js +2130 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2384 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +3 -0
- package/dist/strings/index.d.ts +3 -0
- package/dist/strings/index.js +2353 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/testing/index.cjs +230 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +246 -0
- package/dist/testing/index.d.ts +246 -0
- package/dist/testing/index.js +219 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +41 -0
- package/dist/time/index.d.ts +41 -0
- package/dist/time/index.js +23 -0
- package/dist/time/index.js.map +1 -0
- package/package.json +224 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +29 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +451 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +857 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +24 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +804 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +575 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +89 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +215 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +270 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1065 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1050 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +202 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +211 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +199 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
import type { Polygon, Position } from "geojson";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
import type { LngLat } from "@mountaya/elements/camera";
|
|
5
|
+
import { EARTH_RADIUS_METERS, LATITUDE_LIMIT, LONGITUDE_LIMIT } from "@mountaya/elements/geo";
|
|
6
|
+
import { DEGREES_PER_TURN, DEGREES_TO_RADIANS, RADIANS_TO_DEGREES } from "@mountaya/elements/units";
|
|
7
|
+
|
|
8
|
+
// The sphere the parametric zone builders project a metric offset onto, and the angle factors
|
|
9
|
+
// they turn a bearing with, are imported rather than declared: a radius declared here with a
|
|
10
|
+
// comment saying it "matches the value the elevation profile geodesy uses" is an import's job
|
|
11
|
+
// done by a sentence, across a package boundary, with nothing to fail if one of them were
|
|
12
|
+
// improved.
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* CIRCLE_SEGMENTS_DEFAULT is how many straight edges approximate a full circle
|
|
16
|
+
* when the caller gives no count. 64 keeps a city-to-region radius visually round
|
|
17
|
+
* without an oversized coordinate ring; the cap bounds a caller-supplied value.
|
|
18
|
+
*/
|
|
19
|
+
const CIRCLE_SEGMENTS_DEFAULT = 64;
|
|
20
|
+
const CIRCLE_SEGMENTS_MIN = 8;
|
|
21
|
+
const CIRCLE_SEGMENTS_MAX = 512;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ARC_POINTS_DEFAULT is how many points sample a sector/sensor arc when the
|
|
25
|
+
* caller gives no count. 32 traces a smooth arc across a typical bearing span; the
|
|
26
|
+
* cap bounds a caller-supplied value. It counts the points ALONG the arc (the
|
|
27
|
+
* sweep is sampled at arcPoints positions inclusive of both bearings).
|
|
28
|
+
*/
|
|
29
|
+
const ARC_POINTS_DEFAULT = 32;
|
|
30
|
+
const ARC_POINTS_MIN = 2;
|
|
31
|
+
const ARC_POINTS_MAX = 512;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* RING_POSITIONS_MIN is the fewest positions a polygon's ring holds: three corners and the first
|
|
35
|
+
* one again, which closes it (RFC 7946, section 3.1.6).
|
|
36
|
+
*/
|
|
37
|
+
const RING_POSITIONS_MIN = 4;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* OUTLINE_CLEARANCE_DEGREES is the least two parts of a built outline stand apart, on the plane
|
|
41
|
+
* of longitude and latitude a zone is stored on: a hundred-thousandth of a degree, about a meter
|
|
42
|
+
* on the ground.
|
|
43
|
+
*
|
|
44
|
+
* A zone's outline may not cross itself, retrace itself or repeat a position, and the API refuses
|
|
45
|
+
* one that does when the zone is saved. So the builders keep every part of a ring this far from
|
|
46
|
+
* every other: positions nearer than this are one position, a sweep whose two ends come this
|
|
47
|
+
* near each other is the whole turn, and a shape thinner than this encloses nothing a zone is
|
|
48
|
+
* stored as.
|
|
49
|
+
*
|
|
50
|
+
* The bound is set by the two readers a built outline goes through. An outline is drawn and
|
|
51
|
+
* saved at nine decimals of a degree, so two positions nearer than a billionth of one are one
|
|
52
|
+
* position by then. And the zone editor opens a circle, a sector or a sensor only if TerraDraw
|
|
53
|
+
* judges that its ring does not cross itself, which TerraDraw works out from the lines through
|
|
54
|
+
* its edges, written in whole degrees: under about a meter of edge the rounding of that
|
|
55
|
+
* arithmetic outweighs the edge, and a ring that crosses nothing is refused as one that does. At
|
|
56
|
+
* this clearance every shape a schema takes is one both readers take.
|
|
57
|
+
*/
|
|
58
|
+
const OUTLINE_CLEARANCE_DEGREES = 1e-5;
|
|
59
|
+
|
|
60
|
+
/** planarSpan is how far two positions stand apart on the plane, in degrees. */
|
|
61
|
+
const planarSpan = (first: LngLat, second: LngLat): number =>
|
|
62
|
+
Math.hypot(second[0] - first[0], second[1] - first[1]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* offEdge is how far a position stands from the edge between `start` and `end`, on the plane and
|
|
66
|
+
* in degrees: from the nearest point of the edge, one of its ends where the position lies past
|
|
67
|
+
* it.
|
|
68
|
+
*/
|
|
69
|
+
const offEdge = (position: LngLat, start: LngLat, end: LngLat): number => {
|
|
70
|
+
const along = [end[0] - start[0], end[1] - start[1]] as const;
|
|
71
|
+
const length = along[0] ** 2 + along[1] ** 2;
|
|
72
|
+
if (length === 0) {
|
|
73
|
+
return planarSpan(position, start);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const reached = Math.min(
|
|
77
|
+
1,
|
|
78
|
+
Math.max(
|
|
79
|
+
0,
|
|
80
|
+
((position[0] - start[0]) * along[0] + (position[1] - start[1]) * along[1]) / length,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return planarSpan(position, [start[0] + reached * along[0], start[1] + reached * along[1]]);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* isPosition reports whether a value is a GeoJSON position: a longitude and a latitude at least,
|
|
89
|
+
* every member a finite number.
|
|
90
|
+
*/
|
|
91
|
+
const isPosition = (value: unknown): value is Position =>
|
|
92
|
+
Array.isArray(value) &&
|
|
93
|
+
value.length >= 2 &&
|
|
94
|
+
value.every((member) => typeof member === "number" && Number.isFinite(member));
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* isPolygonGeometry reports whether a value is a GeoJSON Polygon a zone can be drawn from: its
|
|
98
|
+
* `type` says so, and it holds at least one ring, every ring a list of four positions or more.
|
|
99
|
+
*
|
|
100
|
+
* It is the check a zone's geometry passes where it enters the studio from outside its own
|
|
101
|
+
* types: a tool's input, which an agent may write by hand, and an isochrone the Data API
|
|
102
|
+
* answers. It reads the shape and no more. Whether a ring closes on its first position, winds
|
|
103
|
+
* the right way or crosses itself is the API's to refuse, which holds the geometry it stores.
|
|
104
|
+
*/
|
|
105
|
+
export const isPolygonGeometry = (value: unknown): value is Polygon => {
|
|
106
|
+
if (typeof value !== "object" || value === null) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!("type" in value) || value.type !== "Polygon" || !("coordinates" in value)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const rings = value.coordinates;
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
Array.isArray(rings) &&
|
|
118
|
+
rings.length > 0 &&
|
|
119
|
+
rings.every(
|
|
120
|
+
(ring) => Array.isArray(ring) && ring.length >= RING_POSITIONS_MIN && ring.every(isPosition),
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* POLYGON_GEOMETRY_REFUSAL is what a refused zone geometry answers: the shape
|
|
127
|
+
* {@link isPolygonGeometry} holds a value to, and the closing position the API asks of a ring
|
|
128
|
+
* beyond it.
|
|
129
|
+
*/
|
|
130
|
+
const POLYGON_GEOMETRY_REFUSAL =
|
|
131
|
+
"a zone geometry is a GeoJSON Polygon whose `coordinates` hold at least one ring, each ring " +
|
|
132
|
+
"four or more [longitude, latitude] positions, the last repeating the first";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* polygonGeometrySchema is the GeoJSON geometry a zone carries: a Polygon, which every zone mode
|
|
136
|
+
* draws (circle, polygon, sector, sensor, freehand).
|
|
137
|
+
*
|
|
138
|
+
* It holds the value to {@link isPolygonGeometry}: the kind, at least one ring, and four
|
|
139
|
+
* positions of finite numbers or more in every ring. A geometry reaches a zone tool from a draw
|
|
140
|
+
* engine and from a caller's own hand alike, an agent's among them, so the shape is read here
|
|
141
|
+
* and a Polygon with no coordinates never arms a draw or reaches a request. A refusal reads
|
|
142
|
+
* {@link POLYGON_GEOMETRY_REFUSAL}.
|
|
143
|
+
*/
|
|
144
|
+
export const polygonGeometrySchema = z.custom<Polygon>(isPolygonGeometry, {
|
|
145
|
+
error: POLYGON_GEOMETRY_REFUSAL,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* wrapZoneGeometryPastRange answers a zone's Polygon inside -180 and 180 where it lies whole
|
|
150
|
+
* past that range, and as it is written otherwise.
|
|
151
|
+
*
|
|
152
|
+
* A zone astride the antimeridian is one ring whose longitudes run past 180, or below -180
|
|
153
|
+
* ({@link zoneCircleGeometry}), and an editor answers a ring on whichever copy of the world its
|
|
154
|
+
* reader dragged it over. A ring from 170 to 175 dragged fourteen degrees east is answered from
|
|
155
|
+
* 184 to 189: no longitude of it is inside the range, and the same place is written from -176 to
|
|
156
|
+
* -171. So a Polygon whose every longitude is above 180 loses whole turns, and one whose every
|
|
157
|
+
* longitude is below -180 gains them, as many as bring its nearest edge inside the range and the
|
|
158
|
+
* same number for every position of every ring.
|
|
159
|
+
*
|
|
160
|
+
* A Polygon that straddles the antimeridian keeps the side its builder or its edit gave it, and
|
|
161
|
+
* so does one that touches the line: neither lies whole past the range, and moved by a turn it
|
|
162
|
+
* would straddle the other end. It is answered by identity, as is a Polygon inside the range,
|
|
163
|
+
* one that holds no position and one that holds a longitude that is no finite number.
|
|
164
|
+
*
|
|
165
|
+
* It is read where the studio takes an editor's answer: {@link recordZoneDraftChange} for a
|
|
166
|
+
* draft the map reports, and `studio.zone.editCommit` for the shape it saves.
|
|
167
|
+
*
|
|
168
|
+
* @param geometry The Polygon as an editor answers it, its longitudes continuous.
|
|
169
|
+
* @returns The same shape with every longitude moved by the same whole number of turns, or
|
|
170
|
+
* `geometry` itself where nothing moves. Latitudes and any member past the second are kept.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { wrapZoneGeometryPastRange } from "@mountaya/studio";
|
|
175
|
+
*
|
|
176
|
+
* // A zone dragged east across the antimeridian is answered on the copy it was dragged over.
|
|
177
|
+
* const recorded = wrapZoneGeometryPastRange({
|
|
178
|
+
* coordinates: [
|
|
179
|
+
* [
|
|
180
|
+
* [184, -17],
|
|
181
|
+
* [189, -17],
|
|
182
|
+
* [189, -16],
|
|
183
|
+
* [184, -17],
|
|
184
|
+
* ],
|
|
185
|
+
* ],
|
|
186
|
+
* type: "Polygon",
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* recorded.coordinates[0]; // [[-176, -17], [-171, -17], [-171, -16], [-176, -17]]
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export const wrapZoneGeometryPastRange = (geometry: Polygon): Polygon => {
|
|
193
|
+
let west = Number.POSITIVE_INFINITY;
|
|
194
|
+
let east = Number.NEGATIVE_INFINITY;
|
|
195
|
+
for (const ring of geometry.coordinates) {
|
|
196
|
+
for (const [longitude = Number.NaN] of ring) {
|
|
197
|
+
if (!Number.isFinite(longitude)) {
|
|
198
|
+
return geometry;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
west = Math.min(west, longitude);
|
|
202
|
+
east = Math.max(east, longitude);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// No position at all leaves west above east, and both comparisons below false.
|
|
207
|
+
let turns = 0;
|
|
208
|
+
if (west > LONGITUDE_LIMIT && west <= east) {
|
|
209
|
+
turns = -Math.ceil((west - LONGITUDE_LIMIT) / DEGREES_PER_TURN);
|
|
210
|
+
} else if (east < -LONGITUDE_LIMIT && west <= east) {
|
|
211
|
+
turns = Math.ceil((-LONGITUDE_LIMIT - east) / DEGREES_PER_TURN);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (turns === 0) {
|
|
215
|
+
return geometry;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const shift = turns * DEGREES_PER_TURN;
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
...geometry,
|
|
222
|
+
coordinates: geometry.coordinates.map((ring) =>
|
|
223
|
+
ring.map(([longitude = 0, ...rest]) => [longitude + shift, ...rest]),
|
|
224
|
+
),
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* lngLatSchema is a [lng, lat] center point for a parametric builder, bounded to
|
|
230
|
+
* the valid WGS84 range so an out-of-range coordinate is rejected at the boundary
|
|
231
|
+
* the same way the terrain samplers bound their point.
|
|
232
|
+
*/
|
|
233
|
+
const lngLatSchema = z.tuple([z.number().min(-180).max(180), z.number().min(-90).max(90)]);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* LngLat is the package's `[lng, lat]` pair, re-exported beside the schema that BOUNDS one.
|
|
237
|
+
*
|
|
238
|
+
* The schema above and this type answer different questions. `lngLatSchema` rejects an
|
|
239
|
+
* out-of-range coordinate at the boundary; the type says the value is two numbers. Deriving
|
|
240
|
+
* the type from the schema would have produced a third structurally identical tuple with a
|
|
241
|
+
* name already spoken for twice.
|
|
242
|
+
*/
|
|
243
|
+
export type { LngLat } from "@mountaya/elements/geo";
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* radiusMetersSchema is a strictly-positive radius in meters. A non-positive
|
|
247
|
+
* radius cannot describe an area, so it is rejected rather than collapsing the
|
|
248
|
+
* geometry to its center.
|
|
249
|
+
*/
|
|
250
|
+
const radiusMetersSchema = z.number().positive();
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* bearingSchema is a compass bearing in degrees (0 = north, clockwise), bounded
|
|
254
|
+
* to a full turn. The sector/sensor builders normalise the start→end sweep
|
|
255
|
+
* internally, so the two bounds only reject a wildly out-of-range value.
|
|
256
|
+
*/
|
|
257
|
+
const bearingSchema = z.number().min(0).max(DEGREES_PER_TURN);
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* ZonePole names one of the planet's two poles: `north`, at latitude 90, and `south`, at -90.
|
|
261
|
+
*/
|
|
262
|
+
export type ZonePole = "north" | "south";
|
|
263
|
+
|
|
264
|
+
/** poleNames is each pole as a refusal's sentence writes it. */
|
|
265
|
+
const poleNames = { north: "North Pole", south: "South Pole" } as const satisfies Record<
|
|
266
|
+
ZonePole,
|
|
267
|
+
string
|
|
268
|
+
>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* zoneReachPole names the pole a parametric zone's reach holds, or null when it holds none.
|
|
272
|
+
*
|
|
273
|
+
* A reach is what a shape sweeps from its center: the disc of a circle, the slice of a sector,
|
|
274
|
+
* and for a sensor the slice out to its outer radius, the part nearer than its inner radius
|
|
275
|
+
* included. It holds a pole when the pole is no farther from the center than the reach is long,
|
|
276
|
+
* on the sphere of radius `EARTH_RADIUS_METERS`, and the pole's bearing, due north for the one
|
|
277
|
+
* and due south for the other, is within the sweep, both of its ends included. A circle sweeps
|
|
278
|
+
* every bearing, and a shape centred on a pole holds it whatever its sweep.
|
|
279
|
+
*
|
|
280
|
+
* It answers for a center on the sphere and a reach that is a length. A center whose latitude
|
|
281
|
+
* is no number within -90 and 90 is no point of the sphere, and a reach that is no number is no
|
|
282
|
+
* length: each answers null, and the schema that bounds the member refuses it under its own
|
|
283
|
+
* name, with no pole named beside it. An infinite reach holds the nearer pole within its sweep.
|
|
284
|
+
*
|
|
285
|
+
* A ring round a pole is no shape a planar reader draws. Its longitudes, counted on from its
|
|
286
|
+
* center's, run a whole turn and its closing edge steps back across the map, so a map, an
|
|
287
|
+
* editor and a tile draw a band where the caller meant a cap. A sensor whose band lies beyond
|
|
288
|
+
* the pole breaks the same way: its arcs cross the meridian behind the pole, where a longitude
|
|
289
|
+
* counted on from the center's jumps a turn. So the parametric schemas refuse such a reach,
|
|
290
|
+
* with the pole named ({@link zoneCircleParamsSchema}, {@link zoneSectorParamsSchema},
|
|
291
|
+
* {@link zoneSensorParamsSchema}), and `studio.zone.editPropose` answers `invalid-input`.
|
|
292
|
+
*
|
|
293
|
+
* @param center The shape's center, `[longitude, latitude]` in degrees.
|
|
294
|
+
* @param reachMeters How far the shape reaches from its center, in meters: the radius of a
|
|
295
|
+
* circle or a sector, and a sensor's outer radius.
|
|
296
|
+
* @param sweep The bearings a sector or a sensor sweeps between, in degrees clockwise from
|
|
297
|
+
* north, read clockwise from `bearingStart` and as a full turn where the two are equal. Left
|
|
298
|
+
* out for a circle.
|
|
299
|
+
* @returns The pole the reach holds, the nearer one where it holds both, or null.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { zoneReachPole } from "@mountaya/studio";
|
|
304
|
+
*
|
|
305
|
+
* zoneReachPole([20, 60], 3_400_000); // "north": the pole is about 3336 km away
|
|
306
|
+
* zoneReachPole([20, 60], 3_400_000, { bearingStart: 45, bearingEnd: 135 }); // null
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export const zoneReachPole = (
|
|
310
|
+
center: LngLat,
|
|
311
|
+
reachMeters: number,
|
|
312
|
+
sweep?: { readonly bearingEnd: number; readonly bearingStart: number } | undefined,
|
|
313
|
+
): ZonePole | null => {
|
|
314
|
+
const [, latitude] = center;
|
|
315
|
+
// Written as the range a latitude is within, so a latitude that is no number is outside it.
|
|
316
|
+
const onSphere = latitude >= -LATITUDE_LIMIT && latitude <= LATITUDE_LIMIT;
|
|
317
|
+
if (!onSphere || Number.isNaN(reachMeters)) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const north = { bearing: 0, degrees: LATITUDE_LIMIT - latitude, pole: "north" } as const;
|
|
322
|
+
const south = {
|
|
323
|
+
bearing: DEGREES_PER_TURN / 2,
|
|
324
|
+
degrees: LATITUDE_LIMIT + latitude,
|
|
325
|
+
pole: "south",
|
|
326
|
+
} as const;
|
|
327
|
+
|
|
328
|
+
// The nearer pole first, so a reach that holds both names the one its ring breaks at first.
|
|
329
|
+
for (const { bearing, degrees, pole } of latitude >= 0 ? [north, south] : [south, north]) {
|
|
330
|
+
const distanceMeters = degrees * DEGREES_TO_RADIANS * EARTH_RADIUS_METERS;
|
|
331
|
+
if (reachMeters < distanceMeters) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// From a pole every bearing leads away from it, so a center on one has no sweep to read.
|
|
336
|
+
if (sweep === undefined || degrees <= 0) {
|
|
337
|
+
return pole;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const fromStart =
|
|
341
|
+
(((bearing - sweep.bearingStart) % DEGREES_PER_TURN) + DEGREES_PER_TURN) % DEGREES_PER_TURN;
|
|
342
|
+
if (fromStart <= sweepDegrees(sweep.bearingStart, sweep.bearingEnd)) {
|
|
343
|
+
return pole;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return null;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* refusePoleInReach refuses, on the member that states the reach, a parametric zone whose reach
|
|
352
|
+
* holds a pole ({@link zoneReachPole}). The sentence names the pole and says what to change.
|
|
353
|
+
*/
|
|
354
|
+
const refusePoleInReach = (
|
|
355
|
+
issueCtx: z.RefinementCtx,
|
|
356
|
+
member: "outerRadiusMeters" | "radiusMeters",
|
|
357
|
+
pole: ZonePole | null,
|
|
358
|
+
): void => {
|
|
359
|
+
if (pole === null) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
issueCtx.addIssue({
|
|
364
|
+
code: "custom",
|
|
365
|
+
message: `the reach holds the ${poleNames[pole]}, and a ring round a pole is no shape a map draws: shorten the radius, or move the center away from the pole`,
|
|
366
|
+
path: [member],
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* measured reports whether every value a builder measures a shape from is a finite number. A
|
|
372
|
+
* value that is none is refused by the schema that bounds its member, under that member's name,
|
|
373
|
+
* and nothing is built from it to judge.
|
|
374
|
+
*/
|
|
375
|
+
const measured = (...values: readonly number[]): boolean => values.every(Number.isFinite);
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* holdsNoArea reports whether a built ring, as its positions before the closing one, encloses
|
|
379
|
+
* nothing a zone is stored as: fewer than three positions stand apart
|
|
380
|
+
* ({@link OUTLINE_CLEARANCE_DEGREES}), or the ring is thinner than that clearance, read as its
|
|
381
|
+
* area over its length, which for a sliver is a quarter of its width.
|
|
382
|
+
*
|
|
383
|
+
* It is what a circle of next to no radius, a sweep of next to no angle and a band of next to no
|
|
384
|
+
* width come to, and so does a sector that reaches the far side of the planet, where every
|
|
385
|
+
* bearing arrives at one place.
|
|
386
|
+
*/
|
|
387
|
+
const holdsNoArea = (ring: readonly LngLat[]): boolean => {
|
|
388
|
+
if (ring.length < RING_POSITIONS_MIN - 1) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let doubledArea = 0;
|
|
393
|
+
let length = 0;
|
|
394
|
+
for (const [index, position] of ring.entries()) {
|
|
395
|
+
const next = ring[(index + 1) % ring.length] ?? position;
|
|
396
|
+
doubledArea += position[0] * next[1] - next[0] * position[1];
|
|
397
|
+
length += planarSpan(position, next);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return Math.abs(doubledArea) / 2 / length < OUTLINE_CLEARANCE_DEGREES / 4;
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* refuseNoArea refuses, on the member that states the reach, a parametric zone whose ring
|
|
405
|
+
* encloses nothing a zone is stored as ({@link holdsNoArea}). The sentence says what to change.
|
|
406
|
+
*/
|
|
407
|
+
const refuseNoArea = (
|
|
408
|
+
issueCtx: z.RefinementCtx,
|
|
409
|
+
member: "outerRadiusMeters" | "radiusMeters",
|
|
410
|
+
ring: readonly LngLat[],
|
|
411
|
+
remedy: string,
|
|
412
|
+
): void => {
|
|
413
|
+
if (!holdsNoArea(ring)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
issueCtx.addIssue({
|
|
418
|
+
code: "custom",
|
|
419
|
+
message: `the shape is too small to enclose an area a zone is stored as: ${remedy}`,
|
|
420
|
+
path: [member],
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* zoneCircleParamsSchema validates the parametric inputs to a circle zone: a center [lng, lat],
|
|
426
|
+
* a positive radius in meters, and an optional edge count. It is the Zod source of truth shared
|
|
427
|
+
* by the runtime builder, its TS type, and the JSON Schema the agent tool hands a model, so
|
|
428
|
+
* "blast radius / danger radius / exclusion radius from a point + radius" is one validated
|
|
429
|
+
* shape end to end.
|
|
430
|
+
*
|
|
431
|
+
* A circle whose reach holds a pole is refused on `radiusMeters`, with the pole named
|
|
432
|
+
* ({@link zoneReachPole}), and so is one too small to enclose an area a zone is stored as, a
|
|
433
|
+
* circle under about a meter across.
|
|
434
|
+
*/
|
|
435
|
+
export const zoneCircleParamsSchema = z
|
|
436
|
+
.object({
|
|
437
|
+
center: lngLatSchema,
|
|
438
|
+
radiusMeters: radiusMetersSchema,
|
|
439
|
+
segments: z.number().int().min(CIRCLE_SEGMENTS_MIN).max(CIRCLE_SEGMENTS_MAX).optional(),
|
|
440
|
+
})
|
|
441
|
+
.superRefine((params, issueCtx) => {
|
|
442
|
+
const pole = zoneReachPole(params.center, params.radiusMeters);
|
|
443
|
+
refusePoleInReach(issueCtx, "radiusMeters", pole);
|
|
444
|
+
// A reach that holds a pole is refused above, and its ring is no shape to judge.
|
|
445
|
+
if (
|
|
446
|
+
pole === null &&
|
|
447
|
+
measured(...params.center, params.radiusMeters) &&
|
|
448
|
+
params.radiusMeters > 0
|
|
449
|
+
) {
|
|
450
|
+
refuseNoArea(issueCtx, "radiusMeters", circleRing(params), "lengthen the radius");
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* ZoneCircleParams is the parametric circle input, derived from
|
|
456
|
+
* zoneCircleParamsSchema.
|
|
457
|
+
*/
|
|
458
|
+
export type ZoneCircleParams = z.infer<typeof zoneCircleParamsSchema>;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* zoneSectorParamsSchema validates the parametric inputs to a sector (pie-slice)
|
|
462
|
+
* zone: a center, a positive radius, the start and end compass bearings of the
|
|
463
|
+
* sweep, and an optional arc-point count. It backs "avalanche aspect / wind /
|
|
464
|
+
* search bearing / line-of-sight cone from a center + bearing range + radius".
|
|
465
|
+
*
|
|
466
|
+
* A sector whose reach holds a pole, the pole within its sweep and its radius, is refused on
|
|
467
|
+
* `radiusMeters`, with the pole named ({@link zoneReachPole}). So is one too small to enclose an
|
|
468
|
+
* area a zone is stored as: a radius or a sweep that leaves the slice under about a meter
|
|
469
|
+
* across, and a radius that reaches the far side of the planet, where the arc is one place.
|
|
470
|
+
*/
|
|
471
|
+
export const zoneSectorParamsSchema = z
|
|
472
|
+
.object({
|
|
473
|
+
arcPoints: z.number().int().min(ARC_POINTS_MIN).max(ARC_POINTS_MAX).optional(),
|
|
474
|
+
bearingEnd: bearingSchema,
|
|
475
|
+
bearingStart: bearingSchema,
|
|
476
|
+
center: lngLatSchema,
|
|
477
|
+
radiusMeters: radiusMetersSchema,
|
|
478
|
+
})
|
|
479
|
+
.superRefine((params, issueCtx) => {
|
|
480
|
+
const pole = zoneReachPole(params.center, params.radiusMeters, params);
|
|
481
|
+
refusePoleInReach(issueCtx, "radiusMeters", pole);
|
|
482
|
+
// A reach that holds a pole is refused above, and its ring is no shape to judge.
|
|
483
|
+
if (
|
|
484
|
+
pole === null &&
|
|
485
|
+
measured(...params.center, params.radiusMeters, params.bearingStart, params.bearingEnd) &&
|
|
486
|
+
params.radiusMeters > 0
|
|
487
|
+
) {
|
|
488
|
+
refuseNoArea(
|
|
489
|
+
issueCtx,
|
|
490
|
+
"radiusMeters",
|
|
491
|
+
sectorRing(params),
|
|
492
|
+
"lengthen the radius, or widen the sweep",
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* ZoneSectorParams is the parametric sector input, derived from
|
|
499
|
+
* zoneSectorParamsSchema.
|
|
500
|
+
*/
|
|
501
|
+
export type ZoneSectorParams = z.infer<typeof zoneSectorParamsSchema>;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* zoneSensorParamsSchema validates the parametric inputs to a sensor (annular sector or
|
|
505
|
+
* swept-coverage) zone: a center, an inner and outer radius, the start and end bearings of the
|
|
506
|
+
* sweep, and an optional arc-point count. A refine enforces the outer radius exceeds the inner
|
|
507
|
+
* so the annulus has positive width. It backs "antenna / drone / observation coverage": the
|
|
508
|
+
* same swept-polygon family TerraDrawSensorMode draws interactively, expressed as a closed form
|
|
509
|
+
* the agent can specify directly.
|
|
510
|
+
*
|
|
511
|
+
* A sensor whose reach holds a pole, the pole within its sweep and its outer radius, is refused
|
|
512
|
+
* on `outerRadiusMeters`, with the pole named ({@link zoneReachPole}). So is one too small to
|
|
513
|
+
* enclose an area a zone is stored as: an outer radius, a sweep or a band between the two radii
|
|
514
|
+
* that leaves the footprint under about a meter across.
|
|
515
|
+
*/
|
|
516
|
+
export const zoneSensorParamsSchema = z
|
|
517
|
+
.object({
|
|
518
|
+
arcPoints: z.number().int().min(ARC_POINTS_MIN).max(ARC_POINTS_MAX).optional(),
|
|
519
|
+
bearingEnd: bearingSchema,
|
|
520
|
+
bearingStart: bearingSchema,
|
|
521
|
+
center: lngLatSchema,
|
|
522
|
+
innerRadiusMeters: radiusMetersSchema,
|
|
523
|
+
outerRadiusMeters: radiusMetersSchema,
|
|
524
|
+
})
|
|
525
|
+
.refine((params) => params.outerRadiusMeters > params.innerRadiusMeters, {
|
|
526
|
+
message: "sensor outer radius must exceed inner radius",
|
|
527
|
+
})
|
|
528
|
+
.superRefine((params, issueCtx) => {
|
|
529
|
+
const pole = zoneReachPole(params.center, params.outerRadiusMeters, params);
|
|
530
|
+
refusePoleInReach(issueCtx, "outerRadiusMeters", pole);
|
|
531
|
+
// A reach that holds a pole, and a band whose outer radius does not exceed its inner one,
|
|
532
|
+
// are each refused above under their own sentence, and neither is a shape to judge.
|
|
533
|
+
if (
|
|
534
|
+
pole === null &&
|
|
535
|
+
measured(
|
|
536
|
+
...params.center,
|
|
537
|
+
params.innerRadiusMeters,
|
|
538
|
+
params.outerRadiusMeters,
|
|
539
|
+
params.bearingStart,
|
|
540
|
+
params.bearingEnd,
|
|
541
|
+
) &&
|
|
542
|
+
params.innerRadiusMeters > 0 &&
|
|
543
|
+
params.outerRadiusMeters > params.innerRadiusMeters
|
|
544
|
+
) {
|
|
545
|
+
refuseNoArea(
|
|
546
|
+
issueCtx,
|
|
547
|
+
"outerRadiusMeters",
|
|
548
|
+
sensorRing(params),
|
|
549
|
+
"lengthen the outer radius, widen the sweep, or widen the band between the two radii",
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* ZoneSensorParams is the parametric sensor input, derived from
|
|
556
|
+
* zoneSensorParamsSchema.
|
|
557
|
+
*/
|
|
558
|
+
export type ZoneSensorParams = z.infer<typeof zoneSensorParamsSchema>;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* offsetPosition is the [lng, lat] reached by travelling distanceMeters from origin along
|
|
562
|
+
* bearingDeg (0 = north, clockwise), on a sphere of radius EARTH_RADIUS_METERS, with its
|
|
563
|
+
* longitude counted on from the origin's: past 180 where the way crosses the antimeridian
|
|
564
|
+
* eastward, and below -180 where it crosses westward.
|
|
565
|
+
*
|
|
566
|
+
* It is what a ring is built from. Every position of a zone's ring is offset from one center, so
|
|
567
|
+
* two neighbours on the ring stand a fraction of a turn apart and never on opposite edges of the
|
|
568
|
+
* map. The longitude is never further than half a turn from the origin's, so it stays within
|
|
569
|
+
* -360 and 360 for an origin within -180 and 180.
|
|
570
|
+
*/
|
|
571
|
+
const offsetPosition = (origin: LngLat, distanceMeters: number, bearingDeg: number): LngLat => {
|
|
572
|
+
const angular = distanceMeters / EARTH_RADIUS_METERS;
|
|
573
|
+
const bearing = bearingDeg * DEGREES_TO_RADIANS;
|
|
574
|
+
const lat1 = origin[1] * DEGREES_TO_RADIANS;
|
|
575
|
+
const lng1 = origin[0] * DEGREES_TO_RADIANS;
|
|
576
|
+
|
|
577
|
+
const sinLat1 = Math.sin(lat1);
|
|
578
|
+
const cosLat1 = Math.cos(lat1);
|
|
579
|
+
const sinAngular = Math.sin(angular);
|
|
580
|
+
const cosAngular = Math.cos(angular);
|
|
581
|
+
|
|
582
|
+
const lat2 = Math.asin(sinLat1 * cosAngular + cosLat1 * sinAngular * Math.cos(bearing));
|
|
583
|
+
const lng2 =
|
|
584
|
+
lng1 +
|
|
585
|
+
Math.atan2(Math.sin(bearing) * sinAngular * cosLat1, cosAngular - sinLat1 * Math.sin(lat2));
|
|
586
|
+
|
|
587
|
+
return [lng2 * RADIANS_TO_DEGREES, lat2 * RADIANS_TO_DEGREES];
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* destinationPoint returns the [lng, lat] reached by travelling distanceMeters from origin along
|
|
592
|
+
* bearingDeg (0 = north, clockwise), on a sphere of radius EARTH_RADIUS_METERS.
|
|
593
|
+
*
|
|
594
|
+
* It is the spherical law-of-cosines destination formula, the great-circle model the haversine
|
|
595
|
+
* distance uses, inverted. An offset is therefore geodesically reasonable at the city-to-region
|
|
596
|
+
* radii a zone covers, well within a degree of the planar approximation the rest of the studio
|
|
597
|
+
* relies on.
|
|
598
|
+
*
|
|
599
|
+
* It answers one position, so its longitude is brought within -180 (included) and 180
|
|
600
|
+
* (excluded): 50 km east of `[179.9, 0]` is near `[-179.65, 0]`. A ring is another matter. The
|
|
601
|
+
* builders below offset every position of a ring from its center and keep each longitude
|
|
602
|
+
* counted on from the center's ({@link zoneCircleGeometry}), since two positions wrapped one by
|
|
603
|
+
* one land on opposite edges of the map.
|
|
604
|
+
*/
|
|
605
|
+
export const destinationPoint = (
|
|
606
|
+
origin: LngLat,
|
|
607
|
+
distanceMeters: number,
|
|
608
|
+
bearingDeg: number,
|
|
609
|
+
): Position => {
|
|
610
|
+
const [lng, lat] = offsetPosition(origin, distanceMeters, bearingDeg);
|
|
611
|
+
const wrapped = (((lng + 540) % DEGREES_PER_TURN) + DEGREES_PER_TURN) % DEGREES_PER_TURN;
|
|
612
|
+
|
|
613
|
+
return [wrapped - 180, lat];
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* sweepDegrees normalises a start→end bearing sweep to a positive span in
|
|
618
|
+
* [0, 360]: a sweep whose end is at or below its start wraps forward through
|
|
619
|
+
* north (a 350→10 sweep spans 20°, not -340°), and an exactly-equal pair is read
|
|
620
|
+
* as a full turn so "0 to 0" / "180 to 180" describes the whole circle rather
|
|
621
|
+
* than a degenerate slice. The builders walk start + this span so the arc always
|
|
622
|
+
* runs the short clockwise way the bearings name.
|
|
623
|
+
*/
|
|
624
|
+
const sweepDegrees = (bearingStartDeg: number, bearingEndDeg: number): number => {
|
|
625
|
+
const raw = bearingEndDeg - bearingStartDeg;
|
|
626
|
+
const wrapped = ((raw % DEGREES_PER_TURN) + DEGREES_PER_TURN) % DEGREES_PER_TURN;
|
|
627
|
+
|
|
628
|
+
return wrapped === 0 ? DEGREES_PER_TURN : wrapped;
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* closeRing appends the first coordinate to the end of a coordinate list so it
|
|
633
|
+
* forms a closed linear ring (RFC-7946 requires a Polygon ring's first and last
|
|
634
|
+
* positions to be identical). The input must hold at least one coordinate.
|
|
635
|
+
*/
|
|
636
|
+
const closeRing = (coordinates: Position[]): Position[] => {
|
|
637
|
+
const first = coordinates[0];
|
|
638
|
+
if (!first) {
|
|
639
|
+
return coordinates;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return [...coordinates, first];
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* standingApart answers a ring's positions with every one that stands nearer than
|
|
647
|
+
* {@link OUTLINE_CLEARANCE_DEGREES} to the one kept before it left out, and so the last ones
|
|
648
|
+
* that stand that near the first, which the closing edge would run back onto.
|
|
649
|
+
*
|
|
650
|
+
* A shape sampled finer than it is wide lands several samples on one place: an arc swept through
|
|
651
|
+
* next to no angle, a circle a few meters across cut into hundreds of edges, the inner arc of a
|
|
652
|
+
* band whose inner radius is next to nothing. Left in, each would be a position repeating the
|
|
653
|
+
* one before it. A ring whose positions all stand apart is answered as it came.
|
|
654
|
+
*/
|
|
655
|
+
const standingApart = (positions: readonly LngLat[]): LngLat[] => {
|
|
656
|
+
const kept: LngLat[] = [];
|
|
657
|
+
for (const position of positions) {
|
|
658
|
+
const last = kept.at(-1);
|
|
659
|
+
if (last === undefined || planarSpan(last, position) >= OUTLINE_CLEARANCE_DEGREES) {
|
|
660
|
+
kept.push(position);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const [first] = kept;
|
|
665
|
+
let last = kept.at(-1);
|
|
666
|
+
while (
|
|
667
|
+
first !== undefined &&
|
|
668
|
+
last !== undefined &&
|
|
669
|
+
kept.length > 1 &&
|
|
670
|
+
planarSpan(first, last) < OUTLINE_CLEARANCE_DEGREES
|
|
671
|
+
) {
|
|
672
|
+
kept.pop();
|
|
673
|
+
last = kept.at(-1);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return kept;
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* comesRound reports whether an arc swept from `bearingStart` through `span` degrees at
|
|
681
|
+
* `radiusMeters` comes back round to where it began: a whole turn, or a sweep whose far end
|
|
682
|
+
* lands within {@link OUTLINE_CLEARANCE_DEGREES} of the radius it set out along while the middle
|
|
683
|
+
* of the arc stands clear of it.
|
|
684
|
+
*
|
|
685
|
+
* The two radial edges of such a sweep lie along each other, so a ring that ran out along one
|
|
686
|
+
* and back along the other would retrace itself. The middle is read to tell that sweep from one
|
|
687
|
+
* of next to no angle, or at next to no radius, whose ends are near each other because the
|
|
688
|
+
* whole arc is one place.
|
|
689
|
+
*/
|
|
690
|
+
const comesRound = (
|
|
691
|
+
center: LngLat,
|
|
692
|
+
radiusMeters: number,
|
|
693
|
+
bearingStart: number,
|
|
694
|
+
span: number,
|
|
695
|
+
): boolean => {
|
|
696
|
+
if (span === DEGREES_PER_TURN) {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const first = offsetPosition(center, radiusMeters, bearingStart);
|
|
701
|
+
const last = offsetPosition(center, radiusMeters, bearingStart + span);
|
|
702
|
+
const middle = offsetPosition(center, radiusMeters, bearingStart + span / 2);
|
|
703
|
+
const mouth = Math.min(offEdge(last, center, first), offEdge(first, center, last));
|
|
704
|
+
|
|
705
|
+
return (
|
|
706
|
+
mouth < OUTLINE_CLEARANCE_DEGREES && offEdge(middle, center, first) >= OUTLINE_CLEARANCE_DEGREES
|
|
707
|
+
);
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
/** arcOf samples an arc at `points` evenly spaced bearings, both of its ends among them. */
|
|
711
|
+
const arcOf = (
|
|
712
|
+
center: LngLat,
|
|
713
|
+
radiusMeters: number,
|
|
714
|
+
bearingStart: number,
|
|
715
|
+
span: number,
|
|
716
|
+
points: number,
|
|
717
|
+
): LngLat[] => {
|
|
718
|
+
const step = span / (points - 1);
|
|
719
|
+
const arc: LngLat[] = [];
|
|
720
|
+
for (let index = 0; index < points; index += 1) {
|
|
721
|
+
arc.push(offsetPosition(center, radiusMeters, bearingStart + index * step));
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return arc;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
/** circleRing is a circle's ring before its closing position ({@link zoneCircleGeometry}). */
|
|
728
|
+
const circleRing = (params: ZoneCircleParams): LngLat[] => {
|
|
729
|
+
const segments = params.segments ?? CIRCLE_SEGMENTS_DEFAULT;
|
|
730
|
+
const step = DEGREES_PER_TURN / segments;
|
|
731
|
+
const ring: LngLat[] = [];
|
|
732
|
+
for (let index = 0; index < segments; index += 1) {
|
|
733
|
+
ring.push(offsetPosition(params.center, params.radiusMeters, index * step));
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return standingApart(ring);
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
/** sectorRing is a sector's ring before its closing position ({@link zoneSectorGeometry}). */
|
|
740
|
+
const sectorRing = (params: ZoneSectorParams): LngLat[] => {
|
|
741
|
+
const arcPoints = params.arcPoints ?? ARC_POINTS_DEFAULT;
|
|
742
|
+
const span = sweepDegrees(params.bearingStart, params.bearingEnd);
|
|
743
|
+
if (comesRound(params.center, params.radiusMeters, params.bearingStart, span)) {
|
|
744
|
+
return circleRing({
|
|
745
|
+
center: params.center,
|
|
746
|
+
radiusMeters: params.radiusMeters,
|
|
747
|
+
segments: Math.max(arcPoints, CIRCLE_SEGMENTS_MIN),
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return standingApart([
|
|
752
|
+
params.center,
|
|
753
|
+
...arcOf(params.center, params.radiusMeters, params.bearingStart, span, arcPoints),
|
|
754
|
+
]);
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* SLIT_WIDTH_DEGREES is how far apart the two edges of a full-turn sensor's slit stand where
|
|
759
|
+
* they are nearest, at the inner radius: two clearances ({@link OUTLINE_CLEARANCE_DEGREES}),
|
|
760
|
+
* about two meters. The second clearance is the slit's margin: a slit cut exactly one clearance
|
|
761
|
+
* wide would be left short of it by the rounding of its own positions.
|
|
762
|
+
*/
|
|
763
|
+
const SLIT_WIDTH_DEGREES = 2 * OUTLINE_CLEARANCE_DEGREES;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* SLIT_HALF_ANGLE_MAX is the widest a slit opens to either side of the start bearing, in
|
|
767
|
+
* degrees. The edges of a slit converge on the center, so the nearer the inner circle is to the
|
|
768
|
+
* slit's own width, the wider the slit has to open to keep its edges apart there. An inner
|
|
769
|
+
* circle that asks for more than this is under a few meters across, and is no hole a ring goes
|
|
770
|
+
* round.
|
|
771
|
+
*/
|
|
772
|
+
const SLIT_HALF_ANGLE_MAX = 45;
|
|
773
|
+
|
|
774
|
+
/** The most times {@link slitHalfAngle} widens a slit before it answers that none fits. */
|
|
775
|
+
const SLIT_WIDENINGS_MAX = 8;
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* slitHalfAngle is how far to either side of `bearingStart` a full-turn sensor's slit opens, in
|
|
779
|
+
* degrees, or null where its inner circle is too small to cut a slit beside.
|
|
780
|
+
*
|
|
781
|
+
* The slit's two edges run from the inner radius out to the outer one, at this angle to either
|
|
782
|
+
* side of the start bearing. They converge on the center, so they are nearest at the inner
|
|
783
|
+
* radius, and the angle is the least that keeps them {@link SLIT_WIDTH_DEGREES} apart there, on
|
|
784
|
+
* the plane the outline is stored on. A degree of longitude is shorter than one of latitude
|
|
785
|
+
* everywhere but on the equator, so the same slit measures differently by its bearing: the first
|
|
786
|
+
* angle is read off the sphere, and is widened until the edges, measured on the plane, stand
|
|
787
|
+
* that far apart.
|
|
788
|
+
*/
|
|
789
|
+
const slitHalfAngle = (
|
|
790
|
+
center: LngLat,
|
|
791
|
+
innerRadiusMeters: number,
|
|
792
|
+
outerRadiusMeters: number,
|
|
793
|
+
bearingStart: number,
|
|
794
|
+
): number | null => {
|
|
795
|
+
const widthMeters = SLIT_WIDTH_DEGREES * DEGREES_TO_RADIANS * EARTH_RADIUS_METERS;
|
|
796
|
+
let half = Math.asin(Math.min(1, widthMeters / (2 * innerRadiusMeters))) * RADIANS_TO_DEGREES;
|
|
797
|
+
|
|
798
|
+
for (
|
|
799
|
+
let widening = 0;
|
|
800
|
+
widening < SLIT_WIDENINGS_MAX && half <= SLIT_HALF_ANGLE_MAX;
|
|
801
|
+
widening += 1
|
|
802
|
+
) {
|
|
803
|
+
const [near, far] = [bearingStart + half, bearingStart - half].map(
|
|
804
|
+
(bearing) =>
|
|
805
|
+
[
|
|
806
|
+
offsetPosition(center, innerRadiusMeters, bearing),
|
|
807
|
+
offsetPosition(center, outerRadiusMeters, bearing),
|
|
808
|
+
] as const,
|
|
809
|
+
);
|
|
810
|
+
if (near === undefined || far === undefined) {
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
const gap = Math.min(offEdge(near[0], far[0], far[1]), offEdge(far[0], near[0], near[1]));
|
|
815
|
+
if (gap >= SLIT_WIDTH_DEGREES) {
|
|
816
|
+
return half;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
if (gap === 0) {
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
half *= (SLIT_WIDTH_DEGREES / gap) * 1.01;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return null;
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
/** sensorRing is a sensor's ring before its closing position ({@link zoneSensorGeometry}). */
|
|
830
|
+
const sensorRing = (params: ZoneSensorParams): LngLat[] => {
|
|
831
|
+
const { bearingStart, center, innerRadiusMeters, outerRadiusMeters } = params;
|
|
832
|
+
const arcPoints = params.arcPoints ?? ARC_POINTS_DEFAULT;
|
|
833
|
+
const span = sweepDegrees(bearingStart, params.bearingEnd);
|
|
834
|
+
// Outer arc, start to end, then the inner arc back, so the band closes on itself.
|
|
835
|
+
const band = (from: number, through: number, points: number): LngLat[] =>
|
|
836
|
+
standingApart([
|
|
837
|
+
...arcOf(center, outerRadiusMeters, from, through, points),
|
|
838
|
+
...arcOf(center, innerRadiusMeters, from, through, points).reverse(),
|
|
839
|
+
]);
|
|
840
|
+
|
|
841
|
+
if (
|
|
842
|
+
!comesRound(center, outerRadiusMeters, bearingStart, span) &&
|
|
843
|
+
!comesRound(center, innerRadiusMeters, bearingStart, span)
|
|
844
|
+
) {
|
|
845
|
+
return band(bearingStart, span, arcPoints);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// The band goes all the way round. It is cut by a slit along its start bearing where its
|
|
849
|
+
// inner circle is wide enough to cut one beside, and is the disc of its outer radius where
|
|
850
|
+
// the inner circle is one place on the map.
|
|
851
|
+
const half = slitHalfAngle(center, innerRadiusMeters, outerRadiusMeters, bearingStart);
|
|
852
|
+
if (half === null) {
|
|
853
|
+
return circleRing({
|
|
854
|
+
center,
|
|
855
|
+
radiusMeters: outerRadiusMeters,
|
|
856
|
+
segments: Math.max(arcPoints, CIRCLE_SEGMENTS_MIN),
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
return band(
|
|
861
|
+
bearingStart + half,
|
|
862
|
+
DEGREES_PER_TURN - 2 * half,
|
|
863
|
+
Math.max(arcPoints, CIRCLE_SEGMENTS_MIN + 1),
|
|
864
|
+
);
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* zoneCircleGeometry builds a GeoJSON Polygon approximating a geodesic circle of radiusMeters
|
|
869
|
+
* around center, sampled at `segments` evenly spaced bearings. The ring is closed: its last
|
|
870
|
+
* position repeats its first. It is the geometry behind a circle zone (a blast, danger or
|
|
871
|
+
* exclusion radius), shared by the agent's parametric proposal and any in-app default, and the
|
|
872
|
+
* shape the TerraDraw circle mode draws interactively.
|
|
873
|
+
*
|
|
874
|
+
* A ring's longitudes are counted on from its center's, in this builder and in
|
|
875
|
+
* {@link zoneSectorGeometry} and {@link zoneSensorGeometry}. A zone astride the antimeridian is
|
|
876
|
+
* therefore one ring whose longitudes run past 180, or below -180: a circle of 50 km around
|
|
877
|
+
* `[179.9, -16.8]` spans about 179.43 to 180.37. No two neighbours on a ring stand half a turn
|
|
878
|
+
* apart, so a planar reader (a map, a geometry column) draws the disc, where a ring wrapped
|
|
879
|
+
* position by position jumps across the map and encloses every other longitude. A reader that
|
|
880
|
+
* needs each longitude within -180 and 180 brings it back by whole turns, and cuts the shape at
|
|
881
|
+
* the antimeridian if it needs a ring to stay on one side.
|
|
882
|
+
*
|
|
883
|
+
* A circle that holds a pole is outside the rule: its ring goes once round the pole, and no
|
|
884
|
+
* planar ring states that. {@link zoneCircleParamsSchema} refuses one, as the sector's and the
|
|
885
|
+
* sensor's schemas refuse theirs ({@link zoneReachPole}), so a builder is handed parameters its
|
|
886
|
+
* schema took and checks none of this again.
|
|
887
|
+
*/
|
|
888
|
+
export const zoneCircleGeometry = (params: ZoneCircleParams): Polygon => ({
|
|
889
|
+
coordinates: [closeRing(circleRing(params))],
|
|
890
|
+
type: "Polygon",
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* zoneSectorGeometry builds a GeoJSON Polygon pie-slice: the center, an arc of
|
|
895
|
+
* `arcPoints` positions swept from bearingStart to bearingEnd at radiusMeters,
|
|
896
|
+
* and back to the center. The ring is explicitly closed. It is the geometry behind a sector
|
|
897
|
+
* zone: an avalanche-aspect band, a search-bearing or line-of-sight cone.
|
|
898
|
+
*
|
|
899
|
+
* A full-turn sweep (equal bearings, or 0 and 360) is the disc, and answers the ring
|
|
900
|
+
* {@link zoneCircleGeometry} builds, in `arcPoints` edges and never fewer than a circle takes.
|
|
901
|
+
* Built as a slice it would run out to the arc along one radius and back along the same one,
|
|
902
|
+
* a ring that touches itself. A sweep that stops short of the whole turn by less than an outline
|
|
903
|
+
* can hold, its far end within about a meter of the radius it set out along, is the disc too,
|
|
904
|
+
* for the same reason.
|
|
905
|
+
*
|
|
906
|
+
* Arc positions that land on one place are one position of the ring, so a sweep of next to no
|
|
907
|
+
* angle is drawn in fewer positions than `arcPoints`. {@link zoneSectorParamsSchema} refuses a
|
|
908
|
+
* sector too small to enclose an area, and a builder is handed parameters its schema took.
|
|
909
|
+
*/
|
|
910
|
+
export const zoneSectorGeometry = (params: ZoneSectorParams): Polygon => ({
|
|
911
|
+
coordinates: [closeRing(sectorRing(params))],
|
|
912
|
+
type: "Polygon",
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* zoneSensorGeometry builds a GeoJSON Polygon annular sector (a swept-coverage
|
|
917
|
+
* "sensor" footprint): the outer arc swept from bearingStart to bearingEnd at
|
|
918
|
+
* outerRadiusMeters, then the inner arc swept back at innerRadiusMeters, closing
|
|
919
|
+
* the band. The ring is explicitly closed. It is the geometry behind a sensor zone: an
|
|
920
|
+
* antenna, a drone or an observation coverage footprint, the closed-form expression of the
|
|
921
|
+
* swept polygon TerraDrawSensorMode draws interactively.
|
|
922
|
+
*
|
|
923
|
+
* A full-turn sweep (equal bearings, or 0 and 360) answers one ring, cut by a slit along the
|
|
924
|
+
* start bearing: the outer circle, in along one edge of the slit, the inner circle backwards, and
|
|
925
|
+
* out along the other edge. The area inside the inner radius is no part of the zone, and it is
|
|
926
|
+
* not stated as a Polygon of two rings, the inner circle as a hole: a zone's shape is one ring,
|
|
927
|
+
* and the zone editor holds no ring with a hole. The slit has a width, so the ring neither
|
|
928
|
+
* retraces nor touches itself, which the API refuses: its two edges open to either side of the
|
|
929
|
+
* start bearing by the least angle that keeps them about two meters apart at the inner radius,
|
|
930
|
+
* where they are nearest, and the band keeps the rest of its turn. Each circle is drawn in
|
|
931
|
+
* `arcPoints` positions, and in nine at least, the fewest that go round. A sweep that stops
|
|
932
|
+
* short of the whole turn by less than an outline can hold, on either arc, is that ring too.
|
|
933
|
+
*
|
|
934
|
+
* A full turn whose inner circle is too small to cut a slit beside, one under a few meters
|
|
935
|
+
* across, is the disc of the outer radius, the ring {@link zoneCircleGeometry} builds there, as
|
|
936
|
+
* a full-turn sector is: an inner circle that small is one place on the map, and no hole a ring
|
|
937
|
+
* goes round.
|
|
938
|
+
*
|
|
939
|
+
* Arc positions that land on one place are one position of the ring, so a band whose inner
|
|
940
|
+
* radius is next to nothing is drawn as the slice it is. {@link zoneSensorParamsSchema} refuses
|
|
941
|
+
* a sensor too small to enclose an area, and a builder is handed parameters its schema took.
|
|
942
|
+
*/
|
|
943
|
+
export const zoneSensorGeometry = (params: ZoneSensorParams): Polygon => ({
|
|
944
|
+
coordinates: [closeRing(sensorRing(params))],
|
|
945
|
+
type: "Polygon",
|
|
946
|
+
});
|