Skip to content
Closed
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
17 changes: 12 additions & 5 deletions manim/mobject/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ def coordinate_label(
integer_labels: bool = True,
n_dim: int = 2,
color: str = WHITE,
show_bg_rec: bool = False,
):
"""Creates a label based on the coordinates of the vector.

Expand All @@ -1580,11 +1581,13 @@ def coordinate_label(
The number of dimensions of the vector.
color
The color of the label.
show_bg_rec
Display background rectangle for a number.

Examples
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example for the method isn't showing up, as shown here. Could you fix that? The indentation of the manim code block isn't quite right.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite get this one. I saw the page and yes the example is missing. But upon checking the indentation in the function docstring and committing, I couldn't pinpoint the exact issue that could be causing the missing example. I tried crosschecking with the other examples present in the script as well. Will try investigating a bit more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I misjudged, the problem was at the .. manim keyword at the start of the example, it needs a double colon

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, found it. There was some build issue too due to wrong variable name in the example. Fixed both. Am able to see the example in the link now.

--------

.. manim VectorCoordinateLabel
.. manim:: VectorCoordinateLabel
:save_last_frame:

class VectorCoordinateLabel(Scene):
Expand All @@ -1593,12 +1596,13 @@ def construct(self):

vect_1 = Vector([1, 2])
vect_2 = Vector([-3, -2])
label_1 = vect1.coordinate_label()
label_2 = vect2.coordinate_label(color=YELLOW)
label_1 = vect_1.coordinate_label(show_bg_rec=True)
label_2 = vect_2.coordinate_label(color=YELLOW)

self.add(plane, vect_1, vect_2, label_1, label_2)
"""
# avoiding circular imports
from ..mobject.shape_matchers import BackgroundRectangle
from .matrix import Matrix

vect = np.array(self.get_end())
Expand All @@ -1607,7 +1611,7 @@ def construct(self):
vect = vect[:n_dim]
vect = vect.reshape((n_dim, 1))

label = Matrix(vect)
label = Matrix(vect, include_background_rectangle=show_bg_rec)
label.scale(LARGE_BUFF - 0.2)

shift_dir = np.array(self.get_end())
Expand All @@ -1616,7 +1620,10 @@ def construct(self):
else: # Pointing left
shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT
label.shift(shift_dir)
label.set_color(color)
if show_bg_rec:
Copy link
Collaborator

@icedcoffeeee icedcoffeeee Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is redundant no? Passing add_background_rectangles_to_entries in Matrix already does these.
Cancel that, why don't you pass include_background_rectangle to Matrix instead of add_background_rectangles_to_entries and adding a BackgroundRectangle separately?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that sounds better actually. Thanks!
I have made the change in the function.

label[1:].set_color(color)
else:
label.set_color(color)
return label


Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_graphical_units/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def test_Vector(scene):
scene.add(a)


@frames_comparison
def test_VectorCoordLabel(scene):
vec = Vector([1, 2]).coordinate_label(show_bg_rec=True)
scene.add(vec)


@frames_comparison
def test_Polygon(scene):
a = Polygon(*[np.array([1, 1, 0]), np.array([2, 2, 0]), np.array([2, 3, 0])])
Expand Down