mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Slightly cleaner implementation of set_cairo_context_path
This commit is contained in:
parent
1f320a3974
commit
c23f456fd6
2 changed files with 16 additions and 41 deletions
|
@ -326,54 +326,24 @@ class Camera(object):
|
||||||
self.apply_stroke(ctx, vmobject)
|
self.apply_stroke(ctx, vmobject)
|
||||||
return self
|
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):
|
def set_cairo_context_path(self, ctx, vmobject):
|
||||||
points = self.transform_points_pre_display(
|
points = self.transform_points_pre_display(
|
||||||
vmobject, vmobject.points
|
vmobject, vmobject.points
|
||||||
)
|
)
|
||||||
if len(points) == 0:
|
if len(points) == 0:
|
||||||
return
|
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()
|
ctx.new_path()
|
||||||
for p0, p1, p2, p3 in quads:
|
subpaths = vmobject.get_subpaths_from_points(points)
|
||||||
if should_start_new_path(last_p3, p0):
|
for subpath in subpaths:
|
||||||
ctx.new_sub_path()
|
quads = vmobject.get_cubic_bezier_tuples_from_points(subpath)
|
||||||
ctx.move_to(*p0[:2])
|
ctx.new_sub_path()
|
||||||
ctx.curve_to(*p1[:2], *p2[:2], *p3[:2])
|
start = subpath[0]
|
||||||
last_p3 = p3
|
ctx.move_to(*start[:2])
|
||||||
if vmobject.is_closed():
|
for p0, p1, p2, p3 in quads:
|
||||||
ctx.close_path()
|
ctx.curve_to(*p1[:2], *p2[:2], *p3[:2])
|
||||||
|
if vmobject.consider_points_equals(subpath[0], subpath[-1]):
|
||||||
|
ctx.close_path()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_cairo_context_color(self, ctx, rgbas, vmobject):
|
def set_cairo_context_color(self, ctx, rgbas, vmobject):
|
||||||
|
@ -574,7 +544,11 @@ class Camera(object):
|
||||||
|
|
||||||
def transform_points_pre_display(self, mobject, points):
|
def transform_points_pre_display(self, mobject, points):
|
||||||
# Subclasses (like ThreeDCamera) may want to
|
# 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 points
|
return points
|
||||||
|
|
||||||
def points_to_pixel_coords(self, mobject, points):
|
def points_to_pixel_coords(self, mobject, points):
|
||||||
|
|
|
@ -183,6 +183,7 @@ class ThreeDCamera(Camera):
|
||||||
return self.project_points(point.reshape((1, 3)))[0, :]
|
return self.project_points(point.reshape((1, 3)))[0, :]
|
||||||
|
|
||||||
def transform_points_pre_display(self, mobject, points):
|
def transform_points_pre_display(self, mobject, points):
|
||||||
|
points = super().transform_points_pre_display(mobject, points)
|
||||||
fixed_orientation = mobject in self.fixed_orientation_mobjects
|
fixed_orientation = mobject in self.fixed_orientation_mobjects
|
||||||
fixed_in_frame = mobject in self.fixed_in_frame_mobjects
|
fixed_in_frame = mobject in self.fixed_in_frame_mobjects
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue