Skip to content

Commit 44f61b0

Browse files
committed
fix(geometry): ignore invalid points in bounds
1 parent c86772f commit 44f61b0

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { AABBBounds } from '@visactor/vutils';
2+
import { Area } from '../../src/graphic/area';
3+
import { Line } from '../../src/graphic/line';
4+
5+
function expectBounds(bounds: AABBBounds) {
6+
expect(bounds.x1).toBe(0);
7+
expect(bounds.y1).toBe(0);
8+
expect(bounds.x2).toBe(10);
9+
expect(bounds.y2).toBe(10);
10+
}
11+
12+
describe('invalid defined points', () => {
13+
test('line bounds exclude invalid points when connecting the remaining points', () => {
14+
const points = [
15+
{ x: 0, y: 0 },
16+
{ x: 500, y: 500, defined: false },
17+
{ x: 10, y: 10 }
18+
];
19+
const line = new Line({ points, connectedType: 'connect' });
20+
21+
const pointBounds = new AABBBounds();
22+
(line as any).updateLineAABBBoundsByPoints(line.attribute, { points }, pointBounds);
23+
expectBounds(pointBounds);
24+
25+
const segmentBounds = new AABBBounds();
26+
(line as any).updateLineAABBBoundsBySegments(
27+
{ segments: [{ points }], connectedType: 'connect' },
28+
{ segments: [{ points }] },
29+
segmentBounds
30+
);
31+
expectBounds(segmentBounds);
32+
});
33+
34+
test('area bounds exclude both coordinates of invalid points', () => {
35+
const points = [
36+
{ x: 0, y: 0, y1: 2 },
37+
{ x: 500, y: 500, y1: -500, defined: false },
38+
{ x: 10, y: 10, y1: 4 }
39+
];
40+
const area = new Area({ points, connectedType: 'connect' });
41+
42+
const pointBounds = new AABBBounds();
43+
(area as any).updateAreaAABBBoundsByPoints(area.attribute, { points }, pointBounds);
44+
expectBounds(pointBounds);
45+
46+
const segmentBounds = new AABBBounds();
47+
(area as any).updateAreaAABBBoundsBySegments(
48+
{ segments: [{ points }], connectedType: 'connect' },
49+
{ segments: [{ points }] },
50+
segmentBounds
51+
);
52+
expectBounds(segmentBounds);
53+
});
54+
});

packages/vrender-core/src/graphic/area.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export class Area extends Graphic<IAreaGraphicAttribute> implements IArea {
8888
const { points = areaTheme.points } = attribute;
8989
const b = aabbBounds;
9090
points.forEach(p => {
91+
if (p.defined === false) {
92+
return;
93+
}
9194
b.add(p.x, p.y);
9295
b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略
9396
});
@@ -103,6 +106,9 @@ export class Area extends Graphic<IAreaGraphicAttribute> implements IArea {
103106
const b = aabbBounds;
104107
segments.forEach(s => {
105108
s.points.forEach(p => {
109+
if (p.defined === false) {
110+
return;
111+
}
106112
b.add(p.x, p.y);
107113
b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略
108114
});

packages/vrender-core/src/graphic/line.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export class Line extends Graphic<ILineGraphicAttribute> implements ILine {
8282
aabbBounds: IAABBBounds,
8383
graphic?: ILine
8484
): IAABBBounds {
85-
const { points = lineTheme.points, connectedType } = attribute;
85+
const { points = lineTheme.points } = attribute;
8686
const b = aabbBounds;
8787
points.forEach(p => {
88-
if (p.defined !== false || connectedType === 'connect') {
88+
if (p.defined !== false) {
8989
b.add(p.x, p.y);
9090
}
9191
});
@@ -97,11 +97,11 @@ export class Line extends Graphic<ILineGraphicAttribute> implements ILine {
9797
aabbBounds: IAABBBounds,
9898
graphic?: ILine
9999
): IAABBBounds {
100-
const { segments = lineTheme.segments, connectedType } = attribute;
100+
const { segments = lineTheme.segments } = attribute;
101101
const b = aabbBounds;
102102
segments.forEach(s => {
103103
s.points.forEach(p => {
104-
if (p.defined !== false || connectedType === 'connect') {
104+
if (p.defined !== false) {
105105
b.add(p.x, p.y);
106106
}
107107
});

0 commit comments

Comments
 (0)