segmentByCurvature

fun ShapeContour.segmentByCurvature(maxCurvature: Double = 0.05, samples: Int = 500, smoothingWindow: Int = 3, minLengthFraction: Double = 0.01): List<ShapeContour>(source)

Segments this ShapeContour into sub-contours whose curvature stays below maxCurvature. High-curvature stretches are dropped as "seams" between segments; only the low-curvature stretches are returned.

Parameters

maxCurvature

curvature threshold — points above this are treated as split points. Tune this to your contour's scale.

samples

number of samples used to scan the contour (higher = more precise split points, but slower)

smoothingWindow

simple moving-average window (in samples) applied to the curvature signal before thresholding, to avoid over-segmenting on single-sample noise spikes

minLengthFraction

sub-contours shorter than this fraction of the total contour length are discarded