Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: NumberLine number_to_point broken when using add_tip #3820

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ def get_last_handle(self) -> Point3D:

def get_end(self) -> Point3D:
if self.has_tip():
return self.tip.get_start()
return self.tip.base
else:
return super().get_end()

def get_start(self) -> Point3D:
if self.has_start_tip():
return self.start_tip.get_start()
return self.start_tip.base
else:
return super().get_start()

Expand Down
26 changes: 23 additions & 3 deletions manim/mobject/graphing/number_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from typing_extensions import Self

from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject

Expand Down Expand Up @@ -236,7 +238,6 @@ def __init__(
tip_width=self.tip_width,
tip_shape=tip_shape,
)
self.tip.set_stroke(self.stroke_color, self.stroke_width)

if self.include_ticks:
self.add_ticks()
Expand Down Expand Up @@ -275,6 +276,26 @@ def rotate_about_number(
):
return self.rotate(angle, axis, about_point=self.n2p(number), **kwargs)

def add_tip(
self,
tip: ArrowTip | None = None,
tip_shape: type[ArrowTip] | None = None,
tip_length: float | None = None,
tip_width: float | None = None,
at_start: bool = False,
) -> Self:
if tip_length is None:
tip_length = self.tip_height

if tip_width is None:
tip_width = self.tip_width

super().add_tip(tip, tip_shape, tip_length, tip_width, at_start)

self.tip.set_stroke(self.stroke_color, self.stroke_width)

return self

def add_ticks(self):
"""Adds ticks to the number line. Ticks can be accessed after creation
via ``self.ticks``."""
Expand Down Expand Up @@ -325,8 +346,7 @@ def get_tick_range(self) -> np.ndarray:
A numpy array of floats represnting values along the number line.
"""
x_min, x_max, x_step = self.x_range
if not self.include_tip:
x_max += 1e-6
x_max += 1e-6

# Handle cases where min and max are both positive or both negative
if x_min < x_max < 0 or x_max > x_min > 0:
Expand Down
Loading