partforge 0.67.2 → 0.67.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "partforge",
3
- "version": "0.67.2",
3
+ "version": "0.67.3",
4
4
  "description": "Turn a declarative part definition into a parametric-CAD web app (three.js + Manifold/Replicad). Requires a Vite-based consumer.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  // The cubic subdivision approach is ported from glenzli/paperjs-offset
9
9
  // (https://github.com/glenzli/paperjs-offset, MIT License, Copyright (c) glenzli),
10
10
  // adapted from paper.js Segments to the partforge contour IR.
11
- import { arcCenterAndSweep } from "./paper-bridge.js";
11
+ import { arcCenterAndSweep, booleanRegions } from "./paper-bridge.js";
12
12
  import { cubicAt, splitCubic, jointTangents, SMOOTH_JOINT_DEG } from "./contour-ops.js";
13
13
  import { tessellateContour, closeContourGap } from "./profile.js";
14
14
  import { ringArea, pointInRing } from "./shape2d-regions.js";
@@ -718,7 +718,11 @@ const flattenRing = (contour, segs) => {
718
718
  // All seven rescues are oracle-checked: median area error 0.0972 %, worst 1.663 %, with zero
719
719
  // region-count losses and zero complete arc losses. The ladder stays because those seven raw
720
720
  // arrangements remain numerically unclosable, not because the formerly parked comb/text
721
- // failures still exist.
721
+ // failures still exist. Those seven are all erosion (negative delta) or single-region cases;
722
+ // the per-region rung below is positive-delta-and-multi-region only, so it wins none of them
723
+ // and the rates above are unchanged by its addition — its own coverage class (whole-word text
724
+ // dilation, feedback 86970b00) sits outside this corpus, whose glyphs are single characters
725
+ // and whose "Scott" case never reaches the delta band where the merged word fails to close.
722
726
  //
723
727
  // Rung ORDER is by fidelity of what survives, not by hit rate:
724
728
  // 1. delta perturbed by ±1e-9 relative. Escapes an exactly-degenerate arrangement (two
@@ -729,7 +733,13 @@ const flattenRing = (contour, segs) => {
729
733
  // that radius apart onto one vertex. This can merge a genuine severing pinch, so the
730
734
  // 20x rung is not widened further even though the current seven rescues preserve the
731
735
  // oracle's region count.
732
- // 3. the raw outline re-run as polylines (64/256/1024 facets per turn). Geometrically
736
+ // 3. per-region-union (delta > 0, more than one region only). Offsets each region alone and
737
+ // unites the results through paper's curve-native boolean. EXACT, not approximate: a
738
+ // positive dilation distributes over union, so this equals the whole-region offset the
739
+ // resolver could not close — with arcs intact, above the polyline rungs. It is here rather
740
+ // than at #1 only because it costs a boolean per region and re-runs the earlier rungs on
741
+ // each; the two cheaper exact rungs get first refusal.
742
+ // 4. the raw outline re-run as polylines (64/256/1024 facets per turn). Geometrically
733
743
  // faithful to the chord error of that tessellation, but it DEGRADES THE IR: round joins
734
744
  // come back as chords, so A STEP EXPORT OF A POLYLINE-RUNG RESULT LOSES ITS TRUE CIRCLES.
735
745
  // No current corpus rescue loses every arc, but these rungs remain last because that
@@ -753,6 +763,25 @@ const flattenRing = (contour, segs) => {
753
763
  // (±1e-4 and ±1e-3 mm absolute rungs) was measured too: it bought ONE extra case out of 62 and
754
764
  // more than doubled the worst absolute error, 0.048 → 0.112 mm², so it is not here either.
755
765
  //
766
+ // Offset each region on its own and unite the results through paper's planar boolean engine.
767
+ // This is EXACT for a positive delta, not an approximation: Minkowski dilation distributes
768
+ // over union, (⋃ Rᵢ) ⊕ B = ⋃ (Rᵢ ⊕ B), so the whole-region offset the winding resolver cannot
769
+ // close as one merged arrangement equals the union of the single-region offsets. Each single
770
+ // region is a far simpler arrangement — a lone glyph rather than a whole word's worth of offset
771
+ // walls meeting near-tangentially — and its own base offset still gets the earlier rungs'
772
+ // rescues, because the per-region call re-enters the public offsetRegions (which runs its own
773
+ // ladder for that one region). booleanRegions unites through paper's CURVE-native engine rather
774
+ // than a tessellation, so arcs stay arcs and a STEP export keeps its true circles — which is why
775
+ // this rung sits ABOVE the polyline rungs, whose chord approximation is the fidelity floor.
776
+ function perRegionUnion(regions, delta, corners) {
777
+ let out = [];
778
+ for (const rg of regions) {
779
+ const one = offsetRegions([rg], delta, { corners }); // single region: never re-enters this rung
780
+ out = out.length ? booleanRegions(out, one, "unite") : one;
781
+ }
782
+ return out;
783
+ }
784
+
756
785
  // The ladder as named, LAZY rungs — one list, walked by chainFallback below and by
757
786
  // scripts/offset-rates.mjs, so a measurement of "what each rung costs" can never drift from
758
787
  // the ladder that actually ships. Every rung's whole body (including tessellating the outline
@@ -765,6 +794,13 @@ export function _ladderRungs(regions, raw, delta, corners) {
765
794
  run: () => resolveOrRaw(rawOffset(regions, delta * (1 + sign * 1e-9), corners)) })),
766
795
  ...[4, 20].map((mult) => ({ name: `clusterTol*${mult}`,
767
796
  run: () => resolveOffsetWinding(raw, { clusterTol: CLUSTER_TOL * mult }) })),
797
+ // Exact for positive dilation and arc-preserving, so it ranks above the polyline rungs but
798
+ // below the two cheaper exact rungs that need no boolean. Only meaningful when there is more
799
+ // than one region to decompose, and only distributive for a positive delta; the guard is
800
+ // also what bounds the recursion — a single-region offsetRegions call never reaches here.
801
+ ...(delta > 0 && regions.length > 1
802
+ ? [{ name: "per-region-union", run: () => perRegionUnion(regions, delta, corners) }]
803
+ : []),
768
804
  ...[64, 256, 1024].map((segs) => ({ name: `polyline@${segs}`,
769
805
  run: () => resolveOffsetWinding(raw.map((rg) => ({ outer: flattenRing(rg.outer, segs),
770
806
  holes: rg.holes.map((h) => flattenRing(h, segs)) }))) })),
@@ -15,7 +15,7 @@
15
15
  // opentype.js's namespace shape differs between bundler and Node resolution —
16
16
  // see opentype-interop.js for the trap (it has bitten once in each direction).
17
17
  import * as opentypeNamespace from "opentype.js";
18
- import { normalizeOpentype } from "./opentype-interop.js";
18
+ import { normalizeOpentype, parseFont } from "./opentype-interop.js";
19
19
  const opentype = normalizeOpentype(opentypeNamespace);
20
20
  import { KernelCapabilityError } from "./errors.js";
21
21
  import { isPlainOptions, KERNEL_OP_SPECS } from "./op-options.js";
@@ -95,7 +95,7 @@ export function finishKernel(k) {
95
95
  // EXACT byte range — arg.buffer alone spans the whole (possibly pooled) backing
96
96
  // buffer, which would feed opentype garbage for a byteOffset>0 view.
97
97
  const buf = ArrayBuffer.isView(arg) ? arg.buffer.slice(arg.byteOffset, arg.byteOffset + arg.byteLength) : arg;
98
- f = opentype.parse(buf); byteCache.set(arg, f);
98
+ f = parseFont(opentype, buf); byteCache.set(arg, f);
99
99
  }
100
100
  return f;
101
101
  };
