Bump java lib versions to 13
[fw/altos] / altoslib / AltosDistance.java
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altoslib_13;
20
21 public class AltosDistance extends AltosUnits {
22
23         public double value(double v, boolean imperial_units) {
24                 if (imperial_units)
25                         return AltosConvert.meters_to_miles(v);
26                 return v;
27         }
28
29         public double inverse(double v, boolean imperial_units) {
30                 if (imperial_units)
31                         return AltosConvert.miles_to_meters(v);
32                 return v;
33         }
34
35         public String show_units(boolean imperial_units) {
36                 if (imperial_units)
37                         return "miles";
38                 return "m";
39         }
40
41         public String say_units(boolean imperial_units) {
42                 if (imperial_units)
43                         return "miles";
44                 return "meters";
45         }
46
47         public int show_fraction(int width, boolean imperial_units) {
48                 if (imperial_units)
49                         return width / 3;
50                 return width / 9;
51         }
52
53         public int say_fraction(boolean imperial_units) {
54                 if (imperial_units)
55                         return 1;
56                 return 0;
57         }
58
59         public AltosDistance() {
60                 range_metric = new AltosUnitsRange[2];
61
62                 range_metric[0] = new AltosUnitsRange(0, "m", "meters") {
63                                 double value(double v) {
64                                         return v;
65                                 }
66                                 int show_fraction(int width) {
67                                         return width / 9;
68                                 }
69                                 int say_fraction() {
70                                         return 0;
71                                 }
72                         };
73                 range_metric[1] = new AltosUnitsRange(2000, "km", "kilometers") {
74                                 double value(double v) {
75                                         return v / 1000;
76                                 }
77                                 int show_fraction(int width) {
78                                         return width / 5;
79                                 }
80                                 int say_fraction() {
81                                         return 1;
82                                 }
83                         };
84
85                 range_imperial = new AltosUnitsRange[2];
86
87                 range_imperial[0] = new AltosUnitsRange(0, "ft", "feet") {
88                                 double value(double v) {
89                                         return AltosConvert.meters_to_feet(v);
90                                 }
91                                 int show_fraction(int width) {
92                                         return width / 9;
93                                 }
94                                 int say_fraction() {
95                                         return 0;
96                                 }
97                         };
98
99                 range_imperial[1] = new AltosUnitsRange(AltosConvert.feet_to_meters(5280),
100                                                         "mi", "miles") {
101                                 double value(double v) {
102                                         return AltosConvert.meters_to_miles(v);
103                                 }
104                                 int show_fraction(int width) {
105                                         return width / 5;
106                                 }
107                                 int say_fraction() {
108                                         return 1;
109                                 }
110                         };
111         }
112 }