function out = rectint(A,B)
%MATLAB Code Generation Library Function

%   Copyright 1984-2014 The MathWorks, Inc.
%#codegen

eml_invariant(nargin == 2,'MATLAB:minrhs');
eml_invariant( ...
    isnumeric(A) && isnumeric(B) && ...
    isreal(A) && isreal(B) && ...
    ismatrix(A) && ismatrix(B) && ...
    size(A,2) == 4 && size(B,2) == 4, ...
    'Coder:toolbox:InputsMustBeFourColumnRealMatrices');
m = size(A,1);
n = size(B,1);
out = coder.nullcopy(eml_expand(coder.internal.scalarEg(A,B),[m,n]));
for j = 1:n
    Br = B(j,1) + B(j,3);
    Bt = B(j,2) + B(j,4);
    for i = 1:m
        ABl = eml_max(A(i,1),B(j,1));
        ABr = eml_min(A(i,1) + A(i,3),Br);
        ABb = eml_max(A(i,2),B(j,2));
        ABt = eml_min(A(i,2) + A(i,4),Bt);
        if ABr >= ABl && ABt >= ABb
            out(i,j) = (ABr - ABl).*(ABt - ABb);
        else
            out(i,j) = 0;
        end
    end
end
