|
|
|
@ -9,9 +9,10 @@ import { Curve } from "../DatabaseServices/Curve";
|
|
|
|
|
import { Line } from "../DatabaseServices/Line";
|
|
|
|
|
import { Polyline } from '../DatabaseServices/Polyline';
|
|
|
|
|
import { equal, equaln } from "../Geometry/GeUtils";
|
|
|
|
|
import { isTargetCurInOrOnSourceCur, isTargetCurOutOrOnSourceCur } from "./BoolOperateUtils";
|
|
|
|
|
import { isTargetCurInOrOnSourceCur, isTargetCurOutOrOnSourceCur, TargetCurPosForSourceCur } from "./BoolOperateUtils";
|
|
|
|
|
import { IntersectOption } from "./IntersectWith";
|
|
|
|
|
import { LinkSelf } from "./LinkSelft";
|
|
|
|
|
import { app } from "../ApplicationServices/Application";
|
|
|
|
|
interface offestRes
|
|
|
|
|
{
|
|
|
|
|
index: number,
|
|
|
|
@ -59,9 +60,8 @@ export class PolyOffestUtil
|
|
|
|
|
// app.m_Database.ModelSpace.Append(c.Outline);
|
|
|
|
|
// })
|
|
|
|
|
// console.time("trim");
|
|
|
|
|
let newPls = this.trimAndJointOffestPolyline(offres1, this.m_Polyline);
|
|
|
|
|
let newPls = this.trimAndJointOffestPolyline(offres1);
|
|
|
|
|
// console.timeEnd("trim");
|
|
|
|
|
|
|
|
|
|
// console.time("con");
|
|
|
|
|
let cus = this.trimByContours(newPls, contours);
|
|
|
|
|
// console.timeEnd("con");
|
|
|
|
@ -69,9 +69,12 @@ export class PolyOffestUtil
|
|
|
|
|
// console.time("link");
|
|
|
|
|
let rets = this.linkSelfingCurves2(cus);
|
|
|
|
|
// console.timeEnd('link');
|
|
|
|
|
|
|
|
|
|
if (!this.IsKeepAllCurves)
|
|
|
|
|
{
|
|
|
|
|
rets = this.optimizeCus(rets);
|
|
|
|
|
// console.time('k');
|
|
|
|
|
// rets = this.optimizeCus(rets);
|
|
|
|
|
// console.timeEnd('k');
|
|
|
|
|
}
|
|
|
|
|
return rets;
|
|
|
|
|
}
|
|
|
|
@ -84,14 +87,13 @@ export class PolyOffestUtil
|
|
|
|
|
*/
|
|
|
|
|
optimizeCus(rets: Polyline[])
|
|
|
|
|
{
|
|
|
|
|
if (rets.length <= 1) return rets;
|
|
|
|
|
|
|
|
|
|
if (this.m_Polyline.IsClose)
|
|
|
|
|
{
|
|
|
|
|
return rets.filter(l => l.IsClose)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rets.length <= 1) return rets;
|
|
|
|
|
let deleteCus: Set<Polyline> = new Set();
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < rets.length; i++)
|
|
|
|
@ -158,7 +160,7 @@ export class PolyOffestUtil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 修剪连接相邻曲线
|
|
|
|
|
private trimAndJointOffestPolyline(offResList: offestRes[], originLine: Polyline)
|
|
|
|
|
private trimAndJointOffestPolyline(offResList: offestRes[])
|
|
|
|
|
{
|
|
|
|
|
offResList = offResList.filter(r => r.curve && !equaln(r.curve.Length, 0, 1e-6));
|
|
|
|
|
if (offResList.length <= 1)
|
|
|
|
@ -200,12 +202,17 @@ export class PolyOffestUtil
|
|
|
|
|
// 源线段对应索引
|
|
|
|
|
let startIndex = offResList[i].index;
|
|
|
|
|
let endIndex = offResList[FixIndex(i + 1, offResList)].index;
|
|
|
|
|
|
|
|
|
|
let isFillArc = endIndex - startIndex !== 1;
|
|
|
|
|
if (endIndex === 0)
|
|
|
|
|
{
|
|
|
|
|
endIndex = this.m_Polyline.EndParam - 1;
|
|
|
|
|
isFillArc = endIndex !== startIndex;
|
|
|
|
|
}
|
|
|
|
|
// 多段线交点数组
|
|
|
|
|
let interPts = frontLine.IntersectWith(laterLine, IntersectOption.ExtendBoth);
|
|
|
|
|
|
|
|
|
|
//如果有圆弧丢失或者没有交点,则用圆弧连接
|
|
|
|
|
if ((endIndex - startIndex !== 1 && i !== offResList.length - 1) || interPts.length === 0)
|
|
|
|
|
if (isFillArc || interPts.length === 0)
|
|
|
|
|
{
|
|
|
|
|
//偏移线段对应的源线段,取其起始点作为圆心
|
|
|
|
|
this.fillArc(startIndex, endIndex, nextPt, frontLine, laterLine, retPlList);
|
|
|
|
@ -408,26 +415,49 @@ export class PolyOffestUtil
|
|
|
|
|
let outline = c.Outline;
|
|
|
|
|
needCutCus.forEach(l =>
|
|
|
|
|
{
|
|
|
|
|
//在上面或者在外面
|
|
|
|
|
if (isTargetCurOutOrOnSourceCur(outline, l))
|
|
|
|
|
{
|
|
|
|
|
tmpCus.push(l);
|
|
|
|
|
}
|
|
|
|
|
else if (!isTargetCurInOrOnSourceCur(outline, l))
|
|
|
|
|
let posSrcForTar = TargetCurPosForSourceCur(outline, l as Arc | Line);
|
|
|
|
|
|
|
|
|
|
if (posSrcForTar.throughSrc)
|
|
|
|
|
{
|
|
|
|
|
let pts = l.IntersectWith(outline, IntersectOption.OnBothOperands);
|
|
|
|
|
if (pts.length > 0)
|
|
|
|
|
let par = posSrcForTar.pts.map(p => l.GetParamAtPoint(p));
|
|
|
|
|
let cus = l.GetSplitCurves(par);
|
|
|
|
|
if (cus.length === 0)
|
|
|
|
|
{
|
|
|
|
|
let par = pts.map(p => l.GetParamAtPoint(p));
|
|
|
|
|
let cus = l.GetSplitCurves(par);
|
|
|
|
|
|
|
|
|
|
if (cus.length > 0)
|
|
|
|
|
tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && !isTargetCurInOrOnSourceCur(outline, cu)));
|
|
|
|
|
else
|
|
|
|
|
tmpCus.push(l);
|
|
|
|
|
|
|
|
|
|
tmpCus.push(l);
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && isTargetCurOutOrOnSourceCur(outline, cu)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (posSrcForTar.onSrc || posSrcForTar.outSrc)
|
|
|
|
|
{
|
|
|
|
|
tmpCus.push(l);
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
l instanceof Arc && tmpCus.push(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在上面或者在外面
|
|
|
|
|
// if (isTargetCurOutOrOnSourceCur(outline, l))
|
|
|
|
|
// {
|
|
|
|
|
// tmpCus.push(l);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// let pts = l.IntersectWith(outline, IntersectOption.OnBothOperands);
|
|
|
|
|
// if (pts.length > 0)
|
|
|
|
|
// {
|
|
|
|
|
// let par = pts.map(p => l.GetParamAtPoint(p));
|
|
|
|
|
// let cus = l.GetSplitCurves(par);
|
|
|
|
|
|
|
|
|
|
// if (cus.length > 0)
|
|
|
|
|
// tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && !isTargetCurInOrOnSourceCur(outline, cu)));
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// tmpCus.push(l);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
needCutCus = tmpCus;
|
|
|
|
|
})
|
|
|
|
|