Skip to content
Permalink
Browse files
GEOMETRY-106 - Refine Module
  • Loading branch information
arturobernalg committed Dec 8, 2020
1 parent cdc4e74 commit 4573154a284c0e64b1a76d527b3c546696cfc5d0
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 231 deletions.
@@ -808,7 +808,7 @@ private static final class PlaneRegionExtruder {
this.basePlane = basePlane;

// Extruded plane; this forms the end of the 3D region opposite the base plane.
EmbeddingPlane extrudedPlane = basePlane.translate(extrusionVector);
final EmbeddingPlane extrudedPlane = basePlane.translate(extrusionVector);

if (basePlane.contains(extrudedPlane)) {
throw new IllegalArgumentException(
@@ -678,7 +678,7 @@ private int addToVertexIndexMap(final Vector3D vertex, final int targetIdx, fina
final Integer actualIdx = map.putIfAbsent(vertex, targetIdx);

return actualIdx != null ?
actualIdx.intValue() :
actualIdx :
targetIdx;
}

@@ -38,7 +38,7 @@ public BoundarySource3D read(final String type, final File in, final DoublePreci
try (InputStream is = Files.newInputStream(in.toPath())) {
return readInternal(type, is, precision);
}
} catch (IOException exc) {
} catch (final IOException exc) {
throw createUnchecked(exc);
}
}
@@ -49,7 +49,7 @@ public BoundarySource3D read(final String type, final InputStream in, final Doub
ensureTypeSupported(type);
try {
return readInternal(type, in, precision);
} catch (IOException exc) {
} catch (final IOException exc) {
throw createUnchecked(exc);
}
}
@@ -62,18 +62,18 @@ public void write(final BoundarySource3D model, final String type, final File ou
try (OutputStream os = Files.newOutputStream(out.toPath())) {
writeInternal(model, type, os);
}
} catch (IOException exc) {
} catch (final IOException exc) {
throw createUnchecked(exc);
}
}

/** {@inheritDoc} */
@Override
public void write(final BoundarySource3D model, final String type, OutputStream out) {
public void write(final BoundarySource3D model, final String type, final OutputStream out) {
ensureTypeSupported(type);
try {
writeInternal(model, type, out);
} catch (IOException exc) {
} catch (final IOException exc) {
throw createUnchecked(exc);
}
}
@@ -43,7 +43,7 @@ public class DefaultModelIOHandlerRegistryTest {
@Test
public void testDefaultHandlers() {
// act
List<ModelIOHandler> handlers = registry.getHandlers();
final List<ModelIOHandler> handlers = registry.getHandlers();

// assert
Assertions.assertEquals(1, handlers.size());
@@ -62,23 +62,23 @@ public void testReadWrite_supportedTypes() {
checkWriteRead("obj");
}

private void checkWriteRead(String type) {
private void checkWriteRead(final String type) {
// arrange
BoundarySource3D model = BoundarySource3D.from(
final BoundarySource3D model = BoundarySource3D.from(
Planes.triangleFromVertices(Vector3D.ZERO, Vector3D.of(1, 0, 0), Vector3D.of(0, 1, 0), TEST_PRECISION)
);

ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream out = new ByteArrayOutputStream();

// act
registry.write(model, type, out);
BoundarySource3D result = registry.read(type, new ByteArrayInputStream(out.toByteArray()), TEST_PRECISION);
final BoundarySource3D result = registry.read(type, new ByteArrayInputStream(out.toByteArray()), TEST_PRECISION);

// assert
List<Triangle3D> tris = result.triangleStream().collect(Collectors.toList());
final List<Triangle3D> tris = result.triangleStream().collect(Collectors.toList());
Assertions.assertEquals(1, tris.size());

Triangle3D tri = tris.get(0);
final Triangle3D tri = tris.get(0);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.ZERO, tri.getPoint1(), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.of(1, 0, 0), tri.getPoint2(), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.of(0, 1, 0), tri.getPoint3(), TEST_EPS);
@@ -47,16 +47,16 @@ public class ModelIOHandlerRegistryTest {
@Test
public void testGetSetHandlers() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

List<ModelIOHandler> handlers = Arrays.asList(handlerA, handlerB);
final List<ModelIOHandler> handlers = Arrays.asList(handlerA, handlerB);

// act
registry.setHandlers(handlers);

// assert
List<ModelIOHandler> resultHandlers = registry.getHandlers();
final List<ModelIOHandler> resultHandlers = registry.getHandlers();
Assertions.assertNotSame(handlers, resultHandlers);
Assertions.assertEquals(2, resultHandlers.size());

@@ -67,8 +67,8 @@ public void testGetSetHandlers() {
@Test
public void testSetHandlers_null() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

@@ -82,8 +82,8 @@ public void testSetHandlers_null() {
@Test
public void testGetHandlerForType() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

@@ -100,8 +100,8 @@ public void testGetHandlerForType() {
@Test
public void testHandlesType() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

@@ -118,15 +118,15 @@ public void testHandlesType() {
@Test
public void testRead_typeFromFileExtension() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

File file = new File("file.B");
final File file = new File("file.B");

// act
BoundarySource3D src = registry.read(file, TEST_PRECISION);
final BoundarySource3D src = registry.read(file, TEST_PRECISION);

// assert
Assertions.assertSame(SRC_B, src);
@@ -135,7 +135,7 @@ public void testRead_typeFromFileExtension() {
@Test
public void testRead_typeFromFileExtension_unknownType() {
// arrange
File file = new File("file.B");
final File file = new File("file.B");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -146,7 +146,7 @@ public void testRead_typeFromFileExtension_unknownType() {
@Test
public void testRead_typeFromFileExtension_noFileExtension() {
// arrange
File file = new File("file");
final File file = new File("file");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -158,13 +158,13 @@ public void testRead_typeFromFileExtension_noFileExtension() {
@Test
public void testRead_typeAndFile() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

// act
BoundarySource3D src = registry.read("a", new File("file"), TEST_PRECISION);
final BoundarySource3D src = registry.read("a", new File("file"), TEST_PRECISION);

// assert
Assertions.assertSame(SRC_A, src);
@@ -173,7 +173,7 @@ public void testRead_typeAndFile() {
@Test
public void testRead_typeAndFile_unknownType() {
// arrange
File file = new File("file");
final File file = new File("file");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -184,13 +184,13 @@ public void testRead_typeAndFile_unknownType() {
@Test
public void testRead_typeAndInputStream() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

// act
BoundarySource3D src = registry.read("a", new ByteArrayInputStream(new byte[0]), TEST_PRECISION);
final BoundarySource3D src = registry.read("a", new ByteArrayInputStream(new byte[0]), TEST_PRECISION);

// assert
Assertions.assertSame(SRC_A, src);
@@ -207,12 +207,12 @@ public void testRead_typeAndInputStream_unknownType() {
@Test
public void testWrite_typeFromFileExtension() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

File file = new File("file.B");
final File file = new File("file.B");

// act
registry.write(SRC_B, file);
@@ -225,7 +225,7 @@ public void testWrite_typeFromFileExtension() {
@Test
public void testWrite_typeFromFileExtension_unknownType() {
// arrange
File file = new File("file.B");
final File file = new File("file.B");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -236,7 +236,7 @@ public void testWrite_typeFromFileExtension_unknownType() {
@Test
public void testWrite_typeFromFileExtension_noFileExtension() {
// arrange
File file = new File("file");
final File file = new File("file");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -248,12 +248,12 @@ public void testWrite_typeFromFileExtension_noFileExtension() {
@Test
public void testWrite_typeAndFile() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

File file = new File("file.B");
final File file = new File("file.B");

// act
registry.write(SRC_B, "a", file);
@@ -266,7 +266,7 @@ public void testWrite_typeAndFile() {
@Test
public void testWrite_typeAndFile_unknownType() {
// arrange
File file = new File("file");
final File file = new File("file");

// act/assert
GeometryTestUtils.assertThrows(() -> {
@@ -277,8 +277,8 @@ public void testWrite_typeAndFile_unknownType() {
@Test
public void testWrite_typeAndOutputStream() {
// arrange
StubHandler handlerA = new StubHandler("a", SRC_A);
StubHandler handlerB = new StubHandler("b", SRC_B);
final StubHandler handlerA = new StubHandler("a", SRC_A);
final StubHandler handlerB = new StubHandler("b", SRC_B);

registry.setHandlers(Arrays.asList(handlerA, handlerB));

@@ -312,27 +312,27 @@ private static final class StubHandler implements ModelIOHandler {
}

@Override
public boolean handlesType(String type) {
public boolean handlesType(final String type) {
return this.handlerType.equals(type);
}

@Override
public BoundarySource3D read(String type, File in, DoublePrecisionContext precision) {
public BoundarySource3D read(final String type, final File in, final DoublePrecisionContext precision) {
return boundarySrc;
}

@Override
public BoundarySource3D read(String type, InputStream in, DoublePrecisionContext precision) {
public BoundarySource3D read(final String type, final InputStream in, final DoublePrecisionContext precision) {
return boundarySrc;
}

@Override
public void write(BoundarySource3D model, String type, File out) {
public void write(final BoundarySource3D model, final String type, final File out) {
outputBoundarySrc = model;
}

@Override
public void write(BoundarySource3D model, String type, OutputStream out) {
public void write(final BoundarySource3D model, final String type, final OutputStream out) {
outputBoundarySrc = model;
}
}
@@ -48,7 +48,7 @@ public class ModelIOTest {
@Test
public void testGetHandler() {
// act
ModelIOHandlerRegistry registry = ModelIO.getModelIOHandlerRegistry();
final ModelIOHandlerRegistry registry = ModelIO.getModelIOHandlerRegistry();

// assert
Assertions.assertTrue(registry instanceof DefaultModelIOHandlerRegistry);
@@ -60,7 +60,7 @@ public void testWriteRead_typeFromFileExtension() throws IOException {
// act/assert
checkWriteRead(model -> {
//File file = new File(tempFolder.getRoot(), "model.obj");
File file = new File(anotherTempDir, "model.obj");
final File file = new File(anotherTempDir, "model.obj");
ModelIO.write(model, file);
return ModelIO.read(file, TEST_PRECISION);
});
@@ -71,7 +71,7 @@ public void testWriteRead_typeAndFile() throws IOException {
// act/assert
checkWriteRead(model -> {
//File file = new File(tempFolder.getRoot(), "objmodel");
File file = new File(anotherTempDir, "objmodel");
final File file = new File(anotherTempDir, "objmodel");
ModelIO.write(model, "OBJ", file);
return ModelIO.read("obj", file, TEST_PRECISION);
});
@@ -82,7 +82,7 @@ public void testWriteRead_typeAndStream() throws IOException {
// act/assert
checkWriteRead(model -> {
//File file = new File(tempFolder.getRoot(), "objmodel");
File file = new File(anotherTempDir, "objmodel");
final File file = new File(anotherTempDir, "objmodel");
try (OutputStream out = Files.newOutputStream(file.toPath())) {
ModelIO.write(model, "OBJ", out);
}
@@ -98,20 +98,20 @@ private interface ModelIOFunction {
BoundarySource3D apply(BoundarySource3D model) throws IOException;
}

private void checkWriteRead(ModelIOFunction fn) throws IOException {
private void checkWriteRead(final ModelIOFunction fn) throws IOException {
// arrange
BoundarySource3D model = BoundarySource3D.from(
final BoundarySource3D model = BoundarySource3D.from(
Planes.triangleFromVertices(Vector3D.ZERO, Vector3D.of(1, 0, 0), Vector3D.of(0, 1, 0), TEST_PRECISION)
);

// act
BoundarySource3D result = fn.apply(model);
final BoundarySource3D result = fn.apply(model);

// assert
List<Triangle3D> tris = result.triangleStream().collect(Collectors.toList());
final List<Triangle3D> tris = result.triangleStream().collect(Collectors.toList());
Assertions.assertEquals(1, tris.size());

Triangle3D tri = tris.get(0);
final Triangle3D tri = tris.get(0);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.ZERO, tri.getPoint1(), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.of(1, 0, 0), tri.getPoint2(), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector3D.of(0, 1, 0), tri.getPoint3(), TEST_EPS);

0 comments on commit 4573154

Please sign in to comment.