[fix] Fixed RocketComponent::setAfter() => added unittest in TestRocket => fixed IntegrationTest
This commit is contained in:
parent
6793eaaa04
commit
8ab739a304
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user