diff options
| author | Keith Packard <keithp@keithp.com> | 2016-05-10 22:46:58 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2016-05-11 23:22:15 -0700 | 
| commit | 60f4d69592c440ab7bb67a04f4c07fc7279d2c20 (patch) | |
| tree | 8edfca4a59b5d15d251607075453aeab1a9f376f /altoslib/AltosDistance.java | |
| parent | 6a6da23335e6e5864387c7a22946f80f51056a4f (diff) | |
altoslib: Switch distance from m/ft to km/miles for large values
This adds lots of infrastructure to deal with making the unit used
depend on the value itself, and then uses it only for distances.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosDistance.java')
| -rw-r--r-- | altoslib/AltosDistance.java | 56 | 
1 files changed, 55 insertions, 1 deletions
| diff --git a/altoslib/AltosDistance.java b/altoslib/AltosDistance.java index b68a4525..1ec39f8d 100644 --- a/altoslib/AltosDistance.java +++ b/altoslib/AltosDistance.java @@ -54,4 +54,58 @@ public class AltosDistance extends AltosUnits {  			return 1;  		return 0;  	} -}
\ No newline at end of file + +	public AltosDistance() { +		range_metric = new AltosUnitsRange[2]; + +		range_metric[0] = new AltosUnitsRange(0, "m", "meters") { +				double value(double v) { +					return v; +				} +				int show_fraction(int width) { +					return width / 9; +				} +				int say_fraction() { +					return 0; +				} +			}; +		range_metric[1] = new AltosUnitsRange(2000, "km", "kilometers") { +				double value(double v) { +					return v / 1000; +				} +				int show_fraction(int width) { +					return width / 5; +				} +				int say_fraction() { +					return 1; +				} +			}; + +		range_imperial = new AltosUnitsRange[2]; + +		range_imperial[0] = new AltosUnitsRange(0, "ft", "feet") { +				double value(double v) { +					return AltosConvert.meters_to_feet(v); +				} +				int show_fraction(int width) { +					return width / 9; +				} +				int say_fraction() { +					return 0; +				} +			}; + +		range_imperial[1] = new AltosUnitsRange(AltosConvert.feet_to_meters(5280), +							"mi", "miles") { +				double value(double v) { +					return AltosConvert.meters_to_miles(v); +				} +				int show_fraction(int width) { +					return width / 5; +				} +				int say_fraction() { +					return 1; +				} +			}; +	} +} | 
