Package Exports
- @thi.ng/geom
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/geom) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@thi.ng/geom
This project is part of the @thi.ng/umbrella monorepo.
About
This package is a partial WIP port of selected features of the Clojure/ClojureScript version of thi.ng/geom, as well as c.thi.ng. Currently only 2D shapes & operations are supported.
This package will soon be replaced by the currently still unreleased @thi.ng/geom2 package
Status
ALPHA - major breaking changes forthcoming...
Installation
yarn add @thi.ng/geom
Usage examples
Tessellations
import * as g from "@thi.ng/geom";
import * as v from "@thi.ng/vectors";
import * as h from "@thi.ng/hiccup";
import * as svg from "@thi.ng/hiccup-svg";
import * as fs from "fs";
const tintedPoly = (points) => {
const p = g.polygon2(points);
const c = p.centroid().toPolar();
p.attribs = { fill: `hsl(${v.deg(c.y)},${c.x}%,${100-c.x/2}%)` };
return p;
};
fs.writeFileSync(
"tessel.svg",
h.serialize(
svg.svg(
{
width: 1000, height: 1000,
viewBox: "-100 -100 200 200",
fill: "none",
stroke: "#000",
"stroke-width": 0.5,
},
svg.convertTree(
g.circle2(100)
.toPolygon(6)
.tessellate([g.quadFan, g.triFan, g.edgeSplit, g.quadFan])
.map((pts) => tintedPoly(pts).toHiccup())
)
)
)
);
Subdivision curves
Chaikin (closed) | Chaikin (open) |
---|---|
g.polygon2([-100,-100, 0,100, 100,-100, 0,0]).subdivide(g.CHAIKIN_CLOSED, 4);
g.polyline2([-100,100, -100,-100, 0,0, 100,-100, 100,100]).subdivide(g.CHAIKIN_OPEN, 4);
Authors
- Karsten Schmidt
License
© 2013 - 2018 Karsten Schmidt // Apache Software License 2.0