From a1e2b94dc9d38fa503a62459f0fac51fa882836b Mon Sep 17 00:00:00 2001 From: MissLixf <32625824+MissLixf@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:53:04 +0800 Subject: [PATCH] feat(core): add getBoundingRectangleByElements function #WIK-15311 (#862) --- .changeset/fast-hornets-hear.md | 5 +++++ packages/core/src/utils/element.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/fast-hornets-hear.md diff --git a/.changeset/fast-hornets-hear.md b/.changeset/fast-hornets-hear.md new file mode 100644 index 000000000..3d5317b18 --- /dev/null +++ b/.changeset/fast-hornets-hear.md @@ -0,0 +1,5 @@ +--- +'@plait/core': minor +--- + +add getBoundingRectangleByElements function diff --git a/packages/core/src/utils/element.ts b/packages/core/src/utils/element.ts index 0b48f7ded..e92b28fe6 100644 --- a/packages/core/src/utils/element.ts +++ b/packages/core/src/utils/element.ts @@ -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 { @@ -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); }