Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 0f56328

Browse files
committed
Исправление логики вычислений
1 parent efac724 commit 0f56328

5 files changed

Lines changed: 166 additions & 196 deletions

File tree

Interfaces/INotificationService.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace ParametricFunctionApp.Interfaces;
22
public interface INotificationService
33
{
4-
Task ShowSuccessAsync(string message, string title = "Успешно");
5-
Task ShowErrorAsync(string message, string title = "Ошибка");
4+
Task ShowErrorAsync(string message);
5+
Task ShowSuccessAsync(string message);
66
Task ShowInfoAsync(string message, string title = "Информация");
7-
Task<string> ShowPromptAsync(string title, string message, string accept = "OK", string cancel = "Отмена",
8-
string placeholder = "", int maxLength = -1, Keyboard keyboard = null);
9-
Task<bool> ShowConfirmationAsync(string title, string message, string accept = "Да", string cancel = "Нет");
7+
Task<string> ShowPromptAsync(string title, string message, string accept = "OK", string cancel = "Cancel", string placeholder = null, int maxLength = -1, Keyboard keyboard = null);
108
}

Services/NotificationService.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,30 @@ namespace ParametricFunctionApp.Services;
55

66
public class NotificationService : INotificationService
77
{
8-
private readonly Page _page;
8+
private readonly ContentPage _page;
99

10-
public NotificationService(Page page)
10+
public NotificationService(ContentPage page)
1111
{
12-
_page = page ?? throw new ArgumentNullException(nameof(page));
12+
_page = page;
1313
}
1414

15-
public async Task ShowSuccessAsync(string message, string title = "Успешно")
15+
public async Task ShowErrorAsync(string message)
1616
{
17-
await _page.DisplayAlert(title, message, "OK");
17+
await _page.DisplayAlert("Ошибка", message, "OK");
1818
}
1919

20-
public async Task ShowErrorAsync(string message, string title = "Ошибка")
20+
public async Task ShowSuccessAsync(string message)
2121
{
22-
await _page.DisplayAlert(title, message, "OK");
22+
await _page.DisplayAlert("Успех", message, "OK");
2323
}
2424

2525
public async Task ShowInfoAsync(string message, string title = "Информация")
2626
{
2727
await _page.DisplayAlert(title, message, "OK");
2828
}
2929

30-
public async Task<string> ShowPromptAsync(string title, string message, string accept = "OK", string cancel = "Отмена",
31-
string placeholder = "", int maxLength = -1, Keyboard keyboard = null)
30+
public async Task<string> ShowPromptAsync(string title, string message, string accept = "OK", string cancel = "Cancel", string placeholder = null, int maxLength = -1, Keyboard keyboard = null)
3231
{
3332
return await _page.DisplayPromptAsync(title, message, accept, cancel, placeholder, maxLength, keyboard);
3433
}
35-
36-
public async Task<bool> ShowConfirmationAsync(string title, string message, string accept = "Да", string cancel = "Нет")
37-
{
38-
return await _page.DisplayAlert(title, message, accept, cancel);
39-
}
4034
}

ViewModels/MainPageViewModel.cs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
using System.Runtime.CompilerServices;
44
using ParametricFunctionApp.Models;
55
using ParametricFunctionApp.Controls;
6-
using AudioUnit;
76
using ParametricFunctionApp.Interfaces;
87

98
namespace ParametricFunctionApp.ViewModels;
109

1110
public class MainPageViewModel : INotifyPropertyChanged
1211
{
1312
private readonly INotificationService _notificationService;
14-
private double _enterK;
15-
private double _kd;
16-
private double _enterA;
17-
private double _k1;
13+
private double _coefficientK;
14+
private double _stepCoefficient;
15+
private double _parameterA;
16+
private double _initialX;
1817
private bool _kSet = false;
1918
private bool _kdSet = false;
2019
private bool _aSet = false;
21-
private bool _k1Set = false;
20+
private bool _x1Set = false;
2221
private List<stRecursion> _recOut = new List<stRecursion>();
2322
private GraphDrawable _graphDrawable;
2423
private AppSettings _settings = new AppSettings();
@@ -34,54 +33,50 @@ public MainPageViewModel(INotificationService notificationService)
3433
PropertyChanged = delegate { };
3534
}
3635

37-
public double EnterK
36+
public double CoefficientK
3837
{
39-
get => _enterK;
38+
get => _coefficientK;
4039
set
4140
{
42-
if (SetProperty(ref _enterK, value))
41+
if (SetProperty(ref _coefficientK, value))
4342
{
4443
ValidateInputs();
45-
OnPropertyChanged(nameof(EnterK));
4644
}
4745
}
4846
}
4947

