Skip to content

Commit 6ef87d5

Browse files
committed
Fixes size bug, one-point-marks bug.
1 parent f8e648e commit 6ef87d5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

renderer/components/controls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ const SizeButton = styled.button<{
233233
display: block;
234234
border-radius: 100%;
235235
background-color: rgb(${({ color }) => color});
236-
height: ${({ size }) => size / 2}px;
237-
width: ${({ size }) => size / 2}px;
236+
height: ${({ size }) => size * 0.75}px;
237+
width: ${({ size }) => size * 0.75}px;
238238
transition: transform 0.12s;
239239
border: ${({ color }) =>
240240
color === "26, 28, 44"

renderer/lib/state.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,18 +788,23 @@ function getFreehandPath(mark: Mark, isPressure: boolean) {
788788

789789
function getRectPath(mark: Mark) {
790790
const { points } = mark
791+
const path = new Path2D()
792+
if (points.length < 2) return path
793+
791794
const x0 = Math.min(points[0][0], points[1][0])
792795
const y0 = Math.min(points[0][1], points[1][1])
793796
const x1 = Math.max(points[0][0], points[1][0])
794797
const y1 = Math.max(points[0][1], points[1][1])
795798

796-
const path = new Path2D()
797799
path.rect(x0, y0, x1 - x0, y1 - y0)
798800
return path
799801
}
800802

801803
function getEllipsePath(mark: Mark) {
802804
const { points } = mark
805+
const path = new Path2D()
806+
if (points.length < 2) return path
807+
803808
const x0 = Math.min(points[0][0], points[1][0])
804809
const y0 = Math.min(points[0][1], points[1][1])
805810
const x1 = Math.max(points[0][0], points[1][0])
@@ -809,21 +814,22 @@ function getEllipsePath(mark: Mark) {
809814
const cx = x0 + w / 2
810815
const cy = y0 + h / 2
811816

812-
const path = new Path2D()
813817
path.ellipse(cx, cy, w / 2, h / 2, 0, 0, Math.PI * 2)
814818
return path
815819
}
816820

817821
function getArrowPath(mark: Mark) {
818822
const { points } = mark
823+
const path = new Path2D()
824+
if (points.length < 2) return path
825+
819826
const [[x0, y0], [x1, y1]] = points
820827
const angle = Math.atan2(y1 - y0, x1 - x0)
821828
const distance = Math.hypot(y1 - y0, x1 - x0)
822829
const leg = (Math.min(distance / 2, 48) * mark.size) / 16
823830
const [x2, y2] = projectPoint(x1, y1, angle + Math.PI * 1.2, leg)
824831
const [x3, y3] = projectPoint(x1, y1, angle - Math.PI * 1.2, leg)
825832

826-
const path = new Path2D()
827833
path.moveTo(x0, y0)
828834
path.lineTo(x1, y1)
829835
path.lineTo(x2, y2)

0 commit comments

Comments
 (0)