@@ -109,7 +109,7 @@ export function finishKernel(k) {
109
109
  // guards against that ever changing.
110
110
  if (!k._defaultFont) {
111
111
  const { buffer, byteOffset, byteLength } = DEFAULT_FONT_BYTES;
112
- k._defaultFont = opentype.parse(buffer.slice(byteOffset, byteOffset + byteLength));
112
+ k._defaultFont = parseFont(opentype, buffer.slice(byteOffset, byteOffset + byteLength), "the bundled default");
113
113
  }
114
114
  return k._defaultFont;
115
115
  }
@@ -11,3 +11,25 @@
11
11
  // one function so the two interop shapes stay handled in one place.
12
12
  export const normalizeOpentype = (ns) =>
13
13
  typeof ns?.parse === "function" ? ns : (ns?.default ?? ns);
14
+
15
+ // Parse font bytes into an opentype.Font, turning opentype.js's own low-level parse
16
+ // failures into a NAMED, actionable error. A single unreadable font in a part's `fonts`
17
+ // map otherwise kills the whole build with a message that names neither the font nor the
18
+ // fix — a RangeError deep in the TrueType reader, or opentype.js's raw "WOFF2 require an
19
+ // external decompressor library" URL — and the part just "won't build" with no clue which
20
+ // font or why. This is the exact dead end a variable font or a WOFF/WOFF2 upload lands in:
21
+ // opentype.js 2.x reads neither, so the guidance is always the same (supply a static TTF or
22
+ // OTF). `label` is the declared font name where one is known (the `fonts` map key), and is
23
+ // omitted for an inline-bytes font, which has no name to give. All parse sites route through
24
+ // here so the message stays in one place.
25
+ export function parseFont(opentype, buf, label) {
26
+ try {
27
+ return opentype.parse(buf);
28
+ } catch (err) {
29
+ const who = label ? `font "${label}"` : "an inline font";
30
+ throw new Error(
31
+ `text2d: ${who} could not be read as a TTF or OTF — a variable font or a WOFF/WOFF2 ` +
32
+ `file will fail here; supply a static TTF or OTF instead. (${err?.message ?? err})`,
33
+ );
34
+ }
35
+ }
@@ -5,7 +5,7 @@
5
5
  import { meshTo3MF } from "./geometry/threemf.js";
