Package org.opentrafficsim.core.geometry
Class OTS2DSet
- java.lang.Object
-
- org.opentrafficsim.core.geometry.OTS2DSet
-
- All Implemented Interfaces:
Serializable
,Iterable<OTSShape>
,Collection<OTSShape>
,Set<OTSShape>
public class OTS2DSet extends Object implements Set<OTSShape>, Serializable
Set of OTSShape objects and provides methods for fast selection of those objects that intersect an OTSShape.
An OTS2DSet internally stores the OTSShapes in a quad tree. At time of construction the minimum cell size is defined. Node expansion is never performed on nodes that are smaller than this limit.
Each node (even the non-leaf nodes) store a set of OTSShape. Non-leaf nodes locally store those shapes that completely cover the rectangular area of the node. Such shapes are not also stored in leaf nodes below that node. OTSShapes that partially cover a non-leaf node are stored in each of the leaf nodes below that node that those OTSShapes (partially) cover. Leaf nodes that cannot be expanded (because they are too small) also store all OTSShapes that partially cover the area of the node.
If removal of an OTSShape objects results in a leaf becoming empty, that leaf is removed from its parent (which may then itself become empty and removed in turn).Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Jun 20, 2016
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
OTS2DSet.QuadTreeIterator
Iterator for quad tree.(package private) class
OTS2DSet.QuadTreeNode
Spatial-aware storage for a set of OTSShape objects.
-
Constructor Summary
Constructors Constructor Description OTS2DSet(Rectangle2D boundingBox, double minimumCellSize)
Construct an empty OTS2DSet for a rectangular region.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(OTSShape e)
boolean
addAll(Collection<? extends OTSShape> c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
Set<OTSShape>
intersectingShapes(Rectangle2D rectangle)
Return the set of all shapes in this OTS2DSet that intersect the given rectangle.Set<OTSShape>
intersectingShapes(OTSShape shape)
Return all OTSShapes in this OTS2DSet that intersect a given OTSShape.boolean
isEmpty()
Iterator<OTSShape>
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
String
toString()
(package private) String
toString(int recursionDepth)
Recursively print this OTS2DSet.String
toStringGraphic(int recursionDepth)
Return an ASCII art rendering of this OTS2DSet.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
-
-
-
Constructor Detail
-
OTS2DSet
public OTS2DSet(Rectangle2D boundingBox, double minimumCellSize) throws OTSGeometryException
Construct an empty OTS2DSet for a rectangular region. Objects that do not intersect this region will never be stored in this OTS2DSet. (Trying to add such an OTSShape is not an error; theadd
method will return false, indicating that the set has not been modified.)- Parameters:
boundingBox
- Rectangle2D; the regionminimumCellSize
- double; resolution of the underlying quad tree- Throws:
OTSGeometryException
- when the bounding box covers no surface
-
-
Method Detail
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
contains
public final boolean contains(Object o)
-
toArray
public final Object[] toArray()
-
toArray
public final <T> T[] toArray(T[] a)
-
add
public final boolean add(OTSShape e)
-
remove
public final boolean remove(Object o)
-
containsAll
public final boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<OTSShape>
- Specified by:
containsAll
in interfaceSet<OTSShape>
-
addAll
public final boolean addAll(Collection<? extends OTSShape> c)
-
retainAll
public final boolean retainAll(Collection<?> c)
-
removeAll
public final boolean removeAll(Collection<?> c)
-
clear
public final void clear()
-
intersectingShapes
public final Set<OTSShape> intersectingShapes(Rectangle2D rectangle)
Return the set of all shapes in this OTS2DSet that intersect the given rectangle.- Parameters:
rectangle
- Rectangle2D; the rectangle- Returns:
- Set<OTSShape>; the shapes that intersect the rectangle
-
toString
final String toString(int recursionDepth)
Recursively print this OTS2DSet.- Parameters:
recursionDepth
- int; maximum depth to recurse- Returns:
- String
-
intersectingShapes
public final Set<OTSShape> intersectingShapes(OTSShape shape)
Return all OTSShapes in this OTS2DSet that intersect a given OTSShape.- Parameters:
shape
- OTSShape; the given OTSShape- Returns:
- Set<OTSShape>; all OTSShapes in this OTS2DSet that intersect
shape
-
toStringGraphic
public final String toStringGraphic(int recursionDepth)
Return an ASCII art rendering of this OTS2DSet.- Parameters:
recursionDepth
- int; maximum recursion depth- Returns:
- String; a somewhat human readable rendering of this OTS2DSet
-
-