[test] Refactored FreeformFinSetTest to de-dup code execution.

This commit is contained in:
Daniel M Williams 2018-12-27 13:31:04 -05:00 committed by Daniel_M_Williams
parent c5733b9b68
commit cf4a935302

View File

@ -4,13 +4,9 @@ import java.awt.geom.Point2D;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;
import net.sf.openrocket.aerodynamics.AerodynamicForces; import net.sf.openrocket.aerodynamics.AerodynamicForces;
import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.FlightConditions;
@ -32,12 +28,6 @@ public class FreeformFinSetTest extends BaseTestCase {
private static final double EPSILON = 1E-6; private static final double EPSILON = 1E-6;
@Test
public void testMultiplicity() {
final FreeformFinSet fins = new FreeformFinSet();
assertEquals(1, fins.getFinCount());
}
private FreeformFinSet testFreeformConvert(FinSet sourceSet) { private FreeformFinSet testFreeformConvert(FinSet sourceSet) {
sourceSet.setName("test-convert-finset"); sourceSet.setName("test-convert-finset");
sourceSet.setBaseRotation(1.1); sourceSet.setBaseRotation(1.1);
@ -86,7 +76,7 @@ public class FreeformFinSetTest extends BaseTestCase {
nose.setName("Nose Fairing"); nose.setName("Nose Fairing");
stage.addChild(nose); stage.addChild(nose);
BodyTube body = new BodyTube(1.0,1.0,0.01); BodyTube body = new BodyTube(2.0,1.0,0.01);
body.setName("Body Tube"); body.setName("Body Tube");
stage.addChild(body); stage.addChild(body);
@ -99,16 +89,17 @@ public class FreeformFinSetTest extends BaseTestCase {
tail.setName("Tail Cone"); tail.setName("Tail Cone");
stage.addChild(tail); stage.addChild(tail);
createFinOnEllipsoidNose(nose); // zero-length body tube -- triggers a whole other class of errors
createFinOnTube(body); final BodyTube phantom = new BodyTube(0., 0.5, 0.01);
createFinOnConicalTransition(tail); phantom.setName("Phantom Body Tube");
body.setOuterRadiusAutomatic(true);
stage.addChild(phantom);
rocket.enableEvents(); rocket.enableEvents();
return rocket; return rocket;
} }
private FreeformFinSet createFinOnEllipsoidNose(NoseCone nose){
private void createFinOnEllipsoidNose(NoseCone nose){
FreeformFinSet fins = new FreeformFinSet(); FreeformFinSet fins = new FreeformFinSet();
fins.setName("test-freeform-finset"); fins.setName("test-freeform-finset");
fins.setFinCount(1); fins.setFinCount(1);
@ -120,11 +111,12 @@ public class FreeformFinSetTest extends BaseTestCase {
new Coordinate( 0.8, 0.9) // y-value should be automaticaly adjusted to snap to body new Coordinate( 0.8, 0.9) // y-value should be automaticaly adjusted to snap to body
}; };
fins.setPoints(points); fins.setPoints(points);
nose.addChild(fins); nose.addChild(fins);
return fins;
} }
private void createFinOnTube(final BodyTube body){ private FreeformFinSet createFinOnTube(final BodyTube body){
// This is a trapezoid: // This is a trapezoid:
// - Height: 1 // - Height: 1
// - Root Chord: 1 // - Root Chord: 1
@ -132,10 +124,11 @@ public class FreeformFinSetTest extends BaseTestCase {
// - Sweep: 1/2 // - Sweep: 1/2
// It can be decomposed into a triangle followed by a rectangle // It can be decomposed into a triangle followed by a rectangle
// +--+ // +--+
// /. |x // /. |
// / . | // / . |
// +=====+ // +=====+
FreeformFinSet fins = new FreeformFinSet(); FreeformFinSet fins = new FreeformFinSet();
fins.setName("TubeBodyFins");
fins.setFinCount(1); fins.setFinCount(1);
Coordinate[] points = new Coordinate[]{ Coordinate[] points = new Coordinate[]{
new Coordinate(0, 0), new Coordinate(0, 0),
@ -147,9 +140,11 @@ public class FreeformFinSetTest extends BaseTestCase {
fins.setAxialOffset( AxialMethod.BOTTOM, 0.0); fins.setAxialOffset( AxialMethod.BOTTOM, 0.0);
body.addChild(fins); body.addChild(fins);
return fins;
} }
private void createFinOnConicalTransition(final Transition body) { private FreeformFinSet createFinOnConicalTransition(final Transition body) {
// ----+ (1) // ----+ (1)
// (0) ----- | // (0) ----- |
// ---+ | // ---+ |
@ -168,6 +163,8 @@ public class FreeformFinSetTest extends BaseTestCase {
fins.setPoints(initPoints); fins.setPoints(initPoints);
body.addChild(fins); body.addChild(fins);
return fins;
} }
// ==================== Test Methods ==================== // ==================== Test Methods ====================
@ -247,8 +244,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeformCMComputation_trapezoidOnTube() { public void testFreeformCMComputation_trapezoidOnTube() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final BodyTube finMount= (BodyTube)rkt.getChild(0).getChild(1); final BodyTube body = (BodyTube)rkt.getChild(0).getChild(1);
final FreeformFinSet fins = (FreeformFinSet)rkt.getChild(0).getChild(1).getChild(0); final FreeformFinSet fins = createFinOnTube(body);
// assert pre-condition: // assert pre-condition:
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
@ -259,8 +256,8 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(finPoints[3], new Coordinate(1.0, 0.0)); assertEquals(finPoints[3], new Coordinate(1.0, 0.0));
final double x0 = fins.getAxialFront(); final double x0 = fins.getAxialFront();
assertEquals(0., x0, EPSILON); assertEquals(1.0, x0, EPSILON);
assertEquals(1.0, finMount.getRadius(x0), EPSILON); assertEquals(1.0, body.getRadius(x0), EPSILON);
// NOTE: this will be relative to the center of the finset -- which is at the center of it's mounted body // NOTE: this will be relative to the center of the finset -- which is at the center of it's mounted body
final Coordinate coords = fins.getCG(); final Coordinate coords = fins.getCG();
@ -273,7 +270,7 @@ public class FreeformFinSetTest extends BaseTestCase {
public void testFreeformCMComputation_triangleOnTransition(){ public void testFreeformCMComputation_triangleOnTransition(){
Rocket rkt = createTemplateRocket(); Rocket rkt = createTemplateRocket();
final Transition finMount = (Transition)rkt.getChild(0).getChild(2); final Transition finMount = (Transition)rkt.getChild(0).getChild(2);
FinSet fins = (FinSet)rkt.getChild(0).getChild(2).getChild(0); final FreeformFinSet fins = createFinOnConicalTransition(finMount);
// assert pre-condition: // assert pre-condition:
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
@ -318,12 +315,12 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeformCMComputation_triangleOnEllipsoid(){ public void testFreeformCMComputation_triangleOnEllipsoid(){
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final Transition body = (Transition) rkt.getChild(0).getChild(0); final NoseCone nose = (NoseCone) rkt.getChild(0).getChild(0);
final FinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(0).getChild(0); final FinSet fins = createFinOnEllipsoidNose(nose);
// assert preconditions // assert preconditions
assertEquals(Shape.ELLIPSOID, body.getType()); assertEquals(Shape.ELLIPSOID, nose.getType());
assertEquals(1.0, body.getLength(), EPSILON); assertEquals(1.0, nose.getLength(), EPSILON);
assertEquals(AxialMethod.TOP, fins.getAxialMethod()); assertEquals(AxialMethod.TOP, fins.getAxialMethod());
assertEquals(0.02, fins.getAxialOffset(), EPSILON); assertEquals(0.02, fins.getAxialOffset(), EPSILON);
@ -359,7 +356,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeformCMComputationTrapezoidExtraPoints() { public void testFreeformCMComputationTrapezoidExtraPoints() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final FreeformFinSet fins = (FreeformFinSet)rkt.getChild(0).getChild(1).getChild(0); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
final FreeformFinSet fins = createFinOnTube(body);
// This is the same trapezoid as previous free form, but it has // This is the same trapezoid as previous free form, but it has
// some extra points along the lines. // some extra points along the lines.
@ -383,7 +381,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeformCMComputationAdjacentPoints() { public void testFreeformCMComputationAdjacentPoints() {
Rocket rkt = createTemplateRocket(); Rocket rkt = createTemplateRocket();
FreeformFinSet fins = (FreeformFinSet)rkt.getChild(0).getChild(1).getChild(0); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
final FreeformFinSet fins = createFinOnTube(body);
// This is the same trapezoid as previous free form, but it has // This is the same trapezoid as previous free form, but it has
// some extra points which are very close to previous points. // some extra points which are very close to previous points.
@ -410,7 +409,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeformFinAddPoint() { public void testFreeformFinAddPoint() {
Rocket rkt = createTemplateRocket(); Rocket rkt = createTemplateRocket();
FreeformFinSet fin = (FreeformFinSet)rkt.getChild(0).getChild(1).getChild(0); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
final FreeformFinSet fin = createFinOnTube(body);
assertEquals(4, fin.getPointCount()); assertEquals(4, fin.getPointCount());
@ -431,8 +431,8 @@ public class FreeformFinSetTest extends BaseTestCase {
public void testSetFirstPoint() throws IllegalFinPointException { public void testSetFirstPoint() throws IllegalFinPointException {
// more transitions trigger more complicated positioning math: // more transitions trigger more complicated positioning math:
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final Transition finMount = (Transition) rkt.getChild(0).getChild(2); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final FreeformFinSet fins = createFinOnConicalTransition(tailCone);
final Coordinate[] initialPoints = fins.getFinPoints(); final Coordinate[] initialPoints = fins.getFinPoints();
// assert pre-conditions: // assert pre-conditions:
@ -440,8 +440,8 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(initialPoints[0], Coordinate.ZERO); assertEquals(initialPoints[0], Coordinate.ZERO);
assertEquals(initialPoints[1], new Coordinate(0.4, 0.2)); assertEquals(initialPoints[1], new Coordinate(0.4, 0.2));
assertEquals(initialPoints[2], new Coordinate(0.4, -0.2)); assertEquals(initialPoints[2], new Coordinate(0.4, -0.2));
assertEquals(1.0, finMount.getLength(), EPSILON); assertEquals(1.0, tailCone.getLength(), EPSILON);
assertEquals(0.8, finMount.getRadius(fins.getAxialFront()), EPSILON); assertEquals(0.8, tailCone.getRadius(fins.getAxialFront()), EPSILON);
{ // case 1: { // case 1:
fins.setAxialOffset( AxialMethod.TOP, 0.1); fins.setAxialOffset( AxialMethod.TOP, 0.1);
@ -588,8 +588,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testSetLastPoint() { public void testSetLastPoint() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
Transition finMount = (Transition) rkt.getChild(0).getChild(2); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final FreeformFinSet fins = createFinOnConicalTransition(tailCone);
final Coordinate[] initialPoints = fins.getFinPoints(); final Coordinate[] initialPoints = fins.getFinPoints();
final int lastIndex = initialPoints.length - 1; final int lastIndex = initialPoints.length - 1;
final double xf = initialPoints[lastIndex].x; final double xf = initialPoints[lastIndex].x;
@ -599,8 +599,8 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(initialPoints[0], Coordinate.ZERO); assertEquals(initialPoints[0], Coordinate.ZERO);
assertEquals(initialPoints[1], new Coordinate(0.4, 0.2)); assertEquals(initialPoints[1], new Coordinate(0.4, 0.2));
assertEquals(initialPoints[2], new Coordinate(0.4, -0.2)); assertEquals(initialPoints[2], new Coordinate(0.4, -0.2));
assertEquals(1.0, finMount.getLength(), EPSILON); assertEquals(1.0, tailCone.getLength(), EPSILON);
assertEquals(0.8, finMount.getRadius(fins.getAxialFront()), EPSILON); assertEquals(0.8, tailCone.getRadius(fins.getAxialFront()), EPSILON);
{ // case 1: { // case 1:
fins.setAxialOffset( AxialMethod.TOP, 0.1); fins.setAxialOffset( AxialMethod.TOP, 0.1);
@ -753,7 +753,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testSetInteriorPoint() { public void testSetInteriorPoint() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
{ // preconditions // initial points { // preconditions // initial points
final Coordinate[] initialPoints = fins.getFinPoints(); final Coordinate[] initialPoints = fins.getFinPoints();
@ -796,19 +797,15 @@ public class FreeformFinSetTest extends BaseTestCase {
} }
@Test @Test
public void testSetAllPoints() { public void testSetAllPointsOnPhantomBody() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final AxialStage stage = (AxialStage) rkt.getChild(0); final BodyTube phantomBody = (BodyTube) rkt.getChild(0).getChild(3);
{ // setup // mount { // setup // mount
BodyTube body = new BodyTube(0.0, 1.0, 0.002); assertEquals(0.5, phantomBody.getOuterRadius(), EPSILON);
body.setName("Phantom Body Tube"); assertEquals(0.0, phantomBody.getLength(), EPSILON);
body.setOuterRadiusAutomatic(true); }{
stage.addChild(body, 2); final FreeformFinSet fins = new FreeformFinSet();
assertEquals(1.0, body.getOuterRadius(), EPSILON);
assertEquals(0.0, body.getLength(), EPSILON);
FreeformFinSet fins = new FreeformFinSet();
fins.setFinCount(4); fins.setFinCount(4);
Coordinate[] points = new Coordinate[]{ Coordinate[] points = new Coordinate[]{
new Coordinate(0.0, 0.0), new Coordinate(0.0, 0.0),
@ -819,10 +816,11 @@ public class FreeformFinSetTest extends BaseTestCase {
}; };
fins.setPoints(points); fins.setPoints(points);
body.addChild(fins); phantomBody.addChild(fins);
assertEquals(1, phantomBody.getChildCount());
}{ // postconditions }{ // postconditions
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final FreeformFinSet fins = (FreeformFinSet) phantomBody.getChild(0);
final Coordinate[] postPoints = fins.getFinPoints(); final Coordinate[] postPoints = fins.getFinPoints();
assertEquals(6, postPoints.length); assertEquals(6, postPoints.length);
@ -849,21 +847,21 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(0.0, fins.getLength(), EPSILON); assertEquals(0.0, fins.getLength(), EPSILON);
assertEquals(0.0, fins.getFinFront().x, EPSILON); assertEquals(0.0, fins.getFinFront().x, EPSILON);
assertEquals(1.0, fins.getFinFront().y, EPSILON); assertEquals(0.5, fins.getFinFront().y, EPSILON);
} }
} }
@Test @Test
public void testSetFirstPoint_testNonIntersection() { public void testSetFirstPoint_testNonIntersection() {
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final Transition mount = (Transition) rkt.getChild(0).getChild(2); final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
assertEquals( 1, fins.getFinCount()); assertEquals( 1, fins.getFinCount());
assertEquals( 3, fins.getPointCount()); assertEquals( 3, fins.getPointCount());
assertEquals( AxialMethod.TOP, fins.getAxialMethod()); assertEquals( AxialMethod.TOP, fins.getAxialMethod());
assertEquals( 0.4, fins.getAxialOffset(), EPSILON); // pre-condition assertEquals( 0.4, fins.getAxialOffset(), EPSILON); // pre-condition
assertEquals( 1.0, mount.getLength(), EPSILON); assertEquals( 1.0, tailCone.getLength(), EPSILON);
// fin offset: 0.4 -> 0.59 (just short of prev fin end) // fin offset: 0.4 -> 0.59 (just short of prev fin end)
// fin end: 0.4 ~> min root chord // fin end: 0.4 ~> min root chord
@ -888,8 +886,9 @@ public class FreeformFinSetTest extends BaseTestCase {
public void testSetPoint_otherPoint() throws IllegalFinPointException { public void testSetPoint_otherPoint() throws IllegalFinPointException {
// combine the simple case with the complicated to ensure that the simple case is flagged, tested, and debugged before running the more complicated case... // combine the simple case with the complicated to ensure that the simple case is flagged, tested, and debugged before running the more complicated case...
{ // setting points on a Tube Body is the simpler case. Test this first: { // setting points on a Tube Body is the simpler case. Test this first:
Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final FreeformFinSet fins = createFinOnConicalTransition(tailCone);
// all points are restricted to be outside the parent body: // all points are restricted to be outside the parent body:
Coordinate exp_pt = fins.getFinPoints()[0]; Coordinate exp_pt = fins.getFinPoints()[0];
@ -900,9 +899,9 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals( 0.0, act_pt.y, EPSILON); assertEquals( 0.0, act_pt.y, EPSILON);
} }
{ // more transitions trigger more complicated positioning math: { // more transitions trigger more complicated positioning math:
Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
assertEquals( 1, fins.getFinCount()); final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
Coordinate act_p_l; Coordinate act_p_l;
Coordinate exp_p_l; Coordinate exp_p_l;
@ -921,9 +920,9 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testSetOffset_triggerClampCorrection() { public void testSetOffset_triggerClampCorrection() {
// test correction of last point due to moving entire fin: // test correction of last point due to moving entire fin:
Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
Transition body = (Transition) rkt.getChild(0).getChild(2); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
final int lastIndex = fins.getPointCount()-1; final int lastIndex = fins.getPointCount()-1;
@ -931,7 +930,7 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals( 0.4, initXOffset, EPSILON); // pre-condition assertEquals( 0.4, initXOffset, EPSILON); // pre-condition
final double newXTop = 0.85; final double newXTop = 0.85;
final double expFinOffset = 0.6; final double expFinOffset = 0.6;
final double expLength = body.getLength() - expFinOffset; final double expLength = tailCone.getLength() - expFinOffset;
fins.setAxialOffset( AxialMethod.TOP, newXTop); fins.setAxialOffset( AxialMethod.TOP, newXTop);
// fin start: 0.4 => 0.8 [body] // fin start: 0.4 => 0.8 [body]
// fin end: 0.8 => 0.99 [body] // fin end: 0.8 => 0.99 [body]
@ -945,7 +944,7 @@ public class FreeformFinSetTest extends BaseTestCase {
} }
@Test @Test
public void testComputeCM_mountlesFin(){ public void testComputeCM_mountlessFin(){
// This is a trapezoid. Height 1, root 1, tip 1/2 no sweep. // This is a trapezoid. Height 1, root 1, tip 1/2 no sweep.
// It can be decomposed into a rectangle followed by a triangle // It can be decomposed into a rectangle followed by a triangle
// +---+ // +---+
@ -970,11 +969,11 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testTranslatePoints(){ public void testTranslatePoints(){
final Rocket rkt = new Rocket(); final Rocket rkt = createTemplateRocket();
final AxialStage stg = new AxialStage(); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
rkt.addChild(stg); final FreeformFinSet fin = this.createFinOnTube(body);
BodyTube body = new BodyTube(2.0, 0.01);
stg.addChild(body); assertNotNull(fin.getParent());
// Fin length = 1 // Fin length = 1
// Body Length = 2 // Body Length = 2
@ -982,35 +981,46 @@ public class FreeformFinSetTest extends BaseTestCase {
// / | // / |
// / | // / |
// +---+-----+---+ // +---+-----+---+
// final Coordinate[] expectPoints = new Coordinate[]{
FreeformFinSet fins = new FreeformFinSet(); Coordinate.ZERO,
fins.setFinCount(1);
Coordinate[] initPoints = new Coordinate[] {
new Coordinate(0, 0),
new Coordinate(0.5, 1), new Coordinate(0.5, 1),
new Coordinate(1, 1), new Coordinate(1, 1),
new Coordinate(1, 0) new Coordinate(1, 0)
}; };
fins.setPoints(initPoints);
body.addChild(fins); final Coordinate[] finPoints = fin.getFinPoints();
assertEquals(4, finPoints.length);
assertEquals(expectPoints[1], finPoints[1]);
assertEquals(expectPoints[2], finPoints[2]);
assertEquals(expectPoints[3], finPoints[3]);
// mounting body:
assertEquals(body.getLength(), 2.0, EPSILON);
assertEquals(fin.getAxialMethod(), AxialMethod.BOTTOM);
assertEquals(fin.getAxialOffset(), 0.0, EPSILON);
final AxialMethod[] pos={AxialMethod.TOP, AxialMethod.MIDDLE, AxialMethod.MIDDLE, AxialMethod.BOTTOM}; final AxialMethod[] pos={AxialMethod.TOP, AxialMethod.MIDDLE, AxialMethod.MIDDLE, AxialMethod.BOTTOM};
final double[] offs = {1.0, 0.0, 0.4, -0.2}; final double[] offs = {1.0, 0.0, 0.4, -0.2};
final double[] expOffs = {1.0, 0.5, 0.9, 0.8}; final double[] expOffs = {1.0, 0.5, 0.9, 0.8};
for( int caseIndex=0; caseIndex < pos.length; ++caseIndex ){ for( int caseIndex=0; caseIndex < pos.length; ++caseIndex ){
fins.setAxialOffset( pos[caseIndex], offs[caseIndex]); fin.setAxialOffset( pos[caseIndex], offs[caseIndex]);
final double x_delta = fins.getAxialOffset(AxialMethod.TOP);
Coordinate actualPoints[] = fins.getFinPoints(); assertEquals(fin.getAxialMethod(), pos[caseIndex]);
assertEquals(fin.getAxialOffset(), offs[caseIndex], EPSILON);
final String rawPointDescr = "\n"+fins.toDebugDetail().toString()+"\n>> axial offset: "+x_delta; final double x_delta = fin.getAxialOffset(AxialMethod.TOP);
final Coordinate[] actualPoints = fin.getFinPoints();
final String rawPointDescr = "\n"+fin.toDebugDetail().toString()+"\n>> axial offset: "+x_delta;
Coordinate[] displayPoints = FinSet.translatePoints( actualPoints, x_delta, 0); Coordinate[] displayPoints = FinSet.translatePoints( actualPoints, x_delta, 0);
for( int index=0; index < displayPoints.length; ++index){ for( int index=0; index < displayPoints.length; ++index){
assertEquals(String.format("Bad Fin Position.x (%6.2g via:%s at point: %d) %s\n",offs[caseIndex], pos[caseIndex].name(), index, rawPointDescr), assertEquals(String.format("Bad Fin Position.x (%6.2g via:%s at point: %d) %s\n",offs[caseIndex], pos[caseIndex].name(), index, rawPointDescr),
(initPoints[index].x + expOffs[caseIndex]), displayPoints[index].x, EPSILON); (expectPoints[index].x + expOffs[caseIndex]), displayPoints[index].x, EPSILON);
assertEquals(String.format("Bad Fin Position.y (%6.2g via:%s at point: %d) %s\n",offs[caseIndex], pos[caseIndex].name(), index, rawPointDescr), assertEquals(String.format("Bad Fin Position.y (%6.2g via:%s at point: %d) %s\n",offs[caseIndex], pos[caseIndex].name(), index, rawPointDescr),
initPoints[index].y, displayPoints[index].y, EPSILON); expectPoints[index].y, displayPoints[index].y, EPSILON);
} }
} }
@ -1018,11 +1028,9 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testForIntersection_false() { public void testForIntersection_false() {
final Rocket rkt = new Rocket(); final Rocket rkt = createTemplateRocket();
final AxialStage stg = new AxialStage(); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
rkt.addChild(stg); final FreeformFinSet fins = createFinOnTube(body);
BodyTube body = new BodyTube(2.0, 0.01);
stg.addChild(body);
// Fin length = 1 // Fin length = 1
// Body Length = 2 // Body Length = 2
@ -1030,29 +1038,22 @@ public class FreeformFinSetTest extends BaseTestCase {
// / | // / |
// / | // / |
// +---+-----+---+ // +---+-----+---+
// final Coordinate[] finPoints = fins.getFinPoints();
FreeformFinSet fins = new FreeformFinSet(); assertEquals(4, finPoints.length);
fins.setFinCount(1); assertEquals(finPoints[0], Coordinate.ZERO);
Coordinate[] initPoints = new Coordinate[] { assertEquals(finPoints[1], new Coordinate(0.5, 1.0));
new Coordinate(0, 0), assertEquals(finPoints[2], new Coordinate(1.0, 1.0));
new Coordinate(0.5, 1), assertEquals(finPoints[3], new Coordinate(1.0, 0.0));
new Coordinate(1, 1),
new Coordinate(1, 0)
};
fins.setPoints(initPoints);
body.addChild(fins);
assertFalse( " Fin detects false positive intersection in fin points: ", fins.intersects()); assertFalse( " Fin detects false positive intersection in fin points: ", fins.intersects());
} }
@Test @Test
public void testForIntersection_true() { public void testForIntersection_true() {
final Rocket rkt = new Rocket(); final Rocket rkt = createTemplateRocket();
final AxialStage stg = new AxialStage(); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
rkt.addChild(stg); final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
BodyTube body = new BodyTube(2.0, 0.01);
stg.addChild(body);
//
// An obviously intersecting fin: // An obviously intersecting fin:
// [2] +-----+ [1] // [2] +-----+ [1]
// \ / // \ /
@ -1062,8 +1063,6 @@ public class FreeformFinSetTest extends BaseTestCase {
// [0] / \ [3] // [0] / \ [3]
// +---+-----+---+ // +---+-----+---+
// = +x => // = +x =>
FreeformFinSet fins = new FreeformFinSet();
fins.setFinCount(1);
Coordinate[] initPoints = new Coordinate[] { Coordinate[] initPoints = new Coordinate[] {
new Coordinate(0, 0), new Coordinate(0, 0),
new Coordinate(1, 1), new Coordinate(1, 1),
@ -1072,7 +1071,6 @@ public class FreeformFinSetTest extends BaseTestCase {
}; };
// this line throws an exception? // this line throws an exception?
fins.setPoints(initPoints); fins.setPoints(initPoints);
body.addChild(fins);
// this *already* has detected the intersection, and aborted... // this *already* has detected the intersection, and aborted...
Coordinate p1 = fins.getFinPoints()[1]; Coordinate p1 = fins.getFinPoints()[1];
@ -1083,12 +1081,10 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testForIntersectionAtFirstLast() { public void testForIntersectionAtFirstLast() {
final Rocket rkt = new Rocket(); final Rocket rkt = createTemplateRocket();
final AxialStage stg = new AxialStage(); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
rkt.addChild(stg); final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
BodyTube body = new BodyTube(2.0, 0.01);
stg.addChild(body);
//
// An obviously intersecting fin: // An obviously intersecting fin:
// [2] +---+ [1] // [2] +---+ [1]
// | / // | /
@ -1096,8 +1092,6 @@ public class FreeformFinSetTest extends BaseTestCase {
// [0]|/ [3] // [0]|/ [3]
// +---+-----+---+ // +---+-----+---+
// = +x => // = +x =>
FreeformFinSet fins = new FreeformFinSet();
fins.setFinCount(1);
Coordinate[] initPoints = new Coordinate[] { Coordinate[] initPoints = new Coordinate[] {
new Coordinate(0, 0), new Coordinate(0, 0),
new Coordinate(0, 1), new Coordinate(0, 1),
@ -1106,7 +1100,6 @@ public class FreeformFinSetTest extends BaseTestCase {
}; };
// this line throws an exception? // this line throws an exception?
fins.setPoints(initPoints); fins.setPoints(initPoints);
body.addChild(fins);
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
@ -1173,10 +1166,12 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testGenerateBodyPointsOnBodyTube(){ public void testGenerateBodyPointsOnBodyTube(){
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(1).getChild(0); final BodyTube body = (BodyTube) rkt.getChild(0).getChild(1);
final FreeformFinSet fins = this.createFinOnTube(body);
final Coordinate finFront = fins.getFinFront();
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
final Coordinate[] finPointsFromBody = FinSet.translatePoints( finPoints, 0.0, fins.getFinFront().y); final Coordinate[] finPointsFromBody = FinSet.translatePoints( finPoints, finFront.x, finFront.y);
{ // body points (relative to body) { // body points (relative to body)
final Coordinate[] mountPoints = fins.getMountPoints(); final Coordinate[] mountPoints = fins.getMountPoints();
@ -1201,7 +1196,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testGenerateBodyPointsOnConicalTransition(){ public void testGenerateBodyPointsOnConicalTransition(){
final Rocket rkt = createTemplateRocket(); final Rocket rkt = createTemplateRocket();
final FreeformFinSet fins = (FreeformFinSet) rkt.getChild(0).getChild(2).getChild(0); final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
@ -1228,8 +1224,8 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testGenerateBodyPointsOnEllipsoidNose(){ public void testGenerateBodyPointsOnEllipsoidNose(){
final Rocket rocket = createTemplateRocket(); final Rocket rocket = createTemplateRocket();
final Transition body = (Transition)rocket.getChild(0).getChild(0); final NoseCone nose = (NoseCone) rocket.getChild(0).getChild(0);
final FinSet fins = (FreeformFinSet) body.getChild(0); final FreeformFinSet fins = this.createFinOnEllipsoidNose(nose);
final Coordinate finFront = fins.getFinFront(); final Coordinate finFront = fins.getFinFront();
final Coordinate[] finPoints = fins.getFinPoints(); final Coordinate[] finPoints = fins.getFinPoints();
@ -1245,7 +1241,7 @@ public class FreeformFinSetTest extends BaseTestCase {
// ?? SMOKING GUN: // ?? SMOKING GUN:
// ?? is this y-value of the fin not getting snapped to the body? // ?? is this y-value of the fin not getting snapped to the body?
assertEquals(body.getRadius(0.8+finFront.x) - finFront.y, finPoints[3].y, EPSILON); assertEquals(nose.getRadius(0.8+finFront.x) - finFront.y, finPoints[3].y, EPSILON);
assertEquals("incorrect body points! ", 0.78466912, finPoints[3].y, EPSILON); assertEquals("incorrect body points! ", 0.78466912, finPoints[3].y, EPSILON);
@ -1274,7 +1270,7 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(String.format("Root points @ %d :: x coordinate mismatch!", testIndex), assertEquals(String.format("Root points @ %d :: x coordinate mismatch!", testIndex),
expectedX[testCase], rootPoints[testIndex].x, EPSILON); expectedX[testCase], rootPoints[testIndex].x, EPSILON);
assertEquals(String.format("Root points @ %d :: y coordinate mismatch!", testIndex), assertEquals(String.format("Root points @ %d :: y coordinate mismatch!", testIndex),
body.getRadius(rootPoints[testIndex].x + finFront.x) - finFront.y, rootPoints[testIndex].y, EPSILON); nose.getRadius(rootPoints[testIndex].x + finFront.x) - finFront.y, rootPoints[testIndex].y, EPSILON);
} }
} }
}{ // body points (relative to body) }{ // body points (relative to body)
@ -1301,7 +1297,7 @@ public class FreeformFinSetTest extends BaseTestCase {
assertEquals(String.format("Body points @ %d :: x coordinate mismatch!", testIndex), assertEquals(String.format("Body points @ %d :: x coordinate mismatch!", testIndex),
expectedX[testCase], mountPoints[testIndex].x, EPSILON); expectedX[testCase], mountPoints[testIndex].x, EPSILON);
assertEquals(String.format("Body points @ %d :: y coordinate mismatch!", testIndex), assertEquals(String.format("Body points @ %d :: y coordinate mismatch!", testIndex),
body.getRadius(mountPoints[testIndex].x), mountPoints[testIndex].y, EPSILON); nose.getRadius(mountPoints[testIndex].x), mountPoints[testIndex].y, EPSILON);
} }
} }
} }
@ -1309,10 +1305,7 @@ public class FreeformFinSetTest extends BaseTestCase {
@Test @Test
public void testFreeFormCMWithNegativeY() throws Exception { public void testFreeFormCMWithNegativeY() throws Exception {
// A user submitted an ork file which could not be simulated because the fin // A user submitted an ork file which could not be simulated.
// was constructed on a tail cone. It so happened that for one pair of points
// y_n = - y_(n+1) which caused a divide by zero and resulted in CGx = NaN.
//
// This Fin set is constructed to have the same problem. It is a square and rectangle // This Fin set is constructed to have the same problem. It is a square and rectangle
// where the two trailing edge corners of the rectangle satisfy y_0 = -y_1 // where the two trailing edge corners of the rectangle satisfy y_0 = -y_1
// //
@ -1330,9 +1323,7 @@ public class FreeformFinSetTest extends BaseTestCase {
// | // |
// | // |
FreeformFinSet fins = new FreeformFinSet(); FreeformFinSet fins = new FreeformFinSet();
fins.setCrossSection( CrossSection.SQUARE ); // to ensure uniform density fins.setAxialOffset( AxialMethod.BOTTOM, -1.0);
fins.setFinCount(1);
// fins.setAxialOffset( Position.BOTTOM, 1.0); // ERROR: no parent!
Coordinate[] points = new Coordinate[] { Coordinate[] points = new Coordinate[] {
new Coordinate(0, 0), new Coordinate(0, 0),
new Coordinate(0, 1), new Coordinate(0, 1),
@ -1341,26 +1332,24 @@ public class FreeformFinSetTest extends BaseTestCase {
new Coordinate(1, -1), new Coordinate(1, -1),
new Coordinate(1, 0) new Coordinate(1, 0)
}; };
fins.setPoints(points); fins.setPoints(points);
Coordinate coords = fins.getCG();
assertEquals(3.0, fins.getPlanformArea(), EPSILON); System.err.println(fins.toDebugDetail());
assertEquals(3.5 / 3.0, coords.x, EPSILON);
assertEquals(0.5 / 3.0, coords.y, EPSILON);
fins.setPoints( points); fins.setPoints( points);
fins.setFilletRadius( 0.0); fins.setFilletRadius( 0.0);
fins.setTabHeight( 0.0); fins.setTabHeight( 0.0);
fins.setCrossSection( CrossSection.SQUARE ); // to ensure uniform density
fins.setMaterial( Material.newMaterial(Type.BULK, "dummy", 1.0, true)); fins.setMaterial( Material.newMaterial(Type.BULK, "dummy", 1.0, true));
// assertEquals( 3.0, fins.getFinWettedArea(), EPSILON); assertEquals( 3.0, fins.getPlanformArea(), EPSILON);
//
// Coordinate cg = fins.getCG();
// assertEquals( 1.1666, cg.x, EPSILON);
// assertEquals( 0.1666, cg.y, EPSILON);
// assertEquals( 0.0, cg.z, EPSILON);
// assertEquals( 0.009, cg.weight, EPSILON);
final Coordinate cg = fins.getCG();
assertEquals(3.0, fins.getPlanformArea(), EPSILON);
assertEquals(3.5 / 3.0, cg.x, EPSILON);
assertEquals(0.5 / 3.0, cg.y, EPSILON);
assertEquals( 0.0, cg.z, EPSILON);
assertEquals( 0.009, cg.weight, EPSILON);
} }
} }