root/trunk/as2/lib/com/modestmaps/core/Coordinate.as

Revision 292, 2.4 kB (checked in by migurski, 1 year ago)

Added Id keywords all over the place

  • Property svn:keywords set to Id
Line 
1 /*
2  * $Id$
3  */
4
5 class com.modestmaps.core.Coordinate
6 {
7     public var row:Number, column:Number, zoom:Number;
8    
9     public static var MAX_ZOOM:Number = 20;
10
11     function Coordinate(row:Number, column:Number, zoom:Number)
12     {
13         this.row = row;
14         this.column = column;
15         this.zoom = zoom;
16     }
17    
18     public function toString():String
19     {
20         return '(' + row + ',' + column + ' @' + zoom + ')';
21     }
22    
23     public function copy():Coordinate
24     {
25         return new Coordinate(row, column, zoom);
26     }
27    
28    /**
29     * Return a new coordinate that corresponds to that of the tile containing this one
30     */
31     public function container():Coordinate
32     {
33         return new Coordinate(Math.floor(row), Math.floor(column), zoom);
34     }
35    
36     public function zoomTo(destination:Number):Coordinate
37     {
38         return new Coordinate(row * Math.pow(2, destination - zoom),
39                               column * Math.pow(2, destination - zoom),
40                               destination);
41     }
42    
43     public function zoomBy(distance:Number):Coordinate
44     {
45         return new Coordinate(row * Math.pow(2, distance),
46                               column * Math.pow(2, distance),
47                               zoom + distance);
48     }
49    
50     public function isRowEdge():Boolean
51     {
52         return Math.round(row) == row;
53     }
54    
55     public function isColumnEdge():Boolean
56     {
57         return Math.round(column) == column;
58     }
59    
60     public function isEdge():Boolean
61     {
62         return isRowEdge() && isColumnEdge();
63     }
64    
65     public function up(distance:Number):Coordinate
66     {
67         return new Coordinate(row - (distance ? distance : 1), column, zoom);
68     }
69    
70     public function right(distance:Number):Coordinate
71     {
72         return new Coordinate(row, column + (distance ? distance : 1), zoom);
73     }
74    
75     public function down(distance:Number):Coordinate
76     {
77         return new Coordinate(row + (distance ? distance : 1), column, zoom);
78     }
79    
80     public function left(distance:Number):Coordinate
81     {
82         return new Coordinate(row, column - (distance ? distance : 1), zoom);
83     }
84    
85     /*
86      * Returns true if the the two coordinates refer to the same Tile location.
87      */
88     public function equalTo( coord : Coordinate ) : Boolean
89     {
90         return coord.row == this.row && coord.column == this.column && coord.zoom == this.zoom;
91     }
92 }
Note: See TracBrowser for help on using the browser.