/*
 * Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package net.runelite.api;

import java.util.ArrayList;
import java.util.List;
import net.runelite.api.model.Triangle;
import net.runelite.api.model.Vertex;

public class Model
{
	private final net.runelite.rs.api.Model model;

	public Model(net.runelite.rs.api.Model model)
	{
		this.model = model;
	}

	public List<Triangle> getTriangles()
	{
		int[] verticiesX = model.getVerticesX();
		int[] verticiesY = model.getVerticesY();
		int[] verticiesZ = model.getVerticesZ();

		int[] trianglesX = model.getTrianglesX();
		int[] trianglesY = model.getTrianglesY();
		int[] trianglesZ = model.getTrianglesZ();

		assert trianglesX.length == trianglesY.length;
		assert trianglesY.length == trianglesZ.length;

		List<Triangle> triangles = new ArrayList<>(trianglesX.length);

		for (int i = 0; i < trianglesX.length; ++i)
		{
			int triangleX = trianglesX[i];
			int triangleY = trianglesY[i];
			int triangleZ = trianglesZ[i];

			Vertex x = new Vertex(
				verticiesX[triangleX],
				verticiesY[triangleX],
				verticiesZ[triangleX]
			);

			Vertex y = new Vertex(
				verticiesX[triangleY],
				verticiesY[triangleY],
				verticiesZ[triangleY]
			);

			Vertex z = new Vertex(
				verticiesX[triangleZ],
				verticiesY[triangleZ],
				verticiesZ[triangleZ]
			);

			Triangle triangle = new Triangle(x, y, z);
			triangles.add(triangle);
		}

		return triangles;
	}
}

@@ -1698,28 +1698,26 @@
 ist%3C
-Triangle%3E getTriangl
+Vertex%3E getVertici
 es()
@@ -1850,16 +1850,391 @@
 esZ();%0A%0A
+%09%09assert verticiesX.length == verticiesY.length;%0A%09%09assert verticiesY.length == verticiesZ.length;%0A%0A%09%09List%3CVertex%3E verticies = new ArrayList%3C%3E();%0A%0A%09%09for (int i = 0; i %3C verticiesX.length; ++i)%0A%09%09%7B%0A%09%09%09Vertex v = new Vertex(%0A%09%09%09%09verticiesX%5Bi%5D,%0A%09%09%09%09verticiesY%5Bi%5D,%0A%09%09%09%09verticiesZ%5Bi%5D%0A%09%09%09);%0A%09%09%09verticies.add(v);%0A%09%09%7D%0A%0A%09%09return verticies;%0A%09%7D%0A%0A%09public List%3CTriangle%3E getTriangles()%0A%09%7B%0A
 %09%09int%5B%5D 
@@ -2453,24 +2453,67 @@
 sZ.length;%0A%0A
+%09%09List%3CVertex%3E verticies = getVerticies();%0A
 %09%09List%3CTrian
@@ -2726,170 +2726,41 @@
 %0A%09%09%09
-Vertex x = new Vertex(%0A%09%09%09%09verticiesX%5BtriangleX%5D,%0A%09%09%09%09verticiesY%5BtriangleX%5D,%0A%09%09%09%09verticiesZ%5BtriangleX%5D%0A%09%09%09);%0A%0A%09%09%09Vertex y = new Vertex(%0A%09%09%09%09verticiesX%5Bt
+Triangle triangle = new T
 riangle
-Y%5D,
+(
 %0A%09%09%09
@@ -2769,26 +2769,29 @@
 erticies
-Y%5B
+.get(
 triangle
 Y%5D,%0A%09%09%09%09
@@ -2782,18 +2782,18 @@
 triangle
-Y%5D
+X)
 ,%0A%09%09%09%09ve
@@ -2803,77 +2803,21 @@
 cies
-Z%5BtriangleY%5D%0A%09%09%09);%0A%0A%09%09%09Vertex z = new Vertex(%0A%09%09%09%09verticiesX%5B
+.get(
 triangle
 Z%5D,%0A
@@ -2804,34 +2804,34 @@
 ies.get(triangle
-Z%5D
+Y)
 ,%0A%09%09%09%09verticiesY
@@ -2833,98 +2833,27 @@
 cies
-Y%5BtriangleZ%5D,%0A%09%09%09%09verticiesZ%5BtriangleZ%5D%0A%09%09%09);%0A%0A%09%09%09Triangle triangle = new Triangle(x, y, z
+.get(triangleZ)%0A%09%09%09
 );%0A%09

split getTriangles into getVerticies and getTriangles