function AdjacentMatrix=computeAdjacency(polygons)
%computeAdjacency compute adjacency of polygons with respect to each other.

%   Copyright 2022 The MathWorks, Inc.
%#codegen
AdjacentMatrix=zeros(numel(polygons),numel(polygons));
%allowance for intersections. A larger tolerance compensates for artificial
%spacing between two polygons split by a line due to floating point errors
%in intersection tool.
allowance=1e-1;

%Disable warning for simplification.
warning('off','MATLAB:polyshape:repairedBySimplify');
%Enable warning later.
cleanup =onCleanup(@()warning('on', 'MATLAB:polyshape:repairedBySimplify'));

for i=1:1:numel(polygons)
    for j=i+1:1:numel(polygons)
        %Polyshape arrays not supported for codegen
            pShapes_I=polybuffer(polyshape(polygons{i}),allowance);
            pShapes_J=polybuffer(polyshape(polygons{j}),allowance);
            adjacentNodes =~isempty(intersect(pShapes_I,pShapes_J).Vertices);
            AdjacentMatrix(i,j)=adjacentNodes;
            AdjacentMatrix(j,i)=adjacentNodes;
    end
end
end
