@reekon-tools/boldr-cad 1.5.0 → 1.7.0
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.
- package/README.md +12 -1
- package/dist/app/state.d.ts +3 -3
- package/dist/data/provider.d.ts +2 -1
- package/dist/data/sync.js +4 -1
- package/dist/data/sync.js.map +1 -1
- package/dist/editor/actions.js +122 -19
- package/dist/editor/actions.js.map +1 -1
- package/dist/editor/advance.d.ts +2 -0
- package/dist/editor/advance.js +23 -0
- package/dist/editor/advance.js.map +1 -0
- package/dist/editor/dimSize.d.ts +13 -0
- package/dist/editor/dimSize.js +50 -0
- package/dist/editor/dimSize.js.map +1 -0
- package/dist/editor/gestures.js +30 -7
- package/dist/editor/gestures.js.map +1 -1
- package/dist/editor/keypad.d.ts +8 -0
- package/dist/editor/keypad.js +15 -1
- package/dist/editor/keypad.js.map +1 -1
- package/dist/editor/keys.js +2 -1
- package/dist/editor/keys.js.map +1 -1
- package/dist/editor/laser.d.ts +13 -2
- package/dist/editor/laser.js +42 -14
- package/dist/editor/laser.js.map +1 -1
- package/dist/editor/linkActions.d.ts +29 -11
- package/dist/editor/linkActions.js +76 -29
- package/dist/editor/linkActions.js.map +1 -1
- package/dist/editor/links.d.ts +13 -0
- package/dist/editor/links.js +7 -1
- package/dist/editor/links.js.map +1 -1
- package/dist/editor/mode.d.ts +2 -1
- package/dist/editor/mode.js +7 -5
- package/dist/editor/mode.js.map +1 -1
- package/dist/editor/ports.d.ts +9 -0
- package/dist/editor/ports.js +2 -0
- package/dist/editor/ports.js.map +1 -1
- package/dist/editor/selection.js +1 -1
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/tooltips.js +1 -0
- package/dist/editor/tooltips.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/model/clockwise.d.ts +11 -0
- package/dist/model/clockwise.js +123 -0
- package/dist/model/clockwise.js.map +1 -0
- package/dist/model/constraints.js +2 -0
- package/dist/model/constraints.js.map +1 -1
- package/dist/model/geom.d.ts +2 -0
- package/dist/model/geom.js +11 -0
- package/dist/model/geom.js.map +1 -1
- package/dist/model/links.d.ts +6 -1
- package/dist/model/links.js +6 -1
- package/dist/model/links.js.map +1 -1
- package/dist/model/scale.js +3 -0
- package/dist/model/scale.js.map +1 -1
- package/dist/model/settings.d.ts +2 -0
- package/dist/model/settings.js +1 -1
- package/dist/model/settings.js.map +1 -1
- package/dist/model/sketch.d.ts +5 -1
- package/dist/model/sketch.js +19 -18
- package/dist/model/sketch.js.map +1 -1
- package/dist/model/trim.d.ts +54 -0
- package/dist/model/trim.js +219 -0
- package/dist/model/trim.js.map +1 -0
- package/dist/model/types.d.ts +24 -2
- package/dist/react/BottomBar.js +94 -25
- package/dist/react/BottomBar.js.map +1 -1
- package/dist/react/CadEditor.js +18 -9
- package/dist/react/CadEditor.js.map +1 -1
- package/dist/react/Drawer.js +3 -2
- package/dist/react/Drawer.js.map +1 -1
- package/dist/react/PlanCanvas.native.js +15 -9
- package/dist/react/PlanCanvas.native.js.map +1 -1
- package/dist/react/PlanCanvas.web.js +17 -5
- package/dist/react/PlanCanvas.web.js.map +1 -1
- package/dist/react/ShapeMenu.js +3 -2
- package/dist/react/ShapeMenu.js.map +1 -1
- package/dist/react/ToolTip.js +3 -2
- package/dist/react/ToolTip.js.map +1 -1
- package/dist/react/TopBar.js +4 -3
- package/dist/react/TopBar.js.map +1 -1
- package/dist/react/editorBox.d.ts +8 -0
- package/dist/react/editorBox.js +10 -0
- package/dist/react/editorBox.js.map +1 -0
- package/dist/react/host.d.ts +7 -1
- package/dist/react/host.js +12 -2
- package/dist/react/host.js.map +1 -1
- package/dist/react/pageLock.native.d.ts +2 -0
- package/dist/react/pageLock.native.js +2 -0
- package/dist/react/pageLock.native.js.map +1 -1
- package/dist/react/pageLock.web.d.ts +6 -0
- package/dist/react/pageLock.web.js +12 -3
- package/dist/react/pageLock.web.js.map +1 -1
- package/dist/react/ports.js +10 -4
- package/dist/react/ports.js.map +1 -1
- package/dist/react/saving.d.ts +7 -1
- package/dist/react/saving.js +10 -2
- package/dist/react/saving.js.map +1 -1
- package/dist/react/store.d.ts +5 -2
- package/dist/react/store.js +4 -1
- package/dist/react/store.js.map +1 -1
- package/dist/render/draw.d.ts +7 -0
- package/dist/render/draw.js +41 -15
- package/dist/render/draw.js.map +1 -1
- package/dist/render/linkTile.js +2 -2
- package/dist/render/linkTile.js.map +1 -1
- package/dist/render/navigate.d.ts +11 -6
- package/dist/render/navigate.js +34 -20
- package/dist/render/navigate.js.map +1 -1
- package/dist/render/snap.d.ts +5 -0
- package/dist/render/snap.js +84 -14
- package/dist/render/snap.js.map +1 -1
- package/dist/render/view.js +7 -2
- package/dist/render/view.js.map +1 -1
- package/dist/solver/equations.js +30 -16
- package/dist/solver/equations.js.map +1 -1
- package/dist/tools/dim.d.ts +6 -0
- package/dist/tools/dim.js +28 -4
- package/dist/tools/dim.js.map +1 -1
- package/dist/tools/modify.d.ts +32 -4
- package/dist/tools/modify.js +247 -97
- package/dist/tools/modify.js.map +1 -1
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.js +8 -0
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/select.d.ts +11 -8
- package/dist/tools/select.js +51 -19
- package/dist/tools/select.js.map +1 -1
- package/package.json +1 -1
- package/src/app/state.ts +3 -3
- package/src/data/provider.ts +2 -2
- package/src/data/sync.ts +4 -1
- package/src/editor/actions.ts +98 -16
- package/src/editor/advance.ts +23 -0
- package/src/editor/dimSize.ts +53 -0
- package/src/editor/gestures.ts +31 -9
- package/src/editor/keypad.ts +17 -1
- package/src/editor/keys.ts +2 -1
- package/src/editor/laser.ts +45 -14
- package/src/editor/linkActions.ts +87 -26
- package/src/editor/links.ts +17 -1
- package/src/editor/mode.ts +7 -5
- package/src/editor/ports.ts +10 -0
- package/src/editor/selection.ts +1 -1
- package/src/editor/tooltips.ts +1 -0
- package/src/index.ts +2 -2
- package/src/model/clockwise.ts +121 -0
- package/src/model/constraints.ts +1 -0
- package/src/model/geom.ts +10 -0
- package/src/model/links.ts +6 -1
- package/src/model/scale.ts +2 -0
- package/src/model/settings.ts +3 -1
- package/src/model/sketch.ts +14 -7
- package/src/model/trim.ts +188 -0
- package/src/model/types.ts +19 -2
- package/src/react/BottomBar.tsx +109 -25
- package/src/react/CadEditor.tsx +19 -9
- package/src/react/Drawer.tsx +3 -2
- package/src/react/PlanCanvas.native.tsx +25 -12
- package/src/react/PlanCanvas.web.tsx +17 -5
- package/src/react/ShapeMenu.tsx +3 -2
- package/src/react/ToolTip.tsx +3 -2
- package/src/react/TopBar.tsx +4 -3
- package/src/react/editorBox.ts +20 -0
- package/src/react/host.ts +12 -2
- package/src/react/pageLock.native.ts +2 -0
- package/src/react/pageLock.web.ts +12 -3
- package/src/react/ports.ts +10 -4
- package/src/react/saving.ts +10 -2
- package/src/react/store.ts +5 -2
- package/src/render/draw.ts +38 -16
- package/src/render/linkTile.ts +2 -2
- package/src/render/navigate.ts +31 -20
- package/src/render/snap.ts +80 -15
- package/src/render/view.ts +6 -2
- package/src/solver/equations.ts +30 -16
- package/src/tools/dim.ts +28 -4
- package/src/tools/modify.ts +205 -69
- package/src/tools/registry.ts +8 -0
- package/src/tools/select.ts +47 -20
- package/src/ui/domPorts.ts +2 -0
- package/dist/react/LaserTray.d.ts +0 -4
- package/dist/react/LaserTray.js +0 -26
- package/dist/react/LaserTray.js.map +0 -1
- package/src/react/LaserTray.tsx +0 -42
package/src/render/navigate.ts
CHANGED
|
@@ -59,46 +59,57 @@ export interface UiView extends NavView { seq: number }
|
|
|
59
59
|
/** What the drawing on screen was drawn at: its view, the latest of the fingers' views it includes, the screen size. */
|
|
60
60
|
export interface DrawnAt { view: NavView; seq: number; W: number; H: number }
|
|
61
61
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* The pointers on the screen and what they're doing: the fingers that count (a finger a Pencil landed on doesn't — see
|
|
64
|
+
* navTouch), navigating or not, where they were last, and any Pencil down.
|
|
65
|
+
*/
|
|
66
|
+
export interface NavState { fingers: Record<number, { x: number; y: number }>; navigating: boolean; last: Pinch | null; pens: number[] }
|
|
64
67
|
|
|
65
68
|
export const NAV_DOWN = 0, NAV_MOVE = 1, NAV_UP = 2, NAV_CANCEL = 3;
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
71
|
* One touch event, as the UI thread sees it: the fingers after it, and the view (moved if `moved`). Fingers navigate —
|
|
69
|
-
* pan, and zoom about their middle — once two are down, or
|
|
70
|
-
* view only (editor/gestures.ts decides the same on its side), until the last one lifts. A
|
|
71
|
-
*
|
|
72
|
-
*
|
|
72
|
+
* pan, and zoom about their middle — once two are down, or a finger lands while a Pencil is down or when the drawing is
|
|
73
|
+
* view only (editor/gestures.ts decides the same on its side), until the last one lifts. A finger already down and not
|
|
74
|
+
* navigating when a Pencil lands is set aside until it lifts. A pen or a mouse never navigates. `type` is NAV_DOWN… ;
|
|
75
|
+
* `kind` is the event's pointer, for a touch that doesn't say what it is itself; `allIds`, every pointer still down (on
|
|
76
|
+
* a down event: a finger that went without a word, a lost touch-up, is dropped so it can't hold a gesture open).
|
|
73
77
|
*/
|
|
74
78
|
export function navTouch(
|
|
75
|
-
st: NavState, type: number, kind: string, changed: { id: number; x: number; y: number }[], allIds: number[] | null,
|
|
79
|
+
st: NavState, type: number, kind: string, changed: { id: number; x: number; y: number; kind?: string }[], allIds: number[] | null,
|
|
76
80
|
readOnly: boolean, view: UiView, drawn: DrawnAt | null,
|
|
77
81
|
): { st: NavState; view: UiView; moved: boolean } {
|
|
78
82
|
'worklet';
|
|
79
|
-
const
|
|
80
|
-
if (kind !== 'touch') return { st: { ...st, pen }, view, moved: false };
|
|
83
|
+
const lost = (id: number) => type === NAV_DOWN && !!allIds && !allIds.includes(id);
|
|
81
84
|
const fingers: Record<number, { x: number; y: number }> = {};
|
|
82
|
-
for (const k in st.fingers)
|
|
83
|
-
|
|
84
|
-
if (type !== NAV_DOWN || !allIds || allIds.includes(id)) fingers[id] = st.fingers[id];
|
|
85
|
-
}
|
|
85
|
+
for (const k in st.fingers) if (!lost(Number(k))) fingers[Number(k)] = st.fingers[Number(k)];
|
|
86
|
+
let pens = st.pens.filter(id => !lost(id)), landed = false, moved = false;
|
|
86
87
|
for (const t of changed) {
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const k = t.kind ?? kind;
|
|
89
|
+
if (type === NAV_UP || type === NAV_CANCEL) {
|
|
90
|
+
delete fingers[t.id];
|
|
91
|
+
pens = pens.filter(id => id !== t.id);
|
|
92
|
+
} else if (type === NAV_DOWN && k === 'pen') {
|
|
93
|
+
if (!pens.includes(t.id)) pens = [...pens, t.id];
|
|
94
|
+
// (fingers down and not navigating are let go of: their moves and lifts are no finger's from here)
|
|
95
|
+
if (!st.navigating) for (const f in fingers) delete fingers[f];
|
|
96
|
+
} else if (type === NAV_DOWN ? k === 'touch' : t.id in fingers) {
|
|
97
|
+
fingers[t.id] = { x: t.x, y: t.y };
|
|
98
|
+
if (type === NAV_DOWN) landed = true; else moved = true;
|
|
99
|
+
}
|
|
89
100
|
}
|
|
90
101
|
const pts = Object.keys(fingers).map(k => fingers[Number(k)]);
|
|
91
|
-
if (!pts.length) return { st: { fingers, navigating: false, last: null,
|
|
102
|
+
if (!pts.length) return { st: { fingers, navigating: false, last: null, pens }, view, moved: false };
|
|
92
103
|
let navigating = st.navigating, v = view;
|
|
93
104
|
if (!navigating) {
|
|
94
|
-
if (pts.length < 2 && !(
|
|
105
|
+
if (pts.length < 2 && !(landed && (pens.length > 0 || readOnly))) return { st: { fingers, navigating: false, last: null, pens }, view, moved: false };
|
|
95
106
|
navigating = true;
|
|
96
107
|
// start from the view the drawing on screen was drawn at, unless the fingers' own is newer
|
|
97
108
|
if (drawn && v.seq <= drawn.seq) v = { s: drawn.view.s, cx: drawn.view.cx, cy: drawn.view.cy, seq: drawn.seq };
|
|
98
109
|
}
|
|
99
|
-
const now = pinchOf(pts), was = st.last, next = { fingers, navigating, last: now,
|
|
100
|
-
// a finger came or went: carry on from here, no jump
|
|
101
|
-
if (type !== NAV_MOVE || !now || !was || was.n !== now.n || !drawn) return { st: next, view: v, moved: false };
|
|
110
|
+
const now = pinchOf(pts), was = st.last, next = { fingers, navigating, last: now, pens };
|
|
111
|
+
// a finger came or went: carry on from here, no jump (and a Pencil's move alone moves no view)
|
|
112
|
+
if (type !== NAV_MOVE || !moved || !now || !was || was.n !== now.n || !drawn) return { st: next, view: v, moved: false };
|
|
102
113
|
const to = navStep(v, was, now, drawn.W, drawn.H);
|
|
103
114
|
return { st: next, view: { s: to.s, cx: to.cx, cy: to.cy, seq: v.seq + 1 }, moved: true };
|
|
104
115
|
}
|
package/src/render/snap.ts
CHANGED
|
@@ -2,9 +2,12 @@ import { ed, type Guide, type Snap } from '../app/state';
|
|
|
2
2
|
import { distSeg, hyp, norm2, projT, segInter } from '../model/geom';
|
|
3
3
|
import { settings } from '../model/settings';
|
|
4
4
|
import { SK } from '../model/store';
|
|
5
|
-
import { gridSteps } from '../model/planGeom';
|
|
5
|
+
import { edgeId, gridSteps } from '../model/planGeom';
|
|
6
|
+
import { faceCorner, wallFace } from '../model/wallfaces';
|
|
7
|
+
import type { Sketch, XY } from '../model/types';
|
|
6
8
|
import { mainT, S, s2w } from './view';
|
|
7
9
|
import { intoWall } from '../editor/elevation';
|
|
10
|
+
import { drawsWalls } from '../editor/mode';
|
|
8
11
|
|
|
9
12
|
export interface SnapOpts {
|
|
10
13
|
touch?: boolean;
|
|
@@ -18,6 +21,38 @@ export interface SnapOpts {
|
|
|
18
21
|
/** start of the segment being drawn (enables H/V/perpendicular inference) */
|
|
19
22
|
from?: string | null;
|
|
20
23
|
prevLine?: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Onto walls' faces beside the pointer, and the corners where two meet. On unless walls are being drawn: walls join
|
|
26
|
+
* along their centrelines (and a wall's own corner, dragged, says so).
|
|
27
|
+
*/
|
|
28
|
+
faces?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Where two of `walls`' faces meet — an inside corner, or an outside one a face wraps — and the two edges there. */
|
|
32
|
+
function faceCorners(sk: Sketch, walls: Set<string>): { x: number; y: number; refs: [string, string] }[] {
|
|
33
|
+
const out: { x: number; y: number; refs: [string, string] }[] = [];
|
|
34
|
+
for (const id of walls) {
|
|
35
|
+
for (const side of [1, -1] as const) {
|
|
36
|
+
for (const end of ['a', 'b'] as const) {
|
|
37
|
+
const p = faceCorner(sk, id, side, end);
|
|
38
|
+
if (!p) continue;
|
|
39
|
+
let other: string | null = null;
|
|
40
|
+
for (const w of walls) if (w !== id && (other = faceThrough(sk, w, p))) break;
|
|
41
|
+
if (other) out.push({ x: p.x, y: p.y, refs: [edgeId(id, side), other] });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The face of straight wall `id` that point `p` is on, between that face's corners (its edge id), if it's on one. */
|
|
49
|
+
function faceThrough(sk: Sketch, id: string, p: XY): string | null {
|
|
50
|
+
const l = sk.lines[id], A = sk.points[l.a], B = sk.points[l.b], L = hyp(B.x - A.x, B.y - A.y);
|
|
51
|
+
if (L < 1e-9) return null;
|
|
52
|
+
const k = ((B.x - A.x) * (p.y - A.y) - (B.y - A.y) * (p.x - A.x)) / L, side = k > 0 ? 1 : -1;
|
|
53
|
+
if (Math.abs(Math.abs(k) - l.thick / 2) > 1e-6) return null;
|
|
54
|
+
const f = wallFace(sk, id, side), s = ((p.x - A.x) * (B.x - A.x) + (p.y - A.y) * (B.y - A.y)) / L;
|
|
55
|
+
return f && s >= f.s0 - 1e-6 && s <= f.s1 + 1e-6 ? edgeId(id, side) : null;
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
/** Snap a screen point: endpoints > midpoints/intersections > on line > H/V/perp guides > on circle > grid. In the wall view, never past the wall. */
|
|
@@ -97,20 +132,36 @@ function snapRaw(sx: number, sy: number, o: SnapOpts): Snap {
|
|
|
97
132
|
const p = sk.points[ci.c];
|
|
98
133
|
cand(p.x, p.y, 'point', ci.c, 0, 'Center');
|
|
99
134
|
}
|
|
135
|
+
// straight walls near the pointer, for their faces: a face corner is a corner as an endpoint is (the nearer wins).
|
|
136
|
+
// Beside one (not over it), what's inside it — its centreline's middle, where something crosses its centreline — isn't
|
|
137
|
+
// snapped to: that's what landed lines half a wall's thickness inside it
|
|
138
|
+
const walls = new Set<string>(), beside = new Set<string>();
|
|
139
|
+
if (o.faces ?? !drawsWalls()) {
|
|
140
|
+
for (const id in sk.lines) {
|
|
141
|
+
const l = sk.lines[id];
|
|
142
|
+
if (l.kind !== 'wall' || l.constr || !(l.thick > 0) || ex.has(l.a) || ex.has(l.b) || o.excludeLines?.has(id)) continue;
|
|
143
|
+
const A = sk.points[l.a], B = sk.points[l.b], [ax, ay] = S(T, A.x, A.y), [bx, by] = S(T, B.x, B.y);
|
|
144
|
+
if (distSeg({ x: sx, y: sy }, { x: ax, y: ay }, { x: bx, y: by }) >= tol * 3 + (l.thick / 2) * T.s) continue;
|
|
145
|
+
walls.add(id);
|
|
146
|
+
const L = hyp(B.x - A.x, B.y - A.y);
|
|
147
|
+
if (L > 1e-9 && Math.abs((B.x - A.x) * (wy - A.y) - (B.y - A.y) * (wx - A.x)) / L > l.thick / 2) beside.add(id);
|
|
148
|
+
}
|
|
149
|
+
for (const c of faceCorners(sk, walls)) cand(c.x, c.y, 'facecorner', c.refs, 0, 'Face corner');
|
|
150
|
+
}
|
|
100
151
|
const near: string[] = [];
|
|
101
152
|
for (const id in sk.lines) {
|
|
102
153
|
if (o.excludeLines && o.excludeLines.has(id)) continue;
|
|
103
154
|
const l = sk.lines[id];
|
|
104
155
|
if (ex.has(l.a) || ex.has(l.b)) continue;
|
|
105
156
|
const A = sk.points[l.a], B = sk.points[l.b];
|
|
106
|
-
cand((A.x + B.x) / 2, (A.y + B.y) / 2, 'mid', id, 1, 'Midpoint');
|
|
157
|
+
if (!beside.has(id)) cand((A.x + B.x) / 2, (A.y + B.y) / 2, 'mid', id, 1, 'Midpoint');
|
|
107
158
|
const [ax, ay] = S(T, A.x, A.y), [bx, by] = S(T, B.x, B.y);
|
|
108
|
-
if (distSeg({ x: sx, y: sy }, { x: ax, y: ay }, { x: bx, y: by }) < tol * 3) near.push(id);
|
|
159
|
+
if (walls.has(id) || distSeg({ x: sx, y: sy }, { x: ax, y: ay }, { x: bx, y: by }) < tol * 3) near.push(id);
|
|
109
160
|
}
|
|
110
161
|
for (let i = 0; i < near.length; i++) {
|
|
111
162
|
for (let j = i + 1; j < near.length; j++) {
|
|
112
163
|
const l1 = sk.lines[near[i]], l2 = sk.lines[near[j]];
|
|
113
|
-
if (l1.a === l2.a || l1.a === l2.b || l1.b === l2.a || l1.b === l2.b) continue;
|
|
164
|
+
if (l1.a === l2.a || l1.a === l2.b || l1.b === l2.a || l1.b === l2.b || beside.has(near[i]) || beside.has(near[j])) continue;
|
|
114
165
|
const r = segInter(sk.points[l1.a], sk.points[l1.b], sk.points[l2.a], sk.points[l2.b]);
|
|
115
166
|
if (r) cand(r.x, r.y, 'inter', [near[i], near[j]], 1, 'Intersection');
|
|
116
167
|
}
|
|
@@ -121,15 +172,27 @@ function snapRaw(sx: number, sy: number, o: SnapOpts): Snap {
|
|
|
121
172
|
}
|
|
122
173
|
// on a line, near the pointer (checked before the alignment guides: a line under the pointer wins over lining up with
|
|
123
174
|
// a point elsewhere — where both apply, the snap is where the guide crosses the line)
|
|
124
|
-
|
|
175
|
+
// (a wall with the pointer beside it, not over it: its face on that side, between the face's corners — t0 to t1 of
|
|
176
|
+
// the face's own A → B, which is the centreline's moved over)
|
|
177
|
+
let bestL: { d: number; x: number; y: number; id: string; A: XY; B: XY; t0: number; t1: number; face?: 1 | -1 } | null = null;
|
|
125
178
|
for (const id of near) {
|
|
126
|
-
const l = sk.lines[id]
|
|
179
|
+
const l = sk.lines[id];
|
|
180
|
+
let A: XY = sk.points[l.a], B: XY = sk.points[l.b], t0 = 0, t1 = 1, face: 1 | -1 | undefined;
|
|
181
|
+
if (walls.has(id)) {
|
|
182
|
+
const L = hyp(B.x - A.x, B.y - A.y), k = ((B.x - A.x) * (wy - A.y) - (B.y - A.y) * (wx - A.x)) / L, side = k > 0 ? 1 : -1;
|
|
183
|
+
const f = Math.abs(k) > l.thick / 2 ? wallFace(sk, id, side) : null;
|
|
184
|
+
if (f) {
|
|
185
|
+
const nx = (-(B.y - A.y) / L) * side * (l.thick / 2), ny = ((B.x - A.x) / L) * side * (l.thick / 2);
|
|
186
|
+
A = { x: A.x + nx, y: A.y + ny }; B = { x: B.x + nx, y: B.y + ny };
|
|
187
|
+
t0 = f.s0 / L; t1 = f.s1 / L; face = side;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
127
190
|
const t = projT(A, B, { x: wx, y: wy });
|
|
128
|
-
if (t <
|
|
191
|
+
if (t < t0 || t > t1) continue;
|
|
129
192
|
const fx = A.x + (B.x - A.x) * t, fy = A.y + (B.y - A.y) * t;
|
|
130
193
|
const [qx, qy] = S(T, fx, fy);
|
|
131
194
|
const d = hyp(qx - sx, qy - sy);
|
|
132
|
-
if (d < tol && (!bestL || d < bestL.d)) bestL = { d, x: fx, y: fy, id };
|
|
195
|
+
if (d < tol && (!bestL || d < bestL.d)) bestL = { d, x: fx, y: fy, id, A, B, t0, t1, face };
|
|
133
196
|
}
|
|
134
197
|
let x = wx, y = wy, kind: Snap['kind'] = 'free';
|
|
135
198
|
const guides: Guide[] = [];
|
|
@@ -146,31 +209,33 @@ function snapRaw(sx: number, sy: number, o: SnapOpts): Snap {
|
|
|
146
209
|
}
|
|
147
210
|
if (bestL) {
|
|
148
211
|
// a line under the pointer: on it — where a guide crosses it, if one does (level with the start, and on the line)
|
|
149
|
-
const
|
|
212
|
+
const on = bestL, { A, B, t0, t1 } = on, dx = B.x - A.x, dy = B.y - A.y;
|
|
213
|
+
const onIt = (x: number, y: number, guides: Guide[]): Snap =>
|
|
214
|
+
finish(on.face ? { x, y, kind: 'onface', ref: edgeId(on.id, on.face), label: 'On face', guides } : { x, y, kind: 'online', ref: on.id, label: 'On line', guides });
|
|
150
215
|
const g = gy && Math.abs(dy) > 1e-9 ? { t: (gy.y - A.y) / dy, h: gy } : gx && Math.abs(dx) > 1e-9 ? { t: (gx.x - A.x) / dx, v: gx } : null;
|
|
151
|
-
if (g && g.t >=
|
|
216
|
+
if (g && g.t >= t0 && g.t <= t1) {
|
|
152
217
|
const ix = A.x + dx * g.t, iy = A.y + dy * g.t, [qx, qy] = S(T, ix, iy);
|
|
153
218
|
if (hyp(qx - sx, qy - sy) < tol * 1.5) {
|
|
154
219
|
const gd = 'h' in g ? g.h! : g.v!, H = 'h' in g;
|
|
155
|
-
return
|
|
220
|
+
return onIt(ix, iy, [H ? { x1: ix - 1, y1: iy, x2: ix + 1, y2: iy, kind: 'H', from: gd.from, label: gd.own ? 'Horizontal' : 'Aligned' } : { x1: ix, y1: iy - 1, x2: ix, y2: iy + 1, kind: 'V', from: gd.from, label: gd.own ? 'Vertical' : 'Aligned' }]);
|
|
156
221
|
}
|
|
157
222
|
}
|
|
158
223
|
// on the grid, as far as the line allows: where it crosses the grid line nearest (along a level or plumb line,
|
|
159
224
|
// the grid point on it)
|
|
160
225
|
if (st) {
|
|
161
|
-
const
|
|
226
|
+
const near2 = (c: { x: number; y: number }) => hyp(c.x - on.x, c.y - on.y);
|
|
162
227
|
const opts: { x: number; y: number; t: number; axis: 'x' | 'y' }[] = [];
|
|
163
228
|
if (Math.abs(dx) > 1e-9) { const gv = onGrid(on.x, st, was?.x), t = (gv - A.x) / dx; opts.push({ x: gv, y: A.y + dy * t, t, axis: 'x' }); }
|
|
164
229
|
if (Math.abs(dy) > 1e-9) { const gv = onGrid(on.y, st, was?.y), t = (gv - A.y) / dy; opts.push({ x: A.x + dx * t, y: gv, t, axis: 'y' }); }
|
|
165
230
|
const pick = opts
|
|
166
|
-
.filter(c => { const [qx, qy] = S(T, c.x, c.y); return c.t >=
|
|
231
|
+
.filter(c => { const [qx, qy] = S(T, c.x, c.y); return c.t >= t0 && c.t <= t1 && hyp(qx - sx, qy - sy) < tol * 1.5; })
|
|
167
232
|
.sort((a, b) => near2(a) - near2(b))[0];
|
|
168
233
|
if (pick) {
|
|
169
234
|
if (pick.axis === 'x') usedX = pick.x; else usedY = pick.y;
|
|
170
|
-
return
|
|
235
|
+
return onIt(pick.x, pick.y, []);
|
|
171
236
|
}
|
|
172
237
|
}
|
|
173
|
-
return
|
|
238
|
+
return onIt(on.x, on.y, []);
|
|
174
239
|
}
|
|
175
240
|
if (gy) { y = gy.y; guides.push({ x1: wx - 1, y1: gy.y, x2: wx + 1, y2: gy.y, kind: 'H', from: gy.from, label: gy.own ? 'Horizontal' : 'Aligned' }); }
|
|
176
241
|
if (gx) { x = gx.x; guides.push({ x1: gx.x, y1: wy - 1, x2: gx.x, y2: wy + 1, kind: 'V', from: gx.from, label: gx.own ? 'Vertical' : 'Aligned' }); }
|
package/src/render/view.ts
CHANGED
|
@@ -466,11 +466,15 @@ export function setViewSize(W: number, H: number): void {
|
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
export function resize(): void {
|
|
469
|
-
const r = cvs.cv.getBoundingClientRect();
|
|
469
|
+
const r = cvs.cv.getBoundingClientRect(), dpr = Math.min(window.devicePixelRatio || 1, 2.5);
|
|
470
|
+
// (sized again to the same size, a canvas is cleared all the same: it showed blank until the next frame)
|
|
471
|
+
if (r.width === cvs.W && r.height === cvs.H && dpr === cvs.dpr) return;
|
|
470
472
|
cvs.W = r.width;
|
|
471
473
|
cvs.H = r.height;
|
|
472
|
-
cvs.dpr =
|
|
474
|
+
cvs.dpr = dpr;
|
|
473
475
|
cvs.cv.width = Math.max(1, Math.round(cvs.W * cvs.dpr));
|
|
474
476
|
cvs.cv.height = Math.max(1, Math.round(cvs.H * cvs.dpr));
|
|
477
|
+
// drawn now: left for the next frame, the cleared canvas flickered as a split view's divider was dragged
|
|
475
478
|
requestDraw();
|
|
479
|
+
paintPending();
|
|
476
480
|
}
|
package/src/solver/equations.ts
CHANGED
|
@@ -37,6 +37,25 @@ export function tanSide(sk: Sketch, c: Constraint): 1 | -1 {
|
|
|
37
37
|
export function consEqs(sk: Sketch, c: Constraint, P: PFn, D: DFn, RV: RVFn, RD: RDFn): [number[], EqFn][] {
|
|
38
38
|
const L = (id: string | undefined) => (id ? sk.lines[id] : undefined);
|
|
39
39
|
const out: [number[], EqFn][] = [];
|
|
40
|
+
/**
|
|
41
|
+
* Line `id`'s length, and what it depends on — for a wall's `face`, along that face corner to corner: the walls at its
|
|
42
|
+
* ends cut it short (an inside corner) or carry it on (an outside one), so they're part of it too.
|
|
43
|
+
*/
|
|
44
|
+
const len = (id: string, face?: number): { deps: number[]; f: EqFn } => {
|
|
45
|
+
const l = sk.lines[id];
|
|
46
|
+
if (face && l.kind === 'wall') {
|
|
47
|
+
const ends = faceEnds(sk, id), side = face < 0 ? -1 : 1;
|
|
48
|
+
return {
|
|
49
|
+
deps: [...D(l.a), ...D(l.b), ...[...ends.a, ...ends.b].flatMap(e => D(e.far ?? e.arc!.c))],
|
|
50
|
+
f: X => {
|
|
51
|
+
const at = (p: string) => { const q = P(X, p); return { x: q[0], y: q[1] }; };
|
|
52
|
+
const fs = faceSpan(at, at(l.a), at(l.b), l.thick, side, ends);
|
|
53
|
+
return fs ? fs.s1 - fs.s0 : 0;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return { deps: [...D(l.a), ...D(l.b)], f: X => { const a = P(X, l.a), b = P(X, l.b); return hyp(b[0] - a[0], b[1] - a[1]); } };
|
|
58
|
+
};
|
|
40
59
|
const unit = (a: [number, number], b: [number, number]): [number, number] => {
|
|
41
60
|
const x = b[0] - a[0], y = b[1] - a[1], n = hyp(x, y) || 1e-12;
|
|
42
61
|
return [x / n, y / n];
|
|
@@ -102,12 +121,10 @@ export function consEqs(sk: Sketch, c: Constraint, P: PFn, D: DFn, RV: RVFn, RD:
|
|
|
102
121
|
break;
|
|
103
122
|
}
|
|
104
123
|
case 'eq': {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return hyp(b[0] - a[0], b[1] - a[1]) - hyp(q[0] - p[0], q[1] - p[1]);
|
|
110
|
-
}]);
|
|
124
|
+
if (!L(c.l1) || !L(c.l2)) break;
|
|
125
|
+
// (a wall's edge picked: that face's length — faces)
|
|
126
|
+
const a = len(c.l1!, c.faces?.[0]), b = len(c.l2!, c.faces?.[1]);
|
|
127
|
+
out.push([[...a.deps, ...b.deps], X => a.f(X) - b.f(X)]);
|
|
111
128
|
break;
|
|
112
129
|
}
|
|
113
130
|
case 'eqr': {
|
|
@@ -127,9 +144,12 @@ export function consEqs(sk: Sketch, c: Constraint, P: PFn, D: DFn, RV: RVFn, RD:
|
|
|
127
144
|
case 'online': {
|
|
128
145
|
const l = L(c.l);
|
|
129
146
|
if (!l) break;
|
|
147
|
+
// on one face of a wall: half its thickness to that side of the centreline — read when solved, so a wall made
|
|
148
|
+
// thicker carries what's on its face with it
|
|
149
|
+
const faceOff = () => (c.face && l.kind === 'wall' ? (c.face * l.thick) / 2 : 0);
|
|
130
150
|
out.push([[...D(c.p!), ...D(l.a), ...D(l.b)], X => {
|
|
131
151
|
const p = P(X, c.p!), a = P(X, l.a), b = P(X, l.b), dx = b[0] - a[0], dy = b[1] - a[1], n = hyp(dx, dy) || 1e-12;
|
|
132
|
-
return ((p[0] - a[0]) * dy - (p[1] - a[1]) * dx) / n;
|
|
152
|
+
return ((p[0] - a[0]) * dy - (p[1] - a[1]) * dx) / n + faceOff();
|
|
133
153
|
}]);
|
|
134
154
|
break;
|
|
135
155
|
}
|
|
@@ -142,15 +162,9 @@ export function consEqs(sk: Sketch, c: Constraint, P: PFn, D: DFn, RV: RVFn, RD:
|
|
|
142
162
|
case 'dist': {
|
|
143
163
|
const fw = c.face && c.line && (!c.kind || c.kind === 'al') ? L(c.line) : undefined;
|
|
144
164
|
if (fw && fw.kind === 'wall') {
|
|
145
|
-
// along one face of a wall, corner to corner
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const deps = [...D(fw.a), ...D(fw.b), ...[...ends.a, ...ends.b].flatMap(e => D(e.far ?? e.arc!.c))];
|
|
149
|
-
out.push([deps, X => {
|
|
150
|
-
const at = (id: string) => { const q = P(X, id); return { x: q[0], y: q[1] }; };
|
|
151
|
-
const f = faceSpan(at, at(fw.a), at(fw.b), fw.thick, side, ends);
|
|
152
|
-
return (f ? f.s1 - f.s0 : 0) - c.value!;
|
|
153
|
-
}]);
|
|
165
|
+
// along one face of a wall, corner to corner
|
|
166
|
+
const f = len(c.line!, c.face);
|
|
167
|
+
out.push([f.deps, X => f.f(X) - c.value!]);
|
|
154
168
|
break;
|
|
155
169
|
}
|
|
156
170
|
const deps = [...D(c.a!), ...D(c.b!)], s = c.sign || 1;
|
package/src/tools/dim.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { fmtAng, fmtLen } from '../units';
|
|
|
23
23
|
import { addOpeningDim } from './openings';
|
|
24
24
|
import type { PEv } from './registry';
|
|
25
25
|
import { keypadFresh, keypadOpen, keypadSetReading } from '../editor/keypad';
|
|
26
|
+
import { advanceAfterReading } from '../editor/advance';
|
|
26
27
|
import { cornerLines } from '../editor/selection';
|
|
27
28
|
import { closeKeypad, kpTyped, openKeypad, showConflict, toast, updateCtx, updateHint, type KeypadSpec } from '../editor/ports';
|
|
28
29
|
import { noScaleYet, pendingLabel, startingValue } from '../editor/scaleGate';
|
|
@@ -177,7 +178,11 @@ export function dimLine(lid: string, side?: 1 | -1): void {
|
|
|
177
178
|
onPress: () => { face = ch.face!; spec.sub = lengthSub(sk, lid, face); show(); if (keypadFresh() && !noScaleYet()) keypadSetReading(len()); },
|
|
178
179
|
})) : undefined,
|
|
179
180
|
onClose: () => { ed.sel = was; updateCtx(); requestDraw(); },
|
|
180
|
-
onDone: (v, capture) => {
|
|
181
|
+
onDone: (v, capture) => {
|
|
182
|
+
if (!(v > 0)) return;
|
|
183
|
+
// a laser reading's (it comes with its record) moves on to the next line clockwise; a typed one stays
|
|
184
|
+
if (addLength(v, capture !== undefined ? { capture } : {}) && capture !== undefined) advanceAfterReading(lid, side);
|
|
185
|
+
},
|
|
181
186
|
// (or a length of the job's, from its list: the line takes it, linked to it)
|
|
182
187
|
measurements: offersJobMeasurements() ? {
|
|
183
188
|
kind: 'length', pick: t => {
|
|
@@ -188,21 +193,32 @@ export function dimLine(lid: string, side?: 1 | -1): void {
|
|
|
188
193
|
},
|
|
189
194
|
} : undefined,
|
|
190
195
|
};
|
|
191
|
-
/** The line's length dimension, driving, measured where the keypad says (`extra`: what it's from). */
|
|
192
|
-
function addLength(v: number, extra: Partial<Constraint>):
|
|
196
|
+
/** The line's length dimension, driving, measured where the keypad says (`extra`: what it's from). Whether it took. */
|
|
197
|
+
function addLength(v: number, extra: Partial<Constraint>): boolean {
|
|
193
198
|
pushHistory();
|
|
194
199
|
const r = tryAddConstraint({ type: 'dist', a: l.a, b: l.b, kind: 'al', value: v, line: lid, driving: true, off: face ? (face * 30) / V().s : 0, ...(face ? { face } : {}), ...extra });
|
|
195
200
|
// a measurement of the job drives a line, or nothing: not one whose length the drawing already sets
|
|
201
|
+
let took = r.ok;
|
|
196
202
|
if (r.ok && r.ref && extra.measurementRef) {
|
|
197
203
|
delete SK().cons[r.id!];
|
|
198
204
|
dropHistory();
|
|
199
205
|
toast(LENGTH_SET_ALREADY, { warn: true });
|
|
206
|
+
took = false;
|
|
200
207
|
} else if (!r.ok) dropHistory();
|
|
201
208
|
afterEdit();
|
|
209
|
+
return took;
|
|
202
210
|
}
|
|
203
211
|
openKeypad(spec);
|
|
204
212
|
}
|
|
205
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Whether giving dimension `c` the value `v` replaces a value measured there: a driving one, entered (not a default
|
|
216
|
+
* nobody measured), changed by it. Not one linked to a measurement of the job: that's asked about anyway
|
|
217
|
+
* (askLinkedChange). What a host warns about before a reading overwrites (laserReadingOverwrites).
|
|
218
|
+
*/
|
|
219
|
+
export const replacesMeasured = (c: Constraint | undefined, v: number): boolean =>
|
|
220
|
+
!!c && c.driving !== false && !c.auto && !c.measurementRef && changesValue(c, v);
|
|
221
|
+
|
|
206
222
|
/** Why a measurement of the job can't drive a line the drawing already sets the length of. */
|
|
207
223
|
export const LENGTH_SET_ALREADY = 'The drawing already sets that line’s length. Free it first (make one of its dimensions a reference), then pick the measurement.';
|
|
208
224
|
/** Why a measurement of the job can't drive an angle the drawing already sets. */
|
|
@@ -587,7 +603,15 @@ export function editDim(id: string, done?: () => void, modeless = false, pick?:
|
|
|
587
603
|
label: ch.label!, on: onChoice(withFace(c, face), ch),
|
|
588
604
|
onPress: () => { face = onChoice(c, ch) ? null : { ...ch, l2: face?.l2 ?? ch.l2 }; if (keypadFresh()) keypadSetReading(now()); },
|
|
589
605
|
})),
|
|
590
|
-
onDone: (v, capture) => {
|
|
606
|
+
onDone: (v, capture) => {
|
|
607
|
+
const took = setDimValue(id, v * k, face ?? undefined, { capture });
|
|
608
|
+
done?.();
|
|
609
|
+
// a laser reading's (it comes with its record) on a line's length or a curve's diameter moves on to the next
|
|
610
|
+
// line clockwise; a typed one, or one the drawing refused or asked about, stays
|
|
611
|
+
const of = c.type === 'dist' ? c.line : c.type === 'diam' ? c.c : undefined;
|
|
612
|
+
if (took && capture !== undefined && of) advanceAfterReading(of, pick?.face || undefined);
|
|
613
|
+
},
|
|
614
|
+
overwrites: v => replacesMeasured(SK().cons[id], v * k),
|
|
591
615
|
// a line's length or an angle: or one of the job's, from its list — the dimension takes it, linked to it (a
|
|
592
616
|
// dimension already linked to another, re-linked)
|
|
593
617
|
measurements: ((c.type === 'dist' && c.line) || isAng) && offersJobMeasurements() ? {
|