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 : {
"kvector_t"})
31 if (code.find(key) != std::string::npos)
32 to_declare.push_back(key);
38 return value ?
"True" :
"False";
43 std::ostringstream inter;
44 inter << std::setprecision(12);
45 if (std::abs(input) < std::numeric_limits<double>::epsilon()) {
50 if (inter.str().find(
'e') == std::string::npos && inter.str().find(
'.') == std::string::npos)
58 std::ostringstream inter;
59 int ival = std::lround(input);
60 if (std::abs(input - ival) < 1e-11)
63 inter << std::setprecision(12);
64 if (std::abs(input) < std::numeric_limits<double>::epsilon())
67 if (inter.str().find(
'e') == std::string::npos
68 && inter.str().find(
'.') == std::string::npos)
76 std::ostringstream inter;
77 inter << std::setprecision(12);
84 std::ostringstream inter;
85 inter << std::setprecision(12);
93 std::ostringstream inter;
97 std::string::size_type pos = inter.str().find(
'e');
98 if (pos == std::string::npos)
101 std::string part1 = inter.str().substr(0, pos);
102 std::string part2 = inter.str().substr(pos, std::string::npos);
104 part1.erase(part1.find_last_not_of(
'0') + 1, std::string::npos);
105 if (part1.back() ==
'.')
108 return part1 + part2;
113 std::ostringstream inter;
118 std::string
printValue(
double value,
const std::string& units)
122 else if (units ==
"nm")
124 else if (units ==
"")
127 throw std::runtime_error(
"pyfmt::printValue() -> Error. Unknown units '" + units +
"'");
132 std::ostringstream result;
133 result <<
"\"" << value <<
"\"";
137 bool isSquare(
double length1,
double length2,
double angle)
149 std::ostringstream result;
157 return std::string(width,
' ');
Defines and implements namespace algo with some algorithms.
Defines a few helper functions.
Defines M_PI and some more mathematical constants.
Defines functions in namespace pyfmt.
Defines some unit conversion factors and other constants in namespace Units.
T z() const
Returns z-component in cartesian coordinate system.
T y() const
Returns y-component in cartesian coordinate system.
T x() const
Returns x-component in cartesian coordinate system.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
std::string scientific(const T value, int n=10)
Returns scientific string representing given value of any numeric type.
double rad2deg(double angle)
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
Utility functions for writing Python code snippets.
std::string printNm(double input)
std::string printNm2(double input)
std::string printDegrees(double input)
bool isSquare(double length1, double length2, double angle)
std::string printDouble(double input)
std::string printKvector(const kvector_t value)
std::string printScientificDouble(double input)
std::string printBool(double value)
std::string printImportedSymbols(const std::string &code)
std::string printLightDouble(double input)
prints double as an integer, if possible within standard accuracy
std::string printString(const std::string &value)
std::string indent(size_t width)
Returns a string of blanks with given width.
bool isHexagonal(double length1, double length2, double angle)
std::string printValue(double value, const std::string &units)