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
Modifier and TypeClassDescription(package private) class
Iterator for quad tree.(package private) class
Spatial-aware storage for a set of Polygon2d objects. -
Constructor Summary
ConstructorDescriptionOts2dSet
(org.djutils.draw.bounds.Bounds2d boundingBox, double minimumCellSize) Construct an empty Ots2dSet for a rectangular region. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
add
(org.djutils.draw.line.Polygon2d e) final boolean
addAll
(Collection<? extends org.djutils.draw.line.Polygon2d> c) final void
clear()
final boolean
final boolean
containsAll
(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 boolean
isEmpty()
final Iterator<org.djutils.draw.line.Polygon2d>
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
public Ots2dSet(org.djutils.draw.bounds.Bounds2d 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 a Polygon2d 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()- Specified by:
size
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
size
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
isEmpty
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
contains
- Specified by:
contains
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
contains
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
toArray
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
toArray
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
add
public final boolean add(org.djutils.draw.line.Polygon2d e) - Specified by:
add
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
add
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
remove
- Specified by:
remove
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
remove
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
containsAll
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
addAll
- Specified by:
addAll
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
addAll
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
retainAll
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
removeAll
in interfaceSet<org.djutils.draw.line.Polygon2d>
-
clear
public final void clear()- Specified by:
clear
in interfaceCollection<org.djutils.draw.line.Polygon2d>
- Specified by:
clear
in 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
- Rectangle2D; the rectangle- Returns:
- Set<Polygon2d>; the shapes that intersect the rectangle
-
toString
Recursively print this Ots2dSet.- Parameters:
recursionDepth
- int; 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
- Polygon2d; the given Polygon2d- Returns:
- Set<Polygon2d>; all Polygon2ds 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
-