8 using std::numeric_limits;
11 std::string
Plotter<T>::plot(
const std::function<T(T)>& f, T from, T to,
unsigned int n)
const
13 std::vector<std::pair<T, T>> lines;
14 T delta = (to - from) / n;
15 for (
unsigned int i = 0; i < n; ++i) {
16 T x = from +
static_cast<T
>(i) * delta;
17 lines.push_back(std::make_pair(x, f(x)));
20 T mininf = -numeric_limits<double>::infinity();
21 T maxinf = numeric_limits<double>::infinity();
22 T maxx = mininf, maxy = mininf, minx = maxinf, miny = maxinf;
23 for (
auto& p : lines) {
34 T maxrange = (maxx - minx) < (maxy - miny) ? (maxy - miny) : (maxx - minx);
35 T imagex = size * (maxx - minx) / maxrange;
36 T imagey = size * (maxy - miny) / maxrange;
37 T scale = 0.95 * (imagex / (maxx - minx));
38 T DCx = scale * ((minx + maxx) / 2);
39 T DCy = scale * ((miny + maxy) / 2);
40 T dx = (imagex / 2) - DCx;
41 T dy = (imagey / 2) - DCy;
44 for (
size_t i = 0; i < lines.size(); i++) {
45 result +=
"(" + std::to_string(lines[i].first * scale + dx) +
"," +
46 std::to_string(lines[i].second * scale + dy) +
")\n";
54 return plot(f, from, to, n);
std::string operator()(const std::function< T(T)> &f, T from=0.0, T to=1.0, unsigned int n=10) const
std::string plot(const std::function< T(T)> &f, T from=0.0, T to=1.0, unsigned int n=10) const