From 867fad00d2797266e538014008afbe1e1a88cc1b Mon Sep 17 00:00:00 2001 From: ChenX Date: Thu, 21 Jun 2018 17:10:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BD=93=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=9C=A8=E7=AB=AF=E7=82=B9=E7=9A=84=E6=97=B6=E5=80=99,?= =?UTF-8?q?=E4=B8=8D=E7=94=A8=E6=9E=84=E9=80=A0=E5=AD=90=E6=9B=B2=E7=BA=BF?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Polyline/__snapshots__/polyline.test.ts.snap | 8 ++++++++ __test__/Polyline/polyline.test.ts | 12 ++++++++++++ src/DatabaseServices/Polyline.ts | 4 ++-- src/GraphicsSystem/OffestPolyline.ts | 8 +------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/__test__/Polyline/__snapshots__/polyline.test.ts.snap b/__test__/Polyline/__snapshots__/polyline.test.ts.snap index 6151674be..738e3f058 100644 --- a/__test__/Polyline/__snapshots__/polyline.test.ts.snap +++ b/__test__/Polyline/__snapshots__/polyline.test.ts.snap @@ -1,5 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`多段线 优化参数在端点上的时候 1`] = ` +Vector3 { + "x": 0, + "y": 0, + "z": 0, +} +`; + exports[`多段线 最近点精度 1`] = ` Vector3 { "x": 1.987500976448074, diff --git a/__test__/Polyline/polyline.test.ts b/__test__/Polyline/polyline.test.ts index 0c7cd6552..c726e0371 100644 --- a/__test__/Polyline/polyline.test.ts +++ b/__test__/Polyline/polyline.test.ts @@ -486,4 +486,16 @@ describe('多段线', () => 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(); + }); }) diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 9e5e9408b..86c4576b5 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -267,11 +267,11 @@ export class Polyline extends Curve */ 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); if (cu) - { return cu.GetPointAtParam(this.GetCurveParamAtParam(param)); - } return undefined; } diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index 22d108009..00e067d41 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -12,7 +12,6 @@ import { equal, equaln } from "../Geometry/GeUtils"; import { EBox, SortEntityByBox } from "../Geometry/SortEntityByBox"; import { IsPtsAllOutOrOnReg } from "./BoolOperateUtils"; import { IntersectOption } from "./IntersectWith"; -import { testContours, testCurve } from "../Add-on/testEntity/TestCurve"; interface offestRes { @@ -42,21 +41,16 @@ export class PolyOffestUtil let expCus = this.m_Polyline.Explode(); let offres = this.OffestCurve(expCus, this.m_OffestDist); - // console.time("join") this.TrimAndBuildContour(offres); for (let i = 0, count = this.m_Polyline.EndParam; i <= count; i++) { if (i === count && this.m_Polyline.IsClose) - { break; - } - let center = Vec2DTo3D(this.m_Polyline.GetPoint2dAt(i)).applyMatrix4(this.m_Polyline.OCS); - let cir = new Circle(center, this.m_AbsDist); + let cir = new Circle(this.m_Polyline.GetPointAtParam(i), this.m_AbsDist); this.m_Contours.push(Contour.CreateContour([cir])); } - // testContours(this.m_Contours); // console.timeEnd("join") //裁剪 let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves);