Open the context
Choose the project folder and name the files or behavior involved.
Interleave two nonnegative integer grid coordinates into a Morton index with a declared bit width. Check corner coordinates and the maximum supported width, rejecting negatives, fractions and coordinates that do not fit.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def morton2(x, y, bits):
if type(bits) is not int or not 1 <= bits <= 16:
raise ValueError("bits.range")
if any(type(v) is not int or not 0 <= v < (1 << bits)
for v in (x, y)):
raise ValueError("coordinate.range")
result = 0
for i in range(bits):
result |= ((x >> i) & 1) << (2 * i)
result |= ((y >> i) & 1) << (2 * i + 1)
return resultThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.