The px-per-mm mapping was a hard-coded guess twice over, and the right value depends on the monitor - AutoCAD has the same knob as the Adjust Display Scale slider. Expose it: a slider plus a number box next to the lineweight toggle, with a readout of what the drawing's own weights come out to (0.35mm -> 7px, 0.50mm -> 10px at the 20 px/mm default). The value persists in localStorage. Retuning applies to the live materials instead of rebuilding the scene. The hairline cut-off is a millimetre value, so changing the scale moves every weight by the same factor without changing which bucket a segment belongs to - each fat batch now remembers its weight in mm, and only material.linewidth is rewritten. That keeps a drag on the slider instant even on the 37 MB road drawing. Measured headless on its 0.35mm gutter line: 2-3px at scale 8, 7px at 20, 14px at 40 - matching the readout in each case. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
43 lines
2.2 KiB
TypeScript
43 lines
2.2 KiB
TypeScript
// Types for the ported JS 2D engine (Viewer2D.js). Colocated so tsc resolves
|
|
// `./Viewer2D.js` imports without allowJs. Only the methods the app uses are typed.
|
|
import type { CadSpace } from './cadSpaces';
|
|
|
|
export class Viewer2D {
|
|
constructor(container: HTMLElement);
|
|
/** Render a DWG/DXF parseResult. `keepView` preserves pan/zoom on re-render. */
|
|
load(result: unknown, opts?: { keepView?: boolean; keepTheme?: boolean; spaceHandle?: string | number | null }): void;
|
|
/** Zoom-extents to the loaded drawing. */
|
|
fit(): void;
|
|
/** Resync renderer/camera to the container size (call after un-hiding). */
|
|
resize(): void;
|
|
onSelect(cb: (entity: unknown) => void): void;
|
|
getSelectedEntity(): unknown;
|
|
zoomToSelection(): void;
|
|
setAccent(hex: string): void;
|
|
setTheme(dark: boolean): void;
|
|
setGrid(visible: boolean): void;
|
|
/** Lineweight display (AutoCAD LWDISPLAY); null follows the drawing's own flag. */
|
|
setLineweightEnabled(on: boolean | null): void;
|
|
getLineweightEnabled(): boolean;
|
|
/** Lineweight display scale in px per mm (AutoCAD's display-scale slider). Default 20. */
|
|
setLineweightScale(pxPerMm: number | null): void;
|
|
getLineweightScale(): number;
|
|
/** Distinct lineweights (mm) present in the loaded drawing, ascending. */
|
|
getLineweightClasses(): number[];
|
|
getLayerInfo(): { name: string; colorHex: string; count: number; visible: boolean }[];
|
|
setHiddenLayers(nameSet: Set<string>): void;
|
|
/** Model / Paper (Layout) spaces for the loaded drawing. */
|
|
getSpaces(): CadSpace[];
|
|
getActiveSpace(): string | null;
|
|
/** Switch Model ↔ Layout; re-renders (fit unless keepView). */
|
|
setSpace(spaceHandle: string | number | null, opts?: { keepView?: boolean }): void;
|
|
getZoomPercent(): number;
|
|
onViewChange(cb: () => void): void;
|
|
/** Screen client coords → drawing world (Z=0 plane). */
|
|
screenToWorld(clientX: number, clientY: number): { x: number; y: number; z: number } | null;
|
|
/** Live CAD coords under the cursor; null when pointer leaves the canvas. */
|
|
onPointerWorld(cb: ((p: { x: number; y: number; z: number } | null) => void) | null): void;
|
|
startMeasure(cb: (r: { phase: string; ax: number; ay: number; az: number; bx: number; by: number; bz: number; d: number }) => void): void;
|
|
stopMeasure(): void;
|
|
}
|