/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2005-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file StdDefs.h14/// @author Daniel Krajzewicz15/// @author Laura Bieker16/// @author Michael Behrisch17/// @author Jakob Erdmann18/// @date Fri, 29.04.200519///20//21/****************************************************************************/22#pragma once23#include <config.h>24#include <string>25#include <cmath>26#include <limits>2728/* avoiding compiler warning unreferenced parameter */29#define UNUSED_PARAMETER(x) ((void)(x))3031#ifdef _MSC_VER32#if _MSC_VER < 194333#define FALLTHROUGH /* do nothing */34#else35#define FALLTHROUGH [[fallthrough]]36#endif37#elif __GNUC__ < 738#define FALLTHROUGH /* do nothing */39#else40#define FALLTHROUGH __attribute__((fallthrough))41#endif4243/// @brief the maximum number of connections across an intersection44#define SUMO_MAX_CONNECTIONS 2564546class RGBColor;4748/* -------------------------------------------------------------------------49* some constant defaults used by SUMO50* ----------------------------------------------------------------------- */51const double SUMO_const_laneWidth = 3.2;52const double SUMO_const_halfLaneWidth = SUMO_const_laneWidth / 2;53const double SUMO_const_quarterLaneWidth = SUMO_const_laneWidth / 4;54const double SUMO_const_laneMarkWidth = 0.1;55const double SUMO_const_waitingPersonWidth = 0.8;56const double SUMO_const_waitingPersonDepth = 0.67;57const double SUMO_const_waitingContainerWidth = 2.5;58const double SUMO_const_waitingContainerDepth = 6.2;5960/// @brief the speed threshold at which vehicles are considered as halting61const double SUMO_const_haltingSpeed = (double) 0.1;6263/// @brief invalid int64const int INVALID_INT = std::numeric_limits<int>::max();6566/// @brief invalid double67const double INVALID_DOUBLE = std::numeric_limits<double>::max();6869/// @brief (M)ajor/(M)inor version for written networks and default version for loading70typedef std::pair<int, double> MMVersion;71const MMVersion NETWORK_VERSION(1, 20);7273/* -------------------------------------------------------------------------74* templates for mathematical functions missing in some c++-implementations75* ----------------------------------------------------------------------- */7677template<typename T>78inline T79MIN2(T a, T b) {80return a < b ? a : b;81}8283template<typename T>84inline T85MAX2(T a, T b) {86return a > b ? a : b;87}888990template<typename T>91inline T92MIN3(T a, T b, T c) {93return MIN2(c, a < b ? a : b);94}959697template<typename T>98inline T99MAX3(T a, T b, T c) {100return MAX2(c, a > b ? a : b);101}102103104template<typename T>105inline T106MIN4(T a, T b, T c, T d) {107return MIN2(MIN2(a, b), MIN2(c, d));108}109110111template<typename T>112inline T113MAX4(T a, T b, T c, T d) {114return MAX2(MAX2(a, b), MAX2(c, d));115}116117118/// the precision for floating point outputs119extern int gPrecision;120extern int gPrecisionEmissions;121extern int gPrecisionGeo; // for lon,lat122extern int gPrecisionRandom; // for randomized values (i.e. speedFactor)123extern bool gHumanReadableTime;124extern bool gSimulation; // whether the current application is sumo or sumo-gui (as opposed to a router)125extern bool gIgnoreUnknownVClass; // whether the unknown vehicle classes shall be ignored on loading (for upward compatibility)126extern bool gLocaleInitialized; // whether the gettext locale for translating messages has already been loaded127extern double gWeightsRandomFactor; // randomization for edge weights128extern double gWeightsWalkOppositeFactor; // factor for walking against flow of traffic129extern bool gRoutingPreferences; // whether routing preferences have been loaded130131/// the language for GUI elements and messages132extern std::string gLanguage;133134/// the default height for GUI elements135extern int GUIDesignHeight;136137/// the default height for dialog buttons138extern int GUIDesignDialogButtonsHeight;139140/// @brief global utility flags for debugging141extern bool gDebugFlag1;142extern bool gDebugFlag2;143extern bool gDebugFlag3;144extern bool gDebugFlag4;145extern bool gDebugFlag5;146extern bool gDebugFlag6;147148// synchronized output to stdout with << (i.e. DEBUGOUT(gDebugFlag1, SIMTIME << " var=" << var << "\n")149#define DEBUGOUT(cond, msg) if (cond) {std::ostringstream oss; oss << msg; std::cout << oss.str();}150151/// @brief discrds mantissa bits beyond the given number152double truncate(double x, int fractionBits);153154/// @brief round to the given number of mantissa bits beyond the given number155double roundBits(double x, int fractionBits);156157/// @brief round to the given number of decimal digits158double roundDecimal(double x, int precision);159160/// @brief round to the given number of decimal digits (bankers rounding)161double roundDecimalToEven(double x, int precision);162163/** @brief Returns the number of instances of the current object that shall be emitted164* given the number of loaded objects165* considering that "frac" of all objects shall be emitted overall166* @return the number of objects to create (something between 0 and ceil(frac))167*/168int getScalingQuota(double frac, long long int loaded);169170171