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>
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).
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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
Iterator for quad tree.(package private) class
Spatial-aware storage for a set of OtsShape objects. -
Constructor Summary
ConstructorsConstructorDescriptionOts2dSet
(Rectangle2D boundingBox, double minimumCellSize) Construct an empty Ots2dSet for a rectangular region. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
final boolean
addAll
(Collection<? extends OtsShape> c) final void
clear()
final boolean
final boolean
containsAll
(Collection<?> c) intersectingShapes
(Rectangle2D rectangle) Return the set of all shapes in this Ots2dSet that intersect the given rectangle.intersectingShapes
(OtsShape shape) Return all OtsShapes in this Ots2dSet that intersect a given OtsShape.final boolean
isEmpty()
iterator()
final boolean
final boolean
removeAll
(Collection<?> c) final boolean
retainAll
(Collection<?> c) final int
size()
final Object[]
toArray()
final <T> T[]
toArray
(T[] a) final String
toString()
(package private) final String
toString
(int recursionDepth) Recursively print this Ots2dSet.final 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 Details
-
Ots2dSet
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 Details
-
size
public final int size() -
isEmpty
public final boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public final <T> T[] toArray(T[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAll
in interfaceCollection<OtsShape>
- Specified by:
containsAll
in interfaceSet<OtsShape>
-
addAll
-
retainAll
-
removeAll
-
clear
public final void clear() -
intersectingShapes
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
Recursively print this Ots2dSet.- Parameters:
recursionDepth
- int; maximum depth to recurse- Returns:
- String
-
toString
-
intersectingShapes
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
Return an ASCII art rendering of this Ots2dSet.- Parameters:
recursionDepth
- int; maximum recursion depth- Returns:
- String; a somewhat human readable rendering of this Ots2dSet
-