Skip to content
43 changes: 43 additions & 0 deletions manim/mobject/svg/brace.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def __init__(
mob.rotate(angle, about_point=ORIGIN)

def put_at_tip(self, mob, use_next_to=True, **kwargs):
"""Puts the given mobject at the brace tip.

Parameters
----------
mob : :class:`~.Mobject`
The mobject to be placed at the tip.
use_next_to
If true, then :meth:`next_to` is used to place the mobject at the
tip.
kwargs
Any additional keyword arguments are passed to :meth:`next_to` which
is used to put the mobject next to the brace tip.
"""
if use_next_to:
mob.next_to(self.get_tip(), np.round(self.get_direction()), **kwargs)
else:
Expand All @@ -136,23 +149,53 @@ def put_at_tip(self, mob, use_next_to=True, **kwargs):
return self

def get_text(self, *text, **kwargs):
"""Places the text at the brace tip.

Parameters
----------
text
The text to be placed at the brace tip.
kwargs
Any additional keyword arguments are passed to :meth:`.put_at_tip` which
is used to position the text at the brace tip.

Returns
-------
:class:`~.Tex`
"""
text_mob = Tex(*text)
self.put_at_tip(text_mob, **kwargs)
return text_mob

def get_tex(self, *tex, **kwargs):
"""Places the tex at the brace tip.

Parameters
----------
tex
The tex to be placed at the brace tip.
kwargs
Any further keyword arguments are passed to :meth:`.put_at_tip` which
is used to position the tex at the brace tip.

Returns
-------
:class:`~.MathTex`
"""
tex_mob = MathTex(*tex)
self.put_at_tip(tex_mob, **kwargs)
return tex_mob

def get_tip(self):
"""Returns the point at the brace tip."""
# Returns the position of the seventh point in the path, which is the tip.
if config["renderer"] == "opengl":
return self.points[34]

return self.points[28] # = 7*4

def get_direction(self):
"""Returns the direction from the center to the brace tip."""
vect = self.get_tip() - self.get_center()
return vect / np.linalg.norm(vect)

Expand Down