]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Fix direction calculations in addComponent() 93/3993/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 13 Mar 2020 09:48:45 +0000 (11:48 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Fri, 13 Mar 2020 09:48:45 +0000 (11:48 +0200)
Change direction returned by getDirection(PREVIOUS) so that it matches
the expectations of calling routines and is consistent with other
direction vector getters.

gitlab #110

Change-Id: I003d7c720f7643aedb5d545648bda1148cb96315

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index fdb413ee39316b1cbc0652a4e2360c0ceb105b39..124e54bb15761dc7451c63c5a9a4fd3af70335e5 100644 (file)
@@ -791,9 +791,15 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        }
        
        /**
-        * Returns direction vector. 
+        * Returns direction vector pointing towards an adjacent component for
+        * directed control points or turn control points with one open end. 
         * 
-        * For directed control points, always returns outwards pointing vector.
+        * Always returns an outwards pointing vector.
+        * 
+        * For any other type of component, the return value is null.
+        * 
+        * For turn components this only return a non-null value for the unconnected
+        * end of the component. 
         * 
         * @param direction
         * @return normalized vector, or null
@@ -837,6 +843,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                     Vector3d offset = new Vector3d();
                     MathTools.rotate(q2, v, offset);
                     MathTools.rotate(q, offset, dir);
+                    dir.negate();
                     dir.normalize();
                     return dir;
                 }
index 78f4166547b8740367cc3c18eaccb5523d0a3148..913fceb9178276045828d04d9546000e39b62dd2 100644 (file)
@@ -405,6 +405,8 @@ public class ComponentUtils {
                        sizeChange = ((InlineComponent)newComponent).isSizeChange();
                }
                
+               // Calculate component position and direction vectors
+               // 'dir' is a unit vector that represents the direction from 'component' to 'newComponent'
                if (toPcp.isInline()) {
                        switch (position) {
                        case NEXT: 
@@ -434,6 +436,7 @@ public class ComponentUtils {
                                break;
                        case PREVIOUS:
                                pos = new Vector3d(start);
+                               dir.negate();
                                break;
                        case SPLIT:
                                pos = new Vector3d(toPcp.getWorldPosition());
@@ -441,11 +444,9 @@ public class ComponentUtils {
                        default:
                                break;
                        }
-
                } else if (toPcp.isDirected()) {
-                       dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
-                       if (position == PositionType.PREVIOUS)
-                               dir.negate();
+                       // 'dir' always points out of a nozzle regardless of insertion direction
+                       dir = new Vector3d(toPcp.getDirectedControlPointDirection());
                        pos = new Vector3d(toPcp.getWorldPosition());
                } else if (toPcp.isTurn() && toPcp.asFixedAngle()) {
                        dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
@@ -497,7 +498,6 @@ public class ComponentUtils {
                 ((TurnComponent) newComponent).setRotationAngle(inst.rotationAngle);
                }
                
-               
                newComponent.updateParameters();
                
                Vector3d v = new Vector3d(dir);
@@ -516,12 +516,11 @@ public class ComponentUtils {
                } else {
                        v.scale(newComponent.getControlPoint().getInlineLength());
                }
+               
                switch (position) {
                case NEXT:
-                       pos.add(v);
-                       break;
                case PREVIOUS:
-                       pos.sub(v);
+                       pos.add(v);
                        break;
                case SPLIT:
                        break;