Require next and previous symmetric components be in line. Avoids having "next" and "previous" go off between pods

This commit is contained in:
JoePfeiffer 2023-01-03 18:46:53 -07:00
parent b3d2b92edd
commit da1130fd97

View File

@ -10,7 +10,7 @@ import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
/**
* Class for an axially symmetric rocket component generated by rotating
@ -621,7 +621,11 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
while (0 <= searchSiblingIndex) {
final RocketComponent searchSibling = searchParent.getChild(searchSiblingIndex);
if (searchSibling instanceof SymmetricComponent) {
return (SymmetricComponent) searchSibling;
SymmetricComponent candidate = (SymmetricComponent) searchSibling;
if (inline(candidate)) {
return candidate;
}
return null;
}
--searchSiblingIndex;
}
@ -658,9 +662,12 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
if(searchParent instanceof ComponentAssembly){
while (searchSiblingIndex < searchParent.getChildCount()) {
final RocketComponent searchSibling = searchParent.getChild(searchSiblingIndex);
if (searchSibling instanceof SymmetricComponent) {
return (SymmetricComponent) searchSibling;
SymmetricComponent candidate = (SymmetricComponent) searchSibling;
if (inline(candidate)) {
return candidate;
}
return null;
}
++searchSiblingIndex;
}
@ -671,6 +678,29 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
return null;
}
/***
* Determine whether a candidate symmetric component is in line with us
*
*/
private boolean inline(final SymmetricComponent candidate) {
// if we share a parent, we are in line
if (this.parent == candidate.parent)
return true;
// if both of our parents are either not ring instanceable, or
// have a radial offset of 0 from their centerline, we are in line.
if ((this.parent instanceof RingInstanceable) &&
(!MathUtil.equals(this.parent.getRadiusMethod().getRadius(this.parent.parent, this, this.parent.getRadiusOffset()), 0)))
return false;
if ((candidate.parent instanceof RingInstanceable) &&
(!MathUtil.equals(candidate.parent.getRadiusMethod().getRadius(candidate.parent.parent, candidate, candidate.parent.getRadiusOffset()), 0)))
return false;
return true;
}
/**
* Checks whether the component uses the previous symmetric component for its auto diameter.
*/