manim icon indicating copy to clipboard operation
manim copied to clipboard

Argument `scale_stroke` of `scale` method does not behaves as expected on a `VGroup`

Open ccalauzenes opened this issue 7 months ago • 0 comments

Description of bug / unexpected behavior

When using the method scale(k, scale_stroke=True)on a VGroup, the submobjects stroke_width are all set to the one of the VGroup (default 4) and then rescaled, even if they were having different stroke_width before.

Expected behavior

When applying the method scale(k, scale_stroke=True) to a VGroup, the submobjects should have their stroke_width rescale proportionally to their initial individual stroke_width. Especially, scale(1.0, scale_stroke=True) shouldn't change the submobjects (see code example)

How to reproduce the issue

See code example.

Code for reproducing the problem
from manim import *

class TestScene(Scene):
    def construct(self):
        
        dot = Dot(radius=1)
        line = Line(ORIGIN, 2*DOWN, stroke_width=200)

        self.play(FadeIn(dot, line))
        self.wait(1)
        self.play(line.animate.scale(1, scale_stroke=True).set_color(RED))
        self.wait(1)
        self.play(VGroup(dot, line).animate.scale(1, scale_stroke=True).set_color(BLUE))
        self.wait(1)

System specifications

System Details

Environment is the official Manim docker image used as a devcontainer on MacOS 15.4.1 (Sequoia)

Additional comments

When calling scale(k, scale_stroke=True) the method scale calls the method set_stroke with the value abs(scale_factor) * self.get_stroke_width() computed on the current MObject (the VGroup). https://github.com/ManimCommunity/manim/blob/f304bd93eab1ca450a86eff476c7f51bd81fe1fb/manim/mobject/types/vectorized_mobject.py#L524-L531

But because the current MObject is a VGroup, this value is then propagated to all submobjects: https://github.com/ManimCommunity/manim/blob/f304bd93eab1ca450a86eff476c7f51bd81fe1fb/manim/mobject/types/vectorized_mobject.py#L331-L333

ccalauzenes avatar Apr 27 '25 11:04 ccalauzenes