From 63d1114bb04951c92b72c9f1f6a0e08a9c4e77ad Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Mon, 22 Jun 2020 21:20:02 +0200 Subject: [PATCH 1/7] fixed #101 --- manim/mobject/coordinate_systems.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index 10b2e2dca8..4afc256ed3 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -334,14 +334,10 @@ def get_lines_parallel_to_axis(self, axis1, axis2, freq, ratio): lines1 = VGroup() lines2 = VGroup() - ranges = ( - np.arange(0, axis2.x_max, step), - np.arange(0, axis2.x_min, -step), - ) - for inputs in ranges: - for k, x in enumerate(inputs): + unit_vector_axis_perp_to = axis_perpendicular_to.get_unit_vector() + for k, x in enumerate(np.arange(axis_perpendicular_to.x_min, axis_perpendicular_to.x_max, step)): new_line = line.copy() - new_line.move_to(axis2.number_to_point(x)) + new_line.shift(unit_vector_axis_perp_to * x) if k % (1 + ratio) == 0: lines1.add(new_line) else: From a0db3c4a78bfd07c667817ebb5c607bebf81ed49 Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Mon, 22 Jun 2020 21:20:29 +0200 Subject: [PATCH 2/7] added some docstrings --- manim/mobject/coordinate_systems.py | 44 +++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index 4afc256ed3..bc7576805b 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -288,6 +288,7 @@ def __init__(self, **kwargs): self.init_background_lines() def init_background_lines(self): + """Will init all the lines of NumberPlanes (faded or not)""" if self.faded_line_style is None: style = dict(self.background_line_style) # For anything numerical, like stroke_width @@ -310,6 +311,16 @@ def init_background_lines(self): ) def get_lines(self): + """Generate all the lines, faded and not faded. Two sets of lines are generated, parallel to the X-axis and to Y-axis. + + Returns + ------- + :class:`~.VGroup` + First set of lines (i.e the non faded lines) + + :class:`~.VGroup` + Second set of lines (i.e the faded lines) + """ x_axis = self.get_x_axis() y_axis = self.get_y_axis() x_freq = self.x_line_frequency @@ -327,21 +338,38 @@ def get_lines(self): lines2 = VGroup(*x_lines2, *y_lines2) return lines1, lines2 - def get_lines_parallel_to_axis(self, axis1, axis2, freq, ratio): - line = Line(axis1.get_start(), axis1.get_end()) + def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, freq, ratio): + """Generated a set of lines parallel to an axis. + + Parameters + ---------- + axis_parallel_to : :class:`~.Line` + The axis with which the lines will be parallel. + + axis_perpendicular_to : :class:`~.Line` + The axis with which the lines will be perpendicular. + + Returns + ------- + lines1 : :class:`~.VGroup` + First set of lines (i.e the non faded lines parallel to 'axis_parallel_to') + + lines2 : :class:`~.VGroup` + Second set of lines (i.e the faded lines parallel to 'axis_parallel_to') + """ + line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end()) dense_freq = (1 + ratio) step = (1 / dense_freq) * freq - lines1 = VGroup() lines2 = VGroup() unit_vector_axis_perp_to = axis_perpendicular_to.get_unit_vector() for k, x in enumerate(np.arange(axis_perpendicular_to.x_min, axis_perpendicular_to.x_max, step)): - new_line = line.copy() + new_line = line.copy() new_line.shift(unit_vector_axis_perp_to * x) - if k % (1 + ratio) == 0: - lines1.add(new_line) - else: - lines2.add(new_line) + if k % (1 + ratio) == 0: + lines1.add(new_line) + else: + lines2.add(new_line) return lines1, lines2 def get_center_point(self): From 5eb9fed85dc16f790a84432375d854020a14e750 Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Tue, 23 Jun 2020 09:27:15 +0200 Subject: [PATCH 3/7] fixed minor bug (small shift of the grid) --- manim/mobject/coordinate_systems.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index bc7576805b..845d0d9845 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -363,13 +363,18 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr lines1 = VGroup() lines2 = VGroup() unit_vector_axis_perp_to = axis_perpendicular_to.get_unit_vector() - for k, x in enumerate(np.arange(axis_perpendicular_to.x_min, axis_perpendicular_to.x_max, step)): - new_line = line.copy() - new_line.shift(unit_vector_axis_perp_to * x) - if k % (1 + ratio) == 0: - lines1.add(new_line) - else: - lines2.add(new_line) + ranges = ( + np.arange(0, axis_perpendicular_to.x_max, step), + np.arange(0, axis_perpendicular_to.x_min, -step), + ) + for inputs in ranges: + for k, x in enumerate(inputs): + new_line = line.copy() + new_line.shift(unit_vector_axis_perp_to * x) + if k % (1 + ratio) == 0: + lines1.add(new_line) + else: + lines2.add(new_line) return lines1, lines2 def get_center_point(self): From 249e8e87a6fb510630451cace6966d55786026ef Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:19:45 +0200 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Pg Biel <9021226+PgBiel@users.noreply.github.com> --- manim/mobject/coordinate_systems.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index 845d0d9845..6a3ced6ed6 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -315,11 +315,8 @@ def get_lines(self): Returns ------- - :class:`~.VGroup` - First set of lines (i.e the non faded lines) - - :class:`~.VGroup` - Second set of lines (i.e the faded lines) + Tuple[:class:`~.VGroup`, :class:`~.VGroup`] + The first (i.e the non faded lines) and second (i.e the faded lines) sets of lines, respectively. """ x_axis = self.get_x_axis() y_axis = self.get_y_axis() @@ -339,7 +336,7 @@ def get_lines(self): return lines1, lines2 def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, freq, ratio): - """Generated a set of lines parallel to an axis. + """Generate a set of lines parallel to an axis. Parameters ---------- @@ -351,11 +348,8 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr Returns ------- - lines1 : :class:`~.VGroup` - First set of lines (i.e the non faded lines parallel to 'axis_parallel_to') - - lines2 : :class:`~.VGroup` - Second set of lines (i.e the faded lines parallel to 'axis_parallel_to') + Tuple[:class:`~.VGroup`, :class:`~.VGroup`] + The first (i.e the non faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively. """ line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end()) dense_freq = (1 + ratio) @@ -458,4 +452,4 @@ def get_coordinate_labels(self, *numbers, **kwargs): def add_coordinates(self, *numbers): self.add(self.get_coordinate_labels(*numbers)) - return self \ No newline at end of file + return self From d7615a621ccfdfe8e4cf1f652eb3b79782abf7bd Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:49:43 +0200 Subject: [PATCH 5/7] improved doc for clarity --- manim/mobject/coordinate_systems.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index 6a3ced6ed6..800e003fb5 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -335,7 +335,7 @@ def get_lines(self): lines2 = VGroup(*x_lines2, *y_lines2) return lines1, lines2 - def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, freq, ratio): + def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, freq, ratio_faded_lines): """Generate a set of lines parallel to an axis. Parameters @@ -344,7 +344,13 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr The axis with which the lines will be parallel. axis_perpendicular_to : :class:`~.Line` - The axis with which the lines will be perpendicular. + The axis with which the lines will be perpendicular. + + ratio_faded_lines : :class:`float` + The number of faded lines between each non-faded line. + + freq : :class:`float` + Frequence of non-faded lines (number of non-faded lines per graph unit). Returns ------- @@ -352,7 +358,7 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr The first (i.e the non faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively. """ line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end()) - dense_freq = (1 + ratio) + dense_freq = (1 + ratio_faded_lines) step = (1 / dense_freq) * freq lines1 = VGroup() lines2 = VGroup() @@ -365,7 +371,7 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr for k, x in enumerate(inputs): new_line = line.copy() new_line.shift(unit_vector_axis_perp_to * x) - if k % (1 + ratio) == 0: + if k % (1 + ratio_faded_lines) == 0: lines1.add(new_line) else: lines2.add(new_line) From b9b579366a68be810717b26a551b75c9ddddad43 Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:52:11 +0200 Subject: [PATCH 6/7] fixed minor bug (wrong number of faded lines) --- manim/mobject/coordinate_systems.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index 800e003fb5..e4168d3885 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -358,7 +358,7 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr The first (i.e the non faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively. """ line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end()) - dense_freq = (1 + ratio_faded_lines) + dense_freq = ratio_faded_lines step = (1 / dense_freq) * freq lines1 = VGroup() lines2 = VGroup() @@ -371,7 +371,7 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr for k, x in enumerate(inputs): new_line = line.copy() new_line.shift(unit_vector_axis_perp_to * x) - if k % (1 + ratio_faded_lines) == 0: + if k % ratio_faded_lines == 0: lines1.add(new_line) else: lines2.add(new_line) From 353ca9dcc0eedf2df875120b2fd05ecb63766381 Mon Sep 17 00:00:00 2001 From: Hugues Devimeux <36239975+huguesdevimeux@users.noreply.github.com> Date: Tue, 7 Jul 2020 17:56:37 +0200 Subject: [PATCH 7/7] fixed typo --- manim/mobject/coordinate_systems.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py index e4168d3885..3b2b9466f5 100644 --- a/manim/mobject/coordinate_systems.py +++ b/manim/mobject/coordinate_systems.py @@ -311,7 +311,7 @@ def init_background_lines(self): ) def get_lines(self): - """Generate all the lines, faded and not faded. Two sets of lines are generated, parallel to the X-axis and to Y-axis. + """Generate all the lines, faded and not faded. Two sets of lines are generated: one parallel to the X-axis, and parallel to the Y-axis. Returns ------- @@ -350,12 +350,12 @@ def get_lines_parallel_to_axis(self, axis_parallel_to, axis_perpendicular_to, fr The number of faded lines between each non-faded line. freq : :class:`float` - Frequence of non-faded lines (number of non-faded lines per graph unit). + Frequency of non-faded lines (number of non-faded lines per graph unit). Returns ------- Tuple[:class:`~.VGroup`, :class:`~.VGroup`] - The first (i.e the non faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively. + The first (i.e the non-faded lines parallel to `axis_parallel_to`) and second (i.e the faded lines parallel to `axis_parallel_to`) sets of lines, respectively. """ line = Line(axis_parallel_to.get_start(), axis_parallel_to.get_end()) dense_freq = ratio_faded_lines