leaflet-city-mapper 0.0.1 → 0.0.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.
Files changed (629) hide show
  1. package/README.md +61 -13
  2. package/cucumber.mjs +4 -0
  3. package/dist/leaflet-city-mapper.js +3 -1
  4. package/dist/leaflet-city-mapper.js.map +4 -4
  5. package/package.json +3 -4
  6. package/src/archives/decodeDirectory.js +32 -0
  7. package/src/archives/decodeHeader.js +19 -0
  8. package/src/archives/decompress.js +5 -0
  9. package/src/archives/getHeader.js +9 -0
  10. package/src/archives/getZxy.js +75 -0
  11. package/src/archives/loadDirectory.js +7 -0
  12. package/src/archives/loadSource.js +17 -0
  13. package/src/archives/read.js +29 -0
  14. package/src/archives/tileId.js +19 -0
  15. package/src/archives/varint.js +15 -0
  16. package/src/camera/angles.js +6 -0
  17. package/src/camera/animationPoint.js +8 -0
  18. package/src/camera/cameraMapReady.js +8 -0
  19. package/src/camera/cancelCameraAnimation.js +11 -0
  20. package/src/camera/cleanupCameraMap.js +11 -0
  21. package/src/camera/constrainCameraToBounds.js +3 -0
  22. package/src/camera/displayPoint.js +3 -0
  23. package/src/camera/fitCameraBounds.js +48 -0
  24. package/src/camera/groundBounds.js +11 -0
  25. package/src/camera/initializeCameraMap.js +25 -0
  26. package/src/camera/mapAnimateCamera.js +17 -0
  27. package/src/camera/mapCamera.js +123 -0
  28. package/src/camera/mapContainerPointToLayerPoint.js +7 -0
  29. package/src/camera/mapGetBearing.js +1 -0
  30. package/src/camera/mapGetBounds.js +14 -0
  31. package/src/camera/mapGetBoundsCenterZoom.js +7 -0
  32. package/src/camera/mapGetBoundsZoom.js +14 -0
  33. package/src/camera/mapGetCenterLayerPoint.js +5 -0
  34. package/src/camera/mapGetPitch.js +1 -0
  35. package/src/camera/mapLayerPointToContainerPoint.js +7 -0
  36. package/src/camera/mapLimitCenter.js +12 -0
  37. package/src/camera/mapLimitOffset.js +10 -0
  38. package/src/camera/mapPanBy.js +9 -0
  39. package/src/camera/mapPanInside.js +14 -0
  40. package/src/camera/mapResetNorth.js +1 -0
  41. package/src/camera/mapResetNorthPitch.js +1 -0
  42. package/src/camera/mapSetBearing.js +1 -0
  43. package/src/camera/mapSetPitch.js +1 -0
  44. package/src/camera/mapSetPitchAndBearing.js +14 -0
  45. package/src/camera/mapSetZoomAround.js +11 -0
  46. package/src/camera/mapStopPitchBearingAnimation.js +6 -0
  47. package/src/camera/mapTryAnimatedPan.js +9 -0
  48. package/src/camera/mapUpdateCameraOverlays.js +7 -0
  49. package/src/camera/pointOf.js +3 -0
  50. package/src/camera/project.js +20 -0
  51. package/src/camera/runCameraAnimations.js +28 -0
  52. package/src/camera/scheduleCameraAnimation.js +8 -0
  53. package/src/camera/updateSky.js +16 -0
  54. package/src/camera/verticalGroundY.js +4 -0
  55. package/src/collision/collectMeshes.js +5 -0
  56. package/src/collision/collider.js +63 -0
  57. package/src/collision/horizontalRay.js +12 -0
  58. package/src/collision/intersectMeshes.js +133 -0
  59. package/src/collision/sortHits.js +23 -0
  60. package/src/constants/CELL.js +4 -0
  61. package/src/constants/Compass.js +7 -0
  62. package/src/constants/ContainerResize.js +7 -0
  63. package/src/constants/HEIGHT.js +1 -0
  64. package/src/constants/PitchDrag.js +7 -0
  65. package/src/constants/ShiftRotate.js +7 -0
  66. package/src/constants/TILE_RADIUS.js +1 -0
  67. package/src/constants/TILE_SIZE.js +1 -0
  68. package/src/constants/TouchMode.js +6 -0
  69. package/src/constants/accessorSizes.js +1 -0
  70. package/src/constants/accessorTypes.js +8 -0
  71. package/src/constants/attachState.js +1 -0
  72. package/src/constants/cameraControlsState.js +1 -0
  73. package/src/constants/cityMapper.js +6 -0
  74. package/src/constants/colliders.js +2 -0
  75. package/src/constants/dark.js +1 -0
  76. package/src/constants/elevationWGSL.js +27 -0
  77. package/src/constants/glass.js +1 -0
  78. package/src/constants/headlight.js +1 -0
  79. package/src/constants/hull.js +1 -0
  80. package/src/constants/indexState.js +1 -0
  81. package/src/constants/limbs.js +9 -0
  82. package/src/constants/mapCameraState.js +1 -0
  83. package/src/constants/moves.js +11 -0
  84. package/src/constants/nativeEventMaps.js +1 -0
  85. package/src/constants/nativeLayerState.js +1 -0
  86. package/src/constants/nativeMethodHandlers.js +31 -0
  87. package/src/constants/onMapChangeState.js +1 -0
  88. package/src/constants/onZoomAnimState.js +1 -0
  89. package/src/constants/paints.js +10 -0
  90. package/src/constants/parts.js +19 -0
  91. package/src/constants/pendingUpdates.js +1 -0
  92. package/src/constants/pumpState.js +1 -0
  93. package/src/constants/renderers.js +2 -0
  94. package/src/constants/ringDirections.js +10 -0
  95. package/src/constants/roundProfile.js +1 -0
  96. package/src/constants/shirt.js +1 -0
  97. package/src/constants/skin.js +2 -0
  98. package/src/constants/speed.js +3 -0
  99. package/src/constants/taillight.js +1 -0
  100. package/src/constants/trafficShader.js +49 -0
  101. package/src/constants/trousers.js +1 -0
  102. package/src/constants/tyre.js +1 -0
  103. package/src/constants/underEntryState.js +1 -0
  104. package/src/constants/vehicles.js +40 -0
  105. package/src/constants/white.js +1 -0
  106. package/src/controls/acceptPitchDrag.js +4 -0
  107. package/src/controls/acceptRotateDrag.js +3 -0
  108. package/src/controls/adjustCameraDrag.js +10 -0
  109. package/src/controls/cameraControls.js +60 -0
  110. package/src/controls/cameraDragClick.js +9 -0
  111. package/src/controls/cameraDragContextMenu.js +8 -0
  112. package/src/controls/cameraDragDown.js +20 -0
  113. package/src/controls/cameraDragEnd.js +6 -0
  114. package/src/controls/cameraDragMove.js +23 -0
  115. package/src/controls/changeCameraTouch.js +14 -0
  116. package/src/controls/cleanupCameraTouch.js +24 -0
  117. package/src/controls/compassAddHooks.js +15 -0
  118. package/src/controls/compassOrientation.js +6 -0
  119. package/src/controls/compassRemoveHooks.js +5 -0
  120. package/src/controls/containerResizeAddHooks.js +8 -0
  121. package/src/controls/containerResizeRemoveHooks.js +5 -0
  122. package/src/controls/dragCamera.js +22 -0
  123. package/src/controls/editable.js +3 -0
  124. package/src/controls/endAllCameraDrags.js +7 -0
  125. package/src/controls/endAllCameraTouches.js +7 -0
  126. package/src/controls/endCameraTouch.js +11 -0
  127. package/src/controls/endCameraTouchEvent.js +5 -0
  128. package/src/controls/finishCameraDrag.js +9 -0
  129. package/src/controls/finishCompassPermission.js +16 -0
  130. package/src/controls/loadCameraControls.js +9 -0
  131. package/src/controls/moveCameraTouch.js +22 -0
  132. package/src/controls/notifyCameraTouchChange.js +1 -0
  133. package/src/controls/pitchDragAddHooks.js +6 -0
  134. package/src/controls/pitchDragRemoveHooks.js +5 -0
  135. package/src/controls/refreshRotateControl.js +7 -0
  136. package/src/controls/refreshRotateFocus.js +5 -0
  137. package/src/controls/removeCameraDrag.js +23 -0
  138. package/src/controls/resizeMap.js +3 -0
  139. package/src/controls/rotateButtonClick.js +7 -0
  140. package/src/controls/rotateButtonKeydown.js +11 -0
  141. package/src/controls/rotateControl.js +3 -0
  142. package/src/controls/rotateOnAdd.js +38 -0
  143. package/src/controls/rotateOnRemove.js +6 -0
  144. package/src/controls/shiftRotateAddHooks.js +8 -0
  145. package/src/controls/shiftRotateRemoveHooks.js +5 -0
  146. package/src/controls/shiftRotateWheel.js +9 -0
  147. package/src/controls/startCameraTouch.js +23 -0
  148. package/src/core/addImageState.js +7 -0
  149. package/src/core/addRasterImage.js +10 -0
  150. package/src/core/adjustCameraMarkerPan.js +22 -0
  151. package/src/core/beforeNativeRender.js +10 -0
  152. package/src/core/boundsQuad.js +11 -0
  153. package/src/core/bringNativeLayerToBack.js +3 -0
  154. package/src/core/bringNativeLayerToFront.js +3 -0
  155. package/src/core/cameraCircleBounds.js +6 -0
  156. package/src/core/cameraMarkerDrag.js +18 -0
  157. package/src/core/cameraMarkerOnDrag.js +8 -0
  158. package/src/core/cancelGridFade.js +10 -0
  159. package/src/core/closestCameraLayerPoint.js +7 -0
  160. package/src/core/compareNativeHits.js +3 -0
  161. package/src/core/current.js +3 -0
  162. package/src/core/disposeNativeLayer.js +35 -0
  163. package/src/core/fireRasterLoad.js +5 -0
  164. package/src/core/forwardNativeError.js +3 -0
  165. package/src/core/gridlayerGetEvents.js +7 -0
  166. package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
  167. package/src/core/handleNativeMapEvent.js +47 -0
  168. package/src/core/hideTargets.js +16 -0
  169. package/src/core/initNativeGPU.js +21 -0
  170. package/src/core/initializeGridContainer.js +6 -0
  171. package/src/core/initializeNativeLayer.js +42 -0
  172. package/src/core/localPixel.js +5 -0
  173. package/src/core/localPixelForGeometry.js +6 -0
  174. package/src/core/localPosition.js +6 -0
  175. package/src/core/markerCameraIconPoint.js +9 -0
  176. package/src/core/markerGetEvents.js +5 -0
  177. package/src/core/markerInitInteraction.js +8 -0
  178. package/src/core/markerQuadCorners.js +31 -0
  179. package/src/core/markerSetIcon.js +9 -0
  180. package/src/core/markerSetPos.js +14 -0
  181. package/src/core/markerSetRotation.js +7 -0
  182. package/src/core/markerUpdateZIndex.js +8 -0
  183. package/src/core/nativeAddLatLng.js +3 -0
  184. package/src/core/nativeBringToBack.js +3 -0
  185. package/src/core/nativeBringToFront.js +3 -0
  186. package/src/core/nativeEvents.js +26 -0
  187. package/src/core/nativeImageError.js +8 -0
  188. package/src/core/nativeImageRefresh.js +7 -0
  189. package/src/core/nativeLayer.js +97 -0
  190. package/src/core/nativeLayerMethod.js +21 -0
  191. package/src/core/nativeRedraw.js +3 -0
  192. package/src/core/nativeSetBounds.js +3 -0
  193. package/src/core/nativeSetIcon.js +3 -0
  194. package/src/core/nativeSetLatLng.js +3 -0
  195. package/src/core/nativeSetLatLngs.js +3 -0
  196. package/src/core/nativeSetOpacity.js +3 -0
  197. package/src/core/nativeSetRadius.js +3 -0
  198. package/src/core/nativeSetStyle.js +3 -0
  199. package/src/core/nativeSetUrl.js +3 -0
  200. package/src/core/nativeSetZIndex.js +3 -0
  201. package/src/core/nativeSetZIndexOffset.js +3 -0
  202. package/src/core/popupAdjustPan.js +23 -0
  203. package/src/core/popupGetEvents.js +5 -0
  204. package/src/core/popupUpdatePosition.js +14 -0
  205. package/src/core/putNativeMesh.js +33 -0
  206. package/src/core/quadNativeMesh.js +15 -0
  207. package/src/core/readyNativeGPU.js +6 -0
  208. package/src/core/refreshNativeEvent.js +5 -0
  209. package/src/core/refreshNativeLayer.js +29 -0
  210. package/src/core/refreshNativeLayerContract.js +3 -0
  211. package/src/core/rejectNativeReady.js +3 -0
  212. package/src/core/removeImageState.js +8 -0
  213. package/src/core/removeNativeEvents.js +16 -0
  214. package/src/core/removeTargets.js +8 -0
  215. package/src/core/reorderNativeLayer.js +6 -0
  216. package/src/core/resolveNativeReady.js +3 -0
  217. package/src/core/restoreNativeEvents.js +6 -0
  218. package/src/core/runGridFades.js +14 -0
  219. package/src/core/runMarkerPanFrame.js +12 -0
  220. package/src/core/scheduleGridFade.js +9 -0
  221. package/src/core/scheduleMarkerPan.js +8 -0
  222. package/src/core/styleNativeMesh.js +10 -0
  223. package/src/core/syncGridLayer.js +22 -0
  224. package/src/core/syncImageOverlay.js +9 -0
  225. package/src/core/syncMarker.js +12 -0
  226. package/src/core/syncVectorLayer.js +26 -0
  227. package/src/core/synchronizeNativeLayer.js +35 -0
  228. package/src/core/textureFor.js +48 -0
  229. package/src/core/tooltipGetEvents.js +5 -0
  230. package/src/core/tooltipSetPosition.js +8 -0
  231. package/src/core/updateGridOpacity.js +23 -0
  232. package/src/core/updateNativeLayerView.js +6 -0
  233. package/src/core/uploadCanvasTexture.js +19 -0
  234. package/src/geometry/addBridges.js +88 -0
  235. package/src/geometry/below.js +3 -0
  236. package/src/geometry/box.js +3 -0
  237. package/src/geometry/bridgeElevation.js +19 -0
  238. package/src/geometry/bridgeLocal.js +4 -0
  239. package/src/geometry/build.js +19 -0
  240. package/src/geometry/circleAt.js +5 -0
  241. package/src/geometry/clipLine.js +23 -0
  242. package/src/geometry/clipSegment.js +19 -0
  243. package/src/geometry/computeBounds.js +33 -0
  244. package/src/geometry/conformModelToTerrain.js +67 -0
  245. package/src/geometry/cross.js +3 -0
  246. package/src/geometry/disk.js +11 -0
  247. package/src/geometry/diskAt.js +4 -0
  248. package/src/geometry/dot.js +6 -0
  249. package/src/geometry/emitter.js +8 -0
  250. package/src/geometry/lampPostGeometry.js +24 -0
  251. package/src/geometry/lampRing.js +11 -0
  252. package/src/geometry/lightGeometry.js +15 -0
  253. package/src/geometry/line.js +54 -0
  254. package/src/geometry/nativeGeometry.js +55 -0
  255. package/src/geometry/nativeTriangle.js +3 -0
  256. package/src/geometry/polygon.js +22 -0
  257. package/src/geometry/push.js +3 -0
  258. package/src/geometry/quad.js +4 -0
  259. package/src/geometry/roofCoverage.js +52 -0
  260. package/src/geometry/samePoint.js +3 -0
  261. package/src/geometry/segment.js +21 -0
  262. package/src/geometry/setVertexColor.js +15 -0
  263. package/src/geometry/sub.js +6 -0
  264. package/src/geometry/surface.js +17 -0
  265. package/src/geometry/treeGeometry.js +31 -0
  266. package/src/geometry/treeRing.js +14 -0
  267. package/src/geometry/triangle.js +12 -0
  268. package/src/geometry/vertexNormals.js +32 -0
  269. package/src/geometry/visit.js +9 -0
  270. package/src/index.js +98 -65
  271. package/src/lighting/cacheLightGrid.js +23 -0
  272. package/src/lighting/collectLightMeshes.js +6 -0
  273. package/src/lighting/lightGrid.js +42 -0
  274. package/src/lighting/updatePointLights.js +34 -0
  275. package/src/lighting/visitCells.js +15 -0
  276. package/src/lighting/worldLights.js +27 -0
  277. package/src/models/decodeModel.js +45 -0
  278. package/src/models/hasUnsupportedPrimitives.js +10 -0
  279. package/src/models/loadBuffer.js +6 -0
  280. package/src/models/loadImage.js +15 -0
  281. package/src/models/loadModel.js +69 -0
  282. package/src/models/materialFor.js +21 -0
  283. package/src/models/modelNode.js +93 -0
  284. package/src/models/nodeMatrix.js +22 -0
  285. package/src/models/readAccessor.js +53 -0
  286. package/src/models/readAccessorValues.js +16 -0
  287. package/src/models/textureFor.js +35 -0
  288. package/src/models/textureSampler.js +10 -0
  289. package/src/picking/collectVisibleMesh.js +4 -0
  290. package/src/picking/findFeature.js +49 -0
  291. package/src/picking/hit.js +23 -0
  292. package/src/picking/hitMesh.js +30 -0
  293. package/src/picking/onClick.js +13 -0
  294. package/src/picking/onPointerLeave.js +11 -0
  295. package/src/picking/onPointerMove.js +15 -0
  296. package/src/picking/pointerClick.js +5 -0
  297. package/src/picking/pointerLeave.js +5 -0
  298. package/src/picking/pointerMove.js +5 -0
  299. package/src/picking/raycast.js +59 -0
  300. package/src/picking/setHighlight.js +13 -0
  301. package/src/picking/shouldSkipOther.js +3 -0
  302. package/src/picking/showFeature.js +34 -0
  303. package/src/raster/addRasterTile.js +114 -0
  304. package/src/raster/comparePendingTiles.js +5 -0
  305. package/src/raster/createGeometry.js +22 -0
  306. package/src/raster/createRasterMesh.js +47 -0
  307. package/src/raster/finishAttachment.js +11 -0
  308. package/src/raster/finishRasterTile.js +47 -0
  309. package/src/raster/getRasterEvents.js +6 -0
  310. package/src/raster/getRasterTileSize.js +5 -0
  311. package/src/raster/initRaster.js +38 -0
  312. package/src/raster/isLoading.js +5 -0
  313. package/src/raster/loadRasterTile.js +10 -0
  314. package/src/raster/onPMTileAdd.js +10 -0
  315. package/src/raster/onPMTileRemove.js +8 -0
  316. package/src/raster/pruneRasterTiles.js +37 -0
  317. package/src/raster/pumpRasterTiles.js +22 -0
  318. package/src/raster/readyRaster.js +13 -0
  319. package/src/raster/registerTerrainTile.js +12 -0
  320. package/src/raster/releaseRasterTile.js +18 -0
  321. package/src/raster/releaseRasterTiles.js +15 -0
  322. package/src/raster/removeRasterTile.js +13 -0
  323. package/src/raster/reportError.js +6 -0
  324. package/src/raster/setPMTileOpacity.js +7 -0
  325. package/src/raster/setPMTileZIndex.js +7 -0
  326. package/src/raster/setRasterOpacity.js +11 -0
  327. package/src/raster/setRasterTerrain.js +21 -0
  328. package/src/raster/setRasterZIndex.js +11 -0
  329. package/src/raster/updateAttachedTiles.js +10 -0
  330. package/src/raster/updateRasterTiles.js +59 -0
  331. package/src/rendering/collectFrameMeshes.js +31 -0
  332. package/src/rendering/collectMeshes.js +36 -0
  333. package/src/rendering/compareMeshes.js +10 -0
  334. package/src/rendering/compareRoofTiles.js +4 -0
  335. package/src/rendering/composeRoofAtlas.js +52 -0
  336. package/src/rendering/createMesh.js +33 -0
  337. package/src/rendering/createProgram.js +92 -0
  338. package/src/rendering/destroyAfterSubmission.js +8 -0
  339. package/src/rendering/destroyTexture.js +6 -0
  340. package/src/rendering/disposeMesh.js +14 -0
  341. package/src/rendering/drawGeometry.js +129 -0
  342. package/src/rendering/drawSceneMeshes.js +51 -0
  343. package/src/rendering/ensureRoofBlit.js +40 -0
  344. package/src/rendering/prepareFrameMeshes.js +42 -0
  345. package/src/rendering/prepareFrameUniforms.js +49 -0
  346. package/src/rendering/rebuildRoofAtlas.js +67 -0
  347. package/src/rendering/render.js +57 -0
  348. package/src/rendering/reportCompilation.js +17 -0
  349. package/src/rendering/resizeRenderer.js +19 -0
  350. package/src/rendering/sortMeshes.js +6 -0
  351. package/src/rendering/synchronizeZoomView.js +34 -0
  352. package/src/rendering/textureBinding.js +7 -0
  353. package/src/rendering/updateMapCamera.js +32 -0
  354. package/src/rendering/updateRoofRaster.js +32 -0
  355. package/src/scene/attach.js +161 -0
  356. package/src/scene/attachLayer.js +10 -0
  357. package/src/scene/cancelUpdate.js +10 -0
  358. package/src/scene/emptyEvents.js +3 -0
  359. package/src/scene/emptyNode.js +11 -0
  360. package/src/scene/endZoom.js +16 -0
  361. package/src/scene/failAttachment.js +9 -0
  362. package/src/scene/get3DEvents.js +13 -0
  363. package/src/scene/init3D.js +30 -0
  364. package/src/scene/initializeLayer.js +16 -0
  365. package/src/scene/initializerFor.js +14 -0
  366. package/src/scene/layerInitialize.js +38 -0
  367. package/src/scene/layerLayerAdd.js +21 -0
  368. package/src/scene/onAdd3DLayer.js +35 -0
  369. package/src/scene/onMapChange.js +16 -0
  370. package/src/scene/onRemove3DLayer.js +69 -0
  371. package/src/scene/onZoomAnim.js +16 -0
  372. package/src/scene/placeEntry.js +11 -0
  373. package/src/scene/placeUnderEntry.js +8 -0
  374. package/src/scene/ready3D.js +25 -0
  375. package/src/scene/releaseRenderer.js +14 -0
  376. package/src/scene/removeEntry.js +6 -0
  377. package/src/scene/renderPendingMapChange.js +11 -0
  378. package/src/scene/renderPendingUpdates.js +19 -0
  379. package/src/scene/renderPendingZoomAnimation.js +7 -0
  380. package/src/scene/rendererDeviceError.js +10 -0
  381. package/src/scene/rendererDeviceLost.js +11 -0
  382. package/src/scene/replaceEntry.js +7 -0
  383. package/src/scene/reportError.js +3 -0
  384. package/src/scene/requestAdapter.js +12 -0
  385. package/src/scene/requestDevice.js +9 -0
  386. package/src/scene/resolveNextInitialization.js +12 -0
  387. package/src/scene/restoreObject.js +71 -0
  388. package/src/scene/runPlacements.js +7 -0
  389. package/src/scene/setParent.js +7 -0
  390. package/src/scene/showWebGPUWarning.js +16 -0
  391. package/src/scene/startZoom.js +5 -0
  392. package/src/scene/traverse.js +7 -0
  393. package/src/scene/underEntry.js +17 -0
  394. package/src/scene/update.js +19 -0
  395. package/src/scene/updateCamera.js +34 -0
  396. package/src/scene/updateWorldMatrix.js +48 -0
  397. package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
  398. package/src/shadows/bindSunlight.js +12 -0
  399. package/src/shadows/drawShadowMeshes.js +48 -0
  400. package/src/shadows/ensureShadowPipeline.js +53 -0
  401. package/src/shadows/renderSunlight.js +46 -0
  402. package/src/shadows/resizeSunlight.js +15 -0
  403. package/src/shadows/shadowBounds.js +32 -0
  404. package/src/shadows/shadowCacheMatches.js +23 -0
  405. package/src/shadows/shadowMatrix.js +39 -0
  406. package/src/sources/addGeneratedTriangle.js +6 -0
  407. package/src/sources/addTriangle.js +17 -0
  408. package/src/sources/attachAreaMesh.js +58 -0
  409. package/src/sources/buildArea.js +42 -0
  410. package/src/sources/buildAreaFeature.js +41 -0
  411. package/src/sources/buildAreaPoint.js +25 -0
  412. package/src/sources/buildAreaPolygon.js +29 -0
  413. package/src/sources/compareAreaDistance.js +4 -0
  414. package/src/sources/generateTreeGeometry.js +11 -0
  415. package/src/sources/groundOffset.js +3 -0
  416. package/src/sources/initializeGeoJSON.js +8 -0
  417. package/src/sources/instanceAreaGeometry.js +29 -0
  418. package/src/sources/projectRing.js +20 -0
  419. package/src/sources/projectedTree.js +13 -0
  420. package/src/sources/pump.js +54 -0
  421. package/src/sources/releaseArea.js +22 -0
  422. package/src/sources/setGeoJSONData.js +12 -0
  423. package/src/sources/setGeoJSONLayerData.js +5 -0
  424. package/src/sources/sourceAreaContext.js +9 -0
  425. package/src/sources/updateArea.js +45 -0
  426. package/src/sources/updateStatus.js +12 -0
  427. package/src/sunlight/addTimeLayer.js +3 -0
  428. package/src/sunlight/addTo.js +10 -0
  429. package/src/sunlight/atmosphere.js +28 -0
  430. package/src/sunlight/horizontalPosition.js +16 -0
  431. package/src/sunlight/initSunlight.js +14 -0
  432. package/src/sunlight/initialize.js +11 -0
  433. package/src/sunlight/mix.js +6 -0
  434. package/src/sunlight/moonPosition.js +17 -0
  435. package/src/sunlight/onAdd.js +5 -0
  436. package/src/sunlight/onAddSun.js +66 -0
  437. package/src/sunlight/projectCelestialBody.js +13 -0
  438. package/src/sunlight/remove.js +7 -0
  439. package/src/sunlight/removeSun.js +15 -0
  440. package/src/sunlight/removeTimeLayer.js +3 -0
  441. package/src/sunlight/render.js +7 -0
  442. package/src/sunlight/rgb.js +6 -0
  443. package/src/sunlight/solarPosition.js +17 -0
  444. package/src/sunlight/styleTimeControl.js +7 -0
  445. package/src/sunlight/tickSun.js +5 -0
  446. package/src/sunlight/updateSky.js +20 -0
  447. package/src/sunlight/updateSun.js +34 -0
  448. package/src/sunlight/useLiveTime.js +6 -0
  449. package/src/sunlight/useSelectedTime.js +20 -0
  450. package/src/terrain/clearLayerTerrain.js +5 -0
  451. package/src/terrain/getElevation.js +10 -0
  452. package/src/terrain/initTerrain.js +20 -0
  453. package/src/terrain/loadReadyTerrain.js +5 -0
  454. package/src/terrain/loadTerrain.js +63 -0
  455. package/src/terrain/loadTerrainTiles.js +13 -0
  456. package/src/terrain/onTerrainAdd.js +21 -0
  457. package/src/terrain/onTerrainChange.js +14 -0
  458. package/src/terrain/onTerrainRemove.js +41 -0
  459. package/src/terrain/readBridges.js +4 -0
  460. package/src/terrain/sample.js +7 -0
  461. package/src/terrain/setLayerTerrain.js +5 -0
  462. package/src/terrain/setTerrainHeight.js +10 -0
  463. package/src/terrain/terrainAtlas.js +23 -0
  464. package/src/terrain/terrainElevation.js +20 -0
  465. package/src/terrain/terrainGrid.js +24 -0
  466. package/src/traffic/addTraffic.js +7 -0
  467. package/src/traffic/along.js +14 -0
  468. package/src/traffic/clockMinutes.js +6 -0
  469. package/src/traffic/compareDepartures.js +5 -0
  470. package/src/traffic/createTrafficMesh.js +7 -0
  471. package/src/traffic/destroyTrafficGpu.js +5 -0
  472. package/src/traffic/disposeTrafficObject.js +13 -0
  473. package/src/traffic/drawTrafficRoute.js +6 -0
  474. package/src/traffic/failTraffic.js +6 -0
  475. package/src/traffic/failedTrafficLoad.js +5 -0
  476. package/src/traffic/fetchTrafficLanes.js +10 -0
  477. package/src/traffic/groundTraffic.js +15 -0
  478. package/src/traffic/initTraffic.js +54 -0
  479. package/src/traffic/loadTraffic.js +15 -0
  480. package/src/traffic/loadedTrafficLanes.js +16 -0
  481. package/src/traffic/locateTraffic.js +9 -0
  482. package/src/traffic/moveTraffic.js +15 -0
  483. package/src/traffic/placeTraffic.js +21 -0
  484. package/src/traffic/prepareTraffic.js +25 -0
  485. package/src/traffic/readyTraffic.js +6 -0
  486. package/src/traffic/rebaseTraffic.js +58 -0
  487. package/src/traffic/rebuildTrafficMesh.js +28 -0
  488. package/src/traffic/removeTraffic.js +17 -0
  489. package/src/traffic/routeColor.js +6 -0
  490. package/src/traffic/routeGeometry.js +31 -0
  491. package/src/traffic/scheduledTrips.js +40 -0
  492. package/src/traffic/startTraffic.js +8 -0
  493. package/src/traffic/tickTraffic.js +57 -0
  494. package/src/traffic/toLanes.js +16 -0
  495. package/src/traffic/tooltip.js +11 -0
  496. package/src/traffic/trafficBounds.js +17 -0
  497. package/src/traffic/trafficNow.js +4 -0
  498. package/src/traffic/trafficStorage.js +5 -0
  499. package/src/traffic/tripsAt.js +27 -0
  500. package/src/traffic/updateTraffic.js +8 -0
  501. package/src/traffic/updateTrafficTerrain.js +12 -0
  502. package/src/traffic/vehicleOffsets.js +11 -0
  503. package/src/triangulation/area.js +9 -0
  504. package/src/triangulation/clean.js +18 -0
  505. package/src/triangulation/containsVertex.js +11 -0
  506. package/src/triangulation/cross.js +3 -0
  507. package/src/triangulation/crossesBoundary.js +8 -0
  508. package/src/triangulation/crossesRing.js +9 -0
  509. package/src/triangulation/equal.js +3 -0
  510. package/src/triangulation/inside.js +10 -0
  511. package/src/triangulation/insideHole.js +7 -0
  512. package/src/triangulation/intersects.js +11 -0
  513. package/src/triangulation/isClockWise.js +13 -0
  514. package/src/triangulation/minimumX.js +6 -0
  515. package/src/triangulation/on.js +4 -0
  516. package/src/triangulation/sortHoles.js +26 -0
  517. package/src/triangulation/triangulate.js +86 -0
  518. package/src/utils/channel.js +4 -0
  519. package/src/utils/compareDistance.js +3 -0
  520. package/src/utils/noOperation.js +1 -0
  521. package/src/utils/parseColor.js +42 -0
  522. package/src/utils/toSRGB.js +3 -0
  523. package/src/utils/wrap.js +3 -0
  524. package/src/vehicles/bicycleModel.js +23 -0
  525. package/src/vehicles/boatBenches.js +8 -0
  526. package/src/vehicles/boatModel.js +27 -0
  527. package/src/vehicles/busModel.js +6 -0
  528. package/src/vehicles/carModel.js +22 -0
  529. package/src/vehicles/carriage.js +19 -0
  530. package/src/vehicles/metroModel.js +9 -0
  531. package/src/vehicles/mirror.js +8 -0
  532. package/src/vehicles/pedestrianModel.js +17 -0
  533. package/src/vehicles/tramModel.js +9 -0
  534. package/src/walk/blocked.js +6 -0
  535. package/src/walk/createWalk.js +60 -0
  536. package/src/walk/initWalk.js +18 -0
  537. package/src/walk/initialize.js +6 -0
  538. package/src/walk/local.js +10 -0
  539. package/src/walk/onAdd.js +4 -0
  540. package/src/walk/onBlur.js +3 -0
  541. package/src/walk/onKey.js +12 -0
  542. package/src/walk/onPointer.js +13 -0
  543. package/src/walk/onRemove.js +4 -0
  544. package/src/walk/onTerrain.js +5 -0
  545. package/src/walk/place.js +18 -0
  546. package/src/walk/start.js +37 -0
  547. package/src/walk/step.js +53 -0
  548. package/src/walk/stop.js +27 -0
  549. package/src/walk/toggle.js +6 -0
  550. package/dist/scene/gpu.js +0 -3
  551. package/dist/scene/gpu.js.map +0 -7
  552. package/dist/scene/lighting.js +0 -9
  553. package/dist/scene/lighting.js.map +0 -7
  554. package/dist/scene/model.js +0 -2
  555. package/dist/scene/model.js.map +0 -7
  556. package/dist/scene/picking.js +0 -2
  557. package/dist/scene/picking.js.map +0 -7
  558. package/dist/scene/pmtiles.js +0 -2
  559. package/dist/scene/pmtiles.js.map +0 -7
  560. package/dist/scene/render.js +0 -15
  561. package/dist/scene/render.js.map +0 -7
  562. package/dist/scene/sources.js +0 -2
  563. package/dist/scene/sources.js.map +0 -7
  564. package/dist/types/3d.js +0 -2
  565. package/dist/types/3d.js.map +0 -7
  566. package/dist/types/geojson.js +0 -2
  567. package/dist/types/geojson.js.map +0 -7
  568. package/dist/types/pmtiles.js +0 -2
  569. package/dist/types/pmtiles.js.map +0 -7
  570. package/dist/types/sunlight.js +0 -2
  571. package/dist/types/sunlight.js.map +0 -7
  572. package/dist/types/terrain.js +0 -24
  573. package/dist/types/terrain.js.map +0 -7
  574. package/dist/types/traffic.js +0 -41
  575. package/dist/types/traffic.js.map +0 -7
  576. package/dist/types/walk.js +0 -2
  577. package/dist/types/walk.js.map +0 -7
  578. package/dist/utils/control.js +0 -2
  579. package/dist/utils/control.js.map +0 -7
  580. package/dist/utils/geometry.js +0 -2
  581. package/dist/utils/geometry.js.map +0 -7
  582. package/dist/utils/lighting.js +0 -2
  583. package/dist/utils/lighting.js.map +0 -7
  584. package/dist/utils/model.js +0 -2
  585. package/dist/utils/model.js.map +0 -7
  586. package/dist/utils/picking.js +0 -2
  587. package/dist/utils/picking.js.map +0 -7
  588. package/dist/utils/pmtiles.js +0 -2
  589. package/dist/utils/pmtiles.js.map +0 -7
  590. package/dist/utils/scene.js +0 -2
  591. package/dist/utils/scene.js.map +0 -7
  592. package/dist/utils/shaders.js +0 -203
  593. package/dist/utils/shaders.js.map +0 -7
  594. package/dist/utils/sun.js +0 -2
  595. package/dist/utils/sun.js.map +0 -7
  596. package/dist/utils/terrain.js +0 -2
  597. package/dist/utils/terrain.js.map +0 -7
  598. package/dist/utils/traffic.js +0 -2
  599. package/dist/utils/traffic.js.map +0 -7
  600. package/dist/utils/vehicles.js +0 -2
  601. package/dist/utils/vehicles.js.map +0 -7
  602. package/dist/utils/walk.js +0 -2
  603. package/dist/utils/walk.js.map +0 -7
  604. package/src/scene/gpu.js +0 -438
  605. package/src/scene/lighting.js +0 -193
  606. package/src/scene/model.js +0 -204
  607. package/src/scene/picking.js +0 -150
  608. package/src/scene/pmtiles.js +0 -94
  609. package/src/scene/render.js +0 -467
  610. package/src/scene/sources.js +0 -265
  611. package/src/types/3d.js +0 -337
  612. package/src/types/geojson.js +0 -42
  613. package/src/types/pmtiles.js +0 -143
  614. package/src/types/sunlight.js +0 -142
  615. package/src/types/terrain.js +0 -331
  616. package/src/types/traffic.js +0 -356
  617. package/src/types/walk.js +0 -219
  618. package/src/utils/control.js +0 -18
  619. package/src/utils/geometry.js +0 -256
  620. package/src/utils/lighting.js +0 -51
  621. package/src/utils/model.js +0 -178
  622. package/src/utils/picking.js +0 -119
  623. package/src/utils/pmtiles.js +0 -79
  624. package/src/utils/scene.js +0 -102
  625. package/src/utils/sun.js +0 -71
  626. package/src/utils/terrain.js +0 -78
  627. package/src/utils/traffic.js +0 -90
  628. package/src/utils/vehicles.js +0 -69
  629. package/src/utils/walk.js +0 -72
