Skip to content

Commit

Permalink
Merge pull request #93 from Gkuzin13/dev
Browse files Browse the repository at this point in the history
refactor: ellipse radius calculations
  • Loading branch information
Gkuzin13 authored Feb 25, 2024
2 parents ccc90f6 + fff9a11 commit 1983a75
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,9 +34,10 @@ const EllipseDrawable = ({
(event: Konva.KonvaEventObject<Event>) => {
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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
},
});
Expand Down

0 comments on commit 1983a75

Please sign in to comment.