@Test public void testSubdivide() { rootQuad.add(point1); Assert.assertEquals(1, rootQuad.getElements().size); Assert.assertEquals(1, rootQuad.getTotalQuads()); rootQuad.add(point2); Assert.assertEquals(2, rootQuad.getElements().size); Assert.assertEquals(1, rootQuad.getTotalQuads()); rootQuad.add(point3); Assert.assertEquals(3, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(point4); Assert.assertEquals(4, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(new CollisionPoint(32, 32)); Assert.assertEquals(5, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(new CollisionPoint(48, 48)); Assert.assertEquals(6, rootQuad.getElements().size); Assert.assertEquals(7, rootQuad.getTotalQuads()); }
protected void subdivide() { if (topLeft != null) { return; } float halfWidth = getWidth() * 0.5f; float halfHeight = getHeight() * 0.5f; topLeft = new PointQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new PointQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new PointQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new PointQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { T element = elements.removeIndex(i); element.removePositionChangeListener(this); addElementToChild(element); } elements = null; }
PointQuadTree extends Rectangle implements QuadTree<T> { protected void subdivide() { if (topLeft != null) { return; } float halfWidth = getWidth() * 0.5f; float halfHeight = getHeight() * 0.5f; topLeft = new PointQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new PointQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new PointQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new PointQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { T element = elements.removeIndex(i); element.removePositionChangeListener(this); addElementToChild(element); } elements = null; } }
PointQuadTree extends Rectangle implements QuadTree<T> { protected void subdivide() { if (topLeft != null) { return; } float halfWidth = getWidth() * 0.5f; float halfHeight = getHeight() * 0.5f; topLeft = new PointQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new PointQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new PointQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new PointQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { T element = elements.removeIndex(i); element.removePositionChangeListener(this); addElementToChild(element); } elements = null; } PointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width, float height);  PointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  PointQuadTree(PointQuadTree<T> parent, float x, float y, float width, float height);  PointQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); }
PointQuadTree extends Rectangle implements QuadTree<T> { protected void subdivide() { if (topLeft != null) { return; } float halfWidth = getWidth() * 0.5f; float halfHeight = getHeight() * 0.5f; topLeft = new PointQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new PointQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new PointQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new PointQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { T element = elements.removeIndex(i); element.removePositionChangeListener(this); addElementToChild(element); } elements = null; } PointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width, float height);  PointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  PointQuadTree(PointQuadTree<T> parent, float x, float y, float width, float height);  PointQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); void debugRender(Graphics g); void addAll(Array<T> elementsToAdd); boolean add(T element); void removeAll(Array<T> elementsToRemove); boolean remove(T element); void clear(); @Override Array<T> getElementsWithinArea(Shape area); @Override Array<T> getElementsWithinArea(Shape area, QuadTreeSearchDirection searchDirection); @Override void getElementsWithinArea(Array<T> result, Shape area); @Override void getElementsWithinArea(Array<T> result, Shape area, QuadTreeSearchDirection searchDirection); @Override Array<T> getElementsContainingArea(Shape area, boolean entirelyContained); @Override Array<T> getElementsContainingArea(Shape area, QuadTreeSearchDirection searchDirection, boolean entirelyContained); @Override void getElementsContainingArea(Array<T> result, Shape area, boolean entirelyContained); @Override void getElementsContainingArea(Array<T> result, Shape area, QuadTreeSearchDirection searchDirection, boolean entirelyContained); @Override Array<T> getElementsContainingPoint(Point point); @Override Array<T> getElementsContainingPoint(Point point, QuadTreeSearchDirection searchDirection); @Override void getElementsContainingPoint(Array<T> result, Point point); @Override void getElementsContainingPoint(Array<T> result, Point point, QuadTreeSearchDirection searchDirection); Array<T> getElementsIntersectingLineSegment(LineSegment lineSegment); @Override Array<T> getElementsIntersectingLineSegment(LineSegment lineSegment, QuadTreeSearchDirection searchDirection); void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment, QuadTreeSearchDirection searchDirection); Array<T> getElements(); void getElements(Array<T> result); int getTotalQuads(); int getTotalElements(); @Override void positionChanged(T moved); QuadTree<T> getParent(); int getElementLimitPerQuad(); int getMergeWatermark(); boolean hasChildQuads(); @Override float getMinimumQuadWidth(); @Override float getMinimumQuadHeight(); }
PointQuadTree extends Rectangle implements QuadTree<T> { protected void subdivide() { if (topLeft != null) { return; } float halfWidth = getWidth() * 0.5f; float halfHeight = getHeight() * 0.5f; topLeft = new PointQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new PointQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new PointQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new PointQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { T element = elements.removeIndex(i); element.removePositionChangeListener(this); addElementToChild(element); } elements = null; } PointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width, float height);  PointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  PointQuadTree(PointQuadTree<T> parent, float x, float y, float width, float height);  PointQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); void debugRender(Graphics g); void addAll(Array<T> elementsToAdd); boolean add(T element); void removeAll(Array<T> elementsToRemove); boolean remove(T element); void clear(); @Override Array<T> getElementsWithinArea(Shape area); @Override Array<T> getElementsWithinArea(Shape area, QuadTreeSearchDirection searchDirection); @Override void getElementsWithinArea(Array<T> result, Shape area); @Override void getElementsWithinArea(Array<T> result, Shape area, QuadTreeSearchDirection searchDirection); @Override Array<T> getElementsContainingArea(Shape area, boolean entirelyContained); @Override Array<T> getElementsContainingArea(Shape area, QuadTreeSearchDirection searchDirection, boolean entirelyContained); @Override void getElementsContainingArea(Array<T> result, Shape area, boolean entirelyContained); @Override void getElementsContainingArea(Array<T> result, Shape area, QuadTreeSearchDirection searchDirection, boolean entirelyContained); @Override Array<T> getElementsContainingPoint(Point point); @Override Array<T> getElementsContainingPoint(Point point, QuadTreeSearchDirection searchDirection); @Override void getElementsContainingPoint(Array<T> result, Point point); @Override void getElementsContainingPoint(Array<T> result, Point point, QuadTreeSearchDirection searchDirection); Array<T> getElementsIntersectingLineSegment(LineSegment lineSegment); @Override Array<T> getElementsIntersectingLineSegment(LineSegment lineSegment, QuadTreeSearchDirection searchDirection); void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment, QuadTreeSearchDirection searchDirection); Array<T> getElements(); void getElements(Array<T> result); int getTotalQuads(); int getTotalElements(); @Override void positionChanged(T moved); QuadTree<T> getParent(); int getElementLimitPerQuad(); int getMergeWatermark(); boolean hasChildQuads(); @Override float getMinimumQuadWidth(); @Override float getMinimumQuadHeight(); static final float DEFAULT_MINIMUM_QUAD_SIZE; static Color QUAD_COLOR; static Color ELEMENT_COLOR; }