添加偏移测试

pull/68/head
Zoe 6 years ago
parent be6b66d9be
commit 1c27604364

@ -109,5 +109,12 @@ test('多段线偏移测试3', () =>
{ {
expect(cus[0].GetOffsetCurves(i).length).toBe(1); expect(cus[0].GetOffsetCurves(i).length).toBe(1);
} }
for (let i = 0; i <= 0.5; i += 0.01)
{
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
}
for (let i = 0.51; i <= 1; i += 0.1)
{
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
}
}) })

@ -38,11 +38,12 @@ export class TestTargeOnCurve implements Command
// testCurve(res.unionList, 1); // testCurve(res.unionList, 1);
// testCurve(res.intersectionList, 2); // testCurve(res.intersectionList, 2);
// testCurve(res.subtractList, 3); // testCurve(res.subtractList, 3);
this.testClip(source as Polyline, target).forEach((c, i) => // this.testClip(source as Polyline, target).forEach((c, i) =>
{ // {
c.ColorIndex = i + 1; // c.ColorIndex = i + 1;
app.m_Database.ModelSpace.Append(c); // app.m_Database.ModelSpace.Append(c);
}) // })
this.testPtIn(source as Polyline, target);
// target.Erase(); // target.Erase();
// source.Erase(); // source.Erase();
@ -89,6 +90,16 @@ export class TestTargeOnCurve implements Command
} }
return tmpCus; return tmpCus;
} }
testPtIn(outline: Polyline, l: Curve)
{
if (outline.PtInCurve(l.StartPoint))
{
l.ColorIndex = 3
} else
l.ColorIndex = 1;
}
} }
export function testPts(pts: Vector3[], color = 2) export function testPts(pts: Vector3[], color = 2)

@ -55,17 +55,17 @@ export class PolyOffestUtil
// testContours(this.m_Contours); // testContours(this.m_Contours);
//裁剪 //裁剪
let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves); let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves);
// // 优化裁剪后的曲线 // 优化裁剪后的曲线
// this.m_RetCurves = this.optimizeCus(boxCurves, outputCus); this.m_RetCurves = this.optimizeCus(boxCurves, outputCus);
// this.m_RetCurves.push(...this.unNeedCutCus); this.m_RetCurves.push(...this.unNeedCutCus);
// this.m_RetCurves = this.linkCurves(this.m_RetCurves); this.m_RetCurves = this.linkCurves(this.m_RetCurves);
// // 如果源线段闭合只保留闭合的部分 // 如果源线段闭合只保留闭合的部分
// if (this.m_Polyline.IsClose) if (this.m_Polyline.IsClose)
// return this.m_RetCurves.filter(c => c.IsClose); return this.m_RetCurves.filter(c => c.IsClose);
this.m_Contours.forEach(c => { c.Outline.ColorIndex = 2 }); // this.m_Contours.forEach(c => { c.Outline.ColorIndex = 2 });
this.m_RetCurves.push(...this.m_Contours.map(c => c.Outline)) // this.m_RetCurves.push(...this.m_Contours.map(c => c.Outline))
return this.m_RetCurves; return this.m_RetCurves;
} }
@ -192,6 +192,12 @@ export class PolyOffestUtil
this.unNeedCutCus.push(splitCus[1]) this.unNeedCutCus.push(splitCus[1])
} }
} }
//防止轮廓自交
if (l1.IntersectWith(l2, 0).length > 0)
{
l1 = new Line(cu1.StartPoint, cu2.EndPoint);
l2 = new Line(cu1.EndPoint, cu2.StartPoint);
}
return Contour.CreateContour([ return Contour.CreateContour([
cu1.Clone() as Curve, cu1.Clone() as Curve,
cu2.Clone() as Curve, cu2.Clone() as Curve,
@ -541,15 +547,20 @@ export class PolyOffestUtil
//需要计算的点列表 //需要计算的点列表
let needCaclPts: Vector3[] = []; let needCaclPts: Vector3[] = [];
for (let i = 0; i < iParams.length - 1; i++) if (iParams.length === 0)
needCaclPts = [l.StartPoint]
else
{ {
needCaclPts.push(l.GetPointAtParam((iParams[i] + iParams[i + 1]) / 2)); for (let i = 0; i < iParams.length - 1; i++)
{
needCaclPts.push(l.GetPointAtParam((iParams[i] + iParams[i + 1]) / 2));
}
//如果交点不是首尾点,就加入首尾点
if (!equaln(iParams[0], 0, 1e-6))
needCaclPts.unshift(l.StartPoint);
if (!equaln(arrayLast(iParams), 1, 1e-6))
needCaclPts.push(l.EndPoint);
} }
//如果交点不是首尾点,就加入首尾点
if (!equaln(iParams[0], 0, 1e-6))
needCaclPts.unshift(l.StartPoint);
if (!equaln(arrayLast(iParams), 1, 1e-6))
needCaclPts.push(l.EndPoint);
//切割曲线,缓存切割后曲线包围盒 //切割曲线,缓存切割后曲线包围盒
if (IsPtsAllOutOrOnReg(outline, needCaclPts)) if (IsPtsAllOutOrOnReg(outline, needCaclPts))

Loading…
Cancel
Save