Skip to content

The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.

Python

Measure a text at 1080p by the video's short side

Mert Kaya00dbc03daa95
diff --git a/docs/content/changelog.md b/docs/content/changelog.md
index d0a54fc1..dc121dc1 100644
--- a/docs/content/changelog.md
+++ b/docs/content/changelog.md
@@ -40,6 +40,7 @@ The notable changes to ManimGX, release by release. The format follows
### Fixed
- Redraw a shape that empties with `always_redraw` without a RecursionError, and keep a mobject's updaters off the member its points move into when a transform aligns it, so a relative updater such as `always_shift` no longer runs twice on them ([#32](https://github.com/academa-labs/manimgx/issues/32)).
+- Measure a text's size in `inspect` and `render` at 1080p, which is 1080 px on a video's short side, so a tall video (1080x1920) no longer reports readable text as small ([#37](https://github.com/academa-labs/manimgx/issues/37)).
- Keep resources needed by queued video frames until their transparency retries finish, fixing render failures during cache cleanup ([#16](https://github.com/academa-labs/manimgx/issues/16)).
- Draw a storyboard picture without dropping the frame the film holds back, fixing `manimgx render` failures ("unknown shape") under memory pressure.
- Draw a vectorized curve whose function gives a component as one number (`use_vectorized` with `lambda t: (t, t**2, 0)`), which failed with numpy's inhomogeneous-shape error.
diff --git a/src/manimgx/cli/diagnostics.py b/src/manimgx/cli/diagnostics.py
index eb1d9c5a..f2f69785 100644
--- a/src/manimgx/cli/diagnostics.py
+++ b/src/manimgx/cli/diagnostics.py
@@ -281,7 +281,7 @@ GRIDS = {
BACKDROPS = {"BackgroundRectangle"}
# scene units (4 px at 1080p): a line this close to a glyph's box touches it
TOUCH = 0.03
-# pixels tall at 1080p: text below this is hard to read
+# pixels tall at 1080p, a video whose short side is 1080 px: text below this is hard to read
SMALL = 20
@@ -380,7 +380,9 @@ def _cut(box: Box, frame: Box) -> str | None:
def at(seen: View) -> list[Problem]:
"""The problems a viewer sees in this view."""
frame, things = seen.frame, seen.things
- px_per_unit = 1080 / (frame[3] - frame[1])
+ # the camera maps the frame's height onto the video's, whatever the frame's shape
+ short = min(config.pixel_width, config.pixel_height)
+ px_per_unit = 1080 * config.pixel_height / short / (frame[3] - frame[1])
now: list[Problem] = []
texts = [t for t in things if t.text is not None]
shapes = [t for t in things if t.outline is not None]
diff --git a/tests/integration/test_inspect.py b/tests/integration/test_inspect.py
index f4b28b05..dbb8f853 100644
--- a/tests/integration/test_inspect.py
+++ b/tests/integration/test_inspect.py
@@ -13,11 +13,13 @@ from manimgx.cli.storyboard import CAPTION, GAP, tile
from manimgx.rendering.film import Frame
-def source(tmp_path: Path, body: str, base: str = "Scene") -> Path:
+def source(
+ tmp_path: Path, body: str, base: str = "Scene", size: tuple[int, int] = (320, 180)
+) -> Path:
path = tmp_path / "scene.py"
path.write_text(
"import manimgx as m\n"
- "m.config.pixel_width, m.config.pixel_height = 320, 180\n"
+ f"m.config.pixel_width, m.config.pixel_height = {size[0]}, {size[1]}\n"
"m.config.frame_rate = 10\n"
f"class Example(m.{base}):\n"
" def construct(self) -> None:\n"
@@ -104,6 +106,35 @@ def test_the_last_frame_keeps_local_names_and_problem_numbers(tmp_path: Path) ->
assert "tiny (Text 'tiny')" in result.output
+ "size", [(320, 180), (640, 360), (180, 320), (320, 320), (240, 180), (180, 240)]
+)
+def test_a_text_is_as_tall_in_every_video_shape(
+ tmp_path: Path, size: tuple[int, int]
+) -> None:
+ """A video is 1080p when its short side is 1080 px, so a text measures the same at 1080p in
+ a video of any shape and resolution."""
+ body = 'self.add(m.Text("Hello", font_size=12))\nself.wait()'
+ result = CliRunner().invoke(
+ app, ["inspect", str(source(tmp_path, body, size=size))]
+ )
+ assert result.exit_code == 1, result.output
+ assert "text is 16 px tall at 1080p" in result.output
+
+
+def test_a_camera_frame_stretched_narrow_leaves_a_texts_height(tmp_path: Path) -> None:
+ """The camera maps the frame's width and its height onto the video's apart: stretching the
+ frame's width changes how wide a text is, not how tall."""
+ body = (
+ "self.camera.frame.stretch_to_fit_width(4)\n"
+ 'self.add(m.Text("Hello", font_size=12))\nself.wait()'
+ )
+ path = source(tmp_path, body, base="MovingCameraScene", size=(180, 320))
+ result = CliRunner().invoke(app, ["inspect", str(path)])
+ assert result.exit_code == 1, result.output
+ assert "text is 16 px tall at 1080p" in result.output
+
+
def test_notes_do_not_fail_inspection(tmp_path: Path) -> None:
path = source(tmp_path, "self.add(m.Line(10 * m.LEFT, 10 * m.RIGHT))\nself.wait()")
result = CliRunner().invoke(app, ["inspect", str(path)])