function value = boundary_word_is_convex ( s )

%*****************************************************************************80
%
%% boundary_word_is_convex(): convexity of a polyomino from boundary word.
%
%  Discussion:
%
%    Because our boundary word alphabet is limited to four letters,
%    our shapes are limited to strictly horizontal and vertical sides.
%    Under these restrictions, the only convex shape is a rectangle.
%
%    We can easily detect this by considering the first four distinct
%    characters in the boundary word.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 May 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Srecko Briek, Gilbert Labelle, Ariane Lacasse,
%    Algorithms for polyominoes based on the discrete Green theorem,
%    Discrete Applied Mathematics,
%    Volume 147, pages 187-205, 2005.
%
%  Input:
%
%    char s(*): a vector of the characters 'u', 'd', 'l' and 'r' that should
%    represent a path around the boundary of a polyomino.
%
%  Output:
%
%    logical VALUE: true if the polyomino is convex.
%
  value = false;
%
%  Lowercase the string.
%
  s = lower ( s );
%
%  Check that the string is legal.
%
  check = boundary_word_check ( s );

  if ( ~ check )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'boundary_word_is_convex(): Fatal error!\n' );
    fprintf ( 1, '  The boundary word does not pass boundary_word_check().\n' );
    error ( 'boundary_word_is_convex(): Fatal error!\n' );
    return
  end
%
%  Replace the string by its representative.
%
  s2 = boundary_word_representative ( s );
%
%  Remove repeated characters.
%
  s3 = chvec_reduce ( s2 );
%
%  For convexity, the representative must be of length 4.
%
  s3_len = length ( s3 );
  if ( s3_len ~= 4 )
    return
  end
%
%  For convexity, the representative can only be one of two strings.
%
  if ( is_octave ( ) )

    if ( chvec_eq ( s3, 'dlur' ) || chvec_eq ( s3, 'drul' ) ) 
      value = true;
    end
%
%  In MATLAB, convert from character vector to string to make comparison easy.
%
  else

    s3_string = string ( s3 );
    if ( s3_string == "dlur" || s3_string == "drul" )
      value = true;
    end

  end

  return
end
