From 583bbfdf37534482c3058ef370179c289627f9cb Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 9 Sep 2019 09:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=9D=A2=E5=9F=9F=E6=B1=82?= =?UTF-8?q?=E4=BA=A4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Booloperate/__snapshots__/bool4.test.ts.snap | 2 ++ __test__/Booloperate/bool4.test.ts | 11 +++++++++++ src/DatabaseServices/Contour.ts | 11 ++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/__test__/Booloperate/__snapshots__/bool4.test.ts.snap b/__test__/Booloperate/__snapshots__/bool4.test.ts.snap index 733722f48..5d7882de0 100644 --- a/__test__/Booloperate/__snapshots__/bool4.test.ts.snap +++ b/__test__/Booloperate/__snapshots__/bool4.test.ts.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`#I118PO 1`] = `6298.780447492156`; + exports[`交点大于等于2_但是还是分离 1`] = `310430.5057844047`; exports[`交点大于等于2_但是还是分离 2`] = `40090.549687200226`; diff --git a/__test__/Booloperate/bool4.test.ts b/__test__/Booloperate/bool4.test.ts index e67c54991..06928fc4d 100644 --- a/__test__/Booloperate/bool4.test.ts +++ b/__test__/Booloperate/bool4.test.ts @@ -16,3 +16,14 @@ test('交点大于等于2_但是还是分离', () => reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Subtract); expect(reg.Area).toMatchSnapshot(); }); + +test(`#I118PO`, () => +{ + let d = [2, "Region", 5, 2, 109, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 4, [0, 0], 0, [349.99999999999983, 0], 0, [349.99999999999983, 18], 0, [0, 18], 0, true, 0, "Region", 5, 2, 110, false, 1, 7, 0, [-0.6481962787933795, -0.7614732983883384, -3.969057490217688e-17, 0, 0.7614732983883384, -0.6481962787933795, 4.66267918753728e-17, 0, 6.123233995736766e-17, 0, -1, 0, -507.79108398045344, 1098.4374795109752, -4.082417520817821e-14, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [-0.6481962787933795, -0.7614732983883384, -3.969057490217688e-17, 0, -0.7614732983883384, 0.6481962787933795, -4.66267918753728e-17, 0, 6.123233995736766e-17, 0, -1, 0, -507.79108398045344, 1098.4374795109752, -4.082417520817821e-14, 1], 0, 0, 2, 4, [9.993381848422814, -884.0586414166524], 0.17863084838388266, [280.4138219783257, -1365.1880927528969], 0, [507.2825195560087, -1098.6724383169787], -0.09662306706998787, [400.5809327775901, -964.8005274526736], 0, true, 0]; + let [reg1, reg2] = LoadRegionsFromFileData(d); + + let reg = reg1.Clone(); + reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Intersection); + expect(reg.ShapeManager.ShapeCount).toBe(1); + expect(reg.Area).toMatchSnapshot(); +}) diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index 60f2d0386..4ac16f9be 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -1,4 +1,3 @@ -import * as THREE from "three"; import { Vector3 } from "three"; import { arrayLast, arrayRemoveDuplicateBySort, arrayRemoveIf } from "../Common/ArrayExt"; import { curveLinkGroup, equalCurve } from "../Common/CurveUtils"; @@ -185,10 +184,8 @@ export class Contour } /** * 计算与目标轮廓布尔运算后的结果曲线. - * @param {Contour} target 目标轮廓 - * @returns {intersectionList //交集曲线表, unionList //并集曲线表} */ - GetIntersetAndUnionList(target: Contour) + GetIntersetAndUnionList(target: Contour): { intersectionList: Curve[], unionList: Curve[] } { let intersectionList: Curve[] = []; let unionList: Curve[] = []; @@ -232,7 +229,7 @@ export class Contour { //在目标分离曲线数组从若有相等的曲线,且相等的线段不连接2区域,则直接加入合并和相交集合中 //在目标数组中就直接跳过不在添加,在2轮廓有共线部分时需此判断 - hasEqualCus = targetCus.some(l => equalCurve(pl, l)); + hasEqualCus = targetCus.some(l => fastEqualCurve(pl, l)); if (hasEqualCus) { //获得共有线段中点2侧的点,判断是否有存在2区域外的点 @@ -260,7 +257,7 @@ export class Contour for (let pl of targetCus) { - let hasEqualCus = sourceCus.some(l => equalCurve(pl, l)); + let hasEqualCus = sourceCus.some(l => fastEqualCurve(pl, l)); if (hasEqualCus && disLink) { continue; @@ -421,7 +418,7 @@ export class Contour /** * 对于轮廓切割后的曲线判断相同,使用这个函数进行快速判断 */ -function fastEqualCurve(c1: Polyline, c2: Polyline, tolerance = 1e-3) +function fastEqualCurve(c1: Curve, c2: Curve, tolerance = 1e-3) { let sp1 = c1.StartPoint; let ep1 = c1.EndPoint;