@thi.ng/geom-tessellate
Version:
2D/3D convex polygon tessellators
31 lines (30 loc) • 805 B
JavaScript
import { isFunction } from "@thi.ng/checks/is-function";
import { repeat } from "@thi.ng/transducers/repeat";
import { BasicTessellation } from "./tessellation.js";
function tessellate(points, ...args) {
return tessellateWith(
new BasicTessellation(),
points,
...args
);
}
function tessellateWith(tessel, points, ...args) {
const fns = isFunction(args[0]) ? repeat(args[0], args[1] ?? 1) : args[0];
return tessellateFaces(tessel, [tessel.addPoints(points)], fns);
}
const tessellateFaces = (tessel, faces, tessellators) => {
for (let fn of tessellators) {
let newFaces = [];
for (let face of faces) {
fn(tessel, newFaces, face);
}
faces = newFaces;
}
tessel.addFaces(faces);
return tessel;
};
export {
tessellate,
tessellateFaces,
tessellateWith
};