Przeglądaj źródła

Fix chamfer not working on exact numbers bug

Toby Chui 1 dzień temu
rodzic
commit
9790978d21

+ 358 - 23
src/web/3D Modeler/js/kernel/occt.js

@@ -2376,8 +2376,10 @@ function freshFaces(oc, maker, before, after) {
 // Shared by fillet and chamfer: `make(body, edges)` returns a built maker;
 // run it on every body that has picked edges and return the new body list.
 // With `report` ({ fresh: [] }) it also notes which faces of each new body
-// are new (freshFaces), for the live preview.
-function onEdges(oc, bodies, feature, what, make, report) {
+// are new (freshFaces), for the live preview. `retry(body, edges)`
+// (optional) builds it another way when the maker's result is broken, or
+// returns null.
+function onEdges(oc, bodies, feature, what, make, report, retry) {
     const picked = findEdges(oc, bodies, feature.edges);
     if (!picked.length) {
         throw new Error('No edge is selected');
@@ -2400,13 +2402,25 @@ function onEdges(oc, bodies, feature, what, make, report) {
         let maker = null;
         try {
             maker = make(body, edges, which);
-            const made = maker.Shape();
+            let made = maker.Shape();
             if (!isSound(oc, made)) {
                 made.delete();
-                throw new Error('The ' + what + ' does not fit on these edges: it is too large for the faces next to them. Try a smaller size');
+                const other = retry && !maker.fresh ? retry(body, edges, which) : null;
+                if (other) {
+                    maker.delete();
+                    maker = other;
+                    made = maker.Shape();
+                }
+                if (!other || !isSound(oc, made)) {
+                    if (other) {
+                        made.delete();
+                    }
+                    throw new Error('The ' + what + ' does not fit on these edges: it is too large for the faces next to them. Try a smaller size');
+                }
             }
             if (report) {
-                report.fresh[index] = freshFaces(oc, maker, body, made);
+                // a chamfer that was cut (cutChamfer) knows its new faces itself
+                report.fresh[index] = maker.fresh ? maker.fresh() : freshFaces(oc, maker, body, made);
             }
             return made;
         } catch (err) {
@@ -2529,8 +2543,9 @@ export function chamfer(oc, bodies, feature, report) {
     if (mode === 'angle' && !(angle > 0 && angle < 90)) {
         throw new Error('The chamfer angle must be between 0 and 90 degrees');
     }
-    return onEdges(oc, bodies, feature, 'chamfer', function (body, edges) {
-        const maker = new oc.BRepFilletAPI_MakeChamfer(body);
+    // What building the chamfer of `edges` on `body` needs (cutChamfer):
+    // { build(scale), sizes(i, faces, between), free() }
+    const plan = function (body, edges) {
         // Two distances or an angle are measured from one of the edge's two
         // faces. The edges picked together all measure from the same kind
         // of face: the one most of them touch (the top of a box whose top
@@ -2552,11 +2567,12 @@ export function chamfer(oc, bodies, feature, report) {
                 });
             });
         };
+        // per edge, the face `distance` is measured on (none: both)
+        let refs;
         try {
-            edges.forEach(function (edge, i) {
+            refs = edges.map(function (edge, i) {
                 if (mode === 'equal') {
-                    maker.Add(distance, edge);
-                    return;
+                    return null;
                 }
                 const faces = adjacent[i];
                 if (faces.length < 2) {
@@ -2567,26 +2583,345 @@ export function chamfer(oc, bodies, feature, report) {
                 }).sort(function (a, b) {
                     return b.n - a.n || a.k - b.k;
                 });
-                const ref = order[feature.flip ? 1 : 0].face;
-                if (mode === 'two') {
-                    maker.Add(distance, distance2, edge, ref);
-                } else {
-                    maker.AddDA(distance, angle * Math.PI / 180, edge, ref);
-                }
+                return order[feature.flip ? 1 : 0].face;
             });
         } catch (err) {
             free();
-            maker.delete();
             throw err;
         }
-        free();
-        maker.Build();
-        if (!maker.IsDone()) {
+        return {
+            // the builder with every distance times `scale`, built, or null
+            build: function (scale) {
+                const maker = new oc.BRepFilletAPI_MakeChamfer(body);
+                try {
+                    edges.forEach(function (edge, i) {
+                        if (mode === 'equal') {
+                            maker.Add(distance * scale, edge);
+                        } else if (mode === 'two') {
+                            maker.Add(distance * scale, distance2 * scale, edge, refs[i]);
+                        } else {
+                            maker.AddDA(distance * scale, angle * Math.PI / 180, edge, refs[i]);
+                        }
+                    });
+                    maker.Build();
+                    if (maker.IsDone()) {
+                        return maker;
+                    }
+                } catch (err) {
+                    // the kernel throws without a message on an edge it cannot take
+                }
+                maker.delete();
+                return null;
+            },
+            // the distances on the edge's two faces (facesOfEdge order)
+            sizes: function (i, faces, between) {
+                if (mode === 'equal') {
+                    return [distance, distance];
+                }
+                const near = faces[0].IsSame(refs[i]) ? 0 : 1;
+                // the bevel leaves the reference face at `angle`, so on the
+                // other face it reaches (law of sines in the cross section)
+                const far = mode === 'two' ? distance2 : distance * Math.sin(angle * Math.PI / 180) / Math.sin(between + angle * Math.PI / 180);
+                const out = [];
+                out[near] = distance;
+                out[1 - near] = far;
+                return out;
+            },
+            free: free
+        };
+    };
+    // The builder's chamfer; cut (cutChamfer) when the builder refuses it
+    const make = function (body, edges) {
+        const p = plan(body, edges);
+        try {
+            const maker = p.build(1) || cutChamfer(oc, body, edges, p.sizes, p.build);
+            if (!maker) {
+                throw new Error('The chamfer could not be built on these edges. Try a smaller distance');
+            }
+            return maker;
+        } finally {
+            p.free();
+        }
+    };
+    // The builder may also say done and leave the face it should take away
+    // as a broken sliver (the end of a rib standing on a plate): cut it then
+    const retry = function (body, edges) {
+        const p = plan(body, edges);
+        try {
+            return cutChamfer(oc, body, edges, p.sizes, p.build);
+        } finally {
+            p.free();
+        }
+    };
+    return onEdges(oc, bodies, feature, 'chamfer', make, report, retry);
+}
+
+/* ---- a chamfer that takes a whole face away ---- */
+// OpenCascade's chamfer builder refuses a bevel that ends exactly on the far
+// edge of a face next to the edge: a 10 mm chamfer on the end of a 10 mm
+// plate, which takes the end face away, fails while 9.99 builds (and so do
+// two chamfers that meet in a ridge), or it says done and leaves the face as
+// a broken sliver. On straight edges between flat faces a
+// chamfer is the same as cutting a wedge off along the edge, so that is what
+// is done then. The cut is only kept when it takes off what the builder's
+// own chamfers a hair smaller say it should: their volumes, carried on to
+// the full size. A wedge that bites into something past the end of an edge
+// (a wall the edge runs into) fails that check, and the chamfer fails as it
+// did before.
+
+// how much smaller (as a fraction) the builder's chamfers for the check are
+const CUT_CHECK_STEP = 1e-3;
+
+function vSub(a, b) {
+    return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
+}
+
+function vAdd(a, b, k) {
+    return [a[0] + b[0] * k, a[1] + b[1] * k, a[2] + b[2] * k];
+}
+
+function vDot(a, b) {
+    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+}
+
+function vCross(a, b) {
+    return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
+}
+
+function vUnit(a) {
+    const l = Math.hypot(a[0], a[1], a[2]);
+    return l > 1e-12 ? [a[0] / l, a[1] / l, a[2] / l] : null;
+}
+
+// A straight edge between two flat faces that meet at an outside corner:
+// { start, e: unit direction, length, faces: [face, face] (facesOfEdge
+// order, the caller's to delete), u: per face the direction across it away
+// from the edge, between: the angle between the two in radians }, or null.
+function bevelSite(oc, body, edge) {
+    const curve = new oc.BRepAdaptor_Curve(edge);
+    let ends = null;
+    if (curve.GetType() === oc.GeomAbs_CurveType.GeomAbs_Line) {
+        const p = curve.Value(curve.FirstParameter());
+        const q = curve.Value(curve.LastParameter());
+        ends = [[p.X(), p.Y(), p.Z()], [q.X(), q.Y(), q.Z()]];
+        p.delete();
+        q.delete();
+    }
+    curve.delete();
+    if (!ends) {
+        return null;
+    }
+    const length = Math.hypot(ends[1][0] - ends[0][0], ends[1][1] - ends[0][1], ends[1][2] - ends[0][2]);
+    const e = vUnit(vSub(ends[1], ends[0]));
+    const faces = facesOfEdge(oc, body, edge);
+    const drop = function () {
+        faces.forEach(function (f) {
+            f.delete();
+        });
+        return null;
+    };
+    if (!e || faces.length !== 2) {
+        return drop();
+    }
+    const mid = vAdd(ends[0], e, length / 2);
+    const normals = faces.map(function (face) {
+        const at = surfaceAt(oc, face, mid);
+        return at.key.indexOf('plane:') === 0 ? at.normal : null;
+    });
+    if (!normals[0] || !normals[1]) {
+        return drop();
+    }
+    // An outside corner: a step off the edge across one face and under the
+    // other is out of the material (as edgeSignature)
+    const off = vUnit(vSub(normals[0], normals[1]));
+    if (!off || isInside(oc, body, vAdd(mid, off, 0.01))) {
+        return drop();
+    }
+    // Across a face away from the edge is in the face's plane, square to the
+    // edge, and (at an outside corner) against the other face's normal
+    const u = [0, 1].map(function (k) {
+        const across = vUnit(vCross(normals[k], e));
+        return across && vDot(across, normals[1 - k]) > 0 ? across.map(function (c) {
+            return -c;
+        }) : across;
+    });
+    if (!u[0] || !u[1]) {
+        return drop();
+    }
+    // Per end, does the material stop there? Every other face through the
+    // end looks away from the edge (the end of a box): the wedge may run on
+    // past it. A face that looks back at the edge (the plate a rib stands
+    // on) carries the material on: the wedge stops at the end.
+    const open = [false, false];
+    [0, 1].forEach(function (k) {
+        const end = ends[k];
+        const away = k === 0 ? e.map(function (c) {
+            return -c;
+        }) : e;
+        let stops = true;
+        const explorer = new oc.TopExp_Explorer(body, oc.TopAbs_ShapeEnum.TopAbs_FACE);
+        for (; explorer.More() && stops; explorer.Next()) {
+            const face = oc.TopoDS.Face(explorer.Current());
+            if (!face.IsSame(faces[0]) && !face.IsSame(faces[1]) && distanceTo(oc, face, end) < 1e-5) {
+                const normal = surfaceAt(oc, face, end).normal;
+                stops = !!normal && vDot(normal, away) > 1e-6;
+            }
+            face.delete();
+        }
+        explorer.delete();
+        open[k] = stops;
+    });
+    return { start: ends[0], e: e, length: length, faces: faces, u: u, open: open, between: Math.acos(Math.max(-1, Math.min(1, vDot(u[0], u[1])))) };
+}
+
+// A solid: the triangle `corners` swept by `sweep`
+function wedgeSolid(oc, corners, sweep) {
+    const points = corners.map(function (p) {
+        return pnt(oc, p);
+    });
+    const wireMaker = new oc.BRepBuilderAPI_MakeWire();
+    points.forEach(function (point, i) {
+        const edgeMaker = new oc.BRepBuilderAPI_MakeEdge(point, points[(i + 1) % points.length]);
+        wireMaker.Add(edgeMaker.Edge());
+        edgeMaker.delete();
+    });
+    const faceMaker = new oc.BRepBuilderAPI_MakeFace(wireMaker.Wire(), true);
+    const along = vec(oc, sweep);
+    const prism = new oc.BRepPrimAPI_MakePrism(faceMaker.Face(), along, false, true);
+    const solid = prism.Shape();
+    [prism, along, faceMaker, wireMaker].concat(points).forEach(function (o) {
+        o.delete();
+    });
+    return outward(oc, solid);
+}
+
+// The chamfer of `edges` (on `body`) cut as wedges. sizes(i, faces,
+// between): the distances on the two faces of edge i; build(scale): the
+// builder's chamfer with every distance times scale, or null. Returns a
+// stand-in for the builder ({ Shape, fresh, delete }) or null.
+function cutChamfer(oc, body, edges, sizes, build) {
+    const sites = [];
+    const free = function () {
+        sites.forEach(function (site) {
+            site.faces.forEach(function (f) {
+                f.delete();
+            });
+        });
+    };
+    let tool = null;
+    let cut = null;
+    try {
+        const bevels = [];
+        for (let i = 0; i < edges.length; i++) {
+            const site = bevelSite(oc, body, edges[i]);
+            if (!site) {
+                return null;
+            }
+            sites.push(site);
+            const d = sizes(i, site.faces, site.between);
+            if (!(d[0] > 0 && d[1] > 0 && isFinite(d[0]) && isFinite(d[1]))) {
+                return null;
+            }
+            // The cross section: the bevel from one face to the other, and a
+            // corner off the material so no side lies on a face of the body.
+            // Run on past an end where the material stops, so it clears the
+            // face there (the end of a box may lean); else stop at the end.
+            const a = site.u[0].map(function (c) {
+                return c * d[0];
+            });
+            const b = site.u[1].map(function (c) {
+                return c * d[1];
+            });
+            const outside = vUnit(vAdd(site.u[0], site.u[1], 1));
+            if (!outside) {
+                return null;
+            }
+            const past = 2 * Math.max(d[0], d[1]);
+            const head = site.open[0] ? past : 0;
+            const tail = site.open[1] ? past : 0;
+            const base = vAdd(site.start, site.e, -head);
+            const corners = [vAdd(base, a, 1), vAdd(base, b, 1), vAdd(base, outside, -0.5 * Math.min(d[0], d[1]))];
+            const solid = wedgeSolid(oc, corners, site.e.map(function (c) {
+                return c * (site.length + head + tail);
+            }));
+            const joined = tool ? boolean(oc, 'join', tool, solid) : solid;
+            if (tool) {
+                tool.delete();
+                solid.delete();
+            }
+            tool = joined;
+            if (!tool) {
+                return null;
+            }
+            // the bevel's plane, its normal pointing out of the material
+            let normal = vUnit(vCross(vSub(b, a), site.e));
+            if (vDot(normal, outside) > 0) {
+                normal = normal.map(function (c) {
+                    return -c;
+                });
+            }
+            bevels.push({ point: vAdd(site.start, a, 1), normal: normal });
+        }
+        cut = boolean(oc, 'cut', body, tool);
+        if (!cut || isEmpty(oc, cut)) {
+            return null;
+        }
+        // The check: the material the builder takes off at 1 - h and 1 - 2h
+        // of the size, carried on to the full size (a chamfer takes off an
+        // amount that grows smoothly with its size: square, plus a cube
+        // part where bevels meet at a corner, so the error is tiny)
+        const before = volume(oc, body);
+        const taken = [1 - CUT_CHECK_STEP, 1 - 2 * CUT_CHECK_STEP].map(function (scale) {
+            const maker = build(scale);
+            if (!maker) {
+                return null;
+            }
+            const shape = maker.Shape();
+            const v = volume(oc, shape);
+            shape.delete();
             maker.delete();
-            throw new Error('The chamfer could not be built on these edges. Try a smaller distance');
+            return before - v;
+        });
+        if (taken[0] === null || taken[1] === null) {
+            return null;
         }
-        return maker;
-    }, report);
+        const expected = 2 * taken[0] - taken[1];
+        const got = before - volume(oc, cut);
+        if (!(expected > 0) || !(Math.abs(got - expected) <= Math.max(expected * 1e-4, Math.abs(before) * 1e-9))) {
+            return null;
+        }
+        const shape = cut;
+        cut = null;
+        return {
+            Shape: function () {
+                return shape;
+            },
+            // the new faces: those on a bevel's plane (see freshFaces)
+            fresh: function () {
+                const flags = [];
+                const explorer = new oc.TopExp_Explorer(shape, oc.TopAbs_ShapeEnum.TopAbs_FACE);
+                for (; explorer.More(); explorer.Next()) {
+                    const face = oc.TopoDS.Face(explorer.Current());
+                    const info = faceInfo(oc, face, face.Orientation() === oc.TopAbs_Orientation.TopAbs_REVERSED);
+                    flags.push(info.type === 'plane' && bevels.some(function (bevel) {
+                        return vDot(info.normal, bevel.normal) > 1 - 1e-6 && Math.abs(vDot(vSub(info.origin, bevel.point), bevel.normal)) < 1e-4;
+                    }));
+                    face.delete();
+                }
+                explorer.delete();
+                return flags;
+            },
+            delete: function () {}
+        };
+    } finally {
+        free();
+        if (tool) {
+            tool.delete();
+        }
+        if (cut) {
+            cut.delete();
+        }
+    }
 }
 
 // How far a point is from a shape

+ 106 - 0
src/web/3D Modeler/tests/chamfer-whole-face.test.mjs

@@ -0,0 +1,106 @@
+/*
+    A chamfer exactly as wide as a face next to its edge takes that face away
+    (10 mm on the end of a 10 mm plate). OpenCascade's chamfer builder refuses
+    it while 9.99 builds, so the kernel cuts it as a wedge instead (cutChamfer
+    in kernel/occt.js). Run with: node tests/run.mjs chamfer-whole
+*/
+import init from '../lib/occt/replicad_single.js';
+import { createRebuilder } from '../js/kernel/rebuild.js';
+import * as kernel from '../js/kernel/occt.js';
+
+const oc = await init();
+let failed = 0;
+const a = (c, m, x) => { if (!c) { failed++; console.log('FAIL', m, x === undefined ? '' : JSON.stringify(x)); } };
+const near = (x, y, t) => Math.abs(x - y) < (t || 1e-3);
+const ref = e => ({ body: 0, mid: e.mid, length: e.length });
+
+function rect(id, x0, y0, x1, y1) {
+    const pts = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
+    const g = [];
+    pts.forEach((p, i) => g.push({ id: id + 'p' + i, type: 'point', x: p[0], y: p[1] }));
+    pts.forEach((p, i) => g.push({ id: id + 'l' + i, type: 'line', p1: id + 'p' + i, p2: id + 'p' + ((i + 1) % 4) }));
+    return { id: id, type: 'sketch', name: id, plane: { ref: 'origin:xy' }, geometry: g, constraints: [] };
+}
+function extrude(id, sketch, at, height) {
+    return { id: id, type: 'extrude', name: id, sketch: sketch, regions: [at], operation: 'join', extent: { type: 'distance', value: height, direction: 'positive' } };
+}
+// Rebuild `doc` with a chamfer on the edges `pick` chooses: { status, message, body }
+function chamfered(doc, pick, extra) {
+    const body = createRebuilder(oc).rebuild(doc).bodies[0];
+    const edges = body.edges.filter(pick);
+    const withChamfer = JSON.parse(JSON.stringify(doc));
+    withChamfer.features.push(Object.assign({ id: 'c', type: 'chamfer', name: 'Chamfer1', edges: edges.map(ref) }, extra));
+    const out = createRebuilder(oc).rebuild(withChamfer);
+    return { edges: edges.length, status: out.features.c.status, message: out.features.c.message, body: out.bodies[0], before: body };
+}
+
+// A plate 10 wide, 40 deep and 40 tall: its top face is 10 wide
+const plate = { features: [rect('s', 0, 0, 10, 40), extrude('e', 's', [5, 20], 40)] };
+const topRight = e => e.curve && e.curve.type === 'line' && near(e.mid[0], 10) && near(e.mid[2], 40) && near(e.length, 40);
+
+let r = chamfered(plate, topRight, { distance: 9.99 });
+a(r.edges === 1 && r.status === 'ok' && near(r.body.volume, 16000 - 0.5 * 9.99 * 9.99 * 40), 'a chamfer a hair narrower than the face builds as before', r);
+a(r.body && r.body.faces.length === 7, 'and leaves a sliver of the top face', r.body && r.body.faces.length);
+
+r = chamfered(plate, topRight, { distance: 10 });
+a(r.status === 'ok', 'a 10 chamfer on the edge of a 10 wide face builds', r.message);
+a(r.body && near(r.body.volume, 16000 - 0.5 * 10 * 10 * 40), 'it takes off half of 10 x 10 x 40', r.body && r.body.volume);
+a(r.body && r.body.faces.length === 6, 'the top face is gone: four sides, bottom and the bevel', r.body && r.body.faces.length);
+const bevel = r.body && r.body.faces.find(f => f.type === 'plane' && near(f.normal[0], Math.SQRT1_2) && near(f.normal[2], Math.SQRT1_2));
+a(bevel && near(bevel.area, 40 * 10 * Math.SQRT2, 1e-6), 'the bevel runs from the far edge of the top to 10 down the side', bevel && bevel.area);
+
+r = chamfered(plate, topRight, { distance: 12 });
+a(r.status !== 'ok', 'a chamfer wider than the face is still refused', r.status);
+a(r.body && near(r.body.volume, 16000), 'and the body is left alone', r.body && r.body.volume);
+
+// Two distances and distance + angle measure `distance` on the top face
+// (the first of the two faces by position) and also take it away
+r = chamfered(plate, topRight, { distance: 10, mode: 'two', distance2: 5 });
+a(r.status === 'ok' && near(r.body.volume, 16000 - 0.5 * 10 * 5 * 40), 'two distances: 10 across the top, 5 down the side', r);
+r = chamfered(plate, topRight, { distance: 10, mode: 'angle', angle: 30 });
+a(r.status === 'ok' && near(r.body.volume, 16000 - 0.5 * 10 * 10 * Math.tan(Math.PI / 6) * 40), 'distance and angle: 10 across the top at 30 degrees', r);
+
+// Both top edges at 5 meet in a ridge
+r = chamfered(plate, e => e.curve && e.curve.type === 'line' && near(e.mid[2], 40) && near(e.length, 40), { distance: 5 });
+a(r.edges === 2 && r.status === 'ok' && near(r.body.volume, 16000 - 2 * 0.5 * 5 * 5 * 40), 'two chamfers of half the width meet in a ridge', r);
+a(r.body && r.body.faces.length === 7, 'the ridge: four sides, bottom and two bevels', r.body && r.body.faces.length);
+
+// The end of a 10 thick plate, as reported: a 40 x 40 base 10 thick with a
+// 40 tall wall on one side; the end face of the base is 10 tall
+const L = { features: [rect('s', 0, 0, 40, 40), extrude('e', 's', [20, 20], 10), rect('t', 0, 0, 40, 10), extrude('f', 't', [20, 5], 40)] };
+const baseEnd = e => e.curve && e.curve.type === 'line' && near(e.mid[1], 40) && near(e.mid[2], 10) && near(e.length, 40);
+r = chamfered(L, baseEnd, { distance: 10 });
+a(r.status === 'ok' && near(r.body.volume, r.before.volume - 0.5 * 10 * 10 * 40), 'a 10 chamfer takes the 10 tall end of the base away', r);
+a(r.body && r.body.faces.length === r.before.faces.length, 'as many faces: the end face became the bevel, no sliver is left', [r.before.faces.length, r.body && r.body.faces.length]);
+
+// A rib 10 wide standing on a plate: its vertical end edge runs into the
+// plate, so the wedge must stop at the plate rather than bite into it. Here
+// the builder says done but leaves a broken sliver of the rib's end face.
+const rib = { features: [rect('s', 0, 0, 40, 40), extrude('e', 's', [20, 20], 10), rect('t', 15, 0, 25, 40), extrude('f', 't', [20, 20], 40)] };
+const ribEnd = e => e.curve && e.curve.type === 'line' && near(e.mid[0], 25) && near(e.mid[1], 40) && near(e.length, 30);
+r = chamfered(rib, ribEnd, { distance: 10 });
+a(r.status === 'ok', 'a 10 chamfer on the end edge of a 10 wide rib builds', r.message);
+a(r.body && near(r.body.volume, r.before.volume - 0.5 * 10 * 10 * 30), 'only the rib loses material, the plate is untouched', r.body && [r.before.volume, r.body.volume]);
+
+// All four top edges of a 10 x 10 column at 5: the bevels meet in a point
+const column = { features: [rect('s', 0, 0, 10, 10), extrude('e', 's', [5, 5], 30)] };
+r = chamfered(column, e => near(e.mid[2], 30), { distance: 5 });
+a(r.edges === 4 && r.status === 'ok', 'four chamfers of half the width build', r.message);
+a(r.body && near(r.body.volume, 3000 - (500 - 100 * 5 / 3)), 'the column ends in a pyramid 5 tall', r.body && r.body.volume);
+a(r.body && r.body.faces.length === 9, 'four sides, bottom and four bevels', r.body && r.body.faces.length);
+
+// The live preview marks the bevel as the new face
+const rb = createRebuilder(oc);
+const state = rb.shapesBefore(plate, null);
+const block = rb.rebuild(plate).bodies[0];
+const report = { fresh: [] };
+const made = kernel.chamfer(oc, state.bodies, { edges: block.edges.filter(topRight).map(ref), distance: 10 }, report);
+const described = kernel.describe(oc, made[0]);
+const flags = report.fresh[0] || [];
+a(flags.length === described.faces.length, 'one preview flag per face', [flags.length, described.faces.length]);
+const fresh = described.faces.filter((f, i) => flags[i]);
+a(fresh.length === 1 && near(fresh[0].normal[0], Math.SQRT1_2) && near(fresh[0].normal[2], Math.SQRT1_2), 'the preview marks only the bevel as new', fresh.map(f => f.normal));
+made[0].delete();
+
+console.log(failed ? failed + ' check(s) FAILED' : 'chamfer-whole-face: all checks passed');
+process.exitCode = failed ? 1 : 0;