function dist = triangle_point_dist ( t, p )

%*****************************************************************************80
%
%% triangle_point_dist(): distance ( triangle, point ) in 2D.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real T(3,2), the triangle vertices.
%
%    real P(1,2), the point to be checked.
%
%  Output:
%
%    real DIST, the distance from the point to the triangle.
%
  nside = 3;
%
%  Find the distance to each of the line segments.
%
  dist = Inf;

  for i = 1 : nside

    ip1 = i4_wrap ( i + 1, 1, nside );

    dist2 = segment_point_dist_2d ( t(i,1:2), t(ip1,1:2), p );

    if ( dist2 < dist )
      dist = dist2;
    end

  end

  return
end
