package za.redbridge.simulator.sensor;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jamie on 2014/08/05.
 */
public class ProximitySensor extends Sensor {

    private final List<Double> readings = new ArrayList<>(1);

    public ProximitySensor(double bearing) {
        super(bearing, 0.0, 10.0, 0.1);
    }

    public ProximitySensor(double bearing, double orientation, double range, double fieldOfView) {
        super(bearing, orientation, range, fieldOfView);
    }

    @Override
    protected SensorReading provideReading(List<SensedObject> objects) {
        double reading = 0.0;
        for (SensedObject object: objects) {
            double distance = object.getDistance() / range;
            reading += readingCurve(1 - distance);
        }

        readings.clear();
        readings.add(reading);
        return new SensorReading(readings);
    }

    protected double readingCurve(double fraction) {
        // Sigmoid proximity response
        final double offset = 0.5;
        return 1 / (1 + Math.exp(fraction + offset));
    }
}

@@ -311,17 +311,17 @@
 g, 0.0, 
-1
+3
 0.0, 0.1
@@ -622,153 +622,110 @@
     
-for (SensedObject object: objects) %7B%0A            double distance = object.getDistance() / range;%0A            reading += readingCurve(1 - distance
+if (!objects.isEmpty()) %7B%0A            reading = 1 - Math.min(objects.get(0).getDistance() / range, 1.0
 );%0A 

Tweak demo proximity sensor