Merge remote-tracking branch 'upstream/master' into unstable

This commit is contained in:
Kevin Ruland 2016-10-23 13:50:08 -05:00
commit f2d76e3b2b
14 changed files with 3477 additions and 295 deletions

View File

@ -14,7 +14,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
*/ */
private RocketComponent component = null; private RocketComponent component = null;
/** CP and CNa. */ /** CP and CNa. */
private Coordinate cp = null; private Coordinate cp = null;
@ -25,11 +25,11 @@ public class AerodynamicForces implements Cloneable, Monitorable {
* compute CNa directly. * compute CNa directly.
*/ */
private double CNa = Double.NaN; private double CNa = Double.NaN;
/** Normal force coefficient. */ /** Normal force coefficient. */
private double CN = Double.NaN; private double CN = Double.NaN;
/** Pitching moment coefficient, relative to the coordinate origin. */ /** Pitching moment coefficient, relative to the coordinate origin. */
private double Cm = Double.NaN; private double Cm = Double.NaN;
@ -48,7 +48,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
/** Roll moment forcing coefficient */ /** Roll moment forcing coefficient */
private double CrollForce = Double.NaN; private double CrollForce = Double.NaN;
/** Axial drag coefficient, CA */ /** Axial drag coefficient, CA */
private double Caxial = Double.NaN; private double Caxial = Double.NaN;
@ -73,6 +73,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
private boolean axisymmetric = true; private boolean axisymmetric = true;
<<<<<<< HEAD
public boolean isAxisymmetric(){ public boolean isAxisymmetric(){
return this.axisymmetric; return this.axisymmetric;
@ -80,161 +81,186 @@ public class AerodynamicForces implements Cloneable, Monitorable {
public void setAxisymmetric( final boolean isSym ){ public void setAxisymmetric( final boolean isSym ){
this.axisymmetric = isSym; this.axisymmetric = isSym;
=======
/**
* creates an empty bean of AerodynamicForces with NaN values
*/
public AerodynamicForces() {
//all done in members declarations
>>>>>>> refs/remotes/upstream/master
} }
/**
* initializes an AerodynamicForces already at zero
* @param zero flag to iniatilize value to zero or not
*/
public AerodynamicForces(boolean zero) {
if (zero)
this.zero();
}
/**
* gives a new component to be linked with
* changes it's modification id
* @param component The rocket component
*/
public void setComponent(RocketComponent component) { public void setComponent(RocketComponent component) {
this.component = component; this.component = component;
modID++; modID++;
} }
/**
*
* @return the actual component linked with this
*/
public RocketComponent getComponent() { public RocketComponent getComponent() {
return component; return component;
} }
public void setCP(Coordinate cp) { public void setCP(Coordinate cp) {
this.cp = cp; this.cp = cp;
modID++; modID++;
} }
public Coordinate getCP() { public Coordinate getCP() {
return cp; return cp;
} }
public void setCNa(double cNa) { public void setCNa(double cNa) {
CNa = cNa; CNa = cNa;
modID++; modID++;
} }
public double getCNa() { public double getCNa() {
return CNa; return CNa;
} }
public void setCN(double cN) { public void setCN(double cN) {
CN = cN; CN = cN;
modID++; modID++;
} }
public double getCN() { public double getCN() {
return CN; return CN;
} }
public void setCm(double cm) { public void setCm(double cm) {
Cm = cm; Cm = cm;
modID++; modID++;
} }
public double getCm() { public double getCm() {
return Cm; return Cm;
} }
public void setCside(double cside) { public void setCside(double cside) {
Cside = cside; Cside = cside;
modID++; modID++;
} }
public double getCside() { public double getCside() {
return Cside; return Cside;
} }
public void setCyaw(double cyaw) { public void setCyaw(double cyaw) {
Cyaw = cyaw; Cyaw = cyaw;
modID++; modID++;
} }
public double getCyaw() { public double getCyaw() {
return Cyaw; return Cyaw;
} }
public void setCroll(double croll) { public void setCroll(double croll) {
Croll = croll; Croll = croll;
modID++; modID++;
} }
public double getCroll() { public double getCroll() {
return Croll; return Croll;
} }
public void setCrollDamp(double crollDamp) { public void setCrollDamp(double crollDamp) {
CrollDamp = crollDamp; CrollDamp = crollDamp;
modID++; modID++;
} }
public double getCrollDamp() { public double getCrollDamp() {
return CrollDamp; return CrollDamp;
} }
public void setCrollForce(double crollForce) { public void setCrollForce(double crollForce) {
CrollForce = crollForce; CrollForce = crollForce;
modID++; modID++;
} }
public double getCrollForce() { public double getCrollForce() {
return CrollForce; return CrollForce;
} }
public void setCaxial(double caxial) { public void setCaxial(double caxial) {
Caxial = caxial; Caxial = caxial;
modID++; modID++;
} }
public double getCaxial() { public double getCaxial() {
return Caxial; return Caxial;
} }
public void setCD(double cD) { public void setCD(double cD) {
CD = cD; CD = cD;
modID++; modID++;
} }
public double getCD() { public double getCD() {
return CD; return CD;
} }
public void setPressureCD(double pressureCD) { public void setPressureCD(double pressureCD) {
this.pressureCD = pressureCD; this.pressureCD = pressureCD;
modID++; modID++;
} }
public double getPressureCD() { public double getPressureCD() {
return pressureCD; return pressureCD;
} }
public void setBaseCD(double baseCD) { public void setBaseCD(double baseCD) {
this.baseCD = baseCD; this.baseCD = baseCD;
modID++; modID++;
} }
public double getBaseCD() { public double getBaseCD() {
return baseCD; return baseCD;
} }
public void setFrictionCD(double frictionCD) { public void setFrictionCD(double frictionCD) {
this.frictionCD = frictionCD; this.frictionCD = frictionCD;
modID++; modID++;
} }
public double getFrictionCD() { public double getFrictionCD() {
return frictionCD; return frictionCD;
} }
public void setPitchDampingMoment(double pitchDampingMoment) { public void setPitchDampingMoment(double pitchDampingMoment) {
this.pitchDampingMoment = pitchDampingMoment; this.pitchDampingMoment = pitchDampingMoment;
modID++; modID++;
} }
public double getPitchDampingMoment() { public double getPitchDampingMoment() {
return pitchDampingMoment; return pitchDampingMoment;
} }
public void setYawDampingMoment(double yawDampingMoment) { public void setYawDampingMoment(double yawDampingMoment) {
this.yawDampingMoment = yawDampingMoment; this.yawDampingMoment = yawDampingMoment;
modID++; modID++;
} }
public double getYawDampingMoment() { public double getYawDampingMoment() {
return yawDampingMoment; return yawDampingMoment;
} }
/** /**
@ -242,7 +268,7 @@ public class AerodynamicForces implements Cloneable, Monitorable {
*/ */
public void reset() { public void reset() {
setComponent(null); setComponent(null);
setCP(null); setCP(null);
setCNa(Double.NaN); setCNa(Double.NaN);
setCN(Double.NaN); setCN(Double.NaN);
@ -263,8 +289,12 @@ public class AerodynamicForces implements Cloneable, Monitorable {
*/ */
public void zero() { public void zero() {
// component untouched // component untouched
<<<<<<< HEAD
setAxisymmetric(true); setAxisymmetric(true);
=======
>>>>>>> refs/remotes/upstream/master
setCP(Coordinate.NUL); setCP(Coordinate.NUL);
setCNa(0); setCNa(0);
setCN(0); setCN(0);
@ -279,12 +309,12 @@ public class AerodynamicForces implements Cloneable, Monitorable {
setPitchDampingMoment(0); setPitchDampingMoment(0);
setYawDampingMoment(0); setYawDampingMoment(0);
} }
@Override @Override
public AerodynamicForces clone() { public AerodynamicForces clone() {
try { try {
return (AerodynamicForces)super.clone(); return (AerodynamicForces) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new BugException("CloneNotSupportedException?!?"); throw new BugException("CloneNotSupportedException?!?");
} }
@ -319,13 +349,13 @@ public class AerodynamicForces implements Cloneable, Monitorable {
@Override @Override
public int hashCode() { public int hashCode() {
return (int) (1000*(this.getCD()+this.getCaxial()+this.getCNa())) + this.getCP().hashCode(); return (int) (1000 * (this.getCD() + this.getCaxial() + this.getCNa())) + this.getCP().hashCode();
} }
@Override @Override
public String toString() { public String toString() {
String text="AerodynamicForces["; String text = "AerodynamicForces[";
if (getComponent() != null) if (getComponent() != null)
text += "component:" + getComponent() + ","; text += "component:" + getComponent() + ",";
@ -351,14 +381,14 @@ public class AerodynamicForces implements Cloneable, Monitorable {
if (!Double.isNaN(getCD())) if (!Double.isNaN(getCD()))
text += "CD:" + getCD() + ","; text += "CD:" + getCD() + ",";
if (text.charAt(text.length()-1) == ',') if (text.charAt(text.length() - 1) == ',')
text = text.substring(0, text.length()-1); text = text.substring(0, text.length() - 1);
text += "]"; text += "]";
return text; return text;
} }
@Override @Override
public int getModID() { public int getModID() {
return modID; return modID;

View File

@ -41,7 +41,12 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
private double cacheDiameter = -1; private double cacheDiameter = -1;
private double cacheLength = -1; private double cacheLength = -1;
<<<<<<< HEAD
=======
>>>>>>> refs/remotes/upstream/master
public BarrowmanCalculator() { public BarrowmanCalculator() {
@ -65,17 +70,19 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return forces.getCP(); return forces.getCP();
} }
<<<<<<< HEAD
=======
>>>>>>> refs/remotes/upstream/master
@Override @Override
public Map<RocketComponent, AerodynamicForces> getForceAnalysis(FlightConfiguration configuration, public Map<RocketComponent, AerodynamicForces> getForceAnalysis(FlightConfiguration configuration,
FlightConditions conditions, WarningSet warnings) { FlightConditions conditions, WarningSet warnings) {
checkCache(configuration); checkCache(configuration);
AerodynamicForces f; Map<RocketComponent, AerodynamicForces> map = getComponentsMap(configuration);
Map<RocketComponent, AerodynamicForces> map =
new LinkedHashMap<RocketComponent, AerodynamicForces>();
<<<<<<< HEAD
// Add all components to the map // Add all components to the map
for (RocketComponent component : configuration.getActiveComponents()) { for (RocketComponent component : configuration.getActiveComponents()) {
@ -90,17 +97,25 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
=======
>>>>>>> refs/remotes/upstream/master
// Calculate non-axial force data // Calculate non-axial force data
AerodynamicForces total = calculateNonAxialForces(configuration, conditions, map, warnings); AerodynamicForces total = calculateNonAxialForces(configuration, conditions, map, warnings);
<<<<<<< HEAD
// Calculate friction data // Calculate friction data
total.setFrictionCD(calculateFrictionDrag(configuration, conditions, map, warnings)); total.setFrictionCD(calculateFrictionDrag(configuration, conditions, map, warnings));
total.setPressureCD(calculatePressureDrag(configuration, conditions, map, warnings)); total.setPressureCD(calculatePressureDrag(configuration, conditions, map, warnings));
total.setBaseCD(calculateBaseDrag(configuration, conditions, map, warnings)); total.setBaseCD(calculateBaseDrag(configuration, conditions, map, warnings));
=======
calculateFrictionData(total, configuration, conditions, warnings);
>>>>>>> refs/remotes/upstream/master
total.setComponent(configuration.getRocket()); total.setComponent(configuration.getRocket());
map.put(total.getComponent(), total); map.put(total.getComponent(), total);
<<<<<<< HEAD
for (RocketComponent c : map.keySet()) { for (RocketComponent c : map.keySet()) {
@ -118,10 +133,65 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
f.setCaxial(calculateAxialDrag(conditions, f.getCD())); f.setCaxial(calculateAxialDrag(conditions, f.getCD()));
} }
=======
checkCDAndApplyFriction(map, conditions);
>>>>>>> refs/remotes/upstream/master
return map; return map;
} }
/**
* get a map of rocket components with their own Aerodynamic forces bean
* TODO: LOW: maybe transfer the function to Configuration class?
* @param configuration The rocket configuration
* @return the map of rocket configuration with it's
* correspondent aerodynamic forces bean
*/
private Map<RocketComponent, AerodynamicForces> getComponentsMap(Configuration configuration) {
Map<RocketComponent, AerodynamicForces> map = new LinkedHashMap<RocketComponent, AerodynamicForces>();
// Add all components to the map
for (RocketComponent c : configuration) {
AerodynamicForces f = new AerodynamicForces();
f.setComponent(c);
map.put(c, f);
}
return map;
}
<<<<<<< HEAD
=======
/**
* check an analysis to fix possible invalid CDs and apply the actual friction
*
* @param forceAnalysis
* @param conditions
*/
private void checkCDAndApplyFriction(Map<RocketComponent, AerodynamicForces> forceAnalysis, FlightConditions conditions) {
for (RocketComponent c : forceAnalysis.keySet()) {
checkCDConsistency(forceAnalysis.get(c));
applyFriction(forceAnalysis.get(c), conditions);
}
}
/**
* fixes possibles NaN in previous calculation of CDs
*
* @param f
* @param conditions
*/
private void checkCDConsistency(AerodynamicForces f) {
if (Double.isNaN(f.getBaseCD()) && Double.isNaN(f.getPressureCD()) &&
Double.isNaN(f.getFrictionCD()))
return;
if (Double.isNaN(f.getBaseCD()))
f.setBaseCD(0);
if (Double.isNaN(f.getPressureCD()))
f.setPressureCD(0);
if (Double.isNaN(f.getFrictionCD()))
f.setFrictionCD(0);
}
>>>>>>> refs/remotes/upstream/master
@Override @Override
public AerodynamicForces getAerodynamicForces(FlightConfiguration configuration, public AerodynamicForces getAerodynamicForces(FlightConfiguration configuration,
@ -135,32 +205,73 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
AerodynamicForces total = calculateNonAxialForces(configuration, conditions, null, warnings); AerodynamicForces total = calculateNonAxialForces(configuration, conditions, null, warnings);
// Calculate friction data // Calculate friction data
total.setFrictionCD(calculateFrictionDrag(configuration, conditions, null, warnings)); calculateFrictionData(total, configuration, conditions, warnings);
total.setPressureCD(calculatePressureDrag(configuration, conditions, null, warnings)); applyFriction(total, conditions);
total.setBaseCD(calculateBaseDrag(configuration, conditions, null, warnings));
total.setCD(total.getFrictionCD() + total.getPressureCD() + total.getBaseCD());
total.setCaxial(calculateAxialDrag(conditions, total.getCD()));
// Calculate pitch and yaw damping moments // Calculate pitch and yaw damping moments
calculateDampingMoments(configuration, conditions, total); calculateDampingMoments(configuration, conditions, total);
<<<<<<< HEAD
total.setCm(total.getCm() - total.getPitchDampingMoment()); total.setCm(total.getCm() - total.getPitchDampingMoment());
total.setCyaw(total.getCyaw() - total.getYawDampingMoment()); total.setCyaw(total.getCyaw() - total.getYawDampingMoment());
=======
applyDampingMoments(total);
>>>>>>> refs/remotes/upstream/master
return total; return total;
} }
/**
* Applies the actual influence of friction in an AerodynamicForces set
*
* @param force the Aerodynamic forces to be applied with friction
* @param conditions the flight conditions in consideration
*/
private void applyFriction(AerodynamicForces force, FlightConditions conditions) {
force.setCD(force.getFrictionCD() + force.getPressureCD() + force.getBaseCD());
force.setCaxial(calculateAxialDrag(conditions, force.getCD()));
}
<<<<<<< HEAD
private AerodynamicForces calculateNonAxialForces(FlightConfiguration configuration, FlightConditions conditions, private AerodynamicForces calculateNonAxialForces(FlightConfiguration configuration, FlightConditions conditions,
=======
/**
* does the actual action of damping into an AerodynamicForces set
*
* @param total the AerodynamicForces object to be applied with the damping
*/
private void applyDampingMoments(AerodynamicForces total) {
total.setCm(total.getCm() - total.getPitchDampingMoment());
total.setCyaw(total.getCyaw() - total.getYawDampingMoment());
}
/**
* Will calculate all basic CD from an AerodynamicForces set
* @param total The AerodynamicForces that will be calculated
* @param configuration the Rocket configutarion
* @param conditions Flight conditions in the simulation
* @param warnings Warning set to handle special events
*/
private void calculateFrictionData(AerodynamicForces total, Configuration configuration, FlightConditions conditions, WarningSet warnings) {
total.setFrictionCD(calculateFrictionDrag(configuration, conditions, null, warnings));
total.setPressureCD(calculatePressureDrag(configuration, conditions, null, warnings));
total.setBaseCD(calculateBaseDrag(configuration, conditions, null, warnings));
}
/**
* Perform the actual CP calculation.
*/
private AerodynamicForces calculateNonAxialForces(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) { Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) {
checkCache(configuration); checkCache(configuration);
AerodynamicForces total = new AerodynamicForces(); AerodynamicForces total = new AerodynamicForces(true);
total.zero();
AerodynamicForces forces = new AerodynamicForces(); AerodynamicForces forces = new AerodynamicForces();
@ -171,8 +282,12 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
warnings.add(new Warning.LargeAOA(conditions.getAOA())); warnings.add(new Warning.LargeAOA(conditions.getAOA()));
<<<<<<< HEAD
if (calcMap == null) if (calcMap == null)
buildCalcMap(configuration); buildCalcMap(configuration);
=======
checkCalcMap(configuration);
>>>>>>> refs/remotes/upstream/master
if( ! isContinuous( configuration.getRocket() ) ){ if( ! isContinuous( configuration.getRocket() ) ){
@ -218,6 +333,7 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
double CN_instanced = forces.getCN() * instanceCount; double CN_instanced = forces.getCN() * instanceCount;
forces.setCm(CN_instanced * forces.getCP().x / conditions.getRefLength()); forces.setCm(CN_instanced * forces.getCP().x / conditions.getRefLength());
//TODO: LOW: Why is it here? was this the todo from above? Vicilu
if (map != null) { if (map != null) {
AerodynamicForces f = map.get(component); AerodynamicForces f = map.get(component);
@ -230,6 +346,7 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
f.setCroll(forces.getCroll()); f.setCroll(forces.getCroll());
f.setCrollDamp(forces.getCrollDamp()); f.setCrollDamp(forces.getCrollDamp());
f.setCrollForce(forces.getCrollForce()); f.setCrollForce(forces.getCrollForce());
map.put(component, f);
} }
total.setCP(total.getCP().average(forces.getCP())); total.setCP(total.getCP().average(forces.getCP()));
@ -247,6 +364,7 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
<<<<<<< HEAD
@Override @Override
public boolean isContinuous( final Rocket rkt){ public boolean isContinuous( final Rocket rkt){
return testIsContinuous( rkt); return testIsContinuous( rkt);
@ -295,9 +413,26 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
//////////////// DRAG CALCULATIONS //////////////// //////////////// DRAG CALCULATIONS ////////////////
=======
>>>>>>> refs/remotes/upstream/master
<<<<<<< HEAD
private double calculateFrictionDrag(FlightConfiguration configuration, FlightConditions conditions, private double calculateFrictionDrag(FlightConfiguration configuration, FlightConditions conditions,
=======
//////////////// DRAG CALCULATIONS ////////////////
//TODO: LOW: clarify what map is doing here, or use it
/**
* Calculation of drag coefficient due to air friction
*
* @param configuration Rocket configuration
* @param conditions Flight conditions taken into account
* @param map ?
* @param set Set to handle
* @return
*/
private double calculateFrictionDrag(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
Map<RocketComponent, AerodynamicForces> map, WarningSet set) { Map<RocketComponent, AerodynamicForces> map, WarningSet set) {
double c1 = 1.0, c2 = 1.0; double c1 = 1.0, c2 = 1.0;
@ -305,8 +440,7 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
double Re; double Re;
double Cf; double Cf;
if (calcMap == null) checkCalcMap(configuration);
buildCalcMap(configuration);
Re = conditions.getVelocity() * configuration.getLength() / Re = conditions.getVelocity() * configuration.getLength() /
conditions.getAtmosphericConditions().getKinematicViscosity(); conditions.getAtmosphericConditions().getKinematicViscosity();
@ -427,9 +561,8 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
// Calculate the roughness-limited friction coefficient // Calculate the roughness-limited friction coefficient
Finish finish = ((ExternalComponent) c).getFinish(); Finish finish = ((ExternalComponent) c).getFinish();
if (Double.isNaN(roughnessLimited[finish.ordinal()])) { if (Double.isNaN(roughnessLimited[finish.ordinal()])) {
roughnessLimited[finish.ordinal()] = roughnessLimited[finish.ordinal()] = 0.032 * Math.pow(finish.getRoughnessSize() / configuration.getLength(), 0.2) *
0.032 * Math.pow(finish.getRoughnessSize() / configuration.getLength(), 0.2) * roughnessCorrection;
roughnessCorrection;
} }
/* /*
@ -504,16 +637,37 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return (finFriction + correction * bodyFriction) / conditions.getRefArea(); return (finFriction + correction * bodyFriction) / conditions.getRefArea();
} }
/**
* method to avoid repetition, create the calcMap if null
* @param configuration the rocket configuration
*/
private void checkCalcMap(Configuration configuration) {
if (calcMap == null)
buildCalcMap(configuration);
}
<<<<<<< HEAD
private double calculatePressureDrag(FlightConfiguration configuration, FlightConditions conditions, private double calculatePressureDrag(FlightConfiguration configuration, FlightConditions conditions,
=======
//TODO: LOW: clarify what map is doing here, or use it
/**
* Calculation of drag coefficient due to pressure
*
* @param configuration Rocket configuration
* @param conditions Flight conditions taken into account
* @param map ?
* @param set Set to handle
* @return
*/
private double calculatePressureDrag(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) { Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) {
double stagnation, base, total; double stagnation, base, total;
double radius = 0; double radius = 0;
if (calcMap == null) checkCalcMap(configuration);
buildCalcMap(configuration);
stagnation = calculateStagnationCD(conditions.getMach()); stagnation = calculateStagnationCD(conditions.getMach());
base = calculateBaseCD(conditions.getMach()); base = calculateBaseCD(conditions.getMach());
@ -553,16 +707,29 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return total; return total;
} }
<<<<<<< HEAD
private double calculateBaseDrag(FlightConfiguration configuration, FlightConditions conditions, private double calculateBaseDrag(FlightConfiguration configuration, FlightConditions conditions,
=======
//TODO: LOW: clarify what map is doing here, or use it
/**
* Calculation of drag coefficient due to base
*
* @param configuration Rocket configuration
* @param conditions Flight conditions taken into account
* @param map ?
* @param set Set to handle
* @return
*/
private double calculateBaseDrag(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) { Map<RocketComponent, AerodynamicForces> map, WarningSet warnings) {
double base, total; double base, total;
double radius = 0; double radius = 0;
RocketComponent prevComponent = null; RocketComponent prevComponent = null;
if (calcMap == null) checkCalcMap(configuration);
buildCalcMap(configuration);
base = calculateBaseCD(conditions.getMach()); base = calculateBaseCD(conditions.getMach());
total = 0; total = 0;
@ -599,7 +766,15 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
<<<<<<< HEAD
=======
/**
* gets CD by the speed
* @param m Mach number for calculation
* @return Stagnation CD
*/
>>>>>>> refs/remotes/upstream/master
public static double calculateStagnationCD(double m) { public static double calculateStagnationCD(double m) {
double pressure; double pressure;
if (m <= 1) { if (m <= 1) {
@ -610,7 +785,11 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return 0.85 * pressure; return 0.85 * pressure;
} }
/**
* Calculates base CD
* @param m Mach number for calculation
* @return Base CD
*/
public static double calculateBaseCD(double m) { public static double calculateBaseCD(double m) {
if (m <= 1) { if (m <= 1) {
return 0.12 + 0.13 * m * m; return 0.12 + 0.13 * m * m;
@ -626,15 +805,13 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
PolyInterpolator interpolator; PolyInterpolator interpolator;
interpolator = new PolyInterpolator( interpolator = new PolyInterpolator(
new double[] { 0, 17 * Math.PI / 180 }, new double[] { 0, 17 * Math.PI / 180 },
new double[] { 0, 17 * Math.PI / 180 } new double[] { 0, 17 * Math.PI / 180 });
);
axialDragPoly1 = interpolator.interpolator(1, 1.3, 0, 0); axialDragPoly1 = interpolator.interpolator(1, 1.3, 0, 0);
interpolator = new PolyInterpolator( interpolator = new PolyInterpolator(
new double[] { 17 * Math.PI / 180, Math.PI / 2 }, new double[] { 17 * Math.PI / 180, Math.PI / 2 },
new double[] { 17 * Math.PI / 180, Math.PI / 2 }, new double[] { 17 * Math.PI / 180, Math.PI / 2 },
new double[] { Math.PI / 2 } new double[] { Math.PI / 2 });
);
axialDragPoly2 = interpolator.interpolator(1.3, 0, 0, 0, 0); axialDragPoly2 = interpolator.interpolator(1.3, 0, 0, 0, 0);
} }
@ -667,8 +844,18 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return -mul * cd; return -mul * cd;
} }
<<<<<<< HEAD
private void calculateDampingMoments(FlightConfiguration configuration, FlightConditions conditions, private void calculateDampingMoments(FlightConfiguration configuration, FlightConditions conditions,
=======
/**
* get damping moments from a rocket in a flight
* @param configuration Rocket configuration
* @param conditions flight conditions in consideration
* @param total acting aerodynamic forces
*/
private void calculateDampingMoments(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
AerodynamicForces total) { AerodynamicForces total) {
// Calculate pitch and yaw damping moments // Calculate pitch and yaw damping moments
@ -689,7 +876,11 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
// TODO: MEDIUM: Are the rotation etc. being added correctly? sin/cos theta? // TODO: MEDIUM: Are the rotation etc. being added correctly? sin/cos theta?
<<<<<<< HEAD
private double getDampingMultiplier(FlightConfiguration configuration, FlightConditions conditions, private double getDampingMultiplier(FlightConfiguration configuration, FlightConditions conditions,
=======
private double getDampingMultiplier(Configuration configuration, FlightConditions conditions,
>>>>>>> refs/remotes/upstream/master
double cgx) { double cgx) {
if (cacheDiameter < 0) { if (cacheDiameter < 0) {
double area = 0; double area = 0;
@ -721,7 +912,12 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
mul += 0.6 * Math.min(f.getFinCount(), 4) * f.getFinArea() * mul += 0.6 * Math.min(f.getFinCount(), 4) * f.getFinArea() *
MathUtil.pow3(Math.abs(f.toAbsolute(new Coordinate( MathUtil.pow3(Math.abs(f.toAbsolute(new Coordinate(
((FinSetCalc) calcMap.get(f)).getMidchordPos()))[0].x ((FinSetCalc) calcMap.get(f)).getMidchordPos()))[0].x
<<<<<<< HEAD
- cgx)) / - cgx)) /
=======
- cgx))
/
>>>>>>> refs/remotes/upstream/master
(conditions.getRefArea() * conditions.getRefLength()); (conditions.getRefArea() * conditions.getRefLength());
} }
} }
@ -730,9 +926,13 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
} }
<<<<<<< HEAD
//////// The calculator map //////// The calculator map
=======
>>>>>>> refs/remotes/upstream/master
//////// The calculator map
@Override @Override
protected void voidAerodynamicCache() { protected void voidAerodynamicCache() {
super.voidAerodynamicCache(); super.voidAerodynamicCache();
@ -742,8 +942,16 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
cacheLength = -1; cacheLength = -1;
} }
<<<<<<< HEAD
private void buildCalcMap(FlightConfiguration configuration) { private void buildCalcMap(FlightConfiguration configuration) {
=======
/**
* caches the map for aerodynamics calculations
* @param configuration the rocket configuration
*/
private void buildCalcMap(Configuration configuration) {
>>>>>>> refs/remotes/upstream/master
Iterator<RocketComponent> iterator; Iterator<RocketComponent> iterator;
//System.err.println("> Building Calc Map."); //System.err.println("> Building Calc Map.");
@ -770,4 +978,8 @@ public class BarrowmanCalculator extends AbstractAerodynamicCalculator {
return 0; return 0;
} }
<<<<<<< HEAD
=======
>>>>>>> refs/remotes/upstream/master
} }

View File

@ -63,9 +63,12 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** Current roll rate. */ /** Current roll rate. */
private double rollRate = 0; private double rollRate = 0;
/** Current pitch rate. */
private double pitchRate = 0; private double pitchRate = 0;
/** Current yaw rate. */
private double yawRate = 0; private double yawRate = 0;
private Coordinate pitchCenter = Coordinate.NUL; private Coordinate pitchCenter = Coordinate.NUL;
@ -102,6 +105,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Set the reference length and area. * Set the reference length and area.
* fires change event
*/ */
public void setRefLength(double length) { public void setRefLength(double length) {
refLength = length; refLength = length;
@ -111,7 +115,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} }
/** /**
* Return the reference length. * @return the reference length.
*/ */
public double getRefLength() { public double getRefLength() {
return refLength; return refLength;
@ -119,6 +123,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Set the reference area and length. * Set the reference area and length.
* fires change event
*/ */
public void setRefArea(double area) { public void setRefArea(double area) {
refArea = area; refArea = area;
@ -127,7 +132,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} }
/** /**
* Return the reference area. * @return the reference area.
*/ */
public double getRefArea() { public double getRefArea() {
return refArea; return refArea;
@ -137,7 +142,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Sets the angle of attack. It calculates values also for the methods * Sets the angle of attack. It calculates values also for the methods
* {@link #getSinAOA()} and {@link #getSincAOA()}. * {@link #getSinAOA()} and {@link #getSincAOA()}.
* * fires change event if it's different from previous value
* @param aoa the angle of attack. * @param aoa the angle of attack.
*/ */
public void setAOA(double aoa) { public void setAOA(double aoa) {
@ -162,6 +167,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
* to be the sine of <code>aoa</code> for cases in which this value is known. * to be the sine of <code>aoa</code> for cases in which this value is known.
* The AOA must still be specified, as the sine is not unique in the range * The AOA must still be specified, as the sine is not unique in the range
* of 0..180 degrees. * of 0..180 degrees.
* fires change event if it's different from previous value
* *
* @param aoa the angle of attack in radians. * @param aoa the angle of attack in radians.
* @param sinAOA the sine of the angle of attack. * @param sinAOA the sine of the angle of attack.
@ -186,21 +192,21 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Return the angle of attack. * @return the angle of attack.
*/ */
public double getAOA() { public double getAOA() {
return aoa; return aoa;
} }
/** /**
* Return the sine of the angle of attack. * @return the sine of the angle of attack.
*/ */
public double getSinAOA() { public double getSinAOA() {
return sinAOA; return sinAOA;
} }
/** /**
* Return the sinc of the angle of attack (sin(AOA) / AOA). This method returns * @return the sinc of the angle of attack (sin(AOA) / AOA). This method returns
* one if the angle of attack is zero. * one if the angle of attack is zero.
*/ */
public double getSincAOA() { public double getSincAOA() {
@ -210,6 +216,8 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Set the direction of the lateral airflow. * Set the direction of the lateral airflow.
* fires change event if it's different from previous value
*
*/ */
public void setTheta(double theta) { public void setTheta(double theta) {
if (MathUtil.equals(this.theta, theta)) if (MathUtil.equals(this.theta, theta))
@ -219,7 +227,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} }
/** /**
* Return the direction of the lateral airflow. * @return the direction of the lateral airflow.
*/ */
public double getTheta() { public double getTheta() {
return theta; return theta;
@ -229,6 +237,8 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Set the current Mach speed. This should be (but is not required to be) in * Set the current Mach speed. This should be (but is not required to be) in
* reference to the speed of sound of the atmospheric conditions. * reference to the speed of sound of the atmospheric conditions.
*
* fires change event if it's different from previous value
*/ */
public void setMach(double mach) { public void setMach(double mach) {
mach = Math.max(mach, 0); mach = Math.max(mach, 0);
@ -244,7 +254,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} }
/** /**
* Return the current Mach speed. * @return the current Mach speed.
*/ */
public double getMach() { public double getMach() {
return mach; return mach;
@ -272,7 +282,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Return sqrt(abs(1 - Mach^2)). This is calculated in the setting call and is * @return sqrt(abs(1 - Mach^2)). This is calculated in the setting call and is
* therefore fast. * therefore fast.
*/ */
public double getBeta() { public double getBeta() {
@ -281,7 +291,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Return the current roll rate. * @return the current roll rate.
*/ */
public double getRollRate() { public double getRollRate() {
return rollRate; return rollRate;
@ -290,6 +300,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Set the current roll rate. * Set the current roll rate.
* fires change event if it's different from previous
*/ */
public void setRollRate(double rate) { public void setRollRate(double rate) {
if (MathUtil.equals(this.rollRate, rate)) if (MathUtil.equals(this.rollRate, rate))
@ -300,11 +311,19 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
} }
/**
*
* @return current pitch rate
*/
public double getPitchRate() { public double getPitchRate() {
return pitchRate; return pitchRate;
} }
/**
* sets the pitch rate
* fires change event if it's different from previous
* @param pitchRate
*/
public void setPitchRate(double pitchRate) { public void setPitchRate(double pitchRate) {
if (MathUtil.equals(this.pitchRate, pitchRate)) if (MathUtil.equals(this.pitchRate, pitchRate))
return; return;
@ -312,7 +331,10 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
fireChangeEvent(); fireChangeEvent();
} }
/**
*
* @return current yaw rate
*/
public double getYawRate() { public double getYawRate() {
return yawRate; return yawRate;
} }
@ -402,7 +424,7 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
/** /**
* Return a copy of the flight conditions. The copy has no listeners. The * @return a copy of the flight conditions. The copy has no listeners. The
* atmospheric conditions is also cloned. * atmospheric conditions is also cloned.
*/ */
@Override @Override
@ -454,6 +476,9 @@ public class FlightConditions implements Cloneable, ChangeSource, Monitorable {
listenerList.remove(listener); listenerList.remove(listener);
} }
/**
* wake up call to listeners
*/
protected void fireChangeEvent() { protected void fireChangeEvent() {
modID = UniqueID.next(); modID = UniqueID.next();
// Copy the list before iterating to prevent concurrent modification exceptions. // Copy the list before iterating to prevent concurrent modification exceptions.

View File

@ -7,10 +7,11 @@ import net.sf.openrocket.unit.UnitGroup;
public abstract class Warning { public abstract class Warning {
/** support to multiple languages warning */
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
/** /**
* Return a Warning with the specific text. * @return a Warning with the specific text.
*/ */
public static Warning fromString(String text) { public static Warning fromString(String text) {
return new Warning.Other(text); return new Warning.Other(text);
@ -321,43 +322,33 @@ public abstract class Warning {
/** A <code>Warning</code> that the body diameter is discontinuous. */ /** A <code>Warning</code> that the body diameter is discontinuous. */
////Discontinuity in rocket body diameter. ////Discontinuity in rocket body diameter.
public static final Warning DIAMETER_DISCONTINUITY = public static final Warning DIAMETER_DISCONTINUITY = new Other(trans.get("Warning.DISCONTINUITY"));
new Other(trans.get("Warning.DISCONTINUITY"));
/** A <code>Warning</code> that the fins are thick compared to the rocket body. */ /** A <code>Warning</code> that the fins are thick compared to the rocket body. */
////Thick fins may not be modeled accurately. ////Thick fins may not be modeled accurately.
public static final Warning THICK_FIN = public static final Warning THICK_FIN = new Other(trans.get("Warning.THICK_FIN"));
new Other(trans.get("Warning.THICK_FIN"));
/** A <code>Warning</code> that the fins have jagged edges. */ /** A <code>Warning</code> that the fins have jagged edges. */
////Jagged-edged fin predictions may be inaccurate. ////Jagged-edged fin predictions may be inaccurate.
public static final Warning JAGGED_EDGED_FIN = public static final Warning JAGGED_EDGED_FIN = new Other(trans.get("Warning.JAGGED_EDGED_FIN"));
new Other(trans.get("Warning.JAGGED_EDGED_FIN"));
/** A <code>Warning</code> that simulation listeners have affected the simulation */ /** A <code>Warning</code> that simulation listeners have affected the simulation */
////Listeners modified the flight simulation ////Listeners modified the flight simulation
public static final Warning LISTENERS_AFFECTED = public static final Warning LISTENERS_AFFECTED = new Other(trans.get("Warning.LISTENERS_AFFECTED"));
new Other(trans.get("Warning.LISTENERS_AFFECTED"));
////Recovery device opened while motor still burning. ////Recovery device opened while motor still burning.
public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING = public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING = new Other(trans.get("Warning.RECOVERY_DEPLOYMENT_WHILE_BURNING"));
new Other(trans.get("Warning.RECOVERY_DEPLOYMENT_WHILE_BURNING"));
//// Invalid parameter encountered, ignoring. //// Invalid parameter encountered, ignoring.
public static final Warning FILE_INVALID_PARAMETER = public static final Warning FILE_INVALID_PARAMETER = new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));
new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));
public static final Warning PARALLEL_FINS = public static final Warning PARALLEL_FINS = new Other(trans.get("Warning.PARALLEL_FINS"));
new Other(trans.get("Warning.PARALLEL_FINS"));
public static final Warning SUPERSONIC = public static final Warning SUPERSONIC = new Other(trans.get("Warning.SUPERSONIC"));
new Other(trans.get("Warning.SUPERSONIC"));
public static final Warning RECOVERY_LAUNCH_ROD = public static final Warning RECOVERY_LAUNCH_ROD = new Other(trans.get("Warning.RECOVERY_LAUNCH_ROD"));
new Other(trans.get("Warning.RECOVERY_LAUNCH_ROD"));
public static final Warning TUMBLE_UNDER_THRUST = public static final Warning TUMBLE_UNDER_THRUST = new Other(trans.get("Warning.TUMBLE_UNDER_THRUST"));
new Other(trans.get("Warning.TUMBLE_UNDER_THRUST"));
} }

View File

@ -20,6 +20,7 @@ import net.sf.openrocket.util.Mutable;
*/ */
public class WarningSet extends AbstractSet<Warning> implements Cloneable, Monitorable { public class WarningSet extends AbstractSet<Warning> implements Cloneable, Monitorable {
/** the actual array of warnings*/
private ArrayList<Warning> warnings = new ArrayList<Warning>(); private ArrayList<Warning> warnings = new ArrayList<Warning>();
private Mutable mutable = new Mutable(); private Mutable mutable = new Mutable();

View File

@ -5,6 +5,9 @@ import static net.sf.openrocket.util.MathUtil.pow2;
import java.util.Arrays; import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.aerodynamics.AerodynamicForces; import net.sf.openrocket.aerodynamics.AerodynamicForces;
import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.FlightConditions;
import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.Warning;
@ -17,14 +20,13 @@ import net.sf.openrocket.util.LinearInterpolator;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.PolyInterpolator; import net.sf.openrocket.util.PolyInterpolator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FinSetCalc extends RocketComponentCalc { public class FinSetCalc extends RocketComponentCalc {
/** logger for debugging*/
private final static Logger logger = LoggerFactory.getLogger(FinSetCalc.class); private final static Logger logger = LoggerFactory.getLogger(FinSetCalc.class);
/** considers the stall angle as 20 degrees*/
private static final double STALL_ANGLE = (20 * Math.PI / 180); private static final double STALL_ANGLE = (20 * Math.PI / 180);
/** Number of divisions in the fin chords. */ /** Number of divisions in the fin chords. */
@ -57,25 +59,27 @@ public class FinSetCalc extends RocketComponentCalc {
private final double cantAngle; private final double cantAngle;
private final FinSet.CrossSection crossSection; private final FinSet.CrossSection crossSection;
public FinSetCalc(RocketComponent component) { /**
* builds a calculator of aerodynamic forces a specified fin
* @param component The fin in consideration
*/
///why is this accepting RocketComponent when it rejects?
///why not put FinSet in the parameter instead?
public FinSetCalc(FinSet component) {
super(component); super(component);
if (!(component instanceof FinSet)) {
throw new IllegalArgumentException("Illegal component type " + component);
}
FinSet fin = (FinSet) component; thickness = component.getThickness();
thickness = fin.getThickness(); bodyRadius = component.getBodyRadius();
bodyRadius = fin.getBodyRadius(); finCount = component.getFinCount();
finCount = fin.getFinCount(); baseRotation = component.getBaseRotation();
baseRotation = fin.getBaseRotation(); cantAngle = component.getCantAngle();
cantAngle = fin.getCantAngle(); span = component.getSpan();
span = fin.getSpan(); finArea = component.getFinArea();
finArea = fin.getFinArea(); crossSection = component.getCrossSection();
crossSection = fin.getCrossSection();
calculateFinGeometry(fin); calculateFinGeometry(component);
calculatePoly(); calculatePoly();
calculateInterferenceFinCount(fin); calculateInterferenceFinCount(component);
} }
/* /*
@ -388,8 +392,7 @@ public class FinSetCalc extends RocketComponentCalc {
private static final PolyInterpolator cnaInterpolator = new PolyInterpolator( private static final PolyInterpolator cnaInterpolator = new PolyInterpolator(
new double[] { CNA_SUBSONIC, CNA_SUPERSONIC }, new double[] { CNA_SUBSONIC, CNA_SUPERSONIC },
new double[] { CNA_SUBSONIC, CNA_SUPERSONIC }, new double[] { CNA_SUBSONIC, CNA_SUPERSONIC },
new double[] { CNA_SUBSONIC } new double[] { CNA_SUBSONIC });
);
/* Pre-calculate the values for K1, K2 and K3 */ /* Pre-calculate the values for K1, K2 and K3 */
static { static {
// Up to Mach 5 // Up to Mach 5

View File

@ -16,26 +16,48 @@ public class Appearance {
private final double shine; private final double shine;
private final Decal texture; private final Decal texture;
/**
* Main constructor
*
* @param paint the color to be used
* @param shine shine of the appearance, will be clamped between 0 and 1
* @param texture The appearance texture
*/
public Appearance(final Color paint, final double shine, final Decal texture) { public Appearance(final Color paint, final double shine, final Decal texture) {
this.paint = paint; this.paint = paint;
this.shine = MathUtil.clamp(shine, 0, 1); this.shine = MathUtil.clamp(shine, 0, 1);
this.texture = texture; this.texture = texture;
} }
/**
* Main constructor
*
* @param paint the color to be used
* @param shine shine of the appearance, will be clamped between 0 and 1
*/
public Appearance(final Color paint, final double shine) { public Appearance(final Color paint, final double shine) {
this.paint = paint; this.paint = paint;
this.shine = MathUtil.clamp(shine, 0, 1); this.shine = MathUtil.clamp(shine, 0, 1);
this.texture = null; this.texture = null;
} }
/**
* @return colr of the appearance
*/
public Color getPaint() { public Color getPaint() {
return paint; return paint;
} }
/**
* @return Shine of appearance
*/
public double getShine() { public double getShine() {
return shine; return shine;
} }
/**
* @return Texture used in appearance
*/
public Decal getTexture() { public Decal getTexture() {
return texture; return texture;
} }

View File

@ -18,25 +18,38 @@ import net.sf.openrocket.util.Coordinate;
*/ */
public class AppearanceBuilder extends AbstractChangeSource { public class AppearanceBuilder extends AbstractChangeSource {
private Color paint; private Color paint; //current cached color
private double shine; private double shine; //current cached shine
private double offsetU, offsetV; private double offsetU, offsetV;//current offset to be used
private double centerU, centerV; private double centerU, centerV;//current values for the center of the appearance
private double scaleU, scaleV; private double scaleU, scaleV; //current values for scaling
private double rotation; private double rotation; //
private DecalImage image; private DecalImage image;
private Decal.EdgeMode edgeMode; private Decal.EdgeMode edgeMode;
private boolean batch; private boolean batch;
/**
* Default constructor
* Set the builder to make appearance of null values
*
*/
public AppearanceBuilder() { public AppearanceBuilder() {
resetToDefaults(); resetToDefaults();
} }
/**
* Constructor that initializes already with a
*
* @param a the appearance to be copied
*/
public AppearanceBuilder(Appearance a) { public AppearanceBuilder(Appearance a) {
setAppearance(a); setAppearance(a);
} }
/**
* Clears the builder cache and set to build blank appearances
*/
private void resetToDefaults() { private void resetToDefaults() {
paint = new Color(0, 0, 0); paint = new Color(0, 0, 0);
shine = 0; shine = 0;
@ -46,8 +59,15 @@ public class AppearanceBuilder extends AbstractChangeSource {
rotation = 0; rotation = 0;
image = null; image = null;
edgeMode = EdgeMode.REPEAT; edgeMode = EdgeMode.REPEAT;
fireChangeEvent();//shouldn't this fire change event?
} }
/**
* Sets the builder to create appearance equals to an existing appearance
* Fires change only once, hence the call to batch
*
* @param a the appearance to be used as the new template
*/
public void setAppearance(final Appearance a) { public void setAppearance(final Appearance a) {
batch(new Runnable() { batch(new Runnable() {
@Override @Override
@ -56,20 +76,33 @@ public class AppearanceBuilder extends AbstractChangeSource {
if (a != null) { if (a != null) {
setPaint(a.getPaint()); setPaint(a.getPaint());
setShine(a.getShine()); setShine(a.getShine());
Decal d = a.getTexture(); setDecal(a.getTexture());
if (d != null) {
setOffset(d.getOffset().x, d.getOffset().y);
setCenter(d.getCenter().x, d.getCenter().y);
setScaleUV(d.getScale().x, d.getScale().y);
setRotation(d.getRotation());
setEdgeMode(d.getEdgeMode());
setImage(d.getImage());
}
} }
} }
}); });
} }
/**
* makes a full copy of a decal, including information of offsets, center and scale
*
* @param d The decal
*/
public void setDecal(Decal d){
if (d != null) {
setOffset(d.getOffset().x, d.getOffset().y);
setCenter(d.getCenter().x, d.getCenter().y);
setScaleUV(d.getScale().x, d.getScale().y);
setRotation(d.getRotation());
setEdgeMode(d.getEdgeMode());
setImage(d.getImage());
}
fireChangeEvent();
}
/**
* Method creates another object of Appearance
* @return the created appearance
*/
public Appearance getAppearance() { public Appearance getAppearance() {
Decal t = null; Decal t = null;
@ -88,143 +121,316 @@ public class AppearanceBuilder extends AbstractChangeSource {
} }
/**
* get current paint in template
*
* return the color used in the current paint
*/
public Color getPaint() { public Color getPaint() {
return paint; return paint;
} }
/**
* sets a new paint color to be used
* fires change event
*
* @param paint the new color
*/
public void setPaint(Color paint) { public void setPaint(Color paint) {
this.paint = paint; this.paint = paint;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current shine
*
* @return current shine in template
*/
public double getShine() { public double getShine() {
return shine; return shine;
} }
/**
* Sets a new shine for template
* fires change event
*
* @param shine the new shine for template
*/
public void setShine(double shine) { public void setShine(double shine) {
this.shine = shine; this.shine = shine;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current offset axis U used
*
* @return offset in axis U
*/
public double getOffsetU() { public double getOffsetU() {
return offsetU; return offsetU;
} }
/**
* sets a new offset in axis U for template
* fires change event
*
* @param offsetU the new offset to be used
*/
public void setOffsetU(double offsetU) { public void setOffsetU(double offsetU) {
this.offsetU = offsetU; this.offsetU = offsetU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current offset axis V used
*
* @return offset in axis V
*/
public double getOffsetV() { public double getOffsetV() {
return offsetV; return offsetV;
} }
/**
* sets a new offset in axis V for template
* fires change event
*
* @param offsetV the new offset to be used
*/
public void setOffsetV(double offsetV) { public void setOffsetV(double offsetV) {
this.offsetV = offsetV; this.offsetV = offsetV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new offset to be used for template
* fires change event
*
* @param u offset in axis u
* @param v offset in axis v
*/
public void setOffset(double u, double v) { public void setOffset(double u, double v) {
setOffsetU(u); setOffsetU(u);
setOffsetV(v); setOffsetV(v);
} }
/**
* gets the current center in axis U used in template
*
* @return the current value of U of cente in template
*/
public double getCenterU() { public double getCenterU() {
return centerU; return centerU;
} }
/**
* set a new value for axis U for center in template
* fires change event
*
* @param centerU value of axis U for center
*/
public void setCenterU(double centerU) { public void setCenterU(double centerU) {
this.centerU = centerU; this.centerU = centerU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current center in axis V used in template
*
* @return the current value of V of cente in template
*/
public double getCenterV() { public double getCenterV() {
return centerV; return centerV;
} }
/**
* set a new value for axis V for center in template
* fires change event
*
* @param centerU value of axis V for center
*/
public void setCenterV(double centerV) { public void setCenterV(double centerV) {
this.centerV = centerV; this.centerV = centerV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new center for template
* fires chenge event
*
* @param u new value for axis u of the center
* @param v new value for axis v of the center
*/
public void setCenter(double u, double v) { public void setCenter(double u, double v) {
setCenterU(u); setCenterU(u);
setCenterV(v); setCenterV(v);
} }
/**
* gets the current scale value of axis u in template
*
* @return current value for axis u of scale
*/
public double getScaleU() { public double getScaleU() {
return scaleU; return scaleU;
} }
/**
* sets a new value of axis U for scaling in the template
* fires change event
*
* @param scaleU new value of scalling in axis U
*/
public void setScaleU(double scaleU) { public void setScaleU(double scaleU) {
this.scaleU = scaleU; this.scaleU = scaleU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current scale value of axis V in template
*
* @return current value for axis V of scale
*/
public double getScaleV() { public double getScaleV() {
return scaleV; return scaleV;
} }
/**
* sets a new value of axis V for scaling in the template
* fires change event
*
* @param scaleV new value of scalling in axis V
*/
public void setScaleV(double scaleV) { public void setScaleV(double scaleV) {
this.scaleV = scaleV; this.scaleV = scaleV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new value of both axis for scaling in the template
* fires change event
*
* @param u new value of scalling in axis U
* @param v new value of scalling in axis v
*/
public void setScaleUV(double u, double v) { public void setScaleUV(double u, double v) {
setScaleU(u); setScaleU(u);
setScaleV(v); setScaleV(v);
} }
/**
* gets the current value of X axis for scalling in the template
*
* @return value of scalling in axis x
*/
public double getScaleX() { public double getScaleX() {
return 1.0 / getScaleU(); return 1.0 / getScaleU();
} }
public void setScaleX(double scaleU) { /**
setScaleU(1.0 / scaleU); * sets a new value of axis X for scalling in template
* fires change event
*
* @param scaleX the new value for axis X
*/
public void setScaleX(double scaleX) {
setScaleU(1.0 / scaleX);
} }
/**
* gets the current value of Y axis for scalling in the template
*
* @return value of scalling in axis Y
*/
public double getScaleY() { public double getScaleY() {
return 1.0 / getScaleV(); return 1.0 / getScaleV();
} }
public void setScaleY(double scaleV) { /**
setScaleV(1.0 / scaleV); * sets a new value of axis Y for scalling in template
* fires change event
*
* @param scaleX the new value for axis Y
*/
public void setScaleY(double scaleY) {
setScaleV(1.0 / scaleY);
} }
/**
* gets the current value of rotation in template
*
* @return the current rotation in template
*/
public double getRotation() { public double getRotation() {
return rotation; return rotation;
} }
/**
* sets a new value of rotation in template
* fires chenge event
*
* @param rotation the new value for rotation in template
*/
public void setRotation(double rotation) { public void setRotation(double rotation) {
this.rotation = rotation; this.rotation = rotation;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current image in template
*
* @param the current image in template
*/
public DecalImage getImage() { public DecalImage getImage() {
return image; return image;
} }
/**
* sets a new image in template
* fires change event
*
* @param image the new image to be used as template
*/
public void setImage(DecalImage image) { public void setImage(DecalImage image) {
this.image = image; this.image = image;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current Edge mode in use
*
* @return the current edge mode in template
*/
public Decal.EdgeMode getEdgeMode() { public Decal.EdgeMode getEdgeMode() {
return edgeMode; return edgeMode;
} }
/**
* sets a new edge mode to be used in template
* fires change event
*
* @param edgeMode the new edgeMode to be used
*/
public void setEdgeMode(Decal.EdgeMode edgeMode) { public void setEdgeMode(Decal.EdgeMode edgeMode) {
this.edgeMode = edgeMode; this.edgeMode = edgeMode;
fireChangeEvent(); fireChangeEvent();
} }
/**
* only applies change if there is no more changes comming
*/
@Override @Override
protected void fireChangeEvent() { protected void fireChangeEvent() {
if (!batch) if (!batch)
super.fireChangeEvent(); super.fireChangeEvent();
} }
/**
* function that garantees that chenges event only occurs after all changes are made
*
* param r the functor to be executed
*/
public void batch(Runnable r) { public void batch(Runnable r) {
batch = true; batch = true;
r.run(); r.run();

View File

@ -31,6 +31,9 @@ public class AbstractChangeSource implements ChangeSource {
log.trace("Removing change listeners, listener count is now " + listeners.size()); log.trace("Removing change listeners, listener count is now " + listeners.size());
} }
/**
* execute a change event from any listeners that are triggered by it
*/
public void fireChangeEvent(Object source) { public void fireChangeEvent(Object source) {
EventObject event = new EventObject(source); EventObject event = new EventObject(source);
// Copy the list before iterating to prevent concurrent modification exceptions. // Copy the list before iterating to prevent concurrent modification exceptions.

View File

@ -1,206 +1,266 @@
package net.sf.openrocket.unit; package net.sf.openrocket.unit;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.text.DecimalFormat;
import org.junit.Test; import org.junit.Test;
public class FractionalUnitTest { public class FractionalUnitTest {
private final static Unit testUnit = new FractionalUnit(1, "unit", "unit", 4, 0.5); private final static Unit testUnit = new FractionalUnit(1, "unit", "unit", 4, 0.5);
private final static Unit testUnitApprox = new FractionalUnit(1, "unit", "unit", 16, 0.5, 0.02); private final static Unit testUnitApprox = new FractionalUnit(1, "unit", "unit", 16, 0.5, 0.02);
private final static Unit inchUnit = new FractionalUnit(0.0254, "in/64", "in", 64, 1d/16d); private final static Unit inchUnit = new FractionalUnit(0.0254, "in/64", "in", 64, 1d / 16d);
@Test @Test
public void testRound() { public void testRound() {
assertEquals(-1d, testUnit.round(-1.125), 0.0); // rounds to -1 since mod is even assertEquals(-1d, testUnit.round(-1.125), 0.0); // rounds to -1 since mod is even
assertEquals(-1d, testUnit.round(-1.0), 0.0); assertEquals(-1d, testUnit.round(-1.0), 0.0);
assertEquals(-1d, testUnit.round(-.875), 0.0); // rounds to -1 since mod is even assertEquals(-1d, testUnit.round(-.875), 0.0); // rounds to -1 since mod is even
assertEquals(-0.75d, testUnit.round(-.874), 0.0); assertEquals(-0.75d, testUnit.round(-.874), 0.0);
assertEquals(-0.75d, testUnit.round(-.75), 0.0); assertEquals(-0.75d, testUnit.round(-.75), 0.0);
assertEquals(-0.75d, testUnit.round(-.626), 0.0); assertEquals(-0.75d, testUnit.round(-.626), 0.0);
assertEquals(-0.5d, testUnit.round(-.625), 0.0); // rounds to -.5 since mod is even assertEquals(-0.5d, testUnit.round(-.625), 0.0); // rounds to -.5 since mod is even
assertEquals(-0.5d, testUnit.round(-.5), 0.0); assertEquals(-0.5d, testUnit.round(-.5), 0.0);
assertEquals(-0.5d, testUnit.round(-.375), 0.0); // rounds to -.5 since mod is even assertEquals(-0.5d, testUnit.round(-.375), 0.0); // rounds to -.5 since mod is even
assertEquals(-0.25d, testUnit.round(-.374), 0.0); assertEquals(-0.25d, testUnit.round(-.374), 0.0);
assertEquals(-0.25d, testUnit.round(-.25), 0.0); assertEquals(-0.25d, testUnit.round(-.25), 0.0);
assertEquals(-0.25d, testUnit.round(-.126), 0.0); assertEquals(-0.25d, testUnit.round(-.126), 0.0);
assertEquals(0d, testUnit.round(-.125), 0.0); assertEquals(0d, testUnit.round(-.125), 0.0);
assertEquals(0d, testUnit.round(0), 0.0); assertEquals(0d, testUnit.round(0), 0.0);
assertEquals(0d, testUnit.round(.125), 0.0); assertEquals(0d, testUnit.round(.125), 0.0);
assertEquals(0.25d, testUnit.round(.126), 0.0); assertEquals(0.25d, testUnit.round(.126), 0.0);
assertEquals(0.25d, testUnit.round(.25), 0.0); assertEquals(0.25d, testUnit.round(.25), 0.0);
assertEquals(0.25d, testUnit.round(.374), 0.0); assertEquals(0.25d, testUnit.round(.374), 0.0);
assertEquals(0.5d, testUnit.round(.375), 0.0); // rounds to .5 since mod is even assertEquals(0.5d, testUnit.round(.375), 0.0); // rounds to .5 since mod is even
assertEquals(0.5d, testUnit.round(.5), 0.0); assertEquals(0.5d, testUnit.round(.5), 0.0);
assertEquals(0.5d, testUnit.round(.625), 0.0); // rounds to .5 since mod is even assertEquals(0.5d, testUnit.round(.625), 0.0); // rounds to .5 since mod is even
assertEquals(0.75d, testUnit.round(.626), 0.0); assertEquals(0.75d, testUnit.round(.626), 0.0);
assertEquals(0.75d, testUnit.round(.75), 0.0); assertEquals(0.75d, testUnit.round(.75), 0.0);
assertEquals(0.75d, testUnit.round(.874), 0.0); assertEquals(0.75d, testUnit.round(.874), 0.0);
assertEquals(1d, testUnit.round(.875), 0.0); // rounds to 1 since mod is even assertEquals(1d, testUnit.round(.875), 0.0); // rounds to 1 since mod is even
assertEquals(1d, testUnit.round(1.0), 0.0); assertEquals(1d, testUnit.round(1.0), 0.0);
assertEquals(1d, testUnit.round(1.125), 0.0); // rounds to 1 since mod is even assertEquals(1d, testUnit.round(1.125), 0.0); // rounds to 1 since mod is even
} }
@Test @Test
public void testIncrement() { public void testIncrement() {
assertEquals( -1d, testUnit.getNextValue(-1.2), 0.0); assertEquals(-1d, testUnit.getNextValue(-1.2), 0.0);
assertEquals( -1d, testUnit.getNextValue(-1.4), 0.0); assertEquals(-1d, testUnit.getNextValue(-1.4), 0.0);
assertEquals( -0.5d, testUnit.getNextValue(-0.7), 0.0); assertEquals(-0.5d, testUnit.getNextValue(-0.7), 0.0);
assertEquals( -0.5d, testUnit.getNextValue(-0.9), 0.0); assertEquals(-0.5d, testUnit.getNextValue(-0.9), 0.0);
assertEquals( -0.5d, testUnit.getNextValue(-1.0), 0.0); assertEquals(-0.5d, testUnit.getNextValue(-1.0), 0.0);
assertEquals( 0.0d, testUnit.getNextValue(-0.05), 0.0 ); assertEquals(0.0d, testUnit.getNextValue(-0.05), 0.0);
assertEquals( 0.0d, testUnit.getNextValue(-0.062), 0.0 ); assertEquals(0.0d, testUnit.getNextValue(-0.062), 0.0);
assertEquals( 0.0d, testUnit.getNextValue(-0.07), 0.0 ); assertEquals(0.0d, testUnit.getNextValue(-0.07), 0.0);
assertEquals( 0.0d, testUnit.getNextValue(-0.11), 0.0 ); assertEquals(0.0d, testUnit.getNextValue(-0.11), 0.0);
assertEquals( 0.5d, testUnit.getNextValue(0), 0.0 ); assertEquals(0.5d, testUnit.getNextValue(0), 0.0);
assertEquals( 0.5d, testUnit.getNextValue(0.01), 0.0 ); assertEquals(0.5d, testUnit.getNextValue(0.01), 0.0);
assertEquals( 0.5d, testUnit.getNextValue(0.062), 0.0 ); assertEquals(0.5d, testUnit.getNextValue(0.062), 0.0);
assertEquals( 0.5d, testUnit.getNextValue(0.0625), 0.0); assertEquals(0.5d, testUnit.getNextValue(0.0625), 0.0);
assertEquals( 1d, testUnit.getNextValue(0.51), 0.0); assertEquals(1d, testUnit.getNextValue(0.51), 0.0);
assertEquals( 1d, testUnit.getNextValue(0.7), 0.0); assertEquals(1d, testUnit.getNextValue(0.7), 0.0);
} }
@Test @Test
public void testDecrement() { public void testDecrement() {
assertEquals( -1.5d, testUnit.getPreviousValue(-1.2), 0.0); assertEquals(-1.5d, testUnit.getPreviousValue(-1.2), 0.0);
assertEquals( -1.5d, testUnit.getPreviousValue(-1.4), 0.0); assertEquals(-1.5d, testUnit.getPreviousValue(-1.4), 0.0);
assertEquals( -1.5d, testUnit.getPreviousValue(-1.0), 0.0); assertEquals(-1.5d, testUnit.getPreviousValue(-1.0), 0.0);
assertEquals( -1d, testUnit.getPreviousValue(-0.7), 0.0); assertEquals(-1d, testUnit.getPreviousValue(-0.7), 0.0);
assertEquals( -1d, testUnit.getPreviousValue(-0.9), 0.0); assertEquals(-1d, testUnit.getPreviousValue(-0.9), 0.0);
assertEquals( -0.5d, testUnit.getPreviousValue(-0.01), 0.0 ); assertEquals(-0.5d, testUnit.getPreviousValue(-0.01), 0.0);
assertEquals( -0.5d, testUnit.getPreviousValue(-0.05), 0.0 ); assertEquals(-0.5d, testUnit.getPreviousValue(-0.05), 0.0);
assertEquals( -0.5d, testUnit.getPreviousValue(-0.062), 0.0 ); assertEquals(-0.5d, testUnit.getPreviousValue(-0.062), 0.0);
assertEquals( -0.5d, testUnit.getPreviousValue(-0.07), 0.0 ); assertEquals(-0.5d, testUnit.getPreviousValue(-0.07), 0.0);
assertEquals( -0.5d, testUnit.getPreviousValue(0), 0.0 ); assertEquals(-0.5d, testUnit.getPreviousValue(0), 0.0);
assertEquals( 0.0d, testUnit.getPreviousValue(0.49), 0.0 ); assertEquals(0.0d, testUnit.getPreviousValue(0.49), 0.0);
assertEquals( 0.0d, testUnit.getPreviousValue(0.262), 0.0 ); assertEquals(0.0d, testUnit.getPreviousValue(0.262), 0.0);
assertEquals( 0.0d, testUnit.getPreviousValue(0.51), 0.0); assertEquals(0.0d, testUnit.getPreviousValue(0.51), 0.0);
assertEquals( 0.5d, testUnit.getPreviousValue(0.7), 0.0); assertEquals(0.5d, testUnit.getPreviousValue(0.7), 0.0);
assertEquals( 1.0d, testUnit.getPreviousValue(1.2), 0.0); assertEquals(1.0d, testUnit.getPreviousValue(1.2), 0.0);
} }
@Test @Test
public void testToStringDefaultPrecision() { public void testToStringDefaultPrecision() {
if (isPointDecimalSeparator()) {
assertEquals("-1.2", testUnit.toString(-1.2));
assertEquals("-1.3", testUnit.toString(-1.3));
assertEquals("-0.2", testUnit.toString(-.2));
assertEquals("-0.3", testUnit.toString(-.3));
assertEquals("-0.1", testUnit.toString(-.1));
assertEquals("0.1", testUnit.toString(.1));
assertEquals("0.2", testUnit.toString(.2));
assertEquals("0.3", testUnit.toString(.3));
assertEquals("1.2", testUnit.toString(1.2));
assertEquals("1.3", testUnit.toString(1.3));
} else {
assertEquals("-1,2", testUnit.toString(-1.2));
assertEquals("-1,3", testUnit.toString(-1.3));
assertEquals("-0,2", testUnit.toString(-.2));
assertEquals("-0,3", testUnit.toString(-.3));
assertEquals("-0,1", testUnit.toString(-.1));
assertEquals("0,1", testUnit.toString(.1));
assertEquals("0,2", testUnit.toString(.2));
assertEquals("0,3", testUnit.toString(.3));
assertEquals("1,2", testUnit.toString(1.2));
assertEquals("1,3", testUnit.toString(1.3));
}
// default epsilon is 0.025 // default epsilon is 0.025
assertEquals("-1.2", testUnit.toString(-1.2));
assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.225)); assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.225));
assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.227)); assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.227));
assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.25)); assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.25));
assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.25)); assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.25));
assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.275)); assertEquals("-1 \u00B9\u2044\u2084", testUnit.toString(-1.275));
assertEquals("-1.3", testUnit.toString(-1.3));
assertEquals("-0.2", testUnit.toString(-.2));
assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.225)); assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.225));
assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.25)); assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.25));
assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.274)); assertEquals("-\u00B9\u2044\u2084", testUnit.toString(-.274));
//assertEquals("-1/4", testUnit.toString(-.275)); // this has roundoff error which pushes it over epsilon //assertEquals("-1/4", testUnit.toString(-.275)); // this has roundoff error which pushes it over epsilon
assertEquals("-0.3", testUnit.toString(-.3));
assertEquals("-0.1", testUnit.toString(-.1));
assertEquals("0", testUnit.toString(-0.024)); assertEquals("0", testUnit.toString(-0.024));
assertEquals("0", testUnit.toString(0)); assertEquals("0", testUnit.toString(0));
assertEquals("0", testUnit.toString(.024)); assertEquals("0", testUnit.toString(.024));
assertEquals("0.1", testUnit.toString(.1));
assertEquals("0.2", testUnit.toString(.2));
assertEquals("\u00B9\u2044\u2084", testUnit.toString(.225)); assertEquals("\u00B9\u2044\u2084", testUnit.toString(.225));
assertEquals("\u00B9\u2044\u2084", testUnit.toString(.25)); assertEquals("\u00B9\u2044\u2084", testUnit.toString(.25));
assertEquals("\u00B9\u2044\u2084", testUnit.toString(.274)); assertEquals("\u00B9\u2044\u2084", testUnit.toString(.274));
assertEquals("0.3", testUnit.toString(.3));
assertEquals("1.2", testUnit.toString(1.2));
assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.225)); assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.225));
assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.25)); assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.25));
assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.275)); assertEquals("1 \u00B9\u2044\u2084", testUnit.toString(1.275));
assertEquals("1.3", testUnit.toString(1.3));
} }
@Test @Test
public void testToStringWithPrecision() { public void testToStringWithPrecision() {
if (isPointDecimalSeparator()) {
assertEquals("-1.225", testUnitApprox.toString(-1.225));
assertEquals("-1.275", testUnitApprox.toString(-1.275));
assertEquals("-0.225", testUnitApprox.toString(-.225));
assertEquals("-0.275", testUnitApprox.toString(-.275));
assertEquals("-0.1", testUnitApprox.toString(-.1));
assertEquals("-0.024", testUnitApprox.toString(-0.024));
assertEquals("0.024", testUnitApprox.toString(.024));
assertEquals("0.1", testUnitApprox.toString(.1));
assertEquals("0.275", testUnitApprox.toString(.275));
assertEquals("0.225", testUnitApprox.toString(.225));
assertEquals("1.225", testUnitApprox.toString(1.225));
assertEquals("1.275", testUnitApprox.toString(1.275));
} else {
assertEquals("-1,225", testUnitApprox.toString(-1.225));
assertEquals("-1,275", testUnitApprox.toString(-1.275));
assertEquals("-0,225", testUnitApprox.toString(-.225));
assertEquals("-0,275", testUnitApprox.toString(-.275));
assertEquals("-0,1", testUnitApprox.toString(-.1));
assertEquals("-0,024", testUnitApprox.toString(-0.024));
assertEquals("0,024", testUnitApprox.toString(.024));
assertEquals("0,1", testUnitApprox.toString(.1));
assertEquals("0,275", testUnitApprox.toString(.275));
assertEquals("0,225", testUnitApprox.toString(.225));
assertEquals("1,225", testUnitApprox.toString(1.225));
assertEquals("1,275", testUnitApprox.toString(1.275));
}
// epsilon is .02 // epsilon is .02
assertEquals("-1 \u00B3\u2044\u2081\u2086", testUnitApprox.toString(-1.2)); assertEquals("-1 \u00B3\u2044\u2081\u2086", testUnitApprox.toString(-1.2));
assertEquals("-1.225", testUnitApprox.toString(-1.225));
assertEquals("-1 \u00B9\u2044\u2084", testUnitApprox.toString(-1.25)); assertEquals("-1 \u00B9\u2044\u2084", testUnitApprox.toString(-1.25));
assertEquals("-1.275", testUnitApprox.toString(-1.275));
assertEquals("-1 \u2075\u2044\u2081\u2086", testUnitApprox.toString(-1.3)); assertEquals("-1 \u2075\u2044\u2081\u2086", testUnitApprox.toString(-1.3));
assertEquals("-\u00B3\u2044\u2081\u2086", testUnitApprox.toString(-.2)); assertEquals("-\u00B3\u2044\u2081\u2086", testUnitApprox.toString(-.2));
assertEquals("-0.225", testUnitApprox.toString(-.225));
assertEquals("-\u00B9\u2044\u2084", testUnitApprox.toString(-.25)); assertEquals("-\u00B9\u2044\u2084", testUnitApprox.toString(-.25));
assertEquals("-0.275", testUnitApprox.toString(-.275));
assertEquals("-\u2075\u2044\u2081\u2086", testUnitApprox.toString(-.3)); assertEquals("-\u2075\u2044\u2081\u2086", testUnitApprox.toString(-.3));
assertEquals("-0.1", testUnitApprox.toString(-.1));
assertEquals("-0.024", testUnitApprox.toString(-0.024));
assertEquals("0", testUnitApprox.toString(0)); assertEquals("0", testUnitApprox.toString(0));
assertEquals("0.024", testUnitApprox.toString(.024));
assertEquals("0.1", testUnitApprox.toString(.1));
assertEquals("\u00B3\u2044\u2081\u2086", testUnitApprox.toString(.2)); assertEquals("\u00B3\u2044\u2081\u2086", testUnitApprox.toString(.2));
assertEquals("0.225", testUnitApprox.toString(.225));
assertEquals("\u00B9\u2044\u2084", testUnitApprox.toString(.25)); assertEquals("\u00B9\u2044\u2084", testUnitApprox.toString(.25));
assertEquals("0.275", testUnitApprox.toString(.275));
assertEquals("\u2075\u2044\u2081\u2086", testUnitApprox.toString(.3)); assertEquals("\u2075\u2044\u2081\u2086", testUnitApprox.toString(.3));
assertEquals("1 \u00B3\u2044\u2081\u2086", testUnitApprox.toString(1.2)); assertEquals("1 \u00B3\u2044\u2081\u2086", testUnitApprox.toString(1.2));
assertEquals("1.225", testUnitApprox.toString(1.225));
assertEquals("1 \u00B9\u2044\u2084", testUnitApprox.toString(1.25)); assertEquals("1 \u00B9\u2044\u2084", testUnitApprox.toString(1.25));
assertEquals("1.275", testUnitApprox.toString(1.275));
assertEquals("1 \u2075\u2044\u2081\u2086", testUnitApprox.toString(1.3)); assertEquals("1 \u2075\u2044\u2081\u2086", testUnitApprox.toString(1.3));
}
private boolean isPointDecimalSeparator() {
return ((DecimalFormat) DecimalFormat.getInstance()).getDecimalFormatSymbols().getDecimalSeparator() == '.';
} }
@Test @Test
public void testInchToString() { public void testInchToString() {
// Just some random test points. // Just some random test points.
assertEquals( "\u00B9\u2044\u2086\u2084", inchUnit.toString( 1d/64d*0.0254)); assertEquals("\u00B9\u2044\u2086\u2084", inchUnit.toString(1d / 64d * 0.0254));
assertEquals( "-\u2075\u2044\u2086\u2084", inchUnit.toString( -5d/64d*0.0254)); assertEquals("-\u2075\u2044\u2086\u2084", inchUnit.toString(-5d / 64d * 0.0254));
assertEquals( "4 \u00B9\u2044\u2082", inchUnit.toString( 9d/2d*0.0254)); assertEquals("4 \u00B9\u2044\u2082", inchUnit.toString(9d / 2d * 0.0254));
assertEquals( "0.002", inchUnit.toString( 0.002*0.0254)); if (isPointDecimalSeparator()) {
assertEquals("0.002", inchUnit.toString(0.002 * 0.0254));
} else {
assertEquals("0,002", inchUnit.toString(0.002 * 0.0254));
}
// default body tube length: // default body tube length:
double length = 8d * 0.025; double length = 8d * 0.025;
assertEquals( "7 \u2077\u2044\u2088", inchUnit.toString( length) ); assertEquals("7 \u2077\u2044\u2088", inchUnit.toString(length));
// had problems with roundoff in decrement. // had problems with roundoff in decrement.
double v = inchUnit.toUnit(length); double v = inchUnit.toUnit(length);
for ( int i = 0; i< 15; i++ ) { for (int i = 0; i < 15; i++) {
assertTrue( v > inchUnit.getPreviousValue(v) ); assertTrue(v > inchUnit.getPreviousValue(v));
v = inchUnit.getPreviousValue(v); v = inchUnit.getPreviousValue(v);
} }
} }
} }

View File

@ -2,16 +2,52 @@ package net.sf.openrocket.unit;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.text.DecimalFormat;
import org.junit.Test; import org.junit.Test;
public class UnitToStringTest { public class UnitToStringTest {
private boolean isPointDecimalSeparator() {
return ((DecimalFormat) DecimalFormat.getInstance()).getDecimalFormatSymbols().getDecimalSeparator() == '.';
}
@Test @Test
public void testPositiveToString() { public void testPositiveToString() {
if (isPointDecimalSeparator()) {
testPositiveWithPoint();
} else {
testPositiveWithComma();
}
// very small positive numbers ( < 0.0005) are returned as "0" // very small positive numbers ( < 0.0005) are returned as "0"
assertEquals("0", Unit.NOUNIT.toString(0.00040)); assertEquals("0", Unit.NOUNIT.toString(0.00040));
assertEquals("0", Unit.NOUNIT.toString(0.00050)); // check boundary of change in format assertEquals("0", Unit.NOUNIT.toString(0.00050)); // check boundary of change in format
// positive numbers <= 1E6
assertEquals("123", Unit.NOUNIT.toString(123.20));
assertEquals("124", Unit.NOUNIT.toString(123.50)); // round to even
assertEquals("124", Unit.NOUNIT.toString(123.55));
assertEquals("124", Unit.NOUNIT.toString(124.20));
assertEquals("124", Unit.NOUNIT.toString(124.50)); // round to even
assertEquals("125", Unit.NOUNIT.toString(124.55));
assertEquals("1234", Unit.NOUNIT.toString(1234.2));
assertEquals("1234", Unit.NOUNIT.toString(1234.5)); // round to even
assertEquals("1235", Unit.NOUNIT.toString(1234.6));
assertEquals("1235", Unit.NOUNIT.toString(1235.2));
assertEquals("1236", Unit.NOUNIT.toString(1235.5)); // round to even
assertEquals("1236", Unit.NOUNIT.toString(1235.6));
assertEquals("123457", Unit.NOUNIT.toString(123456.789));
assertEquals("1000000", Unit.NOUNIT.toString(1000000)); // boundary check
}
private void testPositiveWithPoint() {
// positive number < 0.095 use 3 digit decimal format // positive number < 0.095 use 3 digit decimal format
assertEquals("0.001", Unit.NOUNIT.toString(0.00051)); // check boundary of change in format assertEquals("0.001", Unit.NOUNIT.toString(0.00051)); // check boundary of change in format
assertEquals("0.001", Unit.NOUNIT.toString(0.00060)); assertEquals("0.001", Unit.NOUNIT.toString(0.00060));
@ -36,7 +72,7 @@ public class UnitToStringTest {
assertEquals("0.095", Unit.NOUNIT.toString(0.0949)); // boundary check assertEquals("0.095", Unit.NOUNIT.toString(0.0949)); // boundary check
// positive numbers < 100 // positive numbers < 100
assertEquals("0.01", Unit.NOUNIT.toString(0.0095)); // boundary check assertEquals("0.01", Unit.NOUNIT.toString(0.0095)); // boundary check
assertEquals("0.111", Unit.NOUNIT.toString(0.1111)); assertEquals("0.111", Unit.NOUNIT.toString(0.1111));
@ -59,26 +95,6 @@ public class UnitToStringTest {
assertEquals("12.4", Unit.NOUNIT.toString(12.420)); assertEquals("12.4", Unit.NOUNIT.toString(12.420));
assertEquals("12.4", Unit.NOUNIT.toString(12.450)); // round to even assertEquals("12.4", Unit.NOUNIT.toString(12.450)); // round to even
assertEquals("12.5", Unit.NOUNIT.toString(12.455)); assertEquals("12.5", Unit.NOUNIT.toString(12.455));
// positive numbers <= 1E6
assertEquals("123", Unit.NOUNIT.toString(123.20));
assertEquals("124", Unit.NOUNIT.toString(123.50)); // round to even
assertEquals("124", Unit.NOUNIT.toString(123.55));
assertEquals("124", Unit.NOUNIT.toString(124.20));
assertEquals("124", Unit.NOUNIT.toString(124.50)); // round to even
assertEquals("125", Unit.NOUNIT.toString(124.55));
assertEquals("1234", Unit.NOUNIT.toString(1234.2));
assertEquals("1234", Unit.NOUNIT.toString(1234.5)); // round to even
assertEquals("1235", Unit.NOUNIT.toString(1234.6));
assertEquals("1235", Unit.NOUNIT.toString(1235.2));
assertEquals("1236", Unit.NOUNIT.toString(1235.5)); // round to even
assertEquals("1236", Unit.NOUNIT.toString(1235.6));
assertEquals("123457", Unit.NOUNIT.toString(123456.789));
assertEquals("1000000", Unit.NOUNIT.toString(1000000)); // boundary check
// positive numbers > 1E6 // positive numbers > 1E6
assertEquals("1.23E6", Unit.NOUNIT.toString(1234567.89)); assertEquals("1.23E6", Unit.NOUNIT.toString(1234567.89));
assertEquals("1.23E7", Unit.NOUNIT.toString(12345678.9)); assertEquals("1.23E7", Unit.NOUNIT.toString(12345678.9));
@ -86,15 +102,152 @@ public class UnitToStringTest {
// Inch precision // Inch precision
assertEquals("25.125", UnitGroup.UNITS_LENGTH.findApproximate("in").toString(25.125 * 25.4 / 1000)); assertEquals("25.125", UnitGroup.UNITS_LENGTH.findApproximate("in").toString(25.125 * 25.4 / 1000));
}
private void testPositiveWithComma() {
// positive number < 0.095 use 3 digit decimal format
assertEquals("0,001", Unit.NOUNIT.toString(0.00051)); // check boundary of change in format
assertEquals("0,001", Unit.NOUNIT.toString(0.00060));
// rounding at third digit.
assertEquals("0,001", Unit.NOUNIT.toString(0.0014));
assertEquals("0,002", Unit.NOUNIT.toString(0.0015)); // round to even
assertEquals("0,002", Unit.NOUNIT.toString(0.0016));
assertEquals("0,002", Unit.NOUNIT.toString(0.0024));
assertEquals("0,002", Unit.NOUNIT.toString(0.0025)); // round to even
assertEquals("0,003", Unit.NOUNIT.toString(0.0026));
assertEquals("0,009", Unit.NOUNIT.toString(0.0094));
assertEquals("0,01", Unit.NOUNIT.toString(0.0095)); // no trailing zeros after rounding
assertEquals("0,011", Unit.NOUNIT.toString(0.0114));
assertEquals("0,012", Unit.NOUNIT.toString(0.0115)); // round to even
assertEquals("0,012", Unit.NOUNIT.toString(0.0119));
assertEquals("0,012", Unit.NOUNIT.toString(0.0124));
assertEquals("0,012", Unit.NOUNIT.toString(0.0125)); // round to even
assertEquals("0,013", Unit.NOUNIT.toString(0.0129));
assertEquals("0,095", Unit.NOUNIT.toString(0.0949)); // boundary check
// positive numbers < 100
assertEquals("0,01", Unit.NOUNIT.toString(0.0095)); // boundary check
assertEquals("0,111", Unit.NOUNIT.toString(0.1111));
assertEquals("0,112", Unit.NOUNIT.toString(0.1115)); // round to even
assertEquals("0,112", Unit.NOUNIT.toString(0.1117));
assertEquals("0,112", Unit.NOUNIT.toString(0.1121));
assertEquals("0,112", Unit.NOUNIT.toString(0.1125)); // round to even
assertEquals("0,113", Unit.NOUNIT.toString(0.1127));
assertEquals("1,11", Unit.NOUNIT.toString(1.113));
assertEquals("1,12", Unit.NOUNIT.toString(1.115)); // round to even
assertEquals("1,12", Unit.NOUNIT.toString(1.117));
assertEquals("1,12", Unit.NOUNIT.toString(1.123));
assertEquals("1,12", Unit.NOUNIT.toString(1.125)); // round to even
assertEquals("1,13", Unit.NOUNIT.toString(1.127));
assertEquals("12,3", Unit.NOUNIT.toString(12.320));
assertEquals("12,4", Unit.NOUNIT.toString(12.350)); // round to even
assertEquals("12,4", Unit.NOUNIT.toString(12.355));
assertEquals("12,4", Unit.NOUNIT.toString(12.420));
assertEquals("12,4", Unit.NOUNIT.toString(12.450)); // round to even
assertEquals("12,5", Unit.NOUNIT.toString(12.455));
// positive numbers > 1E6
assertEquals("1,23E6", Unit.NOUNIT.toString(1234567.89));
assertEquals("1,23E7", Unit.NOUNIT.toString(12345678.9));
// Inch precision
assertEquals("25,125", UnitGroup.UNITS_LENGTH.findApproximate("in").toString(25.125 * 25.4 / 1000));
} }
@Test @Test
public void testNegativeToString() { public void testNegativeToString() {
if (isPointDecimalSeparator()) {
testNegativeWithPoint();
} else {
testNegativeWithComma();
}
// very small negative numbers ( < 0.0005) are returned as "0" // very small negative numbers ( < 0.0005) are returned as "0"
assertEquals("0", Unit.NOUNIT.toString(-0.00040)); assertEquals("0", Unit.NOUNIT.toString(-0.00040));
assertEquals("0", Unit.NOUNIT.toString(-0.00050)); // check boundary of change in format assertEquals("0", Unit.NOUNIT.toString(-0.00050)); // check boundary of change in format
// negative numbers <= 1E6
assertEquals("-123", Unit.NOUNIT.toString(-123.20));
assertEquals("-124", Unit.NOUNIT.toString(-123.50)); // round to even
assertEquals("-124", Unit.NOUNIT.toString(-123.55));
assertEquals("-124", Unit.NOUNIT.toString(-124.20));
assertEquals("-124", Unit.NOUNIT.toString(-124.50)); // round to even
assertEquals("-125", Unit.NOUNIT.toString(-124.55));
assertEquals("-1234", Unit.NOUNIT.toString(-1234.2));
assertEquals("-1234", Unit.NOUNIT.toString(-1234.5)); // round to even
assertEquals("-1235", Unit.NOUNIT.toString(-1234.6));
assertEquals("-1235", Unit.NOUNIT.toString(-1235.2));
assertEquals("-1236", Unit.NOUNIT.toString(-1235.5)); // round to even
assertEquals("-1236", Unit.NOUNIT.toString(-1235.6));
assertEquals("-123457", Unit.NOUNIT.toString(-123456.789));
assertEquals("-1000000", Unit.NOUNIT.toString(-1000000)); // boundary check
}
private void testNegativeWithComma() {
// negative number < 0.095 use 3 digit decimal format
assertEquals("-0,001", Unit.NOUNIT.toString(-0.00051)); // check boundary of change in format
assertEquals("-0,001", Unit.NOUNIT.toString(-0.00060));
// rounding at third digit.
assertEquals("-0,001", Unit.NOUNIT.toString(-0.0014));
assertEquals("-0,002", Unit.NOUNIT.toString(-0.0015)); // round to even
assertEquals("-0,002", Unit.NOUNIT.toString(-0.0016));
assertEquals("-0,002", Unit.NOUNIT.toString(-0.0024));
assertEquals("-0,002", Unit.NOUNIT.toString(-0.0025)); // round to even
assertEquals("-0,003", Unit.NOUNIT.toString(-0.0026));
assertEquals("-0,009", Unit.NOUNIT.toString(-0.0094));
assertEquals("-0,01", Unit.NOUNIT.toString(-0.0095)); // no trailing zeros after rounding
assertEquals("-0,011", Unit.NOUNIT.toString(-0.0114));
assertEquals("-0,012", Unit.NOUNIT.toString(-0.0115)); // round to even
assertEquals("-0,012", Unit.NOUNIT.toString(-0.0119));
assertEquals("-0,012", Unit.NOUNIT.toString(-0.0124));
assertEquals("-0,012", Unit.NOUNIT.toString(-0.0125)); // round to even
assertEquals("-0,013", Unit.NOUNIT.toString(-0.0129));
assertEquals("-0,095", Unit.NOUNIT.toString(-0.0949)); // boundary check
// negative numbers < 100
assertEquals("-0,01", Unit.NOUNIT.toString(-0.0095)); // boundary check
assertEquals("-0,111", Unit.NOUNIT.toString(-0.1111));
assertEquals("-0,112", Unit.NOUNIT.toString(-0.1115)); // round to even
assertEquals("-0,112", Unit.NOUNIT.toString(-0.1117));
assertEquals("-0,112", Unit.NOUNIT.toString(-0.1121));
assertEquals("-0,112", Unit.NOUNIT.toString(-0.1125)); // round to even
assertEquals("-0,113", Unit.NOUNIT.toString(-0.1127));
assertEquals("-1,11", Unit.NOUNIT.toString(-1.113));
assertEquals("-1,12", Unit.NOUNIT.toString(-1.115)); // round to even
assertEquals("-1,12", Unit.NOUNIT.toString(-1.117));
assertEquals("-1,12", Unit.NOUNIT.toString(-1.123));
assertEquals("-1,12", Unit.NOUNIT.toString(-1.125)); // round to even
assertEquals("-1,13", Unit.NOUNIT.toString(-1.127));
assertEquals("-12,3", Unit.NOUNIT.toString(-12.320));
assertEquals("-12,4", Unit.NOUNIT.toString(-12.350)); // round to even
assertEquals("-12,4", Unit.NOUNIT.toString(-12.355));
assertEquals("-12,4", Unit.NOUNIT.toString(-12.420));
assertEquals("-12,4", Unit.NOUNIT.toString(-12.450)); // round to even
assertEquals("-12,5", Unit.NOUNIT.toString(-12.455));
// negative numbers > 1E6
assertEquals("-1,23E6", Unit.NOUNIT.toString(-1234567.89));
assertEquals("-1,23E7", Unit.NOUNIT.toString(-12345678.9));
}
private void testNegativeWithPoint() {
// negative number < 0.095 use 3 digit decimal format // negative number < 0.095 use 3 digit decimal format
assertEquals("-0.001", Unit.NOUNIT.toString(-0.00051)); // check boundary of change in format assertEquals("-0.001", Unit.NOUNIT.toString(-0.00051)); // check boundary of change in format
assertEquals("-0.001", Unit.NOUNIT.toString(-0.00060)); assertEquals("-0.001", Unit.NOUNIT.toString(-0.00060));
@ -142,31 +295,9 @@ public class UnitToStringTest {
assertEquals("-12.4", Unit.NOUNIT.toString(-12.420)); assertEquals("-12.4", Unit.NOUNIT.toString(-12.420));
assertEquals("-12.4", Unit.NOUNIT.toString(-12.450)); // round to even assertEquals("-12.4", Unit.NOUNIT.toString(-12.450)); // round to even
assertEquals("-12.5", Unit.NOUNIT.toString(-12.455)); assertEquals("-12.5", Unit.NOUNIT.toString(-12.455));
// negative numbers <= 1E6
assertEquals("-123", Unit.NOUNIT.toString(-123.20));
assertEquals("-124", Unit.NOUNIT.toString(-123.50)); // round to even
assertEquals("-124", Unit.NOUNIT.toString(-123.55));
assertEquals("-124", Unit.NOUNIT.toString(-124.20));
assertEquals("-124", Unit.NOUNIT.toString(-124.50)); // round to even
assertEquals("-125", Unit.NOUNIT.toString(-124.55));
assertEquals("-1234", Unit.NOUNIT.toString(-1234.2));
assertEquals("-1234", Unit.NOUNIT.toString(-1234.5)); // round to even
assertEquals("-1235", Unit.NOUNIT.toString(-1234.6));
assertEquals("-1235", Unit.NOUNIT.toString(-1235.2));
assertEquals("-1236", Unit.NOUNIT.toString(-1235.5)); // round to even
assertEquals("-1236", Unit.NOUNIT.toString(-1235.6));
assertEquals("-123457", Unit.NOUNIT.toString(-123456.789));
assertEquals("-1000000", Unit.NOUNIT.toString(-1000000)); // boundary check
// negative numbers > 1E6 // negative numbers > 1E6
assertEquals("-1.23E6", Unit.NOUNIT.toString(-1234567.89)); assertEquals("-1.23E6", Unit.NOUNIT.toString(-1234567.89));
assertEquals("-1.23E7", Unit.NOUNIT.toString(-12345678.9)); assertEquals("-1.23E7", Unit.NOUNIT.toString(-12345678.9));
} }

2487
doxygen/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

BIN
doxygen/openRocketLogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -81,6 +81,10 @@ public class RealisticRenderer extends RocketRenderer {
@Override @Override
public boolean isDrawnTransparent(RocketComponent c) { public boolean isDrawnTransparent(RocketComponent c) {
// if there is any degree of transparency, then...
if (getAppearance(c).getPaint().getAlpha()<255){
return true;
}
return false; return false;
} }
@ -91,7 +95,12 @@ public class RealisticRenderer extends RocketRenderer {
@Override @Override
public void renderComponent(final GL2 gl, final RocketComponent c, final float alpha) { public void renderComponent(final GL2 gl, final RocketComponent c, final float alpha) {
render(gl, cr.getGeometry(c, Surface.INSIDE), DefaultAppearance.getDefaultAppearance(c), true, 1.0f); if (isDrawnTransparent(c)){
// if transparent, draw inside the same as the outside so we dont get a cardboard interior on a clear payload bay
render(gl, cr.getGeometry(c, Surface.INSIDE), getAppearance(c), true, alpha);
}else{
render(gl, cr.getGeometry(c, Surface.INSIDE), DefaultAppearance.getDefaultAppearance(c), true, 1.0f);
}
render(gl, cr.getGeometry(c, Surface.OUTSIDE), getAppearance(c), true, alpha); render(gl, cr.getGeometry(c, Surface.OUTSIDE), getAppearance(c), true, alpha);
render(gl, cr.getGeometry(c, Surface.EDGES), getAppearance(c), false, alpha); render(gl, cr.getGeometry(c, Surface.EDGES), getAppearance(c), false, alpha);
} }
@ -103,13 +112,13 @@ public class RealisticRenderer extends RocketRenderer {
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR); gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
convertColor(a.getPaint(), color); convertColor(a.getPaint(), color);//color now contains alpha value
color[3] = alpha;
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0);
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
color[0] = color[1] = color[2] = (float) a.getShine(); color[0] = color[1] = color[2] = (float) a.getShine();
color[3] = alpha; color[3] = 1;//no alpha for shine
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0);
gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, (int) (100 * a.getShine())); gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, (int) (100 * a.getShine()));
@ -201,10 +210,12 @@ public class RealisticRenderer extends RocketRenderer {
out[0] = 1; out[0] = 1;
out[1] = 1; out[1] = 1;
out[2] = 0; out[2] = 0;
out[3] = 1;
} else { } else {
out[0] = (float) color.getRed() / 255f; out[0] = (float) color.getRed() / 255f;
out[1] = (float) color.getGreen() / 255f; out[1] = (float) color.getGreen() / 255f;
out[2] = (float) color.getBlue() / 255f; out[2] = (float) color.getBlue() / 255f;
out[3] = (float) color.getAlpha() / 255f;
} }
} }
} }