From 751e25c55ededcfa683afe4ee9d6eefd41c24abf Mon Sep 17 00:00:00 2001 From: chinzhening Date: Mon, 15 Apr 2024 05:44:36 +0800 Subject: [PATCH 1/5] Add docstrings to `Brace` methods --- manim/mobject/svg/brace.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 788225bb84..d397fd75e2 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -126,6 +126,8 @@ 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. + """ if use_next_to: mob.next_to(self.get_tip(), np.round(self.get_direction()), **kwargs) else: @@ -136,16 +138,23 @@ def put_at_tip(self, mob, use_next_to=True, **kwargs): return self def get_text(self, *text, **kwargs): + """Returns and places the text at the brace tip. + """ text_mob = Tex(*text) self.put_at_tip(text_mob, **kwargs) return text_mob def get_tex(self, *tex, **kwargs): + """Returns and places the tex at the brace tip. + """ tex_mob = MathTex(*tex) self.put_at_tip(tex_mob, **kwargs) return tex_mob def get_tip(self): + """Returns the Point3D 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] @@ -153,6 +162,8 @@ def get_tip(self): 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) From 17862a8657a2fc74dcfc1fcde568587674836c41 Mon Sep 17 00:00:00 2001 From: chinzhening Date: Mon, 15 Apr 2024 05:54:50 +0800 Subject: [PATCH 2/5] Add full NumPy format docstring for the `Brace` methods --- manim/mobject/svg/brace.py | 42 ++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index d397fd75e2..1da670046f 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -127,6 +127,17 @@ def __init__( 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) @@ -138,22 +149,45 @@ def put_at_tip(self, mob, use_next_to=True, **kwargs): return self def get_text(self, *text, **kwargs): - """Returns and places the text at the brace tip. + """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): - """Returns and places the tex at the brace tip. + """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 Point3D at the brace tip. - + """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": From f076d6ca6dcbd9e126ecb93521279e263ec127b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:06:38 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/svg/brace.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 1da670046f..e9e0698f8f 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -150,7 +150,7 @@ def put_at_tip(self, mob, use_next_to=True, **kwargs): def get_text(self, *text, **kwargs): """Places the text at the brace tip. - + Parameters ---------- text @@ -158,7 +158,7 @@ def get_text(self, *text, **kwargs): 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` @@ -187,8 +187,7 @@ def get_tex(self, *tex, **kwargs): return tex_mob def get_tip(self): - """Returns the point at the brace tip. - """ + """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] @@ -196,8 +195,7 @@ def get_tip(self): return self.points[28] # = 7*4 def get_direction(self): - """Returns the direction from the center to the brace tip. - """ + """Returns the direction from the center to the brace tip.""" vect = self.get_tip() - self.get_center() return vect / np.linalg.norm(vect) From 95d18df815ed32e73937d0fe37d407758c9fa700 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Tue, 21 May 2024 09:11:30 -0400 Subject: [PATCH 4/5] feedback --- manim/mobject/svg/brace.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index e9e0698f8f..0f018061f8 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -4,7 +4,7 @@ __all__ = ["Brace", "BraceLabel", "ArcBrace", "BraceText", "BraceBetweenPoints"] -from typing import Sequence +from typing import TYPE_CHECKING import numpy as np import svgelements as se @@ -24,6 +24,11 @@ from ...utils.color import BLACK from ..svg.svg_mobject import VMobjectFromSVGPath +if TYPE_CHECKING: + from manim.typing import Vector3D, Point3D + + from manim.utils.color.core import ParsableManimColor + __all__ = ["Brace", "BraceBetweenPoints", "BraceLabel", "ArcBrace"] @@ -65,13 +70,13 @@ def construct(self): def __init__( self, mobject: Mobject, - direction: Sequence[float] | None = DOWN, - buff=0.2, - sharpness=2, - stroke_width=0, - fill_opacity=1.0, - background_stroke_width=0, - background_stroke_color=BLACK, + direction: Vector3D | None = DOWN, + buff: float = 0.2, + sharpness: float = 2, + stroke_width: float = 0, + fill_opacity: float = 1.0, + background_stroke_width: float = 0, + background_stroke_color: ParsableManimColor = BLACK, **kwargs, ): path_string_template = ( @@ -125,12 +130,12 @@ def __init__( for mob in mobject, self: mob.rotate(angle, about_point=ORIGIN) - def put_at_tip(self, mob, use_next_to=True, **kwargs): + def put_at_tip(self, mob: Mobject, use_next_to: bool = True, **kwargs): """Puts the given mobject at the brace tip. Parameters ---------- - mob : :class:`~.Mobject` + mob 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 @@ -312,9 +317,9 @@ def construct(self): def __init__( self, - point_1: Sequence[float] | None, - point_2: Sequence[float] | None, - direction: Sequence[float] | None = ORIGIN, + point_1: Point3D | None, + point_2: Point3D | None, + direction: Vector3D | None = ORIGIN, **kwargs, ): if all(direction == ORIGIN): From 181eb85002625934723cc89a47966b62cbc8d8d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 11:53:00 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/svg/brace.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index c59c439630..600e841f65 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -4,8 +4,8 @@ __all__ = ["Brace", "BraceLabel", "ArcBrace", "BraceText", "BraceBetweenPoints"] -from typing import TYPE_CHECKING from collections.abc import Sequence +from typing import TYPE_CHECKING import numpy as np import svgelements as se @@ -26,8 +26,7 @@ from ..svg.svg_mobject import VMobjectFromSVGPath if TYPE_CHECKING: - from manim.typing import Vector3D, Point3D - + from manim.typing import Point3D, Vector3D from manim.utils.color.core import ParsableManimColor __all__ = ["Brace", "BraceBetweenPoints", "BraceLabel", "ArcBrace"]