FaceOutCheckTest.java 3.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*-
 *  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();
		
110
		AllPolygonsWrongOrientationCheck foc = new AllPolygonsWrongOrientationCheck();
111
112
113
114
115
116
117
118
119
		foc.check(geom);
		
		Assert.assertEquals(ResultStatus.OK, geom.getCheckResult(foc).getResultStatus());
	}
	
	@Test
	public void testBadGeometry() {
		Geometry geom = createBadGeometry();
		
120
		AllPolygonsWrongOrientationCheck foc = new AllPolygonsWrongOrientationCheck();
121
122
123
124
125
126
127
		foc.check(geom);
		
		Assert.assertEquals(ResultStatus.ERROR, geom.getCheckResult(foc).getResultStatus());

	}

}