UNPKG

@thi.ng/geom-fuzz

Version:

Highly configurable, fuzzy line & polygon creation with presets and composable fill & stroke styles. Canvas & SVG support

25 lines (24 loc) 801 B
import { resample } from "@thi.ng/geom-resample/resample"; import { line } from "@thi.ng/geom/line"; import { polyline } from "@thi.ng/geom/polyline"; import { mergeDeepObj } from "@thi.ng/object-utils/merge-deep"; import { jitter } from "@thi.ng/vectors/jitter"; import { DEFAULT_LINE } from "./api.js"; import { jitterPoints } from "./points.js"; const defLine = (opts = {}) => { opts = mergeDeepObj(DEFAULT_LINE, opts); return opts.resample > 1 ? (a, b, useAttr = true) => polyline( jitterPoints( resample([a, b], { num: opts.resample, last: true }), opts.jitter ), useAttr ? opts.attribs : void 0 ) : (a, b, useAttr = true) => line( jitter(null, a, opts.jitter), jitter(null, b, opts.jitter), useAttr ? opts.attribs : void 0 ); }; export { defLine };