Skip to content

Commit ce1fff6

Browse files
nitzanbuenopre-commit-ci[bot]chopan050
authored
Improve line rendering performance by decreasing redundant subdivision 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]>
1 parent fc58a46 commit ce1fff6

File tree

17 files changed

+18
-1
lines changed

17 files changed

+18
-1
lines changed

manim/mobject/three_d/three_dimensions.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,12 @@ class Line3D(Cylinder):
895895
The thickness of the line.
896896
color
897897
The color of the line.
898+
resolution
899+
The resolution of the line.
900+
By default this value is the number of points the line will sampled at.
901+
If you want the line to also come out checkered, use a tuple.
902+
For example, for a line made of 24 points with 4 checker points on each
903+
cylinder, pass the tuple (4, 24).
898904
899905
Examples
900906
--------
@@ -915,9 +921,11 @@ def __init__(
915921
end: np.ndarray = RIGHT,
916922
thickness: float = 0.02,
917923
color: ParsableManimColor | None = None,
924+
resolution: int | Sequence[int] = 24,
918925
**kwargs,
919926
):
920927
self.thickness = thickness
928+
self.resolution = (2, resolution) if isinstance(resolution, int) else resolution
921929
self.set_start_and_end_attrs(start, end, **kwargs)
922930
if color is not None:
923931
self.set_color(color)
@@ -951,6 +959,7 @@ def set_start_and_end_attrs(
951959
height=np.linalg.norm(self.vect),
952960
radius=self.thickness,
953961
direction=self.direction,
962+
resolution=self.resolution,
954963
**kwargs,
955964
)
956965
self.shift((self.start + self.end) / 2)
@@ -1122,6 +1131,8 @@ class Arrow3D(Line3D):
11221131
The base radius of the conical tip.
11231132
color
11241133
The color of the arrow.
1134+
resolution
1135+
The resolution of the arrow line.
11251136
11261137
Examples
11271138
--------
@@ -1148,10 +1159,16 @@ def __init__(
11481159
height: float = 0.3,
11491160
base_radius: float = 0.08,
11501161
color: ParsableManimColor = WHITE,
1162+
resolution: int | Sequence[int] = 24,
11511163
**kwargs,
11521164
) -> None:
11531165
super().__init__(
1154-
start=start, end=end, thickness=thickness, color=color, **kwargs
1166+
start=start,
1167+
end=end,
1168+
thickness=thickness,
1169+
color=color,
1170+
resolution=resolution,
1171+
**kwargs,
11551172
)
11561173

11571174
self.length = np.linalg.norm(self.vect)
Binary file not shown.
Binary file not shown.
-244 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)