Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 76dcf4d

Browse files
committed
Update nesting stuffs.
1 parent 6c116f7 commit 76dcf4d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/nesting.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ function nestOne(
262262
};
263263
}
264264

265-
export function nest(nesting: Nesting, notNestedDesignDocumentParts: DesignDocumentPart[], raster: boolean) {
265+
export function nest(
266+
nesting: Nesting,
267+
notNestedDesignDocumentParts: DesignDocumentPart[],
268+
raster: boolean,
269+
): { allNestedParts: Part[]; newlyNestedDesignDocumentParts: DesignDocumentPart[] } {
266270
let newlyNestedDesignDocumentParts: DesignDocumentPart[] = [];
267271

268272
const [sheetWidth, sheetHeight] = [nesting.sheetWidth, nesting.sheetHeight];

src/server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createServer } from "http";
44
import moment from "moment";
55
import { noFitPolygon, rasterDifference } from "./nfp";
66
import { time, toFormattedDateTimeString } from "./utils";
7+
import { nest } from "./nesting";
78

89
export function listen(port: number) {
910
const app = express();
@@ -53,6 +54,20 @@ export function listen(port: number) {
5354
return res.json(result.map((dot: any) => ({ X: dot[0], Y: dot[1] })));
5455
});
5556

57+
app.post(`/rest/nest`, async (req, res) => {
58+
const { nestingJson, notNestedDesignDocumentPartsJson, raster } = req.body;
59+
60+
const nesting = JSON.parse(nestingJson as any);
61+
const notNestedDesignDocumentParts = JSON.parse(notNestedDesignDocumentPartsJson as any);
62+
63+
const result = time(
64+
(result) => `nest`,
65+
() => nest(nesting, notNestedDesignDocumentParts, raster),
66+
);
67+
68+
return res.json(result);
69+
});
70+
5671
const server = createServer(app);
5772

5873
server.listen(port, () => {

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function toFormattedDateTimeString(moment: Moment): string {
44
return moment.format("YYYY-MM-DD HH:mm:ss");
55
}
66

7-
export function time(name: (result: any) => string, func: () => any) {
7+
export function time<T>(name: (result: T) => string, func: () => T): T {
88
const start = new Date().getTime();
99

1010
const result = func();

0 commit comments

Comments
 (0)