drawSkeletonConnections function

void drawSkeletonConnections({
  1. required Canvas canvas,
  2. required List<Offset> scaledPoints,
  3. required List<(int, int)> connections,
  4. required Paint paint,
})

Draw straight-line connections between pre-scaled landmark points.

scaledPoints should already have the detector-to-viewport transform applied (x * scaleX + offsetX, y * scaleY + offsetY) so this helper can skip the inner-loop math. connections is a list of index pairs (fromIdx, toIdx) into that list, typically a constant bone topology like a hand or pose skeleton.

Out-of-range indices are silently skipped so callers can share one topology list across different landmark slices.

Implementation

void drawSkeletonConnections({
  required Canvas canvas,
  required List<Offset> scaledPoints,
  required List<(int, int)> connections,
  required Paint paint,
}) {
  final int n = scaledPoints.length;
  for (final (from, to) in connections) {
    if (from < 0 || from >= n || to < 0 || to >= n) continue;
    canvas.drawLine(scaledPoints[from], scaledPoints[to], paint);
  }
}