/*-
 *  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.HashMap;
import java.util.Map;

import org.junit.Test;
import org.xmlobjects.gml.model.geometry.DirectPosition;
import org.xmlobjects.gml.model.geometry.GeometricPosition;
import org.xmlobjects.gml.model.geometry.primitives.AbstractRingProperty;
import org.xmlobjects.gml.model.geometry.primitives.LinearRing;
import org.xmlobjects.gml.model.geometry.primitives.Polygon;

import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.mapper.citygml3.Citygml3GeometryMapper;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;

/**
 * 
 * @author Matthias Betz
 *
 */
public class GeometryMapperTest {

	@Test
	public void testRounding() {
		Polygon p = new Polygon();
		LinearRing ring = new LinearRing();
		GeometricPosition coord = new GeometricPosition(new DirectPosition(0d, 0.0000000049d, 0d));
		ring.getControlPoints().getGeometricPositions().add(coord);
		
		coord = new GeometricPosition(new DirectPosition(0d, 0.0000000050d, 0d));
		ring.getControlPoints().getGeometricPositions().add(coord);
		p.setExterior(new AbstractRingProperty(ring));
		
		ParserConfiguration config = new ParserConfiguration(8, false);
		Map<Vertex, Vertex> vertices = new HashMap<>();
		Citygml3GeometryMapper mapper = new Citygml3GeometryMapper(config, vertices);
		mapper.visit(p);
		assertEquals(2, vertices.size());
	}

}
