public class ConcurrentPointQuadTree<T extends Positionable> extends Rectangle implements QuadTree<T>
Modifier and Type | Field and Description |
---|---|
protected ConcurrentPointQuadTree<T> |
bottomLeft |
protected ConcurrentPointQuadTree<T> |
bottomRight |
static com.badlogic.gdx.graphics.Color |
ELEMENT_COLOR |
protected int |
elementLimitPerQuad |
protected java.util.List<T> |
elements |
protected java.util.concurrent.locks.ReadWriteLock |
lock |
protected int |
mergeWatermark |
protected float |
minimumQuadHeight |
protected float |
minimumQuadWidth |
protected ConcurrentPointQuadTree<T> |
parent |
static com.badlogic.gdx.graphics.Color |
QUAD_COLOR |
protected ConcurrentPointQuadTree<T> |
topLeft |
protected ConcurrentPointQuadTree<T> |
topRight |
protected int |
totalElementsCache |
protected int |
totalMerges |
Constructor and Description |
---|
ConcurrentPointQuadTree(ConcurrentPointQuadTree<T> parent,
float x,
float y,
float width,
float height)
Constructs a
ConcurrentPointQuadTree as a child of another
ConcurrentPointQuadTree |
ConcurrentPointQuadTree(float minimumQuadWidth,
float minimumQuadHeight,
int elementLimitPerQuad,
int mergeWatermark,
float x,
float y,
float width,
float height)
Constructs a
ConcurrentPointQuadTree with a specified minimum
quad size, element limit and watermark |
ConcurrentPointQuadTree(int elementLimitPerQuad,
float x,
float y,
float width,
float height)
Constructs a
ConcurrentPointQuadTree with a specified element
limit and no merging watermark. |
ConcurrentPointQuadTree(int elementLimitPerQuad,
int mergeWatermark,
float x,
float y,
float width,
float height)
Constructs a
ConcurrentPointQuadTree with a specified element
limit and watermark |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T element) |
void |
addAll(java.util.List<T> elementsToAdd) |
protected boolean |
addElement(T element) |
protected boolean |
addElementToChild(T element) |
protected void |
clearTotalElementsCache() |
void |
debugRender(Graphics g) |
int |
getElementLimitPerQuad() |
java.util.List<T> |
getElements() |
void |
getElements(java.util.List<T> result) |
void |
getElementsContainingPoint(java.util.Collection<T> result,
Point point) |
java.util.List<T> |
getElementsContainingPoint(Point point) |
void |
getElementsIntersectingLineSegment(java.util.Collection<T> result,
LineSegment lineSegment) |
java.util.List<T> |
getElementsIntersectingLineSegment(LineSegment lineSegment) |
void |
getElementsWithinArea(java.util.Collection<T> result,
Shape area) |
java.util.List<T> |
getElementsWithinArea(Shape area) |
int |
getMergeWatermark() |
float |
getMinimumQuadHeight() |
float |
getMinimumQuadWidth() |
QuadTree<T> |
getParent() |
int |
getTotalElements() |
int |
getTotalMergeOperations() |
int |
getTotalQuads() |
protected boolean |
isMergable() |
protected void |
merge() |
void |
positionChanged(T moved) |
boolean |
remove(T element) |
void |
removeAll(java.util.List<T> elementsToRemove) |
protected boolean |
removeElement(T element,
boolean topDownInvocation) |
protected boolean |
removeElementFromChild(T element) |
protected void |
subdivide() |
contains, contains, contains, contains, contains, contains, copy, draw, edgeIterator, equals, fill, getCenterX, getCenterY, getDistanceTo, getDistanceTo, getHeight, getMaxX, getMaxY, getMinX, getMinY, getNumberOfSides, getPolygon, getRotation, getVertices, getWidth, getX, getY, hashCode, intersection, intersects, intersects, intersects, intersects, intersects, intersects, intersects, intersectsLineSegment, intersectsLineSegment, intersectsLineSegment, isCircle, lerp, rotate, rotateAround, scale, set, set, set, set, setCenter, setCenterX, setCenterY, setHeight, setRadius, setRotation, setRotationAround, setRotationAround, setSize, setSize, setWidth, setX, setY, toString, translate
add, intersects, subtract
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
contains, contains, getHeight, getMaxX, getMaxY, getRotation, getWidth, getX, getY, intersects, intersects, intersectsLineSegment, rotate, rotateAround, setRotation, setRotationAround
public static com.badlogic.gdx.graphics.Color QUAD_COLOR
public static com.badlogic.gdx.graphics.Color ELEMENT_COLOR
protected ConcurrentPointQuadTree<T extends Positionable> parent
protected ConcurrentPointQuadTree<T extends Positionable> topLeft
protected ConcurrentPointQuadTree<T extends Positionable> topRight
protected ConcurrentPointQuadTree<T extends Positionable> bottomLeft
protected ConcurrentPointQuadTree<T extends Positionable> bottomRight
protected java.util.List<T extends Positionable> elements
protected final int elementLimitPerQuad
protected final int mergeWatermark
protected final float minimumQuadWidth
protected final float minimumQuadHeight
protected final java.util.concurrent.locks.ReadWriteLock lock
protected int totalElementsCache
protected int totalMerges
public ConcurrentPointQuadTree(int elementLimitPerQuad, float x, float y, float width, float height)
ConcurrentPointQuadTree
with a specified element
limit and no merging watermark. As elements are removed, small sized
child ConcurrentPointQuadTree
s will not be merged back together.elementLimitPerQuad
- The maximum number of elements in a quad before it is split
into 4 child ConcurrentPointQuadTree
sx
- The x coordinate of the ConcurrentPointQuadTree
y
- The y coordiante of the ConcurrentPointQuadTree
width
- The width of the ConcurrentPointQuadTree
height
- The height of the ConcurrentPointQuadTree
public ConcurrentPointQuadTree(ConcurrentPointQuadTree<T> parent, float x, float y, float width, float height)
ConcurrentPointQuadTree
as a child of another
ConcurrentPointQuadTree
parent
- The parent ConcurrentPointQuadTree
x
- The x coordinate of the ConcurrentPointQuadTree
y
- The y coordiante of the ConcurrentPointQuadTree
width
- The width of the ConcurrentPointQuadTree
height
- The height of the ConcurrentPointQuadTree
public ConcurrentPointQuadTree(int elementLimitPerQuad, int mergeWatermark, float x, float y, float width, float height)
ConcurrentPointQuadTree
with a specified element
limit and watermarkelementLimitPerQuad
- The maximum number of elements in a quad before it is split
into 4 child ConcurrentPointQuadTree
smergeWatermark
- When a parent ConcurrentPointQuadTree
's total elements
go lower than this mark, the child
ConcurrentPointQuadTree
s will be merged back togetherx
- The x coordinate of the ConcurrentPointQuadTree
y
- The y coordiante of the ConcurrentPointQuadTree
width
- The width of the ConcurrentPointQuadTree
height
- The height of the ConcurrentPointQuadTree
public ConcurrentPointQuadTree(float minimumQuadWidth, float minimumQuadHeight, int elementLimitPerQuad, int mergeWatermark, float x, float y, float width, float height)
ConcurrentPointQuadTree
with a specified minimum
quad size, element limit and watermarkminimumQuadWidth
- The minimum width of quads. Quads will not subdivide smaller
than this width.minimumQuadHeight
- The minimum height of quads. Quads will not subdivide smaller
than this height.elementLimitPerQuad
- The maximum number of elements in a quad before it is split
into 4 child ConcurrentPointQuadTree
smergeWatermark
- When a parent ConcurrentPointQuadTree
's total elements
go lower than this mark, the child
ConcurrentPointQuadTree
s will be merged back togetherx
- The x coordinate of the ConcurrentPointQuadTree
y
- The y coordiante of the ConcurrentPointQuadTree
width
- The width of the ConcurrentPointQuadTree
height
- The height of the ConcurrentPointQuadTree
public void debugRender(Graphics g)
debugRender
in interface QuadTree<T extends Positionable>
public void addAll(java.util.List<T> elementsToAdd)
addAll
in interface QuadTree<T extends Positionable>
public boolean add(T element)
add
in interface QuadTree<T extends Positionable>
protected boolean addElement(T element)
protected boolean addElementToChild(T element)
protected void subdivide()
protected boolean isMergable()
protected void merge()
public void removeAll(java.util.List<T> elementsToRemove)
removeAll
in interface QuadTree<T extends Positionable>
public boolean remove(T element)
remove
in interface QuadTree<T extends Positionable>
protected boolean removeElementFromChild(T element)
protected boolean removeElement(T element, boolean topDownInvocation)
public java.util.List<T> getElementsWithinArea(Shape area)
getElementsWithinArea
in interface QuadTree<T extends Positionable>
public void getElementsWithinArea(java.util.Collection<T> result, Shape area)
getElementsWithinArea
in interface QuadTree<T extends Positionable>
public java.util.List<T> getElementsContainingPoint(Point point)
getElementsContainingPoint
in interface QuadTree<T extends Positionable>
public void getElementsContainingPoint(java.util.Collection<T> result, Point point)
getElementsContainingPoint
in interface QuadTree<T extends Positionable>
public java.util.List<T> getElementsIntersectingLineSegment(LineSegment lineSegment)
getElementsIntersectingLineSegment
in interface QuadTree<T extends Positionable>
public void getElementsIntersectingLineSegment(java.util.Collection<T> result, LineSegment lineSegment)
getElementsIntersectingLineSegment
in interface QuadTree<T extends Positionable>
public java.util.List<T> getElements()
getElements
in interface QuadTree<T extends Positionable>
public void getElements(java.util.List<T> result)
getElements
in interface QuadTree<T extends Positionable>
public int getTotalQuads()
getTotalQuads
in interface QuadTree<T extends Positionable>
public int getTotalElements()
getTotalElements
in interface QuadTree<T extends Positionable>
protected void clearTotalElementsCache()
public void positionChanged(T moved)
positionChanged
in interface PositionChangeListener<T extends Positionable>
public QuadTree<T> getParent()
getParent
in interface QuadTree<T extends Positionable>
public int getTotalMergeOperations()
public int getElementLimitPerQuad()
public int getMergeWatermark()
public float getMinimumQuadWidth()
getMinimumQuadWidth
in interface QuadTree<T extends Positionable>
public float getMinimumQuadHeight()
getMinimumQuadHeight
in interface QuadTree<T extends Positionable>