Skip to content

Commit

Permalink
docs(geom-tessellate): add diagram generator tool
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 14, 2024
1 parent b0d543a commit b7121c5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/geom-tessellate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
"pub": "yarn npm publish --access public",
"test": "bun test",
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts",
"tool:viz": "bun tools/visualize.ts"
},
"dependencies": {
"@thi.ng/api": "^8.11.2",
Expand Down
51 changes: 51 additions & 0 deletions packages/geom-tessellate/tools/visualize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { writeText } from "@thi.ng/file-io";
import {
asSvg,
edgePointsFromTessellation,
groupFromTessellation,
line,
star,
starWithCentroid,
svgDoc,
tessellate,
} from "@thi.ng/geom";
import { kebab } from "@thi.ng/strings";
import { map, mapcat, mapcatIndexed, pairs } from "@thi.ng/transducers";
import {
Tessellator,
earCut,
edgeSplit,
inset,
quadFan,
rimTris,
triFan,
triFanBoundary,
triFanSplit,
} from "../src/index";

const visualize = (tess: Tessellator) =>
asSvg(
svgDoc(
{ __margin: 30 },
...[3, 4, 6, 8].map((n, i) =>
groupFromTessellation(
tessellate(starWithCentroid([i * 210, 0], 100, n, [1]), [
tess,
])
)
)
)
);

for (let [id, tess] of pairs({
earCut,
edgeSplit,
inset: inset(),
rimTris,
triFan,
triFanBoundary,
triFanSplit,
quadFan,
})) {
writeText(`export/${kebab(id)}.svg`, visualize(tess));
}

0 comments on commit b7121c5

Please sign in to comment.