curve2.measure

Length, signed area, centroid and bounds of a 2D curve, chain or region.

GeometricSince 0.18.0

Usage

TypeScript
Curve2.measure(geom: Geom2, options?: Curve2Options): Result<Curve2Measure>

Parameters

  • geomGeom2

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

  • options.tolerancenumber

    A cubic’s length is integrated to it; also the value check’s. Default 1e-9 × the bounds diagonal. In model.

Returns

Ok with { length, area?, centroid?, bounds, tolerance }: area of a circle or closed chain (counter-clockwise positive); a region’s area is the signed sum of its loops’ areas, not the area its fill rule fills (that comes with D4).

Errors

Guarantees

  • lengths of lines, arcs and circles and every area and centroid are closed forms (Green’s theorem about a local origin)
  • The same result on every machine.

Example

TypeScript
const r = Curve2.measure({ id: 1, minter: 0, kind: 'circle', centre: Point2.of(0, 0), radius: 2 })
r.ok ? r.value.area : Result.error(r).code // → ok once loadGeometryKernel() has run; CAPABILITY_UNAVAILABLE before