Skip to content
Shapemetry

Guide

What it is: the COMPUTE tier - pure geometry math over Rust/WASM. Function-only namespaces (Point.*, BrepData.*, Curve2d.*, …). No scene graph, no file I/O.

numbers / JSON in  →  @huukhanhnguyen/geometry  →  numbers / JSON out
B-Rep: BrepData.* (solid-root or one-shell loader; no arena free)
2D fill: Curve2d { curves: PolyCurve2d[], transformation? }
3D curve: Curve { curves: PolyCurve[], transformation? }

Install

pnpm add @huukhanhnguyen/geometry
import { BrepData, Point, Curve2d, Curve } from '@huukhanhnguyen/geometry'

Namespace intros

Curated one-liners the docs generator shows as the guide strip on each namespace reference page. One bullet per namespace, spelled as a bold namespace name, a colon, then the one-liner (see the bullets below). Every namespace in the built package must have exactly one bullet here — the generator fails on a missing intro.

  • Axis: The infinite 3D carrier (origin + unit direction, oriented): measurements (closestPoint / distanceToPoint / shortestSegment) and local frame builders. Wire: length-3 vectors; frames as flattened origin + basis.
  • Axis2d: The infinite 2D carrier (origin + unit direction): project / closestPoint / signedDistance / intersect / offset / reflect. Crate prefix line2d_*.
  • BoundingBox: Axis-aligned 3D box. Type { min, max } in @huukhanhnguyen/types; ops wire [minX,minY,minZ,maxX,maxY,maxZ].
  • BoundingBox2d: Axis-aligned 2D box. Type { minX, minY, maxX, maxY }; ops wire [minX,minY,maxX,maxY].
  • ArcCurve: Analytic 3D circular arc (full circle = sweep 2π). Unit F; was Circle.
  • LineCurve: Bounded 3D line segment factory (fromEndpoints). Unit F analytic family.
  • ArcCurve2d: 2D circular arc factories → the type-tagged Curve2dJSON envelope (Unit I; was Circle2d).
  • Collision: Clash detection over placed B-Rep documents ([{ id, document, matrix? }] in, overlap pairs out), plus the bare AABB prefilter.
  • Color: RGB/HSL color math — rgb/hsl conversion, mix, contrast, luminance, lighten/darken/saturate/rotate. Wire: "#rrggbb".
  • NurbsCurve: 3D NURBS curves. Wire: NurbsCurve JSON string. fromSubpath takes a plane chain JSON (untagged segment bag at the wasm door; prefer PolyCurve2d / Curve2d at TS call sites).
  • NurbsCurve2d: 2D curves in the type-tagged Curve2dJSON envelope (the tag is spelled type, never kind). type: "shape" is a plane chain (Curve2d atom). intersect is exact curve-curve (conic algebraic; NURBS seed+refine on the originals).
  • PolyCurve: Ordered chain of 3D curve segments ({ segments: Segment[] }). Curve-entity geometry. Arc-length domain [0,1]; add auto-reverses for G0 join (tol 1e-7). Factories: polyline/line/fromPoints/fromNurbs/fromCurveJson. Kind predicates (isLine/isArc/isEllipse/isNurbs/isPolyline/isSingleSegment) are pure segment-tag queries — type: "segment" window arms never match pure kinds. Segments meet end to start; a chain never branches.
  • PolyCurve2d: Ordered chain of 2D curve segments ({ segments: Segment2d[] }, flat type tags). Same contract + same kind predicates; Curve2d rings/strokes are this.
  • EllipseCurve: Analytic 3D ellipse / elliptical arc (always carries angles). Unit F; was Ellipse.
  • EllipseCurve2d: 2D ellipse factories → Curve2dJSON (Unit I; was Ellipse2d).
  • Font: OpenType font registry (ids for Text.*).
  • MeshData: Half-edge polygon mesh arena (handle). Not TriangleMesh (indexed soup). Planar face UV is a 16-float matrix (uvMatrix on the face wire): MeshData.uvPlanar / MeshData.uvFromOrigin build it, MeshData.uvApply maps a world point → [u,v]. Layout: [ux,uy,uz,uOffset, vx,vy,vz,vOffset, 0,0,0,0, 0,0,0,1]. Tessellation bakes UVs into the triangle soup.
  • Nesting: 2D part nesting; bin/parts are Curve2d documents.
  • Nurbs: Low-level NURBS basis/sampling shared by NurbsCurve and Surface.
  • Plane: Infinite 3D plane (point + normal) and frames.
  • Point: 3D point algebra and point-cloud ops. Wire: length-3 or flat xyz cloud.
  • Point2d: 2D point algebra.
  • Polyline: Open/closed 3D point chain. Wire: flat [x,y,z,…].
  • Curve: 3D multi-polycurve document: { curves: PolyCurve[], transformation? }. Construct (empty / fromCurves / fromPolyCurve) + transform. Boolean/offset stay on Curve2d.
  • Curve2d: Public 2D filled/stroked document: { curves: PolyCurve2d[], transformation? } (4×4 plane-in-world). Wasm path2d_*. Legacy untagged shapes still accepted on read at the door.
  • Projection: Hidden-line classification of view edges.
  • Quaternion: Unit quaternion rotations. Wire: length-4 [x,y,z,w].
  • BrepData: B-Rep document (four tables): primitives, boolean, fillet, measure, heal, fromFaces / faceLoops / thicken. Display mesh: BrepData.tessellate → TriangleMesh. Validate: BrepData.validate.
  • Surface: 3D NURBS surfaces. Wire: NurbsSurface JSON string.
  • Text: OpenType shaping/outlines. Outlines are untagged segment bags on the wire; convert to PolyCurve2d / Curve2d at the TS door.
  • Transformation: 3D 4×4 transforms (row-major length 16).
  • Transformation2d: 2D affine 3×2 matrices (length 6).
  • TriangleMesh: Indexed triangle soup (not half-edge MeshData).
  • Noise: Perlin / Worley / fbm / turbulence.
  • Stat: sum / mean / variance / percentile / fitLine.
  • Vector: 3D vector algebra. Wire: length-3.
  • Vector2d: 2D vector algebra.

Modules

Last updated: 📖 4 min readEdit on GitHub