diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 6304e628a..e6640e7f8 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -1,15 +1,15 @@ import * as THREE from 'three'; -import { Box3, Geometry, Object3D, Vector2, Vector3, Matrix4 } from 'three'; +import { Box3, Geometry, Matrix4, Object3D, Vector2, Vector3 } from 'three'; import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard'; import { arrayLast } from '../Common/ArrayExt'; import { ColorMaterial } from '../Common/ColorPalette'; import { Vec2DTo3D, Vec3DTo2D, getDeterminantFor2V } from '../Common/CurveUtils'; import { matrixAlignCoordSys } from '../Common/Matrix4Utils'; import { FixIndex } from '../Common/Utils'; -import { equal, equaln, rotatePoint, updateGeometry } from '../Geometry/GeUtils'; +import { equal, equaln, updateGeometry } from '../Geometry/GeUtils'; import { RenderType } from '../GraphicsSystem/Enum'; import { IntersectOption, IntersectPolylineAndCurve } from '../GraphicsSystem/IntersectWith'; -import { PolyOffestUtil, PolyOffestUtil2, PolyOffestUtil3 } from '../GraphicsSystem/OffestPolyline'; +import { PolyOffestUtil3 } from '../GraphicsSystem/OffestPolyline'; import { Arc } from './Arc'; import { Factory } from './CADFactory'; import { CADFile } from './CADFile'; diff --git a/src/GraphicsSystem/IntersectWith.ts b/src/GraphicsSystem/IntersectWith.ts index 8f3365cfa..fb28a0b60 100644 --- a/src/GraphicsSystem/IntersectWith.ts +++ b/src/GraphicsSystem/IntersectWith.ts @@ -244,6 +244,7 @@ export function IntersectLAndLFor3D(p1: Vector3, p2: Vector3, p3: Vector3, p4: V let par = tmpLine.GetParamAtPoint(p3); if (par) { + //FIXME:这样拿交点会导致判断点在线上发生错误 pt = midPoint(midPoint(p1, p2), midPoint(p3, p4)); } } diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index 8ccd495dd..19f1aeb0b 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -1,21 +1,15 @@ import { Vector2, Vector3 } from "three"; -import { Vec2DTo3D, Vec3DTo2D, getCirAngleByChordAndTangent, curveLinkGroup } from "../Common/CurveUtils"; -import { sliceDeep } from "../Common/Utils"; +import { arrayLast } from "../Common/ArrayExt"; +import { Vec2DTo3D, Vec3DTo2D, curveLinkGroup, getCirAngleByChordAndTangent } from "../Common/CurveUtils"; import { Arc } from "../DatabaseServices/Arc"; import { Circle } from "../DatabaseServices/Circle"; import { Contour } from "../DatabaseServices/Contour"; import { Curve } from "../DatabaseServices/Curve"; import { Line } from "../DatabaseServices/Line"; import { Polyline, PolylineProps } from '../DatabaseServices/Polyline'; -import { MoveMatrix, angleTo, equal, equaln } from "../Geometry/GeUtils"; -import { isTargetCurInSourceCur, isTargetCurOutOrOnSourceCur, isTargetCurOnSourceCur } from "./BoolOperateUtils"; +import { equal, equaln } from "../Geometry/GeUtils"; +import { isTargetCurInSourceCur, isTargetCurOutOrOnSourceCur } from "./BoolOperateUtils"; import { IntersectOption } from "./IntersectWith"; -import { removeRepeat, arrayLast, filterArray } from "../Common/ArrayExt"; -import { Region } from "../DatabaseServices/Region"; -import { Shape } from "../DatabaseServices/Shape"; -import { app } from "../ApplicationServices/Application"; -import { ShapeManager } from "../DatabaseServices/ShapeManager"; -import { intercept } from "mobx"; interface offestRes { index: number, @@ -1079,30 +1073,15 @@ export class PolyOffestUtil3 contours.push(this.buildContourByTwoSideOfest(plList1[i].pl, plList2[i].pl)); } let newPls = this.trimAndJointOffestPolyline(plList1, this.m_Polyline); - // let refPls = this.trimAndJointOffestPolyline(plList2, this.m_Polyline); - - // let refPl = new Polyline(refProps); - // return [...newPls, ...refPls] let cus = this.trimByContours(newPls, contours); + if (this.m_Polyline.IsClose && this.offDir < 0) { cus = cus.filter(pl => isTargetCurInSourceCur(this.m_Polyline, pl)) } - let isIntersectWithSelf = this.isSelfingCUs(cus); - if (isIntersectWithSelf) - { - // cus.forEach(c => c.ColorIndex = 2); - - // return cus; - return this.linkSelfingCurves(cus); - } else - return this.linkCurves(cus); - - // let cus1 = this.trimByContours(refPls, contours); - // return [...cus, ...cus1] - // 闭合时向内偏移,偏移线段应在封闭区域内,自交情况下无效 + return this.linkSelfingCurves(cus); } //偏移曲线 @@ -1343,12 +1322,14 @@ export class PolyOffestUtil3 } return needCutPls; } - getIntersectWithSelf(cus: Curve[]) - { - let pls: Polyline[] = []; - - return pls; - } + /** + * 判断曲线是否自交 + * + * @private + * @param {Curve[]} cus + * @returns + * @memberof PolyOffestUtil3 + */ private isSelfingCUs(cus: Curve[]) { for (let i = 0; i < cus.length; i++) @@ -1391,6 +1372,14 @@ export class PolyOffestUtil3 } return resultPls; } + + /** + *连接自交曲线数组 + * + * @param {Curve[]} cus + * @returns + * @memberof PolyOffestUtil3 + */ linkSelfingCurves(cus: Curve[]) { let newPls: Polyline[] = []; @@ -1400,7 +1389,6 @@ export class PolyOffestUtil3 { let pl = new Polyline(); let frontLine = cus.shift(); - pl.Join(frontLine); let end = 0; @@ -1424,34 +1412,47 @@ export class PolyOffestUtil3 let parForFront = frontLine.GetParamAtPoint(pts[0]); let parForLater = laterLine.GetParamAtPoint(pts[0]); + if (equaln(parForLater, 1)) + continue; + if (equaln(parForFront, 0)) { - pl.LineData.pop() - cus.unshift(frontLine); + } - else if (!equaln(parForFront, 1)) + else if (equaln(parForFront, 1)) { - pl.EndPoint = pts[0]; + pl.Join(frontLine); } - - if (equaln(parForLater, 0)) + else { - pl.Join(laterLine); - frontLine = laterLine; - } else if (!equaln(parForLater, 1)) + let spliteCusForFront = frontLine.GetSplitCurves(parForFront); + pl.Join(spliteCusForFront[0]); + cus.unshift(spliteCusForFront[1]); + j++; + } + if (equaln(parForLater, 0)) + frontLine = cus.splice(j, 1)[0]; + else { - let spliteCusForLater = laterLine.GetSplitCurves(parForLater); - pl.Join(spliteCusForLater[1]); - cus[j].StartPoint = pts[0]; - - frontLine = spliteCusForLater[1]; + let splitCus = laterLine.GetSplitCurves(parForLater); + cus[j].EndPoint = pts[0]; + frontLine = splitCus[1]; } - end = j + 1 - j = cus.length - 1; + end = j; + j = cus.length; + } + + //搜索到尽头,先直接join,先不判断 + if (end >= j) + { + pl.Join(frontLine); + break; } } + newPls.push(pl); isSelfing = this.isSelfingCUs(cus); + } newPls.push(...this.linkCurves(cus)); return newPls;