Commit f3a64b8d authored by Matthias Betz's avatar Matthias Betz
Browse files

fixed writing empty geometry properties when writing geometries without polygons in them

added more geometry tests
parent 79bc2870
Pipeline #2562 passed with stage
in 3 minutes and 9 seconds
......@@ -98,7 +98,9 @@ public class BoundarySurface extends CityObject {
for (Geometry geom : getGeometries()) {
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
setGeometryAccordingToLod(geom.getLod(), new MultiSurfaceProperty(ms));
if (ms != null) {
setGeometryAccordingToLod(geom.getLod(), new MultiSurfaceProperty(ms));
}
} else {
throw new IllegalStateException("BoundarySurfaces can only have MultiSurface geometries");
}
......
......@@ -50,10 +50,14 @@ public class BuildingInstallation extends CityObject {
for (Geometry geom : getGeometries()) {
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
setGeometryAccordingToLod(geom.getLod(), new MultiSurfaceProperty(ms));
if (ms != null) {
setGeometryAccordingToLod(geom.getLod(), new MultiSurfaceProperty(ms));
}
} else if (geom.getType() == GeometryType.COMPOSITE_SURFACE) {
CompositeSurface cs = CityGmlUtils.createCompositeSurface(geom, factory, config);
setGeometryAccordingToLod(geom.getLod(), new CompositeSurfaceProperty(cs));
if (cs != null) {
setGeometryAccordingToLod(geom.getLod(), new CompositeSurfaceProperty(cs));
}
} else {
throw new IllegalStateException("BuildingInstallation not have Solid geometries");
}
......
......@@ -274,11 +274,7 @@ public class Geometry extends GmlElement {
}
public Edge getEdge(Vertex v1, Vertex v2) {
Edge edge = edgeMap.get(new SerializablePair<>(v1, v2));
if (edge != null) {
return edge;
}
return null;
return edgeMap.get(new SerializablePair<>(v1, v2));
}
public void updateEdgesAndVertices() {
......@@ -332,7 +328,7 @@ public class Geometry extends GmlElement {
Geometry geom2 = p.getLinkedFromPolygon().getParent();
for (ConcretePolygon newPoly : polygons) {
addPolygon(newPoly);
geom2.addPolygon(new LinkedPolygon(newPoly, this));
geom2.addPolygon(new LinkedPolygon(newPoly, geom2));
}
} else {
for (Polygon newPoly : polygons) {
......
......@@ -42,6 +42,11 @@ public class LinkedPolygon extends Polygon {
private Geometry parent;
private ConcretePolygon poly;
/**
*
* @param poly polygon this is linked to
* @param parent the parent of the linked polygon
*/
public LinkedPolygon(ConcretePolygon poly, Geometry parent) {
this.parent = parent;
this.poly = poly;
......@@ -217,11 +222,6 @@ public class LinkedPolygon extends Polygon {
poly.removeRings();
}
@Override
public boolean isLinkedTo() {
return false;
}
@Override
public boolean isLink() {
return true;
......@@ -246,15 +246,20 @@ public class LinkedPolygon extends Polygon {
public ConcretePolygon getOriginal() {
return poly;
}
@Override
public void prepareForChecking() {
poly.prepareForChecking();
}
@Override
public void clearMetaInformation() {
poly.clearMetaInformation();
}
@Override
public boolean isLinkedTo() {
return false;
}
}
......@@ -74,16 +74,16 @@ public class GeometryTest {
}
@Test
public void testRemovePolygon() {
public void testRemovePolygonConcreteWithLink() {
ParserConfiguration config = new ParserConfiguration(4, false);
AbstractBoundarySurface abs = new WallSurface();
BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
BuildingInstallation bi = new BuildingInstallation();
bi.setGmlObject(gmlBi);
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
Polygon p = new ConcretePolygon();
ConcretePolygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
lr.addVertex(new Vertex(0, 0, 0));
......@@ -92,9 +92,76 @@ public class GeometryTest {
p.setPartOfSurface(bs);
p.setPartOfInstallation(bi);
bs.addGeometry(geom);
Geometry biGeom = new Geometry(GeometryType.COMPOSITE_SURFACE, Lod.LOD2);
biGeom.addPolygon(new LinkedPolygon(p, biGeom));
bi.addGeometry(biGeom);
geom.removePolygon(p);
assertEquals(0, geom.getPolygons().size());
assertEquals(0, biGeom.getPolygons().size());
bs.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(abs.getLod2MultiSurface());
bi.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(gmlBi.getLod2Geometry());
}
@Test
public void testRemovePolygonOnlyConcrete() {
ParserConfiguration config = new ParserConfiguration(4, false);
AbstractBoundarySurface abs = new WallSurface();
BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
ConcretePolygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
lr.addVertex(new Vertex(0, 0, 0));
geom.addPolygon(p);
p.setPartOfSurface(bs);
bs.addGeometry(geom);
geom.removePolygon(p);
bs.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(abs.getLod2MultiSurface());
}
@Test
public void testRemovePolygonLinked() {
ParserConfiguration config = new ParserConfiguration(4, false);
AbstractBoundarySurface abs = new WallSurface();
BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
BuildingInstallation bi = new BuildingInstallation();
bi.setGmlObject(gmlBi);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
ConcretePolygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
lr.addVertex(new Vertex(0, 0, 0));
bs.addGeometry(geom);
geom.addPolygon(p);
p.setPartOfSurface(bs);
p.setPartOfInstallation(bi);
Geometry biGeom = new Geometry(GeometryType.COMPOSITE_SURFACE, Lod.LOD2);
LinkedPolygon linkedPolygon = new LinkedPolygon(p, biGeom);
biGeom.addPolygon(linkedPolygon);
bi.addGeometry(biGeom);
biGeom.removePolygon(linkedPolygon);
assertEquals(0, geom.getPolygons().size());
assertEquals(0, biGeom.getPolygons().size());
bs.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(abs.getLod2MultiSurface());
......@@ -192,8 +259,7 @@ public class GeometryTest {
public void testContainsError() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
assertFalse(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
geom.addCheckResult(
new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
geom.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
assertTrue(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
ConcretePolygon p = new ConcretePolygon();
p.setExteriorRing(mock(LinearRing.class));
......@@ -203,13 +269,12 @@ public class GeometryTest {
new CheckResult(CheckId.C_GE_P_INNER_RINGS_NESTED, ResultStatus.ERROR, mock(CheckError.class)));
assertTrue(geom.containsError(CheckId.C_GE_P_INNER_RINGS_NESTED));
}
@Test
public void testClearAllContainedCheckResults() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
assertFalse(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
geom.addCheckResult(
new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
geom.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
assertTrue(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
Polygon p = mock(Polygon.class);
geom.addPolygon(p);
......@@ -217,13 +282,12 @@ public class GeometryTest {
verify(p).clearAllContainedCheckResults();
assertFalse(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
}
@Test
public void testCollectContainedErrors() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
assertFalse(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
geom.addCheckResult(
new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
geom.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
assertTrue(geom.containsError(CheckId.C_GE_P_HOLE_OUTSIDE));
Polygon p = mock(Polygon.class);
geom.addPolygon(p);
......@@ -232,13 +296,12 @@ public class GeometryTest {
verify(p).collectContainedErrors(errors);
assertEquals(1, errors.size());
}
@Test
public void testContainsAnyError() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
assertFalse(geom.containsAnyError());
geom.addCheckResult(
new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
geom.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR, mock(CheckError.class)));
assertTrue(geom.containsAnyError());
Polygon p = mock(Polygon.class);
geom.addPolygon(p);
......@@ -248,7 +311,7 @@ public class GeometryTest {
when(p.containsAnyError()).thenReturn(true);
assertTrue(geom.containsAnyError());
}
@Test
public void testAccept() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
......@@ -262,22 +325,116 @@ public class GeometryTest {
geom.accept(c);
verify(p).accept(c);
}
@Test
public void testGetVertices() {
Geometry geom = GeometryTestUtils.createDummyGeometry(GeometryType.SOLID);
List<Vertex> vertices = geom.getVertices();
assertEquals(4, vertices.size());
}
@Test
public void testGetEdgesAdjacentToVertex() {
Geometry geom = GeometryTestUtils.createDummyGeometryWithInnerRingWithNeighboringPolygon(GeometryType.SOLID, Lod.LOD1);
Geometry geom = GeometryTestUtils.createDummyGeometryWithInnerRingWithNeighboringPolygon(GeometryType.SOLID,
Lod.LOD1);
Polygon polygon = geom.getPolygons().get(1);
Vertex vertex = polygon.getExteriorRing().getVertices().get(0);
List<Edge> edges = geom.getEdgesAdjacentTo(vertex);
assertEquals(2, edges.size());
assertEquals(3, edges.size());
}
@Test
public void testGetEdge() {
Geometry geom = GeometryTestUtils.createDummyGeometry(GeometryType.SOLID);
Polygon poly = geom.getPolygons().get(0);
LinearRing ext = poly.getExteriorRing();
Vertex v0 = ext.getVertices().get(0);
Vertex v1 = ext.getVertices().get(1);
Edge e = geom.getEdge(v0, v1);
assertNotNull(e);
assertEquals(v0, e.getFrom());
assertEquals(v1, e.getTo());
Edge e2 = geom.getEdge(v1, v0);
assertEquals(e, e2);
Vertex v2 = ext.getVertices().get(2);
Edge e3 = geom.getEdge(v0, v2);
assertNull(e3);
}
@Test
public void testUpdateVertices() {
Geometry geom = GeometryTestUtils.createDummyGeometryWithInnerRingWithNeighboringPolygon(GeometryType.SOLID,
Lod.LOD0);
geom.updateVertices();
Polygon polygon = geom.getPolygons().get(0);
Vertex v1 = polygon.getExteriorRing().getVertices().get(0);
assertTrue(v1.getAdjacentRings(geom).contains(geom.getPolygons().get(0).getExteriorRing()));
assertTrue(v1.getAdjacentRings(geom).contains(geom.getPolygons().get(1).getExteriorRing()));
assertEquals(9, geom.getVertices().size());
}
@Test
public void testGetEdgesAdjacentToPolygon() {
Geometry geom = GeometryTestUtils.createDummyGeometryWithInnerRingWithNeighboringPolygon(GeometryType.SOLID,
Lod.LOD0);
Polygon polygon = geom.getPolygons().get(0);
List<Edge> edges = new ArrayList<>();
for (int i = 0; i < polygon.getExteriorRing().getVertices().size() - 1; i++) {
Vertex v1 = polygon.getExteriorRing().getVertices().get(i);
Vertex v2 = polygon.getExteriorRing().getVertices().get(i + 1);
Edge e = geom.getEdge(v1, v2);
edges.add(e);
}
for (LinearRing lr : polygon.getInnerRings()) {
for (int i = 0; i < lr.getVertices().size() - 1; i++) {
Vertex v1 = lr.getVertices().get(i);
Vertex v2 = lr.getVertices().get(i + 1);
Edge e = geom.getEdge(v1, v2);
edges.add(e);
}
}
List<Edge> edgesAdjacentTo = geom.getEdgesAdjacentTo(polygon);
for (Edge e : edges) {
assertTrue(edgesAdjacentTo.contains(e));
}
}
@Test
public void testContainsPolygon() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
ConcretePolygon cdPoly = new ConcretePolygon();
geom.addPolygon(cdPoly);
cdPoly.setGmlId(new GmlId("test1"));
ConcretePolygon cdPoly2 = new ConcretePolygon();
geom.addPolygon(cdPoly2);
cdPoly2.setGmlId(new GmlId("test2"));
ConcretePolygon cdPoly3 = new ConcretePolygon();
cdPoly3.setGmlId(new GmlId("test1"));
ConcretePolygon cdPoly4 = new ConcretePolygon();
cdPoly4.setGmlId(new GmlId("test3"));
assertTrue(geom.containsPolygon(cdPoly3));
assertFalse(geom.containsPolygon(cdPoly4));
}
@Test
public void testClearMetaInformation() {
Geometry geom = GeometryTestUtils.createDummyGeometryWithInnerRingWithNeighboringPolygon(GeometryType.SOLID,
Lod.LOD0);
assertNotNull(geom.getVertices());
geom.clearMetaInformation();
assertNull(geom.getVertices());
assertNull(geom.getEdges());
geom.clearMetaInformation();
assertNull(geom.getVertices());
assertNull(geom.getEdges());
}
}
......@@ -65,7 +65,6 @@ public class GeometryTestUtils {
Vertex v4 = new Vertex(10, 0, 0);
lr.getVertices().add(v4);
lr.getVertices().add(v1);
geom.updateEdgesAndVertices();
LinearRing interiorRing = new LinearRing(LinearRingType.INTERIOR);
polygon.addInteriorRing(interiorRing);
......@@ -87,6 +86,7 @@ public class GeometryTestUtils {
lr2.addVertex(v2);
lr2.addVertex(new Vertex(0, 5, 10));
lr2.addVertex(v1);
geom.updateEdgesAndVertices();
return geom;
}
......
Supports Markdown
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