fancy modulus arithmetic for edge tiles