Skip to content

Refactoring Math in Manim. Mobject types less intertwined #3096

Open
@MrDiver

Description

@MrDiver

There are many occurences in the Code where mobjects of different types are misused for their points. Don't get me wrong i think reusing code is perfectly fine but i think the generating of points should be a Math function instead of a Mobject which is deleted afterwards.

I would propose to move all of this code to a seperate module which has functions for generating points or doing math. That makes the mobjects much more independent of each other. For example the Line mobject currently depends on Arc and ArcBetweenPoints for their points.

Im not sure where the right place would be to store those math functions because we have a lot of stuff in utils/ i would maybe suggest finding a place there.

arc = ArcBetweenPoints(
v2 - unit_vect1 * cut_off_length,
v2 + unit_vect2 * cut_off_length,
angle=sign * angle,
)
arcs.append(arc)
# To ensure that we loop through starting with last
arcs = [arcs[-1], *arcs[:-1]]
from manim.mobject.geometry.line import Line
for arc1, arc2 in adjacent_pairs(arcs):
new_points.extend(arc1.points)
line = Line(arc1.get_end(), arc2.get_start())
# Make sure anchors are evenly distributed
len_ratio = line.get_length() / arc1.get_arc_length()
line.insert_n_curves(int(arc1.get_num_curves() * len_ratio))
new_points.extend(line.points)
self.set_points(new_points)

Metadata

Metadata

Assignees

Labels

experimentalmaintenancerefactoring, typos, removing clutter/dead code, and other code quality improvementsneeds discussionThings which needs to be discussed before implemented.refactorRefactor or redesign of existing code

Type

No type

Projects

Status

🆕 New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions