Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ManimCommunity/manim into p…
Browse files Browse the repository at this point in the history
…oint3d-like
  • Loading branch information
chopan050 committed Dec 6, 2024
2 parents 2d0917a + d485986 commit 9f684db
Show file tree
Hide file tree
Showing 14 changed files with 1,771 additions and 1,485 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-13, windows-latest]
python: ["3.9", "3.10", "3.11", "3.12"]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install Poetry
run: |
pipx install "poetry==1.7.*"
pipx install "poetry==1.8.*"
poetry config virtualenvs.prefer-active-python true
- name: Setup Python ${{ matrix.python }}
Expand Down Expand Up @@ -142,10 +142,7 @@ jobs:
Expand-Archive -LiteralPath "$($env:TMP)\TinyTex.zip" -DestinationPath "$($PWD)\ManimCache\LatexWindows"
$env:Path = "$($PWD)\ManimCache\LatexWindows\TinyTeX\bin\windows;$($env:PATH)"
tlmgr update --self
foreach ($c in $tinyTexPackages){
$c=$c.Trim()
tlmgr install $c
}
tlmgr install $tinyTexPackages
$env:PATH=$OriPath
echo "Completed Latex"
Expand All @@ -156,10 +153,9 @@ jobs:
$env:Path = "$env:USERPROFILE\.poetry\bin;$($env:PATH)"
echo "$env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install manim
- name: Install dependencies and manim
run: |
poetry config installer.modern-installation false
poetry install
poetry install --all-extras
- name: Run tests
run: |
Expand Down
43 changes: 0 additions & 43 deletions conftest.py

This file was deleted.

31 changes: 17 additions & 14 deletions manim/animation/updaters/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def construct(self):


def turn_animation_into_updater(
animation: Animation, cycle: bool = False, **kwargs
animation: Animation, cycle: bool = False, delay: float = 0, **kwargs
) -> Mobject:
"""
Add an updater to the animation's mobject which applies
Expand All @@ -187,6 +187,8 @@ def turn_animation_into_updater(
If cycle is True, this repeats over and over. Otherwise,
the updater will be popped upon completion
The ``delay`` parameter is the delay (in seconds) before the animation starts..
Examples
--------
Expand All @@ -206,21 +208,22 @@ def construct(self):
mobject = animation.mobject
animation.suspend_mobject_updating = False
animation.begin()
animation.total_time = 0
animation.total_time = -delay

def update(m: Mobject, dt: float):
run_time = animation.get_run_time()
time_ratio = animation.total_time / run_time
if cycle:
alpha = time_ratio % 1
else:
alpha = np.clip(time_ratio, 0, 1)
if alpha >= 1:
animation.finish()
m.remove_updater(update)
return
animation.interpolate(alpha)
animation.update_mobjects(dt)
if animation.total_time >= 0:
run_time = animation.get_run_time()
time_ratio = animation.total_time / run_time
if cycle:
alpha = time_ratio % 1
else:
alpha = np.clip(time_ratio, 0, 1)
if alpha >= 1:
animation.finish()
m.remove_updater(update)
return
animation.interpolate(alpha)
animation.update_mobjects(dt)
animation.total_time += dt

mobject.add_updater(update)
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/geometry/tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def tip_angle(self) -> float:
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]), buff=0)
>>> round(arrow.tip.tip_angle, 5) == round(PI/4, 5)
>>> bool(round(arrow.tip.tip_angle, 5) == round(PI/4, 5))
True
"""
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/graphing/number_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ def point_to_number(self, point: Sequence[float]) -> float:
>>> from manim import NumberLine
>>> number_line = NumberLine()
>>> number_line.point_to_number((0, 0, 0))
0.0
np.float64(0.0)
>>> number_line.point_to_number((1, 0, 0))
1.0
np.float64(1.0)
>>> number_line.point_to_number([[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]])
array([0.5, 1. , 1.5])
Expand Down
30 changes: 15 additions & 15 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,13 +1605,13 @@ def scale_to_fit_width(self, width: float, **kwargs) -> Self:
>>> from manim import *
>>> sq = Square()
>>> sq.height
2.0
np.float64(2.0)
>>> sq.scale_to_fit_width(5)
Square
>>> sq.width
5.0
np.float64(5.0)
>>> sq.height
5.0
np.float64(5.0)
"""
return self.rescale_to_fit(width, 0, stretch=False, **kwargs)

Expand All @@ -1630,13 +1630,13 @@ def stretch_to_fit_width(self, width: float, **kwargs) -> Self:
>>> from manim import *
>>> sq = Square()
>>> sq.height
2.0
np.float64(2.0)
>>> sq.stretch_to_fit_width(5)
Square
>>> sq.width
5.0
np.float64(5.0)
>>> sq.height
2.0
np.float64(2.0)
"""
return self.rescale_to_fit(width, 0, stretch=True, **kwargs)

