Skip to content

Commit

Permalink
feat(geom-fuzz): add hatch flip/mirror options
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 20, 2022
1 parent 16bd8c9 commit f19c5d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/geom-fuzz/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type FillFn = Fn<Polygon, IHiccupShape>;

export type HatchDir = "d" | "h" | "v";

export type FlipDir = "x" | "y" | "xy";

export interface FuzzyPolygonOpts {
num: number;
jitter: number;
Expand All @@ -25,6 +27,7 @@ export interface FuzzyLineOpts {

export interface HatchOpts {
dir: HatchDir;
flip?: FlipDir;
space: number;
line: Partial<FuzzyLineOpts>;
}
Expand Down
10 changes: 9 additions & 1 deletion packages/geom-fuzz/src/hatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { unmapPoint } from "@thi.ng/geom/unmap-point";
import { columnEnds2d } from "@thi.ng/grid-iterators/column-ends";
import { diagonalEnds2d } from "@thi.ng/grid-iterators/diagonal-ends";
import { rowEnds2d } from "@thi.ng/grid-iterators/row-ends";
import { flipX, flipXY, flipY, ident } from "@thi.ng/grid-iterators/transforms";
import { partition } from "@thi.ng/transducers/partition";
import { div2 } from "@thi.ng/vectors/div";
import { DEFAULT_LINE, FillFn, HatchOpts } from "./api.js";
Expand Down Expand Up @@ -36,7 +37,14 @@ export const defHatch = (opts: Partial<HatchOpts> = {}): FillFn => {
const rows = ~~(h / opts.space!);
const maxg = [cols - 1, rows - 1];
const acc = group(opts.line ? opts.line.attribs : null);
for (let [a, b] of partition(2, HATCH_DIRS[opts.dir!](cols, rows))) {
const grid = HATCH_DIRS[opts.dir!]({
cols,
rows,
tx: opts.flip
? { x: flipX, y: flipY, xy: flipXY }[opts.flip]
: ident,
});
for (let [a, b] of partition(2, grid)) {
unmapPoint(box, div2(null, a, maxg), a);
unmapPoint(box, div2(null, b, maxg), b);
const segments = clipLinePoly(a, b, shape.points);
Expand Down

0 comments on commit f19c5d4

Please sign in to comment.