0
\$\begingroup\$

Basically, I have a NumPy array of rectangles that store their colour and position.

I want to be able to compare my mouse position and clicked on the rectangle's position and get the index or the object itself from the array.

Do I have to iterate through every square in the array and compare item's coordinates?

The structure looks like:

Cube[Face][Horizontal-Line][Square] = np.array([colour, coordinates])

What's the most efficient way to do it? I'm thinking of using colliderect() method, but I don't know how to implement it.

1

\$\endgroup\$
2
  • \$\begingroup\$ I’m voting to close this question because it was asked and answered on StackOverflow. Please ask each question on just one site in the StackExchange network, to keep the best answers gathered in one place for future readers. \$\endgroup\$ Commented Feb 2, 2021 at 19:07
  • \$\begingroup\$ Yes, I would prefer to delete this, because it was pointless to ask twice. \$\endgroup\$ Commented Feb 3, 2021 at 20:21

1 Answer 1

0
\$\begingroup\$

The solution was just to use grid system and floor division operator //.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This answer would be better if it showed a sample of the code you used to achieve this. \$\endgroup\$ Commented Jan 3, 2021 at 18:12
  • \$\begingroup\$ I've already asked this in stack overflow site, so it was answered. \$\endgroup\$ Commented Jan 4, 2021 at 23:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.