Skip to content

Two New Classes in geometry module: :class:.LabeledLine and :class:.LabeledArrow #3264

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

Merged

Conversation

andresberejnoi
Copy link
Contributor

@andresberejnoi andresberejnoi commented Jun 12, 2023

Overview: What does this pull request change?

This PR adds two new classes: LabeledLine and LabeledArrow. LabeledLine inherits from Line and creates a line with a label and text box somewhere along its length. The position of the label, as well as the color and size can be controlled through parameters.
LabeledArrow inherits from LabeledLine and Arrow and allows to create arrows with a label somewhere along its length.
I also added some basic tests under tests/test_graphical_units/test_geometry.py.

I think these two classes belong in line.py, however, since they make use of SurroundingRectangle and BackgroundRectangle, there is a circular import problem. SurroundingRectangle and BackgroundRectangle are in shape_matchers.py which imports Line from line.py. For this reason, I decided to create a new file containing my new classes: labeled.py.

Motivation and Explanation: Why and how do your changes improve the library?

I added these classes because I needed to create neural network animations that show weights between neurons. None of the tools already available were suitable for this task if I wanted to easily automate them. I think that lines or arrows with labels are very useful for diagrams and figures, so it would be nice to have them as part of the default package.

Here is a short video of what I am using these classes for:

NetworkWithRandomWeights.mp4

The label box can be moved anywhere along the length of the arrow or line, and in this case, I left it near the beginning.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@andresberejnoi andresberejnoi changed the title Two New Classes in geometry/line.py: LabeledLine and LabeledArrow Two New Classes in geometry module: LabeledLine and LabeledArrow Jun 28, 2023
Copy link
Member

@jsonvillanueva jsonvillanueva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the contribution! Overall, this is a solid PR as is, but I've made a few notes on type hints that should be included. The documentation built looks great and the test cases are nice to see of course.

andresberejnoi and others added 8 commits July 27, 2023 14:56
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
will change name of labeled_shapes.py to labeled.py
Changed name of file from labeled_shapes.py to labeled.py and updated __init__.py to import from the correct location.
Copy link
Member

@jsonvillanueva jsonvillanueva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending these suggested changes, lgtm!

Removed color import line because of redundancy.

Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
andresberejnoi and others added 2 commits July 27, 2023 16:00
default label_color parameter is now set to `None` instead of `WHITE`.
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
@jsonvillanueva jsonvillanueva changed the title Two New Classes in geometry module: LabeledLine and LabeledArrow Two New Classes in geometry module: :class:.LabeledLine and :class:.LabeledArrow Jul 27, 2023
jsonvillanueva and others added 2 commits July 27, 2023 13:51
SurroundingRectangle uses label_color as well and using a default of None removes the rectangle.
@jsonvillanueva jsonvillanueva added the enhancement Additions and improvements in general label Jul 27, 2023
@jsonvillanueva jsonvillanueva merged commit 8ba210f into ManimCommunity:main Jul 31, 2023
@jsonvillanueva
Copy link
Member

Also, thanks again @andresberejnoi for the contribution! If you're on the Manim Discord server and interested in having the Contributor role, message out to ModMail and link this PR :)

@andresberejnoi
Copy link
Contributor Author

Thank you, and I'm glad the contribution is useful. I will make sure to check out the Discord server again.

@behackl behackl added this to the v0.18.0 milestone Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions and improvements in general
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants