@beff/aula 0.1.0 → 0.1.1

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.
@@ -20,6 +20,14 @@ export function polygon(points: Array<Point>): Mobject;
20
20
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
21
21
  */
22
22
  export function polyline(points: Array<Point>): Mobject;
23
+ /**
24
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
25
+ */
26
+ export function pathBoolean(op: BooleanOp, shapes: Array<Array<Array<Point>>>): Array<Point>;
27
+ /**
28
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
29
+ */
30
+ export function pointSquares(points: Array<Point>, side: number): Mobject;
23
31
  /**
24
32
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
25
33
  */
@@ -132,6 +140,10 @@ export function fadeOutTo(m: Mobject, p: Point): Animation;
132
140
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
133
141
  */
134
142
  export function fadeTransform(a: Mobject, b: Mobject, stretch: boolean, dimToMatch: number): Animation;
143
+ /**
144
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
145
+ */
146
+ export function fadeTransformPieces(a: Mobject, b: Mobject, stretch: boolean, dimToMatch: number): Animation;
135
147
  export function create(m: Mobject): Animation;
136
148
  export function uncreate(m: Mobject): Animation;
137
149
  export function write(m: Mobject, reverse: boolean): Animation;
@@ -217,6 +229,10 @@ export function fps(): number;
217
229
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
218
230
  */
219
231
  export function phonemize(text: string): string;
232
+ /**
233
+ * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
234
+ */
235
+ export function misaki(text: string): string;
220
236
  export type Point = import('./aula-engine-types.js').Point;
221
237
  export type Color = import('./aula-engine-types.js').Color;
222
238
  export type Diagnostic = import('./aula-engine-types.js').Diagnostic;
@@ -406,6 +422,18 @@ export interface CodeSettings {
406
422
  fontSize: number,
407
423
  lineSpacing: number,
408
424
  }
