Merge pull request #647 from teyrana/645-fix-auto-radius

[Fixes #645] fix auto radius calculation on Symmetric Components
This commit is contained in:
Daniel Williams 2020-05-07 18:31:48 -04:00 committed by GitHub
commit 83ce19cac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 267 additions and 183 deletions

View File

@ -629,9 +629,9 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
} }
// if I'm the last componenet, set my base CD // if I'm the last component, set my base CD
// note I can't depend on the iterator serving up components in order, // note: the iterator *should* serve up the next component.... buuuut ....
// so I can't just do this after the last iteration. // this code has is tested, and there's no compelling reason to change.
if (s.getNextSymmetricComponent() == null) { if (s.getNextSymmetricComponent() == null) {
double area = Math.PI * pow2(s.getAftRadius()); double area = Math.PI * pow2(s.getAftRadius());
double cd = base * area / conditions.getRefArea(); double cd = base * area / conditions.getRefArea();

View File

@ -1630,9 +1630,26 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
} }
return null; return null;
} }
public final RocketComponent getNextComponent() {
// TODO: Move these methods elsewhere (used only in SymmetricComponent) checkState();
if (getChildCount() > 0)
return getChild(0);
RocketComponent current = this;
RocketComponent nextParent = this.parent;
while (nextParent != null) {
int pos = nextParent.getChildPosition(current);
if (pos < nextParent.getChildCount() - 1)
return nextParent.getChild(pos + 1);
current = nextParent;
nextParent = current.parent;
}
return null;
}
public final RocketComponent getPreviousComponent() { public final RocketComponent getPreviousComponent() {
checkState(); checkState();
this.checkComponentStructure(); this.checkComponentStructure();
@ -1662,28 +1679,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
c = c.getChild(c.getChildCount() - 1); c = c.getChild(c.getChildCount() - 1);
return c; return c;
} }
// TODO: Move these methods elsewhere (used only in SymmetricComponent)
public final RocketComponent getNextComponent() {
checkState();
if (getChildCount() > 0)
return getChild(0);
RocketComponent current = this;
RocketComponent nextParent = this.parent;
while (nextParent != null) {
int pos = nextParent.getChildPosition(current);
if (pos < nextParent.getChildCount() - 1)
return nextParent.getChild(pos + 1);
current = nextParent;
nextParent = current.parent;
}
return null;
}
/////////// Event handling ////////// /////////// Event handling //////////
// //
// Listener lists are provided by the root Rocket component, // Listener lists are provided by the root Rocket component,
@ -2183,7 +2179,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
for (int instanceNumber = 0; instanceNumber < this.getInstanceCount(); instanceNumber++) { for (int instanceNumber = 0; instanceNumber < this.getInstanceCount(); instanceNumber++) {
final String instancePrefix = String.format("%s [%2d/%2d]", indent, instanceNumber+1, getInstanceCount()); final String instancePrefix = String.format("%s [%2d/%2d]", indent, instanceNumber+1, getInstanceCount());
buffer.append(String.format("%-40s| %5.3f; %24s; %24s;\n", instancePrefix, getLength(), this.axialOffset, getLocations()[0])); buffer.append(String.format("%-40s| %5.3f; %24s; %24s;\n", instancePrefix, getLength(), this.axialOffset, getLocations()[instanceNumber]));
} }
}else{ }else{
throw new IllegalStateException("This is a developer error! If you implement an instanced class, please subclass the Instanceable interface."); throw new IllegalStateException("This is a developer error! If you implement an instanced class, please subclass the Instanceable interface.");

View File

@ -566,18 +566,34 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial
* @return the previous SymmetricComponent, or null. * @return the previous SymmetricComponent, or null.
*/ */
public final SymmetricComponent getPreviousSymmetricComponent() { public final SymmetricComponent getPreviousSymmetricComponent() {
RocketComponent c; if(null == this.parent) {
for (c = this.getPreviousComponent(); c != null; c = c.getPreviousComponent()) { return null;
if (c instanceof PodSet) { }
return null;
} // might be: (a) Rocket -- for centerline stages
if (c instanceof SymmetricComponent) { // (b) BodyTube -- for Parallel Stages
return (SymmetricComponent) c; final AxialStage stage = this.getStage();
} final RocketComponent stageParent = stage.getParent();
if (!(c instanceof AxialStage) &&
(c.axialMethod == AxialMethod.AFTER)) { // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one.
return null; // Bad component type as "parent" int stageIndex = stageParent.getChildPosition(stage);
int symmetricIndex = this.parent.getChildPosition(this)-1;
while( 0 <= stageIndex ) {
final RocketComponent prevStage = stageParent.getChild(stageIndex);
if(prevStage instanceof AxialStage){
while (0 <= symmetricIndex) {
final RocketComponent previousSymmetric = prevStage.getChild(symmetricIndex);
if (previousSymmetric instanceof SymmetricComponent) {
return (SymmetricComponent) previousSymmetric;
}
--symmetricIndex;
}
} }
--stageIndex;
symmetricIndex = prevStage.getChildCount() - 1;
} }
return null; return null;
} }
@ -588,17 +604,34 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial
* @return the next SymmetricComponent, or null. * @return the next SymmetricComponent, or null.
*/ */
public final SymmetricComponent getNextSymmetricComponent() { public final SymmetricComponent getNextSymmetricComponent() {
RocketComponent c; if(null == this.parent) {
for (c = this.getNextComponent(); c != null; c = c.getNextComponent()) { return null;
if (c instanceof PodSet) { }
return null;
// might be: (a) Rocket -- for centerline stages
// (b) BodyTube -- for Parallel Stages
final AxialStage stage = this.getStage();
final RocketComponent stageParent = stage.getParent();
// note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one.
int stageIndex = stageParent.getChildPosition(stage);
int symmetricIndex = this.parent.getChildPosition(this) + 1;
while(stageIndex < stageParent.getChildCount()) {
final RocketComponent nextStage = stageParent.getChild(stageIndex);
if(nextStage instanceof AxialStage){
while (symmetricIndex < nextStage.getChildCount()) {
final RocketComponent nextSymmetric = nextStage.getChild(symmetricIndex);
if (nextSymmetric instanceof SymmetricComponent) {
return (SymmetricComponent) nextSymmetric;
}
++symmetricIndex;
}
} }
if (c instanceof SymmetricComponent) { ++stageIndex;
return (SymmetricComponent) c; symmetricIndex = nextStage.getChildCount() - 1;
}
if (!(c instanceof AxialStage) &&
(c.axialMethod == AxialMethod.AFTER))
return null; // Bad component type as "parent"
} }
return null; return null;
} }

View File

@ -551,7 +551,7 @@ public class TestRockets {
} }
} }
// This is an extra stage tacked onto the end of an Estes Alpha III // This is an extra stage tacked onto the end of an Estes Alpha III
// http://www.rocketreviews.com/alpha-iii---estes-221256.html // http://www.rocketreviews.com/alpha-iii---estes-221256.html
// //
// This function is used for unit, integration tests, DO NOT CHANGE WITHOUT UPDATING TESTS // This function is used for unit, integration tests, DO NOT CHANGE WITHOUT UPDATING TESTS
@ -586,7 +586,7 @@ public class TestRockets {
double finRootChord = .05; double finRootChord = .05;
double finTipChord = .03; double finTipChord = .03;
double finSweep = 0.02; double finSweep = 0.02;
double finHeight = 0.05; double finHeight = 0.03;
FinSet finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight); FinSet finset = new TrapezoidFinSet(finCount, finRootChord, finTipChord, finSweep, finHeight);
finset.setName("Booster Fins"); finset.setName("Booster Fins");
finset.setThickness( 0.0032); finset.setThickness( 0.0032);
@ -611,6 +611,14 @@ public class TestRockets {
} }
boosterBody.addChild(boosterMMT); boosterBody.addChild(boosterMMT);
} }
// Tail Cone
Transition boosterTail = new Transition();
boosterTail.setForeRadius(0.012);
boosterTail.setAftRadius(0.01);
boosterTail.setLength(0.005);
boosterTail.setName("Booster Tail Cone");
boosterStage.addChild( boosterTail);
} }
rocket.setSelectedConfiguration( TEST_FCID_1 ); rocket.setSelectedConfiguration( TEST_FCID_1 );

