/**
 * 
 */
package ca.eandb.jmist.framework.geometry.mesh;

import java.util.Iterator;

import ca.eandb.jmist.framework.BoundingBoxBuilder3;
import ca.eandb.jmist.math.Box3;
import ca.eandb.jmist.math.Point3;
import ca.eandb.jmist.math.Sphere;

/**
 * @author bwkimmel
 *
 */
public final class MeshUtil {
  
  private MeshUtil() {}
  
  public static Mesh triangulate(Mesh mesh) {
    return mesh.getMaxFaceVertexCount() == 3
        ? mesh : new TriangulatedMesh(mesh);
  }
  
  public static Sphere getBoundingSphere(Mesh mesh) {
    return getBoundingSphere(mesh.getVertices());
  }
  
  public static Sphere getBoundingSphere(Mesh.Face face) {
    return getBoundingSphere(face.getVertices());
  }
  
  private static Sphere getBoundingSphere(final Iterable<Mesh.Vertex> vertices) {
    return Sphere.smallestContaining(new Iterable<Point3>() {
      @Override
      public Iterator<Point3> iterator() {
        return new Iterator<Point3>() {
          Iterator<Mesh.Vertex> inner = vertices.iterator(); 

          @Override
          public boolean hasNext() {
            return inner.hasNext();
          }

          @Override
          public Point3 next() {
            return inner.next().getPosition();
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException();
          }
        };
      }
    });
  }

  public static Box3 getBoundingBox(Mesh mesh) {
    return getBoundingBox(mesh.getVertices());
  }
  
  public static Box3 getBoundingBox(Mesh.Face face) {
    return getBoundingBox(face.getVertices());
  }

  private static Box3 getBoundingBox(Iterable<Mesh.Vertex> vertices) {
    BoundingBoxBuilder3 builder = new BoundingBoxBuilder3();
    for (Mesh.Vertex vertex : vertices) {
      builder.add(vertex.getPosition());
    }
    return builder.getBoundingBox();
  }

}

@@ -71,24 +71,151 @@
 va.util.
-Iterator
+Collection;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.StreamSupport
 ;%0A%0Aimpor
@@ -869,22 +869,16 @@
 gSphere(
-final 
 Iterable
@@ -944,172 +944,43 @@
 ing(
-new Iterable%3CPoint3%3E() %7B%0A      @Override%0A      public Iterator%3CPoint3%3E iterator() %7B%0A        return new Iterator%3CPoint3%3E() %7B%0A          Iterator%3CMesh.Vertex%3E inner = 
+() -%3E%0A        StreamSupport.stream(
 vert
@@ -984,16 +984,19 @@
 ertices.
+spl
 iterator
@@ -1001,375 +1001,79 @@
 or()
-; %0A%0A          @Override%0A          public boolean hasNext() %7B%0A            return inner.hasNext();%0A          %7D%0A%0A          @Override%0A          public Point3 next() %7B%0A            return inner.next().getPosition();%0A          %7D%0A%0A          @Override%0A          public void remove() %7B%0A            throw new UnsupportedOperationException();%0A          %7D%0A        %7D;%0A      %7D%0A    %7D
+, false)%0A            .map(v -%3E v.getPosition())%0A            .iterator()
 );%0A 

Use lambdas for MeshUtil.getBoundingSphere