Public: anyone can read this; the crew can change it.

A DXF drawing measures: pick two points and read the distance in the drawing's units #16827

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A .dxf blob page now measures: tap two points and the distance reads under the drawing, in the unit the file names. The new tests, tsc, design-lint and the neighbouring suites pass. I could not run the tap or keyboard flow in a browser here, so that part is untested.

Notes

opened this

A .dxf blob page now measures: tap two points and the distance reads under the drawing, in the unit the file names. The new tests, tsc, design-lint and the neighbouring suites pass. I could not run the tap or keyboard flow in a browser here, so that part is untested.

What changed

  • Unit: the parser reads $INSUNITS from the header. A file with it absent or 0, or a code outside the DXF unit table, says "names no unit" and shows raw units.
  • Distance: measureXY in measure.ts computes d = √(dx²+dy²) and returns text like 5 mm (Δx 3 · Δy 4). toDrawing maps a tap back from the SVG's fit to drawing coordinates, so the number is the file's distance, not the screen's.
  • Page: the figure carries the unit line and an aria-live readout. The tool is dxf-client.ts, bundled as /assets/dxf-<hash>.js and loaded only on a page with a drawing. This is the same pattern as the 3D viewer, with one route branch in server.ts.
  • Keyboard: focus the drawing, move the crosshair with the arrow keys, and press Enter or Space to pick. A third pick starts over.
  • Terminal: m on an open .dxf asks for x y x y and answers in the same words (measureDxfTyped). It shares one prompt with the 3D model measure.
  • Reused: distance, deltas, moveCrosshair, nextPicks, and one shared number reader behind both parseTwoPoints variants. The render caps are untouched.
  • Docs and tests: docs/features/file-dxf.md has a Measuring section. test/render-dxf.test.ts covers a 3-4-5 drawing, unit and no-unit files, the tap-to-drawing mapping, the terminal measure, and that the script builds.

Not done

  • No shareable URL for a measure; the state is not in the address.
  • Points are free taps, with no snapping to line ends. DXF bulges, units conversion and 3D entities are not handled.

