jakubcerveny / gilbert

Space-filling curve for rectangular domains or arbitrary size.
BSD 2-Clause "Simplified" License
121 stars 11 forks source link

resolves #11 #13

Closed abetusk closed 4 months ago

abetusk commented 4 months ago
jakubcerveny commented 4 months ago

Thank you. I'm just wondering: how can one get so many iterations? Unless this was called in a loop, the recursion depth should never be this large (it should be a logarithm).

abetusk commented 4 months ago

Getting individual values is logarithmic and calling the function a few times doesn't trigger the issue.

The C program version (compiled with the GILBERT_MAIN define set) loops over every element, either (x,y) pairs or the index, so any dimensions that exceed the hard coded value will trigger this issue. In this case, max_iter was set to 100,000, and 460 * 460 = 211600 > 100000.

The problem was actually much much worse, in that the max_iter variable is static to the function, so it's not just that it gets incremented if the function gets called in order, it gets incremented if the function gets called at all, so calling the function gilbert_d2xy_r(&x, &y, 0, 10, 10) over 100,000 times would have also triggered the issue.