Version 1.2 is ready. #25
11
Base/Forms/GraphForm.Designer.cs
generated
11
Base/Forms/GraphForm.Designer.cs
generated
@ -41,6 +41,7 @@
|
|||||||
MenuEquationsIntegral = new ToolStripMenuItem();
|
MenuEquationsIntegral = new ToolStripMenuItem();
|
||||||
MenuMisc = new ToolStripMenuItem();
|
MenuMisc = new ToolStripMenuItem();
|
||||||
MenuMiscCaches = new ToolStripMenuItem();
|
MenuMiscCaches = new ToolStripMenuItem();
|
||||||
|
MiscMenuPreload = new ToolStripMenuItem();
|
||||||
GraphMenu.SuspendLayout();
|
GraphMenu.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -129,7 +130,7 @@
|
|||||||
//
|
//
|
||||||
// MenuMisc
|
// MenuMisc
|
||||||
//
|
//
|
||||||
MenuMisc.DropDownItems.AddRange(new ToolStripItem[] { MenuMiscCaches });
|
MenuMisc.DropDownItems.AddRange(new ToolStripItem[] { MenuMiscCaches, MiscMenuPreload });
|
||||||
MenuMisc.Name = "MenuMisc";
|
MenuMisc.Name = "MenuMisc";
|
||||||
MenuMisc.Size = new Size(83, 38);
|
MenuMisc.Size = new Size(83, 38);
|
||||||
MenuMisc.Text = "Misc";
|
MenuMisc.Text = "Misc";
|
||||||
@ -141,6 +142,13 @@
|
|||||||
MenuMiscCaches.Text = "View Caches";
|
MenuMiscCaches.Text = "View Caches";
|
||||||
MenuMiscCaches.Click += MenuMiscCaches_Click;
|
MenuMiscCaches.Click += MenuMiscCaches_Click;
|
||||||
//
|
//
|
||||||
|
// MiscMenuPreload
|
||||||
|
//
|
||||||
|
MiscMenuPreload.Name = "MiscMenuPreload";
|
||||||
|
MiscMenuPreload.Size = new Size(359, 44);
|
||||||
|
MiscMenuPreload.Text = "Preload Cache";
|
||||||
|
MiscMenuPreload.Click += MiscMenuPreload_Click;
|
||||||
|
//
|
||||||
// GraphForm
|
// GraphForm
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
@ -172,5 +180,6 @@
|
|||||||
private ToolStripMenuItem MenuEquationsIntegral;
|
private ToolStripMenuItem MenuEquationsIntegral;
|
||||||
private ToolStripMenuItem MenuMisc;
|
private ToolStripMenuItem MenuMisc;
|
||||||
private ToolStripMenuItem MenuMiscCaches;
|
private ToolStripMenuItem MenuMiscCaches;
|
||||||
|
private ToolStripMenuItem MiscMenuPreload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Graphing.Graphables;
|
using Graphing.Graphables;
|
||||||
|
using Graphing.Parts;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
namespace Graphing.Forms;
|
namespace Graphing.Forms;
|
||||||
@ -200,6 +201,10 @@ public partial class GraphForm : Form
|
|||||||
PaintGrid(g);
|
PaintGrid(g);
|
||||||
PaintUnits(g);
|
PaintUnits(g);
|
||||||
|
|
||||||
|
Point clientMousePos = PointToClient(Cursor.Position);
|
||||||
|
Float2 graphMousePos = ScreenSpaceToGraphSpace(new(clientMousePos.X,
|
||||||
|
clientMousePos.Y));
|
||||||
|
|
||||||
// Draw the actual graphs.
|
// Draw the actual graphs.
|
||||||
for (int i = 0; i < ables.Count; i++)
|
for (int i = 0; i < ables.Count; i++)
|
||||||
{
|
{
|
||||||
@ -207,6 +212,18 @@ public partial class GraphForm : Form
|
|||||||
Brush graphBrush = new SolidBrush(ables[i].Color);
|
Brush graphBrush = new SolidBrush(ables[i].Color);
|
||||||
Pen graphPen = new(graphBrush, DpiFloat * 3 / 192);
|
Pen graphPen = new(graphBrush, DpiFloat * 3 / 192);
|
||||||
foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen);
|
foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen);
|
||||||
|
|
||||||
|
// Equation selection detection.
|
||||||
|
// This system lets you select multiple graphs, and that's cool by me.
|
||||||
|
if (ableDrag)
|
||||||
|
{
|
||||||
|
if (ables[i].ShouldSelectGraphable(this, graphMousePos, 2.5))
|
||||||
|
{
|
||||||
|
Float2 selectedPoint = ables[i].GetSelectedPoint(this, graphMousePos);
|
||||||
|
GraphUiCircle select = new(selectedPoint, 8);
|
||||||
|
select.Render(this, g, graphPen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
@ -227,12 +244,29 @@ public partial class GraphForm : Form
|
|||||||
private bool mouseDrag = false;
|
private bool mouseDrag = false;
|
||||||
private Int2 initialMouseLocation;
|
private Int2 initialMouseLocation;
|
||||||
private Float2 initialScreenCenter;
|
private Float2 initialScreenCenter;
|
||||||
|
|
||||||
|
private bool ableDrag = false;
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (!mouseDrag)
|
||||||
|
{
|
||||||
|
Point clientMousePos = PointToClient(Cursor.Position);
|
||||||
|
Float2 graphMousePos = ScreenSpaceToGraphSpace(new(clientMousePos.X,
|
||||||
|
clientMousePos.Y));
|
||||||
|
foreach (Graphable able in Graphables)
|
||||||
|
{
|
||||||
|
if (able.ShouldSelectGraphable(this, graphMousePos, 1)) ableDrag = true;
|
||||||
|
}
|
||||||
|
if (ableDrag) Invalidate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ableDrag)
|
||||||
{
|
{
|
||||||
mouseDrag = true;
|
mouseDrag = true;
|
||||||
initialMouseLocation = new Int2(Cursor.Position.X, Cursor.Position.Y);
|
initialMouseLocation = new Int2(Cursor.Position.X, Cursor.Position.Y);
|
||||||
initialScreenCenter = ScreenCenter;
|
initialScreenCenter = ScreenCenter;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected override void OnMouseUp(MouseEventArgs e)
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (mouseDrag)
|
if (mouseDrag)
|
||||||
@ -242,9 +276,10 @@ public partial class GraphForm : Form
|
|||||||
Float2 graphDiff = new(pixelDiff.x * ZoomLevel / Dpi.x, pixelDiff.y * ZoomLevel / Dpi.y);
|
Float2 graphDiff = new(pixelDiff.x * ZoomLevel / Dpi.x, pixelDiff.y * ZoomLevel / Dpi.y);
|
||||||
ScreenCenter = new(initialScreenCenter.x + graphDiff.x,
|
ScreenCenter = new(initialScreenCenter.x + graphDiff.x,
|
||||||
initialScreenCenter.y + graphDiff.y);
|
initialScreenCenter.y + graphDiff.y);
|
||||||
Invalidate(false);
|
|
||||||
}
|
}
|
||||||
mouseDrag = false;
|
mouseDrag = false;
|
||||||
|
ableDrag = false;
|
||||||
|
Invalidate(false);
|
||||||
}
|
}
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
@ -257,6 +292,7 @@ public partial class GraphForm : Form
|
|||||||
initialScreenCenter.y + graphDiff.y);
|
initialScreenCenter.y + graphDiff.y);
|
||||||
Invalidate(false);
|
Invalidate(false);
|
||||||
}
|
}
|
||||||
|
else if (ableDrag) Invalidate(false);
|
||||||
}
|
}
|
||||||
protected override void OnMouseWheel(MouseEventArgs e)
|
protected override void OnMouseWheel(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
@ -425,4 +461,17 @@ public partial class GraphForm : Form
|
|||||||
cacheForm.TopMost = true;
|
cacheForm.TopMost = true;
|
||||||
cacheForm.Show();
|
cacheForm.Show();
|
||||||
}
|
}
|
||||||
|
private void MiscMenuPreload_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Float2 min = MinVisibleGraph, max = MaxVisibleGraph;
|
||||||
|
Float2 add = new(max.x - min.x, max.y - min.y);
|
||||||
|
add.x *= 0.75; // Expansion
|
||||||
|
add.y *= 0.75; //
|
||||||
|
|
||||||
|
Float2 xRange = new(min.x - add.x, max.x + add.x),
|
||||||
|
yRange = new(min.y - add.y, max.y + add.y);
|
||||||
|
|
||||||
|
foreach (Graphable able in Graphables) able.Preload(xRange, yRange);
|
||||||
|
Invalidate(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using Graphing.Forms;
|
using Graphing.Forms;
|
||||||
using Graphing.Parts;
|
|
||||||
|
|
||||||
namespace Graphing;
|
namespace Graphing;
|
||||||
|
|
||||||
@ -33,4 +32,8 @@ public abstract class Graphable
|
|||||||
|
|
||||||
public abstract void EraseCache();
|
public abstract void EraseCache();
|
||||||
public abstract long GetCacheBytes();
|
public abstract long GetCacheBytes();
|
||||||
|
public abstract void Preload(Float2 xRange, Float2 yRange);
|
||||||
|
|
||||||
|
public abstract bool ShouldSelectGraphable(in GraphForm graph, Float2 graphMousePos, double factor);
|
||||||
|
public abstract Float2 GetSelectedPoint(in GraphForm graph, Float2 graphMousePos);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,4 +48,9 @@ public class ColumnTable : Graphable
|
|||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool ShouldSelectGraphable(in GraphForm graph, Float2 graphMousePos, double factor) => false;
|
||||||
|
public override Float2 GetSelectedPoint(in GraphForm graph, Float2 graphMousePos) => default;
|
||||||
|
|
||||||
|
public override void Preload(Float2 xRange, Float2 yRange) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,6 +96,30 @@ public class Equation : Graphable
|
|||||||
public override Graphable DeepCopy() => new Equation(equ);
|
public override Graphable DeepCopy() => new Equation(equ);
|
||||||
|
|
||||||
public override long GetCacheBytes() => cache.Count * 16;
|
public override long GetCacheBytes() => cache.Count * 16;
|
||||||
|
|
||||||
|
public override bool ShouldSelectGraphable(in GraphForm graph, Float2 graphMousePos, double factor)
|
||||||
|
{
|
||||||
|
Int2 screenMousePos = graph.GraphSpaceToScreenSpace(graphMousePos);
|
||||||
|
|
||||||
|
(_, _, int index) = NearestCachedPoint(graphMousePos.x);
|
||||||
|
Int2 screenCachePos = graph.GraphSpaceToScreenSpace(cache[index]);
|
||||||
|
|
||||||
|
double allowedDist = factor * graph.DpiFloat * 80 / 192;
|
||||||
|
|
||||||
|
Int2 dist = new(screenCachePos.x - screenMousePos.x,
|
||||||
|
screenCachePos.y - screenMousePos.y);
|
||||||
|
double totalDist = Math.Sqrt(dist.x * dist.x + dist.y * dist.y);
|
||||||
|
return totalDist <= allowedDist;
|
||||||
|
}
|
||||||
|
public override Float2 GetSelectedPoint(in GraphForm graph, Float2 graphMousePos)
|
||||||
|
{
|
||||||
|
return new(graphMousePos.x, GetFromCache(graphMousePos.x, 0.001));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Preload(Float2 xRange, Float2 yRange)
|
||||||
|
{
|
||||||
|
for (double x = xRange.x; x <= xRange.y; x += 1e-3) GetFromCache(x, 1e-4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate double EquationDelegate(double x);
|
public delegate double EquationDelegate(double x);
|
||||||
|
|||||||
@ -74,6 +74,11 @@ public class SlopeField : Graphable
|
|||||||
|
|
||||||
public override void EraseCache() => cache.Clear();
|
public override void EraseCache() => cache.Clear();
|
||||||
public override long GetCacheBytes() => cache.Count * 48;
|
public override long GetCacheBytes() => cache.Count * 48;
|
||||||
|
|
||||||
|
public override bool ShouldSelectGraphable(in GraphForm graph, Float2 graphMousePos, double factor) => false;
|
||||||
|
public override Float2 GetSelectedPoint(in GraphForm graph, Float2 graphMousePos) => default;
|
||||||
|
|
||||||
|
public override void Preload(Float2 xRange, Float2 yRange) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate double SlopeFieldsDelegate(double x, double y);
|
public delegate double SlopeFieldsDelegate(double x, double y);
|
||||||
|
|||||||
@ -48,4 +48,9 @@ public class TangentLine : Graphable
|
|||||||
|
|
||||||
public override void EraseCache() { }
|
public override void EraseCache() { }
|
||||||
public override long GetCacheBytes() => 0;
|
public override long GetCacheBytes() => 0;
|
||||||
|
|
||||||
|
public override bool ShouldSelectGraphable(in GraphForm graph, Float2 graphMousePos, double factor) => false;
|
||||||
|
public override Float2 GetSelectedPoint(in GraphForm graph, Float2 graphMousePos) => default;
|
||||||
|
|
||||||
|
public override void Preload(Float2 xRange, Float2 yRange) { }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user