@@ -0,0 +1,16 @@
1
+ // GeoJSON (Multi)LineStrings become lanes ({latlngs, properties, elevation?}); prepare() adds `points` ([x, z, ground]),
2
+ // `lengths` and `length` in layer-local metres.
3
+
4
+ export function toLanes({ features = [] }) {
5
+ const lanes = [];
6
+ let geometry, properties, lines, line, latlngs, lng, lat;
7
+ for ({ geometry, properties } of features) {
8
+ lines = geometry?.type === 'LineString' ? [geometry.coordinates] : geometry?.type === 'MultiLineString' ? geometry.coordinates : [];
9
+ for (line of lines) {
10
+ latlngs = [];
11
+ for ([lng, lat] of line) latlngs.push([lat, lng]);
12
+ lanes.push({ latlngs, properties: properties ?? {}, elevation: properties?.elevation });
13
+ }
14
+ }
15
+ return lanes;
16
+ }
@@ -0,0 +1,11 @@
1
+ export function tooltip({ properties: p }) {
2
+ const content = document.createElement('div');
3
+ content.style.whiteSpace = 'pre-line';
4
+ const lines = [];
5
+ let line;
6
+ for (line of [p.name, p.departure && `Departure ${p.departure} ${p.timetable.timeZone}`, p.description]) {
7
+ if (line) lines.push(line);
8
+ }
9
+ content.textContent = lines.join('\n');
10
+ return content;
11
+ }
@@ -0,0 +1,17 @@
1
+ import { computeBounds } from '../geometry/computeBounds.js';
2
+
3
+ export function trafficBounds(state) {
4
+ let radius = 20, height = 5;
5
+ let i, lane, x, z, y;
6
+ for (i = 0; i < state.template.position.length; i += 3) {
7
+ radius = Math.max(radius, Math.hypot(state.template.position[i], state.template.position[i + 2]) + Math.abs(state.side));
8
+ height = Math.max(height, state.template.position[i + 1]);
9
+ }
10
+ const data = [];
11
+ for (lane of state.lanes) {
12
+ for ([x, z, y] of lane.points) data.push(x - radius, y, z - radius, x + radius, y + height, z + radius);
13
+ }
14
+ const extent = { attributes: { position: { data } } };
15
+ computeBounds(extent);
16
+ state.mesh.geometry.bounds = extent.bounds;
17
+ }
@@ -0,0 +1,4 @@
1
+ export function trafficNow(state) {
2
+ const control = state.layer._map?._timeControl || { live: true };
3
+ return { live: control.live, time: control.live ? new Date() : control.time };
4
+ }
@@ -0,0 +1,5 @@
1
+ export function trafficStorage(device, data) {
2
+ const buffer = device.createBuffer({ size: Math.max(16, data.byteLength), usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST });
3
+ device.queue.writeBuffer(buffer, 0, data);
4
+ return buffer;
5
+ }
@@ -0,0 +1,27 @@
1
+ import { vehicleOffsets } from "./vehicleOffsets.js";
2
+ import { scheduledTrips } from "./scheduledTrips.js";
3
+
4
+ // A lane with a `timetable` runs scheduled trips end to end; one with a `flow` (vehicles/h) loops evenly spaced vehicles.
5
+
6
+ export function tripsAt(time, lanes, velocity) {
7
+ const trips = [];
8
+ let l, lane, timetable, flow, trip, travelled, offsets, k;
9
+ for (l = 0; l < lanes.length; l++) {
10
+ lane = lanes[l];
11
+ ({ timetable, flow = 0 } = lane.properties);
12
+ if (!lane.length) continue;
13
+ if (timetable) {
14
+ for (trip of scheduledTrips(time, timetable)) trips.push({
15
+ id: `${l}-${trip.id}`, lane, distance: trip.progress * lane.length, speed: lane.length / (timetable.duration * 60),
16
+ properties: { ...lane.properties, departure: trip.departure },
17
+ });
18
+ } else {
19
+ travelled = time / 1000 * velocity;
20
+ offsets = lane.offsets ||= vehicleOffsets(lane.length, flow, velocity);
21
+ for (k = 0; k < offsets.length; k++) trips.push({
22
+ id: `${l}-${k}`, lane, distance: (offsets[k] + travelled) % lane.length, speed: velocity, properties: lane.properties,
23
+ });
24
+ }
25
+ }
26
+ return trips;
27
+ }
@@ -0,0 +1,8 @@
1
+ import { loadTraffic } from './loadTraffic.js';
2
+
3
+ export function updateTraffic(state, event) {
4
+ if (event?.layer && !event.layer.control?.time) return;
5
+ cancelAnimationFrame(state.frame);
6
+ loadTraffic(state);
7
+ state.tick();
8
+ }
@@ -0,0 +1,12 @@
1
+ import { disposeTrafficObject } from './disposeTrafficObject.js';
2
+ import { groundTraffic } from './groundTraffic.js';
3
+ import { trafficBounds } from './trafficBounds.js';
4
+
5
+ export function updateTrafficTerrain(state) {
6
+ if (!state.lanes.length) return;
7
+ groundTraffic(state);
8
+ disposeTrafficObject(state, state.route);
9
+ state.route = null;
10
+ if (state.mesh) trafficBounds(state);
11
+ if (!state.frame) state.tick();
12
+ }
@@ -0,0 +1,11 @@
1
+ import { speed } from "../constants/speed.js";
2
+
3
+ /** Evenly spaced starting offsets (metres) for `flow` vehicles/h moving at `velocity` m/s on a `length` metres lane. */
4
+
5
+ export function vehicleOffsets(length, flow, velocity = speed) {
6
+ const count = Math.round(length * flow / 3600 / velocity);
7
+ const offsets = Array.from({ length: count });
8
+ let i;
9
+ for (i = 0; i < offsets.length; i++) offsets[i] = (i + 0.5) * length / count;
10
+ return offsets;
11
+ }
@@ -0,0 +1,9 @@
1
+ export function area(ring) {
2
+ let sum = 0;
3
+ let i, p, q;
4
+ for (i = 0; i < ring.length; i++) {
5
+ p = ring[i], q = ring[(i + 1) % ring.length];
6
+ sum += p.x * q.y - q.x * p.y;
7
+ }
8
+ return Math.abs(sum) / 2;
9
+ }
@@ -0,0 +1,18 @@
1
+ import { cross } from './cross.js';
2
+ import { equal } from './equal.js';
3
+
4
+ export function clean(ring) {
5
+ let changed = true;
6
+ let i, a, b, c;
7
+ while (changed && ring.length > 3) {
8
+ changed = false;
9
+ for (i = 0; i < ring.length; i++) {
10
+ a = ring[(i + ring.length - 1) % ring.length], b = ring[i], c = ring[(i + 1) % ring.length];
11
+ if (equal(a, b) || Math.abs(cross(a, b, c)) < 1e-10) {
12
+ ring.splice(i, 1); changed = true; break;
13
+ }
14
+ }
15
+ }
16
+ if (ring.length < 3) throw new Error('Degenerate polygon ring');
17
+ return ring;
18
+ }
@@ -0,0 +1,11 @@
1
+ import { equal } from './equal.js';
2
+ import { cross } from './cross.js';
3
+
4
+ export function containsVertex(polygon, a, b, c) {
5
+ let p;
6
+ for (p of polygon) {
7
+ if (!equal(p, a) && !equal(p, b) && !equal(p, c) &&
8
+ cross(a, b, p) >= 0 && cross(b, c, p) >= 0 && cross(c, a, p) >= 0) return true;
9
+ }
10
+ return false;
11
+ }
@@ -0,0 +1,3 @@
1
+ export function cross(a, b, c) {
2
+ return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
3
+ }
@@ -0,0 +1,8 @@
1
+ import { crossesRing } from './crossesRing.js';
2
+
3
+ export function crossesBoundary(a, b, polygon, rings) {
4
+ if (crossesRing(a, b, polygon)) return true;
5
+ let i;
6
+ for (i = 1; i < rings.length; i++) if (crossesRing(a, b, rings[i])) return true;
7
+ return false;
8
+ }
@@ -0,0 +1,9 @@
1
+ import { intersects } from './intersects.js';
2
+
3
+ export function crossesRing(a, b, ring) {
4
+ let i;
5
+ for (i = 0; i < ring.length; i++) {
6
+ if (intersects(a, b, ring[i], ring[(i + 1) % ring.length])) return true;
7
+ }
8
+ return false;
9
+ }
@@ -0,0 +1,3 @@
1
+ export function equal(a, b) {
2
+ return a.x === b.x && a.y === b.y;
3
+ }
@@ -0,0 +1,10 @@
1
+ export function inside(point, ring) {
2
+ let result = false;
3
+ let i, j, a, b;
4
+ for (i = 0, j = ring.length - 1; i < ring.length; j = i++) {
5
+ a = ring[i], b = ring[j];
6
+ if ((a.y > point.y) !== (b.y > point.y) &&
7
+ point.x < (b.x - a.x) * (point.y - a.y) / (b.y - a.y) + a.x) result = !result;
8
+ }
9
+ return result;
10
+ }
@@ -0,0 +1,7 @@
1
+ import { inside } from './inside.js';
2
+
3
+ export function insideHole(point, rings) {
4
+ let i;
5
+ for (i = 1; i < rings.length; i++) if (inside(point, rings[i])) return true;
6
+ return false;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { equal } from './equal.js';
2
+ import { cross } from './cross.js';
3
+ import { on } from './on.js';
4
+
5
+ export function intersects(a, b, c, d) {
6
+ if (equal(a, c) || equal(a, d) || equal(b, c) || equal(b, d)) return false;
7
+ const abC = cross(a, b, c), abD = cross(a, b, d), cdA = cross(c, d, a), cdB = cross(c, d, b);
8
+ return abC * abD < 0 && cdA * cdB < 0 ||
9
+ abC === 0 && on(a, b, c) || abD === 0 && on(a, b, d) ||
10
+ cdA === 0 && on(c, d, a) || cdB === 0 && on(c, d, b);
11
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @returns {boolean} Whether the `{x, y}` points are in clockwise order.
3
+ */
4
+
5
+ export function isClockWise(points) {
6
+ let area = 0;
7
+ let i, a, b;
8
+ for (i = 0; i < points.length; i++) {
9
+ a = points[i], b = points[(i + 1) % points.length];
10
+ area += a.x * b.y - b.x * a.y;
11
+ }
12
+ return area < 0;
13
+ }
@@ -0,0 +1,6 @@
1
+ export function minimumX(ring) {
2
+ const values = [];
3
+ let point;
4
+ for (point of ring) values.push(point.x);
5
+ return Math.min(...values);
6
+ }
@@ -0,0 +1,4 @@
1
+ export function on(p, q, r) {
2
+ return Math.min(p.x, q.x) <= r.x && r.x <= Math.max(p.x, q.x) &&
3
+ Math.min(p.y, q.y) <= r.y && r.y <= Math.max(p.y, q.y);
4
+ }
@@ -0,0 +1,26 @@
1
+ import { minimumX } from './minimumX.js';
2
+
3
+ export function sortHoles(holes) {
4
+ const buffer = new Array(holes.length), entries = [];
5
+ let ring, width, start, middle, end, left, right, output, previous, i;
6
+ for (ring of holes) entries.push({ ring, x: minimumX(ring) });
7
+ let source = entries, target = buffer;
8
+ for (width = 1; width < entries.length; width *= 2) {
9
+ for (start = 0; start < entries.length; start += width * 2) {
10
+ middle = Math.min(start + width, entries.length), end = Math.min(start + width * 2, entries.length);
11
+ left = start, right = middle;
12
+ for (output = start; output < end; output++) {
13
+ if (left < middle && (right >= end || source[left].x <= source[right].x)) {
14
+ target[output] = source[left++];
15
+ } else {
16
+ target[output] = source[right++];
17
+ }
18
+ }
19
+ }
20
+ previous = source;
21
+ source = target;
22
+ target = previous;
23
+ }
24
+ for (i = 0; i < holes.length; i++) holes[i] = source[i].ring;
25
+ return holes;
26
+ }
@@ -0,0 +1,86 @@
1
+ import { isClockWise } from "./isClockWise.js";
2
+ import { cross } from './cross.js';
3
+ import { clean } from './clean.js';
4
+ import { inside } from './inside.js';
5
+ import { insideHole } from './insideHole.js';
6
+ import { crossesBoundary } from './crossesBoundary.js';
7
+ import { containsVertex } from './containsVertex.js';
8
+ import { area } from './area.js';
9
+ import { sortHoles } from './sortHoles.js';
10
+
11
+ /**
12
+ * Triangulates a polygon given as `{x, y}` points.
13
+ * Rings omit the repeated closing point; winding is normalized internally.
14
+ * Vertex indices remain relative to the original inputs after duplicate/collinear
15
+ * cleanup. Hole bridges duplicate endpoints, not source vertices.
16
+ * @param {Object[]} contour Outer boundary.
17
+ * @param {Object[][]} [holes] Interior boundaries.
18
+ *
19
+ * @returns {number[][]} Triangles as indices in `[...contour, ...holes.flat()]`.
20
+ */
21
+
22
+ export function triangulate(contour, holes = []) {
23
+ const points = [contour, ...holes].flat();
24
+ let p, index, path, ring, hole, bridge, distance, h, a, b, d, mid, h2, p2, clipped, i, c, triangle2;
25
+ for (p of points) {
26
+ if (!Number.isFinite(p.x) || !Number.isFinite(p.y)) throw new Error('Invalid polygon coordinates');
27
+ }
28
+ // Translate near the origin to avoid cancellation with geographic coordinates.
29
+ const vertices = [];
30
+ for (index = 0; index < points.length; index++) {
31
+ p = points[index];
32
+ vertices.push({ x: p.x - contour[0].x, y: p.y - contour[0].y, index });
33
+ }
34
+ // Remove zero-area corners before connecting holes; keep original vertex indices.
35
+ let offset = 0;
36
+ const rings = [], paths = [contour, ...holes];
37
+ for (index = 0; index < paths.length; index++) {
38
+ path = paths[index];
39
+ ring = clean(vertices.slice(offset, offset += path.length));
40
+ if (isClockWise(ring) !== Boolean(index)) ring.reverse();
41
+ rings.push(ring);
42
+ }
43
+ let polygon = rings[0].slice();
44
+ // A bridge must stay inside the outer boundary, outside every hole, and cross no edge.
45
+ // ponytail: quadratic ear clipping for building footprints; use spatial indexing for large rings.
46
+ const holesToConnect = sortHoles(rings.slice(1));
47
+ for (hole of holesToConnect) {
48
+ bridge = void 0, distance = Infinity;
49
+ for (h = 0; h < hole.length; h++) for (p = 0; p < polygon.length; p++) {
50
+ a = hole[h], b = polygon[p], d = (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
51
+ if (d >= distance) continue;
52
+ mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
53
+ if (!inside(mid, rings[0]) || insideHole(mid, rings)) continue;
54
+ if (crossesBoundary(a, b, polygon, rings)) continue;
55
+ bridge = [h, p]; distance = d;
56
+ }
57
+ if (!bridge) throw new Error('Unable to connect polygon hole');
58
+ [h2, p2] = bridge;
59
+ polygon = [...polygon.slice(0, p2 + 1), ...hole.slice(h2), ...hole.slice(0, h2 + 1),
60
+ polygon[p2], ...polygon.slice(p2 + 1)];
61
+ }
62
+ // Clip a convex corner only when no other vertex is inside/on its triangle.
63
+ const result = [];
64
+ while (polygon.length > 3) {
65
+ clipped = false;
66
+ for (i = 0; i < polygon.length; i++) {
67
+ a = polygon[(i + polygon.length - 1) % polygon.length], b = polygon[i], c = polygon[(i + 1) % polygon.length];
68
+ if (cross(a, b, c) <= 1e-10) continue;
69
+ if (containsVertex(polygon, a, b, c)) continue;
70
+ result.push([a.index, b.index, c.index]); polygon.splice(i, 1); clipped = true; break;
71
+ }
72
+ if (!clipped) throw new Error('Unable to triangulate polygon: invalid or self-intersecting rings');
73
+ }
74
+ if (cross(...polygon) > 1e-10) {
75
+ const triangle = [];
76
+ for (p of polygon) triangle.push(p.index);
77
+ result.push(triangle);
78
+ }
79
+ // Reject incomplete coverage instead of silently emitting a partial roof.
80
+ let holeArea = 0, actual = 0;
81
+ for (i = 1; i < rings.length; i++) holeArea += area(rings[i]);
82
+ const expected = area(rings[0]) - holeArea;
83
+ for (triangle2 of result) actual += cross(vertices[triangle2[0]], vertices[triangle2[1]], vertices[triangle2[2]]) / 2;
84
+ if (expected <= 0 || Math.abs(actual - expected) > Math.max(1e-7, expected * 1e-8)) throw new Error('Polygon triangulation area mismatch');
85
+ return result;
86
+ }
@@ -0,0 +1,4 @@
1
+ export function channel(n, h, l, a) {
2
+ const k = (n + h * 12) % 12;
3
+ return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
4
+ }
@@ -0,0 +1,3 @@
1
+ export function compareDistance(a, b) {
2
+ return a.distance - b.distance;
3
+ }
@@ -0,0 +1 @@
1
+ export function noOperation() {}
@@ -0,0 +1,42 @@
1
+ import { toSRGB } from "./toSRGB.js";
2
+ import { channel } from "./channel.js";
3
+
4
+ /**
5
+ * HSL inputs are linear-space to preserve the original building styling.
6
+ * Numeric/CSS/RGB inputs are already sRGB; CSS alpha is not used for extrusion.
7
+ * @param {number|string|Object} value 0xRRGGBB, CSS color, {r,g,b}, or {h,s,l} in 0..1.
8
+ * @returns {Object} sRGB {r,g,b} components in 0..1.
9
+ */
10
+
11
+ export function parseColor(value) {
12
+ if (value && typeof value === 'object' && 'h' in value) {
13
+ const a = value.s * Math.min(value.l, 1 - value.l);
14
+ return {
15
+ r: toSRGB(channel(0, value.h, value.l, a)),
16
+ g: toSRGB(channel(8, value.h, value.l, a)),
17
+ b: toSRGB(channel(4, value.h, value.l, a))
18
+ };
19
+ }
20
+ if (value && typeof value === 'object' && 'r' in value) {
21
+ return value;
22
+ }
23
+ if (typeof value === 'number') {
24
+ return {
25
+ r: (value >> 16 & 255) / 255,
26
+ g: (value >> 8 & 255) / 255,
27
+ b: (value & 255) / 255,
28
+ };
29
+ }
30
+ if (typeof value !== 'string' || !CSS.supports('color', value)) {
31
+ throw new Error('Invalid 3D color');
32
+ }
33
+ const context = document.createElement('canvas').getContext('2d');
34
+ context.fillStyle = value;
35
+ context.fillRect(0, 0, 1, 1);
36
+ const [r, g, b] = context.getImageData(0, 0, 1, 1).data;
37
+ return {
38
+ r: r / 255,
39
+ g: g / 255,
40
+ b: b / 255
41
+ };
42
+ }
@@ -0,0 +1,3 @@
1
+ export function toSRGB(value) {
2
+ return value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055;
3
+ }
@@ -0,0 +1,3 @@
1
+ export function wrap(angle) {
2
+ return Math.atan2(Math.sin(angle), Math.cos(angle));
3
+ }
@@ -0,0 +1,23 @@
1
+ import { box } from '../geometry/box.js';
2
+ import { skin } from '../constants/skin.js';
3
+ import { trousers } from '../constants/trousers.js';
4
+ import { dark } from '../constants/dark.js';
5
+ import { paints } from '../constants/paints.js';
6
+
7
+ export function bicycleModel(index) {
8
+ const paint = paints[index % paints.length];
9
+ return [
10
+ [box(-0.045, 0.045, -0.85, -0.25), 0.02, 0.62, dark],
11
+ [box(-0.045, 0.045, 0.25, 0.85), 0.02, 0.62, dark],
12
+ [box(-0.06, 0.06, -0.5, 0.5), 0.4, 0.65, paint],
13
+ [box(-0.32, 0.32, -0.58, -0.5), 0.95, 1.02, dark],
14
+ [box(-0.1, 0.1, 0.15, 0.4), 0.85, 0.92, dark],
15
+ [box(-0.18, 0.18, -0.12, 0.28), 1, 1.5, paint],
16
+ [box(-0.11, 0.11, -0.22, 0), 1.5, 1.72, skin],
17
+ [box(-0.13, 0.13, -0.23, 0.01), 1.72, 1.8, paint],
18
+ [box(-0.25, -0.15, -0.5, -0.05), 1, 1.25, skin],
19
+ [box(0.15, 0.25, -0.5, -0.05), 1, 1.25, skin],
20
+ [box(-0.2, -0.08, 0, 0.32), 0.3, 1, trousers],
21
+ [box(0.08, 0.2, -0.25, 0.07), 0.3, 1, trousers],
22
+ ];
23
+ }
@@ -0,0 +1,8 @@
1
+ import { mirror } from './mirror.js';
2
+
3
+ export function boatBenches() {
4
+ const benches = [];
5
+ let i;
6
+ for (i = 0; i < 12; i++) benches.push(...mirror(0.5, 3.8, -12 + i * 3, -11.3 + i * 3, 3.9, 4.4, [0.62, 0.1, 0.1]));
7
+ return benches;
8
+ }
@@ -0,0 +1,27 @@
1
+ import { hull } from '../constants/hull.js';
2
+ import { box } from '../geometry/box.js';
3
+ import { glass } from '../constants/glass.js';
4
+ import { mirror } from './mirror.js';
5
+ import { white } from '../constants/white.js';
6
+ import { boatBenches } from './boatBenches.js';
7
+
8
+ // Panoramic river cruiser, about 60 x 11 m.
9
+ export function boatModel() {
10
+ return [
11
+ [hull, 0, 0.8, [0.1, 0.16, 0.26]],
12
+ [hull, 0.8, 1.4, white],
13
+ [box(-5, 5, -18, 26), 1.4, 3.7, glass, box(-4.6, 4.6, -17.4, 25.6)],
14
+ ...mirror(4.64, 4.74, -17, 25, 3.25, 3.45, [1.6, 1.25, 0.8]),
15
+ [box(-4.8, 4.8, -17.8, 25.8), 3.7, 3.9, white],
16
+ ...boatBenches(),
17
+ ...mirror(4.65, 4.8, -13.6, 25.8, 3.9, 4.8, white),
18
+ [box(-4.8, 4.8, 25.65, 25.8), 3.9, 4.8, white],
19
+ [box(-2.2, 2.2, -17.6, -14), 3.9, 4.7, white],
20
+ [box(-2.2, 2.2, -17.6, -14), 4.7, 5.5, glass],
21
+ [box(-2.5, 2.5, -18, -13.6), 5.5, 5.7, white],
22
+ [box(-2.45, -2.2, -16.2, -15.8), 5, 5.3, [2, 0.15, 0.1]],
23
+ [box(2.2, 2.45, -16.2, -15.8), 5, 5.3, [0.1, 2, 0.4]],
24
+ [box(-0.1, 0.1, -15.9, -15.7), 5.7, 6.6, white],
25
+ [box(-0.15, 0.15, -15.95, -15.65), 6.6, 6.8, [2, 2, 1.9]],
26
+ ];
27
+ }
@@ -0,0 +1,6 @@
1
+ import { routeColor } from '../traffic/routeColor.js';
2
+ import { carriage } from './carriage.js';
3
+
4
+ export function busModel(index, properties) {
5
+ return carriage(0, 12, routeColor(properties));
6
+ }
@@ -0,0 +1,22 @@
1
+ import { box } from '../geometry/box.js';
2
+ import { glass } from '../constants/glass.js';
3
+ import { tyre } from '../constants/tyre.js';
4
+ import { mirror } from './mirror.js';
5
+ import { paints } from '../constants/paints.js';
6
+ import { headlight } from '../constants/headlight.js';
7
+ import { taillight } from '../constants/taillight.js';
8
+
9
+ export function carModel(i) {
10
+ const paint = paints[i % paints.length];
11
+ return [
12
+ ...mirror(0.7, 0.92, -1.68, -1.02, 0, 0.64, tyre),
13
+ ...mirror(0.7, 0.92, 1.02, 1.68, 0, 0.64, tyre),
14
+ [[[-0.9, -1.95], [-0.72, -2.25], [0.72, -2.25], [0.9, -1.95], [0.9, 2.05], [0.76, 2.25], [-0.76, 2.25], [-0.9, 2.05]],
15
+ 0.28, 0.82, paint],
16
+ // Greenhouse: the windscreen leans back, the rear window less.
17
+ [box(-0.84, 0.84, -0.75, 1.6), 0.82, 1.38, glass, box(-0.7, 0.7, -0.05, 1.3)],
18
+ [box(-0.71, 0.71, -0.06, 1.31), 1.38, 1.46, paint],
19
+ ...mirror(0.38, 0.8, -2.3, -2.16, 0.56, 0.76, headlight),
20
+ [box(-0.78, 0.78, 2.16, 2.3), 0.6, 0.76, taillight],
21
+ ];
22
+ }
@@ -0,0 +1,19 @@
1
+ import { box } from '../geometry/box.js';
2
+ import { glass } from '../constants/glass.js';
3
+ import { tyre } from '../constants/tyre.js';
4
+ import { white } from '../constants/white.js';
5
+ import { headlight } from '../constants/headlight.js';
6
+ import { taillight } from '../constants/taillight.js';
7
+
8
+ export function carriage(center, length, color) {
9
+ const front = center - length / 2, rear = center + length / 2;
10
+ return [
11
+ [box(-1.25, 1.25, front, rear), 0.45, 1.25, color],
12
+ [box(-1.2, 1.2, front + 0.15, rear - 0.15), 1.25, 2.65, glass],
13
+ [box(-1.25, 1.25, front, rear), 2.65, 3.1, white],
14
+ [box(-1.15, -0.85, front + 1, front + 2), 0, 0.7, tyre],
15
+ [box(0.85, 1.15, rear - 2, rear - 1), 0, 0.7, tyre],
16
+ [box(-0.9, 0.9, front - 0.03, front), 0.8, 1.05, headlight],
17
+ [box(-0.9, 0.9, rear, rear + 0.03), 0.8, 1.05, taillight],
18
+ ];
19
+ }
@@ -0,0 +1,9 @@
1
+ import { routeColor } from '../traffic/routeColor.js';
2
+ import { carriage } from './carriage.js';
3
+
4
+ export function metroModel(index, properties) {
5
+ const color = routeColor(properties), parts = [];
6
+ let car;
7
+ for (car = 0; car < 5; car++) parts.push(...carriage((car - 2) * 15, 14, color));
8
+ return parts;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { box } from "../geometry/box.js";
2
+
3
+ export function mirror(x0, x1, z0, z1, ...rest) {
4
+ return [
5
+ [box(x0, x1, z0, z1), ...rest],
6
+ [box(-x1, -x0, z0, z1), ...rest]
7
+ ];
8
+ }
@@ -0,0 +1,17 @@
1
+ import { box } from '../geometry/box.js';
2
+ import { parts } from '../constants/parts.js';
3
+ import { skin } from '../constants/skin.js';
4
+ import { trousers } from '../constants/trousers.js';
5
+ import { paints } from '../constants/paints.js';
6
+
7
+ export function pedestrianModel(index) {
8
+ const model = parts.body.slice();
9
+ model[1] = [model[1][0], model[1][1], model[1][2], paints[index % paints.length]];
10
+ model.push(
11
+ [box(-0.16, -0.02, -0.07, 0.07), 0.08, 0.9, trousers],
12
+ [box(0.02, 0.16, -0.07, 0.07), 0.08, 0.9, trousers],
13
+ [box(-0.3, -0.2, -0.05, 0.05), 0.76, 1.42, skin],
14
+ [box(0.2, 0.3, -0.05, 0.05), 0.76, 1.42, skin],
15
+ );
16
+ return model;
17
+ }
@@ -0,0 +1,9 @@
1
+ import { routeColor } from '../traffic/routeColor.js';
2
+ import { carriage } from './carriage.js';
3
+
4
+ export function tramModel(index, properties) {
5
+ const color = routeColor(properties), parts = [];
6
+ let car;
7
+ for (car = 0; car < 5; car++) parts.push(...carriage((car - 2) * 6.5, 6, color));
8
+ return parts;
9
+ }
@@ -0,0 +1,6 @@
1
+ import { hit } from '../picking/hit.js';
2
+
3
+ export function blocked(east, north, feet) {
4
+ const length = Math.hypot(east, north);
5
+ return length > 1e-6 && hit(this.layer, feet[0], feet[1], feet[2], east / length, -north / length, length + 0.3);
6
+ }