|
|
|
@ -9,84 +9,84 @@ import { Polyline } from './Entity/Polyline';
|
|
|
|
|
|
|
|
|
|
export class Shape
|
|
|
|
|
{
|
|
|
|
|
private m_Outline: Contour;
|
|
|
|
|
private m_Holes: Contour[] = [];
|
|
|
|
|
private m_Shape: TShape = new TShape();
|
|
|
|
|
private _Outline: Contour;
|
|
|
|
|
private _Holes: Contour[] = [];
|
|
|
|
|
private _Shape: TShape = new TShape();
|
|
|
|
|
constructor(out?: Contour, hols?: Contour[])
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline = out || new Contour();
|
|
|
|
|
hols && this.m_Holes.push(...hols);
|
|
|
|
|
this._Outline = out || new Contour();
|
|
|
|
|
hols && this._Holes.push(...hols);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get Outline()
|
|
|
|
|
{
|
|
|
|
|
return this.m_Outline;
|
|
|
|
|
return this._Outline;
|
|
|
|
|
}
|
|
|
|
|
get Holes()
|
|
|
|
|
{
|
|
|
|
|
return this.m_Holes;
|
|
|
|
|
return this._Holes;
|
|
|
|
|
}
|
|
|
|
|
get Area()
|
|
|
|
|
{
|
|
|
|
|
let outlineArea = this.m_Outline.Area;
|
|
|
|
|
let holeArea = this.m_Holes.map(l => l.Area).reduce((a1, a2) => a1 + a2, 0);
|
|
|
|
|
let outlineArea = this._Outline.Area;
|
|
|
|
|
let holeArea = this._Holes.map(l => l.Area).reduce((a1, a2) => a1 + a2, 0);
|
|
|
|
|
return outlineArea - holeArea;
|
|
|
|
|
}
|
|
|
|
|
get BoundingBox()
|
|
|
|
|
{
|
|
|
|
|
return this.m_Outline.BoundingBox;
|
|
|
|
|
return this._Outline.BoundingBox;
|
|
|
|
|
}
|
|
|
|
|
set Outline(cus: Contour)
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline = cus;
|
|
|
|
|
this._Outline = cus;
|
|
|
|
|
this.UpdateShape();
|
|
|
|
|
}
|
|
|
|
|
set Holes(cus: Contour[])
|
|
|
|
|
{
|
|
|
|
|
this.m_Holes = cus;
|
|
|
|
|
this._Holes = cus;
|
|
|
|
|
this.UpdateShape();
|
|
|
|
|
}
|
|
|
|
|
get Shape()
|
|
|
|
|
{
|
|
|
|
|
this.UpdateShape();
|
|
|
|
|
return this.m_Shape;
|
|
|
|
|
return this._Shape;
|
|
|
|
|
}
|
|
|
|
|
get Position()
|
|
|
|
|
{
|
|
|
|
|
return this.m_Outline.Curve.Position;
|
|
|
|
|
return this._Outline.Curve.Position;
|
|
|
|
|
}
|
|
|
|
|
set Position(p: Vector3)
|
|
|
|
|
{
|
|
|
|
|
let vec = p.clone().sub(this.m_Outline.Curve.Position);
|
|
|
|
|
this.m_Outline.Curve.Position = p;
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
let vec = p.clone().sub(this._Outline.Curve.Position);
|
|
|
|
|
this._Outline.Curve.Position = p;
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
h.Curve.Position = h.Curve.Position.add(vec);
|
|
|
|
|
}
|
|
|
|
|
Z0()
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline.Curve.Z0();
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
this._Outline.Curve.Z0();
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
h.Curve.Z0();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MatrixPlanarizere()
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline.Curve.MatrixPlanarizere();
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
this._Outline.Curve.MatrixPlanarizere();
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
h.Curve.MatrixPlanarizere();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApplyMatrix(m: Matrix4)
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline.Curve.ApplyMatrix(m);
|
|
|
|
|
this.m_Holes.forEach(h => h.Curve.ApplyMatrix(m));
|
|
|
|
|
this._Outline.Curve.ApplyMatrix(m);
|
|
|
|
|
this._Holes.forEach(h => h.Curve.ApplyMatrix(m));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
ApplyScaleMatrix(m: Matrix4): this
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
let cu = this.Outline.Curve;
|
|
|
|
|
let cus = this.m_Holes.map(h => h.Curve);
|
|
|
|
|
let cus = this._Holes.map(h => h.Curve);
|
|
|
|
|
cus.unshift(cu);
|
|
|
|
|
for (let c of cus)
|
|
|
|
|
{
|
|
|
|
@ -100,7 +100,7 @@ export class Shape
|
|
|
|
|
Explode()
|
|
|
|
|
{
|
|
|
|
|
let cus: Curve[] = [];
|
|
|
|
|
let contours: Contour[] = [this.m_Outline, ...this.m_Holes];
|
|
|
|
|
let contours: Contour[] = [this._Outline, ...this._Holes];
|
|
|
|
|
for (let con of contours)
|
|
|
|
|
{
|
|
|
|
|
if (con.Curve instanceof Polyline)
|
|
|
|
@ -113,14 +113,14 @@ export class Shape
|
|
|
|
|
Clone()
|
|
|
|
|
{
|
|
|
|
|
let shape = new Shape();
|
|
|
|
|
shape.Outline = this.m_Outline.Clone();
|
|
|
|
|
shape.Outline = this._Outline.Clone();
|
|
|
|
|
shape.Holes = this.Holes.map(h => h.Clone());
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
SetColor(color: number)
|
|
|
|
|
{
|
|
|
|
|
this.m_Outline.Curve.ColorIndex = color;
|
|
|
|
|
this.m_Holes.forEach(h => h.Curve.ColorIndex = color);
|
|
|
|
|
this._Outline.Curve.ColorIndex = color;
|
|
|
|
|
this._Holes.forEach(h => h.Curve.ColorIndex = color);
|
|
|
|
|
}
|
|
|
|
|
GetObjectSnapPoints(
|
|
|
|
|
snapMode: ObjectSnapMode,
|
|
|
|
@ -140,8 +140,8 @@ export class Shape
|
|
|
|
|
case ObjectSnapMode.Per:
|
|
|
|
|
case ObjectSnapMode.Tan:
|
|
|
|
|
{
|
|
|
|
|
let cus: Curve[] = [this.m_Outline.Curve];
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
let cus: Curve[] = [this._Outline.Curve];
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
{
|
|
|
|
|
cus.push(h.Curve);
|
|
|
|
|
}
|
|
|
|
@ -160,7 +160,7 @@ export class Shape
|
|
|
|
|
GetGripPoints()
|
|
|
|
|
{
|
|
|
|
|
let pts = this.Outline.Curve.GetGripPoints();
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
{
|
|
|
|
|
pts.push(...h.Curve.GetGripPoints());
|
|
|
|
|
}
|
|
|
|
@ -169,13 +169,13 @@ export class Shape
|
|
|
|
|
MoveGripPoints(indexList: Array<number>, vec: Vector3)
|
|
|
|
|
{
|
|
|
|
|
let i = indexList[0];
|
|
|
|
|
let outlineIndex = this.m_Outline.Curve.GetGripPoints().length;
|
|
|
|
|
let outlineIndex = this._Outline.Curve.GetGripPoints().length;
|
|
|
|
|
|
|
|
|
|
let cu = this.m_Outline.Curve;
|
|
|
|
|
let cu = this._Outline.Curve;
|
|
|
|
|
|
|
|
|
|
if (i >= outlineIndex)
|
|
|
|
|
{
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
{
|
|
|
|
|
let len = h.Curve.GetGripPoints().length;
|
|
|
|
|
if (indexList[0] < outlineIndex + len)
|
|
|
|
@ -192,7 +192,7 @@ export class Shape
|
|
|
|
|
GetStretchPoints()
|
|
|
|
|
{
|
|
|
|
|
let pts = this.Outline.Curve.GetStretchPoints();
|
|
|
|
|
for (let h of this.m_Holes)
|
|
|
|
|
for (let h of this._Holes)
|
|
|
|
|
{
|
|
|
|
|
pts.push(...h.Curve.GetStretchPoints());
|
|
|
|
|
}
|
|
|
|
@ -201,7 +201,7 @@ export class Shape
|
|
|
|
|
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
|
|
|
|
|
{
|
|
|
|
|
let outlen = 0;
|
|
|
|
|
for (let cu of [this.m_Outline.Curve, ...this.m_Holes.map(h => h.Curve)])
|
|
|
|
|
for (let cu of [this._Outline.Curve, ...this._Holes.map(h => h.Curve)])
|
|
|
|
|
{
|
|
|
|
|
let count = cu.GetStretchPoints().length;
|
|
|
|
|
let refIndex = outlen + count;
|
|
|
|
@ -224,15 +224,15 @@ export class Shape
|
|
|
|
|
//交集 如果成功返回一个面域 失败返回0个
|
|
|
|
|
IntersectionBoolOperation(targetShape: Shape): Shape[]
|
|
|
|
|
{
|
|
|
|
|
let resOutlines = this.m_Outline.IntersectionBoolOperation(targetShape.m_Outline);
|
|
|
|
|
let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes]));
|
|
|
|
|
let resOutlines = this._Outline.IntersectionBoolOperation(targetShape._Outline);
|
|
|
|
|
let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this._Holes, ...targetShape._Holes]));
|
|
|
|
|
return Shape.pairHoleAndOutline(cus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//并集,如果成功返回1个形状,不成功返回2个形状
|
|
|
|
|
UnionBoolOperation(targetShape: Shape): Shape[]
|
|
|
|
|
{
|
|
|
|
|
let resOutlines = this.m_Outline.UnionBoolOperation(targetShape.m_Outline);
|
|
|
|
|
let resOutlines = this._Outline.UnionBoolOperation(targetShape._Outline);
|
|
|
|
|
let shapes: Shape[] = [];
|
|
|
|
|
|
|
|
|
|
//提取出所有的孔洞, 目标线段孔洞和原线段差,如果孔洞和目标相减后有被包围轮廓,应把这个单独提取出来作为形状
|
|
|
|
@ -256,11 +256,11 @@ export class Shape
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
pickUpHoleOrShape(targetShape.m_Holes, this.m_Holes, this.m_Outline);
|
|
|
|
|
pickUpHoleOrShape(this.m_Holes, targetShape.m_Holes, targetShape.m_Outline);
|
|
|
|
|
targetShape.m_Holes.forEach(cu =>
|
|
|
|
|
pickUpHoleOrShape(targetShape._Holes, this._Holes, this._Outline);
|
|
|
|
|
pickUpHoleOrShape(this._Holes, targetShape._Holes, targetShape._Outline);
|
|
|
|
|
targetShape._Holes.forEach(cu =>
|
|
|
|
|
{
|
|
|
|
|
this.m_Holes.forEach(c =>
|
|
|
|
|
this._Holes.forEach(c =>
|
|
|
|
|
{
|
|
|
|
|
unionHoles.push(...c.IntersectionBoolOperation(cu));
|
|
|
|
|
});
|
|
|
|
@ -273,28 +273,28 @@ export class Shape
|
|
|
|
|
//如果完全被减掉,就返回0个.其他的返回1个或者n个
|
|
|
|
|
SubstactBoolOperation(targetShape: Shape): Shape[]
|
|
|
|
|
{
|
|
|
|
|
let resOutlines = this.m_Outline.SubstactBoolOperation(targetShape.m_Outline);
|
|
|
|
|
let resOutlines = this._Outline.SubstactBoolOperation(targetShape._Outline);
|
|
|
|
|
let shapes: Shape[] = [];
|
|
|
|
|
//如果相减,则需要取出被减面域和减数面域的洞的交集,结果还需减去被减面域的全部孔洞
|
|
|
|
|
targetShape.m_Holes.forEach(cu =>
|
|
|
|
|
targetShape._Holes.forEach(cu =>
|
|
|
|
|
{
|
|
|
|
|
let tmpInterList = cu.IntersectionBoolOperation(this.m_Outline);
|
|
|
|
|
let tmpInterList = cu.IntersectionBoolOperation(this._Outline);
|
|
|
|
|
|
|
|
|
|
shapes.push(...Shape.pairHoleAndOutline(this.targetOutlineSubHoleOutline(tmpInterList, this.m_Holes)));
|
|
|
|
|
shapes.push(...Shape.pairHoleAndOutline(this.targetOutlineSubHoleOutline(tmpInterList, this._Holes)));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes]));
|
|
|
|
|
let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this._Holes, ...targetShape._Holes]));
|
|
|
|
|
|
|
|
|
|
shapes.push(...Shape.pairHoleAndOutline(fCus));
|
|
|
|
|
return shapes;
|
|
|
|
|
}
|
|
|
|
|
Equal(targetShape: Shape)
|
|
|
|
|
{
|
|
|
|
|
if (this.m_Outline.Equal(targetShape.m_Outline))
|
|
|
|
|
if (this._Outline.Equal(targetShape._Outline))
|
|
|
|
|
{
|
|
|
|
|
return this.m_Holes.length === targetShape.m_Holes.length
|
|
|
|
|
&& this.m_Holes.every(h1 =>
|
|
|
|
|
targetShape.m_Holes.some(h2 => h1.Equal(h2))
|
|
|
|
|
return this._Holes.length === targetShape._Holes.length
|
|
|
|
|
&& this._Holes.every(h1 =>
|
|
|
|
|
targetShape._Holes.some(h2 => h1.Equal(h2))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -428,13 +428,13 @@ export class Shape
|
|
|
|
|
}
|
|
|
|
|
UpdateShape()
|
|
|
|
|
{
|
|
|
|
|
this.m_Shape = this.Outline.Shape;
|
|
|
|
|
this._Shape = this.Outline.Shape;
|
|
|
|
|
this.Holes.forEach(h =>
|
|
|
|
|
{
|
|
|
|
|
if (h.Curve instanceof Polyline)
|
|
|
|
|
h.Curve.UpdateMatrixTo(this.Outline.Curve.OCS);
|
|
|
|
|
});
|
|
|
|
|
this.m_Shape.holes.push(...this.m_Holes.map(
|
|
|
|
|
this._Shape.holes.push(...this._Holes.map(
|
|
|
|
|
h =>
|
|
|
|
|
{
|
|
|
|
|
if (h.Curve instanceof Circle)
|
|
|
|
@ -452,12 +452,12 @@ export class Shape
|
|
|
|
|
ReadFile(file: CADFiler)
|
|
|
|
|
{
|
|
|
|
|
let ver = file.Read();//1
|
|
|
|
|
this.m_Outline = Contour.CreateContour([file.ReadObject() as Curve]);
|
|
|
|
|
this._Outline = Contour.CreateContour([file.ReadObject() as Curve]);
|
|
|
|
|
|
|
|
|
|
let count = file.Read();
|
|
|
|
|
for (let i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
this.m_Holes.push(
|
|
|
|
|
this._Holes.push(
|
|
|
|
|
Contour.CreateContour([file.ReadObject() as Curve])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -467,8 +467,8 @@ export class Shape
|
|
|
|
|
WriteFile(file: CADFiler)
|
|
|
|
|
{
|
|
|
|
|
file.Write(1);//ver
|
|
|
|
|
file.WriteObject(this.m_Outline.Curve);
|
|
|
|
|
file.Write(this.m_Holes.length);
|
|
|
|
|
this.m_Holes.forEach(h => file.WriteObject(h.Curve));
|
|
|
|
|
file.WriteObject(this._Outline.Curve);
|
|
|
|
|
file.Write(this._Holes.length);
|
|
|
|
|
this._Holes.forEach(h => file.WriteObject(h.Curve));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|