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++) {