From aea946bdbb0dfa189dbe40831f65a5b16e6b99db Mon Sep 17 00:00:00 2001 From: David Rundus <114828622+rundvd@users.noreply.github.com> Date: Tue, 1 Dec 2026 09:29:53 -0600 Subject: [PATCH] fix: positions of components nested inside other components --- examples/Anonymous--Alpha/parameters.json | 8 ++++---- examples/Anonymous--Beta/parameters.json | 4 ++-- examples/Anonymous--Epsilon/parameters.json | 14 ++++++------- examples/Anonymous--Eta/parameters.json | 8 ++++---- examples/Anonymous--Gamma/parameters.json | 6 +++--- examples/Anonymous--Iota/parameters.json | 6 +++--- examples/Anonymous--Mu/parameters.json | 2 +- examples/Anonymous--Nu/parameters.json | 2 +- examples/Anonymous--Pi/parameters.json | 2 +- examples/Anonymous--Rho/parameters.json | 2 +- examples/Anonymous--Sigma/parameters.json | 2 +- examples/Anonymous--Theta/parameters.json | 8 ++++---- examples/Anonymous--Zeta/parameters.json | 8 ++++---- examples/NDRT--Rocket--2020/parameters.json | 2 +- .../parameters.json | 4 ++-- .../WERT--Prometheus--2022/parameters.json | 6 +++--- .../components/open_rocket_wrangler.py | 10 +++++++++- tests/acceptance/test_ork_extractor.py | 20 +++++++++++++++++++ tests/conftest.py | 18 +++++++++++++++++ 19 files changed, 89 insertions(+), 43 deletions(-) diff --git a/examples/Anonymous--Alpha/parameters.json b/examples/Anonymous--Alpha/parameters.json index f26374c..26d9ed6 100644 --- a/examples/Anonymous--Alpha/parameters.json +++ b/examples/Anonymous--Alpha/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 0.0, - "distance": 1.5, - "lower_position": 3.7849999999999997, + "distance": 1.205, + "lower_position": 3.465, "name": "Rail Button", - "upper_position": 2.2849999999999997 + "upper_position": 2.26 }, "rocket": { "center_of_mass_without_propellant": 1.991, @@ -118,7 +118,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 3.2449999999999997, + "position": 3.195, "root_chord": 0.26999999999999996, "section": "airfoil", "span": 0.1400000000000001, diff --git a/examples/Anonymous--Beta/parameters.json b/examples/Anonymous--Beta/parameters.json index 4baa400..c64547f 100644 --- a/examples/Anonymous--Beta/parameters.json +++ b/examples/Anonymous--Beta/parameters.json @@ -122,7 +122,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 2.9109999999999996, + "position": 1.226, "root_chord": 0.18, "section": "square", "span": 0.12512, @@ -134,7 +134,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 2.9109999999999996, + "position": 1.226, "root_chord": 0.18, "section": "square", "span": 0.154, diff --git a/examples/Anonymous--Epsilon/parameters.json b/examples/Anonymous--Epsilon/parameters.json index f7898d6..20e5ff1 100644 --- a/examples/Anonymous--Epsilon/parameters.json +++ b/examples/Anonymous--Epsilon/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": -90.0, - "distance": 2.0800000000000005, - "lower_position": 3.0140000000000007, + "distance": 2.0240000000000005, + "lower_position": 2.9060000000000006, "name": "Rail connection A", - "upper_position": 0.9340000000000002 + "upper_position": 0.8820000000000001 }, "rocket": { "center_of_mass_without_propellant": 1.629, @@ -118,7 +118,7 @@ "cant_angle": 0.0, "name": "Main fin set #2 #1 #1", "number": 1, - "position": 2.7350000000000003, + "position": 2.6900000000000004, "root_chord": 0.196, "section": "square", "span": 0.14, @@ -130,7 +130,7 @@ "cant_angle": 0.0, "name": "Main fin set #2 #1 #2", "number": 1, - "position": 2.9290000000000003, + "position": 2.688, "root_chord": 0.198, "section": "square", "span": 0.138, @@ -142,7 +142,7 @@ "cant_angle": 0.0, "name": "Main fin set #2 #1 #3", "number": 1, - "position": 3.128, + "position": 2.689, "root_chord": 0.197, "section": "square", "span": 0.136, @@ -154,7 +154,7 @@ "cant_angle": 0.0, "name": "Main fin set #2 #1 #4", "number": 1, - "position": 3.3240000000000003, + "position": 2.688, "root_chord": 0.198, "section": "square", "span": 0.138, diff --git a/examples/Anonymous--Eta/parameters.json b/examples/Anonymous--Eta/parameters.json index 43bc1db..1991f3c 100644 --- a/examples/Anonymous--Eta/parameters.json +++ b/examples/Anonymous--Eta/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 0.0, - "distance": 1.5035000000000003, - "lower_position": 2.9560000000000004, + "distance": 1.2125000000000004, + "lower_position": 1.9690000000000003, "name": "Launch lug", - "upper_position": 1.4525000000000001 + "upper_position": 0.7565 }, "rocket": { "center_of_mass_without_propellant": 1.458, @@ -110,7 +110,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 3, - "position": 4.0120000000000005, + "position": 2.4930000000000003, "root_chord": 0.23, "section": "rounded", "span": 0.185, diff --git a/examples/Anonymous--Gamma/parameters.json b/examples/Anonymous--Gamma/parameters.json index 08bca97..76ed8ca 100644 --- a/examples/Anonymous--Gamma/parameters.json +++ b/examples/Anonymous--Gamma/parameters.json @@ -91,10 +91,10 @@ }, "rail_buttons": { "angular_position": 0.0, - "distance": 1.4360000000000004, - "lower_position": 3.4889900000000003, + "distance": 0.746, + "lower_position": 2.04399, "name": "Launch Rail Pin 1", - "upper_position": 2.05299 + "upper_position": 1.29799 }, "rocket": { "center_of_mass_without_propellant": 1.4557, diff --git a/examples/Anonymous--Iota/parameters.json b/examples/Anonymous--Iota/parameters.json index 878128c..ed4d4ec 100644 --- a/examples/Anonymous--Iota/parameters.json +++ b/examples/Anonymous--Iota/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 45.0, - "distance": 0.75, - "lower_position": 1.85, + "distance": 0.7200000000000002, + "lower_position": 1.7200000000000002, "name": "Launch lug", - "upper_position": 1.1 + "upper_position": 1.0 }, "rocket": { "center_of_mass_without_propellant": 1.108, diff --git a/examples/Anonymous--Mu/parameters.json b/examples/Anonymous--Mu/parameters.json index fe8ed12..98dc282 100644 --- a/examples/Anonymous--Mu/parameters.json +++ b/examples/Anonymous--Mu/parameters.json @@ -121,7 +121,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 3, - "position": 1.8140000000000003, + "position": 1.015, "root_chord": 0.055, "section": "airfoil", "span": 0.09, diff --git a/examples/Anonymous--Nu/parameters.json b/examples/Anonymous--Nu/parameters.json index ccc92bb..e7edb66 100644 --- a/examples/Anonymous--Nu/parameters.json +++ b/examples/Anonymous--Nu/parameters.json @@ -116,7 +116,7 @@ "cant_angle": 0.0, "name": "Fins", "number": 4, - "position": 4.386, + "position": 3.757, "root_chord": 0.23, "section": "rounded", "span": 0.12, diff --git a/examples/Anonymous--Pi/parameters.json b/examples/Anonymous--Pi/parameters.json index e039ccb..702f355 100644 --- a/examples/Anonymous--Pi/parameters.json +++ b/examples/Anonymous--Pi/parameters.json @@ -112,7 +112,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 2.335, + "position": 1.7350000000000003, "root_chord": 0.125, "section": "square", "span": 0.16, diff --git a/examples/Anonymous--Rho/parameters.json b/examples/Anonymous--Rho/parameters.json index a43a9cb..b1b4347 100644 --- a/examples/Anonymous--Rho/parameters.json +++ b/examples/Anonymous--Rho/parameters.json @@ -104,7 +104,7 @@ "cant_angle": 0.0, "name": "Aletas trapezoidales", "number": 4, - "position": 2.5949999999999993, + "position": 2.06, "root_chord": 0.2, "section": "airfoil", "span": 0.115, diff --git a/examples/Anonymous--Sigma/parameters.json b/examples/Anonymous--Sigma/parameters.json index dff990a..35d3c3e 100644 --- a/examples/Anonymous--Sigma/parameters.json +++ b/examples/Anonymous--Sigma/parameters.json @@ -104,7 +104,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 3, - "position": 2.306, + "position": 2.248, "root_chord": 0.2, "section": "square", "span": 0.27, diff --git a/examples/Anonymous--Theta/parameters.json b/examples/Anonymous--Theta/parameters.json index 80971ab..ac2c008 100644 --- a/examples/Anonymous--Theta/parameters.json +++ b/examples/Anonymous--Theta/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 0.0, - "distance": 0.5092290000000008, - "lower_position": 3.1340420000000004, + "distance": 0.7694999999999999, + "lower_position": 2.068313, "name": "Launch lug", - "upper_position": 2.6248129999999996 + "upper_position": 1.298813 }, "rocket": { "center_of_mass_without_propellant": 1.1921, @@ -118,7 +118,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 2.131513, + "position": 1.9883130000000002, "root_chord": 0.12, "section": "square", "span": 0.08, diff --git a/examples/Anonymous--Zeta/parameters.json b/examples/Anonymous--Zeta/parameters.json index cbc1e52..df2c37f 100644 --- a/examples/Anonymous--Zeta/parameters.json +++ b/examples/Anonymous--Zeta/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 45.0, - "distance": 1.3050000000000006, - "lower_position": 3.49, + "distance": 0.8000000000000003, + "lower_position": 2.95, "name": "S.4.3 Launch lug", - "upper_position": 2.1849999999999996 + "upper_position": 2.15 }, "rocket": { "center_of_mass_without_propellant": 1.7723, @@ -118,7 +118,7 @@ "cant_angle": 0.0, "name": "S.5.2 Fins", "number": 4, - "position": 2.9699999999999998, + "position": 2.8, "root_chord": 0.37, "section": "airfoil", "span": 0.095, diff --git a/examples/NDRT--Rocket--2020/parameters.json b/examples/NDRT--Rocket--2020/parameters.json index 88128f0..23cf9c9 100644 --- a/examples/NDRT--Rocket--2020/parameters.json +++ b/examples/NDRT--Rocket--2020/parameters.json @@ -112,7 +112,7 @@ "cant_angle": 0.0, "name": "Trapezoidal fin set", "number": 4, - "position": 3.3528000000000002, + "position": 3.048, "root_chord": 0.15239999999999995, "section": "rounded", "span": 0.1651, diff --git a/examples/ProjetoJupiter--Valetudo--2019/parameters.json b/examples/ProjetoJupiter--Valetudo--2019/parameters.json index dcdfbe1..aec9ee4 100644 --- a/examples/ProjetoJupiter--Valetudo--2019/parameters.json +++ b/examples/ProjetoJupiter--Valetudo--2019/parameters.json @@ -64,8 +64,8 @@ }, "rail_buttons": { "angular_position": 29.999999999999996, - "distance": 1.2515, - "lower_position": 2.399169, + "distance": 1.1934999999999998, + "lower_position": 2.341169, "name": "Guia de lançamento", "upper_position": 1.147669 }, diff --git a/examples/WERT--Prometheus--2022/parameters.json b/examples/WERT--Prometheus--2022/parameters.json index 410030a..9db9379 100644 --- a/examples/WERT--Prometheus--2022/parameters.json +++ b/examples/WERT--Prometheus--2022/parameters.json @@ -73,10 +73,10 @@ }, "rail_buttons": { "angular_position": 0.0, - "distance": 0.5540000000000003, - "lower_position": 3.2256530000000003, + "distance": 0.5840000000000001, + "lower_position": 1.8085, "name": "Launch lug", - "upper_position": 2.671653 + "upper_position": 1.2245 }, "rocket": { "center_of_mass_without_propellant": 1.266, diff --git a/rocketserializer/components/open_rocket_wrangler.py b/rocketserializer/components/open_rocket_wrangler.py index 303e0d3..e69292f 100644 --- a/rocketserializer/components/open_rocket_wrangler.py +++ b/rocketserializer/components/open_rocket_wrangler.py @@ -78,6 +78,13 @@ def process_elements_position( ) unique_id = hash(frozenset(element.items())) elements[unique_id] = element + + # The children of a rocket or stage are stacked one after the other. All the + # others are placed relative to the front of their own parent. + children_are_stacked = element["type"] in ["Rocket", "Stage", "AxialStage"] + if not children_are_stacked: + top_position = element["position"] + i = 0 while True: @@ -93,7 +100,8 @@ def process_elements_position( elements.update(new_elements) logger.info("Child '%s' processed", child.getName()) - top_position += child.getLength() + if children_are_stacked: + top_position += child.getLength() i += 1 logger.info("Moving to the next child") diff --git a/tests/acceptance/test_ork_extractor.py b/tests/acceptance/test_ork_extractor.py index ccc577d..2515ac0 100644 --- a/tests/acceptance/test_ork_extractor.py +++ b/tests/acceptance/test_ork_extractor.py @@ -58,6 +58,26 @@ def test_ork_extractor(expected_results_file, fixture, request): settings, expected_results = remove_sensitive_keys(settings, expected_results) +def test_positions_match_openrocket(settings_and_locations): + settings, locations = settings_and_locations + + for fins, fin_type in [ + ("trapezoidal_fins", "TrapezoidFinSet"), + ("elliptical_fins", "EllipticalFinSet"), + ]: + for fin in settings[fins].values(): + assert any( + fin["position"] == pytest.approx(x, abs=1e-6) + for x in locations[fin_type] + ) + + buttons = locations.get("LaunchLug", []) + locations.get("RailButton", []) + for key in ["upper_position", "lower_position"]: + if key in settings["rail_buttons"]: + position = settings["rail_buttons"][key] + assert any(position == pytest.approx(x, abs=1e-6) for x in buttons) + + def remove_sensitive_keys(settings, expected): """Remove sensitive keys from the settings and expected_results dicts. This is important to avoid problems with the paths to the files that are saved diff --git a/tests/conftest.py b/tests/conftest.py index e994338..f33d5b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,8 +51,20 @@ def get_settings(ork_path, output_path, ork_document): return settings +def get_locations(component, locations=None): + """Group the component locations calculated by OpenRocket by their type.""" + locations = {} if locations is None else locations + component_type = str(component.getClass().getSimpleName()) + location = float(component.getComponentLocations()[0].x) + locations.setdefault(component_type, []).append(location) + for i in range(component.getChildCount()): + get_locations(component.getChild(i), locations) + return locations + + # Pre-compute all settings at import time using a single OpenRocket session _cached_settings = {} +_cached_locations = {} with OpenRocketSession(select_latest_openrocket_jar(ROOT_DIR), "OFF") as session: for name, rel_path in EXAMPLES.items(): @@ -61,6 +73,12 @@ def get_settings(ork_path, output_path, ork_document): output_dir = ROOT_DIR / "tests" / "acceptance" / Path(rel_path).name ork_doc = session.load_doc(str(ork_filepath)) _cached_settings[name] = get_settings(ork_filepath, output_dir, ork_doc) + _cached_locations[name] = get_locations(ork_doc.getRocket()) + + +@pytest.fixture(params=EXAMPLES) +def settings_and_locations(request): + return _cached_settings[request.param], _cached_locations[request.param] # Create fixtures for each example