From 3f5f24f4b09f4b982af5cc7baba4258173ad1b84 Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:49:46 +0100 Subject: [PATCH 01/10] Added BraceBetweenPoints and some documentation --- manim/mobject/svg/brace.py | 66 +++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 379d878a22..70369dde46 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -1,6 +1,6 @@ """Mobject representing curly braces.""" -__all__ = ["Brace", "BraceLabel", "BraceText"] +__all__ = ["Brace", "BraceLabel", "BraceText", "BraceBetweeenPoints"] import numpy as np @@ -12,11 +12,37 @@ from ...mobject.svg.tex_mobject import MathTex from ...mobject.svg.tex_mobject import Tex from ...mobject.types.vectorized_mobject import VMobject +from ...mobject.geometry import Line from ...utils.config_ops import digest_config from ...utils.space_ops import get_norm class Brace(MathTex): + """Takes a mobject and draws a brace adjacent to it. + Passing a direction vector determines the direction from which the + brace is drawn. By default it is drawn from below. + + Parameters + ---------- + mobject : :class:`~.Mobject` + The mobject adjacent to which the brace is placed + direction : Optional[Union[:class:`list`, + :class:`numpy.array`]], optional + The direction from which the brace faces the mobject. + + Examples + -------- + .. manim:: BraceExample + + class BraceExample(Scene): + def construct(self): + circle = Circle() + brace = Brace(circle,direction=RIGHT) + self.play(ShowCreation(circle)) + self.play(ShowCreation(brace)) + self.wait(2) + """ + CONFIG = { "buff": 0.2, "width_multiplier": 2, @@ -129,3 +155,41 @@ def change_brace_label(self, obj, *text): class BraceText(BraceLabel): CONFIG = {"label_constructor": Tex} + + +class BraceBetweeenPoints(Brace): + """Similar to Brace, but instead of taking a mobject it uses 2 + points to place the brace. A fitting direction for the brace is + computed, but it still can be manually overridden. + If the points go from left to right, the brace is drawn from below. + Swapping the points places the brace on the opposite side. + + Parameters + ---------- + point_1 : :class:`[Union[:class:`list`,:class:`numpy.array`]]` + The first point. + point_2 : :class:`[Union[:class:`list`,:class:`numpy.array`]]` + The second point. + direction : Optional[Union[:class:`list`, + :class:`numpy.array`]], optional + The direction from which the brace faces the mobject. + + Examples + -------- + .. manim:: BraceBPExample + + class BraceBPExample(Scene): + def construct(self): + p1 = [0,0,0] + p2 = [1,2,0] + brace = BraceBetweeenPoints(p1,p2) + self.play(ShowCreation(NumperPlane())) + self.play(ShowCreation(brace)) + self.wait(2) + """ + + def __init__(self, point_1, point_2, direction=ORIGIN, **kwargs): + if all(direction == ORIGIN): + line_vector = np.array(point_2) - np.array(point_1) + direction = np.array([line_vector[1], -line_vector[0], 0]) + Brace.__init__(self, Line(point_1, point_2), direction=direction, **kwargs) From c73de1d00cb46b94ec6478a0491728b93bd0e2eb Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Tue, 10 Nov 2020 17:05:42 +0100 Subject: [PATCH 02/10] Update manim/mobject/svg/brace.py - Doc nitpicks Co-authored-by: Leo Torres --- manim/mobject/svg/brace.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 70369dde46..1988801d45 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -19,30 +19,34 @@ class Brace(MathTex): """Takes a mobject and draws a brace adjacent to it. + Passing a direction vector determines the direction from which the brace is drawn. By default it is drawn from below. Parameters ---------- mobject : :class:`~.Mobject` - The mobject adjacent to which the brace is placed + The mobject adjacent to which the brace is placed. direction : Optional[Union[:class:`list`, :class:`numpy.array`]], optional The direction from which the brace faces the mobject. - Examples + See Also -------- - .. manim:: BraceExample + :class:`BraceBetweenPoints` - class BraceExample(Scene): - def construct(self): - circle = Circle() - brace = Brace(circle,direction=RIGHT) - self.play(ShowCreation(circle)) - self.play(ShowCreation(brace)) - self.wait(2) + Examples + -------- + .. manim:: BraceExample + + class BraceExample(Scene): + def construct(self): + circle = Circle() + brace = Brace(circle, direction=RIGHT) + self.play(ShowCreation(circle)) + self.play(ShowCreation(brace)) + """ - CONFIG = { "buff": 0.2, "width_multiplier": 2, From 1e177cda48149ddd8266015302769ef12d8578ee Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Tue, 10 Nov 2020 17:05:54 +0100 Subject: [PATCH 03/10] Update manim/mobject/svg/brace.py - Typo Co-authored-by: Benjamin Hackl --- manim/mobject/svg/brace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 1988801d45..207d7cf98a 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -187,7 +187,7 @@ def construct(self): p1 = [0,0,0] p2 = [1,2,0] brace = BraceBetweeenPoints(p1,p2) - self.play(ShowCreation(NumperPlane())) + self.play(ShowCreation(NumberPlane())) self.play(ShowCreation(brace)) self.wait(2) """ From 5010fd4821c5d5066f5b8c6d6bd0c66294e3b277 Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Wed, 11 Nov 2020 03:18:00 +0100 Subject: [PATCH 04/10] Re-added wait, black --- manim/mobject/svg/brace.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 207d7cf98a..b4fb92cb10 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -19,7 +19,7 @@ class Brace(MathTex): """Takes a mobject and draws a brace adjacent to it. - + Passing a direction vector determines the direction from which the brace is drawn. By default it is drawn from below. @@ -45,8 +45,10 @@ def construct(self): brace = Brace(circle, direction=RIGHT) self.play(ShowCreation(circle)) self.play(ShowCreation(brace)) - + self.wait(2) + """ + CONFIG = { "buff": 0.2, "width_multiplier": 2, From 8b5f2cd0d463ba91b38cb3b3b85d3bc438ff3dcb Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Wed, 11 Nov 2020 03:20:51 +0100 Subject: [PATCH 05/10] Doc fixing attempt --- manim/mobject/svg/brace.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index b4fb92cb10..995743b68a 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -27,8 +27,7 @@ class Brace(MathTex): ---------- mobject : :class:`~.Mobject` The mobject adjacent to which the brace is placed. - direction : Optional[Union[:class:`list`, - :class:`numpy.array`]], optional + direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional The direction from which the brace faces the mobject. See Also @@ -176,8 +175,7 @@ class BraceBetweeenPoints(Brace): The first point. point_2 : :class:`[Union[:class:`list`,:class:`numpy.array`]]` The second point. - direction : Optional[Union[:class:`list`, - :class:`numpy.array`]], optional + direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional The direction from which the brace faces the mobject. Examples From facf0b97dfcf4b1ac9db5679a939e99ca86bb96c Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Wed, 11 Nov 2020 14:24:39 +0100 Subject: [PATCH 06/10] doc fixing attempt --- manim/mobject/svg/brace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 995743b68a..ffe659c6f1 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -171,9 +171,9 @@ class BraceBetweeenPoints(Brace): Parameters ---------- - point_1 : :class:`[Union[:class:`list`,:class:`numpy.array`]]` + point_1 : Union[:class:`list`, :class:`numpy.array`] The first point. - point_2 : :class:`[Union[:class:`list`,:class:`numpy.array`]]` + point_2 : Union[:class:`list`, :class:`numpy.array`] The second point. direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional The direction from which the brace faces the mobject. From 723f7ac4e6b82b9140239d2af7546f944b7b4f5a Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Fri, 13 Nov 2020 12:08:13 +0100 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Benjamin Hackl --- manim/mobject/svg/brace.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index ffe659c6f1..2f966f3a12 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -27,7 +27,7 @@ class Brace(MathTex): ---------- mobject : :class:`~.Mobject` The mobject adjacent to which the brace is placed. - direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional + direction : Optional[Union[:class:`list`, :class:`numpy.array`]] The direction from which the brace faces the mobject. See Also @@ -164,7 +164,9 @@ class BraceText(BraceLabel): class BraceBetweeenPoints(Brace): """Similar to Brace, but instead of taking a mobject it uses 2 - points to place the brace. A fitting direction for the brace is + points to place the brace. + + A fitting direction for the brace is computed, but it still can be manually overridden. If the points go from left to right, the brace is drawn from below. Swapping the points places the brace on the opposite side. @@ -175,7 +177,7 @@ class BraceBetweeenPoints(Brace): The first point. point_2 : Union[:class:`list`, :class:`numpy.array`] The second point. - direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional + direction : Optional[Union[:class:`list`, :class:`numpy.array`]] The direction from which the brace faces the mobject. Examples From 9084b9fbffc235f322c74de0ba65631314f5fc42 Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Fri, 13 Nov 2020 12:22:54 +0100 Subject: [PATCH 08/10] black Co-authored-by: Benjamin Hackl --- manim/mobject/svg/brace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index 2f966f3a12..e9d0d21d9b 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -164,8 +164,8 @@ class BraceText(BraceLabel): class BraceBetweeenPoints(Brace): """Similar to Brace, but instead of taking a mobject it uses 2 - points to place the brace. - + points to place the brace. + A fitting direction for the brace is computed, but it still can be manually overridden. If the points go from left to right, the brace is drawn from below. From 31f4246c161bdeb4ec253065a262f57a3b4c94b7 Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Fri, 13 Nov 2020 12:37:29 +0100 Subject: [PATCH 09/10] Type, text issue --- manim/mobject/svg/brace.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index ffe659c6f1..47552aeb09 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -1,6 +1,6 @@ """Mobject representing curly braces.""" -__all__ = ["Brace", "BraceLabel", "BraceText", "BraceBetweeenPoints"] +__all__ = ["Brace", "BraceLabel", "BraceText", "BraceBetweenPoints"] import numpy as np @@ -162,7 +162,7 @@ class BraceText(BraceLabel): CONFIG = {"label_constructor": Tex} -class BraceBetweeenPoints(Brace): +class BraceBetweenPoints(Brace): """Similar to Brace, but instead of taking a mobject it uses 2 points to place the brace. A fitting direction for the brace is computed, but it still can be manually overridden. @@ -176,7 +176,7 @@ class BraceBetweeenPoints(Brace): point_2 : Union[:class:`list`, :class:`numpy.array`] The second point. direction : Optional[Union[:class:`list`,:class:`numpy.array`]], optional - The direction from which the brace faces the mobject. + The direction from which the brace faces towards the points. Examples -------- @@ -186,7 +186,7 @@ class BraceBPExample(Scene): def construct(self): p1 = [0,0,0] p2 = [1,2,0] - brace = BraceBetweeenPoints(p1,p2) + brace = BraceBetweenPoints(p1,p2) self.play(ShowCreation(NumberPlane())) self.play(ShowCreation(brace)) self.wait(2) From c91b2c3602e5b77d1df6eb7c4fc53dd060db10c3 Mon Sep 17 00:00:00 2001 From: XorUnison <2881103+XorUnison@users.noreply.github.com> Date: Fri, 13 Nov 2020 12:41:12 +0100 Subject: [PATCH 10/10] Text fix --- manim/mobject/svg/brace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py index bf0541b8f8..997e0911d5 100644 --- a/manim/mobject/svg/brace.py +++ b/manim/mobject/svg/brace.py @@ -178,7 +178,7 @@ class BraceBetweenPoints(Brace): point_2 : Union[:class:`list`, :class:`numpy.array`] The second point. direction : Optional[Union[:class:`list`, :class:`numpy.array`]] - The direction from which the brace faces the mobject. + The direction from which the brace faces towards the points. Examples --------