The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit 022ed92d authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

fix issue #66, add some simple equal test cases for obstacles, polygons, and rectangles.

parent c137a8c1
Pipeline #54036 passed with stage
in 53 seconds
......@@ -88,15 +88,6 @@
"bounded" : true
},
"obstacles" : [ {
"shape" : {
"x" : 10.0,
"y" : 40.0,
"width" : 15.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 9.0,
"y" : 21.0,
......@@ -116,362 +107,11 @@
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 0.5001
}, {
"x" : -1.0E-4,
"y" : 0.5001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : -1.0E-4
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 59.4999
}, {
"x" : 35.0001,
"y" : 59.4999
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : 60.0001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 0.5001
}, {
"x" : -1.0E-4,
"y" : 0.5001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : -1.0E-4
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 59.4999
}, {
"x" : 35.0001,
"y" : 59.4999
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : 60.0001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 0.5001
}, {
"x" : -1.0E-4,
"y" : 0.5001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : -1.0E-4
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 59.4999
}, {
"x" : 35.0001,
"y" : 59.4999
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : 60.0001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 0.5001
}, {
"x" : -1.0E-4,
"y" : 0.5001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : -1.0E-4
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 59.4999
}, {
"x" : 35.0001,
"y" : 59.4999
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : 60.0001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 0.5001
}, {
"x" : -1.0E-4,
"y" : 0.5001
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : -1.0E-4
}, {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : 60.0001
}, {
"x" : 34.4999,
"y" : -1.0E-4
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 35.0001,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : 59.4999
}, {
"x" : 35.0001,
"y" : 59.4999
} ]
},
"id" : -1
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : -1.0E-4,
"y" : 60.0001
}, {
"x" : -1.0E-4,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : -1.0E-4
}, {
"x" : 0.5001,
"y" : 60.0001
} ]
"x" : 10.0,
"y" : 40.0,
"width" : 15.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
} ],
......
......@@ -147,6 +147,7 @@ public class Simulation {
}
processorManager.postLoop(this.simulationState);
topographyController.postLoop(this.simTimeInSec);
}
/**
......
......@@ -68,4 +68,8 @@ public class TopographyController extends OfflineTopographyController {
public void update(double simTimeInSec) {
recomputeCells();
}
public void postLoop(double simTimeInSec) {
topography.reset();
}
}
......@@ -31,4 +31,21 @@ public class AttributesObstacle extends Attributes {
return id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AttributesObstacle that = (AttributesObstacle) o;
if (id != that.id) return false;
return shape != null ? shape.equals(that.shape) : that.shape == null;
}
@Override
public int hashCode() {
int result = shape != null ? shape.hashCode() : 0;
result = 31 * result + id;
return result;
}
}
\ No newline at end of file
package org.vadere.state.scenario;
import org.junit.Before;
import org.junit.Test;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VRectangle;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* @author Benedikt Zoennchen
*/
public class TestObstacle {
private Obstacle obstacle1;
private Obstacle obstacle2;
private Obstacle obstacle3;
private Obstacle obstacle4;
private Obstacle obstacle5;
@Before
public void setUp() {
VRectangle rectangle1 = new VRectangle(0, 0, 10, 10);
VRectangle rectangle2 = new VRectangle(0, 0, 10, 10);
VPolygon polygon1 = GeometryUtils.polygonFromPoints2D(rectangle1.getCornerPoints());
VPolygon polygon2 = GeometryUtils.polygonFromPoints2D(rectangle2.getCornerPoints());
AttributesObstacle attributesObstacle1 = new AttributesObstacle(-1, rectangle1);
AttributesObstacle attributesObstacle2 = new AttributesObstacle(-1, rectangle2);
AttributesObstacle attributesObstacle3 = new AttributesObstacle(-1, polygon1);
AttributesObstacle attributesObstacle4 = new AttributesObstacle(-1, polygon2);
obstacle1 = new Obstacle(attributesObstacle1);
obstacle2 = new Obstacle((AttributesObstacle)attributesObstacle1.clone());
obstacle3 = new Obstacle(attributesObstacle2);
obstacle4 = new Obstacle(attributesObstacle3);
obstacle5 = new Obstacle(attributesObstacle4);
}
@Test
public void testEquals() {
assertEquals("equals() does not work properly.", obstacle1, obstacle2);
assertEquals("equals() does not work properly.", obstacle1, obstacle3);
assertNotEquals("equals() does not work properly.", obstacle1, obstacle4);
assertEquals("equals() does not work properly.", obstacle4, obstacle5);
}
}
......@@ -10,6 +10,10 @@ import java.util.List;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.ShapeType;
/**
* Note: A polygon which has the same points as a rectangle is not
* equals to the rectangle.
*/
public class VPolygon extends Path2D.Double implements VShape {
private static final long serialVersionUID = 6534837112398242609L;
......
......@@ -6,6 +6,10 @@ import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.ShapeType;
@SuppressWarnings("serial")
/**
* Note: A rectangle which has the same corner points as a polygon is not
* equals to the polygon.
*/
public class VRectangle extends Rectangle2D.Double implements VShape {
/**
......
......@@ -21,6 +21,7 @@ import org.vadere.util.io.IOUtils;
*/
public class TestPolygon {
private VPolygon testPolygon;
private VPolygon copyTestPolygon;
private VTriangle testTriangle;
private final double roomSideLen = 100;
......@@ -31,6 +32,11 @@ public class TestPolygon {
new VPoint(roomSideLen, roomSideLen),
new VPoint(0, roomSideLen));
copyTestPolygon = GeometryUtils.polygonFromPoints2D(new VPoint(0, 0),
new VPoint(roomSideLen, 0),
new VPoint(roomSideLen, roomSideLen),
new VPoint(0, roomSideLen));
testTriangle = new VTriangle(new VPoint(30, 50), new VPoint(0, 0),
new VPoint(80, 0));
}
......@@ -95,4 +101,9 @@ public class TestPolygon {
g2string);
}
@Test
public void testEquals() {
assertEquals("equals() does not work properly.", testPolygon, copyTestPolygon);
}
}
package org.vadere.util.geometry;
import org.junit.Before;
import org.junit.Test;
import org.vadere.util.geometry.shapes.VRectangle;
import static org.junit.Assert.assertEquals;
/**
* @author Benedikt Zoennchen
*/
public class TestRectangle {
private VRectangle rect1;
private VRectangle rect2;
@Before
public void setUp() {
rect1 = new VRectangle(1.0, 2.0, 10.123, 22.3123);
rect2 = new VRectangle(1.0, 2.0, 10.123, 22.3123);
}
@Test
public void testEquals() {
assertEquals("equals() does not work properly.", rect1, rect2);
}
}
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