function [splitPolygons,isValid] = splitPolygonByEdge(point,intersection,edgeIndex,polygon)
%splitPolygonByEdge Split polygon into two by a line from POINT to INTERSECTION lies on
%EDGEIDX of POLYGON. Adds point of intersection to polygon and redirects
%call to splitPolygonByVertex.

%   Copyright 2022 The MathWorks, Inc.

if(edgeIndex==size(polygon,1))
    newPolygon=[polygon(1:edgeIndex,:);intersection];
else
    newPolygon= [polygon(1:edgeIndex,:);intersection;polygon(edgeIndex+1:end,:)];
end
i=find(ismember(newPolygon,point,'rows'));
j=edgeIndex+1;
[splitPolygons,isValid] = uav.internal.coveragePlanner.splitPolygonByVertex(i,j,newPolygon);
end
