轮廓添加静态创建方法,失败返回undifined

pull/68/head
Zoe 6 years ago
parent 798d0f445e
commit f8059e6c4a

@ -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<Polyline | Arc> = sourceOutline.GetSplitCurves(pars1);
let targetCus: Array<Polyline | Arc> = 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<Route>) =>
{
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);
}
/**
* 线

@ -722,7 +722,7 @@ export class Polyline extends Curve
//偏移
GetOffsetCurves(offsetDist: number): Array<Curve>
{
let polyOffestUtil = new PolyOffestUtil3(this, offsetDist);
let polyOffestUtil = new PolyOffestUtil2(this, offsetDist);
return polyOffestUtil.GetOffsetCurves();
}
/**

@ -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[] = [];//返回的合并轮廓

@ -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)

@ -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];

Loading…
Cancel
Save