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\$ – DMGregory Feb 2 at 19:07
  • \$\begingroup\$ Yes, I would prefer to delete this, because it was pointless to ask twice. \$\endgroup\$ – Ladasno Vaidas Feb 3 at 20:21
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\$ – DMGregory Jan 3 at 18:12
  • \$\begingroup\$ I've already asked this in stack overflow site, so it was answered. \$\endgroup\$ – Ladasno Vaidas Jan 4 at 23:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.