/*-
 *  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.tesselation;

import java.util.ArrayList;
import java.util.List;

import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.math.Triangle3d;
import de.hft.stuttgart.citydoctor2.math.Vector3d;

/**
 * A tesselated ring containing a list of triangles and a reference to the
 * original ring.
 * 
 * @author Matthias Betz
 *
 */
public class TesselatedRing {

	private List<Triangle3d> triangles;
	private LinearRing ring;

	public TesselatedRing(List<Triangle3d> triangles, LinearRing ring) {
		this.ring = ring;
		this.triangles = triangles;
	}

	public TesselatedRing(List<Vector3d> vertices, List<Integer> indices, LinearRing r) {
		if (indices.size() % 3 != 0) {
			throw new IllegalArgumentException("Number of indices is not a multiple of 3");
		}
		triangles = new ArrayList<>();
		for (int i = 0; i < indices.size(); i = i + 3) {
			Vector3d v1 = vertices.get(indices.get(i + 0));
			Vector3d v2 = vertices.get(indices.get(i + 1));
			Vector3d v3 = vertices.get(indices.get(i + 2));
			triangles.add(new Triangle3d(v1, v2, v3));
		}
		this.ring = r;
	}

	public List<Triangle3d> getTriangles() {
		return triangles;
	}

	/**
	 * Getter method for ring
	 * 
	 * @return the ring
	 */
	public LinearRing getRing() {
		return ring;
	}

}
