优化当参数在端点的时候,不用构造子曲线.

pull/68/head
ChenX 6 years ago
parent 1504a9c9f1
commit 867fad00d2

@ -1,5 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`多段线 优化参数在端点上的时候 1`] = `
Vector3 {
"x": 0,
"y": 0,
"z": 0,
}
`;
exports[`多段线 最近点精度 1`] = ` exports[`多段线 最近点精度 1`] = `
Vector3 { Vector3 {
"x": 1.987500976448074, "x": 1.987500976448074,

@ -486,4 +486,16 @@ describe('多段线', () =>
expect(cp).toMatchSnapshot(); expect(cp).toMatchSnapshot();
}); });
test('优化参数在端点上的时候', () =>
{
let pl = new Polyline();
pl.AddVertexAt(0, new Vector2(0, 0));
pl.AddVertexAt(1, new Vector2(5, 0));
pl.AddVertexAt(2, new Vector2(5, 5));
pl.CloseMark = true;
let p = pl.GetPointAtParam(3);
expect(p).toMatchSnapshot();
});
}) })

@ -267,11 +267,11 @@ export class Polyline extends Curve
*/ */
GetPointAtParam(param: number): Vector3 GetPointAtParam(param: number): Vector3
{ {
if (param === Math.floor(param))
return Vec2DTo3D(this.GetPoint2dAt(FixIndex(param, this.NumberOfVertices))).applyMatrix4(this.OCS);
let cu: Curve = this.GetCurveAtParam(param); let cu: Curve = this.GetCurveAtParam(param);
if (cu) if (cu)
{
return cu.GetPointAtParam(this.GetCurveParamAtParam(param)); return cu.GetPointAtParam(this.GetCurveParamAtParam(param));
}
return undefined; return undefined;
} }

@ -12,7 +12,6 @@ import { equal, equaln } from "../Geometry/GeUtils";
import { EBox, SortEntityByBox } from "../Geometry/SortEntityByBox"; import { EBox, SortEntityByBox } from "../Geometry/SortEntityByBox";
import { IsPtsAllOutOrOnReg } from "./BoolOperateUtils"; import { IsPtsAllOutOrOnReg } from "./BoolOperateUtils";
import { IntersectOption } from "./IntersectWith"; import { IntersectOption } from "./IntersectWith";
import { testContours, testCurve } from "../Add-on/testEntity/TestCurve";
interface offestRes interface offestRes
{ {
@ -42,21 +41,16 @@ export class PolyOffestUtil
let expCus = this.m_Polyline.Explode(); let expCus = this.m_Polyline.Explode();
let offres = this.OffestCurve(expCus, this.m_OffestDist); let offres = this.OffestCurve(expCus, this.m_OffestDist);
// console.time("join") // console.time("join")
this.TrimAndBuildContour(offres); this.TrimAndBuildContour(offres);
for (let i = 0, count = this.m_Polyline.EndParam; i <= count; i++) for (let i = 0, count = this.m_Polyline.EndParam; i <= count; i++)
{ {
if (i === count && this.m_Polyline.IsClose) if (i === count && this.m_Polyline.IsClose)
{
break; break;
} let cir = new Circle(this.m_Polyline.GetPointAtParam(i), this.m_AbsDist);
let center = Vec2DTo3D(this.m_Polyline.GetPoint2dAt(i)).applyMatrix4(this.m_Polyline.OCS);
let cir = new Circle(center, this.m_AbsDist);
this.m_Contours.push(Contour.CreateContour([cir])); this.m_Contours.push(Contour.CreateContour([cir]));
} }
// testContours(this.m_Contours);
// console.timeEnd("join") // console.timeEnd("join")
//裁剪 //裁剪
let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves); let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves);

Loading…
Cancel
Save