Your function is not working for five main reasons:
- The syntax is off - indentation is important in Python;
- You don't check whether
p in G
each timeDownstream
gets called (the first key may be present, but what about later recursive calls?); - You have too many
return
points, for example your last line will never run (what should the function output be?); - You seem to be accessing a 3-tuple
e = (sh, le, en)
by attribute (e.end
); and - You are subtracting from the interval length when you call recursively, so the function can't keep track of how far apart points should be - you need to separate the interval and the offset from the start.
Instead, I think you need something like (untested!):
def Downstream(start, interval, data, offset=0, out=None):
if out is None:
out = []
if start in data:
shape, length, end = data[start]
length = length[0]
if interval < length:
distance = offset
while distance < length:
out.append(Along(shape, distance))
distance += interval
distance -= interval
Downstream(end, interval, data, interval - (length - distance), out)
else:
Downstream(end, interval, data, offset - length, out)
return out
This will give you a list of whatever Along
returns. If the original start not in data
, it will return an empty list.