GeometryTestUtils.java 3.63 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
/*-
 *  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);
		
		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);
62
63
		geom.updateEdgesAndVertices();
	
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
110
111
112
113
		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);
	}

}