优化结果曲线

pull/68/head
Zoe 6 years ago
commit ed670cecd8

@ -19,7 +19,7 @@ export class Test implements Command
{
app.m_Editor.m_CommandStore.Prompt("载入成功!");
}
async exec()
async exec1()
{
let e1Res = await app.m_Editor.GetEntity();
let e2Res = await app.m_Editor.GetEntity();
@ -36,7 +36,7 @@ export class Test implements Command
}
//将多段线转换为cad图形
async execn()
async exec()
{
// let d = [["Polyline", 1, 1, 8987, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 14, [340.820007357324, -3.870032999900914], 0, [431.6163856609081, 116.2815653567217], 0, [485.54806901416487, 54.84040710617603], 0, [533.3356365423672, 67.81131829240235], 0, [624.1320148459513, 40.504136847715344], 0, [656.9006325795757, 23.43714844478601], -0.783383849320176, [633.0068488154745, -74.86870475608706], 0.4462700081240285, [605.0169878346704, -106.27196341747704], -0.8416099256631104, [529.9222388617812, -128.11770857322662], 0, [510.1245323143834, -22.98506001118185], 0, [430.251026588674, -129.48306764546098], 0, [430.251026588674, -65.99387078656383], 0, [351.74287993519897, -145.86737651227318], 0, [303.2726328708796, -87.83961594231337], 0, true]];
// let cadf = new CADFile();
@ -84,7 +84,7 @@ export class Test implements Command
copyTextToClipboard(str);
}
async exec1()
async execn()
{
let ssRes = await app.m_Editor.GetEntity();
if (ssRes.Status != PromptStatus.OK) return;

@ -1,6 +1,6 @@
import { Vector3 } from "three";
import { arrayLast } from "../Common/ArrayExt";
import { Vec3DTo2D, curveLinkGroup, getCirAngleByChordAndTangent } from "../Common/CurveUtils";
import { Vec3DTo2D, curveLinkGroup, getCirAngleByChordAndTangent, Vec2DTo3D } from "../Common/CurveUtils";
import { FixIndex } from "../Common/Utils";
import { Arc } from "../DatabaseServices/Arc";
import { Circle } from "../DatabaseServices/Circle";
@ -34,14 +34,14 @@ export class PolyOffestUtil
GetOffsetCurves(): Curve[]
{
let expCus = this.m_Polyline.Explode();
let plList1 = this.offestCurve(expCus, this.m_OffestDist);
let plList2 = this.offestCurve(expCus, -this.m_OffestDist);
let offres1 = this.offestCurve(expCus, this.m_OffestDist);
let offres2 = this.offestCurve(expCus, -this.m_OffestDist);
let contours: Contour[] = [];
for (let i = 0; i < plList1.length; i++)
for (let i = 0; i < offres1.length; i++)
{
let cu1 = plList1[i].curve;
let cu2 = plList2[i].curve;
let cu1 = offres1[i].curve;
let cu2 = offres2[i].curve;
let con = this.buildContourByTwoSideOfest(cu1, cu2);
//如果有圆弧丢失,则需加入源点上的圆作为轮廓加入计算
if (!cu1 || !cu2)
@ -59,15 +59,12 @@ export class PolyOffestUtil
// app.m_Database.ModelSpace.Append(c.Outline);
// })
let newPls = this.trimAndJointOffestPolyline(plList1, this.m_Polyline);
let newPls = this.trimAndJointOffestPolyline(offres1, this.m_Polyline);
let cus = this.trimByContours(newPls, contours);
if (this.IsKeepAllCurves)
{
return this.linkSelfingCurves(cus);
}
else
let rets = this.linkSelfingCurves(cus);
if (!this.IsKeepAllCurves)
{
let rets = this.linkSelfingCurves(cus);
// 先尝试把线段相连成封闭区域
rets = rets.map(cu => this.closePolyline(cu)).filter((l, i) =>
{
@ -80,8 +77,32 @@ export class PolyOffestUtil
{
return this.m_Polyline.IsClose ? l.IsClose : true;
});
return rets;
if (!this.m_Polyline.IsClose)
{
rets = rets.sort((l1, l2) => l2.Length - l1.Length)
.filter((l, i) =>
{
if (i == 0) return true;
else
{
if (l.IsClose)
{
let pts = l.PtsBuls.pts;
return pts.some(p =>
{
let p1 = Vec2DTo3D(p);
let closePt = rets[0].GetClosestPointTo(p1, false);
let dist = closePt.distanceToSquared(p1);
return dist > Math.pow(this.m_OffestDist, 2);
})
} else return false;
}
});
}
}
return rets;
}
//偏移曲线
private offestCurve(pls: Curve[], dis: number): offestRes[]
@ -372,7 +393,7 @@ export class PolyOffestUtil
{
tmpCus.push(l);
}
else
else if (!isTargetCurInSourceCur(outline, l))
{
let pts = l.IntersectWith(outline, IntersectOption.OnBothOperands);
if (pts.length > 0)

Loading…
Cancel
Save