Gate notes

  • gate.ts still lists two "one implementation?" similarity notes (build against the 3D viewer's build, and the two parseTwoPoints variants). I kept both as they are.
  • The "both doors" rule is satisfied by a No door: commit line, since the terminal door is the existing m key rather than a new screen.
  • I pushed once before the gate's findings were fixed; the second push is the clean one.

Try it: commit a .dxf with a $INSUNITS header (9 / $INSUNITS / 70 / 4) and open its file page. Tap two points, or Tab to the drawing, use the arrows and press Enter. Without the header variable, the page says it names no unit and shows raw units.

[
 {"go":"/<owner>/<repo>/blob/main/<file>.dxf","look":"the line under the drawing naming the unit, and the readout text","expect":"'Distances are in mm…' for a file with $INSUNITS 4, 'names no unit' otherwise"},
 {"go":"same page","look":"tap two points on the drawing","expect":"two dots and a dashed line; readout '5 mm (Δx 3 · Δy 4)' style; a third tap restarts"},
 {"go":"same page","look":"Tab to the drawing, arrows, Enter twice","expect":"focus ring, crosshair moves, same readout text"}
]

Closes #16314

2 earlier comments
commented

A .dxf blob page now measures: tap two points and the distance reads under the drawing, in the unit the file names. The new tests, tsc, design-lint and the neighbouring suites pass. I could not run the tap or keyboard flow in a browser here, so that part is untested.

What changed

  • Unit: the parser reads $INSUNITS from the header. A file with it absent or 0, or a code outside the DXF unit table, says "names no unit" and shows raw units.
  • Distance: measureXY in measure.ts computes d = √(dx²+dy²) and returns text like 5 mm (Δx 3 · Δy 4). toDrawing maps a tap back from the SVG's fit to drawing coordinates, so the number is the file's distance, not the screen's.
  • Page: the figure carries the unit line and an aria-live readout. The tool is dxf-client.ts, bundled as /assets/dxf-<hash>.js and loaded only on a page with a drawing. This is the same pattern as the 3D viewer, with one route branch in server.ts.
  • Keyboard: focus the drawing, move the crosshair with the arrow keys, and press Enter or Space to pick. A third pick starts over.
  • Terminal: m on an open .dxf asks for x y x y and answers in the same words (measureDxfTyped). It shares one prompt with the 3D model measure.
  • Reused: distance, deltas, moveCrosshair, nextPicks, and one shared number reader behind both parseTwoPoints variants. The render caps are untouched.
  • Docs and tests: docs/features/file-dxf.md has a Measuring section. test/render-dxf.test.ts covers a 3-4-5 drawing, unit and no-unit files, the tap-to-drawing mapping, the terminal measure, and that the script builds.

Not done

  • No shareable URL for a measure; the state is not in the address.
  • Points are free taps, with no snapping to line ends. DXF bulges, units conversion and 3D entities are not handled.

Gate notes

  • gate.ts still lists two "one implementation?" similarity notes (build against the 3D viewer's build, and the two parseTwoPoints variants). I kept both as they are.
  • The "both doors" rule is satisfied by a No door: commit line, since the terminal door is the existing m key rather than a new screen.
  • I pushed once before the gate's findings were fixed; the second push is the clean one.

Try it: commit a .dxf with a $INSUNITS header (9 / $INSUNITS / 70 / 4) and open its file page. Tap two points, or Tab to the drawing, use the arrows and press Enter. Without the header variable, the page says it names no unit and shows raw units.

[
 {"go":"/<owner>/<repo>/blob/main/<file>.dxf","look":"the line under the drawing naming the unit, and the readout text","expect":"'Distances are in mm…' for a file with $INSUNITS 4, 'names no unit' otherwise"},
 {"go":"same page","look":"tap two points on the drawing","expect":"two dots and a dashed line; readout '5 mm (Δx 3 · Δy 4)' style; a third tap restarts"},
 {"go":"same page","look":"Tab to the drawing, arrows, Enter twice","expect":"focus ring, crosshair moves, same readout text"}
]
commented

This push fixes the "every module under src/ is imported by another, or allowed" failure. I did not look into the other two failures, and I haven't seen the check's verdict on this push.

src/web/render/dxf-client.ts is bundled by Bun.build in dxf-asset.ts and imported by nothing. I added it to ENTRIES in scripts/unreached.ts, next to highlight-client.ts, which works the same way.

  • Local runs: unreached, media and sentinel-causes pass together, and bun x tsc --noEmit is clean.
  • The other two failures: the "blob page's switch" failure was in test/media.test.ts and the "cause is one issue" failure in test/sentinel-causes.test.ts. Both pass here. Both ran in shards that also hit a changed or shared module, and the check log shows test/media.test.ts green on main, so I assumed they fell with it. I haven't confirmed that.
  • Gate output: scripts/gate.ts --fix printed two "one implementation?" notes: dxf-asset.ts#build against asset.ts#build, and parseTwoPoints2d against parseTwoPoints. I left both as they are.
commented

All four points are addressed and pushed. tsc, design-lint and the tests I ran for this change pass. The check hasn't run on this push yet, and I did not run the whole suite.

  • Pick logic and tests: measure.ts now has a pure pick(marks, sx, sy, frame, unit) that returns the marks and the readout text, plus crosshairPoint and pickPrompt. dxf-client.ts only wires events to them. test/render-dxf.test.ts covers the 1st, 2nd and 3rd tap and a keyboard move-then-pick. The imports are at the top of the file, and the weak toContain("data-measure") check is replaced.
  • Page explains itself once: the unit now appears once, in the readout line, and the separate unit paragraph and the result suffix are gone. The instruction is added by the script, so with JavaScript off the readout shows only the unit line. A test asserts the unit text appears once.
  • Accessibility: the drawing keeps role="img" and its label. The script adds aria-describedby pointing at the readout (id="dxf-readout"), and role=application is gone.
  • One bundling helper: bundleEntry(entry, name, event, plugins?) in asset.ts is now used by the highlight, 3D and DXF assets. server.ts handles model3d- and dxf- in one loop.
  • Terminal m: while testing it I found m was also bound on a binary .dxf, where the page shows a hex view. The t.note === "" check passed there, because that view has no note. The binding now requires that the text parses as DXF (isDrawing in workspace.ts), and test/tui-dxf-measure.test.ts covers both a drawn and an undrawable file.

I left the scripts/gate.ts note about parseTwoPoints2d resembling parseTwoPoints alone. They differ in arity and in the error text they return. The terminal's measureDxfTyped also lost the "· the file names no unit" suffix, so the terminal and the page now word the result the same way.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs