From 22160dbe5d893c8585fca93cc4a16eb2a3025294 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 20 Jun 2020 15:29:45 -0400 Subject: [PATCH] [refactor] BodyTube now implements the BoxBounded interface --- .../openrocket/rocketcomponent/BodyTube.java | 60 +++++-------------- .../rocketcomponent/FlightConfiguration.java | 11 +--- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 141146bc6..4428dfac4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -10,6 +10,7 @@ import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfigurationSet; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -21,7 +22,7 @@ import net.sf.openrocket.util.MathUtil; * @author Sampo Niskanen */ -public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial { +public class BodyTube extends SymmetricComponent implements BoxBounded, MotorMount, Coaxial { private static final Translator trans = Application.getTranslator(); private double outerRadius = 0; @@ -296,52 +297,19 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial private static double getFilledVolume(double r, double l) { return Math.PI * r * r * l; } - - - /** - * Adds bounding coordinates to the given set. The body tube will fit within the - * convex hull of the points. - * - * Currently the points are simply a rectangular box around the body tube. - */ - @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(8); - double x_min_shape = 0; - double x_max_shape = this.length; - double r_max_shape = getOuterRadius(); - - Coordinate[] locs = this.getLocations(); - // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - double x_min_inst = Double.MAX_VALUE; - double x_max_inst = Double.MIN_VALUE; - double r_max_inst = 0.0; - - // refactor: get component inherent bounds - for (Coordinate cur : locs) { - double x_cur = cur.x; - double r_cur = MathUtil.hypot(cur.y, cur.z); - if (x_min_inst > x_cur) { - x_min_inst = x_cur; - } - if (x_max_inst < x_cur) { - x_max_inst = x_cur; - } - if (r_cur > r_max_inst) { - r_max_inst = r_cur; - } - } - - // combine the position bounds with the inherent shape bounds - double x_min = x_min_shape + x_min_inst; - double x_max = x_max_shape + x_max_inst; - double r_max = r_max_shape + r_max_inst; - - addBoundingBox(bounds, x_min, x_max, r_max); - return bounds; + + public BoundingBox getInstanceBoundingBox(){ + BoundingBox instanceBounds = new BoundingBox(); + + instanceBounds.update(new Coordinate(this.getLength(), 0,0)); + + final double r = getOuterRadius(); + instanceBounds.update(new Coordinate(0,r,r)); + instanceBounds.update(new Coordinate(0,-r,-r)); + + return instanceBounds; } - - + /** * Check whether the given type can be added to this component. BodyTubes allow any * InternalComponents or ExternalComponents, excluding BodyComponents, to be added. diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 0a515107f..5b7494897 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -581,17 +581,8 @@ public class FlightConfiguration implements FlightConfigurableParameter instanceCoordinates = component.getComponentBounds(); for (InstanceContext context : contexts) { /*