Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Bug fix: Use np.isclose for float equality in number line elongated ticks (#3392)

Narahari Rao7fab9cdbf9a2
diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py
index 08f6ef48f..aec3bfb53 100644
--- a/manim/mobject/graphing/number_line.py
+++ b/manim/mobject/graphing/number_line.py
@@ -277,9 +277,10 @@ class NumberLine(Line):
via ``self.ticks``."""
ticks = VGroup()
elongated_tick_size = self.tick_size * self.longer_tick_multiple
+ elongated_tick_offsets = self.numbers_with_elongated_ticks - self.x_min
for x in self.get_tick_range():
size = self.tick_size
- if x in self.numbers_with_elongated_ticks:
+ if np.any(np.isclose(x - self.x_min, elongated_tick_offsets)):
size = elongated_tick_size
ticks.add(self.get_tick(x, size))
self.add(ticks)
diff --git a/tests/module/mobject/graphing/test_ticks.py b/tests/module/mobject/graphing/test_ticks.py
index eeac2ac0a..5bc5eb160 100644
--- a/tests/module/mobject/graphing/test_ticks.py
+++ b/tests/module/mobject/graphing/test_ticks.py
@@ -13,6 +13,27 @@ def test_duplicate_ticks_removed_for_axes():
assert np.unique(ticks).size == ticks.size
+def test_elongated_ticks_float_equality():
+ nline = NumberLine(
+ x_range=[1 + 1e-5, 1 + 2e-5, 1e-6],
+ numbers_with_elongated_ticks=[
+ 1 + 12e-6,
+ 1 + 17e-6,
+ ], # Elongate the 3rd and 8th tick
+ include_ticks=True,
+ )
+
+ tick_heights = {tick.height for tick in nline.ticks}
+ default_tick_height, elongated_tick_height = min(tick_heights), max(tick_heights)
+
+ assert all(
+ tick.height == elongated_tick_height
+ if ind in [2, 7]
+ else tick.height == default_tick_height
+ for ind, tick in enumerate(nline.ticks)
+ )
+
+
def test_ticks_not_generated_on_origin_for_axes():
axes = Axes(
x_range=[-10, 10],