now if you want the distance, theres a simple way to do this. You want to look at how far you are from the center of each tile. The division is giving us each tile at its upper left hand corner. You want the distance from the center, which is offset from the corner by 16 in each direction. Taking the modulo of the position gives us the distance from the center:
ist("object") = x("object") mod 32 - 16
ydist("object") = y("object") mod 32 - 16
This gives us positive and negative distances from the center of each tile.
Now when you want to snap objects to that tile, it becomes a question of what kind of distance you want to check.
If you want to check the absolute distance, that is, along the 2d plane, you'd need to use a slow square root:
ist("object") = x("object") mod 32 - 16
ydist("object") = y("object") mod 32 - 16
distance("object") = sqrt(pow(ist("object"),2) + pow(ydist("object"),2))
alternatively, you can use the approximation formula which is much, much faster: