From fff9a11b5a2cf3ac51c562f60c1ed90a304231cd Mon Sep 17 00:00:00 2001 From: gkuzin13 Date: Sun, 25 Feb 2024 23:39:47 +0200 Subject: [PATCH] refactor: ellipse radius calculations --- .../Canvas/Shapes/EllipseDrawable/EllipseDrawable.tsx | 8 ++++---- .../Canvas/Shapes/EllipseDrawable/helpers/calc.ts | 8 -------- .../components/Canvas/Transformer/NodesTransformer.tsx | 6 ++---- 3 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 apps/client/src/components/Canvas/Shapes/EllipseDrawable/helpers/calc.ts diff --git a/apps/client/src/components/Canvas/Shapes/EllipseDrawable/EllipseDrawable.tsx b/apps/client/src/components/Canvas/Shapes/EllipseDrawable/EllipseDrawable.tsx index d69f6773..a4880ee2 100644 --- a/apps/client/src/components/Canvas/Shapes/EllipseDrawable/EllipseDrawable.tsx +++ b/apps/client/src/components/Canvas/Shapes/EllipseDrawable/EllipseDrawable.tsx @@ -4,7 +4,6 @@ import useAnimatedDash from '@/hooks/useAnimatedDash/useAnimatedDash'; import useNode from '@/hooks/useNode/useNode'; import { calculateCircumference } from '@/utils/math'; import { getDashValue, getSizeValue, getTotalDashLength } from '@/utils/shape'; -import { getEllipseRadius } from './helpers/calc'; import { ELLIPSE } from '@/constants/shape'; import type Konva from 'konva'; import type { NodeComponentProps } from '@/components/Canvas/Node/Node'; @@ -35,9 +34,10 @@ const EllipseDrawable = ({ (event: Konva.KonvaEventObject) => { const ellipse = event.target as Konva.Ellipse; - const { radiusX, radiusY } = getEllipseRadius(ellipse); - - const totalLength = calculateCircumference(radiusX, radiusY); + const totalLength = calculateCircumference( + ellipse.radiusX() * ellipse.scaleX(), + ellipse.radiusY() * ellipse.scaleY(), + ); const dash = getDashValue( totalLength, diff --git a/apps/client/src/components/Canvas/Shapes/EllipseDrawable/helpers/calc.ts b/apps/client/src/components/Canvas/Shapes/EllipseDrawable/helpers/calc.ts deleted file mode 100644 index 07cf52e2..00000000 --- a/apps/client/src/components/Canvas/Shapes/EllipseDrawable/helpers/calc.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type Konva from 'konva'; - -export function getEllipseRadius(ellipse: Konva.Ellipse) { - return { - radiusX: (ellipse.width() * ellipse.scaleX()) / 2, - radiusY: (ellipse.height() * ellipse.scaleY()) / 2, - }; -} diff --git a/apps/client/src/components/Canvas/Transformer/NodesTransformer.tsx b/apps/client/src/components/Canvas/Transformer/NodesTransformer.tsx index a6d3f3db..8ace3f3b 100644 --- a/apps/client/src/components/Canvas/Transformer/NodesTransformer.tsx +++ b/apps/client/src/components/Canvas/Transformer/NodesTransformer.tsx @@ -5,7 +5,6 @@ import { TRANSFORMER } from '@/constants/shape'; import { Transformer } from 'react-konva'; import { normalizeTransformerSize } from './helpers'; import { getNodeSize } from '../Shapes/EditableText/helpers/size'; -import { getEllipseRadius } from '../Shapes/EllipseDrawable/helpers/calc'; import { getRectSize } from '../Shapes/RectDrawable/helpers/calc'; import type Konva from 'konva'; import type { NodeObject, Point } from 'shared'; @@ -220,15 +219,14 @@ const NodesTransformer = ({ } case 'ellipse': { const ellipse = element as Konva.Ellipse; - const { radiusX, radiusY } = getEllipseRadius(ellipse); updatedNodes.push({ ...node, nodeProps: { ...node.nodeProps, point: [ellipse.x(), ellipse.y()], - width: radiusX, - height: radiusY, + width: ellipse.radiusX() * ellipse.scaleX(), + height: ellipse.radiusY() * ellipse.scaleY(), rotation: ellipse.rotation(), }, });