Merge pull request #732 from teyrana/refactor/reduce180
Refactor out deprecated functions.
This commit is contained in:
commit
917503149c
@ -6,9 +6,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
|
|
||||||
@ -949,7 +946,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAngleOffset(final double angleRadians) {
|
public void setAngleOffset(final double angleRadians) {
|
||||||
final double reducedAngle = MathUtil.reducePI(angleRadians);
|
final double reducedAngle = MathUtil.reducePi(angleRadians);
|
||||||
if (MathUtil.equals(reducedAngle, firstFinOffsetRadians))
|
if (MathUtil.equals(reducedAngle, firstFinOffsetRadians))
|
||||||
return;
|
return;
|
||||||
firstFinOffsetRadians = reducedAngle;
|
firstFinOffsetRadians = reducedAngle;
|
||||||
@ -974,7 +971,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
|
|||||||
|
|
||||||
double[] result = new double[ getFinCount()];
|
double[] result = new double[ getFinCount()];
|
||||||
for( int finNumber=0; finNumber < getFinCount(); ++finNumber ){
|
for( int finNumber=0; finNumber < getFinCount(); ++finNumber ){
|
||||||
result[finNumber] = MathUtil.reduce2PI( firstFinOffsetRadians + angleIncrementRadians*finNumber);
|
result[finNumber] = MathUtil.reduce2Pi( firstFinOffsetRadians + angleIncrementRadians*finNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -187,7 +187,7 @@ public class InnerTube extends ThicknessRingComponent implements AxialPositionab
|
|||||||
* @param rotation the clusterRotation to set
|
* @param rotation the clusterRotation to set
|
||||||
*/
|
*/
|
||||||
public void setClusterRotation(double rotation) {
|
public void setClusterRotation(double rotation) {
|
||||||
rotation = MathUtil.reduce180(rotation);
|
rotation = MathUtil.reducePi(rotation);
|
||||||
if (clusterRotation == rotation)
|
if (clusterRotation == rotation)
|
||||||
return;
|
return;
|
||||||
this.clusterRotation = rotation;
|
this.clusterRotation = rotation;
|
||||||
|
@ -96,7 +96,7 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void setRadialDirection(double radialDirection) {
|
public final void setRadialDirection(double radialDirection) {
|
||||||
radialDirection = MathUtil.reduce180(radialDirection);
|
radialDirection = MathUtil.reducePi(radialDirection);
|
||||||
if (MathUtil.equals(this.radialDirection, radialDirection)) {
|
if (MathUtil.equals(this.radialDirection, radialDirection)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
|
|||||||
@Override
|
@Override
|
||||||
public void setAngleOffset(final double angle_rad) {
|
public void setAngleOffset(final double angle_rad) {
|
||||||
mutex.verify();
|
mutex.verify();
|
||||||
this.angleOffset_rad = MathUtil.reduce180( angle_rad);
|
this.angleOffset_rad = MathUtil.reducePi( angle_rad);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
|
|||||||
* @param dir the radial direction.
|
* @param dir the radial direction.
|
||||||
*/
|
*/
|
||||||
public void setRadialDirection(double dir) {
|
public void setRadialDirection(double dir) {
|
||||||
dir = MathUtil.reduce180(dir);
|
dir = MathUtil.reducePi(dir);
|
||||||
if (radialDirection == dir)
|
if (radialDirection == dir)
|
||||||
return;
|
return;
|
||||||
radialDirection = dir;
|
radialDirection = dir;
|
||||||
|
@ -373,7 +373,7 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAngleOffset(double angleRadians) {
|
public void setAngleOffset(double angleRadians) {
|
||||||
final double reducedAngle = MathUtil.reducePI(angleRadians);
|
final double reducedAngle = MathUtil.reducePi(angleRadians);
|
||||||
if (MathUtil.equals(reducedAngle, firstFinOffsetRadians))
|
if (MathUtil.equals(reducedAngle, firstFinOffsetRadians))
|
||||||
return;
|
return;
|
||||||
firstFinOffsetRadians = reducedAngle;
|
firstFinOffsetRadians = reducedAngle;
|
||||||
@ -416,7 +416,7 @@ public class TubeFinSet extends ExternalComponent implements AxialPositionable,
|
|||||||
double[] result = new double[getFinCount()];
|
double[] result = new double[getFinCount()];
|
||||||
for (int finNumber=0; finNumber < getFinCount(); ++finNumber) {
|
for (int finNumber=0; finNumber < getFinCount(); ++finNumber) {
|
||||||
double additionalOffset = angleIncrementRadians * finNumber;
|
double additionalOffset = angleIncrementRadians * finNumber;
|
||||||
result[finNumber] = MathUtil.reduce2PI(firstFinOffsetRadians + additionalOffset);
|
result[finNumber] = MathUtil.reduce2Pi(firstFinOffsetRadians + additionalOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -35,7 +35,7 @@ public enum AngleMethod implements DistanceMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getAngle( final RocketComponent parentComponent, final RocketComponent thisComponent, final double requestedOffset ){
|
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 ) {
|
if( Math.PI > combinedAngle ) {
|
||||||
combinedAngle = - ( combinedAngle - Math.PI);
|
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 ) ;
|
public abstract double getAngle( final RocketComponent parentComponent, final RocketComponent thisComponent, final double angleOffset_radians ) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLaunchRodDirection(double launchRodDirection) {
|
public void setLaunchRodDirection(double launchRodDirection) {
|
||||||
launchRodDirection = MathUtil.reduce360(launchRodDirection);
|
launchRodDirection = MathUtil.reduce2Pi(launchRodDirection);
|
||||||
if (MathUtil.equals(this.launchRodDirection, launchRodDirection))
|
if (MathUtil.equals(this.launchRodDirection, launchRodDirection))
|
||||||
return;
|
return;
|
||||||
this.launchRodDirection = launchRodDirection;
|
this.launchRodDirection = launchRodDirection;
|
||||||
@ -189,7 +189,7 @@ public class SimulationOptions implements ChangeSource, Cloneable {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void setWindDirection(double direction) {
|
public void setWindDirection(double direction) {
|
||||||
direction = MathUtil.reduce360(direction);
|
direction = MathUtil.reduce2Pi(direction);
|
||||||
if (launchIntoWind) {
|
if (launchIntoWind) {
|
||||||
this.setLaunchRodDirection(direction);
|
this.setLaunchRodDirection(direction);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ public abstract class Preferences implements ChangeSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLaunchRodDirection(double launchRodDirection) {
|
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))
|
if (MathUtil.equals(this.getDouble(LAUNCH_ROD_DIRECTION, Math.PI / 2.0), launchRodDirection))
|
||||||
return;
|
return;
|
||||||
this.putDouble(LAUNCH_ROD_DIRECTION, launchRodDirection);
|
this.putDouble(LAUNCH_ROD_DIRECTION, launchRodDirection);
|
||||||
@ -267,7 +267,7 @@ public abstract class Preferences implements ChangeSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setWindDirection(double direction) {
|
public void setWindDirection(double direction) {
|
||||||
direction = MathUtil.reduce360(direction);
|
direction = MathUtil.reduce2Pi(direction);
|
||||||
if (this.getBoolean(LAUNCH_INTO_WIND, true)) {
|
if (this.getBoolean(LAUNCH_INTO_WIND, true)) {
|
||||||
this.setLaunchRodDirection(direction);
|
this.setLaunchRodDirection(direction);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ public class MathUtil {
|
|||||||
* @param x Original angle.
|
* @param x Original angle.
|
||||||
* @return The equivalent angle in the range -PI ... PI.
|
* @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));
|
double d = Math.rint(x / (2 * Math.PI));
|
||||||
return x - d * 2 * Math.PI;
|
return x - d * 2 * Math.PI;
|
||||||
}
|
}
|
||||||
@ -203,40 +203,12 @@ public class MathUtil {
|
|||||||
* @param x Original angle.
|
* @param x Original angle.
|
||||||
* @return The equivalent angle in the range 0 ... 2*PI.
|
* @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));
|
double d = Math.floor(x / (2 * Math.PI));
|
||||||
return x - d * 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.
|
* 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.
|
* This is safer in cases where rounding errors might make a value slightly negative.
|
||||||
|
@ -22,7 +22,7 @@ public class WorldCoordinate {
|
|||||||
*/
|
*/
|
||||||
public WorldCoordinate(double lat, double lon, double alt) {
|
public WorldCoordinate(double lat, double lon, double alt) {
|
||||||
this.lat = MathUtil.clamp(Math.toRadians(lat), -Math.PI / 2, Math.PI / 2);
|
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;
|
this.alt = alt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,17 +71,17 @@ public class MathUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void reduceTest() {
|
public void reduceTest() {
|
||||||
|
|
||||||
for (int i = -1000; i < 1000; i++) {
|
for (int i = -1000; i < 1000; i++) {
|
||||||
double angle = Math.random() * 2 * PI;
|
double angle = Math.random() * 2 * PI;
|
||||||
double shift = angle + i * 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++) {
|
for (int i = -1000; i < 1000; i++) {
|
||||||
double angle = Math.random() * 2 * PI - PI;
|
double angle = Math.random() * 2 * PI - PI;
|
||||||
double shift = angle + i * 2 * PI;
|
double shift = angle + i * 2 * PI;
|
||||||
assertEquals(angle, MathUtil.reduce180(shift), EPS);
|
assertEquals(angle, MathUtil.reducePi(shift), EPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class CompassSelectionButton extends FlatButton implements Resettable {
|
|||||||
private String getLabel(double value) {
|
private String getLabel(double value) {
|
||||||
String str;
|
String str;
|
||||||
|
|
||||||
value = MathUtil.reduce360(value);
|
value = MathUtil.reduce2Pi(value);
|
||||||
value = Math.toDegrees(value);
|
value = Math.toDegrees(value);
|
||||||
str = "" + Math.round(value) + Chars.DEGREE + " (";
|
str = "" + Math.round(value) + Chars.DEGREE + " (";
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class CompassSelector extends CompassPointer {
|
|||||||
double distance = Math.hypot(x, y);
|
double distance = Math.hypot(x, y);
|
||||||
|
|
||||||
double theta = Math.atan2(y, x);
|
double theta = Math.atan2(y, x);
|
||||||
theta = MathUtil.reduce360(theta + Math.PI / 2);
|
theta = MathUtil.reduce2Pi(theta + Math.PI / 2);
|
||||||
|
|
||||||
// Round the value appropriately
|
// Round the value appropriately
|
||||||
theta = Math.toDegrees(theta);
|
theta = Math.toDegrees(theta);
|
||||||
|
@ -12,7 +12,6 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -565,14 +564,14 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
private void setRoll(final double rot) {
|
private void setRoll(final double rot) {
|
||||||
if (MathUtil.equals(roll, rot))
|
if (MathUtil.equals(roll, rot))
|
||||||
return;
|
return;
|
||||||
this.roll = MathUtil.reduce2PI(rot);
|
this.roll = MathUtil.reduce2Pi(rot);
|
||||||
internalRepaint();
|
internalRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setYaw(final double rot) {
|
private void setYaw(final double rot) {
|
||||||
if (MathUtil.equals(yaw, rot))
|
if (MathUtil.equals(yaw, rot))
|
||||||
return;
|
return;
|
||||||
this.yaw = MathUtil.reduce2PI(rot);
|
this.yaw = MathUtil.reduce2Pi(rot);
|
||||||
internalRepaint();
|
internalRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user