diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 366b86588..bcefbdea8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -6,9 +6,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.material.Material; @@ -949,7 +946,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona @Override public void setAngleOffset(final double angleRadians) { - final double reducedAngle = MathUtil.reducePI(angleRadians); + final double reducedAngle = MathUtil.reducePi(angleRadians); if (MathUtil.equals(reducedAngle, firstFinOffsetRadians)) return; firstFinOffsetRadians = reducedAngle; @@ -974,7 +971,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona double[] result = new double[ getFinCount()]; for( int finNumber=0; finNumber < getFinCount(); ++finNumber ){ - result[finNumber] = MathUtil.reduce2PI( firstFinOffsetRadians + angleIncrementRadians*finNumber); + result[finNumber] = MathUtil.reduce2Pi( firstFinOffsetRadians + angleIncrementRadians*finNumber); } return result; diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 996885664..e14f99d08 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -187,7 +187,7 @@ public class InnerTube extends ThicknessRingComponent implements AxialPositionab * @param rotation the clusterRotation to set */ public void setClusterRotation(double rotation) { - rotation = MathUtil.reduce180(rotation); + rotation = MathUtil.reducePi(rotation); if (clusterRotation == rotation) return; this.clusterRotation = rotation; diff --git a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java index b018919d2..9999fee70 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MassObject.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MassObject.java @@ -96,7 +96,7 @@ public abstract class MassObject extends InternalComponent { } public final void setRadialDirection(double radialDirection) { - radialDirection = MathUtil.reduce180(radialDirection); + radialDirection = MathUtil.reducePi(radialDirection); if (MathUtil.equals(this.radialDirection, radialDirection)) { return; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java index daf79abda..23f2f0474 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java @@ -192,7 +192,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo @Override public void setAngleOffset(final double angle_rad) { mutex.verify(); - this.angleOffset_rad = MathUtil.reduce180( angle_rad); + this.angleOffset_rad = MathUtil.reducePi( angle_rad); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java index 18473586c..77e3ddeb3 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RingComponent.java @@ -102,7 +102,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi * @param dir the radial direction. */ public void setRadialDirection(double dir) { - dir = MathUtil.reduce180(dir); + dir = MathUtil.reducePi(dir); if (radialDirection == dir) return; radialDirection = dir; diff --git a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java index 936a6d584..0ebcb803d 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/TubeFinSet.java @@ -373,7 +373,7 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable, @Override public void setAngleOffset(double angleRadians) { - final double reducedAngle = MathUtil.reducePI(angleRadians); + final double reducedAngle = MathUtil.reducePi(angleRadians); if (MathUtil.equals(reducedAngle, firstFinOffsetRadians)) return; firstFinOffsetRadians = reducedAngle; @@ -416,7 +416,7 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable, double[] result = new double[getFinCount()]; for (int finNumber=0; finNumber < getFinCount(); ++finNumber) { double additionalOffset = angleIncrementRadians * finNumber; - result[finNumber] = MathUtil.reduce2PI(firstFinOffsetRadians + additionalOffset); + result[finNumber] = MathUtil.reduce2Pi(firstFinOffsetRadians + additionalOffset); } return result; diff --git a/core/src/net/sf/openrocket/rocketcomponent/position/AngleMethod.java b/core/src/net/sf/openrocket/rocketcomponent/position/AngleMethod.java index 59395da17..9d3cc7c3b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/position/AngleMethod.java +++ b/core/src/net/sf/openrocket/rocketcomponent/position/AngleMethod.java @@ -35,7 +35,7 @@ public enum AngleMethod implements DistanceMethod { @Override public double getAngle( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){ - double combinedAngle = MathUtil.reduce2PI( parentComponent.getAngleOffset() + requestedOffset ); + double combinedAngle = MathUtil.reduce2Pi( parentComponent.getAngleOffset() + requestedOffset ); if( Math.PI > combinedAngle ) { combinedAngle = - ( combinedAngle - Math.PI); @@ -65,4 +65,4 @@ public enum AngleMethod implements DistanceMethod { public abstract double getAngle( final RocketComponent parentComponent, final RocketComponent thisComponent, final double angleOffset_radians ) ; -} \ No newline at end of file +} diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index 5aa4d534b..a4d4b959b 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -128,7 +128,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { } public void setLaunchRodDirection(double launchRodDirection) { - launchRodDirection = MathUtil.reduce360(launchRodDirection); + launchRodDirection = MathUtil.reduce2Pi(launchRodDirection); if (MathUtil.equals(this.launchRodDirection, launchRodDirection)) return; this.launchRodDirection = launchRodDirection; @@ -189,7 +189,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { */ public void setWindDirection(double direction) { - direction = MathUtil.reduce360(direction); + direction = MathUtil.reduce2Pi(direction); if (launchIntoWind) { this.setLaunchRodDirection(direction); } diff --git a/core/src/net/sf/openrocket/startup/Preferences.java b/core/src/net/sf/openrocket/startup/Preferences.java index 480f990cb..32fc63c97 100644 --- a/core/src/net/sf/openrocket/startup/Preferences.java +++ b/core/src/net/sf/openrocket/startup/Preferences.java @@ -233,7 +233,7 @@ public abstract class Preferences implements ChangeSource { } public void setLaunchRodDirection(double launchRodDirection) { - launchRodDirection = MathUtil.reduce360(launchRodDirection); + launchRodDirection = MathUtil.reduce2Pi(launchRodDirection); if (MathUtil.equals(this.getDouble(LAUNCH_ROD_DIRECTION, Math.PI / 2.0), launchRodDirection)) return; this.putDouble(LAUNCH_ROD_DIRECTION, launchRodDirection); @@ -267,7 +267,7 @@ public abstract class Preferences implements ChangeSource { } public void setWindDirection(double direction) { - direction = MathUtil.reduce360(direction); + direction = MathUtil.reduce2Pi(direction); if (this.getBoolean(LAUNCH_INTO_WIND, true)) { this.setLaunchRodDirection(direction); } diff --git a/core/src/net/sf/openrocket/util/MathUtil.java b/core/src/net/sf/openrocket/util/MathUtil.java index ef6cc4956..e1ae86c12 100644 --- a/core/src/net/sf/openrocket/util/MathUtil.java +++ b/core/src/net/sf/openrocket/util/MathUtil.java @@ -193,7 +193,7 @@ public class MathUtil { * @param x Original angle. * @return The equivalent angle in the range -PI ... PI. */ - public static double reducePI(double x) { + public static double reducePi(double x) { double d = Math.rint(x / (2 * Math.PI)); return x - d * 2 * Math.PI; } @@ -203,40 +203,12 @@ public class MathUtil { * @param x Original angle. * @return The equivalent angle in the range 0 ... 2*PI. */ - public static double reduce2PI(double x) { - double d = Math.floor(x / (2 * Math.PI)); - return x - d * 2 * Math.PI; - } - - - /** - * Reduce the angle x to the range 0 - 2*PI. - * - * @deprecated function refers to units:degrees, but operates in units:radians. Please use 'MathUtil.reduce2PI' - * @param x Original angle. - * @return The equivalent angle in the range 0 ... 2*PI. - */ - @Deprecated - public static double reduce360(double x) { + public static double reduce2Pi(double x) { double d = Math.floor(x / (2 * Math.PI)); return x - d * 2 * Math.PI; } - - /** - * Reduce the angle x to the range -PI - PI. - * - * Either -PI and PI might be returned, depending on the rounding function. - * - * @deprecated function refers to units:degrees, but operates in units:radians. Please use 'MathUtil.reducePI' - * @param x Original angle. - * @return The equivalent angle in the range -PI ... PI. - */ - @Deprecated - public static double reduce180(double x) { - double d = Math.rint(x / (2 * Math.PI)); - return x - d * 2 * Math.PI; - } - + + /** * Return the square root of a value. If the value is negative, zero is returned. * This is safer in cases where rounding errors might make a value slightly negative. diff --git a/core/src/net/sf/openrocket/util/WorldCoordinate.java b/core/src/net/sf/openrocket/util/WorldCoordinate.java index 762b02958..15f92a5d9 100644 --- a/core/src/net/sf/openrocket/util/WorldCoordinate.java +++ b/core/src/net/sf/openrocket/util/WorldCoordinate.java @@ -22,7 +22,7 @@ public class WorldCoordinate { */ public WorldCoordinate(double lat, double lon, double alt) { this.lat = MathUtil.clamp(Math.toRadians(lat), -Math.PI / 2, Math.PI / 2); - this.lon = MathUtil.reduce180(Math.toRadians(lon)); + this.lon = MathUtil.reducePi(Math.toRadians(lon)); this.alt = alt; } diff --git a/core/test/net/sf/openrocket/util/MathUtilTest.java b/core/test/net/sf/openrocket/util/MathUtilTest.java index 6b9c1e1ad..258542819 100644 --- a/core/test/net/sf/openrocket/util/MathUtilTest.java +++ b/core/test/net/sf/openrocket/util/MathUtilTest.java @@ -71,17 +71,17 @@ public class MathUtilTest { @Test public void reduceTest() { - + for (int i = -1000; i < 1000; i++) { double angle = Math.random() * 2 * PI; double shift = angle + i * 2 * PI; - assertEquals(angle, MathUtil.reduce360(shift), EPS); + assertEquals(angle, MathUtil.reduce2Pi(shift), EPS); } for (int i = -1000; i < 1000; i++) { double angle = Math.random() * 2 * PI - PI; double shift = angle + i * 2 * PI; - assertEquals(angle, MathUtil.reduce180(shift), EPS); + assertEquals(angle, MathUtil.reducePi(shift), EPS); } } diff --git a/swing/src/net/sf/openrocket/gui/components/compass/CompassSelectionButton.java b/swing/src/net/sf/openrocket/gui/components/compass/CompassSelectionButton.java index 097af46bd..5fc4f19b2 100644 --- a/swing/src/net/sf/openrocket/gui/components/compass/CompassSelectionButton.java +++ b/swing/src/net/sf/openrocket/gui/components/compass/CompassSelectionButton.java @@ -100,7 +100,7 @@ public class CompassSelectionButton extends FlatButton implements Resettable { private String getLabel(double value) { String str; - value = MathUtil.reduce360(value); + value = MathUtil.reduce2Pi(value); value = Math.toDegrees(value); str = "" + Math.round(value) + Chars.DEGREE + " ("; diff --git a/swing/src/net/sf/openrocket/gui/components/compass/CompassSelector.java b/swing/src/net/sf/openrocket/gui/components/compass/CompassSelector.java index fb77f2f4d..448bfb35c 100644 --- a/swing/src/net/sf/openrocket/gui/components/compass/CompassSelector.java +++ b/swing/src/net/sf/openrocket/gui/components/compass/CompassSelector.java @@ -77,7 +77,7 @@ public class CompassSelector extends CompassPointer { double distance = Math.hypot(x, y); double theta = Math.atan2(y, x); - theta = MathUtil.reduce360(theta + Math.PI / 2); + theta = MathUtil.reduce2Pi(theta + Math.PI / 2); // Round the value appropriately theta = Math.toDegrees(theta); diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 3058e2187..d81fed8bc 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -12,7 +12,6 @@ import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.ArrayList; -import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -565,14 +564,14 @@ public class RocketFigure3d extends JPanel implements GLEventListener { private void setRoll(final double rot) { if (MathUtil.equals(roll, rot)) return; - this.roll = MathUtil.reduce2PI(rot); + this.roll = MathUtil.reduce2Pi(rot); internalRepaint(); } private void setYaw(final double rot) { if (MathUtil.equals(yaw, rot)) return; - this.yaw = MathUtil.reduce2PI(rot); + this.yaw = MathUtil.reduce2Pi(rot); internalRepaint(); }