brepjs-sheetmetal 0.1.0 → 0.3.0
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/README.md +5 -1
- package/dist/brepjs-sheetmetal.cjs +63 -0
- package/dist/brepjs-sheetmetal.js +64 -2
- package/dist/index.d.ts +2 -2
- package/dist/polygonFns.d.ts +31 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# brepjs-sheetmetal
|
|
2
2
|
|
|
3
|
-
> Experimental,
|
|
3
|
+
> Experimental satellite package, published to npm. Early-stage — the API may change.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install brepjs-sheetmetal
|
|
7
|
+
```
|
|
4
8
|
|
|
5
9
|
A sheet-metal CAD domain for [brepjs](https://github.com/andymai/brepjs). It authors parametric
|
|
6
10
|
sheet-metal parts (flange/bend features), auto-miters corners, folds to 3D, and unfolds to a flat
|
|
@@ -6135,6 +6135,68 @@ function wireToPolygon(outline) {
|
|
|
6135
6135
|
if (poly.length < 3) return (0, brepjs.err)((0, brepjs.validationError)("EMPTY_OUTLINE", "outline polygon has fewer than 3 vertices"));
|
|
6136
6136
|
return (0, brepjs.ok)(poly);
|
|
6137
6137
|
}
|
|
6138
|
+
/**
|
|
6139
|
+
* Read a wire as an OPEN polyline: every edge start plus the final edge's end,
|
|
6140
|
+
* so the last vertex of a non-closing path (a form cut) isn't dropped the way
|
|
6141
|
+
* {@link wireToPolygon} drops it for closed loops.
|
|
6142
|
+
*
|
|
6143
|
+
* Arc edges are linearised to their endpoints — the same assumption
|
|
6144
|
+
* {@link wireToPolygon} and the DXF writer make. Form cuts are straight-sided
|
|
6145
|
+
* today (louver/lance slits), so this is exact; a future curved form-feature cut
|
|
6146
|
+
* would render as straight chords in the overlay until arc tessellation is added.
|
|
6147
|
+
*/
|
|
6148
|
+
function wireToOpenPolyline(wire) {
|
|
6149
|
+
const edges = (0, brepjs.getEdges)(wire);
|
|
6150
|
+
if (edges.length === 0) return [];
|
|
6151
|
+
const pts = edges.map((edge) => {
|
|
6152
|
+
const p = (0, brepjs.curveStartPoint)(edge);
|
|
6153
|
+
return [p[0], p[1]];
|
|
6154
|
+
});
|
|
6155
|
+
const lastEdge = edges[edges.length - 1];
|
|
6156
|
+
if (lastEdge) {
|
|
6157
|
+
const e = (0, brepjs.curveEndPoint)(lastEdge);
|
|
6158
|
+
pts.push([e[0], e[1]]);
|
|
6159
|
+
}
|
|
6160
|
+
return pts;
|
|
6161
|
+
}
|
|
6162
|
+
/**
|
|
6163
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
6164
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
6165
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
6166
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
6167
|
+
* and the DXF writer make.
|
|
6168
|
+
*/
|
|
6169
|
+
function flatPatternToPolylines(pattern) {
|
|
6170
|
+
const outlineResult = wireToPolygon(pattern.outline);
|
|
6171
|
+
const outline = (0, brepjs.isOk)(outlineResult) ? outlineResult.value : [];
|
|
6172
|
+
const holes = [];
|
|
6173
|
+
for (const hole of pattern.holes) {
|
|
6174
|
+
const holeResult = wireToPolygon(hole);
|
|
6175
|
+
if ((0, brepjs.isOk)(holeResult)) holes.push(holeResult.value);
|
|
6176
|
+
}
|
|
6177
|
+
return {
|
|
6178
|
+
outline,
|
|
6179
|
+
holes,
|
|
6180
|
+
bendLines: pattern.bendLines.map((bend) => {
|
|
6181
|
+
const start = (0, brepjs.curveStartPoint)(bend.line);
|
|
6182
|
+
const end = (0, brepjs.curveEndPoint)(bend.line);
|
|
6183
|
+
return {
|
|
6184
|
+
from: [start[0], start[1]],
|
|
6185
|
+
to: [end[0], end[1]],
|
|
6186
|
+
direction: bend.direction
|
|
6187
|
+
};
|
|
6188
|
+
}),
|
|
6189
|
+
formCuts: pattern.formCuts.map(wireToOpenPolyline).filter((p) => p.length >= 2),
|
|
6190
|
+
formHinges: pattern.formHinges.map((hinge) => {
|
|
6191
|
+
const start = (0, brepjs.curveStartPoint)(hinge);
|
|
6192
|
+
const end = (0, brepjs.curveEndPoint)(hinge);
|
|
6193
|
+
return {
|
|
6194
|
+
from: [start[0], start[1]],
|
|
6195
|
+
to: [end[0], end[1]]
|
|
6196
|
+
};
|
|
6197
|
+
})
|
|
6198
|
+
};
|
|
6199
|
+
}
|
|
6138
6200
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
6139
6201
|
function signedArea(poly) {
|
|
6140
6202
|
let a = 0;
|
|
@@ -7271,6 +7333,7 @@ exports.emboss = emboss;
|
|
|
7271
7333
|
exports.featureTree = featureTree;
|
|
7272
7334
|
exports.fitCylinder = fitCylinder;
|
|
7273
7335
|
exports.flatPatternToDXF = flatPatternToDXF;
|
|
7336
|
+
exports.flatPatternToPolylines = flatPatternToPolylines;
|
|
7274
7337
|
exports.fold = fold;
|
|
7275
7338
|
exports.foldFlat = foldFlat;
|
|
7276
7339
|
exports.foldPart = fold$1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { box, curveEndPoint, curveStartPoint, cut, cylinder, err, extrude, face, faceCenter, fuse, getBounds, getEdges, getFaces, getSolids, getSurfaceType, intersect, isErr, isPlanarWire, isSolid, isValid, line, measureArea, measureVolume, normalAt, ok, pointOnSurface, rotate, sharedEdges, translate, validationError, vecAdd, vecCross, vecDot, vecLength, vecNormalize, vecScale, vecSub, wire, wireLoop } from "brepjs";
|
|
1
|
+
import { box, curveEndPoint, curveStartPoint, cut, cylinder, err, extrude, face, faceCenter, fuse, getBounds, getEdges, getFaces, getSolids, getSurfaceType, intersect, isErr, isOk, isPlanarWire, isSolid, isValid, line, measureArea, measureVolume, normalAt, ok, pointOnSurface, rotate, sharedEdges, translate, validationError, vecAdd, vecCross, vecDot, vecLength, vecNormalize, vecScale, vecSub, wire, wireLoop } from "brepjs";
|
|
2
2
|
//#region src/materials.ts
|
|
3
3
|
var DEFAULT_K_FACTOR = .44;
|
|
4
4
|
function gauge(name, thickness, kFactor = DEFAULT_K_FACTOR) {
|
|
@@ -6134,6 +6134,68 @@ function wireToPolygon(outline) {
|
|
|
6134
6134
|
if (poly.length < 3) return err(validationError("EMPTY_OUTLINE", "outline polygon has fewer than 3 vertices"));
|
|
6135
6135
|
return ok(poly);
|
|
6136
6136
|
}
|
|
6137
|
+
/**
|
|
6138
|
+
* Read a wire as an OPEN polyline: every edge start plus the final edge's end,
|
|
6139
|
+
* so the last vertex of a non-closing path (a form cut) isn't dropped the way
|
|
6140
|
+
* {@link wireToPolygon} drops it for closed loops.
|
|
6141
|
+
*
|
|
6142
|
+
* Arc edges are linearised to their endpoints — the same assumption
|
|
6143
|
+
* {@link wireToPolygon} and the DXF writer make. Form cuts are straight-sided
|
|
6144
|
+
* today (louver/lance slits), so this is exact; a future curved form-feature cut
|
|
6145
|
+
* would render as straight chords in the overlay until arc tessellation is added.
|
|
6146
|
+
*/
|
|
6147
|
+
function wireToOpenPolyline(wire) {
|
|
6148
|
+
const edges = getEdges(wire);
|
|
6149
|
+
if (edges.length === 0) return [];
|
|
6150
|
+
const pts = edges.map((edge) => {
|
|
6151
|
+
const p = curveStartPoint(edge);
|
|
6152
|
+
return [p[0], p[1]];
|
|
6153
|
+
});
|
|
6154
|
+
const lastEdge = edges[edges.length - 1];
|
|
6155
|
+
if (lastEdge) {
|
|
6156
|
+
const e = curveEndPoint(lastEdge);
|
|
6157
|
+
pts.push([e[0], e[1]]);
|
|
6158
|
+
}
|
|
6159
|
+
return pts;
|
|
6160
|
+
}
|
|
6161
|
+
/**
|
|
6162
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
6163
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
6164
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
6165
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
6166
|
+
* and the DXF writer make.
|
|
6167
|
+
*/
|
|
6168
|
+
function flatPatternToPolylines(pattern) {
|
|
6169
|
+
const outlineResult = wireToPolygon(pattern.outline);
|
|
6170
|
+
const outline = isOk(outlineResult) ? outlineResult.value : [];
|
|
6171
|
+
const holes = [];
|
|
6172
|
+
for (const hole of pattern.holes) {
|
|
6173
|
+
const holeResult = wireToPolygon(hole);
|
|
6174
|
+
if (isOk(holeResult)) holes.push(holeResult.value);
|
|
6175
|
+
}
|
|
6176
|
+
return {
|
|
6177
|
+
outline,
|
|
6178
|
+
holes,
|
|
6179
|
+
bendLines: pattern.bendLines.map((bend) => {
|
|
6180
|
+
const start = curveStartPoint(bend.line);
|
|
6181
|
+
const end = curveEndPoint(bend.line);
|
|
6182
|
+
return {
|
|
6183
|
+
from: [start[0], start[1]],
|
|
6184
|
+
to: [end[0], end[1]],
|
|
6185
|
+
direction: bend.direction
|
|
6186
|
+
};
|
|
6187
|
+
}),
|
|
6188
|
+
formCuts: pattern.formCuts.map(wireToOpenPolyline).filter((p) => p.length >= 2),
|
|
6189
|
+
formHinges: pattern.formHinges.map((hinge) => {
|
|
6190
|
+
const start = curveStartPoint(hinge);
|
|
6191
|
+
const end = curveEndPoint(hinge);
|
|
6192
|
+
return {
|
|
6193
|
+
from: [start[0], start[1]],
|
|
6194
|
+
to: [end[0], end[1]]
|
|
6195
|
+
};
|
|
6196
|
+
})
|
|
6197
|
+
};
|
|
6198
|
+
}
|
|
6137
6199
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
6138
6200
|
function signedArea(poly) {
|
|
6139
6201
|
let a = 0;
|
|
@@ -7230,4 +7292,4 @@ function fromSolid(solid, opts) {
|
|
|
7230
7292
|
return new ForeignSolidHandle(solid, opts);
|
|
7231
7293
|
}
|
|
7232
7294
|
//#endregion
|
|
7233
|
-
export { ALUMINUM_GAUGES, DEFAULT_K_FACTOR, ForeignSolidHandle, MATERIALS, ROOT_FLAT_ID, STEEL_GAUGES, SheetMetalBuilder, SheetMetalError, SheetMetalPartHandle, addBendRelief, addBendTable, addCutout, addForm, addHole, addPolygonCutout, addSlot, addTab, allowance, author, authorContourFlange, authorLoftedFlange, authorPart, autoBendReliefs, autoMiterCorner, autoReliefs, baseEdgeRef, bendAllowance, bendRelief, bendTable, buildFeatureGraph, buildFeatureTree, buildReport, contourFlange, cornerRelief, developed, developedLength, emboss, featureTree, fitCylinder, flatPatternToDXF, fold, foldFlat, fold$1 as foldPart, foldWithWarnings, fromPart, fromSolid, getBendTable, getMaterial, hem, jog, loftedFlange, louver, miter, miterCorner, miterCut, multiPatternToDXF, nest, nestToDXF, neutralRadius, partToFlatInput, patternBbox, patternToFlatInput, pointInPolygon, polygonBounds, polygonsOverlap, polygonsOverlapWithClearance, registerBendTable, relieveCorner, report, reportFrom, reportFromUnfold, reportJSON, reportToJSON, resolveAllowance, resolveBendAllowance, segmentsIntersect, sheetMetal, signedArea, tabAndSlot, toDXF, transformPolygon, unfold, unfoldForeignSolid, unfold$1 as unfoldPart, unfoldSolid, validate, validatePart, wireToPolygon };
|
|
7295
|
+
export { ALUMINUM_GAUGES, DEFAULT_K_FACTOR, ForeignSolidHandle, MATERIALS, ROOT_FLAT_ID, STEEL_GAUGES, SheetMetalBuilder, SheetMetalError, SheetMetalPartHandle, addBendRelief, addBendTable, addCutout, addForm, addHole, addPolygonCutout, addSlot, addTab, allowance, author, authorContourFlange, authorLoftedFlange, authorPart, autoBendReliefs, autoMiterCorner, autoReliefs, baseEdgeRef, bendAllowance, bendRelief, bendTable, buildFeatureGraph, buildFeatureTree, buildReport, contourFlange, cornerRelief, developed, developedLength, emboss, featureTree, fitCylinder, flatPatternToDXF, flatPatternToPolylines, fold, foldFlat, fold$1 as foldPart, foldWithWarnings, fromPart, fromSolid, getBendTable, getMaterial, hem, jog, loftedFlange, louver, miter, miterCorner, miterCut, multiPatternToDXF, nest, nestToDXF, neutralRadius, partToFlatInput, patternBbox, patternToFlatInput, pointInPolygon, polygonBounds, polygonsOverlap, polygonsOverlapWithClearance, registerBendTable, relieveCorner, report, reportFrom, reportFromUnfold, reportJSON, reportToJSON, resolveAllowance, resolveBendAllowance, segmentsIntersect, sheetMetal, signedArea, tabAndSlot, toDXF, transformPolygon, unfold, unfoldForeignSolid, unfold$1 as unfoldPart, unfoldSolid, validate, validatePart, wireToPolygon };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,8 +26,8 @@ export { flatPatternToDXF, multiPatternToDXF } from './dxfFns.js';
|
|
|
26
26
|
export type { DxfOptions, PlacedPattern, Transform2 } from './dxfFns.js';
|
|
27
27
|
export { patternBbox } from './nestFns.js';
|
|
28
28
|
export type { NestOptions, NestResult, NestSheet, Placement, SheetSpec, Bbox, } from './nestFns.js';
|
|
29
|
-
export { wireToPolygon, polygonsOverlap, polygonsOverlapWithClearance, segmentsIntersect, pointInPolygon, transformPolygon, polygonBounds, signedArea, } from './polygonFns.js';
|
|
30
|
-
export type { Polygon, Pt2 } from './polygonFns.js';
|
|
29
|
+
export { wireToPolygon, flatPatternToPolylines, polygonsOverlap, polygonsOverlapWithClearance, segmentsIntersect, pointInPolygon, transformPolygon, polygonBounds, signedArea, } from './polygonFns.js';
|
|
30
|
+
export type { Polygon, Pt2, FlatPatternPolylines, FlatPatternBendLine, } from './polygonFns.js';
|
|
31
31
|
export { buildReport, reportFromUnfold, reportToJSON } from './reportFns.js';
|
|
32
32
|
export { validatePart } from './validateFns.js';
|
|
33
33
|
export { author, unfold as unfoldPart, unfoldSolid, fold as foldPart, miter, miterCorner, bendRelief, autoReliefs, relieveCorner, toDXF, report, reportFrom, reportJSON, validate, allowance, developed, addBendTable, bendTable, resolveAllowance, contourFlange, loftedFlange, nest, nestToDXF, } from './api.js';
|
package/dist/polygonFns.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Result, Wire } from 'brepjs';
|
|
2
|
+
import { FlatPattern } from './types.js';
|
|
2
3
|
export type Pt2 = [number, number];
|
|
3
4
|
/** A simple (non-self-intersecting) polygon as an ordered, non-closing vertex loop. */
|
|
4
5
|
export type Polygon = Pt2[];
|
|
@@ -9,6 +10,36 @@ export type Polygon = Pt2[];
|
|
|
9
10
|
* `v[i] → v[(i+1) % n]`.
|
|
10
11
|
*/
|
|
11
12
|
export declare function wireToPolygon(outline: Wire): Result<Polygon>;
|
|
13
|
+
/** A bend line in the developed plane: a segment plus its fold direction. */
|
|
14
|
+
export interface FlatPatternBendLine {
|
|
15
|
+
from: Pt2;
|
|
16
|
+
to: Pt2;
|
|
17
|
+
direction: 'up' | 'down';
|
|
18
|
+
}
|
|
19
|
+
/** A flat pattern reduced to serializable 2D polylines for a developed-view overlay. */
|
|
20
|
+
export interface FlatPatternPolylines {
|
|
21
|
+
/** Closed outer boundary as an ordered, non-closing vertex loop. */
|
|
22
|
+
outline: Polygon;
|
|
23
|
+
/** Interior cutout loops (holes / slots / polygon cutouts). */
|
|
24
|
+
holes: Polygon[];
|
|
25
|
+
/** Bend lines, each with its fold direction. */
|
|
26
|
+
bendLines: FlatPatternBendLine[];
|
|
27
|
+
/** Open form-feature cut paths in the blank (e.g. louver/lance three-sided cuts). */
|
|
28
|
+
formCuts: Polygon[];
|
|
29
|
+
/** Form-feature hinge lines (the uncut fold edge a louver/lance forms up along). */
|
|
30
|
+
formHinges: {
|
|
31
|
+
from: Pt2;
|
|
32
|
+
to: Pt2;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
37
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
38
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
39
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
40
|
+
* and the DXF writer make.
|
|
41
|
+
*/
|
|
42
|
+
export declare function flatPatternToPolylines(pattern: FlatPattern): FlatPatternPolylines;
|
|
12
43
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
13
44
|
export declare function signedArea(poly: Polygon): number;
|
|
14
45
|
/** Axis-aligned bounds `[minX, minY, maxX, maxY]` of a polygon. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brepjs-sheetmetal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Sheet-metal CAD domain for brepjs — flange authoring, auto-miter, fold/unfold flat patterns",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sheet-metal",
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
],
|
|
13
13
|
"author": "Andy Aragon",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/andymai/brepjs",
|
|
18
|
+
"directory": "packages/brepjs-sheetmetal"
|
|
19
|
+
},
|
|
15
20
|
"type": "module",
|
|
16
21
|
"sideEffects": false,
|
|
17
22
|
"engines": {
|