function [ w2, p2 ] = boundary_reflect ( w, p, r )

%*****************************************************************************80
%
%% boundary_reflect() reflects a polyiamond described by a boundary word.
%
%  Discussion:
%
%    The boundary word describes how to trace the boundary by starting
%    at a base point (i,j), and taking a sequence of steps of unit length 
%    in one of 6 directions, as suggested by this diagram:
%
%          5-----0-----*
%      ^  / \   / \   /
%     /  /   \ /   \ /
%    J  4-----P-----1
%      / \   / \   /
%     /   \ /   \ /
%    *-----3-----2
%
%          I-->
%
%    If the current position P has parallelogram coordinates (I,J), then
%    the step of given index moves to
%
%      0  (I,  J+1)
%      1  (I+1,J  )
%      2  (I+1,J-1)
%      3  (I,  J-1)
%      4  (I-1,J  )
%      5  (I-1,J+1)
%
%    Reflection replaces each character K in the boundary word by 5-K.
%
%  Example:
%
%    w  = '0053422134444';
%    w2 = '5502133421111';
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string W: the boundary word.  
%
%    integer P(1,2): the starting point.
%
%    integer R: the reflection option.
%    0: no reflection;
%    1: reflect about the I axis;
%    2: reflect about the J axis;
%    3: reflect about both I and J axes.
%
%  Output:
%
%    string W2: the boundary word for the reflected shape.  
%
%    integer P2(1,2): the starting point for the reflected shape.
%
  c1 = [ '0', '1', '2', '3', '4', '5' ];

  if ( r == 1 )
    c2 = [ '5', '4', '3', '2', '1', '0' ];
  elseif ( r == 2 )
    c2 = [ '2', '1', '0', '5', '4', '3' ];
  elseif ( r == 3 )
    c2 = [ '3', '4', '5', '0', '1', '2' ];
  else
    w2 = w;
    p2 = p;
    return
  end
%
%  Reflect the boundary word.
%
  w2 = w;
  for i = 1 : 6
    j = find ( w == c1(i) );
    w2(j) = c2(i);
  end
%
%  Reflect the base point.
%
  p2 = p;

  if ( r == 1 )
    p2(1) = - p2(1) - p2(2);
  elseif ( r == 2 )
    p2(1) =   p2(1) + p2(2);
    p2(2) = - p2(2);
  elseif ( r == 3 )
    p2(1) = - p2(1);
    p2(2) = - p2(2);
  end

  return
end

