/*-
 *  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());
	}

}
