[feat] Implements BoxBounded interface on several RocketComponents

This commit is contained in:
Daniel_M_Williams 2020-08-29 19:41:07 -04:00
parent 709ded2659
commit 81b2f60e55
4 changed files with 57 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.sf.openrocket.util.BoundingBox;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -25,7 +26,7 @@ import net.sf.openrocket.util.MathUtil;
* *
* @author Sampo Niskanen <sampo.niskanen@iki.fi> * @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/ */
public class InnerTube extends ThicknessRingComponent implements AxialPositionable, Clusterable, RadialParent, MotorMount { public class InnerTube extends ThicknessRingComponent implements AxialPositionable, BoxBounded, Clusterable, RadialParent, MotorMount {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(InnerTube.class); private static final Logger log = LoggerFactory.getLogger(InnerTube.class);
@ -135,6 +136,18 @@ public class InnerTube extends ThicknessRingComponent implements AxialPositionab
} }
} }
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;
}
@Override @Override
public int getInstanceCount() { public int getInstanceCount() {
return cluster.getClusterCount(); return cluster.getClusterCount();

View File

@ -8,12 +8,13 @@ import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.preset.ComponentPreset.Type; import net.sf.openrocket.preset.ComponentPreset.Type;
import net.sf.openrocket.rocketcomponent.position.*; import net.sf.openrocket.rocketcomponent.position.*;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
public class LaunchLug extends ExternalComponent implements AnglePositionable, Coaxial, LineInstanceable { public class LaunchLug extends ExternalComponent implements AnglePositionable, BoxBounded, Coaxial, LineInstanceable {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@ -252,7 +253,20 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, C
public int getInstanceCount(){ public int getInstanceCount(){
return this.instanceCount; return this.instanceCount;
} }
@Override
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;
}
@Override @Override
public String getPatternName(){ public String getPatternName(){
return (this.getInstanceCount() + "-Line"); return (this.getInstanceCount() + "-Line");
@ -281,5 +295,4 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, C
public void setAngleMethod(AngleMethod newMethod) { public void setAngleMethod(AngleMethod newMethod) {
// no-op // no-op
} }
} }

View File

@ -13,6 +13,7 @@ import net.sf.openrocket.rocketcomponent.position.AnglePositionable;
import net.sf.openrocket.rocketcomponent.position.AxialMethod; import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.AxialPositionable; import net.sf.openrocket.rocketcomponent.position.AxialPositionable;
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;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -22,7 +23,7 @@ import net.sf.openrocket.util.MathUtil;
* @author widget (Daniel Williams) * @author widget (Daniel Williams)
* *
*/ */
public class RailButton extends ExternalComponent implements AnglePositionable, AxialPositionable, LineInstanceable { public class RailButton extends ExternalComponent implements AnglePositionable, AxialPositionable, BoxBounded, LineInstanceable {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@ -210,6 +211,18 @@ public class RailButton extends ExternalComponent implements AnglePositionable,
fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
} }
public BoundingBox getInstanceBoundingBox(){
BoundingBox instanceBounds = new BoundingBox();
instanceBounds.update(new Coordinate(0, this.getTotalHeight(), 0));
final double r = this.getOuterDiameter();
instanceBounds.update(new Coordinate(r,r,0));
instanceBounds.update(new Coordinate(-r,-r,0));
return instanceBounds;
}
@Override @Override
public Coordinate[] getInstanceOffsets(){ public Coordinate[] getInstanceOffsets(){
Coordinate[] toReturn = new Coordinate[this.getInstanceCount()]; Coordinate[] toReturn = new Coordinate[this.getInstanceCount()];

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
@ -16,7 +17,7 @@ import net.sf.openrocket.util.MathUtil;
* *
* @author Sampo Niskanen <sampo.niskanen@iki.fi> * @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/ */
public abstract class RingComponent extends StructuralComponent implements Coaxial { public abstract class RingComponent extends StructuralComponent implements BoxBounded, Coaxial {
protected boolean outerRadiusAutomatic = false; protected boolean outerRadiusAutomatic = false;
protected boolean innerRadiusAutomatic = false; protected boolean innerRadiusAutomatic = false;
@ -111,9 +112,18 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }
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;
}
/** /**
* Return the radial position of the component. The position is the distance * Return the radial position of the component. The position is the distance
* of the center of the component from the center of the parent component. * of the center of the component from the center of the parent component.