View File

@ -462,9 +462,9 @@ public class FlightConfigurationTest extends BaseTestCase {
assertThat((Class<TrapezoidFinSet>) boosterFinContext0.component.getClass(), equalTo(TrapezoidFinSet.class)); assertThat((Class<TrapezoidFinSet>) boosterFinContext0.component.getClass(), equalTo(TrapezoidFinSet.class));
assertThat(boosterFinContext0.instanceNumber, equalTo(0)); assertThat(boosterFinContext0.instanceNumber, equalTo(0));
final Coordinate boosterFin0Location = boosterFinContext0.getLocation(); final Coordinate boosterFin0Location = boosterFinContext0.getLocation();
assertEquals(boosterFin0Location.x, 1.044, EPSILON); assertEquals(1.044, boosterFin0Location.x, EPSILON);
assertEquals(boosterFin0Location.y, -0.104223611, EPSILON); assertEquals( -0.104223611, boosterFin0Location.y, EPSILON);
assertEquals(boosterFin0Location.z, -0.027223611, EPSILON); assertEquals( -0.027223611, boosterFin0Location.z, EPSILON);
final InstanceContext boosterFinContext1 = finContextList.get(4); final InstanceContext boosterFinContext1 = finContextList.get(4);
assertThat((Class<TrapezoidFinSet>) boosterFinContext1.component.getClass(), equalTo(TrapezoidFinSet.class)); assertThat((Class<TrapezoidFinSet>) boosterFinContext1.component.getClass(), equalTo(TrapezoidFinSet.class));

View File

@ -1207,7 +1207,7 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(0.03423168, coords.x, EPSILON); assertEquals(0.03423168, coords.x, EPSILON);
assertEquals(0.01427544, coords.y, EPSILON); assertEquals(0.01427544, coords.y, EPSILON);
BodyTube bt = new BodyTube(); BodyTube bt = new BodyTube(0.1, 0.1);
bt.addChild(fins); bt.addChild(fins);
FinSetCalc calc = new FinSetCalc(fins); FinSetCalc calc = new FinSetCalc(fins);
FlightConditions conditions = new FlightConditions(null); FlightConditions conditions = new FlightConditions(null);

View File

@ -5,6 +5,7 @@ import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import org.junit.Test; import org.junit.Test;
import net.sf.openrocket.rocketcomponent.position.AngleMethod; import net.sf.openrocket.rocketcomponent.position.AngleMethod;
@ -156,7 +157,84 @@ public class RocketTest extends BaseTestCase {
assertThat(locPost.x, equalTo(0.0)); assertThat(locPost.x, equalTo(0.0));
} }
} }
@Test
public void testAutoSizePreviousComponent() {
Rocket rocket = TestRockets.makeBeta();
final AxialStage sustainer = (AxialStage) rocket.getChild(0);
final AxialStage booster = (AxialStage) rocket.getChild(1);
final double expRadius = 0.012;
{ // test auto-radius within a stage: nose -> body tube
final NoseCone nose = (NoseCone) sustainer.getChild(0);
assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON);
final BodyTube body = (BodyTube) sustainer.getChild(1);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
body.setOuterRadiusAutomatic(true);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
}
{ // test auto-radius within a stage: body tube -> trailing transition
final BodyTube body = (BodyTube) booster.getChild(0);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
final Transition tailCone = (Transition)booster.getChild(1);
assertEquals(" radius match: ", expRadius, tailCone.getForeRadius(), EPSILON);
tailCone.setForeRadiusAutomatic(true);
assertEquals(" trailing transition match: ", expRadius, tailCone.getForeRadius(), EPSILON);
}
{ // test auto-radius across stages: sustainer body -> booster body
BodyTube sustainerBody = (BodyTube) sustainer.getChild(1);
assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON);
BodyTube boosterBody = (BodyTube) booster.getChild(0);
assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON);
boosterBody.setOuterRadiusAutomatic(true);
assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON);
}
}
@Test
public void testAutoSizeNextComponent() {
Rocket rocket = TestRockets.makeBeta();
final AxialStage sustainer = (AxialStage) rocket.getChild(0);
final AxialStage booster = (AxialStage) rocket.getChild(1);
final double expRadius = 0.012;
{ // test auto-radius within a stage: nose <- body tube
System.err.println("## Testing auto-radius: sustainer: nose <- body");
final NoseCone nose = (NoseCone) sustainer.getChild(0);
assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON);
final BodyTube body = (BodyTube) sustainer.getChild(1);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
nose.setAftRadiusAutomatic(true);
assertEquals(" radius match: ", expRadius, nose.getAftRadius(), EPSILON);
}
{ // test auto-radius within a stage: body tube <- trailing transition
System.err.println("## Testing auto-radius: booster: body <- tail");
final BodyTube boosterBody = (BodyTube) booster.getChild(0);
assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON);
final Transition tailCone = (Transition)booster.getChild(1);
assertEquals(" radius match: ", expRadius, tailCone.getForeRadius(), EPSILON);
boosterBody.setOuterRadiusAutomatic(true);
assertEquals(" trailing transition match: ", expRadius, boosterBody.getOuterRadius(), EPSILON);
}
{ // test auto-radius across stages: sustainer body <- booster body
System.err.println("## Testing auto-radius: booster:body -> sustainer:body");
BodyTube sustainerBody = (BodyTube) sustainer.getChild(1);
assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON);
BodyTube boosterBody = (BodyTube) booster.getChild(0);
assertEquals(" radius match: ", expRadius, boosterBody.getOuterRadius(), EPSILON);
sustainerBody.setOuterRadiusAutomatic(true);
assertEquals(" radius match: ", expRadius, sustainerBody.getOuterRadius(), EPSILON);
}
}
@Test @Test
public void testBeta(){ public void testBeta(){
Rocket rocket = TestRockets.makeBeta(); Rocket rocket = TestRockets.makeBeta();

View File

@ -56,27 +56,25 @@ public class TransitionTest extends BaseTestCase {
@Test @Test
public void testVerifyBackwardConicTransition(){ public void testVerifyBackwardConicTransition(){
Transition nose = new Transition(); Transition tail = new Transition();
nose.setType( Transition.Shape.CONICAL); tail.setType( Transition.Shape.CONICAL);
nose.setForeRadius( 1.0); tail.setForeRadius( 1.0);
nose.setAftRadius( 0.5); tail.setAftRadius( 0.5);
nose.setLength( 5.0); tail.setLength( 5.0);
assertEquals("nose cone length is wrong ", 5.0, nose.getLength(), EPSILON );
assertEquals("nose cone fore radius is wrong ", 1.0, nose.getForeRadius(), EPSILON );
assertEquals("nose cone aft radius is wrong ", 0.5, nose.getAftRadius(), EPSILON );
assertThat("nose cone shape type is wrong ", Transition.Shape.CONICAL, equalTo(nose.getType()));
assertEquals("nose cone shape parameter is wrong ", 0.0, nose.getShapeParameter(), EPSILON );
assertEquals("bad shape - conical forward transition", 1.0, nose.getRadius(0.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.9, nose.getRadius(1.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.8, nose.getRadius(2.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.7, nose.getRadius(3.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.6, nose.getRadius(4.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.5, nose.getRadius(5.0), EPSILON );
}
assertEquals("nose cone length is wrong ", 5.0, tail.getLength(), EPSILON );
assertEquals("nose cone fore radius is wrong ", 1.0, tail.getForeRadius(), EPSILON );
assertEquals("nose cone aft radius is wrong ", 0.5, tail.getAftRadius(), EPSILON );
assertThat("nose cone shape type is wrong ", Transition.Shape.CONICAL, equalTo(tail.getType()));
assertEquals("nose cone shape parameter is wrong ", 0.0, tail.getShapeParameter(), EPSILON );
assertEquals("bad shape - conical forward transition", 1.0, tail.getRadius(0.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.9, tail.getRadius(1.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.8, tail.getRadius(2.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.7, tail.getRadius(3.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.6, tail.getRadius(4.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.5, tail.getRadius(5.0), EPSILON );
}
@Test @Test
public void testVerifyOgiveNoseCone(){ public void testVerifyOgiveNoseCone(){
@ -85,7 +83,7 @@ public class TransitionTest extends BaseTestCase {
nose.setForeRadius( 0.0); nose.setForeRadius( 0.0);
nose.setAftRadius( 1.0); nose.setAftRadius( 1.0);
nose.setLength( 8.0); nose.setLength( 8.0);
assertEquals("nose cone length is wrong ", 8.0, nose.getLength(), EPSILON ); assertEquals("nose cone length is wrong ", 8.0, nose.getLength(), EPSILON );
assertEquals("nose cone fore radius is wrong ", 0.0, nose.getForeRadius(), EPSILON ); assertEquals("nose cone fore radius is wrong ", 0.0, nose.getForeRadius(), EPSILON );
assertEquals("nose cone aft radius is wrong ", 1.0, nose.getAftRadius(), EPSILON ); assertEquals("nose cone aft radius is wrong ", 1.0, nose.getAftRadius(), EPSILON );
@ -101,73 +99,67 @@ public class TransitionTest extends BaseTestCase {
assertEquals("bad shape - conical forward transition", 0.93840316661, nose.getRadius(6.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.93840316661, nose.getRadius(6.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.98461174156, nose.getRadius(7.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.98461174156, nose.getRadius(7.0), EPSILON );
assertEquals("bad shape - conical forward transition", 1.0, nose.getRadius(8.0), EPSILON ); assertEquals("bad shape - conical forward transition", 1.0, nose.getRadius(8.0), EPSILON );
} }
@Test @Test
public void testVerifyForwardOgiveTransition(){ public void testVerifyForwardOgiveTransition(){
Transition nose = new Transition(); Transition transition = new Transition();
nose.setType( Transition.Shape.OGIVE); transition.setType( Transition.Shape.OGIVE);
nose.setForeRadius( 0.44135); transition.setForeRadius( 0.44135);
nose.setAftRadius( 1.0); transition.setAftRadius( 1.0);
nose.setLength( 6.0); transition.setLength( 6.0);
assertEquals("nose cone length is wrong ", 6.0, nose.getLength(), EPSILON ); assertEquals("nose cone length is wrong ", 6.0, transition.getLength(), EPSILON );
assertEquals("nose cone fore radius is wrong ", 0.44135, nose.getForeRadius(), EPSILON ); assertEquals("nose cone fore radius is wrong ", 0.44135, transition.getForeRadius(), EPSILON );
assertEquals("nose cone aft radius is wrong ", 1.0, nose.getAftRadius(), EPSILON ); assertEquals("nose cone aft radius is wrong ", 1.0, transition.getAftRadius(), EPSILON );
assertThat("nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(nose.getType())); assertThat("nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(transition.getType()));
assertEquals("nose cone shape parameter is wrong ", 1.0, nose.getShapeParameter(), EPSILON ); assertEquals("nose cone shape parameter is wrong ", 1.0, transition.getShapeParameter(), EPSILON );
assertEquals("bad shape - conical forward transition", 0.44135250736, nose.getRadius(0.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.44135250736, transition.getRadius(0.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.61308144666, nose.getRadius(1.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.61308144666, transition.getRadius(1.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.75290684574, nose.getRadius(2.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.75290684574, transition.getRadius(2.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.86124225056, nose.getRadius(3.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.86124225056, transition.getRadius(3.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.93840316661, nose.getRadius(4.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.93840316661, transition.getRadius(4.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.98461174156, nose.getRadius(5.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.98461174156, transition.getRadius(5.0), EPSILON );
assertEquals("bad shape - conical forward transition", 1.0, nose.getRadius(6.0), EPSILON ); assertEquals("bad shape - conical forward transition", 1.0, transition.getRadius(6.0), EPSILON );
} }
@Test @Test
public void testVerifyBackwardOgiveTransition(){ public void testVerifyBackwardOgiveTransition(){
Transition nose = new Transition(); Transition transition = new Transition();
nose.setType( Transition.Shape.OGIVE); transition.setType( Transition.Shape.OGIVE);
nose.setForeRadius( 1.0); transition.setForeRadius( 1.0);
nose.setAftRadius( 0.44135); transition.setAftRadius( 0.44135);
nose.setLength( 6.0); transition.setLength( 6.0);
assertEquals("nose cone length is wrong ", 6.0, nose.getLength(), EPSILON ); assertEquals("nose cone length is wrong ", 6.0, transition.getLength(), EPSILON );
assertEquals("nose cone fore radius is wrong ", 1.0, nose.getForeRadius(), EPSILON ); assertEquals("nose cone fore radius is wrong ", 1.0, transition.getForeRadius(), EPSILON );
assertEquals("nose cone aft radius is wrong ", 0.44135, nose.getAftRadius(), EPSILON ); assertEquals("nose cone aft radius is wrong ", 0.44135, transition.getAftRadius(), EPSILON );
assertThat("nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(nose.getType())); assertThat("nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(transition.getType()));
assertEquals("nose cone shape parameter is wrong ",1.0, nose.getShapeParameter(), EPSILON ); assertEquals("nose cone shape parameter is wrong ",1.0, transition.getShapeParameter(), EPSILON );
assertEquals("bad shape - conical forward transition", 1.0, nose.getRadius(0.0), EPSILON ); assertEquals("bad shape - conical forward transition", 1.0, transition.getRadius(0.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.98461174156, nose.getRadius(1.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.98461174156, transition.getRadius(1.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.93840316661, nose.getRadius(2.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.93840316661, transition.getRadius(2.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.86124225056, nose.getRadius(3.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.86124225056, transition.getRadius(3.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.75290684574, nose.getRadius(4.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.75290684574, transition.getRadius(4.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.61308144666, nose.getRadius(5.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.61308144666, transition.getRadius(5.0), EPSILON );
assertEquals("bad shape - conical forward transition", 0.44135250736, nose.getRadius(6.0), EPSILON ); assertEquals("bad shape - conical forward transition", 0.44135250736, transition.getRadius(6.0), EPSILON );
} }
@Test @Test
public void testStockIntegration(){ public void testStockIntegration(){
Rocket rocket = TestRockets.makeEstesAlphaIII(); Rocket rocket = TestRockets.makeEstesAlphaIII();
NoseCone nose = (NoseCone)rocket.getChild(0).getChild(0); NoseCone nose = (NoseCone)rocket.getChild(0).getChild(0);
assertEquals("Alpha3 nose cone length is wrong ", 0.07, nose.getLength(), EPSILON ); assertEquals("Alpha3 nose cone length is wrong ", 0.07, nose.getLength(), EPSILON );
assertEquals("Alpha3 nose cone fore radius is wrong ", 0.00, nose.getForeRadius(), EPSILON ); assertEquals("Alpha3 nose cone fore radius is wrong ", 0.00, nose.getForeRadius(), EPSILON );
assertEquals("Alpha3 nose cone aft radius is wrong ", 0.012, nose.getAftRadius(), EPSILON ); assertEquals("Alpha3 nose cone aft radius is wrong ", 0.012, nose.getAftRadius(), EPSILON );
assertThat("Alpha3 nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(nose.getType())); assertThat("Alpha3 nose cone shape type is wrong ", Transition.Shape.OGIVE, equalTo(nose.getType()));
assertEquals("Alpha3 nose cone shape parameter is wrong ", 1.0, nose.getShapeParameter(), EPSILON ); assertEquals("Alpha3 nose cone shape parameter is wrong ", 1.0, nose.getShapeParameter(), EPSILON );
assertEquals("Alpha3 nose cone aft shoulder length is wrong ", 0.02, nose.getAftShoulderLength(), EPSILON ); assertEquals("Alpha3 nose cone aft shoulder length is wrong ", 0.02, nose.getAftShoulderLength(), EPSILON );
assertEquals("Alpha3 nose cone aft shoulder radius is wrong ", 0.011, nose.getAftShoulderRadius(), EPSILON ); assertEquals("Alpha3 nose cone aft shoulder radius is wrong ", 0.011, nose.getAftShoulderRadius(), EPSILON );
} }
} }

View File

@ -172,8 +172,6 @@ public class ComponentPresetChooserDialog extends JDialog {
private JPanel getFilterCheckboxes() { private JPanel getFilterCheckboxes() {
SymmetricComponent sc;
JPanel panel = new JPanel(new MigLayout("ins 0")); JPanel panel = new JPanel(new MigLayout("ins 0"));
/* /*
@ -197,37 +195,40 @@ public class ComponentPresetChooserDialog extends JDialog {
} }
}); });
} }
/* if(component instanceof SymmetricComponent) {
* Add filter by fore diameter final SymmetricComponent curSym = (SymmetricComponent) component;
*/ /*
foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); * Add filter by fore diameter
sc = getPreviousSymmetricComponent(); */
if (sc != null && foreDiameterColumnIndex >= 0) { foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter"));
foreDiameterFilter = new ComponentPresetRowFilter(sc.getAftRadius() * 2.0, foreDiameterColumnIndex); final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent();
panel.add(foreDiameterFilterCheckBox, "wrap"); if (prevSym != null && foreDiameterColumnIndex >= 0) {
foreDiameterFilterCheckBox.addItemListener(new ItemListener() { foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex);
@Override panel.add(foreDiameterFilterCheckBox, "wrap");
public void itemStateChanged(ItemEvent e) { foreDiameterFilterCheckBox.addItemListener(new ItemListener() {
updateFilters(); @Override
} public void itemStateChanged(ItemEvent e) {
}); updateFilters();
} }
});
/* }
* Add filter by aft diameter
*/ /*
aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); * Add filter by aft diameter
sc = getNextSymmetricComponent(); */
if (sc != null && aftDiameterColumnIndex >= 0) { aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter"));
aftDiameterFilter = new ComponentPresetRowFilter(sc.getForeRadius() * 2.0, aftDiameterColumnIndex); final SymmetricComponent nextSym = curSym.getNextSymmetricComponent();
panel.add(aftDiameterFilterCheckBox, "wrap"); if (nextSym != null && aftDiameterColumnIndex >= 0) {
aftDiameterFilterCheckBox.addItemListener(new ItemListener() { aftDiameterFilter = new ComponentPresetRowFilter(nextSym.getForeRadius() * 2.0, aftDiameterColumnIndex);
@Override panel.add(aftDiameterFilterCheckBox, "wrap");
public void itemStateChanged(ItemEvent e) { aftDiameterFilterCheckBox.addItemListener(new ItemListener() {
updateFilters(); @Override
} public void itemStateChanged(ItemEvent e) {
}); updateFilters();
}
});
}
} }
return panel; return panel;
@ -275,28 +276,4 @@ public class ComponentPresetChooserDialog extends JDialog {
componentSelectionTable.setRowFilter(RowFilter.andFilter(filters)); componentSelectionTable.setRowFilter(RowFilter.andFilter(filters));
} }
private SymmetricComponent getPreviousSymmetricComponent() {
RocketComponent c = component;
while (c != null) {
c = c.getPreviousComponent();
if (c instanceof SymmetricComponent) {
return (SymmetricComponent) c;
}
}
return null;
}
private SymmetricComponent getNextSymmetricComponent() {
RocketComponent c = component;
while (c != null) {
c = c.getNextComponent();
if (c instanceof SymmetricComponent) {
return (SymmetricComponent) c;
}
}
return null;
}
} }