Skip to content

2D Geometry

The geometry module in @intermact/core provides immutable primitive factories and sampling kernels (design.md §5).

Primitive factories

FactoryDescription
circleCircle, radius + samples
ellipseEllipse, rx / ry
rectangleRectangle, supports cornerRadius
arcCircular arc
polygonPolygon, supports holes
bezierCurveQuadratic/cubic Bézier chain
linePolyline
arrowLine segment + solid triangular arrowhead (base perpendicular to axis)
polylineFunction/data polyline (M5+)
ts
import { circle, polygon, xy } from "@intermact/core";

const star = polygon({
  points: [xy(0, 1), xy(0.3, 0.1) /* … */],
  style: {
    stroke: "#f59e0b",
    fill: "rgba(245,158,11,0.2)",
    fillRule: "evenodd",
    lineWidth: 0.05,
  },
});

Style2D

ts
style: {
  stroke: "#38bdf8",           // color string
  fill: "rgba(56,189,248,0.2)",
  lineWidth: 0.06,             // world units
  lineWidth: { value: 3, unit: "px" }, // screen pixel approximation
  fillRule: "nonzero" | "evenodd", // v0.1: only nonzero + holes; even-odd deferred
}

Sampling and triangulation

  • resampleByArcLength: uniform arc-length resampling
  • SampledPath2D: Float32Array high-performance channel
  • triangulate: earcut, outer contour + holes
  • computeBounds: axis-aligned bounding box

GeometryProvider2D unifies samplePath / getBounds / sampleBuffer.

Trait composition

Objects declare capabilities via traits: stroke, fill (closed shapes), morphable (morphable). Use findTrait to query capabilities — no inheritance tree.

  • geometry/primitives-gallery — all primitives
  • geometry/sampling-debug — sampling points, bounds, triangulation visualization

Intermact v1.0 — docs cover Phase-1 / Phase-2 / Phase-3 (all stages)