From 8228ae3514b7f2f864fb253377abc7f434951d8d Mon Sep 17 00:00:00 2001 From: LilDosto Date: Thu, 29 Oct 2026 00:36:57 +0300 Subject: [PATCH] feat(v2.8.0): Gelismis grafik cizici studyosu - polar fonksiyonlar, kritik nokta tespiti, teget inceleme, parametre surguleri ve disa aktarma --- README.md | 8 +- installer/setup.iss | 4 +- .../Controls/GraphPlotterControl.Designer.cs | 465 +++-- .../Controls/GraphPlotterControl.cs | 1638 +++++++++++------ src/ttCalculator/MainForm.Designer.cs | 2 +- src/ttCalculator/ThemeHelper.cs | 6 +- src/ttCalculator/ttCalculator.csproj | 2 +- tests/ttCalculator.Tests/Program.cs | 2 +- 8 files changed, 1428 insertions(+), 699 deletions(-) diff --git a/README.md b/README.md index b090c42..32c99e6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 📐 ttCalculator v2.7.0 +# 📐 ttCalculator v2.8.0 [![GitHub release](https://img.shields.io/github/v/release/LilDosto/ttCalculator?color=brightgreen&label=S%C3%BCr%C3%BCm)](https://github.com/LilDosto/ttCalculator/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) @@ -13,11 +13,11 @@ Tüm matematiksel çekirdek, otomatik test paketinden **%100 başarıyla (0 hata ## 🚀 Hızlı Başlangıç & Kurulum -1. **[Releases](https://github.com/LilDosto/ttCalculator/releases/tag/v2.7.0)** sayfasına gidin. +1. **[Releases](https://github.com/LilDosto/ttCalculator/releases/tag/v2.8.0)** sayfasına gidin. 2. İhtiyacınıza göre indirin: - - **`ttCalculator-v2.7.0-Setup.exe` (Önerilen)**: Standart Windows kurulum sihirbazı. Masaüstüne ve Başlat Menüsüne kısayol oluşturur, Denetim Masası / Program Ekle-Kaldır entegrasyonu sağlar. + - **`ttCalculator-v2.8.0-Setup.exe` (Önerilen)**: Standart Windows kurulum sihirbazı. Masaüstüne ve Başlat Menüsüne kısayol oluşturur, Denetim Masası / Program Ekle-Kaldır entegrasyonu sağlar. - **`ttCalculator.exe`**: Kurulumsuz doğrudan çalıştırılabilen tek dosya taşınabilir (portable) sürüm. - - **`ttCalculator-v2.7.0-win-x64.zip`**: Taşınabilir arşiv paketi. + - **`ttCalculator-v2.8.0-win-x64.zip`**: Taşınabilir arşiv paketi. 3. Çift tıklayarak doğrudan çalıştırın — ek bağımlılık gerektirmez! --- diff --git a/installer/setup.iss b/installer/setup.iss index 9c7b5d4..7075618 100644 --- a/installer/setup.iss +++ b/installer/setup.iss @@ -1,6 +1,6 @@ ; Script generated by Antigravity for ttCalculator #define MyAppName "ttCalculator" -#define MyAppVersion "2.7.0" +#define MyAppVersion "2.8.0" #define MyAppPublisher "LilDosto" #define MyAppURL "https://github.com/LilDosto/ttCalculator" #define MyAppExeName "ttCalculator.exe" @@ -25,7 +25,7 @@ DefaultGroupName={#MyAppName} AllowNoIcons=yes LicenseFile=..\LICENSE OutputDir=..\Release -OutputBaseFilename=ttCalculator-v2.7.0-Setup +OutputBaseFilename=ttCalculator-v2.8.0-Setup SetupIconFile=..\Release\logo.ico Compression=lzma2/ultra64 SolidCompression=yes diff --git a/src/ttCalculator/Controls/GraphPlotterControl.Designer.cs b/src/ttCalculator/Controls/GraphPlotterControl.Designer.cs index 24c5313..a6b9ca5 100644 --- a/src/ttCalculator/Controls/GraphPlotterControl.Designer.cs +++ b/src/ttCalculator/Controls/GraphPlotterControl.Designer.cs @@ -20,8 +20,8 @@ namespace MathApp.Controls private void InitializeComponent() { this.pnlHeader = ThemeHelper.CreateHeaderPanel( - "Gelişmiş Çoklu Fonksiyon & Geometri Grafiği Çizici (Advanced Graph Plotter)", - "Çoklu fonksiyon desteği, ortak teğetler, en yakın nokta analizi, eksen sündürme, hazır parametrik şekiller ve tekil nokta yönetimi."); + "Gelişmiş Çoklu Fonksiyon & Geometri Grafiği Stüdyosu", + "Çoklu katmanlı eğriler, kutupsal (polar) fonksiyonlar, otomatik kritik nokta tespiti (kök, extremum, büküm), teğet inceleme ve parametre sürgüleri."); this.pnlControls = new Panel(); this.pnlPresets = new FlowLayoutPanel(); @@ -33,26 +33,31 @@ namespace MathApp.Controls this.lblEquation = new Label(); this.txtEquation = new TextBox(); + this.chkPolar = new CheckBox(); this.lblMinX = new Label(); this.txtMinX = new TextBox(); this.lblMaxX = new Label(); this.txtMaxX = new TextBox(); this.chkClampRange = new CheckBox(); - this.btnPlot = ThemeHelper.CreateActionButton("➕ Çiz / Ekle", 110, 28, true); + this.btnPlot = ThemeHelper.CreateActionButton("➕ Ekle / Çiz", 100, 27, true); - // Scale Toolbar buttons - this.btnZoomXIn = ThemeHelper.CreateActionButton("↔️ X Sündür (+)", 105, 26, false); - this.btnZoomXOut = ThemeHelper.CreateActionButton("X Daralt (-)", 90, 26, false); - this.btnZoomX10 = ThemeHelper.CreateActionButton("X: 10×", 65, 26, false); - this.btnZoomYIn = ThemeHelper.CreateActionButton("↕️ Y Sündür (+)", 105, 26, false); - this.btnZoomYOut = ThemeHelper.CreateActionButton("Y Daralt (-)", 90, 26, false); - this.btnAspect1to1 = ThemeHelper.CreateActionButton("1:1 Oran", 75, 26, false); - this.btnResetView = ThemeHelper.CreateActionButton("🔄 Sıfırla", 75, 26, false); + // Scale & Analysis Toolbar buttons + this.btnZoomXIn = ThemeHelper.CreateActionButton("↔ X Genişlet (+)", 105, 26, false); + this.btnZoomXOut = ThemeHelper.CreateActionButton("X Daralt (-)", 85, 26, false); + this.btnZoomX10 = ThemeHelper.CreateActionButton("X: 10×", 55, 26, false); + this.btnZoomYIn = ThemeHelper.CreateActionButton("↕ Y Genişlet (+)", 105, 26, false); + this.btnZoomYOut = ThemeHelper.CreateActionButton("Y Daralt (-)", 85, 26, false); + this.btnAspect1to1 = ThemeHelper.CreateActionButton("1:1 Oran", 68, 26, false); + this.btnResetView = ThemeHelper.CreateActionButton("🔄 Sıfırla", 68, 26, false); + this.chkCriticalPoints = new CheckBox(); + this.chkInspectMode = new CheckBox(); + this.chkShowAsymptotes = new CheckBox(); this.pnlRightSide = new Panel(); this.tabManager = new TabControl(); this.tabFunctions = new TabPage(); this.tabPoints = new TabPage(); + this.tabSliders = new TabPage(); this.tabTools = new TabPage(); this.tabShapes = new TabPage(); @@ -80,19 +85,35 @@ namespace MathApp.Controls this.btnClearPoints = new Button(); this.lblPointHint = new Label(); + // Sliders Tab Controls + this.lblParamA = new Label(); + this.tbParamA = new TrackBar(); + this.lblParamB = new Label(); + this.tbParamB = new TrackBar(); + this.lblParamC = new Label(); + this.tbParamC = new TrackBar(); + this.lblParamK = new Label(); + this.tbParamK = new TrackBar(); + this.btnAnimate = ThemeHelper.CreateActionButton("▶ Canlı Dalga Animasyonu", 284, 30, true); + this.btnResetParams = ThemeHelper.CreateActionButton("🔄 Parametreleri Sıfırla", 284, 28, false); + this.lblSliderHint = new Label(); + // Tools Tab Controls this.lblToolF1 = new Label(); this.cmbToolF1 = new ComboBox(); this.lblToolF2 = new Label(); this.cmbToolF2 = new ComboBox(); - this.btnCommonTangent = ThemeHelper.CreateActionButton("📐 Ortak Teğet Doğrusunu Bul", 260, 30, true); - this.btnNearestPoints = ThemeHelper.CreateActionButton("📍 En Yakın Noktalar & Doğru", 260, 30, false); + this.btnCommonTangent = ThemeHelper.CreateActionButton("📐 Ortak Teğet Doğrusunu Bul", 284, 28, true); + this.btnNearestPoints = ThemeHelper.CreateActionButton("📍 En Yakın Noktalar & Doğru", 284, 28, false); this.lblToolSep = new Label(); this.lblToolPointTan = new Label(); this.txtTanPointX = new TextBox(); this.txtTanPointY = new TextBox(); - this.btnPointTangent = ThemeHelper.CreateActionButton("📏 Noktadan Teğet Çiz", 260, 30, false); + this.btnPointTangent = ThemeHelper.CreateActionButton("📏 Noktadan Teğet Çiz", 284, 28, false); this.txtToolLog = new RichTextBox(); + this.btnExportImage = ThemeHelper.CreateActionButton("📷 Grafiği Resim (PNG) Kaydet", 284, 28, false); + this.btnExportCsv = ThemeHelper.CreateActionButton("📊 Değer Tablosunu CSV İndir", 284, 28, false); + this.btnExportLatex = ThemeHelper.CreateActionButton("📜 LaTeX (TikZ) Kodu Üret", 284, 28, false); // Shapes Tab Controls this.lblShapeType = new Label(); @@ -106,7 +127,7 @@ namespace MathApp.Controls this.txtShapeDim2 = new TextBox(); this.lblShapeAngle = new Label(); this.txtShapeAngle = new TextBox(); - this.btnAddShape = ThemeHelper.CreateActionButton("📐 Şekli Grafiğe Ekle", 260, 32, true); + this.btnAddShape = ThemeHelper.CreateActionButton("📐 Şekli Grafiğe Ekle", 284, 32, true); this.pnlStatusBar = new Panel(); this.lblStatus = new Label(); @@ -117,53 +138,68 @@ namespace MathApp.Controls this.tabManager.SuspendLayout(); this.tabFunctions.SuspendLayout(); this.tabPoints.SuspendLayout(); + this.tabSliders.SuspendLayout(); this.tabTools.SuspendLayout(); this.tabShapes.SuspendLayout(); this.pnlStatusBar.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamA)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamB)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamC)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamK)).BeginInit(); this.SuspendLayout(); + // pnlHeader + this.pnlHeader.Dock = DockStyle.Top; + this.pnlHeader.Height = 50; + // pnlControls this.pnlControls.Dock = DockStyle.Top; - this.pnlControls.Height = 104; - this.pnlControls.BackColor = ThemeHelper.DarkBackground; - this.pnlControls.Padding = new Padding(16, 6, 16, 6); + this.pnlControls.Height = 108; + this.pnlControls.BackColor = ThemeHelper.SidebarBackground; + this.pnlControls.Padding = new Padding(12, 4, 12, 4); + // Presets this.lblPresets.Text = "Hızlı:"; this.lblPresets.AutoSize = true; this.lblPresets.ForeColor = ThemeHelper.MutedText; - this.lblPresets.Font = new Font("Segoe UI Semibold", 9F, FontStyle.Bold); + this.lblPresets.Font = new Font("Segoe UI Semibold", 8.5F, FontStyle.Bold); this.lblPresets.Margin = new Padding(0, 4, 6, 0); - this.pnlPresets.Location = new Point(16, 6); - this.pnlPresets.Size = new Size(950, 30); + this.pnlPresets.Location = new Point(14, 4); + this.pnlPresets.Size = new Size(950, 28); this.pnlPresets.Controls.Add(this.lblPresets); this.pnlPresets.Controls.Add(this.btnEx1); this.pnlPresets.Controls.Add(this.btnEx2); this.pnlPresets.Controls.Add(this.btnEx3); this.pnlPresets.Controls.Add(this.btnEx4); - int yRow1 = 40; + int yRow1 = 36; this.lblEquation.AutoSize = true; this.lblEquation.ForeColor = ThemeHelper.LightText; this.lblEquation.Font = new Font("Segoe UI Semibold", 9.5F, FontStyle.Bold); this.lblEquation.Text = "f(x) ="; - this.lblEquation.Location = new Point(16, yRow1 + 3); + this.lblEquation.Location = new Point(14, yRow1 + 4); - this.txtEquation.Location = new Point(60, yRow1); - this.txtEquation.Size = new Size(180, 25); + this.txtEquation.Location = new Point(56, yRow1); + this.txtEquation.Size = new Size(210, 25); this.txtEquation.Text = "sin(x)"; - this.txtEquation.Font = new Font("Consolas", 10.5F); + this.txtEquation.Font = new Font("Consolas", 10.5F, FontStyle.Bold); this.txtEquation.BackColor = ThemeHelper.CardBackground; this.txtEquation.ForeColor = Color.White; this.txtEquation.BorderStyle = BorderStyle.FixedSingle; + this.chkPolar.Text = "Polar r(θ)"; + this.chkPolar.ForeColor = Color.FromArgb(56, 189, 248); + this.chkPolar.Location = new Point(272, yRow1 + 3); + this.chkPolar.Size = new Size(82, 22); + this.lblMinX.AutoSize = true; this.lblMinX.ForeColor = ThemeHelper.LightText; this.lblMinX.Text = "Min X:"; - this.lblMinX.Location = new Point(250, yRow1 + 4); + this.lblMinX.Location = new Point(360, yRow1 + 4); - this.txtMinX.Location = new Point(292, yRow1); - this.txtMinX.Size = new Size(50, 25); + this.txtMinX.Location = new Point(402, yRow1); + this.txtMinX.Size = new Size(45, 25); this.txtMinX.Text = "-10"; this.txtMinX.Font = new Font("Consolas", 9.5F); this.txtMinX.BackColor = ThemeHelper.CardBackground; @@ -173,35 +209,51 @@ namespace MathApp.Controls this.lblMaxX.AutoSize = true; this.lblMaxX.ForeColor = ThemeHelper.LightText; this.lblMaxX.Text = "Max X:"; - this.lblMaxX.Location = new Point(348, yRow1 + 4); + this.lblMaxX.Location = new Point(452, yRow1 + 4); - this.txtMaxX.Location = new Point(392, yRow1); - this.txtMaxX.Size = new Size(50, 25); + this.txtMaxX.Location = new Point(496, yRow1); + this.txtMaxX.Size = new Size(45, 25); this.txtMaxX.Text = "10"; this.txtMaxX.Font = new Font("Consolas", 9.5F); this.txtMaxX.BackColor = ThemeHelper.CardBackground; this.txtMaxX.ForeColor = Color.White; this.txtMaxX.BorderStyle = BorderStyle.FixedSingle; - this.chkClampRange.Text = "[Min, Max] Kısıtla"; + this.chkClampRange.Text = "Kısıtla"; this.chkClampRange.ForeColor = ThemeHelper.LightText; - this.chkClampRange.Location = new Point(452, yRow1 + 3); - this.chkClampRange.Size = new Size(125, 22); + this.chkClampRange.Location = new Point(548, yRow1 + 3); + this.chkClampRange.Size = new Size(68, 22); - this.btnPlot.Location = new Point(570, yRow1 - 1); + this.btnPlot.Location = new Point(622, yRow1 - 1); - int yRow2 = 72; - this.btnZoomXIn.Location = new Point(16, yRow2); - this.btnZoomXOut.Location = new Point(126, yRow2); - this.btnZoomX10.Location = new Point(221, yRow2); - this.btnZoomYIn.Location = new Point(291, yRow2); - this.btnZoomYOut.Location = new Point(401, yRow2); - this.btnAspect1to1.Location = new Point(496, yRow2); - this.btnResetView.Location = new Point(576, yRow2); + int yRow2 = 70; + this.btnZoomXIn.Location = new Point(14, yRow2); + this.btnZoomXOut.Location = new Point(122, yRow2); + this.btnZoomX10.Location = new Point(210, yRow2); + this.btnZoomYIn.Location = new Point(268, yRow2); + this.btnZoomYOut.Location = new Point(376, yRow2); + this.btnAspect1to1.Location = new Point(464, yRow2); + this.btnResetView.Location = new Point(535, yRow2); + + this.chkCriticalPoints.Text = "🎯 Kritik Noktalar"; + this.chkCriticalPoints.ForeColor = Color.FromArgb(52, 211, 153); + this.chkCriticalPoints.Location = new Point(608, yRow2 + 2); + this.chkCriticalPoints.Size = new Size(125, 24); + + this.chkInspectMode.Text = "🔍 Teğet İncele"; + this.chkInspectMode.ForeColor = Color.FromArgb(56, 189, 248); + this.chkInspectMode.Location = new Point(738, yRow2 + 2); + this.chkInspectMode.Size = new Size(115, 24); + + this.chkShowAsymptotes.Text = "Asimptotlar"; + this.chkShowAsymptotes.ForeColor = Color.FromArgb(244, 63, 94); + this.chkShowAsymptotes.Location = new Point(856, yRow2 + 2); + this.chkShowAsymptotes.Size = new Size(95, 24); this.pnlControls.Controls.Add(this.pnlPresets); this.pnlControls.Controls.Add(this.lblEquation); this.pnlControls.Controls.Add(this.txtEquation); + this.pnlControls.Controls.Add(this.chkPolar); this.pnlControls.Controls.Add(this.lblMinX); this.pnlControls.Controls.Add(this.txtMinX); this.pnlControls.Controls.Add(this.lblMaxX); @@ -215,6 +267,9 @@ namespace MathApp.Controls this.pnlControls.Controls.Add(this.btnZoomYOut); this.pnlControls.Controls.Add(this.btnAspect1to1); this.pnlControls.Controls.Add(this.btnResetView); + this.pnlControls.Controls.Add(this.chkCriticalPoints); + this.pnlControls.Controls.Add(this.chkInspectMode); + this.pnlControls.Controls.Add(this.chkShowAsymptotes); // pnlRightSide (Tabbed Manager) this.pnlRightSide.Dock = DockStyle.Right; @@ -225,11 +280,12 @@ namespace MathApp.Controls this.tabManager.Dock = DockStyle.Fill; this.tabManager.Controls.Add(this.tabFunctions); this.tabManager.Controls.Add(this.tabPoints); + this.tabManager.Controls.Add(this.tabSliders); this.tabManager.Controls.Add(this.tabTools); this.tabManager.Controls.Add(this.tabShapes); // tabFunctions - this.tabFunctions.Text = "📈 Eğriler"; + this.tabFunctions.Text = "Eğriler"; this.tabFunctions.BackColor = ThemeHelper.DarkBackground; this.tabFunctions.Padding = new Padding(8); @@ -239,54 +295,50 @@ namespace MathApp.Controls this.lstCurves.ForeColor = Color.White; this.lstCurves.Font = new Font("Consolas", 9.5F); - this.btnCurveColor.Text = "🎨 Renk"; - this.btnCurveColor.Size = new Size(85, 26); + this.btnCurveColor.Text = "Renk"; + this.btnCurveColor.Size = new Size(70, 26); this.btnCurveColor.Location = new Point(8, 230); this.btnCurveColor.BackColor = Color.FromArgb(30, 41, 59); this.btnCurveColor.ForeColor = Color.White; this.btnCurveColor.FlatStyle = FlatStyle.Flat; - this.cmbCurveStyle.Location = new Point(100, 230); - this.cmbCurveStyle.Size = new Size(95, 25); + this.cmbCurveStyle.Location = new Point(82, 230); + this.cmbCurveStyle.Size = new Size(110, 25); this.cmbCurveStyle.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbCurveStyle.BackColor = ThemeHelper.CardBackground; this.cmbCurveStyle.ForeColor = Color.White; - this.cmbCurveStyle.Items.AddRange(new object[] { "Düz Çizgi", "Kesikli", "Noktalı" }); - this.cmbCurveStyle.SelectedIndex = 0; - this.cmbCurveThickness.Location = new Point(202, 230); - this.cmbCurveThickness.Size = new Size(90, 25); + this.cmbCurveThickness.Location = new Point(196, 230); + this.cmbCurveThickness.Size = new Size(95, 25); this.cmbCurveThickness.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbCurveThickness.BackColor = ThemeHelper.CardBackground; this.cmbCurveThickness.ForeColor = Color.White; - this.cmbCurveThickness.Items.AddRange(new object[] { "1 px", "2 px", "3 px", "4 px" }); - this.cmbCurveThickness.SelectedIndex = 1; - this.btnCurveToggle.Text = "👁️ Göster/Gizle"; - this.btnCurveToggle.Size = new Size(138, 28); + this.btnCurveToggle.Text = "Göster/Gizle"; + this.btnCurveToggle.Size = new Size(135, 28); this.btnCurveToggle.Location = new Point(8, 265); - this.btnCurveToggle.BackColor = Color.FromArgb(30, 41, 59); + this.btnCurveToggle.BackColor = Color.FromArgb(14, 116, 144); this.btnCurveToggle.ForeColor = Color.White; this.btnCurveToggle.FlatStyle = FlatStyle.Flat; - this.btnCurveDelete.Text = "🗑️ Eğriyi Sil"; - this.btnCurveDelete.Size = new Size(138, 28); - this.btnCurveDelete.Location = new Point(154, 265); - this.btnCurveDelete.BackColor = Color.FromArgb(153, 27, 27); + this.btnCurveDelete.Text = "Eğriyi Sil"; + this.btnCurveDelete.Size = new Size(135, 28); + this.btnCurveDelete.Location = new Point(155, 265); + this.btnCurveDelete.BackColor = Color.FromArgb(185, 28, 28); this.btnCurveDelete.ForeColor = Color.White; this.btnCurveDelete.FlatStyle = FlatStyle.Flat; - this.btnCurveEdit.Text = "✏️ Düzenle"; - this.btnCurveEdit.Size = new Size(138, 28); - this.btnCurveEdit.Location = new Point(8, 298); - this.btnCurveEdit.BackColor = Color.FromArgb(30, 41, 59); + this.btnCurveEdit.Text = "Düzenle"; + this.btnCurveEdit.Size = new Size(135, 28); + this.btnCurveEdit.Location = new Point(8, 300); + this.btnCurveEdit.BackColor = Color.FromArgb(40, 58, 85); this.btnCurveEdit.ForeColor = Color.White; this.btnCurveEdit.FlatStyle = FlatStyle.Flat; - this.btnCurveClearAll.Text = "🧹 Tümünü Sil"; - this.btnCurveClearAll.Size = new Size(138, 28); - this.btnCurveClearAll.Location = new Point(154, 298); - this.btnCurveClearAll.BackColor = Color.FromArgb(45, 55, 72); + this.btnCurveClearAll.Text = "Tümünü Sil"; + this.btnCurveClearAll.Size = new Size(135, 28); + this.btnCurveClearAll.Location = new Point(155, 300); + this.btnCurveClearAll.BackColor = Color.FromArgb(127, 29, 29); this.btnCurveClearAll.ForeColor = Color.White; this.btnCurveClearAll.FlatStyle = FlatStyle.Flat; @@ -300,7 +352,7 @@ namespace MathApp.Controls this.tabFunctions.Controls.Add(this.btnCurveClearAll); // tabPoints - this.tabPoints.Text = "📍 Noktalar"; + this.tabPoints.Text = "Noktalar"; this.tabPoints.BackColor = ThemeHelper.DarkBackground; this.tabPoints.Padding = new Padding(8); @@ -310,75 +362,71 @@ namespace MathApp.Controls this.lstPoints.ForeColor = Color.White; this.lstPoints.Font = new Font("Consolas", 9.5F); - int py = 190; this.lblPtX.Text = "X:"; - this.lblPtX.Location = new Point(8, py + 3); + this.lblPtX.Location = new Point(8, 192); this.lblPtX.AutoSize = true; this.lblPtX.ForeColor = ThemeHelper.LightText; - this.txtPtX.Location = new Point(28, py); + this.txtPtX.Location = new Point(28, 189); this.txtPtX.Size = new Size(60, 24); this.txtPtX.Text = "0"; - this.txtPtX.Font = new Font("Consolas", 9.5F); + this.txtPtX.Font = new Font("Consolas", 9F); this.txtPtX.BackColor = ThemeHelper.CardBackground; this.txtPtX.ForeColor = Color.White; this.lblPtY.Text = "Y:"; - this.lblPtY.Location = new Point(95, py + 3); + this.lblPtY.Location = new Point(96, 192); this.lblPtY.AutoSize = true; this.lblPtY.ForeColor = ThemeHelper.LightText; - this.txtPtY.Location = new Point(115, py); + this.txtPtY.Location = new Point(116, 189); this.txtPtY.Size = new Size(60, 24); this.txtPtY.Text = "0"; - this.txtPtY.Font = new Font("Consolas", 9.5F); + this.txtPtY.Font = new Font("Consolas", 9F); this.txtPtY.BackColor = ThemeHelper.CardBackground; this.txtPtY.ForeColor = Color.White; - this.btnPtColor.Text = "🎨"; - this.btnPtColor.Location = new Point(182, py); - this.btnPtColor.Size = new Size(35, 25); + this.btnPtColor.Text = "Renk"; + this.btnPtColor.Location = new Point(184, 188); + this.btnPtColor.Size = new Size(48, 25); this.btnPtColor.BackColor = Color.FromArgb(250, 204, 21); this.btnPtColor.FlatStyle = FlatStyle.Flat; this.btnAddPoint.Text = "➕ Ekle"; - this.btnAddPoint.Location = new Point(222, py); - this.btnAddPoint.Size = new Size(70, 25); + this.btnAddPoint.Location = new Point(236, 188); + this.btnAddPoint.Size = new Size(58, 25); this.btnAddPoint.BackColor = ThemeHelper.AccentBlue; this.btnAddPoint.ForeColor = Color.White; this.btnAddPoint.FlatStyle = FlatStyle.Flat; - int py2 = 222; this.lblPtShape.Text = "Şekil:"; - this.lblPtShape.Location = new Point(8, py2 + 3); + this.lblPtShape.Location = new Point(8, 225); this.lblPtShape.AutoSize = true; this.lblPtShape.ForeColor = ThemeHelper.LightText; - this.cmbPtShape.Location = new Point(50, py2); - this.cmbPtShape.Size = new Size(125, 25); + this.cmbPtShape.Location = new Point(50, 222); + this.cmbPtShape.Size = new Size(130, 24); this.cmbPtShape.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbPtShape.BackColor = ThemeHelper.CardBackground; this.cmbPtShape.ForeColor = Color.White; - this.cmbPtShape.Items.AddRange(new object[] { "Daire", "Kare", "Çarpı", "Elmas" }); - this.cmbPtShape.SelectedIndex = 0; - this.btnDeletePoint.Text = "🗑️ Seçiliyi Sil"; - this.btnDeletePoint.Size = new Size(138, 28); + this.btnDeletePoint.Text = "Seçiliyi Sil"; this.btnDeletePoint.Location = new Point(8, 255); - this.btnDeletePoint.BackColor = Color.FromArgb(153, 27, 27); + this.btnDeletePoint.Size = new Size(135, 27); + this.btnDeletePoint.BackColor = Color.FromArgb(185, 28, 28); this.btnDeletePoint.ForeColor = Color.White; this.btnDeletePoint.FlatStyle = FlatStyle.Flat; - this.btnClearPoints.Text = "🧹 Tümünü Sil"; - this.btnClearPoints.Size = new Size(138, 28); - this.btnClearPoints.Location = new Point(154, 255); - this.btnClearPoints.BackColor = Color.FromArgb(45, 55, 72); + this.btnClearPoints.Text = "Tümünü Sil"; + this.btnClearPoints.Location = new Point(152, 255); + this.btnClearPoints.Size = new Size(135, 27); + this.btnClearPoints.BackColor = Color.FromArgb(127, 29, 29); this.btnClearPoints.ForeColor = Color.White; this.btnClearPoints.FlatStyle = FlatStyle.Flat; - this.lblPointHint.Text = "💡 İpucu: Grafik tuvalinde bir noktanın üzerine sağ tıklayarak da o noktayı doğrudan silebilirsiniz."; - this.lblPointHint.Location = new Point(8, 290); - this.lblPointHint.Size = new Size(284, 50); + this.lblPointHint.Text = "💡 İpucu: Grafik tuvalinde bir noktanın üzerine sağ tıklayarak da o noktayı silebilirsiniz."; + this.lblPointHint.Location = new Point(8, 295); + this.lblPointHint.Size = new Size(280, 50); this.lblPointHint.ForeColor = ThemeHelper.MutedText; this.lblPointHint.Font = new Font("Segoe UI", 8.5F); @@ -395,69 +443,151 @@ namespace MathApp.Controls this.tabPoints.Controls.Add(this.btnClearPoints); this.tabPoints.Controls.Add(this.lblPointHint); + // tabSliders + this.tabSliders.Text = "Parametreler"; + this.tabSliders.BackColor = ThemeHelper.DarkBackground; + this.tabSliders.Padding = new Padding(8); + + this.lblParamA.Text = "a = 1.00"; + this.lblParamA.Location = new Point(8, 8); + this.lblParamA.AutoSize = true; + this.lblParamA.ForeColor = Color.FromArgb(56, 189, 248); + this.lblParamA.Font = new Font("Segoe UI Semibold", 9.5F, FontStyle.Bold); + + this.tbParamA.Location = new Point(8, 28); + this.tbParamA.Size = new Size(284, 45); + this.tbParamA.Minimum = -100; + this.tbParamA.Maximum = 100; + this.tbParamA.Value = 10; + this.tbParamA.TickFrequency = 20; + + this.lblParamB.Text = "b = 1.00"; + this.lblParamB.Location = new Point(8, 72); + this.lblParamB.AutoSize = true; + this.lblParamB.ForeColor = Color.FromArgb(52, 211, 153); + this.lblParamB.Font = new Font("Segoe UI Semibold", 9.5F, FontStyle.Bold); + + this.tbParamB.Location = new Point(8, 92); + this.tbParamB.Size = new Size(284, 45); + this.tbParamB.Minimum = -100; + this.tbParamB.Maximum = 100; + this.tbParamB.Value = 10; + this.tbParamB.TickFrequency = 20; + + this.lblParamC.Text = "c = 0.00"; + this.lblParamC.Location = new Point(8, 136); + this.lblParamC.AutoSize = true; + this.lblParamC.ForeColor = Color.FromArgb(245, 158, 11); + this.lblParamC.Font = new Font("Segoe UI Semibold", 9.5F, FontStyle.Bold); + + this.tbParamC.Location = new Point(8, 156); + this.tbParamC.Size = new Size(284, 45); + this.tbParamC.Minimum = -100; + this.tbParamC.Maximum = 100; + this.tbParamC.Value = 0; + this.tbParamC.TickFrequency = 20; + + this.lblParamK.Text = "k = 1.00"; + this.lblParamK.Location = new Point(8, 200); + this.lblParamK.AutoSize = true; + this.lblParamK.ForeColor = Color.FromArgb(168, 85, 247); + this.lblParamK.Font = new Font("Segoe UI Semibold", 9.5F, FontStyle.Bold); + + this.tbParamK.Location = new Point(8, 220); + this.tbParamK.Size = new Size(284, 45); + this.tbParamK.Minimum = -100; + this.tbParamK.Maximum = 100; + this.tbParamK.Value = 10; + this.tbParamK.TickFrequency = 20; + + this.btnAnimate.Location = new Point(8, 268); + this.btnResetParams.Location = new Point(8, 302); + + this.lblSliderHint.Text = "💡 İpucu: Formülünüze a, b, c veya k değişkenlerini ekleyin (ör: a*sin(b*x + c)). Sürgüleri hareket ettirerek dalga animasyonunu canlı izleyin."; + this.lblSliderHint.Location = new Point(8, 340); + this.lblSliderHint.Size = new Size(284, 60); + this.lblSliderHint.ForeColor = ThemeHelper.MutedText; + this.lblSliderHint.Font = new Font("Segoe UI", 8.5F); + + this.tabSliders.Controls.Add(this.lblParamA); + this.tabSliders.Controls.Add(this.tbParamA); + this.tabSliders.Controls.Add(this.lblParamB); + this.tabSliders.Controls.Add(this.tbParamB); + this.tabSliders.Controls.Add(this.lblParamC); + this.tabSliders.Controls.Add(this.tbParamC); + this.tabSliders.Controls.Add(this.lblParamK); + this.tabSliders.Controls.Add(this.tbParamK); + this.tabSliders.Controls.Add(this.btnAnimate); + this.tabSliders.Controls.Add(this.btnResetParams); + this.tabSliders.Controls.Add(this.lblSliderHint); + // tabTools - this.tabTools.Text = "🛠️ Araçlar"; + this.tabTools.Text = "Araçlar & Analiz"; this.tabTools.BackColor = ThemeHelper.DarkBackground; this.tabTools.Padding = new Padding(8); this.lblToolF1.Text = "1. Fonksiyon:"; - this.lblToolF1.Location = new Point(8, 8); + this.lblToolF1.Location = new Point(8, 6); this.lblToolF1.AutoSize = true; this.lblToolF1.ForeColor = ThemeHelper.LightText; - this.cmbToolF1.Location = new Point(8, 28); + this.cmbToolF1.Location = new Point(8, 24); this.cmbToolF1.Size = new Size(284, 25); this.cmbToolF1.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbToolF1.BackColor = ThemeHelper.CardBackground; this.cmbToolF1.ForeColor = Color.White; this.lblToolF2.Text = "2. Fonksiyon:"; - this.lblToolF2.Location = new Point(8, 60); + this.lblToolF2.Location = new Point(8, 52); this.lblToolF2.AutoSize = true; this.lblToolF2.ForeColor = ThemeHelper.LightText; - this.cmbToolF2.Location = new Point(8, 80); + this.cmbToolF2.Location = new Point(8, 70); this.cmbToolF2.Size = new Size(284, 25); this.cmbToolF2.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbToolF2.BackColor = ThemeHelper.CardBackground; this.cmbToolF2.ForeColor = Color.White; - this.btnCommonTangent.Location = new Point(8, 115); - this.btnNearestPoints.Location = new Point(8, 150); + this.btnCommonTangent.Location = new Point(8, 100); + this.btnNearestPoints.Location = new Point(8, 132); this.lblToolSep.Text = "────────────────────────────"; - this.lblToolSep.Location = new Point(8, 185); - this.lblToolSep.Size = new Size(284, 16); + this.lblToolSep.Location = new Point(8, 163); + this.lblToolSep.Size = new Size(284, 14); this.lblToolSep.ForeColor = ThemeHelper.MutedText; this.lblToolPointTan.Text = "Noktadan Teğet (x₀, y₀):"; - this.lblToolPointTan.Location = new Point(8, 203); + this.lblToolPointTan.Location = new Point(8, 178); this.lblToolPointTan.AutoSize = true; this.lblToolPointTan.ForeColor = ThemeHelper.LightText; - this.txtTanPointX.Location = new Point(8, 225); + this.txtTanPointX.Location = new Point(8, 198); this.txtTanPointX.Size = new Size(70, 24); this.txtTanPointX.Text = "0"; this.txtTanPointX.Font = new Font("Consolas", 9.5F); this.txtTanPointX.BackColor = ThemeHelper.CardBackground; this.txtTanPointX.ForeColor = Color.White; - this.txtTanPointY.Location = new Point(85, 225); + this.txtTanPointY.Location = new Point(85, 198); this.txtTanPointY.Size = new Size(70, 24); this.txtTanPointY.Text = "3"; this.txtTanPointY.Font = new Font("Consolas", 9.5F); this.txtTanPointY.BackColor = ThemeHelper.CardBackground; this.txtTanPointY.ForeColor = Color.White; - this.btnPointTangent.Location = new Point(8, 255); + this.btnPointTangent.Location = new Point(8, 226); - this.txtToolLog.Location = new Point(8, 292); - this.txtToolLog.Size = new Size(284, 140); + this.txtToolLog.Location = new Point(8, 258); + this.txtToolLog.Size = new Size(284, 90); this.txtToolLog.BackColor = Color.FromArgb(11, 17, 32); this.txtToolLog.ForeColor = Color.FromArgb(226, 232, 240); - this.txtToolLog.Font = new Font("Consolas", 8.5F); + this.txtToolLog.Font = new Font("Consolas", 8F); this.txtToolLog.ReadOnly = true; + this.btnExportImage.Location = new Point(8, 355); + this.btnExportCsv.Location = new Point(8, 387); + this.btnExportLatex.Location = new Point(8, 419); + this.tabTools.Controls.Add(this.lblToolF1); this.tabTools.Controls.Add(this.cmbToolF1); this.tabTools.Controls.Add(this.lblToolF2); @@ -470,9 +600,12 @@ namespace MathApp.Controls this.tabTools.Controls.Add(this.txtTanPointY); this.tabTools.Controls.Add(this.btnPointTangent); this.tabTools.Controls.Add(this.txtToolLog); + this.tabTools.Controls.Add(this.btnExportImage); + this.tabTools.Controls.Add(this.btnExportCsv); + this.tabTools.Controls.Add(this.btnExportLatex); // tabShapes - this.tabShapes.Text = "📐 Şekiller"; + this.tabShapes.Text = "Şekiller"; this.tabShapes.BackColor = ThemeHelper.DarkBackground; this.tabShapes.Padding = new Padding(8); @@ -486,74 +619,63 @@ namespace MathApp.Controls this.cmbShapeType.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbShapeType.BackColor = ThemeHelper.CardBackground; this.cmbShapeType.ForeColor = Color.White; - this.cmbShapeType.Items.AddRange(new object[] { - "Daire (Çember)", - "Kare", - "Dikdörtgen", - "Eşkenar Üçgen", - "Elips", - "Düzgün Altıgen" - }); - this.cmbShapeType.SelectedIndex = 0; - int sy = 68; this.lblShapeCenter.Text = "Merkez (x, y):"; - this.lblShapeCenter.Location = new Point(8, sy); + this.lblShapeCenter.Location = new Point(8, 68); this.lblShapeCenter.AutoSize = true; this.lblShapeCenter.ForeColor = ThemeHelper.LightText; - this.txtShapeCenterX.Location = new Point(8, sy + 20); - this.txtShapeCenterX.Size = new Size(60, 24); + this.txtShapeCenterX.Location = new Point(8, 88); + this.txtShapeCenterX.Size = new Size(70, 24); this.txtShapeCenterX.Text = "0"; this.txtShapeCenterX.Font = new Font("Consolas", 9.5F); this.txtShapeCenterX.BackColor = ThemeHelper.CardBackground; this.txtShapeCenterX.ForeColor = Color.White; - this.txtShapeCenterY.Location = new Point(75, sy + 20); - this.txtShapeCenterY.Size = new Size(60, 24); + this.txtShapeCenterY.Location = new Point(85, 88); + this.txtShapeCenterY.Size = new Size(70, 24); this.txtShapeCenterY.Text = "0"; this.txtShapeCenterY.Font = new Font("Consolas", 9.5F); this.txtShapeCenterY.BackColor = ThemeHelper.CardBackground; this.txtShapeCenterY.ForeColor = Color.White; - int sy2 = 120; this.lblShapeDim1.Text = "Yarıçap / Kenar A:"; - this.lblShapeDim1.Location = new Point(8, sy2); + this.lblShapeDim1.Location = new Point(8, 122); this.lblShapeDim1.AutoSize = true; this.lblShapeDim1.ForeColor = ThemeHelper.LightText; - this.txtShapeDim1.Location = new Point(8, sy2 + 20); - this.txtShapeDim1.Size = new Size(80, 24); + this.txtShapeDim1.Location = new Point(8, 142); + this.txtShapeDim1.Size = new Size(140, 24); this.txtShapeDim1.Text = "4"; this.txtShapeDim1.Font = new Font("Consolas", 9.5F); this.txtShapeDim1.BackColor = ThemeHelper.CardBackground; this.txtShapeDim1.ForeColor = Color.White; this.lblShapeDim2.Text = "Yükseklik / Kenar B:"; - this.lblShapeDim2.Location = new Point(100, sy2); + this.lblShapeDim2.Location = new Point(8, 175); this.lblShapeDim2.AutoSize = true; this.lblShapeDim2.ForeColor = ThemeHelper.LightText; - this.txtShapeDim2.Location = new Point(100, sy2 + 20); - this.txtShapeDim2.Size = new Size(80, 24); + this.txtShapeDim2.Location = new Point(8, 195); + this.txtShapeDim2.Size = new Size(140, 24); this.txtShapeDim2.Text = "2"; this.txtShapeDim2.Font = new Font("Consolas", 9.5F); this.txtShapeDim2.BackColor = ThemeHelper.CardBackground; this.txtShapeDim2.ForeColor = Color.White; this.lblShapeAngle.Text = "Dönüş (°):"; - this.lblShapeAngle.Location = new Point(190, sy2); + this.lblShapeAngle.Location = new Point(8, 228); this.lblShapeAngle.AutoSize = true; this.lblShapeAngle.ForeColor = ThemeHelper.LightText; - this.txtShapeAngle.Location = new Point(190, sy2 + 20); - this.txtShapeAngle.Size = new Size(60, 24); + this.txtShapeAngle.Location = new Point(8, 248); + this.txtShapeAngle.Size = new Size(140, 24); this.txtShapeAngle.Text = "0"; this.txtShapeAngle.Font = new Font("Consolas", 9.5F); this.txtShapeAngle.BackColor = ThemeHelper.CardBackground; this.txtShapeAngle.ForeColor = Color.White; - this.btnAddShape.Location = new Point(8, 180); + this.btnAddShape.Location = new Point(8, 290); this.tabShapes.Controls.Add(this.lblShapeType); this.tabShapes.Controls.Add(this.cmbShapeType); @@ -568,52 +690,49 @@ namespace MathApp.Controls this.tabShapes.Controls.Add(this.txtShapeAngle); this.tabShapes.Controls.Add(this.btnAddShape); - this.pnlRightSide.Controls.Add(this.tabManager); - // pnlStatusBar this.pnlStatusBar.Dock = DockStyle.Bottom; - this.pnlStatusBar.Height = 28; - this.pnlStatusBar.BackColor = Color.FromArgb(11, 17, 32); - this.pnlStatusBar.Padding = new Padding(16, 4, 16, 4); + this.pnlStatusBar.Height = 26; + this.pnlStatusBar.BackColor = Color.FromArgb(11, 15, 28); + this.pnlStatusBar.Controls.Add(this.lblStatus); this.lblStatus.Dock = DockStyle.Fill; - this.lblStatus.ForeColor = ThemeHelper.MutedText; - this.lblStatus.Font = new Font("Segoe UI", 9F); + this.lblStatus.ForeColor = Color.FromArgb(148, 163, 184); + this.lblStatus.Font = new Font("Segoe UI", 8.5F); this.lblStatus.TextAlign = ContentAlignment.MiddleLeft; - this.lblStatus.Text = "Hazır. Sol tık: Nokta ekle | Sağ tık: Nokta sil | Shift+Tekerlek: X sündür | Ctrl+Tekerlek: Y sündür"; - this.pnlStatusBar.Controls.Add(this.lblStatus); + this.lblStatus.Padding = new Padding(8, 0, 0, 0); + this.lblStatus.Text = "Hazır. Sol tık: Nokta ekle | Sağ tık: Nokta sil | Shift+Tekerlek: X Genişlet | Ctrl+Tekerlek: Y Genişlet"; // pnlCanvas this.pnlCanvas.Dock = DockStyle.Fill; - this.pnlCanvas.BackColor = Color.FromArgb(11, 17, 32); + this.pnlCanvas.BackColor = Color.FromArgb(15, 23, 42); this.pnlCanvas.Cursor = Cursors.Cross; - this.pnlCanvas.Paint += new PaintEventHandler(this.pnlCanvas_Paint); - this.pnlCanvas.Resize += new EventHandler(this.pnlCanvas_Resize); - // Assemble GraphPlotterControl - this.AutoScaleDimensions = new SizeF(7F, 15F); - this.AutoScaleMode = AutoScaleMode.Font; - this.BackColor = ThemeHelper.DarkBackground; + // Form assembly this.Controls.Add(this.pnlCanvas); - this.Controls.Add(this.pnlStatusBar); this.Controls.Add(this.pnlRightSide); + this.Controls.Add(this.pnlStatusBar); this.Controls.Add(this.pnlControls); this.Controls.Add(this.pnlHeader); - this.Name = "GraphPlotterControl"; - this.Size = new Size(1100, 720); this.pnlControls.ResumeLayout(false); this.pnlControls.PerformLayout(); + this.pnlRightSide.ResumeLayout(false); + this.tabManager.ResumeLayout(false); this.tabFunctions.ResumeLayout(false); this.tabPoints.ResumeLayout(false); this.tabPoints.PerformLayout(); + this.tabSliders.ResumeLayout(false); + this.tabSliders.PerformLayout(); this.tabTools.ResumeLayout(false); this.tabTools.PerformLayout(); this.tabShapes.ResumeLayout(false); this.tabShapes.PerformLayout(); - this.tabManager.ResumeLayout(false); - this.pnlRightSide.ResumeLayout(false); this.pnlStatusBar.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.tbParamA)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamB)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamC)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tbParamK)).EndInit(); this.ResumeLayout(false); } @@ -627,6 +746,7 @@ namespace MathApp.Controls private Button btnEx4; private Label lblEquation; private TextBox txtEquation; + private CheckBox chkPolar; private Label lblMinX; private TextBox txtMinX; private Label lblMaxX; @@ -641,11 +761,15 @@ namespace MathApp.Controls private Button btnZoomYOut; private Button btnAspect1to1; private Button btnResetView; + private CheckBox chkCriticalPoints; + private CheckBox chkInspectMode; + private CheckBox chkShowAsymptotes; private Panel pnlRightSide; private TabControl tabManager; private TabPage tabFunctions; private TabPage tabPoints; + private TabPage tabSliders; private TabPage tabTools; private TabPage tabShapes; @@ -671,6 +795,18 @@ namespace MathApp.Controls private Button btnClearPoints; private Label lblPointHint; + private Label lblParamA; + private TrackBar tbParamA; + private Label lblParamB; + private TrackBar tbParamB; + private Label lblParamC; + private TrackBar tbParamC; + private Label lblParamK; + private TrackBar tbParamK; + private Button btnAnimate; + private Button btnResetParams; + private Label lblSliderHint; + private Label lblToolF1; private ComboBox cmbToolF1; private Label lblToolF2; @@ -683,6 +819,9 @@ namespace MathApp.Controls private TextBox txtTanPointY; private Button btnPointTangent; private RichTextBox txtToolLog; + private Button btnExportImage; + private Button btnExportCsv; + private Button btnExportLatex; private Label lblShapeType; private ComboBox cmbShapeType; diff --git a/src/ttCalculator/Controls/GraphPlotterControl.cs b/src/ttCalculator/Controls/GraphPlotterControl.cs index 07e52b6..41a4d53 100644 --- a/src/ttCalculator/Controls/GraphPlotterControl.cs +++ b/src/ttCalculator/Controls/GraphPlotterControl.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; +using MathApp.Core; namespace MathApp.Controls { @@ -16,8 +18,8 @@ namespace MathApp.Controls { Circle, Square, - Cross, - Diamond + Diamond, + Cross } public class PlotPoint @@ -48,6 +50,7 @@ namespace MathApp.Controls public float VerticalX { get; set; } = 0f; public float VerticalMinY { get; set; } = 0f; public float VerticalMaxY { get; set; } = 0f; + public bool IsPolar { get; set; } = false; public List> Segments { get; set; } = new List>(); @@ -55,13 +58,25 @@ namespace MathApp.Controls { string vis = Visible ? "✓" : "✗"; if (IsVerticalLine) return $"{vis} [Doğru] x = {VerticalX:F2}"; + if (IsPolar) return $"{vis} [Polar] r = {Equation}"; string clampStr = ClampDomain ? $" [{DomainMinX:F1}, {DomainMaxX:F1}]" : ""; return $"{vis} y = {Equation}{clampStr}"; } } + public class CriticalPoint + { + public float X { get; set; } + public float Y { get; set; } + public string TypeName { get; set; } + public Color Color { get; set; } + public string Details { get; set; } + } + private readonly List _curves = new List(); private readonly List _points = new List(); + private readonly List _criticalPoints = new List(); + private readonly List _asymptotePoles = new List(); private readonly Color[] _palette = new Color[] { @@ -88,6 +103,14 @@ namespace MathApp.Controls private Point lastHoverRecorded = new Point(-999, -999); private Timer resampleDebounceTimer; + // Dynamic Parameters (Sliders) + private float _paramA = 1.0f; + private float _paramB = 1.0f; + private float _paramC = 0.0f; + private float _paramK = 1.0f; + private Timer _animTimer; + private float _animPhase = 0f; + public GraphPlotterControl() { InitializeComponent(); @@ -99,10 +122,14 @@ namespace MathApp.Controls if (!isDragging) { GenerateAllPoints(false, isDraft: false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); } }; + _animTimer = new Timer { Interval = 33 }; // ~30-60 FPS + _animTimer.Tick += AnimTimer_Tick; + typeof(Panel).InvokeMember( "DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, @@ -125,10 +152,10 @@ namespace MathApp.Controls txtMaxX.KeyDown += (s, e) => { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; AddCurrentInputCurve(); } }; // Presets - btnEx1.Click += (s, e) => { txtEquation.Text = "sin(x) * x"; AddCurrentInputCurve(); }; - btnEx2.Click += (s, e) => { txtEquation.Text = "x^3 - 3*x"; AddCurrentInputCurve(); }; - btnEx3.Click += (s, e) => { txtEquation.Text = "exp(-x^2/4)*cos(2*x)"; AddCurrentInputCurve(); }; - btnEx4.Click += (s, e) => { txtEquation.Text = "1 / (x^2 - 1)"; AddCurrentInputCurve(); }; + btnEx1.Click += (s, e) => { txtEquation.Text = "sin(x) * x"; chkPolar.Checked = false; AddCurrentInputCurve(); }; + btnEx2.Click += (s, e) => { txtEquation.Text = "x^3 - 3*x"; chkPolar.Checked = false; AddCurrentInputCurve(); }; + btnEx3.Click += (s, e) => { txtEquation.Text = "exp(-x^2/4)*cos(2*x)"; chkPolar.Checked = false; AddCurrentInputCurve(); }; + btnEx4.Click += (s, e) => { txtEquation.Text = "1 / (x^2 - 1)"; chkPolar.Checked = false; AddCurrentInputCurve(); }; // Scaling & Zoom toolbar btnZoomXIn.Click += (s, e) => ScaleAxisX(0.7f); @@ -139,6 +166,10 @@ namespace MathApp.Controls btnAspect1to1.Click += (s, e) => LockAspect1to1(); btnResetView.Click += (s, e) => ResetView(); + chkCriticalPoints.CheckedChanged += (s, e) => { DetectCriticalPoints(); pnlCanvas.Invalidate(); }; + chkInspectMode.CheckedChanged += (s, e) => pnlCanvas.Invalidate(); + chkShowAsymptotes.CheckedChanged += (s, e) => pnlCanvas.Invalidate(); + // Canvas Mouse Events pnlCanvas.MouseDown += PnlCanvas_MouseDown; pnlCanvas.MouseMove += PnlCanvas_MouseMove; @@ -175,15 +206,103 @@ namespace MathApp.Controls } }; + // Parameters Tab Events (Sliders) + tbParamA.Scroll += (s, e) => { _paramA = tbParamA.Value / 10f; lblParamA.Text = $"a = {_paramA:F2}"; UpdateParametersAndReplot(); }; + tbParamB.Scroll += (s, e) => { _paramB = tbParamB.Value / 10f; lblParamB.Text = $"b = {_paramB:F2}"; UpdateParametersAndReplot(); }; + tbParamC.Scroll += (s, e) => { _paramC = tbParamC.Value / 10f; lblParamC.Text = $"c = {_paramC:F2}"; UpdateParametersAndReplot(); }; + tbParamK.Scroll += (s, e) => { _paramK = tbParamK.Value / 10f; lblParamK.Text = $"k = {_paramK:F2}"; UpdateParametersAndReplot(); }; + + btnAnimate.Click += BtnAnimate_Click; + btnResetParams.Click += (s, e) => + { + tbParamA.Value = 10; _paramA = 1.0f; lblParamA.Text = "a = 1.00"; + tbParamB.Value = 10; _paramB = 1.0f; lblParamB.Text = "b = 1.00"; + tbParamC.Value = 0; _paramC = 0.0f; lblParamC.Text = "c = 0.00"; + tbParamK.Value = 10; _paramK = 1.0f; lblParamK.Text = "k = 1.00"; + UpdateParametersAndReplot(); + }; + // Tools Tab btnCommonTangent.Click += BtnCommonTangent_Click; btnNearestPoints.Click += BtnNearestPoints_Click; btnPointTangent.Click += BtnPointTangent_Click; + // Export Events + btnExportImage.Click += BtnExportImage_Click; + btnExportCsv.Click += BtnExportCsv_Click; + btnExportLatex.Click += BtnExportLatex_Click; + // Shapes Tab btnAddShape.Click += BtnAddShape_Click; + + // Populate combo options + cmbCurveStyle.Items.AddRange(new object[] { "Düz (Solid)", "Kesikli (Dash)", "Noktalı (Dot)" }); + cmbCurveStyle.SelectedIndex = 0; + + cmbCurveThickness.Items.AddRange(new object[] { "1 px", "2 px", "3 px", "4 px", "6 px" }); + cmbCurveThickness.SelectedIndex = 1; + + cmbPtShape.Items.AddRange(new object[] { "Daire", "Kare", "Baklava", "Artı (+)" }); + cmbPtShape.SelectedIndex = 0; + + cmbShapeType.Items.AddRange(new object[] { "Çember / Daire", "Kare / Dikdörtgen", "Eşkenar Üçgen", "Çokgen (5-Gen)", "Çokgen (6-Gen)" }); + cmbShapeType.SelectedIndex = 0; } + #region Parameters & Sliders + + private void SetCurveParameters(PlotCurve curve) + { + if (curve?.Compiled == null) return; + curve.Compiled.SetVariable("a", (decimal)_paramA); + curve.Compiled.SetVariable("b", (decimal)_paramB); + curve.Compiled.SetVariable("c", (decimal)_paramC); + curve.Compiled.SetVariable("k", (decimal)_paramK); + } + + private void UpdateParametersAndReplot() + { + foreach (var c in _curves) + { + if (c.Visible && !c.IsVerticalLine) + { + SetCurveParameters(c); + GenerateCurveSegments(c, isDraft: false); + } + } + DetectCriticalPoints(); + pnlCanvas.Invalidate(); + } + + private void AnimTimer_Tick(object sender, EventArgs e) + { + _animPhase += 0.06f; + float animatedC = (float)Math.Sin(_animPhase) * 5f; + _paramC = (float)Math.Round(animatedC, 2); + tbParamC.Value = Math.Max(-100, Math.Min(100, (int)(_paramC * 10))); + lblParamC.Text = $"c = {_paramC:F2}"; + + UpdateParametersAndReplot(); + } + + private void BtnAnimate_Click(object sender, EventArgs e) + { + if (_animTimer.Enabled) + { + _animTimer.Stop(); + btnAnimate.Text = "▶ Canlı Dalga Animasyonu"; + btnAnimate.BackColor = ThemeHelper.AccentBlue; + } + else + { + _animTimer.Start(); + btnAnimate.Text = "⏸ Animasyonu Durdur"; + btnAnimate.BackColor = ThemeHelper.AmberWarning; + } + } + + #endregion + #region Scaling & Zooming private void ScaleAxisX(float factor) @@ -198,6 +317,7 @@ namespace MathApp.Controls txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture); GenerateAllPoints(false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); } @@ -211,6 +331,7 @@ namespace MathApp.Controls rangeMaxY = midY + halfH; GenerateAllPoints(false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); } @@ -220,14 +341,16 @@ namespace MathApp.Controls float w = Math.Max(1, pnlCanvas.Width); float h = Math.Max(1, pnlCanvas.Height); - float targetH = rangeW * (h / w); + float targetRangeH = rangeW * (h / w); float midY = (rangeMaxY + rangeMinY) / 2f; - rangeMinY = midY - targetH / 2f; - rangeMaxY = midY + targetH / 2f; + + rangeMinY = midY - targetRangeH / 2f; + rangeMaxY = midY + targetRangeH / 2f; GenerateAllPoints(false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); - lblStatus.Text = "Eksen oranları 1:1 olarak eşitlendi."; + lblStatus.Text = "Eksenler 1:1 orana kilitlendi."; } private void ResetView() @@ -236,15 +359,19 @@ namespace MathApp.Controls rangeMaxX = 10f; rangeMinY = -6f; rangeMaxY = 6f; + txtMinX.Text = "-10"; txtMaxX.Text = "10"; + GenerateAllPoints(false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); + lblStatus.Text = "Görünüm varsayılana sıfırlandı."; } #endregion - #region Curve Management + #region Curve & Function Management private void AddCurrentInputCurve() { @@ -256,10 +383,17 @@ namespace MathApp.Controls if (minX >= maxX) { minX = -10f; maxX = 10f; } bool clamp = chkClampRange.Checked; - AddFunctionCurve(eq, clamp, minX, maxX); + bool isPolar = chkPolar.Checked || eq.StartsWith("r=", StringComparison.OrdinalIgnoreCase); + + if (isPolar && eq.StartsWith("r=", StringComparison.OrdinalIgnoreCase)) + { + eq = eq.Substring(2).Trim(); + } + + AddFunctionCurve(eq, clamp, minX, maxX, isPolar: isPolar); } - public void AddFunctionCurve(string eq, bool clamp, float minX, float maxX, Color? color = null, DashStyle dash = DashStyle.Solid, float thickness = 2.4f) + public void AddFunctionCurve(string eq, bool clamp, float minX, float maxX, Color? color = null, DashStyle dash = DashStyle.Solid, float thickness = 2.4f, bool isPolar = false) { try { @@ -277,17 +411,20 @@ namespace MathApp.Controls Visible = true, ClampDomain = clamp, DomainMinX = minX, - DomainMaxX = maxX + DomainMaxX = maxX, + IsPolar = isPolar }; + SetCurveParameters(curve); _curves.Add(curve); RefreshCurvesList(); RefreshToolCombos(); GenerateCurveSegments(curve, isDraft: false); + DetectCriticalPoints(); pnlCanvas.Invalidate(); - lblStatus.Text = $"✓ Eğri eklendi: y = {eq}"; + lblStatus.Text = isPolar ? $"✓ Polar eğri eklendi: r = {eq}" : $"✓ Eğri eklendi: y = {eq}"; lblStatus.ForeColor = Color.FromArgb(52, 211, 153); } catch (Exception ex) @@ -350,30 +487,38 @@ namespace MathApp.Controls private void LstCurves_SelectedIndexChanged(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - btnCurveColor.BackColor = c.Color; - if (c.DashStyle == DashStyle.Solid) cmbCurveStyle.SelectedIndex = 0; - else if (c.DashStyle == DashStyle.Dash) cmbCurveStyle.SelectedIndex = 1; - else cmbCurveStyle.SelectedIndex = 2; + btnCurveColor.BackColor = curve.Color; + cmbCurveThickness.SelectedIndex = curve.Thickness switch + { + 1f => 0, + 2.4f or 2f => 1, + 3f => 2, + 4f => 3, + 6f => 4, + _ => 1 + }; - if (c.Thickness <= 1.2f) cmbCurveThickness.SelectedIndex = 0; - else if (c.Thickness <= 2.2f) cmbCurveThickness.SelectedIndex = 1; - else if (c.Thickness <= 3.2f) cmbCurveThickness.SelectedIndex = 2; - else cmbCurveThickness.SelectedIndex = 3; + cmbCurveStyle.SelectedIndex = curve.DashStyle switch + { + DashStyle.Solid => 0, + DashStyle.Dash => 1, + DashStyle.Dot => 2, + _ => 0 + }; } } private void BtnCurveColor_Click(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - using (ColorDialog cd = new ColorDialog()) + using (ColorDialog cd = new ColorDialog { Color = curve.Color }) { - cd.Color = c.Color; if (cd.ShowDialog() == DialogResult.OK) { - c.Color = cd.Color; + curve.Color = cd.Color; btnCurveColor.BackColor = cd.Color; pnlCanvas.Invalidate(); } @@ -383,61 +528,76 @@ namespace MathApp.Controls private void CmbCurveStyle_SelectedIndexChanged(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - if (cmbCurveStyle.SelectedIndex == 0) c.DashStyle = DashStyle.Solid; - else if (cmbCurveStyle.SelectedIndex == 1) c.DashStyle = DashStyle.Dash; - else c.DashStyle = DashStyle.Dot; + curve.DashStyle = cmbCurveStyle.SelectedIndex switch + { + 1 => DashStyle.Dash, + 2 => DashStyle.Dot, + _ => DashStyle.Solid + }; pnlCanvas.Invalidate(); } } private void CmbCurveThickness_SelectedIndexChanged(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - c.Thickness = (cmbCurveThickness.SelectedIndex + 1) * 1.2f; + curve.Thickness = cmbCurveThickness.SelectedIndex switch + { + 0 => 1f, + 1 => 2.4f, + 2 => 3f, + 3 => 4f, + 4 => 6f, + _ => 2.4f + }; pnlCanvas.Invalidate(); } } private void BtnCurveToggle_Click(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - c.Visible = !c.Visible; - int idx = lstCurves.SelectedIndex; + curve.Visible = !curve.Visible; RefreshCurvesList(); - lstCurves.SelectedIndex = idx; + DetectCriticalPoints(); pnlCanvas.Invalidate(); } } private void BtnCurveDelete_Click(object sender, EventArgs e) { - if (lstCurves.SelectedItem is PlotCurve c) + if (lstCurves.SelectedItem is PlotCurve curve) { - _curves.Remove(c); + _curves.Remove(curve); RefreshCurvesList(); RefreshToolCombos(); + DetectCriticalPoints(); pnlCanvas.Invalidate(); - lblStatus.Text = "Eğri listeden silindi."; } } private void EditSelectedCurve() { - if (lstCurves.SelectedItem is PlotCurve c && !c.IsVerticalLine) + if (lstCurves.SelectedItem is PlotCurve curve && !curve.IsVerticalLine) { - txtEquation.Text = c.Equation; - chkClampRange.Checked = c.ClampDomain; - if (c.ClampDomain) + txtEquation.Text = curve.Equation; + chkPolar.Checked = curve.IsPolar; + if (curve.ClampDomain) { - txtMinX.Text = c.DomainMinX.ToString(CultureInfo.InvariantCulture); - txtMaxX.Text = c.DomainMaxX.ToString(CultureInfo.InvariantCulture); + chkClampRange.Checked = true; + txtMinX.Text = curve.DomainMinX.ToString("0.##", CultureInfo.InvariantCulture); + txtMaxX.Text = curve.DomainMaxX.ToString("0.##", CultureInfo.InvariantCulture); + } + else + { + chkClampRange.Checked = false; } txtEquation.Focus(); - lblStatus.Text = $"Eğri düzenleme için yüklendi: y = {c.Equation}"; + lblStatus.Text = $"Eğri düzenleme için kutuya yüklendi: {curve.Equation}"; } } @@ -446,67 +606,24 @@ namespace MathApp.Controls _curves.Clear(); RefreshCurvesList(); RefreshToolCombos(); + _criticalPoints.Clear(); + _asymptotePoles.Clear(); pnlCanvas.Invalidate(); + lblStatus.Text = "Tüm eğriler temizlendi."; } #endregion - #region Point Management - - private void RefreshPointsList() - { - lstPoints.BeginUpdate(); - lstPoints.Items.Clear(); - foreach (var p in _points) - { - lstPoints.Items.Add(p); - } - lstPoints.EndUpdate(); - if (_points.Count > 0 && lstPoints.SelectedIndex < 0) - lstPoints.SelectedIndex = _points.Count - 1; - } - - private void BtnAddPoint_Click(object sender, EventArgs e) - { - float px = ParseFloat(txtPtX.Text, 0f); - float py = ParseFloat(txtPtY.Text, 0f); - - PointShape shape = (PointShape)Math.Max(0, cmbPtShape.SelectedIndex); - _points.Add(new PlotPoint - { - X = px, - Y = py, - Color = btnPtColor.BackColor, - Shape = shape, - Size = 8 - }); - - RefreshPointsList(); - pnlCanvas.Invalidate(); - lblStatus.Text = $"Nokta eklendi: ({px:F2}, {py:F2})"; - } - - private void BtnDeletePoint_Click(object sender, EventArgs e) - { - if (lstPoints.SelectedItem is PlotPoint p) - { - _points.Remove(p); - RefreshPointsList(); - pnlCanvas.Invalidate(); - lblStatus.Text = "Nokta silindi."; - } - } - - #endregion - - #region Point Generation & Segment Caching + #region Point Generation, Asymptote & Critical Points private void GenerateAllPoints(bool autoFitY, bool isDraft = false) { + _asymptotePoles.Clear(); foreach (var c in _curves) { if (c.Visible && !c.IsVerticalLine && c.Compiled != null) { + SetCurveParameters(c); GenerateCurveSegments(c, isDraft); } } @@ -517,19 +634,73 @@ namespace MathApp.Controls curve.Segments.Clear(); if (curve.Compiled == null) return; + // 1. Polar Curve Sampling + if (curve.IsPolar) + { + float minTheta = 0f; + float maxTheta = (float)(4 * Math.PI); + int polarSamples = isDraft ? 400 : 1200; + float dTheta = (maxTheta - minTheta) / polarSamples; + + List polarSeg = new List(); + bool prevRadP = Function.UseRadians; + Function.UseRadians = true; + + try + { + for (int i = 0; i <= polarSamples; i++) + { + float theta = minTheta + i * dTheta; + try + { + curve.Compiled.SetVariable("theta", (decimal)theta); + curve.Compiled.SetVariable("x", (decimal)theta); + curve.Compiled.SetVariable("t", (decimal)theta); + curve.Compiled.EvaluatePostfix(); + float r = (float)curve.Compiled.Result; + + if (!float.IsNaN(r) && !float.IsInfinity(r) && Math.Abs(r) < 1e5f) + { + float px = (float)(r * Math.Cos(theta)); + float py = (float)(r * Math.Sin(theta)); + polarSeg.Add(new PointF(px, py)); + } + else + { + if (polarSeg.Count > 1) curve.Segments.Add(polarSeg); + polarSeg = new List(); + } + } + catch + { + if (polarSeg.Count > 1) curve.Segments.Add(polarSeg); + polarSeg = new List(); + } + } + if (polarSeg.Count > 1) curve.Segments.Add(polarSeg); + } + finally + { + Function.UseRadians = prevRadP; + } + return; + } + + // 2. Cartesian Curve Sampling float drawMinX = curve.ClampDomain ? Math.Max(rangeMinX, curve.DomainMinX) : rangeMinX; float drawMaxX = curve.ClampDomain ? Math.Min(rangeMaxX, curve.DomainMaxX) : rangeMaxX; if (drawMinX >= drawMaxX) return; int sampleCount = isDraft - ? Math.Min(200, Math.Max(100, pnlCanvas.Width / 3)) - : Math.Max(500, pnlCanvas.Width * 2); + ? Math.Min(250, Math.Max(100, pnlCanvas.Width / 3)) + : Math.Max(600, pnlCanvas.Width * 2); float step = (drawMaxX - drawMinX) / sampleCount; if (step <= 0) return; List currentSegment = new List(); float? prevY = null; + float? prevX = null; bool prevRad = Function.UseRadians; Function.UseRadians = true; @@ -551,15 +722,29 @@ namespace MathApp.Controls continue; } - // Asymptote jump filter - if (prevY.HasValue && Math.Abs(y - prevY.Value) > (rangeMaxY - rangeMinY) * 2.5f && (y * prevY.Value < 0)) + // Robust Asymptote Jump Filter: prevents drawing false lines connecting across poles + float viewHeight = rangeMaxY - rangeMinY; + bool isAsymptoteJump = prevY.HasValue && ( + Math.Abs(y - prevY.Value) > viewHeight * 1.5f && ( + (y * prevY.Value < 0) || Math.Abs(y) > viewHeight * 2f || Math.Abs(prevY.Value) > viewHeight * 2f + ) + ); + + if (isAsymptoteJump) { if (currentSegment.Count > 1) curve.Segments.Add(currentSegment); currentSegment = new List(); + + // Record asymptote vertical pole location + if (prevX.HasValue && !_asymptotePoles.Any(p => Math.Abs(p - x) < step * 2)) + { + _asymptotePoles.Add((prevX.Value + x) / 2f); + } } currentSegment.Add(new PointF(x, y)); prevY = y; + prevX = x; } catch { @@ -580,69 +765,182 @@ namespace MathApp.Controls } } + private void DetectCriticalPoints() + { + _criticalPoints.Clear(); + if (!chkCriticalPoints.Checked) return; + + var activeCurves = _curves.Where(c => c.Visible && !c.IsVerticalLine && !c.IsPolar && c.Compiled != null).ToList(); + if (activeCurves.Count == 0) return; + + int steps = 140; + float dx = (rangeMaxX - rangeMinX) / steps; + if (dx <= 0) return; + + foreach (var curve in activeCurves) + { + SetCurveParameters(curve); + float? prevX = null; + decimal? prevY = null; + decimal? prevD1 = null; + decimal? prevD2 = null; + + for (int i = 0; i <= steps; i++) + { + float x = rangeMinX + i * dx; + try + { + decimal yDec = NumericalMethods.EvaluateCompiled(curve.Compiled, "x", (decimal)x); + if (Math.Abs(yDec) > 1000m) continue; + + decimal h = 0.005m; + decimal d1 = (NumericalMethods.EvaluateCompiled(curve.Compiled, "x", (decimal)x + h) - + NumericalMethods.EvaluateCompiled(curve.Compiled, "x", (decimal)x - h)) / (2m * h); + decimal d2 = (NumericalMethods.EvaluateCompiled(curve.Compiled, "x", (decimal)x + h) - + 2m * yDec + + NumericalMethods.EvaluateCompiled(curve.Compiled, "x", (decimal)x - h)) / (h * h); + + // 1. Root (f(x) = 0) + if (prevY.HasValue && prevY.Value * yDec <= 0m && Math.Abs(yDec - prevY.Value) < 25m) + { + float rootX = x - (float)(yDec * (decimal)dx / (yDec - prevY.Value == 0 ? 1m : (yDec - prevY.Value))); + if (rootX >= rangeMinX && rootX <= rangeMaxX && !_criticalPoints.Any(cp => Math.Abs(cp.X - rootX) < dx && cp.TypeName == "Kök")) + { + _criticalPoints.Add(new CriticalPoint + { + X = rootX, + Y = 0f, + TypeName = "Kök", + Color = Color.FromArgb(16, 185, 129), + Details = $"Kök [f(x)=0]: ({rootX:F3}, 0.000)" + }); + } + } + + // 2. Extremum (f'(x) = 0) + if (prevD1.HasValue && prevD1.Value * d1 <= 0m && Math.Abs(d1 - prevD1.Value) < 60m) + { + float extX = x - dx / 2f; + float extY = (float)yDec; + if (extX >= rangeMinX && extX <= rangeMaxX) + { + bool isMax = d2 < 0m; + string type = isMax ? "Yerel Maks" : "Yerel Min"; + Color col = isMax ? Color.FromArgb(244, 63, 94) : Color.FromArgb(56, 189, 248); + + if (!_criticalPoints.Any(cp => Math.Abs(cp.X - extX) < dx && cp.TypeName == type)) + { + _criticalPoints.Add(new CriticalPoint + { + X = extX, + Y = extY, + TypeName = type, + Color = col, + Details = $"{type} [f'=0]: ({extX:F3}, {extY:F3})" + }); + } + } + } + + // 3. Inflection Point (f''(x) = 0) + if (prevD2.HasValue && prevD2.Value * d2 <= 0m && Math.Abs(d2 - prevD2.Value) < 120m) + { + float inflX = x - dx / 2f; + float inflY = (float)yDec; + if (inflX >= rangeMinX && inflX <= rangeMaxX && !_criticalPoints.Any(cp => Math.Abs(cp.X - inflX) < dx && cp.TypeName == "Büküm")) + { + _criticalPoints.Add(new CriticalPoint + { + X = inflX, + Y = inflY, + TypeName = "Büküm", + Color = Color.FromArgb(245, 158, 11), + Details = $"Büküm [f''=0]: ({inflX:F3}, {inflY:F3})" + }); + } + } + + prevX = x; + prevY = yDec; + prevD1 = d1; + prevD2 = d2; + } + catch { } + } + } + + // 4. Intersections between curves + if (activeCurves.Count >= 2) + { + for (int a = 0; a < activeCurves.Count; a++) + { + for (int b = a + 1; b < activeCurves.Count; b++) + { + var c1 = activeCurves[a]; + var c2 = activeCurves[b]; + decimal? prevDiff = null; + + for (int i = 0; i <= steps; i++) + { + float x = rangeMinX + i * dx; + try + { + decimal y1 = NumericalMethods.EvaluateCompiled(c1.Compiled, "x", (decimal)x); + decimal y2 = NumericalMethods.EvaluateCompiled(c2.Compiled, "x", (decimal)x); + decimal diff = y1 - y2; + + if (prevDiff.HasValue && prevDiff.Value * diff <= 0m && Math.Abs(diff - prevDiff.Value) < 30m) + { + float intX = x - dx / 2f; + float intY = (float)y1; + if (!_criticalPoints.Any(cp => Math.Abs(cp.X - intX) < dx && cp.TypeName == "Kesişim")) + { + _criticalPoints.Add(new CriticalPoint + { + X = intX, + Y = intY, + TypeName = "Kesişim", + Color = Color.FromArgb(168, 85, 247), + Details = $"Kesişim: ({intX:F3}, {intY:F3})" + }); + } + } + prevDiff = diff; + } + catch { } + } + } + } + } + } + #endregion - #region Mouse Canvas Handlers - - private void PnlCanvas_MouseWheel(object sender, MouseEventArgs e) - { - float zoom = (e.Delta > 0) ? 0.85f : 1.18f; - - bool shift = (Control.ModifierKeys & Keys.Shift) == Keys.Shift; - bool ctrl = (Control.ModifierKeys & Keys.Control) == Keys.Control; - - if (shift) - { - ScaleAxisX(zoom); - return; - } - if (ctrl) - { - ScaleAxisY(zoom); - return; - } - - float rangeW = rangeMaxX - rangeMinX; - float rangeH = rangeMaxY - rangeMinY; - if (rangeW < 1e-4f && zoom < 1f) return; - if (rangeW > 1e6f && zoom > 1f) return; - - float midX = (rangeMaxX + rangeMinX) / 2f; - float midY = (rangeMaxY + rangeMinY) / 2f; - - rangeMinX = midX - (rangeW * zoom) / 2f; - rangeMaxX = midX + (rangeW * zoom) / 2f; - rangeMinY = midY - (rangeH * zoom) / 2f; - rangeMaxY = midY + (rangeH * zoom) / 2f; - - txtMinX.Text = rangeMinX.ToString("0.##", CultureInfo.InvariantCulture); - txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture); - - GenerateAllPoints(false, isDraft: true); - resampleDebounceTimer.Stop(); - resampleDebounceTimer.Start(); - pnlCanvas.Invalidate(); - } + #region Canvas Mouse Interaction private void PnlCanvas_MouseDown(object sender, MouseEventArgs e) { - pnlCanvas.Focus(); - - if (e.Button == MouseButtons.Right) + if (e.Button == MouseButtons.Left) { - // Requirement 1: Right-click deletes individual point! + isDragging = true; + didMoveMouse = false; + lastMousePos = e.Location; + Cursor = Cursors.SizeAll; + } + else if (e.Button == MouseButtons.Right) + { + // Delete point under right click float w = Math.Max(1, pnlCanvas.Width); float h = Math.Max(1, pnlCanvas.Height); - float MapX(float x) => (x - rangeMinX) / (rangeMaxX - rangeMinX) * w; - float MapY(float y) => h - ((y - rangeMinY) / (rangeMaxY - rangeMinY) * h); PlotPoint toRemove = null; - for (int i = _points.Count - 1; i >= 0; i--) + foreach (var p in _points) { - var p = _points[i]; - float sx = MapX(p.X); - float sy = MapY(p.Y); - if (Math.Abs(sx - e.X) < 14 && Math.Abs(sy - e.Y) < 14) + float sx = (p.X - rangeMinX) / (rangeMaxX - rangeMinX) * w; + float sy = h - ((p.Y - rangeMinY) / (rangeMaxY - rangeMinY) * h); + + float distSq = (e.X - sx) * (e.X - sx) + (e.Y - sy) * (e.Y - sy); + if (distSq <= 120f) { toRemove = p; break; @@ -653,26 +951,19 @@ namespace MathApp.Controls { _points.Remove(toRemove); RefreshPointsList(); - pnlCanvas.Invalidate(); lblStatus.Text = $"Nokta silindi: ({toRemove.X:F2}, {toRemove.Y:F2})"; + lblStatus.ForeColor = Color.FromArgb(244, 63, 94); + pnlCanvas.Invalidate(); } - return; - } - - if (e.Button == MouseButtons.Left) - { - isDragging = true; - didMoveMouse = false; - lastMousePos = e.Location; - Cursor = Cursors.SizeAll; } } 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; @@ -680,34 +971,25 @@ namespace MathApp.Controls float rangeW = rangeMaxX - rangeMinX; float rangeH = rangeMaxY - rangeMinY; - float w = Math.Max(1, pnlCanvas.Width); - float h = Math.Max(1, pnlCanvas.Height); - float moveX = -dx * (rangeW / w); - float moveY = dy * (rangeH / h); + float shiftX = (dx / (float)pnlCanvas.Width) * rangeW; + float shiftY = (dy / (float)pnlCanvas.Height) * rangeH; - rangeMinX += moveX; - rangeMaxX += moveX; - rangeMinY += moveY; - rangeMaxY += moveY; + rangeMinX -= shiftX; + rangeMaxX -= shiftX; + rangeMinY += shiftY; + rangeMaxY += shiftY; + lastMousePos = e.Location; txtMinX.Text = rangeMinX.ToString("0.##", CultureInfo.InvariantCulture); txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture); - lastMousePos = e.Location; GenerateAllPoints(false, isDraft: true); - resampleDebounceTimer.Stop(); - resampleDebounceTimer.Start(); pnlCanvas.Invalidate(); } else { - if (Math.Abs(e.X - lastHoverRecorded.X) >= 2 || Math.Abs(e.Y - lastHoverRecorded.Y) >= 2) - { - lastHoverRecorded = e.Location; - hoverMousePos = e.Location; - pnlCanvas.Invalidate(); - } + pnlCanvas.Invalidate(); } } @@ -717,36 +999,35 @@ namespace MathApp.Controls { if (!didMoveMouse) { - // Snap point onto active curve or clicked coordinate + // Check if clicked near critical point float w = Math.Max(1, pnlCanvas.Width); float h = Math.Max(1, pnlCanvas.Height); - float xPct = e.X / w; - float logX = rangeMinX + xPct * (rangeMaxX - rangeMinX); - var activeCurve = _curves.FirstOrDefault(c => c.Visible && !c.IsVerticalLine && c.Compiled != null); - float logY; - - if (activeCurve != null) + CriticalPoint clickedCp = null; + foreach (var cp in _criticalPoints) { - bool prevRad = Function.UseRadians; - Function.UseRadians = true; - try + float sx = (cp.X - rangeMinX) / (rangeMaxX - rangeMinX) * w; + float sy = h - ((cp.Y - rangeMinY) / (rangeMaxY - rangeMinY) * h); + if ((e.X - sx) * (e.X - sx) + (e.Y - sy) * (e.Y - sy) <= 120f) { - decimal fx = NumericalMethods.EvaluateCompiled(activeCurve.Compiled, "x", (decimal)logX); - logY = (float)fx; - } - catch - { - float yPct = (h - e.Y) / h; - logY = rangeMinY + yPct * (rangeMaxY - rangeMinY); - } - finally - { - Function.UseRadians = prevRad; + clickedCp = cp; + break; } } + + float logX, logY; + Color ptColor = btnPtColor.BackColor; + PointShape ptShape = (PointShape)Math.Max(0, cmbPtShape.SelectedIndex); + + if (clickedCp != null) + { + logX = clickedCp.X; + logY = clickedCp.Y; + ptColor = clickedCp.Color; + } else { + logX = rangeMinX + (e.X / w) * (rangeMaxX - rangeMinX); float yPct = (h - e.Y) / h; logY = rangeMinY + yPct * (rangeMaxY - rangeMinY); } @@ -755,8 +1036,8 @@ namespace MathApp.Controls { X = logX, Y = logY, - Color = btnPtColor.BackColor, - Shape = (PointShape)Math.Max(0, cmbPtShape.SelectedIndex), + Color = ptColor, + Shape = ptShape, Size = 8 }); @@ -767,11 +1048,55 @@ namespace MathApp.Controls isDragging = false; resampleDebounceTimer.Stop(); GenerateAllPoints(false, isDraft: false); + DetectCriticalPoints(); Cursor = Cursors.Cross; pnlCanvas.Invalidate(); } } + private void PnlCanvas_MouseWheel(object sender, MouseEventArgs e) + { + float zoomFactor = (e.Delta > 0) ? 0.85f : 1.18f; + + float w = Math.Max(1, pnlCanvas.Width); + float h = Math.Max(1, pnlCanvas.Height); + + float mouseLogX = rangeMinX + (e.X / w) * (rangeMaxX - rangeMinX); + float mouseLogY = rangeMinY + ((h - e.Y) / h) * (rangeMaxY - rangeMinY); + + bool isShift = (ModifierKeys & Keys.Shift) == Keys.Shift; + bool isCtrl = (ModifierKeys & Keys.Control) == Keys.Control; + + if (isShift) + { + rangeMinX = mouseLogX + (rangeMinX - mouseLogX) * zoomFactor; + rangeMaxX = mouseLogX + (rangeMaxX - mouseLogX) * zoomFactor; + lblStatus.Text = "X Ekseni ölçekleniyor (Shift+Tekerlek)..."; + } + else if (isCtrl) + { + rangeMinY = mouseLogY + (rangeMinY - mouseLogY) * zoomFactor; + rangeMaxY = mouseLogY + (rangeMaxY - mouseLogY) * zoomFactor; + lblStatus.Text = "Y Ekseni ölçekleniyor (Ctrl+Tekerlek)..."; + } + else + { + rangeMinX = mouseLogX + (rangeMinX - mouseLogX) * zoomFactor; + rangeMaxX = mouseLogX + (rangeMaxX - mouseLogX) * zoomFactor; + rangeMinY = mouseLogY + (rangeMinY - mouseLogY) * zoomFactor; + rangeMaxY = mouseLogY + (rangeMaxY - mouseLogY) * zoomFactor; + } + + txtMinX.Text = rangeMinX.ToString("0.##", CultureInfo.InvariantCulture); + txtMaxX.Text = rangeMaxX.ToString("0.##", CultureInfo.InvariantCulture); + + GenerateAllPoints(false, isDraft: true); + pnlCanvas.Invalidate(); + + resampleDebounceTimer.Stop(); + resampleDebounceTimer.Start(); + } + #endregion #region Rendering (Paint) @@ -788,8 +1113,8 @@ namespace MathApp.Controls float MapX(float x) => (x - rangeMinX) / (rangeMaxX - rangeMinX) * w; float MapY(float y) => h - ((y - rangeMinY) / (rangeMaxY - rangeMinY) * h); - // 1. Grid - DrawGrid(g, w, h, MapX, MapY); + // 1. Adaptive Grid with Sub-Divisions + DrawAdaptiveGrid(g, w, h, MapX, MapY); // 2. Axes using (Pen axisPen = new Pen(Color.FromArgb(148, 163, 184), 1.8f)) @@ -801,7 +1126,26 @@ namespace MathApp.Controls if (x0 >= 0 && x0 <= w) g.DrawLine(axisPen, x0, 0, x0, h); } - // 3. Draw Curves + // 3. Vertical Asymptotes (if enabled) + if (chkShowAsymptotes.Checked && _asymptotePoles.Count > 0) + { + using (Pen asympPen = new Pen(Color.FromArgb(244, 63, 94), 1.4f) { DashStyle = DashStyle.Dash }) + using (Font asympFont = new Font("Segoe UI Semibold", 8F, FontStyle.Bold)) + using (Brush asympBr = new SolidBrush(Color.FromArgb(244, 63, 94))) + { + foreach (var pole in _asymptotePoles) + { + float sx = MapX(pole); + if (sx >= 0 && sx <= w) + { + g.DrawLine(asympPen, sx, 0, sx, h); + g.DrawString($"x = {pole:F2}", asympFont, asympBr, sx + 4, 12); + } + } + } + } + + // 4. Draw Curves foreach (var curve in _curves) { if (!curve.Visible) continue; @@ -845,7 +1189,30 @@ namespace MathApp.Controls } } - // 4. Draw Marked Points + // 5. Critical Points (Roots, Min/Max, Inflection, Intersections) + if (chkCriticalPoints.Checked && _criticalPoints.Count > 0) + { + using (Font cpFont = new Font("Segoe UI", 8F, FontStyle.Bold)) + using (Brush haloBrush = new SolidBrush(Color.FromArgb(60, 255, 255, 255))) + { + foreach (var cp in _criticalPoints) + { + float sx = MapX(cp.X); + float sy = MapY(cp.Y); + if (sx < 0 || sx > w || sy < 0 || sy > h) continue; + + using (Brush ptBrush = new SolidBrush(cp.Color)) + using (Pen outlinePen = new Pen(Color.White, 1.2f)) + { + g.FillEllipse(haloBrush, sx - 8, sy - 8, 16, 16); + g.FillEllipse(ptBrush, sx - 4, sy - 4, 8, 8); + g.DrawEllipse(outlinePen, sx - 4, sy - 4, 8, 8); + } + } + } + } + + // 6. Draw Marked Points using (Font markFont = new Font("Consolas", 8.5F, FontStyle.Bold)) using (Brush bgTag = new SolidBrush(Color.FromArgb(200, 15, 23, 42))) { @@ -867,62 +1234,205 @@ namespace MathApp.Controls } } - // 5. Live Hover Coordinate HUD + // 7. Dynamic Inspect Mode & Live Hover Coordinate HUD if (hoverMousePos.HasValue && !isDragging) { float mx = hoverMousePos.Value.X; float logX = rangeMinX + (mx / w) * (rangeMaxX - rangeMinX); - var activeCurve = _curves.FirstOrDefault(c => c.Visible && !c.IsVerticalLine && c.Compiled != null); + // Check critical point snap + CriticalPoint snappedCp = null; + if (chkCriticalPoints.Checked) + { + snappedCp = _criticalPoints.FirstOrDefault(cp => + { + float csx = MapX(cp.X); + float csy = MapY(cp.Y); + return (hoverMousePos.Value.X - csx) * (hoverMousePos.Value.X - csx) + + (hoverMousePos.Value.Y - csy) * (hoverMousePos.Value.Y - csy) <= 120f; + }); + } + + var activeCurve = _curves.FirstOrDefault(c => c.Visible && !c.IsVerticalLine && !c.IsPolar && c.Compiled != null); if (activeCurve != null) { bool prevRad = Function.UseRadians; Function.UseRadians = true; try { - decimal fxDec = NumericalMethods.EvaluateCompiled(activeCurve.Compiled, "x", (decimal)logX); + SetCurveParameters(activeCurve); + float targetX = snappedCp != null ? snappedCp.X : logX; + decimal fxDec = NumericalMethods.EvaluateCompiled(activeCurve.Compiled, "x", (decimal)targetX); float logY = (float)fxDec; float sy = MapY(logY); + float sx = MapX(targetX); - using (Pen dashPen = new Pen(Color.FromArgb(90, 248, 250, 252), 1f) { DashStyle = DashStyle.Dash }) + decimal dfxDec = EvalDeriv(activeCurve.Compiled, (decimal)targetX); + float slope = (float)dfxDec; + + // Inspect Tangent Line + if (chkInspectMode.Checked && !float.IsNaN(slope) && Math.Abs(slope) < 1e4f) { - g.DrawLine(dashPen, mx, 0, mx, h); - if (sy >= 0 && sy <= h) + using (Pen tanLinePen = new Pen(Color.FromArgb(0, 210, 255), 2f)) + using (Pen normPen = new Pen(Color.FromArgb(168, 85, 247), 1.2f) { DashStyle = DashStyle.Dash }) { - g.DrawLine(dashPen, 0, sy, w, sy); - using (Brush dotBrush = new SolidBrush(activeCurve.Color)) + float x1 = rangeMinX; + float y1 = logY + slope * (x1 - targetX); + float x2 = rangeMaxX; + float y2 = logY + slope * (x2 - targetX); + + g.DrawLine(tanLinePen, MapX(x1), MapY(y1), MapX(x2), MapY(y2)); + + // Normal line: slope = -1 / slope + if (Math.Abs(slope) > 0.001f) { - g.FillEllipse(dotBrush, mx - 4, sy - 4, 8, 8); + float nSlope = -1f / slope; + float ny1 = logY + nSlope * (x1 - targetX); + float ny2 = logY + nSlope * (x2 - targetX); + g.DrawLine(normPen, MapX(x1), MapY(ny1), MapX(x2), MapY(ny2)); } } } - decimal dfxDec = EvalDeriv(activeCurve.Compiled, (decimal)logX); - string coordInfo = $"x = {logX:F3} | f(x) = {logY:F4} | f'(x) = {dfxDec:F4} ({activeCurve.Equation})"; - using (Font hudFont = new Font("Consolas", 9F, FontStyle.Bold)) - using (Brush hudBg = new SolidBrush(Color.FromArgb(220, 15, 23, 42))) - using (Pen hudBorder = new Pen(Color.FromArgb(56, 189, 248), 1.2f)) - using (Brush hudFg = new SolidBrush(Color.FromArgb(186, 230, 253))) + using (Pen dashPen = new Pen(Color.FromArgb(90, 248, 250, 252), 1f) { DashStyle = DashStyle.Dash }) { - SizeF sz = g.MeasureString(coordInfo, hudFont); - RectangleF rect = new RectangleF(16, 12, sz.Width + 14, sz.Height + 8); - g.FillRectangle(hudBg, rect); - g.DrawRectangle(hudBorder, rect.X, rect.Y, rect.Width, rect.Height); - g.DrawString(coordInfo, hudFont, hudFg, rect.X + 7, rect.Y + 4); + g.DrawLine(dashPen, sx, 0, sx, h); + if (sy >= 0 && sy <= h) + { + g.DrawLine(dashPen, 0, sy, w, sy); + using (Brush dotBrush = new SolidBrush(snappedCp != null ? snappedCp.Color : activeCurve.Color)) + { + g.FillEllipse(dotBrush, sx - 5, sy - 5, 10, 10); + g.DrawEllipse(Pens.White, sx - 5, sy - 5, 10, 10); + } + } + } + + // Modern Acrylic HUD Card + using (Font hudFont = new Font("Segoe UI", 9F, FontStyle.Bold)) + using (Brush hudBg = new SolidBrush(Color.FromArgb(230, 11, 15, 28))) + using (Pen hudBorder = new Pen(Color.FromArgb(0, 210, 255), 1.5f)) + using (Brush textCyan = new SolidBrush(Color.FromArgb(0, 210, 255))) + using (Brush textWhite = new SolidBrush(Color.White)) + using (Brush textYellow = new SolidBrush(Color.FromArgb(250, 204, 21))) + { + string tLine1 = snappedCp != null ? snappedCp.Details : $"x = {targetX:F3} | f(x) = {logY:F3}"; + string tLine2 = chkInspectMode.Checked + ? $"Teğet: y = {slope:F2}x + {(logY - slope * targetX):F2} | dy/dx = {slope:F3}" + : $"Eğim f'(x) = {dfxDec:F3}"; + + float boxW = Math.Max(260, Math.Max(g.MeasureString(tLine1, hudFont).Width, g.MeasureString(tLine2, hudFont).Width) + 24); + float boxH = 48; + float bx = Math.Min(w - boxW - 12, Math.Max(12, sx + 12)); + float by = Math.Min(h - boxH - 12, Math.Max(12, sy - boxH - 12)); + + g.FillRectangle(hudBg, bx, by, boxW, boxH); + g.DrawRectangle(hudBorder, bx, by, boxW, boxH); + + g.DrawString(tLine1, hudFont, snappedCp != null ? textYellow : textCyan, bx + 10, by + 6); + g.DrawString(tLine2, hudFont, textWhite, bx + 10, by + 25); } } catch { } - finally { Function.UseRadians = prevRad; } + finally + { + Function.UseRadians = prevRad; + } } } } + private void DrawAdaptiveGrid(Graphics g, float w, float h, Func mapX, Func mapY) + { + float rangeW = rangeMaxX - rangeMinX; + float stepW = CalculateStep(rangeW, 10); + float minorW = stepW / 5f; + + float rangeH = rangeMaxY - rangeMinY; + float stepH = CalculateStep(rangeH, 8); + float minorH = stepH / 5f; + + // 1. Minor Sub-Grid Lines + using (Pen minorPen = new Pen(Color.FromArgb(22, 32, 48), 1f)) + { + if (minorW > 0) + { + float startX = (float)Math.Floor(rangeMinX / minorW) * minorW; + for (float x = startX; x <= rangeMaxX; x += minorW) + { + float sx = mapX(x); + g.DrawLine(minorPen, sx, 0, sx, h); + } + } + if (minorH > 0) + { + float startY = (float)Math.Floor(rangeMinY / minorH) * minorH; + for (float y = startY; y <= rangeMaxY; y += minorH) + { + float sy = mapY(y); + g.DrawLine(minorPen, 0, sy, w, sy); + } + } + } + + // 2. Major Grid Lines & Numbers + using (Pen majorPen = new Pen(Color.FromArgb(45, 60, 85), 1.2f)) + using (Font font = new Font("Segoe UI", 8.5F, FontStyle.Regular)) + using (Brush brush = new SolidBrush(Color.FromArgb(148, 163, 184))) + { + if (stepW > 0) + { + float startX = (float)Math.Floor(rangeMinX / stepW) * stepW; + for (float x = startX; x <= rangeMaxX; x += stepW) + { + float sx = mapX(x); + g.DrawLine(majorPen, sx, 0, sx, h); + if (Math.Abs(x) > 1e-4f) + { + g.DrawString(x.ToString("0.##", CultureInfo.InvariantCulture), font, brush, sx + 3, h - 20); + } + } + } + + if (stepH > 0) + { + float startY = (float)Math.Floor(rangeMinY / stepH) * stepH; + for (float y = startY; y <= rangeMaxY; y += stepH) + { + float sy = mapY(y); + g.DrawLine(majorPen, 0, sy, w, sy); + if (Math.Abs(y) > 1e-4f) + { + g.DrawString(y.ToString("0.##", CultureInfo.InvariantCulture), font, brush, 6, sy - 16); + } + } + } + } + } + + private float CalculateStep(float range, int targetSteps) + { + float rawStep = range / targetSteps; + double log = Math.Log10(rawStep); + double baseExponent = Math.Floor(log); + double fraction = rawStep / Math.Pow(10, baseExponent); + + double niceFraction; + if (fraction <= 1.5) niceFraction = 1; + else if (fraction <= 3.5) niceFraction = 2; + else if (fraction <= 7.5) niceFraction = 5; + else niceFraction = 10; + + return (float)(niceFraction * Math.Pow(10, baseExponent)); + } + private void DrawCustomPoint(Graphics g, float sx, float sy, PlotPoint p) { int sz = p.Size; - float half = sz / 2f; + int half = sz / 2; + using (Brush b = new SolidBrush(p.Color)) - using (Pen pen = new Pen(Color.White, 1.5f)) + using (Pen pen = new Pen(Color.White, 1.2f)) { switch (p.Shape) { @@ -960,80 +1470,235 @@ namespace MathApp.Controls } } - private void DrawGrid(Graphics g, float w, float h, Func mapX, Func mapY) + private decimal EvalDeriv(Function fn, decimal x) { - using (Pen gridPen = new Pen(Color.FromArgb(30, 41, 59), 1)) - using (Font font = new Font("Segoe UI", 8.5f)) - using (Brush brush = new SolidBrush(Color.FromArgb(148, 163, 184))) + decimal h = 0.001m; + decimal y1 = NumericalMethods.EvaluateCompiled(fn, "x", x + h); + decimal y0 = NumericalMethods.EvaluateCompiled(fn, "x", x - h); + return (y1 - y0) / (2m * h); + } + + #endregion + + #region Points List Management + + private void RefreshPointsList() + { + lstPoints.BeginUpdate(); + lstPoints.Items.Clear(); + foreach (var p in _points) { - float rangeW = rangeMaxX - rangeMinX; - float stepW = CalculateStep(rangeW, 10); + lstPoints.Items.Add(p); + } + lstPoints.EndUpdate(); + } - float rangeH = rangeMaxY - rangeMinY; - float stepH = CalculateStep(rangeH, 8); + private void BtnAddPoint_Click(object sender, EventArgs e) + { + float px = ParseFloat(txtPtX.Text, 0f); + float py = ParseFloat(txtPtY.Text, 0f); - if (stepW > 0) + _points.Add(new PlotPoint + { + X = px, + Y = py, + Color = btnPtColor.BackColor, + Shape = (PointShape)Math.Max(0, cmbPtShape.SelectedIndex), + Size = 8 + }); + + RefreshPointsList(); + pnlCanvas.Invalidate(); + } + + private void BtnDeletePoint_Click(object sender, EventArgs e) + { + if (lstPoints.SelectedIndex >= 0 && lstPoints.SelectedIndex < _points.Count) + { + _points.RemoveAt(lstPoints.SelectedIndex); + RefreshPointsList(); + pnlCanvas.Invalidate(); + } + } + + #endregion + + #region Exporting (Image, CSV, LaTeX) + + private void BtnExportImage_Click(object sender, EventArgs e) + { + using (SaveFileDialog sfd = new SaveFileDialog + { + Filter = "PNG Resmi (*.png)|*.png|JPEG Resmi (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp", + FileName = "ttCalculator_Grafik.png", + Title = "Grafiği Resim Olarak Kaydet" + }) + { + if (sfd.ShowDialog() == DialogResult.OK) { - float startX = (float)Math.Floor(rangeMinX / stepW) * stepW; - for (float x = startX; x <= rangeMaxX; x += stepW) + try { - float sx = mapX(x); - g.DrawLine(gridPen, sx, 0, sx, h); - g.DrawString(x.ToString("0.##", CultureInfo.InvariantCulture), font, brush, sx + 3, h - 20); + using (Bitmap bmp = new Bitmap(pnlCanvas.Width, pnlCanvas.Height)) + { + pnlCanvas.DrawToBitmap(bmp, new Rectangle(0, 0, pnlCanvas.Width, pnlCanvas.Height)); + bmp.Save(sfd.FileName); + } + MessageBox.Show("Grafik görseli başarıyla dışa aktarıldı:\n" + sfd.FileName, "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information); } - } - - if (stepH > 0) - { - float startY = (float)Math.Floor(rangeMinY / stepH) * stepH; - for (float y = startY; y <= rangeMaxY; y += stepH) + catch (Exception ex) { - float sy = mapY(y); - g.DrawLine(gridPen, 0, sy, w, sy); - g.DrawString(y.ToString("0.##", CultureInfo.InvariantCulture), font, brush, 6, sy - 16); + MessageBox.Show("Dışa aktarma hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } - private float CalculateStep(float range, int targetSteps) + private void BtnExportCsv_Click(object sender, EventArgs e) { - if (range <= 0 || float.IsNaN(range) || float.IsInfinity(range)) return 1f; - float rawStep = range / targetSteps; - float mag = (float)Math.Pow(10, Math.Floor(Math.Log10(rawStep))); - float normStep = rawStep / mag; + var validCurves = _curves.Where(c => c.Visible && !c.IsVerticalLine && !c.IsPolar && c.Compiled != null).ToList(); + if (validCurves.Count == 0) + { + MessageBox.Show("Dışa aktarılacak görünür bir kartezyen eğri bulunamadı.", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } - if (normStep < 1.5f) return 1f * mag; - if (normStep < 3.5f) return 2f * mag; - if (normStep < 7.5f) return 5f * mag; - return 10f * mag; + using (SaveFileDialog sfd = new SaveFileDialog + { + Filter = "CSV Dosyası (*.csv)|*.csv", + FileName = "ttCalculator_DegerTablosu.csv", + Title = "Değer Tablosunu CSV Olarak İndir" + }) + { + if (sfd.ShowDialog() == DialogResult.OK) + { + try + { + StringBuilder sb = new StringBuilder(); + sb.Append("x"); + foreach (var c in validCurves) + { + sb.Append($",\"{c.Equation}\""); + } + sb.AppendLine(); + + float step = 0.1f; + for (float x = rangeMinX; x <= rangeMaxX + 1e-5f; x += step) + { + sb.Append(x.ToString("F3", CultureInfo.InvariantCulture)); + foreach (var c in validCurves) + { + try + { + SetCurveParameters(c); + decimal y = NumericalMethods.EvaluateCompiled(c.Compiled, "x", (decimal)x); + sb.Append("," + ((float)y).ToString("F4", CultureInfo.InvariantCulture)); + } + catch + { + sb.Append(",NaN"); + } + } + sb.AppendLine(); + } + + File.WriteAllText(sfd.FileName, sb.ToString(), Encoding.UTF8); + MessageBox.Show("Değer tablosu CSV formatında başarıyla kaydedildi:\n" + sfd.FileName, "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show("CSV oluşturma hatası: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } - private void pnlCanvas_Resize(object sender, EventArgs e) + private void BtnExportLatex_Click(object sender, EventArgs e) { - GenerateAllPoints(false, isDraft: false); - pnlCanvas.Invalidate(); - } + var validCurves = _curves.Where(c => c.Visible && !c.IsVerticalLine && !c.IsPolar).ToList(); + StringBuilder sb = new StringBuilder(); + sb.AppendLine("% ttCalculator v2.8 LaTeX Pgfplots / TikZ Kodu"); + sb.AppendLine("\\begin{tikzpicture}"); + sb.AppendLine("\\begin{axis}["); + sb.AppendLine($" xmin={rangeMinX:F1}, xmax={rangeMaxX:F1},"); + sb.AppendLine($" ymin={rangeMinY:F1}, ymax={rangeMaxY:F1},"); + sb.AppendLine(" axis lines=middle,"); + sb.AppendLine(" grid=both,"); + sb.AppendLine(" xlabel={$x$},"); + sb.AppendLine(" ylabel={$y$},"); + sb.AppendLine(" samples=200,"); + sb.AppendLine(" legend pos=outer north east"); + sb.AppendLine("]"); - private float ParseFloat(string s, float def) - { - string norm = (s ?? "").Trim().Replace(',', '.'); - if (float.TryParse(norm, NumberStyles.Any, CultureInfo.InvariantCulture, out float v)) return v; - return def; + string[] colors = { "blue", "red", "green!70!black", "orange", "purple", "cyan" }; + int cIdx = 0; + foreach (var c in validCurves) + { + string col = colors[cIdx % colors.Length]; + cIdx++; + string tikzExpr = c.Equation.Replace("sin(", "sin(deg(") + .Replace("cos(", "cos(deg(") + .Replace("tan(", "tan(deg(") + .Replace("^", "^"); + sb.AppendLine($"\\addplot[color={col}, thick, domain={rangeMinX:F1}:{rangeMaxX:F1}] {{{tikzExpr}}};"); + sb.AppendLine($"\\addlegendentry{{${c.Equation}$}}"); + } + + sb.AppendLine("\\end{axis}"); + sb.AppendLine("\\end{tikzpicture}"); + + using (Form dlg = new Form + { + Text = "LaTeX (TikZ / Pgfplots) Kodu", + Size = new Size(580, 420), + StartPosition = FormStartPosition.CenterParent, + BackColor = ThemeHelper.DarkBackground, + ForeColor = Color.White + }) + { + RichTextBox txt = new RichTextBox + { + Dock = DockStyle.Top, + Height = 310, + Text = sb.ToString(), + Font = new Font("Consolas", 10F), + BackColor = ThemeHelper.CardBackground, + ForeColor = Color.FromArgb(0, 210, 255), + ReadOnly = true + }; + + Button btnCopy = ThemeHelper.CreateActionButton("📋 Panoya Kopyala", 160, 32, true); + btnCopy.Location = new Point(200, 325); + btnCopy.Click += (cs, ce) => + { + Clipboard.SetText(sb.ToString()); + MessageBox.Show("LaTeX kodu panoya kopyalandı!", "Kopyalandı", MessageBoxButtons.OK, MessageBoxIcon.Information); + dlg.Close(); + }; + + dlg.Controls.Add(txt); + dlg.Controls.Add(btnCopy); + dlg.ShowDialog(this); + } } #endregion - #region Advanced Tools (Common Tangent, Closest Points, Tangent from Point) + #region Tools & Geometry (Common Tangent, Closest Points, Point Tangent) private void BtnCommonTangent_Click(object sender, EventArgs e) { - string eq1 = cmbToolF1.SelectedItem?.ToString(); - string eq2 = cmbToolF2.SelectedItem?.ToString(); - - if (string.IsNullOrWhiteSpace(eq1) || string.IsNullOrWhiteSpace(eq2)) + if (cmbToolF1.SelectedIndex < 0 || cmbToolF2.SelectedIndex < 0) { - MessageBox.Show("Lütfen araç için listeden iki fonksiyon seçin.", "Seçim Eksik", MessageBoxButtons.OK, MessageBoxIcon.Information); + txtToolLog.Text = "Lütfen iki fonksiyon seçin."; + return; + } + + string eq1 = cmbToolF1.SelectedItem.ToString(); + string eq2 = cmbToolF2.SelectedItem.ToString(); + + if (eq1 == eq2) + { + txtToolLog.Text = "Hata: İki farklı fonksiyon seçmelisiniz."; return; } @@ -1042,68 +1707,54 @@ namespace MathApp.Controls Function f1 = NumericalMethods.CompileFunction(eq1); Function f2 = NumericalMethods.CompileFunction(eq2); - decimal EvalF1(decimal x) => NumericalMethods.EvaluateCompiled(f1, "x", x); - decimal EvalF2(decimal x) => NumericalMethods.EvaluateCompiled(f2, "x", x); - decimal DerivF1(decimal x) => EvalDeriv(f1, x); - decimal DerivF2(decimal x) => EvalDeriv(f2, x); + txtToolLog.Text = $"Ortak Teğet Çözülüyor...\nf₁(x) = {eq1}\nf₂(x) = {eq2}\n\n"; - // Scan grid over [rangeMinX, rangeMaxX] for (x1, x2) minimizing common tangent loss - decimal bestLoss = decimal.MaxValue; - decimal bestX1 = 0m, bestX2 = 0m; + float x1Cand = -1f; + float x2Cand = 1f; + bool found = false; - int gridN = 40; - decimal xStart = (decimal)rangeMinX; - decimal xEnd = (decimal)rangeMaxX; - decimal dx = (xEnd - xStart) / gridN; - - for (int i = 0; i <= gridN; i++) + for (int iter = 0; iter < 40; iter++) { - decimal x1 = xStart + i * dx; - decimal m1 = DerivF1(x1); - decimal y1 = EvalF1(x1); + decimal y1 = NumericalMethods.EvaluateCompiled(f1, "x", (decimal)x1Cand); + decimal y2 = NumericalMethods.EvaluateCompiled(f2, "x", (decimal)x2Cand); - for (int j = 0; j <= gridN; j++) + decimal m1 = EvalDeriv(f1, (decimal)x1Cand); + decimal m2 = EvalDeriv(f2, (decimal)x2Cand); + + if (Math.Abs(x2Cand - x1Cand) < 1e-4f) { x2Cand += 0.1f; continue; } + + decimal secantM = (y2 - y1) / (decimal)(x2Cand - x1Cand); + + decimal err1 = m1 - m2; + decimal err2 = m1 - secantM; + + if (Math.Abs(err1) < 0.0001m && Math.Abs(err2) < 0.0001m) { - decimal x2 = xStart + j * dx; - if (DecimalMath.Abs(x1 - x2) < 0.05m) continue; - - decimal m2 = DerivF2(x2); - decimal y2 = EvalF2(x2); - decimal chordSlope = (y2 - y1) / (x2 - x1); - - decimal loss = (m1 - m2) * (m1 - m2) + (chordSlope - m1) * (chordSlope - m1); - if (loss < bestLoss) - { - bestLoss = loss; - bestX1 = x1; - bestX2 = x2; - } + found = true; + break; } + + x1Cand -= (float)(err1 * 0.1m); + x2Cand += (float)(err2 * 0.1m); } - if (bestLoss < 1.0m) + if (found) { - decimal m = DerivF1(bestX1); - decimal c = EvalF1(bestX1) - m * bestX1; + decimal m = EvalDeriv(f1, (decimal)x1Cand); + decimal y1 = NumericalMethods.EvaluateCompiled(f1, "x", (decimal)x1Cand); + decimal n = y1 - m * (decimal)x1Cand; - string tanEq = $"{m:F4} * x + {c:F4}"; - AddFunctionCurve(tanEq, false, rangeMinX, rangeMaxX, Color.FromArgb(250, 204, 21), DashStyle.Dash, 2.5f); + string tanEq = $"{m:F4}*x + {n:F4}"; + txtToolLog.AppendText($"✓ Ortak Teğet Bulundu:\n"); + txtToolLog.AppendText($"Teğet 1: x₁ = {x1Cand:F3}\n"); + txtToolLog.AppendText($"Teğet 2: x₂ = {x2Cand:F3}\n"); + txtToolLog.AppendText($"Doğru: y = {tanEq}\n"); - // Add contact points - _points.Add(new PlotPoint { X = (float)bestX1, Y = (float)EvalF1(bestX1), Color = Color.FromArgb(56, 189, 248), Shape = PointShape.Diamond }); - _points.Add(new PlotPoint { X = (float)bestX2, Y = (float)EvalF2(bestX2), Color = Color.FromArgb(244, 63, 94), Shape = PointShape.Diamond }); - RefreshPointsList(); - - StringBuilder sb = new StringBuilder(); - sb.AppendLine("✓ ORTAK TEĞET BULUNDU:"); - sb.AppendLine($"Doğru: y = {m:F4}·x + {c:F4}"); - sb.AppendLine($"1. Değme Noktası: P1({bestX1:F3}, {EvalF1(bestX1):F3})"); - sb.AppendLine($"2. Değme Noktası: P2({bestX2:F3}, {EvalF2(bestX2):F3})"); - txtToolLog.Text = sb.ToString(); + AddFunctionCurve(tanEq, false, -20f, 20f, Color.FromArgb(236, 72, 153), DashStyle.Dash, 2.2f); } else { - txtToolLog.Text = "Belirtilen aralıkta ortak teğet bulunamadı veya eğriler uygun geometriye sahip değil."; + txtToolLog.AppendText("Bu aralıkta ortak teğet yakınsayamadı (Kök bulunamadı)."); } } catch (Exception ex) @@ -1114,102 +1765,76 @@ namespace MathApp.Controls private void BtnNearestPoints_Click(object sender, EventArgs e) { - string eq1 = cmbToolF1.SelectedItem?.ToString(); - string eq2 = cmbToolF2.SelectedItem?.ToString(); - - if (string.IsNullOrWhiteSpace(eq1) || string.IsNullOrWhiteSpace(eq2)) + if (cmbToolF1.SelectedIndex < 0 || cmbToolF2.SelectedIndex < 0) { - MessageBox.Show("Lütfen iki fonksiyon seçin.", "Seçim Eksik", MessageBoxButtons.OK, MessageBoxIcon.Information); + txtToolLog.Text = "Lütfen iki fonksiyon seçin."; return; } + string eq1 = cmbToolF1.SelectedItem.ToString(); + string eq2 = cmbToolF2.SelectedItem.ToString(); + try { - // Check if they intersect: f1 - f2 = 0 - string diffEq = $"({eq1}) - ({eq2})"; - var roots = NumericalMethods.FindAllRoots(diffEq, (decimal)rangeMinX, (decimal)rangeMaxX, "x"); - - if (roots.Count > 0) - { - StringBuilder sbInt = new StringBuilder(); - sbInt.AppendLine("⚠️ FONKSİYONLAR KESİŞİYOR!"); - sbInt.AppendLine($"Kesişme Kökleri ({roots.Count} adet):"); - foreach (var r in roots) - { - sbInt.AppendLine($" • x = {r.Root:F5} (f(x)={r.FVal:G4})"); - } - sbInt.AppendLine("Kesiştikleri için aralarındaki minimum mesafe: 0'dır."); - txtToolLog.Text = sbInt.ToString(); - return; - } - - // If no intersection, find points minimizing Euclidean distance Function f1 = NumericalMethods.CompileFunction(eq1); Function f2 = NumericalMethods.CompileFunction(eq2); - decimal minDistSq = decimal.MaxValue; - decimal bestX1 = 0m, bestX2 = 0m; - decimal bestY1 = 0m, bestY2 = 0m; + txtToolLog.Text = $"En Yakın Noktalar Analizi:\nf₁(x) = {eq1}\nf₂(x) = {eq2}\n\n"; - int gridN = 60; - decimal xStart = (decimal)rangeMinX; - decimal xEnd = (decimal)rangeMaxX; - decimal dx = (xEnd - xStart) / gridN; + float bestX1 = 0, bestX2 = 0; + float minDistSq = float.MaxValue; - for (int i = 0; i <= gridN; i++) + int steps = 60; + float stepX = (rangeMaxX - rangeMinX) / steps; + + for (int i = 0; i <= steps; i++) { - decimal x1 = xStart + i * dx; - decimal y1 = 0m; - try { y1 = NumericalMethods.EvaluateCompiled(f1, "x", x1); } catch { continue; } + float x1 = rangeMinX + i * stepX; + decimal y1Dec = NumericalMethods.EvaluateCompiled(f1, "x", (decimal)x1); + float y1 = (float)y1Dec; - for (int j = 0; j <= gridN; j++) + for (int j = 0; j <= steps; j++) { - decimal x2 = xStart + j * dx; - decimal y2 = 0m; - try { y2 = NumericalMethods.EvaluateCompiled(f2, "x", x2); } catch { continue; } + float x2 = rangeMinX + j * stepX; + decimal y2Dec = NumericalMethods.EvaluateCompiled(f2, "x", (decimal)x2); + float y2 = (float)y2Dec; - decimal dSq = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); + float dSq = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); if (dSq < minDistSq) { minDistSq = dSq; bestX1 = x1; - bestY1 = y1; bestX2 = x2; - bestY2 = y2; } } } - decimal dist = (decimal)Math.Sqrt((double)minDistSq); + float minY1 = (float)NumericalMethods.EvaluateCompiled(f1, "x", (decimal)bestX1); + float minY2 = (float)NumericalMethods.EvaluateCompiled(f2, "x", (decimal)bestX2); + float dist = (float)Math.Sqrt(minDistSq); - // Add points - _points.Add(new PlotPoint { X = (float)bestX1, Y = (float)bestY1, Color = Color.FromArgb(236, 72, 153), Shape = PointShape.Diamond }); - _points.Add(new PlotPoint { X = (float)bestX2, Y = (float)bestY2, Color = Color.FromArgb(236, 72, 153), Shape = PointShape.Diamond }); + txtToolLog.AppendText($"En Kısa Mesafe: {dist:F4}\n"); + txtToolLog.AppendText($"P₁ (f₁ üzerinde): ({bestX1:F3}, {minY1:F3})\n"); + txtToolLog.AppendText($"P₂ (f₂ üzerinde): ({bestX2:F3}, {minY2:F3})\n"); + + _points.Add(new PlotPoint { X = bestX1, Y = minY1, Color = Color.Cyan, Shape = PointShape.Diamond }); + _points.Add(new PlotPoint { X = bestX2, Y = minY2, Color = Color.Magenta, Shape = PointShape.Diamond }); RefreshPointsList(); - // Connecting line equation - decimal m = 0m, c = 0m; - string lineEq; - if (DecimalMath.Abs(bestX2 - bestX1) > 1e-5m) + if (Math.Abs(bestX2 - bestX1) > 0.001f) { - m = (bestY2 - bestY1) / (bestX2 - bestX1); - c = bestY1 - m * bestX1; - lineEq = $"{m:F4} * x + {c:F4}"; - AddFunctionCurve(lineEq, false, rangeMinX, rangeMaxX, Color.FromArgb(236, 72, 153), DashStyle.Dot, 2f); + float m = (minY2 - minY1) / (bestX2 - bestX1); + float n = minY1 - m * bestX1; + string lineEq = $"{m:F4}*x + {n:F4}"; + txtToolLog.AppendText($"Aralarındaki Doğru: y = {lineEq}\n"); + AddFunctionCurve(lineEq, true, Math.Min(bestX1, bestX2), Math.Max(bestX1, bestX2), Color.Yellow, DashStyle.Dot, 2f); } else { - AddVerticalLine((float)bestX1, (float)Math.Min(bestY1, bestY2), (float)Math.Max(bestY1, bestY2), Color.FromArgb(236, 72, 153), DashStyle.Dot); - lineEq = $"x = {bestX1:F4} (Düşey Doğru)"; + AddVerticalLine(bestX1, Math.Min(minY1, minY2), Math.Max(minY1, minY2), Color.Yellow, DashStyle.Dot, 2f); } - StringBuilder sb = new StringBuilder(); - sb.AppendLine("✓ EN YAKIN NOKTALAR HESAPLANDI:"); - sb.AppendLine($"Kesişme: Yok (Denklem kökü bulunamadı)"); - sb.AppendLine($"P1({bestX1:F3}, {bestY1:F3}) ve P2({bestX2:F3}, {bestY2:F3})"); - sb.AppendLine($"Minimum Mesafe: {dist:F5} birim"); - sb.AppendLine($"Geçen Doğru: y = {m:F4}·x + {c:F4}"); - txtToolLog.Text = sb.ToString(); + pnlCanvas.Invalidate(); } catch (Exception ex) { @@ -1219,72 +1844,59 @@ namespace MathApp.Controls private void BtnPointTangent_Click(object sender, EventArgs e) { - string eq = cmbToolF1.SelectedItem?.ToString(); - if (string.IsNullOrWhiteSpace(eq)) + if (cmbToolF1.SelectedIndex < 0) { - MessageBox.Show("Lütfen 1. Fonksiyonu seçin.", "Fonksiyon Eksik", MessageBoxButtons.OK, MessageBoxIcon.Information); + txtToolLog.Text = "Lütfen 1. Fonksiyonu seçin."; return; } - float px = ParseFloat(txtTanPointX.Text, 0f); - float py = ParseFloat(txtTanPointY.Text, 3f); + string eq = cmbToolF1.SelectedItem.ToString(); + float x0 = ParseFloat(txtTanPointX.Text, 0f); + float y0 = ParseFloat(txtTanPointY.Text, 0f); try { Function f = NumericalMethods.CompileFunction(eq); - decimal x0 = (decimal)px; - decimal y0 = (decimal)py; + txtToolLog.Text = $"Noktadan Teğet Analizi:\nNokta: ({x0}, {y0})\nf(x) = {eq}\n\n"; - // Tangent condition: (f(xt) - y0) - f'(xt) * (xt - x0) = 0 - // Search for xt in [rangeMinX, rangeMaxX] - decimal bestDiff = decimal.MaxValue; - decimal bestXt = 0m; - int nScan = 100; - decimal xStart = (decimal)rangeMinX; - decimal xEnd = (decimal)rangeMaxX; - decimal dx = (xEnd - xStart) / nScan; + float xt = x0; + bool found = false; - for (int i = 0; i <= nScan; i++) + for (int iter = 0; iter < 50; iter++) { - decimal xt = xStart + i * dx; - try + decimal yt = NumericalMethods.EvaluateCompiled(f, "x", (decimal)xt); + decimal mt = EvalDeriv(f, (decimal)xt); + + decimal res = yt - (decimal)y0 - mt * (decimal)(xt - x0); + if (Math.Abs(res) < 0.0001m) { - decimal fx = NumericalMethods.EvaluateCompiled(f, "x", xt); - decimal dfx = EvalDeriv(f, xt); - decimal cond = (fx - y0) - dfx * (xt - x0); - if (DecimalMath.Abs(cond) < bestDiff) - { - bestDiff = DecimalMath.Abs(cond); - bestXt = xt; - } + found = true; + break; } - catch { } + + decimal dRes = -EvalDeriv(f, (decimal)xt + 0.01m) + EvalDeriv(f, (decimal)xt - 0.01m); + if (Math.Abs(dRes) < 1e-6m) dRes = 1m; + + xt -= (float)(res / dRes * 0.1m); } - if (bestDiff < 0.5m) + if (found) { - decimal m = EvalDeriv(f, bestXt); - decimal c = y0 - m * x0; + decimal mt = EvalDeriv(f, (decimal)xt); + decimal nt = (decimal)y0 - mt * (decimal)x0; + string tanEq = $"{mt:F4}*x + {nt:F4}"; - string tanEq = $"{m:F4} * x + {c:F4}"; - AddFunctionCurve(tanEq, false, rangeMinX, rangeMaxX, Color.FromArgb(249, 115, 22), DashStyle.Dash, 2.2f); + txtToolLog.AppendText($"✓ Teğet Değme Noktası: x_t = {xt:F4}\n"); + txtToolLog.AppendText($"Teğet Doğrusu: y = {tanEq}\n"); - // Add point and contact point - _points.Add(new PlotPoint { X = px, Y = py, Color = Color.FromArgb(249, 115, 22), Shape = PointShape.Cross }); - _points.Add(new PlotPoint { X = (float)bestXt, Y = (float)NumericalMethods.EvaluateCompiled(f, "x", bestXt), Color = Color.FromArgb(52, 211, 153), Shape = PointShape.Diamond }); + _points.Add(new PlotPoint { X = x0, Y = y0, Color = Color.Lime, Shape = PointShape.Cross }); RefreshPointsList(); - StringBuilder sb = new StringBuilder(); - sb.AppendLine("✓ NOKTADAN ÇİZİLEN TEĞET DOĞRUSU:"); - sb.AppendLine($"Verilen Nokta: P₀({px}, {py})"); - sb.AppendLine($"Değme Noktası: P_teğet({bestXt:F3}, {NumericalMethods.EvaluateCompiled(f, "x", bestXt):F3})"); - sb.AppendLine($"Teğet Eğim (m): {m:F4}"); - sb.AppendLine($"Teğet Denklemi: y = {m:F4}·x + {c:F4}"); - txtToolLog.Text = sb.ToString(); + AddFunctionCurve(tanEq, false, -20f, 20f, Color.Lime, DashStyle.Dash, 2.2f); } else { - txtToolLog.Text = "Verilen noktadan fonksiyona teğet kökü bulunamadı."; + txtToolLog.AppendText("Bu noktadan fonksiyona teğet çözümü bulunamadı."); } } catch (Exception ex) @@ -1295,7 +1907,7 @@ namespace MathApp.Controls #endregion - #region Parametric Shapes + #region Parametric Shapes (Primitives) private void BtnAddShape_Click(object sender, EventArgs e) { @@ -1304,127 +1916,105 @@ namespace MathApp.Controls float d1 = Math.Max(0.1f, ParseFloat(txtShapeDim1.Text, 4f)); float d2 = Math.Max(0.1f, ParseFloat(txtShapeDim2.Text, 2f)); float angleDeg = ParseFloat(txtShapeAngle.Text, 0f); - float angleRad = (float)(angleDeg * Math.PI / 180.0); - PointF center = new PointF(cx, cy); - - PointF RotatePt(PointF pt) - { - if (Math.Abs(angleDeg) < 1e-3f) return pt; - float cos = (float)Math.Cos(angleRad); - float sin = (float)Math.Sin(angleRad); - float dx = pt.X - center.X; - float dy = pt.Y - center.Y; - return new PointF(center.X + dx * cos - dy * sin, center.Y + dx * sin + dy * cos); - } + float angleRad = angleDeg * (float)Math.PI / 180f; int shapeIdx = cmbShapeType.SelectedIndex; - Color shapeColor = _palette[_colorIndex % _palette.Length]; + Color sc = _palette[_colorIndex % _palette.Length]; _colorIndex++; switch (shapeIdx) { - case 0: // Daire (Çember) - string upCircle = $"{cy:F3} + sqrt({d1 * d1:F4} - (x - {cx:F3})^2)"; - string lowCircle = $"{cy:F3} - sqrt({d1 * d1:F4} - (x - {cx:F3})^2)"; - AddFunctionCurve(upCircle, true, cx - d1, cx + d1, shapeColor, DashStyle.Solid, 2.5f); - AddFunctionCurve(lowCircle, true, cx - d1, cx + d1, shapeColor, DashStyle.Solid, 2.5f); - lblStatus.Text = $"Parametrik Daire eklendi [Merkez: ({cx}, {cy}), Yarıçap: {d1}]"; + case 0: // Circle / Ellipse + AddFunctionCurve($"{cy} + {d2} * sqrt(max(0, 1 - ((x - {cx}) / {d1})^2))", true, cx - d1, cx + d1, sc); + AddFunctionCurve($"{cy} - {d2} * sqrt(max(0, 1 - ((x - {cx}) / {d1})^2))", true, cx - d1, cx + d1, sc); + lblStatus.Text = $"Elips eklendi (R1={d1}, R2={d2})"; break; - case 1: // Kare (Kenar d1) - float hs = d1 / 2f; - PointF[] sq = new PointF[] + case 1: // Rectangle / Square + AddParametricPolygon(new PointF[] { - RotatePt(new PointF(cx - hs, cy - hs)), - RotatePt(new PointF(cx + hs, cy - hs)), - RotatePt(new PointF(cx + hs, cy + hs)), - RotatePt(new PointF(cx - hs, cy + hs)) - }; - for (int i = 0; i < 4; i++) AddLineSegmentCurve(sq[i], sq[(i + 1) % 4], shapeColor); - lblStatus.Text = $"Kare eklendi [Merkez: ({cx}, {cy}), Kenar: {d1}, Dönüş: {angleDeg}°]"; + RotatePoint(new PointF(-d1, -d2), angleRad, cx, cy), + RotatePoint(new PointF(d1, -d2), angleRad, cx, cy), + RotatePoint(new PointF(d1, d2), angleRad, cx, cy), + RotatePoint(new PointF(-d1, d2), angleRad, cx, cy) + }, sc); + lblStatus.Text = $"Dikdörtgen eklendi (Genişlik={d1 * 2}, Yükseklik={d2 * 2}, Açı={angleDeg}°)"; break; - case 2: // Dikdörtgen (Genişlik d1, Yükseklik d2) - float hw = d1 / 2f; - float hh = d2 / 2f; - PointF[] rect = new PointF[] + case 2: // Triangle + float hTri = d1 * (float)Math.Sqrt(3) / 2f; + AddParametricPolygon(new PointF[] { - RotatePt(new PointF(cx - hw, cy - hh)), - RotatePt(new PointF(cx + hw, cy - hh)), - RotatePt(new PointF(cx + hw, cy + hh)), - RotatePt(new PointF(cx - hw, cy + hh)) - }; - for (int i = 0; i < 4; i++) AddLineSegmentCurve(rect[i], rect[(i + 1) % 4], shapeColor); - lblStatus.Text = $"Dikdörtgen eklendi [Merkez: ({cx}, {cy}), {d1} × {d2}, Dönüş: {angleDeg}°]"; + RotatePoint(new PointF(0, hTri * 2f / 3f), angleRad, cx, cy), + RotatePoint(new PointF(d1 / 2f, -hTri / 3f), angleRad, cx, cy), + RotatePoint(new PointF(-d1 / 2f, -hTri / 3f), angleRad, cx, cy) + }, sc); + lblStatus.Text = $"Üçgen eklendi (Kenar={d1}, Açı={angleDeg}°)"; break; - case 3: // Eşkenar Üçgen (Yarıçap d1) - PointF v1 = RotatePt(new PointF(cx, cy + d1)); - PointF v2 = RotatePt(new PointF(cx - d1 * 0.866025f, cy - d1 * 0.5f)); - PointF v3 = RotatePt(new PointF(cx + d1 * 0.866025f, cy - d1 * 0.5f)); - AddLineSegmentCurve(v1, v2, shapeColor); - AddLineSegmentCurve(v2, v3, shapeColor); - AddLineSegmentCurve(v3, v1, shapeColor); - lblStatus.Text = $"Eşkenar Üçgen eklendi [Merkez: ({cx}, {cy}), Dönüş: {angleDeg}°]"; + case 3: // Pentagon + AddRegularPolygon(cx, cy, d1, 5, angleRad, sc); + lblStatus.Text = $"Düzgün Beşgen eklendi (R={d1})"; break; - case 4: // Elips (a=d1, b=d2, Dönüş Açılı) - int nEll = 36; - PointF[] ell = new PointF[nEll]; - for (int i = 0; i < nEll; i++) - { - double t = i * 2.0 * Math.PI / nEll; - ell[i] = RotatePt(new PointF((float)(cx + d1 * Math.Cos(t)), (float)(cy + d2 * Math.Sin(t)))); - } - for (int i = 0; i < nEll; i++) AddLineSegmentCurve(ell[i], ell[(i + 1) % nEll], shapeColor); - lblStatus.Text = $"Elips eklendi [Merkez: ({cx}, {cy}), a={d1}, b={d2}, Dönüş: {angleDeg}°]"; - break; - - case 5: // Düzgün Altıgen (Yarıçap d1) - PointF[] hex = new PointF[6]; - for (int i = 0; i < 6; i++) - { - double ang = i * Math.PI / 3.0; - hex[i] = RotatePt(new PointF((float)(cx + d1 * Math.Cos(ang)), (float)(cy + d1 * Math.Sin(ang)))); - } - for (int i = 0; i < 6; i++) AddLineSegmentCurve(hex[i], hex[(i + 1) % 6], shapeColor); - lblStatus.Text = $"Düzgün Altıgen eklendi [Merkez: ({cx}, {cy}), R={d1}, Dönüş: {angleDeg}°]"; + case 4: // Hexagon + AddRegularPolygon(cx, cy, d1, 6, angleRad, sc); + lblStatus.Text = $"Düzgün Altıgen eklendi (R={d1})"; break; } } - private void AddLineSegmentCurve(PointF p1, PointF p2, Color color) + private void AddRegularPolygon(float cx, float cy, float radius, int sides, float angleRad, Color color) { - if (Math.Abs(p1.X - p2.X) < 1e-4f) + PointF[] vertices = new PointF[sides]; + for (int i = 0; i < sides; i++) { - AddVerticalLine(p1.X, Math.Min(p1.Y, p2.Y), Math.Max(p1.Y, p2.Y), color, DashStyle.Solid, 2.5f); - return; + float th = angleRad + i * (2f * (float)Math.PI / sides); + vertices[i] = new PointF(cx + radius * (float)Math.Cos(th), cy + radius * (float)Math.Sin(th)); } - - float minX = Math.Min(p1.X, p2.X); - float maxX = Math.Max(p1.X, p2.X); - float m = (p2.Y - p1.Y) / (p2.X - p1.X); - float c = p1.Y - m * p1.X; - - string eq = $"{m:F4} * x + {c:F4}"; - AddFunctionCurve(eq, true, minX, maxX, color, DashStyle.Solid, 2.5f); + AddParametricPolygon(vertices, color); } - private static decimal EvalDeriv(Function fn, decimal x) + private void AddParametricPolygon(PointF[] vertices, Color color) { - decimal h = 0.0005m; - try + int n = vertices.Length; + for (int i = 0; i < n; i++) { - decimal fPlus = NumericalMethods.EvaluateCompiled(fn, "x", x + h); - decimal fMinus = NumericalMethods.EvaluateCompiled(fn, "x", x - h); - return (fPlus - fMinus) / (2m * h); - } - catch - { - return 0m; + PointF p1 = vertices[i]; + PointF p2 = vertices[(i + 1) % n]; + + if (Math.Abs(p2.X - p1.X) < 1e-4f) + { + AddVerticalLine(p1.X, Math.Min(p1.Y, p2.Y), Math.Max(p1.Y, p2.Y), color); + } + else + { + float m = (p2.Y - p1.Y) / (p2.X - p1.X); + float b = p1.Y - m * p1.X; + string eq = $"{m:F4}*x + {b:F4}"; + AddFunctionCurve(eq, true, Math.Min(p1.X, p2.X), Math.Max(p1.X, p2.X), color); + } } } + private PointF RotatePoint(PointF pt, float angleRad, float cx, float cy) + { + float cos = (float)Math.Cos(angleRad); + float sin = (float)Math.Sin(angleRad); + return new PointF( + cx + (pt.X * cos - pt.Y * sin), + cy + (pt.X * sin + pt.Y * cos) + ); + } + + private float ParseFloat(string s, float fallback) + { + if (string.IsNullOrWhiteSpace(s)) return fallback; + if (float.TryParse(s.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out float val)) + return val; + return fallback; + } + #endregion } } diff --git a/src/ttCalculator/MainForm.Designer.cs b/src/ttCalculator/MainForm.Designer.cs index d230df0..697dbf8 100644 --- a/src/ttCalculator/MainForm.Designer.cs +++ b/src/ttCalculator/MainForm.Designer.cs @@ -156,7 +156,7 @@ namespace MathApp // Footer version label this.lblVersion.Dock = DockStyle.Bottom; this.lblVersion.Height = 28; - this.lblVersion.Text = "v2.7 • 128-bit Decimal Motoru • 60 FPS"; + this.lblVersion.Text = "v2.8 • 128-bit Decimal Motoru • 60 FPS"; this.lblVersion.Font = new Font("Segoe UI", 8F); this.lblVersion.ForeColor = Color.FromArgb(100, 116, 139); this.lblVersion.TextAlign = ContentAlignment.MiddleCenter; diff --git a/src/ttCalculator/ThemeHelper.cs b/src/ttCalculator/ThemeHelper.cs index 9de11cd..ccfda8d 100644 --- a/src/ttCalculator/ThemeHelper.cs +++ b/src/ttCalculator/ThemeHelper.cs @@ -169,7 +169,7 @@ namespace MathApp tabControl.DrawMode = TabDrawMode.OwnerDrawFixed; tabControl.SizeMode = TabSizeMode.Fixed; - tabControl.ItemSize = new Size(Math.Max(70, tabControl.Width / Math.Max(1, tabControl.TabCount) - 4), 32); + tabControl.ItemSize = new Size(Math.Max(56, (tabControl.Width - 10) / Math.Max(1, tabControl.TabCount)), 32); tabControl.DrawItem += (s, e) => { @@ -192,12 +192,12 @@ namespace MathApp // Active accent underline using (Brush barBrush = new SolidBrush(AccentBlue)) { - g.FillRectangle(barBrush, tabRect.X + 6, tabRect.Bottom - 3, tabRect.Width - 12, 3); + g.FillRectangle(barBrush, tabRect.X + 4, tabRect.Bottom - 3, tabRect.Width - 8, 3); } } Color textColor = isSelected ? Color.FromArgb(56, 189, 248) : MutedText; - using (Font font = new Font("Segoe UI Semibold", 9F, isSelected ? FontStyle.Bold : FontStyle.Regular)) + using (Font font = new Font("Segoe UI Semibold", 8.5F, isSelected ? FontStyle.Bold : FontStyle.Regular)) using (Brush textBrush = new SolidBrush(textColor)) { StringFormat sf = new StringFormat diff --git a/src/ttCalculator/ttCalculator.csproj b/src/ttCalculator/ttCalculator.csproj index 4b43610..37bef7f 100644 --- a/src/ttCalculator/ttCalculator.csproj +++ b/src/ttCalculator/ttCalculator.csproj @@ -9,7 +9,7 @@ logo.ico ttCalculator ttCalculator - Gelişmiş Matematik & Nümerik Analiz Stüdyosu - 2.7.0 + 2.8.0 ttCalculator diff --git a/tests/ttCalculator.Tests/Program.cs b/tests/ttCalculator.Tests/Program.cs index be52c1f..13c240b 100644 --- a/tests/ttCalculator.Tests/Program.cs +++ b/tests/ttCalculator.Tests/Program.cs @@ -11,7 +11,7 @@ namespace MathApp.Tests static void Main(string[] args) { Console.WriteLine("================================================="); - Console.WriteLine("ttCalculator v2.7 Algorithm & Installer Verification"); + Console.WriteLine("ttCalculator v2.8 Graph Plotter Studio Verification"); Console.WriteLine("================================================="); int passed = 0;