开发:同步偏移算法,Ver:0.0.4

This commit is contained in:
ChenX 2020-09-28 15:56:59 +08:00
parent 0614d66225
commit e4827ba295
3 changed files with 114 additions and 89 deletions

8
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,8 @@
//
{
"typescript.tsdk": "node_modules\\typescript\\lib",
//
"editor.tabSize": 4,
"editor.formatOnPaste": false,
"editor.formatOnSave": false,
}

View File

@ -1534,7 +1534,8 @@ let Entity = Entity_1 = class Entity extends CADObject
if (!this.IsEmbedEntity) if (!this.IsEmbedEntity)
this._drawObject.userData.Entity = this; this._drawObject.userData.Entity = this;
if (this.IsVisible) { if (this.IsVisible) {
let obj = this.GetDrawObjectFromRenderType((_a = this.__CacheRenderType__) !== null && _a !== void 0 ? _a : userConfig.RenderType); this._CurRenderType = (_a = this.__CacheRenderType__) !== null && _a !== void 0 ? _a : userConfig.RenderType;
let obj = this.GetDrawObjectFromRenderType(this._CurRenderType);
if (obj) if (obj)
this._drawObject.add(obj); this._drawObject.add(obj);
} }
@ -1561,12 +1562,15 @@ let Entity = Entity_1 = class Entity extends CADObject
} }
UpdateRenderType(type) UpdateRenderType(type)
{ {
if ((this.OnlyRenderType && this.DrawObject.children.length > 0) || !this.Visible) if (this._CurRenderType !== type) {
return; this._CurRenderType = type;
Object3DRemoveAll(this.DrawObject); if ((this.OnlyRenderType && this.DrawObject.children.length > 0) || !this.Visible)
let obj = this.GetDrawObjectFromRenderType(type); return;
if (obj) Object3DRemoveAll(this.DrawObject);
this.DrawObject.add(obj); let obj = this.GetDrawObjectFromRenderType(type);
if (obj)
this.DrawObject.add(obj);
}
} }
GetDrawObjectFromRenderType(renderType = RenderType.Wireframe) GetDrawObjectFromRenderType(renderType = RenderType.Wireframe)
{ {
@ -1645,7 +1649,8 @@ let Entity = Entity_1 = class Entity extends CADObject
this.UpdateDrawObjectMaterial(type, obj); this.UpdateDrawObjectMaterial(type, obj);
if (mode & UpdateDraw.Matrix || mode & UpdateDraw.Geometry) { if (mode & UpdateDraw.Matrix || mode & UpdateDraw.Geometry) {
obj.updateMatrixWorld(true); obj.updateMatrixWorld(true);
obj.traverse(UpdateBoundingSphere); if (this.Id) //如果这个是Jig实体,那么我们更新这个盒子球似乎也没有意义
obj.traverse(UpdateBoundingSphere);
} }
} }
this.NeedUpdateFlag = UpdateDraw.None; this.NeedUpdateFlag = UpdateDraw.None;
@ -1794,6 +1799,7 @@ let Entity = Entity_1 = class Entity extends CADObject
Clone() Clone()
{ {
let ent = super.Clone(); let ent = super.Clone();
ent._CurRenderType = this._CurRenderType;
ent.Template = undefined; ent.Template = undefined;
ent.CloneDrawObject(this); ent.CloneDrawObject(this);
return ent; return ent;
@ -1817,6 +1823,9 @@ let Entity = Entity_1 = class Entity extends CADObject
{ {
return this.__ReadFileIng__ || Entity_1.__ReadFileIng__; return this.__ReadFileIng__ || Entity_1.__ReadFileIng__;
} }
/**
* 从文件读取,序列化自身,如果需要,重载_ReadFile
*/
ReadFile(file) ReadFile(file)
{ {
this.__ReadFileIng__ = true; this.__ReadFileIng__ = true;
@ -4752,17 +4761,17 @@ let Arc = Arc_1 = class Arc extends Curve
/** /**
* 曲线为顺时针 * 曲线为顺时针
*/ */
this.m_Clockwise = true; this._Clockwise = true;
this._Matrix.setPosition(center); this._Matrix.setPosition(center);
this.m_Radius = radius; this._Radius = radius;
this.m_StartAngle = clampRad(startAngle); this._StartAngle = clampRad(startAngle);
this.m_EndAngle = clampRad(endAngle); this._EndAngle = clampRad(endAngle);
this.m_Clockwise = clockwise; this._Clockwise = clockwise;
} }
get Shape() get Shape()
{ {
let sp = new Shape(); let sp = new Shape();
sp.absarc(0, 0, this.m_Radius, this.m_StartAngle, this.m_EndAngle, this.m_Clockwise); sp.absarc(0, 0, this._Radius, this._StartAngle, this._EndAngle, this._Clockwise);
return sp; return sp;
} }
get Center() get Center()
@ -4790,7 +4799,7 @@ let Arc = Arc_1 = class Arc extends Curve
//获得曲线的面积,逆时针为正,顺时针为负. //获得曲线的面积,逆时针为正,顺时针为负.
get Area2() get Area2()
{ {
let clockwise = this.m_Clockwise ? -1 : 1; let clockwise = this._Clockwise ? -1 : 1;
return 0.5 * this.AllAngle * this.Radius * this.Radius * clockwise; return 0.5 * this.AllAngle * this.Radius * this.Radius * clockwise;
} }
get IsClose() get IsClose()
@ -4802,10 +4811,10 @@ let Arc = Arc_1 = class Arc extends Curve
let pts = [this.StartPoint, this.EndPoint]; let pts = [this.StartPoint, this.EndPoint];
//TODO:考虑三维圆弧. //TODO:考虑三维圆弧.
let addPts = [ let addPts = [
this.Center.add(new Vector3(this.m_Radius, 0)), this.Center.add(new Vector3(this._Radius, 0)),
this.Center.add(new Vector3(0, this.m_Radius)), this.Center.add(new Vector3(0, this._Radius)),
this.Center.add(new Vector3(-this.m_Radius, 0)), this.Center.add(new Vector3(-this._Radius, 0)),
this.Center.add(new Vector3(0, -this.m_Radius)), this.Center.add(new Vector3(0, -this._Radius)),
]; ];
addPts.forEach(p => addPts.forEach(p =>
{ {
@ -4816,50 +4825,50 @@ let Arc = Arc_1 = class Arc extends Curve
} }
get Radius() get Radius()
{ {
return this.m_Radius; return this._Radius;
} }
set Radius(v) set Radius(v)
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.m_Radius = v <= 0 ? 1e-19 : v; this._Radius = v <= 0 ? 1e-19 : v;
this.Update(); this.Update();
} }
get IsClockWise() get IsClockWise()
{ {
return this.m_Clockwise; return this._Clockwise;
} }
set IsClockWise(v) set IsClockWise(v)
{ {
if (v !== this.m_Clockwise) { if (v !== this._Clockwise) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.m_Clockwise = v; this._Clockwise = v;
this.Update(); this.Update();
} }
} }
get StartAngle() get StartAngle()
{ {
return this.m_StartAngle; return this._StartAngle;
} }
set StartAngle(v) set StartAngle(v)
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.m_StartAngle = v; this._StartAngle = v;
this.Update(); this.Update();
} }
get EndAngle() get EndAngle()
{ {
return this.m_EndAngle; return this._EndAngle;
} }
set EndAngle(v) set EndAngle(v)
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.m_EndAngle = v; this._EndAngle = v;
this.Update(); this.Update();
} }
//******************** Curve function start*****************// //******************** Curve function start*****************//
get StartPoint() get StartPoint()
{ {
return polar(new Vector3(), this.m_StartAngle, this.m_Radius).applyMatrix4(this.OCS); return polar(new Vector3(), this._StartAngle, this._Radius).applyMatrix4(this.OCS);
} }
set StartPoint(v) set StartPoint(v)
{ {
@ -4868,7 +4877,7 @@ let Arc = Arc_1 = class Arc extends Curve
} }
get EndPoint() get EndPoint()
{ {
return polar(new Vector3(), this.m_EndAngle, this.m_Radius).applyMatrix4(this.OCS); return polar(new Vector3(), this._EndAngle, this._Radius).applyMatrix4(this.OCS);
} }
set EndPoint(v) set EndPoint(v)
{ {
@ -4885,7 +4894,7 @@ let Arc = Arc_1 = class Arc extends Curve
} }
get Length() get Length()
{ {
return this.AllAngle * this.m_Radius; return this.AllAngle * this._Radius;
} }
GetParamAtPoint2(pt) GetParamAtPoint2(pt)
{ {
@ -4910,7 +4919,7 @@ let Arc = Arc_1 = class Arc extends Curve
let sp = this.StartPoint; let sp = this.StartPoint;
let ep = this.EndPoint; let ep = this.EndPoint;
reviseMirrorMatrix(this._Matrix); reviseMirrorMatrix(this._Matrix);
this.m_Clockwise = !this.m_Clockwise; this._Clockwise = !this._Clockwise;
this.StartPoint = sp; this.StartPoint = sp;
this.EndPoint = ep; this.EndPoint = ep;
return this; return this;
@ -4918,7 +4927,7 @@ let Arc = Arc_1 = class Arc extends Curve
GetPointAtParam(param) GetPointAtParam(param)
{ {
let an = this.GetAngleAtParam(param); let an = this.GetAngleAtParam(param);
return polar(new Vector3(), an, this.m_Radius).applyMatrix4(this.OCS); return polar(new Vector3(), an, this._Radius).applyMatrix4(this.OCS);
} }
GetPointAtDistance(distance) GetPointAtDistance(distance)
{ {
@ -4938,9 +4947,9 @@ let Arc = Arc_1 = class Arc extends Curve
} }
GetParamAtPoint(pt) GetParamAtPoint(pt)
{ {
if (this.m_Radius == 0 || if (this._Radius == 0 ||
this.AllAngle == 0 || this.AllAngle == 0 ||
!equaln(pt.distanceTo(this.Center), this.m_Radius, 1e-6)) !equaln(pt.distanceTo(this.Center), this._Radius, 1e-6))
return NaN; return NaN;
return this.GetParamAtAngle(this.GetAngleAtPoint(pt)); return this.GetParamAtAngle(this.GetAngleAtPoint(pt));
} }
@ -4961,14 +4970,12 @@ let Arc = Arc_1 = class Arc extends Curve
//减去圆弧角度,剩余角度的一半 //减去圆弧角度,剩余角度的一半
let surplusAngleHalf = Math.PI - allAn / 2; let surplusAngleHalf = Math.PI - allAn / 2;
if (ptAllAn > allAn + surplusAngleHalf) //返回负数 if (ptAllAn > allAn + surplusAngleHalf) //返回负数
{
return ((ptAllAn - allAn) - (surplusAngleHalf * 2)) / allAn; return ((ptAllAn - allAn) - (surplusAngleHalf * 2)) / allAn;
}
else //返回正数 else //返回正数
return ptAllAn / allAn; return ptAllAn / allAn;
} }
/** /**
* Gets param at angle2 * 根据角度获得参数,不过在这里我们可以指定我们是要获取前面的参数还是后面的参数(正负)
* @param an * @param an
* @param [isStart] true:返回负数false 返回正数 * @param [isStart] true:返回负数false 返回正数
* @returns * @returns
@ -4981,9 +4988,7 @@ let Arc = Arc_1 = class Arc extends Curve
//减去圆弧角度,剩余角度的一半 //减去圆弧角度,剩余角度的一半
let surplusAngleHalf = Math.PI - allAn / 2; let surplusAngleHalf = Math.PI - allAn / 2;
if (isStart) //返回负数 if (isStart) //返回负数
{
return ((ptAllAn - allAn) - (surplusAngleHalf * 2)) / allAn; return ((ptAllAn - allAn) - (surplusAngleHalf * 2)) / allAn;
}
else //返回正数 else //返回正数
return ptAllAn / allAn; return ptAllAn / allAn;
} }
@ -4994,7 +4999,7 @@ let Arc = Arc_1 = class Arc extends Curve
} }
GetAngleAtParam(param) GetAngleAtParam(param)
{ {
return clampRad(this.m_StartAngle + param * this.AllAngle * (this.m_Clockwise ? -1 : 1)); return clampRad(this._StartAngle + param * this.AllAngle * (this._Clockwise ? -1 : 1));
} }
GetSplitCurves(param) GetSplitCurves(param)
{ {
@ -5013,11 +5018,11 @@ let Arc = Arc_1 = class Arc extends Curve
} }
GetOffsetCurves(offsetDist) GetOffsetCurves(offsetDist)
{ {
if (this.m_Clockwise) if (this._Clockwise)
offsetDist *= -1; offsetDist *= -1;
if ((offsetDist + this.m_Radius) > 0) { if ((offsetDist + this._Radius) > 0) {
let arc = this.Clone(); let arc = this.Clone();
arc.Radius = offsetDist + this.m_Radius; arc.Radius = offsetDist + this._Radius;
return [arc]; return [arc];
} }
return []; return [];
@ -5026,33 +5031,33 @@ let Arc = Arc_1 = class Arc extends Curve
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
if (newParam < 0) { if (newParam < 0) {
this.m_StartAngle = this.GetAngleAtParam(newParam); this._StartAngle = this.GetAngleAtParam(newParam);
} }
else if (newParam > 1) { else if (newParam > 1) {
this.m_EndAngle = this.GetAngleAtParam(newParam); this._EndAngle = this.GetAngleAtParam(newParam);
} }
this.Update(); this.Update();
} }
Join(cu) Join(cu)
{ {
if (cu instanceof Arc_1) { if (cu instanceof Arc_1) {
if (equalv3(cu.Center, this.Center) && equaln(cu.m_Radius, this.m_Radius)) { if (equalv3(cu.Center, this.Center) && equaln(cu._Radius, this._Radius)) {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
let [sa, ea] = [cu.StartAngle, cu.EndAngle]; let [sa, ea] = [cu.StartAngle, cu.EndAngle];
if (cu.m_Clockwise != this.m_Clockwise) if (cu._Clockwise != this._Clockwise)
[sa, ea] = [ea, sa]; [sa, ea] = [ea, sa];
let allAn = this.AllAngle; let allAn = this.AllAngle;
let saAllan = this.ComputeAnlge(sa); let saAllan = this.ComputeAnlge(sa);
let eaAllan = this.ComputeAnlge(ea); let eaAllan = this.ComputeAnlge(ea);
if (equaln(sa, this.m_StartAngle)) //this起点对起点 if (equaln(sa, this._StartAngle)) //this起点对起点
{ {
if (eaAllan > allAn) if (eaAllan > allAn)
this.EndAngle = ea; this.EndAngle = ea;
return Status.True; return Status.True;
} }
else if (equaln(sa, this.m_EndAngle)) //this终点对起点 else if (equaln(sa, this._EndAngle)) //this终点对起点
{ {
if (eaAllan < allAn || equaln(ea, this.m_StartAngle)) if (eaAllan < allAn || equaln(ea, this._StartAngle))
return Status.ConverToCircle; return Status.ConverToCircle;
else else
this.EndAngle = ea; this.EndAngle = ea;
@ -5066,7 +5071,7 @@ let Arc = Arc_1 = class Arc extends Curve
this.StartAngle = sa; this.StartAngle = sa;
return Status.True; return Status.True;
} }
else if (equaln(ea, this.m_EndAngle)) //this终点对终点 else if (equaln(ea, this._EndAngle)) //this终点对终点
{ {
if (saAllan > allAn) if (saAllan > allAn)
this.StartAngle = sa; this.StartAngle = sa;
@ -5110,8 +5115,8 @@ let Arc = Arc_1 = class Arc extends Curve
Reverse() Reverse()
{ {
this.WriteAllObjectRecord(); this.WriteAllObjectRecord();
this.m_Clockwise = !this.m_Clockwise; this._Clockwise = !this._Clockwise;
[this.m_StartAngle, this.m_EndAngle] = [this.m_EndAngle, this.m_StartAngle]; [this._StartAngle, this._EndAngle] = [this._EndAngle, this._StartAngle];
return this; return this;
} }
IntersectWith2(curve, intType, tolerance = 1e-4) IntersectWith2(curve, intType, tolerance = 1e-4)
@ -5140,7 +5145,7 @@ let Arc = Arc_1 = class Arc extends Curve
*/ */
get AllAngle() get AllAngle()
{ {
return this.ComputeAnlge(this.m_EndAngle); return this.ComputeAnlge(this._EndAngle);
} }
get Bul() get Bul()
{ {
@ -5159,17 +5164,17 @@ let Arc = Arc_1 = class Arc extends Curve
ComputeAnlge(endAngle) ComputeAnlge(endAngle)
{ {
//顺时针 //顺时针
if (this.m_Clockwise) { if (this._Clockwise) {
if (this.m_StartAngle > endAngle) if (this._StartAngle > endAngle)
return this.StartAngle - endAngle; return this._StartAngle - endAngle;
else //越过0点绘制圆弧 else //越过0点绘制圆弧
return (Math.PI * 2) - (endAngle - this.m_StartAngle); return (Math.PI * 2) - (endAngle - this._StartAngle);
} }
else { else {
if (endAngle > this.m_StartAngle) if (endAngle > this._StartAngle)
return endAngle - this.m_StartAngle; return endAngle - this._StartAngle;
else else
return (Math.PI * 2) - (this.m_StartAngle - endAngle); return (Math.PI * 2) - (this._StartAngle - endAngle);
} }
} }
/** /**
@ -5197,17 +5202,17 @@ let Arc = Arc_1 = class Arc extends Curve
let allAngle = Math.atan(bul) * 4; let allAngle = Math.atan(bul) * 4;
let HalfAngle = allAngle * 0.5; let HalfAngle = allAngle * 0.5;
//半径 //半径
this.m_Radius = chordLengthHalf / Math.sin(HalfAngle); this._Radius = chordLengthHalf / Math.sin(HalfAngle);
//指向圆心的角度 //指向圆心的角度
let toCenterAn = chordAn + Math.PI * 0.5; //弦角度转90 let toCenterAn = chordAn + Math.PI * 0.5; //弦角度转90
//圆心 //圆心
let center = midPoint(p1, p2); let center = midPoint(p1, p2);
polar(center, toCenterAn, this.m_Radius - (bul * chordLengthHalf)); polar(center, toCenterAn, this._Radius - (bul * chordLengthHalf));
this.Center = center.clone().applyMatrix4(this.OCS); this.Center = center.clone().applyMatrix4(this.OCS);
this.m_Radius = Math.abs(this.m_Radius); this._Radius = Math.abs(this._Radius);
this.m_StartAngle = angle(p1.clone().sub(center)); this._StartAngle = angle(p1.clone().sub(center));
this.m_EndAngle = angle(p2.clone().sub(center)); this._EndAngle = angle(p2.clone().sub(center));
this.m_Clockwise = bul < 0; this._Clockwise = bul < 0;
return this; return this;
} }
FromThreePoint(pt1, pt2, pt3) FromThreePoint(pt1, pt2, pt3)
@ -5221,14 +5226,14 @@ let Arc = Arc_1 = class Arc extends Curve
let center = getCircleCenter(pt1, pt2, pt3); let center = getCircleCenter(pt1, pt2, pt3);
this.Center = center.clone().applyMatrix4(this.OCS); this.Center = center.clone().applyMatrix4(this.OCS);
//用圆心和其中一个点求距离得到半径: //用圆心和其中一个点求距离得到半径:
this.m_Radius = center.distanceTo(pt1); this._Radius = center.distanceTo(pt1);
//起始角度 端点角度 //起始角度 端点角度
this.m_StartAngle = angle(pt1.clone().sub(center)); this._StartAngle = angle(pt1.clone().sub(center));
this.m_EndAngle = angle(pt3.clone().sub(center)); this._EndAngle = angle(pt3.clone().sub(center));
//求出向量p1->p2,p1->p3 //求出向量p1->p2,p1->p3
let p1 = pt2.clone().sub(pt1); let p1 = pt2.clone().sub(pt1);
let p2 = pt3.clone().sub(pt1); let p2 = pt3.clone().sub(pt1);
this.m_Clockwise = p1.cross(p2).z < 0; this._Clockwise = p1.cross(p2).z < 0;
return this; return this;
} }
/** /**
@ -5354,9 +5359,9 @@ let Arc = Arc_1 = class Arc extends Curve
an = this.GetAngleAtParam(pt); an = this.GetAngleAtParam(pt);
else else
an = angle(pt.clone().applyMatrix4(this.OCSInv)); an = angle(pt.clone().applyMatrix4(this.OCSInv));
an += Math.PI * 0.5 * (this.m_Clockwise ? -1 : 1); an += Math.PI * 0.5 * (this._Clockwise ? -1 : 1);
let ocs = new Matrix4().extractRotation(this.OCS); let ocs = new Matrix4().extractRotation(this.OCS);
return polar(new Vector3(), an, this.m_Radius).applyMatrix4(ocs); return polar(new Vector3(), an, this._Radius).applyMatrix4(ocs);
} }
GetClosestPointTo(pt, extend) GetClosestPointTo(pt, extend)
{ {
@ -5377,20 +5382,20 @@ let Arc = Arc_1 = class Arc extends Curve
this.Center = new Vector3().fromArray(file.Read()); this.Center = new Vector3().fromArray(file.Read());
this.Normal = new Vector3().fromArray(file.Read()); this.Normal = new Vector3().fromArray(file.Read());
} }
this.m_Radius = file.Read(); this._Radius = file.Read();
this.m_StartAngle = file.Read(); this._StartAngle = file.Read();
this.m_EndAngle = file.Read(); this._EndAngle = file.Read();
this.m_Clockwise = file.Read(); this._Clockwise = file.Read();
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file) WriteFile(file)
{ {
super.WriteFile(file); super.WriteFile(file);
file.Write(2); file.Write(2);
file.Write(this.m_Radius); file.Write(this._Radius);
file.Write(this.m_StartAngle); file.Write(this._StartAngle);
file.Write(this.m_EndAngle); file.Write(this._EndAngle);
file.Write(this.m_Clockwise); file.Write(this._Clockwise);
} }
}; };
Arc = Arc_1 = __decorate([ Arc = Arc_1 = __decorate([
@ -6015,6 +6020,7 @@ function IsPtsAllInOrOnReg(sourceReg, pts)
} }
let cache = new WeakMap(); let cache = new WeakMap();
const COMBINE_FUZZ = 1e-2;
class Contour class Contour
{ {
SetCurve(cu) SetCurve(cu)
@ -6036,7 +6042,7 @@ class Contour
} }
return; return;
} }
let closeCurve = Contour.Combine(cus, needLink, 1e-2); let closeCurve = Contour.Combine(cus, needLink, COMBINE_FUZZ);
if (closeCurve && closeCurve.IsClose) { if (closeCurve && closeCurve.IsClose) {
if (closeCurve instanceof Polyline && closeCurve.CloseMark === false) { if (closeCurve instanceof Polyline && closeCurve.CloseMark === false) {
closeCurve.CloseMark = true; closeCurve.CloseMark = true;
@ -6187,7 +6193,7 @@ class Contour
let sourceOutline = this._Curve; let sourceOutline = this._Curve;
let targetOutline = target.Curve; let targetOutline = target.Curve;
let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3); let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3);
let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands); let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, COMBINE_FUZZ);
let sourceContainerTarget = this.CuInOutline(targetOutline); let sourceContainerTarget = this.CuInOutline(targetOutline);
let targetContainerSource = target.CuInOutline(sourceOutline); let targetContainerSource = target.CuInOutline(sourceOutline);
//包含.相交.分离(三种状态) //包含.相交.分离(三种状态)
@ -6252,7 +6258,7 @@ class Contour
let sourceOutline = this._Curve; let sourceOutline = this._Curve;
let targetOutline = target.Curve; let targetOutline = target.Curve;
let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3); let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3);
let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, 1e-3); let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, COMBINE_FUZZ);
if (interPts.length <= 1) { if (interPts.length <= 1) {
//反包含 //反包含
if (fastCurveInCurve2(targetOutline, sourceOutline) || equalCurve(targetOutline, sourceOutline)) if (fastCurveInCurve2(targetOutline, sourceOutline) || equalCurve(targetOutline, sourceOutline))
@ -6335,7 +6341,7 @@ class Contour
const targetOutline = con.Curve; const targetOutline = con.Curve;
if (!IntersectBox2(outBox, targetOutline.BoundingBox)) if (!IntersectBox2(outBox, targetOutline.BoundingBox))
continue; continue;
let pts = sourceOutline.IntersectWith2(con.Curve, IntersectOption.OnBothOperands, 1e-3); let pts = sourceOutline.IntersectWith2(con.Curve, IntersectOption.OnBothOperands, COMBINE_FUZZ);
if (pts.length <= 1) { if (pts.length <= 1) {
//反包含 //反包含
if (fastCurveInCurve2(targetOutline, sourceOutline) || equalCurve(targetOutline, sourceOutline)) if (fastCurveInCurve2(targetOutline, sourceOutline) || equalCurve(targetOutline, sourceOutline))
@ -6763,6 +6769,17 @@ class OffsetPolyline
cu2.StartPoint = d.sp; cu2.StartPoint = d.sp;
if (d.ep) if (d.ep)
cu2.EndPoint = d.ep; cu2.EndPoint = d.ep;
//这是极端情况,圆弧被压缩成0长度圆弧,本质是空圆弧(我们会在下面判断它)(因为精度的问题)
//因为精度的问题,这种0圆心角的圆弧会被当成全圆,但是偏移算法中,应该不可能出现全圆弧的圆弧,所以我们压扁它
if (cu2 instanceof Arc
&& equaln(cu2.StartAngle, cu2.EndAngle, 1e-6)
// && !equaln((<Arc>this._SubCurves[d.index]).AllAngle, Math.PI * 2, 1e-3) 应该不会出现
) {
if (cu2.IsClockWise)
cu2.StartAngle = cu2.EndAngle + 1e-6;
else
cu2.EndAngle = cu2.StartAngle + 1e-6;
}
} }
for (let d of this._SubOffsetedCurves) { for (let d of this._SubOffsetedCurves) {
let cu1 = this._SubCurves[d.index]; let cu1 = this._SubCurves[d.index];
@ -6817,7 +6834,7 @@ class OffsetPolyline
//真理2:隔壁的圆弧不可能破坏当前的圆弧,只能破坏当前的针脚 //真理2:隔壁的圆弧不可能破坏当前的圆弧,只能破坏当前的针脚
if (l1Intact && d.preArc && d.preArc instanceof Arc) { if (l1Intact && d.preArc && d.preArc instanceof Arc) {
let a = d.preArc; let a = d.preArc;
if (Math.sign(a.Bul) !== this._OffsetDistSign) { if (Math.sign(a.Bul) !== this._OffsetDistSign && a.AllAngle > 1e-6) {
let ipts = a.IntersectWith(l1, IntersectOption.OnBothOperands); let ipts = a.IntersectWith(l1, IntersectOption.OnBothOperands);
if (ipts.length === 2) { if (ipts.length === 2) {
let sp = SelectNearP(ipts, p1); let sp = SelectNearP(ipts, p1);
@ -6829,7 +6846,7 @@ class OffsetPolyline
} }
if (l2Intact && d.nextArc && d.nextArc instanceof Arc) { if (l2Intact && d.nextArc && d.nextArc instanceof Arc) {
let a = d.nextArc; let a = d.nextArc;
if (Math.sign(a.Bul) !== this._OffsetDistSign) { if (Math.sign(a.Bul) !== this._OffsetDistSign && a.AllAngle > 1e-6) {
let ipts = a.IntersectWith(l2, IntersectOption.OnBothOperands); let ipts = a.IntersectWith(l2, IntersectOption.OnBothOperands);
if (ipts.length === 2) { if (ipts.length === 2) {
let ep = SelectNearP(ipts, p3); let ep = SelectNearP(ipts, p3);

View File

@ -1,6 +1,6 @@
{ {
"name": "cadapi", "name": "cadapi",
"version": "0.0.3", "version": "0.0.4",
"description": "", "description": "",
"main": "api.esm.js", "main": "api.esm.js",
"module": "api.esm.js", "module": "api.esm.js",