@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 +1 -1
- package/api.js +11 -8
- package/comp.js +4 -1
- package/dots.js +34 -28
- package/hatch.js +39 -36
- package/line.js +16 -5
- package/package.json +16 -14
- package/points.js +4 -1
- package/polygon.js +26 -19
- package/presets.js +13 -10
package/CHANGELOG.md
CHANGED
package/api.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
d: diagonalEnds2d,
|
|
17
|
+
h: rowEnds2d,
|
|
18
|
+
v: columnEnds2d
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.
|
|
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
|
|
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.
|
|
37
|
-
"@thi.ng/associative": "^6.3.
|
|
38
|
-
"@thi.ng/color": "^5.6.
|
|
39
|
-
"@thi.ng/geom": "^6.0.
|
|
40
|
-
"@thi.ng/geom-api": "^3.4.
|
|
41
|
-
"@thi.ng/geom-clip-line": "^2.3.
|
|
42
|
-
"@thi.ng/geom-resample": "^2.3.
|
|
43
|
-
"@thi.ng/grid-iterators": "^4.0.
|
|
44
|
-
"@thi.ng/transducers": "^8.8.
|
|
45
|
-
"@thi.ng/vectors": "^7.8.
|
|
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
|
-
"
|
|
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": "
|
|
124
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
123
125
|
}
|
package/points.js
CHANGED
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
};
|