public static QuadTreeNode and(QuadTreeNode node1, QuadTreeNode node2) { QuadTreeNode node = new QuadTreeNode(); if (node1.isFull && node2.isFull) { node.isFull = true; node.color = node1.color & node2.color; } else if (node1.isFull) { if (node1.color == 0) { node.isFull = true; node.color = 0; } else { node.isFull = false; for (int i = 0; i < 4; ++i) { node.children[i] = and(node1, node2.children[i]); } } } else if (node2.isFull) { return and(node2, node1); } else { node.isFull = false; for (int i = 0; i < 4; ++i) { node.children[i] = and(node1.children[i], node2.children[i]); } } return node; }
/** * Testing the public members of QuadTreeNode * * @author Sam Whitlock (cs61b-eo) * @param void * @return void */ @Test QTNtest1() { QuadTreeNode<QuadPoint> qnt = new QuadTreeNode<QuadPoint>(null, null, -1, 0, 10, 11); assertEquals(qnt.llx(), -1); assertEquals(qnt.lly(), 0); assertEquals(qnt.urx(), 10); assertEquals(qnt.ury(), 11); assertEquals(qnt.x(), 11); assertEquals(qnt.y(), 11); QuadTreeNode<QuadPoint> qnt1 = new QuadTreeNode<QuadPoint>(null, null, 0, 0, 10, 10); qnt.parent = qnt1; assertEquals(qnt1, qnt.parent); QuadTree<QuadPoint> tree = new QuadTree<QuadPoint>(-90, -90, 90, 90, 5); qnt.myTree = tree; assertEquals(qnt.myTree, tree); }
@Override public boolean completelyInBoundry(QuadTreeNode node) { if ((getX() - getR() >= node.getX() && getX() + getR() <= node.getX() + node.getW()) && (getY() - getR() >= node.getY() && getY() + getR() <= node.getY() + node.getH())) { return true; } return false; }