Isometric Tile selection algorithm

The last days, I have been trying to create an algorithm that detects the tile the cursor is on.
I am close to figure it out, but cant manage to get the last piece.

Here is a picture of everything.
32(X) by 16(Y) tileset (top right) with the red dot being 0,0 coordinates & code at bottom:

Right now, when i run my code, the light tiles are selected well, but the dark ones only the top left and bottom right part of them are selected well, while the other half of them counts as if they’re light tiles (top left picture).

If any of you know how i could fix this please tell!!!

Also, if i am overcomplicating myself and there is another way, please tell me too! ^^

Thanks a lot!

In case that last part was a bit confusing…

The purple triangles are the only zones where the code detects dark tiles, the rest it detects light ones.

I’ve managed it!!

if anyone needs something like it, changing the 32’s to your tiles X size (and the 16’s to your X/2) and the 16’s to your tiles Y size (and 8 to Y/2) should make it work on your isometric grid