X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Ftile%2FTileKey.java;fp=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Ftile%2FTileKey.java;h=b50a262d1b50e03ef63c6dec221c75a65466ba09;hb=e9f74f09e0cedb603c0b4de9e542de8dd64a5ce3;hp=0000000000000000000000000000000000000000;hpb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;p=simantics%2Fdistrict.git 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 index 00000000..b50a262d --- /dev/null +++ b/org.simantics.district.maps/src/org/simantics/maps/tile/TileKey.java @@ -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 + "]"; + } + +}