[refactor] ported reduce360 -> reduce2Pi. Because the units are in radians
This commit is contained in:
parent
6efbe1e2ab
commit
aeae4b1e03
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -203,25 +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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -75,7 +75,7 @@ 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++) {
|
||||
|
@ -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 + " (";
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user