Skip to content

Commit ce4ac51

Browse files
WillSoltasWill Soltaspre-commit-ci[bot]behackl
authored
Added Axes Tip Resize Functionality according to Axes documentation (#2661)
* Added Axes Tip Resize Functionality according to Axes class documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Changed Default Tip Size Values to Conform with Global Defaults * Fixed width kwarg usage on circle/square tips * Fixed ratio-impacted default tip width for vectors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Removed Left-over Prints :) Co-authored-by: Will Soltas <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent cfd006a commit ce4ac51

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

manim/mobject/geometry/arc.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,40 +101,52 @@ def __init__(
101101

102102
# Adding, Creating, Modifying tips
103103

104-
def add_tip(self, tip=None, tip_shape=None, tip_length=None, at_start=False):
104+
def add_tip(
105+
self, tip=None, tip_shape=None, tip_length=None, tip_width=None, at_start=False
106+
):
105107
"""Adds a tip to the TipableVMobject instance, recognising
106108
that the endpoints might need to be switched if it's
107109
a 'starting tip' or not.
108110
"""
109111
if tip is None:
110-
tip = self.create_tip(tip_shape, tip_length, at_start)
112+
tip = self.create_tip(tip_shape, tip_length, tip_width, at_start)
111113
else:
112114
self.position_tip(tip, at_start)
113115
self.reset_endpoints_based_on_tip(tip, at_start)
114116
self.asign_tip_attr(tip, at_start)
115117
self.add(tip)
116118
return self
117119

118-
def create_tip(self, tip_shape=None, tip_length=None, at_start=False):
120+
def create_tip(
121+
self, tip_shape=None, tip_length=None, tip_width=None, at_start=False
122+
):
119123
"""Stylises the tip, positions it spatially, and returns
120124
the newly instantiated tip to the caller.
121125
"""
122-
tip = self.get_unpositioned_tip(tip_shape, tip_length)
126+
tip = self.get_unpositioned_tip(tip_shape, tip_length, tip_width)
123127
self.position_tip(tip, at_start)
124128
return tip
125129

126-
def get_unpositioned_tip(self, tip_shape=None, tip_length=None):
130+
def get_unpositioned_tip(self, tip_shape=None, tip_length=None, tip_width=None):
127131
"""Returns a tip that has been stylistically configured,
128132
but has not yet been given a position in space.
129133
"""
130134
from manim.mobject.geometry.tips import ArrowTriangleFilledTip
131135

136+
style = {}
137+
132138
if tip_shape is None:
133139
tip_shape = ArrowTriangleFilledTip
140+
141+
if tip_shape is ArrowTriangleFilledTip:
142+
if tip_width is None:
143+
tip_width = self.get_default_tip_length()
144+
style.update({"width": tip_width})
134145
if tip_length is None:
135146
tip_length = self.get_default_tip_length()
147+
136148
color = self.get_color()
137-
style = {"fill_color": color, "stroke_color": color}
149+
style.update({"fill_color": color, "stroke_color": color})
138150
style.update(self.tip_style)
139151
tip = tip_shape(length=tip_length, **style)
140152
return tip

manim/mobject/geometry/tips.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def __init__(
185185
fill_opacity=0,
186186
stroke_width=3,
187187
length=DEFAULT_ARROW_TIP_LENGTH,
188+
width=DEFAULT_ARROW_TIP_LENGTH,
188189
start_angle=PI,
189190
**kwargs,
190191
):
@@ -195,8 +196,10 @@ def __init__(
195196
start_angle=start_angle,
196197
**kwargs,
197198
)
198-
self.width = length
199-
self.stretch_to_fit_height(length)
199+
self.width = width
200+
201+
self.stretch_to_fit_width(length)
202+
self.stretch_to_fit_height(width)
200203

201204

202205
class ArrowTriangleFilledTip(ArrowTriangleTip):

manim/mobject/graphing/number_line.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def __init__(
138138
stroke_width: float = 2.0,
139139
# tip
140140
include_tip: bool = False,
141-
tip_width: float = 0.25,
142-
tip_height: float = 0.25,
141+
tip_width: float = DEFAULT_ARROW_TIP_LENGTH,
142+
tip_height: float = DEFAULT_ARROW_TIP_LENGTH,
143143
# numbers/labels
144144
include_numbers: bool = False,
145145
font_size: float = 36,
@@ -217,7 +217,7 @@ def __init__(
217217
self.center()
218218

219219
if self.include_tip:
220-
self.add_tip()
220+
self.add_tip(tip_length=self.tip_height, tip_width=self.tip_width)
221221
self.tip.set_stroke(self.stroke_color, self.stroke_width)
222222

223223
if self.include_ticks:
Binary file not shown.
Binary file not shown.

tests/test_graphical_units/test_axes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ def test_get_y_axis_label(scene):
6767
scene.add(ax, y_label)
6868

6969

70+
@frames_comparison
71+
def test_axis_tip_default_width_height(scene):
72+
ax = Axes(
73+
x_range=(0, 4),
74+
y_range=(0, 4),
75+
axis_config={"include_numbers": True, "include_tip": True},
76+
)
77+
78+
scene.add(ax)
79+
80+
81+
@frames_comparison
82+
def test_axis_tip_custom_width_height(scene):
83+
ax = Axes(
84+
x_range=(0, 4),
85+
y_range=(0, 4),
86+
axis_config={"include_numbers": True, "include_tip": True},
87+
x_axis_config={"tip_width": 1, "tip_height": 0.1},
88+
y_axis_config={"tip_width": 0.1, "tip_height": 1},
89+
)
90+
91+
scene.add(ax)
92+
93+
7094
@frames_comparison
7195
def test_plot_derivative_graph(scene):
7296
ax = NumberPlane(y_range=[-1, 7], background_line_style={"stroke_opacity": 0.4})

0 commit comments

Comments
 (0)