diff --git a/Base/Base.csproj.user b/Base/Base.csproj.user
index b8c9d44..a1412bd 100644
--- a/Base/Base.csproj.user
+++ b/Base/Base.csproj.user
@@ -13,9 +13,6 @@
Form
-
- Form
-
Form
diff --git a/Base/Forms/GraphForm.cs b/Base/Forms/GraphForm.cs
index 8f75202..b8e0d2e 100644
--- a/Base/Forms/GraphForm.cs
+++ b/Base/Forms/GraphForm.cs
@@ -27,26 +27,16 @@ public partial class GraphForm : Form
public float DpiFloat { get; private set; }
- public double ZoomLevel
+ public Float2 ZoomLevel
{
get => _zoomLevel;
set
{
- double oldZoom = ZoomLevel;
-
- _zoomLevel = Math.Clamp(value, 1e-5, 1e3);
-
- int totalSegments = 0;
- foreach (Graphable able in ables) totalSegments += able.GetItemsToRender(this).Count();
-
- if (totalSegments > 10_000)
- {
- _zoomLevel = oldZoom;
- return; // Too many segments, stop.
- }
+ _zoomLevel = new(Math.Clamp(value.x, 1e-5, 1e3),
+ Math.Clamp(value.y, 1e-5, 1e3));
}
}
- private double _zoomLevel;
+ private Float2 _zoomLevel;
private readonly Point initialWindowPos;
private readonly Size initialWindowSize;
@@ -74,7 +64,7 @@ public partial class GraphForm : Form
DpiFloat = (float)((Dpi.x + Dpi.y) / 2);
ables = [];
- ZoomLevel = 1;
+ ZoomLevel = new(1, 1);
initialWindowPos = Location;
initialWindowSize = Size;
@@ -88,8 +78,8 @@ public partial class GraphForm : Form
graphPoint.x -= ScreenCenter.x;
graphPoint.y -= ScreenCenter.y;
- graphPoint.x *= Dpi.x / ZoomLevel;
- graphPoint.y *= Dpi.y / ZoomLevel;
+ graphPoint.x *= Dpi.x / ZoomLevel.x;
+ graphPoint.y *= Dpi.y / ZoomLevel.y;
graphPoint.x += ClientRectangle.Width / 2.0;
graphPoint.y += ClientRectangle.Height / 2.0;
@@ -103,8 +93,8 @@ public partial class GraphForm : Form
result.x -= ClientRectangle.Width / 2.0;
result.y -= ClientRectangle.Height / 2.0;
- result.x /= Dpi.x / ZoomLevel;
- result.y /= Dpi.y / ZoomLevel;
+ result.x /= Dpi.x / ZoomLevel.x;
+ result.y /= Dpi.y / ZoomLevel.y;
result.x += ScreenCenter.x;
result.y += ScreenCenter.y;
@@ -116,19 +106,20 @@ public partial class GraphForm : Form
protected virtual void PaintGrid(Graphics g)
{
- double axisScale = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel)));
+ double axisScaleX = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel.x))),
+ axisScaleY = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel.y)));
// Draw horizontal/vertical quarter-axis.
Brush quarterBrush = new SolidBrush(QuarterAxisColor);
Pen quarterPen = new(quarterBrush, DpiFloat * 2 / 192);
- for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScale) * axisScale / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScale) * axisScale / 4; x += axisScale / 4)
+ for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x += axisScaleX / 4)
{
Int2 startPos = GraphSpaceToScreenSpace(new Float2(x, MinVisibleGraph.y)),
endPos = GraphSpaceToScreenSpace(new Float2(x, MaxVisibleGraph.y));
g.DrawLine(quarterPen, startPos, endPos);
}
- for (double y = Math.Ceiling(MinVisibleGraph.y * 4 / axisScale) * axisScale / 4; y <= Math.Floor(MaxVisibleGraph.y * 4 / axisScale) * axisScale / 4; y += axisScale / 4)
+ for (double y = Math.Ceiling(MinVisibleGraph.y * 4 / axisScaleY) * axisScaleY / 4; y <= Math.Floor(MaxVisibleGraph.y * 4 / axisScaleY) * axisScaleY / 4; y += axisScaleY / 4)
{
Int2 startPos = GraphSpaceToScreenSpace(new Float2(MinVisibleGraph.x, y)),
endPos = GraphSpaceToScreenSpace(new Float2(MaxVisibleGraph.x, y));
@@ -139,13 +130,13 @@ public partial class GraphForm : Form
Brush semiBrush = new SolidBrush(SemiAxisColor);
Pen semiPen = new(semiBrush, DpiFloat * 2 / 192);
- for (double x = Math.Ceiling(MinVisibleGraph.x / axisScale) * axisScale; x <= Math.Floor(MaxVisibleGraph.x / axisScale) * axisScale; x += axisScale)
+ for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= Math.Floor(MaxVisibleGraph.x / axisScaleX) * axisScaleX; x += axisScaleX)
{
Int2 startPos = GraphSpaceToScreenSpace(new Float2(x, MinVisibleGraph.y)),
endPos = GraphSpaceToScreenSpace(new Float2(x, MaxVisibleGraph.y));
g.DrawLine(semiPen, startPos, endPos);
}
- for (double y = Math.Ceiling(MinVisibleGraph.y / axisScale) * axisScale; y <= Math.Floor(MaxVisibleGraph.y / axisScale) * axisScale; y += axisScale)
+ for (double y = Math.Ceiling(MinVisibleGraph.y / axisScaleY) * axisScaleY; y <= Math.Floor(MaxVisibleGraph.y / axisScaleY) * axisScaleY; y += axisScaleY)
{
Int2 startPos = GraphSpaceToScreenSpace(new Float2(MinVisibleGraph.x, y)),
endPos = GraphSpaceToScreenSpace(new Float2(MaxVisibleGraph.x, y));
@@ -166,14 +157,15 @@ public partial class GraphForm : Form
}
protected virtual void PaintUnits(Graphics g)
{
- double axisScale = Math.Pow(2, Math.Round(Math.Log(ZoomLevel, 2)));
+ double axisScaleX = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel.x))),
+ axisScaleY = Math.Pow(2, Math.Round(Math.Log2(ZoomLevel.y)));
Brush textBrush = new SolidBrush(UnitsTextColor);
Font textFont = new(Font.Name, 9, FontStyle.Regular);
// X-axis
int minX = (int)(DpiFloat * 50 / 192),
maxX = ClientRectangle.Height - (int)(DpiFloat * 40 / 192);
- for (double x = Math.Ceiling(MinVisibleGraph.x / axisScale) * axisScale; x <= MaxVisibleGraph.x; x += axisScale)
+ for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= MaxVisibleGraph.x; x += axisScaleX)
{
if (x == 0) x = 0; // Fixes -0
@@ -187,7 +179,7 @@ public partial class GraphForm : Form
// Y-axis
int minY = (int)(DpiFloat * 10 / 192);
- for (double y = Math.Ceiling(MinVisibleGraph.y / axisScale) * axisScale; y <= MaxVisibleGraph.y; y += axisScale)
+ for (double y = Math.Ceiling(MinVisibleGraph.y / axisScaleY) * axisScaleY; y <= MaxVisibleGraph.y; y += axisScaleY)
{
if (y == 0) continue;
@@ -304,7 +296,7 @@ public partial class GraphForm : Form
{
Int2 pixelDiff = new(initialMouseLocation.x - Cursor.Position.X,
initialMouseLocation.y - Cursor.Position.Y);
- Float2 graphDiff = new(pixelDiff.x * ZoomLevel / Dpi.x, pixelDiff.y * ZoomLevel / Dpi.y);
+ Float2 graphDiff = new(pixelDiff.x * ZoomLevel.x / Dpi.x, pixelDiff.y * ZoomLevel.y / Dpi.y);
ScreenCenter = new(initialScreenCenter.x + graphDiff.x,
initialScreenCenter.y + graphDiff.y);
}
@@ -318,7 +310,7 @@ public partial class GraphForm : Form
{
Int2 pixelDiff = new(initialMouseLocation.x - Cursor.Position.X,
initialMouseLocation.y - Cursor.Position.Y);
- Float2 graphDiff = new(pixelDiff.x * ZoomLevel / Dpi.x, pixelDiff.y * ZoomLevel / Dpi.y);
+ Float2 graphDiff = new(pixelDiff.x * ZoomLevel.x / Dpi.x, pixelDiff.y * ZoomLevel.y / Dpi.y);
ScreenCenter = new(initialScreenCenter.x + graphDiff.x,
initialScreenCenter.y + graphDiff.y);
Invalidate(false);
@@ -327,14 +319,18 @@ public partial class GraphForm : Form
}
protected override void OnMouseWheel(MouseEventArgs e)
{
- ZoomLevel *= 1 - e.Delta * 0.00075; // Zoom factor.
+ Float2 newZoom = ZoomLevel;
+ newZoom.x *= 1 - e.Delta * 0.00075; // Zoom factor.
+ newZoom.y *= 1 - e.Delta * 0.00075;
+ ZoomLevel = newZoom;
+
Invalidate(false);
}
private void ResetViewportButton_Click(object? sender, EventArgs e)
{
ScreenCenter = new Float2(0, 0);
- ZoomLevel = 1;
+ ZoomLevel = new(1, 1);
Invalidate(false);
}
private void GraphColorPickerButton_Click(Graphable able)
@@ -449,17 +445,7 @@ public partial class GraphForm : Form
private void ButtonViewportSetZoom_Click(object? sender, EventArgs e)
{
- SetZoomForm zoomer = new(this)
- {
- StartPosition = FormStartPosition.Manual,
- };
- zoomer.Location = new Point(Location.X + ClientRectangle.Width + 10,
- Location.Y + (ClientRectangle.Height - zoomer.ClientRectangle.Height) / 2);
- if (zoomer.Location.X + zoomer.Width > Screen.FromControl(this).WorkingArea.Width)
- {
- zoomer.StartPosition = FormStartPosition.WindowsDefaultLocation;
- }
- zoomer.ShowDialog();
+ MessageBox.Show("TODO", "Set Viewport Zoom", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void ButtonViewportSetCenter_Click(object? sender, EventArgs e)
{
@@ -468,7 +454,7 @@ public partial class GraphForm : Form
private void ButtonViewportReset_Click(object? sender, EventArgs e)
{
ScreenCenter = new Float2(0, 0);
- ZoomLevel = 1;
+ ZoomLevel = new(1, 1);
Invalidate(false);
}
private void ButtonViewportResetWindow_Click(object? sender, EventArgs e)
diff --git a/Base/Forms/SetZoomForm.Designer.cs b/Base/Forms/SetZoomForm.Designer.cs
deleted file mode 100644
index 52990db..0000000
--- a/Base/Forms/SetZoomForm.Designer.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-using System.Drawing;
-using System.Windows.Forms;
-
-namespace Graphing.Forms
-{
- partial class SetZoomForm
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- MessageLabel = new Label();
- ZoomTrackBar = new TrackBar();
- ValueLabel = new Label();
- ZoomMinValue = new TextBox();
- ZoomMaxValue = new TextBox();
- ((System.ComponentModel.ISupportInitialize)ZoomTrackBar).BeginInit();
- SuspendLayout();
- //
- // MessageLabel
- //
- MessageLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- MessageLabel.Location = new Point(52, 20);
- MessageLabel.Name = "MessageLabel";
- MessageLabel.Size = new Size(413, 35);
- MessageLabel.TabIndex = 0;
- MessageLabel.Text = "Set the zoom level for the graph.";
- MessageLabel.TextAlign = ContentAlignment.MiddleCenter;
- //
- // ZoomTrackBar
- //
- ZoomTrackBar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- ZoomTrackBar.LargeChange = 1000;
- ZoomTrackBar.Location = new Point(12, 127);
- ZoomTrackBar.Maximum = 10000;
- ZoomTrackBar.Name = "ZoomTrackBar";
- ZoomTrackBar.Size = new Size(489, 90);
- ZoomTrackBar.TabIndex = 1;
- ZoomTrackBar.TickStyle = TickStyle.None;
- ZoomTrackBar.Scroll += ZoomTrackBar_Scroll;
- //
- // ValueLabel
- //
- ValueLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- ValueLabel.Location = new Point(52, 91);
- ValueLabel.Name = "ValueLabel";
- ValueLabel.Size = new Size(413, 33);
- ValueLabel.TabIndex = 2;
- ValueLabel.Text = "1.00x";
- ValueLabel.TextAlign = ContentAlignment.TopCenter;
- //
- // ZoomMinValue
- //
- ZoomMinValue.Location = new Point(12, 178);
- ZoomMinValue.Name = "ZoomMinValue";
- ZoomMinValue.Size = new Size(83, 39);
- ZoomMinValue.TabIndex = 3;
- ZoomMinValue.Text = "0.50";
- ZoomMinValue.TextChanged += ZoomMinValue_TextChanged;
- //
- // ZoomMaxValue
- //
- ZoomMaxValue.Anchor = AnchorStyles.Top | AnchorStyles.Right;
- ZoomMaxValue.Location = new Point(418, 178);
- ZoomMaxValue.Name = "ZoomMaxValue";
- ZoomMaxValue.Size = new Size(83, 39);
- ZoomMaxValue.TabIndex = 4;
- ZoomMaxValue.Text = "2.00";
- ZoomMaxValue.TextAlign = HorizontalAlignment.Right;
- ZoomMaxValue.TextChanged += ZoomMaxValue_TextChanged;
- //
- // SetZoomForm
- //
- AutoScaleDimensions = new SizeF(13F, 32F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(513, 230);
- Controls.Add(ZoomMaxValue);
- Controls.Add(ZoomMinValue);
- Controls.Add(ValueLabel);
- Controls.Add(ZoomTrackBar);
- Controls.Add(MessageLabel);
- FormBorderStyle = FormBorderStyle.FixedToolWindow;
- Name = "SetZoomForm";
- Text = "Zoom Level";
- ((System.ComponentModel.ISupportInitialize)ZoomTrackBar).EndInit();
- ResumeLayout(false);
- PerformLayout();
- }
-
- #endregion
-
- private Label MessageLabel;
- private TrackBar ZoomTrackBar;
- private Label ValueLabel;
- private TextBox ZoomMinValue;
- private TextBox ZoomMaxValue;
- }
-}
\ No newline at end of file
diff --git a/Base/Forms/SetZoomForm.cs b/Base/Forms/SetZoomForm.cs
deleted file mode 100644
index fc21296..0000000
--- a/Base/Forms/SetZoomForm.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Graphing.Forms;
-
-public partial class SetZoomForm : Form
-{
- private double minZoomRange;
- private double maxZoomRange;
-
- private double zoomLevel;
-
- private readonly GraphForm form;
-
- public SetZoomForm(GraphForm form)
- {
- InitializeComponent();
-
- minZoomRange = 1 / (form.ZoomLevel * 2);
- maxZoomRange = 2 / form.ZoomLevel;
- zoomLevel = 1 / form.ZoomLevel;
-
- ZoomTrackBar.Value = (int)(ZoomToFactor(zoomLevel) * (ZoomTrackBar.Maximum - ZoomTrackBar.Minimum) + ZoomTrackBar.Minimum);
-
- this.form = form;
- }
-
- protected override void OnPaint(PaintEventArgs e)
- {
- ZoomMaxValue.Text = maxZoomRange.ToString("0.00");
- ZoomMinValue.Text = minZoomRange.ToString("0.00");
-
- ValueLabel.Text = $"{zoomLevel:0.00}x";
-
- base.OnPaint(e);
-
- form.ZoomLevel = 1 / zoomLevel;
- form.Invalidate(false);
- }
-
- private double FactorToZoom(double factor)
- {
- return minZoomRange + (factor * factor) * (maxZoomRange - minZoomRange);
- }
- private double ZoomToFactor(double zoom)
- {
- double sqrValue = (zoom - minZoomRange) / (maxZoomRange - minZoomRange);
- return Math.Sign(sqrValue) * Math.Sqrt(Math.Abs(sqrValue));
- }
-
- private void ZoomTrackBar_Scroll(object? sender, EventArgs e)
- {
- double factor = (ZoomTrackBar.Value - ZoomTrackBar.Minimum) / (double)(ZoomTrackBar.Maximum - ZoomTrackBar.Minimum);
- zoomLevel = FactorToZoom(factor);
-
- Invalidate(true);
- }
-
- private void ZoomMinValue_TextChanged(object? sender, EventArgs e)
- {
- double original = minZoomRange;
- try
- {
- double value;
- if (string.IsNullOrWhiteSpace(ZoomMinValue.Text) ||
- ZoomMinValue.Text.EndsWith('.'))
- {
- return;
- }
- else
- {
- value = double.Parse(ZoomMinValue.Text);
- if (value < 1e-2 || value > 1e3 || value > maxZoomRange) throw new();
- }
-
- minZoomRange = value;
- ZoomTrackBar.Value = (int)Math.Clamp(ZoomToFactor(zoomLevel) * (ZoomTrackBar.Maximum - ZoomTrackBar.Minimum) + ZoomTrackBar.Minimum, ZoomTrackBar.Minimum, ZoomTrackBar.Maximum);
- double factor = (ZoomTrackBar.Value - ZoomTrackBar.Minimum) / (double)(ZoomTrackBar.Maximum - ZoomTrackBar.Minimum);
- double newZoom = FactorToZoom(factor);
-
- zoomLevel = newZoom;
- if (newZoom != factor) Invalidate(true);
- }
- catch
- {
- minZoomRange = original;
- ZoomMinValue.Text = minZoomRange.ToString("0.00");
- }
- }
-
- private void ZoomMaxValue_TextChanged(object sender, EventArgs e)
- {
- double original = maxZoomRange;
- try
- {
- double value;
- if (string.IsNullOrWhiteSpace(ZoomMaxValue.Text) ||
- ZoomMaxValue.Text.EndsWith('.'))
- {
- return;
- }
- else
- {
- value = double.Parse(ZoomMaxValue.Text);
- if (value < 1e-2 || value > 1e3 || value < minZoomRange) throw new();
- }
-
- maxZoomRange = value;
- ZoomTrackBar.Value = (int)Math.Clamp(ZoomToFactor(zoomLevel) * (ZoomTrackBar.Maximum - ZoomTrackBar.Minimum) + ZoomTrackBar.Minimum, ZoomTrackBar.Minimum, ZoomTrackBar.Maximum);
- double factor = (ZoomTrackBar.Value - ZoomTrackBar.Minimum) / (double)(ZoomTrackBar.Maximum - ZoomTrackBar.Minimum);
- double newZoom = FactorToZoom(factor);
-
- zoomLevel = newZoom;
- if (newZoom != factor) Invalidate(true);
- }
- catch
- {
- maxZoomRange = original;
- ZoomMaxValue.Text = maxZoomRange.ToString("0.00");
- }
- }
-}
diff --git a/Base/Forms/SetZoomForm.resx b/Base/Forms/SetZoomForm.resx
deleted file mode 100644
index af32865..0000000
--- a/Base/Forms/SetZoomForm.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file