TTerraInterlace
Workflows

Coding workflows · Morton grid indexing

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Morton grid indexing

A concrete starting point
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 result

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