Skip to content

Conversation

@RamType0
Copy link
Contributor

public static ulong CalculateTileId(int zoom)

image
image

Both .NET Framework 4.8(x64) and .NET 9.0 can optimize divide by 3 to idiv less.
So this implementation would be faster in most of environment.

public static ulong CalculateTileId(int zoom, int x, int y)

Use bit shift directly to reduce instructions.

public static (int x, int y, int zoom) CalculateTile(ulong id)

Don't use iteration to find zoom level.
Don't use slow integer division operators.

@RamType0
Copy link
Contributor Author

Note: this implementation does not handle overflow.
But the original implementation also has overflow issue in exactly same case.
So this would never be regression.

@RamType0
Copy link
Contributor Author

RamType0 commented Jun 14, 2025

ulong id could represent up to 31 zoom level.
int tile index could represent up to 31 zoom level.
And tile id calculation supports zoom level of up to 31.
So id calculation never overflow unless tile is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant