
The merging routine repeatedly merges adjacent segments. For every ith segment, the program attempts to merge it with i – 1st and i + 1st. Let these new segments be seg1 and seg2. The fit error for them is calculated. For the segment with least error among seg1 and seg2, merging happens only if the error is less than the sum of the corresponding errors of the original segments. The image shows the program merging lines L4 and L5 into arc A4. It also merges arcs A1, A2, and A3 into one arc, A5.