From ca007d7e93ede15140f4f5f02af42db99901a80e Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 24 Nov 2022 16:55:35 +0100 Subject: [PATCH 1/2] [#1849] Only apply component context transforms once --- .../sf/openrocket/rocketcomponent/FlightConfiguration.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 2b58e7b64..b01aeb23e 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -748,7 +748,12 @@ public class FlightConfiguration implements FlightConfigurableParameter instanceCoordinates = component.getComponentBounds(); + List parsedContexts = new ArrayList<>(); for (InstanceContext context : contexts) { + // Don't parse the same context component twice (e.g. multiple copies in a pod set). + if (parsedContexts.contains(context.component)) { + continue; + } Collection transformedCoords = new ArrayList<>(instanceCoordinates); // mutating. Transforms coordinates in place. context.transform.transform(instanceCoordinates); @@ -759,7 +764,9 @@ public class FlightConfiguration implements FlightConfigurableParameter Date: Thu, 24 Nov 2022 17:16:00 +0100 Subject: [PATCH 2/2] Add unit tests for pods bounding box --- .../rocketcomponent/BoundingBoxTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/test/net/sf/openrocket/rocketcomponent/BoundingBoxTest.java b/core/test/net/sf/openrocket/rocketcomponent/BoundingBoxTest.java index 8394a3dfb..21b6e3c09 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/BoundingBoxTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/BoundingBoxTest.java @@ -102,4 +102,37 @@ public class BoundingBoxTest extends BaseTestCase { assertEquals( 0.12069451, bounds.max.z, EPSILON); } + @Test + public void testPodsBoundingBox() { + Rocket rocket = TestRockets.makeEndPlateRocket(); + + // DEBUG + System.err.println(rocket.toDebugTree()); + + BoundingBox bounds = rocket.getBoundingBox(); + assertEquals( 0.0, bounds.min.x, EPSILON); + assertEquals( 0.304, bounds.max.x, EPSILON); + + assertEquals( -0.0365, bounds.min.y, EPSILON); + assertEquals( 0.0365, bounds.max.y, EPSILON); + + assertEquals( -0.0365, bounds.min.z, EPSILON); + assertEquals( 0.0365, bounds.max.z, EPSILON); + + // Add a mass component to the pod set (to test GitHub issue #1849) + PodSet podSet = (PodSet) rocket.getChild(0).getChild(1).getChild(1); + BodyTube tube = (BodyTube) podSet.getChild(0); + tube.addChild(new MassComponent()); + + bounds = rocket.getBoundingBox(); + assertEquals( 0.0, bounds.min.x, EPSILON); + assertEquals( 0.304, bounds.max.x, EPSILON); + + assertEquals( -0.0365, bounds.min.y, EPSILON); + assertEquals( 0.0365, bounds.max.y, EPSILON); + + assertEquals( -0.0365, bounds.min.z, EPSILON); + assertEquals( 0.0365, bounds.max.z, EPSILON); + } + }