Package org.opentrafficsim.core.geometry
Class OTS2DSet
- java.lang.Object
-
- org.opentrafficsim.core.geometry.OTS2DSet
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<OTSShape>
,java.util.Collection<OTSShape>
,java.util.Set<OTSShape>
public class OTS2DSet extends java.lang.Object implements java.util.Set<OTSShape>, java.io.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-2020 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
-
-
Constructor Summary
Constructors Constructor Description OTS2DSet(java.awt.geom.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(java.util.Collection<? extends OTSShape> c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
java.util.Set<OTSShape>
intersectingShapes(java.awt.geom.Rectangle2D rectangle)
Return the set of all shapes in this OTS2DSet that intersect the given rectangle.java.util.Set<OTSShape>
intersectingShapes(OTSShape shape)
Return all OTSShapes in this OTS2DSet that intersect a given OTSShape.boolean
isEmpty()
java.util.Iterator<OTSShape>
iterator()
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
int
size()
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
java.lang.String
toString()
java.lang.String
toStringGraphic(int recursionDepth)
Return an ASCII art rendering of this OTS2DSet.
-
-
-
Constructor Detail
-
OTS2DSet
public OTS2DSet(java.awt.geom.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(java.lang.Object o)
-
iterator
public final java.util.Iterator<OTSShape> iterator()
-
toArray
public final java.lang.Object[] toArray()
-
toArray
public final <T> T[] toArray(T[] a)
-
add
public final boolean add(OTSShape e)
-
remove
public final boolean remove(java.lang.Object o)
-
containsAll
public final boolean containsAll(java.util.Collection<?> c)
-
addAll
public final boolean addAll(java.util.Collection<? extends OTSShape> c)
-
retainAll
public final boolean retainAll(java.util.Collection<?> c)
-
removeAll
public final boolean removeAll(java.util.Collection<?> c)
-
clear
public final void clear()
-
intersectingShapes
public final java.util.Set<OTSShape> intersectingShapes(java.awt.geom.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
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
intersectingShapes
public final java.util.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 java.lang.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
-
-