offset

fun Segment2D.offset(distance: Double, stepSize: Double = 0.01, yPolarity: YPolarity = YPolarity.CW_NEGATIVE_Y): List<Segment2D>(source)


fun ShapeContour.offset(distance: Double, joinType: SegmentJoin = SegmentJoin.ROUND, errorTolerance: Double = 0.05, sampleDistance: Double = 1.0): Shape(source)

Offsets a ShapeContour by given distance.

For a closed contour the result is moved outwards if distance is > 0 or inwards if distance is < 0, for an open contour it is moved along the contour's normal. The contour is split at its sharp corners into smooth runs. Every run is offset along its normal with RectifiedContour.distortUniform, with FoldMode.TRIM cutting out the stretches where the offset would fold over itself. The runs are then joined: where they pull apart the gap is closed with a join of type joinType, where they overlap both runs are cut back to their crossing. Remaining self-intersections are resolved with ShapeContour.removeSelfIntersections, and pieces that are not at distance from the contour (such as the inverted remains of an inward offset larger than the shape) are dropped.

Parameters

joinType

Specifies how to join together the moved runs at sharp corners.

errorTolerance

maximum fit error of the offset curves

sampleDistance

distance along the contour between samples used for fitting the offset curves


fun Shape.offset(distance: Double, joinType: SegmentJoin = SegmentJoin.ROUND, errorTolerance: Double = 0.05, sampleDistance: Double = 1.0): Shape(source)

Offsets a Shape by given distance.

The filled region of the shape grows if distance is > 0 and shrinks if distance is < 0: outlines move outwards while holes shrink, and the other way around. Which closed contours are outlines and which are holes follows from their nesting (a contour inside an odd number of other contours is a hole), not from their winding, so islands inside holes are handled too. Every outline is offset with ShapeContour.offset, its holes are offset by -distance and subtracted, and the results for all outlines are combined. Open contours are offset individually and added to the result.

Parameters

joinType

Specifies how to join together the moved runs at sharp corners.

errorTolerance

maximum fit error of the offset curves

sampleDistance

distance along the contours between samples used for fitting the offset curves