@Test public void testRemoveAll() { Random random = new Random(); Array<CollisionPoint> points = new Array<CollisionPoint>(); for (int i = 0; i < 100; i++) { points.add(new CollisionPoint(random.nextInt(128), random.nextInt(128))); } rootQuad.addAll(points); Assert.assertEquals(points.size, rootQuad.getTotalElements()); rootQuad.removeAll(points); Assert.assertEquals(0, rootQuad.getTotalElements()); }
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.getX(), element.getY())) { 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(); } }
ConcurrentPointQuadTree extends Rectangle implements QuadTree<T> { 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.getX(), element.getY())) { 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(); } } }
ConcurrentPointQuadTree extends Rectangle implements QuadTree<T> { 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.getX(), element.getY())) { 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(); } } ConcurrentPointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  ConcurrentPointQuadTree(ConcurrentPointQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentPointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width,
			float height);  ConcurrentPointQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad,
			int mergeWatermark, float x, float y, float width, float height); }
ConcurrentPointQuadTree extends Rectangle implements QuadTree<T> { 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.getX(), element.getY())) { 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(); } } ConcurrentPointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  ConcurrentPointQuadTree(ConcurrentPointQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentPointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width,
			float height);  ConcurrentPointQuadTree(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); @Override void clear(); boolean remove(T element); @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 getTotalMergeOperations(); int getElementLimitPerQuad(); int getMergeWatermark(); @Override float getMinimumQuadWidth(); @Override float getMinimumQuadHeight(); }
ConcurrentPointQuadTree extends Rectangle implements QuadTree<T> { 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.getX(), element.getY())) { 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(); } } ConcurrentPointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height);  ConcurrentPointQuadTree(ConcurrentPointQuadTree<T> parent, float x, float y, float width, float height);  ConcurrentPointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width,
			float height);  ConcurrentPointQuadTree(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); @Override void clear(); boolean remove(T element); @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 getTotalMergeOperations(); int getElementLimitPerQuad(); int getMergeWatermark(); @Override float getMinimumQuadWidth(); @Override float getMinimumQuadHeight(); static Color QUAD_COLOR; static Color ELEMENT_COLOR; }