* @brief stepToEdge advances cursor to one step behind the next (or n-th) edge. * @param nth number of edges to pass * @param range max number of steps to take * @param backup whether or not to backup one step so we land in front of the edge * @return number of steps taken or 0 if moved outside of range/image */
| 112 | * @return number of steps taken or 0 if moved outside of range/image |
| 113 | */ |
| 114 | int stepToEdge(int nth = 1, int range = 0, bool backup = false) |
| 115 | { |
| 116 | int steps = 0; |
| 117 | auto lv = testAt(p); |
| 118 | |
| 119 | while (nth && (!range || steps < range) && lv.isValid()) { |
| 120 | ++steps; |
| 121 | auto v = testAt(p + steps * d); |
| 122 | if (lv != v) { |
| 123 | lv = v; |
| 124 | --nth; |
| 125 | } |
| 126 | } |
| 127 | if (backup) |
| 128 | --steps; |
| 129 | p += steps * d; |
| 130 | return steps * (nth == 0); |
| 131 | } |
| 132 | |
| 133 | bool stepAlongEdge(Direction dir, bool skipCorner = false) |
| 134 | { |
no test coverage detected