diff --git a/Sources/Grape/Views/ForceDirectedGraph+Gesture.swift b/Sources/Grape/Views/ForceDirectedGraph+Gesture.swift index 781d8cc..ee42d7b 100644 --- a/Sources/Grape/Views/ForceDirectedGraph+Gesture.swift +++ b/Sources/Grape/Views/ForceDirectedGraph+Gesture.swift @@ -9,13 +9,15 @@ extension ForceDirectedGraph { internal func onDragChange( _ value: SwiftUI.DragGesture.Value ) { - if model.draggingNodeID == nil { + if !model.isDragStartStateRecorded { if let nodeID = model.findNode(at: value.startLocation) { model.draggingNodeID = nodeID } else { model.backgroundDragStart = value.location.simd } + assert(model.isDragStartStateRecorded == true) } + guard let nodeID = model.draggingNodeID else { if let dragStart = model.backgroundDragStart { let delta = value.location.simd - dragStart @@ -51,7 +53,7 @@ extension ForceDirectedGraph { if let dragStart = model.backgroundDragStart { let delta = value.location.simd - dragStart model.modelTransform.translate += delta - model.backgroundDragStart = value.location.simd + model.backgroundDragStart = nil } return } diff --git a/Sources/Grape/Views/ForceDirectedGraphModel.swift b/Sources/Grape/Views/ForceDirectedGraphModel.swift index 11fb74b..4d55bb8 100644 --- a/Sources/Grape/Views/ForceDirectedGraphModel.swift +++ b/Sources/Grape/Views/ForceDirectedGraphModel.swift @@ -50,6 +50,11 @@ public final class ForceDirectedGraphModel { @usableFromInline var backgroundDragStart: SIMD2? = nil + @inlinable + var isDragStartStateRecorded: Bool { + return draggingNodeID != nil || backgroundDragStart != nil + } + @usableFromInline let velocityDecay: Double