v2.1.0: Fluidity, responsiveness and zero-freeze performance optimization update
This commit is contained in:
parent
72e2fcf145
commit
2d44405e9f
12 changed files with 674 additions and 419 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DotNetMatrix;
|
||||
|
||||
|
|
@ -80,11 +81,14 @@ namespace MathApp.Controls
|
|||
}
|
||||
}
|
||||
|
||||
private void BtnPascal_Click(object sender, EventArgs e)
|
||||
private async void BtnPascal_Click(object sender, EventArgs e)
|
||||
{
|
||||
Cursor = Cursors.WaitCursor;
|
||||
try
|
||||
{
|
||||
int n = (int)numN.Value;
|
||||
string result = await Task.Run(() =>
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"=== PASCAL UCGENI & BINOM KATSAYILARI (Derece n = {n}) ===");
|
||||
sb.AppendLine($"(a + b)^{n} açılımının katsayıları:");
|
||||
|
|
@ -100,16 +104,22 @@ namespace MathApp.Controls
|
|||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
return sb.ToString();
|
||||
});
|
||||
|
||||
txtOutput.Text = sb.ToString();
|
||||
txtOutput.Text = result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtOutput.Text = "Hata: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnGenStrings_Click(object sender, EventArgs e)
|
||||
private async void BtnGenStrings_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -136,6 +146,11 @@ namespace MathApp.Controls
|
|||
if (dr != DialogResult.Yes) return;
|
||||
}
|
||||
|
||||
Cursor = Cursors.WaitCursor;
|
||||
btnGenStrings.Enabled = false;
|
||||
|
||||
string result = await Task.Run(() =>
|
||||
{
|
||||
string generated = NumericalMethods.GenerateCombinations(alphabet, prefix, length);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -146,13 +161,20 @@ namespace MathApp.Controls
|
|||
sb.AppendLine($"Toplam Sonuç : {totalCount:N0} adet");
|
||||
sb.AppendLine(new string('-', 45));
|
||||
sb.Append(generated);
|
||||
return sb.ToString();
|
||||
});
|
||||
|
||||
txtOutput.Text = sb.ToString();
|
||||
txtOutput.Text = result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtOutput.Text = "Kombinasyon Üretim Hatası: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnGenStrings.Enabled = true;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnPolarConvert_Click(object sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Drawing;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MathApp.Controls
|
||||
|
|
@ -92,8 +93,13 @@ namespace MathApp.Controls
|
|||
throw new ArgumentException($"'{field}' için geçerli bir sayı giriniz.");
|
||||
}
|
||||
|
||||
private void BtnCalcSingle_Click(object sender, EventArgs e)
|
||||
private async void BtnCalcSingle_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnCalcSingle.Text;
|
||||
btnCalcSingle.Enabled = false;
|
||||
btnCalcSingle.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
string eq = txtSingleFn.Text.Trim();
|
||||
|
|
@ -105,6 +111,8 @@ namespace MathApp.Controls
|
|||
int deg = (int)numSingleDegree.Value;
|
||||
int acc = (cmbAccuracy.SelectedIndex + 1) * 2; // 2, 4, 6
|
||||
|
||||
string resultText = await Task.Run(() =>
|
||||
{
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
try
|
||||
|
|
@ -133,21 +141,35 @@ namespace MathApp.Controls
|
|||
sb.AppendLine($" • f^({k})({pt}) = {Math.Round(dk, 6).ToString("0.######", CultureInfo.InvariantCulture)}");
|
||||
}
|
||||
|
||||
txtResult.Text = sb.ToString();
|
||||
return sb.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Function.UseRadians = prevRad;
|
||||
}
|
||||
});
|
||||
|
||||
txtResult.Text = resultText;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtResult.Text = "❌ Hata: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnCalcSingle.Enabled = true;
|
||||
btnCalcSingle.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnCalcPartial_Click(object sender, EventArgs e)
|
||||
private async void BtnCalcPartial_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnCalcPartial.Text;
|
||||
btnCalcPartial.Enabled = false;
|
||||
btnCalcPartial.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
string eq = txtPartialFn.Text.Trim();
|
||||
|
|
@ -171,6 +193,8 @@ namespace MathApp.Controls
|
|||
return;
|
||||
}
|
||||
|
||||
string resultText = await Task.Run(() =>
|
||||
{
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
try
|
||||
|
|
@ -200,17 +224,26 @@ namespace MathApp.Controls
|
|||
}
|
||||
sb.AppendLine($" ∇f({ptStr}) = [ {string.Join(", ", gradParts)} ]");
|
||||
|
||||
txtResult.Text = sb.ToString();
|
||||
return sb.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Function.UseRadians = prevRad;
|
||||
}
|
||||
});
|
||||
|
||||
txtResult.Text = resultText;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtResult.Text = "❌ Hata: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnCalcPartial.Enabled = true;
|
||||
btnCalcPartial.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,24 @@ namespace MathApp.Controls
|
|||
private bool didMoveMouse = false;
|
||||
private Point lastMousePos;
|
||||
private Point? hoverMousePos = null;
|
||||
private Point lastHoverRecorded = new Point(-999, -999);
|
||||
private Timer resampleDebounceTimer;
|
||||
|
||||
public GraphPlotterControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
resampleDebounceTimer = new Timer { Interval = 50 };
|
||||
resampleDebounceTimer.Tick += (s, e) =>
|
||||
{
|
||||
resampleDebounceTimer.Stop();
|
||||
if (!isDragging && compiledFn != null)
|
||||
{
|
||||
GeneratePoints(false, isDraft: false);
|
||||
pnlCanvas.Invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
// Enable DoubleBuffering on pnlCanvas to prevent flickering during pan/zoom
|
||||
typeof(Panel).InvokeMember(
|
||||
"DoubleBuffered",
|
||||
|
|
@ -120,12 +133,14 @@ namespace MathApp.Controls
|
|||
return def;
|
||||
}
|
||||
|
||||
private void GeneratePoints(bool autoFitY)
|
||||
private void GeneratePoints(bool autoFitY, bool isDraft = false)
|
||||
{
|
||||
segments.Clear();
|
||||
if (compiledFn == null) return;
|
||||
|
||||
int sampleCount = Math.Max(600, pnlCanvas.Width * 2);
|
||||
int sampleCount = isDraft
|
||||
? Math.Min(220, Math.Max(120, pnlCanvas.Width / 3))
|
||||
: Math.Max(600, pnlCanvas.Width * 2);
|
||||
float step = (rangeMaxX - rangeMinX) / sampleCount;
|
||||
if (step <= 0) return;
|
||||
|
||||
|
|
@ -229,7 +244,10 @@ namespace MathApp.Controls
|
|||
txtMinX.Text = rangeMinX.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
|
||||
GeneratePoints(false);
|
||||
// Fast preview during continuous wheel spin, debounce high-res
|
||||
GeneratePoints(false, isDraft: true);
|
||||
resampleDebounceTimer.Stop();
|
||||
resampleDebounceTimer.Start();
|
||||
pnlCanvas.Invalidate();
|
||||
}
|
||||
|
||||
|
|
@ -247,10 +265,9 @@ namespace MathApp.Controls
|
|||
|
||||
private void PnlCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
hoverMousePos = e.Location;
|
||||
|
||||
if (isDragging)
|
||||
{
|
||||
hoverMousePos = e.Location;
|
||||
int dx = e.X - lastMousePos.X;
|
||||
int dy = e.Y - lastMousePos.Y;
|
||||
|
||||
|
|
@ -277,11 +294,23 @@ namespace MathApp.Controls
|
|||
txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
|
||||
lastMousePos = e.Location;
|
||||
GeneratePoints(false);
|
||||
}
|
||||
|
||||
// Fluid high-FPS drag preview
|
||||
GeneratePoints(false, isDraft: true);
|
||||
resampleDebounceTimer.Stop();
|
||||
resampleDebounceTimer.Start();
|
||||
pnlCanvas.Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Throttle hover redraws: only repaint when moved at least 2 pixels
|
||||
if (Math.Abs(e.X - lastHoverRecorded.X) >= 2 || Math.Abs(e.Y - lastHoverRecorded.Y) >= 2)
|
||||
{
|
||||
lastHoverRecorded = e.Location;
|
||||
hoverMousePos = e.Location;
|
||||
pnlCanvas.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PnlCanvas_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
|
|
@ -315,6 +344,8 @@ namespace MathApp.Controls
|
|||
}
|
||||
|
||||
isDragging = false;
|
||||
resampleDebounceTimer.Stop();
|
||||
GeneratePoints(false, isDraft: false);
|
||||
Cursor = Cursors.Cross;
|
||||
pnlCanvas.Invalidate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DotNetMatrix;
|
||||
|
||||
|
|
@ -228,88 +229,139 @@ namespace MathApp.Controls
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void RunBinaryOperation(string op)
|
||||
private async void RunBinaryOperation(string op)
|
||||
{
|
||||
Cursor = Cursors.WaitCursor;
|
||||
try
|
||||
{
|
||||
GeneralMatrix A = ReadMatrix(gridCellsA, rowsA, colsA, "A");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string sRaw = txtScalar.Text.Trim().Replace(',', '.');
|
||||
GeneralMatrix B = null;
|
||||
decimal k = 0m;
|
||||
|
||||
if (op == "SCALAR")
|
||||
{
|
||||
string sRaw = txtScalar.Text.Trim().Replace(',', '.');
|
||||
if (!decimal.TryParse(sRaw, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal k))
|
||||
if (!decimal.TryParse(sRaw, NumberStyles.Any, CultureInfo.InvariantCulture, out k))
|
||||
{
|
||||
txtResult.Text = "❌ Geçerli bir skaler çarpan (k) giriniz.";
|
||||
return;
|
||||
}
|
||||
GeneralMatrix res = A.Multiply(k);
|
||||
lastResultMatrix = res;
|
||||
sb.AppendLine($"=== SKALER ÇARPIM (k · A, k = {k}) ===");
|
||||
sb.Append(FormatMatrix(res));
|
||||
txtResult.Text = sb.ToString();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = ReadMatrix(gridCellsB, rowsB, colsB, "B");
|
||||
}
|
||||
|
||||
GeneralMatrix B = ReadMatrix(gridCellsB, rowsB, colsB, "B");
|
||||
|
||||
if (op == "ADD")
|
||||
var (resultMatrix, outputText) = await Task.Run(() =>
|
||||
{
|
||||
lastResultMatrix = A + B;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
GeneralMatrix res = null;
|
||||
|
||||
if (op == "SCALAR")
|
||||
{
|
||||
res = A.Multiply(k);
|
||||
sb.AppendLine($"=== SKALER ÇARPIM (k · A, k = {k}) ===");
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "ADD")
|
||||
{
|
||||
res = A + B;
|
||||
sb.AppendLine("=== MATRİS TOPLAMI (A + B) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "SUB")
|
||||
{
|
||||
lastResultMatrix = A - B;
|
||||
res = A - B;
|
||||
sb.AppendLine("=== MATRİS FARKI (A - B) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "MUL")
|
||||
{
|
||||
lastResultMatrix = A * B;
|
||||
res = A * B;
|
||||
sb.AppendLine($"=== MATRİS ÇARPIMI (A × B) [{rowsA}x{colsA}] · [{rowsB}x{colsB}] ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "ELEM_MUL")
|
||||
{
|
||||
lastResultMatrix = A.ArrayMultiply(B);
|
||||
res = A.ArrayMultiply(B);
|
||||
sb.AppendLine("=== ELEMAN BAZLI (HADAMARD) ÇARPIM (A .* B) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "ELEM_DIV")
|
||||
{
|
||||
lastResultMatrix = A.ArrayRightDivide(B);
|
||||
res = A.ArrayRightDivide(B);
|
||||
sb.AppendLine("=== ELEMAN BAZLI BÖLME (A ./ B) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "SOLVE")
|
||||
{
|
||||
lastResultMatrix = A.Solve(B);
|
||||
res = A.Solve(B);
|
||||
sb.AppendLine("=== MATRİS DENKLEMİ ÇÖZÜMÜ (A · X = B => X) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
else if (op == "SOLVE_TRANS")
|
||||
{
|
||||
lastResultMatrix = A.SolveTranspose(B);
|
||||
res = A.SolveTranspose(B);
|
||||
sb.AppendLine("=== TRANSPOZ MATRİS DENKLEMİ ÇÖZÜMÜ (Aᵀ · Xᵀ = Bᵀ) ===");
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
|
||||
txtResult.Text = sb.ToString();
|
||||
return (res, sb.ToString());
|
||||
});
|
||||
|
||||
if (resultMatrix != null)
|
||||
{
|
||||
lastResultMatrix = resultMatrix;
|
||||
}
|
||||
txtResult.Text = outputText;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtResult.Text = "❌ İşlem Hatası: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void RunUnaryOperation(string op)
|
||||
private async void RunUnaryOperation(string op)
|
||||
{
|
||||
Cursor = Cursors.WaitCursor;
|
||||
try
|
||||
{
|
||||
GeneralMatrix A = ReadMatrix(gridCellsA, rowsA, colsA, "A");
|
||||
|
||||
if (op == "LU" && rowsA < colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ LU Ayrışımı için satır sayısı sütun sayısına eşit veya büyük (m >= n) olmalıdır.";
|
||||
return;
|
||||
}
|
||||
if (op == "QR" && rowsA < colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ QR Ayrışımı için satır sayısı sütun sayısına eşit veya büyük (m >= n) olmalıdır.";
|
||||
return;
|
||||
}
|
||||
if (op == "CHOLESKY" && rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Cholesky Ayrışımı yalnızca kare matrisler için uygulanabilir.";
|
||||
return;
|
||||
}
|
||||
if (op == "EIGEN" && rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Özdeğer & Özvektör analizi yalnızca kare (N x N) matrisler için yapılabilir.";
|
||||
return;
|
||||
}
|
||||
if (op == "INVERSE" && rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Ters matris ve determinant yalnızca kare (N x N) matrisler için hesaplanabilir.";
|
||||
return;
|
||||
}
|
||||
|
||||
var (resultMatrix, outputText) = await Task.Run(() =>
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
GeneralMatrix res = null;
|
||||
|
||||
if (op == "ALL")
|
||||
{
|
||||
|
|
@ -358,11 +410,6 @@ namespace MathApp.Controls
|
|||
}
|
||||
else if (op == "LU")
|
||||
{
|
||||
if (rowsA < colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ LU Ayrışımı için satır sayısı sütun sayısına eşit veya büyük (m >= n) olmalıdır.";
|
||||
return;
|
||||
}
|
||||
LUDecomposition lu = A.LUD();
|
||||
sb.AppendLine("=== LU AYRIŞIMI (P·A = L·U) ===");
|
||||
sb.AppendLine($"Tekil Olmama Durumu (Non-Singular): {(lu.IsNonSingular ? "Evet (Tersinir)" : "Hayır (Tekil)")}");
|
||||
|
|
@ -378,11 +425,6 @@ namespace MathApp.Controls
|
|||
}
|
||||
else if (op == "QR")
|
||||
{
|
||||
if (rowsA < colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ QR Ayrışımı için satır sayısı sütun sayısına eşit veya büyük (m >= n) olmalıdır.";
|
||||
return;
|
||||
}
|
||||
QRDecomposition qr = A.QRD();
|
||||
sb.AppendLine("=== QR AYRIŞIMI (A = Q·R) ===");
|
||||
sb.AppendLine($"Tam Rank (Full Rank): {(qr.FullRank ? "Evet" : "Hayır")}");
|
||||
|
|
@ -398,11 +440,6 @@ namespace MathApp.Controls
|
|||
}
|
||||
else if (op == "CHOLESKY")
|
||||
{
|
||||
if (rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Cholesky Ayrışımı yalnızca kare matrisler için uygulanabilir.";
|
||||
return;
|
||||
}
|
||||
CholeskyDecomposition chol = A.chol();
|
||||
sb.AppendLine("=== CHOLESKY AYRIŞIMI (A = L·Lᵀ) ===");
|
||||
sb.AppendLine($"Simetrik Pozitif Tanımlı (SPD): {(chol.SPD ? "Evet ✓" : "Hayır ✕")}");
|
||||
|
|
@ -433,11 +470,6 @@ namespace MathApp.Controls
|
|||
}
|
||||
else if (op == "EIGEN")
|
||||
{
|
||||
if (rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Özdeğer & Özvektör analizi yalnızca kare (N x N) matrisler için yapılabilir.";
|
||||
return;
|
||||
}
|
||||
EigenvalueDecomposition eig = A.Eigen();
|
||||
sb.AppendLine("=== ÖZDEĞER VE ÖZVEKTÖR ANALİZİ (A·v = λ·v) ===");
|
||||
decimal[] realEigs = eig.RealEigenvalues;
|
||||
|
|
@ -458,11 +490,6 @@ namespace MathApp.Controls
|
|||
}
|
||||
else if (op == "INVERSE")
|
||||
{
|
||||
if (rowsA != colsA)
|
||||
{
|
||||
txtResult.Text = "⚠️ Ters matris ve determinant yalnızca kare (N x N) matrisler için hesaplanabilir.";
|
||||
return;
|
||||
}
|
||||
decimal det = A.Determinant();
|
||||
sb.AppendLine($"=== TERS MATRİS (A⁻¹) & DETERMİNANT ===");
|
||||
sb.AppendLine($"Determinant det(A) = {Math.Round(det, 6)}");
|
||||
|
|
@ -474,17 +501,28 @@ namespace MathApp.Controls
|
|||
else
|
||||
{
|
||||
sb.AppendLine("--- Ters Matris (A⁻¹) ---");
|
||||
lastResultMatrix = A.Inverse();
|
||||
sb.Append(FormatMatrix(lastResultMatrix));
|
||||
res = A.Inverse();
|
||||
sb.Append(FormatMatrix(res));
|
||||
}
|
||||
}
|
||||
|
||||
txtResult.Text = sb.ToString();
|
||||
return (res, sb.ToString());
|
||||
});
|
||||
|
||||
if (resultMatrix != null)
|
||||
{
|
||||
lastResultMatrix = resultMatrix;
|
||||
}
|
||||
txtResult.Text = outputText;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
txtResult.Text = "❌ Hesaplama Hatası: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MathApp.Controls
|
||||
|
|
@ -74,8 +75,13 @@ namespace MathApp.Controls
|
|||
variableRows.Add(row);
|
||||
}
|
||||
|
||||
private void BtnCalculate_Click(object sender, EventArgs e)
|
||||
private async void BtnCalculate_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnCalculate.Text;
|
||||
btnCalculate.Enabled = false;
|
||||
btnCalculate.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
string eq = txtEquation.Text.Trim();
|
||||
|
|
@ -114,17 +120,19 @@ namespace MathApp.Controls
|
|||
return;
|
||||
}
|
||||
|
||||
string result = await Task.Run(() =>
|
||||
{
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
string result;
|
||||
try
|
||||
{
|
||||
result = NumericalMethods.MethodMultiVar_TaylorSeries(eq, degree, points);
|
||||
return NumericalMethods.MethodMultiVar_TaylorSeries(eq, degree, points);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Function.UseRadians = prevRad;
|
||||
}
|
||||
});
|
||||
|
||||
string varsList = string.Join(", ", points.Keys);
|
||||
string centerList = string.Join(", ", points.Select(kv => $"{kv.Key}₀={kv.Value}"));
|
||||
|
|
@ -139,6 +147,12 @@ namespace MathApp.Controls
|
|||
{
|
||||
txtResult.Text = "❌ Hata: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnCalculate.Enabled = true;
|
||||
btnCalculate.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MathApp.Controls
|
||||
|
|
@ -100,8 +101,13 @@ namespace MathApp.Controls
|
|||
throw new ArgumentException($"'{fieldName}' alanı için geçerli bir sayı giriniz.");
|
||||
}
|
||||
|
||||
private void BtnFindRoot_Click(object sender, EventArgs e)
|
||||
private async void BtnFindRoot_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnFindRoot.Text;
|
||||
btnFindRoot.Enabled = false;
|
||||
btnFindRoot.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
string eq = txtEquation.Text.Trim();
|
||||
|
|
@ -118,34 +124,39 @@ namespace MathApp.Controls
|
|||
iterCount = 50;
|
||||
|
||||
int idx = cmbMethod.SelectedIndex;
|
||||
List<string> logs;
|
||||
string initPtText = txtInitialPoint.Text;
|
||||
string minXText = txtMinX.Text;
|
||||
string maxXText = txtMaxX.Text;
|
||||
|
||||
var (logs, finalRoot) = await Task.Run(() =>
|
||||
{
|
||||
List<string> stepLogs;
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
try
|
||||
{
|
||||
if (idx == 0) // Newton-Raphson
|
||||
{
|
||||
decimal initialP = ParseDecimal(txtInitialPoint.Text, "Başlangıç Noktası (x₀)");
|
||||
logs = NumericalMethods.Method_NewtonRaphson(eq, initialP, iterCount, variable);
|
||||
decimal initialP = ParseDecimal(initPtText, "Başlangıç Noktası (x₀)");
|
||||
stepLogs = NumericalMethods.Method_NewtonRaphson(eq, initialP, iterCount, variable);
|
||||
}
|
||||
else if (idx == 1) // Bisection
|
||||
{
|
||||
decimal minX = ParseDecimal(txtMinX.Text, "Alt Sınır (a)");
|
||||
decimal maxX = ParseDecimal(txtMaxX.Text, "Üst Sınır (b)");
|
||||
logs = NumericalMethods.Method_Bisection(eq, minX, maxX, iterCount, variable);
|
||||
decimal minX = ParseDecimal(minXText, "Alt Sınır (a)");
|
||||
decimal maxX = ParseDecimal(maxXText, "Üst Sınır (b)");
|
||||
stepLogs = NumericalMethods.Method_Bisection(eq, minX, maxX, iterCount, variable);
|
||||
}
|
||||
else if (idx == 2) // Secant
|
||||
{
|
||||
decimal minX = ParseDecimal(txtMinX.Text, "Başlangıç 1 (x₀)");
|
||||
decimal maxX = ParseDecimal(txtMaxX.Text, "Başlangıç 2 (x₁)");
|
||||
logs = NumericalMethods.Method_Secant(eq, minX, maxX, iterCount, variable);
|
||||
decimal minX = ParseDecimal(minXText, "Başlangıç 1 (x₀)");
|
||||
decimal maxX = ParseDecimal(maxXText, "Başlangıç 2 (x₁)");
|
||||
stepLogs = NumericalMethods.Method_Secant(eq, minX, maxX, iterCount, variable);
|
||||
}
|
||||
else // Regula Falsi
|
||||
{
|
||||
decimal minX = ParseDecimal(txtMinX.Text, "Alt Sınır (a)");
|
||||
decimal maxX = ParseDecimal(txtMaxX.Text, "Üst Sınır (b)");
|
||||
logs = NumericalMethods.Method_RegulaFalsi(eq, minX, maxX, iterCount, variable);
|
||||
decimal minX = ParseDecimal(minXText, "Alt Sınır (a)");
|
||||
decimal maxX = ParseDecimal(maxXText, "Üst Sınır (b)");
|
||||
stepLogs = NumericalMethods.Method_RegulaFalsi(eq, minX, maxX, iterCount, variable);
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
|
@ -153,20 +164,22 @@ namespace MathApp.Controls
|
|||
Function.UseRadians = prevRad;
|
||||
}
|
||||
|
||||
txtResult.Text = string.Join(Environment.NewLine, logs);
|
||||
|
||||
// Extract final root from logs
|
||||
string finalRoot = "";
|
||||
for (int i = logs.Count - 1; i >= 0; i--)
|
||||
string rootFound = "";
|
||||
for (int i = stepLogs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string line = logs[i];
|
||||
string line = stepLogs[i];
|
||||
if (line.Contains("BULUNAN KÖK") || line.Contains("Root found:") || line.Contains($"{variable} =") || line.Contains("x ="))
|
||||
{
|
||||
finalRoot = line;
|
||||
rootFound = line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (stepLogs, rootFound);
|
||||
});
|
||||
|
||||
txtResult.Text = string.Join(Environment.NewLine, logs);
|
||||
|
||||
if (!string.IsNullOrEmpty(finalRoot))
|
||||
{
|
||||
string displayRoot = finalRoot.Replace(">>>", "").Replace("BULUNAN KÖK:", "").Replace("Root found:", "").Trim();
|
||||
|
|
@ -190,6 +203,12 @@ namespace MathApp.Controls
|
|||
lblRootValue.ForeColor = Color.FromArgb(239, 68, 68);
|
||||
lblRootDetails.Text = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnFindRoot.Enabled = true;
|
||||
btnFindRoot.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Drawing;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MathApp.Controls
|
||||
|
|
@ -220,8 +221,13 @@ namespace MathApp.Controls
|
|||
}
|
||||
}
|
||||
|
||||
private void BtnSolveSystem_Click(object sender, EventArgs e)
|
||||
private async void BtnSolveSystem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnSolveSystem.Text;
|
||||
btnSolveSystem.Enabled = false;
|
||||
btnSolveSystem.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
int count = equationsInputs.Count;
|
||||
|
|
@ -268,37 +274,42 @@ namespace MathApp.Controls
|
|||
iterCount = 50;
|
||||
|
||||
int methodIdx = cmbSolverMethod.SelectedIndex;
|
||||
|
||||
var (results, stepLogs) = await Task.Run(() =>
|
||||
{
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
Dictionary<string, decimal> results;
|
||||
List<string> stepLogs;
|
||||
Dictionary<string, decimal> resDict;
|
||||
List<string> logs;
|
||||
try
|
||||
{
|
||||
if (methodIdx == 0) // Multivariable Newton-Raphson
|
||||
{
|
||||
results = NumericalMethods.SolveEquationSystemWithLogs(eqs, dict, iterCount, out stepLogs);
|
||||
resDict = NumericalMethods.SolveEquationSystemWithLogs(eqs, dict, iterCount, out logs);
|
||||
}
|
||||
else if (methodIdx == 1) // Gauss-Seidel
|
||||
{
|
||||
results = NumericalMethods.Method_GaussSeidel(eqs, dict, iterCount, out stepLogs);
|
||||
resDict = NumericalMethods.Method_GaussSeidel(eqs, dict, iterCount, out logs);
|
||||
}
|
||||
else if (methodIdx == 2) // LU Decomposition
|
||||
{
|
||||
results = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "LU", out stepLogs);
|
||||
resDict = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "LU", out logs);
|
||||
}
|
||||
else if (methodIdx == 3) // Inverse Matrix
|
||||
{
|
||||
results = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "INVERSE", out stepLogs);
|
||||
resDict = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "INVERSE", out logs);
|
||||
}
|
||||
else // QR Decomposition
|
||||
{
|
||||
results = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "QR", out stepLogs);
|
||||
resDict = NumericalMethods.Method_LinearMatrixSolve(eqs, dict.Keys.ToList(), "QR", out logs);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Function.UseRadians = prevRad;
|
||||
}
|
||||
return (resDict, logs);
|
||||
});
|
||||
|
||||
if (results != null)
|
||||
{
|
||||
|
|
@ -342,6 +353,12 @@ namespace MathApp.Controls
|
|||
lblHeroStatus.Text = ex.Message;
|
||||
txtSystemResult.Text = "❌ Hata: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnSolveSystem.Enabled = true;
|
||||
btnSolveSystem.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MathApp.Controls
|
||||
|
|
@ -48,8 +49,13 @@ namespace MathApp.Controls
|
|||
BtnCalculate_Click(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void BtnCalculate_Click(object sender, EventArgs e)
|
||||
private async void BtnCalculate_Click(object sender, EventArgs e)
|
||||
{
|
||||
string origBtnText = btnCalculate.Text;
|
||||
btnCalculate.Enabled = false;
|
||||
btnCalculate.Text = "⏳ Hesaplanıyor...";
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
try
|
||||
{
|
||||
string eq = txtFunction.Text.Trim();
|
||||
|
|
@ -71,29 +77,33 @@ namespace MathApp.Controls
|
|||
return;
|
||||
}
|
||||
|
||||
var (series, derivLines) = await Task.Run(() =>
|
||||
{
|
||||
bool prevRad = Function.UseRadians;
|
||||
Function.UseRadians = true;
|
||||
string series;
|
||||
List<string> derivLines = new List<string>();
|
||||
string polySeries;
|
||||
List<string> lines = new List<string>();
|
||||
try
|
||||
{
|
||||
decimal f0 = NumericalMethods.Method_EvaluateFunction(eq, variable, center);
|
||||
derivLines.Add($" f({center}) = {Math.Round(f0, 6).ToString("0.######", CultureInfo.InvariantCulture)}");
|
||||
lines.Add($" f({center}) = {Math.Round(f0, 6).ToString("0.######", CultureInfo.InvariantCulture)}");
|
||||
|
||||
for (int k = 1; k <= degree; k++)
|
||||
{
|
||||
decimal step = k >= 4 ? 0.01m : 0.005m;
|
||||
decimal dk = NumericalMethods.Method_NumericalDifferentiation(eq, k, variable, center, 4, step);
|
||||
decimal coeff = dk / NumericalMethods.Factorial(k);
|
||||
derivLines.Add($" f^({k})({center}) = {Math.Round(dk, 5).ToString("0.#####", CultureInfo.InvariantCulture),-14} => Katsayı (c_{k}) = {Math.Round(coeff, 6).ToString("0.######", CultureInfo.InvariantCulture)}");
|
||||
lines.Add($" f^({k})({center}) = {Math.Round(dk, 5).ToString("0.#####", CultureInfo.InvariantCulture),-14} => Katsayı (c_{k}) = {Math.Round(coeff, 6).ToString("0.######", CultureInfo.InvariantCulture)}");
|
||||
}
|
||||
|
||||
series = NumericalMethods.Method_TaylorSeries(eq, degree, variable, center);
|
||||
polySeries = NumericalMethods.Method_TaylorSeries(eq, degree, variable, center);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Function.UseRadians = prevRad;
|
||||
}
|
||||
return (polySeries, lines);
|
||||
});
|
||||
|
||||
lblHeroPolyValue.Text = $"P_{degree}({variable}) = {series}";
|
||||
lblHeroPolyValue.ForeColor = Color.FromArgb(52, 211, 153);
|
||||
|
|
@ -110,6 +120,12 @@ namespace MathApp.Controls
|
|||
lblHeroPolyValue.Text = "Hata Oluştu";
|
||||
lblHeroPolyValue.ForeColor = Color.FromArgb(239, 68, 68);
|
||||
}
|
||||
finally
|
||||
{
|
||||
btnCalculate.Enabled = true;
|
||||
btnCalculate.Text = origBtnText;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,24 @@ namespace MathApp
|
|||
private MultivariableTaylorControl multiTaylorControl;
|
||||
private CombinatoricsControl combinatoricsControl;
|
||||
private GraphPlotterControl graphControl;
|
||||
private UserControl[] allControls;
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams cp = base.CreateParams;
|
||||
// WS_EX_COMPOSITED (0x02000000) paints all descendants in bottom-to-top order using double-buffering.
|
||||
// Eliminates window tearing and redraw flicker.
|
||||
cp.ExStyle |= 0x02000000;
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ThemeHelper.EnableDoubleBuffering(this);
|
||||
LoadApplicationIcon();
|
||||
|
||||
ThemeHelper.ApplyTheme(this);
|
||||
|
|
@ -69,14 +83,49 @@ namespace MathApp
|
|||
multiTaylorControl = new MultivariableTaylorControl { Dock = DockStyle.Fill };
|
||||
combinatoricsControl = new CombinatoricsControl { Dock = DockStyle.Fill };
|
||||
graphControl = new GraphPlotterControl { Dock = DockStyle.Fill };
|
||||
|
||||
allControls = new UserControl[] {
|
||||
calcControl,
|
||||
rootControl,
|
||||
systemControl,
|
||||
matrixControl,
|
||||
derivativeControl,
|
||||
taylorControl,
|
||||
multiTaylorControl,
|
||||
combinatoricsControl,
|
||||
graphControl
|
||||
};
|
||||
|
||||
pnlContent.SuspendLayout();
|
||||
// Pre-add all controls once to avoid Win32 HWND re-creation and flickering on tab switch
|
||||
pnlContent.Controls.AddRange(allControls);
|
||||
foreach (var ctrl in allControls)
|
||||
{
|
||||
ctrl.Visible = false;
|
||||
ThemeHelper.EnableDoubleBuffering(ctrl);
|
||||
}
|
||||
pnlContent.ResumeLayout(false);
|
||||
}
|
||||
|
||||
private void ShowControl(UserControl control)
|
||||
{
|
||||
if (control == null || allControls == null) return;
|
||||
|
||||
pnlContent.SuspendLayout();
|
||||
pnlContent.Controls.Clear();
|
||||
pnlContent.Controls.Add(control);
|
||||
pnlContent.ResumeLayout();
|
||||
foreach (var ctrl in allControls)
|
||||
{
|
||||
if (ctrl != control && ctrl.Visible)
|
||||
{
|
||||
ctrl.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!control.Visible)
|
||||
{
|
||||
control.Visible = true;
|
||||
}
|
||||
control.BringToFront();
|
||||
pnlContent.ResumeLayout(true);
|
||||
}
|
||||
|
||||
private void HighlightButton(Button activeBtn)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<ApplicationIcon>logo.ico</ApplicationIcon>
|
||||
<AssemblyName>ttCalculator</AssemblyName>
|
||||
<Product>ttCalculator - Gelişmiş Matematik & Nümerik Analiz Stüdyosu</Product>
|
||||
<Version>2.0.0</Version>
|
||||
<Version>2.1.0</Version>
|
||||
<Company>ttCalculator</Company>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);MathApp.Tests\**</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -148,5 +148,21 @@ namespace MathApp
|
|||
btn.FlatAppearance.MouseOverBackColor = ButtonHover;
|
||||
return btn;
|
||||
}
|
||||
|
||||
public static void EnableDoubleBuffering(Control control)
|
||||
{
|
||||
if (control == null) return;
|
||||
try
|
||||
{
|
||||
var prop = typeof(Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
prop?.SetValue(control, true, null);
|
||||
}
|
||||
catch { }
|
||||
|
||||
foreach (Control child in control.Controls)
|
||||
{
|
||||
EnableDoubleBuffering(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue