[refactor] ComponentAssembly components no longer have bounds -- it's calculated from individual components, on a per-instance basis.

This commit is contained in:
Daniel_M_Williams 2020-06-20 14:31:29 -04:00
parent 0a9df5cc64
commit 7b81f763c7
5 changed files with 49 additions and 92 deletions

View File

@ -55,24 +55,6 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
separations.reset(fcid); separations.reset(fcid);
} }
/**
* {@inheritDoc}
* not strictly accurate, but this should provide an acceptable estimate for total vehicle size
*/
@Override
public Collection<Coordinate> getComponentBounds() {
Collection<Coordinate> bounds = new ArrayList<Coordinate>(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 * Check whether the given type can be added to this component. A Stage allows
* only BodyComponents to be added. * only BodyComponents to be added.

View File

@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import net.sf.openrocket.util.BoundingBox;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,7 +23,7 @@ import net.sf.openrocket.util.Coordinate;
* *
* @author Sampo Niskanen <sampo.niskanen@iki.fi> * @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/ */
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); private static final Logger log = LoggerFactory.getLogger(ComponentAssembly.class);
/** /**
@ -71,6 +72,8 @@ public abstract class ComponentAssembly extends RocketComponent implements Axia
return 0; return 0;
} }
public BoundingBox getInstanceBoundingBox (){ return new BoundingBox(); }
/** /**
* Null method (ComponentAssembly has no mass of itself). * Null method (ComponentAssembly has no mass of itself).
*/ */

View File

@ -581,7 +581,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
componentBounds = instanceBounds.transform(context.transform); componentBounds = instanceBounds.transform(context.transform);
} }
}else if ((component instanceof AxialStage) || (component instanceof BodyTube) || (component instanceof PodSet)) { }else if (component instanceof BodyTube) {
// Legacy Case #1: // Legacy Case #1:
// These components do not need the transform performed in // These components do not need the transform performed in
// order to provide the proper coordinates for length calculation. // order to provide the proper coordinates for length calculation.
@ -593,7 +593,6 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
// Legacy Case #2: // Legacy Case #2:
// These components do not implement // These components do not implement
Collection<Coordinate> instanceCoordinates = component.getComponentBounds(); Collection<Coordinate> instanceCoordinates = component.getComponentBounds();
for (InstanceContext context : contexts) { for (InstanceContext context : contexts) {
/* /*
* If the instance is not active in the current context, then * If the instance is not active in the current context, then

View File

@ -3,11 +3,13 @@ package net.sf.openrocket.rocketcomponent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import jdk.jshell.spi.ExecutionControl;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.position.AngleMethod; import net.sf.openrocket.rocketcomponent.position.AngleMethod;
import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.RadiusMethod; import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
@ -44,34 +46,6 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
return trans.get("PodSet.PodSet"); return trans.get("PodSet.PodSet");
} }
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size
@Override
public Collection<Coordinate> getComponentBounds() {
Collection<Coordinate> bounds = new ArrayList<Coordinate>(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 * Check whether the given type can be added to this component. A Stage allows
* only BodyComponents to be added. * only BodyComponents to be added.
@ -85,7 +59,6 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
return BodyComponent.class.isAssignableFrom(type); return BodyComponent.class.isAssignableFrom(type);
} }
@Override @Override
public double getInstanceAngleIncrement(){ public double getInstanceAngleIncrement(){
return angleSeparation; return angleSeparation;

View File

@ -45,29 +45,29 @@ public abstract class AbstractScaleFigure extends JPanel {
// size of the visible region // size of the visible region
protected Dimension visibleBounds_px = new Dimension(0,0); protected Dimension visibleBounds_px = new Dimension(0,0);
// ======= whatever this figure is drawing, in real-space coordinates: meters // ======= whatever this figure is drawing, in real-space coordinates: meters
protected Rectangle2D subjectBounds_m = null; protected Rectangle2D subjectBounds_m = null;
// combines the translation and scale in one place: // combines the translation and scale in one place:
// which frames does this transform between ? // which frames does this transform between ?
protected AffineTransform projection = null; protected AffineTransform projection = null;
protected final List<EventListener> listeners = new LinkedList<EventListener>(); protected final List<EventListener> listeners = new LinkedList<EventListener>();
public AbstractScaleFigure() { public AbstractScaleFigure() {
// produces a pixels-per-meter scale factor // produces a pixels-per-meter scale factor
// //
// dots dots inch // dots dots inch
// ---- = ------ * ----- // ---- = ------ * -----
// meter inch meter // meter inch meter
// //
this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER; this.baseScale = GUIUtil.getDPI() * INCHES_PER_METER;
this.userScale = 1.0; this.userScale = 1.0;
this.scale = baseScale * userScale; this.scale = baseScale * userScale;
this.setPreferredSize(new Dimension(100,100)); this.setPreferredSize(new Dimension(100,100));
setSize(100,100); setSize(100,100);
setBackground(Color.WHITE); setBackground(Color.WHITE);
setOpaque(true); setOpaque(true);
@ -77,11 +77,11 @@ public abstract class AbstractScaleFigure extends JPanel {
return userScale; return userScale;
} }
public double getAbsoluteScale() { public double getAbsoluteScale() {
return scale; return scale;
} }
public Dimension getSubjectOrigin() { public Dimension getSubjectOrigin() {
return originLocation_px; return originLocation_px;
} }
@ -98,7 +98,7 @@ public abstract class AbstractScaleFigure extends JPanel {
public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) { public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) {
if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){ if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){
return;} return;}
if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest)) { if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) {
return;} return;}
this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM); 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. * @param visibleBounds the visible bounds to scale this figure to.
*/ */
public void scaleTo(Dimension visibleBounds) { public void scaleTo(Dimension visibleBounds) {
if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight()) if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight())
return; return;
updateSubjectDimensions(); updateSubjectDimensions();
// dimensions within the viewable area, which are available to draw // dimensions within the viewable area, which are available to draw
final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width; final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width;
final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height; final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height;
if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) { if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) {
final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale); final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale);
final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale); final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale);
final double minScale = Math.min(height_scale, width_scale); final double minScale = Math.min(height_scale, width_scale);
scaleTo(minScale, visibleBounds); scaleTo(minScale, visibleBounds);
} }
} }