diff --git a/core/src/net/sf/openrocket/rocketcomponent/Configuration.java b/core/src/net/sf/openrocket/rocketcomponent/Configuration.java index e426df1d7..5fb2a52d4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Configuration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Configuration.java @@ -271,14 +271,12 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; for (RocketComponent component : this) { - for (Coordinate c : component.getComponentBounds()) { - for (Coordinate coord : component.toAbsolute(c)) { - cachedBounds.add(coord); - if (coord.x < minX) - minX = coord.x; - if (coord.x > maxX) - maxX = coord.x; - } + for (Coordinate coord : component.getComponentBounds()) { + cachedBounds.add(coord); + if (coord.x < minX) + minX = coord.x; + if (coord.x > maxX) + maxX = coord.x; } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 86d70224c..391c77f58 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -252,6 +252,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab /** * Return a collection of bounding coordinates. The coordinates must be such that * the component is fully enclosed in their convex hull. + * + * Note: this function gets the bounds only for this component. Subchildren must be called individually. * * @return a collection of coordinates that bound the component. */ @@ -1078,7 +1080,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab } public Coordinate getAbsolutePositionVector() { - if (null == this.parent) { // i.e. root / Rocket instance OR improperly initialized components + if (null == this.parent) { + // == improperly initialized components OR the root Rocket instance return new Coordinate(); } else { return this.parent.getAbsolutePositionVector().add(this.getRelativePositionVector()); @@ -1888,7 +1891,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab /** - * Helper method to add rotationally symmetric bounds at the specified coordinates. + * Helper method to add four bounds rotated around the given x coordinate at radius 'r', and 90deg between each. * The X-axis value is x and the radius at the specified position is * r. */ diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index 56ede1182..3b6f28b5a 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -1,5 +1,7 @@ package net.sf.openrocket.rocketcomponent; +import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import net.sf.openrocket.l10n.Translator; @@ -54,28 +56,23 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return true; } + // not strictly accurate, but this should provide an acceptable estimate for total vehicle size @Override - public void toDebugTreeNode(final StringBuilder buffer, final String prefix) { + public Collection getComponentBounds() { + Collection bounds = new ArrayList(8); + final double WAG_FACTOR = 1.05; + Coordinate center = this.getAbsolutePositionVector(); + double startx = center.x - this.length / 2; + double endx = center.x + this.length / 2; + double r = this.getRadialOffset() * WAG_FACTOR; - String thisLabel = this.getName() + " (" + this.getStageNumber() + ")"; - - buffer.append(String.format("%s %-24s %5.3f %24s %24s", prefix, thisLabel, this.getLength(), - this.getRelativePositionVector(), this.getAbsolutePositionVector())); - - if (this.isCenterline()) { - buffer.append("\n"); - } else { - buffer.append(String.format(" %4.1f//%s \n", this.getAxialOffset(), this.relativePosition.name())); - Coordinate componentAbsolutePosition = this.getAbsolutePositionVector(); - Coordinate[] instanceCoords = new Coordinate[] { componentAbsolutePosition }; - instanceCoords = this.shiftCoordinates(instanceCoords); - - for (int instance = 0; instance < this.count; instance++) { - Coordinate instanceAbsolutePosition = instanceCoords[instance]; - buffer.append(String.format("%s [instance %2d of %2d] %s\n", prefix, instance, count, instanceAbsolutePosition)); - } + if (!this.isCenterline()) { + System.err.println(">> .getComponentBounds(): r=" + r); } + addBound(bounds, startx, r); + addBound(bounds, endx, r); + return bounds; } /** @@ -329,6 +326,31 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return buf; } + @Override + public void toDebugTreeNode(final StringBuilder buffer, final String prefix) { + + String thisLabel = this.getName() + " (" + this.getStageNumber() + ")"; + + buffer.append(String.format("%s %-24s %5.3f %24s %24s", prefix, thisLabel, this.getLength(), + this.getRelativePositionVector(), this.getAbsolutePositionVector())); + + if (this.isCenterline()) { + buffer.append("\n"); + } else { + buffer.append(String.format(" %4.1f//%s \n", this.getAxialOffset(), this.relativePosition.name())); + Coordinate componentAbsolutePosition = this.getAbsolutePositionVector(); + Coordinate[] instanceCoords = new Coordinate[] { componentAbsolutePosition }; + instanceCoords = this.shiftCoordinates(instanceCoords); + + for (int instance = 0; instance < this.count; instance++) { + Coordinate instanceAbsolutePosition = instanceCoords[instance]; + buffer.append(String.format("%s [instance %2d of %2d] %s\n", prefix, instance, count, instanceAbsolutePosition)); + } + } + + } + + @Override public void updateBounds() { // currently only updates the length