createSegments method

  1. @override
({List<PathSegment> segments, Offset start}) createSegments(
  1. ConnectionPathParameters params
)
override

Creates the path segments for this connection.

This is the ONLY method that subclasses MUST implement.

Returns a tuple of:

  • start: The starting point of the path
  • segments: The list of path segments

All derived operations (path, hit test, bend points) use the segments returned by this method via static utility methods.

Implementation

@override
({Offset start, List<PathSegment> segments}) createSegments(
  ConnectionPathParameters params,
) {
  // Calculate waypoints for all routing scenarios (ONCE)
  // Use sourceOffset/targetOffset to handle temporary connections correctly
  // (mouse position should not be extended)
  final waypoints = WaypointBuilder.calculateWaypoints(
    start: params.start,
    end: params.end,
    sourcePosition: params.sourcePosition,
    targetPosition: params.targetPosition,
    offset: params.offset,
    sourceOffset: params.sourceOffset,
    targetOffset: params.targetOffset,
    backEdgeGap: params.backEdgeGap,
    sourceNodeBounds: params.sourceNodeBounds,
    targetNodeBounds: params.targetNodeBounds,
    debugMode: params.debugMode,
  );

  // Optimize waypoints (remove redundant collinear points)
  final optimized = WaypointBuilder.optimizeWaypoints(waypoints);

  // Determine effective corner radius
  final effectiveCornerRadius = params.cornerRadius > 0
      ? params.cornerRadius
      : cornerRadius;

  // Convert to segments with rounded corners
  final segments = WaypointBuilder.waypointsToSegments(
    optimized,
    cornerRadius: effectiveCornerRadius,
  );

  return (start: params.start, segments: segments);
}