3b1b/manim

Rectangle of 0 width or 0 height cannot change width or height after created

ljw20180420 opened this issue · 1 comments

If I create a rectangle of 0 width, then I cannot change its width after that.

from manim import *
rec1 = Rectangle(height=1, width=0)
print(f"{rec1.height} {rec1.width}")
rec1.height = 2
rec1.width = 1
print(f"{rec1.height} {rec1.width}")
3b1b commented

The lines rec1.height = 2 won't have any effect on the shape, what you'd want to call is rec1.set_height(2, stretch=True), or rec.set_shape(1, 2)`

But even then, you're correct that it won't recover from a width of zero. This is because setting the width or height happens at the level of Mobject, not Rectangle, so if the points have collapsed to a line like this, it has no way to know what shape they're supposed to be upon expanding. If this came up, and you wanted to recover back to the shape of a rectangle, you could call something like rect.match_points(Rectangle(1, 2)).

There's a much deeper change that's on my wish list to get to one day where the points data remains more static, and position/shape/rotation are tracked just with the matrix associated with the Mobject. In the meantime, I'll close this particular issue.