Explorar el Código

Minimize sketch movement on dimension edits

Choose dimension solutions that move the fewest points, preserving shared edges and preferring earlier-drawn geometry on ties. Apply this behavior to parameter edits and add regression coverage.
Toby Chui hace 9 horas
padre
commit
9007f3ad11

+ 8 - 0
src/web/3D Modeler/PROPOSAL.md

@@ -806,6 +806,14 @@ Plan for stage 1:
   It runs on the main thread because a solve takes milliseconds and has to
   follow the cursor during a drag. The sketch is translated to its primitive
   list on every change; a drag is a temporary constraint on the dragged point.
+- A dimension whose value is edited (value box, Manage > Parameters) goes
+  through `solveChange` in `js/sketch/solver.js`, not a plain solve: each
+  end of the dimension is held in turn while every other point is held
+  softly (temporary constraints), and the answer that moves the fewest
+  points wins; on a tie the end drawn first stays. A plain solve shares the
+  change out, which moved an edge shared with the shapes beside it and
+  turned shapes over (owner's report: three rectangles on one bottom line,
+  shortening one lifted the line). Tests: `tests/dimension-change.test.mjs`.
 - Stage 1 constraints: coincident, point on line, horizontal, vertical,
   parallel, perpendicular, tangent, equal, fix, midpoint, symmetric. Stage 1
   dimensions: distance, horizontal and vertical distance, radius, diameter,

+ 7 - 1
src/web/3D Modeler/js/app.js

@@ -2692,7 +2692,13 @@ const paramTable = createParameterTable({
                     const sketch = d.features.find(function (f) {
                         return f.id === id;
                     });
-                    const solved = s.solve(sketch);
+                    // Only the dimensions whose value changed move anything
+                    const changed = (sketch.constraints || []).filter(function (c, i) {
+                        return c.value !== before[id][i];
+                    }).map(function (c) {
+                        return c.id;
+                    });
+                    const solved = s.solveChange(sketch, changed);
                     if (!solved.ok) {
                         (sketch.constraints || []).forEach(function (c, i) {
                             c.value = before[id][i];

+ 28 - 0
src/web/3D Modeler/js/sketch/model.js

@@ -687,6 +687,34 @@ export function measure(sk, d) {
     return 0;
 }
 
+// The ends a dimension measures between, as lists of point ids: a new value
+// moves one end against the other, and solveChange (solver.js) tries
+// holding each in turn. A radius or a diameter has one end, the centre.
+export function dimensionSides(sk, d) {
+    const ends = function (id) {
+        const g = find(sk, id);
+        return g && g.type === 'line' ? [g.p1, g.p2] : [];
+    };
+    switch (d.type) {
+        case 'distance':
+        case 'hdistance':
+        case 'vdistance':
+        case 'axisangle':
+            return [[d.a], [d.b]];
+        case 'pldistance':
+            return [[d.p], ends(d.line)];
+        case 'angle':
+            return [ends(d.l1), ends(d.l2)];
+        case 'radius':
+        case 'diameter': {
+            const g = find(sk, d.curve);
+            return g && g.c ? [[g.c]] : [];
+        }
+        default:
+            return [];
+    }
+}
+
 /* ================= solver translation ================= */
 // The end point two curves (lines or arcs) share, or null
 function sharedEnd(sk, a, b) {

+ 6 - 3
src/web/3D Modeler/js/sketch/sketcher.js

@@ -250,14 +250,17 @@ export function createSketcher(options) {
     // Solve the working copy and store it as one undo step. Constraints added
     // since the last store that turn out redundant are dropped quietly, unless
     // `strict` is set: then the whole edit is refused, as it is for a conflict.
-    function commit(label, strict) {
+    // `changed` lists dimensions whose value was edited: they move as little
+    // of the sketch as they can (solveChange), so an edge shared with other
+    // shapes stays and the free end moves.
+    function commit(label, strict, changed) {
         const before = new Set(JSON.parse(saved).constraints.map(function (c) {
             return c.id;
         }));
         const added = function (id) {
             return !before.has(id);
         };
-        let r = solver.solve(sk);
+        let r = changed ? solver.solveChange(sk, changed) : solver.solve(sk);
         let dropped = 0;
         if (!r.ok && !strict) {
             // A snap left a constraint behind that cannot hold with the rest:
@@ -908,7 +911,7 @@ export function createSketcher(options) {
             } else {
                 delete d.expr;
             }
-            commit('Edit dimension', true);
+            commit('Edit dimension', true, [id]);
         }
     }
 

+ 188 - 17
src/web/3D Modeler/js/sketch/solver.js

@@ -11,7 +11,10 @@
 */
 
 import { init_planegcs_module, GcsWrapper } from '../../lib/planegcs/index.js';
-import { toPrimitives, applySolution } from './model.js';
+import { toPrimitives, applySolution, dimensionSides, measure, find, ORIGIN } from './model.js';
+
+// A point that ends up closer than this to where it was has not moved (mm)
+const STILL = 1e-6;
 
 let modulePromise = null;
 
@@ -78,10 +81,11 @@ export async function createSolver() {
     const wrapper = new GcsWrapper(new mod.GcsSystem());
     wrapper.debug_mode = 0; // DebugMode.NoDebug: keep the solver out of the console
 
-    // Push the sketch, minus the equations in `skip`, and solve it
-    function attempt(sketch, drag, skip) {
+    // Push the sketch and the `extra` primitives, minus the equations in
+    // `skip`, and solve it
+    function attempt(sketch, drag, skip, extra) {
         wrapper.clear_data();
-        const primitives = toPrimitives(sketch, drag).filter(function (p) {
+        const primitives = toPrimitives(sketch, drag).concat(extra || []).filter(function (p) {
             return !skip.has(String(p.id));
         });
         wrapper.push_primitives_and_params(primitives);
@@ -94,22 +98,29 @@ export async function createSolver() {
         };
     }
 
-    function solve(sketch, drag) {
+    // Each pass leaves out the parts of constraints found to be implied by
+    // the rest (see spareParts); one pass is the usual case. Throws when the
+    // solver does.
+    function passes(sketch, drag, extra) {
         const skip = new Set();
         let run = null;
-        try {
-            // Each pass leaves out the parts of constraints found to be implied
-            // by the rest (see spareParts); one pass is the usual case
-            for (let pass = 0; pass < 4; pass++) {
-                run = attempt(sketch, drag, skip);
-                const spare = run.conflicting.length ? [] : spareParts(sketch, run.primitives, run.redundant);
-                if (!spare.length) {
-                    break;
-                }
-                spare.forEach(function (id) {
-                    skip.add(id);
-                });
+        for (let pass = 0; pass < 4; pass++) {
+            run = attempt(sketch, drag, skip, extra);
+            const spare = run.conflicting.length ? [] : spareParts(sketch, run.primitives, run.redundant);
+            if (!spare.length) {
+                break;
             }
+            spare.forEach(function (id) {
+                skip.add(id);
+            });
+        }
+        return run;
+    }
+
+    function solve(sketch, drag) {
+        let run = null;
+        try {
+            run = passes(sketch, drag);
         } catch (err) {
             return { ok: false, dof: -1, conflicting: [], redundant: [], error: String(err && err.message ? err.message : err) };
         }
@@ -124,8 +135,168 @@ export async function createSolver() {
         return { ok: ok, dof: wrapper.gcs.dof(), conflicting: conflicting, redundant: redundant };
     }
 
+    /* ---------- changing a dimension ---------- */
+    // Holds for a change: each free point (not the origin, not projected
+    // from the model) gets a pair of coordinate equations keeping it where
+    // it is. Those of the points in `keep` are hard; the others are soft
+    // (planegcs temporary constraints, which the solver meets as closely as
+    // the real constraints allow, the way a dragged point follows the
+    // cursor). Circles keep their size softly as well.
+    function holds(sketch, keep) {
+        const out = [];
+        sketch.geometry.forEach(function (g, i) {
+            if (g.ref) {
+                return;
+            }
+            if (g.type === 'point') {
+                const soft = !keep.has(g.id);
+                out.push({ id: '$hx' + i, type: 'coordinate_x', p_id: g.id, x: g.x, temporary: soft });
+                out.push({ id: '$hy' + i, type: 'coordinate_y', p_id: g.id, y: g.y, temporary: soft });
+            } else if (g.type === 'circle') {
+                out.push({ id: '$hr' + i, type: 'circle_radius', c_id: g.id, radius: g.r, temporary: true });
+            }
+        });
+        return out;
+    }
+
+    // Solve `sketch` with the points in `keep` held and the rest held
+    // softly, then once more without the holds to make sure every constraint
+    // is met. True when both work; the sketch has then moved.
+    function holding(sketch, keep) {
+        let run = null;
+        try {
+            run = passes(sketch, null, holds(sketch, keep));
+        } catch (err) {
+            return false;
+        }
+        if ((run.status !== 0 && run.status !== 1) || run.conflicting.length) {
+            return false;
+        }
+        wrapper.apply_solution();
+        applySolution(sketch, wrapper.sketch_index.get_primitives());
+        return solve(sketch).ok;
+    }
+
+    // How many points (and circle sizes) differ between two copies
+    function moved(before, after) {
+        let count = 0;
+        after.geometry.forEach(function (g, i) {
+            const b = before.geometry[i];
+            const d = g.type === 'point' ? Math.hypot(g.x - b.x, g.y - b.y) : g.type === 'circle' ? Math.abs(g.r - b.r) : 0;
+            if (d > STILL) {
+                count++;
+            }
+        });
+        return count;
+    }
+
+    // How early an end of a dimension was drawn: the place of its first
+    // point in the geometry list; the origin and model edges come first
+    function age(sketch, side) {
+        let first = Infinity;
+        side.forEach(function (id) {
+            const g = id === ORIGIN ? null : find(sketch, id);
+            const at = !g || g.ref ? -1 : sketch.geometry.indexOf(g);
+            first = Math.min(first, at);
+        });
+        return first;
+    }
+
+    function copyPlaces(from, to) {
+        to.geometry.forEach(function (g, i) {
+            const s = from.geometry[i];
+            if (g.type === 'point') {
+                g.x = s.x;
+                g.y = s.y;
+            } else if (g.type === 'circle') {
+                g.r = s.r;
+            }
+        });
+    }
+
+    // Meet the new value of dimension `dim` moving as little as possible:
+    // hold each of its ends in turn, everything else held softly, and keep
+    // the answer that moves the fewest points. On a tie the end drawn first
+    // stays. When no end can be held, everything is held softly. False if
+    // nothing worked; the sketch is then untouched.
+    function settle(sketch, dim) {
+        const text = JSON.stringify({ geometry: sketch.geometry, constraints: sketch.constraints });
+        let best = null;
+        const tryKeeping = function (side) {
+            const copy = JSON.parse(text);
+            const keep = new Set(side.filter(function (id) {
+                const g = id === ORIGIN ? null : find(copy, id);
+                return g && !g.ref; // the origin and model edges never move anyway
+            }));
+            if (!holding(copy, keep)) {
+                return;
+            }
+            const score = [moved(sketch, copy), age(sketch, side)];
+            if (!best || score[0] < best.score[0] || (score[0] === best.score[0] && score[1] < best.score[1])) {
+                best = { copy: copy, score: score };
+            }
+        };
+        dimensionSides(sketch, dim).forEach(tryKeeping);
+        if (!best) {
+            tryKeeping([]);
+        }
+        if (best) {
+            copyPlaces(best.copy, sketch);
+        }
+        return !!best;
+    }
+
+    // solveChange(sketch, ids): solve after the value of the dimensions
+    // `ids` was edited. A plain solve shares a change out over the whole
+    // sketch: shortening a rectangle moved the edge it shares with the
+    // shapes beside it, dragging them along, or turned shapes over. Here the
+    // edited dimension moves only what it must, and an edge that is joined
+    // to others stays. Several dimensions are settled one at a time, each
+    // from the sizes the sketch has now; if that fails, all at once with
+    // everything held softly. Same result as solve().
+    function solveChange(sketch, ids) {
+        const wanted = new Set([].concat(ids || []));
+        const dims = sketch.constraints.filter(function (c) {
+            return wanted.has(c.id) && !c.driven;
+        });
+        if (!dims.length) {
+            return solve(sketch);
+        }
+        const start = JSON.stringify(sketch.geometry);
+        const values = dims.map(function (d) {
+            return d.value;
+        });
+        // The others wait at what they measure now, so each step changes one
+        dims.forEach(function (d) {
+            const now = measure(sketch, d);
+            if (isFinite(now)) {
+                d.value = now;
+            }
+        });
+        let ok = true;
+        dims.forEach(function (d, i) {
+            d.value = values[i];
+            ok = ok && settle(sketch, d);
+        });
+        dims.forEach(function (d, i) {
+            d.value = values[i];
+        });
+        if (!ok) {
+            copyPlaces({ geometry: JSON.parse(start) }, sketch);
+            if (dims.length > 1) {
+                ok = settle(sketch, { type: 'none' });
+            }
+            if (!ok) {
+                // Nothing held: the plain solve below decides on its own
+                copyPlaces({ geometry: JSON.parse(start) }, sketch);
+            }
+        }
+        return solve(sketch);
+    }
+
     return {
         solve: solve,
+        solveChange: solveChange,
         destroy: function () {
             wrapper.destroy_gcs_module();
         }

+ 208 - 0
src/web/3D Modeler/tests/dimension-change.test.mjs

@@ -0,0 +1,208 @@
+// Changing a dimension moves as little of the sketch as it can (solveChange
+// in js/sketch/solver.js): an edge shared with other shapes stays, the free
+// end of the dimension moves, and nothing turns over.
+import * as M from '../js/sketch/model.js';
+import { createSolver } from '../js/sketch/solver.js';
+
+let failed = 0;
+const a = (c, m, extra) => { if (!c) { failed++; console.log('FAIL', m, extra === undefined ? '' : JSON.stringify(extra)); } };
+const near = (x, y, tol) => Math.abs(x - y) < (tol || 1e-6);
+const P = (sk, id) => M.point(sk, id);
+const solver = await createSolver();
+
+// A rectangle as the Rectangle tool draws it: first corner, the corner level
+// with it, the opposite corner, the corner above / below the first
+function rect(sk, from, to, start) {
+    const c = [from, [to[0], from[1]], to, [from[0], to[1]]];
+    const p = [start || M.addPoint(sk, c[0][0], c[0][1]), M.addPoint(sk, c[1][0], c[1][1]),
+        M.addPoint(sk, c[2][0], c[2][1]), M.addPoint(sk, c[3][0], c[3][1])];
+    const l = p.map((id, i) => M.addLine(sk, id, p[(i + 1) % 4]));
+    ['horizontal', 'vertical', 'horizontal', 'vertical'].forEach((t, i) => M.addConstraint(sk, { type: t, line: l[i] }));
+    return { p, l };
+}
+
+const places = sk => JSON.stringify(sk.geometry.filter(g => g.type === 'point').map(g => [g.id, +g.x.toFixed(6), +g.y.toFixed(6)]));
+const setValue = (sk, id, value) => { sk.constraints.find(c => c.id === id).value = value; };
+
+// Three rectangles side by side on one bottom line, the corners where they
+// meet shared (snapped), as in the owner's report
+function threeInARow() {
+    const sk = { geometry: [], constraints: [] };
+    const L = rect(sk, [-15, 2.9], [-5, -4.1]);
+    const Mi = rect(sk, [-5, -4.1], [6.5, -2.05], L.p[2]);
+    const R = rect(sk, [6.5, -4.1], [16.5, 30.6], Mi.p[1]);
+    const d = {
+        lw: M.addConstraint(sk, { type: 'distance', a: L.p[0], b: L.p[1], value: 10 }),
+        lh: M.addConstraint(sk, { type: 'distance', a: L.p[3], b: L.p[0], value: 7 }),
+        mh: M.addConstraint(sk, { type: 'distance', a: Mi.p[3], b: Mi.p[0], value: 2.05 }),
+        rw: M.addConstraint(sk, { type: 'distance', a: R.p[3], b: R.p[2], value: 10 }),
+        rh: M.addConstraint(sk, { type: 'distance', a: R.p[1], b: R.p[2], value: 34.7 }),
+        all: M.addConstraint(sk, { type: 'hdistance', a: L.p[3], b: R.p[1], value: 31.5 })
+    };
+    a(solver.solve(sk).ok, 'three rectangles solve');
+    return { sk, L, Mi, R, d };
+}
+
+// 1. the report: shortening the tall rectangle brings its top down; the
+// shared bottom line and the other two rectangles stay where they are
+{
+    const { sk, L, Mi, R, d } = threeInARow();
+    const others = JSON.stringify([L.p, Mi.p].flat().map(id => P(sk, id)));
+    setValue(sk, d.rh, 7);
+    const r = solver.solveChange(sk, [d.rh]);
+    a(r.ok && r.dof === 2, 'shorter tall rectangle solves', r);
+    a(near(P(sk, R.p[1])[1], -4.1) && near(P(sk, R.p[0])[1], -4.1), 'its bottom edge stays on the shared line', [P(sk, R.p[0]), P(sk, R.p[1])]);
+    a(near(P(sk, R.p[2])[1], 2.9) && near(P(sk, R.p[3])[1], 2.9), 'its top edge comes down', [P(sk, R.p[2]), P(sk, R.p[3])]);
+    a(JSON.stringify([L.p, Mi.p].flat().map(id => P(sk, id))) === others, 'the other two rectangles do not move');
+    // and back up, past where it started
+    setValue(sk, d.rh, 50);
+    a(solver.solveChange(sk, [d.rh]).ok && near(P(sk, R.p[1])[1], -4.1) && near(P(sk, R.p[2])[1], 45.9), 'taller: the top goes up', P(sk, R.p[2]));
+}
+// the plain solve is what moved the shared line before
+{
+    const { sk, R, d } = threeInARow();
+    setValue(sk, d.rh, 7);
+    solver.solve(sk);
+    a(!near(P(sk, R.p[1])[1], -4.1), 'a plain solve still shares the change out (the old behaviour)', P(sk, R.p[1]));
+}
+
+// 2. the same for the other snapped edges: the free edge moves
+{
+    const { sk, L, Mi, R, d } = threeInARow();
+    setValue(sk, d.lh, 12);
+    a(solver.solveChange(sk, [d.lh]).ok, 'left height solves');
+    a(near(P(sk, L.p[3])[1], -4.1) && near(P(sk, L.p[0])[1], 7.9), 'left rectangle grows upwards from the shared line', [P(sk, L.p[3]), P(sk, L.p[0])]);
+    a(near(P(sk, R.p[2])[1], 30.6) && near(P(sk, Mi.p[2])[1], -2.05), 'the others stay');
+
+    setValue(sk, d.mh, 5);
+    a(solver.solveChange(sk, [d.mh]).ok, 'middle height solves');
+    a(near(P(sk, Mi.p[0])[1], -4.1) && near(P(sk, Mi.p[3])[1], 0.9) && near(P(sk, Mi.p[2])[1], 0.9), 'middle rectangle grows upwards', [P(sk, Mi.p[3]), P(sk, Mi.p[2])]);
+
+    // Width of the left rectangle with the overall 31.5 holding both outer
+    // sides: it grows into the middle one (3 points move) rather than
+    // pushing the right rectangle along (7 points)
+    setValue(sk, d.lw, 14);
+    a(solver.solveChange(sk, [d.lw]).ok, 'left width solves');
+    a(near(P(sk, L.p[3])[0], -15) && near(P(sk, L.p[2])[0], -1) && near(P(sk, R.p[1])[0], 16.5), 'left rectangle grows into the middle one', [P(sk, L.p[3]), P(sk, L.p[2])]);
+}
+// Without the overall width the left rectangle's free side moves out
+{
+    const { sk, L, d } = threeInARow();
+    M.remove(sk, [d.all]);
+    solver.solve(sk);
+    setValue(sk, d.lw, 14);
+    a(solver.solveChange(sk, [d.lw]).ok, 'left width solves without the overall width');
+    a(near(P(sk, L.p[2])[0], -5) && near(P(sk, L.p[3])[0], -19) && near(P(sk, L.p[0])[0], -19), 'left rectangle widens to the left', [P(sk, L.p[0]), P(sk, L.p[2])]);
+}
+
+// 3. a rectangle alone: on a tie the corner drawn first stays
+{
+    const sk = { geometry: [], constraints: [] };
+    const { p } = rect(sk, [0, 0], [20, -10]);
+    const w = M.addConstraint(sk, { type: 'distance', a: p[0], b: p[1], value: 20 });
+    const h = M.addConstraint(sk, { type: 'distance', a: p[1], b: p[2], value: 10 });
+    a(solver.solve(sk).ok, 'lone rectangle');
+    setValue(sk, w, 30);
+    setValue(sk, h, 4);
+    a(solver.solveChange(sk, [w]).ok && solver.solveChange(sk, [h]).ok, 'lone rectangle resizes');
+    a(near(P(sk, p[0])[0], 0) && near(P(sk, p[0])[1], 0), 'first corner stays', P(sk, p[0]));
+    a(near(P(sk, p[2])[0], 30) && near(P(sk, p[2])[1], -4), 'opposite corner moves', P(sk, p[2]));
+    // A size the other way round keeps the same corner
+    const sk2 = { geometry: [], constraints: [] };
+    const q = rect(sk2, [0, 0], [20, -10]).p;
+    const h2 = M.addConstraint(sk2, { type: 'distance', a: q[2], b: q[1], value: 10 });
+    solver.solve(sk2);
+    setValue(sk2, h2, 4);
+    a(solver.solveChange(sk2, [h2]).ok && near(P(sk2, q[1])[1], 0) && near(P(sk2, q[2])[1], -4), 'the earlier end stays whichever way the dimension was picked', [P(sk2, q[1]), P(sk2, q[2])]);
+}
+
+// 4. anchored to the origin and fully constrained: the change still lands
+{
+    const sk = { geometry: [], constraints: [] };
+    const { p } = rect(sk, [0, 0], [20, 10]);
+    M.addConstraint(sk, { type: 'coincident', a: p[0], b: M.ORIGIN });
+    M.addConstraint(sk, { type: 'distance', a: p[0], b: p[1], value: 20 });
+    const h = M.addConstraint(sk, { type: 'distance', a: p[2], b: p[1], value: 10 });
+    a(solver.solve(sk).dof === 0, 'anchored rectangle is fully constrained');
+    setValue(sk, h, 25);
+    const r = solver.solveChange(sk, [h]);
+    a(r.ok && r.dof === 0 && near(P(sk, p[2])[1], 25) && near(P(sk, p[0])[0], 0), 'fully constrained change', P(sk, p[2]));
+    a(r.redundant.length === 0 && r.conflicting.length === 0, 'no holds left in the report', r);
+}
+
+// 5. a diameter keeps the centre; an angle turns the later line
+{
+    const sk = { geometry: [], constraints: [] };
+    const c = M.addPoint(sk, 5, 5);
+    const k = M.addCircle(sk, c, 3);
+    const dia = M.addConstraint(sk, { type: 'diameter', curve: k, value: 6 });
+    const o = M.addPoint(sk, 30, 0);
+    const e1 = M.addPoint(sk, 50, 0);
+    const e2 = M.addPoint(sk, 40, 10);
+    const l1 = M.addLine(sk, o, e1);
+    const l2 = M.addLine(sk, o, e2);
+    M.addConstraint(sk, { type: 'distance', a: o, b: e2, value: Math.hypot(10, 10) });
+    const ang = M.addConstraint(sk, { type: 'angle', l1: l1, l2: l2, value: Math.PI / 4 });
+    a(solver.solve(sk).ok, 'circle and angle');
+    setValue(sk, dia, 16);
+    a(solver.solveChange(sk, [dia]).ok && near(M.find(sk, k).r, 8) && near(P(sk, c)[0], 5) && near(P(sk, c)[1], 5), 'circle grows about its centre', [M.find(sk, k).r, P(sk, c)]);
+    setValue(sk, ang, Math.PI / 2);
+    a(solver.solveChange(sk, [ang]).ok, 'angle solves');
+    a(near(P(sk, e1)[0], 50) && near(P(sk, e1)[1], 0) && near(P(sk, o)[0], 30), 'the first line stays', [P(sk, o), P(sk, e1)]);
+    a(near(P(sk, e2)[0], 30, 1e-5) && near(P(sk, e2)[1], Math.hypot(10, 10), 1e-5), 'the second line turns about the shared end', P(sk, e2));
+}
+
+// 6. several at once (Manage > Parameters), and a value that cannot be met
+{
+    const { sk, L, Mi, R, d } = threeInARow();
+    setValue(sk, d.lh, 3);
+    setValue(sk, d.rh, 9);
+    const r = solver.solveChange(sk, [d.lh, d.rh]);
+    a(r.ok && near(P(sk, L.p[0])[1], -1.1) && near(P(sk, R.p[2])[1], 4.9), 'two heights at once, both from the shared line', [P(sk, L.p[0]), P(sk, R.p[2])]);
+    a(near(P(sk, Mi.p[0])[1], -4.1) && near(P(sk, R.p[1])[1], -4.1), 'shared line stays');
+    a(sk.constraints.find(c => c.id === d.lh).value === 3 && sk.constraints.find(c => c.id === d.rh).value === 9, 'values are kept as typed');
+
+}
+// a value that cannot be met: a triangle side longer than the other two
+{
+    const sk = { geometry: [], constraints: [] };
+    const t = [[0, 0], [10, 0], [5, 8.66]].map(c => M.addPoint(sk, c[0], c[1]));
+    t.forEach((id, i) => M.addLine(sk, id, t[(i + 1) % 3]));
+    const s = t.map((id, i) => M.addConstraint(sk, { type: 'distance', a: id, b: t[(i + 1) % 3], value: 10 }));
+    a(solver.solve(sk).ok, 'triangle solves');
+    const before = places(sk);
+    setValue(sk, s[0], 25);
+    const bad = solver.solveChange(sk, [s[0]]);
+    a(!bad.ok && places(sk) === before, 'an impossible value fails and leaves the sketch alone', bad);
+    setValue(sk, s[0], 15);
+    a(solver.solveChange(sk, [s[0]]).ok && near(M.measure(sk, sk.constraints.find(c => c.id === s[0])), 15), 'a possible one lands');
+}
+
+// 7. a long row: a change at one end leaves the rest alone, and stays quick
+{
+    const sk = { geometry: [], constraints: [] };
+    let start = null;
+    let last = null;
+    const heights = [];
+    for (let i = 0; i < 25; i++) {
+        last = rect(sk, [i * 10, 0], [i * 10 + 10, 5 + i % 3], start);
+        start = last.p[1];
+        heights.push(M.addConstraint(sk, { type: 'distance', a: last.p[1], b: last.p[2], value: 5 + i % 3 }));
+        M.addConstraint(sk, { type: 'distance', a: last.p[0], b: last.p[1], value: 10 });
+    }
+    a(solver.solve(sk).ok, 'row of 25 solves');
+    const first = JSON.parse(JSON.stringify(sk.geometry.slice(0, 8)));
+    setValue(sk, heights[24], 20);
+    const t0 = performance.now();
+    const r = solver.solveChange(sk, [heights[24]]);
+    const ms = performance.now() - t0;
+    a(r.ok && near(P(sk, last.p[2])[1], 20) && near(P(sk, last.p[1])[1], 0), 'last rectangle grows upwards', P(sk, last.p[2]));
+    const drift = Math.max(...first.map((g, k) => g.type === 'point' ? Math.hypot(sk.geometry[k].x - g.x, sk.geometry[k].y - g.y) : 0));
+    a(drift < 1e-6, 'the first rectangles do not move', drift);
+    a(ms < 1500, 'quick enough to run on Enter', ms);
+    console.log('row of 25: ' + ms.toFixed(0) + ' ms');
+}
+
+solver.destroy();
+console.log(failed ? failed + ' FAILED' : 'all dimension change tests passed');
+process.exitCode = failed ? 1 : 0;