[fix #801] eliminate redundant angle-offset property in LaunchLug component

This commit is contained in:
Daniel_M_Williams 2020-11-01 19:37:23 -05:00
parent 67fed96137
commit c9d408a8ee
9 changed files with 45 additions and 63 deletions

View File

@ -28,7 +28,6 @@ public class LaunchLugSaver extends ExternalComponentSaver {
elements.add("<radius>" + lug.getOuterRadius() + "</radius>"); elements.add("<radius>" + lug.getOuterRadius() + "</radius>");
elements.add("<length>" + lug.getLength() + "</length>"); elements.add("<length>" + lug.getLength() + "</length>");
elements.add("<thickness>" + lug.getThickness() + "</thickness>"); elements.add("<thickness>" + lug.getThickness() + "</thickness>");
elements.add("<radialdirection>" + (lug.getAngularOffset()*180.0/Math.PI)+ "</radialdirection>");
} }

View File

@ -88,32 +88,31 @@ public class RocketComponentSaver {
if ( c instanceof Instanceable) { if ( c instanceof Instanceable) {
int instanceCount = c.getInstanceCount(); int instanceCount = c.getInstanceCount();
if( c instanceof Clusterable ){ if (c instanceof Clusterable) {
; // no-op. Instance counts are set via named cluster configurations ; // no-op. Instance counts are set via named cluster configurations
}else { } else {
emitInteger(elements, "instancecount", c.getInstanceCount()); emitInteger(elements, "instancecount", c.getInstanceCount());
} }
if( c instanceof LineInstanceable ){ if (c instanceof LineInstanceable) {
LineInstanceable line = (LineInstanceable)c; LineInstanceable line = (LineInstanceable) c;
emitDouble( elements, "instanceseparation", line.getInstanceSeparation()); emitDouble(elements, "instanceseparation", line.getInstanceSeparation());
}
if( c instanceof RadiusPositionable ){
final RadiusPositionable radPos = (RadiusPositionable)c;
// The type names are currently equivalent to the enum names except for case.
final String radiusMethod = radPos.getRadiusMethod().name().toLowerCase(Locale.ENGLISH);
final double radiusOffset = radPos.getRadiusOffset();
elements.add("<radiusoffset method=\"" + radiusMethod + "\">" + radiusOffset + "</radiusoffset>");
}
if( c instanceof AnglePositionable ) {
final AnglePositionable anglePos= (AnglePositionable)c;
// The type names are currently equivalent to the enum names except for case.
final String angleMethod = anglePos.getAngleMethod().name().toLowerCase(Locale.ENGLISH);
final double angleOffset = anglePos.getAngleOffset()*180.0/Math.PI ;
elements.add("<angleoffset method=\"" + angleMethod + "\">" + angleOffset + "</angleoffset>");
} }
} }
if( c instanceof RadiusPositionable ){
final RadiusPositionable radPos = (RadiusPositionable)c;
// The type names are currently equivalent to the enum names except for case.
final String radiusMethod = radPos.getRadiusMethod().name().toLowerCase(Locale.ENGLISH);
final double radiusOffset = radPos.getRadiusOffset();
elements.add("<radiusoffset method=\"" + radiusMethod + "\">" + radiusOffset + "</radiusoffset>");
}
if( c instanceof AnglePositionable ) {
final AnglePositionable anglePos = (AnglePositionable)c;
// The type names are currently equivalent to the enum names except for case.
final String angleMethod = anglePos.getAngleMethod().name().toLowerCase(Locale.ENGLISH);
final double angleOffset = anglePos.getAngleOffset()*180.0/Math.PI;
elements.add("<angleoffset method=\"" + angleMethod + "\">" + angleOffset + "</angleoffset>");
}
// Save position unless "AFTER" // Save position unless "AFTER"
if (c.getAxialMethod() != AxialMethod.AFTER) { if (c.getAxialMethod() != AxialMethod.AFTER) {

View File

@ -35,7 +35,7 @@ public class LaunchLugDTO extends BasePartDTO {
super(theORLaunchLug); super(theORLaunchLug);
setId(theORLaunchLug.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); setId(theORLaunchLug.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
setOd(theORLaunchLug.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS); setOd(theORLaunchLug.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
setRadialAngle(theORLaunchLug.getAngularOffset()); setRadialAngle(theORLaunchLug.getAngleOffset());
} }
public double getOd() { public double getOd() {

View File

@ -70,7 +70,7 @@ class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
setMaterialName(content); setMaterialName(content);
} }
if (RocksimCommonConstants.RADIAL_ANGLE.equals(element)) { if (RocksimCommonConstants.RADIAL_ANGLE.equals(element)) {
lug.setAngularOffset(Double.parseDouble(content)); lug.setAngleOffset(Double.parseDouble(content));
} }
if (RocksimCommonConstants.FINISH_CODE.equals(element)) { if (RocksimCommonConstants.FINISH_CODE.equals(element)) {
lug.setFinish(RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket()); lug.setFinish(RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket());

View File

@ -21,14 +21,12 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
private double radius; private double radius;
private double thickness; private double thickness;
private double radialDirection = 0; private double angleOffsetRadians = 0;
private double radialDistance = 0; private double radialOffset = 0;
private int instanceCount = 1; private int instanceCount = 1;
private double instanceSeparation = 0; // front-front along the positive rocket axis. i.e. [1,0,0]; private double instanceSeparation = 0; // front-front along the positive rocket axis. i.e. [1,0,0];
private double angle_rad = 0;
public LaunchLug() { public LaunchLug() {
super(AxialMethod.MIDDLE); super(AxialMethod.MIDDLE);
radius = 0.01 / 2; radius = 0.01 / 2;
@ -75,15 +73,17 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
public double getAngularOffset() { @Override
return this.radialDirection; public double getAngleOffset() {
return this.angleOffsetRadians;
} }
public void setAngularOffset(final double newAngle_rad){ @Override
double clamped_rad = MathUtil.clamp( newAngle_rad, -Math.PI, Math.PI); public void setAngleOffset(double newAngleRadians) {
if (MathUtil.equals(this.radialDirection, clamped_rad)) double clamped_rad = MathUtil.clamp( newAngleRadians, -Math.PI, Math.PI);
if (MathUtil.equals(this.angleOffsetRadians, clamped_rad))
return; return;
this.radialDirection = clamped_rad; this.angleOffsetRadians = clamped_rad;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@ -94,7 +94,6 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
} }
@Override @Override
public boolean isAfter() { public boolean isAfter() {
return false; return false;
@ -126,8 +125,8 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
public Coordinate[] getInstanceOffsets(){ public Coordinate[] getInstanceOffsets(){
Coordinate[] toReturn = new Coordinate[this.getInstanceCount()]; Coordinate[] toReturn = new Coordinate[this.getInstanceCount()];
final double yOffset = Math.cos(radialDirection) * (radialDistance); final double yOffset = Math.cos(angleOffsetRadians) * (radialOffset);
final double zOffset = Math.sin(radialDirection) * (radialDistance); final double zOffset = Math.sin(angleOffsetRadians) * (radialOffset);
for ( int index=0; index < this.getInstanceCount(); index++){ for ( int index=0; index < this.getInstanceCount(); index++){
toReturn[index] = new Coordinate(index*this.instanceSeparation, yOffset, zOffset); toReturn[index] = new Coordinate(index*this.instanceSeparation, yOffset, zOffset);
@ -177,12 +176,9 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
parentRadius = Math.max(s.getRadius(x1), s.getRadius(x2)); parentRadius = Math.max(s.getRadius(x1), s.getRadius(x2));
} }
this.radialDistance = parentRadius + radius; this.radialOffset = parentRadius + radius;
} }
@Override @Override
public double getComponentVolume() { public double getComponentVolume() {
return length * Math.PI * (MathUtil.pow2(radius) - MathUtil.pow2(radius - thickness)); return length * Math.PI * (MathUtil.pow2(radius) - MathUtil.pow2(radius - thickness));
@ -273,18 +269,6 @@ public class LaunchLug extends ExternalComponent implements AnglePositionable, B
} }
@Override
public double getAngleOffset() {
return this.angle_rad;
}
@Override
public void setAngleOffset(double newAngle) {
this.angle_rad = newAngle;
}
@Override @Override
public AngleMethod getAngleMethod() { public AngleMethod getAngleMethod() {
return AngleMethod.RELATIVE; return AngleMethod.RELATIVE;

View File

@ -134,7 +134,7 @@ public class RocksimLoaderTest extends BaseTestCase {
BodyTube bt = (BodyTube) stage2.getChild(0); BodyTube bt = (BodyTube) stage2.getChild(0);
LaunchLug ll = (LaunchLug) bt.getChild(6); LaunchLug ll = (LaunchLug) bt.getChild(6);
Assert.assertEquals(1.22d, ll.getAngularOffset(), 0.001); Assert.assertEquals(1.22d, ll.getAngleOffset(), 0.001);
Assert.assertEquals(2, stage3.getChildCount()); Assert.assertEquals(2, stage3.getChildCount());
Assert.assertEquals("Transition", stage3.getChild(0).getName()); Assert.assertEquals("Transition", stage3.getChild(0).getName());

View File

@ -42,7 +42,7 @@ public class LaunchLugTest extends BaseTestCase {
BodyTube body= (BodyTube)rocket.getChild(0).getChild(1); BodyTube body= (BodyTube)rocket.getChild(0).getChild(1);
LaunchLug lug = (LaunchLug)rocket.getChild(0).getChild(1).getChild(1); LaunchLug lug = (LaunchLug)rocket.getChild(0).getChild(1).getChild(1);
double startAngle = Math.PI/2; double startAngle = Math.PI/2;
lug.setAngularOffset( startAngle ); lug.setAngleOffset( startAngle );
lug.setInstanceSeparation(0.05); lug.setInstanceSeparation(0.05);
lug.setInstanceCount(2); lug.setInstanceCount(2);

View File

@ -94,8 +94,8 @@ public class LaunchLugConfig extends RocketComponentConfig {
//// Radial position: //// Radial position:
panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Radialpos"))); panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Radialpos")));
m = new DoubleModel(component, "AngularOffset", UnitGroup.UNITS_ANGLE, -180, 180); m = new DoubleModel(component, "AngleOffset", UnitGroup.UNITS_ANGLE, -180, 180);
spin = new JSpinner(m.getSpinnerModel()); spin = new JSpinner(m.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin)); spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "growx"); panel.add(spin, "growx");
@ -103,12 +103,12 @@ public class LaunchLugConfig extends RocketComponentConfig {
panel.add(new UnitSelector(m), "growx"); panel.add(new UnitSelector(m), "growx");
panel.add(new BasicSlider(m.getSliderModel(-180, 180) ), "w 100lp, wrap"); panel.add(new BasicSlider(m.getSliderModel(-180, 180) ), "w 100lp, wrap");
// finish up the left column
primary.add(panel, "grow, gapright 20lp"); primary.add(panel, "grow, gapright 20lp");
// create a new panel for the right column
panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::][]", "")); panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::][]", ""));
//// Position relative to: //// Position relative to:
panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto"))); panel.add(new JLabel(trans.get("LaunchLugCfg.lbl.Posrelativeto")));
EnumModel<AxialMethod> positionModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods ); EnumModel<AxialMethod> positionModel = new EnumModel<AxialMethod>(component, "AxialMethod", AxialMethod.axialOffsetMethods );

View File

@ -287,7 +287,7 @@ public class FinMarkingGuide extends JPanel {
} }
else if (externalComponent instanceof LaunchLug) { else if (externalComponent instanceof LaunchLug) {
LaunchLug lug = (LaunchLug) externalComponent; LaunchLug lug = (LaunchLug) externalComponent;
double angle = lug.getAngularOffset() - radialOrigin; double angle = lug.getAngleOffset() - radialOrigin;
while (angle < 0) { while (angle < 0) {
angle += TWO_PI; angle += TWO_PI;
} }
@ -331,7 +331,7 @@ public class FinMarkingGuide extends JPanel {
for (ExternalComponent component : components) { for (ExternalComponent component : components) {
if (component instanceof LaunchLug) { if (component instanceof LaunchLug) {
double componentPosition = ((LaunchLug) component).getAngularOffset(); double componentPosition = ((LaunchLug) component).getAngleOffset();
positions.add(makeZeroTwoPi(componentPosition)); positions.add(makeZeroTwoPi(componentPosition));
} }
@ -479,4 +479,4 @@ public class FinMarkingGuide extends JPanel {
g2.fillPolygon(new int[] { x1, x1 + ARROW_SIZE, x1 + ARROW_SIZE, x1 }, g2.fillPolygon(new int[] { x1, x1 + ARROW_SIZE, x1 + ARROW_SIZE, x1 },
new int[] { y1, y1 - ARROW_SIZE / 2, y1 + ARROW_SIZE / 2, y1 }, 4); new int[] { y1, y1 - ARROW_SIZE / 2, y1 + ARROW_SIZE / 2, y1 }, 4);
} }
} }