Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix AUTO cap style and joint type inheriting the previous mobject's style in Cairo renderer (#5016)

Rızgar Ozand5f7d534f597
diff --git a/manim/camera/camera.py b/manim/camera/camera.py
index 1d54e5cf9..b3371faf3 100644
--- a/manim/camera/camera.py
+++ b/manim/camera/camera.py
@@ -43,7 +43,7 @@ if TYPE_CHECKING:
LINE_JOIN_MAP = {
- LineJointType.AUTO: None, # TODO: this could be improved
+ LineJointType.AUTO: cairo.LineJoin.MITER, # cairo default; TODO: this could be improved
LineJointType.ROUND: cairo.LineJoin.ROUND,
LineJointType.BEVEL: cairo.LineJoin.BEVEL,
LineJointType.MITER: cairo.LineJoin.MITER,
@@ -51,7 +51,7 @@ LINE_JOIN_MAP = {
CAP_STYLE_MAP = {
- CapStyleType.AUTO: None, # TODO: this could be improved
+ CapStyleType.AUTO: cairo.LineCap.BUTT, # cairo default; TODO: this could be improved
CapStyleType.ROUND: cairo.LineCap.ROUND,
CapStyleType.BUTT: cairo.LineCap.BUTT,
CapStyleType.SQUARE: cairo.LineCap.SQUARE,
@@ -852,10 +852,8 @@ class Camera:
* (self.frame_width / self.frame_width),
# This ensures lines have constant width as you zoom in on them.
)
- if vmobject.joint_type != LineJointType.AUTO:
- ctx.set_line_join(LINE_JOIN_MAP[vmobject.joint_type])
- if vmobject.cap_style != CapStyleType.AUTO:
- ctx.set_line_cap(CAP_STYLE_MAP[vmobject.cap_style])
+ ctx.set_line_join(LINE_JOIN_MAP[vmobject.joint_type])
+ ctx.set_line_cap(CAP_STYLE_MAP[vmobject.cap_style])
ctx.stroke_preserve()
return self
diff --git a/tests/test_camera.py b/tests/test_camera.py
index 44c54e7e4..2d80eafef 100644
--- a/tests/test_camera.py
+++ b/tests/test_camera.py
@@ -1,6 +1,20 @@
from __future__ import annotations
-from manim import MovingCamera, Square
+import numpy as np
+import pytest
+
+from manim import (
+ LEFT,
+ ORIGIN,
+ RIGHT,
+ UP,
+ Camera,
+ CapStyleType,
+ LineJointType,
+ MovingCamera,
+ Square,
+ VMobject,
+)
def test_movingcamera_auto_zoom():
@@ -9,3 +23,31 @@ def test_movingcamera_auto_zoom():
margin = 0.5
camera.auto_zoom([square], margin=margin, animate=False)
assert camera.frame.height == square.height + margin
+
+
+def _angled_line(**kwargs):
+ return VMobject(stroke_width=20, **kwargs).set_points_as_corners(
+ [LEFT, ORIGIN, LEFT + UP]
+ )
+
+
+ "styled_kwargs",
+ [
+ {"cap_style": CapStyleType.ROUND},
+ {"cap_style": CapStyleType.SQUARE},
+ {"joint_type": LineJointType.ROUND},
+ {"joint_type": LineJointType.BEVEL},
+ ],
+)
+def test_auto_stroke_style_does_not_inherit_previous_style(styled_kwargs):
+ # The two mobjects do not overlap, so the drawing order must not matter.
+ styled = _angled_line(**styled_kwargs).shift(3 * LEFT)
+ default = _angled_line().shift(3 * RIGHT)
+
+ styled_first = Camera()
+ styled_first.capture_mobjects([styled, default])
+ default_first = Camera()
+ default_first.capture_mobjects([default, styled])
+
+ np.testing.assert_array_equal(styled_first.pixel_array, default_first.pixel_array)