Package org.opentrafficsim.core.geometry
Class Ots2dSet
java.lang.Object
org.opentrafficsim.core.geometry.Ots2dSet
- All Implemented Interfaces:
Serializable,Iterable<org.djutils.draw.line.Polygon2d>,Collection<org.djutils.draw.line.Polygon2d>,Set<org.djutils.draw.line.Polygon2d>
Set of Polygon2d objects and provides methods for fast selection of those objects that intersect a Polygon2d.
An Ots2dSet internally stores the Polygon2ds 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 Polygon2d. 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. Polygon2ds that partially cover a non-leaf node are stored in each of the leaf nodes below that node that those Polygon2ds (partially) cover. Leaf nodes that cannot be expanded (because they are too small) also store all Polygon2ds that partially cover the area of the node.
If removal of a Polygon2d 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 Polygon2ds 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 Polygon2d. 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. Polygon2ds that partially cover a non-leaf node are stored in each of the leaf nodes below that node that those Polygon2ds (partially) cover. Leaf nodes that cannot be expanded (because they are too small) also store all Polygon2ds that partially cover the area of the node.
If removal of a Polygon2d 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-2024 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) classIterator for quad tree.(package private) classSpatial-aware storage for a set of Polygon2d objects. -
Constructor Summary
ConstructorsConstructorDescriptionOts2dSet(org.djutils.draw.bounds.Bounds2d boundingBox, double minimumCellSize) Construct an empty Ots2dSet for a rectangular region. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanadd(org.djutils.draw.line.Polygon2d e) final booleanaddAll(Collection<? extends org.djutils.draw.line.Polygon2d> c) final voidclear()final booleanfinal booleancontainsAll(Collection<?> c) final Set<org.djutils.draw.line.Polygon2d>intersectingShapes(org.djutils.draw.bounds.Bounds2d rectangle) Return the set of all shapes in this Ots2dSet that intersect the given rectangle.final Set<org.djutils.draw.line.Polygon2d>intersectingShapes(org.djutils.draw.line.Polygon2d shape) Return all Polygon2ds in this Ots2dSet that intersect a given Polygon2d.final booleanisEmpty()final Iterator<org.djutils.draw.line.Polygon2d>iterator()final booleanfinal booleanremoveAll(Collection<?> c) final booleanretainAll(Collection<?> c) final intsize()final Object[]toArray()final <T> T[]toArray(T[] a) final StringtoString()(package private) final StringtoString(int recursionDepth) Recursively print this Ots2dSet.final StringtoStringGraphic(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, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Constructor Details
-
Ots2dSet
public Ots2dSet(org.djutils.draw.bounds.Bounds2d boundingBox, double minimumCellSize) throws IllegalArgumentException 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 a Polygon2d is not an error; theaddmethod will return false, indicating that the set has not been modified.)- Parameters:
boundingBox- the regionminimumCellSize- resolution of the underlying quad tree- Throws:
IllegalArgumentException- when the bounding box covers no surface or the minimum cell size is not above zero
-
-
Method Details
-
size
public final int size()- Specified by:
sizein interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
sizein interfaceSet<org.djutils.draw.line.Polygon2d>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
isEmptyin interfaceSet<org.djutils.draw.line.Polygon2d>
-
contains
- Specified by:
containsin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
containsin interfaceSet<org.djutils.draw.line.Polygon2d>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
toArrayin interfaceSet<org.djutils.draw.line.Polygon2d>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
toArrayin interfaceSet<org.djutils.draw.line.Polygon2d>
-
add
public final boolean add(org.djutils.draw.line.Polygon2d e) - Specified by:
addin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
addin interfaceSet<org.djutils.draw.line.Polygon2d>
-
remove
- Specified by:
removein interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
removein interfaceSet<org.djutils.draw.line.Polygon2d>
-
containsAll
- Specified by:
containsAllin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
containsAllin interfaceSet<org.djutils.draw.line.Polygon2d>
-
addAll
- Specified by:
addAllin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
addAllin interfaceSet<org.djutils.draw.line.Polygon2d>
-
retainAll
- Specified by:
retainAllin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
retainAllin interfaceSet<org.djutils.draw.line.Polygon2d>
-
removeAll
- Specified by:
removeAllin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
removeAllin interfaceSet<org.djutils.draw.line.Polygon2d>
-
clear
public final void clear()- Specified by:
clearin interfaceCollection<org.djutils.draw.line.Polygon2d>- Specified by:
clearin interfaceSet<org.djutils.draw.line.Polygon2d>
-
intersectingShapes
public final Set<org.djutils.draw.line.Polygon2d> intersectingShapes(org.djutils.draw.bounds.Bounds2d rectangle) Return the set of all shapes in this Ots2dSet that intersect the given rectangle.- Parameters:
rectangle- the rectangle- Returns:
- the shapes that intersect the rectangle
-
toString
Recursively print this Ots2dSet.- Parameters:
recursionDepth- maximum depth to recurse- Returns:
- String
-
toString
-
intersectingShapes
public final Set<org.djutils.draw.line.Polygon2d> intersectingShapes(org.djutils.draw.line.Polygon2d shape) Return all Polygon2ds in this Ots2dSet that intersect a given Polygon2d.- Parameters:
shape- the given Polygon2d- Returns:
- all Polygon2ds in this Ots2dSet that intersect
shape
-
toStringGraphic
Return an ASCII art rendering of this Ots2dSet.- Parameters:
recursionDepth- maximum recursion depth- Returns:
- a somewhat human readable rendering of this Ots2dSet
-