region2.toJSON

The region as plain JSON: each part’s outline and holes as flat rings.

Value helperSince 0.4.0

Usage

TypeScript
region.toJSON(): { parts: { outer: number[]; holes: number[][] }[] }

Returns

{ parts } with every ring as a plain [x0, y0, …] array, wound as stored; { parts: [] } for Region2.empty.

Example

TypeScript
JSON.stringify(Region2.of(Polygon2.rectangle(2, 2).value)) // → '{"parts":[{"outer":[-1,-1,1,-1,1,1,-1,1],"holes":[]}]}'

See also