From ccfaf505003f19ce8710f83480494d7ba1343ec5 Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 4 Aug 2023 12:24:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E5=88=A4=E6=96=AD=E7=9F=A9?= =?UTF-8?q?=E5=BD=A2=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E5=B9=B2=E6=B6=89?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/rectOffset.test.ts | 10 ++++++++++ src/Common/CurveUtils.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/__test__/Polyline/rectOffset.test.ts b/__test__/Polyline/rectOffset.test.ts index 377e68a54..130095ded 100644 --- a/__test__/Polyline/rectOffset.test.ts +++ b/__test__/Polyline/rectOffset.test.ts @@ -92,4 +92,14 @@ describe("矩形偏移", () => expect(rectInfo).toMatchSnapshot(); expect(pl.LineData).toMatchSnapshot(); }); + + test('不是矩形', () => + { + let d = + [1, "Polyline", 10, 2, 0, 0, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 4, [49.95586871614796, 0], 0, [49.96160816995791, 0], 0, [49.95586871614796, 2352.839413948619], 0, [49.95586871614796, 2352.0000499849994], 0, true]; + + let pl = LoadEntityFromFileData(d)[0] as Polyline; + let rectInfo = IsRect(pl); + expect(rectInfo).toBeUndefined(); + }); }); diff --git a/src/Common/CurveUtils.ts b/src/Common/CurveUtils.ts index 758956eb6..dab5c3267 100644 --- a/src/Common/CurveUtils.ts +++ b/src/Common/CurveUtils.ts @@ -9,7 +9,7 @@ import { IsPointInBowArc } from '../DatabaseServices/PointInPolyline'; import { Spline } from '../DatabaseServices/Spline'; import { Count } from '../Geometry/Count'; import { CurveMap, Vertice } from '../Geometry/CurveMap'; -import { AsVector2, AsVector3, equaln, equalv2, equalv3, isIntersect, isParallelTo, XAxis, YAxis, ZAxis, ZeroVec } from '../Geometry/GeUtils'; +import { AsVector2, AsVector3, XAxis, YAxis, ZAxis, ZeroVec, equaln, equalv2, equalv3, isIntersect, isParallelTo } from '../Geometry/GeUtils'; import { Vec3 } from '../Geometry/IVec3'; import { Matrix2 } from '../Geometry/Matrix2'; import { Orbit } from '../Geometry/Orbit'; @@ -585,7 +585,7 @@ export function IsRect(cu: Curve): IRectInfo | undefined preV.copy(nowV).negate();//翻转它 以便下一次计算 } - if (pts4.length === 4 && !crossV)//没有90度 (就不是矩形) + if (pts4.length !== 4 || !crossV)//没有90度 (就不是矩形) return; let rectOCS: Matrix4;