View Javadoc
1   package org.opentrafficsim.core.network.point2d;
2   
3   import java.awt.geom.Point2D;
4   import java.rmi.RemoteException;
5   
6   import javax.media.j3d.Bounds;
7   import javax.vecmath.Point3d;
8   
9   import nl.tudelft.simulation.language.d3.BoundingBox;
10  import nl.tudelft.simulation.language.d3.DirectedPoint;
11  
12  import org.opentrafficsim.core.network.AbstractLink;
13  import org.opentrafficsim.core.unit.FrequencyUnit;
14  import org.opentrafficsim.core.unit.LengthUnit;
15  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
16  
17  /**
18   * <p>
19   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
21   * <p>
22   * @version Jan 4, 2015 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @param <IDL> the ID type of the Link, e.g., String or Integer.
26   * @param <IDN> the ID type of the Node, e.g., String or Integer.
27   */
28  public class LinkPoint2D<IDL, IDN> extends AbstractLink<IDL, IDN, Point2D, NodePoint2D<IDN>>
29  {
30      /** */
31      private static final long serialVersionUID = 20150104L;
32  
33      /**
34       * Construct a new link.
35       * @param id the link id
36       * @param startNode start node (directional)
37       * @param endNode end node (directional)
38       * @param length link length in a length unit
39       * @param capacity link capacity in GTUs per hour
40       */
41      public LinkPoint2D(final IDL id, final NodePoint2D<IDN> startNode, final NodePoint2D<IDN> endNode,
42          final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
43      {
44          super(id, startNode, endNode, length, capacity);
45      }
46  
47      /**
48       * Construct a new link with infinite capacity.
49       * @param id the link id
50       * @param startNode start node (directional)
51       * @param endNode end node (directional)
52       * @param length link length in a length unit
53       */
54      public LinkPoint2D(final IDL id, final NodePoint2D<IDN> startNode, final NodePoint2D<IDN> endNode,
55          final DoubleScalar.Rel<LengthUnit> length)
56      {
57          super(id, startNode, endNode, length);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public final DirectedPoint getLocation() throws RemoteException
63      {
64          double x = (getEndNode().getX() - getStartNode().getX()) / 2.0;
65          double y = (getEndNode().getY() - getStartNode().getY()) / 2.0;
66          return new DirectedPoint(new double[] {x, y, 0.0d});
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public final Bounds getBounds() throws RemoteException
72      {
73          DirectedPoint c = getLocation();
74          double minX = Math.min(getEndNode().getX(), getStartNode().getX());
75          double minY = Math.min(getEndNode().getY(), getStartNode().getY());
76          double maxX = Math.max(getEndNode().getX(), getStartNode().getX());
77          double maxY = Math.max(getEndNode().getY(), getStartNode().getY());
78          return new BoundingBox(new Point3d(minX - c.x, minY - c.y, 0.0d), new Point3d(maxX - c.x, maxY - c.y, 0.0d));
79      }
80  
81      /**
82       * String ID implementation of the Point2D link.
83       * <p>
84       * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
85       * All rights reserved. <br>
86       * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
87       * <p>
88       * @version Jan 4, 2015 <br>
89       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
90       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
91       */
92      public static class STR extends LinkPoint2D<String, String>
93      {
94          /** */
95          private static final long serialVersionUID = 20150104L;
96  
97          /**
98           * Construct a new link.
99           * @param id the link id
100          * @param startNode start node (directional)
101          * @param endNode end node (directional)
102          * @param length link length in a length unit
103          * @param capacity link capacity in GTUs per hour
104          */
105         public STR(final String id, final NodePoint2D.STR startNode, final NodePoint2D.STR endNode,
106             final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
107         {
108             super(id, startNode, endNode, length, capacity);
109         }
110 
111         /**
112          * Construct a new link with infinite capacity.
113          * @param id the link id
114          * @param startNode start node (directional)
115          * @param endNode end node (directional)
116          * @param length link length in a length unit
117          */
118         public STR(final String id, final NodePoint2D.STR startNode, final NodePoint2D.STR endNode,
119             final DoubleScalar.Rel<LengthUnit> length)
120         {
121             super(id, startNode, endNode, length);
122         }
123     }
124 
125     /**
126      * Integer ID implementation of the Point2D link.
127      * <p>
128      * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
129      * All rights reserved. <br>
130      * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
131      * <p>
132      * @version Jan 4, 2015 <br>
133      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
134      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
135      */
136     public static class INT extends LinkPoint2D<Integer, Integer>
137     {
138         /** */
139         private static final long serialVersionUID = 20150104L;
140 
141         /**
142          * Construct a new link.
143          * @param id the link id
144          * @param startNode start node (directional)
145          * @param endNode end node (directional)
146          * @param length link length in a length unit
147          * @param capacity link capacity in GTUs per hour
148          */
149         public INT(final int id, final NodePoint2D.INT startNode, final NodePoint2D.INT endNode,
150             final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
151         {
152             super(id, startNode, endNode, length, capacity);
153         }
154 
155         /**
156          * Construct a new link with infinite capacity.
157          * @param id the link id
158          * @param startNode start node (directional)
159          * @param endNode end node (directional)
160          * @param length link length in a length unit
161          */
162         public INT(final int id, final NodePoint2D.INT startNode, final NodePoint2D.INT endNode,
163             final DoubleScalar.Rel<LengthUnit> length)
164         {
165             super(id, startNode, endNode, length);
166         }
167     }
168 
169 }