function [ distance ] = IRSensorAll( coords, rectangles,...
    numberOfRectangles, sensorx, sensory, sensorTheta)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
    distance = -1;
    intersectionx = 0;
    intersectiony = 0;
    
    for i = 1:numberOfRectangles
        rect = rectangles(i, :);
        [thisDistance, thisIntx, thisInty] = IRSensor(rect, sensorx, sensory, sensorTheta); 
        if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
            distance = thisDistance;
            intersectionx = thisIntx;
            intersectiony = thisInty;
        end
    end
    
    %have IR also react to other cars
    %check car 1:
    car1x = coords(1, 1);
    car1y = coords(1, 2);
    car1theta = coords(1, 3);
    thisDistance = IRSensorCar(sensorx, sensory, sensorTheta, car1x, car1y, car1theta);
    if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
        distance = thisDistance;
    end
    
    %check car 3:
    car3x = coords(3, 1);
    car3y = coords(3, 2);
    car3theta = coords(3, 3);
    thisDistance = IRSensorCar(sensorx, sensory, sensorTheta, car3x, car3y, car3theta);
    if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
        distance = thisDistance;
    end

end
