]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Check parameter inputs in geometry providers. 32/3032/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 18 Jul 2019 14:50:36 +0000 (17:50 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 18 Jul 2019 14:50:36 +0000 (17:50 +0300)
gitlab #15

Change-Id: Ib891e910c7a78d1d4f9e6ff8ca1bad137e3ff95d

org.simantics.plant3d/src/org/simantics/plant3d/geometry/BallValveGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/CapGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/CheckValveGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/ElbowGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/HorizontalTankGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/NozzleGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/VerticalTankGeometryProvider.java

index b0da882a29ca6f6358bf0ed0c0d9fefe18771647..c58ce987b7841c456578206927f96b02fdb96aa7 100644 (file)
@@ -19,6 +19,8 @@ public class BallValveGeometryProvider extends BuiltinGeometryProvider {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (radius < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {-radius*2, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*4);
                TopoDS_Shape sph = OccTriangulator.makeSphere(0, 0, 0, radius*1.5);
                TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[]{cyl, sph});
index 4161d941a33615d9f15f1444ce16fa0419613a42..80e3bb2ce131c268a8687c1b658420a70f52c9ac 100644 (file)
@@ -27,8 +27,9 @@ public class CapGeometryProvider extends BuiltinGeometryProvider {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
-//             TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {0.0, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.25);
-//             return Collections.singletonList(cyl);
+               if (radius < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
+
                double length = radius * 0.5;
                double p0[] = new double[]{    length,        0.0,0.0};
                double p1[] = new double[]{length*0.8, radius*0.6,0.0};
index 5106731647a34da576e1a4846b29648210ea1348..c14ff4b477fe1511cf3f8abeea5e186ccb7c3028 100644 (file)
@@ -19,6 +19,8 @@ public class CheckValveGeometryProvider extends BuiltinGeometryProvider {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (radius < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                double l = radius*0.2;
                TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {radius-l, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, l);
                TopoDS_Shape con = OccTriangulator.makeCone(new double[] {-radius, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.1,radius*2);
index ead9f0f52292a0e9d00aa5d3e2f0cdfa8403dde7..70463979c56041af1673d92624ff622b51394afe 100644 (file)
@@ -27,6 +27,8 @@ public class ElbowGeometryProvider extends BuiltinMeshProvider {
        
 //     @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (radius < MathTools.NEAR_ZERO || turnRadius < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                double t = Math.tan((Math.PI - turnAngle) * 0.5);
                double R = 0.0;
                if (t > MathTools.NEAR_ZERO)
@@ -38,6 +40,8 @@ public class ElbowGeometryProvider extends BuiltinMeshProvider {
        
 //     @Override
        public Mesh getMesh() {
+               if (radius < MathTools.NEAR_ZERO || turnRadius < MathTools.NEAR_ZERO)
+                       return null;
                double t = Math.tan((Math.PI - turnAngle) * 0.5);
                double R = 0.0;
                if (t > MathTools.NEAR_ZERO)
index 90c39363cded7860fad4ce0c5642b8f91c8c9f78..3ab958898aaace972e6197dbdd78edd29996cf33 100644 (file)
@@ -19,7 +19,8 @@ public class GateValveGeometryProvider extends BuiltinGeometryProvider {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
-               
+               if (radius < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                TopoDS_Shape con = OccTriangulator.makeCone(new double[] {-radius, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.1,radius);
                TopoDS_Shape con2 = OccTriangulator.makeCone(new double[] {radius, 0.0, 0.0}, new double[] { -1.0, 0.0, 0.0 }, radius, radius*0.1,radius);
                //TopoDS_Shape sph = OccTriangulator.makeSphere(0, 0, 0, radius*0.75);
index c6d4201597ad9e8c74e9b8af5fd83a9d57ae3a5c..1b68ce75def643197799803e360af542fa69bb39 100644 (file)
@@ -15,6 +15,7 @@ import org.jcae.opencascade.jni.TopoDS_Face;
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.jcae.opencascade.jni.TopoDS_Wire;
 import org.simantics.db.Resource;
+import org.simantics.g3d.math.MathTools;
 import org.simantics.opencascade.OccTriangulator;
 
 public class HorizontalTankGeometryProvider extends BuiltinGeometryProvider  {
@@ -28,7 +29,8 @@ public class HorizontalTankGeometryProvider extends BuiltinGeometryProvider  {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
-               
+               if (radius < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                double p0[] = new double[]{ length*0.50,        0.0,0.0};
                double p1[] = new double[]{ length*0.488, radius*0.6,0.0};
                double p2[] = new double[]{ length*0.46,     radius,0.0};
index cdfe73ccd4bcd1ab31ea829e3f0e86bdcba87e8d..0b0f4884a1554a9fe45bca11123530aa888973d9 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Map;
 
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.simantics.db.Resource;
+import org.simantics.g3d.math.MathTools;
 import org.simantics.opencascade.OccTriangulator;
 
 public class NozzleGeometryProvider extends BuiltinGeometryProvider  {
@@ -19,6 +20,8 @@ public class NozzleGeometryProvider extends BuiltinGeometryProvider  {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (radius < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
                TopoDS_Shape shape2 = OccTriangulator.makeCylinder(new double[] {-length*0.25, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius*1.2, length*0.25);
                TopoDS_Shape shape3 = OccTriangulator.makeCompound(new TopoDS_Shape[]{shape,shape2});
index 29a6869f74334ad8b1a8ca5e69595536e2c6e595..451abe1e1da5251bb096caefca8a9efea5cc58c1 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Map;
 
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.simantics.db.Resource;
+import org.simantics.g3d.math.MathTools;
 import org.simantics.opencascade.OccTriangulator;
 
 public class PumpGeometryProvider extends BuiltinGeometryProvider  {
@@ -19,6 +20,8 @@ public class PumpGeometryProvider extends BuiltinGeometryProvider  {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (width < MathTools.NEAR_ZERO || length < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                double h = width * 0.5;
                double h2 = width * 0.1;
                double ld2 = length * 0.5;
index 5ca0330dd34d0c38e12c248af81e7902d4d1605b..8697fe1447a32f67b0802c24c6f736edab9c40de 100644 (file)
@@ -30,9 +30,8 @@ public class ReducerGeometryProvider extends BuiltinMeshProvider  {
        
 //     @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
-//             GP_Circ circ = new GP_Circ(new double[]{-length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius);
-//             GP_Circ circ2 = new GP_Circ(new double[]{length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius2);
-//             System.out.println("Reducer " + length  + " " + radius + " " + radius2);
+               if (radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
                TopoDS_Shape shape;
                if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) {
@@ -46,7 +45,7 @@ public class ReducerGeometryProvider extends BuiltinMeshProvider  {
        @Override
        public Mesh getMesh() {
                double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
-               if (length < .0001)
+               if (length < .0001 || radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO)
                        return null;
                Tube tube = new Tube();
                tube.setResolution(16);
index 6879b2238628ff2c759912d5d1a891972b03f31f..c7df71a1ea3d2f3f6281ee5af576c5bdabc5942c 100644 (file)
@@ -32,7 +32,7 @@ public class StraightGeometryProvider extends BuiltinMeshProvider {
        
        @Override
        public Mesh getMesh() {
-               if (length < .001)
+               if (length < .001 || radius < MathTools.NEAR_ZERO )
                        return null;
                Tube tube = new Tube();
                tube.setResolution(16);
index 5cb078e0714511a78999020bb49c051fe9d2cc12..c29b3bcac7666886751dbb3c29c79fd1e3ac3fe9 100644 (file)
@@ -15,6 +15,7 @@ import org.jcae.opencascade.jni.TopoDS_Face;
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.jcae.opencascade.jni.TopoDS_Wire;
 import org.simantics.db.Resource;
+import org.simantics.g3d.math.MathTools;
 
 public class VerticalTankGeometryProvider extends BuiltinGeometryProvider  {
        
@@ -27,6 +28,8 @@ public class VerticalTankGeometryProvider extends BuiltinGeometryProvider  {
        
        @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
+               if (radius < MathTools.NEAR_ZERO || height < MathTools.NEAR_ZERO)
+                       return Collections.emptyList();
                
                double p0[] = new double[]{       0.0,     height,0.0};
                double p1[] = new double[]{radius*0.6,height*0.98,0.0};