function dists = UTM_zipper_dists(flights,lanes)
%

WAITING = 1;
IN_FLIGHT = 0;
DONE = -1;

num_flights = length(flights);
dists = Inf*ones(num_flights,num_flights);

for f1 = 1:num_flights-1
    if flights(f1).status==IN_FLIGHT
        lane_index1 = flights(f1).lane_index;
        lane_number1 = flights(f1).traj(lane_index1);
        e11 = lanes(lane_number1,1:3);
        e12 = lanes(lane_number1,4:6);
        dir1 = e12 - e11;
        dir1 = dir1/norm(dir1);
        loc1 = e11 + dir1*flights(f1).lane_dists(lane_index1);
        for f2 = f1+1:num_flights
            if flights(f2).status==IN_FLIGHT
                lane_index2 = flights(f2).lane_index;
                lane_number2 = flights(f2).traj(lane_index2);
                e21 = lanes(lane_number2,1:3);
                e22 = lanes(lane_number2,4:6);
                dir2 = e22 - e21;
                dir2 = dir2/norm(dir2);
                loc2 = e21 + dir2*flights(f2).lane_dists(lane_index2);
                case1 = norm(e12-e21)<1;  % ---1--> ---2--->
                case2 = norm(e22-e11)<1;  % ---2--> ---1--->
                case3 = norm(e12-e22)<1;  % ---1--> <--2---
                case4 = norm(e11-e21)<1;  % <--1--- ---2--->
                if case1
                    dists(f1,f2) = norm(loc1-e12) + norm(loc2-e21);
                elseif case2
                    dists(f1,f2) = norm(loc2-e22) + norm(loc1-e11);
                elseif case3
                    dists(f1,f2) = norm(loc1-e12) + norm(loc2-e22);
                end
                dists(f1,f2) = norm(loc1-loc2);
                dists(f2,f1) = dists(f1,f2);
            end
        end
    end
end
