@Test public void testSubdivide() { rootQuad.add(box1); Assert.assertEquals(1, rootQuad.getElements().size); Assert.assertEquals(1, rootQuad.getTotalQuads()); rootQuad.add(box2); Assert.assertEquals(2, rootQuad.getElements().size); Assert.assertEquals(1, rootQuad.getTotalQuads()); rootQuad.add(box3); Assert.assertEquals(3, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(box4); Assert.assertEquals(4, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(new CollisionBox(24, 24, 2, 2)); Assert.assertEquals(5, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(new CollisionBox(48, 48, 32, 32)); Assert.assertEquals(6, rootQuad.getElements().size); Assert.assertEquals(4, rootQuad.getTotalQuads()); rootQuad.add(new CollisionBox(12, 48, 8, 8)); Assert.assertEquals(7, rootQuad.getElements().size); Assert.assertEquals(7, rootQuad.getTotalQuads()); }
@Override protected void subdivide() { if (topLeft != null) return; float halfWidth = getWidth() / 2f; float halfHeight = getHeight() / 2f; topLeft = new RegionQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new RegionQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { if (addElementToChild(elements.get(i))) { removeElement(elements.get(i)); } } }
RegionQuadTree extends PointQuadTree<T> { @Override protected void subdivide() { if (topLeft != null) return; float halfWidth = getWidth() / 2f; float halfHeight = getHeight() / 2f; topLeft = new RegionQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new RegionQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { if (addElementToChild(elements.get(i))) { removeElement(elements.get(i)); } } } }
RegionQuadTree extends PointQuadTree<T> { @Override protected void subdivide() { if (topLeft != null) return; float halfWidth = getWidth() / 2f; float halfHeight = getHeight() / 2f; topLeft = new RegionQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new RegionQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { if (addElementToChild(elements.get(i))) { removeElement(elements.get(i)); } } } RegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  RegionQuadTree(int elementLimit, float x, float y, float width, float height);  RegionQuadTree(RegionQuadTree<T> parent, float x, float y, float width, float height);  RegionQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); }
RegionQuadTree extends PointQuadTree<T> { @Override protected void subdivide() { if (topLeft != null) return; float halfWidth = getWidth() / 2f; float halfHeight = getHeight() / 2f; topLeft = new RegionQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new RegionQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { if (addElementToChild(elements.get(i))) { removeElement(elements.get(i)); } } } RegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  RegionQuadTree(int elementLimit, float x, float y, float width, float height);  RegionQuadTree(RegionQuadTree<T> parent, float x, float y, float width, float height);  RegionQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); @Override void debugRender(Graphics g); @Override void addAll(Array<T> elementsToAdd); @Override boolean add(T element); @Override boolean remove(T element); @Override void clear(); @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 void getElementsContainingPoint(Array<T> result, Point point); @Override void getElementsContainingPoint(Array<T> result, Point point, QuadTreeSearchDirection searchDirection); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment, QuadTreeSearchDirection searchDirection); @Override Array<T> getElements(); @Override void getElements(Array<T> result); @Override int getTotalElements(); @Override void positionChanged(T moved); }
RegionQuadTree extends PointQuadTree<T> { @Override protected void subdivide() { if (topLeft != null) return; float halfWidth = getWidth() / 2f; float halfHeight = getHeight() / 2f; topLeft = new RegionQuadTree<T>(this, getX(), getY(), halfWidth, halfHeight); topRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY(), halfWidth, halfHeight); bottomLeft = new RegionQuadTree<T>(this, getX(), getY() + halfHeight, halfWidth, halfHeight); bottomRight = new RegionQuadTree<T>(this, getX() + halfWidth, getY() + halfHeight, halfWidth, halfHeight); for (int i = elements.size - 1; i >= 0; i--) { if (addElementToChild(elements.get(i))) { removeElement(elements.get(i)); } } } RegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  RegionQuadTree(int elementLimit, float x, float y, float width, float height);  RegionQuadTree(RegionQuadTree<T> parent, float x, float y, float width, float height);  RegionQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark,
			float x, float y, float width, float height); @Override void debugRender(Graphics g); @Override void addAll(Array<T> elementsToAdd); @Override boolean add(T element); @Override boolean remove(T element); @Override void clear(); @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 void getElementsContainingPoint(Array<T> result, Point point); @Override void getElementsContainingPoint(Array<T> result, Point point, QuadTreeSearchDirection searchDirection); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment); @Override void getElementsIntersectingLineSegment(Array<T> result, LineSegment lineSegment, QuadTreeSearchDirection searchDirection); @Override Array<T> getElements(); @Override void getElements(Array<T> result); @Override int getTotalElements(); @Override void positionChanged(T moved);  }