A community-maintained Python framework for creating mathematical animations.
Slightly cleaner implementation of set_cairo_context_path
Grant Sandersonc23f456fd6f4
diff --git a/manimlib/camera/camera.py b/manimlib/camera/camera.pyindex c0843782c..085cc6841 100644--- a/manimlib/camera/camera.py+++ b/manimlib/camera/camera.py@@ -326,54 +326,24 @@ class Camera(object):self.apply_stroke(ctx, vmobject)return self- # def old_set_cairo_context_path(self, ctx, vmobject):- # ctx.new_path()- # for vmob in it.chain([vmobject], vmobject.get_subpath_mobjects()):- # points = self.transform_points_pre_display(- # vmob, vmob.points- # )- # if np.any(np.isnan(points)) or np.any(points == np.inf):- # # TODO, print some kind of warning about- # # mobject having invalid points?- # points = np.zeros((1, 3))- # ctx.new_sub_path()- # ctx.move_to(*points[0][:2])- # for p0, p1, p2 in zip(points[1::3], points[2::3], points[3::3]):- # ctx.curve_to(*p0[:2], *p1[:2], *p2[:2])- # if vmob.is_closed():- # ctx.close_path()- # return self-def set_cairo_context_path(self, ctx, vmobject):points = self.transform_points_pre_display(vmobject, vmobject.points)if len(points) == 0:return- elif np.any(np.isnan(points)) or np.any(points == np.inf):- # TODO, print some kind of warning about- # mobject having invalid points?- points = np.zeros((1, 3))-- def should_start_new_path(last_p3, p0):- if last_p3 is None:- return True- else:- return not vmobject.consider_points_equals(- last_p3, p0- )- last_p3 = None- quads = vmobject.get_cubic_bezier_tuples_from_points(points)ctx.new_path()- for p0, p1, p2, p3 in quads:- if should_start_new_path(last_p3, p0):- ctx.new_sub_path()- ctx.move_to(*p0[:2])- ctx.curve_to(*p1[:2], *p2[:2], *p3[:2])- last_p3 = p3- if vmobject.is_closed():- ctx.close_path()+ subpaths = vmobject.get_subpaths_from_points(points)+ for subpath in subpaths:+ quads = vmobject.get_cubic_bezier_tuples_from_points(subpath)+ ctx.new_sub_path()+ start = subpath[0]+ ctx.move_to(*start[:2])+ for p0, p1, p2, p3 in quads:+ ctx.curve_to(*p1[:2], *p2[:2], *p3[:2])+ if vmobject.consider_points_equals(subpath[0], subpath[-1]):+ ctx.close_path()return selfdef set_cairo_context_color(self, ctx, rgbas, vmobject):@@ -574,7 +544,11 @@ class Camera(object):def transform_points_pre_display(self, mobject, points):# Subclasses (like ThreeDCamera) may want to- # adjust points before they're shown+ # adjust points futher before they're shown+ if np.any(np.isnan(points)) or np.any(points == np.inf):+ # TODO, print some kind of warning about+ # mobject having invalid points?+ points = np.zeros((1, 3))return pointsdef points_to_pixel_coords(self, mobject, points):diff --git a/manimlib/camera/three_d_camera.py b/manimlib/camera/three_d_camera.pyindex 3f8b92290..5cf4ba0d1 100644--- a/manimlib/camera/three_d_camera.py+++ b/manimlib/camera/three_d_camera.py@@ -183,6 +183,7 @@ class ThreeDCamera(Camera):return self.project_points(point.reshape((1, 3)))[0, :]def transform_points_pre_display(self, mobject, points):+ points = super().transform_points_pre_display(mobject, points)fixed_orientation = mobject in self.fixed_orientation_mobjectsfixed_in_frame = mobject in self.fixed_in_frame_mobjects