hitTestConnections method
Tests if a point hits any connection.
Uses the connection painter's hit-testing to determine if the given graph position intersects with any connection path.
Parameters:
graphPosition: The position to test in graph/world coordinates
Returns the connection ID if hit, null otherwise.
Example:
final hitConnectionId = controller.hitTestConnections(Offset(100, 100));
if (hitConnectionId != null) {
print('Clicked on connection: $hitConnectionId');
}
Implementation
String? hitTestConnections(Offset graphPosition) {
// Use the controller's connection painter for hit-testing
final painter = connectionPainter;
// Check connections for hit-testing
for (final connection in _connections) {
final sourceNode = getNode(connection.sourceNodeId);
final targetNode = getNode(connection.targetNodeId);
if (sourceNode != null && targetNode != null) {
if (painter.hitTestConnection(
connection: connection,
sourceNode: sourceNode,
targetNode: targetNode,
testPoint: graphPosition,
)) {
return connection.id;
}
}
}
return null;
}