Skip to content

Commit

Permalink
Merge pull request #64 from SubhadeepJasu/remediation_2
Browse files Browse the repository at this point in the history
Remediation 2
  • Loading branch information
SubhadeepJasu authored Jul 5, 2020
2 parents e302bf3 + 2e1e3ec commit c09a23e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
10 changes: 10 additions & 0 deletions data/com.github.subhadeepjasu.pebbles.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
</screenshot>
</screenshots>
<releases>
<release date="2020-07-05" version="1.0.5">
<description>
<p>Fixed:</p>
<ul>
<li>[UI] Allow navigation left and right buttons to pass through selectively</li>
<li>[Core] Better negative number handling</li>
<li>[Core] Implicit multiplication on parenthesis and around variable (x)</li>
</ul>
</description>
</release>
<release date="2020-06-20" version="1.0.4">
<description>
<p>Fixed:</p>
Expand Down
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
com.github.subhadeepjasu.pebbles (1.0.5) bionic; urgency=low

[FIXED]
* Allow navigation left and right buttons to pass through selectively
* Better negative number handling
* Implicit multiplication on parenthesis and around variable x

-- Subhadeep Jasu <[email protected]> Sun, 5 Jul 2020 11:37:45 +0530

com.github.subhadeepjasu.pebbles (1.0.4) bionic; urgency=low

[FIXED]
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
project (
'com.github.subhadeepjasu.pebbles',
'vala', 'c',
version: '1.0.4',
version: '1.0.5',
)

# GNOME module
Expand Down
11 changes: 7 additions & 4 deletions src/Core/Calculus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Pebbles {
double result, error;

string revised_exp = Utils.st_tokenize (exp);
revised_exp = Utils.algebraic_variable_product_convert (revised_exp);
char* user_func = new char [revised_exp.length];
for (int i = 0; i < revised_exp.length; i++) {
user_func [i] = (char)revised_exp.get_char (i);
Expand All @@ -59,12 +60,14 @@ namespace Pebbles {
public static string get_definite_integral (string exp, GlobalAngleUnit angle_mode_in, double lower_limit, double upper_limit) {
// Using Simpson's 3/8 method

string revised_exp = Utils.st_tokenize (exp);
revised_exp = Utils.algebraic_variable_product_convert (revised_exp);
ScientificCalculator sci_calc = new ScientificCalculator ();
int accuracy = 40;
double interval_size = (upper_limit - lower_limit) / accuracy;
//stdout.printf ("DEBUG: lower_limit = %lf, upper_limit = %lf\n", lower_limit, upper_limit);
string exp1 = sci_calc.get_result (exp.replace ("x", lower_limit.to_string()), angle_mode_in);
string exp2 = sci_calc.get_result (exp.replace ("x", upper_limit.to_string()), angle_mode_in);
string exp1 = sci_calc.get_result (revised_exp.replace ("x", lower_limit.to_string()), angle_mode_in);
string exp2 = sci_calc.get_result (revised_exp.replace ("x", upper_limit.to_string()), angle_mode_in);

if (exp1 != "E" && exp2 != "E") {
double sum = 0.0;
Expand All @@ -84,10 +87,10 @@ namespace Pebbles {
// Calculate value till integral limit is reached
for (int i = 1; i < accuracy; i++) {
if (i % 3 == 0) {
sum = sum + 2 * double.parse (sci_calc.get_result (exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
sum = sum + 2 * double.parse (sci_calc.get_result (revised_exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
}
else {
sum = sum + 3 * double.parse (sci_calc.get_result (exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
sum = sum + 3 * double.parse (sci_calc.get_result (revised_exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
}
}
Settings accuracy_settings = Settings.get_default ();
Expand Down
62 changes: 52 additions & 10 deletions src/Core/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ namespace Pebbles {
exp = exp.strip ();
exp = space_removal (exp);

// Take care of unary subtraction
exp = uniminus_convert (exp);
//stdout.printf ("'%s'\n", exp);
// Intelligently convert expressions based on common rules
exp = algebraic_parenthesis_product_convert (exp);
exp = unary_minus_convert (exp);

//exp = space_removal (exp);
print ("Final exp: " + exp + "\n");
return exp;
}
else {
Expand All @@ -199,27 +202,65 @@ namespace Pebbles {
}
return result;
}
private static string uniminus_convert (string exp) {
private static string unary_minus_convert (string exp) {
print(">%s<\n", exp);
string uniminus_converted = "";
string[] tokens = exp.split (" ");
for (int i = 0; i < tokens.length; i++) {
if (tokens[i] == "-") {
print("token: %d\n", i);
print("token: %s\n", tokens[i + 1]);
if (i == 0) {
tokens [i] = "u";
if (i < tokens.length) {
tokens [i] = "( 0 u";
tokens [i + 1] = tokens [i + 1] + " )";
}
} else if (tokens [i - 1] == ")" || tokens [i - 1] == "x" || is_number (tokens [i - 1]) ) {
tokens [i] = "-";
} else {
tokens [i] = "u";
if (i < tokens.length) {
tokens [i] = "( 0 u";
tokens [i + 1] = tokens [i + 1] + " )";
}
}
}
}
uniminus_converted = string.joinv (" ", tokens);
uniminus_converted = uniminus_converted.replace ("u", "0 u");
print("converted: %s\n", uniminus_converted);
//uniminus_converted = uniminus_converted.replace ("u", "0 u");
print("unary converted: %s\n", uniminus_converted);
return uniminus_converted;
}

public static string algebraic_variable_product_convert (string exp) {
string converted_exp = "";
string[] tokens = exp.replace("x", " x ").split (" ");
for (int i = 1; i < tokens.length; i++) {
if (tokens[i] == "x" && is_number(tokens[i - 1]) && tokens[i - 1] != "(") {
tokens[i] = "* x";
}
}
converted_exp = space_removal(string.joinv (" ", tokens));
//print("algebraic converted: %s\n", converted_exp);
return converted_exp;
}

public static string algebraic_parenthesis_product_convert (string exp) {
string[] tokens = exp.split (" ");
for (int i = 1; i < tokens.length - 1; i++) {
if (tokens[i] == "(") {
if (is_number (tokens[i - 1])) {
tokens[i] = "* (";
}
}
if (tokens[i] == ")") {
if (is_number (tokens[i + 1]) || tokens[i + 1] == "(") {
tokens[i] = ") *";
}
}
}
string converted_exp = space_removal(string.joinv (" ", tokens));
print("algebraic converted: %s\n", converted_exp);
return converted_exp;
}

private static bool is_number (string exp) {
if (exp.has_suffix ("0") ||
Expand All @@ -232,7 +273,8 @@ namespace Pebbles {
exp.has_suffix ("7") ||
exp.has_suffix ("8") ||
exp.has_suffix ("9") ||
exp.has_suffix (".")
exp.has_suffix (".") ||
exp.has_suffix ("x")
) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ namespace Pebbles {
conv_curr_view.key_press_event (event);
break;
}
if (settings.view_index != 4 &&
(event.keyval == KeyboardHandler.KeyMap.NAV_LEFT ||
event.keyval == KeyboardHandler.KeyMap.NAV_RIGHT)
) {
return false;
}
if (event.keyval == 65505) {
keyboard_shift_status = true;
}
Expand Down

0 comments on commit c09a23e

Please sign in to comment.