Skip to content
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

Fix AttributeError and ValueError in Bezier and Interpolation functions #3372

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

import moderngl
import numpy as np
from colour import Color
Copy link
Member

Choose a reason for hiding this comment

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

This does not look correct.


from manim import config, logger
from manim.constants import *
from manim.utils.bezier import integer_interpolate, interpolate
from manim.utils.color import *
from manim.utils.color import Colors
from manim.utils.config_ops import _Data, _Uniforms

# from ..utils.iterables import batch_by_property
Expand Down Expand Up @@ -144,7 +146,7 @@ def __init__(
self.init_updaters()
# self.init_event_listners()
self.init_points()
self.color = ManimColor.parse(color)
self.color = Color(color) if color else None
self.init_colors()

self.shader_indices = None
Expand Down Expand Up @@ -201,10 +203,10 @@ def set_default(cls, **kwargs):
>>> from manim import Square, GREEN
>>> Square.set_default(color=GREEN, fill_opacity=0.25)
>>> s = Square(); s.color, s.fill_opacity
(ManimColor('#83C167'), 0.25)
(<Color #83c167>, 0.25)
>>> Square.set_default()
>>> s = Square(); s.color, s.fill_opacity
(ManimColor('#FFFFFF'), 0.0)
(<Color white>, 0.0)

.. manim:: ChangedDefaultTextcolor
:save_last_frame:
Expand Down Expand Up @@ -1969,12 +1971,12 @@ def set_rgba_array_direct(self, rgbas: np.ndarray, name="rgbas", recurse=True):
for mob in self.get_family(recurse):
mob.data[name] = rgbas.copy()

def set_color(self, color: ParsableManimColor | None, opacity=None, recurse=True):
def set_color(self, color, opacity=None, recurse=True):
self.set_rgba_array(color, opacity, recurse=False)
# Recurse to submobjects differently from how set_rgba_array
# in case they implement set_color differently
if color is not None:
self.color: ManimColor = ManimColor.parse(color)
self.color = Color(color)
if opacity is not None:
self.opacity = opacity
if recurse:
Expand Down Expand Up @@ -2035,7 +2037,7 @@ def set_shadow(self, shadow, recurse=True):
# Background rectangle

def add_background_rectangle(
self, color: ParsableManimColor | None = None, opacity: float = 0.75, **kwargs
self, color: Colors | None = None, opacity: float = 0.75, **kwargs
):
# TODO, this does not behave well when the mobject has points,
# since it gets displayed on top
Expand Down Expand Up @@ -2315,6 +2317,8 @@ def align_data(self, mobject):
continue
arr1 = mob1.data[key]
arr2 = mob2.data[key]
if arr1 is None or arr2 is None:
continue # Or handle this case in a manner appropriate for your program
if len(arr2) > len(arr1):
mob1.data[key] = resize_preserving_order(arr1, len(arr2))
elif len(arr1) > len(arr2):
Expand Down Expand Up @@ -2399,7 +2403,7 @@ def construct(self):
for key in self.data:
if key in self.locked_data_keys:
continue
if len(self.data[key]) == 0:
if self.data[key] is None or len(self.data[key]) == 0:
continue
if key not in mobject1.data or key not in mobject2.data:
continue
Expand Down Expand Up @@ -2723,7 +2727,7 @@ def throw_error_if_no_points(self):

class OpenGLGroup(OpenGLMobject):
def __init__(self, *mobjects, **kwargs):
if not all(isinstance(m, OpenGLMobject) for m in mobjects):
if not all([isinstance(m, OpenGLMobject) for m in mobjects]):
raise Exception("All submobjects must be of type OpenGLMobject")
super().__init__(**kwargs)
self.add(*mobjects)
Expand Down
9 changes: 7 additions & 2 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ def get_bezier_tuples_from_points(self, points):
nppc = self.n_points_per_curve
remainder = len(points) % nppc
points = points[: len(points) - remainder]
return points.reshape((-1, nppc, 3))
points_np = np.array(points)
return points_np.reshape((-1, nppc, 3))

def get_bezier_tuples(self):
return self.get_bezier_tuples_from_points(self.points)
Expand Down Expand Up @@ -1301,7 +1302,11 @@ def interpolate(self, mobject1, mobject2, alpha, *args, **kwargs):
if self.has_fill():
tri1 = mobject1.get_triangulation()
tri2 = mobject2.get_triangulation()
if len(tri1) != len(tri2) or not np.all(tri1 == tri2):
if (
len(tri1) != len(tri2)
or tri1.shape != tri2.shape
or not np.all(tri1 == tri2)
):
self.refresh_triangulation()
return self

Expand Down
Loading