Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/common/StdDefs.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2005-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file StdDefs.h
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @author Jakob Erdmann
19
/// @date Fri, 29.04.2005
20
///
21
//
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
#include <string>
26
#include <cmath>
27
#include <limits>
28
29
/* avoiding compiler warning unreferenced parameter */
30
#define UNUSED_PARAMETER(x) ((void)(x))
31
32
#ifdef _MSC_VER
33
#if _MSC_VER < 1943
34
#define FALLTHROUGH /* do nothing */
35
#else
36
#define FALLTHROUGH [[fallthrough]]
37
#endif
38
#elif __GNUC__ < 7
39
#define FALLTHROUGH /* do nothing */
40
#else
41
#define FALLTHROUGH __attribute__((fallthrough))
42
#endif
43
44
/// @brief the maximum number of connections across an intersection
45
#define SUMO_MAX_CONNECTIONS 256
46
47
class RGBColor;
48
49
/* -------------------------------------------------------------------------
50
* some constant defaults used by SUMO
51
* ----------------------------------------------------------------------- */
52
const double SUMO_const_laneWidth = 3.2;
53
const double SUMO_const_halfLaneWidth = SUMO_const_laneWidth / 2;
54
const double SUMO_const_quarterLaneWidth = SUMO_const_laneWidth / 4;
55
const double SUMO_const_laneMarkWidth = 0.1;
56
const double SUMO_const_waitingPersonWidth = 0.8;
57
const double SUMO_const_waitingPersonDepth = 0.67;
58
const double SUMO_const_waitingContainerWidth = 2.5;
59
const double SUMO_const_waitingContainerDepth = 6.2;
60
61
/// @brief the speed threshold at which vehicles are considered as halting
62
const double SUMO_const_haltingSpeed = (double) 0.1;
63
64
/// @brief invalid int
65
const int INVALID_INT = std::numeric_limits<int>::max();
66
67
/// @brief invalid double
68
const double INVALID_DOUBLE = std::numeric_limits<double>::max();
69
70
/// @brief (M)ajor/(M)inor version for written networks and default version for loading
71
typedef std::pair<int, double> MMVersion;
72
const MMVersion NETWORK_VERSION(1, 20);
73
74
/* -------------------------------------------------------------------------
75
* templates for mathematical functions missing in some c++-implementations
76
* ----------------------------------------------------------------------- */
77
78
template<typename T>
79
inline T
80
MIN2(T a, T b) {
81
return a < b ? a : b;
82
}
83
84
template<typename T>
85
inline T
86
MAX2(T a, T b) {
87
return a > b ? a : b;
88
}
89
90
91
template<typename T>
92
inline T
93
MIN3(T a, T b, T c) {
94
return MIN2(c, a < b ? a : b);
95
}
96
97
98
template<typename T>
99
inline T
100
MAX3(T a, T b, T c) {
101
return MAX2(c, a > b ? a : b);
102
}
103
104
105
template<typename T>
106
inline T
107
MIN4(T a, T b, T c, T d) {
108
return MIN2(MIN2(a, b), MIN2(c, d));
109
}
110
111
112
template<typename T>
113
inline T
114
MAX4(T a, T b, T c, T d) {
115
return MAX2(MAX2(a, b), MAX2(c, d));
116
}
117
118
119
/// the precision for floating point outputs
120
extern int gPrecision;
121
extern int gPrecisionEmissions;
122
extern int gPrecisionGeo; // for lon,lat
123
extern int gPrecisionRandom; // for randomized values (i.e. speedFactor)
124
extern bool gHumanReadableTime;
125
extern bool gSimulation; // whether the current application is sumo or sumo-gui (as opposed to a router)
126
extern bool gIgnoreUnknownVClass; // whether the unknown vehicle classes shall be ignored on loading (for upward compatibility)
127
extern double gWeightsRandomFactor; // randomization for edge weights
128
extern double gWeightsWalkOppositeFactor; // factor for walking against flow of traffic
129
130
/// the language for GUI elements and messages
131
extern std::string gLanguage;
132
133
/// the default height for GUI elements
134
extern int GUIDesignHeight;
135
136
/// the default height for dialog buttons
137
extern int GUIDesignDialogButtonsHeight;
138
139
/// @brief global utility flags for debugging
140
extern bool gDebugFlag1;
141
extern bool gDebugFlag2;
142
extern bool gDebugFlag3;
143
extern bool gDebugFlag4;
144
extern bool gDebugFlag5;
145
extern bool gDebugFlag6;
146
147
// synchronized output to stdout with << (i.e. DEBUGOUT(gDebugFlag1, SIMTIME << " var=" << var << "\n")
148
#define DEBUGOUT(cond, msg) if (cond) {std::ostringstream oss; oss << msg; std::cout << oss.str();}
149
150
/// @brief discrds mantissa bits beyond the given number
151
double truncate(double x, int fractionBits);
152
153
/// @brief round to the given number of mantissa bits beyond the given number
154
double roundBits(double x, int fractionBits);
155
156
/// @brief round to the given number of decimal digits
157
double roundDecimal(double x, int precision);
158
159
/// @brief round to the given number of decimal digits (bankers rounding)
160
double roundDecimalToEven(double x, int precision);
161
162
/** @brief Returns the number of instances of the current object that shall be emitted
163
* given the number of loaded objects
164
* considering that "frac" of all objects shall be emitted overall
165
* @return the number of objects to create (something between 0 and ceil(frac))
166
*/
167
int getScalingQuota(double frac, int loaded);
168
169