From 6ebf1ed6e45c66f46e29bbe9af86439f8bc16d8d Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 27 Aug 2024 00:06:29 +0200 Subject: [PATCH] Store separation time in data branch --- .../core/simulation/FlightDataBranch.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java b/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java index e844add41..d7b3740f6 100644 --- a/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java +++ b/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java @@ -27,6 +27,7 @@ import info.openrocket.core.util.ModID; public class FlightDataBranch extends DataBranch { private double timeToOptimumAltitude = Double.NaN; private double optimumAltitude = Double.NaN; + private double separationTime = Double.NaN; private final ArrayList events = new ArrayList<>(); /** @@ -183,6 +184,9 @@ public class FlightDataBranch extends DataBranch { public void addEvent(FlightEvent event) { mutable.check(); events.add(event); + if (event.getType() == FlightEvent.Type.STAGE_SEPARATION) { + separationTime = event.getTime(); + } modID = new ModID(); } @@ -225,6 +229,35 @@ public class FlightDataBranch extends DataBranch { 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 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() { FlightDataType[] types = getTypes(); FlightDataBranch clone = new FlightDataBranch(name, types);