updateControlPoint method
Updates the position of a control point on a connection.
This method is typically called during drag operations to move an existing control point to a new position.
Example:
controller.updateControlPoint('conn1', 0, Offset(180, 220));
Implementation
void updateControlPoint(String connectionId, int index, Offset position) {
final connection = _connections.firstWhere(
(c) => c.id == connectionId,
orElse: () => throw ArgumentError('Connection $connectionId not found'),
);
if (index < 0 || index >= connection.controlPoints.length) {
return; // Invalid index
}
runInAction(() {
final controlPoints = List<Offset>.from(connection.controlPoints);
controlPoints[index] = position;
connection.controlPoints = controlPoints;
});
// Invalidate cached path and rebuild spatial index
_connectionPainter?.pathCache.removeConnection(connectionId);
_rebuildSingleConnectionSpatialIndex(connection);
}