distort
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
max allowed RMS fit error before a piece is split in two
recursion limit; caps output at 2^maxDepth pieces per segment. Keep this modest (5-8)
interior samples used both for fitting and for measuring the resulting error
maps a rectified t value and the position at that t to a distorted position
Approximates the curve you'd get by applying an arbitrary point-wise distort function to every point of curve, while representing the result as adaptively-split cubic Beziers.
distort just maps a position to its displaced position - it knows nothing about Beziers, attraction, or curve parameters. That means this function works for anything: attraction/repulsion toward one or more points, noise-based warping, swirls, lens-style distortions, etc. All the curve-specific logic (fitting, continuity across splits, error-driven subdivision) lives here and is reused as-is.
Each candidate piece is fit with its endpoints FIXED to distort(B(t0)) and distort(B(t1)) - the true distorted position at that piece's boundaries - so neighboring pieces always join up exactly, no matter how many times a piece gets split.
Note: because distort only sees a position, it can't distinguish "this point is near the curve's original t=0 endpoint" from "this point just happens to be near the attractor spatially". If you need that distinction (e.g. partial endpoint pinning based on arc-length position), change the signature to (Vector2, Double) -> Vector2 and pass t through from displaced() below - everything else stays the same.
Parameters
original cubic Bezier
max allowed RMS fit error (same units as the curve's coordinates) before a piece is split in two
recursion limit; caps output at 2^maxDepth pieces. Keep this modest (5-8) — it's a hard ceiling, not a target.
interior samples used both for fitting and for measuring the resulting error
maps a point on the original curve to its distorted position
Parameter-aware variant of distort: the distort function additionally receives the global parameter t of the original curve, which makes it possible to express displacement fields that vary along the curve, for example tapering toward the endpoints.
Parameters
original cubic Bezier
max allowed RMS fit error before a piece is split in two
recursion limit; caps output at 2^maxDepth pieces
interior samples used both for fitting and for measuring the error
maps a point on the original curve, plus its global t, to its distorted position
Distorts the points along this ShapeContour by applying a specified distortion function. The output is a new ShapeContour with segments that adaptively approximate the distorted curve while maintaining the original closed property.
The distortion function is applied independently to each point in the input contour, and the resulting distorted points are used to create an approximated curve by splitting and fitting segments adaptively based on the specified error tolerance and depth limits.
Return
A new ShapeContour resulting from the adaptive distortion of this contour using the provided distortion function.
Parameters
The maximum allowed RMS error (in the same units as the curve's coordinates) before a segment is subdivided. Higher values result in less precise approximations but faster processing.
The recursion depth limit for splitting segments. Limits the number of resulting pieces to 2^maxDepth. Recommended range is 5 to 8.
The number of interior samples used for measuring fit error and curve fitting. Larger values increase accuracy at the cost of computational performance.
A function that maps an input Vector2 (position) to a distorted Vector2 position. This function defines the type of distortion (e.g., noise, swirls, attraction) applied.