From 54dc1b47d29f44cf91da5a844f613202aeea500c Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 24 Jun 2022 14:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E5=B9=B2=E6=B6=89=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfere/__snapshots__/intf.test.ts.snap | 11 +++++++++ __test__/Interfere/intf.test.ts | 23 +++++++++++++++++++ src/DatabaseServices/Entity/Polyline.ts | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 __test__/Interfere/__snapshots__/intf.test.ts.snap create mode 100644 __test__/Interfere/intf.test.ts diff --git a/__test__/Interfere/__snapshots__/intf.test.ts.snap b/__test__/Interfere/__snapshots__/intf.test.ts.snap new file mode 100644 index 000000000..620dcdd20 --- /dev/null +++ b/__test__/Interfere/__snapshots__/intf.test.ts.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`求交集错误 1`] = `2`; + +exports[`求交集错误 2`] = `1`; + +exports[`求交集错误 3`] = `"7704.00000"`; + +exports[`求交集错误 4`] = `"5771.53229"`; + +exports[`求交集错误 5`] = `"0.00000"`; diff --git a/__test__/Interfere/intf.test.ts b/__test__/Interfere/intf.test.ts new file mode 100644 index 000000000..d3026bade --- /dev/null +++ b/__test__/Interfere/intf.test.ts @@ -0,0 +1,23 @@ +import { Polyline } from "../../src/api"; +import { Contour } from "../../src/DatabaseServices/Contour"; +import "../Utils/jest.util"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; + +test('求交集错误', () => +{ + let d = [2, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [9.094947017729282e-12, -1411.0000000000002], 0, [9.094947017729282e-12, 2423], 0, [-17.999999999990905, 2423], 0, [-17.999999999990905, -1411.0000000000002], 0, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 2, 8, [540, 0], 0, [540, 102], 0, [552, 102], 0, [561, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [0, 0], 0, true]; + + let pls = LoadEntityFromFileData(d) as Polyline[]; + + let cons = pls.map(pl => Contour.CreateContour(pl)); + + let res = cons[0].GetIntersetAndUnionList(cons[1]); + + expect(res.unionList.length).toMatchSnapshot(); + expect(res.intersectionList.length).toMatchSnapshot(); + + for (let c of res.unionList) + expect(c.Length).toMatchNumberSnapshot(); + for (let c of res.intersectionList) + expect(c.Length).toMatchNumberSnapshot(); +}); diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index 390b85880..5cd709806 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -547,6 +547,8 @@ export class Polyline extends Curve } GetParamAtDist(dist: number): number { + if (equaln(dist, 0)) return 0; + let cus = this.Explode(); for (let i = 0; i < cus.length; i++) {