Skip to content

Commit 64b2ea9

Browse files
aasitvora99claude
andcommitted
ENH: add /rockets/{id}/drawing-geometry endpoint
Exposes structured drawing geometry that mirrors rocketpy.Rocket.draw(), so clients can redraw a rocket using the same shape math rocketpy uses without server-side rendering or duplicated geometry logic in the UI. Response carries per-surface shape_x/shape_y arrays, body tube segments, motor patch polygons (nozzle, chamber, grains, tanks, outline), rail button positions, sensors, t=0 CG/CP, and drawing bounds. Coordinates are already transformed into the draw frame rocketpy uses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9067812 commit 64b2ea9

4 files changed

Lines changed: 593 additions & 4 deletions

File tree

src/controllers/rocket.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
ControllerBase,
55
controller_exception_handler,
66
)
7-
from src.views.rocket import RocketSimulation, RocketCreated
7+
from src.views.rocket import (
8+
RocketSimulation,
9+
RocketCreated,
10+
RocketDrawingGeometry,
11+
)
812
from src.models.motor import MotorModel
913
from src.models.rocket import (
1014
RocketModel,
@@ -75,6 +79,27 @@ async def get_rocketpy_rocket_binary(self, rocket_id: str) -> bytes:
7579
rocket_service = RocketService.from_rocket_model(rocket.rocket)
7680
return rocket_service.get_rocket_binary()
7781

82+
@controller_exception_handler
83+
async def get_rocket_drawing_geometry(
84+
self, rocket_id: str
85+
) -> RocketDrawingGeometry:
86+
"""
87+
Build the drawing geometry payload for a persisted rocket.
88+
89+
Args:
90+
rocket_id: str
91+
92+
Returns:
93+
views.RocketDrawingGeometry
94+
95+
Raises:
96+
HTTP 404 Not Found: If the rocket does not exist in the database.
97+
HTTP 422: If the rocket has no aerodynamic surfaces to draw.
98+
"""
99+
rocket = await self.get_rocket_by_id(rocket_id)
100+
rocket_service = RocketService.from_rocket_model(rocket.rocket)
101+
return rocket_service.get_drawing_geometry()
102+
78103
@controller_exception_handler
79104
async def get_rocket_simulation(
80105
self,

src/routes/rocket.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
RocketSimulation,
1010
RocketCreated,
1111
RocketRetrieved,
12+
RocketDrawingGeometry,
1213
)
1314
from src.models.rocket import (
1415
RocketModel,
@@ -177,3 +178,23 @@ async def simulate_rocket(
177178
"""
178179
with tracer.start_as_current_span("get_rocket_simulation"):
179180
return await controller.get_rocket_simulation(rocket_id)
181+
182+
183+
@router.get("/{rocket_id}/drawing-geometry")
184+
async def get_rocket_drawing_geometry(
185+
rocket_id: str,
186+
controller: RocketControllerDep,
187+
) -> RocketDrawingGeometry:
188+
"""
189+
Returns structured drawing geometry for the rocket so that a frontend
190+
can redraw exactly what rocketpy.Rocket.draw() would render.
191+
192+
Response contains shape coordinate arrays for each aerodynamic surface,
193+
tube segments, motor polygons (nozzle, chamber, grains, tanks, outline),
194+
rail-button positions, CG/CP at t=0, sensors, and overall drawing bounds.
195+
196+
## Args
197+
``` rocket_id: Rocket ID ```
198+
"""
199+
with tracer.start_as_current_span("get_rocket_drawing_geometry"):
200+
return await controller.get_rocket_drawing_geometry(rocket_id)

0 commit comments

Comments
 (0)