@vectorstream/core
v0.1.0
Published
Topological core of the vectorstream map editor: half-edge structure, Euler operators, snap rounding.
Readme
@vectorstream/core
Topological core: half-edge structure, Euler operators, snap rounding, undo history, GeoJSON import and export. No DOM, no map.
The model underneath the editor: one planar partition in which every boundary exists once and is shared by the faces on both sides.
Install
npm install @vectorstream/coreExample
import {
History,
SpatialIndex,
checkGeometry,
importGeoJSON,
insertPolygon,
type FaceId,
type FeatureCollection,
type Partition,
type Point,
} from '@vectorstream/core';
/**
* The core without editor and map: a partition, a history, and an intent inside a transaction.
* The editor does the same for every drawing, with the same checks.
*/
export function insertOutline(data: FeatureCollection, outline: Point[]): { partition: Partition; history: History; faces: FaceId[] } {
const partition = importGeoJSON(data);
const history = new History(partition, {
checkInvariants: true, // structure: half-edge pairs, closed cycles, Euler's formula, …
validators: [(p) => checkGeometry(p, new SpatialIndex(p), 0)], // geometry: crossings, overlaps
});
// All or nothing: if a check fails, the transaction is rolled back and throws.
const faces = history.transaction('insert-outline', (tx) => insertPolygon(tx, outline));
return { partition, history, faces };
}Documentation
The handbook lives in docs/handbuch/ of the vectorstream repository; a public address follows with the first release.
License
MIT, see LICENSE.
