function [ distance ] = IRSensorLeft45All( 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] = IRSensorLeft45(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 2:
    car2x = coords(2, 1);
    car2y = coords(2, 2);
    car2theta = coords(2, 3);
    thisDistance = IRSensorCarLeft45(sensorx, sensory, sensorTheta, car2x, car2y, car2theta);
    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 = IRSensorCarLeft45(sensorx, sensory, sensorTheta, car3x, car3y, car3theta);
    if (distance == -1 || (thisDistance > 0 && thisDistance < distance))
        distance = thisDistance;
    end
end

