@Test public void testRemoveAll() { Random random = new Random(); Array<CollisionBox> rects = new Array<CollisionBox>(); for (int i = 0; i < 100; i++) { rects.add(new CollisionBox(random.nextInt(96), random.nextInt(96), random.nextInt(32), random.nextInt(32))); } rootQuad.addAll(rects); Assert.assertEquals(rects.size, rootQuad.getTotalElements()); rootQuad.removeAll(rects); Assert.assertEquals(0, rootQuad.getTotalElements()); }
@Override public void removeAll(Array<T> elementsToRemove) { if(elementsToRemove == null || elementsToRemove.size == 0) { return; } clearTotalElementsCache(); Array<T> elementsWithinQuad = new Array<T>(); for(T element : elementsToRemove) { if(this.contains(element) || this.intersects(element)) { elementsWithinQuad.add(element); } } lock.lockRead(); if(topLeft != null) { for(int i = elementsWithinQuad.size - 1; i >= 0; i--) { T element = elementsWithinQuad.get(i); if (topLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (topRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } } } lock.unlockRead(); lock.lockWrite(); elements.removeAll(elementsWithinQuad, false); lock.unlockWrite(); for(T element : elementsWithinQuad) { element.removePositionChangeListener(this); } if (parent == null) { return; } if (parent.isMergable()) { parent.merge(); } }
ConcurrentRegionQuadTree extends ConcurrentPointQuadTree<T> { @Override public void removeAll(Array<T> elementsToRemove) { if(elementsToRemove == null || elementsToRemove.size == 0) { return; } clearTotalElementsCache(); Array<T> elementsWithinQuad = new Array<T>(); for(T element : elementsToRemove) { if(this.contains(element) || this.intersects(element)) { elementsWithinQuad.add(element); } } lock.lockRead(); if(topLeft != null) { for(int i = elementsWithinQuad.size - 1; i >= 0; i--) { T element = elementsWithinQuad.get(i); if (topLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (topRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } } } lock.unlockRead(); lock.lockWrite(); elements.removeAll(elementsWithinQuad, false); lock.unlockWrite(); for(T element : elementsWithinQuad) { element.removePositionChangeListener(this); } if (parent == null) { return; } if (parent.isMergable()) { parent.merge(); } } }
ConcurrentRegionQuadTree extends ConcurrentPointQuadTree<T> { @Override public void removeAll(Array<T> elementsToRemove) { if(elementsToRemove == null || elementsToRemove.size == 0) { return; } clearTotalElementsCache(); Array<T> elementsWithinQuad = new Array<T>(); for(T element : elementsToRemove) { if(this.contains(element) || this.intersects(element)) { elementsWithinQuad.add(element); } } lock.lockRead(); if(topLeft != null) { for(int i = elementsWithinQuad.size - 1; i >= 0; i--) { T element = elementsWithinQuad.get(i); if (topLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (topRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } } } lock.unlockRead(); lock.lockWrite(); elements.removeAll(elementsWithinQuad, false); lock.unlockWrite(); for(T element : elementsWithinQuad) { element.removePositionChangeListener(this); } if (parent == null) { return; } if (parent.isMergable()) { parent.merge(); } } ConcurrentRegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  ConcurrentRegionQuadTree(int elementLimit, float x, float y, float width, float height);  ConcurrentRegionQuadTree(ConcurrentRegionQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentRegionQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad,
			int mergeWatermark, float x, float y, float width, float height); }
ConcurrentRegionQuadTree extends ConcurrentPointQuadTree<T> { @Override public void removeAll(Array<T> elementsToRemove) { if(elementsToRemove == null || elementsToRemove.size == 0) { return; } clearTotalElementsCache(); Array<T> elementsWithinQuad = new Array<T>(); for(T element : elementsToRemove) { if(this.contains(element) || this.intersects(element)) { elementsWithinQuad.add(element); } } lock.lockRead(); if(topLeft != null) { for(int i = elementsWithinQuad.size - 1; i >= 0; i--) { T element = elementsWithinQuad.get(i); if (topLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (topRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } } } lock.unlockRead(); lock.lockWrite(); elements.removeAll(elementsWithinQuad, false); lock.unlockWrite(); for(T element : elementsWithinQuad) { element.removePositionChangeListener(this); } if (parent == null) { return; } if (parent.isMergable()) { parent.merge(); } } ConcurrentRegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  ConcurrentRegionQuadTree(int elementLimit, float x, float y, float width, float height);  ConcurrentRegionQuadTree(ConcurrentRegionQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentRegionQuadTree(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> elements); @Override boolean add(T element); @Override void removeAll(Array<T> elementsToRemove); @Override boolean remove(T element); @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); }
ConcurrentRegionQuadTree extends ConcurrentPointQuadTree<T> { @Override public void removeAll(Array<T> elementsToRemove) { if(elementsToRemove == null || elementsToRemove.size == 0) { return; } clearTotalElementsCache(); Array<T> elementsWithinQuad = new Array<T>(); for(T element : elementsToRemove) { if(this.contains(element) || this.intersects(element)) { elementsWithinQuad.add(element); } } lock.lockRead(); if(topLeft != null) { for(int i = elementsWithinQuad.size - 1; i >= 0; i--) { T element = elementsWithinQuad.get(i); if (topLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (topRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomLeft.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } if (bottomRight.remove(element)) { elementsWithinQuad.removeIndex(i); continue; } } } lock.unlockRead(); lock.lockWrite(); elements.removeAll(elementsWithinQuad, false); lock.unlockWrite(); for(T element : elementsWithinQuad) { element.removePositionChangeListener(this); } if (parent == null) { return; } if (parent.isMergable()) { parent.merge(); } } ConcurrentRegionQuadTree(int elementLimit, int mergeWatermark, float x, float y, float width, float height);  ConcurrentRegionQuadTree(int elementLimit, float x, float y, float width, float height);  ConcurrentRegionQuadTree(ConcurrentRegionQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentRegionQuadTree(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> elements); @Override boolean add(T element); @Override void removeAll(Array<T> elementsToRemove); @Override boolean remove(T element); @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);  }