@rulecad/shapes 0.4.5 → 0.4.6

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/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ What changed in each release, for someone upgrading a workspace. A **printed siz
4
4
  print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
5
5
  why.
6
6
 
7
+ ## 0.4.6: print-in-place clearances (#162)
8
+
9
+ ### Added
10
+
11
+ - `ops('manifold').gap(a, b, within)`: the least distance between two solids' surfaces, by Manifold's `minGap`, up to
12
+ `within` mm (#162). cad uses it to check that parts printed in place stand the print gap apart. On the JSCAD engine
13
+ `gap` refuses by name.
14
+
15
+ No printed size moved.
16
+
7
17
  ## 0.4.5: shapes holds no screw size (Fixings 3)
8
18
 
9
19
  ### What reads fixings now
package/README.md CHANGED
@@ -133,4 +133,8 @@ export function main (v) {
133
133
  }
134
134
  ```
135
135
 
136
+ With Manifold, `gap(a, b, within)` gives the least distance between two solids' surfaces (Manifold's `minGap`), in
137
+ mm: 0 where they touch or cross, `within` where nothing is nearer than that. cad checks parts printed in place with it.
138
+ JSCAD has no distance query, so `gap` on the JSCAD engine refuses by name.
139
+
136
140
  A shape Manifold can't read as a closed solid falls back to JSCAD for that operation (`stats.fallbacks` counts them).
package/ops.d.mts CHANGED
@@ -11,6 +11,7 @@ export function ops(engine?: "jscad" | "manifold"): Promise<{
11
11
  union: (...a: any[]) => jscad.geometries.geom2.Geom2;
12
12
  subtract: (...a: any[]) => jscad.geometries.geom2.Geom2;
13
13
  intersect: (...a: any[]) => jscad.geometries.geom2.Geom2;
14
+ gap: () => never;
14
15
  } | {
15
16
  engine: "manifold";
16
17
  stats: {
@@ -20,5 +21,6 @@ export function ops(engine?: "jscad" | "manifold"): Promise<{
20
21
  union: (...a: any[]) => any;
21
22
  subtract: (...a: any[]) => any;
22
23
  intersect: (...a: any[]) => any;
24
+ gap: (a: any, b: any, within?: number) => number;
23
25
  }>;
24
26
  import jscad from '@jscad/modeling';
package/ops.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
  // faster, and always watertight). Each op takes shapes or arrays of them, like JSCAD's. With Manifold, a shape that
4
4
  // can't be read as a closed solid falls back to JSCAD for that op (counted in stats.fallbacks).
5
5
  // const o = await ops('manifold'); o.union(a, b); o.subtract(a, b, c); o.intersect(a, b); o.stats
6
+ // and with Manifold, the least distance between two solids: o.gap(a, b, within)
6
7
  import jscad from '@jscad/modeling';
7
8
 
8
9
  const { geom3, poly3 } = jscad.geometries;
@@ -15,7 +16,9 @@ const flat = (args) => args.flat(Infinity).filter((g) => g != null);
15
16
  export async function ops(engine = 'jscad') {
16
17
  const stats = { ops: 0, fallbacks: 0 };
17
18
  const { union, subtract, intersect } = jscad.booleans;
18
- if (engine === 'jscad') return { engine, stats, union: (...a) => (stats.ops++, union(...flat(a))), subtract: (...a) => (stats.ops++, subtract(...flat(a))), intersect: (...a) => (stats.ops++, intersect(...flat(a))) };
19
+ // (the gap between two solids needs Manifold: JSCAD has no distance query, so it says so by name)
20
+ const noGap = () => { throw Object.assign(new Error('gap needs the manifold engine: ops(\'manifold\'), with manifold-3d installed'), { code: 'engine.gap' }); };
21
+ if (engine === 'jscad') return { engine, stats, union: (...a) => (stats.ops++, union(...flat(a))), subtract: (...a) => (stats.ops++, subtract(...flat(a))), intersect: (...a) => (stats.ops++, intersect(...flat(a))), gap: noGap };
19
22
  if (engine !== 'manifold') throw new Error(`no boolean engine "${engine}" (jscad or manifold)`);
20
23
  let wasm;
21
24
  try { wasm = await (await import('manifold-3d')).default(); } catch (e) {
@@ -57,5 +60,12 @@ export async function ops(engine = 'jscad') {
57
60
  return jscadOp(...shapes);
58
61
  } finally { for (const m of made) m.delete(); }
59
62
  };
60
- return { engine, stats, union: (...a) => run('union', union, a), subtract: (...a) => run('subtract', subtract, a), intersect: (...a) => run('intersect', intersect, a) };
63
+ // The least distance between two solids' surfaces, by Manifold's minGap, up to `within` mm (beyond it, within is
64
+ // returned: nothing nearer). 0 when they touch or cross.
65
+ const gap = (a, b, within = 1) => {
66
+ if (!(typeof within === 'number' && within > 0)) throw new Error(`gap: within is how far to look, in mm above 0 (got ${JSON.stringify(within)})`);
67
+ let ma = null, mb = null;
68
+ try { ma = toManifold(a); mb = toManifold(b); return Math.max(0, ma.minGap(mb, within)); } finally { ma?.delete(); mb?.delete(); }
69
+ };
70
+ return { engine, stats, union: (...a) => run('union', union, a), subtract: (...a) => run('subtract', subtract, a), intersect: (...a) => run('intersect', intersect, a), gap };
61
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/shapes",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Shape helpers for printed JSCAD designs: text that prints cleanly, anchors on a face, clean local cuts, and enclosure pieces (shells, lids, rails, print-safe holes).",
5
5
  "type": "module",
6
6
  "exports": {