]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.maps/src/org/simantics/maps/tile/TileKey.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / tile / TileKey.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.maps.tile;
13
14 /**
15  * @author Tuukka Lehtonen
16  *
17  */
18 public class TileKey {
19
20     /**
21      * Valid values within {0, 1, 2,... , n}. When the value is 0, the only
22      * valid (x,y) values are in {(0,0), (1,0)}, meaning half of the whole
23      * globe. Every time the value of level increases by one, the map is
24      * subdivided by 4 in the x direction and by two in the y direction, i.e.
25      * into eight equal size parts.
26      */
27     private final int level;
28
29     private final int x;
30
31     private final int y;
32
33     private final int hash;
34
35     public TileKey(int level, int x, int y) {
36         this.level = level;
37         this.x = x;
38         this.y = y;
39         this.hash = hash();
40     }
41
42     private int hash() {
43         final int prime = 31;
44         int result = 1;
45         result = prime * result + level;
46         result = prime * result + x;
47         result = prime * result + y;
48         return result;
49     }
50
51     public int getLevel() {
52         return level;
53     }
54
55     public int getX() {
56         return x;
57     }
58
59     public int getY() {
60         return y;
61     }
62
63     @Override
64     public int hashCode() {
65         return hash;
66     }
67
68     @Override
69     public boolean equals(Object obj) {
70         if (this == obj)
71             return true;
72         if (obj == null)
73             return false;
74         if (getClass() != obj.getClass())
75             return false;
76         final TileKey other = (TileKey) obj;
77         if (level != other.level)
78             return false;
79         if (x != other.x)
80             return false;
81         if (y != other.y)
82             return false;
83         return true;
84     }
85
86     @Override
87     public String toString() {
88         return "TileKey [level=" + level + ", x=" + x + ", y=" + y + "]";
89     }
90
91 }