Fix arrows not drawing when dragged left or upward

CGRect.maxX/maxY standardize to positive values, collapsing
the arrow endpoint onto the start point for negative width/height.
Use origin + size instead to preserve direction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 07:39:56 +02:00
co-authored by Claude Opus 4.6
parent 519706dd41
commit 8d6c2213ad
2 changed files with 7 additions and 3 deletions
+2 -1
View File
@@ -108,7 +108,8 @@ final class AnnotationCanvasView: NSView {
let handleRect: CGRect
if item.kind == .arrow {
let start = item.rect.origin
let end = CGPoint(x: item.rect.maxX, y: item.rect.maxY)
let end = CGPoint(x: item.rect.origin.x + item.rect.size.width,
y: item.rect.origin.y + item.rect.size.height)
handleRect = CGRect(x: min(start.x, end.x), y: min(start.y, end.y),
width: abs(end.x - start.x), height: abs(end.y - start.y))
} else if item.kind == .text {
+5 -2
View File
@@ -48,7 +48,8 @@ enum AnnotationRenderer {
private static func drawArrow(_ item: AnnotationItem, in context: CGContext) {
let start = item.rect.origin
let end = CGPoint(x: item.rect.maxX, y: item.rect.maxY)
let end = CGPoint(x: item.rect.origin.x + item.rect.size.width,
y: item.rect.origin.y + item.rect.size.height)
context.move(to: start)
context.addLine(to: end)
@@ -98,9 +99,11 @@ enum AnnotationRenderer {
static func hitTest(point: CGPoint, item: AnnotationItem, tolerance: CGFloat = 6) -> Bool {
switch item.kind {
case .arrow:
let arrowEnd = CGPoint(x: item.rect.origin.x + item.rect.size.width,
y: item.rect.origin.y + item.rect.size.height)
return distanceToLine(point: point,
from: item.rect.origin,
to: CGPoint(x: item.rect.maxX, y: item.rect.maxY)) < tolerance + item.lineWidth
to: arrowEnd) < tolerance + item.lineWidth
case .rectangle:
let outer = item.rect.insetBy(dx: -(tolerance + item.lineWidth),
dy: -(tolerance + item.lineWidth))