}
- @SuppressWarnings("unused")
+ private static boolean calculateDirectedOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
+ return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, true);
+ }
+
private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
- boolean hasOffsets = false;
- List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
- // Only start offset affects the calculation
- if (start.isOffset())
- offsets.add(start);
- for (PipeControlPoint icp : list) {
- if (icp.isOffset()) {
- offsets.add(icp);
- } else if (icp.isDualSub())
- ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
- }
+ return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, false);
+ }
+
+ private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset, boolean directed) {
+ List<PipeControlPoint> offsets = getOffsetPoints(start, list);
if (offsets.size() == 0) {
- dir.set(endPoint);
- dir.sub(startPoint);
- double l = dir.lengthSquared();
- if (l > MathTools.NEAR_ZERO)
- dir.scale(1.0/Math.sqrt(l));
- offset.set(0.0, 0.0, 0.0);
+ setZeroOffset(startPoint, endPoint, dir, offset);
return false;
} else {
Vector3d sp = new Vector3d(startPoint);
double l = dir.lengthSquared();
if (l > MathTools.NEAR_ZERO)
dir.scale(1.0/Math.sqrt(l));
+
int iter = 100;
while (iter >= 0) {
iter--;
Vector3d v = icp.getSizeChangeOffsetVector(dir);
offset.add(v);
}
+
+ if (directed)
+ break;
+
Point3d nep = new Point3d(endPoint);
nep.sub(offset);
if (nep.distance(ep) < 0.0000000001) {
break;
- }
+ }
+
ep = nep;
dir.set(ep);
dir.sub(sp);
if (l > MathTools.NEAR_ZERO)
dir.scale(1.0/Math.sqrt(l));
}
- hasOffsets = true;
+
+ if (DEBUG)
+ System.out.println("calcOffset s:"+ startPoint + " e:" + endPoint + " d:" + dir + " o:"+offset) ;
+
+ return true;
}
-
- if (DEBUG && hasOffsets)
- System.out.println("calcOffset s:"+ startPoint + " e:" + endPoint + " d:" + dir + " o:"+offset) ;
- return hasOffsets;
}
+ public static void setZeroOffset(Vector3d startPoint, Vector3d endPoint, Vector3d dir, Vector3d offset) {
+ dir.set(endPoint);
+ dir.sub(startPoint);
+ double l = dir.lengthSquared();
+ if (l > MathTools.NEAR_ZERO)
+ dir.scale(1.0/Math.sqrt(l));
+ offset.set(0.0, 0.0, 0.0);
+ }
+
+ public static List<PipeControlPoint> getOffsetPoints(PipeControlPoint start, ArrayList<PipeControlPoint> list) {
+ List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
+ // Only start offset affects the calculation
+ if (start.isOffset())
+ offsets.add(start);
+ for (PipeControlPoint icp : list) {
+ if (icp.isOffset()) {
+ offsets.add(icp);
+ } else if (icp.isDualSub())
+ ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
+ }
+ return offsets;
+ }
+
private static UpdateStruct2 createUS(PipeControlPoint start, Direction direction, int iter, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) {
ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
PipeControlPoint end = null;
//if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
// processPathLeg(u, true, false);
checkExpandPathLeg(u, lengthChange, inlineEnd || u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle());
-
} else {
if (u.iter > 0) {
backIter(u);
if (canMoveOther) {
if (DEBUG)
System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + closest);
+
+ // Not aligned - we need to recalculate the offset to reflect new end points.
+ Vector3d offset;
+ if (u.hasOffsets) {
+ offset = new Vector3d();
+ Vector3d newDir = new Vector3d();
+ calculateDirectedOffset(position, closest, u.start, u.list, u.end, newDir, offset);
+ closest.add(offset);
+ } else {
+ offset = new Vector3d();
+ }
+
other.setWorldPosition(closest);
+
if (dcpStart) {
- ppNoOffset(new UpdateStruct2(u.start, u.startPoint, u.list, u.end, new Vector3d(closest), directedDirection, null, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated),true);
+ checkExpandPathLeg(new UpdateStruct2(u.start, u.startPoint, u.list, u.end, new Vector3d(closest), directedDirection, offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), PathLegUpdateType.NONE, true);
if (u.end.getNext() != null)
updatePathLegNext(u.end, u.updated, PathLegUpdateType.NEXT);
} else {
- ppNoOffset(new UpdateStruct2(u.start, new Vector3d(closest), u.list, u.end, u.endPoint, directedDirection, null, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated),true);
+ checkExpandPathLeg(new UpdateStruct2(u.start, new Vector3d(closest), u.list, u.end, u.endPoint, directedDirection, offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), PathLegUpdateType.NONE, true);
if (u.start.getPrevious() != null)
updatePathLegPrev(u.start, u.updated, PathLegUpdateType.PREV);
}