From 463895adb6fbbd45e37c45a0c9d89bd0b1af5c6f Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 23 Mar 2023 00:39:12 +0100 Subject: [PATCH] Use higher precision for inches lengths --- core/src/net/sf/openrocket/unit/InchUnit.java | 22 +++++++++++++++++++ .../src/net/sf/openrocket/unit/UnitGroup.java | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/unit/InchUnit.java b/core/src/net/sf/openrocket/unit/InchUnit.java index 0a2a77ee9..bc126f656 100644 --- a/core/src/net/sf/openrocket/unit/InchUnit.java +++ b/core/src/net/sf/openrocket/unit/InchUnit.java @@ -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; + } } diff --git a/core/src/net/sf/openrocket/unit/UnitGroup.java b/core/src/net/sf/openrocket/unit/UnitGroup.java index e86c22f9c..c5e10cfdd 100644 --- a/core/src/net/sf/openrocket/unit/UnitGroup.java +++ b/core/src/net/sf/openrocket/unit/UnitGroup.java @@ -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"));