修复圆相交bug,修改轮廓切割代码

pull/68/head
Zoe 6 years ago
parent 59551723dd
commit 8c75bf0427

@ -60,15 +60,7 @@ Array [
]
`;
exports[`三维空间圆圆相交测试 5`] = `
Array [
Vector3 {
"x": 2.5,
"y": 0,
"z": 0,
},
]
`;
exports[`三维空间圆圆相交测试 5`] = `Array []`;
exports[`三维空间直线和圆相交测试 1`] = `
Array [

@ -41,17 +41,6 @@ export class Test implements Command
//将多段线转换为cad图形
async exec()
{
let ssResx = await app.m_Editor.GetSelection();
if (ssResx.Status == PromptStatus.OK)
{
let cus = ssResx.SelectSet.SelectEntityList as Curve[];
new LinkSelf(cus);
return;
}
// let d = [["Polyline", 1, 1, 12839, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 24, [256.5228611988947, -38.705370748164505], 0, [372.1955588024039, 31.844231195771492], 0, [372.1955588024039, -31.54297461172431], 0, [450.9819163032461, 37.57414810492366], 0, [423.0485713711294, -54.10452244151095], 0, [589.216161736542, 52.97329979827009], 0, [611.0614699526845, -2.177150452319474], 0, [672.6580767260702, 61.21005535517633], 0, [678.0298738284004, 13.938240854670997], 0, [735.329042919922, 21.100636991111184], 0, [684.1179105443746, -21.515620020708024], 0, [730.6734854312358, -32.61733403219032], 0, [815.1897598412304, 38.29038771856768], 0, [835.6025888300849, -8.981426781937659], 0, [862.1034545349137, 74.4604882075907], 0, [943.4539498526012, 74.46048820759069], 0, [986.972668777612, -29.064785548515978], 0, [924.5022496755805, -66.26627108118637], 0, [1001.0109652050348, -106.27541589934134], 0, [965.9152241364777, -128.73669018321777], 0, [1006.6262837760039, -176.46689803645526], 0, [904.1467198558175, -189.8032796425069], 0, [981.3573502066429, -242.44689124534239], 0, [1004.5205393118904, -256.48518767276516], 0, false]]
// let cadf = new CADFile();

@ -5,8 +5,9 @@ import { Ellipse } from '../DatabaseServices/Ellipse';
import { Polyline } from '../DatabaseServices/Polyline';
import { IntersectOption } from './IntersectWith';
import { app } from '../ApplicationServices/Application';
import { equal } from '../Geometry/GeUtils';
import { equal, equaln } from '../Geometry/GeUtils';
import { Line } from '../DatabaseServices/Line';
import { Arc } from '../DatabaseServices/Arc';
export enum BoolOpeartionType
{
@ -38,7 +39,7 @@ function getIntPtContextPts(sourceCur: Curve, cu: Curve, pts: Vector3[])
pars.forEach(par =>
{
par >= 0.02 && pts.push(cu.GetPointAtParam(par - 0.01));
par <= (cu.EndParam - 0.01) && pts.push(cu.GetPointAtParam(par + 0.01));
par <= (cu.EndParam - 0.02) && pts.push(cu.GetPointAtParam(par + 0.01));
})
}
@ -75,27 +76,52 @@ function IsPtsAllOutOrOnReg(sourceReg: Polyline | Circle | Ellipse, pts: Vector3
}
// 判断曲线在封闭区域上
export function isTargetCurOnSourceCur(sourceCur: Polyline | Circle | Ellipse, targetCur: Curve)
export function TargetCurPosForSourceCur(sourceCur: Polyline | Circle | Ellipse, targetCur: Arc | Line)
{
let cus: Curve[];
if (targetCur instanceof Polyline)
{
cus = targetCur.Explode();
} else
cus = [targetCur];
let inSrc = false;
let outSrc = false;
let onSrc = false;
let throughSrc = false;
return cus.every(cu =>
let pts = targetCur.IntersectWith(sourceCur, IntersectOption.OnBothOperands);
if (pts.length === 0)
{
let pts = cu.IntersectWith(sourceCur, IntersectOption.OnBothOperands);
if (pts.length >= 2)
onSrc = sourceCur.PtOnCurve(targetCur.StartPoint);
inSrc = !onSrc && sourceCur.PtInCurve(targetCur.StartPoint);
outSrc = !inSrc;
}
else
{
if (cu instanceof Line)
let caclPts = [];
let pars = pts.map(pt => targetCur.GetParamAtPoint(pt));
let noStartI = pars.findIndex(v => equaln(v, 0, 1e-6)) === -1;
let noEndI = pars.findIndex(v => equaln(v, 1, 1e-6)) === -1;
pars.forEach(par =>
{
let pars = pts.map(p => sourceCur.GetParamAtPoint(p)).sort((a, b) => a - b);
let tmpCu = (sourceCur as Polyline).GetCurveAtParam(Math.floor(pars[0]));
return pts.every(p => tmpCu.PtOnCurve(p))
par > 0.01 && caclPts.push(targetCur.GetPointAtParam(par - 0.01));
par < (targetCur.EndParam - 0.01) && caclPts.push(targetCur.GetPointAtParam(par + 0.01));
})
if (noStartI) caclPts.push(targetCur.StartPoint);
if (noEndI) caclPts.push(targetCur.EndPoint);
// caclPts.forEach(p =>
// {
// let c = new Circle(p, 0.5);
// c.ColorIndex = 2;
// app.m_Database.ModelSpace.Append(c);
// })
onSrc = caclPts.every(pt => sourceCur.PtOnCurve(pt));
if (!onSrc)
{
let hasInCur = caclPts.some(p => sourceCur.PtInCurve(p));
let hasOutCur = caclPts.some(p => !sourceCur.PtInCurve(p) && !sourceCur.PtOnCurve(p));
throughSrc = hasInCur && hasOutCur;
inSrc = hasInCur && !hasOutCur;
outSrc = hasOutCur && !hasInCur;
}
}
} else return false;
})
return { inSrc, onSrc, outSrc, throughSrc, pts };
}

