-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Changed color
, stroke_color
and fill_color
attributes to properties
#2332
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
Changed color
, stroke_color
and fill_color
attributes to properties
#2332
Conversation
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'm slightly hesitant to merge this – on the one hand, this is a nice quality of life improvement for Mobject
, but at the same time it lets VMobject
diverge more from OpenGLVMobject
. Maybe the same attributes could be turned into properties for OpenGLVMobject
as well?
9ddaf5f
to
eaf7f69
Compare
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.
This looks good now, thank you! It would be good to have someone else look over your changes as well; maybe @hydrobeam?
b958734
to
631f7ad
Compare
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.
Left some questions about some decisions here, also some minor comments.
manim/mobject/mobject.py
Outdated
@@ -78,6 +78,7 @@ class Mobject: | |||
""" | |||
|
|||
animation_overrides = {} | |||
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.
What was the reasoning for adding this class level attribute? Also, why did you decide against this in opengl_mobject.py
?
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.
This was an ugly workaround similar to the one pointed out in the previous review. I've removed it.
manim/mobject/mobject.py
Outdated
|
||
self.color = Color(color) if color else None | ||
|
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.
NIT: odd spacing
self.color = Color(color) if color else None | |
self.color = Color(color) if color else None |
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.
Fixed
@@ -76,6 +77,10 @@ def __init__( | |||
should_subdivide_sharp_curves=False, | |||
should_remove_null_curves=False, | |||
color=None, | |||
*, |
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.
Is this a typo or intentional?
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.
This is intentional, so as not to change the constructor signature. fill_color
, stroke_color
and stroke_opacity
were keyword only before and they are keyword only now.
manim/mobject/svg/text_mobject.py
Outdated
@@ -1066,7 +1065,7 @@ def __init__( | |||
else: | |||
self.line_spacing = self._font_size + self._font_size * self.line_spacing | |||
|
|||
file_name = self.text2svg() | |||
file_name = self.text2svg(Color(color) if color else None) |
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.
What happens if None
is passed here? I'm not familiar with manimpango so I'm not sure if None could cause problems here
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.
Since None
is not a valid color it would default to black, but I've made it more explicit.
self.update_rgbas_array(array_name, color, opacity) | ||
if width is not None: | ||
setattr(self, width_name, width) | ||
if opacity is not None: | ||
setattr(self, opacity_name, opacity) | ||
if color is not None: | ||
if background: |
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.
Why switch this to depending on background
? Also, it might be better to have it lumped in with the rest of the if background:
attribute setting.
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.
The old condition, color is not None
, should also be present, I've fixed it now. It is depending on background
because only then the color_name
should be updated, otherwise it does not exist. I've made it more explicit, so hopefully the code is more understandable now.
manim/utils/config_ops.py
Outdated
@@ -56,10 +56,10 @@ def __set_name__(self, obj, name): | |||
self.name = name | |||
|
|||
def __get__(self, obj, owner): | |||
return obj.__dict__["data"][self.name] | |||
return obj.data[self.name] if self.name in obj.data else [] |
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.
Checking if an attribute is in data
might prove to be too expensive and cause a performance dropoff, since data
is called a lot of times (haven't tested, just speculation). Is there a way to get around doing this?
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.
This turned out to be no longer necessary after fixing ugly workarounds described above.
self.stroke_opacity = stroke_opacity | ||
self.stroke_width = stroke_width | ||
self.stroke_width = [stroke_width] |
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.
Why did this need to be changed? Iirc set_stroke
should be handling converting the float into a 2d-array to be placed into self.data
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've no idea why I've changed it. I've removed it and everything works fine.
Sorry for the long wait! Can you resolve the merge conflicts? |
5d15936
to
aeca1fa
Compare
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.
Left two minor comments about typings, otherwise LGTM!
manim/mobject/svg/svg_mobject.py
Outdated
@@ -9,11 +9,12 @@ | |||
import re | |||
import string | |||
import warnings | |||
from typing import Dict, List | |||
from typing import Dict, List, Optional |
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.
These imports are not used.
manim/mobject/svg/text_mobject.py
Outdated
@@ -1225,7 +1225,7 @@ def _text2hash(self): | |||
hasher.update(id_str.encode()) | |||
return hasher.hexdigest()[:16] | |||
|
|||
def _text2svg(self): | |||
def _text2svg(self, color: Optional[Color]): |
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.
def _text2svg(self, color: Optional[Color]): | |
def _text2svg(self, color: Color | None): |
Looks like this has broken |
I'll look at it tomorrow. |
color
, stroke_color
and fill_color
fields to properties color
, stroke_color
and fill_color
attributes to properties
color
, stroke_color
and fill_color
attributes to properties color
, stroke_color
and fill_color
attributes to properties
Overview: What does this pull request change?
color
,stroke_color
andfill_color
are now properties inVMobject
, making them synchronized withset_*
andget_*
methodsMotivation and Explanation: Why and how do your changes improve the library?
Fixes #2324.
Reviewer Checklist