Skip to content

Commit c8a6dcd

Browse files
committed
feat(graph): update default polar function and improve parsing logic
1 parent 86687cd commit c8a6dcd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/core/Core/Application.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ExitStatus App::Application::run() {
113113
const ImVec2 base_pos = viewport->Pos;
114114
const ImVec2 base_size = viewport->Size;
115115

116-
static char function[1024] = "tanh(x)";
116+
static char function[1024] = "r = 1 + 0.5*cos(theta)";
117117
static float zoom = 100.0f;
118118

119119
// Left Pane (expression)
@@ -214,7 +214,7 @@ ExitStatus App::Application::run() {
214214

215215
if (!plotted) {
216216
std::string func_str(function);
217-
bool is_polar = func_str.find("theta") != std::string::npos;
217+
bool is_polar = func_str.find("r=") != std::string::npos || func_str.find("r =") != std::string::npos;
218218

219219
if (is_polar) {
220220
double theta;
@@ -227,8 +227,19 @@ ExitStatus App::Application::run() {
227227
exprtk::expression<double> expression;
228228
expression.register_symbol_table(symbolTable);
229229

230+
std::string polar_function = func_str;
231+
size_t eq_pos = func_str.find("r=");
232+
if (eq_pos == std::string::npos) {
233+
eq_pos = func_str.find("r =");
234+
}
235+
if (eq_pos != std::string::npos) {
236+
size_t start_pos = func_str.find("=", eq_pos) + 1;
237+
polar_function = func_str.substr(start_pos);
238+
polar_function.erase(0, polar_function.find_first_not_of(" \t"));
239+
}
240+
230241
exprtk::parser<double> parser;
231-
if (parser.compile(function, expression)) {
242+
if (parser.compile(polar_function, expression)) {
232243
const double theta_min = 0.0;
233244
const double theta_max = 4.0 * M_PI;
234245
const double theta_step = 0.02;

0 commit comments

Comments
 (0)