6
6
  import { exportablePartNames } from "./export-select.js";
7
7
  import { resolveFonts } from "./fonts.js";
8
- import { normalizeOpentype } from "./geometry/opentype-interop.js";
8
+ import { normalizeOpentype, parseFont } from "./geometry/opentype-interop.js";
9
9
  import { ensureImports, resolveImports } from "./imports.js";
10
10
  import { safeName } from "./safe-name.js";
11
11
  import { exportSubParts, resolveParams, buildPosed } from "./part-model.js";
@@ -107,7 +107,7 @@ export async function handle(kernel, part, msg, post, opts = {}) {
107
107
  if (part.fonts && kernel._fonts) {
108
108
  const opentype = normalizeOpentype(await import("opentype.js"));
109
109
  const bufs = await resolveFonts(part.fonts);
110
- for (const [name, buf] of bufs) if (!kernel._fonts.has(name)) kernel._fonts.set(name, opentype.parse(buf));
110
+ for (const [name, buf] of bufs) if (!kernel._fonts.has(name)) kernel._fonts.set(name, parseFont(opentype, buf, name));
111
111
  }
112
112
  // Register this part's declared imports on the kernel running this job — the
113
113
  // import-asset sibling of the fonts preload above. See ensureImports for the
@@ -4,7 +4,7 @@
4
4
  import Module from "manifold-3d";
5
5
  import { createManifoldKernel } from "../framework/geometry/manifold-backend.js";
6
6
  import { resolveFonts } from "../framework/fonts.js";
7
- import { normalizeOpentype } from "../framework/geometry/opentype-interop.js";
7
+ import { normalizeOpentype, parseFont } from "../framework/geometry/opentype-interop.js";
8
8
  import { ensureImports } from "../framework/imports.js";
9
9
  import { nodeAssetSources } from "./assets.js";
10
10
  import { tessellateStepAssets } from "./step-mesh.js";
@@ -14,7 +14,7 @@ export async function bootManifoldKernel({ quality = "preview", fonts, imports,
14
14
  wasm.setup();
15
15
  const kernel = createManifoldKernel(wasm, { quality });
16
16
  if (fonts) { const opentype = normalizeOpentype(await import("opentype.js"));
17
- for (const [name, buf] of await resolveFonts(nodeAssetSources(fonts))) kernel._fonts.set(name, opentype.parse(buf)); }
17
+ for (const [name, buf] of await resolveFonts(nodeAssetSources(fonts))) kernel._fonts.set(name, parseFont(opentype, buf, name)); }
18
18
  if (imports) {
19
19
  const decl = nodeAssetSources(imports);
20
20
  const { resolveImports } = await import("../framework/imports.js");
@@ -6,7 +6,7 @@ import path from "path";
6
6
  import fs from "fs";
7
7
  import { createOcctKernel } from "../framework/geometry/occt-backend.js";
8
8
  import { resolveFonts } from "../framework/fonts.js";
9
- import { normalizeOpentype } from "../framework/geometry/opentype-interop.js";
9
+ import { normalizeOpentype, parseFont } from "../framework/geometry/opentype-interop.js";
10
10
  import { ensureImports } from "../framework/imports.js";
11
11
  import { nodeAssetSources } from "./assets.js";
12
12
 
@@ -20,7 +20,7 @@ export async function bootOcctKernel({ fonts, imports, importMeshes } = {}) {
20
20
  replicad.setOC(OC);
21
21
  const kernel = createOcctKernel(replicad);
22
22
  if (fonts) { const opentype = normalizeOpentype(await import("opentype.js"));
23
- for (const [name, buf] of await resolveFonts(nodeAssetSources(fonts))) kernel._fonts.set(name, opentype.parse(buf)); }
23
+ for (const [name, buf] of await resolveFonts(nodeAssetSources(fonts))) kernel._fonts.set(name, parseFont(opentype, buf, name)); }
24
24
  if (imports) await ensureImports(kernel, nodeAssetSources(imports), importMeshes ?? null);
25
25
  return kernel;
26
26
  }