Skip to content

Commit 0cc71cb

Browse files
committed
BUG: add rail buttons checks in add_surfaces
1 parent 9d34c7e commit 0cc71cb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

rocketpy/rocket/rocket.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,29 @@ def add_motor(self, motor, position): # pylint: disable=too-many-statements
966966
self.evaluate_com_to_cdm_function()
967967
self.evaluate_nozzle_gyration_tensor()
968968

969+
def __add_single_surface(self, surface, position):
970+
"""Adds a single aerodynamic surface to the rocket. Makes checks for
971+
rail buttons case, and position type.
972+
"""
973+
position = (
974+
Vector([0, 0, position])
975+
if not isinstance(position, (Vector, tuple, list))
976+
else Vector(position)
977+
)
978+
if isinstance(surface, RailButtons):
979+
self.rail_buttons.add(surface, position)
980+
else:
981+
self.aerodynamic_surfaces.add(surface, position)
982+
self.__evaluate_single_surface_cp_to_cdm(surface, position)
983+
969984
def add_surfaces(self, surfaces, positions):
970985
"""Adds one or more aerodynamic surfaces to the rocket. The aerodynamic
971986
surface must be an instance of a class that inherits from the
972987
AeroSurface (e.g. NoseCone, TrapezoidalFins, etc.)
973988
974989
Parameters
975990
----------
976-
surfaces : list, AeroSurface, NoseCone, TrapezoidalFins, EllipticalFins, Tail
991+
surfaces : list, AeroSurface, NoseCone, TrapezoidalFins, EllipticalFins, Tail, RailButtons
977992
Aerodynamic surface to be added to the rocket. Can be a list of
978993
AeroSurface if more than one surface is to be added.
979994
positions : int, float, list, tuple, Vector
@@ -996,22 +1011,11 @@ def add_surfaces(self, surfaces, positions):
9961011
-------
9971012
None
9981013
"""
999-
# TODO: separate this method into smaller methods: https://github.com/RocketPy-Team/RocketPy/pull/696#discussion_r1771978422
10001014
try:
10011015
for surface, position in zip(surfaces, positions):
1002-
if not isinstance(position, (Vector, tuple, list)):
1003-
position = Vector([0, 0, position])
1004-
else:
1005-
position = Vector(position)
1006-
self.aerodynamic_surfaces.add(surface, position)
1007-
self.__evaluate_single_surface_cp_to_cdm(surface, position)
1016+
self.__add_single_surface(surface, position)
10081017
except TypeError:
1009-
if not isinstance(positions, (Vector, tuple, list)):
1010-
positions = Vector([0, 0, positions])
1011-
else:
1012-
positions = Vector(positions)
1013-
self.aerodynamic_surfaces.add(surfaces, positions)
1014-
self.__evaluate_single_surface_cp_to_cdm(surfaces, positions)
1018+
self.__add_single_surface(surfaces, positions)
10151019

10161020
self.evaluate_center_of_pressure()
10171021
self.evaluate_stability_margin()

0 commit comments

Comments
 (0)