Merge pull request #2184 from SiboVG/issue-2171

[#2171] Compute position based on active components
This commit is contained in:
Sibo Van Gool 2023-04-12 22:07:07 +02:00 committed by GitHub
commit a18452c824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -1338,7 +1338,18 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
if( 0 == thisIndex ) { if( 0 == thisIndex ) {
this.position = this.position.setX(0.); this.position = this.position.setX(0.);
}else if( 0 < thisIndex ) { }else if( 0 < thisIndex ) {
RocketComponent referenceComponent = parent.getChild( thisIndex - 1 ); int idx = thisIndex - 1;
RocketComponent referenceComponent = parent.getChild(idx);
while (!getRocket().getSelectedConfiguration().isComponentActive(referenceComponent) && idx > 0) {
idx--;
referenceComponent = parent.getChild(idx);
}
// If previous components are inactive, set this as the new reference point
if (!getRocket().getSelectedConfiguration().isComponentActive(referenceComponent)) {
this.position = this.position.setX(0.);
return;
}
double refLength = referenceComponent.getLength(); double refLength = referenceComponent.getLength();
double refRelX = referenceComponent.getPosition().x; double refRelX = referenceComponent.getPosition().x;

View File

@ -998,7 +998,7 @@ public class MassCalculatorTest extends BaseTestCase {
double expTotalMass = overrideMass; double expTotalMass = overrideMass;
assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, calcTotalMass, EPSILON); assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, calcTotalMass, EPSILON);
double expCMx = 6.484; double expCMx = 5.92;
Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass); Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass);
assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterSetCM.x, EPSILON); assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterSetCM.x, EPSILON);
assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterSetCM.y, EPSILON); assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterSetCM.y, EPSILON);
@ -1052,7 +1052,7 @@ public class MassCalculatorTest extends BaseTestCase {
double expTotalMass = 3.3565872; double expTotalMass = 3.3565872;
assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, boosterData.getMass(), EPSILON); assertEquals(" Booster Launch Mass is incorrect: ", expTotalMass, boosterData.getMass(), EPSILON);
double expCMx = 0.847508988; double expCMx = 0.2835089882645608;
Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass); Coordinate expCM = new Coordinate(expCMx, 0, 0, expTotalMass);
assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterCM.x, EPSILON); assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, boosterCM.x, EPSILON);
assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterCM.y, EPSILON); assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, boosterCM.y, EPSILON);
@ -1099,7 +1099,7 @@ public class MassCalculatorTest extends BaseTestCase {
double calcTotalMass = structure.getMass(); double calcTotalMass = structure.getMass();
assertEquals(" Booster Launch Mass is incorrect: ", expMass, calcTotalMass, EPSILON); assertEquals(" Booster Launch Mass is incorrect: ", expMass, calcTotalMass, EPSILON);
final double expCMx = 1.1191303646438673; final double expCMx = 0.5551303646438673;
Coordinate expCM = new Coordinate(expCMx, 0, 0, expMass); Coordinate expCM = new Coordinate(expCMx, 0, 0, expMass);
assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, structure.getCM().x, EPSILON); assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, structure.getCM().x, EPSILON);
assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, structure.getCM().y, EPSILON); assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, structure.getCM().y, EPSILON);

View File

@ -42,7 +42,7 @@ public class DisableStageTest extends BaseTestCase {
} }
} }
//// Test re-enableing the stage. //// Test re-enabling the stage.
Rocket rocketOriginal = TestRockets.makeEstesAlphaIII(); Rocket rocketOriginal = TestRockets.makeEstesAlphaIII();
Simulation simOriginal = new Simulation(rocketOriginal); Simulation simOriginal = new Simulation(rocketOriginal);
@ -81,7 +81,7 @@ public class DisableStageTest extends BaseTestCase {
compareSims(simRemoved, simDisabled, delta); compareSims(simRemoved, simDisabled, delta);
//// Test re-enableing the stage. //// Test re-enabling the stage.
Rocket rocketOriginal = TestRockets.makeBeta(); Rocket rocketOriginal = TestRockets.makeBeta();
Simulation simOriginal = new Simulation(rocketOriginal); Simulation simOriginal = new Simulation(rocketOriginal);
simOriginal.setFlightConfigurationId(TestRockets.TEST_FCID_1); simOriginal.setFlightConfigurationId(TestRockets.TEST_FCID_1);
@ -173,7 +173,7 @@ public class DisableStageTest extends BaseTestCase {
compareSims(simRemoved, simDisabled, delta); compareSims(simRemoved, simDisabled, delta);
//// Test re-enableing the stage. //// Test re-enabling the stage.
Rocket rocketOriginal = TestRockets.makeFalcon9Heavy(); Rocket rocketOriginal = TestRockets.makeFalcon9Heavy();
TestRockets.addCoreFins(rocketOriginal); TestRockets.addCoreFins(rocketOriginal);
@ -232,7 +232,7 @@ public class DisableStageTest extends BaseTestCase {
} }
} }
//// Test re-enableing the stage. //// Test re-enabling the stage.
Rocket rocketOriginal = TestRockets.makeFalcon9Heavy(); Rocket rocketOriginal = TestRockets.makeFalcon9Heavy();
TestRockets.addCoreFins(rocketOriginal); TestRockets.addCoreFins(rocketOriginal);