UNPKG

fernandez-polygon-decomposition

Version:

An algorithm to decompose polygons with holes from "A practical algorithm for decomposing polygonal domains into convex polygons by diagonals" by J Fernández

9 lines (7 loc) 329 B
import { pointEquality } from './utils.js'; export function preprocessPolygon (polygon, offset = 0) { const polygonLength = polygon.length; return polygon.filter((vertex, index) => { return !pointEquality(vertex, polygon[(index + 1) % polygonLength]); }).map((vertex, index) => ({ ...vertex, id: index + offset })); }