Skip to content

Commit 9699727

Browse files
kolibril13jsonvillanuevapre-commit-ci[bot]
authored
Added futher docstrings and typehints to :class:~.Mobject (#1301)
* added docstings * added link * Apply suggestions from code review Co-authored-by: Jason Villanueva <[email protected]> * Update manim/mobject/mobject.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added more missing punctuation Co-authored-by: Jason Villanueva <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 01cd85a commit 9699727

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

manim/mobject/mobject.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class Mobject(Container):
5858
points : :class:`numpy.ndarray`
5959
The points of the objects.
6060
61+
.. seealso::
62+
63+
:class:`~.VMobject`
64+
6165
"""
6266

6367
def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0, **kwargs):
@@ -1755,9 +1759,11 @@ def get_critical_point(self, direction):
17551759
# Pseudonyms for more general get_critical_point method
17561760

17571761
def get_edge_center(self, direction) -> np.ndarray:
1762+
"""Get edge coordinates for certain direction."""
17581763
return self.get_critical_point(direction)
17591764

17601765
def get_corner(self, direction) -> np.ndarray:
1766+
"""Get corner coordinates for certain direction."""
17611767
return self.get_critical_point(direction)
17621768

17631769
def get_center(self) -> np.ndarray:
@@ -1788,10 +1794,12 @@ def get_left(self) -> np.ndarray:
17881794
"""Get left coordinates of a box bounding the :class:`~.Mobject`"""
17891795
return self.get_edge_center(LEFT)
17901796

1791-
def get_zenith(self):
1797+
def get_zenith(self) -> np.ndarray:
1798+
"""Get zenith coordinates of a box bounding a 3D :class:`~.Mobject`."""
17921799
return self.get_edge_center(OUT)
17931800

1794-
def get_nadir(self):
1801+
def get_nadir(self) -> np.ndarray:
1802+
"""Get nadir (opposite the zenith) coordinates of a box bounding a 3D :class:`~.Mobject`."""
17951803
return self.get_edge_center(IN)
17961804

17971805
def length_over_dim(self, dim):
@@ -1855,31 +1863,38 @@ def get_z_index_reference_point(self):
18551863
z_index_group = getattr(self, "z_index_group", self)
18561864
return z_index_group.get_center()
18571865

1858-
def has_points(self):
1866+
def has_points(self) -> bool:
18591867
"""Check if :class:`~.Mobject` contains points. """
18601868
return len(self.points) > 0
18611869

1862-
def has_no_points(self):
1870+
def has_no_points(self) -> bool:
1871+
"""Check if :class:`~.Mobject` *does not* contains points."""
18631872
return not self.has_points()
18641873

18651874
# Match other mobject properties
18661875

18671876
def match_color(self, mobject: "Mobject"):
1877+
"""Match the color with the color of another :class:`~.Mobject`."""
18681878
return self.set_color(mobject.get_color())
18691879

18701880
def match_dim_size(self, mobject: "Mobject", dim, **kwargs):
1881+
"""Match the specified dimension with the dimension of another :class:`~.Mobject`."""
18711882
return self.rescale_to_fit(mobject.length_over_dim(dim), dim, **kwargs)
18721883

18731884
def match_width(self, mobject: "Mobject", **kwargs):
1885+
"""Match the width with the width of another :class:`~.Mobject`."""
18741886
return self.match_dim_size(mobject, 0, **kwargs)
18751887

18761888
def match_height(self, mobject: "Mobject", **kwargs):
1889+
"""Match the height with the height of another :class:`~.Mobject`."""
18771890
return self.match_dim_size(mobject, 1, **kwargs)
18781891

18791892
def match_depth(self, mobject: "Mobject", **kwargs):
1893+
"""Match the depth with the depth of another :class:`~.Mobject`."""
18801894
return self.match_dim_size(mobject, 2, **kwargs)
18811895

18821896
def match_coord(self, mobject: "Mobject", dim, direction=ORIGIN):
1897+
"""Match the coordinates with the coordinates of another :class:`~.Mobject`."""
18831898
return self.set_coord(
18841899
mobject.get_coord(dim, direction),
18851900
dim=dim,
@@ -1890,7 +1905,7 @@ def match_x(self, mobject: "Mobject", direction=ORIGIN):
18901905
"""Match x coord. to the x coord. of another :class:`~.Mobject`."""
18911906
return self.match_coord(mobject, 0, direction)
18921907

1893-
def Match_y(self, mobject: "Mobject", direction=ORIGIN):
1908+
def match_y(self, mobject: "Mobject", direction=ORIGIN):
18941909
"""Match y coord. to the x coord. of another :class:`~.Mobject`."""
18951910
return self.match_coord(mobject, 1, direction)
18961911

@@ -1904,7 +1919,9 @@ def align_to(
19041919
direction=ORIGIN,
19051920
alignment_vect=UP,
19061921
):
1907-
"""Examples:
1922+
"""Aligns mobject to another :class:`~.Mobject` in a certain direction.
1923+
1924+
Examples:
19081925
mob1.align_to(mob2, UP) moves mob1 vertically so that its
19091926
top edge lines ups with mob2's top edge.
19101927
@@ -1989,6 +2006,21 @@ def construct(self):
19892006
return self
19902007

19912008
def arrange_in_grid(self, n_rows=None, n_cols=None, **kwargs):
2009+
"""Sorts :class:`~.Mobject` next to each other on screen using a grid.
2010+
2011+
Examples
2012+
--------
2013+
2014+
.. manim:: ArrangeExample
2015+
:save_last_frame:
2016+
2017+
class ArrangeExample(Scene):
2018+
def construct(self):
2019+
self.add(*[Square(color= random_bright_color()) for i in range(0,5)])
2020+
x = VGroup(*self.mobjects).arrange_in_grid(buff=0.2)
2021+
self.add(x)
2022+
"""
2023+
19922024
submobs = self.submobjects
19932025
if n_rows is None and n_cols is None:
19942026
n_cols = int(np.sqrt(len(submobs)))
@@ -2010,12 +2042,14 @@ def arrange_in_grid(self, n_rows=None, n_cols=None, **kwargs):
20102042
return self
20112043

20122044
def sort(self, point_to_num_func=lambda p: p[0], submob_func=None):
2045+
"""Sorts the list of :attr:`submobjects` by a function defined by ``submob_func``."""
20132046
if submob_func is None:
20142047
submob_func = lambda m: point_to_num_func(m.get_center())
20152048
self.submobjects.sort(key=submob_func)
20162049
return self
20172050

20182051
def shuffle(self, recursive=False):
2052+
"""Shuffles the list of :attr:`submobjects`."""
20192053
if recursive:
20202054
for submob in self.submobjects:
20212055
submob.shuffle(recursive=True)

0 commit comments

Comments
 (0)