From 8ab739a30481ef8b6872057e308939d2c701d2fa Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 27 Oct 2018 15:43:04 -0400 Subject: [PATCH] [fix] Fixed RocketComponent::setAfter() => added unittest in TestRocket => fixed IntegrationTest --- .../rocketcomponent/RocketComponent.java | 12 +++++++---- .../rocketcomponent/RocketTest.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index b004c22e1..fc20dc813 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1003,16 +1003,19 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab return; } + this.axialMethod = AxialMethod.AFTER; + this.axialOffset = 0.; + // if first component in the stage. => position from the top of the parent final int thisIndex = this.parent.getChildPosition( this ); - if( 0 < thisIndex ) { + if( 0 == thisIndex ) { + this.position = this.position.setX(0.); + }else if( 0 < thisIndex ) { RocketComponent referenceComponent = parent.getChild( thisIndex - 1 ); double refLength = referenceComponent.getLength(); double refRelX = referenceComponent.getPosition().x; - this.axialMethod = AxialMethod.AFTER; - this.axialOffset = 0.; this.position = this.position.setX(refRelX + refLength); } } @@ -1432,8 +1435,9 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab this.checkComponentStructure(); component.checkComponentStructure(); - updateBounds(); fireAddRemoveEvent(component); + updateBounds(); + return true; } return false; diff --git a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java index c37536cfe..c26158c73 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertThat; import org.junit.Test; +import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.rocketcomponent.position.AngleMethod; import net.sf.openrocket.rocketcomponent.position.RadiusMethod; import net.sf.openrocket.util.Coordinate; @@ -137,6 +138,26 @@ public class RocketTest extends BaseTestCase { } } + @Test + public void testRemoveReadjustLocation() { + final Rocket rocket = TestRockets.makeEstesAlphaIII(); + + { + BodyTube bodyPrior = (BodyTube)rocket.getChild(0).getChild(1); + Coordinate locPrior = bodyPrior.getComponentLocations()[0]; + assertThat(locPrior.x, equalTo(0.07)); + } + + // remove the nose cone, causing the bodytube to reposition: + rocket.getChild(0).removeChild(0); + + { + BodyTube tubePost = (BodyTube)rocket.getChild(0).getChild(0); + Coordinate locPost = tubePost.getComponentLocations()[0]; + assertThat(locPost.x, equalTo(0.0)); + } + } + @Test public void testBeta(){ Rocket rocket = TestRockets.makeBeta();