1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import java.io.*;
7    
8    public class MapScale implements Serializable,Cloneable {
9    
10     private static final long serialVersionUID = Version.getSUID();
11   
12     public Unit display = Unit.inch;
13     public Unit map = Unit.foot;
14     public transient double metersperpixel = -1;
15   
16     public MapScale(Unit disp,Unit m) {
17       display = disp;
18       map = m;
19     }
20   
21     public MapScale(Unit disp,Unit m,double metersperpixel) {
22       display = disp;
23       map = m;
24       this.metersperpixel=metersperpixel;
25     }
26   
27     public MapScale(double fact,Unit dispbase,Unit m,double metersperpixel) {
28       this(new Unit(fact,dispbase),m);
29       this.metersperpixel=metersperpixel;
30     }
31   
32     public MapScale(double fact,Unit dispbase,Unit m) {
33       this(new Unit(fact,dispbase),m);
34       this.metersperpixel = -1;
35     }
36   
37     public String toString() {
38       return("disp = "+display+" map = "+map);
39     }
40   
41     public double scale(Unit source) {
42       return(display.size*map.toUnit(source,metersperpixel));
43     }
44   
45     public Object clone() {
46       return((Object)new MapScale(new Unit(display.size,display.base),map,metersperpixel));
47     }
48   
49     public double toBase(Unit old) {
50   //    System.out.println("base = "+display.base+" old = "+old+" metersperpixel = "+metersperpixel);
51       return(display.base.toUnit(old,metersperpixel));
52     }
53   
54     public boolean equals(Object that) {
55       return((that instanceof MapScale) &&
56              (map==((MapScale)that).map) &&
57              (display.base==((MapScale)that).display.base) &&
58              (display.size==((MapScale)that).display.size));
59     }
60   
61     public int compareTo(MapScale that) {
62       double fact = (that.map.getRootSize()/
63         (map.getRootSize()*display.toUnit(that.display,metersperpixel)));
64       if (fact<1) return(-1);
65       if (fact>1) return(1);
66       return(0);
67     }
68   
69   }
70   
71