/*-
 *  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.Collections;
import java.util.List;

import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;

/**
 * A Polygon that has been moved by an offset point. Used to avoid numerical
 * inaccuracies.
 * 
 * @author Matthias Betz
 *
 */
public class MovedPolygon {

	private Polygon original;

	private MovedRing exteriorRing;
	private List<MovedRing> innerRings;

	public static MovedPolygon ofPolygon(Polygon p, Vector3d movedBy) {
		MovedPolygon indPoly = new MovedPolygon();
		indPoly.original = p;
		indPoly.exteriorRing = MovedRing.ofRing(p.getExteriorRing(), movedBy);
		for (LinearRing inner : p.getInnerRings()) {
			indPoly.addInnerRing(MovedRing.ofRing(inner, movedBy));
		}
		return indPoly;
	}

	public Polygon getOriginal() {
		return original;
	}

	public void setExteriorRing(MovedRing exteriorRing) {
		this.exteriorRing = exteriorRing;
	}

	public MovedRing getExteriorRing() {
		return exteriorRing;
	}

	public void addInnerRing(MovedRing ring) {
		if (innerRings == null) {
			innerRings = new ArrayList<>();
		}
		innerRings.add(ring);
	}

	public List<MovedRing> getInnerRings() {
		if (innerRings == null) {
			return Collections.emptyList();
		}
		return innerRings;
	}

}
