function ap = myVOCap(rec, prec, recThresh)

mrec=[0 ; rec ; 1];
mpre=[0 ; prec ; 0];
for i=numel(mpre)-1:-1:1
    mpre(i)=max(mpre(i),mpre(i+1));
end
i=find(mrec(2:end)~=mrec(1:end-1))+1;
threshInd = find(mrec > recThresh, 1, 'first');
i = i(i <= threshInd);
ap=sum((mrec(i)-mrec(i-1)).*mpre(i));

% ap can't be greater than the recall.
if ap > recThresh
  ap = recThresh;
end
