-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Allow :class:.SurroundingRectangle
to accept multiple Mobjects
#3964
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
Allow :class:.SurroundingRectangle
to accept multiple Mobjects
#3964
Conversation
Hello, and first off, thanks for the PR! My concern with adding another constructor (albeit as a classmethod) is that it introduces two ways of doing the same thing and could confuse users. SurroundingRectangle(Square())
SurroundingRectangle.multiple([Square()]) As such, I'd be interested to hear more about the benefits of a separate constructor. Otherwise, I'd suggest just making def __init__(self, *mobjects: Mobject, ...) -> None:
mobject = Group(*mobjects)
... |
Thank you for the quick reply!
This was my first thought with this implementation, however, it would not be backward compatible for cases such as Here are two other solutions I see to this issue. Both eliminate the need for a separate constructor, but have their drawbacks. Would you consider either one acceptable? If not, perhaps sticking to delegating VGroup creation to user is the best way, then #3863 should be closed. P.S.: Thank you for your time and input on this. This is my first OSs PR, and I really appreciate your feedback. Solution 1
The idea is to toggle between single/multiple object mode based on the default value of None for either argument. This solution may be less intuitive because technically both Solution 2Perhaps typing the original mobject argument as either a single object or a Collection would be more suitable:
This solution is slightly more hacky because it relies on object typing, however, it is way more straightforward to use. As a bonus, it does not require named keywords for multiple objects, and the following syntaxis would work for solution 2 but not solution 1: |
for more information, see https://pre-commit.ci
Personally, I think it's probably better to break backwards compatibility in exchange for this (arguably) more intuitive syntax. This is especially true because we're not at 1.0.0 yet, so it's better to work towards a nicer API :)
We could always add a line like P.S. Welcome to OSS! |
for more information, see https://pre-commit.ci
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.
Almost there! I left a few (admittedly pretty nitpicky) comments. Other than that, I think it's good to go! Thanks!
Co-authored-by: Aarush Deshpande <[email protected]>
Co-authored-by: Aarush Deshpande <[email protected]>
…863-SurroundingRectangle-mobjects
…om/Boris-Filin/manim into 3863-SurroundingRectangle-mobjects
for more information, see https://pre-commit.ci
…om/Boris-Filin/manim into 3863-SurroundingRectangle-mobjects
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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.
Sorry for the late reply, but it looks good to me now! Thanks for implementing this :)
.SurroundingRectangle
to accept multiple Mobjects
Overview: What does this pull request change?
Adds a secondary constructor to SurroundingRectangle and BackgroundRectangle, which takes a list of objects rather than a single one, outlining them all at once.
The constructor is implemented via classmethod decorator:
box = SurroundingRectangle.multiple([...], ...)
Motivation and Explanation: Why and how do your changes improve the library?
This PR resolves issue #3863. The changes are mostly cosmetic, improving the readability of the code by removing the necessity to create an additional VGroup.
Further Information and Comments
In principle, this change only moves the construction of VGroup from the user end to the class constructor. As such, it is a minor addition and might not be necessary for the project.
This is a university-driven PR
Just for context, this PR (same as some other recent ones on this repo) is motivated by a university assignment that requires us to contribute to an Open-Source project. PR merge is not required, however. I figured this information might affect your judgment.
Reviewer Checklist