Skip to content

Commit 07b9d57

Browse files
Bug: do not allow drawing rockets with no aerodynamic surface (#774)
* DEV: add validation for aerodynamic surfaces in rocket plots * MNT: add conditional check for aerodynamic surfaces before drawing rocket * DEV: update CHANGELOG
1 parent 81449d4 commit 07b9d57

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Attention: The newest changes should be on top -->
4040

4141
### Fixed
4242

43+
- BUG: do not allow drawing rockets with no aerodynamic surface [#774](https://github.com/RocketPy-Team/RocketPy/pull/774)
4344
- BUG: update flight simulation logic to include burn start time [#778](https://github.com/RocketPy-Team/RocketPy/pull/778)
4445

4546
## [v1.8.0] - 2025-01-20

rocketpy/plots/rocket_plots.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def draw(self, vis_args=None, plane="xz", *, filename=None):
212212
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
213213
and webp (these are the formats supported by matplotlib).
214214
"""
215+
216+
self.__validate_aerodynamic_surfaces()
217+
215218
if vis_args is None:
216219
vis_args = {
217220
"background": "#EEEEEE",
@@ -248,6 +251,12 @@ def draw(self, vis_args=None, plane="xz", *, filename=None):
248251
plt.tight_layout()
249252
show_or_save_plot(filename)
250253

254+
def __validate_aerodynamic_surfaces(self):
255+
if not self.rocket.aerodynamic_surfaces:
256+
raise ValueError(
257+
"The rocket must have at least one aerodynamic surface to be drawn."
258+
)
259+
251260
def _draw_aerodynamic_surfaces(self, ax, vis_args, plane):
252261
"""Draws the aerodynamic surfaces and saves the position of the points
253262
of interest for the tubes."""
@@ -399,6 +408,8 @@ def _draw_generic_surface(
399408

400409
def _draw_tubes(self, ax, drawn_surfaces, vis_args):
401410
"""Draws the tubes between the aerodynamic surfaces."""
411+
radius = 0
412+
last_x = 0
402413
for i, d_surface in enumerate(drawn_surfaces):
403414
# Draw the tubes, from the end of the first surface to the beginning
404415
# of the next surface, with the radius of the rocket at that point
@@ -670,9 +681,10 @@ def all(self):
670681
"""
671682

672683
# Rocket draw
673-
print("\nRocket Draw")
674-
print("-" * 40)
675-
self.draw()
684+
if len(self.rocket.aerodynamic_surfaces) > 0:
685+
print("\nRocket Draw")
686+
print("-" * 40)
687+
self.draw()
676688

677689
# Mass Plots
678690
print("\nMass Plots")

0 commit comments

Comments
 (0)