From 4e64d817d17568715acd103971aba0e6ac10d133 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 24 Jan 2016 21:37:13 -0500 Subject: [PATCH] [Bugfix] Added unit tests for Transition Shapes - and refactored member names a bit --- .../openrocket/rocketcomponent/NoseCone.java | 2 + .../sf/openrocket/rocketcomponent/Rocket.java | 2 +- .../rocketcomponent/Transition.java | 48 +++++++++---------- .../net/sf/openrocket/util/TestRockets.java | 4 +- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/NoseCone.java b/core/src/net/sf/openrocket/rocketcomponent/NoseCone.java index 6ef65ed24..f58f40bd2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/NoseCone.java +++ b/core/src/net/sf/openrocket/rocketcomponent/NoseCone.java @@ -34,6 +34,8 @@ public class NoseCone extends Transition { super.setLength(length); super.setClipped(false); + super.setAftRadiusAutomatic(false); + super.setAftRadius(radius); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index e80152308..437ebb4f1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -424,7 +424,7 @@ public class Rocket extends RocketComponent { checkState(); { // vvvv DEVEL vvvv - System.err.println("fireEvent@rocket."); + //System.err.println("fireEvent@rocket."); } // ^^^^ DEVEL ^^^^ // Update modification ID's only for normal (not undo/redo) events diff --git a/core/src/net/sf/openrocket/rocketcomponent/Transition.java b/core/src/net/sf/openrocket/rocketcomponent/Transition.java index 6b12f156e..f9ded5e0d 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Transition.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Transition.java @@ -23,8 +23,8 @@ public class Transition extends SymmetricComponent { private double shapeParameter; private boolean clipped; // Not to be read - use isClipped(), which may be overriden - private double radius1, radius2; - private boolean autoRadius1, autoRadius2; // Whether the start radius is automatic + private double foreRadius, aftRadius; + private boolean autoForeRadius, autoAftRadius2; // Whether the start radius is automatic private double foreShoulderRadius; @@ -43,11 +43,11 @@ public class Transition extends SymmetricComponent { public Transition() { super(); - this.radius1 = DEFAULT_RADIUS; - this.radius2 = DEFAULT_RADIUS; + this.foreRadius = DEFAULT_RADIUS; + this.aftRadius = DEFAULT_RADIUS; this.length = DEFAULT_RADIUS * 3; - this.autoRadius1 = true; - this.autoRadius2 = true; + this.autoForeRadius = true; + this.autoAftRadius2 = true; this.type = Shape.CONICAL; this.shapeParameter = 0; @@ -82,18 +82,18 @@ public class Transition extends SymmetricComponent { r = DEFAULT_RADIUS; return r; } - return radius1; + return foreRadius; } public void setForeRadius(double radius) { - if ((this.radius1 == radius) && (autoRadius1 == false)) + if ((this.foreRadius == radius) && (autoForeRadius == false)) return; - this.autoRadius1 = false; - this.radius1 = Math.max(radius, 0); + this.autoForeRadius = false; + this.foreRadius = Math.max(radius, 0); - if (this.thickness > this.radius1 && this.thickness > this.radius2) - this.thickness = Math.max(this.radius1, this.radius2); + if (this.thickness > this.foreRadius && this.thickness > this.aftRadius) + this.thickness = Math.max(this.foreRadius, this.aftRadius); clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); @@ -101,14 +101,14 @@ public class Transition extends SymmetricComponent { @Override public boolean isForeRadiusAutomatic() { - return autoRadius1; + return autoForeRadius; } public void setForeRadiusAutomatic(boolean auto) { - if (autoRadius1 == auto) + if (autoForeRadius == auto) return; - autoRadius1 = auto; + autoForeRadius = auto; clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); @@ -130,20 +130,20 @@ public class Transition extends SymmetricComponent { r = DEFAULT_RADIUS; return r; } - return radius2; + return aftRadius; } public void setAftRadius(double radius) { - if ((this.radius2 == radius) && (autoRadius2 == false)) + if ((this.aftRadius == radius) && (autoAftRadius2 == false)) return; - this.autoRadius2 = false; - this.radius2 = Math.max(radius, 0); + this.autoAftRadius2 = false; + this.aftRadius = Math.max(radius, 0); - if (this.thickness > this.radius1 && this.thickness > this.radius2) - this.thickness = Math.max(this.radius1, this.radius2); + if (this.thickness > this.foreRadius && this.thickness > this.aftRadius) + this.thickness = Math.max(this.foreRadius, this.aftRadius); clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); @@ -151,14 +151,14 @@ public class Transition extends SymmetricComponent { @Override public boolean isAftRadiusAutomatic() { - return autoRadius2; + return autoAftRadius2; } public void setAftRadiusAutomatic(boolean auto) { - if (autoRadius2 == auto) + if (autoAftRadius2 == auto) return; - autoRadius2 = auto; + autoAftRadius2 = auto; clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index b2ce4801f..bcb6475d1 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -404,8 +404,8 @@ public class TestRockets { double noseconeLength = 0.07; double noseconeRadius = 0.012; NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius); - nosecone.setAftShoulderLength(0.025); - nosecone.setAftShoulderRadius(0.012); + nosecone.setAftShoulderLength(0.02); + nosecone.setAftShoulderRadius(0.011); nosecone.setName("Nose Cone"); stage.addChild(nosecone);