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:
@@ -108,7 +108,8 @@ final class AnnotationCanvasView: NSView {
|
|||||||
let handleRect: CGRect
|
let handleRect: CGRect
|
||||||
if item.kind == .arrow {
|
if item.kind == .arrow {
|
||||||
let start = item.rect.origin
|
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),
|
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))
|
width: abs(end.x - start.x), height: abs(end.y - start.y))
|
||||||
} else if item.kind == .text {
|
} else if item.kind == .text {
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ enum AnnotationRenderer {
|
|||||||
|
|
||||||
private static func drawArrow(_ item: AnnotationItem, in context: CGContext) {
|
private static func drawArrow(_ item: AnnotationItem, in context: CGContext) {
|
||||||
let start = item.rect.origin
|
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.move(to: start)
|
||||||
context.addLine(to: end)
|
context.addLine(to: end)
|
||||||
@@ -98,9 +99,11 @@ enum AnnotationRenderer {
|
|||||||
static func hitTest(point: CGPoint, item: AnnotationItem, tolerance: CGFloat = 6) -> Bool {
|
static func hitTest(point: CGPoint, item: AnnotationItem, tolerance: CGFloat = 6) -> Bool {
|
||||||
switch item.kind {
|
switch item.kind {
|
||||||
case .arrow:
|
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,
|
return distanceToLine(point: point,
|
||||||
from: item.rect.origin,
|
from: item.rect.origin,
|
||||||
to: CGPoint(x: item.rect.maxX, y: item.rect.maxY)) < tolerance + item.lineWidth
|
to: arrowEnd) < tolerance + item.lineWidth
|
||||||
case .rectangle:
|
case .rectangle:
|
||||||
let outer = item.rect.insetBy(dx: -(tolerance + item.lineWidth),
|
let outer = item.rect.insetBy(dx: -(tolerance + item.lineWidth),
|
||||||
dy: -(tolerance + item.lineWidth))
|
dy: -(tolerance + item.lineWidth))
|
||||||
|
|||||||
Reference in New Issue
Block a user