diff --git a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java index a5607615e..4db208072 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/AxialStage.java @@ -54,25 +54,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC public void reset( final FlightConfigurationId fcid){ separations.reset(fcid); } - - /** - * {@inheritDoc} - * not strictly accurate, but this should provide an acceptable estimate for total vehicle size - */ - @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(8); - Coordinate[] instanceLocations = this.getInstanceLocations(); - double x_min = instanceLocations[0].x; - double x_max = x_min + this.length; - double r_max = 0; - - addBound(bounds, x_min, r_max); - addBound(bounds, x_max, r_max); - - return bounds; - } - + /** * Check whether the given type can be added to this component. A Stage allows * only BodyComponents to be added. diff --git a/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java b/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java index 24468aeb3..cee911aef 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ComponentAssembly.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import net.sf.openrocket.util.BoundingBox; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +23,7 @@ import net.sf.openrocket.util.Coordinate; * * @author Sampo Niskanen */ -public abstract class ComponentAssembly extends RocketComponent implements AxialPositionable { +public abstract class ComponentAssembly extends RocketComponent implements AxialPositionable, BoxBounded { private static final Logger log = LoggerFactory.getLogger(ComponentAssembly.class); /** @@ -54,7 +55,7 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia public Collection getComponentBounds() { return Collections.emptyList(); } - + /** * Null method (ComponentAssembly has no mass of itself). */ @@ -70,7 +71,9 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia public double getComponentMass() { return 0; } - + + public BoundingBox getInstanceBoundingBox (){ return new BoundingBox(); } + /** * Null method (ComponentAssembly has no mass of itself). */ diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 0cff35040..0a515107f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -581,7 +581,7 @@ public class FlightConfiguration implements FlightConfigurableParameter instanceCoordinates = component.getComponentBounds(); - for (InstanceContext context : contexts) { /* * If the instance is not active in the current context, then diff --git a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java index e22fc51aa..3e40d899d 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/PodSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/PodSet.java @@ -3,11 +3,13 @@ package net.sf.openrocket.rocketcomponent; import java.util.ArrayList; import java.util.Collection; +import jdk.jshell.spi.ExecutionControl; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.position.AngleMethod; import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.RadiusMethod; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; @@ -43,35 +45,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable { //// Stage return trans.get("PodSet.PodSet"); } - - - // not strictly accurate, but this should provide an acceptable estimate for total vehicle size - @Override - public Collection getComponentBounds() { - Collection bounds = new ArrayList(8); - double x_min = Double.MAX_VALUE; - double x_max = Double.MIN_VALUE; - double r_max = 0; - - Coordinate[] instanceLocations = this.getComponentLocations(); - - for (Coordinate currentInstanceLocation : instanceLocations) { - if (x_min > (currentInstanceLocation.x)) { - x_min = currentInstanceLocation.x; - } - if (x_max < (currentInstanceLocation.x + this.length)) { - x_max = currentInstanceLocation.x + this.length; - } - if (r_max < (this.getRadiusOffset())) { - r_max = this.getRadiusOffset(); - } - } - addBound(bounds, x_min, r_max); - addBound(bounds, x_max, r_max); - - return bounds; - } - + /** * Check whether the given type can be added to this component. A Stage allows * only BodyComponents to be added. @@ -85,7 +59,6 @@ public class PodSet extends ComponentAssembly implements RingInstanceable { return BodyComponent.class.isAssignableFrom(type); } - @Override public double getInstanceAngleIncrement(){ return angleSeparation; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java index eba695c4d..b06b96668 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java @@ -45,30 +45,30 @@ public abstract class AbstractScaleFigure extends JPanel { // size of the visible region protected Dimension visibleBounds_px = new Dimension(0,0); - // ======= whatever this figure is drawing, in real-space coordinates: meters - protected Rectangle2D subjectBounds_m = null; - - // combines the translation and scale in one place: - // which frames does this transform between ? - protected AffineTransform projection = null; + // ======= whatever this figure is drawing, in real-space coordinates: meters + protected Rectangle2D subjectBounds_m = null; + + // combines the translation and scale in one place: + // which frames does this transform between ? + protected AffineTransform projection = null; protected final List listeners = new LinkedList(); public AbstractScaleFigure() { - // produces a pixels-per-meter scale factor - // - // dots dots inch - // ---- = ------ * ----- - // meter inch meter - // - this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER; - this.userScale = 1.0; - this.scale = baseScale * userScale; - - this.setPreferredSize(new Dimension(100,100)); - setSize(100,100); - + // produces a pixels-per-meter scale factor + // + // dots dots inch + // ---- = ------ * ----- + // meter inch meter + // + this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER; + this.userScale = 1.0; + this.scale = baseScale * userScale; + + this.setPreferredSize(new Dimension(100,100)); + setSize(100,100); + setBackground(Color.WHITE); setOpaque(true); } @@ -77,28 +77,28 @@ public abstract class AbstractScaleFigure extends JPanel { return userScale; } - public double getAbsoluteScale() { - return scale; - } + public double getAbsoluteScale() { + return scale; + } - public Dimension getSubjectOrigin() { + public Dimension getSubjectOrigin() { return originLocation_px; } - + /** * Set the scale level of the figure. A scale value of 1.0 is equivalent to 100 % scale. * Smaller scales display the subject smaller. * * If the figure would be smaller than the 'visibleBounds', then the figure is grown to match, * and the figures internal contents are centered according to the figure's origin. - * + * * @param newScaleRequest the scale level * @param visibleBounds the visible bounds upon the Figure */ public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) { if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){ return;} - if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest)) { + if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) { return;} this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM); @@ -115,21 +115,21 @@ public abstract class AbstractScaleFigure extends JPanel { * @param visibleBounds the visible bounds to scale this figure to. */ public void scaleTo(Dimension visibleBounds) { - if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight()) - return; - - updateSubjectDimensions(); - - // dimensions within the viewable area, which are available to draw + if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight()) + return; + + updateSubjectDimensions(); + + // dimensions within the viewable area, which are available to draw final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width; final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height; - if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) { - final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale); - final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale); - final double minScale = Math.min(height_scale, width_scale); - - scaleTo(minScale, visibleBounds); + if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) { + final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale); + final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale); + final double minScale = Math.min(height_scale, width_scale); + + scaleTo(minScale, visibleBounds); } }