brepjs-sheetmetal 0.1.0 → 0.2.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 +30 -0
- package/dist/brepjs-sheetmetal.js +31 -2
- package/dist/index.d.ts +2 -2
- package/dist/polygonFns.d.ts +24 -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,35 @@ 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
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
6140
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
6141
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
6142
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
6143
|
+
* and the DXF writer make.
|
|
6144
|
+
*/
|
|
6145
|
+
function flatPatternToPolylines(pattern) {
|
|
6146
|
+
const outlineResult = wireToPolygon(pattern.outline);
|
|
6147
|
+
const outline = (0, brepjs.isOk)(outlineResult) ? outlineResult.value : [];
|
|
6148
|
+
const holes = [];
|
|
6149
|
+
for (const hole of pattern.holes) {
|
|
6150
|
+
const holeResult = wireToPolygon(hole);
|
|
6151
|
+
if ((0, brepjs.isOk)(holeResult)) holes.push(holeResult.value);
|
|
6152
|
+
}
|
|
6153
|
+
return {
|
|
6154
|
+
outline,
|
|
6155
|
+
holes,
|
|
6156
|
+
bendLines: pattern.bendLines.map((bend) => {
|
|
6157
|
+
const start = (0, brepjs.curveStartPoint)(bend.line);
|
|
6158
|
+
const end = (0, brepjs.curveEndPoint)(bend.line);
|
|
6159
|
+
return {
|
|
6160
|
+
from: [start[0], start[1]],
|
|
6161
|
+
to: [end[0], end[1]],
|
|
6162
|
+
direction: bend.direction
|
|
6163
|
+
};
|
|
6164
|
+
})
|
|
6165
|
+
};
|
|
6166
|
+
}
|
|
6138
6167
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
6139
6168
|
function signedArea(poly) {
|
|
6140
6169
|
let a = 0;
|
|
@@ -7271,6 +7300,7 @@ exports.emboss = emboss;
|
|
|
7271
7300
|
exports.featureTree = featureTree;
|
|
7272
7301
|
exports.fitCylinder = fitCylinder;
|
|
7273
7302
|
exports.flatPatternToDXF = flatPatternToDXF;
|
|
7303
|
+
exports.flatPatternToPolylines = flatPatternToPolylines;
|
|
7274
7304
|
exports.fold = fold;
|
|
7275
7305
|
exports.foldFlat = foldFlat;
|
|
7276
7306
|
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,35 @@ 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
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
6139
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
6140
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
6141
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
6142
|
+
* and the DXF writer make.
|
|
6143
|
+
*/
|
|
6144
|
+
function flatPatternToPolylines(pattern) {
|
|
6145
|
+
const outlineResult = wireToPolygon(pattern.outline);
|
|
6146
|
+
const outline = isOk(outlineResult) ? outlineResult.value : [];
|
|
6147
|
+
const holes = [];
|
|
6148
|
+
for (const hole of pattern.holes) {
|
|
6149
|
+
const holeResult = wireToPolygon(hole);
|
|
6150
|
+
if (isOk(holeResult)) holes.push(holeResult.value);
|
|
6151
|
+
}
|
|
6152
|
+
return {
|
|
6153
|
+
outline,
|
|
6154
|
+
holes,
|
|
6155
|
+
bendLines: pattern.bendLines.map((bend) => {
|
|
6156
|
+
const start = curveStartPoint(bend.line);
|
|
6157
|
+
const end = curveEndPoint(bend.line);
|
|
6158
|
+
return {
|
|
6159
|
+
from: [start[0], start[1]],
|
|
6160
|
+
to: [end[0], end[1]],
|
|
6161
|
+
direction: bend.direction
|
|
6162
|
+
};
|
|
6163
|
+
})
|
|
6164
|
+
};
|
|
6165
|
+
}
|
|
6137
6166
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
6138
6167
|
function signedArea(poly) {
|
|
6139
6168
|
let a = 0;
|
|
@@ -7230,4 +7259,4 @@ function fromSolid(solid, opts) {
|
|
|
7230
7259
|
return new ForeignSolidHandle(solid, opts);
|
|
7231
7260
|
}
|
|
7232
7261
|
//#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 };
|
|
7262
|
+
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,29 @@ 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
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reduce a {@link FlatPattern} to serializable 2D polylines (outline, holes, bend
|
|
30
|
+
* lines) for a developed-pattern overlay. Best-effort: a wire that fails to read
|
|
31
|
+
* is dropped rather than throwing, so a partial pattern still yields what it can.
|
|
32
|
+
* Arc edges are approximated by endpoints, the same assumption {@link wireToPolygon}
|
|
33
|
+
* and the DXF writer make.
|
|
34
|
+
*/
|
|
35
|
+
export declare function flatPatternToPolylines(pattern: FlatPattern): FlatPatternPolylines;
|
|
12
36
|
/** Signed area (CCW positive) — used to normalise orientation and reject degenerates. */
|
|
13
37
|
export declare function signedArea(poly: Polygon): number;
|
|
14
38
|
/** 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.2.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": {
|