Compare commits

..

3 Commits

Author SHA1 Message Date
ChenX
063a010609 暴露CurveWrap 2023-11-02 15:15:50 +08:00
ChenX
78b1c316da 增加注释 移除小特性 2023-11-01 17:28:57 +08:00
ChenX
6014fc40a2 开发:修复错误 2023-11-01 17:07:20 +08:00
14 changed files with 451 additions and 118 deletions

View File

@@ -370,31 +370,31 @@ function Object3DRemoveAll(obj) {
return obj; return obj;
} }
var Status; exports.Status = void 0;
(function (Status) { (function (Status) {
Status[Status["False"] = 0] = "False"; Status[Status["False"] = 0] = "False";
Status[Status["True"] = 1] = "True"; Status[Status["True"] = 1] = "True";
Status[Status["Canel"] = -1] = "Canel"; Status[Status["Canel"] = -1] = "Canel";
Status[Status["ConverToCircle"] = 101] = "ConverToCircle"; Status[Status["ConverToCircle"] = 101] = "ConverToCircle";
Status[Status["DuplicateRecordName"] = 102] = "DuplicateRecordName"; Status[Status["DuplicateRecordName"] = 102] = "DuplicateRecordName";
})(Status || (Status = {})); })(exports.Status || (exports.Status = {}));
var UpdateDraw; exports.UpdateDraw = void 0;
(function (UpdateDraw) { (function (UpdateDraw) {
UpdateDraw[UpdateDraw["None"] = 0] = "None"; UpdateDraw[UpdateDraw["None"] = 0] = "None";
UpdateDraw[UpdateDraw["Matrix"] = 1] = "Matrix"; UpdateDraw[UpdateDraw["Matrix"] = 1] = "Matrix";
UpdateDraw[UpdateDraw["Geometry"] = 2] = "Geometry"; UpdateDraw[UpdateDraw["Geometry"] = 2] = "Geometry";
UpdateDraw[UpdateDraw["Material"] = 4] = "Material"; UpdateDraw[UpdateDraw["Material"] = 4] = "Material";
UpdateDraw[UpdateDraw["All"] = 63] = "All"; UpdateDraw[UpdateDraw["All"] = 63] = "All";
})(UpdateDraw || (UpdateDraw = {})); })(exports.UpdateDraw || (exports.UpdateDraw = {}));
/** /**
* WblockClne时,遇到重复记录的操作方式 * WblockClne时,遇到重复记录的操作方式
*/ */
var DuplicateRecordCloning; exports.DuplicateRecordCloning = void 0;
(function (DuplicateRecordCloning) { (function (DuplicateRecordCloning) {
DuplicateRecordCloning[DuplicateRecordCloning["Ignore"] = 1] = "Ignore"; DuplicateRecordCloning[DuplicateRecordCloning["Ignore"] = 1] = "Ignore";
DuplicateRecordCloning[DuplicateRecordCloning["Replace"] = 2] = "Replace"; DuplicateRecordCloning[DuplicateRecordCloning["Replace"] = 2] = "Replace";
DuplicateRecordCloning[DuplicateRecordCloning["Rename"] = 3] = "Rename"; DuplicateRecordCloning[DuplicateRecordCloning["Rename"] = 3] = "Rename";
})(DuplicateRecordCloning || (DuplicateRecordCloning = {})); })(exports.DuplicateRecordCloning || (exports.DuplicateRecordCloning = {}));
/** /**
* 盒子的切割类型 * 盒子的切割类型
@@ -1065,7 +1065,7 @@ class SymbolTableRecord extends CADObject {
this.name = name; this.name = name;
} }
Add(obj, isCheckObjectCleanly = true) { Add(obj, isCheckObjectCleanly = true) {
return Status.False; return exports.Status.False;
} }
WriteFile(file) { WriteFile(file) {
super.WriteFile(file); super.WriteFile(file);
@@ -1536,7 +1536,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
* 当AutoUpdate为false时,记录需要更新的标志. * 当AutoUpdate为false时,记录需要更新的标志.
* 以便延迟更新时找到相应的更新标志. * 以便延迟更新时找到相应的更新标志.
*/ */
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = exports.UpdateDraw.None;
this.AutoUpdate = true; this.AutoUpdate = true;
this._drawObject = undefined; this._drawObject = undefined;
//实体绘制更新版本号 //实体绘制更新版本号
@@ -1563,7 +1563,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
return; return;
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._Freeze = f; this._Freeze = f;
this.Update(UpdateDraw.Material); this.Update(exports.UpdateDraw.Material);
} }
get VisibleInRender() { return this._VisibleInRender; } get VisibleInRender() { return this._VisibleInRender; }
set VisibleInRender(v) { set VisibleInRender(v) {
@@ -1602,7 +1602,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
undoRec.WriteObjectHistoryPath(this, hisRec); undoRec.WriteObjectHistoryPath(this, hisRec);
} }
this._Color = color; this._Color = color;
this.Update(UpdateDraw.Material); this.Update(exports.UpdateDraw.Material);
} }
} }
get ColorIndex() { get ColorIndex() {
@@ -1632,7 +1632,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
if (isClearDraw) { if (isClearDraw) {
for (let [, obj] of this._CacheDrawObject) for (let [, obj] of this._CacheDrawObject)
obj.matrix = this._Matrix; //因为使用了备份的矩阵,导致此时这个矩形是错误的,这里还原它 obj.matrix = this._Matrix; //因为使用了备份的矩阵,导致此时这个矩形是错误的,这里还原它
this.Update(UpdateDraw.Matrix); //保证盒子是正确的 this.Update(exports.UpdateDraw.Matrix); //保证盒子是正确的
} }
return new Box3Ext().copy(box); return new Box3Ext().copy(box);
} }
@@ -1834,7 +1834,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
/** /**
* 当实体数据改变时,绘制的实体必须做出改变.供框架调用 * 当实体数据改变时,绘制的实体必须做出改变.供框架调用
*/ */
Update(mode = UpdateDraw.All) { Update(mode = exports.UpdateDraw.All) {
this.__UpdateVersion__++; this.__UpdateVersion__++;
this.NeedUpdateFlag |= mode; this.NeedUpdateFlag |= mode;
if (this.AutoUpdate) { if (this.AutoUpdate) {
@@ -1851,14 +1851,14 @@ let Entity = Entity_1 = class Entity extends CADObject {
let mode = this.NeedUpdateFlag; let mode = this.NeedUpdateFlag;
if (mode === 0) if (mode === 0)
return; return;
if (mode & UpdateDraw.Geometry && this._CacheDrawObject.size > 0) if (mode & exports.UpdateDraw.Geometry && this._CacheDrawObject.size > 0)
this.UpdateDrawGeometry(); this.UpdateDrawGeometry();
this.UpdateVisible(); this.UpdateVisible();
let isJigIng = this._CacheDrawObject.has(RenderType.Jig); let isJigIng = this._CacheDrawObject.has(RenderType.Jig);
for (let [type, obj] of this._CacheDrawObject) { for (let [type, obj] of this._CacheDrawObject) {
if (isJigIng && type !== RenderType.Jig) if (isJigIng && type !== RenderType.Jig)
continue; continue;
if (mode & UpdateDraw.Geometry) { if (mode & exports.UpdateDraw.Geometry) {
if (obj.userData.IsClone) { if (obj.userData.IsClone) {
let parent = obj.parent; let parent = obj.parent;
DisposeThreeObj(obj); DisposeThreeObj(obj);
@@ -1873,15 +1873,15 @@ let Entity = Entity_1 = class Entity extends CADObject {
else else
this.UpdateDrawObject(type, obj); this.UpdateDrawObject(type, obj);
} }
if (mode & UpdateDraw.Material) if (mode & exports.UpdateDraw.Material)
this.UpdateDrawObjectMaterial(type, obj); this.UpdateDrawObjectMaterial(type, obj);
if (mode & UpdateDraw.Matrix || mode & UpdateDraw.Geometry) { if (mode & exports.UpdateDraw.Matrix || mode & exports.UpdateDraw.Geometry) {
obj.updateMatrixWorld(true); obj.updateMatrixWorld(true);
// if (this.Id)//如果这个是Jig实体,那么我们更新这个盒子球似乎也没有意义 (虽然这在某些情况能改进性能,但是在绘制圆弧的时候,因为没有更新圆弧的盒子,导致绘制出来的圆弧无法被选中) // if (this.Id)//如果这个是Jig实体,那么我们更新这个盒子球似乎也没有意义 (虽然这在某些情况能改进性能,但是在绘制圆弧的时候,因为没有更新圆弧的盒子,导致绘制出来的圆弧无法被选中)
obj.traverse(UpdateBoundingSphere); obj.traverse(UpdateBoundingSphere);
} }
} }
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = exports.UpdateDraw.None;
} }
/** /**
* 当实体需要更新时,需要重载该方法,实现实体更新 * 当实体需要更新时,需要重载该方法,实现实体更新
@@ -1961,7 +1961,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
} }
else else
this.ApplyScaleMatrix(m); this.ApplyScaleMatrix(m);
this.Update(UpdateDraw.Matrix); this.Update(exports.UpdateDraw.Matrix);
return this; return this;
} }
ApplyScaleMatrix(m) { ApplyScaleMatrix(m) {
@@ -2018,7 +2018,7 @@ let Entity = Entity_1 = class Entity extends CADObject {
newObj.userData.IsClone = true; newObj.userData.IsClone = true;
this._CacheDrawObject.set(type, newObj); this._CacheDrawObject.set(type, newObj);
} }
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = exports.UpdateDraw.None;
} }
get ReadFileIng() { get ReadFileIng() {
return this.__ReadFileIng__ || Entity_1.__ReadFileIng__; return this.__ReadFileIng__ || Entity_1.__ReadFileIng__;
@@ -3564,7 +3564,7 @@ let Curve = class Curve extends Entity {
* @returns {boolean} 连接成功 * @returns {boolean} 连接成功
* @memberof Curve * @memberof Curve
*/ */
Join(cu, allowGap = false, tolerance = 1e-4) { return Status.False; } Join(cu, allowGap = false, tolerance = 1e-4) { return exports.Status.False; }
//翻转曲线.首尾调换. //翻转曲线.首尾调换.
Reverse() { return this; } Reverse() { return this; }
//点在曲线上 //点在曲线上
@@ -3997,15 +3997,15 @@ exports.Line = Line_1 = class Line extends Curve {
if (cu instanceof Line_1 || cu.constructor.name === "RoomWallLine") { if (cu instanceof Line_1 || cu.constructor.name === "RoomWallLine") {
//平行 //平行
if (!isParallelTo(this.GetFirstDeriv(0).normalize(), cu.GetFirstDeriv(0).normalize())) if (!isParallelTo(this.GetFirstDeriv(0).normalize(), cu.GetFirstDeriv(0).normalize()))
return Status.False; return exports.Status.False;
let sp = cu.StartPoint; let sp = cu.StartPoint;
let { closestPt: cp1, param: param1 } = this.GetClosestAtPoint(sp, true); let { closestPt: cp1, param: param1 } = this.GetClosestAtPoint(sp, true);
if (!equalv3(sp, cp1, tolerance)) //点在曲线上,允许较低的精度 if (!equalv3(sp, cp1, tolerance)) //点在曲线上,允许较低的精度
return Status.False; return exports.Status.False;
let ep = cu.EndPoint; let ep = cu.EndPoint;
let { closestPt: cp2, param: param2 } = this.GetClosestAtPoint(ep, true); let { closestPt: cp2, param: param2 } = this.GetClosestAtPoint(ep, true);
if (!equalv3(ep, cp2, tolerance)) if (!equalv3(ep, cp2, tolerance))
return Status.False; return exports.Status.False;
if (param1 > param2) { if (param1 > param2) {
[param1, param2] = [param2, param1]; [param1, param2] = [param2, param1];
[sp, ep] = [ep, sp]; [sp, ep] = [ep, sp];
@@ -4016,10 +4016,10 @@ exports.Line = Line_1 = class Line extends Curve {
this.StartPoint = sp; this.StartPoint = sp;
if (param2 > 1) if (param2 > 1)
this.EndPoint = ep; this.EndPoint = ep;
return Status.True; return exports.Status.True;
} }
} }
return Status.False; return exports.Status.False;
} }
Reverse() { Reverse() {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
@@ -4388,17 +4388,17 @@ let Ellipse = Ellipse_1 = class Ellipse extends Curve {
} }
Join(el) { Join(el) {
if (this.IsClose || el.IsClose || !this.IsCoplaneTo(el) || !equalv3(el.Center, this.Center)) if (this.IsClose || el.IsClose || !this.IsCoplaneTo(el) || !equalv3(el.Center, this.Center))
return Status.False; return exports.Status.False;
let status = Status.False; let status = exports.Status.False;
if (equaln$1(this._endAngle, this._startAngle)) { if (equaln$1(this._endAngle, this._startAngle)) {
this.EndAngle = this._endAngle; this.EndAngle = this._endAngle;
status = Status.True; status = exports.Status.True;
} }
else if (equaln$1(this._startAngle, el._endAngle)) { else if (equaln$1(this._startAngle, el._endAngle)) {
this.StartAngle = el._startAngle; this.StartAngle = el._startAngle;
status = Status.True; status = exports.Status.True;
} }
if (status === Status.True && !this.IsClose && equaln$1(this._startAngle, this._endAngle)) { if (status === exports.Status.True && !this.IsClose && equaln$1(this._startAngle, this._endAngle)) {
this.StartAngle = 0; this.StartAngle = 0;
this.EndAngle = Math.PI * 2; this.EndAngle = Math.PI * 2;
} }
@@ -6223,11 +6223,11 @@ class Contour {
let nextI = FixIndex$1(i + 1, g); let nextI = FixIndex$1(i + 1, g);
let c2 = g[nextI]; let c2 = g[nextI];
let status = c1.Join(c2); let status = c1.Join(c2);
if (status === Status.True) { if (status === exports.Status.True) {
g.splice(nextI, 1); g.splice(nextI, 1);
i--; i--;
} }
else if (status === Status.ConverToCircle) { else if (status === exports.Status.ConverToCircle) {
g.length = 0; g.length = 0;
let a = c1; let a = c1;
g.push(new exports.Circle(a.Center, a.Radius)); g.push(new exports.Circle(a.Center, a.Radius));
@@ -6532,7 +6532,7 @@ class Contour {
if (cache$1.has(g)) if (cache$1.has(g))
return cache$1.get(g); return cache$1.get(g);
let gclone = g.map(c => c.Clone()); let gclone = g.map(c => c.Clone());
arrayRemoveDuplicateBySort(gclone, (cu1, cu2) => cu1.Join(cu2, false, tolerance) === Status.True); arrayRemoveDuplicateBySort(gclone, (cu1, cu2) => cu1.Join(cu2, false, tolerance) === exports.Status.True);
if (gclone.length > 1 && gclone[0].Join(arrayLast(gclone), false, tolerance)) if (gclone.length > 1 && gclone[0].Join(arrayLast(gclone), false, tolerance))
gclone.pop(); gclone.pop();
let pl = exports.Polyline.Combine(gclone, tolerance); let pl = exports.Polyline.Combine(gclone, tolerance);
@@ -7079,14 +7079,14 @@ class OffsetPolyline {
if (n2.used) if (n2.used)
continue; continue;
let status = n.curve.Join(n2.curve); let status = n.curve.Join(n2.curve);
if (status === Status.ConverToCircle) { if (status === exports.Status.ConverToCircle) {
n.used = true; n.used = true;
n2.used = true; n2.used = true;
let circle = new exports.Circle(n.curve.Center, n.curve.Radius); let circle = new exports.Circle(n.curve.Center, n.curve.Radius);
n.curve = circle; n.curve = circle;
this._RetCurves.push(ConverCircleToPolyline$1(circle).ApplyMatrix(this._CacheOCS)); this._RetCurves.push(ConverCircleToPolyline$1(circle).ApplyMatrix(this._CacheOCS));
} }
else if (status === Status.True) { else if (status === exports.Status.True) {
if (equalv3(sp, n.curve.StartPoint)) if (equalv3(sp, n.curve.StartPoint))
n2.used = true; n2.used = true;
else { else {
@@ -8097,7 +8097,7 @@ exports.Polyline = Polyline_1 = class Polyline extends Curve {
Join(cu, allowGap = false, tolerance = 1e-4) { Join(cu, allowGap = false, tolerance = 1e-4) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
if (this._ClosedMark) if (this._ClosedMark)
return Status.False; return exports.Status.False;
let [sp, ep, cuSp, cuEp] = [this.StartPoint, this.EndPoint, cu.StartPoint, cu.EndPoint]; let [sp, ep, cuSp, cuEp] = [this.StartPoint, this.EndPoint, cu.StartPoint, cu.EndPoint];
let ocsInv = this.OCSInv; let ocsInv = this.OCSInv;
let [cuSp2, cuEp2] = [cuSp, cuEp].map(p => AsVector2(p.clone().applyMatrix4(ocsInv))); let [cuSp2, cuEp2] = [cuSp, cuEp].map(p => AsVector2(p.clone().applyMatrix4(ocsInv)));
@@ -8121,7 +8121,7 @@ exports.Polyline = Polyline_1 = class Polyline extends Curve {
this.ReadFile(f); this.ReadFile(f);
} }
else else
return Status.False; return exports.Status.False;
} }
else { else {
let LinkType; let LinkType;
@@ -8155,7 +8155,7 @@ exports.Polyline = Polyline_1 = class Polyline extends Curve {
minDis = spepDisSq; minDis = spepDisSq;
} }
if (linkType === LinkType.None) if (linkType === LinkType.None)
return Status.False; return exports.Status.False;
if (cu instanceof exports.Line) { if (cu instanceof exports.Line) {
if (linkType === LinkType.SpSp) { if (linkType === LinkType.SpSp) {
this._LineData.unshift({ pt: cuEp2, bul: 0 }); this._LineData.unshift({ pt: cuEp2, bul: 0 });
@@ -8193,7 +8193,7 @@ exports.Polyline = Polyline_1 = class Polyline extends Curve {
} }
else if (cu instanceof Polyline_1) { else if (cu instanceof Polyline_1) {
if (cu.CloseMark) if (cu.CloseMark)
return Status.False; return exports.Status.False;
let { pts, buls } = this.PtsBuls; let { pts, buls } = this.PtsBuls;
if (linkType === LinkType.SpSp) { if (linkType === LinkType.SpSp) {
cu.Reverse(); cu.Reverse();
@@ -8231,11 +8231,11 @@ exports.Polyline = Polyline_1 = class Polyline extends Curve {
} }
} }
else else
return Status.False; return exports.Status.False;
} }
//在上面的其他分支已经返回了假 所以这里直接返回真. //在上面的其他分支已经返回了假 所以这里直接返回真.
this.Update(); this.Update();
return Status.True; return exports.Status.True;
} }
/** /**
* 将曲线数组组合成多段线 * 将曲线数组组合成多段线
@@ -9653,7 +9653,7 @@ exports.Arc = Arc_1 = class Arc extends Curve {
if (cu instanceof Arc_1) { if (cu instanceof Arc_1) {
//非常小的圆弧直接结束 //非常小的圆弧直接结束
if (cu.AllAngle < 5e-6) if (cu.AllAngle < 5e-6)
return Status.False; return exports.Status.False;
if (equalv3(cu.Center, this.Center) && equaln$1(cu._Radius, this._Radius)) { if (equalv3(cu.Center, this.Center) && equaln$1(cu._Radius, this._Radius)) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
let [sa, ea] = [cu.StartAngle, cu.EndAngle]; let [sa, ea] = [cu.StartAngle, cu.EndAngle];
@@ -9666,40 +9666,40 @@ exports.Arc = Arc_1 = class Arc extends Curve {
{ {
if (eaAllan > allAn) if (eaAllan > allAn)
this.EndAngle = ea; this.EndAngle = ea;
return Status.True; return exports.Status.True;
} }
else if (equaln$1(sa, this._EndAngle)) //this终点对起点 else if (equaln$1(sa, this._EndAngle)) //this终点对起点
{ {
if (eaAllan < allAn || equaln$1(ea, this._StartAngle)) if (eaAllan < allAn || equaln$1(ea, this._StartAngle))
return Status.ConverToCircle; return exports.Status.ConverToCircle;
else else
this.EndAngle = ea; this.EndAngle = ea;
return Status.True; return exports.Status.True;
} }
else if (equaln$1(ea, this.StartAngle)) //this起点对终点 else if (equaln$1(ea, this.StartAngle)) //this起点对终点
{ {
if (saAllan < allAn) if (saAllan < allAn)
return Status.ConverToCircle; return exports.Status.ConverToCircle;
else else
this.StartAngle = sa; this.StartAngle = sa;
return Status.True; return exports.Status.True;
} }
else if (equaln$1(ea, this._EndAngle)) //this终点对终点 else if (equaln$1(ea, this._EndAngle)) //this终点对终点
{ {
if (saAllan > allAn) if (saAllan > allAn)
this.StartAngle = sa; this.StartAngle = sa;
return Status.True; return exports.Status.True;
} }
else if (this.ParamOnCurve(this.GetParamAtAngle(sa))) { else if (this.ParamOnCurve(this.GetParamAtAngle(sa))) {
if (eaAllan < saAllan) if (eaAllan < saAllan)
return Status.ConverToCircle; return exports.Status.ConverToCircle;
else if (eaAllan > allAn) else if (eaAllan > allAn)
this.EndAngle = ea; this.EndAngle = ea;
return Status.True; return exports.Status.True;
} }
else if (this.ParamOnCurve(this.GetParamAtAngle(ea))) { else if (this.ParamOnCurve(this.GetParamAtAngle(ea))) {
this.StartAngle = sa; this.StartAngle = sa;
return Status.True; return exports.Status.True;
} }
//使用按负方向去计算它的参数 //使用按负方向去计算它的参数
let saParam; let saParam;
@@ -9719,11 +9719,11 @@ exports.Arc = Arc_1 = class Arc extends Curve {
this.StartAngle = sa; this.StartAngle = sa;
if (eaParam > 1) if (eaParam > 1)
this.EndAngle = ea; this.EndAngle = ea;
return Status.True; return exports.Status.True;
} }
} }
} }
return Status.False; return exports.Status.False;
} }
Reverse() { Reverse() {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
@@ -10355,12 +10355,12 @@ function MergeCurvelist(cus) {
if (cir) if (cir)
return true; return true;
let status = c1.Join(c2, false, LINK_FUZZ); let status = c1.Join(c2, false, LINK_FUZZ);
if (status === Status.ConverToCircle) { if (status === exports.Status.ConverToCircle) {
let arc = c1; let arc = c1;
cir = new exports.Circle(arc.Center, arc.Radius); cir = new exports.Circle(arc.Center, arc.Radius);
return true; return true;
} }
return status === Status.True; return status === exports.Status.True;
}); });
if (cir) { if (cir) {
cus.length = 0; cus.length = 0;
@@ -11191,13 +11191,13 @@ let Region = Region_1 = class Region extends Entity {
let m = new three.Matrix4().setPosition(moveX, moveY, moveZ); let m = new three.Matrix4().setPosition(moveX, moveY, moveZ);
for (let s of this.ShapeManager.ShapeList) for (let s of this.ShapeManager.ShapeList)
s.ApplyMatrix(m); s.ApplyMatrix(m);
this.Update(UpdateDraw.Matrix); this.Update(exports.UpdateDraw.Matrix);
} }
ApplyScaleMatrix(m) { ApplyScaleMatrix(m) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
for (let s of this._ShapeManager.ShapeList) for (let s of this._ShapeManager.ShapeList)
s.ApplyScaleMatrix(m); s.ApplyScaleMatrix(m);
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
return this; return this;
} }
//Z轴归0 //Z轴归0
@@ -14502,7 +14502,7 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity {
else { else {
this._Matrix.multiplyMatrices(m, this._Matrix); this._Matrix.multiplyMatrices(m, this._Matrix);
this._SpaceOCS.multiplyMatrices(m, this._SpaceOCS); this._SpaceOCS.multiplyMatrices(m, this._SpaceOCS);
this.Update(UpdateDraw.Matrix); this.Update(exports.UpdateDraw.Matrix);
} }
} }
else { else {
@@ -14524,7 +14524,7 @@ let SweepSolid = SweepSolid_1 = class SweepSolid extends Entity {
} }
else else
this._PathCurve.ApplyMatrix(this.OCSNoClone).ApplyMatrix(m).ApplyMatrix(ocsInv); this._PathCurve.ApplyMatrix(this.OCSNoClone).ApplyMatrix(m).ApplyMatrix(ocsInv);
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
return this; return this;
} }
_ReadFile(file) { _ReadFile(file) {
@@ -15342,7 +15342,7 @@ class EdgeGeometryBuild {
pl.ColorIndex = g[0].ColorIndex; pl.ColorIndex = g[0].ColorIndex;
pl.OCS = ComputerCurvesNormalOCS(g); pl.OCS = ComputerCurvesNormalOCS(g);
for (let cu of g) { for (let cu of g) {
if (pl.Join(cu, false, 0.1) === Status.True) if (pl.Join(cu, false, 0.1) === exports.Status.True)
cu.Erase(); cu.Erase();
} }
pl.CloseMark = true; pl.CloseMark = true;
@@ -16339,7 +16339,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
let scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; let scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
let scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; let scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
if (!equaln$1(scaleXSq, 1, 1e-4) || !equaln$1(scaleYSq, 1, 1e-4) || !equaln$1(scaleZSq, 1, 1e-4)) if (!equaln$1(scaleXSq, 1, 1e-4) || !equaln$1(scaleYSq, 1, 1e-4) || !equaln$1(scaleZSq, 1, 1e-4))
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
else if (this.AutoUpdate) else if (this.AutoUpdate)
this.DeferUpdate(); this.DeferUpdate();
return this; return this;
@@ -16392,7 +16392,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
this.SetContourCurve(curve); this.SetContourCurve(curve);
} }
if (this.grooves.length) if (this.grooves.length)
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
return this; return this;
} }
get Width() { get Width() {
@@ -16421,7 +16421,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
} }
} }
this.thickness = thickness; this.thickness = thickness;
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
} }
//修复#I7CBHO的过程中 直接修改了这个属性 //修复#I7CBHO的过程中 直接修改了这个属性
@@ -16578,7 +16578,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
Join(target) { Join(target) {
let [n, tn] = [this.Normal, target.Normal]; let [n, tn] = [this.Normal, target.Normal];
if (!isParallelTo(n, tn)) if (!isParallelTo(n, tn))
return Status.False; return exports.Status.False;
let isEqualNorm = equalv3(n, tn); let isEqualNorm = equalv3(n, tn);
let targetZMin = target.Position.applyMatrix4(this.OCSInv).z; let targetZMin = target.Position.applyMatrix4(this.OCSInv).z;
let targetZMax = targetZMin + target.Thickness * (isEqualNorm ? 1 : -1); let targetZMax = targetZMin + target.Thickness * (isEqualNorm ? 1 : -1);
@@ -16626,12 +16626,12 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
MergeRelevance(); MergeRelevance();
this.GrooveCheckMerge(); this.GrooveCheckMerge();
this.Update(); this.Update();
return Status.True; return exports.Status.True;
} }
} }
else { else {
if (!isIntersect(0, this.thickness, targetZMin, targetZMax, 1e-5)) if (!isIntersect(0, this.thickness, targetZMin, targetZMax, 1e-5))
return Status.False; return exports.Status.False;
let matrixToLocal = this.OCSInv.multiply(target.OCS); let matrixToLocal = this.OCSInv.multiply(target.OCS);
let thisCurve = this.ContourCurve; let thisCurve = this.ContourCurve;
let targetCurve = target.ContourCurve.Clone().ApplyMatrix(matrixToLocal); let targetCurve = target.ContourCurve.Clone().ApplyMatrix(matrixToLocal);
@@ -16645,10 +16645,10 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
MergeRelevance(); MergeRelevance();
this.GrooveCheckMerge(); this.GrooveCheckMerge();
this.Update(); this.Update();
return Status.True; return exports.Status.True;
} }
} }
return Status.False; return exports.Status.False;
} }
get Volume() { get Volume() {
let sum = this.ContourCurve.Area * this.thickness; let sum = this.ContourCurve.Area * this.thickness;
@@ -16929,7 +16929,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
*/ */
GrooveCheckPosition(target) { GrooveCheckPosition(target) {
if (target.Width < 1e-1 || target.Height < 1e-1 || target.Thickness < 1e-1) if (target.Width < 1e-1 || target.Height < 1e-1 || target.Thickness < 1e-1)
return Status.False; return exports.Status.False;
let tp = target.Position.applyMatrix4(this.OCSInv); let tp = target.Position.applyMatrix4(this.OCSInv);
let minZ = tp.z; let minZ = tp.z;
let maxZ = tp.z + target.thickness; let maxZ = tp.z + target.thickness;
@@ -16942,10 +16942,10 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
else if (maxZ >= (this.thickness - 1e-2) && minZ > 0) //正面 else if (maxZ >= (this.thickness - 1e-2) && minZ > 0) //正面
target.Thickness = this.thickness - minZ; target.Thickness = this.thickness - minZ;
else else
return Status.False; return exports.Status.False;
if (equaln$1(target.thickness, this.thickness, 1e-2)) if (equaln$1(target.thickness, this.thickness, 1e-2))
target.thickness = this.thickness; target.thickness = this.thickness;
return target.thickness > 1e-2 ? Status.True : Status.False; return target.thickness > 1e-2 ? exports.Status.True : exports.Status.False;
} }
/** /**
* (步骤3) * (步骤3)
@@ -16985,7 +16985,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
})); }));
for (let id of ids) { for (let id of ids) {
let ng = this.grooves[id]; let ng = this.grooves[id];
if (equaln$1(startG.knifeRadius, ng.knifeRadius, 1e-3) && startG.Join(ng) === Status.True) { if (equaln$1(startG.knifeRadius, ng.knifeRadius, 1e-3) && startG.Join(ng) === exports.Status.True) {
ng.TempData.used = true; ng.TempData.used = true;
stack.push(ng); stack.push(ng);
} }
@@ -17125,7 +17125,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
//校验Z轴位置 //校验Z轴位置
arrayRemoveIf(this.grooves, g => { arrayRemoveIf(this.grooves, g => {
return this.GrooveCheckPosition(g) === Status.False; return this.GrooveCheckPosition(g) === exports.Status.False;
}); });
//清除全深洞的子槽 //清除全深洞的子槽
for (let g of this.grooves) { for (let g of this.grooves) {
@@ -17344,7 +17344,7 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
*/ */
get SplitExtrudes() { get SplitExtrudes() {
if (this.NeedUpdateRelevanceGroove) if (this.NeedUpdateRelevanceGroove)
this.Update(UpdateDraw.Geometry); //我们先直接更新绘制 this.Update(exports.UpdateDraw.Geometry); //我们先直接更新绘制
if (this.NeedUpdateRelevanceGroove) //如果更新失败,那么我们更新这个槽(似乎也证明了我们没有绘制实体) if (this.NeedUpdateRelevanceGroove) //如果更新失败,那么我们更新这个槽(似乎也证明了我们没有绘制实体)
this.CalcRelevanceGroove(); //注意,这也将更新绘制的实体(EdgeGeo,MeshGeo)(如果拆单也用这个,可能会带来性能损耗) this.CalcRelevanceGroove(); //注意,这也将更新绘制的实体(EdgeGeo,MeshGeo)(如果拆单也用这个,可能会带来性能损耗)
if (this.__CacheSplitExtrudes) if (this.__CacheSplitExtrudes)
@@ -17521,10 +17521,10 @@ let ExtrudeSolid = ExtrudeSolid_1 = class ExtrudeSolid extends Entity {
} }
} }
DeferUpdate() { DeferUpdate() {
if (this.NeedUpdateFlag & UpdateDraw.Matrix) { if (this.NeedUpdateFlag & exports.UpdateDraw.Matrix) {
//如果是Jig实体,那么就算它有关联切割,我们也不更新实体(因为似乎没必要?) //如果是Jig实体,那么就算它有关联切割,我们也不更新实体(因为似乎没必要?)
if (this.Id && this.RelevanceKnifs.some(id => !id.IsErase)) if (this.Id && this.RelevanceKnifs.some(id => !id.IsErase))
this.NeedUpdateFlag |= UpdateDraw.Geometry; this.NeedUpdateFlag |= exports.UpdateDraw.Geometry;
} }
super.DeferUpdate(); super.DeferUpdate();
} }
@@ -17904,11 +17904,11 @@ let CompositeEntity = CompositeEntity_1 = class CompositeEntity extends Entity {
newObj.userData.IsClone = true; newObj.userData.IsClone = true;
this._CacheDrawObject.set(type, newObj); this._CacheDrawObject.set(type, newObj);
} }
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = exports.UpdateDraw.None;
} }
ApplyMirrorMatrix(m) { ApplyMirrorMatrix(m) {
if (this.Id) if (this.Id)
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
return this; return this;
} }
//#endregion //#endregion
@@ -19460,7 +19460,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
if (!this.__ReadFileIng__) //看起来使用 this.ReadFileIng 似乎也是没问题的 if (!this.__ReadFileIng__) //看起来使用 this.ReadFileIng 似乎也是没问题的
{ {
if (key === EBoardKeyList.Lines) if (key === EBoardKeyList.Lines)
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
else if (key === EBoardKeyList.ComposingFace) { else if (key === EBoardKeyList.ComposingFace) {
let obj = this.CacheDrawObject.get(RenderType.PlaceFace); let obj = this.CacheDrawObject.get(RenderType.PlaceFace);
if (obj) { if (obj) {
@@ -19505,7 +19505,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this._BoardProcessOption.drillType = type; this._BoardProcessOption.drillType = type;
this._BoardProcessOption.highDrill = Array(4).fill(type); this._BoardProcessOption.highDrill = Array(4).fill(type);
this.ConverToRectSolid(width, length, thickness); this.ConverToRectSolid(width, length, thickness);
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
static CreateBoard(length, width, thickness, boardType = BoardType.Layer) { static CreateBoard(length, width, thickness, boardType = BoardType.Layer) {
let board = new Board_1(); let board = new Board_1();
@@ -19715,7 +19715,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._2DModelingList = ms; this._2DModelingList = ms;
this.Clear2DPathCache(); this.Clear2DPathCache();
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
get Modeling3D() { get Modeling3D() {
return [...this._3DModelingList]; return [...this._3DModelingList];
@@ -19724,7 +19724,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.Clear3DPathCache(); this.Clear3DPathCache();
this._3DModelingList = ms; this._3DModelingList = ms;
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
ClearModeling2DList() { ClearModeling2DList() {
if (this._2DModelingList.length === 0) if (this._2DModelingList.length === 0)
@@ -19732,7 +19732,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._2DModelingList.length = 0; this._2DModelingList.length = 0;
this.Clear2DPathCache(); this.Clear2DPathCache();
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
ClearModeling3DList() { ClearModeling3DList() {
if (this._3DModelingList.length === 0) if (this._3DModelingList.length === 0)
@@ -19740,7 +19740,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._3DModelingList.length = 0; this._3DModelingList.length = 0;
this.Clear3DPathCache(); this.Clear3DPathCache();
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
get IsChaiDan() { get IsChaiDan() {
return this._IsChaiDan; return this._IsChaiDan;
@@ -19749,7 +19749,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
if (this._IsChaiDan !== v) { if (this._IsChaiDan !== v) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._IsChaiDan = v; this._IsChaiDan = v;
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
} }
get OpenDir() { get OpenDir() {
@@ -19760,7 +19760,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this._OpenDir = v; this._OpenDir = v;
//开门方向改变更新 //开门方向改变更新
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
} }
ClearBoardModeling() { ClearBoardModeling() {
@@ -19768,7 +19768,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
return; return;
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.grooves.length = 0; this.grooves.length = 0;
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
/** /**
* 注意传入的排钻列表,避免指针被引用 * 注意传入的排钻列表,避免指针被引用
@@ -20533,7 +20533,7 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
} }
this.Clear2DPathCache(); this.Clear2DPathCache();
this.Clear3DPathCache(); this.Clear3DPathCache();
this.Update(UpdateDraw.Geometry); this.Update(exports.UpdateDraw.Geometry);
} }
GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform, frustum) { GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform, frustum) {
let pts = super.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform, frustum); let pts = super.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform, frustum);
@@ -20572,9 +20572,9 @@ let Board = Board_1 = class Board extends ExtrudeSolid {
return pts; return pts;
} }
DeferUpdate() { DeferUpdate() {
if (this.NeedUpdateFlag & UpdateDraw.Matrix) { if (this.NeedUpdateFlag & exports.UpdateDraw.Matrix) {
if (this.RelativeHardware.some(id => !id.IsErase)) if (this.RelativeHardware.some(id => !id.IsErase))
this.NeedUpdateFlag |= UpdateDraw.Geometry; this.NeedUpdateFlag |= exports.UpdateDraw.Geometry;
} }
super.DeferUpdate(); super.DeferUpdate();
} }
@@ -22909,11 +22909,9 @@ function Polyline2Points(pl, outside, knifeRadius) {
let bul = pl.GetBulgeAt(i); let bul = pl.GetBulgeAt(i);
if (bul !== 0) { if (bul !== 0) {
let arc = pl.GetCurveAtIndex(i); let arc = pl.GetCurveAtIndex(i);
//小圆弧内嵌时忽略小圆(直线连接) // //小圆弧内嵌时忽略小圆(直线连接) 有可能产生自交 放弃这个
if (!outside && arc.Radius < 30 && bul > 0) // if (!outside && arc.Radius < 30 && bul > 0) continue;
continue; // if (outside && arc.Radius < 30 && bul < 0) continue;
if (outside && arc.Radius < 30 && bul < 0)
continue;
let allAngle = arc.AllAngle; let allAngle = arc.AllAngle;
let arcLength = arc.Length; let arcLength = arc.Length;
let minCount = Math.floor(allAngle * 4 / Math.PI); let minCount = Math.floor(allAngle * 4 / Math.PI);
@@ -22943,33 +22941,182 @@ function Polyline2Points(pl, outside, knifeRadius) {
return [pl, pts]; return [pl, pts];
} }
/** /**
* 移除小圆弧,使用尖角直连 * 移除小圆弧,使用尖角直连(有可能产生自交 概率不大)
* @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个) * @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个)
* @param [radius=30] * @param [radius=30]
*/ */
function PolylineFilletMinArc(pl, radius = 30) { function PolylineFilletMinArc(pl, radius = 30) {
let ocsInv = pl.OCSInv; let ocsInv = pl.OCSInv;
for (let i = 0; i < pl.LineData.length; i++) { for (let i = 0; i < pl.EndParam; i++) {
let bul = pl.LineData[i].bul; let bul = pl.LineData[i].bul;
if (equaln(bul, BUL_IS_LINE_FUZZ)) if (equaln(bul, BUL_IS_LINE_FUZZ))
continue; continue;
let arc = pl.GetCurveAtIndex(i); let arc = pl.GetCurveAtIndex(i);
if (arc.Radius > radius) if (arc.Radius > radius)
continue; continue;
let preCurve = pl.GetCurveAtIndex(FixIndex(i - 1, pl.LineData)); let preCurve = pl.GetCurveAtIndex(FixIndex(i - 1, pl.EndParam));
if (!(preCurve instanceof exports.Line)) if (!(preCurve instanceof exports.Line))
continue; continue;
let nextCurve = pl.GetCurveAtIndex(FixIndex(i + 1, pl.LineData)); let nextCurve = pl.GetCurveAtIndex(FixIndex(i + 1, pl.EndParam));
if (!(nextCurve instanceof exports.Line)) if (!(nextCurve instanceof exports.Line))
continue; continue;
if (preCurve.IntersectWith2(arc, IntersectOption.ExtendThis).length === 2) if (preCurve.IntersectWith2(arc, IntersectOption.ExtendThis).length === 2)
continue; continue;
let ipt = nextCurve.IntersectWith(preCurve, IntersectOption.ExtendBoth)[0]; let ipt = nextCurve.IntersectWith(preCurve, IntersectOption.ExtendBoth)[0];
if (!ipt)
continue;
if (ipt.distanceTo(arc.Midpoint) > 50)
continue;
pl.LineData.splice(i, 1); pl.LineData.splice(i, 1);
pl.SetPointAt(i, ipt.applyMatrix4(ocsInv)); pl.SetPointAt(i, ipt.applyMatrix4(ocsInv));
} }
} }
/** 点p到线段P1P2 的最短距离的平方,线段不延伸 */
function GetSqSegDist(p, p1, p2) {
let x = p1.x;
let y = p1.y;
let dx = p2.x - x;
let dy = p2.y - y;
if (dx !== 0 || dy !== 0) //不是0长度线
{
let t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
if (t > 1) {
x = p2.x;
y = p2.y;
}
else if (t > 0) {
x += dx * t;
y += dy * t;
}
}
dx = p.x - x;
dy = p.y - y;
return dx * dx + dy * dy;
}
function CrossVector2(a, b) {
return a.x * b.y - a.y * b.x;
}
//Ramer-Douglas-Peucker algorithm
function SimplifyDPStep(points, first, last, sqTolerance, simplified, offset) {
let maxSqDist = 0;
let index;
let fp = points[first];
let lp = points[last];
for (let i = first + 1; i < last; i++) {
let p = points[i];
let sqDist = GetSqSegDist(p, fp, lp);
if (sqDist > maxSqDist) {
index = i;
maxSqDist = sqDist;
}
}
if (maxSqDist > sqTolerance) {
if (index - first > 1)
SimplifyDPStep(points, first, index, sqTolerance, simplified, offset);
simplified.push(points[index]);
if (last - index > 1)
SimplifyDPStep(points, index, last, sqTolerance, simplified, offset);
}
else {
//记录偏移
let v = new Vector2(lp.x - fp.x, lp.y - fp.y).normalize();
for (let i = first + 1; i < last; i++) {
let p = points[i];
let offsetDist = -CrossVector2(v, { x: p.x - fp.x, y: p.y - fp.y });
offset.positiveOffset = Math.max(offset.positiveOffset, offsetDist);
offset.negativeOffset = Math.min(offset.negativeOffset, offsetDist);
}
}
}
// Ramer-Douglas-Peucker 算法
function SimplifyDouglasPeucker(points, sqTolerance) {
let last = points.length - 1;
let simplified = [points[0]];
let offset = { negativeOffset: 0, positiveOffset: 0 };
SimplifyDPStep(points, 0, last, sqTolerance, simplified, offset);
simplified.push(points[last]);
return [simplified, offset];
}
/**
* 运用此代码将曲线转换为点,并且精简它.
* @class CurveWrap
*/
class CurveWrap {
constructor(Curve, KnifRadius = 3, IsOutside = true) {
this.Curve = Curve;
this.KnifRadius = KnifRadius;
this.IsOutside = IsOutside;
this.Used = false;
this.Holes = [];
this.BoundingBox = Curve.BoundingBox;
if (Curve instanceof exports.Polyline) {
let pts = Polyline2Points(Curve, IsOutside, 0)[1];
let [spts, offset] = SimplifyDouglasPeucker(pts, KnifRadius ** 2 + KnifRadius);
if (spts.length !== pts.length) {
this.SimplyOffset = offset;
this.SimplyPolyline = Path2Polyline(spts);
this.Curve = this.SimplyPolyline; //保险起见,也更新它
this.Area = this.SimplyPolyline.Area;
}
else //此处更新多段线
this.Curve = Path2Polyline(pts);
this.Points = spts;
}
if (this.Area === undefined)
this.Area = this.Curve.Area;
}
ContainsCurve(curve) {
if (this.SimplyPolyline)
return this.SimplyPolyline.PtInCurve(curve.Curve.StartPoint);
return this.Curve.PtInCurve(curve.Curve.StartPoint);
}
GetOutsidePoints() {
if (this.Curve instanceof exports.Circle) {
let pts = Circle2Points(this.Curve, this.KnifRadius, 10, true);
return pts;
}
else {
let pl = this.SimplyPolyline || this.Curve;
let offset = this.KnifRadius;
if (this.SimplyOffset)
offset += this.SimplyOffset.positiveOffset;
if (offset > 0) {
let pts = pl.GetStretchPoints();
pts = clipperCpp.lib.offsetToPaths({
delta: offset * 10000,
offsetInputs: [{ data: PathScale(pts, 10000), joinType: clipperLib.JoinType.Miter, endType: clipperLib.EndType.ClosedPolygon }]
})[0];
PathScale(pts, 0.0001);
return pts;
}
else
return this.Points;
}
}
GetInsidePoints() {
if (this.Curve instanceof exports.Circle) {
let pts = Circle2Points(this.Curve, this.KnifRadius, 10, false);
return pts;
}
else {
let pl = this.SimplyPolyline || this.Curve;
let offset = -this.KnifRadius;
if (this.SimplyOffset) {
offset += this.SimplyOffset.negativeOffset;
}
if (offset < -0.01) {
let pls = pl.GetOffsetCurves(offset);
if (pls.length)
return pls[0].GetStretchPoints();
}
else
return this.Points;
}
}
}
exports.BUL_IS_LINE_FUZZ = BUL_IS_LINE_FUZZ; exports.BUL_IS_LINE_FUZZ = BUL_IS_LINE_FUZZ;
exports.CADFiler = CADFiler; exports.CADFiler = CADFiler;
exports.Circle2Points = Circle2Points; exports.Circle2Points = Circle2Points;
@@ -22977,6 +23124,7 @@ exports.ComputeBiarc = ComputeBiarc;
exports.Contour = Contour; exports.Contour = Contour;
exports.ConverToPolylineAndSplitArc = ConverToPolylineAndSplitArc; exports.ConverToPolylineAndSplitArc = ConverToPolylineAndSplitArc;
exports.CurveContainerCurve = CurveContainerCurve; exports.CurveContainerCurve = CurveContainerCurve;
exports.CurveWrap = CurveWrap;
exports.Curves2Points = Curves2Points; exports.Curves2Points = Curves2Points;
exports.FeedingToolPath = FeedingToolPath; exports.FeedingToolPath = FeedingToolPath;
exports.IsPtsAllOutOrOnReg = IsPtsAllOutOrOnReg; exports.IsPtsAllOutOrOnReg = IsPtsAllOutOrOnReg;

File diff suppressed because one or more lines are too long

View File

@@ -22900,11 +22900,9 @@ function Polyline2Points(pl, outside, knifeRadius) {
let bul = pl.GetBulgeAt(i); let bul = pl.GetBulgeAt(i);
if (bul !== 0) { if (bul !== 0) {
let arc = pl.GetCurveAtIndex(i); let arc = pl.GetCurveAtIndex(i);
//小圆弧内嵌时忽略小圆(直线连接) // //小圆弧内嵌时忽略小圆(直线连接) 有可能产生自交 放弃这个
if (!outside && arc.Radius < 30 && bul > 0) // if (!outside && arc.Radius < 30 && bul > 0) continue;
continue; // if (outside && arc.Radius < 30 && bul < 0) continue;
if (outside && arc.Radius < 30 && bul < 0)
continue;
let allAngle = arc.AllAngle; let allAngle = arc.AllAngle;
let arcLength = arc.Length; let arcLength = arc.Length;
let minCount = Math.floor(allAngle * 4 / Math.PI); let minCount = Math.floor(allAngle * 4 / Math.PI);
@@ -22934,32 +22932,181 @@ function Polyline2Points(pl, outside, knifeRadius) {
return [pl, pts]; return [pl, pts];
} }
/** /**
* 移除小圆弧,使用尖角直连 * 移除小圆弧,使用尖角直连(有可能产生自交 概率不大)
* @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个) * @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个)
* @param [radius=30] * @param [radius=30]
*/ */
function PolylineFilletMinArc(pl, radius = 30) { function PolylineFilletMinArc(pl, radius = 30) {
let ocsInv = pl.OCSInv; let ocsInv = pl.OCSInv;
for (let i = 0; i < pl.LineData.length; i++) { for (let i = 0; i < pl.EndParam; i++) {
let bul = pl.LineData[i].bul; let bul = pl.LineData[i].bul;
if (equaln(bul, BUL_IS_LINE_FUZZ)) if (equaln(bul, BUL_IS_LINE_FUZZ))
continue; continue;
let arc = pl.GetCurveAtIndex(i); let arc = pl.GetCurveAtIndex(i);
if (arc.Radius > radius) if (arc.Radius > radius)
continue; continue;
let preCurve = pl.GetCurveAtIndex(FixIndex(i - 1, pl.LineData)); let preCurve = pl.GetCurveAtIndex(FixIndex(i - 1, pl.EndParam));
if (!(preCurve instanceof Line)) if (!(preCurve instanceof Line))
continue; continue;
let nextCurve = pl.GetCurveAtIndex(FixIndex(i + 1, pl.LineData)); let nextCurve = pl.GetCurveAtIndex(FixIndex(i + 1, pl.EndParam));
if (!(nextCurve instanceof Line)) if (!(nextCurve instanceof Line))
continue; continue;
if (preCurve.IntersectWith2(arc, IntersectOption.ExtendThis).length === 2) if (preCurve.IntersectWith2(arc, IntersectOption.ExtendThis).length === 2)
continue; continue;
let ipt = nextCurve.IntersectWith(preCurve, IntersectOption.ExtendBoth)[0]; let ipt = nextCurve.IntersectWith(preCurve, IntersectOption.ExtendBoth)[0];
if (!ipt)
continue;
if (ipt.distanceTo(arc.Midpoint) > 50)
continue;
pl.LineData.splice(i, 1); pl.LineData.splice(i, 1);
pl.SetPointAt(i, ipt.applyMatrix4(ocsInv)); pl.SetPointAt(i, ipt.applyMatrix4(ocsInv));
} }
} }
export { Arc, BUL_IS_LINE_FUZZ, BoolOpeartionType, CADFiler, Circle, Circle2Points, ComputeBiarc, Contour, ConverToPolylineAndSplitArc, CurveContainerCurve, Curves2Points, FeedingToolPath, IsPtsAllOutOrOnReg, IsRect, Line, ParseRegionTextPos, PointsSimplify2PolylineAndParseArc, Polyline, Polyline2Points, PolylineFilletMinArc, Production, Shape, ShapeManager, SmartPointsSimply2Polyline, SmartPolylineSimply2Polyline, SplineConver2Polyline, TEXT_BOX, TempPolyline, VData2Curve, VKnifToolPath, fastCurveInCurve2, isTargetCurInOrOnSourceCur }; /** 点p到线段P1P2 的最短距离的平方,线段不延伸 */
function GetSqSegDist(p, p1, p2) {
let x = p1.x;
let y = p1.y;
let dx = p2.x - x;
let dy = p2.y - y;
if (dx !== 0 || dy !== 0) //不是0长度线
{
let t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
if (t > 1) {
x = p2.x;
y = p2.y;
}
else if (t > 0) {
x += dx * t;
y += dy * t;
}
}
dx = p.x - x;
dy = p.y - y;
return dx * dx + dy * dy;
}
function CrossVector2(a, b) {
return a.x * b.y - a.y * b.x;
}
//Ramer-Douglas-Peucker algorithm
function SimplifyDPStep(points, first, last, sqTolerance, simplified, offset) {
let maxSqDist = 0;
let index;
let fp = points[first];
let lp = points[last];
for (let i = first + 1; i < last; i++) {
let p = points[i];
let sqDist = GetSqSegDist(p, fp, lp);
if (sqDist > maxSqDist) {
index = i;
maxSqDist = sqDist;
}
}
if (maxSqDist > sqTolerance) {
if (index - first > 1)
SimplifyDPStep(points, first, index, sqTolerance, simplified, offset);
simplified.push(points[index]);
if (last - index > 1)
SimplifyDPStep(points, index, last, sqTolerance, simplified, offset);
}
else {
//记录偏移
let v = new Vector2(lp.x - fp.x, lp.y - fp.y).normalize();
for (let i = first + 1; i < last; i++) {
let p = points[i];
let offsetDist = -CrossVector2(v, { x: p.x - fp.x, y: p.y - fp.y });
offset.positiveOffset = Math.max(offset.positiveOffset, offsetDist);
offset.negativeOffset = Math.min(offset.negativeOffset, offsetDist);
}
}
}
// Ramer-Douglas-Peucker 算法
function SimplifyDouglasPeucker(points, sqTolerance) {
let last = points.length - 1;
let simplified = [points[0]];
let offset = { negativeOffset: 0, positiveOffset: 0 };
SimplifyDPStep(points, 0, last, sqTolerance, simplified, offset);
simplified.push(points[last]);
return [simplified, offset];
}
/**
* 运用此代码将曲线转换为点,并且精简它.
* @class CurveWrap
*/
class CurveWrap {
constructor(Curve, KnifRadius = 3, IsOutside = true) {
this.Curve = Curve;
this.KnifRadius = KnifRadius;
this.IsOutside = IsOutside;
this.Used = false;
this.Holes = [];
this.BoundingBox = Curve.BoundingBox;
if (Curve instanceof Polyline) {
let pts = Polyline2Points(Curve, IsOutside, 0)[1];
let [spts, offset] = SimplifyDouglasPeucker(pts, KnifRadius ** 2 + KnifRadius);
if (spts.length !== pts.length) {
this.SimplyOffset = offset;
this.SimplyPolyline = Path2Polyline(spts);
this.Curve = this.SimplyPolyline; //保险起见,也更新它
this.Area = this.SimplyPolyline.Area;
}
else //此处更新多段线
this.Curve = Path2Polyline(pts);
this.Points = spts;
}
if (this.Area === undefined)
this.Area = this.Curve.Area;
}
ContainsCurve(curve) {
if (this.SimplyPolyline)
return this.SimplyPolyline.PtInCurve(curve.Curve.StartPoint);
return this.Curve.PtInCurve(curve.Curve.StartPoint);
}
GetOutsidePoints() {
if (this.Curve instanceof Circle) {
let pts = Circle2Points(this.Curve, this.KnifRadius, 10, true);
return pts;
}
else {
let pl = this.SimplyPolyline || this.Curve;
let offset = this.KnifRadius;
if (this.SimplyOffset)
offset += this.SimplyOffset.positiveOffset;
if (offset > 0) {
let pts = pl.GetStretchPoints();
pts = clipperCpp.lib.offsetToPaths({
delta: offset * 10000,
offsetInputs: [{ data: PathScale(pts, 10000), joinType: JoinType.Miter, endType: EndType.ClosedPolygon }]
})[0];
PathScale(pts, 0.0001);
return pts;
}
else
return this.Points;
}
}
GetInsidePoints() {
if (this.Curve instanceof Circle) {
let pts = Circle2Points(this.Curve, this.KnifRadius, 10, false);
return pts;
}
else {
let pl = this.SimplyPolyline || this.Curve;
let offset = -this.KnifRadius;
if (this.SimplyOffset) {
offset += this.SimplyOffset.negativeOffset;
}
if (offset < -0.01) {
let pls = pl.GetOffsetCurves(offset);
if (pls.length)
return pls[0].GetStretchPoints();
}
else
return this.Points;
}
}
}
export { Arc, BUL_IS_LINE_FUZZ, BoolOpeartionType, CADFiler, Circle, Circle2Points, ComputeBiarc, Contour, ConverToPolylineAndSplitArc, CurveContainerCurve, CurveWrap, Curves2Points, DuplicateRecordCloning, FeedingToolPath, IsPtsAllOutOrOnReg, IsRect, Line, ParseRegionTextPos, PointsSimplify2PolylineAndParseArc, Polyline, Polyline2Points, PolylineFilletMinArc, Production, Shape, ShapeManager, SmartPointsSimply2Polyline, SmartPolylineSimply2Polyline, SplineConver2Polyline, Status, TEXT_BOX, TempPolyline, UpdateDraw, VData2Curve, VKnifToolPath, fastCurveInCurve2, isTargetCurInOrOnSourceCur };
//# sourceMappingURL=api.esm.js.map //# sourceMappingURL=api.esm.js.map

File diff suppressed because one or more lines are too long

View File

@@ -168,9 +168,6 @@ export declare class Board extends ExtrudeSolid {
private _async2DPathIng; private _async2DPathIng;
GoodBye(): void; GoodBye(): void;
HandleSpliteEntitys(splitEntitys: this[]): void; HandleSpliteEntitys(splitEntitys: this[]): void;
InitDrawObject(renderType?: RenderType): Object3D;
UpdateDrawObject(renderType: RenderType, obj: Object3D): Object3D;
private DrawAsyncText;
private get PlaceColor(); private get PlaceColor();
private GetPlaceFace; private GetPlaceFace;
private GetBigHoleFace; private GetBigHoleFace;

File diff suppressed because one or more lines are too long

26
types/Nest/Converter/CurveWrap.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
import { Box3 } from "three";
import { Circle } from "../../DatabaseServices/Entity/Circle";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { Point } from "../Common/Point";
import { IOffset } from "./Simplify2";
/**
* 运用此代码将曲线转换为点,并且精简它.
* @class CurveWrap
*/
export declare class CurveWrap {
Curve: Polyline | Circle;
KnifRadius: number;
IsOutside: boolean;
BoundingBox: Box3;
Area: number;
SimplyPolyline: Polyline;
SimplyOffset: IOffset;
Used: boolean;
Holes: CurveWrap[];
Points: Point[];
constructor(Curve: Polyline | Circle, KnifRadius?: number, IsOutside?: boolean);
ContainsCurve(curve: CurveWrap): boolean;
GetOutsidePoints(): Point[];
GetInsidePoints(): Point[];
}
//# sourceMappingURL=CurveWrap.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CurveWrap.d.ts","sourceRoot":"","sources":["../../../../src/Nest/Converter/CurveWrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,OAAO,EAAE,OAAO,EAA0B,MAAM,aAAa,CAAC;AAG9D;;;GAGG;AACH,qBAAa,SAAS;IAaC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAAS,UAAU;IAAa,SAAS,EAAE,OAAO;IAX7F,WAAW,EAAE,IAAI,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;IAEb,cAAc,EAAE,QAAQ,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,UAAS;IACb,KAAK,EAAE,SAAS,EAAE,CAAM;IAExB,MAAM,EAAE,KAAK,EAAE,CAAC;gBAEG,KAAK,EAAE,QAAQ,GAAG,MAAM,EAAS,UAAU,SAAI,EAAS,SAAS,GAAE,OAAc;IAwBpG,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAOxC,gBAAgB,IAAI,KAAK,EAAE;IA+B3B,eAAe,IAAI,KAAK,EAAE;CA2B7B"}

View File

@@ -9,7 +9,7 @@ export declare function Circle2Points(circle: Circle, knifRadius: number, splitS
export declare function Curves2Points(cu: Circle | Polyline, outside: boolean, knifeRadius: number): [(Circle | Polyline), Point[]]; export declare function Curves2Points(cu: Circle | Polyline, outside: boolean, knifeRadius: number): [(Circle | Polyline), Point[]];
export declare function Polyline2Points(pl: Polyline, outside: boolean, knifeRadius: number): [Polyline, Point[]]; export declare function Polyline2Points(pl: Polyline, outside: boolean, knifeRadius: number): [Polyline, Point[]];
/** /**
* 移除小圆弧,使用尖角直连 * 移除小圆弧,使用尖角直连(有可能产生自交 概率不大)
* @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个) * @param pl 请传入逆时针多段线(我们将直接修改这个多段线,如果你不想被修改 你应该拷贝一个)
* @param [radius=30] * @param [radius=30]
*/ */

View File

@@ -1 +1 @@
{"version":3,"file":"Curves2Points.d.ts","sourceRoot":"","sources":["../../../../src/Nest/Converter/Curves2Points.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAE9D,OAAO,EAAoB,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAIpF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,aAAa;AACb,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,SAAK,EAAE,OAAO,UAAQ,GAAG,KAAK,EAAE,CAiB1G;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAM1H;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAqDxG;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAK,QAyB7D"} {"version":3,"file":"Curves2Points.d.ts","sourceRoot":"","sources":["../../../../src/Nest/Converter/Curves2Points.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAE9D,OAAO,EAAoB,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAIpF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,aAAa;AACb,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,SAAK,EAAE,OAAO,UAAQ,GAAG,KAAK,EAAE,CAiB1G;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAM1H;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAqDxG;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAK,QA6B7D"}

11
types/Nest/Converter/Simplify2.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
interface P {
x: number;
y: number;
}
export interface IOffset {
negativeOffset: number;
positiveOffset: number;
}
export declare function SimplifyDouglasPeucker(points: P[], sqTolerance: number): [P[], IOffset];
export {};
//# sourceMappingURL=Simplify2.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Simplify2.d.ts","sourceRoot":"","sources":["../../../../src/Nest/Converter/Simplify2.ts"],"names":[],"mappings":"AAEA,UAAU,CAAC;IAEP,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,OAAO;IAEpB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CAC1B;AA0ED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAQvF"}

2
types/api.d.ts vendored
View File

@@ -15,4 +15,6 @@ export * from "./DatabaseServices/Contour";
export * from "./DatabaseServices/Shape"; export * from "./DatabaseServices/Shape";
export * from "./DatabaseServices/ShapeManager"; export * from "./DatabaseServices/ShapeManager";
export * from "./Nest/Converter/Curves2Points"; export * from "./Nest/Converter/Curves2Points";
export * from "./Nest/Converter/CurveWrap";
export * from "./Common/Status";
//# sourceMappingURL=api.d.ts.map //# sourceMappingURL=api.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,cAAc,yCAAyC,CAAC;AACxD,cAAc,sBAAsB,CAAC;AACrC,cAAc,wCAAwC,CAAC;AACvD,cAAc,yDAAyD,CAAC;AACxE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAGhD,cAAc,gCAAgC,CAAC"} {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,cAAc,yCAAyC,CAAC;AACxD,cAAc,sBAAsB,CAAC;AACrC,cAAc,wCAAwC,CAAC;AACvD,cAAc,yDAAyD,CAAC;AACxE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAGhD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC"}