-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionplottermenudialog.cpp
More file actions
107 lines (95 loc) · 2.79 KB
/
functionplottermenudialog.cpp
File metadata and controls
107 lines (95 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "functionplottermenudialog.h"
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/math/constants/constants.hpp>
#include "drawcanvas.h"
#include "functionplottermaindialog.h"
#pragma GCC diagnostic pop
int ribi::FunctionPlotterMenuDialog::ExecuteSpecific(const std::vector<std::string>& argv) noexcept
{
const int argc = static_cast<int>(argv.size());
if (argc != 3 || (argv[1] != "-e" && argv[1] != "--equation"))
{
std::cout << GetHelp() << '\n';
return 1;
}
const std::string formula { argv[2] };
const int n_cols = 78;
const double x_min = 0.0;
const double x_max = static_cast<double>(n_cols);
const int n_rows = 20;
try
{
const FunctionPlotterMainDialog d(
formula,
x_min,
x_max,
n_cols
);
const std::vector<double> xs { d.GetXs() };
const std::vector<double> ys { d.GetYs() };
assert(xs.size() == ys.size());
boost::shared_ptr<DrawCanvas> canvas {
new DrawCanvas(n_cols,n_rows,CanvasColorSystem::invert)
};
const int sz = static_cast<int>(xs.size());
for (int i=0; i!=sz; ++i)
{
canvas->DrawDot(xs[i],ys[i]);
}
std::cout << (*canvas) << std::endl;
return 0;
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
}
ribi::About ribi::FunctionPlotterMenuDialog::GetAbout() const noexcept
{
About a(
"Richel Bilderbeek",
"FunctionPlotter",
"plots a function",
"the 6th of February 2014",
"2013-2015",
"http://www.richelbilderbeek.nl/FunctionPlotter.htm",
GetVersion(),
GetVersionHistory());
a.AddLibrary("Canvas version: " + Canvas::GetVersion());
a.AddLibrary("DrawCanvas version: " + DrawCanvas::GetVersion());
a.AddLibrary("Warp's FunctionParser version: 4.4.3");
return a;
}
ribi::Help ribi::FunctionPlotterMenuDialog::GetHelp() const noexcept
{
return ribi::Help(
GetAbout().GetFileTitle(),
GetAbout().GetFileDescription(),
{
Help::Option('e',"equation","an equation")
},
{
GetAbout().GetFileTitle() + " -e \"10 + (8 * sin(x / 10))\"",
GetAbout().GetFileTitle() + " --equation \"10 + (8 * sin(x / 10))\""
}
);
}
std::string ribi::FunctionPlotterMenuDialog::GetVersion() const noexcept
{
return "2.3";
}
std::vector<std::string> ribi::FunctionPlotterMenuDialog::GetVersionHistory() const noexcept
{
return {
"2010-xx-xx: version 1.0: initial Windows-only version",
"2010-xx-xx: version 1.1: added integration",
"2013-12-05: version 2.0: port to Qt",
"2014-02-06: version 2.1: added command-line version",
"2014-07-04: version 2.2: desktop version plots nothing if function cannot be parsed",
"2016-03-02: version 2.3: moved to own GitHub",
};
}