From 466f46f8709d485804ef0449fce1ab28bb28dbce Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 17:33:13 +0000 Subject: [PATCH 1/5] Share the collar draw handlers with the pipe and duct tools The collar inspectors' "Draw from" handlers move next to the existing continuation starters, so the collar start can be exercised without rendering the inspector. --- .../nodes/src/duct-segment/continuation.ts | 22 ++++++++++++ .../nodes/src/pipe-segment/continuation.ts | 34 ++++++++++++++++++- .../src/shared/duct-collar-inspector.tsx | 26 ++------------ .../src/shared/pipe-collar-inspector.tsx | 32 ++--------------- 4 files changed, 59 insertions(+), 55 deletions(-) diff --git a/packages/nodes/src/duct-segment/continuation.ts b/packages/nodes/src/duct-segment/continuation.ts index 92a4c391d8..4450e2850d 100644 --- a/packages/nodes/src/duct-segment/continuation.ts +++ b/packages/nodes/src/duct-segment/continuation.ts @@ -4,6 +4,7 @@ import { type DuctFittingNode, DuctSegmentNode, type FloorplanAffordance, + type NodePort, nodeRegistry, useScene, } from '@pascal-app/core' @@ -217,6 +218,27 @@ export function activateDuctContinuation( editor.setTool('duct-segment') } +export function activateDuctCollarContinuation(node: AnyNode, port: NodePort): void { + const editor = useEditor.getState() + editor.setToolDefaults('duct-segment', { + ...editor.toolDefaults['duct-segment'], + continuation: { nodeId: node.id, portId: port.id }, + shape: port.shape ?? 'round', + diameter: port.diameter, + width: port.width ?? 14, + height: port.height ?? 8, + system: port.system, + ductMaterial: 'sheet-metal', + elevation: port.position[1], + routingMode: + Math.hypot(port.direction[0], port.direction[2]) < 1e-6 ? 'vertical' : 'horizontal', + targetElevation: port.position[1] + Math.sign(port.direction[1] || 1), + crossingMode: 'connect', + }) + useViewer.getState().setSelection({ selectedIds: [] }) + editor.setTool('duct-segment') +} + export const ductContinuationAffordance: FloorplanAffordance = { start({ node, payload }) { const data = payload as { endpoint?: unknown; fittingId?: unknown } | null diff --git a/packages/nodes/src/pipe-segment/continuation.ts b/packages/nodes/src/pipe-segment/continuation.ts index cdf445a02e..9f4cb88e6c 100644 --- a/packages/nodes/src/pipe-segment/continuation.ts +++ b/packages/nodes/src/pipe-segment/continuation.ts @@ -1,4 +1,10 @@ -import { type AnyNode, type AnyNodeId, type FloorplanAffordance, useScene } from '@pascal-app/core' +import { + type AnyNode, + type AnyNodeId, + type FloorplanAffordance, + type NodePort, + useScene, +} from '@pascal-app/core' import { useEditor } from '@pascal-app/editor' import type { RunBodyHit, ScenePort } from '@pascal-app/editor/distribution' import { useViewer } from '@pascal-app/viewer' @@ -191,6 +197,32 @@ export function activatePipeContinuation( editor.setTool('pipe-segment') } +export function activatePipeCollarContinuation(node: AnyNode, port: NodePort): void { + const editor = useEditor.getState() + editor.setToolDefaults('pipe-segment', { + ...editor.toolDefaults['pipe-segment'], + continuation: { nodeId: node.id, portId: port.id }, + diameter: port.diameter, + system: port.system, + pipeMaterial: 'pipeMaterial' in node ? node.pipeMaterial : 'pvc', + elevation: port.position[1], + routingMode: + Math.hypot(port.direction[0], port.direction[2]) < 1e-6 ? 'vertical' : 'horizontal', + targetElevation: port.position[1] + Math.sign(port.direction[1] || 1), + ...(() => { + const grade = pipeGrade([0, 0, 0], [...port.direction]) ?? 0 + return { + fall: Math.abs(grade) > 1e-6 ? 'sloped' : 'level', + gradePercent: Math.abs(grade) * 100, + flowDirection: grade < 0 ? 'reverse' : 'forward', + } + })(), + crossingMode: 'connect', + }) + useViewer.getState().setSelection({ selectedIds: [] }) + editor.setTool('pipe-segment') +} + export const pipeContinuationAffordance: FloorplanAffordance = { start({ node, payload }) { const data = payload as { endpoint?: unknown; fittingId?: unknown } | null diff --git a/packages/nodes/src/shared/duct-collar-inspector.tsx b/packages/nodes/src/shared/duct-collar-inspector.tsx index 439de6a33a..09c47408f3 100644 --- a/packages/nodes/src/shared/duct-collar-inspector.tsx +++ b/packages/nodes/src/shared/duct-collar-inspector.tsx @@ -1,9 +1,8 @@ 'use client' import { type AnyNode, formatNumber, nodeRegistry, usePascalI18n, useScene } from '@pascal-app/core' -import { useEditor } from '@pascal-app/editor' -import { useViewer } from '@pascal-app/viewer' import { Vector3 } from 'three' +import { activateDuctCollarContinuation } from '../duct-segment/continuation' export default function DuctCollarInspector({ node }: { node: AnyNode }) { const i18n = usePascalI18n() @@ -39,28 +38,7 @@ export default function DuctCollarInspector({ node }: { node: AnyNode }) { type="button" disabled={occupied} className="block w-full rounded border px-2 py-1 text-left text-xs disabled:opacity-50" - onClick={() => { - const editor = useEditor.getState() - editor.setToolDefaults('duct-segment', { - ...editor.toolDefaults['duct-segment'], - continuation: { nodeId: node.id, portId: port.id }, - shape: port.shape ?? 'round', - diameter: port.diameter, - width: port.width ?? 14, - height: port.height ?? 8, - system: port.system, - ductMaterial: 'sheet-metal', - elevation: port.position[1], - routingMode: - Math.hypot(port.direction[0], port.direction[2]) < 1e-6 - ? 'vertical' - : 'horizontal', - targetElevation: port.position[1] + Math.sign(port.direction[1] || 1), - crossingMode: 'connect', - }) - useViewer.getState().setSelection({ selectedIds: [] }) - editor.setTool('duct-segment') - }} + onClick={() => activateDuctCollarContinuation(node, port)} > {i18n._({ id: 'node.shared.ductCollarInspector.collarButton', diff --git a/packages/nodes/src/shared/pipe-collar-inspector.tsx b/packages/nodes/src/shared/pipe-collar-inspector.tsx index cd6d151ffe..73314c3581 100644 --- a/packages/nodes/src/shared/pipe-collar-inspector.tsx +++ b/packages/nodes/src/shared/pipe-collar-inspector.tsx @@ -8,10 +8,8 @@ import { usePascalI18n, useScene, } from '@pascal-app/core' -import { useEditor } from '@pascal-app/editor' -import { useViewer } from '@pascal-app/viewer' import { pipeCollarOccupied } from '../pipe-segment/collar-connection' -import { pipeGrade } from '../pipe-segment/slope' +import { activatePipeCollarContinuation } from '../pipe-segment/continuation' export default function PipeCollarInspector({ node }: { node: AnyNode }) { const i18n = usePascalI18n() @@ -32,33 +30,7 @@ export default function PipeCollarInspector({ node }: { node: AnyNode }) { type="button" disabled={occupied} className="block w-full rounded border px-2 py-1 text-left text-xs disabled:opacity-50" - onClick={() => { - const editor = useEditor.getState() - editor.setToolDefaults('pipe-segment', { - ...editor.toolDefaults['pipe-segment'], - continuation: { nodeId: node.id, portId: port.id }, - diameter: port.diameter, - system: port.system, - pipeMaterial: 'pipeMaterial' in node ? node.pipeMaterial : 'pvc', - elevation: port.position[1], - routingMode: - Math.hypot(port.direction[0], port.direction[2]) < 1e-6 - ? 'vertical' - : 'horizontal', - targetElevation: port.position[1] + Math.sign(port.direction[1] || 1), - ...(() => { - const grade = pipeGrade([0, 0, 0], [...port.direction]) ?? 0 - return { - fall: Math.abs(grade) > 1e-6 ? 'sloped' : 'level', - gradePercent: Math.abs(grade) * 100, - flowDirection: grade < 0 ? 'reverse' : 'forward', - } - })(), - crossingMode: 'connect', - }) - useViewer.getState().setSelection({ selectedIds: [] }) - editor.setTool('pipe-segment') - }} + onClick={() => activatePipeCollarContinuation(node, port)} > {i18n._({ id: 'node.shared.pipeCollarInspector.collarButton', From d8c5cb2d3f3cf4f684a9ebe65b82d7ab1cc75038 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 17:33:50 +0000 Subject: [PATCH 2/5] Pin how a pipe run leaves a fixed collar The first section follows the collar's axis and takes its grade; a chosen grade that cannot meet the collar is refused with the grade message, not the fitting-clearance one, and later sections take the chosen grade. --- .../nodes/src/shared/collar-draw.test.tsx | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 packages/nodes/src/shared/collar-draw.test.tsx diff --git a/packages/nodes/src/shared/collar-draw.test.tsx b/packages/nodes/src/shared/collar-draw.test.tsx new file mode 100644 index 0000000000..dbfd584b9c --- /dev/null +++ b/packages/nodes/src/shared/collar-draw.test.tsx @@ -0,0 +1,191 @@ +import { afterEach, beforeEach, expect, spyOn, test } from 'bun:test' +import { + type AnyNode, + type AnyNodeId, + BuildingNode, + createSceneApi, + emitter, + LevelNode, + type PipeSegmentNode, + PipeTrapNode, + registerNode, + useScene, +} from '@pascal-app/core' +import { + type EditorGridEvent, + RegistryToolProvider, + useEditor, + useInteractionScope, +} from '@pascal-app/editor' +import { Html } from '@react-three/drei' +import { useThree } from '@react-three/fiber' +import { act, create } from '@react-three/test-renderer' +import type { ReactElement, ReactNode } from 'react' +import { pipeFittingDefinition } from '../pipe-fitting/definition' +import { pipeSegmentDefinition } from '../pipe-segment/definition' +import { pipeGrade } from '../pipe-segment/slope' +import PipeSegmentTool from '../pipe-segment/tool' +import { pipeTrapDefinition } from '../pipe-trap/definition' + +type Vec3 = readonly [number, number, number] + +const building = BuildingNode.parse({}) +const level = LevelNode.parse({ parentId: building.id }) +const trap = PipeTrapNode.parse({ + parentId: level.id, + position: [0, 0.5, 0], + diameter: 1.5, + pipeMaterial: 'abs', +}) +const trapPort = (id: 'inlet' | 'outlet') => + pipeTrapDefinition.ports!(trap).find((p) => p.id === id)! + +const labels: unknown[] = [] +const textOf = (node: unknown): string => { + if (typeof node === 'string' || typeof node === 'number') return String(node) + if (Array.isArray(node)) return node.map(textOf).join(' ') + if (node && typeof node === 'object') { + const element = node as { props?: { children?: unknown }; children?: unknown } + return textOf(element.props?.children ?? element.children) + } + return '' +} +const shown = () => labels.map(textOf).join(' | ') + +// A plan view at 100 px per metre, so a pointer on a collar snaps to it. +const plan = (x: number, z: number): EditorGridEvent => ({ + position: [x, 0, z], + localPosition: [x, 0, z], + screenProjection: { pointer: [x * 100, z * 100], localToScreen: [100, 0, 0, 100, 0, 0] }, + nativeEvent: {} as EditorGridEvent['nativeEvent'], +}) +const move = (x: number, z: number) => act(async () => emitter.emit('grid:move', plan(x, z))) +const click = (x: number, z: number) => act(async () => emitter.emit('grid:click', plan(x, z))) +const setRunDefaults = (kind: 'pipe-segment', patch: Record) => + act(async () => { + const editor = useEditor.getState() + editor.setToolDefaults(kind, { ...editor.toolDefaults[kind], ...patch }) + }) +const runDefaults = (kind: 'pipe-segment') => useEditor.getState().toolDefaults[kind] ?? {} +const pipes = () => + Object.values(useScene.getState().nodes).filter( + (node): node is PipeSegmentNode => node.type === 'pipe-segment', + ) +const expectPoint = (actual: Vec3 | undefined, expected: Vec3) => { + expect(actual).toBeDefined() + for (let i = 0; i < 3; i++) expect(actual![i]).toBeCloseTo(expected[i]!, 6) +} + +function Viewport() { + const gl = useThree((state) => state.gl) + gl.domElement.getBoundingClientRect = () => + ({ left: 0, top: 0, width: 100, height: 100 }) as DOMRect + return null +} +const mountTool = (tool: ReactElement) => + create( + false, + sceneApi: createSceneApi(useScene), + selectNode: () => {}, + unit: 'metric', + }} + > + + {tool} + , + ) + +const globals = ['window', 'document', 'IS_REACT_ACT_ENVIRONMENT'] as const +let savedGlobals: (PropertyDescriptor | undefined)[] = [] +let savedScope: ReturnType +let htmlLabels: ReturnType +beforeEach(() => { + savedGlobals = globals.map((name) => Object.getOwnPropertyDescriptor(globalThis, name)) + // Key listeners attach to window; labels portal into document.body. + for (const [name, value] of [ + ['window', new EventTarget()], + ['document', { body: { nodeType: 1, style: {} } }], + ['IS_REACT_ACT_ENVIRONMENT', true], + ] as const) + Object.defineProperty(globalThis, name, { value, configurable: true, writable: true }) + savedScope = useInteractionScope.getState() + labels.length = 0 + htmlLabels = spyOn( + Html as unknown as { render: (props: { children?: ReactNode }) => ReactNode }, + 'render', + ).mockImplementation((props) => { + labels.push(props.children) + return null + }) + for (const definition of [pipeSegmentDefinition, pipeFittingDefinition, pipeTrapDefinition]) + registerNode(definition as never) + useScene.setState({ + nodes: { + [building.id]: { ...building, children: [level.id] }, + [level.id]: { ...level, children: [trap.id] }, + [trap.id]: trap, + } as Record, + rootNodeIds: [building.id], + dirtyNodes: new Set(), + readOnly: false, + }) + useEditor.setState({ + mode: 'build', + magneticSnap: true, + snappingModeByContext: { ...useEditor.getState().snappingModeByContext, wall: 'lines' }, + }) +}) +afterEach(() => { + htmlLabels.mockRestore() + useInteractionScope.setState(savedScope, true) + globals.forEach((name, index) => { + const saved = savedGlobals[index] + if (saved) Object.defineProperty(globalThis, name, saved) + else Reflect.deleteProperty(globalThis, name) + }) +}) + +test('a pipe run from a fixed collar leaves along its axis, then takes the chosen grade', async () => { + const [x, y, z] = trapPort('outlet').position + useEditor.setState({ tool: 'pipe-segment' }) + useEditor.getState().setToolDefaults('pipe-segment', { + system: 'waste', + fall: 'sloped', + gradePercent: 2, + }) + const renderer = await mountTool() + try { + await move(x, z) + await click(x, z) + // The horizontal outlet is level, so the run adopts that. + expect(runDefaults('pipe-segment')).toMatchObject({ fall: 'level', gradePercent: 0 }) + + await setRunDefaults('pipe-segment', { fall: 'sloped', gradePercent: 2 }) + labels.length = 0 + await move(x + 1, z + 0.4) + await click(x + 1, z + 0.4) + expect(pipes()).toHaveLength(0) + expect(shown()).toContain( + 'The connection elevation conflicts with the chosen grade. Adjust the grade or target elevation.', + ) + expect(shown()).not.toContain('Fitting clearance') + + await setRunDefaults('pipe-segment', { fall: 'level' }) + await click(x + 1, z + 0.4) + const [first] = pipes() + expectPoint(first?.path[0], [x, y, z]) + expectPoint(first?.path.at(-1), [x + 1, y, z]) + + await setRunDefaults('pipe-segment', { fall: 'sloped', gradePercent: 2 }) + await move(x + 3, z) + await click(x + 3, z) + const second = pipes()[1] + expectPoint(second?.path[0], [x + 1, y, z]) + expect(pipeGrade(second!.path[0]!, second!.path.at(-1)!)).toBeCloseTo(0.02, 9) + } finally { + await renderer.unmount() + } +}) From f0977ddd06fa02f6f3c34d5006bd95b945f21e3a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 17:35:36 +0000 Subject: [PATCH 3/5] Leave vertical routing after a riser drawn from a fixed collar Drawing from a collar that points up or down sets Route to Vertical. After the riser reached the target elevation, the next vertical section aimed at the riser's own top, so every click was refused until the route or target changed. A committed riser out of a fixed collar now switches the pipe and duct tools to the plan route; a vertical route chosen from a pipe or duct end is left alone. Reported by Cursor Bugbot on #1236 ("Vertical collar draw blocks next segment"). --- packages/nodes/src/duct-segment/tool.tsx | 11 +++ packages/nodes/src/pipe-segment/tool.tsx | 4 + .../nodes/src/shared/collar-draw.test.tsx | 80 ++++++++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/packages/nodes/src/duct-segment/tool.tsx b/packages/nodes/src/duct-segment/tool.tsx index 8e5f5d9af2..9fca621809 100644 --- a/packages/nodes/src/duct-segment/tool.tsx +++ b/packages/nodes/src/duct-segment/tool.tsx @@ -709,6 +709,17 @@ const DuctSegmentTool = () => { delete: plan.delete, }) pendingPromotionRef.current = null + const startOwner = + startConnection.port && !promotedFitting ? sceneApi.get(startConnection.port.nodeId) : null + // A riser out of a fixed collar reaches the target; staying vertical would aim the + // next section at the riser's own top. + if ( + hangerDefaults?.routingMode === 'vertical' && + startOwner && + startOwner.type !== 'duct-segment' && + startOwner.type !== 'duct-fitting' + ) + updateRunDefaults('duct-segment', { routingMode: 'horizontal' }) const nextDuct = plan.ducts.at(-1) const nextStart = nextDuct ? nextDuct.path[nextDuct.path.length - 1]! : end const nextPort = nextDuct ? ductEndpointPort(nextDuct, 'end') : endConnection.port diff --git a/packages/nodes/src/pipe-segment/tool.tsx b/packages/nodes/src/pipe-segment/tool.tsx index b7359e5a53..8c4a75b72c 100644 --- a/packages/nodes/src/pipe-segment/tool.tsx +++ b/packages/nodes/src/pipe-segment/tool.tsx @@ -432,6 +432,10 @@ const PipeSegmentTool = () => { if (!sceneApi.applyChanges) throw new Error('Registry SceneApi must support atomic changes') sceneApi.applyChanges(changes) pendingPromotionRef.current = null + // A riser out of a fixed collar reaches the target; staying vertical would aim the + // next section at the riser's own top. + if (startCollar && hangerDefaults?.routingMode === 'vertical') + updateRunDefaults('pipe-segment', { routingMode: 'horizontal' }) } const nextStart = nextPipe ? nextPipe.path[nextPipe.path.length - 1]! : end const nextPort = nextPipe ? pipeEndpointPort(nextPipe, 'end') : endConnection.port diff --git a/packages/nodes/src/shared/collar-draw.test.tsx b/packages/nodes/src/shared/collar-draw.test.tsx index dbfd584b9c..13e8575550 100644 --- a/packages/nodes/src/shared/collar-draw.test.tsx +++ b/packages/nodes/src/shared/collar-draw.test.tsx @@ -4,6 +4,8 @@ import { type AnyNodeId, BuildingNode, createSceneApi, + type DuctSegmentNode, + DuctTerminalNode, emitter, LevelNode, type PipeSegmentNode, @@ -21,7 +23,13 @@ import { Html } from '@react-three/drei' import { useThree } from '@react-three/fiber' import { act, create } from '@react-three/test-renderer' import type { ReactElement, ReactNode } from 'react' +import { ductFittingDefinition } from '../duct-fitting/definition' +import { activateDuctCollarContinuation } from '../duct-segment/continuation' +import { ductSegmentDefinition } from '../duct-segment/definition' +import DuctSegmentTool from '../duct-segment/tool' +import { ductTerminalDefinition } from '../duct-terminal/definition' import { pipeFittingDefinition } from '../pipe-fitting/definition' +import { activatePipeCollarContinuation } from '../pipe-segment/continuation' import { pipeSegmentDefinition } from '../pipe-segment/definition' import { pipeGrade } from '../pipe-segment/slope' import PipeSegmentTool from '../pipe-segment/tool' @@ -37,6 +45,12 @@ const trap = PipeTrapNode.parse({ diameter: 1.5, pipeMaterial: 'abs', }) +const diffuser = DuctTerminalNode.parse({ + parentId: level.id, + position: [4, 2.7, 0], + mount: 'ceiling', + terminalType: 'diffuser', +}) const trapPort = (id: 'inlet' | 'outlet') => pipeTrapDefinition.ports!(trap).find((p) => p.id === id)! @@ -61,16 +75,21 @@ const plan = (x: number, z: number): EditorGridEvent => ({ }) const move = (x: number, z: number) => act(async () => emitter.emit('grid:move', plan(x, z))) const click = (x: number, z: number) => act(async () => emitter.emit('grid:click', plan(x, z))) -const setRunDefaults = (kind: 'pipe-segment', patch: Record) => +const setRunDefaults = (kind: 'pipe-segment' | 'duct-segment', patch: Record) => act(async () => { const editor = useEditor.getState() editor.setToolDefaults(kind, { ...editor.toolDefaults[kind], ...patch }) }) -const runDefaults = (kind: 'pipe-segment') => useEditor.getState().toolDefaults[kind] ?? {} +const runDefaults = (kind: 'pipe-segment' | 'duct-segment') => + useEditor.getState().toolDefaults[kind] ?? {} const pipes = () => Object.values(useScene.getState().nodes).filter( (node): node is PipeSegmentNode => node.type === 'pipe-segment', ) +const ducts = () => + Object.values(useScene.getState().nodes).filter( + (node): node is DuctSegmentNode => node.type === 'duct-segment', + ) const expectPoint = (actual: Vec3 | undefined, expected: Vec3) => { expect(actual).toBeDefined() for (let i = 0; i < 3; i++) expect(actual![i]).toBeCloseTo(expected[i]!, 6) @@ -120,13 +139,21 @@ beforeEach(() => { labels.push(props.children) return null }) - for (const definition of [pipeSegmentDefinition, pipeFittingDefinition, pipeTrapDefinition]) + for (const definition of [ + pipeSegmentDefinition, + pipeFittingDefinition, + pipeTrapDefinition, + ductSegmentDefinition, + ductFittingDefinition, + ductTerminalDefinition, + ]) registerNode(definition as never) useScene.setState({ nodes: { [building.id]: { ...building, children: [level.id] }, - [level.id]: { ...level, children: [trap.id] }, + [level.id]: { ...level, children: [trap.id, diffuser.id] }, [trap.id]: trap, + [diffuser.id]: diffuser, } as Record, rootNodeIds: [building.id], dirtyNodes: new Set(), @@ -189,3 +216,48 @@ test('a pipe run from a fixed collar leaves along its axis, then takes the chose await renderer.unmount() } }) + +test('a riser drawn from a vertical pipe collar continues on the plan route', async () => { + const inlet = trapPort('inlet') + const [x, y, z] = inlet.position + activatePipeCollarContinuation(trap, inlet) + expect(runDefaults('pipe-segment')).toMatchObject({ routingMode: 'vertical' }) + const renderer = await mountTool() + try { + await click(x + 0.5, z) + expect(pipes()).toHaveLength(1) + expectPoint(pipes()[0]?.path.at(-1), [x, y + 1, z]) + expect(runDefaults('pipe-segment').routingMode).toBe('horizontal') + + await move(x + 1.5, z) + await click(x + 1.5, z) + const [riser, across] = pipes() + expectPoint(riser?.path[0], [x, y, z]) + expectPoint(across?.path.at(-1), [x + 1.5, y + 1, z]) + expect(pipeGrade(across!.path[0]!, across!.path.at(-1)!)).toBeCloseTo(0, 9) + } finally { + await renderer.unmount() + } +}) + +test('a riser drawn from a vertical duct collar continues on the horizontal route', async () => { + const collar = ductTerminalDefinition.ports!(diffuser)[0]! + const [x, y, z] = collar.position + activateDuctCollarContinuation(diffuser, collar) + expect(runDefaults('duct-segment')).toMatchObject({ routingMode: 'vertical' }) + const renderer = await mountTool() + try { + await click(x + 0.5, z) + expect(ducts()).toHaveLength(1) + expectPoint(ducts()[0]?.path.at(-1), [x, y + 1, z]) + expect(runDefaults('duct-segment').routingMode).toBe('horizontal') + + await move(x + 1.5, z) + await click(x + 1.5, z) + const [riser, across] = ducts() + expectPoint(riser?.path[0], [x, y, z]) + expectPoint(across?.path.at(-1), [x + 1.5, y + 1, z]) + } finally { + await renderer.unmount() + } +}) From 1a250ac038ab76a508dee535678fcd0273c544ea Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 17:41:08 +0000 Subject: [PATCH 4/5] Check that a graded section after a collar joins without a bend The level first section and the 2% section after it meet directly; the only fitting is the end cap on the open end. --- packages/nodes/src/shared/collar-draw.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/nodes/src/shared/collar-draw.test.tsx b/packages/nodes/src/shared/collar-draw.test.tsx index 13e8575550..152c8612fd 100644 --- a/packages/nodes/src/shared/collar-draw.test.tsx +++ b/packages/nodes/src/shared/collar-draw.test.tsx @@ -8,6 +8,7 @@ import { DuctTerminalNode, emitter, LevelNode, + type PipeFittingNode, type PipeSegmentNode, PipeTrapNode, registerNode, @@ -86,6 +87,10 @@ const pipes = () => Object.values(useScene.getState().nodes).filter( (node): node is PipeSegmentNode => node.type === 'pipe-segment', ) +const fittings = () => + Object.values(useScene.getState().nodes).filter( + (node): node is PipeFittingNode => node.type === 'pipe-fitting', + ) const ducts = () => Object.values(useScene.getState().nodes).filter( (node): node is DuctSegmentNode => node.type === 'duct-segment', @@ -212,6 +217,8 @@ test('a pipe run from a fixed collar leaves along its axis, then takes the chose const second = pipes()[1] expectPoint(second?.path[0], [x + 1, y, z]) expect(pipeGrade(second!.path[0]!, second!.path.at(-1)!)).toBeCloseTo(0.02, 9) + // A 2% fall turns far less than any bend, so only the open end is capped. + expect(fittings().map((fitting) => fitting.fittingType)).toEqual(['end-cap']) } finally { await renderer.unmount() } From 5a20e28cd53f118f606f42a2b3efb1597e288ade Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 17:42:24 +0000 Subject: [PATCH 5/5] Keep a chosen vertical route after a riser from a run end The switch to the plan route applies only to risers out of a fixed collar; a vertical route chosen while drawing from a pipe or duct end stays on for the next riser. --- packages/nodes/src/shared/collar-draw.test.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/nodes/src/shared/collar-draw.test.tsx b/packages/nodes/src/shared/collar-draw.test.tsx index 152c8612fd..77758425ce 100644 --- a/packages/nodes/src/shared/collar-draw.test.tsx +++ b/packages/nodes/src/shared/collar-draw.test.tsx @@ -242,6 +242,12 @@ test('a riser drawn from a vertical pipe collar continues on the plan route', as expectPoint(riser?.path[0], [x, y, z]) expectPoint(across?.path.at(-1), [x + 1.5, y + 1, z]) expect(pipeGrade(across!.path[0]!, across!.path.at(-1)!)).toBeCloseTo(0, 9) + + await setRunDefaults('pipe-segment', { routingMode: 'vertical', targetElevation: y + 2 }) + await click(x + 2, z) + expect(pipes()).toHaveLength(3) + expectPoint(pipes()[2]?.path.at(-1), [x + 1.5, y + 2, z]) + expect(runDefaults('pipe-segment').routingMode).toBe('vertical') } finally { await renderer.unmount() } @@ -264,6 +270,12 @@ test('a riser drawn from a vertical duct collar continues on the horizontal rout const [riser, across] = ducts() expectPoint(riser?.path[0], [x, y, z]) expectPoint(across?.path.at(-1), [x + 1.5, y + 1, z]) + + await setRunDefaults('duct-segment', { routingMode: 'vertical', targetElevation: y + 2 }) + await click(x + 2, z) + expect(ducts()).toHaveLength(3) + expectPoint(ducts()[2]?.path.at(-1), [x + 1.5, y + 2, z]) + expect(runDefaults('duct-segment').routingMode).toBe('vertical') } finally { await renderer.unmount() }