
E - public final class FlexibleQuadTree<E> extends Object implements SpatialIndex<E>
| Modifier and Type | Class and Description |
|---|---|
private static class |
FlexibleQuadTree.Child |
private static class |
FlexibleQuadTree.QuadTreeEntry<E> |
private static class |
FlexibleQuadTree.Rectangle2D |
| Modifier and Type | Field and Description |
|---|---|
private FlexibleQuadTree.Rectangle2D |
bounds |
private List<com.google.common.base.Optional<FlexibleQuadTree<E>>> |
children |
private boolean |
childrenCreated |
static int |
DEFAULT_CAPACITY
Default maximum number of entries per node.
|
private Deque<FlexibleQuadTree.QuadTreeEntry<E>> |
elements |
private int |
maxElements |
private FlexibleQuadTree<E> |
parent |
private FlexibleQuadTree<E> |
root
root is NOT consistent everywhere.
|
private static long |
serialVersionUID |
| Modifier | Constructor and Description |
|---|---|
|
FlexibleQuadTree()
Builds a
FlexibleQuadTree with the default node capacity. |
private |
FlexibleQuadTree(double minx,
double maxx,
double miny,
double maxy,
int elemPerQuad,
FlexibleQuadTree<E> rootNode,
FlexibleQuadTree<E> parentNode) |
|
FlexibleQuadTree(int elemPerQuad) |
| Modifier and Type | Method and Description |
|---|---|
private double |
centerX() |
private double |
centerY() |
private boolean |
contains(double x,
double y) |
private FlexibleQuadTree<E> |
create(double minx,
double maxx,
double miny,
double maxy,
FlexibleQuadTree<E> father) |
private void |
createChildIfAbsent(FlexibleQuadTree.Child c) |
private void |
createParent(double x,
double y) |
private FlexibleQuadTree<E> |
getChild(FlexibleQuadTree.Child c) |
int |
getDimensions() |
int |
getMaxElementsNumber() |
private boolean |
hasChildren() |
private boolean |
hasSpace() |
void |
insert(E e,
double... pos)
Inserts an element in the
SpatialIndex. |
void |
insert(E e,
double x,
double y)
Same of
insert(Object, double...), but with explicit parameters. |
private void |
insertHere(E e,
double x,
double y) |
private void |
insertNode(E e,
double x,
double y) |
private double |
maxX() |
private double |
maxX(FlexibleQuadTree.Child c) |
private double |
maxY() |
private double |
maxY(FlexibleQuadTree.Child c) |
private double |
minX() |
private double |
minX(FlexibleQuadTree.Child c) |
private double |
minY() |
private double |
minY(FlexibleQuadTree.Child c) |
boolean |
move(E e,
double[] start,
double[] end)
If an element is moved, updates the
SpatialIndex accordingly. |
boolean |
move(E e,
double sx,
double sy,
double fx,
double fy)
Same of
move(Object, double[], double[]), but with explicit
parameters. |
private boolean |
moveFromNode(FlexibleQuadTree<E> root,
E e,
double sx,
double sy,
double fx,
double fy) |
List<E> |
query(double[]... space)
Queries the
SpatialIndex, searching for elements in a
parallelotope. |
List<E> |
query(double x1,
double y1,
double x2,
double y2)
Same of
#query(double...), but with explicit parameters. |
private void |
query(double sx,
double sy,
double fx,
double fy,
List<E> results) |
boolean |
remove(E e,
double... pos)
Deletes an element from the
SpatialIndex. |
boolean |
remove(E e,
double x,
double y)
Same of
remove(Object, double...) with explicit parameters. |
private boolean |
removeHere(E e,
double x,
double y) |
private boolean |
removeInChildren(E e,
double x,
double y) |
private FlexibleQuadTree<E> |
selectChild(double x,
double y) |
private void |
setChild(FlexibleQuadTree.Child c,
FlexibleQuadTree<E> child) |
private void |
subdivide() |
private boolean |
swapMostStatic(E e,
double fx,
double fy) |
String |
toString() |
private static final long serialVersionUID
public static final int DEFAULT_CAPACITY
private final FlexibleQuadTree.Rectangle2D bounds
private final Deque<FlexibleQuadTree.QuadTreeEntry<E>> elements
private final int maxElements
private final List<com.google.common.base.Optional<FlexibleQuadTree<E>>> children
private FlexibleQuadTree<E> root
private FlexibleQuadTree<E> parent
private boolean childrenCreated
public FlexibleQuadTree()
FlexibleQuadTree with the default node capacity.private FlexibleQuadTree(double minx,
double maxx,
double miny,
double maxy,
int elemPerQuad,
FlexibleQuadTree<E> rootNode,
FlexibleQuadTree<E> parentNode)
public FlexibleQuadTree(int elemPerQuad)
elemPerQuad - maximum number of elements per quadprivate boolean moveFromNode(FlexibleQuadTree<E> root, E e, double sx, double sy, double fx, double fy)
private double centerX()
private double centerY()
private boolean contains(double x,
double y)
private FlexibleQuadTree<E> create(double minx, double maxx, double miny, double maxy, FlexibleQuadTree<E> father)
private void createChildIfAbsent(FlexibleQuadTree.Child c)
private void createParent(double x,
double y)
private FlexibleQuadTree<E> getChild(FlexibleQuadTree.Child c)
public int getDimensions()
getDimensions in interface SpatialIndex<E>SpatialIndex.public int getMaxElementsNumber()
private boolean hasChildren()
private boolean hasSpace()
public void insert(E e, double... pos)
SpatialIndexSpatialIndex.insert in interface SpatialIndex<E>e - The element to addpos - the coordinates where the element should be addedpublic void insert(E e, double x, double y)
insert(Object, double...), but with explicit parameters.e - elementx - Xy - Yprivate void insertHere(E e, double x, double y)
private void insertNode(E e, double x, double y)
private double maxX()
private double maxX(FlexibleQuadTree.Child c)
private double maxY()
private double maxY(FlexibleQuadTree.Child c)
private double minX()
private double minX(FlexibleQuadTree.Child c)
private double minY()
private double minY(FlexibleQuadTree.Child c)
public boolean move(E e, double[] start, double[] end)
SpatialIndexSpatialIndex accordingly.move in interface SpatialIndex<E>e - The element to addstart - the coordinates where the element is currently locatedend - the coordinates where the element is should be movedpublic boolean move(E e, double sx, double sy, double fx, double fy)
move(Object, double[], double[]), but with explicit
parameters.e - the elementsx - the start xsy - the start yfx - the final xfy - the final ypublic List<E> query(double[]... space)
SpatialIndexSpatialIndex, searching for elements in a
parallelotope. "Parallelotope" is a fancy word for
"N-dimensional rectangle". A 2-parallelotope is in fact a rectangle, a
3-parallelotope is a parallelepiped, and so on.query in interface SpatialIndex<E>space - the space where to search for elementsSpatialIndex.public List<E> query(double x1, double y1, double x2, double y2)
#query(double...), but with explicit parameters.x1 - Rectangle X coordinate of the first pointy1 - Rectangle Y coordinate of the first pointx2 - Rectangle X coordinate of the second pointy2 - Rectangle Y coordinate of the second pointList of Objects in range.public boolean remove(E e, double... pos)
SpatialIndexSpatialIndex.remove in interface SpatialIndex<E>e - The element to addpos - the coordinates where the element should be addedpublic boolean remove(E e, double x, double y)
remove(Object, double...) with explicit parameters.e - Element to removex - X position of the elementy - Y position of the elementprivate boolean removeHere(E e, double x, double y)
private boolean removeInChildren(E e, double x, double y)
private FlexibleQuadTree<E> selectChild(double x, double y)
private void setChild(FlexibleQuadTree.Child c, FlexibleQuadTree<E> child)
private void subdivide()
private boolean swapMostStatic(E e, double fx, double fy)