[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

@ -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);