]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java
Fix cause of endless loop in overlap resolution
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / controlpoint / PipingRules.java
index 33c832f1b8c4bec41cc22d5c0d1dec791f6f8968..2c77c2bfbc9f24f1b9bb5fe89ca37dcb3ca894c1 100644 (file)
@@ -759,7 +759,7 @@ public class PipingRules {
                        continue;
                    double curr = gapObj.d;
                    int d = 1;
-                   while (curr < -MIN_INLINE_LENGTH) {
+                   while (d < gaps.size() && curr < -MIN_INLINE_LENGTH) {
                        GapObj next = i+d >= 0 ? gaps.get(i+d) : null;
                     GapObj prev = i-d >= 0 ? gaps.get(i-d) : null;
                        if (next != null && next.gap == Gap.SPACE) {
@@ -778,12 +778,12 @@ public class PipingRules {
                                pcp.first.setWorldPosition(p);
                            }
                        }
-                       if (curr < -MIN_INLINE_LENGTH && prev != null && prev.gap == Gap.SPACE) {
+                       else if (prev != null && prev.gap == Gap.SPACE) {
                            double move = Math.min(-curr, prev.d);
                         curr+= move;
-                        next.d -= move;
-                        if (next.d < MIN_INLINE_LENGTH)
-                            next.gap = Gap.ATTACHED;
+                        prev.d -= move;
+                        if (prev.d < MIN_INLINE_LENGTH)
+                            prev.gap = Gap.ATTACHED;
                         Vector3d mv = new Vector3d(dir);
                         mv.normalize();
                         mv.scale(-move);
@@ -794,6 +794,9 @@ public class PipingRules {
                             pcp.first.setWorldPosition(p);
                         }
                        }
+                       else {
+                           d++;
+                       }
                    }
                }
            } else {
@@ -1901,7 +1904,7 @@ public class PipingRules {
                                return Math.PI; // FIXME : argh
                        }
                        
-                       Quat4d q = PipeControlPoint.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
+                       Quat4d q = tcp.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
                        Vector3d v = new Vector3d();
                        MathTools.rotate(q, MathTools.Y_AXIS,v);
                        tcp.setTurnAxis(v);