Skip to content

Commit

Permalink
fix(hull): fix issue with fully enclosing collinear tree nodes (#6565)
Browse files Browse the repository at this point in the history
* fix(hull): fix issue with fully enclosing collinear tree nodes

* test: update snapshot

---------

Co-authored-by: Aaron <[email protected]>
  • Loading branch information
yvonneyx and Aarebecca authored Nov 27, 2024
1 parent 49ec991 commit 05044e1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createGraph } from '@@/utils';

describe('bug: plugin-hull-three-collinear-dots', () => {
it('fully enclosed', async () => {
const graph = createGraph({
animation: false,
data: {
nodes: [{ id: 'node1' }, { id: 'node2' }, { id: 'node3' }],
},
layout: {
type: 'grid',
rows: 3,
cols: 1,
},
plugins: [
{
key: 'hull',
type: 'hull',
members: ['node1', 'node2', 'node3'],
},
],
});

await graph.render();

await expect(graph).toMatchSnapshot(__filename);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion packages/g6/src/plugins/hull/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type PathArray } from '@antv/util';
import type { Point, Vector2 } from '../../types';
import { getLinesIntersection } from '../../utils/line';
import { getClosedSpline } from '../../utils/path';
import { sortByClockwise } from '../../utils/point';
import { isCollinear, sortByClockwise } from '../../utils/point';
import { add, angle, normalize, perpendicular, scale, subtract, toVector2, toVector3 } from '../../utils/vector';
import type { HullOptions } from '../hull';

Expand All @@ -18,6 +18,11 @@ import type { HullOptions } from '../hull';
export function computeHullPath(points: Point[], padding: number, corner: 'rounded' | 'smooth' | 'sharp'): PathArray {
if (points.length === 1) return genSinglePointHullPath(points[0], padding, corner);
if (points.length === 2) return genTwoPointsHullPath(points, padding, corner);
if (points.length === 3) {
const [p1, p2, p3] = sortByClockwise(points);
if (isCollinear(p1, p2, p3)) return genTwoPointsHullPath([p1, p3], padding, corner);
}

switch (corner) {
case 'smooth':
return genMultiPointsSmoothHull(points, padding);
Expand Down Expand Up @@ -134,6 +139,7 @@ const genMultiPointsRoundedHull = (points: Point[], padding: number): PathArray
},
];
});

const arcData = [padding, padding, 0, 0, 0];
const startIndex = segments.findIndex(
(segment, i) =>
Expand Down

0 comments on commit 05044e1

Please sign in to comment.