function v2 = vertex_sort ( v )

%*****************************************************************************80
%
%% vertex_sort() sorts the vertex list of a polyiamond.
%
%  Discussion:
%
%    The vertex list of a polyiamond gives the IJ coordinates of the
%    polygonal vertices, in counterclockwise order.
%
%    Sorting "rotates" the vertex list so that the first vertex is lexically
%    smallest.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer V(VN,2): the vertex list.
%
%  Output:
%
%    integer V2(VN,2): the sorted vertex list for the polyiamond.  
%
  vn = size ( v, 1 );

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

  v2 = [ v(m:end,1:2); ...
         v(1:m-1,1:2)];

  return
end

