polygon2.inset

The ring shrunk by a distance with mitred corners, keeping every part it splits into.

GeometricSince 0.4.0

Usage

TypeScript
polygon.inset(distance: number): Result<Region2>

Parameters

  • distancenumber

    How far to move the edges inward; finite and ≥ 0. Required. Range [0, 1.7976931348623157e+308] model.

Returns

Ok with a region of zero or more parts (outlines counter-clockwise); Region2.empty when the shape collapses entirely.

Errors

Guarantees

  • a square of side s inset by d < s/2 has area (s − 2d)² (Region2.area); d ≥ s/2 gives Region2.empty
  • a dumbbell whose neck is narrower than 2d gives two parts (parts.length)
  • inset(0) has the input’s area
  • outlines wind counter-clockwise and holes clockwise (part.outer.isCounterClockwise(), !hole.isCounterClockwise())
  • The same result on every machine.

Use instead

  • polygon2.offset: round or bevel corners are needed and the shape cannot split

Example

TypeScript
const r = Polygon2.rectangle(2, 2).value.inset(0.5) // → area 1 once loadGeometryKernel() has run

See also