From 5c3fa84b7bb587f760e892983ecf0004d6b4e4ea Mon Sep 17 00:00:00 2001 From: chopan Date: Sat, 8 Jul 2023 02:06:27 -0400 Subject: [PATCH 01/18] Modified NumberLine to optimize number_to_point --- manim/mobject/graphing/number_line.py | 60 +++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 08f6ef48fa..879a151e37 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -23,7 +23,6 @@ from manim.mobject.types.vectorized_mobject import VGroup, VMobject from manim.utils.bezier import interpolate from manim.utils.config_ops import merge_dicts_recursively -from manim.utils.space_ops import normalize class NumberLine(Line): @@ -187,6 +186,8 @@ def __init__( # turn into a NumPy array to scale by just applying the function self.x_range = np.array(x_range, dtype=float) self.x_min, self.x_max, self.x_step = scaling.function(self.x_range) + self.x_min_no_tips = self.x_min + self.x_max_no_tips = self.x_max self.length = length self.unit_size = unit_size # ticks @@ -264,6 +265,48 @@ def __init__( font_size=self.font_size, ) + def add_tip( + self, tip=None, tip_shape=None, tip_length=None, tip_width=None, at_start=False + ): + """Wrapper for TipableVMobject.add_tip. + + Adds a tip to the NumberLine, and recalculates x_min and x_max + from the new line component without its tips, storing the new + values in x_min_no_tips and x_max_no_tips. + """ + old_start = self.points[0].copy() + old_end = self.points[-1].copy() + super().add_tip(tip, tip_shape, tip_length, tip_width, at_start) + new_start = self.points[0] + new_end = self.points[-1] + + direction = old_end - old_start + new_start_proportion = np.dot(new_start - old_start, direction) / np.dot( + direction, direction + ) + new_end_proportion = np.dot(new_end - old_start, direction) / np.dot( + direction, direction + ) + + self.x_min_no_tips = self.x_min + new_start_proportion * ( + self.x_max - self.x_min + ) + self.x_max_no_tips = self.x_min + new_end_proportion * (self.x_max - self.x_min) + + return self + + def pop_tips(self): + """Wrapper for TipableVMobject.pop_tips. + + After removing the tips from NumberLine, x_min_no_tips and x_max_no_tips + are reset to their original values: x_min and x_max. Then, pop_tips + returns the removed tips. + """ + result = super().pop_tips() + self.x_min_no_tips = self.x_min + self.x_max_no_tips = self.x_max + return result + def rotate_about_zero(self, angle: float, axis: Sequence[float] = OUT, **kwargs): return self.rotate_about_number(0, angle, axis, **kwargs) @@ -370,9 +413,11 @@ def number_to_point(self, number: float | np.ndarray) -> np.ndarray: number = np.asarray(number) scalar = number.ndim == 0 number = self.scaling.inverse_function(number) - alphas = (number - self.x_range[0]) / (self.x_range[1] - self.x_range[0]) - alphas = float(alphas) if scalar else np.vstack(alphas) - val = interpolate(self.get_start(), self.get_end(), alphas) + alphas = (number - self.x_min_no_tips) / ( + self.x_max_no_tips - self.x_min_no_tips + ) + alphas = float(alphas) if scalar else alphas.reshape(-1, 1) + val = interpolate(self.points[0], self.points[-1], alphas) return val def point_to_number(self, point: Sequence[float]) -> float: @@ -403,9 +448,10 @@ def point_to_number(self, point: Sequence[float]) -> float: """ point = np.asarray(point) - start, end = self.get_start_and_end() - unit_vect = normalize(end - start) - proportion = np.dot(point - start, unit_vect) / np.dot(end - start, unit_vect) + start = self.points[0] + end = self.points[-1] + direction = end - start + proportion = np.dot(point - start, direction) / np.dot(direction, direction) return interpolate(self.x_min, self.x_max, proportion) def n2p(self, number: float | np.ndarray) -> np.ndarray: From 637110a60913fab93ce5b29e09dd9c8a3c2a3368 Mon Sep 17 00:00:00 2001 From: chopan Date: Sat, 8 Jul 2023 13:10:52 -0400 Subject: [PATCH 02/18] Modified NumberLine's point_to_number and get_unit_size --- manim/mobject/graphing/number_line.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 879a151e37..13c1dc8d27 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -452,7 +452,7 @@ def point_to_number(self, point: Sequence[float]) -> float: end = self.points[-1] direction = end - start proportion = np.dot(point - start, direction) / np.dot(direction, direction) - return interpolate(self.x_min, self.x_max, proportion) + return interpolate(self.x_min_no_tips, self.x_max_no_tips, proportion) def n2p(self, number: float | np.ndarray) -> np.ndarray: """Abbreviation for :meth:`~.NumberLine.number_to_point`.""" @@ -463,7 +463,9 @@ def p2n(self, point: Sequence[float]) -> float: return self.point_to_number(point) def get_unit_size(self) -> float: - return self.get_length() / (self.x_range[1] - self.x_range[0]) + return (self.points[-1] - self.points[0]) / ( + self.x_max_no_tip - self.x_min_no_tip + ) def get_unit_vector(self) -> np.ndarray: return super().get_unit_vector() * self.unit_size From 858927ea28f8b22a0c13912f969e101cb57bad10 Mon Sep 17 00:00:00 2001 From: chopan Date: Sat, 8 Jul 2023 13:12:54 -0400 Subject: [PATCH 03/18] Modified NumberLine's add_numbers and add_labels to avoid repeated calling of VGroup.add --- manim/mobject/graphing/number_line.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 13c1dc8d27..ee62900214 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -572,18 +572,18 @@ def add_numbers( if label_constructor is None: label_constructor = self.label_constructor - numbers = VGroup() - for x in x_values: - if x in excluding: - continue - numbers.add( + numbers = VGroup( + *[ self.get_number_mobject( x, font_size=font_size, label_constructor=label_constructor, **kwargs, ) - ) + for x in x_values + if x not in excluding + ] + ) self.add(numbers) self.numbers = numbers return self @@ -628,7 +628,7 @@ def add_labels( if label_constructor is None: label_constructor = self.label_constructor - labels = VGroup() + labels = [] for x, label in dict_values.items(): # TODO: remove this check and ability to call # this method via CoordinateSystem.add_coordinates() @@ -643,8 +643,9 @@ def add_labels( else: raise AttributeError(f"{label} is not compatible with add_labels.") label.next_to(self.number_to_point(x), direction=direction, buff=buff) - labels.add(label) + labels.append(label) + labels = VGroup(*labels) self.labels = labels self.add(labels) return self From 8aad111cfa4aaa02bcff0dfe1f9ce6f4bc584e29 Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 16:36:09 -0400 Subject: [PATCH 04/18] Added UnitLinearScale and fixed variable name typos --- manim/mobject/graphing/number_line.py | 6 +++--- manim/mobject/graphing/scale.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index ee62900214..36a3f547ae 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -17,7 +17,7 @@ from manim import config from manim.constants import * from manim.mobject.geometry.line import Line -from manim.mobject.graphing.scale import LinearBase, _ScaleBase +from manim.mobject.graphing.scale import UnitLinearBase, _ScaleBase from manim.mobject.text.numbers import DecimalNumber from manim.mobject.text.tex_mobject import MathTex, Tex from manim.mobject.types.vectorized_mobject import VGroup, VMobject @@ -155,7 +155,7 @@ def __init__( font_size: float = 36, label_direction: Sequence[float] = DOWN, label_constructor: VMobject = MathTex, - scaling: _ScaleBase = LinearBase(), + scaling: _ScaleBase = UnitLinearBase(), line_to_number_buff: float = MED_SMALL_BUFF, decimal_number_config: dict | None = None, numbers_to_exclude: Iterable[float] | None = None, @@ -464,7 +464,7 @@ def p2n(self, point: Sequence[float]) -> float: def get_unit_size(self) -> float: return (self.points[-1] - self.points[0]) / ( - self.x_max_no_tip - self.x_min_no_tip + self.x_max_no_tips - self.x_min_no_tips ) def get_unit_vector(self) -> np.ndarray: diff --git a/manim/mobject/graphing/scale.py b/manim/mobject/graphing/scale.py index e1f88398a1..3323f5b30b 100644 --- a/manim/mobject/graphing/scale.py +++ b/manim/mobject/graphing/scale.py @@ -114,6 +114,33 @@ def inverse_function(self, value: float) -> float: return value / self.scale_factor +class UnitLinearBase(LinearBase): + def __init__(self): + """The default scaling class.""" + + super().__init__(scale_factor=1.0) + + def function(self, value: float) -> float: + """Multiplies the value by 1.0, i.e. returns the value as is. + + Parameters + ---------- + value + Value to be multiplied by the scale factor. + """ + return value + + def inverse_function(self, value: float) -> float: + """Inverse of function. Divides the value by 1.0, i.e. returns the value as is. + + Parameters + ---------- + value + value to be divided by the scale factor. + """ + return value + + class LogBase(_ScaleBase): def __init__(self, base: float = 10, custom_labels: bool = True): """Scale for logarithmic graphs/functions. From 57bafc235e36c213e63301bd72c0b51170d36b7d Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 17:41:11 -0400 Subject: [PATCH 05/18] Fixed NumberLine's get_unit_vector and get_unit_size --- manim/mobject/graphing/number_line.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 36a3f547ae..69cd9dd08d 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -12,6 +12,8 @@ if TYPE_CHECKING: from manim.mobject.geometry.tips import ArrowTip +from math import sqrt + import numpy as np from manim import config @@ -463,13 +465,14 @@ def p2n(self, point: Sequence[float]) -> float: return self.point_to_number(point) def get_unit_size(self) -> float: + v = self.get_unit_vector() + return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) + + def get_unit_vector(self) -> np.ndarray: return (self.points[-1] - self.points[0]) / ( self.x_max_no_tips - self.x_min_no_tips ) - def get_unit_vector(self) -> np.ndarray: - return super().get_unit_vector() * self.unit_size - def get_number_mobject( self, x: float, From 67837334989495d5607953d742fb0d6292fd5e63 Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 18:18:25 -0400 Subject: [PATCH 06/18] Fixed NumberLine.n2p when using LogBase --- manim/mobject/graphing/number_line.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 69cd9dd08d..cc4fc62127 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -188,6 +188,7 @@ def __init__( # turn into a NumPy array to scale by just applying the function self.x_range = np.array(x_range, dtype=float) self.x_min, self.x_max, self.x_step = scaling.function(self.x_range) + self.x_range_no_tips = self.x_range.copy() self.x_min_no_tips = self.x_min self.x_max_no_tips = self.x_max self.length = length @@ -290,10 +291,10 @@ def add_tip( direction, direction ) - self.x_min_no_tips = self.x_min + new_start_proportion * ( - self.x_max - self.x_min - ) - self.x_max_no_tips = self.x_min + new_end_proportion * (self.x_max - self.x_min) + x_max, x_min, _ = self.x_range_no_tips + self.x_range_no_tips[0] = x_min + new_start_proportion * (x_max - x_min) + self.x_range_no_tips[1] = x_max + new_start_proportion * (x_max - x_min) + self.x_min_no_tips, self.x_max_no_tips, _ = self.x_range_no_tips return self @@ -305,6 +306,7 @@ def pop_tips(self): returns the removed tips. """ result = super().pop_tips() + self.x_range_no_tips[:] = self.x_range self.x_min_no_tips = self.x_min self.x_max_no_tips = self.x_max return result @@ -412,12 +414,16 @@ def number_to_point(self, number: float | np.ndarray) -> np.ndarray: [2., 0., 0.], [3., 0., 0.]]) """ + print(self.x_range_no_tips) + print(self.x_min_no_tips) + print(self.x_max_no_tips) number = np.asarray(number) scalar = number.ndim == 0 number = self.scaling.inverse_function(number) - alphas = (number - self.x_min_no_tips) / ( - self.x_max_no_tips - self.x_min_no_tips - ) + print("Number(s):", number) + x_min, x_max, _ = self.x_range_no_tips + alphas = (number - x_min) / (x_max - x_min) + print("Alpha(s): ", alphas) alphas = float(alphas) if scalar else alphas.reshape(-1, 1) val = interpolate(self.points[0], self.points[-1], alphas) return val From 01ec9c5c1dfd75aadaa8ee4bc0a7311692d545fe Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 18:20:44 -0400 Subject: [PATCH 07/18] Fixed scaling in NumberLine.add_tips --- manim/mobject/graphing/number_line.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index cc4fc62127..2f5320b00d 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -294,7 +294,9 @@ def add_tip( x_max, x_min, _ = self.x_range_no_tips self.x_range_no_tips[0] = x_min + new_start_proportion * (x_max - x_min) self.x_range_no_tips[1] = x_max + new_start_proportion * (x_max - x_min) - self.x_min_no_tips, self.x_max_no_tips, _ = self.x_range_no_tips + self.x_min_no_tips, self.x_max_no_tips, _ = self.scaling.function( + self.x_range_no_tips + ) return self From 12b1eb178b2fc129f7e18c2ccc5bb4006478dfe0 Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 18:23:56 -0400 Subject: [PATCH 08/18] Fixed NumberLine.get_unit_vector when using LogBase --- manim/mobject/graphing/number_line.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 2f5320b00d..f66362e914 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -416,16 +416,11 @@ def number_to_point(self, number: float | np.ndarray) -> np.ndarray: [2., 0., 0.], [3., 0., 0.]]) """ - print(self.x_range_no_tips) - print(self.x_min_no_tips) - print(self.x_max_no_tips) number = np.asarray(number) scalar = number.ndim == 0 number = self.scaling.inverse_function(number) - print("Number(s):", number) - x_min, x_max, _ = self.x_range_no_tips - alphas = (number - x_min) / (x_max - x_min) - print("Alpha(s): ", alphas) + range_min, range_max, _ = self.x_range_no_tips + alphas = (number - range_min) / (range_max - range_min) alphas = float(alphas) if scalar else alphas.reshape(-1, 1) val = interpolate(self.points[0], self.points[-1], alphas) return val @@ -477,9 +472,8 @@ def get_unit_size(self) -> float: return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) def get_unit_vector(self) -> np.ndarray: - return (self.points[-1] - self.points[0]) / ( - self.x_max_no_tips - self.x_min_no_tips - ) + range_min, range_max, _ = self.x_range_no_tips + return (self.points[-1] - self.points[0]) / (range_max - range_min) def get_number_mobject( self, From 1b02f0349fd01e4233f3b71ea873df86f37deed8 Mon Sep 17 00:00:00 2001 From: chopan Date: Wed, 12 Jul 2023 18:32:09 -0400 Subject: [PATCH 09/18] Fixed NumberLine.add_tip finally --- manim/mobject/graphing/number_line.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index f66362e914..2c9340d4d9 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -284,16 +284,14 @@ def add_tip( new_end = self.points[-1] direction = old_end - old_start - new_start_proportion = np.dot(new_start - old_start, direction) / np.dot( - direction, direction - ) - new_end_proportion = np.dot(new_end - old_start, direction) / np.dot( - direction, direction - ) + length2 = np.dot(direction, direction) + new_start_proportion = np.dot(new_start - old_start, direction) / length2 + new_end_proportion = np.dot(new_end - old_start, direction) / length2 - x_max, x_min, _ = self.x_range_no_tips - self.x_range_no_tips[0] = x_min + new_start_proportion * (x_max - x_min) - self.x_range_no_tips[1] = x_max + new_start_proportion * (x_max - x_min) + range_min, range_max, _ = self.x_range_no_tips + diff = range_max - range_min + self.x_range_no_tips[0] = range_min + new_start_proportion * diff + self.x_range_no_tips[1] = range_min + new_end_proportion * diff self.x_min_no_tips, self.x_max_no_tips, _ = self.scaling.function( self.x_range_no_tips ) From a0572285b40fd32d0b2f075534f2c64b5c5b225a Mon Sep 17 00:00:00 2001 From: chopan Date: Thu, 13 Jul 2023 13:51:57 -0400 Subject: [PATCH 10/18] Added UnitLinearScale to scale.py's __all__ --- manim/mobject/graphing/scale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/graphing/scale.py b/manim/mobject/graphing/scale.py index 3323f5b30b..401230d545 100644 --- a/manim/mobject/graphing/scale.py +++ b/manim/mobject/graphing/scale.py @@ -5,7 +5,7 @@ import numpy as np -__all__ = ["LogBase", "LinearBase"] +__all__ = ["LogBase", "LinearBase", "UnitLinearBase"] from manim.mobject.text.numbers import Integer From 94f394c41827b4e17864663a95c89049147b4b7d Mon Sep 17 00:00:00 2001 From: chopan Date: Thu, 13 Jul 2023 14:35:44 -0400 Subject: [PATCH 11/18] Updated commentaries in NumberLine's add_tip and pop_tips --- manim/mobject/graphing/number_line.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 2c9340d4d9..3c04ae01be 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -273,9 +273,10 @@ def add_tip( ): """Wrapper for TipableVMobject.add_tip. - Adds a tip to the NumberLine, and recalculates x_min and x_max - from the new line component without its tips, storing the new - values in x_min_no_tips and x_max_no_tips. + Adds a tip to the NumberLine, and recalculates the range of the portion of + the new line component excluding its tips, storing the new range in + self.x_range_no_tips. This also calculates a new min and max, and stores + their values in self.x_min_no_tips and self.x_max_no_tips. """ old_start = self.points[0].copy() old_end = self.points[-1].copy() @@ -301,9 +302,9 @@ def add_tip( def pop_tips(self): """Wrapper for TipableVMobject.pop_tips. - After removing the tips from NumberLine, x_min_no_tips and x_max_no_tips - are reset to their original values: x_min and x_max. Then, pop_tips - returns the removed tips. + After removing the tips from NumberLine, x_range_no_tips, x_min_no_tips and + x_max_no_tips are reset to their original values: x_range, x_min and x_max. + Then, pop_tips returns the removed tips. """ result = super().pop_tips() self.x_range_no_tips[:] = self.x_range From 7ea490d0209404cffb603285bd35c1df46ec5e80 Mon Sep 17 00:00:00 2001 From: MrDiver Date: Sat, 5 Aug 2023 02:03:22 +0200 Subject: [PATCH 12/18] Adding new test data for get_lines_to_point in test_axes --- .../control_data/plot/get_lines_to_point.npz | Bin 7092 -> 7155 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/test_graphical_units/control_data/plot/get_lines_to_point.npz b/tests/test_graphical_units/control_data/plot/get_lines_to_point.npz index d65208f03ee3f3392840940e7b11707e38b5138f..8fec243f13320869be7b75daa1e8821c848d1d20 100644 GIT binary patch literal 7155 zcmdT}c~n!^x(`L=UafLp6|F@;>r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{8m)OBH&0Meel|Cv{r3{p` zIkppLyX$-7(GeR+{_{7_Ivza8VPX9$2Jy(rEi95!MhU9X7{b34v1E1mML1J?Urq*n z!b*gM+kpa2KjF!dkcQuuILPmR5u|$hc1Ms(VP|_wYL194DDp!FI(o)S5E`#B6nWG` z9Xfxa@m-SK(?Rx2eygHwvNuTeIuY&85p4B2&WWF12DcE|T1&Qws^BOL2j^S!xCn<- z@JiH-)!8iyic&vAYU4d=AreIcmZ+B>KrJ{Q)n{7?hisCFJ?=;KQJ+X(dV|4Gx-A_L zz=`hqo+M(7%T;0w6CC>B9G6(f1;yV?uPzl7d=H>uO%ic#@Kfm&64Z3RFF|bwb^pJq z{e}F}@*@TwinmwH zd-?18QdOM{t6rQbI*Y7utGh|Dmy6~#R!Q89!cmI~D2Z+hpR0(1sE#K0HfkC@+jg^v zg4`^6OHJbrv>Ns$ieTVL?7!x**Z8HA`HbmMr}Qyi5E0@7Vrg;{}jtuwT7#b9Gw20{V6d__qh+x7xREe*%IZ BO(y^V From 974d19c9ed4f6ea8fef896fecd6b247446cd29ef Mon Sep 17 00:00:00 2001 From: chopan Date: Sat, 9 Dec 2023 22:00:03 +0100 Subject: [PATCH 13/18] Added rounding to 15 decimals at the end of n2p --- manim/mobject/graphing/number_line.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index d31d42820e..2ea3648207 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -388,7 +388,9 @@ def get_tick_range(self) -> np.ndarray: return self.scaling.function(tick_range) - def number_to_point(self, number: float | np.ndarray) -> np.ndarray: + def number_to_point( + self, number: float | np.ndarray, decimals: int = 15 + ) -> np.ndarray: """Accepts a value along the number line and returns a point with respect to the scene. @@ -423,7 +425,7 @@ def number_to_point(self, number: float | np.ndarray) -> np.ndarray: alphas = (number - range_min) / (range_max - range_min) alphas = float(alphas) if scalar else alphas.reshape(-1, 1) val = interpolate(self.points[0], self.points[-1], alphas) - return val + return np.around(val, decimals) def point_to_number(self, point: Sequence[float]) -> float: """Accepts a point with respect to the scene and returns From 8e8d1d6ff5e06d1cf5a2abb857ac4468bcbbbd95 Mon Sep 17 00:00:00 2001 From: chopan Date: Sat, 9 Dec 2023 23:40:32 +0100 Subject: [PATCH 14/18] Reverted calculation of line ends to previous state --- manim/mobject/graphing/number_line.py | 73 ++++----------------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 2ea3648207..a9745daabc 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -188,9 +188,6 @@ def __init__( # turn into a NumPy array to scale by just applying the function self.x_range = np.array(x_range, dtype=float) self.x_min, self.x_max, self.x_step = scaling.function(self.x_range) - self.x_range_no_tips = self.x_range.copy() - self.x_min_no_tips = self.x_min - self.x_max_no_tips = self.x_max self.length = length self.unit_size = unit_size # ticks @@ -268,50 +265,6 @@ def __init__( font_size=self.font_size, ) - def add_tip( - self, tip=None, tip_shape=None, tip_length=None, tip_width=None, at_start=False - ): - """Wrapper for TipableVMobject.add_tip. - - Adds a tip to the NumberLine, and recalculates the range of the portion of - the new line component excluding its tips, storing the new range in - self.x_range_no_tips. This also calculates a new min and max, and stores - their values in self.x_min_no_tips and self.x_max_no_tips. - """ - old_start = self.points[0].copy() - old_end = self.points[-1].copy() - super().add_tip(tip, tip_shape, tip_length, tip_width, at_start) - new_start = self.points[0] - new_end = self.points[-1] - - direction = old_end - old_start - length2 = np.dot(direction, direction) - new_start_proportion = np.dot(new_start - old_start, direction) / length2 - new_end_proportion = np.dot(new_end - old_start, direction) / length2 - - range_min, range_max, _ = self.x_range_no_tips - diff = range_max - range_min - self.x_range_no_tips[0] = range_min + new_start_proportion * diff - self.x_range_no_tips[1] = range_min + new_end_proportion * diff - self.x_min_no_tips, self.x_max_no_tips, _ = self.scaling.function( - self.x_range_no_tips - ) - - return self - - def pop_tips(self): - """Wrapper for TipableVMobject.pop_tips. - - After removing the tips from NumberLine, x_range_no_tips, x_min_no_tips and - x_max_no_tips are reset to their original values: x_range, x_min and x_max. - Then, pop_tips returns the removed tips. - """ - result = super().pop_tips() - self.x_range_no_tips[:] = self.x_range - self.x_min_no_tips = self.x_min - self.x_max_no_tips = self.x_max - return result - def rotate_about_zero(self, angle: float, axis: Sequence[float] = OUT, **kwargs): return self.rotate_about_number(0, angle, axis, **kwargs) @@ -388,9 +341,7 @@ def get_tick_range(self) -> np.ndarray: return self.scaling.function(tick_range) - def number_to_point( - self, number: float | np.ndarray, decimals: int = 15 - ) -> np.ndarray: + def number_to_point(self, number: float | np.ndarray) -> np.ndarray: """Accepts a value along the number line and returns a point with respect to the scene. @@ -421,11 +372,10 @@ def number_to_point( number = np.asarray(number) scalar = number.ndim == 0 number = self.scaling.inverse_function(number) - range_min, range_max, _ = self.x_range_no_tips - alphas = (number - range_min) / (range_max - range_min) + alphas = (number - self.x_range[0]) / (self.x_range[1] - self.x_range[0]) alphas = float(alphas) if scalar else alphas.reshape(-1, 1) - val = interpolate(self.points[0], self.points[-1], alphas) - return np.around(val, decimals) + val = interpolate(self.get_start(), self.get_end(), alphas) + return val def point_to_number(self, point: Sequence[float]) -> float: """Accepts a point with respect to the scene and returns @@ -455,11 +405,10 @@ def point_to_number(self, point: Sequence[float]) -> float: """ point = np.asarray(point) - start = self.points[0] - end = self.points[-1] - direction = end - start - proportion = np.dot(point - start, direction) / np.dot(direction, direction) - return interpolate(self.x_min_no_tips, self.x_max_no_tips, proportion) + start, end = self.get_start_and_end() + unit_vect = normalize(end - start) + proportion = np.dot(point - start, unit_vect) / np.dot(end - start, unit_vect) + return interpolate(self.x_min, self.x_max, proportion) def n2p(self, number: float | np.ndarray) -> np.ndarray: """Abbreviation for :meth:`~.NumberLine.number_to_point`.""" @@ -470,12 +419,10 @@ def p2n(self, point: Sequence[float]) -> float: return self.point_to_number(point) def get_unit_size(self) -> float: - v = self.get_unit_vector() - return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) + return self.get_length() / (self.x_range[1] - self.x_range[0]) def get_unit_vector(self) -> np.ndarray: - range_min, range_max, _ = self.x_range_no_tips - return (self.points[-1] - self.points[0]) / (range_max - range_min) + return super().get_unit_vector() * self.unit_size def get_number_mobject( self, From 014d38dacb049692b6967d79752675cf22988331 Mon Sep 17 00:00:00 2001 From: chopan Date: Sun, 10 Dec 2023 00:07:30 +0100 Subject: [PATCH 15/18] Reimported manim.utils.space_ops.normalize --- manim/mobject/graphing/number_line.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index a9745daabc..02bfd3edb4 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -12,8 +12,6 @@ if TYPE_CHECKING: from manim.mobject.geometry.tips import ArrowTip -from math import sqrt - import numpy as np from manim import config @@ -25,6 +23,7 @@ from manim.mobject.types.vectorized_mobject import VGroup, VMobject from manim.utils.bezier import interpolate from manim.utils.config_ops import merge_dicts_recursively +from manim.utils.space_ops import normalize class NumberLine(Line): From 6c7736617ccf4a7f66a155790099b542940d7553 Mon Sep 17 00:00:00 2001 From: chopan Date: Sun, 10 Dec 2023 00:51:34 +0100 Subject: [PATCH 16/18] Reverted other stuff --- manim/mobject/graphing/number_line.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 02bfd3edb4..5e45d46e59 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -17,7 +17,7 @@ from manim import config from manim.constants import * from manim.mobject.geometry.line import Line -from manim.mobject.graphing.scale import UnitLinearBase, _ScaleBase +from manim.mobject.graphing.scale import LinearBase, _ScaleBase from manim.mobject.text.numbers import DecimalNumber from manim.mobject.text.tex_mobject import MathTex, Tex from manim.mobject.types.vectorized_mobject import VGroup, VMobject @@ -156,7 +156,7 @@ def __init__( font_size: float = 36, label_direction: Sequence[float] = DOWN, label_constructor: VMobject = MathTex, - scaling: _ScaleBase = UnitLinearBase(), + scaling: _ScaleBase = LinearBase(), line_to_number_buff: float = MED_SMALL_BUFF, decimal_number_config: dict | None = None, numbers_to_exclude: Iterable[float] | None = None, @@ -525,8 +525,11 @@ def add_numbers( if label_constructor is None: label_constructor = self.label_constructor - numbers = VGroup( - *[ + numbers = VGroup() + for x in x_values: + if x in excluding: + continue + numbers.add( self.get_number_mobject( x, font_size=font_size, @@ -535,8 +538,7 @@ def add_numbers( ) for x in x_values if x not in excluding - ] - ) + ) self.add(numbers) self.numbers = numbers return self From 4ec6db52acc75fc1b65f000a058a6f165d1db3dc Mon Sep 17 00:00:00 2001 From: chopan Date: Sun, 10 Dec 2023 00:53:17 +0100 Subject: [PATCH 17/18] Fixed stuff --- manim/mobject/graphing/number_line.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py index 5e45d46e59..51c609c5ae 100644 --- a/manim/mobject/graphing/number_line.py +++ b/manim/mobject/graphing/number_line.py @@ -536,8 +536,6 @@ def add_numbers( label_constructor=label_constructor, **kwargs, ) - for x in x_values - if x not in excluding ) self.add(numbers) self.numbers = numbers @@ -583,7 +581,7 @@ def add_labels( if label_constructor is None: label_constructor = self.label_constructor - labels = [] + labels = VGroup() for x, label in dict_values.items(): # TODO: remove this check and ability to call # this method via CoordinateSystem.add_coordinates() @@ -598,9 +596,8 @@ def add_labels( else: raise AttributeError(f"{label} is not compatible with add_labels.") label.next_to(self.number_to_point(x), direction=direction, buff=buff) - labels.append(label) + labels.add(label) - labels = VGroup(*labels) self.labels = labels self.add(labels) return self From ebcffa82f0b5e1b5ce025595339bb9511a726c89 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:05:22 +0000 Subject: [PATCH 18/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/graphing/scale.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/mobject/graphing/scale.py b/manim/mobject/graphing/scale.py index e0d7381bc3..f8ea79831c 100644 --- a/manim/mobject/graphing/scale.py +++ b/manim/mobject/graphing/scale.py @@ -117,7 +117,6 @@ def inverse_function(self, value: float) -> float: class UnitLinearBase(LinearBase): def __init__(self): """The default scaling class.""" - super().__init__(scale_factor=1.0) def function(self, value: float) -> float: