Line data Source code
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 : /// @author Mirko Barthauer
19 : /// @date 2014-01-07
20 : ///
21 : /****************************************************************************/
22 : #include "StdDefs.h"
23 : #include <sstream>
24 :
25 :
26 : // set by option --precision (see SystemFrame.cpp)
27 : int gPrecision = 2;
28 : int gPrecisionEmissions = 2;
29 : int gPrecisionGeo = 6;
30 : int gPrecisionRandom = 4;
31 : bool gHumanReadableTime = false;
32 : bool gSimulation = false;
33 : bool gIgnoreUnknownVClass = false;
34 : bool gLocaleInitialized = false;
35 : double gWeightsRandomFactor = 1;
36 : double gWeightsWalkOppositeFactor = 1;
37 : bool gRoutingPreferences = false;
38 : std::string gLanguage = "C";
39 :
40 : int GUIDesignHeight = 23;
41 : int GUIDesignDialogButtonsHeight = 32;
42 :
43 : bool gDebugFlag1 = false;
44 : bool gDebugFlag2 = false;
45 : bool gDebugFlag3 = false;
46 : bool gDebugFlag4 = false;
47 : bool gDebugFlag5 = false;
48 : bool gDebugFlag6 = false;
49 :
50 0 : double truncate(double x, int fractionBits) {
51 0 : return ceil(x * (1 << fractionBits)) / (1 << fractionBits);
52 : }
53 :
54 0 : double roundBits(double x, int fractionBits) {
55 0 : const double x2 = x * (1 << fractionBits);
56 0 : const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);
57 0 : return rounded / (1 << fractionBits);
58 : }
59 :
60 6128307 : double roundDecimal(double x, int precision) {
61 6128307 : const double p = pow(10, precision);
62 6128307 : const double x2 = x * p;
63 6128307 : return (x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5)) / p;
64 : }
65 :
66 1488685 : double roundDecimalToEven(double x, int precision) {
67 1488685 : const int p = (int)pow(10, precision);
68 1488685 : return std::nearbyint(x * p) / p;
69 : }
70 :
71 : int
72 1623989 : getScalingQuota(double frac, int loaded) {
73 1623989 : if (frac < 0 || frac == 1.) {
74 : return 1;
75 : }
76 90234 : const int base = (int)frac;
77 : const int resolution = 1000;
78 90234 : const int intFrac = (int)floor((frac - base) * resolution + 0.5);
79 : // apply % twice to avoid integer overflow
80 90234 : if (((loaded % resolution) * intFrac) % resolution < intFrac) {
81 56381 : return base + 1;
82 : }
83 : return base;
84 : }
85 :
86 : /****************************************************************************/
|