Skip to content

Commit

Permalink
chore: 控制点和端点重合的曲线简化
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jan 16, 2025
1 parent ea3f381 commit 39ca6e9
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/math/bo/Segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 39ca6e9

Please sign in to comment.