Create a list of boundary records, where each boundary has the form
bound.type = start,finish bound.position = 0..n bound.color = red,green,blue...
and for each line segment add two such entries to the list (ine for each end). Then sort all the records by position. Now, if you iterate over the list as follows:
colors=[] write '[0' for each bound in list write '-',bound.pos,'] -> [',colours,']' if bound.type = start then add bound.color to colors else remove bound.type from colors write '[',bound.pos write '-',n'] -> []'
you will have to tidy up a bit if the first line segment starts at 0 or the last ends at n.
source share