function [ xmin, xmax, ymin, ymax ] = boundary_word_range ( s )

%*****************************************************************************80
%
%% boundary_word_range() returns the range of a polyomino defined by a boundary word.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    char s(*): a string of the characters 'u', 'd', 'l' and 'r' that should
%    represent a path around the boundary of a polyomino.
%
%  Output:
%
%    integer xmin, xmax, ymin, ymax: the range of the polyomino.
%
  check = boundary_word_check ( s );

  if ( ~ check )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'boundary_word_range - Fatal error!\n' );
    fprintf ( 1, '  The boundary word is illegal.\n' );
    error ( 'boundary_word_range: The boundary word is illegal!' );
  end

  s = lower ( s );
  s_len = length ( s );
  x = zeros(s_len + 1, 1);
  y = zeros(s_len + 1, 1);

  x(1) = 0;
  y(1) = 0;
  for i = 1: s_len

    if ( s(i) == 'r' )
      x(i+1) = x(i) + 1;
      y(i+1) = y(i);
    elseif ( s(i) == 'l' )
      x(i+1) = x(i) - 1;
      y(i+1) = y(i);
    elseif ( s(i) == 'u' )
      x(i+1) = x(i);
      y(i+1) = y(i) + 1;
    elseif ( s(i) == 'd' )
      x(i+1) = x(i);
      y(i+1) = y(i) - 1;
    end
  end

  xmin = min ( x );
  xmax = max ( x );
  ymin = min ( y );
  ymax = max ( y );

  return
end

