Store separation time in data branch
This commit is contained in:
parent
64d0d7e022
commit
6ebf1ed6e4
@ -27,6 +27,7 @@ import info.openrocket.core.util.ModID;
|
|||||||
public class FlightDataBranch extends DataBranch<FlightDataType> {
|
public class FlightDataBranch extends DataBranch<FlightDataType> {
|
||||||
private double timeToOptimumAltitude = Double.NaN;
|
private double timeToOptimumAltitude = Double.NaN;
|
||||||
private double optimumAltitude = Double.NaN;
|
private double optimumAltitude = Double.NaN;
|
||||||
|
private double separationTime = Double.NaN;
|
||||||
private final ArrayList<FlightEvent> events = new ArrayList<>();
|
private final ArrayList<FlightEvent> events = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,6 +184,9 @@ public class FlightDataBranch extends DataBranch<FlightDataType> {
|
|||||||
public void addEvent(FlightEvent event) {
|
public void addEvent(FlightEvent event) {
|
||||||
mutable.check();
|
mutable.check();
|
||||||
events.add(event);
|
events.add(event);
|
||||||
|
if (event.getType() == FlightEvent.Type.STAGE_SEPARATION) {
|
||||||
|
separationTime = event.getTime();
|
||||||
|
}
|
||||||
modID = new ModID();
|
modID = new ModID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +229,35 @@ public class FlightDataBranch extends DataBranch<FlightDataType> {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the time of the stage separation event.
|
||||||
|
* @return the time of the stage separation event, or NaN if no separation event has occurred.
|
||||||
|
*/
|
||||||
|
public double getSeparationTime() {
|
||||||
|
return separationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the data index corresponding to the given time.
|
||||||
|
* @param time the time to search for
|
||||||
|
* @return the data index corresponding to the given time, or -1 if the time is not found.
|
||||||
|
*/
|
||||||
|
public int getDataIndexOfTime(double time) {
|
||||||
|
if (Double.isNaN(time)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
List<Double> times = get(FlightDataType.TYPE_TIME);
|
||||||
|
if (times == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < times.size(); i++) {
|
||||||
|
if (times.get(i) >= time) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public FlightDataBranch clone() {
|
public FlightDataBranch clone() {
|
||||||
FlightDataType[] types = getTypes();
|
FlightDataType[] types = getTypes();
|
||||||
FlightDataBranch clone = new FlightDataBranch(name, types);
|
FlightDataBranch clone = new FlightDataBranch(name, types);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user