mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
feat: add get_lines method to MathTex for line grouping
This commit is contained in:
parent
6b85ff6df5
commit
23a06b0122
2 changed files with 29 additions and 2 deletions
|
|
@ -157,15 +157,21 @@ class TracedPath(VMobject, metaclass=ConvertToOpenGL):
|
|||
self.dissipating_time = dissipating_time
|
||||
self.time = 1.0 if self.dissipating_time else None
|
||||
self.add_updater(self.update_path)
|
||||
self._point_history: list = []
|
||||
|
||||
def update_path(self, mob: Mobject, dt: float) -> None:
|
||||
new_point = self.traced_point_func()
|
||||
if not self.has_points():
|
||||
self.start_new_path(new_point)
|
||||
self.add_line_to(new_point)
|
||||
self._point_history = [new_point]
|
||||
else:
|
||||
self._point_history.append(new_point)
|
||||
self.set_points_as_corners(self._point_history)
|
||||
|
||||
if self.dissipating_time:
|
||||
assert self.time is not None
|
||||
self.time += dt
|
||||
if self.time - 1 > self.dissipating_time:
|
||||
nppcc = self.n_points_per_curve
|
||||
self.set_points(self.points[nppcc:])
|
||||
self._point_history = self._point_history[nppcc:]
|
||||
self.set_points_as_corners(self._point_history)
|
||||
|
|
|
|||
|
|
@ -596,6 +596,27 @@ class MathTex(SingleStringMathTex):
|
|||
def sort_alphabetically(self) -> None:
|
||||
self.submobjects.sort(key=lambda m: m.get_tex_string())
|
||||
|
||||
def get_lines(self) -> VGroup:
|
||||
r"""Groups submobjects into lines based on the \\ line break indicator.
|
||||
|
||||
Returns
|
||||
-------
|
||||
VGroup
|
||||
A VGroup containing VGroups, each representing a line of the LaTeX expression.
|
||||
"""
|
||||
lines = VGroup()
|
||||
current_line = VGroup()
|
||||
for submob in self.submobjects:
|
||||
if submob.get_tex_string() == r"\\":
|
||||
if len(current_line) > 0:
|
||||
lines.add(current_line)
|
||||
current_line = VGroup()
|
||||
else:
|
||||
current_line.add(submob)
|
||||
if len(current_line) > 0:
|
||||
lines.add(current_line)
|
||||
return lines
|
||||
|
||||
|
||||
class MathTexPart(VMobject, metaclass=ConvertToOpenGL):
|
||||
tex_string: str
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue