@thi.ng/geom-fuzz 2.2.58 → 2.2.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/api.js CHANGED
@@ -1,9 +1,12 @@
1
- export const DEFAULT_LINE = {
2
- resample: 0,
3
- jitter: 2,
4
- attribs: {
5
- lineCap: "butt",
6
- lineJoin: "round",
7
- stroke: "black",
8
- },
1
+ const DEFAULT_LINE = {
2
+ resample: 0,
3
+ jitter: 2,
4
+ attribs: {
5
+ lineCap: "butt",
6
+ lineJoin: "round",
7
+ stroke: "black"
8
+ }
9
+ };
10
+ export {
11
+ DEFAULT_LINE
9
12
  };
package/comp.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { group } from "@thi.ng/geom/group";
2
- export const compFill = (a, b) => (poly) => group({}, [a(poly), b(poly)]);
2
+ const compFill = (a, b) => (poly) => group({}, [a(poly), b(poly)]);
3
+ export {
4
+ compFill
5
+ };
package/dots.js CHANGED
@@ -6,32 +6,38 @@ import { unmapPoint } from "@thi.ng/geom/unmap-point";
6
6
  import { range2d } from "@thi.ng/transducers/range2d";
7
7
  import { div2 } from "@thi.ng/vectors/div";
8
8
  import { jitter } from "@thi.ng/vectors/jitter";
9
- export const defDots = (opts = {}) => {
10
- opts = mergeDeepObj({
11
- space: 5,
12
- jitter: 0.5,
13
- attribs: {
14
- shape: "circle",
15
- stroke: "black",
16
- fill: "none",
17
- },
18
- }, opts);
19
- return (shape) => {
20
- const box = bounds(shape);
21
- const [w, h] = box.size;
22
- const cols = ~~(w / opts.space);
23
- const rows = ~~(h / opts.space);
24
- const maxg = [cols - 1, rows - 1];
25
- const acc = [];
26
- for (let p of range2d(cols, rows)) {
27
- if (p[1] & 1)
28
- p[0] += 0.5;
29
- unmapPoint(box, div2(null, p, maxg), p);
30
- jitter(p, p, opts.jitter);
31
- if (pointInside(shape, p)) {
32
- acc.push(p);
33
- }
34
- }
35
- return points(acc, opts.attribs);
36
- };
9
+ const defDots = (opts = {}) => {
10
+ opts = mergeDeepObj(
11
+ {
12
+ space: 5,
13
+ jitter: 0.5,
14
+ attribs: {
15
+ shape: "circle",
16
+ stroke: "black",
17
+ fill: "none"
18
+ }
19
+ },
20
+ opts
21
+ );
22
+ return (shape) => {
23
+ const box = bounds(shape);
24
+ const [w, h] = box.size;
25
+ const cols = ~~(w / opts.space);
26
+ const rows = ~~(h / opts.space);
27
+ const maxg = [cols - 1, rows - 1];
28
+ const acc = [];
29
+ for (let p of range2d(cols, rows)) {
30
+ if (p[1] & 1)
31
+ p[0] += 0.5;
32
+ unmapPoint(box, div2(null, p, maxg), p);
33
+ jitter(p, p, opts.jitter);
34
+ if (pointInside(shape, p)) {
35
+ acc.push(p);
36
+ }
37
+ }
38
+ return points(acc, opts.attribs);
39
+ };
40
+ };
41
+ export {
42
+ defDots
37
43
  };
package/hatch.js CHANGED
@@ -13,42 +13,45 @@ import { div2 } from "@thi.ng/vectors/div";
13
13
  import { DEFAULT_LINE } from "./api.js";
14
14
  import { defLine } from "./line.js";
15
15
  const HATCH_DIRS = {
16
- d: diagonalEnds2d,
17
- h: rowEnds2d,
18
- v: columnEnds2d,
16
+ d: diagonalEnds2d,
17
+ h: rowEnds2d,
18
+ v: columnEnds2d
19
19
  };
20
- export const defHatch = (opts = {}) => {
21
- opts = mergeDeepObj({
22
- dir: "d",
23
- space: 5,
24
- line: DEFAULT_LINE,
25
- }, opts);
26
- const line = defLine(opts.line);
27
- return (shape) => {
28
- const box = offset(bounds(shape), 1);
29
- const [w, h] = box.size;
30
- const cols = ~~(w / opts.space);
31
- const rows = ~~(h / opts.space);
32
- const maxg = [cols - 1, rows - 1];
33
- const acc = group(opts.line ? opts.line.attribs : null);
34
- const grid = HATCH_DIRS[opts.dir]({
35
- cols,
36
- rows,
37
- tx: opts.tx ||
38
- (opts.flip
39
- ? { x: flipX, y: flipY, xy: flipXY }[opts.flip]
40
- : ident),
41
- });
42
- for (let [a, b] of partition(2, grid)) {
43
- unmapPoint(box, div2(null, a, maxg), a);
44
- unmapPoint(box, div2(null, b, maxg), b);
45
- const segments = clipLinePoly(a, b, shape.points);
46
- if (segments) {
47
- for (let s of segments) {
48
- acc.children.push(line(s[0], s[1], false));
49
- }
50
- }
20
+ const defHatch = (opts = {}) => {
21
+ opts = mergeDeepObj(
22
+ {
23
+ dir: "d",
24
+ space: 5,
25
+ line: DEFAULT_LINE
26
+ },
27
+ opts
28
+ );
29
+ const line = defLine(opts.line);
30
+ return (shape) => {
31
+ const box = offset(bounds(shape), 1);
32
+ const [w, h] = box.size;
33
+ const cols = ~~(w / opts.space);
34
+ const rows = ~~(h / opts.space);
35
+ const maxg = [cols - 1, rows - 1];
36
+ const acc = group(opts.line ? opts.line.attribs : null);
37
+ const grid = HATCH_DIRS[opts.dir]({
38
+ cols,
39
+ rows,
40
+ tx: opts.tx || (opts.flip ? { x: flipX, y: flipY, xy: flipXY }[opts.flip] : ident)
41
+ });
42
+ for (let [a, b] of partition(2, grid)) {
43
+ unmapPoint(box, div2(null, a, maxg), a);
44
+ unmapPoint(box, div2(null, b, maxg), b);
45
+ const segments = clipLinePoly(a, b, shape.points);
46
+ if (segments) {
47
+ for (let s of segments) {
48
+ acc.children.push(line(s[0], s[1], false));
51
49
  }
52
- return acc;
53
- };
50
+ }
51
+ }
52
+ return acc;
53
+ };
54
+ };
55
+ export {
56
+ defHatch
54
57
  };
package/line.js CHANGED
@@ -5,9 +5,20 @@ import { polyline } from "@thi.ng/geom/polyline";
5
5
  import { jitter } from "@thi.ng/vectors/jitter";
6
6
  import { DEFAULT_LINE } from "./api.js";
7
7
  import { jitterPoints } from "./points.js";
8
- export const defLine = (opts = {}) => {
9
- opts = mergeDeepObj(DEFAULT_LINE, opts);
10
- return opts.resample > 1
11
- ? (a, b, useAttr = true) => polyline(jitterPoints(resample([a, b], { num: opts.resample, last: true }), opts.jitter), useAttr ? opts.attribs : undefined)
12
- : (a, b, useAttr = true) => line(jitter(null, a, opts.jitter), jitter(null, b, opts.jitter), useAttr ? opts.attribs : undefined);
8
+ const defLine = (opts = {}) => {
9
+ opts = mergeDeepObj(DEFAULT_LINE, opts);
10
+ return opts.resample > 1 ? (a, b, useAttr = true) => polyline(
11
+ jitterPoints(
12
+ resample([a, b], { num: opts.resample, last: true }),
13
+ opts.jitter
14
+ ),
15
+ useAttr ? opts.attribs : void 0
16
+ ) : (a, b, useAttr = true) => line(
17
+ jitter(null, a, opts.jitter),
18
+ jitter(null, b, opts.jitter),
19
+ useAttr ? opts.attribs : void 0
20
+ );
21
+ };
22
+ export {
23
+ defLine
13
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom-fuzz",
3
- "version": "2.2.58",
3
+ "version": "2.2.60",
4
4
  "description": "Highly configurable, fuzzy line & polygon creation with presets and composable fill & stroke styles. Canvas & SVG support",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,20 +35,20 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.10",
37
- "@thi.ng/associative": "^6.3.22",
38
- "@thi.ng/color": "^5.6.2",
39
- "@thi.ng/geom": "^6.0.6",
40
- "@thi.ng/geom-api": "^3.4.48",
41
- "@thi.ng/geom-clip-line": "^2.3.48",
42
- "@thi.ng/geom-resample": "^2.3.12",
43
- "@thi.ng/grid-iterators": "^4.0.34",
44
- "@thi.ng/transducers": "^8.8.13",
45
- "@thi.ng/vectors": "^7.8.7"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/associative": "^6.3.24",
40
+ "@thi.ng/color": "^5.6.4",
41
+ "@thi.ng/geom": "^6.0.8",
42
+ "@thi.ng/geom-api": "^3.4.50",
43
+ "@thi.ng/geom-clip-line": "^2.3.50",
44
+ "@thi.ng/geom-resample": "^2.3.14",
45
+ "@thi.ng/grid-iterators": "^4.0.36",
46
+ "@thi.ng/transducers": "^8.8.15",
47
+ "@thi.ng/vectors": "^7.8.9"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@microsoft/api-extractor": "^7.38.3",
49
- "@thi.ng/testament": "^0.4.3",
51
+ "esbuild": "^0.19.8",
50
52
  "rimraf": "^5.0.5",
51
53
  "tools": "^0.0.1",
52
54
  "typedoc": "^0.25.4",
@@ -119,5 +121,5 @@
119
121
  ],
120
122
  "year": 2020
121
123
  },
122
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
124
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
123
125
  }
package/points.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { jitter } from "@thi.ng/vectors/jitter";
2
- export const jitterPoints = (pts, scl = 5) => pts.map((p) => jitter([], p, scl));
2
+ const jitterPoints = (pts, scl = 5) => pts.map((p) => jitter([], p, scl));
3
+ export {
4
+ jitterPoints
5
+ };
package/polygon.js CHANGED
@@ -3,24 +3,31 @@ import { group } from "@thi.ng/geom/group";
3
3
  import { pathFromCubics } from "@thi.ng/geom/path";
4
4
  import { polygon } from "@thi.ng/geom/polygon";
5
5
  import { jitterPoints } from "./points.js";
6
- export const fuzzyPoly = (pts, attribs = {}, opts = {}) => {
7
- opts = {
8
- num: 2,
9
- jitter: 2,
10
- curveBreakPoints: true,
11
- curveScale: 0.1,
12
- ...opts,
13
- };
14
- const acc = group(attribs, []);
15
- for (; --opts.num >= 0;) {
16
- const poly = polygon(jitterPoints(pts, opts.jitter));
17
- acc.children.push(pathFromCubics(asCubic(poly, {
18
- breakPoints: opts.curveBreakPoints,
19
- scale: opts.curveScale,
20
- })));
21
- if (!opts.num && opts.fill) {
22
- acc.children.push(opts.fill(poly));
23
- }
6
+ const fuzzyPoly = (pts, attribs = {}, opts = {}) => {
7
+ opts = {
8
+ num: 2,
9
+ jitter: 2,
10
+ curveBreakPoints: true,
11
+ curveScale: 0.1,
12
+ ...opts
13
+ };
14
+ const acc = group(attribs, []);
15
+ for (; --opts.num >= 0; ) {
16
+ const poly = polygon(jitterPoints(pts, opts.jitter));
17
+ acc.children.push(
18
+ pathFromCubics(
19
+ asCubic(poly, {
20
+ breakPoints: opts.curveBreakPoints,
21
+ scale: opts.curveScale
22
+ })
23
+ )
24
+ );
25
+ if (!opts.num && opts.fill) {
26
+ acc.children.push(opts.fill(poly));
24
27
  }
25
- return acc;
28
+ }
29
+ return acc;
30
+ };
31
+ export {
32
+ fuzzyPoly
26
33
  };
package/presets.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import { defHatch } from "./hatch.js";
2
- export const defHatchPen = (color, dir = "d", thick = 8, space = 1, steps = 4) => defHatch({
3
- dir,
4
- space: thick * space,
5
- line: {
6
- attribs: {
7
- stroke: color,
8
- weight: thick,
9
- },
10
- jitter: thick * space * 0.25,
11
- resample: steps,
2
+ const defHatchPen = (color, dir = "d", thick = 8, space = 1, steps = 4) => defHatch({
3
+ dir,
4
+ space: thick * space,
5
+ line: {
6
+ attribs: {
7
+ stroke: color,
8
+ weight: thick
12
9
  },
10
+ jitter: thick * space * 0.25,
11
+ resample: steps
12
+ }
13
13
  });
14
+ export {
15
+ defHatchPen
16
+ };