Skip to content

Commit 35f70d5

Browse files
feat: modify implicit logic to support double equals expression
1 parent 186f8c4 commit 35f70d5

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/core/Core/Application.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,43 @@ ExitStatus App::Application::run() {
257257

258258
// check for implicit form: f(x,y) = g(x,y)
259259
if (!plotted) {
260-
size_t equals_pos = findTopLevelEquals(func_str);
260+
size_t equals_pos = findTopLevelEquals(func_str);
261+
bool has_double_equals = hasEqualsEqualsOperator(func_str);
262+
263+
if (equals_pos != std::string::npos || has_double_equals) {
261264

262-
if (equals_pos != std::string::npos) {
263-
// split into LHS and RHS
264-
std::string lhs = trim(func_str.substr(0, equals_pos));
265-
std::string rhs = trim(func_str.substr(equals_pos + 1));
266-
267-
// create expression: LHS - RHS
268-
std::string implicit_expr = "(" + lhs + ") - (" + rhs + ")";
269-
265+
std::string implicit_expr;
266+
267+
if (has_double_equals) {
268+
// Handle == operator
269+
std::string temp_str = func_str;
270+
int depth = 0;
271+
size_t eq_pos = std::string::npos;
272+
273+
for (size_t i = 0; i < temp_str.size() - 1; ++i) {
274+
char c = temp_str[i];
275+
if (c == '(') ++depth;
276+
else if (c == ')') --depth;
277+
else if (depth == 0 && c == '=' && temp_str[i+1] == '=') {
278+
eq_pos = i;
279+
break;
280+
}
281+
}
282+
283+
if (eq_pos != std::string::npos) {
284+
std::string lhs = trim(temp_str.substr(0, eq_pos));
285+
std::string rhs = trim(temp_str.substr(eq_pos + 2)); // +2 to skip ==
286+
implicit_expr = "(" + lhs + ") - (" + rhs + ")";
287+
}
288+
} else {
289+
// Handle = operator
290+
std::string lhs = trim(func_str.substr(0, equals_pos));
291+
std::string rhs = trim(func_str.substr(equals_pos + 1));
292+
implicit_expr = "(" + lhs + ") - (" + rhs + ")";
293+
}
294+
295+
if (!implicit_expr.empty()) {
296+
270297
// setup exprtk with x and y variables
271298
double x = 0.0, y = 0.0;
272299
exprtk::symbol_table<double> symbolTable;
@@ -341,7 +368,8 @@ ExitStatus App::Application::run() {
341368
}
342369
}
343370

344-
plotted = true;
371+
plotted = true;
372+
}
345373
}
346374
}
347375
}

0 commit comments

Comments
 (0)