Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 6c75b16b authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

adapt mock in test and clean code

parent 4bd57b11
Pipeline #113071 passed with stages
in 139 minutes and 17 seconds
...@@ -63,7 +63,7 @@ public class ProcessorManager { ...@@ -63,7 +63,7 @@ public class ProcessorManager {
} }
if (requireRectangular && !measurementArea.isRectangular()) { if (requireRectangular && !measurementArea.isRectangular()) {
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas."); throw new RuntimeException(String.format("Measurement area for %d is required to be rectangular", measurementAreaId));
} }
return measurementArea; return measurementArea;
......
...@@ -35,27 +35,27 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm { ...@@ -35,27 +35,27 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm {
// compute everything // compute everything
List<Face> faces = generateFaces(state); List<Face> faces = generateFaces(state);
double area = 0.0; double area = 0.0;
int pedCount = 0; int pedCount = 0;
for (Face face : faces) { for (Face face : faces) {
if (this.measurementArea.contains(face.getSite())) { if (this.measurementArea.contains(face.getSite())) {
area += face.computeArea(); area += face.computeArea();
pedCount++; pedCount++;
} }
} }
return pedCount > 0 ? pedCount / area : 0; return pedCount > 0 ? pedCount / area : 0;
} }
private List<Face> generateFaces(@NotNull final SimulationState state) { private List<Face> generateFaces(@NotNull final SimulationState state) {
VoronoiDiagram voronoiDiagram = new VoronoiDiagram(this.voronoiArea); VoronoiDiagram voronoiDiagram = new VoronoiDiagram(this.voronoiArea);
// convert pedestrians to positions // convert pedestrians to positions
List<VPoint> pedestrianPositions = Agent.getPositions(state.getTopography().getElements(Agent.class)); List<VPoint> pedestrianPositions = Agent.getPositions(state.getTopography().getElements(Agent.class));
voronoiDiagram.computeVoronoiDiagram(pedestrianPositions); voronoiDiagram.computeVoronoiDiagram(pedestrianPositions);
// compute everything // compute everything
List<Face> faces = voronoiDiagram.getFaces(); List<Face> faces = voronoiDiagram.getFaces();
return faces == null ? Collections.emptyList() : faces; return faces == null ? Collections.emptyList() : faces;
} }
} }
...@@ -7,6 +7,9 @@ import org.vadere.state.attributes.processor.AttributesProcessor; ...@@ -7,6 +7,9 @@ import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass; import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.scenario.MeasurementArea; import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.List;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
...@@ -23,11 +26,12 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements ...@@ -23,11 +26,12 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor implements
@Override @Override
public void init(final ProcessorManager manager) { public void init(final ProcessorManager manager) {
super.init(manager); super.init(manager);
AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes(); AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes();
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true); MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId(), true);
MeasurementArea measurementVoronoiArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId(), true);
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), measurementArea)); this.setAlgorithm(new AreaDensityVoronoiAlgorithm(measurementVoronoiArea, measurementArea));
} }
@Override @Override
......
...@@ -43,7 +43,8 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> { ...@@ -43,7 +43,8 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
final int pedId = entry.getKey().getPedestrianId(); final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue(); final VPoint pos = entry.getValue();
if (getMeasurementArea().asVRectangle().contains(pos)) { //getMeasurementArea from AreaDataProcessor
if (this.getMeasurementArea().getShape().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId)); sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++; pedCount++;
} }
......
...@@ -36,6 +36,7 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<Timeste ...@@ -36,6 +36,7 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<Timeste
attr.setMeasurementAreaId(42); attr.setMeasurementAreaId(42);
MeasurementArea measurementArea = new MeasurementArea( MeasurementArea measurementArea = new MeasurementArea(
new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16))); new AttributesMeasurementArea(42, new VRectangle(0, 0, 16, 16)));
Mockito.when(manager.getMeasurementArea(42, false)).thenReturn(measurementArea);
Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea); Mockito.when(manager.getMeasurementArea(42, true)).thenReturn(measurementArea);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment