Skip to content

Commit c09a23e

Browse files
Merge pull request #64 from SubhadeepJasu/remediation_2
Remediation 2
2 parents e302bf3 + 2e1e3ec commit c09a23e

File tree

6 files changed

+85
-15
lines changed

6 files changed

+85
-15
lines changed

data/com.github.subhadeepjasu.pebbles.appdata.xml.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
</screenshot>
6161
</screenshots>
6262
<releases>
63+
<release date="2020-07-05" version="1.0.5">
64+
<description>
65+
<p>Fixed:</p>
66+
<ul>
67+
<li>[UI] Allow navigation left and right buttons to pass through selectively</li>
68+
<li>[Core] Better negative number handling</li>
69+
<li>[Core] Implicit multiplication on parenthesis and around variable (x)</li>
70+
</ul>
71+
</description>
72+
</release>
6373
<release date="2020-06-20" version="1.0.4">
6474
<description>
6575
<p>Fixed:</p>

debian/changelog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
com.github.subhadeepjasu.pebbles (1.0.5) bionic; urgency=low
2+
3+
[FIXED]
4+
* Allow navigation left and right buttons to pass through selectively
5+
* Better negative number handling
6+
* Implicit multiplication on parenthesis and around variable x
7+
8+
-- Subhadeep Jasu <subhadeep@gmail.com> Sun, 5 Jul 2020 11:37:45 +0530
9+
110
com.github.subhadeepjasu.pebbles (1.0.4) bionic; urgency=low
211

312
[FIXED]

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project (
33
'com.github.subhadeepjasu.pebbles',
44
'vala', 'c',
5-
version: '1.0.4',
5+
version: '1.0.5',
66
)
77

88
# GNOME module

