[refactor] ported reduce180 -> reducePi. Because the units are in radians
This commit is contained in:
parent
14bbcecc1e
commit
6efbe1e2ab
@ -949,7 +949,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;
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
@ -222,21 +222,6 @@ public class MathUtil {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class MathUtilTest {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user