@pascal-app/core 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/dist/events/bus.d.ts +30 -2
  2. package/dist/events/bus.d.ts.map +1 -1
  3. package/dist/hooks/scene-registry/item-clip-registry.d.ts +18 -0
  4. package/dist/hooks/scene-registry/item-clip-registry.d.ts.map +1 -0
  5. package/dist/hooks/scene-registry/item-clip-registry.js +10 -0
  6. package/dist/hooks/scene-registry/scene-registry.d.ts +8 -1
  7. package/dist/hooks/scene-registry/scene-registry.d.ts.map +1 -1
  8. package/dist/hooks/scene-registry/scene-registry.js +27 -1
  9. package/dist/hooks/scene-registry/scene-registry.test.d.ts +2 -0
  10. package/dist/hooks/scene-registry/scene-registry.test.d.ts.map +1 -0
  11. package/dist/hooks/scene-registry/scene-registry.test.js +26 -0
  12. package/dist/hooks/spatial-grid/floor-placed-elevation.test.js +93 -0
  13. package/dist/hooks/spatial-grid/spatial-grid-manager.d.ts +69 -12
  14. package/dist/hooks/spatial-grid/spatial-grid-manager.d.ts.map +1 -1
  15. package/dist/hooks/spatial-grid/spatial-grid-manager.js +476 -195
  16. package/dist/hooks/spatial-grid/spatial-grid-sync.d.ts.map +1 -1
  17. package/dist/hooks/spatial-grid/spatial-grid-sync.js +19 -1
  18. package/dist/hooks/spatial-grid/wall-slab-overlap.test.d.ts +2 -0
  19. package/dist/hooks/spatial-grid/wall-slab-overlap.test.d.ts.map +1 -0
  20. package/dist/hooks/spatial-grid/wall-slab-overlap.test.js +363 -0
  21. package/dist/index.d.ts +16 -6
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +15 -5
  24. package/dist/lib/level-name.d.ts +4 -0
  25. package/dist/lib/level-name.d.ts.map +1 -0
  26. package/dist/lib/level-name.js +10 -0
  27. package/dist/lib/measurement-geometry.d.ts +19 -0
  28. package/dist/lib/measurement-geometry.d.ts.map +1 -0
  29. package/dist/lib/measurement-geometry.js +232 -0
  30. package/dist/lib/measurement-geometry.test.d.ts +2 -0
  31. package/dist/lib/measurement-geometry.test.d.ts.map +1 -0
  32. package/dist/lib/measurement-geometry.test.js +102 -0
  33. package/dist/lib/polygon-geometry.d.ts +0 -1
  34. package/dist/lib/polygon-geometry.d.ts.map +1 -1
  35. package/dist/lib/polygon-geometry.js +0 -18
  36. package/dist/lib/selection-proxy.d.ts +4 -0
  37. package/dist/lib/selection-proxy.d.ts.map +1 -0
  38. package/dist/lib/selection-proxy.js +12 -0
  39. package/dist/lib/slab-polygon.d.ts +31 -2
  40. package/dist/lib/slab-polygon.d.ts.map +1 -1
  41. package/dist/lib/slab-polygon.js +525 -31
  42. package/dist/lib/slab-polygon.test.d.ts +2 -0
  43. package/dist/lib/slab-polygon.test.d.ts.map +1 -0
  44. package/dist/lib/slab-polygon.test.js +635 -0
  45. package/dist/lib/slots.d.ts +14 -0
  46. package/dist/lib/slots.d.ts.map +1 -0
  47. package/dist/lib/slots.js +26 -0
  48. package/dist/lib/space-detection.d.ts +25 -2
  49. package/dist/lib/space-detection.d.ts.map +1 -1
  50. package/dist/lib/space-detection.js +414 -118
  51. package/dist/lib/space-detection.test.js +301 -2
  52. package/dist/lib/wall-distance.d.ts +60 -0
  53. package/dist/lib/wall-distance.d.ts.map +1 -0
  54. package/dist/lib/wall-distance.js +85 -0
  55. package/dist/lib/zone-quantities.d.ts +21 -0
  56. package/dist/lib/zone-quantities.d.ts.map +1 -0
  57. package/dist/lib/zone-quantities.js +183 -0
  58. package/dist/lib/zone-quantities.test.d.ts +2 -0
  59. package/dist/lib/zone-quantities.test.d.ts.map +1 -0
  60. package/dist/lib/zone-quantities.test.js +82 -0
  61. package/dist/material-library.d.ts +20 -1
  62. package/dist/material-library.d.ts.map +1 -1
  63. package/dist/material-library.js +2181 -441
  64. package/dist/registry/handles.d.ts +75 -2
  65. package/dist/registry/handles.d.ts.map +1 -1
  66. package/dist/registry/index.d.ts +3 -3
  67. package/dist/registry/index.d.ts.map +1 -1
  68. package/dist/registry/index.js +1 -1
  69. package/dist/registry/registry.d.ts +46 -3
  70. package/dist/registry/registry.d.ts.map +1 -1
  71. package/dist/registry/registry.js +82 -1
  72. package/dist/registry/registry.test.js +14 -1
  73. package/dist/registry/subtree.d.ts.map +1 -1
  74. package/dist/registry/subtree.js +4 -0
  75. package/dist/registry/subtree.test.js +30 -0
  76. package/dist/registry/types.d.ts +717 -38
  77. package/dist/registry/types.d.ts.map +1 -1
  78. package/dist/schema/index.d.ts +21 -5
  79. package/dist/schema/index.d.ts.map +1 -1
  80. package/dist/schema/index.js +17 -3
  81. package/dist/schema/material.d.ts +3 -2
  82. package/dist/schema/material.d.ts.map +1 -1
  83. package/dist/schema/material.js +7 -5
  84. package/dist/schema/material.test.d.ts +2 -0
  85. package/dist/schema/material.test.d.ts.map +1 -0
  86. package/dist/schema/material.test.js +43 -0
  87. package/dist/schema/nodes/box-vent.d.ts +2 -2
  88. package/dist/schema/nodes/cabinet.d.ts +534 -0
  89. package/dist/schema/nodes/cabinet.d.ts.map +1 -0
  90. package/dist/schema/nodes/cabinet.js +137 -0
  91. package/dist/schema/nodes/ceiling.d.ts +3 -2
  92. package/dist/schema/nodes/ceiling.d.ts.map +1 -1
  93. package/dist/schema/nodes/ceiling.js +4 -0
  94. package/dist/schema/nodes/chimney.d.ts +4 -4
  95. package/dist/schema/nodes/column.d.ts +3 -2
  96. package/dist/schema/nodes/column.d.ts.map +1 -1
  97. package/dist/schema/nodes/column.js +3 -0
  98. package/dist/schema/nodes/cupola.d.ts +2 -2
  99. package/dist/schema/nodes/door.d.ts +13 -5
  100. package/dist/schema/nodes/door.d.ts.map +1 -1
  101. package/dist/schema/nodes/door.js +12 -0
  102. package/dist/schema/nodes/dormer.d.ts +8 -8
  103. package/dist/schema/nodes/dormer.js +1 -1
  104. package/dist/schema/nodes/downspout.d.ts +2 -2
  105. package/dist/schema/nodes/duct-fitting.d.ts +91 -0
  106. package/dist/schema/nodes/duct-fitting.d.ts.map +1 -0
  107. package/dist/schema/nodes/duct-fitting.js +92 -0
  108. package/dist/schema/nodes/duct-segment.d.ts +61 -0
  109. package/dist/schema/nodes/duct-segment.d.ts.map +1 -0
  110. package/dist/schema/nodes/duct-segment.js +73 -0
  111. package/dist/schema/nodes/duct-terminal.d.ts +57 -0
  112. package/dist/schema/nodes/duct-terminal.d.ts.map +1 -0
  113. package/dist/schema/nodes/duct-terminal.js +51 -0
  114. package/dist/schema/nodes/elevator.d.ts +3 -2
  115. package/dist/schema/nodes/elevator.d.ts.map +1 -1
  116. package/dist/schema/nodes/elevator.js +3 -0
  117. package/dist/schema/nodes/eyebrow-vent.d.ts +2 -2
  118. package/dist/schema/nodes/fence.d.ts +18 -2
  119. package/dist/schema/nodes/fence.d.ts.map +1 -1
  120. package/dist/schema/nodes/fence.js +25 -2
  121. package/dist/schema/nodes/gutter.d.ts +2 -2
  122. package/dist/schema/nodes/hvac-equipment.d.ts +63 -0
  123. package/dist/schema/nodes/hvac-equipment.d.ts.map +1 -0
  124. package/dist/schema/nodes/hvac-equipment.js +55 -0
  125. package/dist/schema/nodes/item.d.ts +8 -0
  126. package/dist/schema/nodes/item.d.ts.map +1 -1
  127. package/dist/schema/nodes/item.js +11 -0
  128. package/dist/schema/nodes/level.d.ts +1 -1
  129. package/dist/schema/nodes/level.d.ts.map +1 -1
  130. package/dist/schema/nodes/level.js +2 -0
  131. package/dist/schema/nodes/lineset.d.ts +42 -0
  132. package/dist/schema/nodes/lineset.d.ts.map +1 -0
  133. package/dist/schema/nodes/lineset.js +38 -0
  134. package/dist/schema/nodes/liquid-line.d.ts +34 -0
  135. package/dist/schema/nodes/liquid-line.d.ts.map +1 -0
  136. package/dist/schema/nodes/liquid-line.js +24 -0
  137. package/dist/schema/nodes/measurement.d.ts +306 -0
  138. package/dist/schema/nodes/measurement.d.ts.map +1 -0
  139. package/dist/schema/nodes/measurement.js +87 -0
  140. package/dist/schema/nodes/measurement.test.d.ts +2 -0
  141. package/dist/schema/nodes/measurement.test.d.ts.map +1 -0
  142. package/dist/schema/nodes/measurement.test.js +139 -0
  143. package/dist/schema/nodes/pipe-fitting.d.ts +56 -0
  144. package/dist/schema/nodes/pipe-fitting.d.ts.map +1 -0
  145. package/dist/schema/nodes/pipe-fitting.js +45 -0
  146. package/dist/schema/nodes/pipe-segment.d.ts +48 -0
  147. package/dist/schema/nodes/pipe-segment.d.ts.map +1 -0
  148. package/dist/schema/nodes/pipe-segment.js +36 -0
  149. package/dist/schema/nodes/pipe-trap.d.ts +43 -0
  150. package/dist/schema/nodes/pipe-trap.d.ts.map +1 -0
  151. package/dist/schema/nodes/pipe-trap.js +36 -0
  152. package/dist/schema/nodes/ridge-vent-defaults.test.d.ts +2 -0
  153. package/dist/schema/nodes/ridge-vent-defaults.test.d.ts.map +1 -0
  154. package/dist/schema/nodes/ridge-vent-defaults.test.js +205 -0
  155. package/dist/schema/nodes/ridge-vent.d.ts +18 -3
  156. package/dist/schema/nodes/ridge-vent.d.ts.map +1 -1
  157. package/dist/schema/nodes/ridge-vent.js +221 -3
  158. package/dist/schema/nodes/roof-segment-shape.d.ts +90 -0
  159. package/dist/schema/nodes/roof-segment-shape.d.ts.map +1 -0
  160. package/dist/schema/nodes/roof-segment-shape.js +318 -0
  161. package/dist/schema/nodes/roof-segment-shape.test.d.ts +2 -0
  162. package/dist/schema/nodes/roof-segment-shape.test.d.ts.map +1 -0
  163. package/dist/schema/nodes/roof-segment-shape.test.js +175 -0
  164. package/dist/schema/nodes/roof-segment-surface.test.d.ts +2 -0
  165. package/dist/schema/nodes/roof-segment-surface.test.d.ts.map +1 -0
  166. package/dist/schema/nodes/roof-segment-surface.test.js +48 -0
  167. package/dist/schema/nodes/roof-segment-trim.test.d.ts +2 -0
  168. package/dist/schema/nodes/roof-segment-trim.test.d.ts.map +1 -0
  169. package/dist/schema/nodes/roof-segment-trim.test.js +107 -0
  170. package/dist/schema/nodes/roof-segment-walls.d.ts +101 -0
  171. package/dist/schema/nodes/roof-segment-walls.d.ts.map +1 -0
  172. package/dist/schema/nodes/roof-segment-walls.js +330 -0
  173. package/dist/schema/nodes/roof-segment-walls.test.d.ts +2 -0
  174. package/dist/schema/nodes/roof-segment-walls.test.d.ts.map +1 -0
  175. package/dist/schema/nodes/roof-segment-walls.test.js +92 -0
  176. package/dist/schema/nodes/roof-segment.d.ts +84 -8
  177. package/dist/schema/nodes/roof-segment.d.ts.map +1 -1
  178. package/dist/schema/nodes/roof-segment.js +290 -5
  179. package/dist/schema/nodes/roof.d.ts +8 -8
  180. package/dist/schema/nodes/shelf.d.ts +3 -2
  181. package/dist/schema/nodes/shelf.d.ts.map +1 -1
  182. package/dist/schema/nodes/shelf.js +6 -0
  183. package/dist/schema/nodes/skylight.d.ts +10 -10
  184. package/dist/schema/nodes/slab.d.ts +3 -2
  185. package/dist/schema/nodes/slab.d.ts.map +1 -1
  186. package/dist/schema/nodes/slab.js +4 -0
  187. package/dist/schema/nodes/solar-panel.d.ts +4 -4
  188. package/dist/schema/nodes/stair-segment.d.ts +4 -4
  189. package/dist/schema/nodes/stair.d.ts +13 -12
  190. package/dist/schema/nodes/stair.d.ts.map +1 -1
  191. package/dist/schema/nodes/stair.js +3 -0
  192. package/dist/schema/nodes/turbine-vent.d.ts +2 -2
  193. package/dist/schema/nodes/wall.d.ts +245 -6
  194. package/dist/schema/nodes/wall.d.ts.map +1 -1
  195. package/dist/schema/nodes/wall.js +257 -0
  196. package/dist/schema/nodes/wall.test.d.ts +2 -0
  197. package/dist/schema/nodes/wall.test.d.ts.map +1 -0
  198. package/dist/schema/nodes/wall.test.js +208 -0
  199. package/dist/schema/nodes/window.d.ts +11 -3
  200. package/dist/schema/nodes/window.d.ts.map +1 -1
  201. package/dist/schema/nodes/window.js +12 -0
  202. package/dist/schema/nodes/zone.d.ts +2 -0
  203. package/dist/schema/nodes/zone.d.ts.map +1 -1
  204. package/dist/schema/nodes/zone.js +6 -0
  205. package/dist/schema/scene-material.d.ts +41 -0
  206. package/dist/schema/scene-material.d.ts.map +1 -0
  207. package/dist/schema/scene-material.js +9 -0
  208. package/dist/schema/types.d.ts +1089 -94
  209. package/dist/schema/types.d.ts.map +1 -1
  210. package/dist/schema/types.js +23 -0
  211. package/dist/services/alignment-anchors.d.ts.map +1 -1
  212. package/dist/services/alignment-anchors.js +30 -1
  213. package/dist/services/alignment.d.ts +5 -0
  214. package/dist/services/alignment.d.ts.map +1 -1
  215. package/dist/services/alignment.js +2 -0
  216. package/dist/services/hosting.d.ts +8 -0
  217. package/dist/services/hosting.d.ts.map +1 -1
  218. package/dist/services/hosting.js +13 -4
  219. package/dist/services/hosting.test.js +32 -1
  220. package/dist/services/index.d.ts +8 -2
  221. package/dist/services/index.d.ts.map +1 -1
  222. package/dist/services/index.js +8 -2
  223. package/dist/services/level-height.d.ts +28 -0
  224. package/dist/services/level-height.d.ts.map +1 -0
  225. package/dist/services/level-height.js +62 -0
  226. package/dist/services/opening-guides.d.ts +141 -0
  227. package/dist/services/opening-guides.d.ts.map +1 -0
  228. package/dist/services/opening-guides.js +267 -0
  229. package/dist/services/opening-guides.test.d.ts +2 -0
  230. package/dist/services/opening-guides.test.d.ts.map +1 -0
  231. package/dist/services/opening-guides.test.js +208 -0
  232. package/dist/services/port-connectivity.d.ts +115 -0
  233. package/dist/services/port-connectivity.d.ts.map +1 -0
  234. package/dist/services/port-connectivity.js +300 -0
  235. package/dist/services/port-connectivity.test.d.ts +2 -0
  236. package/dist/services/port-connectivity.test.d.ts.map +1 -0
  237. package/dist/services/port-connectivity.test.js +297 -0
  238. package/dist/services/riser-diagram.d.ts +40 -0
  239. package/dist/services/riser-diagram.d.ts.map +1 -0
  240. package/dist/services/riser-diagram.js +110 -0
  241. package/dist/services/riser-diagram.test.d.ts +2 -0
  242. package/dist/services/riser-diagram.test.d.ts.map +1 -0
  243. package/dist/services/riser-diagram.test.js +66 -0
  244. package/dist/services/snap.d.ts +9 -1
  245. package/dist/services/snap.d.ts.map +1 -1
  246. package/dist/services/snap.js +21 -1
  247. package/dist/services/snap.test.js +43 -1
  248. package/dist/services/system-graph.d.ts +30 -0
  249. package/dist/services/system-graph.d.ts.map +1 -0
  250. package/dist/services/system-graph.js +164 -0
  251. package/dist/services/system-graph.test.d.ts +2 -0
  252. package/dist/services/system-graph.test.d.ts.map +1 -0
  253. package/dist/services/system-graph.test.js +138 -0
  254. package/dist/services/validate-dwv.d.ts +32 -0
  255. package/dist/services/validate-dwv.d.ts.map +1 -0
  256. package/dist/services/validate-dwv.js +118 -0
  257. package/dist/services/validate-dwv.test.d.ts +2 -0
  258. package/dist/services/validate-dwv.test.d.ts.map +1 -0
  259. package/dist/services/validate-dwv.test.js +109 -0
  260. package/dist/store/actions/node-actions.d.ts.map +1 -1
  261. package/dist/store/actions/node-actions.js +94 -1
  262. package/dist/store/actions/ridge-vent-update.test.d.ts +2 -0
  263. package/dist/store/actions/ridge-vent-update.test.d.ts.map +1 -0
  264. package/dist/store/actions/ridge-vent-update.test.js +264 -0
  265. package/dist/store/history-control.d.ts +11 -0
  266. package/dist/store/history-control.d.ts.map +1 -1
  267. package/dist/store/history-control.js +33 -0
  268. package/dist/store/use-scene-dirty-tracking.test.d.ts +2 -0
  269. package/dist/store/use-scene-dirty-tracking.test.d.ts.map +1 -0
  270. package/dist/store/use-scene-dirty-tracking.test.js +68 -0
  271. package/dist/store/use-scene-measurement-roundtrip.test.d.ts +2 -0
  272. package/dist/store/use-scene-measurement-roundtrip.test.d.ts.map +1 -0
  273. package/dist/store/use-scene-measurement-roundtrip.test.js +97 -0
  274. package/dist/store/use-scene-plugins.test.d.ts +2 -0
  275. package/dist/store/use-scene-plugins.test.d.ts.map +1 -0
  276. package/dist/store/use-scene-plugins.test.js +51 -0
  277. package/dist/store/use-scene-wall-slot-migration.test.d.ts +2 -0
  278. package/dist/store/use-scene-wall-slot-migration.test.d.ts.map +1 -0
  279. package/dist/store/use-scene-wall-slot-migration.test.js +210 -0
  280. package/dist/store/use-scene-window-migration.test.d.ts +2 -0
  281. package/dist/store/use-scene-window-migration.test.d.ts.map +1 -0
  282. package/dist/store/use-scene-window-migration.test.js +85 -0
  283. package/dist/store/use-scene.d.ts +17 -2
  284. package/dist/store/use-scene.d.ts.map +1 -1
  285. package/dist/store/use-scene.js +358 -51
  286. package/dist/systems/elevator/elevator-service.js +1 -1
  287. package/dist/systems/fence/fence-centerline.d.ts +12 -0
  288. package/dist/systems/fence/fence-centerline.d.ts.map +1 -0
  289. package/dist/systems/fence/fence-centerline.js +37 -0
  290. package/dist/systems/fence/fence-spline.d.ts +39 -0
  291. package/dist/systems/fence/fence-spline.d.ts.map +1 -0
  292. package/dist/systems/fence/fence-spline.js +196 -0
  293. package/dist/systems/fence/fence-spline.test.d.ts +2 -0
  294. package/dist/systems/fence/fence-spline.test.d.ts.map +1 -0
  295. package/dist/systems/fence/fence-spline.test.js +136 -0
  296. package/dist/systems/stair/stair-footprint.d.ts.map +1 -1
  297. package/dist/systems/stair/stair-footprint.js +21 -11
  298. package/dist/systems/stair/stair-opening-preview.d.ts +1139 -469
  299. package/dist/systems/stair/stair-opening-preview.d.ts.map +1 -1
  300. package/dist/systems/stair/stair-opening-sync.d.ts.map +1 -1
  301. package/dist/systems/stair/stair-opening-sync.js +1 -18
  302. package/dist/systems/stair/stair-opening-sync.test.js +39 -0
  303. package/dist/systems/wall/wall-mitering.d.ts.map +1 -1
  304. package/dist/systems/wall/wall-mitering.js +38 -2
  305. package/dist/systems/wall/wall-mitering.test.d.ts +2 -0
  306. package/dist/systems/wall/wall-mitering.test.d.ts.map +1 -0
  307. package/dist/systems/wall/wall-mitering.test.js +63 -0
  308. package/dist/utils/clone-scene-graph.d.ts +1 -0
  309. package/dist/utils/clone-scene-graph.d.ts.map +1 -1
  310. package/dist/utils/clone-scene-graph.js +23 -3
  311. package/dist/utils/clone-scene-graph.test.js +3 -0
  312. package/dist/utils/heal-scene-graph.d.ts +18 -0
  313. package/dist/utils/heal-scene-graph.d.ts.map +1 -0
  314. package/dist/utils/heal-scene-graph.js +90 -0
  315. package/dist/utils/heal-scene-graph.test.d.ts +2 -0
  316. package/dist/utils/heal-scene-graph.test.d.ts.map +1 -0
  317. package/dist/utils/heal-scene-graph.test.js +88 -0
  318. package/dist/validation/validate-build-json.d.ts +1 -0
  319. package/dist/validation/validate-build-json.d.ts.map +1 -1
  320. package/dist/validation/validate-build-json.js +31 -2
  321. package/package.json +3 -3
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Pure 2D spline sampling for fences whose centerline is defined by a `path`
3
+ * of control points (the "flying path" curved fence).
4
+ *
5
+ * Each control point carries an OUT-handle offset vector. When the user has
6
+ * not adjusted it, the handle defaults to a distance-aware Catmull-Rom-style
7
+ * tangent: direction comes from neighbouring points, while length is capped by
8
+ * the shorter adjacent span. When the user drags a tangent handle (stored in
9
+ * `tangents[i]`), that point's handle becomes the stored vector and the IN
10
+ * handle is its mirror, so the curve stays smooth (C1) through the point but
11
+ * bends to taste. Each span is then a cubic Bézier between consecutive points
12
+ * using their handles.
13
+ *
14
+ * Lives in `@pascal-app/core` and imports NO Three.js — the same `CurveFrame`
15
+ * shape that `wall-curve.ts` returns (point / tangent / normal) is produced
16
+ * here so the spline branch is a drop-in for the arc branch in every consumer.
17
+ */
18
+ const EPSILON = 1e-6;
19
+ const DEFAULT_SEGMENTS_PER_SPAN = 32;
20
+ const TWO_POINT_CURVE_SAGITTA_RATIO = 0.18;
21
+ const TWO_POINT_CURVE_MIN_SAGITTA = 0.18;
22
+ const TWO_POINT_CURVE_MAX_SAGITTA = 1.2;
23
+ export function isSplineFence(fence) {
24
+ return Array.isArray(fence.path) && fence.path.length >= 2;
25
+ }
26
+ function toPoints(path) {
27
+ return path.map(([x, y]) => ({ x, y }));
28
+ }
29
+ function distance(a, b) {
30
+ return Math.hypot(b.x - a.x, b.y - a.y);
31
+ }
32
+ function clamp01(value) {
33
+ return Math.max(0, Math.min(1, value));
34
+ }
35
+ function clamp(value, min, max) {
36
+ return Math.max(min, Math.min(max, value));
37
+ }
38
+ /**
39
+ * OUT-handle offset vector for control point `index` — the stored tangent if
40
+ * the user has adjusted it, otherwise the automatic distance-aware tangent
41
+ * (endpoints duplicate the neighbour so the ends stay tangent to their single
42
+ * span). The IN handle is the negation of this.
43
+ *
44
+ * Exported so the editing UI can draw the tangent line / handle dots at the
45
+ * right place even before the user has dragged them.
46
+ */
47
+ export function getFenceControlHandle(path, tangents, index) {
48
+ const stored = tangents?.[index];
49
+ if (stored) {
50
+ return { x: stored[0], y: stored[1] };
51
+ }
52
+ const prev = path[index - 1] ?? path[index];
53
+ const next = path[index + 1] ?? path[index];
54
+ const prevDistance = distance({ x: path[index][0], y: path[index][1] }, {
55
+ x: prev[0],
56
+ y: prev[1],
57
+ });
58
+ const nextDistance = distance({ x: path[index][0], y: path[index][1] }, {
59
+ x: next[0],
60
+ y: next[1],
61
+ });
62
+ const handleLength = Math.min(prevDistance || nextDistance, nextDistance || prevDistance) / 3;
63
+ const vx = next[0] - prev[0];
64
+ const vy = next[1] - prev[1];
65
+ const len = Math.hypot(vx, vy);
66
+ if (len < EPSILON || handleLength < EPSILON) {
67
+ return { x: 0, y: 0 };
68
+ }
69
+ return {
70
+ x: (vx / len) * handleLength,
71
+ y: (vy / len) * handleLength,
72
+ };
73
+ }
74
+ export function getTwoPointFenceCurveTangents(path) {
75
+ if (path.length !== 2)
76
+ return undefined;
77
+ const start = path[0];
78
+ const end = path[1];
79
+ const dx = end[0] - start[0];
80
+ const dy = end[1] - start[1];
81
+ const chordLength = Math.hypot(dx, dy);
82
+ if (chordLength < EPSILON)
83
+ return undefined;
84
+ const tangentX = dx / 3;
85
+ const tangentY = dy / 3;
86
+ const normalX = -dy / chordLength;
87
+ const normalY = dx / chordLength;
88
+ const sagitta = clamp(chordLength * TWO_POINT_CURVE_SAGITTA_RATIO, TWO_POINT_CURVE_MIN_SAGITTA, TWO_POINT_CURVE_MAX_SAGITTA);
89
+ const bendX = normalX * sagitta * (4 / 3);
90
+ const bendY = normalY * sagitta * (4 / 3);
91
+ return [
92
+ [tangentX + bendX, tangentY + bendY],
93
+ [tangentX - bendX, tangentY - bendY],
94
+ ];
95
+ }
96
+ function cubicBezier(p0, p1, p2, p3, u) {
97
+ const mu = 1 - u;
98
+ const a = mu * mu * mu;
99
+ const b = 3 * mu * mu * u;
100
+ const c = 3 * mu * u * u;
101
+ const d = u * u * u;
102
+ return {
103
+ x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
104
+ y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,
105
+ };
106
+ }
107
+ function hasAnyTangent(tangents) {
108
+ return Array.isArray(tangents) && tangents.some((t) => t != null);
109
+ }
110
+ /**
111
+ * Sample the spline centerline into a polyline. Control points are honored as
112
+ * on-curve anchors; `segmentsPerSpan` controls smoothness between them.
113
+ * Returns `(segmentsPerSpan * spanCount) + 1` points, first == path[0],
114
+ * last == path[-1].
115
+ */
116
+ export function sampleFenceSpline(path, tangents, segmentsPerSpan = DEFAULT_SEGMENTS_PER_SPAN) {
117
+ const pts = toPoints(path);
118
+ if (pts.length === 0)
119
+ return [];
120
+ if (pts.length === 1)
121
+ return [pts[0]];
122
+ // Two points with no adjusted tangents is a straight segment.
123
+ if (pts.length === 2 && !hasAnyTangent(tangents))
124
+ return [pts[0], pts[1]];
125
+ const steps = Math.max(1, Math.floor(segmentsPerSpan));
126
+ const result = [pts[0]];
127
+ for (let i = 0; i < pts.length - 1; i += 1) {
128
+ const p1 = pts[i];
129
+ const p2 = pts[i + 1];
130
+ const outHandle = getFenceControlHandle(path, tangents, i);
131
+ const nextHandle = getFenceControlHandle(path, tangents, i + 1);
132
+ // Bézier controls: leave p1 along its OUT handle, arrive at p2 along its
133
+ // IN handle (= negated OUT handle).
134
+ const c1 = { x: p1.x + outHandle.x, y: p1.y + outHandle.y };
135
+ const c2 = { x: p2.x - nextHandle.x, y: p2.y - nextHandle.y };
136
+ for (let s = 1; s <= steps; s += 1) {
137
+ result.push(cubicBezier(p1, c1, c2, p2, s / steps));
138
+ }
139
+ }
140
+ return result;
141
+ }
142
+ function frameFromPolyline(points, t) {
143
+ if (points.length === 0) {
144
+ return {
145
+ point: { x: 0, y: 0 },
146
+ tangent: { x: 1, y: 0 },
147
+ normal: { x: 0, y: 1 },
148
+ };
149
+ }
150
+ if (points.length === 1) {
151
+ return {
152
+ point: points[0],
153
+ tangent: { x: 1, y: 0 },
154
+ normal: { x: 0, y: 1 },
155
+ };
156
+ }
157
+ const clamped = clamp01(t);
158
+ const lastIndex = points.length - 1;
159
+ const scaled = clamped * lastIndex;
160
+ const lower = Math.min(lastIndex - 1, Math.floor(scaled));
161
+ const upper = lower + 1;
162
+ const localU = scaled - lower;
163
+ const a = points[lower];
164
+ const b = points[upper];
165
+ const point = {
166
+ x: a.x + (b.x - a.x) * localU,
167
+ y: a.y + (b.y - a.y) * localU,
168
+ };
169
+ const dx = b.x - a.x;
170
+ const dy = b.y - a.y;
171
+ const len = Math.hypot(dx, dy);
172
+ const tangent = len < EPSILON ? { x: 1, y: 0 } : { x: dx / len, y: dy / len };
173
+ return {
174
+ point,
175
+ tangent,
176
+ normal: { x: -tangent.y, y: tangent.x },
177
+ };
178
+ }
179
+ /**
180
+ * Frame (point + tangent + normal) at parameter `t` in [0, 1] along the spline
181
+ * centerline. Same return shape as `getWallCurveFrameAt` so it is a drop-in for
182
+ * the arc branch. `t` is uniform over the sampled polyline (arc length is not
183
+ * reparameterised — adequate for marching posts / rails and far cheaper).
184
+ */
185
+ export function getFenceSplineFrameAt(path, t, tangents, segmentsPerSpan = DEFAULT_SEGMENTS_PER_SPAN) {
186
+ return frameFromPolyline(sampleFenceSpline(path, tangents, segmentsPerSpan), t);
187
+ }
188
+ /** Total polyline length of the sampled spline centerline. */
189
+ export function getFenceSplineLength(path, tangents, segmentsPerSpan = DEFAULT_SEGMENTS_PER_SPAN) {
190
+ const points = sampleFenceSpline(path, tangents, segmentsPerSpan);
191
+ let total = 0;
192
+ for (let i = 1; i < points.length; i += 1) {
193
+ total += distance(points[i - 1], points[i]);
194
+ }
195
+ return total;
196
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fence-spline.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence-spline.test.d.ts","sourceRoot":"","sources":["../../../src/systems/fence/fence-spline.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,136 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { getFenceControlHandle, getFenceSplineFrameAt, getFenceSplineLength, getTwoPointFenceCurveTangents, isSplineFence, sampleFenceSpline, } from './fence-spline';
3
+ describe('isSplineFence', () => {
4
+ test('false without a path or with < 2 points', () => {
5
+ expect(isSplineFence({ path: undefined })).toBe(false);
6
+ expect(isSplineFence({ path: [[0, 0]] })).toBe(false);
7
+ });
8
+ test('true with >= 2 points', () => {
9
+ expect(isSplineFence({
10
+ path: [
11
+ [0, 0],
12
+ [1, 0],
13
+ ],
14
+ })).toBe(true);
15
+ });
16
+ });
17
+ describe('sampleFenceSpline', () => {
18
+ test('honors the control points as on-curve anchors', () => {
19
+ const path = [
20
+ [0, 0],
21
+ [2, 2],
22
+ [4, 0],
23
+ ];
24
+ const sampled = sampleFenceSpline(path, undefined, 8);
25
+ // First and last sample equal the path endpoints exactly.
26
+ expect(sampled[0]).toEqual({ x: 0, y: 0 });
27
+ expect(sampled[sampled.length - 1]).toEqual({ x: 4, y: 0 });
28
+ // The interior control point is interpolated: some sample lands on (2, 2).
29
+ const hitsMiddle = sampled.some((p) => Math.hypot(p.x - 2, p.y - 2) < 1e-6);
30
+ expect(hitsMiddle).toBe(true);
31
+ });
32
+ test('two-point path with no tangents is a straight segment', () => {
33
+ expect(sampleFenceSpline([
34
+ [0, 0],
35
+ [3, 0],
36
+ ], undefined, 8)).toEqual([
37
+ { x: 0, y: 0 },
38
+ { x: 3, y: 0 },
39
+ ]);
40
+ });
41
+ test('a stored tangent bends an otherwise straight two-point span', () => {
42
+ const path = [
43
+ [0, 0],
44
+ [4, 0],
45
+ ];
46
+ // Pull the first point's handle up — the span should bow off the X axis.
47
+ const sampled = sampleFenceSpline(path, [[0, 2], null], 12);
48
+ expect(sampled[0]).toEqual({ x: 0, y: 0 });
49
+ expect(sampled[sampled.length - 1]).toEqual({ x: 4, y: 0 });
50
+ const maxY = Math.max(...sampled.map((p) => Math.abs(p.y)));
51
+ expect(maxY).toBeGreaterThan(0.1);
52
+ });
53
+ test('generated two-point curve tangents create a gentle arc', () => {
54
+ const path = [
55
+ [0, 0],
56
+ [4, 0],
57
+ ];
58
+ const sampled = sampleFenceSpline(path, getTwoPointFenceCurveTangents(path), 16);
59
+ expect(sampled[0]).toEqual({ x: 0, y: 0 });
60
+ expect(sampled[sampled.length - 1]).toEqual({ x: 4, y: 0 });
61
+ const maxY = Math.max(...sampled.map((p) => p.y));
62
+ expect(maxY).toBeGreaterThan(0.4);
63
+ });
64
+ test('produces a smooth (no-cusp) curve on uneven spacing', () => {
65
+ const path = [
66
+ [0, 0],
67
+ [1, 0.2],
68
+ [5, 0.3],
69
+ [6, 0],
70
+ ];
71
+ const sampled = sampleFenceSpline(path, undefined, 16);
72
+ let maxTurn = 0;
73
+ for (let i = 2; i < sampled.length; i += 1) {
74
+ const a = sampled[i - 2];
75
+ const b = sampled[i - 1];
76
+ const c = sampled[i];
77
+ const t1 = Math.atan2(b.y - a.y, b.x - a.x);
78
+ const t2 = Math.atan2(c.y - b.y, c.x - b.x);
79
+ let d = Math.abs(t2 - t1);
80
+ if (d > Math.PI)
81
+ d = 2 * Math.PI - d;
82
+ maxTurn = Math.max(maxTurn, d);
83
+ }
84
+ expect(maxTurn).toBeLessThan(Math.PI / 2);
85
+ });
86
+ });
87
+ describe('getFenceControlHandle', () => {
88
+ test('returns the stored tangent when present', () => {
89
+ expect(getFenceControlHandle([
90
+ [0, 0],
91
+ [4, 0],
92
+ ], [[1, 2], null], 0)).toEqual({ x: 1, y: 2 });
93
+ });
94
+ test('falls back to the automatic distance-aware tangent', () => {
95
+ const path = [
96
+ [0, 0],
97
+ [3, 0],
98
+ [6, 0],
99
+ ];
100
+ expect(getFenceControlHandle(path, undefined, 1)).toEqual({ x: 1, y: 0 });
101
+ });
102
+ });
103
+ describe('getFenceSplineFrameAt', () => {
104
+ const path = [
105
+ [0, 0],
106
+ [2, 0],
107
+ [4, 0],
108
+ ];
109
+ test('t=0 / t=1 land on the endpoints', () => {
110
+ expect(getFenceSplineFrameAt(path, 0).point).toEqual({ x: 0, y: 0 });
111
+ expect(getFenceSplineFrameAt(path, 1).point).toEqual({ x: 4, y: 0 });
112
+ });
113
+ test('returns a unit tangent and perpendicular normal', () => {
114
+ const frame = getFenceSplineFrameAt(path, 0.5);
115
+ expect(Math.hypot(frame.tangent.x, frame.tangent.y)).toBeCloseTo(1, 5);
116
+ const dot = frame.tangent.x * frame.normal.x + frame.tangent.y * frame.normal.y;
117
+ expect(dot).toBeCloseTo(0, 5);
118
+ });
119
+ });
120
+ describe('getFenceSplineLength', () => {
121
+ test('roughly matches the straight distance for a straight path', () => {
122
+ expect(getFenceSplineLength([
123
+ [0, 0],
124
+ [3, 4],
125
+ ], undefined, 8)).toBeCloseTo(5, 5);
126
+ });
127
+ test('a curved path is longer than its endpoint chord', () => {
128
+ const path = [
129
+ [0, 0],
130
+ [2, 2],
131
+ [4, 0],
132
+ ];
133
+ const chord = Math.hypot(4, 0);
134
+ expect(getFenceSplineLength(path, undefined, 16)).toBeGreaterThan(chord);
135
+ });
136
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"stair-footprint.d.ts","sourceRoot":"","sources":["../../../src/systems/stair/stair-footprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAa,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEnF;;;;;;;;;GASG;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3F,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAkDzF;AA0GD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,kBAAkB,GAAG,IAAI,CAK3B"}
1
+ {"version":3,"file":"stair-footprint.d.ts","sourceRoot":"","sources":["../../../src/systems/stair/stair-footprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAa,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEnF;;;;;;;;;GASG;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3F,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAkDzF;AAwHD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,kBAAkB,GAAG,IAAI,CAK3B"}
@@ -115,6 +115,15 @@ function straightStairAABB(stair, nodes) {
115
115
  return finiteBox(box);
116
116
  }
117
117
  const ARC_SAMPLES = 48;
118
+ function getSpiralLandingSweep(stair, sweepAngle) {
119
+ if ((stair.topLandingMode ?? 'none') !== 'integrated')
120
+ return 0;
121
+ const innerRadius = Math.max(0.05, stair.innerRadius ?? 0.9);
122
+ const width = Math.max(stair.width ?? 1, 0.4);
123
+ const landingDepth = Math.max(0.3, stair.topLandingDepth ?? Math.max(width * 0.9, 0.8));
124
+ return (Math.min(Math.PI * 0.75, landingDepth / Math.max(innerRadius + width / 2, 0.1)) *
125
+ Math.sign(sweepAngle || 1));
126
+ }
118
127
  /** Bounding box of a curved / spiral stair's annular sector (plus the
119
128
  * integrated spiral top landing when present). */
120
129
  function arcStairAABB(stair) {
@@ -123,7 +132,8 @@ function arcStairAABB(stair) {
123
132
  const innerRadius = Math.max(minInnerRadius, stair.innerRadius ?? (isSpiral ? 0.2 : 0.9));
124
133
  const width = Math.max(stair.width ?? 1, 0.4);
125
134
  const outerRadius = innerRadius + width;
126
- let sweep = stair.sweepAngle ?? (isSpiral ? Math.PI * 2 : Math.PI / 2);
135
+ const rawSweep = stair.sweepAngle ?? (isSpiral ? Math.PI * 2 : Math.PI / 2);
136
+ let sweep = rawSweep;
127
137
  // A full revolution would make the arc degenerate; clamp just under 2π the
128
138
  // same way the floor-plan emitter does so the sampled box stays correct.
129
139
  if (Math.abs(sweep) >= Math.PI * 2)
@@ -139,17 +149,17 @@ function arcStairAABB(stair) {
139
149
  extendByLocal(box, stair, cos * innerRadius, sin * innerRadius);
140
150
  extendByLocal(box, stair, cos * outerRadius, sin * outerRadius);
141
151
  }
142
- // Integrated spiral top landing a rectangle hung off the outer rim.
152
+ // Integrated spiral top landing renders as an angular extension of the
153
+ // annular stair body, not as a rectangular box outside the outer rim.
143
154
  if (isSpiral && stair.topLandingMode === 'integrated') {
144
- const depth = Math.max(stair.topLandingDepth ?? 0.9, 0.1);
145
- const halfWidth = width / 2;
146
- for (const [cornerX, cornerZ] of [
147
- [outerRadius, -halfWidth],
148
- [outerRadius + depth, -halfWidth],
149
- [outerRadius + depth, halfWidth],
150
- [outerRadius, halfWidth],
151
- ]) {
152
- extendByLocal(box, stair, cornerX, cornerZ);
155
+ const landingSweep = getSpiralLandingSweep(stair, rawSweep);
156
+ const landingSteps = Math.max(1, Math.ceil(Math.abs(landingSweep) / (Math.PI / 24)));
157
+ for (let step = 0; step <= landingSteps; step += 1) {
158
+ const angle = rawSweep / 2 + (landingSweep * step) / landingSteps;
159
+ const cos = Math.cos(angle);
160
+ const sin = Math.sin(angle);
161
+ extendByLocal(box, stair, cos * innerRadius, sin * innerRadius);
162
+ extendByLocal(box, stair, cos * outerRadius, sin * outerRadius);
153
163
  }
154
164
  }
155
165
  return finiteBox(box);