@thi.ng/geom
Version:
Functional, polymorphic API for 2D geometry types & SVG generation
25 lines (24 loc) • 893 B
JavaScript
import { TAU } from "@thi.ng/math/api";
import { cycle } from "@thi.ng/transducers/cycle";
import { map } from "@thi.ng/transducers/map";
import { normRange } from "@thi.ng/transducers/norm-range";
import { push } from "@thi.ng/transducers/push";
import { transduce } from "@thi.ng/transducers/transduce";
import { zip } from "@thi.ng/transducers/zip";
import { cartesian2 } from "@thi.ng/vectors/cartesian";
import { Polygon } from "./api/polygon.js";
const polygon = (pts, attribs) => new Polygon(pts, attribs);
const star = (r, n, profile, attribs) => starWithCentroid([0, 0], r, n, profile, attribs);
const starWithCentroid = (pos, r, n, profile, attribs) => new Polygon(
transduce(
map(([i, p]) => cartesian2(null, [r * p, i * TAU], pos)),
push(),
zip(normRange(n * profile.length, false), cycle(profile))
),
attribs
);
export {
polygon,
star,
starWithCentroid
};