pathLegPoints.add(u.end);
// TODO : values can be cached in the loop
- for (int i = 1; i < pathLegPoints.size(); i++) {
+ for (int i = 0; i < pathLegPoints.size(); i++) {
PipeControlPoint icp = pathLegPoints.get(i);
- PipeControlPoint prev = pathLegPoints.get(i - 1);
-
+ PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
+ PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
if (icp.isVariableLength()) {
- if (i != pathLegPoints.size() - 1) {
- PipeControlPoint next = pathLegPoints.get(i + 1);
+ if (prev != null && next != null) {
+
recalcline = recalcline | updateVariableLength(icp, prev, next);
} else {
// the problem is that we want to keep unconnected end
// of the component in the same
// place, but center of the component must be moved.
- updateVariableLengthEnd(icp, prev);
+ updateVariableLengthEnd(icp, prev != null ? prev : next);
}
- } else if (!prev.isVariableLength()) {
+ } else if (prev != null && !prev.isVariableLength()) {
// If this and previous control point are not variable
// length pcps, we'll have to check if there is no empty
// space between them.
ep = new Vector3d(u.endPoint);
ep.sub(u.offset);
- for (int i = 1; i < pathLegPoints.size(); i++) {
+ for (int i = 0; i < pathLegPoints.size(); i++) {
PipeControlPoint icp = pathLegPoints.get(i);
- PipeControlPoint prev = pathLegPoints.get(i - 1);
- if (prev.isDualInline())
+ PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
+ PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
+
+ if (prev != null && prev.isDualInline())
prev = prev.getSubPoint().get(0);
if (icp.isVariableLength()) {
- if (i != pathLegPoints.size() - 1) {
- PipeControlPoint next;
- next = pathLegPoints.get(i + 1);
+ if (prev != null && next != null) {
recalcline = recalcline | updateVariableLength(icp, prev, next);
} else {
// the problem is that we want to keep unconnected end
// of the component in the same
// place, but center of the component must be moved.
- updateVariableLengthEnd(icp, prev);
+ updateVariableLengthEnd(icp, prev != null ? prev : next);
}
- } else if (!prev.isVariableLength()) {
+ } else if (prev != null && !prev.isVariableLength()) {
// If this and previous control point are not variable
// length pcps, we'll have to check if there is no empty
// space between them.
}
Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
+ if (directedDirection == null) {
+ updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
+ directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
+ if (directedDirection == null) {
+ return;
+ }
+ }
Point3d directedEndPoint = new Point3d(u.endPoint);
if (u.hasOffsets)
directedEndPoint.add(u.offset);
if (!tcp.isFixed()) {
if (next == null || prev == null)
- return Math.PI; // FIXME : argh
+ return tcp.getTurnAngle();
Vector3d middlePoint = tcp.getWorldPosition();
Vector3d nextPoint = next.getWorldPosition();
Vector3d prevPoint = prev.getWorldPosition();
return updateTurnControlPointTurn(tcp, middlePoint, prevPoint, nextPoint);
} else {
+ // Verify that fixed turn is properly defined.
+ // TODO : when reversed flag is changed, rotation angle should be recalculated, otherwise the orientation will change.
+ // TODO : should reverse flag toggle to be done already when we are removing defining side?
+ if (prev != null && next != null) {
+ // Nothing to do
+ } else if (prev == null) {
+ if (!tcp._getReversed())
+ tcp.setReversed(true);
+ } else if (next == null) {
+ if (tcp._getReversed())
+ tcp.setReversed(false);
+ }
+
Vector3d dir;
if (!tcp._getReversed()) {
if (prev == null)
Vector3d middlePoint = tcp.getWorldPosition();
Vector3d nextPoint = next.getWorldPosition();
dir = new Vector3d();
- dir.sub(nextPoint,middlePoint);
+ dir.sub(middlePoint, nextPoint);
}
dir.normalize();
}
}
+ if (current.isTurn() && current.isFixed()) {
+ current.setReversed(!current._getReversed());
+ }
+ if (current.isInline() && current.isReverse()) {
+ current.setReversed(!current._getReversed());
+ }
}
}