srecord noeq G22SkeletonWalker(IImageRegion region) is Steppable { // nodes by starting point (filled during exploration) new Map nodesByPt; // temporary data ItIt ptIterator; // region pixel iterator new LinkedList> queue; // incomplete nodes queue (with point to check) // each node is a path, at the end of which there is an optional // junction with multiple branches class Node { new PtBuffer path; L branches; // junction part (optional) Pt startingPt() { ret first(path); } } void add(A a, A prev default null) { if (!links.containsKey(a)) { links.put(a, prev); queue.add(a); } } public bool step() { ping(); if (nempty(queue)) { Pt p = popFirst(queue); } if (ptIterator == null) ptIterator = region.pixelIterator(); fOr (A b : getChildren.get(a)) add(b, a); true; } bool nodeReached(A a) { ret links.containsKey(a); } Cl getBackLinks(A a) { ret links.get(a); } L examplePath(A start, A dest) { new L path; A node = dest; path.add(node); do { if (node == null) null; // no path found node = first(getBackLinks(node)); path.add(node); } while (node != start); ret reversed(path); } }