From 6d74f5e0a8599c1db9fa680bc024dae512246a0b Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Fri, 1 Oct 2021 01:22:50 -0400 Subject: [PATCH 01/13] fix docs --- manim/mobject/mobject.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index f9fac8a115..a914da57e0 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -208,10 +208,9 @@ def set_default(cls, **kwargs): .. manim:: ChangedDefaultTextcolor :save_last_frame: - config.background_color = WHITE - class ChangedDefaultTextcolor(Scene): def construct(self): + self.camera.background_color = WHITE Text.set_default(color=BLACK) self.add(Text("Changing default values is easy!")) From bf6b97bec52f275b6692f022cef9528798d95d8d Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Fri, 1 Oct 2021 01:42:10 -0400 Subject: [PATCH 02/13] fix doc --- manim/mobject/mobject.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index f9fac8a115..ac0263b0f4 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -208,10 +208,9 @@ def set_default(cls, **kwargs): .. manim:: ChangedDefaultTextcolor :save_last_frame: - config.background_color = WHITE - class ChangedDefaultTextcolor(Scene): def construct(self): + self.camera.background_color Text.set_default(color=BLACK) self.add(Text("Changing default values is easy!")) From 2ff7ea94e1a7f6d549e6dd4402a1e046d6682f96 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 16:35:37 -0400 Subject: [PATCH 03/13] apply fixes --- manim/mobject/geometry.py | 25 ++++++++++++++----------- manim/mobject/matrix.py | 10 +++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index 184f33889f..6f82c90f0f 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -1559,7 +1559,8 @@ def coordinate_label( self, integer_labels: bool = True, n_dim: int = 2, - color: str = WHITE, + color: Optional[Color] = None, + **kwargs, ): """Creates a label based on the coordinates of the vector. @@ -1570,24 +1571,26 @@ def coordinate_label( n_dim The number of dimensions of the vector. color - The color of the label. + Sets the color of label, optional. + kwargs + Additional arguments to be passed to :class:`~.Matrix`. Examples -------- - .. manim VectorCoordinateLabel + .. manim:: VectorCoordinateLabel :save_last_frame: class VectorCoordinateLabel(Scene): def construct(self): plane = NumberPlane() - vect_1 = Vector([1, 2]) - vect_2 = Vector([-3, -2]) - label_1 = vect1.coordinate_label() - label_2 = vect2.coordinate_label(color=YELLOW) + vec_1 = Vector([1, 2]) + vec_2 = Vector([-3, -2]) + label_1 = vec_1.coordinate_label() + label_2 = vec_2.coordinate_label(color=YELLOW) - self.add(plane, vect_1, vect_2, label_1, label_2) + self.add(plane, vec_1, vec_2, label_1, label_2) """ # avoiding circular imports from .matrix import Matrix @@ -1597,8 +1600,7 @@ def construct(self): vect = np.round(vect).astype(int) vect = vect[:n_dim] vect = vect.reshape((n_dim, 1)) - - label = Matrix(vect) + label = Matrix(vect, **kwargs) label.scale(LARGE_BUFF - 0.2) shift_dir = np.array(self.get_end()) @@ -1607,7 +1609,8 @@ def construct(self): else: # Pointing left shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT label.shift(shift_dir) - label.set_color(color) + if color is not None: + label.set_color(label) return label diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py index 3f6037d6d2..486258fcba 100644 --- a/manim/mobject/matrix.py +++ b/manim/mobject/matrix.py @@ -138,6 +138,7 @@ def __init__( element_alignment_corner=DR, left_bracket="[", right_bracket="]", + bracket_config={}, **kwargs, ): """ @@ -168,6 +169,9 @@ def __init__( the left bracket type, by default "[" right_bracket : :class:`str`, optional the right bracket type, by default "]" + bracket_config : :class:`dict`, optional + Additional arguments to be passed to :class:`~.MathTex` when constructing + the brackets. """ @@ -187,7 +191,7 @@ def __init__( self.organize_mob_matrix(mob_matrix) self.elements = VGroup(*it.chain(*mob_matrix)) self.add(self.elements) - self.add_brackets(self.left_bracket, self.right_bracket) + self.add_brackets(self.left_bracket, self.right_bracket, **bracket_config) self.center() self.mob_matrix = mob_matrix if self.add_background_rectangles_to_entries: @@ -217,7 +221,7 @@ def organize_mob_matrix(self, matrix): ) return self - def add_brackets(self, left="[", right="]"): + def add_brackets(self, left="[", right="]", **kwargs): """Used internally. Adds the brackets to the Matrix mobject. See Latex document for various bracket types. @@ -235,7 +239,7 @@ def add_brackets(self, left="[", right="]"): The current matrix object (self). """ - bracket_pair = MathTex(left, right) + bracket_pair = MathTex(left, right, **kwargs) bracket_pair.scale(2) bracket_pair.stretch_to_fit_height(self.height + 2 * self.bracket_v_buff) l_bracket, r_bracket = bracket_pair.split() From dc04d4589f59e5d196df92325df25488231c3a51 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 16:39:43 -0400 Subject: [PATCH 04/13] improve typing --- manim/mobject/geometry.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index 6f82c90f0f..eb10698f51 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -68,7 +68,7 @@ def construct(self): import itertools import math import warnings -from typing import Iterable, Optional, Sequence +from typing import TYPE_CHECKING, Iterable, Optional, Sequence import numpy as np from colour import Color @@ -94,6 +94,9 @@ def construct(self): ) from .opengl_compatibility import ConvertToOpenGL +if TYPE_CHECKING: + from .matrix import Matrix + class TipableVMobject(VMobject, metaclass=ConvertToOpenGL): """ @@ -1561,7 +1564,7 @@ def coordinate_label( n_dim: int = 2, color: Optional[Color] = None, **kwargs, - ): + ) -> Matrix: """Creates a label based on the coordinates of the vector. Parameters From 19ffba83dcbb73b2af3521580809a84eb1b6d4c8 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 21:40:57 -0400 Subject: [PATCH 05/13] weird change --- manim/mobject/mobject.py | 71 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index ce691b758d..f9fac8a115 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -180,43 +180,40 @@ def add_animation_override( def set_default(cls, **kwargs): """Sets the default values of keyword arguments. - If this method is called without any additional keyword - arguments, the original default values of the initialization - method of this class are restored. - - Parameters - ---------- - - kwargs - Passing any keyword argument will update the default - values of the keyword arguments of the initialization - function of this class. - - Examples - -------- - - :: - - >>> from manim import Square, GREEN - >>> Square.set_default(color=GREEN, fill_opacity=0.25) - >>> s = Square(); s.color, s.fill_opacity - (, 0.25) - >>> Square.set_default() - >>> s = Square(); s.color, s.fill_opacity - (, 0.0) - - .. manim:: ChangedDefaultTextcolor - :save_last_frame: - - class ChangedDefaultTextcolor(Scene): - def construct(self): - <<<<<<< HEAD - self.camera.background_color - ======= - self.camera.background_color = WHITE - >>>>>>> 6d74f5e0a8599c1db9fa680bc024dae512246a0b - Text.set_default(color=BLACK) - self.add(Text("Changing default values is easy!")) + If this method is called without any additional keyword + arguments, the original default values of the initialization + method of this class are restored. + + Parameters + ---------- + + kwargs + Passing any keyword argument will update the default + values of the keyword arguments of the initialization + function of this class. + + Examples + -------- + + :: + + >>> from manim import Square, GREEN + >>> Square.set_default(color=GREEN, fill_opacity=0.25) + >>> s = Square(); s.color, s.fill_opacity + (, 0.25) + >>> Square.set_default() + >>> s = Square(); s.color, s.fill_opacity + (, 0.0) + + .. manim:: ChangedDefaultTextcolor + :save_last_frame: + + config.background_color = WHITE + + class ChangedDefaultTextcolor(Scene): + def construct(self): + Text.set_default(color=BLACK) + self.add(Text("Changing default values is easy!")) """ if kwargs: From f6894bf399df1100e3a162a55e100df7c2ed1588 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 21:53:36 -0400 Subject: [PATCH 06/13] improve typing + docs --- manim/mobject/matrix.py | 72 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py index 486258fcba..974c2b8802 100644 --- a/manim/mobject/matrix.py +++ b/manim/mobject/matrix.py @@ -38,6 +38,7 @@ def construct(self): import itertools as it +from typing import Iterable, Sequence import numpy as np @@ -126,49 +127,50 @@ def construct(self): def __init__( self, - matrix, - v_buff=0.8, - h_buff=1.3, - bracket_h_buff=MED_SMALL_BUFF, - bracket_v_buff=MED_SMALL_BUFF, - add_background_rectangles_to_entries=False, - include_background_rectangle=False, - element_to_mobject=MathTex, - element_to_mobject_config={}, - element_alignment_corner=DR, - left_bracket="[", - right_bracket="]", - bracket_config={}, + matrix: Iterable, + v_buff: float = 0.8, + h_buff: float = 1.3, + bracket_h_buff: float = MED_SMALL_BUFF, + bracket_v_buff: float = MED_SMALL_BUFF, + add_background_rectangles_to_entries: bool = False, + include_background_rectangle: bool = False, + element_to_mobject: "VMobject" = MathTex, + element_to_mobject_config: dict = {}, + element_alignment_corner: Sequence[float] = DR, + left_bracket: str = "[", + right_bracket: str = "]", + bracket_config: dict = {}, **kwargs, ): """ Parameters ---------- - matrix : :class:`typing.Iterable` - A numpy 2d array or list of lists - v_buff : :class:`float`, optional - vertical buffer, by default 0.8 - h_buff : :class:`float`, optional - horizontal buffer, by default 1.3 - bracket_h_buff : :class:`float`, optional - bracket horizontal buffer, by default MED_SMALL_BUFF - bracket_v_buff : :class:`float`, optional - bracket vertical buffer, by default MED_SMALL_BUFF - add_background_rectangles_to_entries : :class:`bool`, optional - `True` if should add backgraound rectangles to entries, by default False - include_background_rectangle : :class:`bool`, optional - `True` if should include background rectangle, by default False - element_to_mobject : :class:`~.Mobject`, optional - element to mobject, by default MathTex - element_to_mobject_config : Dict[:class:`str`, :class:`~.Mobject`], optional - element to mobject config, by default {} - element_alignment_corner : :class:`np.ndarray`, optional - the element alignment corner, by default DR + matrix + A numpy 2d array or list of lists. + v_buff + Vertical distance between elements, by default 0.8. + h_buff + Horizontal distance between elements, by default 1.3. + bracket_h_buff + Distance of the brackets from the matrix, by default ``MED_SMALL_BUFF``. + bracket_v_buff + Height of the brackets, by default ``MED_SMALL_BUFF``. + add_background_rectangles_to_entries + ``True`` if should add backgraound rectangles to entries, by default ``False``. + include_background_rectangle + ``True`` if should include background rectangle, by default ``False``. + element_to_mobject + The mobject used to construct the elements, by default :class:`~.MathTex`. + element_to_mobject_config + Additional arguments to be passed to the constructor in ``element_to_mobject``, + by default ``{}``. + element_alignment_corner + The corner to which elements are aligned, by default ``DR``. left_bracket : :class:`str`, optional - the left bracket type, by default "[" + The left bracket type, by default ``"["``. right_bracket : :class:`str`, optional - the right bracket type, by default "]" + The right bracket type, by default ``"]"``. bracket_config : :class:`dict`, optional Additional arguments to be passed to :class:`~.MathTex` when constructing the brackets. From 56be7bd9a1af31b5e04717e767f186c39b987417 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 21:56:14 -0400 Subject: [PATCH 07/13] forgot three params --- manim/mobject/matrix.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py index 974c2b8802..4fd1fdd7e8 100644 --- a/manim/mobject/matrix.py +++ b/manim/mobject/matrix.py @@ -167,11 +167,11 @@ def __init__( by default ``{}``. element_alignment_corner The corner to which elements are aligned, by default ``DR``. - left_bracket : :class:`str`, optional + left_bracket The left bracket type, by default ``"["``. - right_bracket : :class:`str`, optional + right_bracket The right bracket type, by default ``"]"``. - bracket_config : :class:`dict`, optional + bracket_config Additional arguments to be passed to :class:`~.MathTex` when constructing the brackets. From 3412307b75151af627ec7535416b8e90e13e0c5b Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 21:59:52 -0400 Subject: [PATCH 08/13] fix TYPE_CHECKING return val --- manim/mobject/geometry.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index eb10698f51..6eb194d10c 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -68,7 +68,7 @@ def construct(self): import itertools import math import warnings -from typing import TYPE_CHECKING, Iterable, Optional, Sequence +from typing import Iterable, Optional, Sequence import numpy as np from colour import Color @@ -94,9 +94,6 @@ def construct(self): ) from .opengl_compatibility import ConvertToOpenGL -if TYPE_CHECKING: - from .matrix import Matrix - class TipableVMobject(VMobject, metaclass=ConvertToOpenGL): """ @@ -1564,7 +1561,7 @@ def coordinate_label( n_dim: int = 2, color: Optional[Color] = None, **kwargs, - ) -> Matrix: + ): """Creates a label based on the coordinates of the vector. Parameters @@ -1594,6 +1591,11 @@ def construct(self): label_2 = vec_2.coordinate_label(color=YELLOW) self.add(plane, vec_1, vec_2, label_1, label_2) + + Returns + ------- + :class:`~.Matrix` + The label. """ # avoiding circular imports from .matrix import Matrix From 47ea453357acec46adadfafd6fe3c498321ec283 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Sat, 2 Oct 2021 22:30:54 -0400 Subject: [PATCH 09/13] label -> color --- manim/mobject/geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index 6eb194d10c..1e8186987b 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -1615,7 +1615,7 @@ def construct(self): shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT label.shift(shift_dir) if color is not None: - label.set_color(label) + label.set_color(color) return label From 85c5cd7a348f94071f53bd7b0ae2321c9e2adbfe Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Mon, 1 Nov 2021 03:19:31 -0400 Subject: [PATCH 10/13] apply suggestions from code review --- manim/mobject/matrix.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py index 4fd1fdd7e8..450dbcd99e 100644 --- a/manim/mobject/matrix.py +++ b/manim/mobject/matrix.py @@ -38,7 +38,7 @@ def construct(self): import itertools as it -from typing import Iterable, Sequence +from typing import Iterable, Sequence, Type import numpy as np @@ -134,7 +134,7 @@ def __init__( bracket_v_buff: float = MED_SMALL_BUFF, add_background_rectangles_to_entries: bool = False, include_background_rectangle: bool = False, - element_to_mobject: "VMobject" = MathTex, + element_to_mobject: Type[MathTex] = MathTex, element_to_mobject_config: dict = {}, element_alignment_corner: Sequence[float] = DR, left_bracket: str = "[", @@ -161,7 +161,7 @@ def __init__( include_background_rectangle ``True`` if should include background rectangle, by default ``False``. element_to_mobject - The mobject used to construct the elements, by default :class:`~.MathTex`. + The mobject class used to construct the elements, by default :class:`~.MathTex`. element_to_mobject_config Additional arguments to be passed to the constructor in ``element_to_mobject``, by default ``{}``. From 1da862728ae7ff9ca7edf420af17340a5916aeef Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Mon, 1 Nov 2021 11:26:19 -0400 Subject: [PATCH 11/13] attempt at fixing duplicated parameters --- manim/mobject/geometry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index 1e8186987b..b02946cdc0 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -1594,6 +1594,7 @@ def construct(self): Returns ------- + :class:`~.Matrix` The label. """ From 62b50252d68a57fac8ccfc98d43d7a664aca4f5d Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Mon, 1 Nov 2021 12:02:45 -0400 Subject: [PATCH 12/13] attempt to fix duplicated paramters pt.2 --- manim/mobject/geometry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index 65ab61de07..bf2fa160f6 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -1568,6 +1568,7 @@ def coordinate_label( Parameters ---------- + integer_labels Whether or not to round the coordinates to integers. n_dim From 9add3ebf8b9be385c021c545719079b6105a93a0 Mon Sep 17 00:00:00 2001 From: hydrobeam Date: Mon, 1 Nov 2021 12:38:44 -0400 Subject: [PATCH 13/13] attempt to fix duplicated paramters pt.3 final --- manim/mobject/geometry.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py index bf2fa160f6..760677a3be 100644 --- a/manim/mobject/geometry.py +++ b/manim/mobject/geometry.py @@ -1568,7 +1568,6 @@ def coordinate_label( Parameters ---------- - integer_labels Whether or not to round the coordinates to integers. n_dim @@ -1597,8 +1596,8 @@ def construct(self): Returns ------- - :class:`~.Matrix` + The label. """ # avoiding circular imports