Use higher precision for inches lengths

This commit is contained in:
SiboVG 2023-03-23 00:39:12 +01:00
parent f4f6200662
commit 463895adb6
2 changed files with 23 additions and 1 deletions

View File

@ -4,9 +4,21 @@ package net.sf.openrocket.unit;
* Special unit for inches, which always provides 3-decimal precision.
*/
public class InchUnit extends GeneralUnit {
private final double precision;
public InchUnit(double multiplier, String unit) {
this(multiplier, unit, 1);
}
/**
*
* @param multiplier
* @param unit
* @param precision The precision of the unit, in inches.
*/
public InchUnit(double multiplier, String unit, double precision) {
super(multiplier, unit);
this.precision = precision;
}
@ -16,5 +28,15 @@ public class InchUnit extends GeneralUnit {
val = Math.rint(val * mul) / mul;
return val;
}
@Override
public double getNextValue(double value) {
return value + precision;
}
@Override
public double getPreviousValue(double value) {
return value - precision;
}
}

View File

@ -123,7 +123,7 @@ public class UnitGroup {
UNITS_LENGTH.addUnit(new GeneralUnit(0.001, "mm"));
UNITS_LENGTH.addUnit(new GeneralUnit(0.01, "cm"));
UNITS_LENGTH.addUnit(new GeneralUnit(1, "m"));
UNITS_LENGTH.addUnit(new InchUnit(0.0254, "in"));
UNITS_LENGTH.addUnit(new InchUnit(0.0254, "in", 0.1));
UNITS_LENGTH.addUnit(new FractionalUnit(0.0254, "in/64", "in", 64, 1d / 16d, 0.5d / 64d));
UNITS_LENGTH.addUnit(new GeneralUnit(0.3048, "ft"));