26 std::vector<std::string> to_declare;
27 for (
const std::string key : {
"angstrom",
"deg",
"nm",
"nm2",
"micrometer"})
28 if (code.find(
"*" + key) != std::string::npos)
29 to_declare.push_back(key);
30 for (
const std::string key : {
"R3"})
31 if (code.find(key) != std::string::npos)
32 to_declare.push_back(key);
38 return std::to_string(value);
43 return value ?
"True" :
"False";
48 std::ostringstream inter;
49 inter << std::setprecision(12);
50 if (std::abs(input) < std::numeric_limits<double>::epsilon()) {
55 if (inter.str().find(
'e') == std::string::npos && inter.str().find(
'.') == std::string::npos)
63 std::ostringstream inter;
64 int ival = std::lround(input);
65 if (std::abs(input - ival) < 1e-11)
68 inter << std::setprecision(12);
69 if (std::abs(input) < std::numeric_limits<double>::epsilon())
72 if (inter.str().find(
'e') == std::string::npos
73 && inter.str().find(
'.') == std::string::npos)
81 std::ostringstream inter;
82 inter << std::setprecision(12);
89 std::ostringstream inter;
90 inter << std::setprecision(12);
98 std::ostringstream inter;
102 std::string::size_type pos = inter.str().find(
'e');
103 if (pos == std::string::npos)
106 std::string part1 = inter.str().substr(0, pos);
107 std::string part2 = inter.str().substr(pos, std::string::npos);
109 part1.erase(part1.find_last_not_of(
'0') + 1, std::string::npos);
110 if (part1.back() ==
'.')
113 return part1 + part2;
118 std::ostringstream inter;
123 std::string
printValue(
double value,
const std::string& units)
134 std::string
printValue(std::variant<double, int> value,
const std::string& units )
136 if (std::holds_alternative<int>(value)) {
138 return printInt(std::get<int>(value));
141 return printValue(std::get<double>(value), units);
146 std::ostringstream result;
147 result <<
"\"" << value <<
"\"";
151 std::string
printArguments(
const std::vector<std::pair<double, std::string>>& arguments)
153 std::vector<std::string> args;
154 for (
const auto& argument : arguments)
160 printArguments(
const std::vector<std::pair<std::variant<double, int>, std::string>>& arguments)
162 std::vector<std::string> args;
163 for (
const auto& argument : arguments)
169 const std::vector<std::pair<double, std::string>>& arguments)
174 std::string
printFunction(
const std::string& name,
double value,
const std::string& unit)
179 std::string
printFunction(
const std::string& name,
double value1,
const std::string& unit1,
180 double value2,
const std::string& unit2)
182 return printFunction(name, {{value1, unit1}, {value2, unit2}});
185 bool isSquare(
double length1,
double length2,
double angle)
197 std::ostringstream result;
205 return std::string(width,
' ');
Defines and implements namespace BaseUtils::algo with some algorithms.
#define ASSERT(condition)
Defines a few helper functions.
Defines M_PI and some more mathematical constants.
Defines some unit conversion factors and other constants in namespace Units.
std::string scientific(T value, int n=10)
Returns scientific string representing given value of any numeric type.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
Utility functions for writing Python code snippets.
std::string printDegrees(double input)
std::string printDouble(double input)
std::string printLightDouble(double input)
prints double as an integer, if possible within standard accuracy
std::string printString(const std::string &value)
std::string printKvector(const R3 value)
std::string printScientificDouble(double input)
std::string printNm(double input)
bool isHexagonal(double length1, double length2, double angle)
std::string printBool(double value)
std::string indent(size_t width)
Returns a string of blanks with given width. By default the width equals standard offset in python fi...
std::string printNm2(double input)
std::string printFunction(const std::string &name, const std::vector< std::pair< double, std::string >> &arguments)
Print a function in the form "<name>(<arguments>)". arguments will be processed by printArguments(),...
std::string printArguments(const std::vector< std::pair< double, std::string >> &arguments)
Takes pairs of value/unit and concatenates them for an argument list. Each pair's content will be pro...
std::string printValue(double value, const std::string &units)
bool isSquare(double length1, double length2, double angle)
std::string printImportedSymbols(const std::string &code)
std::string printInt(int value)
double rad2deg(double angle)