Skip to content

Commit 850fcb7

Browse files
committed
Fix findNode method by scaling node radius with viewport transform
1 parent 045ee7f commit 850fcb7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/Grape/Views/ForceDirectedGraphModel.findNode.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ extension ForceDirectedGraphModel {
77
internal func findNode(
88
at locationInSimulationCoordinate: SIMD2<Double>
99
) -> NodeID? {
10+
11+
let viewportScale = self.finalTransform.scale
12+
1013
for i in simulationContext.storage.kinetics.range.reversed() {
1114
let iNodeID = simulationContext.nodeIndices[i]
1215
guard
@@ -16,9 +19,10 @@ extension ForceDirectedGraphModel {
1619
else { continue }
1720
let iPos = simulationContext.storage.kinetics.position[i]
1821

19-
20-
if simd_length_squared(locationInSimulationCoordinate - iPos) <= iRadius2
21-
{
22+
let scaledRadius2 = iRadius2 / max(.ulpOfOne, (8.0 * viewportScale * viewportScale))
23+
let length2 = simd_length_squared(locationInSimulationCoordinate - iPos)
24+
25+
if length2 <= scaledRadius2 {
2226
return iNodeID
2327
}
2428
}

0 commit comments

Comments
 (0)