Skip to content

Commit 0fbd6e4

Browse files
committed
1.1.5
-- - Correction du bug sur les exposants qui ne se mettaient pas. - Correction du bug qui créait des lignes vides dans le tableau. - Suppression de la double barre sur les lignes de valeur interdite. - Correction d'un bug qui faisait apparaître 2 colonnes pour un même nombre. - La flèche s'étend maintenant lorsque x colonnes possèdent le même signe. En appuyant sur le petit 'i' en haut à droite de la fenêtre vous pouvez envoyer un commentaire/des suggestions/un bug
1 parent a0302b0 commit 0fbd6e4

6 files changed

Lines changed: 122 additions & 38 deletions

File tree

Setup/SignaMath.exe

836 Bytes
Binary file not shown.

Setup/setup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "SignaMath"
5-
#define MyAppVersion "1.1.4"
5+
#define MyAppVersion "1.1.5"
66
#define MyAppPublisher "zonetecde"
77
#define MyAppURL "github.com/zonetecde/SignaMath"
88
#define MyAppExeName "SignaMath.exe"

SignaMath/Classes/ExpressionElement.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public ExpressionElement(bool interdite, string expression)
1414
Expression = expression;
1515
}
1616

17+
public ExpressionElement(bool isNumerator, string expression, string exposant)
18+
{
19+
IsNumerator = isNumerator;
20+
Exposant = exposant;
21+
Expression = expression;
22+
}
23+
24+
public bool IsNumerator { get; }
25+
public string Exposant { get; }
26+
1727
internal bool Interdite { get; set; }
1828
internal string Expression { get; set; }
1929
}

SignaMath/Extension/Sheller.cs

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
75

86
namespace SignaMath.Extension
97
{
@@ -16,44 +14,53 @@ internal static class Sheller
1614
/// <param name="function">La nouvelle fonction</param>
1715
internal static List<ExpressionElement> ShellFunction(string function)
1816
{
19-
List<string> lignes = DecouperExpression(function);
17+
List<ExpressionElement> lignes = DecouperExpression(function);
2018

21-
List<string> expressions = new();
19+
List<ExpressionElement> expressions = new();
2220
if (lignes.Any())
2321
{
2422
for (int i = 0; i < lignes.Count; i++)
2523
{
26-
string expression = lignes[i];
24+
if (String.IsNullOrEmpty(lignes[i].Exposant))
25+
{
26+
string expression = lignes[i].Expression;
2727

28-
expression = SupprimerParentheses(expression);
28+
expression = SupprimerParentheses(expression);
2929

30-
List<string> nouvellesExpressions = new List<string>();
30+
List<ExpressionElement> nouvellesExpressions = new List<ExpressionElement>();
3131

32-
var decoupe = DecouperExpression(expression);
33-
nouvellesExpressions.AddRange(decoupe);
32+
var decoupe = DecouperExpression(expression);
33+
nouvellesExpressions.AddRange(decoupe);
3434

35-
nouvellesExpressions.ForEach(ligne =>
35+
nouvellesExpressions.ForEach(ligne =>
36+
{
37+
expressions.Add(new ExpressionElement(lignes[i].Expression.Contains('/'), ligne.Expression.Replace("/", string.Empty).Replace("*", string.Empty)));
38+
});
39+
}
40+
else
3641
{
37-
expressions.Add((lignes[i].Contains('/') ? 'd' : 'n') + ligne.Replace("/", string.Empty).Replace("*", string.Empty));
38-
});
42+
// s'il y a un exposant on ne shell pas l'expression; on garde l'expression
43+
// total avec l'exposant
44+
expressions.Add(lignes[i]);
45+
}
3946
}
4047
}
4148

4249
for (int i = 0; i < expressions.Count; i++)
4350
{
44-
string? expression = expressions[i].Remove(0, 1);
51+
string? expression = expressions[i].Expression.Remove(0, 1);
4552
var decoupe = DecouperExpression(expression, true);
4653
if (decoupe.Count > 1)
4754
{
4855
expressions.RemoveAt(i);
49-
expressions.AddRange(decoupe.ConvertAll(x => expressions[i][0] + x));
56+
expressions.AddRange(decoupe.ConvertAll(x => new ExpressionElement(expressions[i].Interdite, x.Expression)));
5057
i = 0;
5158
}
5259
}
5360

54-
expressions.RemoveAll(x => x.Length == 1);
61+
expressions.RemoveAll(x => x.Expression.Length == 1);
5562

56-
return (expressions.ConvertAll(x => new ExpressionElement(x.StartsWith('d'), x.Remove(0, 1))));
63+
return expressions;
5764
}
5865

5966
private static string SupprimerParentheses(string expression)
@@ -72,14 +79,14 @@ private static string SupprimerParentheses(string expression)
7279
return expression;
7380
}
7481

