@rulecad/topopt 0.2.2 → 0.2.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 +1 -1
- package/topopt.mjs +12 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/topopt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Topology optimisation for flat and solid parts: the stiffest layout of a fixed amount of material, printable without supports if asked, as outlines or a surface ready to print.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/topopt.mjs
CHANGED
|
@@ -58,14 +58,21 @@ export function discretise(p) {
|
|
|
58
58
|
const space = [p.space].flat(), keep = p.keep || [], avoid = p.avoid || [], dim = dimension(space[0]);
|
|
59
59
|
if (!(p.cell > 0)) throw new Error('the cell size must be more than 0 mm');
|
|
60
60
|
for (const r of [...space, ...keep, ...avoid]) if (dimension(r) !== dim) throw new Error(`a ${dimension(r)}D region in a ${dim}D problem: give every region ${dim === 3 ? 'x, y and z' : 'x and y'}`);
|
|
61
|
-
const all = [...space, ...keep].map(bounds), lo = [], n = [];
|
|
61
|
+
const all = [...space, ...keep].map(bounds), lo = [], hi = [], n = [];
|
|
62
62
|
for (let a = 0; a < dim; a++) {
|
|
63
|
-
lo.push(Math.min(...all.map((b) => b[a])));
|
|
64
|
-
n.push(Math.max(1, Math.round((
|
|
63
|
+
lo.push(Math.min(...all.map((b) => b[a]))); hi.push(Math.max(...all.map((b) => b[dim + a])));
|
|
64
|
+
n.push(Math.max(1, Math.round((hi[a] - lo[a]) / p.cell)));
|
|
65
65
|
}
|
|
66
66
|
if (dim === 3) { // whole numbers of 2, 4 or 8 cells along every side, for multigrid
|
|
67
|
-
const q = Math.min(...n) >= 16 ? 8 : Math.min(...n) >= 8 ? 4 : 2;
|
|
68
|
-
for (let a = 0; a < 3; a++)
|
|
67
|
+
const q = Math.min(...n) >= 16 ? 8 : Math.min(...n) >= 8 ? 4 : 2, build = /^([+-])([xyz])$/.exec(p.overhang ?? '');
|
|
68
|
+
for (let a = 0; a < 3; a++) {
|
|
69
|
+
n[a] = Math.ceil(n[a] / q) * q;
|
|
70
|
+
// The padding split evenly round the space, so a round space sits in the middle of its grid (all on one side, a
|
|
71
|
+
// round wall ran along the grid's edge there and drew as flat blocks). Along the build direction the bed's side
|
|
72
|
+
// stays flush, so the first layer sits on the bed.
|
|
73
|
+
const pad = n[a] * p.cell - (hi[a] - lo[a]);
|
|
74
|
+
lo[a] -= build && 'xyz'.indexOf(build[2]) === a ? (build[1] === '-' ? pad : 0) : pad / 2;
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
const size = dim === 3 ? { nx: n[0], ny: n[1], nz: n[2], h: p.cell } : { nx: n[0], ny: n[1], h: p.cell };
|
|
71
78
|
const g = makeGrid(size), origin = lo, h = p.cell;
|