50-
public double Kd
48+
public double StepCoefficient
5149
{
52-
get => _kd;
50+
get => _stepCoefficient;
5351
set
5452
{
55-
if (SetProperty(ref _kd, value))
53+
if (SetProperty(ref _stepCoefficient, value))
5654
{
5755
ValidateInputs();
58-
OnPropertyChanged(nameof(Kd));
5956
}
6057
}
6158
}
6259

63-
public double EnterA
60+
public double ParameterA
6461
{
65-
get => _enterA;
62+
get => _parameterA;
6663
set
6764
{
68-
if (SetProperty(ref _enterA, value))
65+
if (SetProperty(ref _parameterA, value))
6966
{
7067
ValidateInputs();
71-
OnPropertyChanged(nameof(EnterA));
7268
}
7369
}
7470
}
7571

76-
public double K1
72+
public double InitialX
7773
{
78-
get => _k1;
74+
get => _initialX;
7975
set
8076
{
81-
if (SetProperty(ref _k1, value))
77+
if (SetProperty(ref _initialX, value))
8278
{
8379
ValidateInputs();
84-
OnPropertyChanged(nameof(K1));
8580
}
8681
}
8782
}
@@ -103,10 +98,11 @@ public bool ASet
10398
get => _aSet;
10499
set => SetProperty(ref _aSet, value);
105100
}
106-
public bool K1Set
101+
102+
public bool X1Set
107103
{
108-
get => _k1Set;
109-
set => SetProperty(ref _k1Set, value);
104+
get => _x1Set;
105+
set => SetProperty(ref _x1Set, value);
110106
}
111107

112108
public List<stRecursion> RecOut
@@ -142,36 +138,35 @@ public int PointsCount
142138
{
143139
_settings.PointsCount = value;
144140
ValidateInputs();
145-
OnPropertyChanged(nameof(PointsCount));
146141
}
147142
}
148143
}
149144

150145
public void ResetK()
151146
{
152-
EnterK = 0;
147+
CoefficientK = 0;
153148
KSet = false;
154149
ValidateInputs();
155150
}
156151

157152
public void ResetKd()
158153
{
159-
Kd = 0;
154+
StepCoefficient = 0;
160155
KdSet = false;
161156
ValidateInputs();
162157
}
163158

164159
public void ResetA()
165160
{
166-
EnterA = 0;
161+
ParameterA = 0;
167162
ASet = false;
168163
ValidateInputs();
169164
}
170165

171-
public void ResetK1()
166+
public void ResetX1()
172167
{
173-
K1 = 0;
174-
K1Set = false;
168+
InitialX = 0;
169+
X1Set = false;
175170
ValidateInputs();
176171
}
177172

@@ -183,7 +178,7 @@ public async Task<bool> SetKValueAsync(string input)
183178
return false;
184179
}
185180

186-
EnterK = Math.Round(value, 1);
181+
CoefficientK = Math.Round(value, 1);
187182
KSet = true;
188183
return true;
189184
}
@@ -202,7 +197,7 @@ public async Task<bool> SetKdValueAsync(string input)
202197
return false;
203198
}
204199

205-
Kd = Math.Round(value, 1);
200+
StepCoefficient = Math.Round(value, 1);
206201
KdSet = true;
207202
return true;
208203
}
@@ -215,21 +210,27 @@ public async Task<bool> SetAValueAsync(string input)
215210
return false;
216211
}
217212

218-
EnterA = Math.Round(value, 1);
213+
if (value <= 0)
214+
{
215+
await _notificationService.ShowErrorAsync("Параметр A должен быть положительным числом");
216+
return false;
217+
}
218+
219+
ParameterA = Math.Round(value, 1);
219220
ASet = true;
220221
return true;
221222
}
222223

223-
public async Task<bool> SetK1ValueAsync(string input)
224+
public async Task<bool> SetX1ValueAsync(string input)
224225
{
225226
if (!ValidateAndParseDouble(input, out double value))
226227
{
227228
await _notificationService.ShowErrorAsync("Введите числовое значение с максимум 1 знаком после запятой");
228229
return false;
229230
}
230231

231-
K1 = Math.Round(value, 1);
232-
K1Set = true;
232+
InitialX = Math.Round(value, 1);
233+
X1Set = true;
233234
return true;
234235
}
235236

@@ -243,7 +244,6 @@ await _notificationService.ShowInfoAsync(
243244
"О программе");
244245
}
245246

