24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 583f67cf authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add checkStairTreadSanity check

parent 9fe754e4
......@@ -305,7 +305,7 @@ TopographyChecker.source.noTargetIdSet=No Target Ids set for Source.
TopographyChecker.source.noTargetIdAndNoSpawn=No Target Ids set for Source with SpawnNumber 0. This might be an error.
TopographyChecker.source.idNotUnique=Multiple Sources have the same ID.
TopographyChecker.source.overlapWithObstacle=Source overlaps with Obstacle. This leads to pedestrians spawn in obstacle.
#TopographyChecker.stairs.wrongTreadDim"=
TopographyChecker.stairs.wrongTreadDim=Stair treadDepth outside of allowed dimension.
TopographyChecker.target.unused=The target is not used in any source. Remove target to increase performance.
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
......
......@@ -304,7 +304,7 @@ TopographyChecker.source.noTargetIdSet=In der Quelle wurden keine Ziel Ids verge
TopographyChecker.source.noTargetIdAndNoSpawn=In der Quelle wurden keine Ziel Ids vergeben, aber die Spawn Anzahl ist bei 0.
TopographyChecker.source.idNotUnique=Quellen haben keine eindeutige ID.
TopographyChecker.source.overlapWithObstacle=Quelle und Hinderniss \u00fcberlappen sich. Dies kann f\u00fcrt zuf\u00fchren, dass Personen im Hinderniss erzeugt werden.
#TopographyChecker.stairs.wrongTreadDim"=
TopographyChecker.stairs.wrongTreadDim=Stufentiefe ist au\u00dferhalb des Definitionsbereichs.
TopographyChecker.target.unused=Das Ziel wird von keiner Quelle verwendet. Entferne das Ziel um die Performance zu erh\u00fchen
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
......
......@@ -4,6 +4,7 @@ import org.apache.commons.math3.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Stairs;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
......@@ -60,17 +61,36 @@ public class TopographyChecker {
}
public List<TopographyCheckerMessage> checkBuildingStep(){
List<TopographyCheckerMessage> ret = new ArrayList<>();
ret.addAll(checkValidTargetsInSource());
ret.addAll(checkUniqueSourceId());
ret.addAll(checkSourceObstacleOverlap());
ret.addAll(checkUnusedTargets());
ret.addAll(checkStairTreadSanity());
return ret;
}
public List<TopographyCheckerMessage> checkStairTreadSanity() {
List<TopographyCheckerMessage> ret = new ArrayList<>();
topography.getStairs().forEach( stairs -> {
double treadDepth = stairs.getTreadDepth();
if (treadDepth < Stairs.MIN_TREAD_DEPTH || treadDepth > Stairs.MAX_TREAD_DEPTH){
ret.add(msgBuilder
.warning()
.target(stairs)
.reason(TopographyCheckerReason.STAIRS_TREAD_DIM_WRONG
, "(" + Stairs.MIN_TREAD_DEPTH + "m &lt; treadDepth &gt; " + Stairs.MAX_TREAD_DEPTH +
"m) current treadDepth is: " + String.format("%.3fm",stairs.getTreadDepth()))
.build()
);
}
});
return ret;
}
public List<TopographyCheckerMessage> checkUnusedTargets() {
List<TopographyCheckerMessage> ret = new ArrayList<>();
Set<Integer> usedTargetIds = new HashSet<>();
......
......@@ -6,6 +6,7 @@ import org.junit.Test;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.builder.AttributesObstacleBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesSourceBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesStairsBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesTargetBuilder;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Source;
......@@ -133,8 +134,8 @@ public class TopographyCheckerTest {
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkValidTargetsInSource();
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_NO_TARGET_ID_NO_SPAWN, out.get(0).getReason());
TopographyCheckerMessage msg = hasOneElement(out);
assertEquals(TopographyCheckerReason.SOURCE_NO_TARGET_ID_NO_SPAWN, msg.getReason());
}
@Test
......@@ -149,9 +150,9 @@ public class TopographyCheckerTest {
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkValidTargetsInSource();
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_NO_TARGET_ID_SET, out.get(0).getReason());
isErrorMsg(out.get(0));
TopographyCheckerMessage msg = hasOneElement(out);
assertEquals(TopographyCheckerReason.SOURCE_NO_TARGET_ID_SET, msg.getReason());
isErrorMsg(msg);
}
......@@ -172,9 +173,9 @@ public class TopographyCheckerTest {
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkValidTargetsInSource();
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, out.get(0).getReason());
isErrorMsg(out.get(0));
TopographyCheckerMessage msg = hasOneElement(out);
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, msg.getReason());
isErrorMsg(msg);
}
@Test
......@@ -198,10 +199,10 @@ public class TopographyCheckerTest {
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkValidTargetsInSource();
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, out.get(0).getReason());
isErrorMsg(out.get(0));
assertEquals("[2]", out.get(0).getReasonModifier());
TopographyCheckerMessage msg = hasOneElement(out);
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, msg.getReason());
isErrorMsg(msg);
assertEquals("[2]", msg.getReasonModifier());
}
@Test
......@@ -221,7 +222,7 @@ public class TopographyCheckerTest {
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkValidTargetsInSource();
assertEquals(0, out.size());
hasNoElement(out);
}
// Test checkSourceObstacleOverlap
......@@ -244,7 +245,7 @@ public class TopographyCheckerTest {
List<TopographyCheckerMessage> out = checker.checkSourceObstacleOverlap();
assertEquals( 0, out.size());
hasNoElement(out);
}
......@@ -277,8 +278,7 @@ public class TopographyCheckerTest {
List<TopographyCheckerMessage> out = checker.checkSourceObstacleOverlap();
TopographyCheckerMessage msg = out.get(0);
assertEquals( 1, out.size());
TopographyCheckerMessage msg = hasOneElement(out);
isErrorMsg(msg);
assertEquals(TopographyCheckerReason.SOURCE_OVERLAP_WITH_OBSTACLE, msg.getReason());
assertEquals(testSource, msg.getMsgTarget().getTargets().get(0));
......@@ -304,7 +304,7 @@ public class TopographyCheckerTest {
List<TopographyCheckerMessage> out = checker.checkUnusedTargets();
assertEquals(0, out.size());
hasNoElement(out);
}
@Test
......@@ -322,13 +322,73 @@ public class TopographyCheckerTest {
List<TopographyCheckerMessage> out = checker.checkUnusedTargets();
assertEquals(1, out.size());
TopographyCheckerMessage msg = out.get(0);
TopographyCheckerMessage msg = hasOneElement(out);
isWarnMsg(msg);
assertEquals(TopographyCheckerReason.TARGET_UNUSED, msg.getReason());
}
// Test checkStairTreadSanity
@Test
public void tesCheckStairTreadSanityTreadToBig(){
AttributesStairsBuilder attrStairsB = AttributesStairsBuilder.anAttributesStairs();
builder.addStairs(attrStairsB
.shape(new VRectangle(0,0,10.0,10.0))
.treadCount(3) // 10m / 3treads = 3.333
.build());
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkStairTreadSanity();
TopographyCheckerMessage msg = hasOneElement(out);
isWarnMsg(msg);
assertEquals(TopographyCheckerReason.STAIRS_TREAD_DIM_WRONG, msg.getReason());
}
@Test
public void tesCheckStairTreadSanityTreadToSmall(){
AttributesStairsBuilder attrStairsB = AttributesStairsBuilder.anAttributesStairs();
builder.addStairs(attrStairsB
.shape(new VRectangle(0,0,10.0,10.0))
.treadCount(200) // 10m / 200 treads = 0.050
.build());
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkStairTreadSanity();
TopographyCheckerMessage msg = hasOneElement(out);
isWarnMsg(msg);
assertEquals(TopographyCheckerReason.STAIRS_TREAD_DIM_WRONG, msg.getReason());
}
@Test
public void tesCheckStairTreadSanityTreadOk(){
AttributesStairsBuilder attrStairsB = AttributesStairsBuilder.anAttributesStairs();
builder.addStairs(attrStairsB
.shape(new VRectangle(0,0,10.0,10.0))
.treadCount(80) // 10m / 80treads = 0.125
.build());
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkStairTreadSanity();
hasNoElement(out);
}
private TopographyCheckerMessage hasOneElement(List<TopographyCheckerMessage> out){
assertEquals(1, out.size());
return out.get(0);
}
private void hasNoElement(List<TopographyCheckerMessage> out){
assertEquals(0, out.size());
}
private void isErrorMsg(TopographyCheckerMessage msg){
assertEquals(TopographyCheckerMessageType.ERROR, msg.getMsgType());
......
......@@ -2,10 +2,12 @@ package org.vadere.simulator.util;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.AttributesSource;
import org.vadere.state.attributes.scenario.AttributesStairs;
import org.vadere.state.attributes.scenario.AttributesTarget;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Stairs;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -97,4 +99,18 @@ public class TopographyTestBuilder {
return this;
}
TopographyTestBuilder addStairs(){
addStairs(new AttributesStairs());
return this;
}
TopographyTestBuilder addStairs(AttributesStairs attr){
Stairs stairs = new Stairs(attr);
lastAddedElement = stairs;
topography.addStairs(stairs);
return this;
}
}
package org.vadere.state.attributes.scenario.builder;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesStairs;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VShape;
public final class AttributesStairsBuilder {
private VShape shape = null;
private int id = Attributes.ID_NOT_SET;
private int treadCount = 1;
private Vector2D upwardDirection = new Vector2D(1.0, 0.0);
private AttributesStairsBuilder() {
}
public static AttributesStairsBuilder anAttributesStairs() {
return new AttributesStairsBuilder();
}
public AttributesStairsBuilder shape(VShape shape) {
this.shape = shape;
return this;
}
public AttributesStairsBuilder id(int id) {
this.id = id;
return this;
}
public AttributesStairsBuilder treadCount(int treadCount) {
this.treadCount = treadCount;
return this;
}
public AttributesStairsBuilder upwardDirection(Vector2D upwardDirection) {
this.upwardDirection = upwardDirection;
return this;
}
public AttributesStairs build() {
return new AttributesStairs(id, shape, treadCount, upwardDirection);
}
}
......@@ -19,6 +19,9 @@ import org.vadere.util.geometry.shapes.VShape;
public class Stairs extends ScenarioElement {
private static Logger logger = LogManager.getLogger(Stairs.class);
public static double MIN_TREAD_DEPTH = 0.100;
public static double MAX_TREAD_DEPTH = 0.350;
public static class Tread {
public final VLine treadline;
......
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