curve2.closest
The point of the nearest of a set of 2D curves to a point, with its parameter, distance and tangent.
Usage
Curve2.closest(curves: readonly IdCurve2[], p: Point2, options?: Curve2Options): Result<Curve2Closest>Parameters
curvesreadonly IdCurve2[]At least one curve. Required. In model.
pPoint2The query point. Required. In model.
options.tolerancenumberA cubic’s certified closest point is found within it. Default
1e-9 × the bounds diagonal. In model.
Returns
Ok with { curve, t, point, distance, tangent, tolerance }: tangent is the unit tangent in the direction of increasing t, null where it vanishes.
Errors
Guarantees
- distance is the smallest over curves; ties go to the smaller t, then the lowest index
- The same result on every machine.
Example
const r = Curve2.closest([{ id: 1, minter: 0, kind: 'line', a: Point2.of(0, 0), b: Point2.of(10, 0) }], Point2.of(3, 2))
r.ok ? r.value.distance : Result.error(r).code // → ok once loadGeometryKernel() has run; CAPABILITY_UNAVAILABLE before