/** * Returns a fixed-size supplier backed by a portion of the given list starting with the first * element and specified by its length {@code numberOfVertices}. * * @param vertices the list by which the supplier will be backed. * @param numberOfVertices the portion's length. * @return the supplier. */ public static FrameVertex3DSupplier asFrameVertex3DSupplier(List<? extends FramePoint3DReadOnly> vertices, int numberOfVertices) { return asFrameVertex3DSupplier(vertices, 0, numberOfVertices); }
/** * Returns a fixed-size supplier backed by the given array. * * @param vertices the array by which the supplier will be backed. * @return the supplier. */ public static FrameVertex3DSupplier asFrameVertex3DSupplier(FramePoint3DReadOnly... vertices) { return asFrameVertex3DSupplier(Arrays.asList(vertices)); }
/** * Returns a fixed-size supplier backed by the given list. * * @param vertices the list by which the supplier will be backed. * @return the supplier. */ public static FrameVertex3DSupplier asFrameVertex3DSupplier(List<? extends FramePoint3DReadOnly> vertices) { return asFrameVertex3DSupplier(vertices, vertices.size()); }
/** * Returns a fixed-size supplier backed by a portion of the given array starting with the first * element and specified by its length {@code numberOfVertices}. * * @param vertices the array by which the supplier will be backed. * @param numberOfVertices the portion's length. * @return the supplier. */ public static FrameVertex3DSupplier asFrameVertex3DSupplier(FramePoint3DReadOnly[] vertices, int numberOfVertices) { return asFrameVertex3DSupplier(Arrays.asList(vertices), numberOfVertices); }
/** * Returns a fixed-size supplier backed by a portion of the given array specified by the first * index {@code startIndex} and the portion length {@code numberOfVertices}. * * @param vertices the array by which the supplier will be backed. * @param startIndex the first vertex index. * @param numberOfVertices the portion's length. * @return the supplier. */ public static FrameVertex3DSupplier asFrameVertex3DSupplier(FramePoint3DReadOnly[] vertices, int startIndex, int numberOfVertices) { if (numberOfVertices == 0) return emptyFrameVertex3DSupplier(); if (startIndex + numberOfVertices > vertices.length) throw new IllegalArgumentException("The array is too small. Array length = " + vertices.length + ", expected minimum length = " + (startIndex + numberOfVertices)); return asFrameVertex3DSupplier(Arrays.asList(vertices), startIndex, numberOfVertices); }
@Test public void testEquals() throws Exception { Random random = new Random(9017); for (int i = 0; i < ITERATIONS; i++) { int sizeA = random.nextInt(100) + 1; List<FramePoint3D> listA = IntStream.range(0, sizeA).mapToObj(v -> EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)) .collect(Collectors.toList()); List<FramePoint3D> listAPrime = listA.stream().map(FramePoint3D::new).collect(Collectors.toList()); List<FramePoint3D> listSizeA = IntStream.range(0, sizeA).mapToObj(v -> EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)) .collect(Collectors.toList()); int sizeB = random.nextInt(100) + 1; List<FramePoint3D> listB = IntStream.range(0, sizeB).mapToObj(v -> EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)) .collect(Collectors.toList()); assertTrue(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).equals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA))); assertTrue(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).equals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listAPrime))); assertFalse(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).equals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listSizeA))); assertFalse(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).equals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listB))); } }
FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).epsilonEquals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listA), epsilon)); assertTrue("Iteration: " + i, FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).epsilonEquals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listAPrime), epsilon)); assertFalse("Iteration: " + i, FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).epsilonEquals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listSizeA), epsilon)); assertFalse("Iteration: " + i, FrameVertex3DSupplier.asFrameVertex3DSupplier(listA).epsilonEquals(FrameVertex3DSupplier.asFrameVertex3DSupplier(listB), epsilon));
@Test public void testCreatingEmptySupplier() { FrameVertex3DSupplier expected = FrameVertex3DSupplier.emptyFrameVertex3DSupplier(); FrameVertex3DSupplier actual; actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(new FramePoint3DReadOnly[0], 0); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(new FramePoint3DReadOnly[0], 0, 0); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(Collections.emptyList()); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(Collections.emptyList(), 0); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); actual = FrameVertex3DSupplier.asFrameVertex3DSupplier(Collections.emptyList(), 0, 0); assertEquals(expected, actual); assertTrue(expected.epsilonEquals(actual, EPSILON)); }
original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original); original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original, numberOfVertices); original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original, startIndex, numberOfVertices); original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original.toArray(new FramePoint3DReadOnly[0])); original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original.toArray(new FramePoint3DReadOnly[0]), numberOfVertices); original.add(EuclidFrameRandomTools.nextFramePoint3D(random, worldFrame)); FrameVertex3DSupplier supplier = FrameVertex3DSupplier.asFrameVertex3DSupplier(original.toArray(new FramePoint3DReadOnly[0]), startIndex, numberOfVertices);
FramePoint3D[] framePoints = new FramePoint3D[]{p0, p1, p2, p3}; yoFrameConvexPolygon2d.set(FrameVertex3DSupplier.asFrameVertex3DSupplier(framePoints));