diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index 8c534c5e7..020fae966 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -1,7 +1,6 @@ import * as THREE from "three"; import { CreateBoardUtil } from "../ApplicationServices/mesh/createBoard"; import { Vec2DTo3D, Vec3DTo2D, curveLinkGroup, equalCurveAndCurve } from "../Common/CurveUtils"; -import { RegionParse, Route } from "../Geometry/RegionParse"; import { isTargetCurInSourceCur } from "../GraphicsSystem/BoolOperateUtils"; import { IntersectOption } from "../GraphicsSystem/IntersectWith"; import { Arc } from "./Arc"; @@ -29,6 +28,16 @@ export class Contour } } } + static CreateContour(cus: Curve[]) + { + let con = new Contour(); + con.m_Outline = Contour.Combine(cus ? cus : [])[0] as Polyline | Circle; + if (con.m_Outline && !con.m_Outline.IsClose) + { + return undefined; + } + return con; + } get Outline(): Polyline | Circle { return this.m_Outline; @@ -77,6 +86,9 @@ export class Contour let targetOutline = target.Outline; let interPts = sourceOutline.IntersectWith(targetOutline, IntersectOption.OnBothOperands); + + + let sourceContainerTarget = this.CuInOutline(targetOutline); let targetContainerSource = target.CuInOutline(sourceOutline); @@ -104,15 +116,17 @@ export class Contour let sourceCus: Array = sourceOutline.GetSplitCurves(pars1); let targetCus: Array = targetOutline.GetSplitCurves(pars2); + let equalPls: Curve[] = [] for (let pl of sourceCus) { - //在目标分离曲线数组从若有相等的曲线,则直接加入合并和相交集合中,在目标数组中就直接跳过不在添加,在2轮廓有共线部分时需此判断 + // 在目标分离曲线数组从若有相等的曲线,则直接加入合并和相交集合中,在目标数组中就直接跳过不在添加,在2轮廓有共线部分时需此判断 let hasEqualCus = targetCus.some(l => equalCurveAndCurve(pl, l)); if (hasEqualCus) { - unionList.push(pl); - intersectionList.push(pl); + // unionList.push(pl); + // intersectionList.push(pl); + equalPls.push(pl); continue; } @@ -145,32 +159,23 @@ export class Contour } } } + + return { intersectionList, unionList, subtractList }; } //获得所有闭合的轮廓. static GetAllContour(cus: Curve[]) { - const getSealCurByRoutes = (route: Set) => - { - let cus: Curve[] = []; - for (let r of route) - { - cus.push(r.curve); - } - return new Contour(cus); - } - let regPar = new RegionParse(cus); + let cuGroups = curveLinkGroup(cus); + let contours: Contour[] = [] - for (let routes of regPar.m_RegionsOutline) - { - contours.push(getSealCurByRoutes(routes)); - } - for (let routes of regPar.m_RegionsInternal) + + cuGroups.forEach(cus => { - contours.push(getSealCurByRoutes(routes)); - } - return contours; + contours.push(Contour.CreateContour(cus)); + }) + return contours.filter(c => c !== undefined); } /** * 合并曲线数组 diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 194206727..cf4e5007b 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -722,7 +722,7 @@ export class Polyline extends Curve //偏移 GetOffsetCurves(offsetDist: number): Array { - let polyOffestUtil = new PolyOffestUtil3(this, offsetDist); + let polyOffestUtil = new PolyOffestUtil2(this, offsetDist); return polyOffestUtil.GetOffsetCurves(); } /** diff --git a/src/DatabaseServices/Shape.ts b/src/DatabaseServices/Shape.ts index d4757e5f9..a606b6225 100644 --- a/src/DatabaseServices/Shape.ts +++ b/src/DatabaseServices/Shape.ts @@ -63,7 +63,7 @@ export class Shape IntersectionBoolOperation(targetShape: Shape): Shape[] { let resOutlines = this.m_Outline.IntersectionBoolOperation(targetShape.m_Outline); - let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeHoles([...this.m_Holes, ...targetShape.m_Holes])) + let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes])) return this.pairHoleAndOutline(cus); } @@ -121,7 +121,7 @@ export class Shape shapes.push(...this.pairHoleAndOutline(this.targetOutlineSubHoleOutline(tmpInterList, this.m_Holes))) }) - let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeHoles([...this.m_Holes, ...targetShape.m_Holes])); + let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes])); shapes.push(...this.pairHoleAndOutline(fCus)); return shapes; @@ -206,7 +206,7 @@ export class Shape * @returns * @memberof Shape */ - static mergeHoles(holes: Contour[]): Contour[] + static mergeContours(holes: Contour[]): Contour[] { if (holes.length <= 1) return holes; let rets: Contour[] = [];//返回的合并轮廓 diff --git a/src/GraphicsSystem/IntersectWith.ts b/src/GraphicsSystem/IntersectWith.ts index 369c918df..8f3365cfa 100644 --- a/src/GraphicsSystem/IntersectWith.ts +++ b/src/GraphicsSystem/IntersectWith.ts @@ -276,6 +276,7 @@ export function IntersectLineAndLine(l1: Line, l2: Line, extType: IntersectOptio export function IntersectPolylineAndCurve(pl: Polyline, cu: Curve, extType: IntersectOption): Vector3[] { + //TODO:若2多段线轮廓有完全重合的线段,会有多余交点 let cus: Curve[] = pl.Explode(); let cus2: Curve[]; @@ -306,7 +307,8 @@ export function IntersectPolylineAndCurve(pl: Polyline, cu: Curve, extType: Inte if ((cu instanceof Polyline && cu.CloseMark) || !(isStart2 || isEnd2)) ext = ext & ~IntersectOption.ExtendArg; - let ipts = cu1.IntersectWith(cu2, ext); + //TODO:去除重复的点 + let ipts = cu1.IntersectWith(cu2, ext).filter(p1 => pts.every(p2 => !equal(p1, p2))); //校验延伸 if (IntersectOption.ExtendThis & ext) diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index 9e61ff5b0..4a64d3842 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -623,24 +623,30 @@ export class PolyOffestUtil2 { contours.push(this.buildSealed(plList1[i].pl, plList2[i].pl)); } - // contours = Shape.mergeHoles(contours); + // contours = Shape.mergeContours(contours); // let shapes = contours.map(c => new Shape(c)); // let reg = new Region(); // reg.ShapeManager.AppendShapeList(shapes); // app.m_Database.ModelSpace.Append(reg); + contours.forEach(c => + { + c.Outline.ColorIndex = 3; + app.m_Database.ModelSpace.Append(c.Outline); + }) let newProps = this.trimAndJointOffestPolyline(plList1, this.m_Polyline); - // let refProps = this.trimAndJointOffestPolyline(plList2, this.m_Polyline); + let refProps = this.trimAndJointOffestPolyline(plList2, this.m_Polyline); let newPl = new Polyline(newProps); - // let refPl = new Polyline(refProps); - + let refPl = new Polyline(refProps); // newPl.ColorIndex = 1; // refPl.ColorIndex = 2; + // return [newPl, refPl] + // return [refPl, ...this.clipOffestPolyline(this.m_Polyline, newPl, refPl)] // return this.clipOffestPolyline(this.m_Polyline, newPl, refPl); // return [newPl] - return this.cutting(newPl, contours); + return [...this.cutting(newPl, contours), ...this.cutting(refPl, contours)]; } //偏移曲线 @@ -1152,15 +1158,15 @@ export class PolyOffestUtil3 console.log(box, Math.sqrt(Math.pow(box.x, 2) + Math.pow(box.y, 2)) / 2); console.log('off', this.m_OffestDist); - newPlList = this.cutting(newPlList, contours); - testPlList = this.cutting(testPlList, contours); + // newPlList = this.cutting(newPlList, contours); + // testPlList = this.cutting(testPlList, contours); - // 闭合时向内偏移,偏移线段应在封闭区域内 - if (this.m_Polyline.IsClose && this.offDir > 0) - { - // newPlList = newPlList.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl)) - testPlList = testPlList.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl)) - } + // // 闭合时向内偏移,偏移线段应在封闭区域内 + // if (this.m_Polyline.IsClose && this.offDir > 0) + // { + // // newPlList = newPlList.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl)) + // testPlList = testPlList.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl)) + // } // this.cuttingPolyLines(newPlList); // this.cuttingPolyLines(testPlList); return [...newPlList, ...testPlList];