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

v0.18.1 weird behavior of Axes().coords_to_point / Axes().c2p #4073

Open
uwezi opened this issue Dec 27, 2024 · 2 comments
Open

v0.18.1 weird behavior of Axes().coords_to_point / Axes().c2p #4073

uwezi opened this issue Dec 27, 2024 · 2 comments

Comments

@uwezi
Copy link
Contributor

uwezi commented Dec 27, 2024

Description of bug / unexpected behavior

According to the documentation, the argument of .c2p() may be individual values for x, y (and z), as well as lists, lists of lists and numpy.arrays. However, when using just lists [x,y,z] or 1D np.arrays the returned coordinates are wrong.

Expected behavior

How to reproduce the issue

Code for reproducing the problem
class testc2p(Scene):
    def construct(self):
        ax = Axes()
        print("ax.c2p(1,2) = ",ax.c2p(1,2))
        print("ax.c2p(1,2,1) = ",ax.c2p(1,2,1))
        print("ax.c2p(np.array([1,2])) = ",ax.c2p(np.array([1,2])))
        print("ax.c2p(np.array([1,2,1])) = ",ax.c2p(np.array([1,2,1])))
        print("ax.c2p([1,2,1]) = ",ax.c2p([1,2,1]))
        print("ax.c2p([1,2]) = ",ax.c2p([1,2]))
        print("ax.c2p([[1,2],[2,3]]) = ",ax.c2p([[1,2],[2,3]]))

returns

Manim Community v0.18.1

ax.c2p(1,2)   =  [0.85714286 1.5        0.        ]
ax.c2p(1,2,1) =  [0.85714286 1.5        0.        ]
ax.c2p(np.array([1,2])) =  [[0.85714286 1.71428571]
                            [0.         0.        ]
                            [0.         0.        ]]
ax.c2p(np.array([1,2,1])) =  [[0.85714286 1.71428571 0.85714286]
                              [0.         0.         0.        ]
                              [0.         0.         0.        ]]
ax.c2p([1,2,1]) =  [[0.85714286 1.71428571 0.85714286]
                    [0.         0.         0.        ]
                    [0.         0.         0.        ]]
ax.c2p([1,2]) =  [[0.85714286 1.71428571]
                  [0.         0.        ]
                  [0.         0.        ]]
ax.c2p([[1,2],[2,3]]) =  [[0.85714286 1.5        0.        ]
                          [1.71428571 2.25       0.        ]]
  • ax.c2p(1,2) and ax.c2p(1,2,1) return reasonable values
  • ax.c2p(np.array([1,2])) appears to be treated as two "points" with x=1 and x=2 respectively, returning [[x1, x2],[y1, y2],[z1, z2]] rather than [[x1 y1 z1],[x2, y2, z2]], similar for all other 1D-lists
  • ax.c2p([[1,2],[2,3]]) appears to correctly return two points

System specifications

System Details
  • OS : Windows 10
  • RAM: enough
  • Python version (python/py/python3 --version): 3.11.6
@JasonGrace2282
Copy link
Member

JasonGrace2282 commented Dec 30, 2024

Let me preface this by saying that I'm (personally) not a big fan of this behavior.

However, the reason for this is when passing a list (ax.c2p([1,2])) it's treating it as you passed a list of the structure [x1, x2], [y1, y2], [z1, z2] - see the implementation if you're interested. (edit: oops you already figured this out)

I would like to make this behavior less confusing, so I'm open to ideas!

@uwezi
Copy link
Contributor Author

uwezi commented Dec 30, 2024

I would say the expected behavior would be: list of coordinates - in list of coordinates out
But I can also imagine that it is not easy to distinguish the different formats. But I think the following behavior would be more logical
axes.c2p(x,y,z) -> np.array([X, Y, Z])
axes.c2p([[x,y,z]]) -> [np.array([X, Y, Z])]
axes.c2p([[x1,y1,z1],[x2,y2,z2]]) -> [np.array([X1, Y1, Z1]),np.array([X2, Y2, Z2])]
Personally I cannot see any use case where I would expect to get individual lists of the Xs, Ys and Zs back...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants