加入polyline join的功能

pull/59/head
ChenX 7 years ago
parent 7502d64a0d
commit e46eea463b

@ -31,7 +31,7 @@ export class Polyline extends Curve
constructor(data?: PolylineProps[]) constructor(data?: PolylineProps[])
{ {
super(); super();
this.m_LineData = data || [{ pt: new Vector2(0, 0), bul: 0 }]; this.m_LineData = data || [];
this.m_ClosedMark = false; this.m_ClosedMark = false;
} }
@ -435,6 +435,135 @@ export class Polyline extends Curve
this.Update(); this.Update();
} }
Join(cu: Curve): boolean
{
if (this.m_ClosedMark)
return false;
let [sp, ep, cuSp, cuEp] = [this.StartPoint, this.EndPoint, cu.StartPoint, cu.EndPoint];
if (this.m_LineData.length === 0)
{
if (cu instanceof Line)
{
this.m_LineData.push({ pt: Vec3DTo2D(cuSp), bul: 0 })
this.m_LineData.push({ pt: Vec3DTo2D(cuEp), bul: 0 })
}
else if (cu instanceof Arc)
{
this.m_LineData.push({ pt: Vec3DTo2D(cuSp), bul: Math.tan(0.25 * cu.AllAngle) })
this.m_LineData.push({ pt: Vec3DTo2D(cuEp), bul: 0 })
}
else
return false;
}
else
{
if (cu instanceof Line)
{
if (equal(cuSp, sp))
{
this.m_LineData.unshift({ pt: Vec3DTo2D(cuEp), bul: 0 });
}
else if (equal(cuSp, ep))
{
this.m_LineData.push({ pt: Vec3DTo2D(cuEp), bul: 0 });
}
else if (equal(cuEp, sp))
{
this.m_LineData.unshift({ pt: Vec3DTo2D(cuSp), bul: 0 });
}
else if (equal(cuEp, ep))
{
this.m_LineData.push({ pt: Vec3DTo2D(cuSp), bul: 0 });
}
else
return false;
}
else if (cu instanceof Arc)
{
let bul = Math.tan(cu.AllAngle * 0.25) * (cu.IsClockWise ? -1 : 1);
if (equal(cuSp, sp))
{
this.m_LineData.unshift({ pt: Vec3DTo2D(cuEp), bul: -bul });
}
else if (equal(cuSp, ep))
{
arrayLast(this.m_LineData).bul = bul;
this.m_LineData.push({ pt: Vec3DTo2D(cuEp), bul: 0 });
}
else if (equal(cuEp, sp))
{
this.m_LineData.unshift({ pt: Vec3DTo2D(cuSp), bul: bul });
}
else if (equal(cuEp, ep))
{
arrayLast(this.m_LineData).bul = -bul;
this.m_LineData.push({ pt: Vec3DTo2D(cuSp), bul: 0 });
}
else
return false;
}
else if (cu instanceof Polyline)
{
if (cu.CloseMark) return false;
let { pts, buls } = this.PtsBuls;
if (equal(cuSp, sp))
{
cu.Reverse();
let cuPtsBul = cu.PtsBuls;
cuPtsBul.pts.pop();
cuPtsBul.buls.pop();
pts = cuPtsBul.pts.concat(pts);
buls = cuPtsBul.buls.concat(buls);
}
else if (equal(cuSp, ep))
{
pts.pop();
buls.pop();
let cuPtsBul = cu.PtsBuls;
pts = pts.concat(cuPtsBul.pts);
buls = buls.concat(cuPtsBul.buls);
}
else if (equal(cuEp, sp))
{
let cuPtsBul = cu.PtsBuls;
cuPtsBul.pts.pop();
cuPtsBul.buls.pop();
pts = cuPtsBul.pts.concat(pts);
buls = cuPtsBul.buls.concat(buls);
}
else if (equal(cuEp, ep))
{
pts.pop();
buls.pop();
cu.Reverse();
let cuPtsBul = cu.PtsBuls;
pts = pts.concat(cuPtsBul.pts);
buls = buls.concat(cuPtsBul.buls);
}
else
return false;
this.m_LineData.length = 0;
for (let i = 0; i < pts.length; i++)
{
this.m_LineData.push({ pt: pts[i], bul: buls[i] });
}
}
else
return false;
}
//在上面的其他分支已经返回了假 所以这里直接返回真.
this.Update();
return true;
};
PtOnCurve(pt: Vector3): boolean PtOnCurve(pt: Vector3): boolean
{ {
let param = this.GetParamAtPoint(pt); let param = this.GetParamAtPoint(pt);
@ -1194,6 +1323,10 @@ export class Polyline extends Curve
{ {
let pts: Vector2[] = []; let pts: Vector2[] = [];
let buls: number[] = []; let buls: number[] = [];
if (this.m_LineData.length === 0)
return { pts, buls };
for (let data of this.m_LineData) for (let data of this.m_LineData)
{ {
pts.push(data.pt.clone()); pts.push(data.pt.clone());

Loading…
Cancel
Save