From 39ca6e941bd17e31d01f5f8684197f897c2335f3 Mon Sep 17 00:00:00 2001 From: Army Date: Thu, 16 Jan 2025 16:15:32 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=8E=A7=E5=88=B6=E7=82=B9=E5=92=8C?= =?UTF-8?q?=E7=AB=AF=E7=82=B9=E9=87=8D=E5=90=88=E7=9A=84=E6=9B=B2=E7=BA=BF?= =?UTF-8?q?=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/math/bo/Segment.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/math/bo/Segment.ts b/src/math/bo/Segment.ts index f7d4f68d..9d5cadd0 100644 --- a/src/math/bo/Segment.ts +++ b/src/math/bo/Segment.ts @@ -16,9 +16,9 @@ class Segment { constructor(coords: Point[], belong: number) { this.uuid = uuid++; - // 截取过程中曲线可能分成很小一截的水平/垂直直线,这里去除一下 + const first = coords[0]; if (coords.length > 2) { - const first = coords[0]; + // 截取过程中曲线可能分成很小一截的水平/垂直直线,这里去除一下 let equalX = true, equalY = true; for (let i = 1, len = coords.length; i < len; i++) { const item = coords[i]; @@ -67,6 +67,19 @@ class Segment { } } } + // 控制点如果和端点重合,视为无效 + if (coords.length > 2) { + if (coords[1].x === first.x && coords[1].y === first.y) { + coords.splice(1, 1); + } + } + if (coords.length > 2) { + const l = coords.length; + const end = coords[l - 1]; + if (coords[l - 2].x === end.x && coords[l - 2].y === end.y) { + coords.splice(l - 2, 1); + } + } this.coords = coords; this.belong = belong; // 属于source多边形还是clip多边形,0和1区别 this.bbox = this.calBbox(); @@ -79,7 +92,7 @@ class Segment { } calBbox() { - let coords = this.coords, l = coords.length; + const coords = this.coords, l = coords.length; const a = coords[0], b = coords[l - 1]; // 由于曲线已经x/y单调,直接看两端即可 const x1 = Math.min(a.x, b.x); @@ -95,7 +108,7 @@ class Segment { } equal(o: Segment) { - let ca = this.coords, cb = o.coords; + const ca = this.coords, cb = o.coords; if (ca.length !== cb.length) { return false; }