@rulecad/shapes 0.4.7 → 0.4.9
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 +17 -0
- package/optimised.d.mts +6 -2
- package/optimised.mjs +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ 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.9: swept parts as regions
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `regionShape` (and so `optimisedOutline`) takes a region of `rings`: closed outlines solid on their left, holes
|
|
11
|
+
clockwise, as cad gives a part swept past a flat plate. It is cut with its holes open; drawn from its `points`
|
|
12
|
+
alone, the solver's single polygon of all its outlines, it would not be.
|
|
13
|
+
|
|
14
|
+
### Printed sizes that moved
|
|
15
|
+
|
|
16
|
+
- None.
|
|
17
|
+
|
|
18
|
+
## 0.4.8: a part as a region
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `optimisedOutline` leaves a design's part named as a keep or avoid region to the design, as `optimisedSolid` does:
|
|
22
|
+
`regionShape` gives null for one. Before, it was drawn as a circle with no radius, and the build failed.
|
|
23
|
+
|
|
7
24
|
## 0.4.7: shaft bores in one place
|
|
8
25
|
### Added
|
|
9
26
|
|
package/optimised.d.mts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function fromOutlines(loops: [number, number][][]): jscad.geometries.geom2.Geom2;
|
|
6
6
|
/**
|
|
7
|
-
* A region of a problem (a circle, a centred rectangle
|
|
8
|
-
*
|
|
7
|
+
* A region of a problem (a circle, a centred rectangle, a polygon, or rings: closed outlines solid on their left, holes
|
|
8
|
+
* clockwise, as a part swept past the plate is cut) as a JSCAD 2D shape; a design's part is null (it is the design's own
|
|
9
|
+
* to add or cut, as it is in 3D).
|
|
10
|
+
* @param {{ at?: [number, number], r?: number, size?: [number, number], points?: [number, number][], rings?: [number, number][][], part?: string }} r
|
|
9
11
|
* @param {number} [segments]
|
|
10
12
|
*/
|
|
11
13
|
export function regionShape(r: {
|
|
@@ -13,6 +15,8 @@ export function regionShape(r: {
|
|
|
13
15
|
r?: number;
|
|
14
16
|
size?: [number, number];
|
|
15
17
|
points?: [number, number][];
|
|
18
|
+
rings?: [number, number][][];
|
|
19
|
+
part?: string;
|
|
16
20
|
}, segments?: number): jscad.geometries.geom2.Geom2;
|
|
17
21
|
/**
|
|
18
22
|
* An optimised result's outline, its keep regions added and avoid regions cut exactly.
|
package/optimised.mjs
CHANGED
|
@@ -23,11 +23,15 @@ export function fromOutlines(loops) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* A region of a problem (a circle, a centred rectangle
|
|
27
|
-
*
|
|
26
|
+
* A region of a problem (a circle, a centred rectangle, a polygon, or rings: closed outlines solid on their left, holes
|
|
27
|
+
* clockwise, as a part swept past the plate is cut) as a JSCAD 2D shape; a design's part is null (it is the design's own
|
|
28
|
+
* to add or cut, as it is in 3D).
|
|
29
|
+
* @param {{ at?: [number, number], r?: number, size?: [number, number], points?: [number, number][], rings?: [number, number][][], part?: string }} r
|
|
28
30
|
* @param {number} [segments]
|
|
29
31
|
*/
|
|
30
32
|
export function regionShape(r, segments = 48) {
|
|
33
|
+
if (r.part || r.triangles) return null;
|
|
34
|
+
if (r.rings) return fromOutlines(r.rings); // a section of several outlines (a part swept past, its holes open), each solid on its left
|
|
31
35
|
if (r.points) return polygon({ points: r.points });
|
|
32
36
|
if (r.size) return rectangle({ center: r.at, size: r.size });
|
|
33
37
|
return circle({ center: r.at, radius: r.r, segments });
|
|
@@ -40,8 +44,9 @@ export function regionShape(r, segments = 48) {
|
|
|
40
44
|
*/
|
|
41
45
|
export function optimisedOutline(result, { segments = 48 } = {}) {
|
|
42
46
|
let shape = fromOutlines(result.outlines);
|
|
43
|
-
|
|
44
|
-
if (
|
|
47
|
+
const keep = result.regions.keep.map((r) => regionShape(r, segments)).filter(Boolean), avoid = result.regions.avoid.map((r) => regionShape(r, segments)).filter(Boolean);
|
|
48
|
+
if (keep.length) shape = union(shape, ...keep);
|
|
49
|
+
if (avoid.length) shape = subtract(shape, ...avoid);
|
|
45
50
|
return shape;
|
|
46
51
|
}
|
|
47
52
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/shapes",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
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": {
|