curve2.trim

A 2D curve trimmed at its hits with a boundary set, keeping the piece that holds a picked point or parameter.

GeometricSince 0.18.0

Usage

TypeScript
Curve2.trim(curve: IdCurve2, boundary: readonly IdCurve2[], pick: Point2 | number, options?: Curve2EditOptions): Result<Curve2Edit>

Parameters

  • curveIdCurve2

    The curve to trim; it keeps its id and direction. Required. In model.

  • boundaryreadonly IdCurve2[]

    The curves that cut it. Required. In model.

  • pickPoint2 | number

    A point (projected onto the curve) or a parameter in [0, 1]. Required. In model.

  • options.dryRunboolean

    Return the outline only. Default false.

  • options.tolerancenumber

    Distance under which curves touch. Default 1e-9 × the bounds diagonal. In model.

Returns

Ok with { outline, curves: [the kept piece] }: its ends are the cut points (an arc keeps its centre bit for bit; a circle becomes an arc); curves is left out under dryRun.

Errors

Guarantees

  • the kept piece’s ends are the intersection points, the same bits as curve2_intersect gives
  • The same result on every machine.

Example

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

See also