Skip to content
Permalink
Browse files
GEOMETRY-63: throwing NoSuchElementException in SimpleTriangleMesh Fa…
…ce iterator
  • Loading branch information
darkma773r committed Jul 3, 2020
1 parent 452e5ba commit d951410cba41f5ea5eadbdd9fb4d7a84c4074a4d
Showing 2 changed files with 33 additions and 2 deletions.
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.Function;
@@ -398,8 +399,11 @@ public boolean hasNext() {
/** {@inheritDoc} */
@Override
public T next() {
final Face face = getFace(index++);
return fn.apply(face);
if (hasNext()) {
final Face face = getFace(index++);
return fn.apply(face);
}
throw new NoSuchElementException();
}
}

@@ -19,7 +19,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@@ -250,6 +252,31 @@ public void testFaces_iterable() {
Assert.assertTrue(f2.definesPolygon());
}

@Test
public void testFaces_iterator() {
// arrange
final List<Vector3D> vertices = Arrays.asList(
Vector3D.ZERO,
Vector3D.of(1, 0, 0),
Vector3D.of(0, 1, 0)
);

final List<int[]> faceIndices = Arrays.asList(
new int[] {0, 1, 2}
);

final SimpleTriangleMesh mesh = SimpleTriangleMesh.from(vertices, faceIndices, TEST_PRECISION);

// act/assert
final Iterator<TriangleMesh.Face> it = mesh.faces().iterator();

Assert.assertTrue(it.hasNext());
Assert.assertEquals(0, it.next().getIndex());
Assert.assertFalse(it.hasNext());

GeometryTestUtils.assertThrows(() -> it.next(), NoSuchElementException.class);
}

@Test
public void testTriangleStream() {
// arrange

0 comments on commit d951410

Please sign in to comment.