Skip to content

Commit

Permalink
feat(core): add getBoundingRectangleByElements function #WIK-15311 (#862
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MissLixf authored Apr 29, 2024
1 parent 04a0803 commit a1e2b94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fast-hornets-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/core': minor
---

add getBoundingRectangleByElements function
8 changes: 7 additions & 1 deletion packages/core/src/utils/element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ancestor, PlaitBoard, PlaitElement, Point, RectangleClient } from '../interfaces';
import { getSelectionAngle, hasSameAngle, getRotatedBoundingRectangle, rotatePointsByElement } from './angle';
import { getSelectionAngle, hasSameAngle, getRotatedBoundingRectangle, rotatePointsByElement, getRectangleByAngle } from './angle';
import { depthFirstRecursion, getIsRecursionFunc } from './tree';

export function getRectangleByElements(board: PlaitBoard, elements: PlaitElement[], recursion: boolean): RectangleClient {
Expand Down Expand Up @@ -45,6 +45,12 @@ export function getRectangleByElements(board: PlaitBoard, elements: PlaitElement
}
}

export function getBoundingRectangleByElements(board: PlaitBoard, elements: PlaitElement[], recursion: boolean): RectangleClient {
const rectangle = getRectangleByElements(board, elements, recursion)!;
const angle = getSelectionAngle(elements);
return getRectangleByAngle(rectangle, angle) || rectangle;
}

export function getBoardRectangle(board: PlaitBoard): RectangleClient {
return getRectangleByElements(board, board.children, true);
}
Expand Down

0 comments on commit a1e2b94

Please sign in to comment.