function [closestIntersection,validIntersection,vertexIndex,edgeIndex,isVertexIndex]=intersectInterface(poly,xl,yl)
%intersectInterface find the underlying intersection point for the
%polyshape with line segment through [xl,yl].

%   Copyright 2022 The MathWorks, Inc.

[inside, ~, vinid, ~] =matlab.internal.math.psIntersect(poly,[xl,yl]);

%g2833607. Check both inside and vinid for their size.
validIntersection=(size(inside,1)>1)&&(size(vinid,1)>1);
if(validIntersection)
    %Non sorted vertices.
    closestIntersection=inside(2,1:2);
    isVertexIndex =vinid(2,1) == vinid(2,2);
    edgeIndex=vinid(2,1);
    vertexIndex=vinid(2,1);
else
    validIntersection=false;
    closestIntersection=nan(1,2);
    edgeIndex=nan;
    vertexIndex=nan;
    isVertexIndex=false;
end

% LocalWords:  xl yl vinid
