Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/common/StdDefs.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2014-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.cpp
15
/// @author Jakob Erdmann
16
/// @author Michael Behrisch
17
/// @author Laura Bieker
18
/// @date 2014-01-07
19
///
20
/****************************************************************************/
21
#include "StdDefs.h"
22
#include <sstream>
23
24
25
// set by option --precision (see SystemFrame.cpp)
26
int gPrecision = 2;
27
int gPrecisionEmissions = 2;
28
int gPrecisionGeo = 6;
29
int gPrecisionRandom = 4;
30
bool gHumanReadableTime = false;
31
bool gSimulation = false;
32
bool gIgnoreUnknownVClass = false;
33
double gWeightsRandomFactor = 1;
34
double gWeightsWalkOppositeFactor = 1;
35
std::string gLanguage = "C";
36
37
int GUIDesignHeight = 23;
38
int GUIDesignDialogButtonsHeight = 32;
39
40
bool gDebugFlag1 = false;
41
bool gDebugFlag2 = false;
42
bool gDebugFlag3 = false;
43
bool gDebugFlag4 = false;
44
bool gDebugFlag5 = false;
45
bool gDebugFlag6 = false;
46
47
double truncate(double x, int fractionBits) {
48
return ceil(x * (1 << fractionBits)) / (1 << fractionBits);
49
}
50
51
double roundBits(double x, int fractionBits) {
52
const double x2 = x * (1 << fractionBits);
53
const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);
54
return rounded / (1 << fractionBits);
55
}
56
57
double roundDecimal(double x, int precision) {
58
const double p = pow(10, precision);
59
const double x2 = x * p;
60
return (x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5)) / p;
61
}
62
63
double roundDecimalToEven(double x, int precision) {
64
const int p = (int)pow(10, precision);
65
return std::nearbyint(x * p) / p;
66
}
67
68
int
69
getScalingQuota(double frac, int loaded) {
70
if (frac < 0 || frac == 1.) {
71
return 1;
72
}
73
const int base = (int)frac;
74
const int resolution = 1000;
75
const int intFrac = (int)floor((frac - base) * resolution + 0.5);
76
// apply % twice to avoid integer overflow
77
if (((loaded % resolution) * intFrac) % resolution < intFrac) {
78
return base + 1;
79
}
80
return base;
81
}
82
83
/****************************************************************************/
84
85