return(new MapPart(parentNeighbor.level+1, parentNeighbor.node, parentNeighbor.offset));
}
}
public MapPart getCornerNeighbor() {
if (getParent() == null) return(new MapPart(0, this, new Point2DInt(0,0))); // loop the root tile
/* test what child this tile is */
Point2DInt ownposition = getSimpleTileCoordinates(getThisChildnr());
/* if we can reach the neighbor directly using the parent then do so */
Point2DInt godirection = new Point2DInt(1,1);
Point2DInt newposition = ownposition.add(godirection);
if (newposition.x>=0 && newposition.x<=1 &&
newposition.y>=0 && newposition.y<=1) {
MapTileTreeNode result = getParent().getChild(getChildnr(newposition));
if (result==null) { // child does not exist, use parent and difference level of 1
return(new MapPart(1, getParent(), newposition));
}
else { // child does exist, use it with level difference of 0
return(new MapPart(0, getParent().getChild(getChildnr(newposition)), new Point2DInt(0,0)));
}
}
MapPart parentNeighbor = new MapPart();
Point2DInt searchposition = new Point2DInt();
try {
if (newposition.x>1 && newposition.y>1) {
/* otherwise we need to get the right neighbor from the parent tile */
parentNeighbor = (MapPart) getParent().getCornerNeighbor().clone();
searchposition = new Point2DInt(0,0);
}
else {
if (newposition.x>1) {
parentNeighbor = (MapPart) getSelectedNeighbor(0).clone();
searchposition = new Point2DInt(0,1);
}
else {
if (newposition.y>1) {
parentNeighbor = (MapPart) getSelectedNeighbor(1).clone();
searchposition = new Point2DInt(1,0);
}
}
}
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* from the parentNeighbor we need the child that is in the opposite direction */
if (parentNeighbor.node==null) { // neighbor does not exist
return(new MapPart(0, null, new Point2DInt(0,0)));
}
if (parentNeighbor.level==0 && !parentNeighbor.node.getSelectedForDrawing()) { // more childs exist
/* now get this child */
MapTileTreeNode result = parentNeighbor.node.getChild(getChildnr(searchposition));
if (result != null) { // has a child
return(new MapPart(0, result, new Point2DInt(0,0)));
}
else { // has no child, use parent
return(new MapPart(1, parentNeighbor.node, searchposition));
}
}