polygon2.offset
The ring moved outward or inward along its edges with chosen corners, as at most one ring.
Usage
polygon.offset(distance: number, options?: { join?: JoinStyle; miterLimit?: number; arcStepRad?: number }): Result<Region2>Parameters
distancenumberHow far to move the edges: positive grows the shape, negative shrinks it, whatever the ring’s orientation. Required. In model.
options.joinJoinStyleHow corners are drawn. Default
'round'. One ofmiter,bevel,round.options.miterLimitnumberFor miter joins: how far a mitre may reach, as a ratio to the distance, before it is cut (Clipper-style). Default
4. Range [1, 1.7976931348623157e+308].options.arcStepRadnumberFor round joins: the angle each arc segment spans; must be in (0, π/2]. Default
Math.PI / 8. Range [0, 1.5707963267948966] radians.
Returns
Ok with a region of one outline and no holes, counter-clockwise; Region2.empty when an inward offset collapses the shape (and, see limits, outside the magnitude contract).
Errors
Guarantees
- a mitred offset of a square of side s by d > 0 has area (s + 2d)² (Region2.area)
- a round offset of a square of side s by d > 0 has area s² + 4sd + πd² as arcStepRad → 0 (to 3 decimals at π/256; the default π/8 draws chords, slightly under)
- the result has at most one part and no holes (parts.length ≤ 1)
- every corner of an inward result lies at least |distance| from the input’s edges, to 1e-9 relative (the guard the facade runs)
- The same result on every machine.
Use instead
polygon2.inset: the shape can pinch or split when shrunk: inset keeps every partpolygon2.outset: mitred corners will do and gaps that close must become holes
Example
const r = Polygon2.rectangle(2, 2).value.offset(0.5, { join: 'miter' }) // → area 9 once loadGeometryKernel() has run