// retourne le noeud voisin d'un noeud (algorithme générique) private QuadTreeNodeInterface<E> sibling( AbstractQuadTreeNode<E> node, int[] ancestortype, int[] reverter) { int[] path = new int[treeRoot.maxNodeDepth + 1]; int pathlength = 0; // recherche du plus proche ancetre commun AbstractQuadTreeNode<E> ancestor = node; while (true) { if (ancestor.getPositionInParentNode() == ROOT) { return null; // no common ancestor -> exit } path[pathlength] = ancestor.getPositionInParentNode(); pathlength++; if (ancestor.getPositionInParentNode() == ancestortype[0]) { ancestor = ancestor.getParent(); break; } if (ancestor.getPositionInParentNode() == ancestortype[1]) { ancestor = ancestor.getParent(); break; } ancestor = ancestor.getParent(); } // parcours de l'arbre en utilisant le chemin symetrique AbstractQuadTreeNode<E> cursor = ancestor, next = null; for (int i = pathlength - 1; i >= 0; i--) { if (cursor.children == null) break; next = cursor.children.get(reverter[path[i]]); if (next == null) break; cursor = next; } return cursor; }