From e4d565dda293c443ae6d7911e4e1d3a939b7ada8 Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 8 Dec 2023 17:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91:=E5=A2=9E=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Nest/__snapshots__/nest.test.ts.snap | 47 +++++++++ __test__/Nest/nest.test.ts | 99 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 __test__/Nest/__snapshots__/nest.test.ts.snap create mode 100644 __test__/Nest/nest.test.ts diff --git a/__test__/Nest/__snapshots__/nest.test.ts.snap b/__test__/Nest/__snapshots__/nest.test.ts.snap new file mode 100644 index 000000000..d3defb91f --- /dev/null +++ b/__test__/Nest/__snapshots__/nest.test.ts.snap @@ -0,0 +1,47 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`异形优化测试 1`] = ` +Array [ + 1, + 1.959058347014103, + 2, + -1, + 0, + undefined, + 1, + 0, + 0, + Object { + "x": 0, + "y": 0, + }, + Array [ + 0, + 0, + ], + Array [ + 94, + 94, + ], + -1, + 0, + undefined, + 1, + 1, + 0, + Object { + "x": 0, + "y": 0, + }, + Array [ + 0, + 0, + ], + Array [ + 1194, + 2394, + ], + 0, + 0, +] +`; diff --git a/__test__/Nest/nest.test.ts b/__test__/Nest/nest.test.ts new file mode 100644 index 000000000..34b8bae9f --- /dev/null +++ b/__test__/Nest/nest.test.ts @@ -0,0 +1,99 @@ +import { Circle } from "../../src/DatabaseServices/Entity/Circle"; +import { Polyline } from "../../src/DatabaseServices/Entity/Polyline"; +import { InitClipperCpp } from "../../src/Nest/Common/ClipperCpp"; +import { NestFiler } from "../../src/Nest/Common/Filer"; +import { CurveWrap } from "../../src/Nest/Converter/CurveWrap"; +import { Circle2Points } from "../../src/Nest/Converter/Curves2Points"; +import { DefaultBin } from "../../src/Nest/Core/DefaultBin"; +import { Individual } from "../../src/Nest/Core/Individual"; +import { NestCache } from "../../src/Nest/Core/NestCache"; +import { DefaultComparePointKeys, NestDatabase } from "../../src/Nest/Core/NestDatabase"; +import { OptimizeMachine } from "../../src/Nest/Core/OptimizeMachine"; +import { Part } from "../../src/Nest/Core/Part"; +import { Path } from "../../src/Nest/Core/Path"; +import { PathGeneratorSingle } from "../../src/Nest/Core/PathGenerator"; + +//@ts-ignore +globalThis.document = {}; + +export function Curve2Path(curve: Circle | Polyline, outside = false): Path +{ + if (curve.IsClockWise) + curve.Reverse(); + if (curve instanceof Circle) + { + return new Path(Circle2Points(curve, 0, 10, outside), 3); + } + else + { + let w = new CurveWrap(curve, 3, outside); + return new Path(outside ? w.GetOutsidePoints() : w.GetInsidePoints()); + } +} + +test('异形优化测试', async () => +{ + await InitClipperCpp(); + + PathGeneratorSingle.Clear(); + NestCache.Clear(); + DefaultBin.InsideNFPCache = {}; + + let binPath = DefaultBin; + binPath.Id = undefined; + PathGeneratorSingle.RegisterId(binPath); + + let path = Curve2Path(new Polyline().Rectangle(100, 100)); + let part1 = new Part().Init(path, binPath); + + let path2 = Curve2Path(new Polyline().Rectangle(1200, 2400)); + let part2 = new Part().Init(path2, binPath); + + part1.IsPrePlace = true; + part2.IsPrePlace = false; + + let parts = [part1, part2]; + + parts.forEach((p, i) => p.Id = i); + + let db = new NestDatabase(); + db.Paths = PathGeneratorSingle.paths; + db.Parts = parts; + db.Bin = DefaultBin; + db.OddmentsBins = []; + db.ComparePointKeys = DefaultComparePointKeys; + + let f = new NestFiler(); + db.WriteFile(f); + + db = new NestDatabase; + db.ReadFile(f); + + let m = new OptimizeMachine; + m.Bin = db.Bin; + m.OddmentsBins = db.OddmentsBins; + + + m.PutParts(db.Parts); + + let promise = new Promise((res, rej) => + { + m.callBack = async (inv) => + { + m.Suspend(); + + let f = new NestFiler; + inv.WriteFile(f); + expect(f._datas).toMatchSnapshot(); + + let inv2 = new Individual(db.Parts); + inv2.ReadFile(f); + + res(); + }; + }); + + m.Start(); + + await promise; +});