246-
247247
public bool ValidateAndParseDouble(string input, out double result)
248248
{
249249
input = input.Replace('.', ',');
@@ -270,7 +270,7 @@ private int GetDecimalPlaces(string numberString)
270270

271271
public bool CanCalculate()
272272
{
273-
return KSet && KdSet && !HasErrors && PointsCount > 0;
273+
return KSet && KdSet && ASet && X1Set && !HasErrors && PointsCount > 0;
274274
}
275275

276276
private void ValidateInputs()
@@ -285,37 +285,36 @@ private void ValidateInputs()
285285
return;
286286
}
287287

288-
if (ASet && EnterA <= 0)
288+
if (ASet && ParameterA <= 0)
289289
{
290290
HasErrors = true;
291291
ErrorMessage = "Параметр A должен быть положительным числом (A > 0)";
292292
return;
293293
}
294294

295-
if (KSet && KdSet && ASet)
296-
{
297-
if (Kd <= 0)
298-
{
299-
HasErrors = true;
300-
ErrorMessage = "Шаг kd должен быть положительным числом (kd > 0)";
301-
return;
302-
}
303-
304-
double x1 = EnterK * EnterA + K1;
305-
double step = EnterA * Kd;
306-
double lastX = x1 + (PointsCount - 1) * step;
295+
if (KdSet && StepCoefficient <= 0)
296+
{
297+
HasErrors = true;
298+
ErrorMessage = "Шаг kd должен быть положительным числом (kd > 0)";
299+
return;
300+
}
301+
302+
if (KSet && KdSet && ASet && X1Set)
303+
{
304+
double step = ParameterA * StepCoefficient;
305+
double lastX = InitialX + (PointsCount - 1) * step;
307306

308-
if (lastX >= EnterA)
307+
if (lastX >= ParameterA)
309308
{
310309
HasErrors = true;
311-
ErrorMessage = $"Ошибка: конечное значение x ({lastX:F1}) должно быть меньше A = {EnterA} (ограничение: x < A). Уменьшите количество точек N или шаг kd.";
310+
ErrorMessage = $"Ошибка: конечное значение x ({lastX:F1}) должно быть меньше A = {ParameterA} (ограничение: x < A). Уменьшите количество точек N или шаг kd.";
312311
return;
313312
}
314313

315-
if (x1 >= EnterA)
314+
if (InitialX >= ParameterA)
316315
{
317316
HasErrors = true;
318-
ErrorMessage = $"Ошибка: начальное значение x ({x1:F1}) должно быть меньше A = {EnterA} (ограничение: x < A). Уменьшите коэффициент k.";
317+
ErrorMessage = $"Ошибка: начальное значение x ({InitialX:F1}) должно быть меньше A = {ParameterA} (ограничение: x < A).";
319318
return;
320319
}
321320
}
@@ -330,32 +329,33 @@ public void CalculateFunction()
330329

331330
var newRecOut = new List<stRecursion>();
332331

333-
double boundary = EnterK * EnterA;
334-
double step = EnterA * Kd;
335-
double x = K1;
332+
double boundary = CoefficientK * ParameterA;
333+
double step = ParameterA * StepCoefficient;
334+
double x = InitialX;
336335

337336
for (int i = 0; i < PointsCount; i++)
338337
{
339-
if (x >= EnterA)
338+
if (x >= ParameterA)
340339
{
341340
continue;
342341
}
343342

344343
double y;
345-
344+
346345
if (x < boundary)
347-
y = EnterA * Math.Sqrt(Math.Abs(x + 2 * EnterA));
346+
y = ParameterA * Math.Sqrt(Math.Abs(x + 2 * ParameterA));
348347
else
349-
y = EnterA * Math.Cos(x + 1) + EnterA;
348+
y = ParameterA * Math.Cos(x + 1) + ParameterA;
350349

351-
newRecOut.Add(new stRecursion(i + 1, x, y));
350+
newRecOut.Add(new stRecursion(i + 1, Math.Round(x, 3), Math.Round(y, 3)));
352351
x += step;
353352
}
354353

355354
RecOut = newRecOut;
356355
GraphDrawable.DataPoints = newRecOut;
357356
OnPropertyChanged(nameof(GraphDrawable));
358357
}
358+
359359
public event PropertyChangedEventHandler? PropertyChanged;
360360

361361
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)

Views/MainPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<Button Grid.Column="1"
130130
Grid.Row="1"
131131
Text="Ввести k1"
132-
Clicked="OnEnterK1Cliked"
132+
Clicked="OnEnterX1Clicked"
133133
Style="{StaticResource FluentButton}"/>
134134
</Grid>
135135
</VerticalStackLayout>

0 commit comments

Comments
 (0)