75-
private static List<string> DecouperExpression(string nouvelleFonction, bool estDeuxieme = false)
82+
private static List<ExpressionElement> DecouperExpression(string nouvelleFonction, bool estDeuxieme = false)
7683
{
7784
if (estDeuxieme)
7885
{
7986
nouvelleFonction = SupprimerParentheses(nouvelleFonction);
8087
}
8188

82-
List<string> lignes = new List<string>();
89+
List<ExpressionElement> lignes = new List<ExpressionElement>();
8390
int compteurParenthesesOuvertes = 0;
8491
int indexDebutLigne = 0;
8592

@@ -95,25 +102,65 @@ private static List<string> DecouperExpression(string nouvelleFonction, bool est
95102

96103
if (compteurParenthesesOuvertes == 0)
97104
{
98-
string ligne = nouvelleFonction.Substring(indexDebutLigne, i - indexDebutLigne + 1);
99-
lignes.Add(ligne);
105+
string exposant = string.Empty;
106+
107+
if (nouvelleFonction.Length > i + 1)
108+
if (nouvelleFonction[i + 1] == '^')
109+
{
110+
// il y a un exposant à l'expression, on la garde en entière
111+
// si l'exposant est 1 chiffre (ex : ^2)
112+
if (nouvelleFonction[i + 2] != '(')
113+
{
114+
exposant += nouvelleFonction[i + 2];
115+
}
116+
else
117+
{
118+
// exposant entre les parenthèses
119+
bool endExp = false;
120+
int z = i + 3; // index dans la parenthèse
121+
int tempOuverte = 0;
122+
while (!endExp)
123+
{
124+
exposant += nouvelleFonction[z];
125+
if (nouvelleFonction[z + 1] == '(')
126+
tempOuverte++;
127+
else if (nouvelleFonction[z + 1] == ')' && tempOuverte > 0)
128+
tempOuverte--;
129+
else if (nouvelleFonction[z + 1] == ')')
130+
// fin de l'exposant
131+
endExp = true;
132+
133+
134+
z++;
135+
}
136+
}
137+
138+
}
139+
140+
ExpressionElement exp = new ExpressionElement(true, nouvelleFonction.Substring(indexDebutLigne, i - indexDebutLigne + 1), exposant);
141+
142+
lignes.Add(exp);
100143
indexDebutLigne = i + 1;
101144
}
102145
}
103146
else if (nouvelleFonction[i] == '/' && compteurParenthesesOuvertes == 0)
104147
{
105148
string ligneInterdite = nouvelleFonction.Substring(indexDebutLigne, i - indexDebutLigne).Trim();
106-
lignes.Add(ligneInterdite);
149+
ExpressionElement exp = new ExpressionElement(true, ligneInterdite, string.Empty);
150+
exp.Interdite = true;
151+
lignes.Add(exp);
107152
indexDebutLigne = i;
108153
}
109154
}
110155

111156
if (indexDebutLigne < nouvelleFonction.Length)
112157
{
113158
string derniereLigne = nouvelleFonction.Substring(indexDebutLigne).Trim();
114-
lignes.Add(derniereLigne);
159+
ExpressionElement exp = new ExpressionElement(true, derniereLigne, string.Empty);
160+
lignes.Add(exp);
115161
}
116162

163+
lignes.RemoveAll(x => x.Expression.StartsWith('^') || String.IsNullOrEmpty(x.Expression)); // enlève les exposants seul
117164
return lignes;
118165
}
119166
}

SignaMath/MainWindow.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public partial class MainWindow : Window
3535
{
3636
internal static MainWindow _MainWindow { get; set; }
3737

38-
private const string VERSION = "1.1.4";
38+
private const string VERSION = "1.1.5";
3939
internal static string BASE_URL { get; } = "https://zoneck.bsite.net";
4040
private Software Software { get; set; }
4141

@@ -200,15 +200,23 @@ private void NewFunctionWrited(string newFunction, bool callUpdateBoard = true)
200200
// Ajoute les nouvelles rows
201201
foreach(var row in rows)
202202
{
203+
string expression = row.Expression;
204+
if(!String.IsNullOrEmpty(row.Exposant))
205+
{
206+
expression = expression.Insert(0, "(") + ")^("; // ajoute des parenthèses englobante
207+
expression += row.Exposant; // Ajoute l'exposant
208+
expression += ")";
209+
}
210+
203211
if(row.Interdite)
204212
{
205213
Button_AddForbiddenValueRow_Click(this, null);
206-
TableauDeSigne.StackPanel_Row.Children.OfType<UserControl_Row>().Last().TextBox_Expression.textBox_clear.Text = row.Expression;
214+
TableauDeSigne.StackPanel_Row.Children.OfType<UserControl_Row>().Last().TextBox_Expression.textBox_clear.Text = expression;
207215
}
208216
else
209217
{
210218
Button_AddRow_Click(this, null);
211-
TableauDeSigne.StackPanel_Row.Children.OfType<UserControl_Row>().Last().TextBox_Expression.textBox_clear.Text = row.Expression;
219+
TableauDeSigne.StackPanel_Row.Children.OfType<UserControl_Row>().Last().TextBox_Expression.textBox_clear.Text = expression;
212220
}
213221
}
214222

SignaMath/UC/Row/UserControl_Row.xaml.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,13 @@ internal void FormulaChanged(string newFormula, bool callUpdateBoard = true)
254254

255255
foreach (string solution in solutions)
256256
{
257+
string _solution = solution.Trim();
258+
257259
// Calcul une approximation de la solution (dans le cas où elle contient un nombre aux décimals infinis)
258-
double approximation = Extension.Extension.StrToDouble(solution.EvalNumerical().Stringize());
260+
double approximation = Extension.Extension.StrToDouble(_solution.EvalNumerical().Stringize());
259261

260262
// On regarde si une colonne dans le tableau existe déjà contenant cette solution
261-
var column = GlobalVariable.TableColumns.FirstOrDefault(x => x.Expression == solution);
263+
var column = GlobalVariable.TableColumns.FirstOrDefault(x => x.Expression == _solution);
262264

263265
// Si la colonne existe déjà, on ajoute cette row à la liste de la colonne
264266
// contenant toutes les rows pour laquelle elle est une solution
@@ -269,7 +271,7 @@ internal void FormulaChanged(string newFormula, bool callUpdateBoard = true)
269271
{
270272
// Sinon, on ajoute une nouvelle colonne au tableau
271273
// avec comme row concerné cette row-ci.
272-
ColumnElement columnElement = new ColumnElement(solution, approximation, new List<int> { RowId });
274+
ColumnElement columnElement = new ColumnElement(_solution, approximation, new List<int> { RowId });
273275
GlobalVariable.TableColumns.Add(columnElement);
274276
}
275277
}
@@ -296,12 +298,15 @@ internal void UpdateRow()
296298
var tableColumns = new List<ColumnElement>(GlobalVariable.TableColumns);
297299
tableColumns.RemoveAll(x => x.Value <= GlobalVariable.IntervalleMin || x.Value >= GlobalVariable.IntervalleMax);
298300

301+
bool? lastArrowUp = null; // contient l'orientation de la flèche de la dernière colonne du tab de variation
302+
// ainsi on peut savoir si on ajoute une nouvelle flèche ou étend la première
303+
299304
// Ajoute, pour chaque colonne du tableau, une colonne dans la ligne
300305
// Le `i` va de 0 à `nombre de colonne + 1` car sinon il manquerait la dernière case dans la row
301306
for (int i = 0; i < tableColumns.Count + 1; i++)
302307
{
303308
// Ajoute la colonne
304-
Grid_RowColumns.ColumnDefinitions.Add(new ColumnDefinition());
309+
Grid_RowColumns.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star)});
305310

306311
// Si c'est la ligne header
307312
if (RowType == RowType.HEADER)
@@ -389,6 +394,24 @@ internal void UpdateRow()
389394
.First(x => x.RowType == RowType.CONCLUANTE).Grid_RowColumns.Children[i]))
390395
.Label_Sign.Content.ToString() == "+";
391396

397+
if (lastArrowUp == isPlus)
398+
{
399+
// étend la flèche de la dernière colonne; supprime donc celle qui vient d'être créé
400+
Grid_RowColumns.ColumnDefinitions.RemoveAt(Grid_RowColumns.ColumnDefinitions.Count - 1);
401+
Grid_RowColumns.ColumnDefinitions.Last().Width = new GridLength(Grid_RowColumns.ColumnDefinitions.Last().Width.Value + 1, GridUnitType.Star);
402+
break;
403+
}
404+
else
405+
{
406+
lastArrowUp = isPlus;
407+
408+
// si c'est une valeur interdite alors on force le fait que la prochaine row ai sa propre flèche
409+
if (i != tableColumns.Count)
410+
if (tableColumns[i].ValeurInterdite)
411+
lastArrowUp = null;
412+
}
413+
414+
392415
// Set l'image de la flèche
393416
userControl_CellSign.Image_Arrow.Source = isPlus ? MainWindow._MainWindow.img_arrowTemplateTop.Source : MainWindow._MainWindow.img_arrowTemplateBottom.Source;
394417
userControl_CellSign.Image_Arrow.Visibility = Visibility.Visible;
@@ -521,15 +544,11 @@ internal void UpdateRow()
521544
{
522545
// Set la colonne entière en tant que valeur interdite (pour le tableau de variation)
523546
tableColumns[i].ValeurInterdite = true;
524-
525-
// Affiche la seconde barre
526-
userControl_CellSign.Border_SecondeBarre.Visibility = Visibility.Visible;
527-
}
528-
else
529-
{
530-
// Ce n'est pas une valeur interdite, on affiche le '0'
531-
userControl_CellSign.Label_Zero.Visibility = Visibility.Visible;
532547
}
548+
549+
// on affiche le '0'
550+
userControl_CellSign.Label_Zero.Visibility = Visibility.Visible;
551+
533552
}
534553

535554
// Enfin, place le signe de l'expression entre la colonne d'avant et la colonne actuelle

0 commit comments

Comments
 (0)