distortUniform

fun RectifiedContour.distortUniform(errorTolerance: Double = 0.5, maxDepth: Int = 6, sampleDistance: Double = 4.0, distort: (t: Double, position: Vector2) -> Vector2): ShapeContour(source)

Distorts the contour underlying this RectifiedContour using a distortion function that is evaluated on the rectified (proportional to contour length) t parameter.

This works like ShapeContour.distort, but the distort function additionally receives the rectified t value of the point it is displacing. That makes it possible to express distortions in terms of arc length position, for example tapering an effect towards the ends of the contour or applying a wave with a constant wavelength in curve-length units.

The result is built from adaptively split cubic Beziers, one group per segment of the original contour, such that corners of the original contour are preserved. Each candidate piece is fit with its endpoints fixed to the true distorted positions at that piece's boundaries, so neighbouring pieces always join up exactly.

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)

samplesPerPiece

interior samples used both for fitting and for measuring the resulting error

distort

maps a rectified t value and the position at that t to a distorted position