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.datastructure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import org.citygml4j.model.citygml.building.RoofSurface;
import org.citygml4j.model.gml.basicTypes.Code;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
/**
*
* @author Matthias Betz
*
*/
public class BuildingTest {
@Test
public void testCopy() {
Building b = new Building();
b.setGmlId(new GmlId("testId"));
Vertex v1 = new Vertex(1, 0, 0);
Vertex v2 = new Vertex(2, 0, 0);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
ConcretePolygon p = new ConcretePolygon();
p.setExteriorRing(lr);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v1);
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
geom.addPolygon(p);
geom.updateEdgesAndVertices();
b.addGeometry(geom);
b.setCityGmlBuilding(createCityGmlBuilding());
RoofSurface rs = new RoofSurface();
rs.setId("testRoof");
BoundarySurface surface = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.ROOF, rs);
Geometry geomSurface = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
geomSurface.addPolygon(new LinkedPolygon(p, geomSurface));
geomSurface.updateEdgesAndVertices();
surface.addGeometry(geomSurface);
b.addBoundarySurface(surface);
Building copy = b.copy();
assertNotSame(b, copy);
assertEquals(b.getGmlId(), copy.getGmlId());
assertNotSame(b.getGmlId(), copy.getGmlId());
Geometry copyGeom = copy.getGeometries().get(0);
assertNotSame(geom, copyGeom);
Edge edge = geom.getEdges().get(0);
Edge copyEdge = copyGeom.getEdges().get(0);
assertEquals(edge, copyEdge);
assertNotSame(edge, copyEdge);
Polygon copyPolygon = copyGeom.getPolygons().get(0);
assertNotSame(p, copyPolygon);
LinearRing copyRing = copyPolygon.getExteriorRing();
assertNotSame(lr, copyRing);
BoundarySurface copyBs = copy.getBoundarySurfaces().get(0);
assertNotSame(surface, copyBs);
assertEquals(surface.getType(), copyBs.getType());
assertEquals(surface.getFeatureType(), copyBs.getFeatureType());
Geometry copyBsGeom = copyBs.getGeometries().get(0);
assertNotSame(geomSurface, copyBsGeom);
Polygon copyLinkedPoly = copyBsGeom.getPolygons().get(0);
assertNotSame(geomSurface.getPolygons().get(0), copyLinkedPoly);
LinearRing copyExtRing = copyLinkedPoly.getExteriorRing();
assertSame(copyExtRing, copyPolygon.getExteriorRing());
Vertex copyV1 = copyExtRing.getVertices().get(0);
assertSame(copyV1, copyExtRing.getVertices().get(2));
assertEquals(v1, copyV1);
assertNotSame(v1, copyV1);
assertEquals(v2, copyExtRing.getVertices().get(1));
assertNotSame(v2, copyExtRing.getVertices().get(1));
assertEquals(v1, copyExtRing.getVertices().get(2));
Polygon adjacentPoly = v1.getAdjacentPolygons(geom).iterator().next();
Polygon copyAdjacentPoly = copyV1.getAdjacentPolygons(copyGeom).iterator().next();
assertNotNull(copyAdjacentPoly);
assertNotSame(adjacentPoly, copyAdjacentPoly);
assertNotSame(b.getGmlObject(), copy.getGmlObject());
assertEquals(b.getGmlObject().getFunction().get(0).getValue(), copy.getGmlObject().getFunction().get(0).getValue());
}
private org.citygml4j.model.citygml.building.Building createCityGmlBuilding() {
org.citygml4j.model.citygml.building.Building b = new org.citygml4j.model.citygml.building.Building();
b.addFunction(new Code("2349"));
b.setId("test");
return b;
}
}
/*-
* 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.datastructure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.building.AbstractBoundarySurface;
import org.citygml4j.model.citygml.building.WallSurface;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
/**
*
* @author Matthias Betz
*
*/
public class GeometryTest {
@Test
public void testCreate() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
assertNotNull(geom);
assertSame(GeometryType.SOLID, geom.getType());
assertSame(Lod.LOD0, geom.getLod());
}
@Test
public void testAddPolygon() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD0);
Polygon p = new ConcretePolygon();
geom.addPolygon(p);
assertEquals(1, geom.getPolygons().size());
assertSame(geom, p.getParent());
assertSame(geom.getPolygons().get(0), p);
}
@Test
public void testRemovePolygon() {
ParserConfiguration config = new ParserConfiguration(4, false);
AbstractBoundarySurface abs = new WallSurface();
BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
BuildingInstallation bi = new BuildingInstallation();
bi.setGmlObject(gmlBi);
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
Polygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
lr.addVertex(new Vertex(0, 0, 0));
geom.addPolygon(p);
p.setPartOfSurface(bs);
p.setPartOfInstallation(bi);
geom.removePolygon(p);
assertEquals(0, geom.getPolygons().size());
bs.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(abs.getLod2MultiSurface());
bi.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(gmlBi.getLod2Geometry());
}
@Test
public void testReplacePolygon() {
ParserConfiguration config = new ParserConfiguration(4, false);
AbstractBoundarySurface abs = new WallSurface();
BoundarySurface bs = new BoundarySurface(SurfaceFeatureType.BUILDING, BoundarySurfaceType.WALL, abs);
org.citygml4j.model.citygml.building.BuildingInstallation gmlBi = new org.citygml4j.model.citygml.building.BuildingInstallation();
BuildingInstallation bi = new BuildingInstallation();
bi.setGmlObject(gmlBi);
bi.addBoundarySurface(bs);
Geometry geom2 = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
ConcretePolygon p = new ConcretePolygon();
geom2.addPolygon(p);
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
lr.addVertex(new Vertex(0, 0, 0));
p.setPartOfSurface(bs);
p.setPartOfInstallation(bi);
bs.addGeometry(geom2);
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
Polygon linkedPoly = new LinkedPolygon(p, geom);
geom.addPolygon(linkedPoly);
ConcretePolygon p2 = new ConcretePolygon();
p2.setExteriorRing(lr);
ConcretePolygon p3 = new ConcretePolygon();
p3.setExteriorRing(lr);
geom.replacePolygon(linkedPoly, p2, p3);
assertEquals(2, geom.getPolygons().size());
assertEquals(2, geom2.getPolygons().size());
bi.reCreateGeometries(new GMLGeometryFactory(), config);
assertNull(gmlBi.getLod2Geometry());
assertNull(gmlBi.getLod3Geometry());
assertNull(gmlBi.getLod4Geometry());
bs.reCreateGeometries(new GMLGeometryFactory(), config);
assertNotNull(abs.getLod2MultiSurface());
assertNotNull(abs.getLod2MultiSurface().getMultiSurface());
assertNotNull(abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember());
assertFalse(abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember().isEmpty());
assertEquals(2, abs.getLod2MultiSurface().getMultiSurface().getSurfaceMember().size());
assertNull(gmlBi.getLod2Geometry());
}
}
/*-
* 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.datastructure;
import static org.junit.Assert.*;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
/**
*
* @author Matthias Betz
*
*/
public class LinearRingTest {
@Test
public void testIsPointInside1() {
Polygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
Vertex v3 = new Vertex(0, 10, 0);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v3);
lr.addVertex(v0);
assertTrue(lr.isPointInside(v0));
assertTrue(lr.isPointInside(v1));
assertTrue(lr.isPointInside(v2));
assertTrue(lr.isPointInside(v3));
Vector3d v4 = new Vector3d(0.00001, 0.00001, 0);
assertTrue(lr.isPointInside(v4));
Vector3d v5 = new Vector3d(9.9999, 9.9999, 0);
assertTrue(lr.isPointInside(v5));
Vector3d v6 = new Vector3d(-0.00001, 0.00001, 0);
assertFalse(lr.isPointInside(v6));
}
@Test
public void testCalculateNormal() {
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 10, 0);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v0);
Vector3d normal = lr.calculateNormal();
assertEquals(0.0, normal.getX(), 0.0000001);
assertEquals(0.0, normal.getY(), 0.0000001);
assertEquals(1.0, normal.getZ(), 0.0000001);
}
@Test
public void testCalculateNormal2() {
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(10, 0, 0);
Vertex v2 = new Vertex(10, 0, 10);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v0);
Vector3d normal = lr.calculateNormal();
assertEquals(0.0, normal.getX(), 0.0000001);
assertEquals(-1.0, normal.getY(), 0.0000001);
assertEquals(0.0, normal.getZ(), 0.0000001);
}
@Test
public void testCalculateNormal3() {
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
Vertex v0 = new Vertex(0, 0, 0);
Vertex v1 = new Vertex(0, 10, 0);
Vertex v2 = new Vertex(0, 10, 10);
lr.addVertex(v0);
lr.addVertex(v1);
lr.addVertex(v2);
lr.addVertex(v0);
Vector3d normal = lr.calculateNormal();
assertEquals(1.0, normal.getX(), 0.0000001);
assertEquals(0.0, normal.getY(), 0.0000001);
assertEquals(0.0, normal.getZ(), 0.0000001);
}
}
/*-
* 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.datastructure;
import static org.junit.Assert.*;
import org.junit.Test;
public class LodTest {
@Test
public void testIsHigher() {
assertTrue(Lod.LOD1.isHigher(Lod.LOD0));
assertFalse(Lod.LOD1.isHigher(Lod.LOD1));
assertFalse(Lod.LOD0.isHigher(Lod.LOD1));
assertTrue(Lod.LOD3.isHigher(Lod.LOD1));
assertTrue(Lod.LOD1.isHigher(null));
}
}
/*-
* 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.datastructure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
/**
*
* @author Matthias Betz
*
*/
public class VertexTest {
@Test
public void testFromVector() {
Vector3d vec = new Vector3d(1, 2, 3);
Vertex v = new Vertex(vec);
assertEquals(1, v.getX(), 0.0000001);
assertEquals(2, v.getY(), 0.0000001);
assertEquals(3, v.getZ(), 0.0000001);
}
@Test
public void testAddNeightbor() {
Vertex v = new Vertex(0, 0, 0);
Vertex neigh = new Vertex(1, 0, 0);
v.addNeighbor(neigh);
assertSame(neigh, v.getNeighbors().get(0));
Vertex neigh2 = new Vertex(2, 0, 0);
v.addNeighbor(neigh2);
assertSame(neigh2, v.getNeighbors().get(1));
}
@Test
public void testEqualsWidthNeighbor() {
Vertex v = new Vertex(0, 0, 0);
Vertex neigh = new Vertex(1, 0, 0);
v.addNeighbor(neigh);
Vertex other = new Vertex(1, 0, 0);
assertTrue(v.equalsWithNeighbors(other));
Vertex other2 = new Vertex(2, 0, 0);
assertFalse(v.equalsWithNeighbors(other2));
}
@Test
public void testNoNeighbors() {
Vertex v = new Vertex(1, 2, 3);
assertTrue(v.getNeighbors().isEmpty());
}
@Test
public void testGetAdjacentRings() {
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(0, 0, 0);
lr.addVertex(v0);
Set<LinearRing> adjacentRings = v0.getAdjacentRings(geom);
assertEquals(1, adjacentRings.size());
assertTrue(adjacentRings.contains(lr));
}
@Test
public void testGetAdjacentRingsWithNeighbor() {
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(0, 0, 0);
lr.addVertex(v0);
Polygon p2 = new ConcretePolygon();
geom.addPolygon(p2);
LinearRing lr2 = new LinearRing(LinearRingType.EXTERIOR);
p2.setExteriorRing(lr2);
Vertex v1 = new Vertex(0, 0.00000001, 0);
lr2.addVertex(v1);
v0.addNeighbor(v1);
v1.addNeighbor(v0);
assertSame(v0, v1.getNeighbors().get(0));
assertSame(v1, v0.getNeighbors().get(0));
Set<LinearRing> adjacentRings = v0.getAdjacentRings(geom);
assertEquals(2, adjacentRings.size());
assertTrue(adjacentRings.contains(lr));
assertTrue(adjacentRings.contains(lr2));
adjacentRings = v1.getAdjacentRings(geom);
assertEquals(2, adjacentRings.size());
assertTrue(adjacentRings.contains(lr));
assertTrue(adjacentRings.contains(lr2));
}
@Test(expected = IllegalStateException.class)
public void testGetAdjacentRingsGeometryNotContainingVertex() {
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
Polygon p = new ConcretePolygon();
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
p.setExteriorRing(lr);
Vertex v0 = new Vertex(0, 0, 0);
lr.addVertex(v0);
v0.getAdjacentRings(geom);
}
}
/*-
* 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.mapper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.citygml4j.model.citygml.waterbody.WaterBody;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.gml.geometry.primitives.Coord;
import org.citygml4j.model.gml.geometry.primitives.Exterior;
import org.citygml4j.model.gml.geometry.primitives.LinearRing;
import org.citygml4j.model.gml.geometry.primitives.Polygon;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.Edge;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.datastructure.WaterObject;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
/**
*
* @author Matthias Betz
*
*/
public class FeatureMapperTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void testNeighboringVertices() throws IOException {
WaterBody body = new WaterBody();
Polygon p = new Polygon();
LinearRing ring = new LinearRing();
Coord coord = createCoord(0, 0.0000000049, 0);
ring.addCoord(coord);
p.setExterior(new Exterior(ring));
Polygon p2 = new Polygon();
LinearRing ring2 = new LinearRing();
coord = createCoord(0, 0.0000000050, 0);
ring2.addCoord(coord);
p2.setExterior(new Exterior(ring2));
MultiSurface ms = new MultiSurface(p, p2);
body.setLod1MultiSurface(new MultiSurfaceProperty(ms));
ParserConfiguration config = new ParserConfiguration(8, false);
FeatureMapper mapper = new FeatureMapper(config, folder.newFile());
mapper.visit(body);
CityDoctorModel model = mapper.getModel();
assertEquals(1, model.getWater().size());
WaterObject waterObject = model.getWater().get(0);
Geometry geometry = waterObject.getGeometries().get(0);
assertEquals(2, geometry.getVertices().size());
Vertex vertex = geometry.getVertices().get(0);
assertEquals(1, vertex.getNeighbors().size());
Vertex neighbor = vertex.getNeighbors().get(0);
if (vertex.equals(new Vertex(0, 0, 0))) {
assertEquals(new Vertex(0, 0.00000001, 0), neighbor);
} else {
assertEquals(new Vertex(0, 0, 0), neighbor);
}
vertex = geometry.getVertices().get(1);
assertEquals(1, vertex.getNeighbors().size());
neighbor = vertex.getNeighbors().get(0);
if (vertex.equals(new Vertex(0, 0, 0))) {
assertEquals(new Vertex(0, 0.00000001, 0), neighbor);
} else {
assertEquals(new Vertex(0, 0, 0), neighbor);
}
}
@Test
public void testNeighboringVertices2() throws IOException {
WaterBody body = new WaterBody();
Polygon p = new Polygon();
LinearRing ring = new LinearRing();
Coord coord = createCoord(0, 0.0000000049, 0);
ring.addCoord(coord);
coord = createCoord(0, 0.0000000150, 0);
ring.addCoord(coord);
p.setExterior(new Exterior(ring));
MultiSurface ms = new MultiSurface(p);
body.setLod1MultiSurface(new MultiSurfaceProperty(ms));
ParserConfiguration config = new ParserConfiguration(8, false);
FeatureMapper mapper = new FeatureMapper(config, folder.newFile());
mapper.visit(body);
CityDoctorModel model = mapper.getModel();
assertEquals(1, model.getWater().size());
WaterObject waterObject = model.getWater().get(0);
Geometry geometry = waterObject.getGeometries().get(0);
assertEquals(2, geometry.getVertices().size());
Vertex vertex = geometry.getVertices().get(0);
assertEquals(0, vertex.getNeighbors().size());
}
@Test
public void testNeighboringVerticesWithCompleteGeometry() throws IOException {
WaterBody body = new WaterBody();
Polygon p1 = new Polygon();
LinearRing ring1 = new LinearRing();
p1.setExterior(new Exterior(ring1));
ring1.addCoord(createCoord(0, 0, 0));
ring1.addCoord(createCoord(1, 0, 0));
ring1.addCoord(createCoord(1, 1, 0));
ring1.addCoord(createCoord(1, 2, 0));
ring1.addCoord(createCoord(0, 2, 0));
ring1.addCoord(createCoord(0, 0, 0));
Polygon p2 = new Polygon();
LinearRing ring2 = new LinearRing();
p2.setExterior(new Exterior(ring2));
ring2.addCoord(createCoord(1, 0, 0));
ring2.addCoord(createCoord(2, 0, 0));
ring2.addCoord(createCoord(2, 2, 0));
ring2.addCoord(createCoord(1, 2, 0));
ring2.addCoord(createCoord(1, 1.0000000050, 0));
ring2.addCoord(createCoord(1, 0, 0));
MultiSurface ms = new MultiSurface(p1, p2);
body.setLod1MultiSurface(new MultiSurfaceProperty(ms));
ParserConfiguration config = new ParserConfiguration(8, false);
FeatureMapper mapper = new FeatureMapper(config, folder.newFile());
mapper.visit(body);
CityDoctorModel model = mapper.getModel();
assertEquals(1, model.getWater().size());
WaterObject waterObject = model.getWater().get(0);
Geometry geometry = waterObject.getGeometries().get(0);
assertEquals(8, geometry.getVertices().size());
List<Vertex> neighborVertices = new ArrayList<>();
for (Vertex v : geometry.getVertices()) {
if (!v.getNeighbors().isEmpty()) {
assertEquals(1, v.getNeighbors().size());
assertEquals(2, v.getAdjacentPolygons(geometry).size());
assertEquals(2, v.getAdjacentRings(geometry).size());
neighborVertices.add(v);
}
}
assertEquals(2, neighborVertices.size());
Vertex v0 = neighborVertices.get(0);
Vertex v1 = neighborVertices.get(1);
assertEquals(v0.getNeighbors().get(0), v1);
assertEquals(v1.getNeighbors().get(0), v0);
assertEquals(8, geometry.getEdges().size());
assertNull(geometry.getEdge(v0, v1));
List<Vertex> ringVertices = geometry.getPolygons().get(0).getExteriorRing().getVertices();
int pos = -1;
for (int i = 0; i < ringVertices.size(); i++) {
if (ringVertices.get(i).equals(v0) || ringVertices.get(i).equals(v1)) {
pos = i;
break;
}
}
assertTrue(pos > 0);
Vertex prev = ringVertices.get(pos - 1);
Edge e1 = geometry.getEdge(v0, prev);
Edge e2 = geometry.getEdge(v1, prev);
Edge e3 = geometry.getEdge(prev, v0);
Edge e4 = geometry.getEdge(prev, v1);
assertEquals(e1, e2);
assertEquals(e1, e3);
assertEquals(e1, e4);
assertEquals(e2, e3);
assertEquals(e2, e4);
assertEquals(e3, e4);
}
private Coord createCoord(double x, double y, double z) {
Coord coord = new Coord();
coord.setX(x);
coord.setY(y);
coord.setZ(z);
return coord;
}
}
/*-
* 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.mapper;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.citygml4j.model.gml.geometry.primitives.Coord;
import org.citygml4j.model.gml.geometry.primitives.Exterior;
import org.citygml4j.model.gml.geometry.primitives.LinearRing;
import org.citygml4j.model.gml.geometry.primitives.Polygon;
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.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Pair;
/**
*
* @author Matthias Betz
*
*/
public class GeometryMapperTest {
@Test
public void testRounding() {
Polygon p = new Polygon();
LinearRing ring = new LinearRing();
Coord coord = new Coord();
coord.setX(0d);
coord.setY(0.0000000049d);
coord.setZ(0d);
ring.addCoord(coord);
coord = new Coord();
coord.setX(0d);
coord.setY(0.0000000050d);
coord.setZ(0d);
ring.addCoord(coord);
p.setExterior(new Exterior(ring));
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD0);
ParserConfiguration config = new ParserConfiguration(8, false);
Map<String, ConcretePolygon> polygons = new HashMap<>();
List<Pair<String, Geometry>> linkedPolygons = new ArrayList<>();
Map<Vertex, Vertex> vertices = new HashMap<>();
GeometryMapper mapper = new GeometryMapper(geom, config, polygons, linkedPolygons, vertices);
mapper.visit(p);
assertEquals(2, vertices.size());
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class LineTest {
@Test
public void testIntersection1() {
Vector3d v0 = new Vector3d(-1, 0, 2);
Vector3d v1 = new Vector3d(-1, 0, -2);
Vector3d v2 = new Vector3d(1, 0, 0);
Triangle3d t = new Triangle3d(v0, v1, v2);
Line3d l = new Line3d(new Vector3d(0, 0, 0), new Vector3d(0, 1, 0));
assertEquals(l.intersection(t), new Vector3d(0, 0, 0));
}
@Test
public void testIntersection2() {
Vector3d v0 = new Vector3d(-1, 0, 2);
Vector3d v1 = new Vector3d(-1, 0, -2);
Vector3d v2 = new Vector3d(1, 0, 0);
Triangle3d t = new Triangle3d(v0, v1, v2);
Line3d l = new Line3d(new Vector3d(0, 1, 0), new Vector3d(0, 1, 0));
assertEquals(l.intersection(t), new Vector3d(0, 0, 0));
}
@Test
public void testIntersection3() {
Vector3d v0 = new Vector3d(-1, 0, 2);
Vector3d v1 = new Vector3d(-1, 0, -2);
Vector3d v2 = new Vector3d(1, 0, 0);
Triangle3d t = new Triangle3d(v0, v1, v2);
Line3d l = new Line3d(new Vector3d(2, 1, 0), new Vector3d(0, 1, 0));
assertNull(l.intersection(t));
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class Matrix3x3dTest {
@Test
public void testTranspose() {
double[][] original = new double[][] {
{9, 8, 7},
{6, 5, 4},
{3, 2, 1}
};
double[][] expected = new double[][] {
{9, 6, 3},
{8, 5, 2},
{7, 4, 1}
};
Matrix3x3d originalMatrix = new Matrix3x3d(original);
Matrix3x3d expectedMatrix = new Matrix3x3d(expected);
assertEquals(expectedMatrix, originalMatrix.transpose());
}
}
/*-
* 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.math;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class OrthogonalRegressionLineTest {
@Test
public void testRegressionLine() {
Vertex v1 = new Vertex(0, 0, 0);
Vertex v2 = new Vertex(1, 1, 0);
Vertex v3 = new Vertex(2, 2, 0);
Vertex v4 = new Vertex(5, 5, 0);
List<Vertex> vertices = new ArrayList<>();
vertices.add(v1);
vertices.add(v2);
vertices.add(v3);
vertices.add(v4);
Line3d result = OrthogonalRegressionLine.getRegressionLine(vertices);
Assert.assertEquals(0, result.distanceToPoint(v2), 0.000001);
Assert.assertEquals(Math.sqrt(2) / 2, result.distanceToPoint(new Vertex(1, 0, 0)), 0.000001);
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class PlaneTest {
@Test
public void testProjectPointToPlane() {
Vector3d n = new Vector3d(0, 0, 1);
Vector3d origin = new Vector3d(0, 0, 0);
Plane plane = new Plane(n, origin);
Vector3d p = new Vector3d(5, 5, 5);
assertEquals(5, plane.getDistance(p), 0.00001);
assertEquals(new Vector3d(5, 5, 0), plane.projectPointToPlane(p));
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class QuaternionTest {
@Test
public void testFromToRotation() {
Vector3d v0 = new Vector3d(1, 164, 4);
Vector3d v1 = new Vector3d(1, 5, 10);
Vector3d v2 = new Vector3d(3, 3, 4);
Vector3d d0 = v1.minus(v0);
Vector3d d1 = v2.minus(v0);
Vector3d normal = d0.cross(d1);
normal.normalize();
Vector3d zAxis = new Vector3d(0, 0, 1);
Quaternion quad = Quaternion.fromToRotation(normal, zAxis);
Matrix3x3d rota2 = quad.toRotationMatrix();
Vector3d newV0 = rota2.mult(v0);
Vector3d newV1 = rota2.mult(v1);
Vector3d newV2 = rota2.mult(v2);
Vector3d newd0 = newV1.minus(newV0);
Vector3d newd1 = newV2.minus(newV0);
assertEquals(d0.getLength(), newd0.getLength(), 0.00001);
assertEquals(d1.getLength(), newd1.getLength(), 0.00001);
assertEquals(newV1.getZ(), newV0.getZ(), 0.00001);
assertEquals(newV2.getZ(), newV0.getZ(), 0.00001);
assertEquals(newV1.getZ(), newV2.getZ(), 0.00001);
}
}
/*-
* 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.math;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class RayTest {
@Test
public void testTriangleIntersection() {
Vector3d origin = new Vector3d(0, 0, 0);
Vector3d direction = new Vector3d(1D, 0, 0);
Ray ray = new Ray(origin, direction);
Vector3d v0 = new Vector3d(1D, -5D, -10D);
Vector3d v1 = new Vector3d(1D, -5D, 10D);
Vector3d v2 = new Vector3d(1D, 10D, 10D);
assertNotNull(ray.intersectTriangle(v0, v1, v2));
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class Segment2dTest {
@Test
public void testDistance() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Segment2d seg = new Segment2d(p1, p2);
Vector2d p3 = new Vector2d(2.5, 1);
assertEquals(1d, seg.distance(p3), 0.00001);
Vector2d p4 = new Vector2d(1, 1);
assertEquals(1d, seg.distance(p4), 0.00001);
Vector2d p5 = new Vector2d(0, -2);
assertEquals(2d, seg.distance(p5), 0.00001);
}
@Test
public void testIntersect() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 5);
Vector2d p3 = new Vector2d(0, 5);
Vector2d p4 = new Vector2d(5, 0);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertTrue(seg1.intersects(seg2));
}
/**
* two segments on same line, not intersecting
*/
@Test
public void testIntersect2() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Vector2d p3 = new Vector2d(7, 0);
Vector2d p4 = new Vector2d(10, 0);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertFalse(seg1.intersects(seg2));
}
/**
* two segments on same line, intersecting
*/
@Test
public void testIntersect3() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Vector2d p3 = new Vector2d(3, 0);
Vector2d p4 = new Vector2d(10, 0);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertTrue(seg1.intersects(seg2));
}
/**
* two segments on same line, same segments
*/
@Test
public void testIntersect4() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5.1, 0);
Vector2d p3 = new Vector2d(0, 0);
Vector2d p4 = new Vector2d(5, 0);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertTrue(seg1.intersects(seg2));
}
/**
* two segments parallel
*/
@Test
public void testIntersect5() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Vector2d p3 = new Vector2d(0, 1);
Vector2d p4 = new Vector2d(5, 1);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertFalse(seg1.intersects(seg2));
}
/**
* two segments not parallel, not intersecting
*/
@Test
public void testIntersect6() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Vector2d p3 = new Vector2d(0, 1);
Vector2d p4 = new Vector2d(5, 0.1);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertFalse(seg1.intersects(seg2));
}
/**
* two segments intersecting, calculate intersection point
*/
@Test
public void testIntersectionPoint1() {
Vector2d p1 = new Vector2d(1, 1);
Vector2d p2 = new Vector2d(3, 2);
Vector2d p3 = new Vector2d(1, 4);
Vector2d p4 = new Vector2d(2, -1);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
Vector2d expected = new Vector2d(17d/11d, 14d/11d);
assertTrue(expected.equalsWithinEpsilon(seg1.intersectionPoint(seg2), 0.00001));
}
/**
* two segments on same line, intersecting
*/
@Test
public void testIntersectionPoint2() {
Vector2d p1 = new Vector2d(0, 0);
Vector2d p2 = new Vector2d(5, 0);
Vector2d p3 = new Vector2d(3, 0);
Vector2d p4 = new Vector2d(10, 0);
Segment2d seg1 = new Segment2d(p1, p2);
Segment2d seg2 = new Segment2d(p3, p4);
assertTrue(p3.equalsWithinEpsilon(seg1.intersectionPoint(seg2), 0.00001));
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class Segment3dTest {
@Test
public void testGetNormalThroughPoint1() {
Vector3d v0 = new Vector3d(0, -1, 0);
Vector3d v1 = new Vector3d(1, -1, 0);
Vector3d v2 = new Vector3d(2, 1, 0);
Segment3d seg = new Segment3d(v0, v1);
assertEquals(new Vector3d(0, 2, 0), seg.getNormalThroughPoint(v2));
}
@Test
public void testGetNormalThroughPoint2() {
Vector3d v0 = new Vector3d(0, -1, 0);
Vector3d v1 = new Vector3d(1, -1, 0);
Vector3d v2 = new Vector3d(2, -3, 0);
Segment3d seg = new Segment3d(v0, v1);
assertEquals(new Vector3d(0, -2, 0), seg.getNormalThroughPoint(v2));
}
@Test
public void testGetDistance1() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(1, 0, 0);
Vector3d v3 = new Vector3d(2, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1 / Math.sqrt(2), s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance2() {
Vector3d v0 = new Vector3d(0, 0, 1);
Vector3d v1 = new Vector3d(1, 0, 1);
Vector3d v2 = new Vector3d(2, 0, 1);
Vector3d v3 = new Vector3d(3, 0, 1);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance3() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(2, 0, -1);
Vector3d v3 = new Vector3d(2, 0, 1);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance4() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(0, -1, 0);
Vector3d v3 = new Vector3d(2.1, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(0.7241379, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance5() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(1, 0, 0);
Vector3d v3 = new Vector3d(0, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(0.0, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistancePoint1() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Segment3d s1 = new Segment3d(v0, v1);
Vector3d v2 = new Vector3d(2, 0, 0);
assertEquals(1.0, s1.getDistance(v2), 0.000001);
Vector3d v3 = new Vector3d(-1, 0, 0);
assertEquals(1.0, s1.getDistance(v3), 0.000001);
Vector3d v4 = new Vector3d(0, 1, 0);
assertEquals(1.0, s1.getDistance(v4), 0.000001);
Vector3d v5 = new Vector3d(0.5, 1, 1);
assertEquals(Math.sqrt(2), s1.getDistance(v5), 0.000001);
}
}
/*-
* 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.math;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class SegmentTest {
@Test
public void testGetDistance1() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(1, 0, 0);
Vector3d v3 = new Vector3d(2, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1 / Math.sqrt(2), s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance2() {
Vector3d v0 = new Vector3d(0, 0, 1);
Vector3d v1 = new Vector3d(1, 0, 1);
Vector3d v2 = new Vector3d(2, 0, 1);
Vector3d v3 = new Vector3d(3, 0, 1);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance3() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(2, 0, -1);
Vector3d v3 = new Vector3d(2, 0, 1);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(1, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance4() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(0, -1, 0);
Vector3d v3 = new Vector3d(2.1, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(0.7241379, s1.getDistance(s2), 0.000001);
}
@Test
public void testGetDistance5() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 1, 0);
Vector3d v2 = new Vector3d(1, 0, 0);
Vector3d v3 = new Vector3d(0, 1, 0);
Segment3d s1 = new Segment3d(v0, v1);
Segment3d s2 = new Segment3d(v2, v3);
assertEquals(0.0, s1.getDistance(s2), 0.000001);
}
}
/*-
* 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.math;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class Triangle3dTest {
/**
* Simple square
*/
@Test
public void testIntersection1() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(1, 1, 0);
Vector3d v3 = new Vector3d(0, 1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v2, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane bordering triangle in y-z plane
*/
@Test
public void testIntersection2() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(0, 1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v2, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane intersecting with triangle in y-z plane in one point
*/
@Test
public void testIntersection3() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(0, 1, 0);
Vector3d v4 = new Vector3d(0, 1, 1);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v4, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane bordering triangle in y-z plane
*/
@Test
public void testIntersection4() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(0, 1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v2, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane intersecting with triangle in y-z plane in one corner point
*/
@Test
public void testIntersection5() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(-0.5, 1, 0);
Vector3d v4 = new Vector3d(-0.5, 1, 1);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v4, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane not intersecting with triangle in y-z plane
*/
@Test
public void testIntersection6() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(-0.5, 1, 0);
Vector3d v4 = new Vector3d(-0.5, 1, 1);
Vector3d v5 = new Vector3d(-0.5, -1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v5, v4, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane intersecting with other triangle
*/
@Test
public void testIntersection7() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(-0.5, 1, 0);
Vector3d v4 = new Vector3d(-0.5, 1, 1);
Vector3d v5 = new Vector3d(1, -1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v5, v4, v3);
assertTrue(t1.doesIntersect(t2));
assertTrue(t2.doesIntersect(t1));
}
/**
* triangle in x-z plane not intersecting with triangle in y-z plane
*/
@Test
public void testIntersection8() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 1);
Vector3d v3 = new Vector3d(0.5, 1, 0);
Vector3d v4 = new Vector3d(0.5, 1, 1);
Vector3d v5 = new Vector3d(1, 1, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v5, v4, v3);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* two triangles bordering a third, but not sharing an exact edge
*/
@Test
public void testIntersection9() {
Vector3d v0 = new Vector3d(1, 1, 0);
Vector3d v1 = new Vector3d(2, 0, 0);
Vector3d v2 = new Vector3d(3, 1, 0);
Vector3d v3 = new Vector3d(1.5, 2, 0);
Vector3d v4 = new Vector3d(2, 1, 0);
Vector3d v5 = new Vector3d(2.5, 2, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v4, v3);
Triangle3d t3 = new Triangle3d(v4, v2, v5);
assertFalse(t1.doesIntersect(t2));
assertFalse(t1.doesIntersect(t3));
assertFalse(t2.doesIntersect(t3));
assertFalse(t2.doesIntersect(t1));
assertFalse(t2.doesIntersect(t1));
assertFalse(t3.doesIntersect(t2));
}
/**
* two triangles bordering a third, but not sharing an exact edge, one intersecting into the third
*/
@Test
public void testIntersection10() {
Vector3d v0 = new Vector3d(1, 1, 0);
Vector3d v1 = new Vector3d(2, 0, 0);
Vector3d v2 = new Vector3d(3, 1, 0);
Vector3d v3 = new Vector3d(1.5, 2, 0);
Vector3d v4 = new Vector3d(2, 1, 0);
Vector3d v5 = new Vector3d(2.5, 2, 0);
Vector3d v6 = new Vector3d(3, 0.5, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v0, v4, v3);
Triangle3d t3 = new Triangle3d(v4, v6, v5);
assertFalse(t1.doesIntersect(t2));
assertTrue(t1.doesIntersect(t3));
assertFalse(t2.doesIntersect(t3));
assertFalse(t2.doesIntersect(t1));
assertTrue(t3.doesIntersect(t1));
assertFalse(t3.doesIntersect(t2));
}
/**
* two triangles intersecting
*/
@Test
public void testIntersection11() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(2, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 4);
Vector3d v3 = new Vector3d(-1, 2, 2);
Vector3d v4 = new Vector3d(-1, -2, 2);
Vector3d v5 = new Vector3d(1.5, 2, 2);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertTrue(t1.doesIntersect(t2));
assertTrue(t2.doesIntersect(t1));
}
/**
* two triangles not intersecting
*/
@Test
public void testIntersection12() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(2, 0, 0);
Vector3d v2 = new Vector3d(0, 0, 4);
Vector3d v3 = new Vector3d(-10, 2, 2);
Vector3d v4 = new Vector3d(-10, -2, 2);
Vector3d v5 = new Vector3d(-7.5, 2, 2);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* two triangles, one completely in another
*/
@Test
public void testIntersection13() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(3, 0, 0);
Vector3d v2 = new Vector3d(0, 3, 0);
Vector3d v3 = new Vector3d(0.5, 0.5, 0);
Vector3d v4 = new Vector3d(1.5, 0.5, 0);
Vector3d v5 = new Vector3d(0.5, 1.5, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertTrue(t1.doesIntersect(t2));
assertTrue(t2.doesIntersect(t1));
}
/**
* one triangle intersecting with itself
*/
@Test
public void testIntersection14() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(3, 0, 0);
Vector3d v2 = new Vector3d(0, 3, 0);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
assertTrue(t1.doesIntersect(t1));
}
/**
* two triangles intersecting
*/
@Test
public void testIntersection15() {
Vector3d v0 = new Vector3d(0, 0, 0);
Vector3d v1 = new Vector3d(30, 0, 0);
Vector3d v2 = new Vector3d(0, 30, 0);
Vector3d v3 = new Vector3d(1, 1, 2);
Vector3d v4 = new Vector3d(1, 2, 2);
Vector3d v5 = new Vector3d(1, 1, -2);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertTrue(t1.doesIntersect(t2));
assertTrue(t2.doesIntersect(t1));
}
/**
* two triangles not intersecting, forming square in z-y plane
*/
@Test
public void testIntersection16() {
Vector3d v0 = new Vector3d(0, 0, 10);
Vector3d v1 = new Vector3d(0, 0, 0);
Vector3d v2 = new Vector3d(0, 10, 0);
Vector3d v3 = new Vector3d(0, 0, 10);
Vector3d v4 = new Vector3d(0, 10, 0);
Vector3d v5 = new Vector3d(0, 10, 10);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* two triangles not intersecting
*/
@Test
public void testIntersection17() {
Vector3d v0 = new Vector3d(550200.6852498532, 5804577.182086236, 53.93);
Vector3d v1 = new Vector3d(550200.7309999987, 5804577.647, 76.3842995075415);
Vector3d v2 = new Vector3d(550200.7309999987, 5804577.647, 53.93);
Vector3d v3 = new Vector3d(550200.7309999987, 5804577.647, 76.3842995075415);
Vector3d v4 = new Vector3d(550208.1420000009, 5804576.824, 53.93);
Vector3d v5 = new Vector3d(550206.5491363483, 5804577.000889325, 53.93);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* two triangles not intersecting
*/
@Test
public void testIntersection18() {
Vector3d v0 = new Vector3d(550149.932, 5804610.759, 54.03);
Vector3d v1 = new Vector3d(550149.9542761615, 5804610.920099844, 54.03);
Vector3d v2 = new Vector3d(550158.8960000016, 5804609.528, 54.03);
Vector3d v3 = new Vector3d(550149.9542761615, 5804610.920099844, 54.03);
Vector3d v4 = new Vector3d(550150.4580000006, 5804614.563, 54.03);
Vector3d v5 = new Vector3d(550158.8960000016, 5804609.528, 54.03);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
assertFalse(t1.doesIntersect(t2));
assertFalse(t2.doesIntersect(t1));
}
/**
* two triangles not intersecting
*/
@Test
public void testIntersection19() {
Vector3d v0 = new Vector3d(16.18180670822862, 4.826301792879059, 9.101142199244872);
Vector3d v1 = new Vector3d(14.894806708275654, 12.727301792484178, 9.101142199244872);
Vector3d v2 = new Vector3d(10.549806708245386, 6.8063017923947715, 13.101142199244872);
Vector3d v3 = new Vector3d(17.296806708277515, 5.008301792908862, 9.101142199244872);
Vector3d v4 = new Vector3d(15.228806708249111, 4.671301792618289, 9.101142199244872);
Vector3d v5 = new Vector3d(15.228806708249111, 4.671301792618289, 0.6911421992448763);
double xMin = Double.MAX_VALUE;
double yMin = Double.MAX_VALUE;
double zMin = Double.MAX_VALUE;
xMin = Math.min(xMin, v0.getX());
xMin = Math.min(xMin, v1.getX());
xMin = Math.min(xMin, v2.getX());
xMin = Math.min(xMin, v3.getX());
xMin = Math.min(xMin, v4.getX());
xMin = Math.min(xMin, v5.getX());
yMin = Math.min(yMin, v0.getY());
yMin = Math.min(yMin, v1.getY());
yMin = Math.min(yMin, v2.getY());
yMin = Math.min(yMin, v3.getY());
yMin = Math.min(yMin, v4.getY());
yMin = Math.min(yMin, v5.getY());
zMin = Math.min(zMin, v0.getZ());
zMin = Math.min(zMin, v1.getZ());
zMin = Math.min(zMin, v2.getZ());
zMin = Math.min(zMin, v3.getZ());
zMin = Math.min(zMin, v4.getZ());
zMin = Math.min(zMin, v5.getZ());
v0.setX(v0.getX() - xMin);
v0.setY(v0.getY() - yMin);
v0.setZ(v0.getZ() - zMin);
v1.setX(v1.getX() - xMin);
v1.setY(v1.getY() - yMin);
v1.setZ(v1.getZ() - zMin);
v2.setX(v2.getX() - xMin);
v2.setY(v2.getY() - yMin);
v2.setZ(v2.getZ() - zMin);
v3.setX(v3.getX() - xMin);
v3.setY(v3.getY() - yMin);
v3.setZ(v3.getZ() - zMin);
v4.setX(v4.getX() - xMin);
v4.setY(v4.getY() - yMin);
v4.setZ(v4.getZ() - zMin);
v5.setX(v5.getX() - xMin);
v5.setY(v5.getY() - yMin);
v5.setZ(v5.getZ() - zMin);
Triangle3d t1 = new Triangle3d(v0, v1, v2);
Triangle3d t2 = new Triangle3d(v3, v4, v5);
// System.out.println(String.format("dreieck(%.4f|%.4f|%.4f %.4f|%.4f|%.4f %.4f|%.4f|%.4f)", v0.getX(), v0.getY(), v0.getZ(), v1.getX(), v1.getY(), v1.getZ(), v2.getX(), v2.getY(), v2.getZ()));
// System.out.println(String.format("dreieck(%.4f|%.4f|%.4f %.4f|%.4f|%.4f %.4f|%.4f|%.4f)", v3.getX(), v3.getY(), v3.getZ(), v4.getX(), v4.getY(), v4.getZ(), v5.getX(), v5.getY(), v5.getZ()));
assertFalse(t2.doesIntersect(t1));
assertFalse(t1.doesIntersect(t2));
}
}
/*-
* 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.math;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author Matthias Betz
*
*/
public class Vector3dTest {
@Test
public void testDotProduct() {
Vector3d vec = new Vector3d(1, 0, 0);
Vector3d v2 = new Vector3d(1, 1, 0);
v2.normalize();
assertEquals(Math.sqrt(2) / 2, vec.dot(v2), 0.00001);
Vector3d v3 = new Vector3d(1, -1, 0);
v3.normalize();
assertEquals(Math.sqrt(2) / 2, vec.dot(v3), 0.00001);
}
}
/*-
* 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.math.graph;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
/**
*
* @author Matthias Betz
*
*/
public class KDTreeTest {
@Test
public void testGetNodesInRange() {
Vertex v1 = new Vertex(0, 0, 0);
Vertex v2 = new Vertex(0, 0, 0.1);
Vertex v3 = new Vertex(0.1, 0, 0);
Vertex v4 = new Vertex(-0.201, 0, 0);
KDTree tree = new KDTree();
tree.add(v1);
tree.add(v2);
tree.add(v3);
tree.add(v4);
List<Vertex> nodesInRange = tree.getNodesInRange(new Vertex(0, 0, 0), 0.2);
assertTrue(nodesInRange.contains(v1));
assertTrue(nodesInRange.contains(v2));
assertTrue(nodesInRange.contains(v3));
}
}
/*-
* 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.math.graph;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
/**
*
* @author Matthias Betz
*
*/
public class TarjanGraphTest {
@Test
public void testConnectedComponents() {
LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R1"));
CycleNode root = new CycleNode(lr);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R2"));
CycleNode c0 = new CycleNode(lr);
root.addChild(c0);
c0.addChild(root);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R3"));
CycleNode c00 = new CycleNode(lr);
c0.addChild(c00);
c00.addChild(root);
c00.addChild(c0);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R4"));
CycleNode c000 = new CycleNode(lr);
c00.addChild(c000);
c000.addChild(root);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R5"));
CycleNode c1 = new CycleNode(lr);
root.addChild(c1);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R6"));
CycleNode c2 = new CycleNode(lr);
root.addChild(c2);
lr = new LinearRing(LinearRingType.EXTERIOR);
lr.setGmlId(new GmlId("R7"));
CycleNode c20 = new CycleNode(lr);
c2.addChild(c20);
root.addChild(c20);
CycleGraph tg = new CycleGraph(root);
List<List<LinearRing>> connectedComponents = tg.getConnectedComponents();
Assert.assertEquals(4, connectedComponents.size());
}
}
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