Skip to content

Commit

Permalink
Improve line rendering performance by decreasing redundant subdivisio…
Browse files Browse the repository at this point in the history
…n count (#3893)

* Reduce line cylinder height resolution to 2

Subdividing a line cylinder by its height adds no extra resolution -
since it's not checkerboarded, all new rectangles would look the same as
one long rectangle. Decreasing the default subdivision resolution to 2
reduces submobject count by 12x while sacrificing no quality.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Allow for 2 resolution values in Line3D

This prevents a breaking change where a tuple of resolution values
passed to Line3D.resolution would no longer work.
Also applies to Arrow3D.

* Assign field before init

* Add checkered line info to docstring

* Regenerate test control frame

* Regenerate missing control frames

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2024
1 parent fc58a46 commit ce1fff6
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion manim/mobject/three_d/three_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,12 @@ class Line3D(Cylinder):
The thickness of the line.
color
The color of the line.
resolution
The resolution of the line.
By default this value is the number of points the line will sampled at.
If you want the line to also come out checkered, use a tuple.
For example, for a line made of 24 points with 4 checker points on each
cylinder, pass the tuple (4, 24).
Examples
--------
Expand All @@ -915,9 +921,11 @@ def __init__(
end: np.ndarray = RIGHT,
thickness: float = 0.02,
color: ParsableManimColor | None = None,
resolution: int | Sequence[int] = 24,
**kwargs,
):
self.thickness = thickness
self.resolution = (2, resolution) if isinstance(resolution, int) else resolution
self.set_start_and_end_attrs(start, end, **kwargs)
if color is not None:
self.set_color(color)
Expand Down Expand Up @@ -951,6 +959,7 @@ def set_start_and_end_attrs(
height=np.linalg.norm(self.vect),
radius=self.thickness,
direction=self.direction,
resolution=self.resolution,
**kwargs,
)
self.shift((self.start + self.end) / 2)
Expand Down Expand Up @@ -1122,6 +1131,8 @@ class Arrow3D(Line3D):
The base radius of the conical tip.
color
The color of the arrow.
resolution
The resolution of the arrow line.
Examples
--------
Expand All @@ -1148,10 +1159,16 @@ def __init__(
height: float = 0.3,
base_radius: float = 0.08,
color: ParsableManimColor = WHITE,
resolution: int | Sequence[int] = 24,
**kwargs,
) -> None:
super().__init__(
start=start, end=end, thickness=thickness, color=color, **kwargs
start=start,
end=end,
thickness=thickness,
color=color,
resolution=resolution,
**kwargs,
)

self.length = np.linalg.norm(self.vect)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Arrow3D.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Axes.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/CameraMove.npz
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Cone.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Cube.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Cylinder.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Dot3D.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Line3D.npz
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Sphere.npz
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Torus.npz
Binary file not shown.
Binary file modified tests/test_graphical_units/control_data/threed/Y_Direction.npz
Binary file not shown.

0 comments on commit ce1fff6

Please sign in to comment.