]> gerrit.simantics Code Review - simantics/district.git/blobdiff - 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
diff --git a/org.simantics.district.maps/src/org/simantics/maps/tile/TileKey.java b/org.simantics.district.maps/src/org/simantics/maps/tile/TileKey.java
new file mode 100644 (file)
index 0000000..b50a262
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.maps.tile;
+
+/**
+ * @author Tuukka Lehtonen
+ *
+ */
+public class TileKey {
+
+    /**
+     * Valid values within {0, 1, 2,... , n}. When the value is 0, the only
+     * valid (x,y) values are in {(0,0), (1,0)}, meaning half of the whole
+     * globe. Every time the value of level increases by one, the map is
+     * subdivided by 4 in the x direction and by two in the y direction, i.e.
+     * into eight equal size parts.
+     */
+    private final int level;
+
+    private final int x;
+
+    private final int y;
+
+    private final int hash;
+
+    public TileKey(int level, int x, int y) {
+        this.level = level;
+        this.x = x;
+        this.y = y;
+        this.hash = hash();
+    }
+
+    private int hash() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + level;
+        result = prime * result + x;
+        result = prime * result + y;
+        return result;
+    }
+
+    public int getLevel() {
+        return level;
+    }
+
+    public int getX() {
+        return x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    @Override
+    public int hashCode() {
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final TileKey other = (TileKey) obj;
+        if (level != other.level)
+            return false;
+        if (x != other.x)
+            return false;
+        if (y != other.y)
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "TileKey [level=" + level + ", x=" + x + ", y=" + y + "]";
+    }
+
+}