Use Double.NaN to identify values that haven't been calculated. Spotting uncalculated values by checking for <0 is just asking for trouble down the line.
This commit is contained in:
parent
7fe41ed0ae
commit
9fec2af7a8
@ -30,13 +30,13 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
|
|
||||||
|
|
||||||
// Cached data, default values signify not calculated
|
// Cached data, default values signify not calculated
|
||||||
private double wetArea = -1;
|
private double wetArea = Double.NaN;
|
||||||
private double planArea = -1;
|
private double planArea = Double.NaN;
|
||||||
private double planCenter = -1;
|
private double planCenter = Double.NaN;
|
||||||
private double volume = -1;
|
private double volume = Double.NaN;
|
||||||
private double fullVolume = -1;
|
private double fullVolume = Double.NaN;
|
||||||
private double longitudinalInertia = -1;
|
private double longitudinalInertia = Double.NaN;
|
||||||
private double rotationalInertia = -1;
|
private double rotationalInertia = Double.NaN;
|
||||||
private Coordinate cg = null;
|
private Coordinate cg = null;
|
||||||
|
|
||||||
|
|
||||||
@ -213,8 +213,9 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double getComponentVolume() {
|
public double getComponentVolume() {
|
||||||
if (volume < 0)
|
if (Double.isNaN(volume)) {
|
||||||
integrate();
|
integrate();
|
||||||
|
}
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,8 +229,9 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
* @return The filled volume of the component.
|
* @return The filled volume of the component.
|
||||||
*/
|
*/
|
||||||
public double getFullVolume() {
|
public double getFullVolume() {
|
||||||
if (fullVolume < 0)
|
if (Double.isNaN(fullVolume)) {
|
||||||
integrate();
|
integrate();
|
||||||
|
}
|
||||||
return fullVolume;
|
return fullVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,8 +245,9 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
* @return The wetted area of the component.
|
* @return The wetted area of the component.
|
||||||
*/
|
*/
|
||||||
public double getComponentWetArea() {
|
public double getComponentWetArea() {
|
||||||
if (wetArea < 0)
|
if (Double.isNaN(wetArea)) {
|
||||||
integrate();
|
integrate();
|
||||||
|
}
|
||||||
return wetArea;
|
return wetArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +261,9 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
* @return The planform area of the component.
|
* @return The planform area of the component.
|
||||||
*/
|
*/
|
||||||
public double getComponentPlanformArea() {
|
public double getComponentPlanformArea() {
|
||||||
if (planArea < 0)
|
if (Double.isNaN(planArea)) {
|
||||||
integrate();
|
integrate();
|
||||||
|
}
|
||||||
return planArea;
|
return planArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,8 +278,9 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
* @return The planform center of the component.
|
* @return The planform center of the component.
|
||||||
*/
|
*/
|
||||||
public double getComponentPlanformCenter() {
|
public double getComponentPlanformCenter() {
|
||||||
if (planCenter < 0)
|
if (Double.isNaN(planCenter)) {
|
||||||
integrate();
|
integrate();
|
||||||
|
}
|
||||||
return planCenter;
|
return planCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +313,7 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getLongitudinalUnitInertia() {
|
public double getLongitudinalUnitInertia() {
|
||||||
if (longitudinalInertia < 0) {
|
if (Double.isNaN(longitudinalInertia)) {
|
||||||
if (getComponentVolume() > 0.0000001) // == 0.1cm^3
|
if (getComponentVolume() > 0.0000001) // == 0.1cm^3
|
||||||
integrateInertiaVolume();
|
integrateInertiaVolume();
|
||||||
else
|
else
|
||||||
@ -320,7 +325,7 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRotationalUnitInertia() {
|
public double getRotationalUnitInertia() {
|
||||||
if (rotationalInertia < 0) {
|
if (Double.isNaN(rotationalInertia)) {
|
||||||
if (getComponentVolume() > 0.0000001) // == 0.1cm^3
|
if (getComponentVolume() > 0.0000001) // == 0.1cm^3
|
||||||
integrateInertiaVolume();
|
integrateInertiaVolume();
|
||||||
else
|
else
|
||||||
@ -572,13 +577,13 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
|
|||||||
protected void componentChanged(ComponentChangeEvent e) {
|
protected void componentChanged(ComponentChangeEvent e) {
|
||||||
super.componentChanged(e);
|
super.componentChanged(e);
|
||||||
if( e.isAerodynamicChange() || e.isMassChange()){
|
if( e.isAerodynamicChange() || e.isMassChange()){
|
||||||
wetArea = -1;
|
wetArea = Double.NaN;
|
||||||
planArea = -1;
|
planArea = Double.NaN;
|
||||||
planCenter = -1;
|
planCenter = Double.NaN;
|
||||||
volume = -1;
|
volume = Double.NaN;
|
||||||
fullVolume = -1;
|
fullVolume = Double.NaN;
|
||||||
longitudinalInertia = -1;
|
longitudinalInertia = Double.NaN;
|
||||||
rotationalInertia = -1;
|
rotationalInertia = Double.NaN;
|
||||||
cg = null;
|
cg = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user