sclass SimpleOutlineWalker is Steppable { IIntIntPred pixelIsInside; int x, y; int startX, startY; NESWDirection direction = NESWDirection.right; event foundPoint(int x, int y); // x, y must be inside the shape *(IIntIntPred *pixelIsInside, int *x, int *y) { if (!pixelIsInside.get(x, y)) fail("pixel is not inside shape: " + x + "/" + y); // go north until we hit the border while (pixelIsInside.get(x, y-1)) --y; startX = x; startY = y; } public bool step() { foundPoint(x, y); // try left, straight, right, back for (int turn = 3; turn <= 6; turn++) { Direction newDirection = direction.plus(turn); int x2 = x+newDirection.x, y2 = y+newDirection.y; bool inside = pixelIsInside.get(x2, y2); ifdef SimpleOutlineWalker_debug printVars(+x, +y, +direction, +turn, +newDirection, +x2, +y2, +inside); endifdef if (inside) { x = x2; y = y2; dir = newDir; true; } } if (x == startX && y == startY) false; } }