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

Add shared scene types and constants

apoogdkd6facc34c4b6
diff --git a/rust/bridge/Cargo.toml b/rust/bridge/Cargo.toml
new file mode 100644
index 00000000..9ed96dca
--- /dev/null
+++ b/rust/bridge/Cargo.toml
@@ -0,0 +1,20 @@
+[workspace]
+resolver = "2"
+members = [
+ "crates/manimgx-core",
+ "crates/manimgx-encode",
+ "crates/manimgx-render",
+ "crates/manimgx-metal",
+ "crates/manimgx-py",
+]
+default-members = [
+ "crates/manimgx-core",
+ "crates/manimgx-encode",
+ "crates/manimgx-render",
+ "crates/manimgx-metal",
+]
+
+[workspace.dependencies]
+glam = "0.29"
+bytemuck = { version = "1", features = ["derive"] }
+log = "0.4"
diff --git a/rust/bridge/crates/manimgx-core/Cargo.toml b/rust/bridge/crates/manimgx-core/Cargo.toml
new file mode 100644
index 00000000..1da7358f
--- /dev/null
+++ b/rust/bridge/crates/manimgx-core/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "manimgx-core"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+glam = { workspace = true }
+bytemuck = { workspace = true }
+log = { workspace = true }
diff --git a/rust/bridge/crates/manimgx-core/src/camera.rs b/rust/bridge/crates/manimgx-core/src/camera.rs
new file mode 100644
index 00000000..676bf11a
--- /dev/null
+++ b/rust/bridge/crates/manimgx-core/src/camera.rs
@@ -0,0 +1,225 @@
+use glam::{Mat4, Vec3};
+
+/// View transform — position, look_at, up. Shared by all projection types.
+#[derive(Clone, Copy, Debug)]
+pub struct Camera {
+ pub position: Vec3,
+ pub look_at: Vec3,
+ pub up: Vec3,
+}
+
+impl Default for Camera {
+ fn default() -> Self {
+ Self {
+ position: Vec3::new(3.0, 2.0, 5.0),
+ look_at: Vec3::ZERO,
+ up: Vec3::Y,
+ }
+ }
+}
+
+impl Camera {
+ pub fn view_matrix(&self) -> Mat4 {
+ Mat4::look_at_rh(self.position, self.look_at, self.up)
+ }
+}
+
+/// Projection type — each variant stores its own parameters and computes its own matrix.
+#[derive(Clone, Copy, Debug)]
+pub enum Projection {
+ /// Standard perspective projection.
+ Perspective { fov: f32, near: f32, far: f32 },
+ /// Parallel projection with oblique rays (cabinet/cavalier).
+ /// `alpha` — angle of oblique rays in degrees.
+ /// `l` — foreshortening ratio (0.5 = cabinet, 1.0 = cavalier).
+ /// `height` — visible vertical range in world units. Width = height * aspect_ratio.
+ Oblique {
+ alpha: f32,
+ l: f32,
+ height: f32,
+ near: f32,
+ far: f32,
+ },
+}
+
+impl Projection {
+ /// Returns the pure projection matrix (no oblique shear).
+ pub fn projection_matrix(&self, _aspect_ratio: f32) -> Mat4 {
+ match self {
+ Projection::Perspective { fov, near, far } => {
+ Mat4::perspective_rh(fov.to_radians(), _aspect_ratio, *near, *far)
+ }
+ Projection::Oblique {
+ height, near, far, ..
+ } => {
+ let width = height * _aspect_ratio;
+ let half_w = width / 2.0;
+ let half_h = height / 2.0;
+ Mat4::orthographic_rh(-half_w, half_w, -half_h, half_h, *near, *far)
+ }
+ }
+ }
+
+ /// Returns the oblique shear matrix (identity for non-oblique projections).
+ /// This shear must be applied in world space (before the view transform)
+ /// so that objects at z=0 are unaffected.
+ pub fn world_shear_matrix(&self) -> Mat4 {
+ match self {
+ Projection::Perspective { .. } => Mat4::IDENTITY,
+ Projection::Oblique { alpha, l, .. } => {
+ let alpha_rad = alpha.to_radians();
+ let shear_x = l * alpha_rad.cos();
+ let shear_y = l * alpha_rad.sin();
+ Mat4::from_cols_array(&[
+ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, shear_x, shear_y, 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0,
+ ])
+ }
+ }
+ }
+}
+
+impl Default for Projection {
+ fn default() -> Self {
+ Projection::Perspective {
+ fov: 45.0,
+ near: 0.1,
+ far: 100.0,
+ }
+ }
+}
+
+/// Composes Camera (view) + Projection into a single rig.
+/// Stored in Scene, consumed by renderer.
+#[derive(Clone, Copy, Debug, Default)]
+pub struct CameraRig {
+ pub camera: Camera,
+ pub projection: Projection,
+}
+
+impl CameraRig {
+ pub fn view_projection_matrix(&self, aspect_ratio: f32) -> Mat4 {
+ // Oblique shear is applied in world space (before view transform)
+ // so that 2D objects at z=0 are unaffected by the shear.
+ // Pipeline: projection * view * shear * world_pos
+ let proj = self.projection.projection_matrix(aspect_ratio);
+ let view = self.camera.view_matrix();
+ let shear = self.projection.world_shear_matrix();
+ proj * view * shear
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn camera_view_matrix_look_at() {
+ let camera = Camera {
+ position: Vec3::new(0.0, 0.0, 5.0),
+ look_at: Vec3::ZERO,
+ up: Vec3::Y,
+ };
+ let view = camera.view_matrix();
+ let expected = Mat4::look_at_rh(Vec3::new(0.0, 0.0, 5.0), Vec3::ZERO, Vec3::Y);
+ assert_eq!(view, expected);
+ }
+
+ #[test]
+ fn perspective_projection_matches_glam() {
+ let proj = Projection::Perspective {
+ fov: 45.0,
+ near: 0.1,
+ far: 100.0,
+ };
+ let aspect = 16.0 / 9.0;
+ let mat = proj.projection_matrix(aspect);
+ let expected = Mat4::perspective_rh(45.0_f32.to_radians(), aspect, 0.1, 100.0);
+ assert_eq!(mat, expected);
+ }
+
+ #[test]
+ fn oblique_cavalier_vs_cabinet() {
+ let cavalier = Projection::Oblique {
+ alpha: 45.0,
+ l: 1.0,
+ height: 10.0,
+ near: 0.1,
+ far: 100.0,
+ };
+ let cabinet = Projection::Oblique {
+ alpha: 45.0,
+ l: 0.5,
+ height: 10.0,
+ near: 0.1,
+ far: 100.0,
+ };
+
+ // Cavalier has stronger shear than cabinet (l=1.0 vs l=0.5)
+ let cav_shear = cavalier.world_shear_matrix();
+ let cab_shear = cabinet.world_shear_matrix();
+ assert_ne!(cav_shear, Mat4::IDENTITY);
+ assert_ne!(cab_shear, Mat4::IDENTITY);
+ assert_ne!(cav_shear, cab_shear);
+ }
+
+ #[test]
+ fn oblique_different_angles() {
+ let alpha0 = Projection::Oblique {
+ alpha: 0.0,
+ l: 0.5,
+ height: 10.0,
+ near: 0.1,
+ far: 100.0,
+ };
+ let alpha45 = Projection::Oblique {
+ alpha: 45.0,
+ l: 0.5,
+ height: 10.0,
+ near: 0.1,
+ far: 100.0,
+ };
+ let shear0 = alpha0.world_shear_matrix();
+ let shear45 = alpha45.world_shear_matrix();
+ assert_ne!(shear0, shear45);
+ }
+
+ #[test]
+ fn oblique_2d_objects_unaffected_by_shear() {
+ // Objects at z=0 should not be displaced by oblique shear
+ let proj = Projection::Oblique {
+ alpha: 45.0,
+ l: 0.5,
+ height: 8.0,
+ near: 0.1,
+ far: 100.0,
+ };
+ let shear = proj.world_shear_matrix();
+ let point_at_z0 = glam::Vec4::new(3.0, 2.0, 0.0, 1.0);
+ let result = shear * point_at_z0;
+ assert_eq!(result.x, 3.0);
+ assert_eq!(result.y, 2.0);
+ assert_eq!(result.z, 0.0);
+ }
+
+ #[test]
+ fn camera_rig_perspective_view_projection() {
+ // For perspective (no shear), view_projection = projection * view
+ let rig = CameraRig {
+ camera: Camera {
+ position: Vec3::new(3.0, 2.0, 5.0),
+ look_at: Vec3::ZERO,
+ up: Vec3::Y,
+ },
+ projection: Projection::Perspective {
+ fov: 60.0,
+ near: 0.5,
+ far: 200.0,
+ },
+ };
+ let aspect = 16.0 / 9.0;
+ let vp = rig.view_projection_matrix(aspect);
+ let expected = rig.projection.projection_matrix(aspect) * rig.camera.view_matrix();
+ assert_eq!(vp, expected);
+ }
+}
diff --git a/rust/bridge/crates/manimgx-core/src/lib.rs b/rust/bridge/crates/manimgx-core/src/lib.rs
new file mode 100644
index 00000000..06e0bd9e
--- /dev/null
+++ b/rust/bridge/crates/manimgx-core/src/lib.rs
@@ -0,0 +1,12 @@
+pub mod animation;
+pub mod camera;
+pub mod color;
+pub mod encoder;
+pub mod geometry;
+pub mod material;
+pub mod mp4_muxer;
+pub mod scene;
+pub mod timeline_eval;
+pub mod transform;
+pub mod uniform;
+pub mod vertex;
diff --git a/rust/bridge/crates/manimgx-core/src/scene.rs b/rust/bridge/crates/manimgx-core/src/scene.rs
new file mode 100644
index 00000000..1832b763
--- /dev/null
+++ b/rust/bridge/crates/manimgx-core/src/scene.rs
@@ -0,0 +1,149 @@
+use crate::camera::CameraRig;
+use crate::material::Material;
+use crate::transform::Transform;
+use crate::vertex::Vertex;
+
+pub type ObjectId = usize;
+
+/// RGBA bitmap data for textured objects (e.g. rendered text).
+#[derive(Clone, Debug)]
+pub struct TextureData {
+ pub rgba: Vec<u8>,
+ pub width: u32,
+ pub height: u32,
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+pub enum RenderHint {
+ #[default]
+ Default,
+ FlatUnlit,
+ /// Textured quad (e.g. text bitmap). Uses text.wgsl with texture sampling.
+ Textured,
+}
+
+#[derive(Clone, Debug)]
+pub struct SceneObject {
+ pub id: ObjectId,
+ pub vertices: Vec<Vertex>,
+ pub indices: Vec<u32>,
+ pub transform: Transform,
+ pub base_transform: Transform,
+ pub material: Material,
+ pub base_material: Material,
+ pub render_hint: RenderHint,
+ /// Optional texture data for Textured render hint (uploaded once, not per frame).
+ pub texture_data: Option<TextureData>,
+}
+
+pub struct Scene {
+ pub width: u32,
+ pub height: u32,
+ pub fps: u32,
+ pub background: [f32; 4],
+ pub camera: CameraRig,
+ pub base_camera: CameraRig,
+ pub objects: Vec<SceneObject>,
+ next_id: ObjectId,
+}
+
+impl Scene {
+ pub fn new(width: u32, height: u32, fps: u32, background: [f32; 3]) -> Self {
+ Self {
+ width,
+ height,
+ fps,
+ background: [background[0], background[1], background[2], 1.0],
+ camera: CameraRig::default(),
+ base_camera: CameraRig::default(),
+ objects: Vec::new(),
+ next_id: 0,
+ }
+ }
+
+ pub fn set_camera(&mut self, camera: CameraRig) {
+ self.camera = camera.clone();
+ self.base_camera = camera;
+ }
+
+ pub fn add_object_with_hint(
+ &mut self,
+ vertices: Vec<Vertex>,
+ indices: Vec<u32>,
+ material: Material,
+ render_hint: RenderHint,
+ position: [f32; 3],
+ ) -> ObjectId {
+ let id = self.next_id;
+ self.next_id += 1;
+ let transform = Transform {
+ translation: glam::Vec3::new(position[0], position[1], position[2]),
+ ..Transform::default()
+ };
+ self.objects.push(SceneObject {
+ id,
+ vertices,
+ indices,
+ transform: transform.clone(),
+ base_transform: transform,
+ material: material.clone(),
+ base_material: material,
+ render_hint,
+ texture_data: None,
+ });
+ id
+ }
+
+ /// Add a textured object (e.g. text bitmap) with texture data attached.
+ pub fn add_textured_object(
+ &mut self,
+ vertices: Vec<Vertex>,
+ indices: Vec<u32>,
+ material: Material,
+ position: [f32; 3],
+ texture: TextureData,
+ ) -> ObjectId {
+ let id = self.next_id;
+ self.next_id += 1;
+ let transform = Transform {
+ translation: glam::Vec3::new(position[0], position[1], position[2]),
+ ..Transform::default()
+ };
+ self.objects.push(SceneObject {
+ id,
+ vertices,
+ indices,
+ transform: transform.clone(),
+ base_transform: transform,
+ material: material.clone(),
+ base_material: material,
+ render_hint: RenderHint::Textured,
+ texture_data: Some(texture),
+ });
+ id
+ }
+
+ pub fn set_transform(&mut self, id: ObjectId, transform: Transform) {
+ if let Some(obj) = self.objects.get_mut(id) {
+ obj.transform = transform;
+ }
+ }
+
+ pub fn set_material(&mut self, id: ObjectId, material: Material) {
+ if let Some(obj) = self.objects.get_mut(id) {
+ obj.material = material;
+ }
+ }
+
+ pub fn reset_to_base(&mut self) {
+ self.camera = self.base_camera.clone();
+ for obj in &mut self.objects {
+ obj.transform = obj.base_transform.clone();
+ obj.material = obj.base_material.clone();
+ }
+ }
+
+ pub fn aspect_ratio(&self) -> f32 {
+ self.width as f32 / self.height as f32
+ }
+}
diff --git a/rust/bridge/crates/manimgx-core/src/transform.rs b/rust/bridge/crates/manimgx-core/src/transform.rs
new file mode 100644
index 00000000..dc2f28c3
--- /dev/null
+++ b/rust/bridge/crates/manimgx-core/src/transform.rs
@@ -0,0 +1,46 @@
+use glam::{Mat4, Quat, Vec3};
+
+#[derive(Clone, Copy, Debug)]
+pub struct Transform {
+ pub translation: Vec3,
+ pub rotation: Vec3,
+ pub scale: Vec3,
+}
+
+impl Default for Transform {
+ fn default() -> Self {
+ Self {
+ translation: Vec3::ZERO,
+ rotation: Vec3::ZERO,
+ scale: Vec3::ONE,
+ }
+ }
+}
+
+impl Transform {
+ pub fn to_matrix(&self) -> Mat4 {
+ // Fast path: skip quaternion for zero rotation (common for 2D objects)
+ if self.rotation == Vec3::ZERO {
+ return Mat4::from_scale_rotation_translation(
+ self.scale,
+ Quat::IDENTITY,
+ self.translation,
+ );
+ }
+ let rotation_quat = Quat::from_euler(
+ glam::EulerRot::YXZ,
+ self.rotation.y.to_radians(),
+ self.rotation.x.to_radians(),
+ self.rotation.z.to_radians(),
+ );
+ Mat4::from_scale_rotation_translation(self.scale, rotation_quat, self.translation)
+ }
+
+ pub fn lerp(&self, other: &Transform, t: f32) -> Transform {
+ Transform {
+ translation: self.translation.lerp(other.translation, t),
+ rotation: self.rotation.lerp(other.rotation, t),
+ scale: self.scale.lerp(other.scale, t),
+ }
+ }
+}
diff --git a/src/manimgx/constants.py b/src/manimgx/constants.py
new file mode 100644
index 00000000..690bb43e
--- /dev/null
+++ b/src/manimgx/constants.py
@@ -0,0 +1,267 @@
+"""Directions, buffers, math constants and style enums (values identical to Manim CE 0.21)."""
+
+from enum import Enum
+from typing import Literal
+
+import numpy as np
+
+from manimgx.typing import Vector3D
+
+__all__ = [
+ "BOLD",
+ "BOOK",
+ "DEFAULT_ARROW_TIP_LENGTH",
+ "DEFAULT_DASH_LENGTH",
+ "DEFAULT_DOT_RADIUS",
+ "DEFAULT_FONT_SIZE",
+ "DEFAULT_MOBJECT_TO_EDGE_BUFFER",
+ "DEFAULT_MOBJECT_TO_MOBJECT_BUFFER",
+ "DEFAULT_POINTWISE_FUNCTION_RUN_TIME",
+ "DEFAULT_POINT_DENSITY_1D",
+ "DEFAULT_POINT_DENSITY_2D",
+ "DEFAULT_SMALL_DOT_RADIUS",
+ "DEFAULT_STROKE_WIDTH",
+ "DEFAULT_WAIT_TIME",
+ "DEGREES",
+ "DL",
+ "DOWN",
+ "DR",
+ "HEAVY",
+ "IN",
+ "ITALIC",
+ "LARGE_BUFF",
+ "LEFT",
+ "LIGHT",
+ "MEDIUM",
+ "MED_LARGE_BUFF",
+ "MED_SMALL_BUFF",
+ "NORMAL",
+ "OBLIQUE",
+ "ORIGIN",
+ "OUT",
+ "PI",
+ "RESAMPLING_ALGORITHMS",
+ "RIGHT",
+ "SCALE_FACTOR_PER_FONT_POINT",
+ "SEMIBOLD",
+ "SEMILIGHT",
+ "SMALL_BUFF",
+ "START_X",
+ "START_Y",
+ "TAU",
+ "THIN",
+ "UL",
+ "ULTRABOLD",
+ "ULTRAHEAVY",
+ "ULTRALIGHT",
+ "UP",
+ "UR",
+ "X_AXIS",
+ "Y_AXIS",
+ "Z_AXIS",
+ "CapStyleType",
+ "LineJointType",
+]
+
+ORIGIN: Vector3D = np.array((0.0, 0.0, 0.0))
+"""The center of the scene: (0, 0, 0)."""
+UP: Vector3D = np.array((0.0, 1.0, 0.0))
+"""One unit up: (0, 1, 0)."""
+DOWN: Vector3D = np.array((0.0, -1.0, 0.0))
+"""One unit down: (0, −1, 0)."""
+RIGHT: Vector3D = np.array((1.0, 0.0, 0.0))
+"""One unit right: (1, 0, 0)."""
+LEFT: Vector3D = np.array((-1.0, 0.0, 0.0))
+"""One unit left: (−1, 0, 0)."""
+IN: Vector3D = np.array((0.0, 0.0, -1.0))
+"""One unit into the screen, away from the viewer: (0, 0, −1)."""
+OUT: Vector3D = np.array((0.0, 0.0, 1.0))
+"""One unit out of the screen, toward the viewer: (0, 0, 1)."""
+X_AXIS: Vector3D = np.array((1.0, 0.0, 0.0))
+"""The direction of the x axis: (1, 0, 0)."""
+Y_AXIS: Vector3D = np.array((0.0, 1.0, 0.0))
+"""The direction of the y axis: (0, 1, 0)."""
+Z_AXIS: Vector3D = np.array((0.0, 0.0, 1.0))
+"""The direction of the z axis, out of the screen: (0, 0, 1)."""
+UL: Vector3D = UP + LEFT
+"""Up and left, toward the upper left corner: (−1, 1, 0)."""
+UR: Vector3D = UP + RIGHT
+"""Up and right, toward the upper right corner: (1, 1, 0)."""
+DL: Vector3D = DOWN + LEFT
+"""Down and left, toward the lower left corner: (−1, −1, 0)."""
+DR: Vector3D = DOWN + RIGHT
+"""Down and right, toward the lower right corner: (1, −1, 0)."""
+
+PI = np.pi
+"""π: half a turn, in radians."""
+TAU = 2 * PI
+"""τ = 2π: a whole turn, in radians."""
+DEGREES = TAU / 360
+"""One degree, in radians: `30 * DEGREES` is a twelfth of a turn."""
+
+SMALL_BUFF = 0.1
+"""A small gap, in scene units: 0.1."""
+MED_SMALL_BUFF = 0.25
+"""A medium-small gap, in scene units: 0.25, the default between mobjects
+placed next to each other."""
+MED_LARGE_BUFF = 0.5
+"""A medium-large gap, in scene units: 0.5, the default between a mobject and the
+frame's edge."""
+LARGE_BUFF = 1
+"""A large gap, in scene units: 1."""
+DEFAULT_MOBJECT_TO_EDGE_BUFFER = MED_LARGE_BUFF
+"""The gap a mobject keeps from the frame's edge by default, in scene units: 0.5
+(`to_edge`, `to_corner`)."""
+DEFAULT_MOBJECT_TO_MOBJECT_BUFFER = MED_SMALL_BUFF
+"""The gap between mobjects placed next to each other by default, in scene units:
+0.25 (`next_to`, `arrange`)."""
+DEFAULT_DOT_RADIUS = 0.08
+"""A dot's radius by default, in scene units."""
+DEFAULT_SMALL_DOT_RADIUS = 0.04
+"""A small dot's radius, in scene units: half the default."""
+DEFAULT_DASH_LENGTH = 0.05
+"""A dashed line's dash length by default, in scene units."""
+DEFAULT_ARROW_TIP_LENGTH = 0.35
+"""An arrow tip's length by default, in scene units."""
+DEFAULT_STROKE_WIDTH = 4
+"""A stroke's width by default, in hundredths of a scene unit."""
+DEFAULT_FONT_SIZE = 48
+"""Text's font size by default."""
+DEFAULT_WAIT_TIME = 1.0
+"""How long a wait lasts by default, in seconds."""
+DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0
+"""How long [ApplyPointwiseFunction][manimgx.ApplyPointwiseFunction], which moves every
+point through a function, and the animations built on it run by default, in seconds."""
+SCALE_FACTOR_PER_FONT_POINT = 1 / 960
+"""The scale of typeset text per unit of font size: Typst and LaTeX, typeset in 10-point
+type, are scaled so a point is `font_size` / 960 scene units and an em `font_size` / 96
+(0.5 at the default, 48). A [Text][manimgx.Text] is sized by its capitals instead."""
+
+
+class LineJointType(Enum):
+ """How a stroke is joined where its path turns (`joint_type`): round, beveled or
+ mitered.
+
+ The default, `AUTO`, is mitered. A two-dimensional scene draws the joints, of a
+ stroke and of its background stroke alike; a three-dimensional scene miters every
+ stroke.
+
+ Examples:
+ ```python
+ import manimgx as m
+
+
+ class LineJointTypeExample(m.Scene):
+ def construct(self) -> None:
+ corners = [[-1, -1.5, 0], [0, 1.5, 0], [1, -1.5, 0]]
+ paths = m.VGroup()
+ for joint in m.LineJointType:
+ path = m.VMobject(color=m.YELLOW, stroke_width=40, joint_type=joint)
+ path.set_points_as_corners(corners)
+ label = m.Text(joint.name, font_size=36).next_to(path, m.DOWN, 0.6)
+ paths.add(m.VGroup(path, label))
+ self.add(paths.arrange(buff=1))
+ ```
+ """
+
+ AUTO = 0
+ """The default: mitered, as `MITER`."""
+ ROUND = 1
+ """Round corners."""
+ BEVEL = 2
+ """Corners cut straight across."""
+ MITER = 3
+ """Pointed corners, where the stroke's edges meet; cut straight across where the
+ point would be more than ten stroke widths long."""
+
+
+class CapStyleType(Enum):
+ """How a stroke ends (`cap_style`): round, butt or square.
+
+ Every end a stroke shows is capped: the ends of an open path, the moving end of a
+ reveal ([Create][manimgx.Create], [Write][manimgx.Write], …) and both ends of every
+ dash. A closed path shown whole has no ends, and a stroke of no length (a path that
+ stays at one point) shows as a dot with round caps, a square with square ones. The
+ default, `AUTO`, is butt. A two-dimensional scene draws the caps, of a stroke and of
+ its background stroke alike; a three-dimensional scene ends every stroke flat.
+
+ Examples:
+ ```python
+ import manimgx as m
+
+
+ class CapStyleTypeExample(m.Scene):
+ def construct(self) -> None:
+ arcs = m.VGroup()
+ for cap in m.CapStyleType:
+ arc = m.Arc(radius=2, color=m.GREEN, stroke_width=40)
+ arc.set_cap_style(cap)
+ label = m.Text(cap.name, font_size=36).next_to(arc, m.DOWN, 0.6)
+ arcs.add(m.VGroup(arc, label))
+ self.add(arcs.arrange(buff=1))
+ ```
+ """
+
+ AUTO = 0
+ """The default: flat at the end, as `BUTT`."""
+ ROUND = 1
+ """A half disk past the end."""
+ BUTT = 2
+ """Flat, at the end."""
+ SQUARE = 3
+ """Flat, half the stroke's width past the end."""
+
+
+NORMAL = "NORMAL"
+"""Text's normal slant, upright, and its normal weight (400)."""
+ITALIC = "ITALIC"
+"""An italic slant of text."""
+OBLIQUE = "OBLIQUE"
+"""An oblique slant of text: its upright letters, slanted."""
+BOLD = "BOLD"
+"""A weight of text: bold (700)."""
+THIN = "THIN"
+"""A weight of text: thin (100)."""
+ULTRALIGHT = "ULTRALIGHT"
+"""A weight of text: ultralight (200)."""
+LIGHT = "LIGHT"
+"""A weight of text: light (300)."""
+SEMILIGHT = "SEMILIGHT"
+"""A weight of text: semilight (350)."""
+BOOK = "BOOK"
+"""A weight of text: book (380)."""
+MEDIUM = "MEDIUM"
+"""A weight of text: medium (500)."""
+SEMIBOLD = "SEMIBOLD"
+"""A weight of text: semibold (600)."""
+ULTRABOLD = "ULTRABOLD"
+"""A weight of text: ultrabold (800)."""
+HEAVY = "HEAVY"
+"""A weight of text: heavy (900)."""
+ULTRAHEAVY = "ULTRAHEAVY"
+"""A weight of text: ultraheavy (950)."""
+DEFAULT_POINT_DENSITY_1D = 10
+"""How many points a point cloud's line gets per scene unit by default."""
+DEFAULT_POINT_DENSITY_2D = 25
+"""Kept for Manim compatibility; unused."""
+START_X = 30
+"""Kept for Manim compatibility; unused."""
+START_Y = 20
+"""Kept for Manim compatibility; unused."""
+
+type Resampling = Literal[0, 2, 3]
+"""How an image is reconstructed from its pixels where it is drawn larger than they are,
+numbered as the Pillow library numbers its filters: 0, nearest (each pixel a square of
+its color); 2, linear; 3, cubic (Keys' cubic convolution with a = −1/2, Pillow's
+BICUBIC: smooth, and through every pixel)."""
+RESAMPLING_ALGORITHMS: dict[str, Resampling] = {
+ "nearest": 0,
+ "none": 0,
+ "bilinear": 2,
+ "linear": 2,
+ "bicubic": 3,
+ "cubic": 3,
+}
+"""The filters an image can be reconstructed with, by name, each with its number (see
+[Resampling][manimgx.constants.Resampling]): "nearest" or "none", "bilinear" or
+"linear", "bicubic" or "cubic"."""
diff --git a/src/manimgx/typing.py b/src/manimgx/typing.py
new file mode 100644
index 00000000..ced72b80
--- /dev/null
+++ b/src/manimgx/typing.py
@@ -0,0 +1,46 @@
+"""Array aliases, by rank: a point is 1-D, an array of points 2-D (numpy types the rank, not the 3)."""
+
+from collections.abc import Callable, Sequence
+from os import PathLike
+from typing import TYPE_CHECKING
+
+import numpy as np
+import numpy.typing as npt
+
+if TYPE_CHECKING:
+ from manimgx.mobjects.text import Typst
+
+type Float = np.float64
+type Vec = np.ndarray[tuple[int], np.dtype[np.float64]] # 1-D
+type Rows = np.ndarray[tuple[int, int], np.dtype[np.float64]] # 2-D
+type Point3D = Vec
+type Point3D_Array = Rows
+type Vector3D = Vec
+# an input: any array of floats (as CE's docs pass a tracker's `points`), a tuple or a sequence
+type Point3DLike = npt.NDArray[np.floating] | tuple[float, float, float] | Sequence[
+ float
+]
+type Vector3DLike = Point3DLike
+type Point3DLike_Array = Point3D_Array | Sequence[Point3DLike]
+type RGBA_Array = Rows
+type MatrixMN = Rows
+type RateFunc = Callable[[float], float]
+type PathFunc = Callable[[Point3D_Array, Point3D_Array, float], Point3D_Array]
+type PointsFunc = Callable[[Point3D_Array], Point3D_Array]
+type Point2D = Vec
+type Point2DLike = Point2D | tuple[float, float] | Sequence[float]
+type Vector2D = Point2D
+type Vector2DLike = Point2DLike
+type Vector3D_Array = Point3D_Array
+type ManimFloat = np.float64
+type ManimTextLabel = Typst # every text class typesets through Typst
+type MappingFunction = Callable[[Point3D], Point3D] # a point to a point (CE)
+type StrPath = str | PathLike[str]
+type Point2D_Array = Point3D_Array
+type Point2DLike_Array = Point3DLike_Array
+type PointND = Point3D
+type PointND_Array = Point3D_Array
+type FloatRGB = Vec
+type FloatRGB_Array = Rows
+type FloatRGBA_Array = RGBA_Array
+type QuadraticSpline = Point3D_Array