425
+ /**
426
+ * # Variants
427
+ *
428
+ * ## `"union"`
429
+ *
430
+ * ## `"intersection"`
431
+ *
432
+ * ## `"difference"`
433
+ *
434
+ * ## `"exclusion"`
435
+ */
436
+ export type BooleanOp = "union" | "intersection" | "difference" | "exclusion";
409
437
  export interface NumberSettings {
410
438
  numDecimalPlaces: number,
411
439
  includeSign: boolean,
@@ -620,12 +648,11 @@ export class Chapter implements Disposable {
620
648
  /**
621
649
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
622
650
  */
623
- static render(narration: Narration, background: Color, chapter: number, count: number, name: string, lint: boolean, text: ChapterText | undefined): Chapter;
651
+ static render(narration: Narration, background: Color, chapter: number, count: number, name: string, lint: boolean): Chapter;
624
652
  /**
625
653
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
626
654
  */
627
655
  static scene(): Chapter;
628
- narratedParagraphs(): number;
629
656
  /**
630
657
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
631
658
  */
package/dist/geometry.js CHANGED
@@ -1361,305 +1361,39 @@ export function LabeledPolygram(...args) {
1361
1361
  l.moveTo(polylabel(groups, precision));
1362
1362
  return m.add(l);
1363
1363
  }
1364
- function lineCubic(a, b) {
1365
- return [a, lerp(a, b, 1 / 3), lerp(a, b, 2 / 3), b];
1366
- }
1367
- function reversed(c) {
1368
- return [c[3], c[2], c[1], c[0]];
1369
- }
1370
- /** The loops of the family of `m`, each closed with a straight piece as Skia closes a filled path. */
1371
- function loopsOf(m) {
1372
- const out = [];
1373
- const close = (loop) => {
1374
- const [first, last] = [loop[0], loop.at(-1)];
1375
- if (first === undefined || last === undefined)
1376
- return;
1377
- if (!same(last[3], first[0], 1e-6))
1378
- loop.push(lineCubic(last[3], first[0]));
1379
- out.push(loop);
1380
- };
1381
- for (const member of m.getFamily()) {
1382
- let loop = [];
1383
- for (const c of cubics(member.getPoints())) {
1384
- if (c.every((p) => same(p, c[0], 0)))
1385
- continue;
1386
- const last = loop.at(-1);
1387
- if (last !== undefined && !same(last[3], c[0], 1e-6)) {
1388
- close(loop);
1389
- loop = [];
1390
- }
1391
- loop.push(c);
1392
- }
1393
- close(loop);
1394
- }
1395
- return out;
1396
- }
1397
- /** The real roots of `a t² + b t + c`. */
1398
- function quadraticRoots(a, b, c) {
1399
- if (Math.abs(a) < 1e-12)
1400
- return Math.abs(b) < 1e-12 ? [] : [-c / b];
1401
- const d = b * b - 4 * a * c;
1402
- if (d < 0)
1403
- return [];
1404
- const s = Math.sqrt(d);
1405
- return [(-b - s) / (2 * a), (-b + s) / (2 * a)];
1406
- }
1407
- /** The parameter ranges of `c` where its `y` only rises or only falls. */
1408
- function yMonotonic(c) {
1409
- const [a, b, d] = [c[1][1] - c[0][1], c[2][1] - c[1][1], c[3][1] - c[2][1]];
1410
- const roots = quadraticRoots(a - 2 * b + d, 2 * (b - a), a).filter((t) => t > 0 && t < 1);
1411
- const ts = [0, ...roots.toSorted((x, y) => x - y), 1];
1412
- return ts.slice(1).map((t, i) => [ts[i] ?? 0, t]);
1413
- }
1414
- /** Non-zero inside test of `p` in the loops, as Skia and the renderer fill. */
1415
- function insideLoops(p, loops) {
1416
- let winding = 0;
1417
- for (const loop of loops)
1418
- for (const c of loop)
1419
- for (const [t0, t1] of yMonotonic(c)) {
1420
- const [y0, y1] = [cubicAt(c, t0)[1], cubicAt(c, t1)[1]];
1421
- if (y0 > p[1] === y1 > p[1])
1422
- continue;
1423
- let [lo, hi] = [t0, t1];
1424
- for (let i = 0; i < 60; i++) {
1425
- const mid = (lo + hi) / 2;
1426
- if (cubicAt(c, mid)[1] > p[1] === y0 > p[1])
1427
- lo = mid;
1428
- else
1429
- hi = mid;
1430
- }
1431
- if (cubicAt(c, (lo + hi) / 2)[0] > p[0])
1432
- winding += y1 > y0 ? 1 : -1;
1433
- }
1434
- return winding !== 0;
1435
- }
1436
- function bezierDerivative(c, t) {
1437
- const u = 1 - t;
1438
- const [a, b, d] = [sub(c[1], c[0]), sub(c[2], c[1]), sub(c[3], c[2])];
1439
- return add(add(mul(a, 3 * u * u), mul(b, 6 * u * t)), mul(d, 3 * t * t));
1440
- }
1441
- function flat(c) {
1442
- const v = sub(c[3], c[0]);
1443
- const n = norm(v);
1444
- const off = (q) => (n === 0 ? norm(sub(q, c[0])) : Math.abs(cross(v, sub(q, c[0]))) / n);
1445
- return Math.max(off(c[1]), off(c[2])) < 1e-9;
1446
- }
1447
- function boxesMeet(a, b) {
1448
- for (const k of [0, 1]) {
1449
- const [as, bs] = [a.map((p) => p[k]), b.map((p) => p[k])];
1450
- if (Math.min(...as) > Math.max(...bs) + 1e-9 || Math.min(...bs) > Math.max(...as) + 1e-9)
1451
- return false;
1452
- }
1453
- return true;
1454
- }
1455
- /** The crossings of two cubics: subdivision down to flat pieces, then Newton steps on the curves. */
1456
- function crossings(a, b) {
1457
- const rough = [];
1458
- const go = (pa, ta, pb, tb, depth) => {
1459
- if (!boxesMeet(pa, pb))
1460
- return;
1461
- const [fa, fb] = [flat(pa), flat(pb)];
1462
- if ((fa && fb) || depth > 48) {
1463
- const [r, s] = [sub(pa[3], pa[0]), sub(pb[3], pb[0])];
1464
- const den = cross(r, s);
1465
- if (Math.abs(den) <= 1e-12 * norm(r) * norm(s)) {
1466
- // Two straight curves on one line cut each other at the ends of their common part.
1467
- if (depth > 0 || Math.abs(cross(r, sub(pb[0], pa[0]))) > 1e-9 * norm(r))
1468
- return;
1469
- const on = (q, from, v) => dot(sub(q, from), v) / dot(v, v);
1470
- const commonEnds = [
1471
- { t: on(pb[0], pa[0], r), u: 0 },
1472
- { t: on(pb[3], pa[0], r), u: 1 },
1473
- { t: 0, u: on(pa[0], pb[0], s) },
1474
- { t: 1, u: on(pa[3], pb[0], s) },
1475
- ];
1476
- rough.push(...commonEnds.filter((h) => h.t >= 0 && h.t <= 1 && h.u >= 0 && h.u <= 1));
1477
- return;
1478
- }
1479
- const t = cross(sub(pb[0], pa[0]), s) / den;
1480
- const u = cross(sub(pb[0], pa[0]), r) / den;
1481
- if (t < -1e-9 || t > 1 + 1e-9 || u < -1e-9 || u > 1 + 1e-9)
1482
- return;
1483
- rough.push({ t: ta[0] + (ta[1] - ta[0]) * clip01(t), u: tb[0] + (tb[1] - tb[0]) * clip01(u) });
1484
- return;
1485
- }
1486
- const halves = (c, ts, isFlat) => {
1487
- if (isFlat)
1488
- return [[c, ts]];
1489
- const half = (ts[0] + ts[1]) / 2;
1490
- return [
1491
- [cubicPart(c, 0, 0.5), [ts[0], half]],
1492
- [cubicPart(c, 0.5, 1), [half, ts[1]]],
1493
- ];
1494
- };
1495
- for (const [ca, ra] of halves(pa, ta, fa))
1496
- for (const [cb, rb] of halves(pb, tb, fb))
1497
- go(ca, ra, cb, rb, depth + 1);
1498
- };
1499
- go(a, [0, 1], b, [0, 1], 0);
1500
- const hits = [];
1501
- for (let { t, u } of rough) {
1502
- for (let i = 0; i < 8; i++) {
1503
- const f = sub(cubicAt(a, t), cubicAt(b, u));
1504
- const [da, db] = [bezierDerivative(a, t), bezierDerivative(b, u)];
1505
- const det = -cross(da, db);
1506
- if (Math.abs(det) < 1e-14)
1507
- break;
1508
- const [nt, nu] = [clip01(t + cross(f, db) / det), clip01(u - cross(da, f) / det)];
1509
- if (norm(sub(cubicAt(a, nt), cubicAt(b, nu))) > norm(f))
1510
- break;
1511
- [t, u] = [nt, nu];
1512
- }
1513
- const p = lerp(cubicAt(a, t), cubicAt(b, u), 0.5);
1514
- if (!hits.some((h) => same(h.p, p, 1e-7)))
1515
- hits.push({ t, u, p });
1516
- }
1517
- return hits;
1518
- }
1519
- /** The pieces of `c` between its cuts; each cut point ends one piece and starts the next. */
1520
- function cutCubic(c, cuts) {
1521
- const inner = cuts.filter((k) => k.t > 1e-9 && k.t < 1 - 1e-9).toSorted((x, y) => x.t - y.t);
1522
- const stops = [{ t: 0, p: c[0] }];
1523
- for (const k of inner)
1524
- if (k.t - (stops.at(-1)?.t ?? 0) > 1e-9)
1525
- stops.push(k);
1526
- stops.push({ t: 1, p: c[3] });
1527
- return stops.slice(1).map((end, i) => {
1528
- const start = stops[i] ?? end;
1529
- const part = cubicPart(c, start.t, end.t);
1530
- return [start.p, part[1], part[2], end.p];
1531
- });
1532
- }
1533
- /** The curves of both shapes, cut where they cross. */
1534
- function cutAll(la, lb) {
1535
- const [ca, cb] = [la.flat(), lb.flat()];
1536
- const cutsA = ca.map(() => []);
1537
- const cutsB = cb.map(() => []);
1538
- ca.forEach((a, i) => {
1539
- cb.forEach((b, j) => {
1540
- for (const h of crossings(a, b)) {
1541
- cutsA[i]?.push({ t: h.t, p: h.p });
1542
- cutsB[j]?.push({ t: h.u, p: h.p });
1543
- }
1544
- });
1545
- });
1546
- return [ca.flatMap((c, i) => cutCubic(c, cutsA[i] ?? [])), cb.flatMap((c, i) => cutCubic(c, cutsB[i] ?? []))];
1547
- }
1548
- /** Where the curve heads at its start or end: the first handle that is not on the anchor. */
1549
- function heading(c, atEnd) {
1550
- const ds = atEnd
1551
- ? [sub(c[3], c[2]), sub(c[3], c[1]), sub(c[3], c[0])]
1552
- : [sub(c[1], c[0]), sub(c[2], c[0]), sub(c[3], c[0])];
1553
- return ds.find((d) => norm(d) > 1e-12) ?? [1, 0];
1554
- }
1555
- /** The turn from heading `into` to heading `out`, counter-clockwise positive. */
1556
- function turnAngle(into, out) {
1557
- return Math.atan2(cross(into, out), dot(into, out));
1558
- }
1559
- /** Two straight pieces in a row on one line become one, as Skia writes them. */
1560
- function mergeLines(loop) {
1561
- const inLine = (a, b) => isStraight(a) && isStraight(b) && Math.abs(cross(unit(sub(a[3], a[0])), unit(sub(b[3], b[0])))) < 1e-9;
1562
- const out = [];
1563
- for (const c of loop) {
1564
- const last = out.at(-1);
1565
- if (last !== undefined && inLine(last, c))
1566
- out[out.length - 1] = lineCubic(last[0], c[3]);
1567
- else
1568
- out.push(c);
1569
- }
1570
- const [first, last] = [out[0], out.at(-1)];
1571
- if (out.length > 2 && first !== undefined && last !== undefined && inLine(last, first))
1572
- return [lineCubic(last[0], first[3]), ...out.slice(1, -1)];
1573
- return out;
1574
- }
1575
- /** The kept pieces, each with the result on its left, joined into closed loops. At a point
1576
- * where loops touch, each loop takes the piece that turns most to the left, so the loops stay
1577
- * apart. The outer loops turn counter-clockwise and the holes clockwise, so the even-odd fill
1578
- * and the non-zero fill agree. */
1579
- function joinLoops(pieces) {
1580
- const used = new Set();
1581
- const found = [];
1582
- pieces.forEach((first, i) => {
1583
- if (used.has(i))
1584
- return;
1585
- used.add(i);
1586
- const loop = [first];
1587
- for (;;) {
1588
- const last = loop.at(-1) ?? first;
1589
- const into = heading(last, true);
1590
- let [best, bestTurn] = [-1, -Infinity];
1591
- pieces.forEach((c, k) => {
1592
- if (used.has(k) || !same(c[0], last[3], 1e-6))
1593
- return;
1594
- const t = turnAngle(into, heading(c, false));
1595
- if (t > bestTurn)
1596
- [best, bestTurn] = [k, t];
1597
- });
1598
- const closing = same(first[0], last[3], 1e-6);
1599
- if (closing && turnAngle(into, heading(first, false)) >= bestTurn) {
1600
- loop[loop.length - 1] = [last[0], last[1], last[2], first[0]];
1601
- break;
1602
- }
1603
- const next = pieces[best];
1604
- if (next === undefined)
1605
- break;
1606
- used.add(best);
1607
- loop.push([last[3], next[1], next[2], next[3]]);
1608
- }
1609
- found.push(mergeLines(loop));
1610
- });
1611
- return found.flat(2);
1612
- }
1613
- /** The boundary of the result, as Skia's path operations make it: the curves of `a` and `b`
1614
- * cut where they cross. A piece is kept when the result is on one side of it and not on the
1615
- * other, and it is turned so that the result is on its left. A piece that both shapes have
1616
- * is kept one time. */
1617
- function boolean(label, a, b, op) {
1618
- const [la, lb] = [loopsOf(a), loopsOf(b)];
1619
- if (la.length === 0 || lb.length === 0)
1620
- wrong(label, "each Mobject needs a closed path");
1621
- const [pa, pb] = cutAll(la, lb);
1622
- const kept = [];
1623
- for (const c of [...pa, ...pb]) {
1624
- const p = cubicAt(c, 0.5);
1625
- const left = mul(rotated(unit(bezierDerivative(c, 0.5)), PI / 2), 1e-6);
1626
- const inResult = (q) => op(insideLoops(q, la), insideLoops(q, lb));
1627
- const [onLeft, onRight] = [inResult(add(p, left)), inResult(sub(p, left))];
1628
- if (onLeft === onRight)
1629
- continue;
1630
- const piece = onLeft ? c : reversed(c);
1631
- const twin = (k) => same(k[0], piece[0], 1e-7) && same(k[3], piece[3], 1e-7) && same(cubicAt(k, 0.5), p, 1e-7);
1632
- if (!kept.some(twin))
1633
- kept.push(piece);
1634
- }
1635
- return joinLoops(kept);
1636
- }
1637
- function fold(label, ms, op, style) {
1364
+ // --- boolean operations ----------------------------------------------------------------
1365
+ /** Manim's boolean operations, in the engine: Skia's PathOps and skia-pathops' contour
1366
+ * directions and start points, so the points and their order are Manim's (a Transform from a
1367
+ * boolean shape moves as in Manim). Each shape gives the points of each member of its family. */
1368
+ function fold(label, ms, style) {
1638
1369
  if (ms.length < 2)
1639
1370
  wrong(label, `${label} needs at least 2 Mobjects`);
1640
- const [first, ...rest] = ms;
1641
- let acc = first ?? wrong(label, "no Mobject");
1642
- for (const m of rest)
1643
- acc = wrap(pathNode(boolean(label, acc, m, op)));
1644
- return styled(acc, style);
1371
+ const shapes = ms.map((m) => m
1372
+ .getFamily()
1373
+ .map((member) => member.getPoints())
1374
+ .filter((points) => points.length > 0));
1375
+ if (shapes.some((members) => members.length === 0))
1376
+ wrong(label, "each Mobject needs a path");
1377
+ const op = { Union: "union", Intersection: "intersection", Difference: "difference", Exclusion: "exclusion" }[label];
1378
+ return styled(wrap(pathNode(engine.pathBoolean(op, shapes))), style);
1645
1379
  }
1646
1380
  /** The area inside any of the mobjects (Manim `Union`): `Union(a, b, opts)`. */
1647
1381
  export function Union(...args) {
1648
1382
  const [ms, style] = split(args);
1649
- return fold("Union", ms, (inA, inB) => inA || inB, style ?? {});
1383
+ return fold("Union", ms, style ?? {});
1650
1384
  }
1651
1385
  /** The area inside all the mobjects (Manim `Intersection`). */
1652
1386
  export function Intersection(...args) {
1653
1387
  const [ms, style] = split(args);
1654
- return fold("Intersection", ms, (inA, inB) => inA && inB, style ?? {});
1388
+ return fold("Intersection", ms, style ?? {});
1655
1389
  }
1656
1390
  /** The area of `subject` outside `clip` (Manim `Difference`). */
1657
1391
  export function Difference(subject, clip, opts = {}) {
1658
- return fold("Difference", [subject, clip], (inA, inB) => inA && !inB, opts);
1392
+ return fold("Difference", [subject, clip], opts);
1659
1393
  }
1660
1394
  /** The area inside one of the two, not both (Manim `Exclusion`). */
1661
1395
  export function Exclusion(subject, clip, opts = {}) {
1662
- return fold("Exclusion", [subject, clip], (inA, inB) => inA !== inB, opts);
1396
+ return fold("Exclusion", [subject, clip], opts);
1663
1397
  }
1664
1398
  /** A curve: Manim's `ParametricFunction`. */
1665
1399
  export class ParametricFunctionMobject extends Mobject {
@@ -0,0 +1,35 @@
1
+ aula-core uses valo-pathops 0.27.0 (https://crates.io/crates/valo-pathops), MIT AND
2
+ BSD-3-Clause: a line-for-line Rust port of Skia's PathOps, for the boolean operations
3
+ (src/boolean.rs). src/boolean.rs also ports parts of skia-pathops 0.9.2
4
+ (https://github.com/fonttools/skia-pathops, BSD-3-Clause): winding_from_even_odd,
5
+ restore_starting_points and their helpers. Skia's license follows.
6
+
7
+ Copyright (c) 2011 Google Inc. All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are
11
+ met:
12
+
13
+ * Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ * Redistributions in binary form must reproduce the above copyright
17
+ notice, this list of conditions and the following disclaimer in
18
+ the documentation and/or other materials provided with the
19
+ distribution.
20
+
21
+ * Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived
23
+ from this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -28,7 +28,7 @@ export declare class PMobjectMobject extends Mobject {
28
28
  alpha?: number;
29
29
  family?: boolean;
30
30
  }): this;
31
- /** The size of a point, in pixels of a 1080-pixel-high frame. */
31
+ /** The size of a point, in pixels of the 854×480 frame. */
32
32
  getStrokeWidth(): number;
33
33
  /** Sets the size of the points (Manim `set_stroke_width`); with `family` (true) also of the
34
34
  * sub-clouds. */
@@ -80,7 +80,7 @@ export declare class PMobjectMobject extends Mobject {
80
80
  }
81
81
  /** The options of a point cloud (Manim's keyword arguments). */
82
82
  export interface PMobjectOptions {
83
- /** The size of a point, in pixels of a 1080-pixel-high frame (default 4). */
83
+ /** The size of a point, in pixels of the 854×480 frame (default 4). */
84
84
  strokeWidth?: number;
85
85
  /** The colour of new points (default white). */
86
86
  color?: ParsableManimColor;
@@ -1,30 +1,14 @@
1
1
  // Manim CE's point clouds: PMobject, Mobject1D, Mobject2D, PGroup, PointCloudDot and Point.
2
- // Each point is a small filled square, `strokeWidth` pixels of the frame wide, as Manim's
3
- // camera draws it. The points of one colour run are the subpaths of one node, so
4
- // a cloud of thousands of points is a few nodes. The points and their colours are read back from
2
+ // Each point is a small filled square, `strokeWidth` pixels of the frame wide. The frame draws
3
+ // it as Manim's camera draws a point: a block of whole pixels (the engine's `point-squares`).
4
+ // The points of one colour run are the subpaths of one node, so a cloud of thousands of
5
+ // points is a few nodes. The points and their colours are read back from
5
6
  // the nodes, so every Mobject method and animation keeps them right.
6
- import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, Polyline, add, mul, norm, raw, sub, wrong, } from "./engine.js";
7
+ import { BLACK, FRAME_WIDTH, ORIGIN, PIXEL_WIDTH, PURE_YELLOW, TAU, WHITE, Mobject, add, mul, norm, raw, sub, wrong, wrap, } from "./engine.js";
7
8
  import { colorGradient, colorToRgba, rgbaToColor } from "./colors.js";
8
9
  import { engine } from "./load.js";
9
10
  /** Frame units of one pixel of the frame. */
10
11
  const PIXEL = FRAME_WIDTH / PIXEL_WIDTH;
11
- /** The square subpaths of `points` with side `side`, four lines each. */
12
- function squares(points, side) {
13
- const h = side / 2;
14
- return points.flatMap(([x, y]) => {
15
- const corners = [
16
- [x - h, y - h],
17
- [x + h, y - h],
18
- [x + h, y + h],
19
- [x - h, y + h],
20
- [x - h, y - h],
21
- ];
22
- return corners.slice(0, 4).flatMap((a, i) => {
23
- const b = corners[i + 1] ?? a;
24
- return [a, add(a, mul(sub(b, a), 1 / 3)), add(a, mul(sub(b, a), 2 / 3)), b];
25
- });
26
- });
27
- }
28
12
  /** The points of a node of squares (the centres of its square subpaths), and their side. */
29
13
  function squareCentres(node) {
30
14
  const p = node.getPoints();
@@ -90,7 +74,7 @@ export class PMobjectMobject extends Mobject {
90
74
  const a = rgbas[start] ?? [1, 1, 1, 1];
91
75
  if (i < points.length && sameRgba(a, rgbas[i] ?? a))
92
76
  continue;
93
- const run = Polyline(ORIGIN, ORIGIN).setPoints(squares(points.slice(start, i), side));
77
+ const run = wrap(engine.pointSquares(points.slice(start, i), side));
94
78
  run.setFill(rgbaToColor(a), { opacity: a[3] }).setStroke({ width: 0 });
95
79
  this.add(run);
96
80
  start = i;
@@ -127,7 +111,7 @@ export class PMobjectMobject extends Mobject {
127
111
  }
128
112
  return this;
129
113
  }
130
- /** The size of a point, in pixels of a 1080-pixel-high frame. */
114
+ /** The size of a point, in pixels of the 854×480 frame. */
131
115
  getStrokeWidth() {
132
116
  return this.#strokeWidth;
133
117
  }
package/dist/run.d.ts CHANGED
@@ -69,8 +69,7 @@ export declare function checkChapter(project: Pick<ProjectDefinition, "title" |
69
69
  }>;
70
70
  /** How aula draws a chapter against a narration. */
71
71
  export interface RenderOptions extends ReadOptions {
72
- /** The narration of this chapter. With fewer cues than the chapter's text (a prefix, as the
73
- * web app narrates a chapter while it plays), the chapter is drawn up to the narrated end. */
72
+ /** The narration of this chapter: a cue for its heading and for each paragraph. */
74
73
  narration: Narration;
75
74
  /** Draw no frames: only the clock (the waits and the narration on the clock of the
76
75
  * picture). */
package/dist/text.d.ts CHANGED
@@ -10,8 +10,8 @@ export declare function scriptMarkdown(title: string, texts: readonly ChapterTex
10
10
  /** The narration script, one list of cues for each chapter: the title card (the title), then
11
11
  * each chapter (its heading and paragraphs). */
12
12
  export declare function narrationScript(title: string, texts: readonly ChapterText[]): ScriptCue[][];
13
- /** The narration of a chapter from its script `cues` and the speech of its first cues
14
- * (`spoken[i]` speaks `cues[i]`; fewer make a prefix), at `sampleRate`. The caller puts the
13
+ /** The narration of a chapter from its script `cues` and the speech of each cue (`spoken[i]`
14
+ * speaks `cues[i]`), at `sampleRate`. The caller puts the
15
15
  * samples of each speech at the `speechStartFrame` of its cue. */
16
16
  export declare function chapterNarration(cues: readonly ScriptCue[], spoken: readonly SpokenCue[], sampleRate: number): Narration;
17
17
  /** The engine's rules on the text of a chapter. */
package/dist/text.js CHANGED
@@ -11,8 +11,8 @@ export function scriptMarkdown(title, texts) {
11
11
  export function narrationScript(title, texts) {
12
12
  return engine.narrationScript(title, [...texts]);
13
13
  }
14
- /** The narration of a chapter from its script `cues` and the speech of its first cues
15
- * (`spoken[i]` speaks `cues[i]`; fewer make a prefix), at `sampleRate`. The caller puts the
14
+ /** The narration of a chapter from its script `cues` and the speech of each cue (`spoken[i]`
15
+ * speaks `cues[i]`), at `sampleRate`. The caller puts the
16
16
  * samples of each speech at the `speechStartFrame` of its cue. */
17
17
  export function chapterNarration(cues, spoken, sampleRate) {
18
18
  return engine.chapterNarration([...cues], [...spoken], sampleRate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beff/aula",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "The aula engine for narrated explainer videos: the Manim CE API, defineChapter, its rows, readChapter and renderChapter over a Rust WebAssembly component. Chapters and kits import it; the aula command is @beff/aula-cli.",
6
6
  "license": "MIT AND GPL-3.0-or-later",