From 3501a4ff413c403aa78b261ac23695f660d0372e Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 8 Dec 2022 02:32:47 +0100 Subject: [PATCH] Add unit tests for root points when fin out of parent's bounds --- .../rocketcomponent/FreeformFinSetTest.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java index 8e17dfa71..5dfae5e5a 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java @@ -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();