Commit 5d40c7b6 authored by Matthias Betz's avatar Matthias Betz
Browse files

CityDoctor2 validation open source release

parents
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class FaceOutCheckTest {
private Geometry createBadGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = createVertex(0, 0, 0, geom);
Vertex v1 = createVertex(10, 0, 0, geom);
Vertex v2 = createVertex(10, 10, 0, geom);
Vertex v3 = createVertex(0, 10, 0, geom);
Vertex v4 = createVertex(0, 0, 10, geom);
Vertex v5 = createVertex(10, 0, 10, geom);
Vertex v6 = createVertex(10, 10, 10, geom);
Vertex v7 = createVertex(0, 10, 10, geom);
addPolygon(geom, v0, v1, v2, v3);
addPolygon(geom, v1, v5, v6, v2);
addPolygon(geom, v4, v7, v6, v5);
addPolygon(geom, v0, v3, v7, v4);
addPolygon(geom, v3, v2, v6, v7);
addPolygon(geom, v0, v4, v5, v1);
return geom;
}
private Geometry createGoodGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = createVertex(0, 0, 0, geom);
Vertex v1 = createVertex(10, 0, 0, geom);
Vertex v2 = createVertex(10, 10, 0, geom);
Vertex v3 = createVertex(0, 10, 0, geom);
Vertex v4 = createVertex(0, 0, 10, geom);
Vertex v5 = createVertex(10, 0, 10, geom);
Vertex v6 = createVertex(10, 10, 10, geom);
Vertex v7 = createVertex(0, 10, 10, geom);
addPolygon(geom, v3, v2, v1, v0);
addPolygon(geom, v2, v6, v5, v1);
addPolygon(geom, v5, v6, v7, v4);
addPolygon(geom, v4, v7, v3, v0);
addPolygon(geom, v7, v6, v2, v3);
addPolygon(geom, v1, v5, v4, v0);
return geom;
}
private void addPolygon(Geometry geom, Vertex v0, Vertex v1, Vertex v2, Vertex v3) {
Polygon poly;
LinearRing ex;
poly = new ConcretePolygon();
poly.setParent(geom);
geom.addPolygon(poly);
ex = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(ex);
ex.setParent(poly);
ex.addVertex(v0);
ex.addVertex(v1);
ex.addVertex(v2);
ex.addVertex(v3);
ex.addVertex(v0);
}
private Vertex createVertex(double x, double y, double z, Geometry geom) {
return new Vertex(x, y, z);
}
@Test
public void testGoodGeometry() {
Geometry geom = createGoodGeometry();
FaceOutCheck foc = new FaceOutCheck();
foc.check(geom);
Assert.assertEquals(ResultStatus.OK, geom.getCheckResult(foc).getResultStatus());
}
@Test
public void testBadGeometry() {
Geometry geom = createBadGeometry();
FaceOutCheck foc = new FaceOutCheck();
foc.check(geom);
Assert.assertEquals(ResultStatus.ERROR, geom.getCheckResult(foc).getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class HoleOutsideCheckTest {
@Test
public void testHoleOutside() {
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
// create exterior ring
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(ext);
Vertex firstVertex = addVertex(0, 0, 0, ext, geom);
addVertex(3, 0, 0, ext, geom);
addVertex(3, 3, 0, ext, geom);
addVertex(0, 3, 0, ext, geom);
ext.addVertex(firstVertex);
// create interior ring outside exterior ring
LinearRing inter = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(inter);
inter.setParent(p);
Vertex firstIntVertex = addVertex(4, 0, 0, inter, geom);
addVertex(5, 0, 0, inter, geom);
addVertex(5, 1, 0, inter, geom);
addVertex(4, 1, 0, inter, geom);
inter.addVertex(firstIntVertex);
HoleOutsideCheck c = new HoleOutsideCheck();
c.check(p);
CheckResult cr = p.getCheckResult(c);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_HOLE_OUTSIDE, cr.getError().getErrorId());
}
@Test
public void testPolygonGood() {
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(8, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(8, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(9, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(9, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
HoleOutsideCheck c = new HoleOutsideCheck();
c.check(poly);
assertEquals(ResultStatus.OK, poly.getCheckResult(c).getResultStatus());
}
private Vertex addVertex(double x, double y, double z, LinearRing lr, Geometry geom) {
Vertex v = new Vertex(x, y, z);
lr.addVertex(v);
return v;
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class InteriorDisconnectedCheckTest {
/**
* One interior ring disconnects interior
*/
@Test
public void testBadPolygon1() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
Vertex v0 = new Vertex(2, 2, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 2, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(2, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing intRing = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(intRing);
Vertex v4 = new Vertex(4, 2, 0);
intRing.addVertex(v4);
Vertex v5 = new Vertex(2, 6, 0);
intRing.addVertex(v5);
Vertex v6 = new Vertex(4, 6, 0);
intRing.addVertex(v6);
intRing.addVertex(v4);
InteriorDisconnectedCheck c = new InteriorDisconnectedCheck();
c.check(p);
Assert.assertEquals(ResultStatus.ERROR, p.getCheckResult(c).getResultStatus());
}
/**
* two interior rings are disconnecting some interior
*/
@Test
public void testBadPolygon2() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
Vertex v0 = addVertex(0, 0, 0);
Vertex v1 = addVertex(20, 0, 0);
Vertex v2 = addVertex(20, 20, 0);
Vertex v3 = addVertex(0, 20, 0);
Vertex v4 = addVertex(10, 10, 0);
Vertex v5 = addVertex(12, 12, 0);
Vertex v6 = addVertex(10, 14, 0);
Vertex v7 = addVertex(14, 14, 0);
Vertex v8 = addVertex(14, 10, 0);
Vertex v9 = addVertex(8, 12, 0);
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(ext);
ext.addVertex(v0);
ext.addVertex(v1);
ext.addVertex(v2);
ext.addVertex(v3);
ext.addVertex(v0);
LinearRing intRing1 = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(intRing1);
intRing1.addVertex(v4);
intRing1.addVertex(v5);
intRing1.addVertex(v6);
intRing1.addVertex(v7);
intRing1.addVertex(v8);
intRing1.addVertex(v4);
LinearRing intRing2 = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(intRing2);
intRing2.addVertex(v4);
intRing2.addVertex(v9);
intRing2.addVertex(v6);
intRing2.addVertex(v4);
InteriorDisconnectedCheck c = new InteriorDisconnectedCheck();
c.check(p);
Assert.assertEquals(ResultStatus.ERROR, p.getCheckResult(c).getResultStatus());
}
/**
* three interior rings are disconnecting some interior
*/
@Test
public void testBadPolygon3() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
Vertex v0 = addVertex(0, 0, 0);
Vertex v1 = addVertex(10, 0, 0);
Vertex v2 = addVertex(10, 10, 0);
Vertex v3 = addVertex(0, 10, 0);
Vertex v4 = addVertex(3, 3, 0);
Vertex v5 = addVertex(2, 4, 0);
Vertex v6 = addVertex(3, 5, 0);
Vertex v7 = addVertex(5, 5, 0);
Vertex v8 = addVertex(5, 4, 0);
Vertex v9 = addVertex(5, 3, 0);
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
ext.setGmlId(new GmlId("ext"));
p.setExteriorRing(ext);
ext.addVertex(v0);
ext.addVertex(v1);
ext.addVertex(v2);
ext.addVertex(v3);
ext.addVertex(v0);
LinearRing intRing2 = new LinearRing(LinearRingType.INTERIOR);
intRing2.setGmlId(new GmlId("IntRing2"));
p.addInteriorRing(intRing2);
intRing2.addVertex(v6);
intRing2.addVertex(v7);
intRing2.addVertex(v8);
intRing2.addVertex(v6);
LinearRing intRing1 = new LinearRing(LinearRingType.INTERIOR);
intRing1.setGmlId(new GmlId("IntRing1"));
p.addInteriorRing(intRing1);
intRing1.addVertex(v4);
intRing1.addVertex(v5);
intRing1.addVertex(v6);
intRing1.addVertex(v4);
LinearRing intRing3 = new LinearRing(LinearRingType.INTERIOR);
intRing3.setGmlId(new GmlId("IntRing3"));
p.addInteriorRing(intRing3);
intRing3.addVertex(v8);
intRing3.addVertex(v9);
intRing3.addVertex(v4);
intRing3.addVertex(v8);
InteriorDisconnectedCheck c = new InteriorDisconnectedCheck();
c.check(p);
Assert.assertEquals(ResultStatus.ERROR, p.getCheckResult(c).getResultStatus());
}
/**
* three interior rings are NOT disconnecting some interior
*/
@Test
public void testGoodPolygon3() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
Vertex v0 = addVertex(0, 0, 0);
Vertex v1 = addVertex(10, 0, 0);
Vertex v2 = addVertex(10, 10, 0);
Vertex v3 = addVertex(0, 10, 0);
Vertex v4 = addVertex(3, 3, 0);
Vertex v5 = addVertex(2, 4, 0);
Vertex v6 = addVertex(3, 5, 0);
Vertex v7 = addVertex(5, 5, 0);
Vertex v8 = addVertex(5, 4, 0);
Vertex v9 = addVertex(5, 3, 0);
Vertex v10 = addVertex(2, 3, 0);
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
ext.setGmlId(new GmlId("ext"));
p.setExteriorRing(ext);
ext.addVertex(v0);
ext.addVertex(v1);
ext.addVertex(v2);
ext.addVertex(v3);
LinearRing intRing1 = new LinearRing(LinearRingType.INTERIOR);
intRing1.setGmlId(new GmlId("intRing1"));
p.addInteriorRing(intRing1);
intRing1.addVertex(v10);
intRing1.addVertex(v5);
intRing1.addVertex(v6);
LinearRing intRing2 = new LinearRing(LinearRingType.INTERIOR);
intRing2.setGmlId(new GmlId("intRing2"));
p.addInteriorRing(intRing2);
intRing2.addVertex(v6);
intRing2.addVertex(v7);
intRing2.addVertex(v8);
LinearRing intRing3 = new LinearRing(LinearRingType.INTERIOR);
intRing3.setGmlId(new GmlId("intRing3"));
p.addInteriorRing(intRing3);
intRing3.addVertex(v8);
intRing3.addVertex(v9);
intRing3.addVertex(v4);
InteriorDisconnectedCheck c = new InteriorDisconnectedCheck();
c.check(p);
Assert.assertEquals(ResultStatus.OK, p.getCheckResult(c).getResultStatus());
}
@Test
public void testGoodPolygon2() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
Vertex v0 = addVertex(0, 0, 0);
Vertex v1 = addVertex(20, 0, 0);
Vertex v2 = addVertex(20, 20, 0);
Vertex v3 = addVertex(0, 20, 0);
Vertex v4 = addVertex(10, 10, 0);
Vertex v5 = addVertex(12, 12, 0);
Vertex v6 = addVertex(10, 14, 0);
Vertex v7 = addVertex(14, 14, 0);
Vertex v8 = addVertex(14, 10, 0);
Vertex v9 = addVertex(8, 12, 0);
Vertex v10 = addVertex(8, 10, 0);
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
ext.setGmlId(new GmlId("ext"));
p.setExteriorRing(ext);
ext.addVertex(v0);
ext.addVertex(v1);
ext.addVertex(v2);
ext.addVertex(v3);
LinearRing intRing1 = new LinearRing(LinearRingType.INTERIOR);
intRing1.setGmlId(new GmlId("intRing1"));
p.addInteriorRing(intRing1);
intRing1.addVertex(v4);
intRing1.addVertex(v5);
intRing1.addVertex(v6);
intRing1.addVertex(v7);
intRing1.addVertex(v8);
LinearRing intRing2 = new LinearRing(LinearRingType.INTERIOR);
intRing2.setGmlId(new GmlId("IntRing2"));
p.addInteriorRing(intRing2);
intRing2.addVertex(v10);
intRing2.addVertex(v9);
intRing2.addVertex(v6);
InteriorDisconnectedCheck c = new InteriorDisconnectedCheck();
c.check(p);
Assert.assertEquals(ResultStatus.OK, p.getCheckResult(c).getResultStatus());
}
private Vertex addVertex(double x, double y, double z) {
Vertex v0 = new Vertex(x, y, z);
return v0;
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static de.hft.stuttgart.citydoctor2.checks.util.GeometryTestUtils.addPolygon;
import static de.hft.stuttgart.citydoctor2.checks.util.GeometryTestUtils.createVertex;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.checks.util.GeometryTestUtils;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class ManifoldVertexCheckTest {
@Test
public void testNonManifoldVertex() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v12 = createVertex(10, 10, 3, geom);
Vertex v13 = createVertex(10, 10, 0, geom);
Vertex v9 = createVertex(10, 15, 0, geom);
Vertex v10 = createVertex(10, 15, 3, geom);
Vertex v14 = createVertex(11.5, 10, 4.5, geom);
Vertex v11 = createVertex(11.5, 15, 4.5, geom);
Vertex v0 = createVertex(13, 15, 0, geom);
Vertex v1 = createVertex(13, 15, 3, geom);
Vertex v2 = createVertex(13, 10, 3, geom);
Vertex v3 = createVertex(13, 10, 0, geom);
Vertex v8 = createVertex(13, 16, 3, geom);
Vertex v5 = createVertex(13.5, 15.5, 3.5, geom);
Vertex v6 = createVertex(14, 15, 3, geom);
Vertex v7 = createVertex(14, 16, 3, geom);
List<Vertex> vertices = new ArrayList<>();
Collections.addAll(vertices, v0, v1, v2, v3, v12, v13, v9, v10, v14, v11, v8, v5, v6, v7);
geom.setVertices(vertices);
addPolygon(geom, v0, v1, v2, v3);
addPolygon(geom, v1, v6, v5);
addPolygon(geom, v6, v7, v5);
addPolygon(geom, v7, v8, v5);
addPolygon(geom, v8, v1, v5);
addPolygon(geom, v1, v8, v7, v6);
addPolygon(geom, v9, v10, v11, v1, v0);
addPolygon(geom, v12, v10, v9, v13);
addPolygon(geom, v3, v2, v14, v12, v13);
addPolygon(geom, v12, v14, v11, v10);
addPolygon(geom, v14, v2, v1, v11);
addPolygon(geom, v13, v9, v0, v3);
geom.updateEdges();
ManifoldVertexCheck check = new ManifoldVertexCheck();
check.check(geom);
CheckResult cr = geom.getCheckResult(check);
Assert.assertNotNull(cr);
Assert.assertEquals(ResultStatus.ERROR, cr.getResultStatus());
}
@Test
public void testGoodSolid() {
Geometry g = GeometryTestUtils.createGoodGeometry();
g.updateEdges();
ManifoldVertexCheck check = new ManifoldVertexCheck();
check.check(g);
CheckResult cr = g.getCheckResult(check);
Assert.assertNotNull(cr);
Assert.assertEquals(ResultStatus.OK, cr.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class NestedRingsCheckTest {
@Test
public void testNestedRings() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
// create exterior ring
LinearRing ext = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(ext);
ext.setParent(p);
Vertex firstVertex = addVertex(0, 0, 0, ext, geom);
addVertex(3, 0, 0, ext, geom);
addVertex(3, 3, 0, ext, geom);
addVertex(0, 3, 0, ext, geom);
ext.addVertex(firstVertex);
// create interior ring
LinearRing inter = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(inter);
Vertex firstIntVertex = addVertex(0.5, 0.5, 0, inter, geom);
addVertex(2.5, 0.5, 0, inter, geom);
addVertex(2.5, 2.5, 0, inter, geom);
addVertex(0.5, 2.5, 0, inter, geom);
inter.addVertex(firstIntVertex);
// create interior inside interior ring
LinearRing inter2 = new LinearRing(LinearRingType.INTERIOR);
p.addInteriorRing(inter2);
Vertex firstIntVertex2 = addVertex(1, 1, 0, inter2, geom);
addVertex(2, 1, 0, inter2, geom);
addVertex(2, 2, 0, inter2, geom);
addVertex(1, 2, 0, inter2, geom);
inter2.addVertex(firstIntVertex2);
NestedRingsCheck c = new NestedRingsCheck();
c.check(p);
CheckResult cr = p.getCheckResult(c);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_INNER_RINGS_NESTED, cr.getError().getErrorId());
}
@Test
public void testPolygonGood() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setParent(poly);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(8, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(8, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(9, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(9, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
NestedRingsCheck c = new NestedRingsCheck();
c.check(poly);
assertEquals(ResultStatus.OK, poly.getCheckResult(c).getResultStatus());
}
private Vertex addVertex(double x, double y, double z, LinearRing lr, Geometry geom) {
Vertex v = new Vertex(x, y, z);
lr.addVertex(v);
return v;
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class NullAreaCheckTest {
private LinearRing setupValidGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
LinearRing r = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(r);
Vertex v1 = new Vertex(0, 0, 0);
r.addVertex(v1);
Vertex v2 = new Vertex(1, 1, 0);
r.addVertex(v2);
Vertex v3 = new Vertex(2, 2, 0);
r.addVertex(v3);
Vertex v4 = new Vertex(5, 5.5, 0);
r.addVertex(v4);
r.addVertex(v1);
return r;
}
private LinearRing setupErrorGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
LinearRing r = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(r);
Vertex v1 = new Vertex(0, 0, 0);
r.addVertex(v1);
Vertex v2 = new Vertex(1, 1, 0);
r.addVertex(v2);
Vertex v3 = new Vertex(2, 2, 0);
r.addVertex(v3);
Vertex v4 = new Vertex(5, 5.00001, 0);
r.addVertex(v4);
r.addVertex(v1);
return r;
}
@Test
public void testCheckRingError() {
LinearRing r = setupErrorGeometry();
NullAreaCheck nac = new NullAreaCheck();
nac.check(r);
Assert.assertTrue(r.hasAnyError());
}
@Test
public void testCheckRing() {
LinearRing r = setupValidGeometry();
NullAreaCheck nac = new NullAreaCheck();
nac.check(r);
Assert.assertFalse(r.hasAnyError());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Collections;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
/**
*
* @author Matthias Betz
*
*/
public class NumPointsCheckTest {
@Test
public void testNumberOfPointsWithNeighboringPoints() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 0.00000001, 0);
v0.addNeighbor(v1);
v1.addNeighbor(v0);
Vertex v2 = new Vertex(0, 1, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v0);
NumPointsCheck check = new NumPointsCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(lr);
CheckResult checkResult = lr.getCheckResult(check);
assertNotNull(checkResult);
assertEquals(ResultStatus.ERROR, checkResult.getResultStatus());
}
@Test
public void testNumberOfPointsWithNeighboringPointsEnoughPoints() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 0.00000001, 0);
v0.addNeighbor(v1);
v1.addNeighbor(v0);
Vertex v2 = new Vertex(0, 1, 0);
Vertex v3 = new Vertex(0, 2, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
NumPointsCheck check = new NumPointsCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(lr);
CheckResult checkResult = lr.getCheckResult(check);
assertNotNull(checkResult);
assertEquals(ResultStatus.OK, checkResult.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class PlanarCheckTest {
@Test
public void testCheckPolygonOK() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 0, 1);
Vertex v2 = new Vertex(1, 0, 1);
Vertex v3 = new Vertex(1, 0, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
geom.addPolygon(p);
PlanarCheck c = new PlanarCheck();
c.check(p);
assertTrue(p.getCheckResult(c).getResultStatus() == ResultStatus.OK);
}
@Test
public void testCheckPolygonDistanceERROR() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 0.06, 1);
Vertex v2 = new Vertex(1, 1, 1);
Vertex v3 = new Vertex(1, 1, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
lr.setParent(p);
geom.addPolygon(p);
PlanarCheck c = new PlanarCheck();
c.check(p);
assertTrue(p.getCheckResult(c).getResultStatus() == ResultStatus.ERROR);
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.checks.util.GeometryTestUtils;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class PolygonSameOrientationCheckTest {
@Test
public void testSameOrientation() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = GeometryTestUtils.createVertex(0, 0, 0, geom);
Vertex v1 = GeometryTestUtils.createVertex(6, 0, 0, geom);
Vertex v2 = GeometryTestUtils.createVertex(6, 6, 0, geom);
Vertex v3 = GeometryTestUtils.createVertex(0, 6, 0, geom);
Vertex v4 = GeometryTestUtils.createVertex(2, 2, 0, geom);
Vertex v5 = GeometryTestUtils.createVertex(4, 2, 0, geom);
Vertex v6 = GeometryTestUtils.createVertex(4, 4, 0, geom);
Vertex v7 = GeometryTestUtils.createVertex(2, 4, 0, geom);
Polygon poly = GeometryTestUtils.addPolygon(geom, v0, v1, v2, v3);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
interior.addVertex(v4);
interior.addVertex(v5);
interior.addVertex(v6);
interior.addVertex(v7);
interior.addVertex(v4);
PolygonSameOrientationCheck check = new PolygonSameOrientationCheck();
check.check(poly);
CheckResult cr = poly.getCheckResult(check);
assertSame(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_ORIENTATION_RINGS_SAME, cr.getError().getErrorId());
}
@Test
public void testGoodPoly() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = GeometryTestUtils.createVertex(0, 0, 0, geom);
Vertex v1 = GeometryTestUtils.createVertex(6, 0, 0, geom);
Vertex v2 = GeometryTestUtils.createVertex(6, 6, 0, geom);
Vertex v3 = GeometryTestUtils.createVertex(0, 6, 0, geom);
Vertex v4 = GeometryTestUtils.createVertex(2, 2, 0, geom);
Vertex v5 = GeometryTestUtils.createVertex(4, 2, 0, geom);
Vertex v6 = GeometryTestUtils.createVertex(4, 4, 0, geom);
Vertex v7 = GeometryTestUtils.createVertex(2, 4, 0, geom);
Polygon poly = GeometryTestUtils.addPolygon(geom, v0, v1, v2, v3);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
interior.addVertex(v4);
interior.addVertex(v7);
interior.addVertex(v6);
interior.addVertex(v5);
interior.addVertex(v4);
PolygonSameOrientationCheck check = new PolygonSameOrientationCheck();
check.check(poly);
CheckResult cr = poly.getCheckResult(check);
assertSame(ResultStatus.OK, cr.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class PolygonSelfIntCheckTest {
@Test
public void testPolygonInteriorIntersectExterior() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setParent(poly);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(8, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(8, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(12, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(12, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
PolygonSelfIntCheck c = new PolygonSelfIntCheck();
c.check(poly);
CheckResult cr = poly.getCheckResult(c);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_INTERSECTING_RINGS, cr.getError().getErrorId());
}
@Test
public void testPolygonGood() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
interior.setParent(poly);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(8, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(8, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(9, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(9, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
PolygonSelfIntCheck c = new PolygonSelfIntCheck();
c.check(poly);
assertEquals(ResultStatus.OK, poly.getCheckResult(c).getResultStatus());
}
@Test
public void test2InteriorRingsIntersecting() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setParent(poly);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
interior.setParent(poly);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(5, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(5, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(9, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(9, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
LinearRing interior2 = new LinearRing(LinearRingType.INTERIOR);
interior2.setParent(poly);
poly.addInteriorRing(interior2);
Vertex v8 = new Vertex(3, 2, 0);
interior2.addVertex(v8);
Vertex v9 = new Vertex(3, 3, 0);
interior2.addVertex(v9);
Vertex v10 = new Vertex(6, 3, 0);
interior2.addVertex(v10);
Vertex v11 = new Vertex(6, 2, 0);
interior2.addVertex(v11);
interior2.addVertex(v8);
PolygonSelfIntCheck c = new PolygonSelfIntCheck();
c.check(poly);
CheckResult cr = poly.getCheckResult(c);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_INTERSECTING_RINGS, cr.getError().getErrorId());
}
@Test
public void test2InteriorRingsNotIntersecting() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
LinearRing interior = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior);
Vertex v4 = new Vertex(5, 2, 0);
interior.addVertex(v4);
Vertex v5 = new Vertex(5, 4, 0);
interior.addVertex(v5);
Vertex v6 = new Vertex(9, 4, 0);
interior.addVertex(v6);
Vertex v7 = new Vertex(9, 2, 0);
interior.addVertex(v7);
interior.addVertex(v4);
LinearRing interior2 = new LinearRing(LinearRingType.INTERIOR);
poly.addInteriorRing(interior2);
Vertex v8 = new Vertex(3, 2, 0);
interior2.addVertex(v8);
Vertex v9 = new Vertex(3, 3, 0);
interior2.addVertex(v9);
Vertex v10 = new Vertex(4, 3, 0);
interior2.addVertex(v10);
Vertex v11 = new Vertex(4, 2, 0);
interior2.addVertex(v11);
interior2.addVertex(v8);
PolygonSelfIntCheck c = new PolygonSelfIntCheck();
c.check(poly);
assertEquals(ResultStatus.OK, poly.getCheckResult(c).getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.check.error.EdgeIntersectionError;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
/**
*
* @author Matthias Betz
*
*/
public class RingSelfIntCheckTest {
@Test
public void testIntersect() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 6);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 10, 4);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 0, 5);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 5);
lr.addVertex(v3);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.check(lr);
CheckResult cr = lr.getCheckResult(check);
assertSame(ResultStatus.ERROR, cr.getResultStatus());
assertTrue(cr.getError() instanceof EdgeIntersectionError);
EdgeIntersectionError err = (EdgeIntersectionError) cr.getError();
assertNotNull(err.getIntersection());
assertEquals(5d, err.getIntersection().getX(), 0.00001);
assertEquals(5d, err.getIntersection().getY(), 0.00001);
assertEquals(5d, err.getIntersection().getZ(), 0.00001);
}
@Test
public void testNonIntersect() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(10, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v3);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.check(lr);
CheckResult cr = lr.getCheckResult(check);
assertSame(ResultStatus.OK, cr.getResultStatus());
}
@Test
public void testTouching() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(5, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(5, 3, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(2.5, 0.00005, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 3, 0);
lr.addVertex(v3);
Vertex v4 = new Vertex(0, 0, 0);
lr.addVertex(v4);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.init(Collections.emptyMap(), new ParserConfiguration(2, false));
check.check(lr);
CheckResult cr = lr.getCheckResult(check);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
}
@Test
public void testNotTouching() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
lr.setParent(poly);
Vertex v0 = new Vertex(5, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(5, 3, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(2.5, 0.05, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 3, 0);
lr.addVertex(v3);
Vertex v4 = new Vertex(0, 0, 0);
lr.addVertex(v4);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.init(Collections.emptyMap(), new ParserConfiguration(2, false));
check.check(lr);
CheckResult cr = lr.getCheckResult(check);
assertSame(ResultStatus.OK, cr.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.geometry;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.checks.util.GeometryTestUtils;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
/**
*
* @author Matthias Betz
*
*/
public class SolidSelfIntCheckTest {
@Test
public void testGoodGeometry() {
SolidSelfIntCheck check = new SolidSelfIntCheck();
Geometry g = GeometryTestUtils.createGoodGeometry();
check.check(g);
CheckResult cr = g.getCheckResult(check);
Assert.assertNotNull(cr);
Assert.assertEquals(ResultStatus.OK, cr.getResultStatus());
}
@Test
public void testBadGeometry() {
SolidSelfIntCheck check = new SolidSelfIntCheck();
Geometry g = GeometryTestUtils.createBadGeometry();
check.check(g);
CheckResult cr = g.getCheckResult(check);
Assert.assertNotNull(cr);
Assert.assertEquals(ResultStatus.ERROR, cr.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.semantics;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.Collections;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.BoundarySurface;
import de.hft.stuttgart.citydoctor2.datastructure.BoundarySurfaceType;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
/**
*
* @author Matthias Betz
*
*/
public class IsWallCheckTest {
@Test
public void testIsWallWarning() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(1, 0, 0);
Vertex v2 = new Vertex(1, 1, 0);
Vertex v3 = new Vertex(0, 1, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
geom.addPolygon(p);
BoundarySurface bs = new BoundarySurface(null);
bs.setType(BoundarySurfaceType.WALL);
bs.addGeometry(geom);
IsWallCheck check = new IsWallCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(bs);
CheckResult checkResult = bs.getCheckResult(check);
assertNotNull(checkResult);
assertEquals(ResultStatus.ERROR, checkResult.getResultStatus());
}
@Test
public void testNotWall() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(1, 0, 0);
Vertex v2 = new Vertex(1, 1, 0);
Vertex v3 = new Vertex(0, 1, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
geom.addPolygon(p);
BoundarySurface bs = new BoundarySurface(null);
bs.setType(BoundarySurfaceType.CLOSURE);
bs.addGeometry(geom);
IsWallCheck check = new IsWallCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(bs);
CheckResult checkResult = bs.getCheckResult(check);
assertNull(checkResult);
}
@Test
public void testIsWallWarning2() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 1, 0);
Vertex v2 = new Vertex(1, 1, 0);
Vertex v3 = new Vertex(1, 0, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
geom.addPolygon(p);
BoundarySurface bs = new BoundarySurface(null);
bs.setType(BoundarySurfaceType.WALL);
bs.addGeometry(geom);
IsWallCheck check = new IsWallCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(bs);
CheckResult checkResult = bs.getCheckResult(check);
assertNotNull(checkResult);
assertEquals(ResultStatus.ERROR, checkResult.getResultStatus());
}
@Test
public void testIsWallOk() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(1, 0, 0);
Vertex v2 = new Vertex(1, 0, 1);
Vertex v3 = new Vertex(0, 0, 1);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
Polygon p = new ConcretePolygon();
p.setExteriorRing(lr);
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
geom.addPolygon(p);
BoundarySurface bs = new BoundarySurface(null);
bs.setType(BoundarySurfaceType.WALL);
bs.addGeometry(geom);
IsWallCheck check = new IsWallCheck();
ParserConfiguration config = new ParserConfiguration(8, false);
check.init(Collections.emptyMap(), config);
check.check(bs);
CheckResult checkResult = bs.getCheckResult(check);
assertNotNull(checkResult);
assertEquals(ResultStatus.OK, checkResult.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class GeometryTestUtils {
public static Geometry createGoodGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = createVertex(0, 0, 0, geom);
Vertex v1 = createVertex(10, 0, 0, geom);
Vertex v2 = createVertex(10, 10, 0, geom);
Vertex v3 = createVertex(0, 10, 0, geom);
Vertex v4 = createVertex(0, 0, 10, geom);
Vertex v5 = createVertex(10, 0, 10, geom);
Vertex v6 = createVertex(10, 10, 10, geom);
Vertex v7 = createVertex(0, 10, 10, geom);
List<Vertex> vertices = new ArrayList<>();
Collections.addAll(vertices, v0, v1, v2, v3, v4, v5, v6, v7);
geom.setVertices(vertices);
addPolygon(geom, v0, v1, v2, v3);
addPolygon(geom, v1, v5, v6, v2);
addPolygon(geom, v4, v7, v6, v5);
addPolygon(geom, v0, v3, v7, v4);
addPolygon(geom, v3, v2, v6, v7);
addPolygon(geom, v0, v4, v5, v1);
return geom;
}
public static Geometry createBadGeometry() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Vertex v0 = createVertex(0, 0, 0, geom);
Vertex v1 = createVertex(10, 0, 0, geom);
Vertex v2 = createVertex(10, 10, 0, geom);
Vertex v3 = createVertex(0, 10, 0, geom);
Vertex v4 = createVertex(0, 0, 10, geom);
Vertex v5 = createVertex(10, 0, 10, geom);
Vertex v6 = createVertex(10, 10, 10, geom);
Vertex v7 = createVertex(0, 10, 10, geom);
Vertex v8 = createVertex(5, -5, 5, geom);
addPolygon(geom, v3, v2, v1, v0);
addPolygon(geom, v2, v6, v5, v1);
addPolygon(geom, v5, v6, v7, v4);
addPolygon(geom, v4, v7, v3, v0);
addPolygon(geom, v1, v5, v4, v0);
// create bad polygon
addPolygon(geom, v8, v7, v6);
addPolygon(geom, v8, v6, v2);
addPolygon(geom, v8, v2, v3);
addPolygon(geom, v8, v3, v7);
return geom;
}
public static Polygon addPolygon(Geometry geom, Vertex... vertices) {
Polygon poly;
LinearRing ex;
poly = new ConcretePolygon();
geom.addPolygon(poly);
ex = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(ex);
for (Vertex v : vertices) {
ex.addVertex(v);
}
ex.addVertex(vertices[0]);
return poly;
}
public static Vertex createVertex(double x, double y, double z, Geometry geom) {
return new Vertex(x, y, z);
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.checks.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.checks.geometry.RingSelfIntCheck;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.math.Segment3d;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.PolygonIntersection;
import de.hft.stuttgart.citydoctor2.utils.PolygonIntersection.IntersectionType;
/**
*
* @author Matthias Betz
*
*/
public class SelfIntersectionUtilTest {
@Test
public void testNonIntersection1() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 0, 1);
Vertex v4 = new Vertex(10, 0, 1);
Vertex v5 = new Vertex(10, 10, 1);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testNonIntersection2() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 0, -1);
Vertex v4 = new Vertex(0, 10, -1);
Vertex v5 = new Vertex(10, 10, -1);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testLineIntersectionTouchingPolygonsWithoutCommonEdge() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(7, 7, 5);
Vertex v4 = new Vertex(5, 5, -5);
Vertex v5 = new Vertex(7, 7, -5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
// Segment3d line = intersection.getLines().get(0);
// assertEquals(new Vector3d(6, 6, 0), line.getPointA());
// assertEquals(new Vector3d(7, 7, 0), line.getPointB());
}
@Test
public void testNonIntersection3() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(7, 7, 5);
Vertex v4 = new Vertex(0, 0, 0);
Vertex v5 = new Vertex(10, 10, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testIntersection1() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(7, 6, 5);
Vertex v4 = new Vertex(5, 5, -5);
Vertex v5 = new Vertex(7, 7, -5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.LINE, intersection.getType());
Vector3d point1 = new Vector3d(6, 5.5, 0);
Vector3d point2 = new Vector3d(7, 6.5, 0);
List<Segment3d> lines = intersection.getLines();
assertNotNull(lines);
assertEquals(1, lines.size());
Segment3d segment = lines.get(0);
assertTrue(point1.equals(segment.getPointA()) || point1.equals(segment.getPointB()));
assertTrue(point2.equals(segment.getPointA()) || point2.equals(segment.getPointB()));
}
@Test
public void testIntersection2() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(7, 0, 5);
Vertex v4 = new Vertex(5, -5, -5);
Vertex v5 = new Vertex(7, 7, -5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.LINE, intersection.getType());
Vector3d point1 = new Vector3d(6.41666, 0, 0);
Vector3d point2 = new Vector3d(7, 3.5, 0);
List<Segment3d> lines = intersection.getLines();
assertNotNull(lines);
assertEquals(1, lines.size());
Segment3d segment = lines.get(0);
assertTrue(point1.equalsWithEpsilon(segment.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment.getPointB(), 0.01));
}
@Test
public void testIntersectionWithTwoLineSegments() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(7, 0, 5);
Vertex v4 = new Vertex(5, -5, -5);
Vertex v5 = new Vertex(9, 3, -5);
Vertex v6 = new Vertex(9, 3, 5);
Vertex v7 = new Vertex(9, 2, -3);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v7);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.LINE, intersection.getType());
List<Segment3d> lines = intersection.getLines();
assertNotNull(lines);
assertEquals(2, lines.size());
Segment3d segment1 = lines.get(0);
Vector3d point1 = new Vector3d(7.40, 0, 0);
Vector3d point2 = new Vector3d(8.25, 1.25, 0);
assertTrue(point1.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment1.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment1.getPointB(), 0.01));
Segment3d segment2 = lines.get(1);
point1 = new Vector3d(9, 2.375, 0);
point2 = new Vector3d(9, 3.0, 0);
assertTrue(point1.equalsWithEpsilon(segment2.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment2.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment2.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment2.getPointB(), 0.01));
}
@Test
public void testIntersectionWithInnerRings() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex i0 = new Vertex(7, 1, 0);
Vertex i1 = new Vertex(7, 0.5, 0);
Vertex i2 = new Vertex(9, 0.5, 0);
Vertex i3 = new Vertex(9, 1, 0);
LinearRing ri = new LinearRing(LinearRingType.INTERIOR);
p1.addInteriorRing(ri);
ri.addVertex(i0);
ri.addVertex(i1);
ri.addVertex(i2);
ri.addVertex(i3);
ri.addVertex(i0);
Vertex v3 = new Vertex(7, 0, 5);
Vertex v4 = new Vertex(5, -5, -5);
Vertex v5 = new Vertex(9, 3, -5);
Vertex v6 = new Vertex(9, 3, 5);
Vertex v7 = new Vertex(9, 2, -3);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v7);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.LINE, intersection.getType());
List<Segment3d> lines = intersection.getLines();
assertNotNull(lines);
assertEquals(3, lines.size());
Segment3d segment1 = lines.get(0);
Vector3d point1 = new Vector3d(7.40, 0, 0);
Vector3d point2 = new Vector3d(7.684, 0.5, 0);
assertTrue(point1.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment1.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment1.getPointB(), 0.01));
Segment3d segment2 = lines.get(1);
point1 = new Vector3d(7.96, 1, 0);
point2 = new Vector3d(8.25, 1.25, 0);
assertTrue(point1.equalsWithEpsilon(segment2.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment2.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment2.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment2.getPointB(), 0.01));
Segment3d segment3 = lines.get(2);
point1 = new Vector3d(9, 2.375, 0);
point2 = new Vector3d(9, 3.0, 0);
assertTrue(point1.equalsWithEpsilon(segment3.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment3.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment3.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment3.getPointB(), 0.01));
}
@Test
public void testIntersectionWithInnerRingsOneLineInInnerRing() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex i0 = new Vertex(7, 2, 0);
Vertex i1 = new Vertex(7, 5, 0);
Vertex i2 = new Vertex(9.5, 5, 0);
Vertex i3 = new Vertex(9.5, 2, 0);
LinearRing ri = new LinearRing(LinearRingType.INTERIOR);
p1.addInteriorRing(ri);
ri.addVertex(i0);
ri.addVertex(i1);
ri.addVertex(i2);
ri.addVertex(i3);
ri.addVertex(i0);
Vertex v3 = new Vertex(7, 0, 5);
Vertex v4 = new Vertex(5, -5, -5);
Vertex v5 = new Vertex(9, 3, -5);
Vertex v6 = new Vertex(9, 3, 5);
Vertex v7 = new Vertex(9, 2, -3);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v7);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.LINE, intersection.getType());
List<Segment3d> lines = intersection.getLines();
assertNotNull(lines);
assertEquals(1, lines.size());
Segment3d segment1 = lines.get(0);
Vector3d point1 = new Vector3d(7.40, 0, 0);
Vector3d point2 = new Vector3d(8.25, 1.25, 0);
assertTrue(point1.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point1.equalsWithEpsilon(segment1.getPointB(), 0.01));
assertTrue(point2.equalsWithEpsilon(segment1.getPointA(), 0.01)
|| point2.equalsWithEpsilon(segment1.getPointB(), 0.01));
}
@Test
public void testIntersectionNoPlanarIntersectionTouching() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 0, 0);
Vertex v4 = new Vertex(0, 10, 0);
Vertex v5 = new Vertex(10, 10, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testIntersectionNoPlanarIntersectionTouchingInOnePoint() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 0, 0);
Vertex v4 = new Vertex(0, 10, 0);
Vertex v5 = new Vertex(9, 10, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testIntersectionNoPlanarIntersectionNotTouching() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 1, 0);
Vertex v4 = new Vertex(0, 11, 0);
Vertex v5 = new Vertex(10, 11, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.NONE, intersection.getType());
}
@Test
public void testIntersectionPlanarIntersection1() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 10);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(5, 5, 5);
Vertex v4 = new Vertex(5, 10, 10);
Vertex v5 = new Vertex(8, 10, 10);
Vertex v6 = new Vertex(8, 5, 5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.POLYGON, intersection.getType());
List<Vertex> vertices = intersection.getIntersectionPolygon().getExteriorRing().getVertices();
assertEquals(new Vertex(5, 5, 5), vertices.get(0));
assertEquals(new Vertex(8, 8, 7.999999999999999), vertices.get(1));
assertEquals(new Vertex(8, 5, 4.999999999999999), vertices.get(2));
assertEquals(new Vertex(5, 5, 5), vertices.get(3));
}
@Test
public void testIntersectionPlanarIntersection2() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 0, 10);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(5, 0, 5);
Vertex v4 = new Vertex(5, 0, 10);
Vertex v5 = new Vertex(8, 0, 10);
Vertex v6 = new Vertex(8, 0, 5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.POLYGON, intersection.getType());
List<Vertex> vertices = intersection.getIntersectionPolygon().getExteriorRing().getVertices();
assertEquals(new Vertex(5, 0, 5), vertices.get(0));
assertEquals(new Vertex(8, 0, 8), vertices.get(1));
assertEquals(new Vertex(8, 0, 5), vertices.get(2));
assertEquals(new Vertex(5, 0, 5), vertices.get(3));
}
@Test
public void testIntersectionPlanarIntersection3() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 10, 0);
Vertex v2 = new Vertex(0, 10, 10);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(0, 5, 5);
Vertex v4 = new Vertex(0, 5, 10);
Vertex v5 = new Vertex(0, 8, 10);
Vertex v6 = new Vertex(0, 8, 5);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v3);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.POLYGON, intersection.getType());
List<Vertex> polygon = intersection.getIntersectionPolygon().getExteriorRing().getVertices();
assertEquals(new Vertex(0, 5, 5), polygon.get(0));
assertEquals(new Vertex(0, 8, 8), polygon.get(1));
assertEquals(new Vertex(0, 8, 5), polygon.get(2));
assertEquals(new Vertex(0, 5, 5), polygon.get(3));
}
@Test
public void testIntersectionPlanarIntersection4() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 10, 0);
Vertex v2 = new Vertex(10, 0, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(5, 2, 0);
Vertex v4 = new Vertex(5, 10, 0);
Vertex v5 = new Vertex(8, 10, 0);
Vertex v6 = new Vertex(8, 2, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v3);
Vertex i0 = new Vertex(6, 3, 0);
Vertex i1 = new Vertex(6, 4, 0);
Vertex i2 = new Vertex(7, 4, 0);
Vertex i3 = new Vertex(7, 3, 0);
LinearRing r3 = new LinearRing(LinearRingType.INTERIOR);
p1.addInteriorRing(r3);
r3.addVertex(i0);
r3.addVertex(i1);
r3.addVertex(i2);
r3.addVertex(i3);
r3.addVertex(i0);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.POLYGON, intersection.getType());
List<Vertex> ext = intersection.getIntersectionPolygon().getExteriorRing().getVertices();
assertEquals(new Vertex(5, 5, 0), ext.get(0));
assertEquals(new Vertex(8, 8, 0), ext.get(1));
assertEquals(new Vertex(8, 2, 0), ext.get(2));
assertEquals(new Vertex(5, 2, 0), ext.get(3));
assertEquals(new Vertex(5, 5, 0), ext.get(4));
List<Vertex> inner = intersection.getIntersectionPolygon().getInnerRings().get(0).getVertices();
assertEquals(new Vertex(6, 3, 0), inner.get(0));
assertEquals(new Vertex(7, 3, 0), inner.get(1));
assertEquals(new Vertex(7, 4, 0), inner.get(2));
assertEquals(new Vertex(6, 4, 0), inner.get(3));
assertEquals(new Vertex(6, 3, 0), inner.get(4));
}
@Test
public void testIntersectionPlanarIntersection5() {
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 10, 0);
Vertex v2 = new Vertex(10, 0, 0);
Polygon p1 = new ConcretePolygon();
LinearRing r1 = new LinearRing(LinearRingType.EXTERIOR);
p1.setExteriorRing(r1);
r1.addVertex(v0);
r1.addVertex(v1);
r1.addVertex(v2);
r1.addVertex(v0);
Vertex v3 = new Vertex(5, 2, 0);
Vertex v4 = new Vertex(5, 10, 0);
Vertex v5 = new Vertex(8, 10, 0);
Vertex v6 = new Vertex(8, 2, 0);
Polygon p2 = new ConcretePolygon();
LinearRing r2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(r2);
r2.addVertex(v3);
r2.addVertex(v4);
r2.addVertex(v5);
r2.addVertex(v6);
r2.addVertex(v3);
Vertex i0 = new Vertex(6, 3, 0);
Vertex i1 = new Vertex(6, 4, 0);
Vertex i2 = new Vertex(7, 4, 0);
Vertex i3 = new Vertex(7, 3, 0);
LinearRing r3 = new LinearRing(LinearRingType.INTERIOR);
p1.addInteriorRing(r3);
r3.addVertex(i0);
r3.addVertex(i1);
r3.addVertex(i2);
r3.addVertex(i3);
r3.addVertex(i0);
Vertex i5 = new Vertex(6, 6, 0);
Vertex i6 = new Vertex(6, 7, 0);
Vertex i7 = new Vertex(7, 7, 0);
Vertex i8 = new Vertex(7, 6, 0);
LinearRing r4 = new LinearRing(LinearRingType.INTERIOR);
p2.addInteriorRing(r4);
r4.addVertex(i5);
r4.addVertex(i6);
r4.addVertex(i7);
r4.addVertex(i8);
r4.addVertex(i5);
PolygonIntersection intersection = SelfIntersectionUtil.polygonIntersection(p1, p2, 1, 0.0001);
assertNotNull(intersection);
assertEquals(IntersectionType.POLYGON, intersection.getType());
List<Vertex> ext = intersection.getIntersectionPolygon().getExteriorRing().getVertices();
assertEquals(new Vertex(5, 5, 0), ext.get(0));
assertEquals(new Vertex(6, 6, 0), ext.get(1));
assertEquals(new Vertex(7, 6, 0), ext.get(2));
assertEquals(new Vertex(7, 7, 0), ext.get(3));
assertEquals(new Vertex(8, 8, 0), ext.get(4));
assertEquals(new Vertex(8, 2, 0), ext.get(5));
assertEquals(new Vertex(5, 2, 0), ext.get(6));
assertEquals(new Vertex(5, 5, 0), ext.get(7));
List<Vertex> inner = intersection.getIntersectionPolygon().getInnerRings().get(0).getVertices();
assertEquals(new Vertex(6, 3, 0), inner.get(0));
assertEquals(new Vertex(7, 3, 0), inner.get(1));
assertEquals(new Vertex(7, 4, 0), inner.get(2));
assertEquals(new Vertex(6, 4, 0), inner.get(3));
assertEquals(new Vertex(6, 3, 0), inner.get(4));
}
@Test
public void testIsSimpleGood() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(0, 10, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(0, 10, 10);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 0, 10);
lr.addVertex(v3);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.init(Collections.emptyMap(), new ParserConfiguration(8, false));
check.check(lr);
assertEquals(ResultStatus.OK, lr.getCheckResult(check).getResultStatus());
}
@Test
public void testIsSimpleFail() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
lr.setParent(poly);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(0, 10, 10);
lr.addVertex(v1);
Vertex v2 = new Vertex(0, 10, 0);
lr.addVertex(v2);
Vertex v3 = new Vertex(0, 0, 10);
lr.addVertex(v3);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.init(Collections.emptyMap(), new ParserConfiguration(8, false));
check.check(lr);
assertEquals(ResultStatus.ERROR, lr.getCheckResult(check).getResultStatus());
}
@Test
public void testIsSimpleGood2() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon poly = new ConcretePolygon();
geom.addPolygon(poly);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
poly.setExteriorRing(lr);
lr.setParent(poly);
Vertex v0 = new Vertex(0, 2, 0);
lr.addVertex(v0);
Vertex v1 = new Vertex(0, 0, 0);
lr.addVertex(v1);
Vertex v2 = new Vertex(0, 0, 3);
lr.addVertex(v2);
lr.addVertex(v0);
geom.updateEdgesAndVertices();
RingSelfIntCheck check = new RingSelfIntCheck();
check.init(Collections.emptyMap(), new ParserConfiguration(8, false));
check.check(lr);
assertEquals(ResultStatus.OK, lr.getCheckResult(check).getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.systemtest;
import static org.junit.Assert.assertFalse;
import java.io.IOException;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.Checker;
import de.hft.stuttgart.citydoctor2.check.ValidationConfiguration;
import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
/**
*
* @author Matthias Betz
*
*/
public class AllPolygonWrongOrientedTest {
@Test
public void testPolygonsWrongOriented1() throws CityGmlParseException, IOException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
CityDoctorModel model = CityGmlParser.parseCityGmlFile("src/test/resources/AllPolygonsWrongOrientation_Test1.gml", config.getParserConfiguration());
Checker c = new Checker(config, model);
c.runChecks();
Building b = model.getBuildings().get(0);
assertFalse(b.containsError(CheckId.C_GE_S_ALL_POLYGONS_WRONG_ORIENTATION));
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.systemtest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.Checker;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
/**
*
* @author Matthias Betz
*
*/
public class ConCompCheckTest extends TestCleanUp {
@Test
public void testConComp1() throws CityGmlParseException, IOException, InvalidGmlFileException {
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-CS-CONCOMP.gml", config);
Checker c = new Checker(m);
c.runChecks();
Geometry geom = m.getBuildings().get(0).getGeometries().get(0);
CheckResult cr = geom.getCheckResult(CheckId.C_GE_S_MULTIPLE_CONNECTED_COMPONENTS);
assertNotNull(cr);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_S_MULTIPLE_CONNECTED_COMPONENTS, cr.getError().getErrorId());
}
@Test
public void testConComp2() throws CityGmlParseException, IOException, InvalidGmlFileException {
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-CS-CONCOMPGK.gml", config);
Checker c = new Checker(m);
c.runChecks();
Geometry geom = m.getBuildings().get(0).getGeometries().get(0);
CheckResult cr = geom.getCheckResult(CheckId.C_GE_S_MULTIPLE_CONNECTED_COMPONENTS);
assertNotNull(cr);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_S_MULTIPLE_CONNECTED_COMPONENTS, cr.getError().getErrorId());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.systemtest;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.Checker;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
/**
*
* @author Matthias Betz
*
*/
public class DupPointsCheckTest {
@Test
public void testDupPoints1() throws CityGmlParseException, IOException, InvalidGmlFileException {
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-Ex-C-LR-3.gml", config);
Checker c = new Checker(m);
c.runChecks();
LinearRing r1 = TestUtil.getPolygonById("p_r_1", m).getExteriorRing();
CheckResult cr1 = r1.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr1.getResultStatus());
assertEquals(ErrorId.GE_R_CONSECUTIVE_POINTS_SAME, cr1.getError().getErrorId());
LinearRing r2 = TestUtil.getPolygonById("p_w_4", m).getExteriorRing();
assertEquals(ResultStatus.OK, r2.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT).getResultStatus());
}
@Test
public void testDupPoints2() throws CityGmlParseException, IOException, InvalidGmlFileException {
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/QA-Ex-C-LR-3GK.gml", config);
Checker c = new Checker(m);
c.runChecks();
LinearRing r1 = TestUtil.getPolygonById("p_r_1", m).getExteriorRing();
CheckResult cr1 = r1.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr1.getResultStatus());
assertEquals(ErrorId.GE_R_CONSECUTIVE_POINTS_SAME, cr1.getError().getErrorId());
LinearRing r2 = TestUtil.getPolygonById("p_w_4", m).getExteriorRing();
assertEquals(ResultStatus.OK, r2.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT).getResultStatus());
}
@Test
public void testDupPoints3() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel m = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS.gml");
for (Polygon p : m.getBuildings().get(0).getGeometries().get(0).getPolygons()) {
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.OK, cr.getResultStatus());
}
}
@Test
public void testDupPoints4() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel m = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-LR-0002-T0001.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.6", m);
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_R_CONSECUTIVE_POINTS_SAME, cr.getError().getErrorId());
}
@Test
public void testDupPoints5() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-LR-0002-T0002.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.6", c);
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_R_SELF_INTERSECTION, cr.getError().getErrorId());
}
@Test
public void testDupPoints6() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-LR-0002-T0003.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.6", c);
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_R_SELF_INTERSECTION, cr.getError().getErrorId());
}
@Test
public void testDupPoints7() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-LR-0002-T0004.gml",
1);
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.6", c);
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_R_CONSECUTIVE_POINTS_SAME, cr.getError().getErrorId());
}
@Test
public void testDupPoints8() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-LR-0002-T0005.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.6", c);
LinearRing r = p.getExteriorRing();
CheckResult cr = r.getCheckResult(CheckId.C_GE_R_DUPLICATE_POINT);
assertEquals(ResultStatus.DEPENDENCIES_NOT_MET, cr.getResultStatus());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.systemtest;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
/**
*
* @author Matthias Betz
*
*/
public class HoleOutsideSystemTest {
@Test
public void testHoleOutside1() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0001-T0002.gml");
for (Polygon p : c.getBuildings().get(0).getGeometries().get(0).getPolygons()) {
CheckResult cr = p.getCheckResult(CheckId.C_GE_P_HOLE_OUTSIDE);
assertEquals(ResultStatus.OK, cr.getResultStatus());
}
}
@Test
public void testHoleOutside2() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0004-T0001.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.2", c);
CheckResult cr = p.getCheckResult(CheckId.C_GE_P_HOLE_OUTSIDE);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_HOLE_OUTSIDE, cr.getError().getErrorId());
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.systemtest;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ErrorId;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
/**
*
* @author Matthias Betz
*
*/
public class InnerRingsNestedSystemTest {
@Test
public void innerRingsNested1() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0001-T0002.gml");
for (Polygon p : c.getBuildings().get(0).getGeometries().get(0).getPolygons()) {
CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INNER_RINGS_NESTED);
assertEquals(ResultStatus.OK, cr.getResultStatus());
}
}
@Test
public void innerRingsNested2() throws CityGmlParseException, IOException, InvalidGmlFileException {
CityDoctorModel c = TestUtil.loadAndCheckCityModel("src/test/resources/SimpleSolid_SrefBS-GE-gml-PO-0005-T0001.gml");
Polygon p = TestUtil.getPolygonById("_Simple_BD.1_PG.2", c);
CheckResult cr = p.getCheckResult(CheckId.C_GE_P_INNER_RINGS_NESTED);
assertEquals(ResultStatus.ERROR, cr.getResultStatus());
assertEquals(ErrorId.GE_P_INNER_RINGS_NESTED, cr.getError().getErrorId());
}
}
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