Skip to content

Commit a88421c

Browse files
committed
Ensure that stroke_width is always a np.ndarray
1 parent 6070531 commit a88421c

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

manim/mobject/opengl/opengl_mobject.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ def align_data(self, mobject: OpenGLMobject) -> Self:
25812581
# can handle that case differently if they choose
25822582
mob1.align_points(mob2)
25832583
for key in mob1.data.keys() & mob2.data.keys():
2584-
if key == "points" or key == "stroke_width":
2584+
if key == "points":
25852585
continue
25862586
arr1 = mob1.data[key]
25872587
arr2 = mob2.data[key]
@@ -2676,8 +2676,6 @@ def construct(self):
26762676
for key in self.data:
26772677
if key in self.locked_data_keys:
26782678
continue
2679-
if isinstance(self.data[key], int):
2680-
continue
26812679
if len(self.data[key]) == 0:
26822680
continue
26832681
if key not in mobject1.data or key not in mobject2.data:

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ def __init__(
124124
self.data = {}
125125
self.fill_opacity = fill_opacity
126126
self.stroke_opacity = stroke_opacity
127+
print("OpenGLVMobject")
128+
print(stroke_width)
127129
self.stroke_width = np.array([[stroke_width]])
130+
print("self.stroke_width:", self.stroke_width)
128131
self.draw_stroke_behind_fill = draw_stroke_behind_fill
129132
# Indicates that it will not be displayed, but
130133
# that it should count in parent mobject's path
@@ -199,6 +202,8 @@ def init_colors(self):
199202
color=self.fill_color or self.color,
200203
opacity=self.fill_opacity,
201204
)
205+
print("init_colors")
206+
print("self.stroke_width:", self.stroke_width)
202207
self.set_stroke(
203208
color=self.stroke_color or self.color,
204209
width=self.stroke_width,
@@ -267,8 +272,6 @@ def set_stroke(
267272
background=None,
268273
recurse=True,
269274
):
270-
if width is None:
271-
width = np.array([[0]])
272275
if opacity is not None:
273276
self.stroke_opacity = opacity
274277
if recurse:
@@ -312,8 +315,16 @@ def set_style(
312315

313316
if stroke_rgba is not None:
314317
self.stroke_rgba = resize_with_interpolation(stroke_rgba, len(fill_rgba))
318+
print("set_style")
319+
print(self)
320+
print("stroke_width: ", stroke_width)
321+
print("self.stroke_width:", self.stroke_width)
315322
self.set_stroke(width=stroke_width)
316323
else:
324+
print("set_style")
325+
print(self)
326+
print("stroke_width: ", stroke_width)
327+
print("self.stroke_width:", self.stroke_width)
317328
self.set_stroke(
318329
color=stroke_color,
319330
width=stroke_width,
@@ -359,6 +370,8 @@ def set_color(self, color, opacity=None, recurse=True):
359370
self.opacity = opacity
360371

361372
self.set_fill(color, opacity=opacity, recurse=recurse)
373+
print("set_color")
374+
print(self.stroke_width)
362375
self.set_stroke(color, opacity=opacity, recurse=recurse)
363376
return self
364377

@@ -436,7 +449,11 @@ def get_colors(self):
436449
fill_color = property(get_fill_color, set_fill)
437450

438451
def has_stroke(self):
452+
print("has_stroke")
453+
print(self)
454+
print("self.stroke_width: ", self.stroke_width)
439455
stroke_widths = self.get_stroke_widths()
456+
print("stroke_widths: ", stroke_widths)
440457
stroke_opacities = self.get_stroke_opacities()
441458
return (
442459
stroke_widths is not None

manim/mobject/svg/svg_mobject.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ def __init__(
126126
self.fill_opacity = fill_opacity # type: ignore[assignment]
127127
self.stroke_color = stroke_color
128128
self.stroke_opacity = stroke_opacity # type: ignore[assignment]
129-
self.stroke_width = stroke_width # type: ignore[assignment]
130-
if self.stroke_width is None:
131-
self.stroke_width = 0
129+
if stroke_width is None:
130+
self.stroke_width = None
131+
else:
132+
self.stroke_width = np.array([[stroke_width]]) # type: ignore[assignment]
132133

133134
if svg_default is None:
134135
svg_default = {
135136
"color": None,
136137
"opacity": None,
137138
"fill_color": None,
138139
"fill_opacity": None,
139-
"stroke_width": 0,
140+
"stroke_width": None,
140141
"stroke_color": None,
141142
"stroke_opacity": None,
142143
}
@@ -327,13 +328,17 @@ def apply_style_to_mobject(mob: VMobject, shape: se.GraphicObject) -> VMobject:
327328
shape
328329
The parsed SVG element.
329330
"""
331+
print("apply_style_to_mobject")
332+
print("mob")
333+
print("mob.stroke_width:", mob.stroke_width)
330334
mob.set_style(
331335
stroke_width=shape.stroke_width,
332336
stroke_color=shape.stroke.hexrgb,
333337
stroke_opacity=shape.stroke.opacity,
334338
fill_color=shape.fill.hexrgb,
335339
fill_opacity=shape.fill.opacity,
336340
)
341+
print("mob.stroke_width:", mob.stroke_width)
337342
return mob
338343

339344
def path_to_mobject(self, path: se.Path) -> VMobjectFromSVGPath:

0 commit comments

Comments
 (0)