function inside = vertex_contains_point ( v, p )

%*****************************************************************************80
%
%% vertex_contains_point(): is a point inside a polyiamond given its vertex list?
%
%  Discussion:
%
%    The vertex list of a polyiamond gives the IJ coordinates of the
%    polygonal vertices, in counterclockwise order.
%
%    There are two different coordinate systems in use:
%    (I,J) refers to the parallelogram grid coordinates.
%    (X,Y) refers to the Cartesian coordinates.
%
%    There is an affine relationship between these two systems.
%    As long as both V and P are reported in the same coordinate system,
%    this function should give correct results.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real V(VN,2): the coordinates of the polygon vertices.
%
%    real P(2): the coordinates of the point, using the same
%    coordinate system as V.
%
%  Output:
%
%    logical INSIDE, is TRUE if the point is inside the polygon.
%
  vn = size ( v, 1 );

  inside = false;

  vx1 = v(1,1);
  vy1 = v(1,2);
  xints = p(1) - 1.0;

  for i = 1 : vn

    vx2 = v(mod(i,vn)+1,1);
    vy2 = v(mod(i,vn)+1,2);

    if ( min ( vy1, vy2 ) < p(2) )
      if ( p(2) <= max ( vy1, vy2 ) )
        if ( p(1) <= max ( vx1, vx2 ) )
          if ( vy1 ~= vy2 )
            xints = ( p(2) - vy1 ) * ( vx2 - vx1 ) / ( vy2 - vy1 ) + vx1;
          end
          if ( vx1 == vx2 || p(1) <= xints )
            inside = ~ inside;
          end
        end
      end
    end

    vx1 = vx2;
    vy1 = vy2;

  end

  return
end

