polygon2.convexHull

The smallest convex polygon containing every point, counter-clockwise.

GeometricSince 0.4.0

Usage

TypeScript
Polygon2.convexHull(points: readonly Point2[]): Result<Polygon2>

Parameters

  • pointsreadonly Point2[]

    The points, in any order; duplicates and interior points are allowed. Required. In model.

Returns

Ok with the hull’s corners, counter-clockwise; points inside or on its edges are not corners.

Errors

Guarantees

  • the result is convex and counter-clockwise (isCounterClockwise())
  • every input point is contained or on the boundary (contains, up to the edge rule)
  • The same result on every machine.

Example

TypeScript
const r = Polygon2.convexHull([Point2.of(0, 0), Point2.of(2, 0), Point2.of(1, 0.5), Point2.of(2, 2), Point2.of(0, 2)])
r.ok // → true, area 4, once loadGeometryKernel() has run (CAPABILITY_UNAVAILABLE before)

See also