@ -1,4 +1,4 @@
import { Vector3 } from 'three';
import { Vector3, EquirectangularReflectionMapping } from 'three';
import { getDeterminantFor3V } from '../Common/CurveUtils';
import { Arc } from '../DatabaseServices/Arc';
import { Circle } from '../DatabaseServices/Circle';
@ -77,6 +77,7 @@ export function IntersectCircleAndCircle(cu1: Circle | Arc, cu2: Circle | Arc)
if (dist > (radius1 + radius2 + 1e-3))
return pts;
if (equaln(dist, 0, 1e-6)) return pts;
let dstsqr = dist * dist;
let r1sqr = radius1 * radius1;

@ -9,9 +9,10 @@ import { Curve } from "../DatabaseServices/Curve";
import { Line } from "../DatabaseServices/Line";
import { Polyline } from '../DatabaseServices/Polyline';
import { equal, equaln } from "../Geometry/GeUtils";
import { isTargetCurInOrOnSourceCur, isTargetCurOutOrOnSourceCur } from "./BoolOperateUtils";
import { isTargetCurInOrOnSourceCur, isTargetCurOutOrOnSourceCur, TargetCurPosForSourceCur } from "./BoolOperateUtils";
import { IntersectOption } from "./IntersectWith";
import { LinkSelf } from "./LinkSelft";
import { app } from "../ApplicationServices/Application";
interface offestRes
{
index: number,
@ -59,9 +60,8 @@ export class PolyOffestUtil
// app.m_Database.ModelSpace.Append(c.Outline);
// })
// console.time("trim");
let newPls = this.trimAndJointOffestPolyline(offres1, this.m_Polyline);
let newPls = this.trimAndJointOffestPolyline(offres1);
// console.timeEnd("trim");
// console.time("con");
let cus = this.trimByContours(newPls, contours);
// console.timeEnd("con");
@ -69,9 +69,12 @@ export class PolyOffestUtil
// console.time("link");
let rets = this.linkSelfingCurves2(cus);
// console.timeEnd('link');
if (!this.IsKeepAllCurves)
{
rets = this.optimizeCus(rets);
// console.time('k');
// rets = this.optimizeCus(rets);
// console.timeEnd('k');
}
return rets;
}
@ -84,14 +87,13 @@ export class PolyOffestUtil
*/
optimizeCus(rets: Polyline[])
{
if (rets.length <= 1) return rets;
if (this.m_Polyline.IsClose)
{
return rets.filter(l => l.IsClose)
}
else
{
if (rets.length <= 1) return rets;
let deleteCus: Set<Polyline> = new Set();
for (let i = 0; i < rets.length; i++)
@ -158,7 +160,7 @@ export class PolyOffestUtil
}
}
// 修剪连接相邻曲线
private trimAndJointOffestPolyline(offResList: offestRes[], originLine: Polyline)
private trimAndJointOffestPolyline(offResList: offestRes[])
{
offResList = offResList.filter(r => r.curve && !equaln(r.curve.Length, 0, 1e-6));
if (offResList.length <= 1)
@ -200,12 +202,17 @@ export class PolyOffestUtil
// 源线段对应索引
let startIndex = offResList[i].index;
let endIndex = offResList[FixIndex(i + 1, offResList)].index;
let isFillArc = endIndex - startIndex !== 1;
if (endIndex === 0)
{
endIndex = this.m_Polyline.EndParam - 1;
isFillArc = endIndex !== startIndex;
}
// 多段线交点数组
let interPts = frontLine.IntersectWith(laterLine, IntersectOption.ExtendBoth);
//如果有圆弧丢失或者没有交点,则用圆弧连接
if ((endIndex - startIndex !== 1 && i !== offResList.length - 1) || interPts.length === 0)
if (isFillArc || interPts.length === 0)
{
//偏移线段对应的源线段,取其起始点作为圆心
this.fillArc(startIndex, endIndex, nextPt, frontLine, laterLine, retPlList);
@ -408,26 +415,49 @@ export class PolyOffestUtil
let outline = c.Outline;
needCutCus.forEach(l =>
{
//在上面或者在外面
if (isTargetCurOutOrOnSourceCur(outline, l))
let posSrcForTar = TargetCurPosForSourceCur(outline, l as Arc | Line);
if (posSrcForTar.throughSrc)
{
let par = posSrcForTar.pts.map(p => l.GetParamAtPoint(p));
let cus = l.GetSplitCurves(par);
if (cus.length === 0)
{
tmpCus.push(l);
} else
{
tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && isTargetCurOutOrOnSourceCur(outline, cu)));
}
}
else if (!isTargetCurInOrOnSourceCur(outline, l))
else if (posSrcForTar.onSrc || posSrcForTar.outSrc)
{
let pts = l.IntersectWith(outline, IntersectOption.OnBothOperands);
if (pts.length > 0)
tmpCus.push(l);
} else
{
let par = pts.map(p => l.GetParamAtPoint(p));
let cus = l.GetSplitCurves(par);
l instanceof Arc && tmpCus.push(l);
}
if (cus.length > 0)
tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && !isTargetCurInOrOnSourceCur(outline, cu)));
else
tmpCus.push(l);
// 在上面或者在外面
// if (isTargetCurOutOrOnSourceCur(outline, l))
// {
// tmpCus.push(l);
// }
// else
// {
// let pts = l.IntersectWith(outline, IntersectOption.OnBothOperands);
// if (pts.length > 0)
// {
// let par = pts.map(p => l.GetParamAtPoint(p));
// let cus = l.GetSplitCurves(par);
}
}
// if (cus.length > 0)
// tmpCus.push(...cus.filter(cu => !equaln(cu.Length, 0, 1e-6) && !isTargetCurInOrOnSourceCur(outline, cu)));
// else
// {
// tmpCus.push(l);
// }
// }
// }
})
needCutCus = tmpCus;
})

Loading…
Cancel
Save