mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 19:07:46 +00:00
Coninuation of VMobject restructuring
This commit is contained in:
parent
55081c75ef
commit
dcb7dc8a1d
1 changed files with 19 additions and 25 deletions
|
|
@ -485,37 +485,30 @@ class VMobject(Mobject):
|
||||||
return points
|
return points
|
||||||
|
|
||||||
def set_points_as_corners(self, points):
|
def set_points_as_corners(self, points):
|
||||||
|
if len(points) == 0:
|
||||||
|
return # TODO, raise warning?
|
||||||
self.clear_points()
|
self.clear_points()
|
||||||
self.start_new_path(points[0])
|
self.start_new_path(points[0])
|
||||||
self.add_points_as_corners(points[1:])
|
self.add_points_as_corners(points[1:])
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_points_smoothly(self, points):
|
def set_points_smoothly(self, points):
|
||||||
assert(len(points) > 1)
|
self.set_points_as_corners(points)
|
||||||
h1, h2 = get_smooth_handle_points(points)
|
self.make_smooth()
|
||||||
self.set_anchors_and_handles(
|
|
||||||
points[:-1], h1, h2, points[1:]
|
|
||||||
)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def set_anchor_points(self, points, mode="smooth"):
|
|
||||||
if mode == "smooth":
|
|
||||||
self.set_points_smoothly(points)
|
|
||||||
elif mode == "corners":
|
|
||||||
self.set_points_as_corners(points)
|
|
||||||
else:
|
|
||||||
raise Exception("Unknown mode")
|
|
||||||
return self
|
|
||||||
|
|
||||||
# TODO, this will not work!
|
|
||||||
def change_anchor_mode(self, mode):
|
|
||||||
for submob in self.family_members_with_points():
|
|
||||||
anchors = submob.get_anchors()
|
|
||||||
submob.set_anchor_points(anchors, mode=mode)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def make_smooth(self):
|
def make_smooth(self):
|
||||||
return self.change_anchor_mode("smooth")
|
nppcc = self.n_points_per_cubic_curve
|
||||||
|
subpaths = self.get_subpaths()
|
||||||
|
self.clear_points()
|
||||||
|
for subpath in subpaths:
|
||||||
|
anchors = [*subpath[::nppcc], subpath[-1]]
|
||||||
|
h1, h2 = get_smooth_handle_points(anchors)
|
||||||
|
new_subpath = np.array(subpath)
|
||||||
|
new_subpath[1::nppcc] = h1
|
||||||
|
new_subpath[2::nppcc] = h2
|
||||||
|
self.append_points(new_subpath)
|
||||||
|
return self
|
||||||
|
|
||||||
def make_jagged(self):
|
def make_jagged(self):
|
||||||
return self.change_anchor_mode("corners")
|
return self.change_anchor_mode("corners")
|
||||||
|
|
@ -795,9 +788,10 @@ class VMobject(Mobject):
|
||||||
))
|
))
|
||||||
for quad in bezier_quads[lower_index + 1:upper_index]:
|
for quad in bezier_quads[lower_index + 1:upper_index]:
|
||||||
self.append_points(quad)
|
self.append_points(quad)
|
||||||
self.append_points(partial_bezier_points(
|
if upper_index > lower_index:
|
||||||
bezier_quads[upper_index], 0, upper_residue
|
self.append_points(partial_bezier_points(
|
||||||
))
|
bezier_quads[upper_index], 0, upper_residue
|
||||||
|
))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue