From 2e6271050106a68dee8f96775d105929ce1cb881 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 2 Mar 2025 22:40:12 -0300 Subject: [PATCH 1/3] DEV: add validation for aerodynamic surfaces in rocket plots --- rocketpy/plots/rocket_plots.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index 4521e5793..f77d6d5cf 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -212,6 +212,9 @@ def draw(self, vis_args=None, plane="xz", *, filename=None): eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff and webp (these are the formats supported by matplotlib). """ + + self.__validate_aerodynamic_surfaces() + if vis_args is None: vis_args = { "background": "#EEEEEE", @@ -248,6 +251,12 @@ def draw(self, vis_args=None, plane="xz", *, filename=None): plt.tight_layout() show_or_save_plot(filename) + def __validate_aerodynamic_surfaces(self): + if not self.rocket.aerodynamic_surfaces: + raise ValueError( + "The rocket must have at least one aerodynamic surface to be drawn." + ) + def _draw_aerodynamic_surfaces(self, ax, vis_args, plane): """Draws the aerodynamic surfaces and saves the position of the points of interest for the tubes.""" @@ -399,6 +408,8 @@ def _draw_generic_surface( def _draw_tubes(self, ax, drawn_surfaces, vis_args): """Draws the tubes between the aerodynamic surfaces.""" + radius = 0 + last_x = 0 for i, d_surface in enumerate(drawn_surfaces): # Draw the tubes, from the end of the first surface to the beginning # of the next surface, with the radius of the rocket at that point From 67a386bb7da16236f84fb0e703fd26a87874f869 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 2 Mar 2025 22:43:25 -0300 Subject: [PATCH 2/3] MNT: add conditional check for aerodynamic surfaces before drawing rocket --- rocketpy/plots/rocket_plots.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index f77d6d5cf..db53f6f49 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -681,9 +681,10 @@ def all(self): """ # Rocket draw - print("\nRocket Draw") - print("-" * 40) - self.draw() + if len(self.rocket.aerodynamic_surfaces) > 0: + print("\nRocket Draw") + print("-" * 40) + self.draw() # Mass Plots print("\nMass Plots") From b0ed1bcef33f0c490130df3d0b44a6b013227042 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 2 Mar 2025 22:44:54 -0300 Subject: [PATCH 3/3] DEV: update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 876de3847..8c1a07c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ Attention: The newest changes should be on top --> ### Fixed -- +- BUG: do not allow drawing rockets with no aerodynamic surface [#774](https://github.com/RocketPy-Team/RocketPy/pull/774) ## [v1.8.0] - 2025-01-20