26 const std::string result =
"import numpy\n"
27 "import bornagain as ba\n"
28 "from bornagain import deg, angstrom, nm, nm2, kvector_t\n\n\n";
40 return value ?
"True" :
"False";
45 std::ostringstream inter;
46 inter << std::setprecision(12);
47 if (std::abs(input) < std::numeric_limits<double>::epsilon()) {
52 if (inter.str().find(
'e') == std::string::npos && inter.str().find(
'.') == std::string::npos)
59 std::ostringstream inter;
60 inter << std::setprecision(12);
67 std::ostringstream inter;
68 inter << std::setprecision(12);
76 std::ostringstream inter;
80 std::string::size_type pos = inter.str().find(
'e');
81 if (pos == std::string::npos)
84 std::string part1 = inter.str().substr(0, pos);
85 std::string part2 = inter.str().substr(pos, std::string::npos);
87 part1.erase(part1.find_last_not_of(
'0') + 1, std::string::npos);
88 if (part1.back() ==
'.')
96 std::ostringstream inter;
98 if (inter.str().find(
'e') == std::string::npos && inter.str().find(
'.') == std::string::npos)
104 std::string
printValue(
double value,
const std::string& units)
108 else if (units ==
"nm")
110 else if (units ==
"")
113 throw std::runtime_error(
"pyfmt::printValue() -> Error. Unknown units '" + units +
"'");
118 std::ostringstream result;
119 result <<
"\"" << value <<
"\"";
123 bool isSquare(
double length1,
double length2,
double angle)
135 std::ostringstream result;
143 return std::string(
width,
' ');
Defines and implements namespace algo with some algorithms.
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 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 getSampleFunctionName()
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 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)
std::string scriptPreamble()