-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix wrong value of MObject width/height with empty VGroup #4088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -136,21 +136,19 @@ def test_mobject_dimensions_nested_mobjects(): | |||
|
|||
|
|||
def test_mobject_dimensions_mobjects_with_no_points_are_at_origin(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the previous test was testing an unexpected behavior, it should have been linked to an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
Now, given that the unexpected behavior is fixed and empty Mobjects are no longer considered as "at the origin", it would be nice to change the name of this test in order to reflect that:
def test_mobject_dimensions_mobjects_with_no_points_are_at_origin(): | |
def test_mobject_dimensions_mobjects_with_no_points(): |
@@ -2149,10 +2153,11 @@ def get_nadir(self) -> Point3D: | |||
|
|||
def length_over_dim(self, dim: int) -> float: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this function is meant to be used only internally, it should be private
def length_over_dim(self, dim: int) -> float: | |
def __length_over_dim(self, dim: int) -> float: |
or at least protected
def length_over_dim(self, dim: int) -> float: | |
def _length_over_dim(self, dim: int) -> float: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense. In that case, .reduce_across_dimension()
is an even stronger case of a method which should be marked as internal.
Now, I would probably not mark them as internal in this PR, because there's already a PR which proposes marking some methods as "internal". It's worth checking it and proposing to include these methods in that list:
#3793
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this fix! I left some suggestions:
def reduce_across_dimension(self, reduce_func: Callable, dim: int) -> float | None: | ||
"""Find the min or max value from a dimension across all points in this and submobjects.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this method can now also return None
, it would be nice to document this new behavior in the docstring. Something along the lines of:
def reduce_across_dimension(self, reduce_func: Callable, dim: int) -> float | None: | |
"""Find the min or max value from a dimension across all points in this and submobjects.""" | |
def reduce_across_dimension(self, reduce_func: Callable, dim: int) -> float | None: | |
"""Find the min or max value from a dimension across all points in this Mobject and its | |
submobjects. This allows for using :meth:`~.length_over_dim` to calculate its length over | |
a dimension, i.e. its height, width or depth. If this Mobject is empty, return ``None``, | |
since this Mobject should not be taken into account when calculating lengths. | |
Parameters | |
---------- | |
reduce_func | |
The reducer function to use in order to calculate a value over a dimension. | |
dim | |
The dimension to use. It should be 0, 1 or 2, representing the X, Y or Z coordinate, | |
respectively. | |
Returns | |
------- | |
float | None | |
The min or max value over the dimension specified by ``dim``, or ``None`` if this | |
Mobject is empty. | |
""" |
@@ -2149,10 +2153,11 @@ def get_nadir(self) -> Point3D: | |||
|
|||
def length_over_dim(self, dim: int) -> float: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense. In that case, .reduce_across_dimension()
is an even stronger case of a method which should be marked as internal.
Now, I would probably not mark them as internal in this PR, because there's already a PR which proposes marking some methods as "internal". It's worth checking it and proposing to include these methods in that list:
#3793
@@ -136,21 +136,19 @@ def test_mobject_dimensions_nested_mobjects(): | |||
|
|||
|
|||
def test_mobject_dimensions_mobjects_with_no_points_are_at_origin(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
Now, given that the unexpected behavior is fixed and empty Mobjects are no longer considered as "at the origin", it would be nice to change the name of this test in order to reflect that:
def test_mobject_dimensions_mobjects_with_no_points_are_at_origin(): | |
def test_mobject_dimensions_mobjects_with_no_points(): |
Overview: What does this pull request change?
Fixes #4087
When a Mobject contains an empty VGroup, its width or height can be wrong
Motivation and Explanation: Why and how do your changes improve the library?
Bug fix + tests
Links to added or changed documentation pages
No documentation page, bug fix only.
Further Information and Comments
Reviewer Checklist