The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.
Python
Document build and test workflow
Sina Atalayd64e73f7a45c
diff --git a/AGENTS.md b/AGENTS.mdnew file mode 100644index 00000000..5c3d9d46--- /dev/null+++ b/AGENTS.md@@ -0,0 +1,113 @@+# AGENTS.md++manimgx is an animation engine with Manim Community Edition's API. The Python package+(`src/manimgx`) is typed throughout; the engine under it (`rust/engine`,+built by maturin into `manimgx._engine`) typesets text with Typst, draws on the GPU with wgpu,+and encodes video with x264. Setup and conventions are in the Developer Guide+(`docs/content/developer-guide/`, published at https://manimgx.academa.ai/developer-guide/);+this is the short version.++## Commands++- `just sync`: the environment, `.venv`, with the engine built into it, and the browser package's+ locked development dependencies.+- `just format`: ruff's fixes and formatter (the Python, and the Python in the Markdown), and+ Prettier for the browser package.+- `just check`: every pre-commit check (ruff, ty, TypeScript, Prettier, reuse and the files'+ hygiene). It must pass.+- `just test [PYTEST ARGS]`: the suite, in parallel; `just test-thorough`: the unit tests'+ properties on 2,000 examples each; `just mutate`: mutation testing (`[tool.mutmut]`).+- `just test-typescript`: the browser package's tests, including its compiled worker and+ public declarations.+- `just corpus …`: render, compare and review the integration corpus (`just corpus --help`).+- `just bench [REF]`: the timed benchmarks, this checkout against REF's manimgx (main unless+ named), side by side.+- `just build-docs`, `just serve-docs`: the docs site.++Run Python through `uv run --frozen`. uv rebuilds the engine when its Rust sources, shaders or+manifests change, so there is no separate build step.++## Rules++- No `Any` in public signatures: keyword arguments are a `TypedDict` taken with `Unpack`.+- ty honors `# ty: ignore[rule]` and a bare `# type: ignore`, not `# type: ignore[code]`, and+ an unused suppression is an error. ruff's formatter splits a line too long without its+ trailing suppression and moves the suppression to the last line, so run `just check` after+ `just format`.+- Manim CE is the source of the API, not of the behavior: don't copy CE's behavior, or its+ bugs, for compatibility. The corpus is the specification.+- Measure before and after any change to the engine or the render path (`just bench main`);+ don't lose speed without a reason.+- A test comes with every fix and feature. A corpus reference changes only when a change means+ it to, and after someone has looked at the new frames.+- Docstrings are Google style: the API reference is generated from them.+- `docs/content/changelog.md` says only "First release of manimgx." until 0.1.0, the first+ release, is out. After it, a user-visible change gets a line under "Unreleased".+- Code from elsewhere says whose it is in its first lines (`SPDX-FileCopyrightText`, one per+ holder, and `SPDX-License-Identifier`); data or an image, in `REUSE.toml`. `LICENSES/` holds+ the licenses' texts.+- Don't install git hooks; run the checks by hand (`just check`).++## Layout++The repository is the package, manimgx: its `pyproject.toml` (with the uv workspace, the+dependency groups and every tool's settings), its sources and its tests are at the root. What+is published apart from it has a folder of its own, with its own tests.++- `src/manimgx/`: the package. `__init__.py` exports the authoring API. `mobject.py` is the+ mutable object kernel; `mobjects/` is its catalog of constructors. `drawing/` owns geometry,+ paint and typesetting data. `scene.py` owns cameras and scene execution; `animation/` owns+ time and changes; `rendering/` turns evaluated state into native records, films and window+ playback. `audio/` owns sound, speech and providers. `cli/` contains scene loading, export,+ preview, diagnostics and storyboards, with the presentation template in `cli/present.html`.+ `config.py`, `constants.py`, `typing.py` and `caches.py` hold the shared configuration,+ vocabulary, types and reuse policy. `LICENSE-THIRD-PARTY` (`just licenses` writes it) and+ `LICENSE-LAVAPIPE`, at the root, hold the notices for what others own in the wheels.+- `rust/`: the engine's crates, a Cargo workspace (`rust/Cargo.toml`; cargo runs there).+ `engine/` is the engine: the Python extension (with the player in a window, natively), and+ the player for a page, the engine built for the browser, which Pyodide's extension carries.+ The other crates build what the engine takes from other projects, whose sources their build+ scripts fetch, each pinned by the hash of its files (`fetch/`), so the repository holds none+ of them: `x264/` the H.264 encoder, with NASM (`nasm/`) for its x86-64 assembly; `ffmpeg/`+ FFmpeg's audio decoders, with libopus; `mitex-spec-gen/` mitex's Typst package, which the+ engine serves to Typst, and the command spec of the LaTeX-to-Typst converter made from it.+- `fonts/`: `manimgx-fonts/` and `manimgx-fonts-cjk/`, the Noto fonts text is set in, published+ apart and required at exact versions (the CJK one not in the browser); the uv workspace's+ other members.+- `browser/`: manimgx for the browser, published on npm: strict TypeScript in+ `src/`, its tests in `tests/`, and its pinned tools in `bun.lock`. Bun bundles the player+ and compiled worker into one JavaScript file; TypeScript 7 generates the public declarations.+- `docker/`: the Docker image, manimgx from PyPI.+- `tests/unit/`: properties of each module, mirroring `src/manimgx/`, drawn+ with Hypothesis (the shared kit: `tests/strategies.py`, `tests/oracles.py`, `tests/scenes.py`).+- `tests/integration/`: stories per subject (`test_*.py`) and the corpus, `cases/` (per case:+ `scene.py`, its reference `manimgx.mkv`, Manim CE's `ce.mkv`, `case.json`, and once reviewed+ `review.json`), with its tools in `corpus/` and the review panel in `review/`.+ `tests/docs/`: `llms.txt`'s hand-written primer for agents, checked against the API, and+ the narrated examples, which say what `docs/voice/` keeps (the site is built with no key).+- `tests/benchmarks/`: laws of what work costs (with the suite) and timed benchmarks against+ another commit (`just bench`): `manimgx render` of the README's scenes (`scenes/`) and of+ example films, from launch to exit.+- `docs/`: the Zensical site and what its build loads. Pages are in `docs/content/`, the+ first, Welcome, being the README, included; `docs/examples.py` renders the examples in+ them and in the docstrings, and shows each above its code; `docs/links.py` makes the+ README's URLs of the site its paths; `docs/previews.py` marks a reference to the API to+ preview its target on hover, as a link does; `docs/deprecated.py` leaves what is+ `@deprecated` out of the API reference; `docs/films.py` shows a card's film by its scene's+ name; `docs/mkdocstrings.py` lets mkdocstrings find `docs/templates/`, which shows each+ entry of the reference. The reference is written by hand (`docs/content/reference/`), a+ story whose pages render the API with mkdocstrings; `tests/docs/test_reference.py` keeps it+ whole. `docs/zensical.toml` sets the site; its llmstxt plugin+ writes each page's Markdown beside it, and `llms.txt`, whose primer for agents it holds.+- `examples/`: example films.+- `scripts/`: what writes and builds, a folder for each thing it makes. `release/`: lavapipe+ for the Linux wheels, the wheels' third-party notice, the executables, and the smoke test a+ wheel or an executable passes. `docs/`: the pages the docs build generates (not committed),+ the command line's reference (`reference.py`) and the Gallery from `examples/`+ (`gallery.py`). `showcase/`: the README's pictures (committed), the logo (`logo.py`: the+ banner, the header's, the favicon) and the wall of films (`wall.py`). `engine/`: the DFG+ table the engine is compiled with (`dfg_table.py`). `benchmark/` times manimgx against+ Manim CE, ManimGL and Blender on the README's scenes (`run.py` writes `results.json`;+ `chart.py` draws the README's chart from it into `docs/content/images/`).+- `skills/manimgx/`: the agent skill, which `npx skills add academa-labs/manimgx` installs;+ `tests/docs/test_skill.py` checks its front matter.diff --git a/docs/content/developer-guide/.nav.yml b/docs/content/developer-guide/.nav.ymlnew file mode 100644index 00000000..1bff5b3e--- /dev/null+++ b/docs/content/developer-guide/.nav.yml@@ -0,0 +1,9 @@+title: Developer Guide+nav:+ - index.md+ - project-management.md+ - understanding-manimgx.md+ - engine.md+ - testing.md+ - documentation.md+ - github-workflows.mddiff --git a/docs/content/developer-guide/documentation.md b/docs/content/developer-guide/documentation.mdnew file mode 100644index 00000000..3c9b7aca--- /dev/null+++ b/docs/content/developer-guide/documentation.md@@ -0,0 +1,437 @@+# Documentation++## The goal++manimgx's docs are a website with four tabs: the User Guide (Welcome, which is the README,+the Quickstart, chapters read in order, then the API reference), the Gallery, this+Developer Guide, and the Changelog. Two things make them more than pages of text:++- **Every example shows what it makes.** A code block that defines a scene appears with+ the film manimgx renders from it, rendered when the site is built, so no picture is ever+ older than the code beside it.+- **The reference tells a story, and misses nothing.** Its pages are written by hand, in+ the order of a video's parts, and render the API from the docstrings; tests keep them+ whole: every name the package documents is on a page, once.++A website is HTML, CSS and JavaScript files, served by a host. Nobody wants to write those+by hand for a docs site: the pages are Markdown, and a static site generator makes the+files.++## [Zensical](https://zensical.org): the site generator++Zensical builds a site from Markdown. It is made by the team behind Material for MkDocs,+with the same theme and Markdown extensions, and it supports some of MkDocs' plugins,+awesome-nav and mkdocstrings among them. Its settings are+[`docs/zensical.toml`](https://github.com/academa-labs/manimgx/blob/main/docs/zensical.toml), whose paths are the docs+folder's:++- **The site:** its name, URL and repository, and where each page's "edit" link goes.+- **The theme:** its features (the navbar's tabs, instant navigation, a copy button on+ code), its light and dark palettes, manimgx's own stylesheet and script, and+ `docs/overrides/`, where manimgx changes the theme's templates.+- **Markdown extensions:** admonitions, content tabs, math (rendered by KaTeX), Mermaid+ diagrams, keyboard keys, and a formatter of manimgx's own for Python blocks (below).+- **Plugins:** awesome-nav, which reads the navigation from the folders; mkdocstrings,+ which renders the API reference from the docstrings; and autorefs, which resolves links+ such as `[Circle][manimgx.Circle]`.++`zensical.toml` has no `nav`: the navigation is the folders' (below).++## The docs folder++The docs live in [`docs/`](https://github.com/academa-labs/manimgx/tree/main/docs), and+the scripts that write what is generated in them in+[`scripts/`](https://github.com/academa-labs/manimgx/tree/main/scripts):++```text+docs/+├── content/ ← the site: every page, at the path its URL shows+│ ├── .nav.yml ← the tabs, and the User Guide's reading order+│ ├── index.md ← Welcome, the home page: the README, included+│ ├── user-guide/ ← the User Guide's chapters+│ ├── reference/ ← the API reference, by hand; its command-line page generated+│ ├── gallery/ ← the Gallery: its cards, and a page per film; generated+│ ├── developer-guide/ ← this guide, ordered by its own .nav.yml+│ ├── changelog.md+│ ├── films/ ← the examples' films: rendered, git-ignored+│ ├── showcase/ ← the README's wall and banner: made by scripts/showcase/+│ ├── stylesheets/, javascripts/, images/+│ └── _headers ← the response headers Cloudflare sends+├── overrides/ ← where manimgx changes the theme: the header's logo and byline,+│ the footer's band+├── templates/ ← how mkdocstrings shows an entry of the reference+├── zensical.toml ← the site's settings, and llms.txt's primer for agents+├── site/ ← the site, built: git-ignored+├── voice/ ← what the narrated examples say: spoken once, committed+├── examples.py ← renders the examples into content/films/, and shows each above+│ its code while the site builds+├── svg.py ← a scene as an SVG that plays itself: the README's+├── links.py ← the README's URLs of the site as the site's paths+├── deprecated.py ← leaves what is deprecated out of the API reference+├── films.py ← a picture named by its scene (a card's) shows its film's still+├── mkdocstrings.py ← mkdocstrings finds templates/, from where the build runs+└── previews.py ← a reference to the API previews its target, as a link does++scripts/+├── docs/+│ ├── gallery.py ← writes the Gallery from examples/ into docs/content/gallery/+│ └── reference.py ← writes the command line's reference, from its Typer app+└── showcase/+ ├── logo.py ← draws the logo: the README's banner, the header's and its byline,+ │ Academa's wordmark, the favicon+ └── wall.py ← makes the README's wall from the example films' scenes+```++What the site's build loads (its formatter, its Markdown extensions and its griffe extension)+is in `docs/`, beside the settings that name it; what writes pages and pictures before it is+in `scripts/`.++## Navigation: folders and `.nav.yml`++The navigation is the folder tree of `docs/content/`.+[awesome-nav](https://lukasgeiter.github.io/mkdocs-awesome-nav/), which Zensical runs+natively, reads the `.nav.yml` file of a folder for the order of its pages, and a page's+title is its first heading (or the `title` of its front matter):++- [`docs/content/.nav.yml`](https://github.com/academa-labs/manimgx/blob/main/docs/content/.nav.yml)+ makes the navbar's tabs, and gives the User Guide's reading order: Welcome, the+ Quickstart, the chapters, then the Reference.+- `developer-guide/.nav.yml` orders this guide.+- The reference's navigation is the folder tree that `scripts/docs/reference.py` writes+ (below): each level's own page comes first, as its Overview.++A section's own page (`index.md`) is a page like the others, listed first in its sidebar:+Welcome, this guide's Setup, a reference level's Overview. `navigation.indexes`, which would+make it the section's title instead and leave it out of the sidebar, is off.++## Welcome: the home page++[`docs/content/index.md`](https://github.com/academa-labs/manimgx/blob/main/docs/content/index.md),+the User Guide's first page, is the README: `pymdownx.snippets` includes it+(`--8<-- "README.md"`), so the two can't drift. The README reaches the site's images and+pages by absolute URLs, for GitHub and PyPI; on the site they become its own paths+([`docs/links.py`](https://github.com/academa-labs/manimgx/blob/main/docs/links.py)), so+`just serve-docs` shows the images it built. The README's picture of its scene ends in+`#readme`: GitHub and PyPI show it, and the site, which shows the film itself above the+code, hides it (`stylesheets/manimgx.css`).++## The README++The README is the front page on GitHub and on PyPI, which render it themselves, so it is+written in plain GitHub Markdown, with absolute links (PyPI resolves no relative link). Its+images are the site's. GitHub and PyPI play no video, so what moves in them is an animated+image: SVGs that play themselves where the picture is made of paths, sharp at any size and+a fraction of a video's weight, and an AVIF where it is not. An SVG draws a surface's shape+exactly (a circle in space is seen as an ellipse, a sphere's outline is one), but not its+light, and a browser repaints an animated SVG at the screen's rate: six shaded films as SVGs+cost Firefox two to three cores to play, the AVIF tiles at 25 frames a second 0.6 of one.++- **The banner** (`showcase/logo-dark.svg` and `logo-light.svg`): the logo, which plays+ its opening once. The word ManimGX, typeset by manimgx's Typst (𝕄 as `$bb(M)$`, "anim" in+ New Computer Modern Bold, "GX" in Playwrite NO), is written in; then Manim's circle,+ square and triangle are drawn and each becomes a solid, a sphere, a cube and a pyramid,+ every frame a projection of their scene.+ [`scripts/showcase/logo.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/showcase/logo.py)+ draws it, the header's still logo (`images/logo-*.svg`) and the favicon;+ `python -m scripts.showcase.logo` draws them again.+- **The wall** (`showcase/<film>.avif` and `<film>@2x.avif`): five seconds of six example+ films, three a row, each its own image, linked to its film.+ [`scripts/showcase/wall.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/showcase/wall.py)+ runs each film's scene and keeps its moment: on no background, so the page's own shows+ through, light or dark; without what the film fixes in the frame (its titles and+ readouts); as an animated AVIF with alpha at 25 frames a second, which GitHub and PyPI+ show; at a tile's size and twice it, which a `<picture>` picks by the screen's density+ (GitHub keeps it; PyPI shows the larger). A browser decodes an animated image on the CPU,+ frame after frame: at 60 frames a second the wall fell behind (Chromium showed some 50, for+ a core's work); at 25 every tile shows every frame. GitHub's image proxy served an image of+ 4.97 MB and refused one of 6.35 MB; the largest tile is 1.3 MB. The films take a minute to+ run, so the tiles are committed; `python -m scripts.showcase.wall` makes them again.+- **The chart** (`images/benchmark-light.svg` and `benchmark-dark.svg`): the benchmark, as+ a race; `scripts/benchmark/chart.py` draws it from `scripts/benchmark/results.json`.+- **The scene's film** (`films/readme-<scene>.svg`): `docs/examples.py` records the README's+ scene frame by frame with+ [`docs/svg.py`](https://github.com/academa-labs/manimgx/blob/main/docs/svg.py), which+ reads the view and each path's paint at every frame and writes them as an SVG that+ plays itself (SMIL): a README scene is made of paths, whose shapes hold still.++## Examples: films rendered from the code++[`docs/examples.py`](https://github.com/academa-labs/manimgx/blob/main/docs/examples.py)+renders the examples before the site is built:++1. It gathers the Python blocks (fenced as `python` or `py`) of the pages, of the README+ and of the docstrings in `src/manimgx/`, and keeps those that define a+ scene: a class whose base's name ends in `Scene` (the block's last, if it defines several).+2. It renders each scene at 1280 × 720 and 60 frames per second, the films' own rate, in a+ process of its own (an example may change the configuration: a 9:16 one renders tall),+ into `docs/content/films/`: a still of its last frame with anything on it, and a video+ too if anything moves.+3. A film is named after its scene and a digest of its code and of how films are made+ (`FORMAT`), so an example renders once per version of its code, and all of them again+ when the format changes. Only missing films are rendered, and films no example makes+ any more are deleted.++While the site builds, `fence`, the formatter that `zensical.toml` gives Python blocks,+puts each block's film above its code. `show="code"` shows the code alone, and+`show="film"` the film alone: two blocks with the same code let a page put words between+a program and its video (the Basics shows a command there). On the page, a film plays+while it is on screen, unless the reader prefers reduced motion.++So a scene's name is its film's, and must be unique across the docs; a failed example fails+the build. A block meant to show code without a film defines no scene. Given paths,+`python -m docs.examples docs/content/user-guide` renders only the examples written under+them.++A narrated example (`self.say(…)`) says what `docs/voice/` keeps, since the site is built with+no voice's key: a new or changed line is spoken once, by a render with `FAL_KEY`, and its+audio and words are committed with it.+[`tests/docs/test_examples.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_examples.py)+fails until they are.++A film is encoded for the web (x264's `slow` preset at CRF 28): a tenth of the size of a+render's default (`ultrafast`, 18), alike to the eye, made in the same time.++## The Gallery++[`scripts/docs/gallery.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/docs/gallery.py)+writes the Gallery from `examples/` alone, before the examples are rendered: a page of cards,+one for each film, and a page for each film. What it says is in+[`examples/README.md`](https://github.com/academa-labs/manimgx/blob/main/examples/README.md),+which lists every example once:++- **The first page:** the README's introduction (its first paragraph), then its groups, in+ their order, each a grid of cards. A card shows the film's still+ (``, which `docs/films.py` resolves), its title and its first+ sentence. The whole card is a link to the film's page.+- **A film's page:** its line in the README,+ `- [The Hopf fibration](hopf_fibration.py): The 3-sphere is made of circles…`, gives its+ title and its words, a sentence or two. Then the film, and its code, the file, folded under+ it: a block marked `fold`, whose film `docs/examples.py` renders as it renders every+ example's. The file's docstring tells the mathematics, for the reader who opens the code.+- **Its navigation:** `gallery/.nav.yml`, written with the pages: the README's groups, so+ that a film's page lists every film beside it.++The pages are generated (`content/gallery/`, git-ignored), so an example added to `examples/`+and its README is in the Gallery at the next build.+[`tests/docs/test_gallery.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_gallery.py)+checks that every example has its card and its page, and that a card says one short sentence.++## The API reference++**The problem:** a reference generated from the package lists what the package has, module+by module: it misses no name, but it tells no story. A reader finds every class and learns+nothing of how the parts of a video fit together, and reads every name Manim CE kept, useful+or not. A reference written by hand tells the story, but misses the names added after it, and+keeps the names removed since.++**The solution:** the reference is written by hand, as a story, and renders the API from the+package; tests keep the two together.++- **Its story:** a video is a scene, which shows mobjects, which animations change and+ updaters keep, as the camera sees them, with sound, until rendering makes the video. Each+ section of `docs/content/reference/` tells one part, in Learn's order: Scenes, Mobjects,+ Animations, Updaters, Camera and 3D, Sound, Rendering. A section opens with what its part+ is, then a card for each of its pages. A page is a topic, not a class: "Lines and arrows"+ tells Line, then Arrow, then Vector, then the tips, as one story.+- **Its API:** a page writes its story in prose, and renders each object in it with+ mkdocstrings' `::: manimgx.Circle` block, from its docstring, in the order the story needs.+ A class's block shows its members, unless the page lists some, or none (`members: false`),+ to show them under headings of its own (Mobject's, on six pages). A member a public class+ takes from a private base (`_Grid`'s, Matrix's and Table's) is listed in the block's+ `inherited_members`.+- **What it leaves out:** a class, a function or a property decorated with `@deprecated`+ (PEP 702): a name kept only for code written for Manim CE, which ty flags where it is+ used.+ [`docs/deprecated.py`](https://github.com/academa-labs/manimgx/blob/main/docs/deprecated.py)+ removes each one as griffe loads the package, so it has no entry, its class does not list+ it, and a link to it does not resolve. A deprecated class stays in its module, under no+ other name, for the classes made from it to take their constructor from: no page shows it,+ nor what they take from it. The extension reads the decorator in the source, as ty does (a+ property's, on its getter). An attribute, a constant or a type alias can't carry+ the decorator: the few that no scene needs are listed in+ [`tests/docs/test_reference.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_reference.py)'s+ `UNDOCUMENTED`.+- **What keeps it whole:** `tests/docs/test_reference.py` finds what the package documents+ (every name it exports, and every documented member of an exported class) and what the+ pages render, and fails on a name no page shows, one shown twice, or one deprecated. The+ site's strict build fails on a block or a link whose object is gone.+ [`tests/docs/test_hidden.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_hidden.py)+ type-checks every example the docs show, `deprecated` an error, so no page teaches a+ hidden name.+- **Cards:** a section's page shows its pages as cards: a film's still, the page's name and+ a sentence, the whole card a link. A card names its film by its scene,+ ``, which+ [`docs/films.py`](https://github.com/academa-labs/manimgx/blob/main/docs/films.py)+ resolves to the film the examples' renderer made, whatever its digest. Each page opens with+ such a film, its code folded under it: a card's picture, and the page's.++The pages are rendered by [mkdocstrings](https://mkdocstrings.github.io), which reads the+docstrings with [griffe](https://mkdocstrings.github.io/griffe/).+[`docs/templates/python/material/`](https://github.com/academa-labs/manimgx/tree/main/docs/templates/python/material)+shows an entry as a scene writes it:++- **Its film first:** the docstring's example, its code folded under it, then what it is.+- **Its call, without types:** `m.Circle(radius=None, …)`, `self.play(…)`,+ `circle.surround(…)`, `Circle.from_three_points(…)`, `class MyScene(m.Scene):`; an+ editor shows the types.+- **What it takes, in words:** each parameter's name and description. Its `**kwargs`, a+ `TypedDict`, is opened by vocabulary: the keywords one class owns are listed on its+ entry ("A [Matrix][manimgx.Matrix]'s keywords …", its docstring says) and linked from+ every other; the style, tip, animation and transform keywords are one link each, to where+ they are told.+- **Its source, one click away:** a Source button that opens the code where it is defined.++A module's docstring is not shown: in manimgx it is a note for the developers who change the+module. mkdocstrings reads the `custom_templates` setting from the working directory, and+Zensical passes it on as written, not made absolute from the settings' folder as MkDocs+does; [`docs/mkdocstrings.py`](https://github.com/academa-labs/manimgx/blob/main/docs/mkdocstrings.py)+makes it absolute before mkdocstrings reads it.++## Instant previews++Rest the pointer on a link to a page of the site, and a preview of its target opens. A+reference to the API previews too: its name, signature, bases and summary, as an editor's+hover shows them. So the summary line of a docstring is also what its previews show.++- **Which links preview:** Zensical's `preview` extension marks every link to a page of the+ site (`targets.include = ["*"]` in `docs/zensical.toml`), but not a heading's `¶` or a+ footnote. A reference to the API is an `<autoref>` tag until Zensical resolves it, after+ the extension has run. So+ [`docs/previews.py`](https://github.com/academa-labs/manimgx/blob/main/docs/previews.py)+ marks each of these tags, and the link keeps the mark. It also takes the mark off a+ card's link: the card shows its page's still, name and words already, and a preview would+ cover the cards beside it.+- **What a preview shows:** the theme shows the target heading and the text after it, up to+ the next heading. `stylesheets/manimgx.css` limits the preview of an API object to its+ name, signature, bases and summary, and the preview of a module to its members' names and+ summaries. No icon marks a link that previews, because every link to the site does.+- **After a change to a Markdown extension in `docs/`:** delete `docs/.cache`. Zensical's+ cache does not see a change in an extension's code, so a build reuses the pages it made+ before.++## The command line's reference++[`scripts/docs/reference.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/docs/reference.py)+writes the command line's reference,+[`reference/rendering/command-line.md`](../reference/rendering/command-line.md), from the+Typer app itself (`typer manimgx.cli utils docs`): the one page of the reference that is+generated. It is always the app's, and it is not committed.++## Docstrings++The reference is made from the docstrings, so they are written for readers of the docs:++- They follow the+ [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings):+ a summary line, then `Args:`, `Returns:`, `Raises:` and `Examples:` sections.+- An example is a Python block, under `Examples:`, that defines a scene. It is rendered like+ the pages' examples, so its scene's name is unique across the docs+ (`TipableVMobjectAddTipExample`, say).+- A docstring links to another object as `[text][manimgx.path.to.it]`, an autoref. The+ object must be on a page of the reference: the site's strict build fails on a link whose+ target no page shows. A class's keywords are linked by their class+ (`[number line keywords][manimgx.NumberLine]`), whose entry lists them.++## Markdown for agents++An agent reads Markdown better than a page's HTML. Zensical's+[`llmstxt` plugin](https://zensical.org/docs/compatibility/mkdocs/plugins/#llmstxt), set in+`[project.plugins.llmstxt]` of+[`docs/zensical.toml`](https://github.com/academa-labs/manimgx/blob/main/docs/zensical.toml),+writes three things:++- **Each page's Markdown, beside the page:** `/user-guide/quickstart/index.md` beside+ `/user-guide/quickstart/`. The plugin converts the page as it is built, so the Markdown+ has what the page shows: the examples' code, the admonitions, the reference's signatures.+ A page's one action, Copy as Markdown (`content.action.copy`), copies it.+- **`llms.txt`,** at the site's root, <https://manimgx.academa.ai/llms.txt>, which the+ README tells an agent to follow. First, a primer for an agent asked to make a video with+ manimgx: how to install it, a scene, `check` then `render`, and a cheat sheet of the API.+ Then a list of every page's Markdown, by section.+- **`llms-full.txt`:** every page's Markdown, in one file.++The primer is the plugin's `markdown_description`, written by hand, so+[`tests/docs/test_llms.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_llms.py)+checks it against the API: its scene runs, and every name it teaches exists. The plugin+writes the Markdown only of the pages its sections name, so the sections name every page+with patterns (`user-guide/*.md`), and the test checks that each page matches one: a page in+a new folder needs a pattern.++## The agent skill++[`skills/manimgx/SKILL.md`](https://github.com/academa-labs/manimgx/blob/main/skills/manimgx/SKILL.md)+is manimgx's [agent skill](https://agentskills.io). `npx skills add academa-labs/manimgx`+and `gh skill install academa-labs/manimgx` find it by its path, `skills/<name>/SKILL.md`,+and copy its folder into an agent's skills, so the folder stays where it is. The installers+read its front matter, so+[`tests/docs/test_skill.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_skill.py)+checks it against the [specification](https://agentskills.io/specification): the name is+its folder's, and the description is 1 to 1,024 characters.++## The changelog++[`docs/content/changelog.md`](https://github.com/academa-labs/manimgx/blob/main/docs/content/changelog.md)+follows [Keep a Changelog](https://keepachangelog.com). The first release, 0.1.0, has no+changes to list: its section says only that it is the first. After it, a change a user would+notice adds a line under "Unreleased", in the same pull request. A release moves those lines+into its version's section, which becomes the release's notes (see+[Project management](project-management.md#releases)).++## Local preview++```sh+just serve-docs+```++Writes the Gallery, renders the missing films, writes the reference, then serves the site at+<http://localhost:8000> and rebuilds it as its pages change. An example that fails to render+is reported and served without its film. A block added while it serves+has no film until the examples are rendered again, and a name added to or removed from the+package's exports shows in the reference once `just serve-docs` runs again: the reference's+pages are written before it serves.++```sh+just build-docs+```++Writes the Gallery, renders the examples, writes the reference, and builds the site into+`docs/site/` with `--strict`: a warning, such as a link to a page or a name that does not+exist, fails the build. This is what CI deploys.++Zensical runs as `python -m zensical`, from the repository's root, which it puts on the+path, so it can import `docs.examples.fence`; `--config-file docs/zensical.toml` gives it the+site.++## Deployment++The site is static files, served by+[Cloudflare Workers](https://developers.cloudflare.com/workers/static-assets/) as static+assets: no Worker script runs, and every request is answered from the files in `site/`.+[`.github/deploy/docs.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/docs.jsonc)+configures it:++- The Worker, `manimgx-docs`, serves the site at its domain,+ [manimgx.academa.ai](https://manimgx.academa.ai).+- A page is a folder (`changelog/index.html`): a request for `/changelog` is redirected to+ `/changelog/`.+- A path that matches nothing gets the nearest `404.html`, with status 404.+- `docs/content/_headers` is copied to the site's root, where Cloudflare reads it (it is+ never served): security headers for every page, long caching for the theme's bundles+ (their names change with their content), and `noindex` on `workers.dev` hosts.++The workflow [`deploy-docs.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/deploy-docs.yaml)+builds the site on every push and pull request, deploys it from `main`, and previews each+pull request from a branch of the repository at its own address,+`pr-<number>-manimgx-docs.<account subdomain>.workers.dev`. See+[GitHub workflows](github-workflows.md#3-deploy-docsyaml-the-docs-site).++## Learn more++- [Zensical's documentation](https://zensical.org/docs/): setup, authoring, and its+ compatibility with Material for MkDocs.+- [awesome-nav's documentation](https://lukasgeiter.github.io/mkdocs-awesome-nav/): what a+ `.nav.yml` can say.+- [mkdocstrings' Python handler](https://mkdocstrings.github.io/python/): the options in+ `zensical.toml`.+- [Cloudflare's static assets](https://developers.cloudflare.com/workers/static-assets/):+ routing, headers, previews.diff --git a/docs/content/developer-guide/engine.md b/docs/content/developer-guide/engine.mdnew file mode 100644index 00000000..d624c62c--- /dev/null+++ b/docs/content/developer-guide/engine.md@@ -0,0 +1,390 @@+# The engine++The engine is the Rust crate in [`rust/engine/`](https://github.com/academa-labs/manimgx/tree/main/rust/engine), one of the+crates of the Rust workspace, [`rust/`](https://github.com/academa-labs/manimgx/tree/main/rust).+maturin compiles it into the package as `manimgx._engine`, a Python extension module. It+does three things: it draws frames on the GPU, encodes them into an MP4, and typesets text.+Python decides what each frame shows; the engine makes the pixels. It also records a film as+a *take*, the same work written down, for manimgx's player to play: one player, the same in a+window of its own on this machine's screen (`manimgx preview`) and on a page's canvas, where+the engine itself, compiled to WebAssembly, is the player.++## Why a compiled engine?++Drawing a frame means computing millions of pixels, and a GPU does that through native+APIs (Metal, Vulkan) that Python cannot reach directly. Typst is a Rust library, and x264+a C library. A compiled extension module holds all of them in the Python process: no+subprocess, and no files passed between programs.++The crate's dependencies do the heavy lifting:++- [wgpu](https://wgpu.rs): one GPU API over Metal, Vulkan and the others.+- [PyO3](https://pyo3.rs): the Python module, its classes and its functions.+- [wasm-bindgen](https://wasm-bindgen.github.io/wasm-bindgen/): the player's bindings to+ JavaScript, and wgpu's to the browser's WebGPU and Web Audio.+- [Typst](https://github.com/typst/typst) (`typst`, `typst-kit`, `typst-layout`): the+ typesetter, as a library.+- [mitex](https://github.com/mitex-rs/mitex): LaTeX converted to Typst.+- [x264](https://www.videolan.org/developers/x264.html): the H.264 encoder, a C library,+ built from its source with the engine (`rust/x264/`).+- [FFmpeg](https://ffmpeg.org)'s audio decoders, with [libopus](https://opus-codec.org) for+ Opus: C libraries, built from their sources with the engine (`rust/ffmpeg/`).+- [winit](https://github.com/rust-windowing/winit): the window `manimgx preview` plays in;+ [cpal](https://github.com/RustAudio/cpal): its sound, on macOS and Windows.+- [rustybuzz](https://github.com/harfbuzz/rustybuzz), the shaper Typst sets text with, and+ [unicode-bidi](https://github.com/servo/unicode-bidi): the player's face's text, in lines.++## Files++| File | What it holds |+| --- | --- |+| [`src/lib.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/lib.rs) | The crate: its builds (features), and the content key |+| [`src/render.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/render.rs) | The GPU's player (`Player`, Python's too): the store of shapes, a frame's passes, the GPU |+| [`src/lavapipe.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/lavapipe.rs) | Mesa's lavapipe, which a Linux wheel bundles, loaded where no GPU driver is |+| [`src/python.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/python.rs) | The Python module: the `Player` and `Recorder` classes and the functions Python calls |+| [`src/take.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/take.rs) | A take's messages, written and read |+| [`src/pack.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/pack.rs) | A take's arrays, each coded against the one it replaces |+| [`src/project.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/project.rs) | The projector: takes as they come, any frame of them drawn on demand, in bounded memory |+| [`src/player.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/player.rs) | manimgx's player, on any screen: the projector on a clock, its face and sound, its viewer's input |+| [`src/chrome.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/chrome.rs) | The player's face (its controls, its text), drawn by the engine itself |+| [`src/text.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/text.rs) | The face's text: lines shaped as Typst shapes them, in manimgx's fonts |+| [`src/speaker.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/speaker.rs) | The player's sound, following its clock: a window's (cpal), a page's (Web Audio) |+| [`src/window.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/window.rs) | The player in a window on this machine's screen (winit) |+| [`src/web.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/web.rs) | The player on a page's canvas (WebAssembly) |+| [`src/export.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/export.rs) | A film's video: frames converted and handed to the encoder |+| [`src/vector.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/vector.rs), [`src/vector.wgsl`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/vector.wgsl) | A 2D view, drawn exactly |+| [`src/blend.wgsl`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/blend.wgsl) | The raster pipeline: 3D views, point clouds and meshes |+| [`src/paint.wgsl`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/paint.wgsl) | Paint, as both pipelines evaluate it |+| [`src/nv12.wgsl`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/nv12.wgsl) | A frame's changed macroblocks, converted for the encoder |+| [`src/encode.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/encode.rs) | H.264 through x264 |+| [`src/mp4.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/mp4.rs) | The MP4 file |+| [`src/audio.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/audio.rs) | Sound read from its files (FFmpeg), and resampled |+| [`src/aac.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/aac.rs) | A film's sound, as AAC |+| [`src/typeset.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/src/typeset.rs) | Typst as a library, and mitex |+| [`build.rs`](https://github.com/academa-labs/manimgx/blob/main/rust/engine/build.rs) | The player for a page, built beside Pyodide's module and carried inside it |+| [`../mitex-spec-gen/`](https://github.com/academa-labs/manimgx/tree/main/rust/mitex-spec-gen) | mitex's Typst package (fetched), and the LaTeX command spec made from it |+| [`../x264/`](https://github.com/academa-labs/manimgx/tree/main/rust/x264) | x264, built from its source (fetched), behind a C shim and a few safe calls |+| [`../nasm/`](https://github.com/academa-labs/manimgx/tree/main/rust/nasm) | NASM, built from its source (fetched), for x264's x86-64 assembly |+| [`../ffmpeg/`](https://github.com/academa-labs/manimgx/tree/main/rust/ffmpeg) | FFmpeg's audio decoders and libopus, built from their sources (fetched), behind a C shim and one safe call |+| [`../fetch/`](https://github.com/academa-labs/manimgx/tree/main/rust/fetch) | The sources the other crates build from, fetched by their build scripts and pinned by the hash of their files |++Each file begins with a comment that states its design.++## The boundary with Python++[`src/manimgx/_engine.pyi`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/_engine.pyi)+is the engine's interface as Python sees it, typed: the `Player` and `Recorder` classes,+the typesetting functions, `digest` (the content key that names what is uploaded), `note`+and `TypstError`. It is+written by hand, so a change to the engine's interface changes it too; ty checks the Python+code against it.++- **One module for every Python from 3.13 on.** The crate builds against Python's stable+ ABI (PyO3's `abi3-py313`).+- **Bytes, not objects.** What crosses is packed arrays: control points as float64,+ records of 320 bytes, a view of float32s. Python packs them with numpy+ ([`rendering/feed.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/rendering/feed.py));+ the engine reads them as they are. A shape crosses as its object defines it, and the+ engine derives what drawing needs: it flattens a path's curves, and sums a mesh's faces+ into its vertices' normals.+- **Upload once, then per frame.** `add_path`, `add_points`, `add_mesh`, `add_rows` and+ `add_texture` store a shape, a set of color rows or an image under a key; `grow_path`+ extends a path, and `evict` forgets what no frame shows any more. A frame is then a view+ and its records: `render` draws one and reads it back as RGBA, and `push` sends one to+ the video that `begin_export` started and `end_export` finishes.+- **A take is the same calls, written down.** `Recorder` takes the uploads a `Player` takes,+ then `frame` for each frame, and writes them as messages: a take, which the projector reads+ back (see [The player](#the-player) and [The browser](#the-browser)). A film given `take`+ records into one.+- **The GIL is released** while the engine draws and encodes, so other Python threads run.+- **One GPU per process**, brought up on a thread of its own once the process knows it will+ draw (`start_gpu`): a drawing command starts it before the rest of the command line loads,+ and a film with a video or frames as it begins. It comes up meanwhile, and the first frame+ waits for it; a process that never draws (`manimgx --version`, a take, a film that only+ counts its frames) never brings it up. A process that ends before the GPU is up waits for+ it, as Python exits: exit unloads the drivers, and must not unload one while it starts.++## Drawing++wgpu takes the high-performance adapter: Metal on macOS, Direct3D 12 on Windows (WARP,+on the CPU, where there is no GPU), Vulkan on Linux. The engine needs one that can blend+float32 render targets, since a 2D view adds up its coverage in one.++On Linux, where no adapter will do (no GPU driver: a server, a container), the engine draws+with Mesa's lavapipe, Vulkan on the CPU, which the Linux wheels bundle beside it+(`manimgx/lavapipe/libvulkan_lvp.so`, built from Mesa's source with LLVM linked in by+[`scripts/release/build_lavapipe.sh`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/build_lavapipe.sh)).+`src/lavapipe.rs` loads it as Vulkan's loader loads a driver, and gives wgpu an instance of+it: neither the system's loader nor the environment is involved, and a machine with a GPU+never loads it. An engine built from source has none of its own; there, the system's Mesa+draws.++### A 2D view, exactly++No tessellation, no stencil, no multisampling: each pixel's coverage is the area of the+object inside it, computed from the control points.++1. A compute pass flattens every curve of every path into as many segments as its size on+ screen needs (Wang's bound, to 1/32 of a pixel), every frame, at the size it is drawn.+2. A raster pass adds each segment's exact area into the object's rectangle of a float+ atlas: a fill by its winding, a stroke as pieces along the curve's exact normals, with+ its joints and caps.+3. A compute pass composites each 16×16 tile of the view over the objects that reach it,+ in draw order. It keeps each pixel as two regions split by a line, so edges that two+ shapes share do not show what lies under them.++A 2D view's point clouds and meshes are drawn by the raster pipeline, into layers that the+composite lays in their place in the order.++See `vector.rs` and `vector.wgsl`.++### The raster pipeline++The raster pipeline draws every object of a 3D view, and a 2D view's point clouds and+meshes, with real depth. A vertex is placed by the blend itself:+clip = C₁·S₁ + C₂·S₂, where Cₖ = camera · Mₖ is composed on the CPU once per object (the+second term only while a shape morphs). The kinds differ only in how their vertices become+triangles:++- A path's fill is a fan counted into the stencil, then covered, unless the shape is+ convex, fully shown and still; its stroke is a ribbon in screen space.+- A point is a disk that faces the camera.+- A mesh is its triangles, optionally textured.++Where 3D surfaces can be seen through, each fragment is appended to a list per pixel, and+the lists are composited in depth order: a pixel shows every surface on its ray, the nearer+over the farther, whatever order they were drawn in.++A camera's picture, as a [`ZoomedScene`][manimgx.ZoomedScene] shows it, is a view drawn+first into a texture, which the frame then samples by its key.++See `blend.wgsl`, and the `Player` in `lib.rs`.++### Paint++`paint.wgsl` is shared by both pipelines. Colors mix in OKLab, weighted by opacity, as+Python's colors mix. A gradient is evenly spaced stops. A tween's paint is two paints and+how far the second is mixed in: the engine mixes them, so a tween uploads nothing.++## Encoding++**The problem:** encoding a video frame by frame repeats work where nothing changed, and+most of an animation's frame does not change: a moving square touches a few blocks of the+picture.++**The engine's answer:** the records say what changed, so only that is converted, read+back and analyzed.++1. For each frame, the engine finds the 16×16 macroblocks that can differ from the+ previous frame: the old and new footprints of every record that changed. A new camera,+ objects added or removed, or anything that cannot be bounded makes it the whole frame.+2. It converts only those macroblocks to NV12 on the GPU (`nv12.wgsl`), and reads only+ those back.+3. x264, on a thread of its own, is told which macroblocks are unchanged and skips its+ analysis there (`encode.rs`).+4. `mp4.rs` writes each picture as a sample of an MP4; a held frame is one sample that+ lasts longer. The header is written first, so a player can start before the file has+ arrived.++[`Film.export`][manimgx.Film.export] reports how it went: the seconds taken, the part of+them in x264, the share of macroblocks converted, and the file's size.++x264 is built with the engine, from its source (r3223, 8-bit, without its command line), so+nothing is installed and the engine links it statically. Its build+script writes the configuration x264's `configure` would for the target, then compiles its+C and its assembly with the `cc` crate: NEON and SVE with the C compiler on AArch64; on+x86-64, SSE to AVX-512 with NASM, which x264's x86 code is written for. NASM comes from its+source too (`rust/nasm/`): compiled into x264's build script, which runs it as a process of+itself. Elsewhere, x264's C alone; assembly makes x264 two to five times faster. Rust sees+x264 through `x264/src/shim.c`, which sets x264's parameters and moves pictures in and samples+out, so x264's structs never cross into Rust. The build takes a few seconds, and makes the+same bytes as a `configure`-built x264.++## Typesetting++`typeset.rs` runs Typst as a library. `typeset` takes Typst source and returns its layout,+read straight off Typst's frames: every glyph with its outline's key, its placement, its+paint and the bytes of the source it draws; every shape as cubic curves; every labelled+group as the items inside it. A glyph's outline comes separately, by key+(`glyph_outlines`), so it crosses once.++Fonts come from the folders Python passes, manimgx's own among them: the font packages'+([`fonts/manimgx-fonts/`](https://github.com/academa-labs/manimgx/tree/main/fonts/manimgx-fonts)+and+[`fonts/manimgx-fonts-cjk/`](https://github.com/academa-labs/manimgx/tree/main/fonts/manimgx-fonts-cjk),+published apart and required at exact versions), then from Typst's embedded fonts. The+system's fonts are read only for a family a text names: their scan is cached on disk, and+they are memory-mapped, not read whole (a CJK font can be 60 MB).++LaTeX reaches Typst through mitex (`mitex_math`, `mitex_text`). mitex converts by a+*command spec*: which LaTeX commands it knows, and how many arguments each takes. mitex's+own spec crate reads the spec from a git submodule or makes it with a `typst` on the PATH;+`rust/Cargo.toml` replaces that crate with+[`mitex-spec-gen`](https://github.com/academa-labs/manimgx/tree/main/rust/mitex-spec-gen),+which fetches mitex's Typst package (with its own `lib.typ`, which imports only the scope the+converted LaTeX calls) and holds the spec (`spec.rkyv`) made from it. The engine serves the+package to Typst itself, as `@preview/mitex:0.2.7`, so+the converted code finds its scope with no files on disk, and the converter and the Typst+code it converts for come from the same files. `cargo test -p mitex-spec-gen`, in `rust/`,+checks that the committed spec is still what the package makes, and that the engine serves+every file of it; after an upgrade of mitex, `MITEX_SPEC=write cargo test -p mitex-spec-gen`+writes the new spec. No workflow runs it.++## The player++manimgx's player plays takes: [`manimgx preview`](../user-guide/rendering.md#preview) and+[`Window`][manimgx.Window] in a window of its own on this machine's screen, the npm package on+a page's canvas. It is one player, `player.rs`, the same code on both screens: a screen gives+it a surface, hands on its viewer's input, draws it when it is due and does what it asks. The+window's screen is winit's (`window.rs`); a page's is the engine compiled to WebAssembly+(`web.rs`), with the page's element handing on its events+([`browser/src/player.ts`](https://github.com/academa-labs/manimgx/blob/main/browser/src/player.ts)).++- **Any frame, at once.** The player keeps the take as sent (`project.rs`), and draws the frame+ its clock is at, at the size it is shown, in the screen's own pixels. A newer take, the scene+ run again, replaces the one shown once it has the moment shown, or ends: an edit never loses+ the place. A take ends with a message of its own (END), which says whether its scene failed:+ a failed take replaces the shown one only if it got to the moment shown. A save cuts a run it+ makes out of date (the take raises `Cut`), and the scene runs again at once. A frame whose+ see-through layers overflow the lists is drawn again once its count is back: the player never+ waits for the GPU.+- **One clock.** It runs from an instant at a rate, waits at the last frame made while the take+ is being recorded, and stops at the end; a frame is drawn for the moment it is seen (a+ refresh of the screen ahead). The sound follows it (`speaker.rs`), continuous while the clock+ runs, again from the clock after a jump or 30 ms of drift: in a window, written for the+ instant it is heard (cpal; on Linux the window is silent, as the system's audio would be+ linked, ALSA); in a page, a Web Audio source started at the context's moment that is heard+ when the clock is there (its output timestamp ties the context's clock to the page's).+- **Its face is the engine's own drawing.** The controls, the time, the plays (its chapters,+ named by the lines that played them), the captions, the error and the keys are shapes and+ text, records of a 2D view over the film, drawn exactly (`chrome.rs`): no toolkit, and one+ face on both screens. Its text is set in lines, in manimgx's fonts (`text.rs`), shaped by+ rustybuzz, the shaper Typst sets text with: a test sets the face's lines both ways and finds+ the same glyphs in the same places. Typst itself, a typesetter of documents, would be 28 MB+ of WebAssembly in a page; the lines take 0.7 MB. The player composites the film, at its+ place, and the face in one pass. A control is where the layout put it, so a click, a tap and+ a key do the same thing.+- **Input in the web's words.** A key comes as its `KeyboardEvent.key` value (winit names keys+ as the web does), a pointer as its place in pixels, a wheel's turn in points, the web's way+ round. Each input says whether the player took it, so that a page lets the rest go by: a+ vertical scroll over a film scrolls the page, a sideways one moves the playhead.+- **Notes, both ways.** The director's notes (JSON) give it the plays, sections and captions,+ and between takes the file's scenes and the scene's error. The player asks for another of the+ file's scenes: the window writes the ask as a line of JSON on its standard output, the page+ posts it to its director.++The window is a process of its own (`python -m manimgx.rendering.window`, whose main+thread runs the window's event loop, `_engine.window`), and the take reaches it through a pipe, on its+standard input: so the scene keeps its process — its main thread, its signals — as+`manimgx render` gives them, a script or a notebook can open one, and a scene that crashes+leaves the window up. A `Window` is a take: `Scene.render(take=window)`. Closing it cuts the+film sent to it (`Cut`); it closes when its director closes it, or goes. On a page, the player+runs on the page's own thread, as the window's runs on its own: its events, its clock, its+drawing and its sound on one thread, so it says at once whether it took an input.++Measured on an M4 Pro: a save is on screen 43-79 ms later; the window draws the heaviest+example film (the Hopf fibration, 2560×1440) in 0.5-1.7 ms a frame (the median), using 5-17%+of a core at 60 Hz in 150-320 MB. In Chrome, a page's thread spends 0.7 ms a frame on it, face+included (the median; 1.2 ms at the 95th percentile, at 1920×1080).++## The browser++In the browser, Python runs in [Pyodide](https://pyodide.org), which has no GPU, and the+engine is two WebAssembly builds of the same crate:++- **The Python module, without the GPU** (features `python` and `typeset`): typesetting, the+ content keys, sound read, and `Recorder`, but no `Player`. Pyodide's toolchain compiles it for+ `wasm32-unknown-emscripten`, and it ships as manimgx's wheel for the browser+ (`pyemscripten_2026_0_wasm32`, [PEP 783](https://peps.python.org/pep-0783/)). There, every+ film is recorded as a take.+- **The player** (feature `web`, for `wasm32-unknown-unknown`): `player.rs` on a page's canvas,+ drawing with WebGPU and sounding with Web Audio (`web.rs`). The page's element hands it the+ take as it comes (`feed`), its viewer's input (`key`, `pointer`, `press`, `release`, `cancel`,+ `wheel`) and its canvas's size, and draws it when it is due (`wake`, `draw`). It keeps the+ take as sent, coded, and makes a frame's shapes from it when the frame is drawn; the GPU's+ player keeps what the frames drawn lately drew, up to a budget. Its face's fonts come from+ Pyodide, the ones the window's face is set in: `_engine.face_fonts` gives manimgx's font+ files and Typst's monospace font.+ [`browser/`](https://github.com/academa-labs/manimgx/tree/main/browser) holds the+ page's side: the element and the director's worker (Pyodide).++A take is the protocol between Python and the player: `manimgx preview` sends one through a+pipe to its window, and in the browser the director hands one from Pyodide to the page. What+its uploads hold goes as arrays (`pack.rs`), each under a key of its+kind and content, sent once, and coded against the array it replaces: the same role's in what+the same record slot drew the frame before, which the writer reads off the frames' records. A+film whose shapes change a little every frame is sent as their changes: the example films'+takes are 14 times smaller for it (50 GB in all before, 3.6 GB after), and a 3D film of 30+seconds is tens of megabytes, where it was gigabytes. A mesh's points, uvs and normals go as+float32, the precision the GPU draws them at; everything else goes exactly as Python gave it. The frames the browser draws match the native engine's: of the+integration corpus's 841 scenes, 534 are identical in every frame, and the others differ by+rounding, one level in a few pixels.++## Others' sources++The repository holds only manimgx's code. What the engine is built from that others wrote —+x264 and NASM, FFmpeg's audio decoders and libopus, mitex's Typst package — its crates' build+scripts fetch from where each project publishes it (`fetch::tree`, in `rust/fetch/`), each+pinned by the SHA-256 of its files: their paths and bytes, not an archive's, which hosts+regenerate, so any copy of the same files passes. A tree is fetched once into the crate's+build folder and found again by that hash. The first build needs the network, as cargo does+for crates. `MANIMGX_SOURCES` names a folder for the archives (an absolute path): a build reads+an archive there, and downloads it there first if it isn't. A folder that holds them builds+offline; one shared by your checkouts downloads each archive once; and a build into an empty+one gathers what it was built from. A build script fetches the same archives on every target,+whatever it compiles of them, so one build gathers what every build reads.++That is how a release ships the wheels' complete source, which x264's GPL and FFmpeg's LGPL+ask for: `manimgx-X.Y.Z-source.tar.xz`, on the GitHub release (`just build-source` makes it).+It is the source distribution with `vendor/`, every crate `rust/Cargo.lock` names+(`cargo vendor`), `sources/`, the archives, and a `.cargo/config.toml` that reads them,+offline. The wheel the recipe builds from it gathers the archives into `sources/`, and shows+that nothing else is needed. Unpacked, it builds a wheel with the tools alone (Rust, a C+compiler, and maturin, which uv installs), reading nothing else from the network:++```sh+tar -xf manimgx-X.Y.Z-source.tar.xz+cd manimgx-X.Y.Z && uv build --wheel+```++Each is built by its crate's build script with the `cc` crate, the C compiler alone, the same+way on every target: no project's own build system runs. x264's and NASM's scripts write the+configuration their `configure` would for the target. FFmpeg's `configure` resolved the+components manimgx decodes with once, and `rust/ffmpeg/build.rs` keeps what it resolved (the+names it turns on, the files it compiles; the command is in the script's comment): its+configuration is written from that, in portable C (no assembly, no threads: one file decodes+at a time), the same on every target, the browser's included. Opus goes to libopus, the+reference decoder, which passes all of RFC 8251's test vectors (FFmpeg's own fails four).+`rust/ffmpeg/src/shim.c` decodes a file from memory into float samples, at most two channels+(wider sound is downmixed to stereo, scaled so it can't clip), starting and ending where the+file declares.++## Building++- `uv sync`, and every `uv run`, rebuild the engine when one of its sources changes, with+ maturin's release build: see+ [Project management](project-management.md#rebuilding-the-engine).+- `just build-wheel` builds this machine's wheel as a release does, with cibuildwheel, and+ tests it on every supported Python (see+ [Project management](project-management.md#distribution)); `just build-wheel pyodide`+ builds the browser's, with Pyodide's toolchain.+- `build.rs` builds the player for a page with Pyodide's module (a cargo of its own, in+ `rust/target/web-player/`), and the module carries it: `_engine.web()` gives its JavaScript+ and WebAssembly (`engine.js`, `engine_bg.wasm`), which the director hands to the page. It+ needs Rust's WebAssembly target (`rustup target add wasm32-unknown-unknown`); without it the+ module builds, with a warning. A native module carries none: natively, a film plays in a+ window.+- Cargo run by hand in `rust/` (`cargo clippy`, `cargo test -p mitex-spec-gen`,+ `cargo test -p fetch`) uses the `dev` profile, which is optimized too (`opt-level = 2`).+- `rust/engine/Cargo.toml` denies Clippy's correctness lints and warns on its suspicious and+ performance ones. No recipe, check or workflow runs Clippy: run `cargo clippy` in `rust/`.++The engine is tested through Python, by the suite and the integration corpus (see+[Testing](testing.md)); its Rust unit tests (`cargo test --lib`, in `rust/`) check that a take+reads back as it was written, that its arrays' codings decode exactly, and how the projector+takes takes in: a newer one replacing the shown one at the frame shown, a failed one dropped+or ended, the stream read whole however it is cut. They also check the player: its keys by the+web's names, its chapters, a take's sound read as it was written, and the face's lines, set as+Typst sets them. The player in a page is tried by hand, in a browser. `cargo test -p fetch`+checks `MANIMGX_SOURCES`: an empty folder gathers an archive, whole, and a full one builds+with the archive gone from its URL.diff --git a/docs/content/developer-guide/github-workflows.md b/docs/content/developer-guide/github-workflows.mdnew file mode 100644index 00000000..5bfdeda4--- /dev/null+++ b/docs/content/developer-guide/github-workflows.md@@ -0,0 +1,277 @@+# GitHub workflows++## The problem++Some tasks must run the same way every time:++- **For every change**, pushed to `main` or proposed in a pull request: run the checks,+ and the tests on every system and Python manimgx supports; time it against the code+ before it; build the docs; publish the tests' coverage and a preview of the docs.+- **For every release:** test; build the wheels, the source distribution, the font+ packages and the executables; publish them to GitHub and PyPI, the package for the+ browser to npm, and the Docker image to ghcr.io.+- **For every issue and pull request:** a first reply to a newcomer's issue, a first+ review, and an assistant that a maintainer can ask.+- **Every week or month:** move the pinned actions and dependencies to their new releases.++Done by hand, steps get forgotten, and every run costs someone's time.++## What are GitHub Actions?++[GitHub Actions](https://docs.github.com/en/actions) runs automation on GitHub's servers+when something happens in the repository. A workflow is a file in `.github/workflows/`+that says:++1. **When it runs:** a push to `main`, a pull request, a tag, a comment, a click in+ GitHub's interface.+2. **What it does:** jobs, each a list of steps (commands, or published actions).+3. **Where it runs:** on a fresh virtual machine: Ubuntu, macOS or Windows.++A job that builds or tests begins as you would on a new machine: it checks out the+repository, installs `just` and `uv` (and, on Linux, Mesa's lavapipe to draw with when it+renders), and runs `just` recipes (see [Setup](index.md)). The+workflows run the justfile's recipes, so a task does the same in CI as on your machine.++## manimgx's workflows++manimgx has seven workflows, in+[`.github/workflows/`](https://github.com/academa-labs/manimgx/tree/main/.github/workflows).++### 1. [`test.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/test.yaml): the checks and the tests++**When it runs:**++- Every push to `main`.+- Every pull request.+- By hand, from GitHub's interface.+- When the Release workflow calls it.++**What it does**, in five jobs:++1. **Run pre-commit checks**, on Ubuntu: runs `just check`.+2. **Test the browser package**, on Ubuntu: runs `just test-typescript`, building the+ TypeScript package and checking its player, compiled worker, and public declarations.+3. **Test**, six times: on Linux, macOS and Windows, with Python 3.13 and with 3.14. Each+ runs `just test-coverage` (on Linux, with Mesa's lavapipe installed to draw with), and+ keeps its coverage data.+4. **Combine the coverage**, even when a test job failed: `just combine-coverage` makes one+ report of the jobs' data, and its table goes in the run's summary. The report is kept,+ with the data of a coverage badge (`badge.json`).+5. **Publish the coverage**, for `main`'s pushes and for pull requests from a branch of the+ repository: to the Worker `manimgx-coverage`+ ([`.github/deploy/coverage.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/coverage.jsonc)).+ `main`'s report is served at <https://coverage.manimgx.academa.ai>. Each commit's report+ is also a preview deployment of its own (in the preview `main`, or `pr-<number>`), which+ the commit's "coverage" status links to.++### 2. [`benchmark.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/benchmark.yaml): the timed benchmarks++**When it runs:**++- Every push to `main` and every pull request that changes the package, the engine, the+ examples, the benchmarks or the dependencies.+- By hand, from GitHub's interface, against a commit, branch or tag you name.++**What it does**, in one job on Ubuntu: installs Mesa's lavapipe to draw with, then runs+`just bench` against the base (see [Testing](testing.md#timed-benchmarks)). A pull request is+checked out merged into its base, so its base is the merge's first parent; a push to `main`+is compared with the commit before it. There what is judged is CPU time, and the GPU is+lavapipe's, on the CPU. A workload that became slower fails the job, and every workload's+change goes in the run's summary. It is the only job that measures time: time is only+comparable on one machine at one time.++### 3. [`deploy-docs.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/deploy-docs.yaml): the docs site++**When it runs:**++- Every push to `main`.+- Every pull request, as it is opened, updated, reopened and closed.+- By hand, from GitHub's interface.++**What it does**, in four jobs:++1. **Build**, on every run except a pull request's closing: installs Mesa's lavapipe (the+ examples' videos are drawn with it), runs `just build-docs` (the narrated examples speak+ from `docs/voice/`, so the build needs no voice's key), and keeps `site/` and+ `.github/deploy/docs.jsonc` for seven days.+2. **Deploy**, from `main` (a push, or a run by hand): deploys what the build made to+ Cloudflare Workers with `wrangler deploy --config .github/deploy/docs.jsonc`, the+ commit's hash as its message. The `docs` environment shows the site's address,+ <https://manimgx.academa.ai>.+3. **Preview**, for a pull request from a branch of the repository: uploads the build as a+ preview named `pr-<number>`, at its own address, shown on the `docs-preview`+ environment.+4. **Delete the preview**, when a pull request closes. A pull request that was never+ previewed has no preview to delete, and that failure is ignored.++See [Documentation](documentation.md#deployment) for how the site is served.++### 4. [`release.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/release.yaml): a release++**When it runs:**++- A pushed tag, `vX.Y.Z` (`just release`; see+ [Project management](project-management.md#releases)).+- A pull request that changes how releases are made: the release's workflows and scripts,+ the `pyproject.toml` files, the npm package, or the engine's crates' manifests and build+ scripts. It is a dry run: it builds everything, and publishes nothing.+- By hand, from GitHub's interface, on a branch: a dry run too.++**What it does**, in order. Everything is built before anything is published:++1. **Check the version.** A tag must be `v` followed by manimgx's version (in+ `pyproject.toml`), and the changelog must have a section for that+ version. A version that ends in `aN`,+ `bN` or `rcN` is a pre-release.+2. **Test**, on a tag: it runs the Test workflow.+3. **Build:** the wheels (`create-wheels.yaml`), the source distribution and the wheels'+ complete source (`just build-source`: the source distribution with every crate and each+ archive the engine's build fetches, which a wheel is built from, offline for the crates,+ gathering the archives, so it holds all the wheels are built from; see+ [Others' sources](engine.md#others-sources)), the font packages (`just build-fonts`), and+ the executables, from the wheels (`create-executables.yaml`).+4. **Draft the GitHub release**, on a tag: it signs each file's provenance (an attestation+ of the workflow, the commit and the run that built it, which+ `gh attestation verify FILE --repo academa-labs/manimgx` checks), and drafts the release+ `manimgx X.Y.Z` with the files (the complete source too, which PyPI doesn't get), its notes+ the changelog's section for the version (`just release-notes`), then where the complete+ source is, which x264's and FFmpeg's licenses ask for.+5. **Publish to PyPI:** the wheels and the source distribution, with `uv publish`, each+ with its [PEP 740](https://peps.python.org/pep-0740/) attestation, and the font packages'+ files PyPI doesn't have yet (`--check-url` skips the others: the fonts are released when+ they change). It authenticates by trusted publishing, with the workflow's OIDC token: no+ PyPI token is stored.+6. **Publish to npm:** the package for the browser (`just build-npm`), which installs this+ release of manimgx from PyPI, so it comes after PyPI; by trusted publishing too, with+ provenance.+7. **Publish the Docker image:** [docker/github-builder](https://github.com/docker/github-builder)+ builds `docker/Dockerfile` for the version, for `linux/amd64` and `linux/arm64`,+ with a signed provenance and SBOM (each package the image holds, with its license), and+ pushes it to `ghcr.io/academa-labs/manimgx`, tagged `X.Y.Z` and `X.Y` (a pre-release,+ `X.Y.Z` only), labeled `MIT AND GPL-3.0-or-later`: manimgx's code, and the engine, which+ x264 makes GPL-3.0-or-later as a whole. The image installs manimgx from PyPI, so it comes+ after PyPI.+8. **Publish the GitHub release:** the draft becomes public last, once PyPI, npm and+ ghcr.io have their files. GitHub's immutable releases lock a published release's files+ and tag, which is why the files are attached while the release is a draft.++### 5. [`create-wheels.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/create-wheels.yaml): the wheels++**When it runs:** when the Release workflow calls it (or Create executables, run by hand),+and by hand, to try a branch's wheels.++**What it does:** a job per platform (Linux x86_64 and arm64, macOS arm64 and x86_64,+Windows x86_64) runs `just build-wheel`; the macOS x86_64 wheel is cross-compiled on an+arm64 runner (`CIBW_ARCHS`), and tested there under Rosetta, and a Linux job builds Mesa's+lavapipe for its wheel first (`scripts/release/build_lavapipe.sh`). cibuildwheel builds the+platform's wheel and tests it on every+supported Python, as `[tool.cibuildwheel]` in `pyproject.toml` says (see+[Project management](project-management.md#distribution)). Each wheel is kept as+`wheel-<platform>`.++### 6. [`create-executables.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/create-executables.yaml): the executables++**When it runs:** when the Release workflow calls it, with its wheels, and by hand, when it+builds the wheels first.++**What it does:** a job per platform takes the platform's wheel and runs+`just create-executable`+([`scripts/release/create_executable.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/create_executable.py)),+which renders a scene with the executable before it keeps it: on Linux with Mesa's+lavapipe, which the job installs (macOS has Metal, Windows WARP). Each executable is kept as+`executable-<platform>`: `manimgx-<os>-<arch>.tar.gz`, or a `.zip` on Windows.++### 7. [`ai.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/ai.yaml): Claude on issues and pull requests++Claude runs through [claude-code-action](https://github.com/anthropics/claude-code-action),+on Amazon Bedrock. GitHub's OIDC token is exchanged for a short-lived AWS session (for the+role in the variable `AWS_ROLE`), so no key is stored. The jobs that use it run in the `ai`+environment, and each run has a budget in dollars.++**When it runs:** an issue is opened, a comment is made on an issue or a pull request, or a+pull request is opened or marked ready for review.++**What it does**, in three ways:++- **A first reply** to an issue opened by someone outside the team (not an owner, a member+ or a collaborator, and not a bot). A model, Claude Sonnet, reads the issue, the titles of+ the open issues and the repository, and can do nothing else: it may only read the+ checked-out files, and it answers with a reply of at most 2,000 characters and up to+ three related issues. Its instructions are the workflow's own (`prompt`).+ A second job, with no model and no checkout, posts the reply: it refuses one that looks+ like it carries a credential, defuses its @-mentions, drops its images, links the related+ issues, and says that the reply is automated and that a maintainer will follow up.+- **A review** of a pull request from a branch of the repository (not a draft, and not a+ bot's), when it is opened or marked ready: Anthropic's code-review plugin, with Claude+ Opus, comments on the problems it is sure of.+- **@claude:** a maintainer mentions @claude in a new issue, or in a comment on an issue or+ a pull request, and asks for anything: an answer, a review, a change. The job first+ checks that the author can write to the repository, and stops otherwise. Claude Opus+ works in the environment `just sync` makes, and its commands run in Claude Code's+ sandbox: they reach only GitHub, PyPI, crates.io and npm, and never see the AWS session. It+ is told to follow [`AGENTS.md`](https://github.com/academa-labs/manimgx/blob/main/AGENTS.md),+ to run `just check` and the tests its change touches before it pushes, and to open a+ change as a draft pull request. On a pull request from a fork, it only reads.++## Secrets never meet the code++The jobs that run the repository's code get no secrets, and the jobs that get secrets do+not run it:++- The checks, the tests and the docs' build run the repository's code (they build the+ engine and render scenes), with a token that can only read the repository. The jobs that+ get Cloudflare's API token and account ID (the docs' deploy, preview and deletion, and+ the coverage's publishing) never run the repository's code: they only run a pinned+ version of wrangler, on what a build made (and `gh`, to set the coverage status).+- Pull requests from forks and from Dependabot get no secrets: they are built and tested,+ not previewed, and their coverage is not published.+- The first reply's model can only read, and the job that posts its reply runs no model.+- The @claude assistant is the exception: it runs the repository's code (`just sync`, the+ checks, the tests) with the AWS session at hand, and its sandbox hides the session from+ every command it runs.++Every workflow's default permissions are none (`permissions: {}`); each job asks for what+it needs.++## Details++- One run of the Test and docs workflows per pull request or branch at a time: a new+ commit to a pull request cancels its running one, while a run on `main` finishes before+ the next one begins.+- Every action is pinned to a commit, its version in a comment beside it, and wrangler's+ version is pinned in `WRANGLER_VERSION`. Dependabot moves the pins (below), and+ [zizmor](https://docs.zizmor.sh), one of the checks of `just check`, finds security+ problems in the workflows.+- The Test, docs and AI workflows share one cache of the engine's compiled Rust+ dependencies; only `main`'s runs save it.++## [`dependabot.yml`](https://github.com/academa-labs/manimgx/blob/main/.github/dependabot.yml): updates++[Dependabot](https://docs.github.com/en/code-security/dependabot) opens pull requests that+move dependencies to new releases, one per ecosystem, its updates grouped:++| Ecosystem | What moves | How often |+| --- | --- | --- |+| GitHub Actions | The workflows' pinned actions (a pinned action gets no security alerts) | Weekly |+| uv | `uv.lock`; a requirement in a `pyproject.toml` only when a release falls outside it | Monthly |+| Cargo | The engine's crates, in `Cargo.lock` | Monthly |+| pre-commit | The hooks' repositories in `.pre-commit-config.yaml` | Monthly |+| Docker | The Docker image's base, and its uv | Monthly |+| bun | The browser package's tools and the review panel's packages, grouped separately | Monthly |++A release waits a week before Dependabot proposes it: most compromised releases are caught+within days. Security updates do not wait.++## Other files in `.github/`++The [contributing guide](https://github.com/academa-labs/manimgx/blob/main/.github/CONTRIBUTING.md),+the security policy, the code of conduct, the issue forms (a bug, a feature, the docs, a+question; no blank issues) and the pull request template (a summary, a test plan, and the+use of AI). GitHub shows each where it applies.++## Learn more++- [`.github/workflows/`](https://github.com/academa-labs/manimgx/tree/main/.github/workflows):+ the workflow files.+- [GitHub Actions' documentation](https://docs.github.com/en/actions).+- [Dependabot's options](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference).diff --git a/docs/content/developer-guide/index.md b/docs/content/developer-guide/index.mdnew file mode 100644index 00000000..656db8a9--- /dev/null+++ b/docs/content/developer-guide/index.md@@ -0,0 +1,172 @@+# Setup++This guide is for working on manimgx itself: its Python package, its Rust engine, its+TypeScript browser package, its tests and these docs. It explains how the project works and+how to work on it. How to propose a+change (issues, pull requests, the use of AI) is in the+[contributing guide](https://github.com/academa-labs/manimgx/blob/main/.github/CONTRIBUTING.md).++This page takes a machine to a clone of manimgx that builds, checks, tests and serves the+docs.++## Prerequisites++manimgx is a Python package with an engine written in Rust. You need four tools; building+and testing it needs nothing else from your system: the engine builds x264 (with NASM, the+assembler x264's x86-64 code is written for), FFmpeg's audio decoders and libopus from their+sources, which its build fetches the first time (with `curl` and `tar`, which macOS, Linux and+Windows have), and the tests read and write video with PyAV, which brings FFmpeg's libraries in+its wheels.++- **[`uv`](https://docs.astral.sh/uv/getting-started/installation/)**: the project+ manager. It installs Python (3.13 or 3.14), every dependency, and manimgx itself,+ compiling its engine.+- **[`just`](https://just.systems/man/en/packages.html)**: the command runner. The+ development tasks are recipes in the+ [`justfile`](https://github.com/academa-labs/manimgx/blob/main/justfile).+- **[Rust](https://www.rust-lang.org/tools/install)**, the stable toolchain, through+ `rustup`, with the C toolchain it links with (`rustup` says which: the Xcode Command Line+ Tools on macOS, `build-essential` on Debian or Ubuntu, Visual Studio's C++ build tools on+ Windows): it compiles the engine, and x264's, FFmpeg's and libopus's C.+- **[`bun`](https://bun.sh)**: it installs the browser package's locked tools, bundles its+ TypeScript sources, and runs its tests. It also builds the web page of the corpus's review+ panel (see [Testing](testing.md#the-review-panel)).++### A GPU++The engine draws with [wgpu](https://wgpu.rs): through Metal on macOS, Direct3D 12 on+Windows (WARP, on the CPU, where there is no GPU), and Vulkan on Linux. It takes the+high-performance adapter, which must be able to blend float32 render targets (a 2D view+adds up its coverage in one). Without such an adapter, rendering raises an error that says+what is missing.++On Linux without a GPU driver, Mesa's lavapipe draws on the CPU. The Linux wheels bundle it+(`scripts/release/build_lavapipe.sh` builds it, and the engine loads it itself: see+[The engine](engine.md#drawing)); an engine built from source, as here, draws with the+system's, which the workflows' Linux jobs install:++```sh+sudo apt-get install libvulkan1 mesa-vulkan-drivers+```++### Manim Community Edition++The integration corpus compares every case with Manim Community Edition's rendering of it.+CE's references are in the repository; rendering them again (a new case, or a changed+scene) needs CE, which is in its own dependency group: `uv sync --group ce` (`just sync`+leaves it out again). Its bindings to Cairo and Pango build from source where they have no+wheels (pycairo on macOS and Linux, ManimPango on Linux), so that needs those libraries:+`brew install cairo pkg-config` on macOS, `apt-get install libcairo2-dev libpango1.0-dev+pkg-config` on Debian or Ubuntu.++## Setting up the development environment++1. Clone the repository and enter it:++ ```sh+ git clone --filter=blob:none https://github.com/academa-labs/manimgx.git+ cd manimgx+ ```++ The integration corpus's reference videos make the full history large.+ `--filter=blob:none` makes a partial clone: it downloads every commit, but an old+ version of a file only when a command needs it (checking out an old commit, say).++2. Make the environment:++ ```sh+ just sync+ ```++ uv creates `./.venv`: Python, manimgx installed in editable mode with its engine+ compiled, the development tools and the docs' tools. The first sync compiles the engine+ and its dependencies (Typst, wgpu, x264), which takes a while. After that, `uv run`+ rebuilds the engine by itself whenever its Rust sources, shaders or manifests change,+ so there is no separate build step (see+ [Project management](project-management.md#rebuilding-the-engine)).+ Bun installs the browser package's development tools from `browser/bun.lock`.++3. Check that it works:++ ```sh+ just check+ just test-typescript+ just test tests/integration/test_time.py+ ```++ `just check` runs every check the repository has (see+ [Project management](project-management.md#pre-commit-configyaml-and-just-check)).+ The tests in `test_time.py` render scenes, so they use the GPU. `just test` alone runs+ the whole suite, which renders every case of the integration corpus and takes much+ longer (see [Testing](testing.md)).++4. Select the environment's interpreter in your editor. In Visual Studio Code: press+ ++ctrl+shift+p++ (++cmd+shift+p++ on macOS), run **Python: Select Interpreter**, and+ pick the one in `./.venv`. The engine's crates are a workspace,+ [`rust/`](https://github.com/academa-labs/manimgx/tree/main/rust): point rust-analyzer at `rust/Cargo.toml` if your editor+ does not find it.++## Commands++`just` lists the recipes, in four groups. The GitHub workflows run these same recipes, so a+task does the same on your machine as in CI. The recipes that run the project's tools run+them with `uv run --frozen`: in the environment, at the versions `uv.lock` pins, taking the+lockfile as it is. Run anything else the same way (`uv run --frozen python …`).++### Development++- `just sync`: make `.venv` with everything `uv.lock` pins, build the engine into it, and+ install the browser package's locked development tools.+- `just lock`: update `uv.lock` after a change to `pyproject.toml`'s dependencies.+- `just upgrade`: move `uv.lock` and `Cargo.lock` to the newest versions the manifests+ allow.+- `just licenses`: write the wheels' third-party notice+ (`LICENSE-THIRD-PARTY`) after `Cargo.lock` changes, checking that+ manimgx's `license` covers it.+- `just format`: apply ruff's fixes and format the Python with ruff (the Python in the+ Markdown too), and the browser package with Prettier.+- `just format-file <path>`: apply ruff's fixes and format with ruff, in one file or folder.+- `just check`: every check of `.pre-commit-config.yaml`, on every file. It must pass.+- `just check-typescript`: check the browser package's types and formatting.++### Testing++- `just test [args]`: the suite, in parallel; `args` go to pytest, as in+ `just test tests/integration/test_time.py -x`.+- `just test-typescript`: build and test the browser package, including its compiled worker+ and public declarations.+- `just test-coverage [args]`: the same, measuring coverage (see+ [Testing](testing.md#coverage)).+- `just combine-coverage <folder>`: one report from the coverage of several runs, as CI+ makes it.+- `just bench [REF] [args]`: the timed benchmarks, this checkout against REF's manimgx, main+ unless named (see [Testing](testing.md#benchmarks)).+- `just corpus <command>`: render, compare and review the integration corpus.+- `just review`: the corpus's review panel, at <http://127.0.0.1:8000>.++### Docs++- `just serve-docs`: the docs site at <http://localhost:8000>, rebuilt as its pages change.+- `just build-docs`: the docs site, into `site/`, as it is deployed.++See [Documentation](documentation.md#local-preview).++### Release++- `just build-wheel`: this machine's wheel, into `dist/`, tested on every supported Python.+- `just build-sdist`: the source distribution, into `dist/`.+- `just create-executable`: this machine's executable, into `dist/`, from its wheel there.+- `just build-docker-image <version>`: the Docker image of a version published on PyPI.+- `just release-notes <version>`: a version's section of the changelog.+- `just release`: tag the version in `pyproject.toml` and push the tag; the Release+ workflow publishes it.++See [Project management](project-management.md#releases).++### By hand++Two tools have no recipe, and no workflow runs them. Run them in `rust/`:++- `cargo test -p mitex-spec-gen`: whether the committed LaTeX command spec is still what+ mitex's package makes (see [The engine](engine.md#typesetting)).+- `cargo clippy`: the lints `rust/engine/Cargo.toml` sets for the engine.diff --git a/docs/content/developer-guide/project-management.md b/docs/content/developer-guide/project-management.mdnew file mode 100644index 00000000..a81b1a6d--- /dev/null+++ b/docs/content/developer-guide/project-management.md@@ -0,0 +1,483 @@+# Project management++## What is project management?++The repository is the package, manimgx, and holds more than its code:++```text+.+├── src/manimgx/ ← the package: the scene API and the command line+├── rust/ ← the engine's crates: the engine, compiled into the package as+│ manimgx._engine, and the crates it is built with from others'+│ sources, which they fetch+├── tests/ ← the package's tests and the integration corpus+├── fonts/ ← the fonts text is set in, packages of their own:+│ ├── manimgx-fonts/ the Noto fonts+│ └── manimgx-fonts-cjk/ Noto Sans CJK (not in the browser)+├── browser/ ← manimgx for the browser, published on npm, with its tests+├── docker/ ← the Docker image+├── docs/ ← the docs site: its pages, its settings, what its build loads+├── examples/ ← thirty example films, a Python file each+├── scripts/ ← what writes and builds: the release's scripts, the docs' generated+│ pages and pictures, the engine's DFG table, and the benchmark+│ against Manim CE, ManimGL and Blender+├── skills/ ← the agent skill+├── pyproject.toml ← the package, its workspace (with fonts/), the tools and their settings+├── uv.lock ← the exact version of every Python package+├── justfile ← the development tasks+├── .pre-commit-config.yaml ← the checks+├── README.md ← the front page: GitHub's, PyPI's, and the docs' Welcome+├── AGENTS.md ← this guide's commands and rules in brief, for coding agents+├── CITATION.cff ← how to cite manimgx+├── LICENSE ← manimgx's license, the MIT License+├── LICENSE-THIRD-PARTY ← what the wheels hold that others hold the copyright in+├── LICENSE-LAVAPIPE ← the notices of the lavapipe the Linux wheels bundle+├── LICENSES/ ← the text of each license a file of the repository is under+├── REUSE.toml ← whose each file is, and under which license, where it doesn't say+└── .github/ ← the workflows, deployment configs, Dependabot, the+ contributing guide, issue forms and pull request template+```++Project management is everything but the code, in `src/`, `rust/` and `browser/src/`: what+makes the code installable, the same on every machine, and checked the same way by everyone.+The repository's root is the package; what is published apart from it (the font packages, the+browser package, the Docker image) has a folder of its own.++## Why isn't code enough?++Code alone leaves two problems open: how users get it, and how developers work on it.++### Distribution++A user wants `pip install manimgx` and a working `manimgx` command. manimgx is harder to+ship than pure Python: its engine is compiled, so every platform needs a build of its own,+with the engine inside. A release publishes manimgx in five forms:++- **Wheels**, one per platform: Linux (x86_64 and arm64), macOS (arm64, and x86_64+ cross-compiled on arm64) and Windows (x86_64). The engine is built against Python's+ stable ABI, so a platform's one wheel serves every supported Python, and x264 is built+ into it, so a wheel needs nothing from the system. A Linux wheel bundles Mesa's lavapipe+ too, to draw on the CPU where there is no GPU driver+ ([`scripts/release/build_lavapipe.sh`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/build_lavapipe.sh)+ builds it in the manylinux image first: about 24 MB of the wheel).+ [cibuildwheel](https://cibuildwheel.pypa.io) builds each wheel and installs it on every+ supported Python, where it must render a scene+ ([`scripts/release/smoke_test.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/smoke_test.py))+ before it is kept: on Linux, with no driver in the image, so with the bundled lavapipe. Its+ settings are `[tool.cibuildwheel]` in `pyproject.toml`.+- **A source distribution**, which builds the engine on the machine that installs it: that+ needs Rust and a C compiler, nothing else (the engine's build fetches the sources it takes+ from others: see [Others' sources](engine.md#others-sources)).+- **Executables**, one per platform: one file that holds a Python with manimgx installed,+ for a machine without Python (see [`scripts/`](#scripts)).+- **A Docker image**, `ghcr.io/academa-labs/manimgx` (see [`docker/`](#docker)).+- **The package for the browser**, `manimgx` on npm: the player in one file, which runs+ scenes with the wheel for the browser (see [`browser/`](#browser)).++The fonts text is set in are packages of their own, `manimgx-fonts` and `manimgx-fonts-cjk`:+a wheel for every platform, released when the fonts change, not with every manimgx (see+[`fonts/`](#fonts)).++PyPI gets the wheels, the source distribution and the font packages; the GitHub release gets+the wheels, the source distribution, the wheels' complete source (`manimgx-X.Y.Z-source.tar.xz`:+see [Licenses](#licenses)) and the executables; npm gets the package for the browser; ghcr.io+gets the image. [Releases](#releases) says how a release is made.++### The development environment++Developer A installs the dependencies today and the tests pass. Developer B installs them+a month later, gets a newer Typst or numpy, and the tests fail. For manimgx the risk is+sharper than usual: the integration corpus compares frames by the hash of their pixels, so+any change in how a glyph is laid out or a color is rounded shows.++So everyone needs the same Python, the same version of every package and crate, and the+same tools with the same settings, in one command:++```sh+just sync+```++A bug from six months ago? Check out that commit and run `just sync`: its Python packages+and Rust crates come back as they were. The system's libraries and the Rust toolchain are+not pinned.++The rest of this page describes the files that make this work.++## Files in the root++### [`pyproject.toml`](https://github.com/academa-labs/manimgx/blob/main/pyproject.toml)++The package (see [The package](#the-package)), the workspace it is developed in, and what+developing it takes. [uv](https://docs.astral.sh/uv/concepts/projects/workspaces/) manages+the workspace as one:++- `[tool.uv.workspace]`: its other members, the font packages in `fonts/`, each with a+ `pyproject.toml` of its own (see [`fonts/`](#fonts)). One lockfile holds them all, and one+ environment, `.venv`, has them all installed.+- `[tool.uv.sources]`: the members as they are here. manimgx requires its font packages+ at exact versions; in the workspace those are the ones in `fonts/`, installed editable,+ like manimgx, whose engine uv builds.+- `[dependency-groups]`: what developing needs. `dev` holds the tools (ruff, ty, pytest and+ its plugins, prek), FastAPI for the review panel, and PyAV, with which the+ corpus writes and reads its videos. `docs` holds Zensical and mkdocstrings. `ce` holds+ Manim Community Edition, which renders the corpus's Manim references (see+ [Setup](index.md#manim-community-edition)). Each is installed with manimgx.+- `[tool.uv]`: `dev` and `docs` are installed by default.+- The tools' settings: `[tool.pytest]`, `[tool.coverage.run]` (see+ [Testing](testing.md#coverage)), `[tool.mutmut]`, `[tool.fastapi]`, and those of the tools+ that keep the code's form and check its types, `[tool.ruff]` and `[tool.ty]` (below).++### [`uv.lock`](https://github.com/academa-labs/manimgx/blob/main/uv.lock)++The exact version of every Python package the project uses, down to the dependencies of+dependencies. `just sync` installs exactly these, not the latest ones.++Never edit it by hand: after changing a dependency in a `pyproject.toml`, run `just lock`,+and commit both files. `just upgrade` moves every package to the newest version the+`pyproject.toml` files allow. The recipes run their tools with `uv run --frozen`, which uses+the lockfile as it is, without checking it against the `pyproject.toml` files.++### [`justfile`](https://github.com/academa-labs/manimgx/blob/main/justfile)++[just](https://just.systems) runs commands defined once in a file. Without it, everyone+types the same long commands with different options. With it:++```sh+just test # pytest, in parallel, in the locked environment+just check # every check of .pre-commit-config.yaml+just serve-docs # render the docs' examples, write the reference, serve the site+```++The recipes are grouped (development, testing, docs, release), and a comment above a recipe+is its description in `just --list`. The GitHub workflows run these same recipes, so a+task does the same on a developer's machine as in CI. [Setup](index.md#commands) lists+every recipe.++### ruff++[ruff](https://docs.astral.sh/ruff/) keeps the code's form the same everywhere:++- it formats, in its stable style and 88 columns: the Python, the examples in the+ docstrings, and the Python in the Markdown. It does not split a long string.+- it lints: it finds likely bugs, unsorted imports and outdated idioms. `[tool.ruff]` in+ `pyproject.toml` selects its rules and gives the reason for each one it ignores; the+ package's re-exports in `__init__.py` may import with `*` and import names they do not+ use.++`just format` runs ruff's automatic fixes, then its formatter. `just check` runs both too+(below). Docstrings have a form of their own, the Google style, since the API reference is+generated from them: see [Documentation](documentation.md#docstrings).++### ty++[ty](https://docs.astral.sh/ty/) checks types. manimgx is typed throughout, and ty reports+nothing on it: `just check` must pass with no errors, and a change keeps it that way. Two+rules follow:++- **No `Any` in a public signature.** Keyword options are a `TypedDict`, taken as+ `**kwargs: Unpack[…]`, never as `**kwargs: Any`, so a misspelled keyword fails the check,+ in manimgx and in a user's scene alike. [`Style`][manimgx.drawing.paint.Style], in+ [`drawing/paint.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/drawing/paint.py),+ is the style keywords; [`Polygon`][manimgx.Polygon] takes `**kwargs: Unpack[Style]`.+- **Only live suppressions, in ty's form.** ty honors `# ty: ignore[rule]` and a bare+ `# type: ignore`, not `# type: ignore[code]`. A suppression that suppresses nothing is an+ error (`[tool.ty]` makes it one), so one that a fix has made useless fails the check.+ ruff's formatter does not count a trailing suppression comment in a line's width, but it+ splits a line too long without one and moves the comment to the last line, so run+ `just check` after `just format`.++`[tool.ty]` is the one list of what ty checks: the packages, the docs' scripts, the corpus's+tools and review server, and the tests it names. The hook that runs ty passes it no files,+so `just check` checks that list. It also reads `svgelements` as untyped (ty cannot read its+source's encoding).++A user's scene is held to more: every corpus case type-checks with every rule, and no+value manimgx gives it may be `Any` (see [Testing](testing.md#the-three-checks)).++### [`.pre-commit-config.yaml`](https://github.com/academa-labs/manimgx/blob/main/.pre-commit-config.yaml) and `just check`++Every check the repository has, as hooks:++- file checks: no merge conflict markers, valid TOML and YAML, a final newline, no trailing+ whitespace;+- [check-jsonschema](https://check-jsonschema.readthedocs.io), which checks `CITATION.cff`+ against the [Citation File Format](https://citation-file-format.github.io)'s schema;+- [zizmor](https://docs.zizmor.sh), which finds security problems in the GitHub workflows;+- ruff and ty, run from the environment (`uv run --frozen`), so they are the versions+ `uv.lock` pins;+- TypeScript 7 and Prettier for the browser package, run with the versions its `bun.lock` pins;+- [reuse](https://reuse.software), from the environment too, which checks that the license+ and the copyright of every file are known (see [Licenses](#licenses)).++[prek](https://prek.j178.dev), a fast implementation of pre-commit, runs them: `just check`+is `prek run --all-files --show-diff-on-failure`. A hook that changes a file (ruff fixing+or formatting it, a final newline added) fails the check, shows the change,+and leaves the file changed; the next `just check` passes if nothing else is wrong.++The repository installs no git hooks: the checks run when you run them, and on every push+to `main` and every pull request, in the Test workflow (see+[GitHub workflows](github-workflows.md#1-testyaml-the-checks-and-the-tests)).++### Licenses++manimgx is under the MIT License, in+[`LICENSE`](https://github.com/academa-labs/manimgx/blob/main/LICENSE): GitHub, PyPI and+npm show it. Some files are others': modules ported from Manim CE, the Noto fonts, the+corpus's scenes from CE's documentation, the command spec made from mitex's Typst package, a+few documents and images. The repository says whose each file is, and under which license, as+[REUSE](https://reuse.software) specifies:++- a file with code from elsewhere says it in its first lines: an `SPDX-FileCopyrightText`+ line for each copyright holder (manimgx's, `2026 Academa, Inc.`, among them) and an+ `SPDX-License-Identifier` line, as the modules ported from Manim CE do;+- [`REUSE.toml`](https://github.com/academa-labs/manimgx/blob/main/REUSE.toml) says it for the+ rest: manimgx's own files, in one annotation; the fonts, the corpus, data and images;+- [`LICENSES/`](https://github.com/academa-labs/manimgx/tree/main/LICENSES) holds each+ license's text, once, named by its SPDX identifier.++The license texts the engine's crates keep for the sources they fetch (`COPYING`, `LICENSE`;+see [Others' sources](engine.md#others-sources)) are their projects', as published: REUSE+leaves files of those names be. `reuse lint`, a hook of `just check`, fails while a file's+license or copyright is unknown, or a license has no text. A new file of manimgx's needs+nothing; code brought from elsewhere needs its lines; data or an image needs an annotation.+What a wheel holds that others hold the copyright in comes with its notices (see+[The package](#the-package)).++A wheel holds FFmpeg's audio decoders, under the LGPL-2.1-or-later, and every wheel but the+browser's holds x264, under the GPL-2.0-or-later, with crates under the Apache-2.0 alone+(Typst, mitex), which only the GPL's third version takes in: such a wheel, as a whole, is under+the GPL-3.0-or-later. Its section 6 (and the LGPL's, which refers to it) asks+that whoever gets the wheels can get their complete source, from where the wheels are or from+a place the wheels point to, for as long as the wheels are offered: all of it, the crates too,+not links to where others publish them, which can go. Each GitHub release carries it,+`manimgx-X.Y.Z-source.tar.xz`, which builds the wheels offline (see+[Others' sources](engine.md#others-sources)); the wheels' notice, the README (PyPI's page) and+the release's notes point to it, and the README and the notes say what FFmpeg asks every page+that offers it to say. A release is never deleted while PyPI offers its wheels.++### [`scripts/`](https://github.com/academa-labs/manimgx/tree/main/scripts)++What writes and builds, a folder for each thing it makes:++- [`release/`](https://github.com/academa-labs/manimgx/tree/main/scripts/release): the release's scripts, which the recipes and+ cibuildwheel run.+ - [`create_executable.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/create_executable.py)+ (`just create-executable`) makes this machine's executable from its wheel in `dist/`:+ a standalone Python (3.14, through uv) with the wheel, the font packages and the+ dependencies `uv.lock` pins installed, packed into one file by+ [PyApp](https://ofek.dev/pyapp). The file's+ first run unpacks the Python it holds; every run then runs `manimgx` there, with no+ network and no Python on the machine, and `manimgx self` manages it (`self pip install`+ adds a package a scene imports). The script writes+ `dist/manimgx-<os>-<arch>.tar.gz` (a `.zip` on Windows), after running what it made once.+ - [`smoke_test.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/smoke_test.py)+ renders a scene with an installed manimgx: the check a wheel or an executable passes+ before it is kept.+ - [`build_lavapipe.sh`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/build_lavapipe.sh)+ builds Mesa's lavapipe for a Linux wheel, in the manylinux image (cibuildwheel's+ `before-all`): Mesa and glslang from their sources, checked against pinned hashes, with+ the image's LLVM linked in, exporting only what Vulkan's loader calls. It writes+ `src/manimgx/lavapipe/libvulkan_lvp.so`, which the wheel then takes in.+ - [`licenses.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/release/licenses.py)+ (`just licenses`) writes the wheels' third-party notice (see+ [The package](#the-package)).+- [`docs/`](https://github.com/academa-labs/manimgx/tree/main/scripts/docs): the docs' generated pages, which `just build-docs` writes+ before the site is built: the Gallery and the API reference (see+ [Documentation](documentation.md)).+- [`showcase/`](https://github.com/academa-labs/manimgx/tree/main/scripts/showcase): the README's pictures, made by hand and committed:+ the logo (the banner, the header's, the favicon) and the wall of example films.+- [`engine/`](https://github.com/academa-labs/manimgx/tree/main/scripts/engine): what the engine is compiled with, made by hand:+ [`dfg_table.py`](https://github.com/academa-labs/manimgx/blob/main/scripts/engine/dfg_table.py) writes `rust/engine/src/dfg.bin`, the+ split-sum table a lit surface's specular reflection is read from, run again only if the+ lighting changes.+- [`benchmark/`](https://github.com/academa-labs/manimgx/tree/main/scripts/benchmark): manimgx against Manim CE, ManimGL and Blender on+ the README's scenes, and the README's chart from its results.++### The docs' and the coverage's hosting++[`docs/zensical.toml`](https://github.com/academa-labs/manimgx/blob/main/docs/zensical.toml) holds the+docs site's settings (see [Documentation](documentation.md)); the site is built into+`docs/site/`. Hosting is configured alongside+the workflows, in [`.github/deploy/`](https://github.com/academa-labs/manimgx/tree/main/.github/deploy):+`docs.jsonc` serves the docs site, and `coverage.jsonc` serves the tests' coverage report+(see [Testing](testing.md#coverage)).++### [`AGENTS.md`](https://github.com/academa-labs/manimgx/blob/main/AGENTS.md) and the contributing guide++`AGENTS.md` is this guide's commands, rules and layout in brief, for coding agents; the+assistant of the [AI workflow](github-workflows.md#7-aiyaml-claude-on-issues-and-pull-requests)+is told to follow it. The+[contributing guide](https://github.com/academa-labs/manimgx/blob/main/.github/CONTRIBUTING.md)+says how a change is proposed (an issue first, then a pull request) and links here for how+the project works. When a command or a rule changes, `AGENTS.md` changes with this guide.++### [`.gitignore`](https://github.com/academa-labs/manimgx/blob/main/.gitignore)++What is made, not written, stays out of git: the environment, the compiled engine,+`rust/target/`, `dist/`, the built site, the docs' rendered films and generated reference,+the coverage data and report, and render output (`media/`, `*.mp4`). The corpus's reference+videos are `.mkv` files, and are committed.++## The package++The repository's root is the package, defined in+[`pyproject.toml`](https://github.com/academa-labs/manimgx/blob/main/pyproject.toml), in the+[standard format](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/):++- `[project]`: the name, version, supported Pythons (3.13 and 3.14), license, and the+ packages manimgx needs at run time.+ [Understanding manimgx](understanding-manimgx.md#dependencies) says what each is for.+ `license` names every license of what the distributions hold, as one SPDX expression:+ manimgx's own MIT, those of the crates compiled into the engine (x264's GPL-2.0-or-later+ among them), of Typst's fonts and data, and of the lavapipe a Linux wheel bundles.+ `license-files` puts `LICENSE` and the two notices beside it into the wheel's metadata.+ Its README is the repository's, `README.md`.+- `[project.scripts]`: makes `manimgx` a command, running `manimgx.cli:main`.+- `[build-system]` and `[tool.maturin]`: [maturin](https://www.maturin.rs) builds the+ package. It compiles the crate in `rust/engine/` into the module `manimgx._engine` and+ puts it beside the Python sources from `src/`.+- `[tool.uv]`: `cache-keys` says when the engine is rebuilt (below).+- `[tool.cibuildwheel]`: how the wheels are built and tested ([Distribution](#distribution)).+ A wheel is tested with the fonts it is released with, this repository's, which PyPI may+ not have yet: they are installed before it.++Beside it, at the root, the notices `license-files` names besides `LICENSE`:++- [`LICENSE-THIRD-PARTY`](https://github.com/academa-labs/manimgx/blob/main/LICENSE-THIRD-PARTY):+ what the wheels hold that others hold the copyright in, with the licenses and notices it+ comes with: the package's files that name others (the modules ported from Manim CE), with+ their copyright lines and their licenses' texts from `LICENSES/`; and every crate compiled+ into the engine, in each build a wheel holds (each platform's extension, Pyodide's, the+ player for a page), with the license and notice files it ships, the workspace's crates+ those of what they fetch (x264's, FFmpeg's, libopus's, mitex's). `just licenses` writes it+ again after `Cargo.lock` changes (so does `just upgrade`), or after code carrying+ third-party notices moves between files. A test fails while the notice is stale, or+ while a license in it is not among manimgx's.+- [`LICENSE-LAVAPIPE`](https://github.com/academa-labs/manimgx/blob/main/LICENSE-LAVAPIPE):+ the notices of the lavapipe the Linux wheels hold: Mesa's, with the copyright lines of the+ sources it is built from, and those of what it holds, of the libraries it links to and of+ LLVM. It is written by hand, from Mesa's sources: a test fails when+ `scripts/release/build_lavapipe.sh` builds another Mesa than the one it describes.++In `src/manimgx/`, besides the Python:++- `py.typed`: marks the package as typed, so type checkers read its annotations.+- [`_engine.pyi`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/_engine.pyi):+ the engine's interface, typed (see [The engine](engine.md#the-boundary-with-python)).+- [`cli/present.html`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/cli/present.html):+ the page that presents a film's slides in a browser (`manimgx present`).++#### Rebuilding the engine++uv installs manimgx in editable mode: a change to a Python file applies the next time+Python runs. The engine is different: it is a compiled file (`_engine.abi3.so` in+`src/manimgx/` on macOS and Linux, ignored by git) that exists only once maturin has built+it.++uv rebuilds a package when one of its *cache keys* changes. `cache-keys` lists the engine's+sources: the crates' Rust files and shaders (`*.wgsl`, compiled into it), their manifests+and build scripts, the C shims, the lockfile, and mitex's `lib.typ` and command spec. What the+crates fetch changes only with their build scripts, which pin it.+`uv run` brings the environment up to date before it runs anything, so after an edit to+`rust/engine/src/vector.wgsl`, the next `just test` rebuilds the engine, then tests it.++The build is maturin's release build, optimized as `[profile.release]` in `rust/Cargo.toml`+says (full optimization, thin link-time optimization): slower to compile, fast to run. A file the engine is built from that no pattern in `cache-keys` matches needs an+entry of its own, or its changes are not seen. `uv sync --reinstall-package manimgx`+rebuilds the engine whatever changed.++## [`fonts/`](https://github.com/academa-labs/manimgx/tree/main/fonts)++The font packages, the workspace's other members:+[`manimgx-fonts/`](https://github.com/academa-labs/manimgx/tree/main/fonts/manimgx-fonts) and+[`manimgx-fonts-cjk/`](https://github.com/academa-labs/manimgx/tree/main/fonts/manimgx-fonts-cjk),+each with its manifest, its README and its license; what each holds is what its users get.++The Noto fonts text is set in, besides Typst's own, so that text is the same on every+machine: Noto Sans and the faces for the scripts Latin faces lack in `manimgx-fonts`, Noto+Sans CJK in `manimgx-fonts-cjk`, each under the SIL Open Font License (`LICENSE`). They are+data, 40 MB of it, and change rarely: packages of their own, built by uv's backend into one+wheel for every platform, and released when they change, not with every manimgx, which+requires them at exact versions. A version is the date the fonts were taken from Noto.+`manimgx-fonts-cjk` is not required in the browser, where 33 MB is too much for a page to+download. manimgx finds the fonts in them (`importlib.resources`), in whichever are+installed.++## [`rust/`](https://github.com/academa-labs/manimgx/tree/main/rust)++The engine's crates, as one workspace: [`rust/Cargo.toml`](https://github.com/academa-labs/manimgx/blob/main/rust/Cargo.toml)+lists them (every folder here), the build profiles they are compiled with, and the patch that+gives mitex manimgx's own spec crate; `Cargo.lock` is to Rust what `uv.lock` is to Python, every+crate's exact version, committed (`just upgrade` moves it too). Cargo runs here, and builds into+`rust/target/`. [The engine](engine.md) says what the crates do:++- `engine/`: the engine, `manimgx._engine` — with the player, in a window natively, and in+ Pyodide carrying the player for a page; its manifest holds its dependencies (wgpu, PyO3,+ Typst, mitex, winit, rustybuzz) and the Clippy lints it answers to.+- `x264/`, `nasm/`: x264 and NASM, built from their sources.+- `ffmpeg/`: FFmpeg's audio decoders and libopus, built from their sources, behind one call.+- `mitex-spec-gen/`: mitex's Typst package, which the engine serves to Typst (with its own+ `lib.typ`, which imports only the scope the converted LaTeX calls), and the command spec made+ from it.+- `fetch/`: what the others' build scripts fetch with: a source tree, pinned by the SHA-256 of+ its files (see [The engine](engine.md#others-sources)).++The repository holds none of what others wrote but its license texts, which the crates keep+for the notices (`COPYING`, `LICENSE`), as their authors published them; the checks leave them+alone.++## [`browser/`](https://github.com/academa-labs/manimgx/tree/main/browser)++manimgx for the browser, published to npm as `manimgx`: the player's element (`src/player.ts`)+and the director's worker (`src/director.ts`). `just build-npm` compiles the worker before+embedding it in one browser module (`dist/manimgx.js`), and TypeScript 7 generates the public+declarations from the implementation. The package installs manimgx's wheel for the browser+from PyPI, at its own version, in Pyodide, and plays with the player that wheel's engine carries.++The development tools are pinned in `bun.lock`. `just check` checks the TypeScript and its+formatting; `just test-typescript` runs the package's tests, in `browser/tests/`.++## [`docker/`](https://github.com/academa-labs/manimgx/tree/main/docker)++The `Dockerfile` of an image that installs manimgx from PyPI (the version it is built with,+or the latest) into `python:3.14-slim`, with Vulkan's loader and Mesa's drivers: lavapipe+draws on the CPU, and a GPU given to the container (`--device /dev/dri` for AMD and Intel,+`--gpus all` for NVIDIA) is used instead. Its entry point is the `manimgx` command, run in+`/work`:++```sh+docker run --rm -v "$PWD:/work" ghcr.io/academa-labs/manimgx render scene.py+```++`just build-docker-image <version>` builds it; a release publishes it.++## Releases++The version is in `pyproject.toml` (`0.1.0`; the engine's crate carries the+same number). manimgx follows [Semantic Versioning](https://semver.org), and its+[changelog](../changelog.md) [Keep a Changelog](https://keepachangelog.com): a change a+user would notice adds a line under "Unreleased" (see+[Documentation](documentation.md#the-changelog)).++A release takes three steps:++1. A commit on `main` sets the new version in `pyproject.toml`, and moves+ the changelog's "Unreleased" lines into a section of their own, `## X.Y.Z`.+2. `just release`, at that commit, asks for confirmation, tags it `vX.Y.Z`, and pushes the+ tag.+3. The tag starts the [Release workflow](github-workflows.md#4-releaseyaml-a-release). It+ stops unless the tag is manimgx's version and the changelog has a section for it; then+ it runs the tests, builds everything, and publishes: the GitHub release, whose notes are+ the changelog's section (`just release-notes X.Y.Z` prints them), PyPI, npm and ghcr.io.+ PyPI gets the font packages' versions it doesn't have yet: a change to the fonts sets a+ new version in their `pyproject.toml` and in manimgx's requirement, and is released with+ the next manimgx.++A version that ends in `aN`, `bN` or `rcN` (`0.2.0rc1`, say) is a pre-release.++## Learn more++- [uv's documentation](https://docs.astral.sh/uv/): projects, lockfiles, dependency groups.+- [maturin's user guide](https://www.maturin.rs): mixed Rust and Python projects.+- [cibuildwheel's documentation](https://cibuildwheel.pypa.io): building and testing wheels.+- [just's manual](https://just.systems/man/en/).diff --git a/docs/content/developer-guide/testing.md b/docs/content/developer-guide/testing.mdnew file mode 100644index 00000000..63c0fa07--- /dev/null+++ b/docs/content/developer-guide/testing.md@@ -0,0 +1,470 @@+# Testing++A test is code that checks that other code does what it should. Written once, it runs+again after every change, and says whether the change broke something.++manimgx's Python and integration tests are in+[`tests/`](https://github.com/academa-labs/manimgx/tree/main/tests).+Most of them render scenes, so the suite needs what rendering needs: a GPU the engine can+draw with (see [Setup](index.md#a-gpu)). Rendering the corpus's Manim references again+needs Manim Community Edition too (see+[Setup](index.md#manim-community-edition)).++The browser package's tests live beside it, in+[`browser/tests/`](https://github.com/academa-labs/manimgx/tree/main/browser/tests).+Run them with `just test-typescript`: it builds the package, tests the compiled player and+embedded worker with browser and Pyodide doubles, and type-checks a consumer of the generated+public declarations. These tests need Bun; they do not need a GPU or download Pyodide.++## [pytest](https://docs.pytest.org): the test runner++pytest finds the files named `test_*.py` under `tests/` and runs the functions in them+named `test_*`. [pytest-xdist](https://pytest-xdist.readthedocs.io) runs them in parallel,+a worker per CPU core. `just test` runs them, and passes its arguments on to pytest:++```sh+just test # the whole suite+just test tests/integration/test_time.py # one module+just test -k add_subpath_example # the tests whose name matches: one case's+just test tests/integration/test_time.py -x # stop at the first failure+```++The whole suite renders every case of the integration corpus, so it takes a while; while+you work, run the part your change touches. `pyproject.toml` puts the repository's root on+the path, so the tests import their own tools as `tests.integration.corpus`.++The Test workflow runs the suite on every push to `main` and every pull request, on Linux,+macOS and Windows, with Python 3.13 and 3.14 (see+[GitHub workflows](github-workflows.md#1-testyaml-the-checks-and-the-tests)).++## What the tests are++```text+tests/+├── unit/ ← properties of each module: unit/<path>/test_<module>.py+├── conftest.py ← each test's fresh world, its `config` marks, Hypothesis's profiles+├── strategies.py ← what Hypothesis draws, and a registry of every mobject class+├── oracles.py ← slow, plainly correct computations to compare with+├── scenes.py ← scenes made of functions, drawn or probed; random stories+├── test_tests.py ← the suite's own rules+├── integration/+│ ├── test_*.py ← stories: what a comparison with Manim cannot see+│ ├── test_corpus.py ← the corpus's three checks, for every case+│ ├── test_corpus_tools.py ← the corpus's tools keep their rules+│ ├── cases/ ← the corpus: a folder per case+│ ├── corpus/ ← the corpus's tools: render, compare, review+│ ├── review/ ← the review panel: a FastAPI server and its web page+│ └── settings.json ← the comparison's metric and tolerance+├── docs/+│ ├── test_llms.py ← llms.txt's primer, checked against the API; every page's Markdown+│ ├── test_skill.py ← the agent skill, checked against its specification+│ ├── test_reference.py ← the API reference shows every name the package documents, once+│ ├── test_hidden.py ← no example in the docs uses a name manimgx hides+│ ├── test_deprecated.py ← what is deprecated is left out of the reference+│ └── test_examples.py ← the narrated examples say what docs/voice/ keeps+└── benchmarks/+ ├── test_laws.py ← laws of cost: work grows as what is made does+ ├── test_speed.py ← timed: this checkout against another commit (just bench)+ ├── scenes/ ← the README's three scenes, which test_speed.py times+ ├── harness.py ← the trees compared, a render measured, and their rounds+ └── work.py ← work, counted+```++[`tests/docs/test_llms.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_llms.py)+checks the primer of the docs' `llms.txt`, written by hand for AI agents (see+[Documentation](documentation.md#markdown-for-agents)): its scene runs, and every name it+teaches exists. It also checks that every page is in a section of `llms.txt`, so that every+page has its Markdown.+[`tests/docs/test_skill.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_skill.py)+checks the agent skill's front matter (see+[Documentation](documentation.md#the-agent-skill)).+[`tests/docs/test_examples.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_examples.py)+runs the narrated examples with no voice's key, as the site is built (see+[Documentation](documentation.md#examples-films-rendered-from-the-code)).+[`tests/docs/test_reference.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_reference.py)+keeps the API reference, written by hand, whole: every name the package documents is on a+page, once, and no name it hides is (see [Documentation](documentation.md#the-api-reference)).+[`tests/docs/test_hidden.py`](https://github.com/academa-labs/manimgx/blob/main/tests/docs/test_hidden.py)+type-checks every example the docs show, and fails on a name manimgx hides (`@deprecated`).+The unit tests are in `tests/unit/`, the benchmarks in `tests/benchmarks/` (see+[Benchmarks](#benchmarks)), and the rest of the suite is in `tests/integration/`.++### Unit tests++[`tests/unit/`](https://github.com/academa-labs/manimgx/tree/main/tests/unit) mirrors the+package: `tests/unit/<path>/test_<module>.py` tests+`src/manimgx/<path>/<module>.py`, and opens with a docstring listing the+properties it checks. [`tests/test_tests.py`](https://github.com/academa-labs/manimgx/blob/main/tests/test_tests.py)+holds the suite to both, and its registries to every public mobject and animation class.++The unit tests check properties of the public API, not examples, and not how the code is+built inside: no test reads private storage, counts calls or orders hooks to pin how a result+is reached. With [Hypothesis](https://hypothesis.readthedocs.io), a test states what holds for+every input, and Hypothesis draws hundreds of inputs, then shrinks any that fails to the+simplest one that still does. The properties that do the work:++- agreement with a slow and plainly correct computation from+ [`tests/oracles.py`](https://github.com/academa-labs/manimgx/blob/main/tests/oracles.py):+ de Casteljau's construction, numpy's root finder, Gauss–Legendre quadrature, `decimal`+ arithmetic for a number's digits, the tight box of what is drawn;+- laws: `AnimationGroup(x)` plays as `x`, nested successions play as one, `Rotate` is+ `.animate.rotate`, moves played together end as applied in turn;+- laws every public class keeps, over the registries in+ [`tests/strategies.py`](https://github.com/academa-labs/manimgx/blob/main/tests/strategies.py):+ `MOBJECTS` (a copy, a target, a saved state or a construction made again is an independent+ replica of the same object graph, reaching nothing of its original; its inputs and outputs+ are values; its box is what it draws) and `ANIMATIONS` (made, it changes nothing; begun, it+ shows what it showed; it is a function of its progress);+- state machines checked against a plain model, over any history of public calls: a family's+ edits, transforms, updaters and their clocks, a scene's membership, a graph's edits, the+ feeder's books, what a paint remembers;+- remembered work is invisible: anything made with manimgx's memories warm is what it is made+ cold (a test marked `cold` starts and ends with nothing remembered);+- for time, random stories told on a headless scene+ ([`tests/scenes.py`](https://github.com/academa-labs/manimgx/blob/main/tests/scenes.py)):+ a play computed ahead of time shows what the same play computed frame by frame shows,+ and the world at an instant is the same at every frame rate.++[`tests/conftest.py`](https://github.com/academa-labs/manimgx/blob/main/tests/conftest.py)+starts every test from the same world: the scene clock at 0 and the configuration as it ships,+restored after the test. A test that needs another configuration says so with a mark,+`pytestmark = pytest.mark.config(pixel_width=320, pixel_height=180)` for a module, or+`@pytest.mark.config(frame_rate=30)` on a test, never by setting and restoring it by hand. It+also holds Hypothesis's profiles: `default`; `thorough`, 2,000 examples a property+(`just test-thorough`); and `mutation`. On CI, Hypothesis loads its own `ci` profile.++A fix comes with the property it broke, stated so that it fails without the fix. A bug found+on one input is that input added to the law it broke (an `@example`, or an entry of a+registry), not a test of its own; work that grew too fast is a row of the laws of cost. A law+that a known bug breaks marks exactly the cases it breaks `xfail(strict=True)`, its reason the+bug in a sentence: the day the bug is fixed, the mark has to go.++### Mutation testing++A test that passes proves little unless it would fail were the code wrong.+[mutmut](https://mutmut.readthedocs.io) checks that: it changes the code in small ways (a+`<` for a `<=`, a `+` for a `-`), one mutant at a time, and runs the tests against each. A+mutant that no test fails is a change the tests let through. `just mutate` runs it on the+modules `[tool.mutmut]` in `pyproject.toml` lists, under the `mutation` profile and with+everything manimgx remembers forgotten between tests (`manimgx.caches.clear`), so that a+cache cannot hide a mutant. It is slow, so it runs by hand, not on CI.++### Stories++Each `test_*.py` module in+[`tests/integration/`](https://github.com/academa-labs/manimgx/tree/main/tests/integration)+but `test_corpus.py` tells stories about one subject: time, motion, what the engine draws+(strokes, fills, images), light, perspective, 3D compositing, the film's hooks, its video,+sound and takes, the window and the preview, the banner. A story renders a scene and probes+it at every instant the scene computes, often at several frame rates. Its module's docstring+lists what it shows. `tests/scenes.py` makes a scene of a function (`scene`, `scene_3d`),+draws one and keeps its frames as arrays (`frames`), or keeps what a probe sees of it at+every instant (`instants`).++Stories check what a comparison with Manim cannot.+[`test_time.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/test_time.py),+for one, checks that what a frame shows does not depend on the frame rate: at 10, 30 and 60+frames per second, a dot moved by an updater is where its exact trajectory puts it at every+instant.++A fix or a feature comes with a test that shows it: a story in the module it belongs to,+or a new corpus case (see [Working with the corpus](#working-with-the-corpus)).++## The integration corpus++### The problem++manimgx implements Manim Community Edition's API. Scenes written for Manim must work, and+keep working as the engine changes. A test of one function does not see a wrong frame, and+reference images are too many to check by hand. And "the same as Manim" is not "correct":+Manim has bugs of its own, and manimgx differs from it on purpose (the exact clock, for+one).++So the corpus renders real scenes in both engines, compares them, lets a person decide+what is right, and holds manimgx to every stored render so a change cannot pass unnoticed.++### A case++A case is a folder in+[`tests/integration/cases/`](https://github.com/academa-labs/manimgx/tree/main/tests/integration/cases):++- `scene.py`: the only source. It is Manim code, and it reaches the engine only through+ `import manimgx`. A file the scene reads (an SVG, a sound) sits beside it.+- `manimgx.mkv` and `ce.mkv`: each engine's frames, lossless.+- `case.json`: the facts, written by the tools. The hash of the source both renders came+ from, the hash of every frame, and how the two engines' frames compare.+- `review.json`, once a person has reviewed the case: their verdict and note, pinned to the+ renders they were shown.++The cases are the examples of Manim's documentation and docstrings (the first line of+`scene.py` names its source), scenes written to cover manimgx's API, regressions, and+scenes written in answer to a question (the question is their docstring). The corpus is+the specification: what its working cases show is what manimgx does.++### Two engines, one source++Both engines run the same bytes. manimgx runs `scene.py` as it is. Manim runs it with+`manimgx` resolved to `manim`, and the run fails if the real manimgx is ever imported+([`run_ce.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/run_ce.py)).+Each render runs in a process of its own, with a fixed hash seed.++A frame is identified by the hash of its pixels, and stored in lossless video (x264 in+RGB, written and read with [PyAV](https://pyav.basswood-io.com), FFmpeg's libraries in a+wheel). A video is rewritten only when its pixels change, so+rendering an unchanged scene again changes no file. The corpus renders at 960 × 540, 10+frames per second.++### Comparing at the same scene time++Frames are paired by scene time, never by index. manimgx's frame _k_ shows the scene at+exactly _k_/fps. Manim rounds each play to whole frames and never shows a scene's last+animation landing; none of that may count against manimgx. So each manimgx frame is+compared with the frame Manim has on screen at the same scene time.++Each pair is measured in four metrics, from 0 to 255: `local_max`, `mae`, `rmse` and `max`.+[`settings.json`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/settings.json)+picks the one that decides, and its tolerance: `local_max` up to 30. `local_max` is the+largest mean, over any 7 × 7 window, of each pixel's largest channel difference: a lone+wrong pixel fades to 1/49 of itself, while a wrong stroke or shape stands out.++See [`compare.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/compare.py).++### Verdicts++A case is in one of these states:++| State | Meaning |+| --- | --- |+| `working` | At every manimgx frame, Manim's frame is within tolerance, and the scenes last as long. |+| `not_matching` | Otherwise, or Manim could not render the scene. |+| `not_working` | manimgx could not render the scene. |+| `stale`, `unrendered` | The case has no current renders to judge. |++The comparison gives a verdict; a person's verdict on exactly these renders overrides it.+Manim is a reference to look at, not a definition of correct, so "Manim does it this way"+is a reason to look closely, not a reason to change manimgx. A case is trusted when it is+working.++See [`case.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/case.py).++### The three checks++[`test_corpus.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/test_corpus.py)+checks every case three ways:++1. `test_same_source`: both references were rendered from this exact `scene.py`, which+ imports manimgx, never Manim. So the two engines ran the same program.+2. `test_types`: the scene type-checks as written: ty with every rule, no way around the+ checker (suppression comments, `Any`, `cast`, …), and no value that manimgx leaves+ `Any` or `Unknown`+ ([`typecheck.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/typecheck.py)).+3. `test_regression`: the scene renders, and the MP4 the product exports shows every frame+ of its film. Today's manimgx matches its stored frames, hash for hash, as well as the+ duration and timeline. This check covers every case, including those that differ from+ Manim or await review.++When `test_regression` fails, it reports changes to the duration, timeline or frames. For+changed frames it measures the difference and writes the worst pair, the reference's frame+beside today's, into `tests/integration/_diffs/<case>/`.++### Working with the corpus++`test_corpus.py` only checks; `just corpus` renders and reviews. A reference changes only+when a change means it to, and after someone has looked at the new frames.++- **A new case** is a folder in `cases/` holding its `scene.py`. Render it with+ `just corpus render CASE`, which renders it in both engines and compares them; look at+ it (`just review`); and record your verdict with `just corpus review CASE working` (or+ `not_matching`, or `not_working`; `--note` says why). Commit the folder as the tools left+ it.+- **A change that is meant to change how cases look** renders their references again with+ `just corpus render CASE…`. A case's review is pinned to the renders it was given for,+ so it no longer speaks for the new ones: look at the new frames before you commit them,+ and renew the verdict (in the review panel, or with `just corpus review`).+- `just corpus status` says where every case stands, and `just corpus --help` lists the+ rest.++### The corpus's tools++`just corpus` runs+[`tests/integration/corpus`](https://github.com/academa-labs/manimgx/tree/main/tests/integration/corpus):++| Command | What it does |+| --- | --- |+| `render [CASE…] [--all \| --stale] [--engine E] [-j N]` | Render references, then compare them |+| `compare [CASE…] [--all] [-j N]` | Compare the existing references again |+| `status [--list STATE…]` | Where every case stands |+| `review CASE VERDICT [--note TEXT]` | Record a verdict (`auto`: the comparison's) |+| `settings [--metric M] [--tolerance T]` | The comparison's metric and tolerance |+| `diff CASE [--frames N]` | Write the most different pairs of Manim's and manimgx's frames as images |+| `types` | The type report for every scene |+| `leaks` | Scenes that render differently after others, in one process |++`render` rewrites a video only when its pixels change, and a `case.json` only when its+facts do. Rendering Manim's references (the `ce` engine, and both engines when a scene+changed) needs Manim Community Edition: `uv sync --group ce` (see+[Setup](index.md#manim-community-edition)).++### The review panel++Judging a case means looking at it. `just review` builds the panel's web page (Svelte,+built by bun with Vite into `web/dist`) and serves it, with its FastAPI server, at+<http://127.0.0.1:8000>. The panel browses the corpus, shows each case's frames from both+engines side by side, and records verdicts; it also changes the comparison's settings and+renders a case again.++For work on the panel itself, `uv run fastapi dev` serves the server alone, reloading as+it changes, and `bun run dev` in `tests/integration/review/web/` serves the page.++See [`tests/integration/review/`](https://github.com/academa-labs/manimgx/tree/main/tests/integration/review).++## Coverage++Coverage says which lines of manimgx the tests run, and so which lines no test checks.+`just test-coverage` runs the suite with [pytest-cov](https://pytest-cov.readthedocs.io):+a summary in the terminal, and every line in `htmlcov/index.html`.++`[tool.coverage.run]` in `pyproject.toml` measures the package in the tests' processes and+in the ones they start (the corpus renders each case in its own), with paths relative to+the repository, so that runs on different systems combine: `just combine-coverage <folder>`+makes one report of their data files.++The Test workflow combines the coverage of its runs and publishes the report, served by+Cloudflare as+[`.github/deploy/coverage.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/coverage.jsonc)+says: `main`'s at <https://coverage.manimgx.academa.ai>, a pull request's (from a branch of+this repository) at a preview address, and each commit's linked from its "coverage"+status.++## Benchmarks++Speed is a feature, and a change that slows manimgx down is a regression like any other.+The benchmarks, in+[`tests/benchmarks/`](https://github.com/academa-labs/manimgx/tree/main/tests/benchmarks),+look for one in two ways: laws of cost, which run with the rest of the suite, and timed+benchmarks, which run alone.++### No benchmark holds a number of seconds++A test that asserts "this scene renders in under two seconds" checks the machine as much as+the code. A scene takes twice as long on one machine as on another (GitHub gives a single+runner label to machines 1.5 times apart), and on one machine one run differs from the next+by a few percent. So no benchmark compares a measurement with a number written down: each+compares two measurements taken side by side.++- **Work**, what a render does, is the same on every machine, and can be counted exactly:+ the Python functions manimgx runs and its loops' iterations (counted with+ [`sys.monitoring`](https://docs.python.org/3/library/sys.monitoring.html)), the points+ computed from a geometry's pieces, the bytes hashed, the bytes handed to the engine+ ([`work.py`](https://github.com/academa-labs/manimgx/blob/main/tests/benchmarks/work.py)).+ The laws compare the work of two sizes of one thing.+- **Time** can only be compared with time measured on the same machine at the same time.+ The timed benchmarks run this checkout and another commit's manimgx in turns, and+ compare them round by round.++### Laws of cost++[`test_laws.py`](https://github.com/academa-labs/manimgx/blob/main/tests/benchmarks/test_laws.py)+states how work may grow, and Hypothesis checks it:++- **Growth.** A thing made twice as big does at most twice the work, with a tenth to spare+ (a surface of twice the resolution, four times): a path built curve by curve, a group of+ shapes played, a text written, a graph redrawn every frame, a path traced for longer, a+ film held for longer, a table laid out. Some cost Python nothing more as they grow, their+ arrays doing the growing (`PYTHON`: no loop runs once an element). Each is a row,+ `law(build, sizes, power)`: `build(n)` sets a run of size n up and returns it, and only the+ run is counted. Hypothesis draws the size, and+ [`target`](https://hypothesis.readthedocs.io/en/latest/reference/api.html#hypothesis.target)+ climbs toward the worst ratio; the largest size always runs. A law that counts nothing of+ manimgx's fails.+- **Sharing.** Copies of any mobject, moved, turned and scaled, upload what one does: a+ shape is uploaded once, and its copies and moves are placements of it. Hypothesis draws the+ class from the registry of every public mobject class, and the copies and the moves.+- **Stillness.** A scene that holds a mobject still (one with no updater) does as much work+ for a second as for half a minute: a held frame is sent once.+- **History.** A story told four times does twice the work of two tellings: nothing a scene+ keeps makes its later frames dearer.++They run with `just test`, in seconds, on every system. They find what changes how work+grows: when a path read all of its points to find where it ends (fixed in `eef74e37`), a+path of twice the curves computed four times the points, and the laws of paths and of+traced paths fail on that code. A law that fails today is marked+`xfail(strict=True)` with its reason, and the day the code is fixed the mark has to go.++Work cannot see an operation that became slower, the same calls each taking longer: that is+what the timed benchmarks are for.++### Timed benchmarks++A workload is a scene rendered as a user renders it: `manimgx render`, in a process of its+own, from launch to the finished video. The workloads, in+[`test_speed.py`](https://github.com/academa-labs/manimgx/blob/main/tests/benchmarks/test_speed.py),+are the README's three scenes as the README times them, at 1920 × 1080 and 60 frames per+second ([`scenes/`](https://github.com/academa-labs/manimgx/tree/main/tests/benchmarks/scenes):+a surface the camera circles, a surface rebuilt every frame, and a 2D explainer), and six+example films at 480 × 270 and 10 frames per second. In the suite, each is rendered once,+tiny: it still renders. `just bench` times them against another manimgx:++```sh+just bench # this checkout against main+just bench HEAD # your uncommitted changes against the last commit+just bench v0.1.0 # against any commit, branch or tag+just bench ../manimgx-2 # against another checkout, as it is on disk+just bench main -k orbit # some of the workloads (arguments go to pytest)+```++- REF's manimgx is made in pytest's cache (`.pytest_cache/`), from git: with this checkout's+ engine when REF's engine sources (`rust/`) are this checkout's, else built (the first time+ takes a few minutes).+- Each run is a fresh process, with a fixed hash seed and an empty temporary directory, so no+ run finds another's Typst layouts. It is measured from launch to exit: what the README+ times, the imports, the GPU coming up, the storyboard and the encoder included.+- What is judged is the steadiest measure the system gives. macOS counts the instructions a+ process retires, and they do not change with the cores that ran it, or with what else the+ machine does. On a Mac whose GPU another program kept 90% busy, identical trees agreed to+ within 1.7% in every round; their CPU time differed by up to 36% and their wall time by 57%.+ Elsewhere it is CPU time, every thread's. Wall time and peak memory are shown beside it, not+ judged: on a shared machine they measure the other programs too.+- A round runs both, in a random order. The first round is not kept: it reads each tree's+ files into the disk's cache (a tree made a minute before ran 12% slower until then). Then+ five rounds (`--bench-rounds`).+- A round's two measures make a ratio. A workload is slower when the median ratio is more+ than 5% above 1 and the rounds agree, every one of the five: a machine's noise sends ratios+ both ways, and a real change moves all of them. A workload that looks slower is timed five+ rounds more, and is judged on all ten: nine must agree. Then its test fails. A workload that+ REF cannot render (it uses what came after REF) is skipped.+- Each tree's work is counted too, once, and the table shows the counts that changed:+ "points ×7328" says what a slowdown did.++Put into the code, a slowdown is found where it costs 5% or more; nothing is found when+nothing changed. Measured on that busy Mac, commit `289730bd`:++| This checkout | Workloads found slower | Largest change, and its work |+| --- | --- | --- |+| Unchanged | none: every round within 1.7% | no count changed |+| A path read whole to append a curve (`eef74e37` reverted) | neural_untangle, of the 3 tried | +60%: 7,328 times the points |+| 0.5 ms of Python in every frame | 5 of 9 | +9% (explainer): loops ×6.2 |+| 150 ms of work as manimgx is imported | 4 of 9 | +13% (taylor_poles) |+| A surface refined twice | morph | +50% |++Timing each scene's frames inside one process, as the benchmarks did before, saw none of the+work done as manimgx is imported; judging CPU time on that Mac, an identical tree came out+12% faster, and a change to code a film never runs made it "5% slower", in every round. What+instructions cannot see, a wait (a process that sleeps until its GPU is done) or work done on+the GPU, shows in the wall-time column: read it on a quiet machine.++The [Benchmark workflow](github-workflows.md#2-benchmarkyaml-the-timed-benchmarks) runs them+on Linux for every pull request that changes the package, against its base, and for every+push to `main`, against the commit before it; its table is in the run's summary. There the+measure is CPU time, and the GPU is Mesa's lavapipe, which draws on the CPU, so a workload's+time includes its drawing. A change that is meant to cost time (a feature) says so in its pull+request, with the table.++## Learn more++- [`test_corpus.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/test_corpus.py):+ the three checks.+- [`corpus/case.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/case.py):+ what a case holds, and its states.+- [`corpus/__main__.py`](https://github.com/academa-labs/manimgx/blob/main/tests/integration/corpus/__main__.py):+ the corpus's tools.diff --git a/docs/content/developer-guide/understanding-manimgx.md b/docs/content/developer-guide/understanding-manimgx.mdnew file mode 100644index 00000000..4347bbf3--- /dev/null+++ b/docs/content/developer-guide/understanding-manimgx.md@@ -0,0 +1,388 @@+# Understanding manimgx++This page follows a scene from its code to its video: what each step does, why it is built+the way it is, and where its code lives.++## How the package is organized++There are three different things to follow: constructing objects, changing their+state over time, and producing output. `mobjects/` is the catalog of constructors;+`mobject.py` is the shared mutable object model they use. Objects hold immutable+geometry and paint from `drawing/`. `scene.py` and `animation/` evaluate the object+graph, then `rendering/` turns its state into native records, films and playback.++| Responsibility | Implementation |+| --- | --- |+| Object identity, families, copying, layout, updaters and trackers; path, point-cloud and mesh rules | `mobject.py` |+| Authored shapes, plots, graphs, grids, text, images and other constructors | `mobjects/` |+| Geometry algorithms, immutable shapes, affine blends and motion paths | `drawing/geometry.py` |+| Color parsing and interpolation, immutable brushes and appearance | `drawing/paint.py` |+| Source and font environment to owned Typst layout | `drawing/typesetting.py` |+| Scene lifecycle, membership and camera state, including the specialized scenes | `scene.py` |+| Animation windows, transforms, presets, matching, updaters, easing and the exact clock | `animation/` |+| Native draw records, output sessions and the playback window | `rendering/feed.py`, `rendering/film.py`, `rendering/window.py` |+| Sound and speech values, word timing and voice providers | `audio/sound.py`, `audio/fal.py` |+| Scene loading, export, preview, diagnostics and storyboards | `cli/` |++These boundaries follow ownership. A drawing value has no mutable object family;+many objects can hold the same shape. A catalog constructor builds those objects+but does not own the scene clock. The scene evaluates them; the output layer reads+their evaluated values. Typesetting belongs with drawing data because a layout+contains glyphs, placements and labels, before any scene objects are built.++Configuration and frame-relative units live in `config.py`; shared authoring+constants and type aliases in `constants.py` and `typing.py`. `caches.py` supplies+the reuse and invalidation policy. Each algorithm keeps its own cached values.+The font distributions remain separate Python packages. The browser presentation+template lives beside its exporter in `cli/present.html`.++The top-level `manimgx` module exports the authoring API, and scenes import from it+alone: CE's module paths, such as `manim.utils.paths`, have no counterpart. The corpus+runs the same scenes on CE by finding those names where CE keeps them+(`tests/integration/corpus/run_ce.py`). Implementation code imports the owning module+directly.++## The core workflow++A scene passes through construction, evaluation and output:++```mermaid+flowchart LR+ subgraph python ["Python: src/manimgx"]+ A["construct(): catalog constructors"] --> B["mobject.py: object graph"]+ V["drawing: geometry and paint"] --> B+ T["drawing/typesetting: source and layout"] --> B+ B --> C["scene + animation: evaluate state"]+ C --> D["rendering: feed, film and playback"]+ end+ subgraph rust ["Rust: manimgx._engine"]+ Y["Typesetting: Typst"]+ G["Drawing: wgpu"]+ E["Encoding: x264"]+ end+ A -- "text source" --> T+ T -- "compile document" --> Y+ Y -- "glyphs, curves and labels" --> T+ D -- "resources and frame records" --> G+ G -- "pixels" --> E+ E --> O["video.mp4"]+```++The scene's code describes what happens. Constructors build mobjects whose current+state refers to drawing values; animations and updaters change that state. The clock+decides which instant a frame shows. The feed translates the evaluated state into+native drawing records, and the film directs the output. Python decides what a+frame shows; Rust draws its pixels and encodes the video.++This page follows this scene:++```python+import manimgx as m+++class UnderstandingManimgx(m.Scene):+ def construct(self) -> None:+ square = m.Square(side_length=3, color=m.BLUE, fill_opacity=0.5)+ label = m.MathTex(r"A = s^2", font_size=64).next_to(square, m.UP)+ self.play(m.Create(square), m.Write(label))+ self.play(square.animate.rotate(m.PI / 4))+```++## Step 1: The scene runs its code++`manimgx render scene.py` loads the file, picks the scene and calls+[`Scene.render`][manimgx.Scene.render]. `render` makes a new [`Film`][manimgx.Film], calls+`setup`, `construct` and `tear_down`, records a closing frame, and closes the film.++`construct` is ordinary Python, run once from top to bottom. The API it calls is Manim+Community Edition's: the same classes, methods and parameters. CE's behavior does not come+with it: what a scene means (its timing, its geometry, how it looks) is decided on its own+merits, so "Manim CE does it this way" is a reason to look closely, not a reason to change+manimgx. What the calls do is manimgx's own design, described below.++A [`Scene`][manimgx.Scene] holds three things: the mobjects it draws, a camera, and a clock.+Time passes only in [`play`][manimgx.Scene.play] and [`wait`][manimgx.Scene.wait]; everything+between two of them happens at one instant. The camera is made of mobjects (a frame+rectangle, value trackers for the 3D orbit), so animations and updaters move it as they+move anything else.++See [`scene.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/scene.py),+which owns the camera and scene variants as well as their shared execution model.++## Step 2: Mobjects++A mobject is what you see: the square and the formula above. It is a node of an object graph+(a [`VGroup`][manimgx.VGroup] holds others, and groups may share children) with points,+a style, updaters and a z-index.++### Geometry as a blend of shapes++Geometry is independent of the object that holds it: a mobject's points are a *blend* of immutable shapes,+points = Σₖ Mₖ·Sₖ. A shape Sₖ is an array of control points that never changes, identified+by its content. A matrix Mₖ is an affine map. Moving, scaling or turning a mobject composes+a matrix and leaves the shape alone; a morph from one shape to another is a blend of two+terms. Reading `points` computes the sum, and caches it. The engine receives the terms,+not the sum: turning the square sends one new matrix, not new points. Assigning a+mobject the points it has changes nothing (so does assigning a mesh its triangles, or a+paint its colors): it keeps what it holds, and all that was derived from it.++See [`drawing/geometry.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/drawing/geometry.py).+It also owns numeric sampling and cubic-outline conversion. Text clipping and Boolean+shapes use the same planar paths; `VMobject` owns building mutable curves from the result.++### Paint++A mobject's style is one immutable value, its `Paint`: its fill and stroke (a color each,+or several), its background stroke, its caps and joints, its dashes, and the part of it+that is revealed. A change makes a new paint. Every kind of mobject shares it; a kind+decides what several colors mean: gradient stops on a path, point or vertex colors,+or fill colors per lattice cell.++See [`drawing/paint.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/drawing/paint.py).++### Three kinds++[`Mobject`][manimgx.Mobject] implements, once, what every mobject does: transforms, bounds,+layout, style, interpolation. A kind overrides only how it is bounded, aligned with another+of its kind, and cut into parts:++- [`VMobject`][manimgx.VMobject]: paths of cubic Bézier curves, four control points each.+ The square is one.+- [`PMobject`][manimgx.PMobject]: point clouds.+- [`MeshMobject`][manimgx.MeshMobject]: vertices and triangles, colored per vertex or by a+ texture. Its topology is one immutable value: explicit triangle indices, or the+ dimensions of a sampled lattice. An [`ImageMobject`][manimgx.ImageMobject] is a textured+ quad; a [`Surface`][manimgx.Surface] samples a lattice once, with paint per cell and UVs+ per sample. Rendering derives its smooth spline, cell outlines and vertex colors.+ Equal lattices morph directly; different topology aligns as independent triangles.++All three kinds live in+[`mobject.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobject.py).+They share object identity, copying, family operations and lifecycle; their classes+keep the different rules for path curves, point colors and mesh topology explicit.++The [`mobjects/`](https://github.com/academa-labs/manimgx/tree/main/src/manimgx/mobjects)+catalog builds concrete drawings on those rules. `shapes.py` constructs figures,+curve decompositions, dashed paths and Boolean regions; `annotations.py` places labels,+frames and braces around objects;+`plotting.py` owns coordinate models and plotted data. `grid.py` groups the shared+entry model for matrices and tables, retaining their distinct layouts. Images,+graphs, surfaces, vector fields and text likewise have their own constructors.+Catalog code uses the kernel; the kernel does not import the catalog wholesale.++### Text: source, layout, and drawing++The formula is typeset by [Typst](https://typst.app), compiled into the engine: in the same+process, with no TeX installation. Typesetting constructs ordinary path mobjects; their+geometry, paint, animation, and rendering then work like the square's.++1. **Source.** [`mobjects/text.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobjects/text.py)+ holds the source frontends and their common builder. [`Typst`][manimgx.Typst] takes+ Typst markup; [`MathTypst`][manimgx.MathTypst] adds mathematical grouping;+ [`Text`][manimgx.Text] writes literal strings and typography runs;+ [`MathTex`][manimgx.MathTex] and [`Tex`][manimgx.Tex] convert LaTeX through the engine's+ [mitex](https://github.com/mitex-rs/mitex) converter. Each reaches the same typesetter.+2. **Layout.** [`drawing/typesetting.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/drawing/typesetting.py)+ combines the source with its preamble, fonts, and package environment. The engine+ typesets the document and reads Typst's frames: glyph placements, paint, source+ byte ranges, cubic shapes, and labeled groups. Python keeps the drawable rows+ and the immutable outlines and ligature carets they refer to. This is drawing data;+ it contains no scene objects.+3. **Mobjects.** The common Typst builder places each glyph as a blend of its immutable+ outline and a matrix, gives each part its paint, and creates groups referring to+ the actual parts. Literal text associates glyphs with characters; LaTeX associates+ them with selectable formula pieces. Changing a character's color can split a+ ligature at its carets without changing the typeset layout.++Layouts are cached on disk in the system's temporary `manimgx-layouts` directory,+keyed by source and environment. Decoded glyph records are reused in a bounded cache,+while layouts and live glyphs hold what they need themselves. Clearing that cache does+not invalidate existing text. The fonts come from the caller's paths, the installed+manimgx font packages, and Typst's embedded fonts; a system font is considered only for+a family the document explicitly names. See [The engine](engine.md#typesetting) for+the native compiler and font environment.++Two consumers have their own layout responsibilities.+[`mobjects/code.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobjects/code.py)+builds syntax-colored listings with a line and column grid, line numbers, and a frame.+[`mobjects/numbers.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobjects/numbers.py)+formats and lays out number rows that can change during an animation. Both use the+typeset mobjects rather than another text renderer.++SVG takes a separate input route.+[`mobjects/svg.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobjects/svg.py)+reads an external vector drawing, converts its shapes and paths, applies its paint and+transforms, and preserves its id groups. It reaches the same geometry and paint model+without passing through the typesetter.++## Step 3: Animations++Animations describe changes to the object graph. Their timing and their geometric+composition have separate owners: a window says when an animation acts, while a+transform says how it changes an object. Animation classes are built on two primitives.++- A **tween**, [`Transform`][manimgx.Transform]: it moves each leaf of its mobject between+ keyframes, along a path. Most classes are presets of keyframes, path and flags. A reveal+ is paint (the revealed part of a path), so [`Create`][manimgx.Create] is a tween too.+- A **procedure**, [`Animation`][manimgx.Animation]: its progress α, from 0 to 1, drives+ code that changes the mobject.++On top of them:++- [`.animate`][manimgx.Mobject.animate] records method calls. When its animation begins, it+ carries them out on the mobject as it is then, and tweens to the result.+- [`AnimationGroup`][manimgx.AnimationGroup], [`LaggedStart`][manimgx.LaggedStart] and+ [`Succession`][manimgx.Succession] are one class. A group gives each part a window of its+ own time, and a part's α is a function of that time alone, so a group can be evaluated at+ any number of instants at once.+- Tweens that begin together on one leaf compose: its motion chains all of theirs, and+ each paint field is the last changer's.++See [`animation/`](https://github.com/academa-labs/manimgx/tree/main/src/manimgx/animation):+[`timeline.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/animation/timeline.py)+owns lifecycle and nested time windows;+[`transform.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/animation/transform.py)+owns keyframe evaluation, recorded method calls and concurrent leaf composition;+[`motion.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/animation/motion.py)+builds the animation presets on them. Timing composition and geometric composition+have separate owners because they answer different questions: when a part acts, and+how its contribution combines with the other transforms acting on the same object.++## Step 4: The clock++If time is a float that each frame advances by 1/fps, errors accumulate,+a play's length is rounded to whole frames, and a physics updater given `dt = 1/fps`+behaves differently at 30 and at 60 frames per second. What a scene shows would depend on+its frame rate.++Scene time is exact, a `Fraction` of seconds, and frames sample it.++- A play or wait of duration _d_ that begins at time _T_ owns the frames whose times fall+ in [_T_, _T_ + _d_). Frame _k_ shows the world at exactly _k_/fps.+- Then the world is brought to _T_ + _d_ itself, where `construct` goes on.+- When `construct` returns, a closing frame shows the scene as it ends.++At each instant, the playing animation is evaluated at its point in its window of time,+then the updaters run, then the recorders (such as a [`TracedPath`][manimgx.TracedPath]).+A per-frame updater restores a relation. A time-based updater that is a *flow* is exact at+any instant; any other time-based updater is *simulated*, stepped on a clock of its own+(`config.simulation_rate` ticks a second, 60 by default), so the world is the same at every+frame rate.++The frames of a play are computed in one of two ways:++- **One instant at a time**, in general: the play's step, then the updaters, for each frame.+- **All at once**, for a play that is a pure function of time: tweens between fixed+ keyframes, in a scene with no updaters. Its frames are computed together, as arrays.++A wait in which nothing can change is one frame, held.++See [`animation/clock.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/animation/clock.py) and,+in [`scene.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/scene.py),+`play`, `_run` and `_instant`. The User Guide's+[The basics](../user-guide/the-basics.md#one-step-after-another) describes the clock as a+scene's author sees it.++## Step 5: The film and its feed++The renderer consumes drawing values rather than the Python object graph. A frame+is described to the engine as a *view* (the camera's matrices and the background) and one 320-byte *record* per object: its two shape keys and+two 3×4 matrices (the blend's terms), its reveal window, its colors, its gradient or+per-vertex color rows (by key), its widths and flags. Shapes, color rows and textures are+uploaded once, keyed by their content and interpretation (an xxh3 digest). Equal shapes+of the same kind share GPU memory; a path and a point cloud with the same coordinates+remain separate resources. What no frame has shown for a while is freed.++The [`Film`][manimgx.Film] sends each frame:++- to the video, encoded as it comes;+- to a function, if one is given, as a [`Frame`][manimgx.rendering.film.Frame] that draws its pixels+ only when asked;+- or without per-frame output: `manimgx check` evaluates the timeline and draws only+ selected storyboard snapshots.++A frame equal to the one before is not sent again: it lengthens it, into a hold. Each play,+as it ends, is kept as a [`Play`][manimgx.rendering.film.Play]: its exact start and end, and the line+of the scene's code that played it.++See [`rendering/film.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/rendering/film.py) and+[`rendering/feed.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/rendering/feed.py).++Sound follows the same scene timeline. `audio/sound.py` owns [`Sound`][manimgx.Sound]+and [`Speech`][manimgx.Speech], their edits and word times. The scene schedules clips+and captions; the film carries them into its output. Voice-provider code is separate+in `audio/fal.py`, while any function returning a Speech can be a voice.++## Step 6: The engine++The engine is a Rust crate compiled into the package as `manimgx._engine`. It draws the+records on the GPU with [wgpu](https://wgpu.rs), 2D paths exactly (each pixel covered by+the area inside it, computed from the control points), and 3D scenes, point clouds and+meshes with a raster pipeline. For a video, it converts only the parts of a frame that+changed, hands them to x264 on a thread of its own, and writes the MP4. It also typesets.++[The engine](engine.md) describes it.++## The command line++`manimgx render`, `still` and `check` are a [Typer](https://typer.tiangolo.com) app in+[`cli/`](https://github.com/academa-labs/manimgx/tree/main/src/manimgx/cli). Each loads the+scene file, picks the scene, sets the configuration, and renders it with the film's hooks:+a *take*. `render` and `check` report the timeline, a storyboard, and the layout problems a+viewer would see when each play ends (what the frame cuts off, texts that overlap, lines+through a text, fills drawn over one, text too small to read), measured on geometry, not+pixels; `still` draws the frames at given times on one sheet. An error in the scene is+shown through the lines of the author's own code. `manimgx preview` records the scene as a+take and sends it to a [`Window`][manimgx.Window], a process of its own that plays it, and+runs the scene again each time its file is saved (see [The engine](engine.md#the-player)).++The command-line modules follow those operations: `cli/scenes.py` loads and selects+scenes and records takes; `cli/export.py` writes videos, stills and presentation+pages; `cli/preview.py` manages re-recording for the window. `cli/diagnostics.py`+reads visible scene geometry and reports layout problems. `cli/storyboard.py`+collects frame sheets and timeline reports. These are clients of scene execution+and film hooks, rather than another scene or rendering model.++The [command line's reference](../reference/rendering/command-line.md) lists every command and+option.++## Dependencies++manimgx needs these packages at run time:++| Package | What it does for manimgx | Where |+| --- | --- | --- |+| [numpy](https://numpy.org) | Arrays: points, matrices, colors, records | Everywhere |+| [pillow](https://python-pillow.github.io) | Images: an `ImageMobject`'s pixels, the command line's sheets | `mobjects/images.py`, `cli/storyboard.py` |+| [skia-pathops](https://github.com/fonttools/skia-pathops) | Boolean operations on paths: `Union`, `Difference`, `Intersection`, `Exclusion` | `mobjects/shapes.py` |+| [svgelements](https://github.com/meerk40t/svgelements) | Reading SVG: `SVGMobject`, braces, the logo | `mobjects/svg.py` |+| [networkx](https://networkx.org) | Graph layouts, for `Graph` | `mobjects/graph.py` |+| [isosurfaces](https://github.com/jared-hughes/isosurfaces) | The curves of `ImplicitFunction` | `mobjects/plotting.py` |+| [typer](https://typer.tiangolo.com) | The command line | `cli/` |++The engine's own dependencies are Rust crates, compiled in: see [The engine](engine.md).++## The complete pipeline++When you run `manimgx render scene.py`:++1. **Run**: the scene's `construct` runs once; `play` and `wait` move its exact clock.+2. **Change**: animations and updaters change mobjects, whose geometry is a blend of+ immutable shapes and whose style is one immutable paint.+3. **Sample**: frame _k_ shows the world at _k_/fps; a pure play's frames are computed at+ once.+4. **Feed**: each frame becomes a view and a 320-byte record per object; shapes cross to+ the engine once.+5. **Draw and encode**: the engine draws each frame on the GPU and encodes what changed+ into an H.264 MP4.++## Learn more++- [`scene.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/scene.py): a+ scene's lifecycle, `play`, `wait`, and the clock's rules.+- [`mobject.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/mobject.py):+ what every mobject has.+- [`rendering/feed.py`](https://github.com/academa-labs/manimgx/blob/main/src/manimgx/rendering/feed.py): the+ record, field by field.+- Implementation modules introduce their design in a module docstring for the+ developers who change them. The API reference does not show it.