Merge pull request #732 from teyrana/refactor/reduce180

Refactor out deprecated functions.
This commit is contained in:
Daniel Williams 2020-08-02 16:49:54 -04:00 committed by GitHub
commit 917503149c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 26 additions and 58 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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) {
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) {
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.

View File

@ -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;
}

View File

@ -75,13 +75,13 @@ public class MathUtilTest {
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);
}
}

View File

@ -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 + " (";

View File

@ -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);

View File

@ -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();
}