removeControlPoint method

void removeControlPoint(
  1. String connectionId,
  2. int index
)

Removes a control point from a connection.

Deletes the control point at the specified index.

Example:

controller.removeControlPoint('conn1', 1);

Implementation

void removeControlPoint(String connectionId, int index) {
  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.removeAt(index);
    connection.controlPoints = controlPoints;
  });

  // Invalidate cached path and rebuild spatial index
  _connectionPainter?.pathCache.removeConnection(connectionId);
  _rebuildSingleConnectionSpatialIndex(connection);
}