function polygon_sample_test ( )

%*****************************************************************************80
%
%% polygon_sample_test() tests polygon_sample().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 January 2025
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../polygon_sample' );

  timestamp ( );

  rng ( 'shuffle' );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_sample_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test polygon_sample(), which uniformly samples points\n' );
  fprintf ( 1, '  in a polygon.\n' );

  n = 1000;

  v = [ ...
    0,   0; ...
   10,   7; ...
   12,   3; ...
   20,   8; ...
   13,  17; ...
   10,  12; ...
   12,  14; ...
   14,   9; ...
    8,  10; ...
    6,  14; ...
   10,  15; ...
    7,  18; ...
    0,  16; ...
    1,  13; ...
    3,  15; ...
    5,   8; ...
   -2,   9; ...
    5,   5 ];

  nv = size ( v, 1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of points N =    %12d\n', n );
  fprintf ( 1, '  Number of vertices NV = %12d\n', nv );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Polygonal vertices:\n' );
  disp ( v )

  p = polygon_sample ( nv, v, n );
  triangles = polygon_triangulate ( nv, v(1:nv,1), v(1:nv,2) );

  clf ( );
  hold ( 'on' );
%
%  Plot polygon edges.
%
  im1 = nv;
  for i = 1 : nv
    plot ( [ v(im1,1), v(i,1) ], ...
           [ v(im1,2), v(i,2) ], 'r-', 'linewidth', 3 );
    im1 = i;
  end
%
%  Plot sample points.
%
  plot ( p(:,1), p(:,2), 'bo', 'markersize', 2 );
%
%  Plot triangulation lines.
%
  for i = 1 : nv - 3
    i1 = triangles(i,1);
    i2 = triangles(i,2);
    line ( [ v(i1,1), v(i2,1) ], ...
           [ v(i1,2), v(i2,2) ], ...
           'LineWidth', 3, 'Color', 'r' );
  end

  hold ( 'off' );
  xlabel ( '<--- X --->' );
  ylabel ( '<--- Y --->' );
  title ( 'polygon sample points' );
  grid ( 'on' );
  axis ( 'equal' );
  filename = 'polygon_sample.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_sample_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../polygon_sample' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2022
%
%  Author:
%
%    John Burkardt
%
  t = now ( );
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end


