[refactor] ported reduce180 -> reducePi. Because the units are in radians

This commit is contained in:
Daniel_M_Williams 2020-08-02 16:34:07 -04:00
parent 14bbcecc1e
commit 6efbe1e2ab
9 changed files with 10 additions and 25 deletions

View File

@ -949,7 +949,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;

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;

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;
}
@ -221,22 +221,7 @@ public class MathUtil {
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

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