1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file StdDefs.h
11 /// @author Daniel Krajzewicz
12 /// @author Laura Bieker
13 /// @author Michael Behrisch
14 /// @author Jakob Erdmann
15 /// @date Fri, 29.04.2005
16 /// @version $Id$
17 ///
18 //
19 /****************************************************************************/
20 #ifndef StdDefs_h
21 #define StdDefs_h
22
23
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <string>
28 #include <cmath>
29 #include <limits>
30
31 /* avoiding compiler warning unreferenced parameter */
32 #define UNUSED_PARAMETER(x) ((void)(x))
33
34 #ifdef _MSC_VER
35 #define FALLTHROUGH /* do nothing */
36 #elif __GNUC__ < 7
37 #define FALLTHROUGH /* do nothing */
38 #else
39 #define FALLTHROUGH __attribute__((fallthrough))
40 #endif
41
42 /// @brief the maximum number of connections across an intersection
43 #define SUMO_MAX_CONNECTIONS 256
44
45 class RGBColor;
46
47 /* -------------------------------------------------------------------------
48 * some constant defaults used by SUMO
49 * ----------------------------------------------------------------------- */
50 const double SUMO_const_laneWidth = (double) 3.2;
51 const double SUMO_const_laneOffset = (double) 0;
52 const double SUMO_const_halfLaneWidth = SUMO_const_laneWidth / 2;
53 const double SUMO_const_quarterLaneWidth = SUMO_const_laneWidth / 4;
54 const double SUMO_const_laneWidthAndOffset = SUMO_const_laneWidth + SUMO_const_laneOffset;
55 const double SUMO_const_halfLaneAndOffset = SUMO_const_halfLaneWidth + SUMO_const_laneOffset;
56 const double SUMO_const_laneMarkWidth = (double) 0.1;
57 const double SUMO_const_waitingPersonWidth = 0.8;
58 const double SUMO_const_waitingPersonDepth = 0.67;
59
60 /// @brief the speed threshold at which vehicles are considered as halting
61 const double SUMO_const_haltingSpeed = (double) 0.1;
62
63 const double INVALID_DOUBLE = std::numeric_limits<double>::max();
64
65
66 /* -------------------------------------------------------------------------
67 * templates for mathematical functions missing in some c++-implementations
68 * ----------------------------------------------------------------------- */
69 template<typename T>
70 inline T
MIN2(T a,T b)71 MIN2(T a, T b) {
72 return a < b ? a : b;
73 }
74
75 template<typename T>
76 inline T
MAX2(T a,T b)77 MAX2(T a, T b) {
78 return a > b ? a : b;
79 }
80
81
82 template<typename T>
83 inline T
MIN3(T a,T b,T c)84 MIN3(T a, T b, T c) {
85 return MIN2(c, a < b ? a : b);
86 }
87
88
89 template<typename T>
90 inline T
MAX3(T a,T b,T c)91 MAX3(T a, T b, T c) {
92 return MAX2(c, a > b ? a : b);
93 }
94
95
96 template<typename T>
97 inline T
MIN4(T a,T b,T c,T d)98 MIN4(T a, T b, T c, T d) {
99 return MIN2(MIN2(a, b), MIN2(c, d));
100 }
101
102
103 template<typename T>
104 inline T
MAX4(T a,T b,T c,T d)105 MAX4(T a, T b, T c, T d) {
106 return MAX2(MAX2(a, b), MAX2(c, d));
107 }
108
109
110 template<typename T>
111 inline T
ISNAN(T a)112 ISNAN(T a) {
113 volatile T d = a;
114 return d != d;
115 }
116
117
118 /// the precision for floating point outputs
119 extern int gPrecision;
120 extern int gPrecisionGeo; // for lon,lat
121 extern bool gHumanReadableTime;
122 extern bool gSimulation; // whether the current application is sumo or sumo-gui (as opposed to a router)
123 extern double gWeightsRandomFactor; // randomization for edge weights
124
125
126 /// @brief global utility flags for debugging
127 extern bool gDebugFlag1;
128 extern bool gDebugFlag2;
129 extern bool gDebugFlag3;
130 extern bool gDebugFlag4;
131
132 /// @brief discrds mantissa bits beyond the given number
133 double truncate(double x, int fractionBits);
134
135 /// @brief round to the given number of mantissa bits beyond the given number
136 double roundBits(double x, int fractionBits);
137
138 #endif
139
140 /****************************************************************************/
141
142