Types

Types

Constructors and structural types for geometry.

Imports

import {
  vec2, circle, segment, path, polygon, polyline, group,
  type Vec2, type Ring, type Path, type Group, type Circle, type Segment,
} from 'pattapatta'

Types

TypeMeaning
Vec2{ x, y }
RingVec2[] โ€” one closed or open vertex loop
Path{ rings: Ring[], closed: boolean } โ€” exterior + holes
Group{ paths: Path[] }
Circle{ x, y, r }
Segment{ a: Vec2, b: Vec2 }

Functions

FunctionDescription
vec2(x, y)Point
circle(x, y, r)Disk descriptor
segment(a, b)Line segment
polygon(exterior, holes?)Closed path
polyline(points)Open path
path(rings, closed?)General path
group(paths) / groupFromPathsOrdered group
clonePath / cloneGroup / cloneVec2Deep copies
normalizeRing(ring)Drop duplicate closing vertex
equalsVec2(a, b, eps?)Approximate equality
circleCenter(c){ x, y } of a circle

Example

const square = polygon([
  vec2(0, 0), vec2(100, 0), vec2(100, 100), vec2(0, 100),
])

Construction shapes