convolute

fun RectifiedContour.convolute(errorTolerance: Double = 0.5, maxDepth: Int = 6, sampleDistance: Double = 4.0, kernel: DoubleArray): ShapeContour(source)

Convolutes the contour underlying this RectifiedContour with kernel.

This works by first generating semi-uniform samples along the contour: samples are placed at roughly sampleDistance apart, but the start and end of every original contour segment always coincides with a sample, which is why the resulting spacing is only semi-uniform. The supplied kernel, which must have an odd size (2n+1), is then applied as a centered convolution over these samples (for closed contours the samples wrap around, for open contours the samples at the ends are repeated).

The convoluted samples are then used to re-fit segments, using the same adaptive cubic Bezier fitting strategy as distort and distortUniform, one group per segment of the original contour so corners of the original contour are preserved. Sample indices are tracked so it is known which convoluted samples belong to which original segment.

Parameters

errorTolerance

max allowed RMS fit error before a piece is split in two

maxDepth

recursion limit; caps output at 2^maxDepth pieces per segment. Keep this modest (5-8)

sampleDistance

approximate distance (in contour length units) between generated samples

kernel

convolution kernel, must have an odd size (2n+1) so it can be applied centered