curve2.offset

The offset of a 2D curve, chain or region by a signed distance, keeping lines, arcs and circles, with round, miter or bevel corners.

GeometricSince 0.18.0

Usage

TypeScript
Curve2.offset(geom: Geom2, distance: number, options?: Curve2OffsetOptions): Result<Curve2Offset>

Parameters

  • geomGeom2

    A curve, a chain or a region. Required. In model.

  • distancenumber

    Positive to the left of the direction of travel (inwards for a counter-clockwise loop or a circle); a region grows for a positive one. Required. In model.

  • options.join'round' | 'miter' | 'bevel'

    How the pieces meet at a convex corner. Default 'round'.

  • options.miterLimitnumber

    A miter farther than this many distances from the vertex bevels; at least 1. Default 4.

  • options.cap'butt' | 'round'

    An open chain: return its closed outline, both sides joined by these caps.

    Required

  • options.scopestring

    The node id minted ids are keyed under.

    Required

  • options.dryRunboolean

    Return the outline only. Default false.

  • options.tolerancenumber

    A cubic’s offset is fitted within it. Default 1e-9 × the bounds diagonal. In model.

Returns

Ok with { outline, curves | chain | region, fitted? }: a line’s offset is a line, an arc’s a concentric arc with the same centre, a cubic’s cubics fitted within the tolerance (their ids in fitted); concave corners are cut where the pieces cross.

Errors

Guarantees

  • every output point lies the distance from the input (fitted pieces within the tolerance)
  • ids are keyed by source and side, never by position
  • The same result on every machine.

Example

TypeScript
const r = Curve2.offset({ id: 1, minter: 0, kind: 'line', a: Point2.of(0, 0), b: Point2.of(10, 0) }, 1)
r.ok ? r.value.outline : Result.error(r).code // → ok once loadGeometryKernel() has run; CAPABILITY_UNAVAILABLE before

See also