Expand All @@ -1655,13 +1655,13 @@ def scale_to_fit_height(self, height: float, **kwargs) -> Self:
>>> from manim import *
>>> sq = Square()
>>> sq.width
2.0
np.float64(2.0)
>>> sq.scale_to_fit_height(5)
Square
>>> sq.height
5.0
np.float64(5.0)
>>> sq.width
5.0
np.float64(5.0)
"""
return self.rescale_to_fit(height, 1, stretch=False, **kwargs)

Expand All @@ -1680,13 +1680,13 @@ def stretch_to_fit_height(self, height: float, **kwargs) -> Self:
>>> from manim import *
>>> sq = Square()
>>> sq.width
2.0
np.float64(2.0)
>>> sq.stretch_to_fit_height(5)
Square
>>> sq.height
5.0
np.float64(5.0)
>>> sq.width
2.0
np.float64(2.0)
"""
return self.rescale_to_fit(height, 1, stretch=True, **kwargs)

Expand Down Expand Up @@ -2872,7 +2872,7 @@ def construct(self):
>>> result = rect.copy().become(circ, stretch=True)
>>> result.height, result.width
(2.0, 4.0)
(np.float64(2.0), np.float64(4.0))
>>> ellipse_points = np.array(result.get_anchors())
>>> ellipse_eq = np.sum(ellipse_points**2 * [1/4, 1, 0], axis=1)
>>> np.allclose(ellipse_eq, 1)
Expand All @@ -2886,14 +2886,14 @@ def construct(self):
>>> result = rect.copy().become(circ, match_height=True)
>>> result.height, result.width
(2.0, 2.0)
(np.float64(2.0), np.float64(2.0))
>>> circle_points = np.array(result.get_anchors())
>>> circle_eq = np.sum(circle_points**2, axis=1)
>>> np.allclose(circle_eq, 1)
True
>>> result = rect.copy().become(circ, match_width=True)
>>> result.height, result.width
(4.0, 4.0)
(np.float64(4.0), np.float64(4.0))
>>> circle_points = np.array(result.get_anchors())
>>> circle_eq = np.sum(circle_points**2, axis=1)
>>> np.allclose(circle_eq, 2**2)
Expand Down
6 changes: 3 additions & 3 deletions manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ def inverse_interpolate(
.. code-block:: pycon
>>> inverse_interpolate(start=2, end=6, value=4)
0.5
np.float64(0.5)
>>> start = np.array([1, 2, 1])
>>> end = np.array([7, 8, 11])
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def match_interpolate(
Examples
--------
>>> match_interpolate(0, 100, 10, 20, 15)
50.0
np.float64(50.0)
"""
old_alpha = inverse_interpolate(old_start, old_end, old_value)
return interpolate(
Expand Down Expand Up @@ -1949,7 +1949,7 @@ def is_closed(points: Point3DLike_Array) -> bool:
return False
if abs(end[1] - start[1]) > tolerance[1]:
return False
return abs(end[2] - start[2]) <= tolerance[2]
return bool(abs(end[2] - start[2]) <= tolerance[2])


def proportions_along_bezier_curve_for_point(
Expand Down
33 changes: 21 additions & 12 deletions manim/utils/docbuild/module_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import ast
import sys
from pathlib import Path

from typing_extensions import TypeAlias
Expand Down Expand Up @@ -158,27 +159,35 @@ def parse_module_attributes() -> tuple[AliasDocsDict, DataDict, TypeVarDict]:
inner_nodes = [node]

for node in inner_nodes:
# If we encounter an assignment annotated as "TypeAlias":
if (
# Check if this node is a TypeAlias (type <name> = <value>)
# or an AnnAssign annotated as TypeAlias (<target>: TypeAlias = <value>).
is_type_alias = (
sys.version_info >= (3, 12) and type(node) is ast.TypeAlias
)
is_annotated_assignment_with_value = (
type(node) is ast.AnnAssign
and type(node.annotation) is ast.Name
and node.annotation.id == "TypeAlias"
and type(node.target) is ast.Name
and node.value is not None
):
alias_name = node.target.id
def_node = node.value
# If it's an Union, replace it with vertical bar notation
)
if is_type_alias or is_annotated_assignment_with_value:
alias_name = node.name.id if is_type_alias else node.target.id
definition_node = node.value

# If the definition is a Union, replace with vertical bar notation.
# Instead of "Union[Type1, Type2]", we'll have "Type1 | Type2".
if (
type(def_node) is ast.Subscript
and type(def_node.value) is ast.Name
and def_node.value.id == "Union"
type(definition_node) is ast.Subscript
and type(definition_node.value) is ast.Name
and definition_node.value.id == "Union"
):
union_elements = definition_node.slice.elts
definition = " | ".join(
ast.unparse(elem) for elem in def_node.slice.elts
ast.unparse(elem) for elem in union_elements
)
else:
definition = ast.unparse(def_node)
definition = ast.unparse(definition_node)

definition = definition.replace("npt.", "")
if category_dict is None:
Expand All @@ -188,7 +197,7 @@ def parse_module_attributes() -> tuple[AliasDocsDict, DataDict, TypeVarDict]:
alias_info = category_dict[alias_name]
continue

# Check if it is a typing.TypeVar
# Check if it is a typing.TypeVar (<target> = TypeVar(...)).
elif (
type(node) is ast.Assign
and type(node.targets[0]) is ast.Name
Expand Down
4 changes: 2 additions & 2 deletions manim/utils/simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def binary_search(
::
>>> solution = binary_search(lambda x: x**2 + 3*x + 1, 11, 0, 5)
>>> abs(solution - 2) < 1e-4
>>> bool(abs(solution - 2) < 1e-4)
True
>>> solution = binary_search(lambda x: x**2 + 3*x + 1, 11, 0, 5, tolerance=0.01)
>>> abs(solution - 2) < 0.01
>>> bool(abs(solution - 2) < 0.01)
True
Searching in the interval :math:`[0, 5]` for a target value of :math:`71`
Expand Down
6 changes: 3 additions & 3 deletions manim/utils/space_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ def get_winding_number(points: Sequence[np.ndarray]) -> float:
>>> from manim import Square, get_winding_number
>>> polygon = Square()
>>> get_winding_number(polygon.get_vertices())
1.0
np.float64(1.0)
>>> polygon.shift(2 * UP)
Square
>>> get_winding_number(polygon.get_vertices())
0.0
np.float64(0.0)
"""
total_angle = 0
for p1, p2 in adjacent_pairs(points):
Expand Down Expand Up @@ -682,7 +682,7 @@ def cross2d(
.. code-block:: pycon
>>> cross2d(np.array([1, 2]), np.array([3, 4]))
-2
np.int64(-2)
>>> cross2d(
... np.array([[1, 2, 0], [1, 0, 0]]),
... np.array([[3, 4, 0], [0, 1, 0]]),
Expand Down
Loading

0 comments on commit 9f684db

Please sign in to comment.