I have some heavy calculations that essentially takes a point in the plane as input and gives an integer as output. Points in the same region gives the same integer (think about the regions as pieces in a jigsaw (every point in completed puzzle belongs to a specific jigsaw piece), the boundaries being simple, closed curves). I've made a very simple algorithm that first finds a boundary by finding the integers of two neighboring corners of my search rectangle and divides and conquers its way to find a boundary (to within a predefined accuracy). So I find a random boundary in O(log(width)) time, where width is the width of my search rectangle. Now my naive approach is then to sort of take small steps in a circle around that point until the number changes, record that point and repeat. The problem is checking a points number is really expensive (NP-hard) and even worse my algorithm misses forkings in the boundaries. All I can find online is image processing algorithms like floodfill, where checking a point is cheap. Does algorithms like this exist? Or do you have any good ideas to make one?