From 6e386d7d7d5b5b5f9fd7d70b96a40d13f8ace04b Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 4 Jul 2022 09:47:32 +0000 Subject: [PATCH] =?UTF-8?q?!1962=20=E4=BF=AE=E5=A4=8D:=E5=B8=83=E5=B0=94?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=B9=B2=E6=B6=89=E6=A3=80=E6=9F=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Booloperate/more_sub.test.ts | 18 ++++++++++++++++++ src/DatabaseServices/Contour.ts | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 __test__/Booloperate/more_sub.test.ts diff --git a/__test__/Booloperate/more_sub.test.ts b/__test__/Booloperate/more_sub.test.ts new file mode 100644 index 000000000..fe8588f68 --- /dev/null +++ b/__test__/Booloperate/more_sub.test.ts @@ -0,0 +1,18 @@ +import { Polyline } from "../../src/api"; +import { Contour } from "../../src/DatabaseServices/Contour"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; + +test('多个布尔错误', () => +{ + let d = + [2, "Polyline", 8, 2, 0, false, 0, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 142, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 8, [942, -142], 0, [942, 202], 0, [430, 202], 0, [430.0000000000002, 18], 0, [430.0000000000002, 18], 0, [430.0000000000002, 0], 0, [0, 0], 0, [0, -142], 0, true, "Polyline", 8, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 142, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 142, 0, 1], 0, 2, 4, [0, 0], 0, [698, 0], 0, [698, 18], 0, [0, 18], 0, true]; + + let pls = LoadEntityFromFileData(d) as Polyline[]; + + let cons = pls.map(pl => Contour.CreateContour(pl)); + + let res = cons[0].GetSubtractListByMoreTargets(cons.slice(1)); + + expect(res.outlines.length).toBe(1); + expect(res.holes.length).toBe(0); +}); diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index eccebf47a..3b76d0d56 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -603,12 +603,12 @@ function fastEqualCurve(c1: Curve, c2: Curve, tolerance = 1e-3) //也许有一天这个中点算法需要改一下, 使用.MidPoint比较稳妥 function fastCurveInCurve(sourceCu: Polyline | Circle, targetCu: Curve) { - return sourceCu.PtInCurve(targetCu.GetPointAtParam(targetCu.EndParam * 0.5)); + return sourceCu.PtInCurve(targetCu.Midpoint); } //当交点小于等于1时 export function fastCurveInCurve2(sourceCu: Polyline | Circle, targetCu: Curve) { return sourceCu.PtInCurve(targetCu.StartPoint) || - sourceCu.PtInCurve(targetCu.GetPointAtParam(targetCu.EndParam * 0.5)); + sourceCu.PtInCurve(targetCu.Midpoint); }