Add unit tests for root points when fin out of parent's bounds

This commit is contained in:
SiboVG 2022-12-08 02:32:47 +01:00
parent 0956b9e956
commit 3501a4ff41

View File

@ -1310,6 +1310,119 @@ public class FreeformFinSetTest extends BaseTestCase {
}
}
@Test
public void testGenerateBodyPointsWhenFinOutsideParentBounds() {
final Rocket rkt = createTemplateRocket();
final Transition tailCone = (Transition) rkt.getChild(0).getChild(2);
final FreeformFinSet fins = this.createFinOnConicalTransition(tailCone);
final Coordinate[] initialPoints = fins.getFinPoints();
assertEquals(1.0, tailCone.getLength(), EPSILON);
{ // move first point out of bounds, keep last point in bounds
fins.setAxialOffset(AxialMethod.TOP, 0);
fins.setPoints(initialPoints);
assertEquals(0f, fins.getFinFront().x, EPSILON);
assertEquals(1f, fins.getFinFront().y, EPSILON);
// Move first point
fins.setPoint(0, -0.1, 0.1f);
final Coordinate[] rootPoints = fins.getRootPoints();
assertEquals(3, rootPoints.length);
assertEquals("incorrect body points! ", 0f, rootPoints[0].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[0].y, EPSILON);
assertEquals("incorrect body points! ", 0.1f, rootPoints[1].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[1].y, EPSILON);
assertEquals("incorrect body points! ", 0.5f, rootPoints[2].x, EPSILON);
assertEquals("incorrect body points! ", -0.2f, rootPoints[2].y, EPSILON);
} { // move both first and last point out of bounds to the left
fins.setAxialOffset(AxialMethod.TOP, 0);
fins.setPoints(initialPoints);
assertEquals(0f, fins.getFinFront().x, EPSILON);
assertEquals(1f, fins.getFinFront().y, EPSILON);
// Move first and last point
fins.setPoint(0, -0.2, 0.1f);
fins.setPoint(fins.getPointCount()-1, 0.1, 0.1f);
final Coordinate[] rootPoints = fins.getRootPoints();
assertEquals(2, rootPoints.length);
assertEquals("incorrect body points! ", 0f, rootPoints[0].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[0].y, EPSILON);
assertEquals("incorrect body points! ", 0.1f, rootPoints[1].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[1].y, EPSILON);
} { // move last point out of bounds, keep first point in bounds
fins.setPoints(initialPoints);
fins.setAxialOffset(AxialMethod.BOTTOM, fins.getLength());
assertEquals(1f, fins.getFinFront().x, EPSILON);
assertEquals(0.5f, fins.getFinFront().y, EPSILON);
// Move first point
fins.setPoint(0, -0.1f, 0.1f);
fins.setPoint(fins.getPointCount()-1, 0.2f, 0f);
final Coordinate[] rootPoints = fins.getRootPoints();
assertEquals(3, rootPoints.length);
assertEquals("incorrect body points! ", 0f, rootPoints[0].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[0].y, EPSILON);
assertEquals("incorrect body points! ", 0.1f, rootPoints[1].x, EPSILON);
assertEquals("incorrect body points! ", -0.05f, rootPoints[1].y, EPSILON);
assertEquals("incorrect body points! ", 0.2f, rootPoints[2].x, EPSILON);
assertEquals("incorrect body points! ", -0.05f, rootPoints[2].y, EPSILON);
} { // move both first and last point out of bounds to the right
fins.setPoints(initialPoints);
fins.setAxialOffset(AxialMethod.BOTTOM, fins.getLength());
assertEquals(1f, fins.getFinFront().x, EPSILON);
assertEquals(0.5f, fins.getFinFront().y, EPSILON);
// Move first and last point
fins.setPoint(0, 0.1, 0.1f);
fins.setPoint(fins.getPointCount()-1, 0.2, 0.1f);
final Coordinate[] rootPoints = fins.getRootPoints();
assertEquals(2, rootPoints.length);
assertEquals("incorrect body points! ", 0f, rootPoints[0].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[0].y, EPSILON);
assertEquals("incorrect body points! ", 0.2f, rootPoints[1].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[1].y, EPSILON);
} { // move first point out of bounds to the left, and last point out of bounds to the right
fins.setAxialOffset(AxialMethod.TOP, 0);
fins.setPoints(initialPoints);
assertEquals(0, fins.getFinFront().x, EPSILON);
assertEquals(1, fins.getFinFront().y, EPSILON);
// Move first and last point
fins.setPoint(0, -0.1, 0.1f);
fins.setPoint(fins.getPointCount()-1, 1.2, -0.1f);
final Coordinate[] rootPoints = fins.getRootPoints();
assertEquals(4, rootPoints.length);
assertEquals("incorrect body points! ", 0f, rootPoints[0].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[0].y, EPSILON);
assertEquals("incorrect body points! ", 0.1f, rootPoints[1].x, EPSILON);
assertEquals("incorrect body points! ", 0f, rootPoints[1].y, EPSILON);
assertEquals("incorrect body points! ", 1.1f, rootPoints[2].x, EPSILON);
assertEquals("incorrect body points! ", -0.5f, rootPoints[2].y, EPSILON);
assertEquals("incorrect body points! ", 1.2f, rootPoints[3].x, EPSILON);
assertEquals("incorrect body points! ", -0.5f, rootPoints[3].y, EPSILON);
}
}
@Test
public void testFreeFormCMWithNegativeY() throws Exception {
final Rocket rkt = createTemplateRocket();