Class OTSShape

java.lang.Object
org.opentrafficsim.core.geometry.OTSLine3D
org.opentrafficsim.core.geometry.OTSShape
All Implemented Interfaces:
java.io.Serializable, Locatable

public class OTSShape
extends OTSLine3D

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.

$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Mar 31, 2016
Author:
Alexander Verbraeck, Peter Knoppers
See Also:
Serialized Form
  • Constructor Details

    • OTSShape

      public OTSShape​(OTSPoint3D... points) throws OTSGeometryException
      Construct a new OTSShape (closed shape).
      Parameters:
      points - OTSPoint3D...; the array of points to construct this OTSLine3D from.
      Throws:
      OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
    • OTSShape

      public OTSShape​(org.locationtech.jts.geom.Coordinate[] coordinates) throws OTSGeometryException
      Construct a new OTSShape (closed shape) from an array of Coordinate.
      Parameters:
      coordinates - Coordinate[]; the array of coordinates to construct this OTSLine3D from
      Throws:
      OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
    • OTSShape

      public OTSShape​(org.locationtech.jts.geom.LineString lineString) throws OTSGeometryException
      Construct a new OTSShape (closed shape) from a LineString.
      Parameters:
      lineString - LineString; the lineString to construct this OTSLine3D from.
      Throws:
      OTSGeometryException - when the provided LineString does not constitute a valid line (too few points or identical adjacent points)
    • OTSShape

      public OTSShape​(org.locationtech.jts.geom.Geometry geometry) throws OTSGeometryException
      Construct a new OTSShape (closed shape) from a Geometry.
      Parameters:
      geometry - Geometry; the geometry to construct this OTSLine3D from
      Throws:
      OTSGeometryException - when the provided Geometry do not constitute a valid line (too few points or identical adjacent points)
    • OTSShape

      public OTSShape​(java.util.List<OTSPoint3D> pointList) throws OTSGeometryException
      Construct a new OTSShape (closed shape) from a List<OTSPoint3D>.
      Parameters:
      pointList - List<OTSPoint3D>; the list of points to construct this OTSLine3D from.
      Throws:
      OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
    • OTSShape

      public OTSShape​(java.awt.geom.Path2D path) throws OTSGeometryException
      Construct a new OTSShape (closed shape) from a Path2D.
      Parameters:
      path - Path2D; the Path2D to construct this OTSLine3D from.
      Throws:
      OTSGeometryException - when the provided points do not constitute a valid line (too few points or identical adjacent points)
  • Method Details

    • getShape

      public final java.awt.geom.Path2D getShape()
      Returns:
      shape
    • contains

      public final boolean contains​(OTSPoint3D point)
      Parameters:
      point - OTSPoint3D; the point to check if it is inside the shape
      Returns:
      whether the point is inside the shape
    • contains

      public final boolean contains​(java.awt.geom.Rectangle2D rectangle)
      Check if this OTSShape completely covers a rectangular region.
      Parameters:
      rectangle - Rectangle2D; the rectangular region
      Returns:
      boolean; true if this OTSShape completely covers the region; false otherwise (or when the implementation of java.awt.geom.Path2D.contains found it prohibitively expensive to decide. Let us hope that this cannot happen with OTSShape objects. Peter has been unable to find out when this might happen.
    • intersects

      public final boolean intersects​(OTSShape otsShape)
      Parameters:
      otsShape - OTSShape; the shape to test the intersection with
      Returns:
      whether the shapes intersect or whether one shape contains the other
    • createAndCleanOTSShape

      public static OTSShape createAndCleanOTSShape​(OTSPoint3D[] points) throws OTSGeometryException
      Create an OTSLine3D, while cleaning repeating successive points.
      Parameters:
      points - OTSPoint3D[]; the coordinates of the line as OTSPoint3D
      Returns:
      the line
      Throws:
      OTSGeometryException - when number of points < 2
    • createAndCleanOTSShape

      public static OTSShape createAndCleanOTSShape​(java.util.List<OTSPoint3D> pointList) throws OTSGeometryException
      Create an OTSLine3D, while cleaning repeating successive points.
      Parameters:
      pointList - List<OTSPoint3D>; list of the coordinates of the line as OTSPoint3D; any duplicate points in this list are removed (this method may modify the provided list)
      Returns:
      OTSLine3D; the line
      Throws:
      OTSGeometryException - when number of non-equal points < 2
    • main

      public static void main​(java.lang.String[] args) throws OTSGeometryException
      Small test.
      Parameters:
      args - String[]; empty
      Throws:
      OTSGeometryException - when construction fails
    • toString

      public final java.lang.String toString()
      Overrides:
      toString in class OTSLine3D