@pixerate/editor 0.266.2 → 0.268.0
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/dist/agent/index.cjs +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/animation-editor/controller.d.cts +8 -0
- package/dist/animation-editor/controller.d.ts +8 -0
- package/dist/animation-editor/effect-tools.d.cts +1 -1
- package/dist/animation-editor/effect-tools.d.ts +1 -1
- package/dist/animation-editor/index.cjs +175 -108
- package/dist/animation-editor/index.js +94 -27
- package/dist/brushes/index.cjs +201 -75
- package/dist/brushes/index.d.cts +4 -3
- package/dist/brushes/index.d.ts +4 -3
- package/dist/brushes/index.js +138 -12
- package/dist/brushes/library.d.cts +27 -1
- package/dist/brushes/library.d.ts +27 -1
- package/dist/brushes/profiles.d.cts +10 -1
- package/dist/brushes/profiles.d.ts +10 -1
- package/dist/brushes/schema.d.cts +4 -0
- package/dist/brushes/schema.d.ts +4 -0
- package/dist/brushes/sources.d.cts +114 -0
- package/dist/brushes/sources.d.ts +114 -0
- package/dist/brushes/types.d.cts +37 -5
- package/dist/brushes/types.d.ts +37 -5
- package/dist/brushes/ui.d.cts +40 -4
- package/dist/brushes/ui.d.ts +40 -4
- package/dist/{brushstrokeRender-KD453OBX.js → brushstrokeRender-A727TTNQ.js} +7 -7
- package/dist/{brushstrokeRender-FSUWXUZY.cjs → brushstrokeRender-WR2N5HHY.cjs} +23 -23
- package/dist/canvas/brushTypes.d.cts +12 -0
- package/dist/canvas/brushTypes.d.ts +12 -0
- package/dist/canvas/brushstroke.d.cts +1 -1
- package/dist/canvas/brushstroke.d.ts +1 -1
- package/dist/canvas/drawController.d.cts +19 -4
- package/dist/canvas/drawController.d.ts +19 -4
- package/dist/canvas/index.cjs +144 -105
- package/dist/canvas/index.js +46 -7
- package/dist/{chunk-TOID45I2.cjs → chunk-2WOGXEDX.cjs} +1 -1
- package/dist/{chunk-XORJ7UZO.cjs → chunk-3VHH6V67.cjs} +13 -12
- package/dist/{chunk-3C33YTNN.js → chunk-3XDSNIGF.js} +73 -6
- package/dist/chunk-62MFUHSI.cjs +802 -0
- package/dist/{chunk-R44Y3EFS.js → chunk-74ODPZLX.js} +17 -345
- package/dist/{chunk-GCVFEPJG.js → chunk-ACTHSQOI.js} +182 -0
- package/dist/chunk-ADMRNWR7.js +340 -0
- package/dist/{chunk-MVUQSK5J.cjs → chunk-B3G7BKUV.cjs} +111 -439
- package/dist/{chunk-DXYHQ2VN.js → chunk-BAZMCFVL.js} +1 -1
- package/dist/{chunk-VRK322ZC.cjs → chunk-BPJSI4NT.cjs} +2 -2
- package/dist/{chunk-RFJZGTHA.cjs → chunk-EU2ZZA6L.cjs} +400 -69
- package/dist/{chunk-XC6DPRYI.js → chunk-GSTSZPSR.js} +154 -949
- package/dist/{chunk-EZOJBP4D.js → chunk-HFY5LG5J.js} +1 -1
- package/dist/chunk-HVO6XCI4.js +802 -0
- package/dist/{chunk-YHDHFJUC.cjs → chunk-J5VQYK7T.cjs} +217 -1012
- package/dist/{chunk-XRXFVRGY.cjs → chunk-JBB3GDBB.cjs} +2483 -208
- package/dist/{chunk-ACFSFUQH.js → chunk-JL6YH5WD.js} +4 -0
- package/dist/{chunk-CIJBSUM5.js → chunk-KZI3YWKW.js} +353 -22
- package/dist/{chunk-4ODRXQRW.js → chunk-LETF75CA.js} +1 -1
- package/dist/{chunk-FQPUF2W2.cjs → chunk-NIBFKXMD.cjs} +217 -35
- package/dist/{chunk-AQZQWXEU.cjs → chunk-NPWWSCWT.cjs} +35 -35
- package/dist/{chunk-DOZ6F2K2.js → chunk-NSETJI74.js} +3 -2
- package/dist/{chunk-PE6YJMQT.cjs → chunk-PFHJS4HE.cjs} +20 -19
- package/dist/{chunk-7KNW3WXZ.cjs → chunk-QEVLRLUN.cjs} +63 -0
- package/dist/{chunk-LK4SXL3V.js → chunk-QNY7BDFP.js} +1 -1
- package/dist/{chunk-OTN6VB5S.cjs → chunk-RDFHWAHL.cjs} +5 -1
- package/dist/{chunk-PXDIAYB6.cjs → chunk-STLTOISW.cjs} +34 -214
- package/dist/{chunk-T2LDTEXK.js → chunk-UVTO3D4E.js} +2333 -58
- package/dist/{chunk-6JL2D5SG.js → chunk-VE6UKYQ2.js} +3 -2
- package/dist/{chunk-TXFWZ5ZJ.js → chunk-W6JDUXP3.js} +4 -184
- package/dist/{chunk-3SBLVGOM.cjs → chunk-YOVXQHA3.cjs} +23 -23
- package/dist/{chunk-WLUVZKVD.cjs → chunk-YXP6X3SY.cjs} +103 -36
- package/dist/chunk-YZWM6ZIP.cjs +340 -0
- package/dist/{chunk-472INMWH.js → chunk-ZA7L5YJB.js} +63 -0
- package/dist/commands/builtins.d.cts +12 -1
- package/dist/commands/builtins.d.ts +12 -1
- package/dist/commands/index.cjs +2 -2
- package/dist/commands/index.js +1 -1
- package/dist/image-editor/controller.d.cts +1 -1
- package/dist/image-editor/controller.d.ts +1 -1
- package/dist/image-editor/index.cjs +868 -864
- package/dist/image-editor/index.js +123 -119
- package/dist/paint/index.cjs +8 -6
- package/dist/paint/index.js +56 -54
- package/dist/paint-editor/brush-library-tools.d.cts +12 -2
- package/dist/paint-editor/brush-library-tools.d.ts +12 -2
- package/dist/paint-editor/brush-model.d.cts +29 -1
- package/dist/paint-editor/brush-model.d.ts +29 -1
- package/dist/paint-editor/brush-source-art.d.cts +32 -0
- package/dist/paint-editor/brush-source-art.d.ts +32 -0
- package/dist/paint-editor/controller.d.cts +11 -4
- package/dist/paint-editor/controller.d.ts +11 -4
- package/dist/paint-editor/dab-stroke.d.cts +2 -0
- package/dist/paint-editor/dab-stroke.d.ts +2 -0
- package/dist/paint-editor/engine.d.cts +11 -2
- package/dist/paint-editor/engine.d.ts +11 -2
- package/dist/paint-editor/index.cjs +967 -2335
- package/dist/paint-editor/index.d.cts +3 -1
- package/dist/paint-editor/index.d.ts +3 -1
- package/dist/paint-editor/index.js +394 -1762
- package/dist/paint-editor/path-samples.d.cts +2 -0
- package/dist/paint-editor/path-samples.d.ts +2 -0
- package/dist/paint-editor/presence.d.cts +20 -1
- package/dist/paint-editor/presence.d.ts +20 -1
- package/dist/paint-editor/stamp-tip.d.cts +8 -5
- package/dist/paint-editor/stamp-tip.d.ts +8 -5
- package/dist/paint-editor/thumbnails.d.cts +6 -0
- package/dist/paint-editor/thumbnails.d.ts +6 -0
- package/dist/paint-editor/tip-grain.d.cts +34 -0
- package/dist/paint-editor/tip-grain.d.ts +34 -0
- package/dist/raster/index.cjs +2 -2
- package/dist/raster/index.js +9 -9
- package/dist/stickers/helpers.d.cts +2 -0
- package/dist/stickers/helpers.d.ts +2 -0
- package/dist/stickers/index.cjs +41 -35
- package/dist/stickers/index.js +22 -16
- package/dist/stickers/types.d.cts +4 -2
- package/dist/stickers/types.d.ts +4 -2
- package/dist/vector/backdrop.d.cts +13 -0
- package/dist/vector/backdrop.d.ts +13 -0
- package/dist/vector/brushstroke.d.cts +54 -7
- package/dist/vector/brushstroke.d.ts +54 -7
- package/dist/vector/brushstrokeMedia.d.cts +96 -0
- package/dist/vector/brushstrokeMedia.d.ts +96 -0
- package/dist/vector/controller.d.cts +17 -3
- package/dist/vector/controller.d.ts +17 -3
- package/dist/vector/index.cjs +1850 -1390
- package/dist/vector/index.d.cts +2 -0
- package/dist/vector/index.d.ts +2 -0
- package/dist/vector/index.js +520 -60
- package/dist/vector/render.d.cts +6 -0
- package/dist/vector/render.d.ts +6 -0
- package/dist/vector/types.d.cts +14 -0
- package/dist/vector/types.d.ts +14 -0
- package/package.json +1 -1
- package/skills/pixerate-animation-editor/SKILL.md +1 -0
- package/skills/pixerate-brushes/SKILL.md +37 -10
- package/skills/pixerate-brushes-design/SKILL.md +15 -5
- package/skills/pixerate-brushes-design/evals/port-to-vector.json +8 -8
- package/skills/pixerate-canvas/SKILL.md +11 -1
- package/skills/pixerate-image-editor/SKILL.md +19 -64
- package/skills/pixerate-image-editor/references/color-management.md +2 -1
- package/skills/pixerate-image-editor/references/free-transform.md +12 -0
- package/skills/pixerate-image-editor/references/layer-effects.md +10 -0
- package/skills/pixerate-image-editor/references/painting.md +17 -0
- package/skills/pixerate-image-editor/references/photoshop-files.md +1 -1
- package/skills/pixerate-image-editor/references/shapes-and-type.md +14 -0
- package/skills/pixerate-image-editor/references/smart-objects.md +10 -0
- package/skills/pixerate-paint-editor/SKILL.md +14 -4
- package/skills/pixerate-paint-editor/references/brush-facets.md +3 -1
- package/skills/pixerate-paint-editor/references/wet-media.md +9 -0
- package/skills/pixerate-paint-sketch-to-finish/SKILL.md +1 -0
- package/skills/pixerate-vector/SKILL.md +16 -6
- package/skills/pixerate-vector/references/best-practices.md +1 -0
- package/skills/pixerate-vector/references/commands.md +19 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// src/image-editor/layers/vector-raster.ts
|
|
2
|
+
var FLATNESS = 0.01;
|
|
3
|
+
function flattenPath(path, tolerance = FLATNESS) {
|
|
4
|
+
const out = [];
|
|
5
|
+
let pts = [];
|
|
6
|
+
let cx = 0;
|
|
7
|
+
let cy = 0;
|
|
8
|
+
let sx = 0;
|
|
9
|
+
let sy = 0;
|
|
10
|
+
const flush = () => {
|
|
11
|
+
if (pts.length >= 6) out.push(Float64Array.from(pts));
|
|
12
|
+
pts = [];
|
|
13
|
+
};
|
|
14
|
+
const steps = (dd, degree) => Math.max(1, Math.min(1024, Math.ceil(Math.sqrt(degree * (degree - 1) * dd / (8 * tolerance)))));
|
|
15
|
+
for (const c of path) {
|
|
16
|
+
switch (c.type) {
|
|
17
|
+
case "M":
|
|
18
|
+
flush();
|
|
19
|
+
cx = sx = c.x;
|
|
20
|
+
cy = sy = c.y;
|
|
21
|
+
pts.push(cx, cy);
|
|
22
|
+
break;
|
|
23
|
+
case "L":
|
|
24
|
+
if (!pts.length) pts.push(cx, cy);
|
|
25
|
+
cx = c.x;
|
|
26
|
+
cy = c.y;
|
|
27
|
+
pts.push(cx, cy);
|
|
28
|
+
break;
|
|
29
|
+
case "Q": {
|
|
30
|
+
if (!pts.length) pts.push(cx, cy);
|
|
31
|
+
const n = steps(Math.hypot(cx - 2 * c.x1 + c.x, cy - 2 * c.y1 + c.y), 2);
|
|
32
|
+
for (let k = 1; k <= n; k++) {
|
|
33
|
+
const t = k / n;
|
|
34
|
+
const u = 1 - t;
|
|
35
|
+
pts.push(u * u * cx + 2 * u * t * c.x1 + t * t * c.x, u * u * cy + 2 * u * t * c.y1 + t * t * c.y);
|
|
36
|
+
}
|
|
37
|
+
cx = c.x;
|
|
38
|
+
cy = c.y;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case "C": {
|
|
42
|
+
if (!pts.length) pts.push(cx, cy);
|
|
43
|
+
const dd = Math.max(Math.hypot(cx - 2 * c.x1 + c.x2, cy - 2 * c.y1 + c.y2), Math.hypot(c.x1 - 2 * c.x2 + c.x, c.y1 - 2 * c.y2 + c.y));
|
|
44
|
+
const n = steps(dd, 3);
|
|
45
|
+
for (let k = 1; k <= n; k++) {
|
|
46
|
+
const t = k / n;
|
|
47
|
+
const u = 1 - t;
|
|
48
|
+
const a = u * u * u;
|
|
49
|
+
const b = 3 * u * u * t;
|
|
50
|
+
const d = 3 * u * t * t;
|
|
51
|
+
const e = t * t * t;
|
|
52
|
+
pts.push(a * cx + b * c.x1 + d * c.x2 + e * c.x, a * cy + b * c.y1 + d * c.y2 + e * c.y);
|
|
53
|
+
}
|
|
54
|
+
cx = c.x;
|
|
55
|
+
cy = c.y;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "Z":
|
|
59
|
+
flush();
|
|
60
|
+
cx = sx;
|
|
61
|
+
cy = sy;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
flush();
|
|
66
|
+
return out.filter((p) => p.every(Number.isFinite));
|
|
67
|
+
}
|
|
68
|
+
function flatBounds(flat) {
|
|
69
|
+
let x0 = Infinity;
|
|
70
|
+
let y0 = Infinity;
|
|
71
|
+
let x1 = -Infinity;
|
|
72
|
+
let y1 = -Infinity;
|
|
73
|
+
for (const p of flat) {
|
|
74
|
+
for (let i = 0; i < p.length; i += 2) {
|
|
75
|
+
if (p[i] < x0) x0 = p[i];
|
|
76
|
+
if (p[i] > x1) x1 = p[i];
|
|
77
|
+
if (p[i + 1] < y0) y0 = p[i + 1];
|
|
78
|
+
if (p[i + 1] > y1) y1 = p[i + 1];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (x0 === Infinity) return null;
|
|
82
|
+
const x = Math.floor(x0);
|
|
83
|
+
const y = Math.floor(y0);
|
|
84
|
+
return { x, y, width: Math.ceil(x1) - x, height: Math.ceil(y1) - y };
|
|
85
|
+
}
|
|
86
|
+
function drawLine(a, w, h, x0, y0, x1, y1) {
|
|
87
|
+
if (y0 === y1) return;
|
|
88
|
+
let dir = 1;
|
|
89
|
+
if (y0 > y1) {
|
|
90
|
+
dir = -1;
|
|
91
|
+
let t = x0;
|
|
92
|
+
x0 = x1;
|
|
93
|
+
x1 = t;
|
|
94
|
+
t = y0;
|
|
95
|
+
y0 = y1;
|
|
96
|
+
y1 = t;
|
|
97
|
+
}
|
|
98
|
+
if (y1 <= 0 || y0 >= h) return;
|
|
99
|
+
const dxdy = (x1 - x0) / (y1 - y0);
|
|
100
|
+
let x = x0;
|
|
101
|
+
if (y0 < 0) x -= y0 * dxdy;
|
|
102
|
+
const rowStart = Math.max(0, Math.floor(y0));
|
|
103
|
+
const rowEnd = Math.min(h, Math.ceil(y1));
|
|
104
|
+
for (let y = rowStart; y < rowEnd; y++) {
|
|
105
|
+
const line = y * w;
|
|
106
|
+
const dy = Math.min(y + 1, y1) - Math.max(y, y0);
|
|
107
|
+
const xnext = x + dxdy * dy;
|
|
108
|
+
const d = dy * dir;
|
|
109
|
+
const xa = x < xnext ? x : xnext;
|
|
110
|
+
const xb = x < xnext ? xnext : x;
|
|
111
|
+
const xaFloor = Math.floor(xa);
|
|
112
|
+
const xai = xaFloor;
|
|
113
|
+
const xbCeil = Math.ceil(xb);
|
|
114
|
+
const xbi = xbCeil;
|
|
115
|
+
if (xbi <= xai + 1) {
|
|
116
|
+
const xmf = 0.5 * (x + xnext) - xaFloor;
|
|
117
|
+
a[line + xai] += d - d * xmf;
|
|
118
|
+
a[line + xai + 1] += d * xmf;
|
|
119
|
+
} else {
|
|
120
|
+
const s = 1 / (xb - xa);
|
|
121
|
+
const xaf = xa - xaFloor;
|
|
122
|
+
const a0 = 0.5 * s * (1 - xaf) * (1 - xaf);
|
|
123
|
+
const xbf = xb - xbCeil + 1;
|
|
124
|
+
const am = 0.5 * s * xbf * xbf;
|
|
125
|
+
a[line + xai] += d * a0;
|
|
126
|
+
if (xbi === xai + 2) a[line + xai + 1] += d * (1 - a0 - am);
|
|
127
|
+
else {
|
|
128
|
+
const a1 = s * (1.5 - xaf);
|
|
129
|
+
a[line + xai + 1] += d * (a1 - a0);
|
|
130
|
+
for (let xi = xai + 2; xi < xbi - 1; xi++) a[line + xi] += d * s;
|
|
131
|
+
const a2 = a1 + (xbi - xai - 3) * s;
|
|
132
|
+
a[line + xbi - 1] += d * (1 - a2 - am);
|
|
133
|
+
}
|
|
134
|
+
a[line + xbi] += d * am;
|
|
135
|
+
}
|
|
136
|
+
x = xnext;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function drawClippedLine(a, w, h, x0, y0, x1, y1) {
|
|
140
|
+
if (y0 === y1) return;
|
|
141
|
+
if (y0 <= 0 && y1 <= 0 || y0 >= h && y1 >= h) return;
|
|
142
|
+
if (x0 >= 0 && x0 <= w && x1 >= 0 && x1 <= w) return drawLine(a, w, h, x0, y0, x1, y1);
|
|
143
|
+
const ts = [0, 1];
|
|
144
|
+
const dx = x1 - x0;
|
|
145
|
+
if (dx !== 0) {
|
|
146
|
+
for (const edge of [0, w]) {
|
|
147
|
+
const t = (edge - x0) / dx;
|
|
148
|
+
if (t > 0 && t < 1) ts.push(t);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
ts.sort((p, q) => p - q);
|
|
152
|
+
const clamp = (v) => v < 0 ? 0 : v > w ? w : v;
|
|
153
|
+
for (let i = 0; i + 1 < ts.length; i++) {
|
|
154
|
+
const ta = ts[i];
|
|
155
|
+
const tb = ts[i + 1];
|
|
156
|
+
drawLine(a, w, h, clamp(x0 + dx * ta), y0 + (y1 - y0) * ta, clamp(x0 + dx * tb), y0 + (y1 - y0) * tb);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function ruleCoverage(v, rule) {
|
|
160
|
+
const m = v < 0 ? -v : v;
|
|
161
|
+
if (rule === "nonzero") return m >= 1 ? 1 : m;
|
|
162
|
+
const f = m % 2;
|
|
163
|
+
return f > 1 ? 2 - f : f;
|
|
164
|
+
}
|
|
165
|
+
function rasterizeCoverage(flat, rect, rule = "nonzero") {
|
|
166
|
+
const w = rect.width;
|
|
167
|
+
const h = rect.height;
|
|
168
|
+
if (w <= 0 || h <= 0 || !flat.length) return null;
|
|
169
|
+
const a = new Float64Array(w * h + w + 4);
|
|
170
|
+
const ox = rect.x;
|
|
171
|
+
const oy = rect.y;
|
|
172
|
+
let touched = false;
|
|
173
|
+
for (const p of flat) {
|
|
174
|
+
const n = p.length;
|
|
175
|
+
for (let i = 0; i < n; i += 2) {
|
|
176
|
+
const j = i + 2 < n ? i + 2 : 0;
|
|
177
|
+
const ya = p[i + 1] - oy;
|
|
178
|
+
const yb = p[j + 1] - oy;
|
|
179
|
+
if (ya <= 0 && yb <= 0 || ya >= h && yb >= h || ya === yb) continue;
|
|
180
|
+
drawClippedLine(a, w, h, p[i] - ox, ya, p[j] - ox, yb);
|
|
181
|
+
touched = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!touched) return null;
|
|
185
|
+
const out = new Float32Array(w * h);
|
|
186
|
+
let acc = 0;
|
|
187
|
+
let any = false;
|
|
188
|
+
for (let i = 0; i < out.length; i++) {
|
|
189
|
+
acc += a[i];
|
|
190
|
+
const c = ruleCoverage(acc, rule);
|
|
191
|
+
if (c > 1e-6) {
|
|
192
|
+
out[i] = c;
|
|
193
|
+
any = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return any ? out : null;
|
|
197
|
+
}
|
|
198
|
+
var SUB_ROWS = 16;
|
|
199
|
+
function rasterizeCoverageSampled(flat, rect, rule = "nonzero") {
|
|
200
|
+
const w = rect.width;
|
|
201
|
+
const h = rect.height;
|
|
202
|
+
if (w <= 0 || h <= 0 || !flat.length) return null;
|
|
203
|
+
let n = 0;
|
|
204
|
+
for (const p of flat) n += p.length >> 1;
|
|
205
|
+
const ey0 = new Float64Array(n);
|
|
206
|
+
const ey1 = new Float64Array(n);
|
|
207
|
+
const ex0 = new Float64Array(n);
|
|
208
|
+
const eslope = new Float64Array(n);
|
|
209
|
+
const edir = new Int8Array(n);
|
|
210
|
+
let count = 0;
|
|
211
|
+
for (const p of flat) {
|
|
212
|
+
const len = p.length;
|
|
213
|
+
for (let i = 0; i < len; i += 2) {
|
|
214
|
+
const j = i + 2 < len ? i + 2 : 0;
|
|
215
|
+
let xa = p[i] - rect.x;
|
|
216
|
+
let ya = p[i + 1] - rect.y;
|
|
217
|
+
let xb = p[j] - rect.x;
|
|
218
|
+
let yb = p[j + 1] - rect.y;
|
|
219
|
+
if (ya === yb) continue;
|
|
220
|
+
let dir = 1;
|
|
221
|
+
if (ya > yb) {
|
|
222
|
+
dir = -1;
|
|
223
|
+
let t = xa;
|
|
224
|
+
xa = xb;
|
|
225
|
+
xb = t;
|
|
226
|
+
t = ya;
|
|
227
|
+
ya = yb;
|
|
228
|
+
yb = t;
|
|
229
|
+
}
|
|
230
|
+
if (yb <= 0 || ya >= h) continue;
|
|
231
|
+
ey0[count] = ya;
|
|
232
|
+
ey1[count] = yb;
|
|
233
|
+
ex0[count] = xa;
|
|
234
|
+
eslope[count] = (xb - xa) / (yb - ya);
|
|
235
|
+
edir[count] = dir;
|
|
236
|
+
count++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!count) return null;
|
|
240
|
+
const order = Array.from({ length: count }, (_, i) => i).sort((a, b) => ey0[a] - ey0[b]);
|
|
241
|
+
const out = new Float32Array(w * h);
|
|
242
|
+
const diff = new Float32Array(w + 1);
|
|
243
|
+
let active = [];
|
|
244
|
+
let next = 0;
|
|
245
|
+
const xs = [];
|
|
246
|
+
const ds = [];
|
|
247
|
+
const idx = [];
|
|
248
|
+
const f = 1 / SUB_ROWS;
|
|
249
|
+
let any = false;
|
|
250
|
+
const firstRow = Math.max(0, Math.floor(ey0[order[0]]));
|
|
251
|
+
for (let y = firstRow; y < h; y++) {
|
|
252
|
+
if (next >= count && !active.length) break;
|
|
253
|
+
const row = y * w;
|
|
254
|
+
let rowTouched = false;
|
|
255
|
+
for (let s = 0; s < SUB_ROWS; s++) {
|
|
256
|
+
const sy = y + (s + 0.5) * f;
|
|
257
|
+
while (next < count && ey0[order[next]] <= sy) active.push(order[next++]);
|
|
258
|
+
if (!active.length) continue;
|
|
259
|
+
active = active.filter((e) => ey1[e] > sy);
|
|
260
|
+
xs.length = 0;
|
|
261
|
+
ds.length = 0;
|
|
262
|
+
idx.length = 0;
|
|
263
|
+
for (const e of active) {
|
|
264
|
+
if (ey0[e] > sy) continue;
|
|
265
|
+
idx.push(xs.length);
|
|
266
|
+
xs.push(ex0[e] + (sy - ey0[e]) * eslope[e]);
|
|
267
|
+
ds.push(edir[e]);
|
|
268
|
+
}
|
|
269
|
+
if (xs.length < 2) continue;
|
|
270
|
+
idx.sort((a, b) => xs[a] - xs[b]);
|
|
271
|
+
let wind = 0;
|
|
272
|
+
for (let k = 0; k + 1 < idx.length; k++) {
|
|
273
|
+
wind += ds[idx[k]];
|
|
274
|
+
const inside = rule === "nonzero" ? wind !== 0 : (wind & 1) !== 0;
|
|
275
|
+
if (!inside) continue;
|
|
276
|
+
let xa = xs[idx[k]];
|
|
277
|
+
let xb = xs[idx[k + 1]];
|
|
278
|
+
if (xb <= 0 || xa >= w || xb <= xa) continue;
|
|
279
|
+
if (xa < 0) xa = 0;
|
|
280
|
+
if (xb > w) xb = w;
|
|
281
|
+
const ia = Math.floor(xa);
|
|
282
|
+
const ib = Math.floor(xb);
|
|
283
|
+
rowTouched = true;
|
|
284
|
+
if (ia === ib) {
|
|
285
|
+
out[row + ia] += (xb - xa) * f;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
out[row + ia] += (ia + 1 - xa) * f;
|
|
289
|
+
diff[ia + 1] += f;
|
|
290
|
+
diff[ib] -= f;
|
|
291
|
+
if (ib < w) out[row + ib] += (xb - ib) * f;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!rowTouched) continue;
|
|
295
|
+
let run = 0;
|
|
296
|
+
for (let x = 0; x < w; x++) {
|
|
297
|
+
run += diff[x];
|
|
298
|
+
diff[x] = 0;
|
|
299
|
+
const v = out[row + x] + run;
|
|
300
|
+
out[row + x] = v > 1 ? 1 : v < 1e-6 ? 0 : v;
|
|
301
|
+
if (out[row + x] > 0) any = true;
|
|
302
|
+
}
|
|
303
|
+
diff[w] = 0;
|
|
304
|
+
}
|
|
305
|
+
return any ? out : null;
|
|
306
|
+
}
|
|
307
|
+
function combineCoverage(a, b, op, n) {
|
|
308
|
+
if (op === "combine") {
|
|
309
|
+
if (!a) return b;
|
|
310
|
+
if (!b) return a;
|
|
311
|
+
const out2 = new Float32Array(n);
|
|
312
|
+
for (let i = 0; i < n; i++) out2[i] = a[i] + b[i] - a[i] * b[i];
|
|
313
|
+
return out2;
|
|
314
|
+
}
|
|
315
|
+
if (op === "subtract") {
|
|
316
|
+
if (!a || !b) return a;
|
|
317
|
+
const out2 = new Float32Array(n);
|
|
318
|
+
for (let i = 0; i < n; i++) out2[i] = a[i] * (1 - b[i]);
|
|
319
|
+
return out2;
|
|
320
|
+
}
|
|
321
|
+
if (op === "intersect") {
|
|
322
|
+
if (!a || !b) return null;
|
|
323
|
+
const out2 = new Float32Array(n);
|
|
324
|
+
for (let i = 0; i < n; i++) out2[i] = a[i] * b[i];
|
|
325
|
+
return out2;
|
|
326
|
+
}
|
|
327
|
+
if (!a) return b;
|
|
328
|
+
if (!b) return a;
|
|
329
|
+
const out = new Float32Array(n);
|
|
330
|
+
for (let i = 0; i < n; i++) out[i] = a[i] + b[i] - 2 * a[i] * b[i];
|
|
331
|
+
return out;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {
|
|
335
|
+
flattenPath,
|
|
336
|
+
flatBounds,
|
|
337
|
+
rasterizeCoverage,
|
|
338
|
+
rasterizeCoverageSampled,
|
|
339
|
+
combineCoverage
|
|
340
|
+
};
|