function e2 = edge_sort ( e )

%*****************************************************************************80
%
%% edge_sort() sorts the edge list of a polyiamond.
%
%  Discussion:
%
%    The edge list of a polyiamond gives the IJ coordinates of the
%    boundary nodes, in counterclockwise order.
%
%    Sorting "rotates" the edge list so that the first edge is lexically
%    smallest.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer E(EN,2): the edge list.
%
%  Output:
%
%    integer E2(EN,2): the sorted edge list for the polyiamond.  
%
  en = size ( e, 1 );

  m = 1;
  for i = 2 : en
    if ( ( e(i,1) <  e(m,1)                    ) || ...
         ( e(i,1) == e(m,1) && e(i,2) < e(m,2) ) )
      m = i;
    end
  end

  e2 = [ e(m:end,1:2); ...
         e(1:m-1,1:2)];

  return
end