src/Core/Calculus.vala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Pebbles {
3636
double result, error;
3737

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

63+
string revised_exp = Utils.st_tokenize (exp);
64+
revised_exp = Utils.algebraic_variable_product_convert (revised_exp);
6265
ScientificCalculator sci_calc = new ScientificCalculator ();
6366
int accuracy = 40;
6467
double interval_size = (upper_limit - lower_limit) / accuracy;
6568
//stdout.printf ("DEBUG: lower_limit = %lf, upper_limit = %lf\n", lower_limit, upper_limit);
66-
string exp1 = sci_calc.get_result (exp.replace ("x", lower_limit.to_string()), angle_mode_in);
67-
string exp2 = sci_calc.get_result (exp.replace ("x", upper_limit.to_string()), angle_mode_in);
69+
string exp1 = sci_calc.get_result (revised_exp.replace ("x", lower_limit.to_string()), angle_mode_in);
70+
string exp2 = sci_calc.get_result (revised_exp.replace ("x", upper_limit.to_string()), angle_mode_in);
6871

6972
if (exp1 != "E" && exp2 != "E") {
7073
double sum = 0.0;
@@ -84,10 +87,10 @@ namespace Pebbles {
8487
// Calculate value till integral limit is reached
8588
for (int i = 1; i < accuracy; i++) {
8689
if (i % 3 == 0) {
87-
sum = sum + 2 * double.parse (sci_calc.get_result (exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
90+
sum = sum + 2 * double.parse (sci_calc.get_result (revised_exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
8891
}
8992
else {
90-
sum = sum + 3 * double.parse (sci_calc.get_result (exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
93+
sum = sum + 3 * double.parse (sci_calc.get_result (revised_exp.replace ("x", (lower_limit + i * interval_size).to_string()), angle_mode_in));
9194
}
9295
}
9396
Settings accuracy_settings = Settings.get_default ();

src/Core/Utils.vala

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ namespace Pebbles {
171171
exp = exp.strip ();
172172
exp = space_removal (exp);
173173

174-
// Take care of unary subtraction
175-
exp = uniminus_convert (exp);
176-
//stdout.printf ("'%s'\n", exp);
174+
// Intelligently convert expressions based on common rules
175+
exp = algebraic_parenthesis_product_convert (exp);
176+
exp = unary_minus_convert (exp);
177+
178+
//exp = space_removal (exp);
179+
print ("Final exp: " + exp + "\n");
177180
return exp;
178181
}
179182
else {
@@ -199,27 +202,65 @@ namespace Pebbles {
199202
}
200203
return result;
201204
}
202-
private static string uniminus_convert (string exp) {
205+
private static string unary_minus_convert (string exp) {
203206
print(">%s<\n", exp);
204207
string uniminus_converted = "";
205208
string[] tokens = exp.split (" ");
206209
for (int i = 0; i < tokens.length; i++) {
207210
if (tokens[i] == "-") {
208-
print("token: %d\n", i);
211+
print("token: %s\n", tokens[i + 1]);
209212
if (i == 0) {
210-
tokens [i] = "u";
213+
if (i < tokens.length) {
214+
tokens [i] = "( 0 u";
215+
tokens [i + 1] = tokens [i + 1] + " )";
216+
}
211217
} else if (tokens [i - 1] == ")" || tokens [i - 1] == "x" || is_number (tokens [i - 1]) ) {
212218
tokens [i] = "-";
213219
} else {
214-
tokens [i] = "u";
220+
if (i < tokens.length) {
221+
tokens [i] = "( 0 u";
222+
tokens [i + 1] = tokens [i + 1] + " )";
223+
}
215224
}
216225
}
217226
}
218227
uniminus_converted = string.joinv (" ", tokens);
219-
uniminus_converted = uniminus_converted.replace ("u", "0 u");
220-
print("converted: %s\n", uniminus_converted);
228+
//uniminus_converted = uniminus_converted.replace ("u", "0 u");
229+
print("unary converted: %s\n", uniminus_converted);
221230
return uniminus_converted;
222231
}
232+
233+
public static string algebraic_variable_product_convert (string exp) {
234+
string converted_exp = "";
235+
string[] tokens = exp.replace("x", " x ").split (" ");
236+
for (int i = 1; i < tokens.length; i++) {
237+
if (tokens[i] == "x" && is_number(tokens[i - 1]) && tokens[i - 1] != "(") {
238+
tokens[i] = "* x";
239+
}
240+
}
241+
converted_exp = space_removal(string.joinv (" ", tokens));
242+
//print("algebraic converted: %s\n", converted_exp);
243+
return converted_exp;
244+
}
245+
246+
public static string algebraic_parenthesis_product_convert (string exp) {
247+
string[] tokens = exp.split (" ");
248+
for (int i = 1; i < tokens.length - 1; i++) {
249+
if (tokens[i] == "(") {
250+
if (is_number (tokens[i - 1])) {
251+
tokens[i] = "* (";
252+
}
253+
}
254+
if (tokens[i] == ")") {
255+
if (is_number (tokens[i + 1]) || tokens[i + 1] == "(") {
256+
tokens[i] = ") *";
257+
}
258+
}
259+
}
260+
string converted_exp = space_removal(string.joinv (" ", tokens));
261+
print("algebraic converted: %s\n", converted_exp);
262+
return converted_exp;
263+
}
223264

224265
private static bool is_number (string exp) {
225266
if (exp.has_suffix ("0") ||
@@ -232,7 +273,8 @@ namespace Pebbles {
232273
exp.has_suffix ("7") ||
233274
exp.has_suffix ("8") ||
234275
exp.has_suffix ("9") ||
235-
exp.has_suffix (".")
276+
exp.has_suffix (".") ||
277+
exp.has_suffix ("x")
236278
) {
237279
return true;
238280
}

src/MainWindow.vala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,12 @@ namespace Pebbles {
842842
conv_curr_view.key_press_event (event);
843843
break;
844844
}
845+
if (settings.view_index != 4 &&
846+
(event.keyval == KeyboardHandler.KeyMap.NAV_LEFT ||
847+
event.keyval == KeyboardHandler.KeyMap.NAV_RIGHT)
848+
) {
849+
return false;
850+
}
845851
if (event.keyval == 65505) {
846852
keyboard_shift_status = true;
847853
}

0 commit comments

Comments
 (0)