Skip to content

Commit

Permalink
MNT: use local variable instead of class variable in TimeNodes.merge()
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR committed Mar 26, 2024
1 parent 99d8948 commit 9b47dfe
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -3664,19 +3664,18 @@ def sort(self):

def merge(self):
# Initialize temporary list
self.tmp_list = [self.list[0]]
self.copy_list = self.list[1:]
tmp_list = [self.list[0]]
# Iterate through all other time nodes
for node in self.copy_list:
for node in self.list[1:]:
# If there is already another node with similar time: merge
if abs(node.t - self.tmp_list[-1].t) < 1e-7:
self.tmp_list[-1].parachutes += node.parachutes
self.tmp_list[-1].callbacks += node.callbacks
if abs(node.t - tmp_list[-1].t) < 1e-7:
tmp_list[-1].parachutes += node.parachutes
tmp_list[-1].callbacks += node.callbacks
# Add new node to tmp list if there is none with the same time
else:
self.tmp_list.append(node)
tmp_list.append(node)
# Save tmp list to permanent
self.list = self.tmp_list
self.list = tmp_list

def flush_after(self, index):
del self.list[index + 1 :]
Expand Down

0 comments on commit 9b47dfe

Please sign in to comment.