diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..adc3c9ea --- /dev/null +++ b/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + com.github.miho + JCSG + master-SNAPSHOT + + + + + eu.mihosoft.vvecmath + vvecmath + 0.3.8 + + + org.slf4j + slf4j-simple + 1.6.1 + + + + junit + junit + 4.12 + test + + + + + + + jitpack.io + https://jitpack.io + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + 1.8 + 1.8 + + + + + diff --git a/src/main/java/eu/mihosoft/jcsg/Plane.java b/src/main/java/eu/mihosoft/jcsg/Plane.java index 37f1407c..cf1d6c7b 100644 --- a/src/main/java/eu/mihosoft/jcsg/Plane.java +++ b/src/main/java/eu/mihosoft/jcsg/Plane.java @@ -147,6 +147,12 @@ public void splitPolygon( types.add(type); } + // fix for stackoverflow + if (this.normal.equals(polygon._csg_plane.normal) && polygonType!=SPANNING && polygonType!=COPLANAR) { + System.out.println("our plane is not spanning and not coplannar but it should be " + this.normal.dot(polygon._csg_plane.normal)); + polygonType=COPLANAR; + } + //System.out.println("> switching"); // Put the polygon in the correct list, splitting it when necessary. switch (polygonType) { diff --git a/src/test/java/eu/mihosoft/jcsg/AppleTest.java b/src/test/java/eu/mihosoft/jcsg/AppleTest.java new file mode 100644 index 00000000..1bd49b0a --- /dev/null +++ b/src/test/java/eu/mihosoft/jcsg/AppleTest.java @@ -0,0 +1,69 @@ +package eu.mihosoft.jcsg; + +import java.io.IOException; +import java.nio.file.Paths; + +import org.junit.After; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.mihosoft.jcsg.CSG; +import eu.mihosoft.jcsg.Cube; +import eu.mihosoft.jcsg.STL; +import eu.mihosoft.vvecmath.Transform; +import eu.mihosoft.vvecmath.Vector3d; + +public class AppleTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(AppleTest.class); + + String originalFilename = "src/test/resources/Apple.stl"; + + @After + public void tearDown() throws Exception {} + + @Test + public void test() throws IOException { + CSG apple = STL.file(Paths.get(originalFilename)).optimization(CSG.OptType.POLYGON_BOUND); + + // center model around zero point + + double xDim = apple.getBounds().getMax().getX()-apple.getBounds().getMin().getX(); + double yDim = apple.getBounds().getMax().getY()-apple.getBounds().getMin().getY(); + double zDim = apple.getBounds().getMax().getZ()-apple.getBounds().getMin().getZ(); + + Vector3d moveToCenterVector = Vector3d.xyz(xDim/2-apple.getBounds().getMax().getX(), yDim/2-apple.getBounds().getMax().getY(), zDim/2-apple.getBounds().getMax().getZ()); + + LOGGER.info("center=" + apple.getBounds().getCenter().getX() + ":" + + apple.getBounds().getCenter().getY() + ":" + + apple.getBounds().getCenter().getZ()); + + LOGGER.info("max=" + apple.getBounds().getMax().getX() + ":" + + apple.getBounds().getMax().getY() + ":" + + apple.getBounds().getMax().getZ()); + + LOGGER.info("min=" + apple.getBounds().getMin().getX() + ":" + + apple.getBounds().getMin().getY() + ":" + + apple.getBounds().getMin().getZ()); + + apple = apple + .transformed(Transform.unity() + .translate(moveToCenterVector) + ); + + Vector3d max = apple.getBounds().getMax(); + Vector3d min = apple.getBounds().getMin(); + + double cubeMaxDimension = Math.max(Math.max(Math.max(max.x(), Math.abs(min.x())),Math.max(max.y(), Math.abs(min.y()))),Math.max(max.z(), Math.abs(min.z()))) ; + cubeMaxDimension+=1; + + CSG cube = new Cube(cubeMaxDimension*2).toCSG(). + transformed(Transform.unity(). + translateZ(cubeMaxDimension)); + + CSG diff = apple.difference(cube); + + } + +} diff --git a/src/test/resources/Apple.stl b/src/test/resources/Apple.stl new file mode 100644 index 00000000..fd385a58 Binary files /dev/null and b/src/test/resources/Apple.stl differ