diff --git a/packages/vrender-core/__tests__/graphic/invalid-defined-bounds.test.ts b/packages/vrender-core/__tests__/graphic/invalid-defined-bounds.test.ts new file mode 100644 index 000000000..40e451d47 --- /dev/null +++ b/packages/vrender-core/__tests__/graphic/invalid-defined-bounds.test.ts @@ -0,0 +1,54 @@ +import { AABBBounds } from '@visactor/vutils'; +import { Area } from '../../src/graphic/area'; +import { Line } from '../../src/graphic/line'; + +function expectBounds(bounds: AABBBounds) { + expect(bounds.x1).toBe(0); + expect(bounds.y1).toBe(0); + expect(bounds.x2).toBe(10); + expect(bounds.y2).toBe(10); +} + +describe('invalid defined points', () => { + test('line bounds exclude invalid points when connecting the remaining points', () => { + const points = [ + { x: 0, y: 0 }, + { x: 500, y: 500, defined: false }, + { x: 10, y: 10 } + ]; + const line = new Line({ points, connectedType: 'connect' }); + + const pointBounds = new AABBBounds(); + (line as any).updateLineAABBBoundsByPoints(line.attribute, { points }, pointBounds); + expectBounds(pointBounds); + + const segmentBounds = new AABBBounds(); + (line as any).updateLineAABBBoundsBySegments( + { segments: [{ points }], connectedType: 'connect' }, + { segments: [{ points }] }, + segmentBounds + ); + expectBounds(segmentBounds); + }); + + test('area bounds exclude both coordinates of invalid points', () => { + const points = [ + { x: 0, y: 0, y1: 2 }, + { x: 500, y: 500, y1: -500, defined: false }, + { x: 10, y: 10, y1: 4 } + ]; + const area = new Area({ points, connectedType: 'connect' }); + + const pointBounds = new AABBBounds(); + (area as any).updateAreaAABBBoundsByPoints(area.attribute, { points }, pointBounds); + expectBounds(pointBounds); + + const segmentBounds = new AABBBounds(); + (area as any).updateAreaAABBBoundsBySegments( + { segments: [{ points }], connectedType: 'connect' }, + { segments: [{ points }] }, + segmentBounds + ); + expectBounds(segmentBounds); + }); +}); diff --git a/packages/vrender-core/src/graphic/area.ts b/packages/vrender-core/src/graphic/area.ts index 391da50be..74579ad78 100644 --- a/packages/vrender-core/src/graphic/area.ts +++ b/packages/vrender-core/src/graphic/area.ts @@ -88,6 +88,9 @@ export class Area extends Graphic implements IArea { const { points = areaTheme.points } = attribute; const b = aabbBounds; points.forEach(p => { + if (p.defined === false) { + return; + } b.add(p.x, p.y); b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略 }); @@ -103,6 +106,9 @@ export class Area extends Graphic implements IArea { const b = aabbBounds; segments.forEach(s => { s.points.forEach(p => { + if (p.defined === false) { + return; + } b.add(p.x, p.y); b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略 }); diff --git a/packages/vrender-core/src/graphic/line.ts b/packages/vrender-core/src/graphic/line.ts index b69d6a2c8..33d3c2440 100644 --- a/packages/vrender-core/src/graphic/line.ts +++ b/packages/vrender-core/src/graphic/line.ts @@ -82,10 +82,10 @@ export class Line extends Graphic implements ILine { aabbBounds: IAABBBounds, graphic?: ILine ): IAABBBounds { - const { points = lineTheme.points, connectedType } = attribute; + const { points = lineTheme.points } = attribute; const b = aabbBounds; points.forEach(p => { - if (p.defined !== false || connectedType === 'connect') { + if (p.defined !== false) { b.add(p.x, p.y); } }); @@ -97,11 +97,11 @@ export class Line extends Graphic implements ILine { aabbBounds: IAABBBounds, graphic?: ILine ): IAABBBounds { - const { segments = lineTheme.segments, connectedType } = attribute; + const { segments = lineTheme.segments } = attribute; const b = aabbBounds; segments.forEach(s => { s.points.forEach(p => { - if (p.defined !== false || connectedType === 'connect') { + if (p.defined !== false) { b.add(p.x, p.y); } });