The tracing algorithm expects each trace to be nearly vertical, which isn't always the case. If there's a significant region where the trace is lost, it can fail to find it on the other side because it only tries to find a peak around the last position. With pinhole masks (or close sources) it's possible that another trace might be closer to this position than the correct trace.
A suggested solution is to create Trace objects which store the coordinates along a trace, probably in a deque and have a method with extrapolates the last 2 or 3 points to determine a better estimate of the trace location. This should improve the readability of the code as well, instead of juggling various lists.
The tracing algorithm expects each trace to be nearly vertical, which isn't always the case. If there's a significant region where the trace is lost, it can fail to find it on the other side because it only tries to find a peak around the last position. With pinhole masks (or close sources) it's possible that another trace might be closer to this position than the correct trace.
A suggested solution is to create
Traceobjects which store the coordinates along a trace, probably in adequeand have a method with extrapolates the last 2 or 3 points to determine a better estimate of the trace location. This should improve the readability of the code as well, instead of juggling various lists.