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-2019 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

    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.

    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.lang.Iterable

    forEach

    Methods inherited from interface java.util.Set

    equals, hashCode, spliterator
  • Constructor Details

    • 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; the add method will return false, indicating that the set has not been modified.)
      Parameters:
      boundingBox - Rectangle2D; the region
      minimumCellSize - 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 interface java.util.Collection<OTSShape>
      Specified by:
      size in interface java.util.Set<OTSShape>
    • isEmpty

      public final boolean isEmpty()
      Specified by:
      isEmpty in interface java.util.Collection<OTSShape>
      Specified by:
      isEmpty in interface java.util.Set<OTSShape>
    • contains

      public final boolean contains​(java.lang.Object o)
      Specified by:
      contains in interface java.util.Collection<OTSShape>
      Specified by:
      contains in interface java.util.Set<OTSShape>
    • iterator

      public final java.util.Iterator<OTSShape> iterator()
      Specified by:
      iterator in interface java.util.Collection<OTSShape>
      Specified by:
      iterator in interface java.lang.Iterable<OTSShape>
      Specified by:
      iterator in interface java.util.Set<OTSShape>
    • toArray

      public final java.lang.Object[] toArray()
      Specified by:
      toArray in interface java.util.Collection<OTSShape>
      Specified by:
      toArray in interface java.util.Set<OTSShape>
    • toArray

      public final <T> T[] toArray​(T[] a)
      Specified by:
      toArray in interface java.util.Collection<OTSShape>
      Specified by:
      toArray in interface java.util.Set<OTSShape>
    • add

      public final boolean add​(OTSShape e)
      Specified by:
      add in interface java.util.Collection<OTSShape>
      Specified by:
      add in interface java.util.Set<OTSShape>
    • remove

      public final boolean remove​(java.lang.Object o)
      Specified by:
      remove in interface java.util.Collection<OTSShape>
      Specified by:
      remove in interface java.util.Set<OTSShape>
    • containsAll

      public final boolean containsAll​(java.util.Collection<?> c)
      Specified by:
      containsAll in interface java.util.Collection<OTSShape>
      Specified by:
      containsAll in interface java.util.Set<OTSShape>
    • addAll

      public final boolean addAll​(java.util.Collection<? extends OTSShape> c)
      Specified by:
      addAll in interface java.util.Collection<OTSShape>
      Specified by:
      addAll in interface java.util.Set<OTSShape>
    • retainAll

      public final boolean retainAll​(java.util.Collection<?> c)
      Specified by:
      retainAll in interface java.util.Collection<OTSShape>
      Specified by:
      retainAll in interface java.util.Set<OTSShape>
    • removeAll

      public final boolean removeAll​(java.util.Collection<?> c)
      Specified by:
      removeAll in interface java.util.Collection<OTSShape>
      Specified by:
      removeAll in interface java.util.Set<OTSShape>
    • clear

      public final void clear()
      Specified by:
      clear in interface java.util.Collection<OTSShape>
      Specified by:
      clear in interface java.util.Set<OTSShape>
    • 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 class java.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