From d23d25ed15ffb8910aa7f68b9e7525bd8cd6de6f Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 16 Feb 2020 13:17:49 -0500 Subject: [PATCH] [fix] Fixes error when loading FinSet angles --- .../importt/AnglePositionSetter.java | 4 +- .../file/openrocket/savers/FinSetSaver.java | 2 +- .../sf/openrocket/rocketcomponent/FinSet.java | 52 ++++++++++--------- .../position/AnglePositionable.java | 6 +++ core/src/net/sf/openrocket/util/MathUtil.java | 11 ++-- .../rocketcomponent/FinSetTest.java | 20 ++++++- .../configdialog/EllipticalFinSetConfig.java | 4 +- .../configdialog/FreeformFinSetConfig.java | 4 +- .../configdialog/TrapezoidFinSetConfig.java | 4 +- 9 files changed, 69 insertions(+), 38 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/AnglePositionSetter.java b/core/src/net/sf/openrocket/file/openrocket/importt/AnglePositionSetter.java index 06b6d97d2..4843f6872 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/AnglePositionSetter.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/AnglePositionSetter.java @@ -20,9 +20,9 @@ class AnglePositionSetter implements Setter { double pos; try { - pos = Double.parseDouble(value) * Math.PI / 180.0 ; + pos = Math.toRadians(Double.parseDouble(value)); } catch (NumberFormatException e) { - warnings.add(String.format("Warning: invalid value radius position. value=%s class: %s", value, c.getClass().getCanonicalName() )); + warnings.add(String.format("Warning: invalid angle position. value=%s (degrees) class: %s", value, c.getClass().getCanonicalName() )); return; } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/FinSetSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/FinSetSaver.java index c7d5ded18..ef6c25212 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/FinSetSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/FinSetSaver.java @@ -20,7 +20,7 @@ public class FinSetSaver extends ExternalComponentSaver { elements.add("" + fins.getThickness() + ""); elements.add("" + fins.getCrossSection().name().toLowerCase(Locale.ENGLISH) + ""); - elements.add("" + (fins.getCantAngle() * 180.0 / Math.PI) + ""); + elements.add("" + Math.toDegrees(fins.getCantAngle()) + ""); // Save fin tabs only if they exist (compatibility with file version < 1.1) if (!MathUtil.equals(fins.getTabHeight(), 0) && diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 54b8b683b..749855850 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -35,7 +35,7 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab /** * Maximum allowed cant of fins. */ - public static final double MAX_CANT = (15.0 * Math.PI / 180); + public static final double MAX_CANT_RADIANS = (15.0 * Math.PI / 180); public enum CrossSection { //// Square @@ -78,13 +78,13 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab * Rotation angle of the first fin. Zero corresponds to the positive y-axis. */ private AngleMethod angleMethod = AngleMethod.RELATIVE; - private double firstFinOffset = 0; + private double firstFinOffsetRadians = 0; private Transformation baseRotation = Transformation.IDENTITY; // initially, rotate by 0 degrees. /** * Cant angle of fins. */ - private double cantAngle = 0; + private double cantRadians = 0; /* Cached value: */ private Transformation cantRotation = null; @@ -194,26 +194,33 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab setAngleOffset(r); } + /** + * @return angle current cant angle, in radians + */ public double getCantAngle() { - return cantAngle; + return cantRadians; } - public void setCantAngle(double cant) { - cant = MathUtil.clamp(cant, -MAX_CANT, MAX_CANT); - if (MathUtil.equals(cant, cantAngle)) + /** + * + * @param cant -- new cant angle, in radians + */ + public void setCantAngle(final double newCantRadians) { + final double clampedCant = MathUtil.clamp(newCantRadians, -MAX_CANT_RADIANS, MAX_CANT_RADIANS); + if (MathUtil.equals(clampedCant, this.cantRadians)) return; - this.cantAngle = cant; + this.cantRadians = clampedCant; fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } public Transformation getCantRotation() { if (cantRotation == null) { - if (MathUtil.equals(cantAngle, 0)) { + if (MathUtil.equals(this.cantRadians, 0)) { cantRotation = Transformation.IDENTITY; } else { Transformation t = new Transformation(-length / 2, 0, 0); - t = Transformation.rotate_y(cantAngle).applyTransformation(t); + t = Transformation.rotate_y(cantRadians).applyTransformation(t); t = new Transformation(length / 2, 0, 0).applyTransformation(t); cantRotation = t; } @@ -928,16 +935,15 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab @Override public double getAngleOffset() { - return firstFinOffset; + return firstFinOffsetRadians; } - @Override - public void setAngleOffset(double angle) { - angle = MathUtil.reduce180(angle); - if (MathUtil.equals(angle, firstFinOffset)) + public void setAngleOffset(final double angleRadians) { + final double reducedAngle = MathUtil.reducePI(angleRadians); + if (MathUtil.equals(reducedAngle, firstFinOffsetRadians)) return; - firstFinOffset = angle; + firstFinOffsetRadians = reducedAngle; fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } @@ -947,13 +953,12 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab } @Override - public double[] getInstanceAngles(){ - final double baseAngle = getAngleOffset(); - final double incrAngle = getInstanceAngleIncrement(); + public double[] getInstanceAngles() { + final double angleIncrementRadians = getInstanceAngleIncrement(); double[] result = new double[ getFinCount()]; - for( int i=0; i