protected static Mesh getMesh() { final Mesh m = new NaiveDoubleMesh(); // To prevent duplicates, map each (x, y, z) triple to its own index. final Map<Vector3D, Long> indexMap = new HashMap<>(); final LongArray indices = new LongArray(); try { Files.lines(Paths.get(AbstractFeatureTest.class.getResource("3d_geometric_features_mesh.txt").toURI())) .forEach(l -> { String[] coord = l.split(" "); final double x = Double.parseDouble(coord[0]); final double y = Double.parseDouble(coord[1]); final double z = Double.parseDouble(coord[2]); final Vector3D vertex = new Vector3D(x, y, z); final long vIndex = indexMap.computeIfAbsent(vertex, // v -> m.vertices().add(x, y, z)); indices.add(vIndex); }); } catch (IOException | URISyntaxException exc) { exc.printStackTrace(); } for (int i = 0; i < indices.size(); i += 3) { final long v0 = indices.get(i); final long v1 = indices.get(i + 1); final long v2 = indices.get(i + 2); m.triangles().add(v0, v1, v2); } return m; }
/** Tests {@link LongArray#set(int, Long)}. */ @Test public void testSet() { final long[] raw = { 3, 5, 8, 13, 21 }; final LongArray array = new LongArray(raw.clone()); final Long e0 = 7L, e2 = 1L, e4 = 2L; array.set(0, e0); array.set(2, e2); array.set(4, e4); assertEquals(raw.length, array.size()); assertEquals(e0, array.get(0)); assertEquals(raw[1], array.getValue(1)); assertEquals(e2, array.get(2)); assertEquals(raw[3], array.getValue(3)); assertEquals(e4, array.get(4)); }
/** Tests {@link LongArray#add(int, Long)}. */ @Test public void testAdd() { final long[] raw = { 3, 5, 8, 13, 21 }; final LongArray array = new LongArray(raw.clone()); final Long e6 = 1L, e7 = 2L; array.add(e6); array.add(e7); assertEquals(raw.length + 2, array.size()); for (int i = 0; i < raw.length; i++) { assertEquals("@" + i, raw[i], array.getValue(i)); } assertEquals(e6, array.get(5)); assertEquals(e7, array.get(6)); }
/** Tests {@link LongArray#get(int)}. */ @Test public void testGet() { final long[] raw = { 3, 5, 8, 13, 21 }; final LongArray array = new LongArray(raw.clone()); for (int i = 0; i < raw.length; i++) { assertEquals("@" + i, raw[i], array.get(i).longValue()); } }