Geometric.js is a JavaScript library for working with points, lines, polygons, and angles. It uses plain JavaScript arrays for geometry primitives, includes TypeScript declarations for editor autocomplete and type checking, and works in modern browsers and Node.js.
Documentation and interactive examples are on the Geometric.js website.
npm install geometric -Simport * as geometric from "geometric";Geometric.js keeps geometry simple. A point is an [x, y] array, a line is an array of two points, and a polygon is an array of points.
const point = [0, 0];
const line = [
[0, 0],
[10, 10],
];
const polygon = [
[0, 0],
[10, 0],
[10, 10],
[0, 10],
];There are no custom classes to instantiate and no special data structures to learn. The values you pass into Geometric.js are the same values you can serialize, inspect, draw to SVG or Canvas, store in JSON, or pass to other JavaScript code.
pnpm install
pnpm testThe test suite builds the package, runs runtime tests, and checks the TypeScript declarations.