Package org.opentrafficsim.core.geometry
Class Ots2dSet
java.lang.Object
org.opentrafficsim.core.geometry.Ots2dSet
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal booleanaddAll(Collection<? extends Polygon2d> c) final voidclear()final booleanfinal booleancontainsAll(Collection<?> c) intersectingShapes(Bounds2d rectangle) Return the set of all shapes in this Ots2dSet that intersect the given rectangle.intersectingShapes(Polygon2d shape) Return all Polygon2ds in this Ots2dSet that intersect a given Polygon2d.final booleanisEmpty()iterator()final booleanfinal booleanremoveAll(Collection<?> c) final booleanretainAll(Collection<?> c) final intsize()final Object[]toArray()final <T> T[]toArray(T[] a) final StringtoString()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
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() -
isEmpty
public final boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public final <T> T[] toArray(T[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<Polygon2d>- Specified by:
containsAllin interfaceSet<Polygon2d>
-
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- the rectangle- Returns:
- the shapes that intersect the rectangle
-
toString
-
intersectingShapes
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
-