View Javadoc
1   package org.opentrafficsim.kpi.sampling;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djunits.value.vdouble.scalar.Time;
5   import org.djutils.exceptions.Throw;
6   import org.opentrafficsim.kpi.interfaces.LaneData;
7   
8   /**
9    * Defines a rectangular region over space and time on a lane.
10   * <p>
11   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   * @param <L> lane data type
18   * @param lane L; lane
19   * @param startPosition Length; start position
20   * @param endPosition Length; end position
21   * @param startTime Time; start time
22   * @param endTime Time; end time
23   */
24  public record SpaceTimeRegion<L extends LaneData<L>>(L lane, Length startPosition, Length endPosition, Time startTime,
25          Time endTime)
26  {
27  
28      /**
29       * Creates a space-time region.
30       * @param lane L; lane
31       * @param startPosition Length; start position
32       * @param endPosition Length; end position
33       * @param startTime Time; start time
34       * @param endTime Time; end time
35       * @throws IllegalArgumentException if start time is larger than end time
36       */
37      public SpaceTimeRegion
38      {
39          Throw.whenNull(startPosition, "Start position may not be null.");
40          Throw.whenNull(endPosition, "End position may not be null.");
41          Throw.whenNull(startTime, "Start time may not be null.");
42          Throw.whenNull(endTime, "End time may not be null.");
43          Throw.when(endPosition.lt(startPosition), IllegalArgumentException.class,
44                  "End position should be greater than start position.");
45          Throw.when(endTime.lt(startTime), IllegalArgumentException.class, "End time should be greater than start time.");
46      }
47  
48  }