Nice progress. Some of it is bodged a bit but that's okay.
This commit is contained in:
parent
66146355c6
commit
3665b0547a
@ -11,6 +11,7 @@ namespace Graphing.Forms;
|
|||||||
|
|
||||||
public partial class GraphForm : Form
|
public partial class GraphForm : Form
|
||||||
{
|
{
|
||||||
|
public static readonly Color BackgroundColor = Color.White;
|
||||||
public static readonly Color MainAxisColor = Color.Black;
|
public static readonly Color MainAxisColor = Color.Black;
|
||||||
public static readonly Color SemiAxisColor = Color.FromArgb(unchecked((int)0xFF_999999));
|
public static readonly Color SemiAxisColor = Color.FromArgb(unchecked((int)0xFF_999999));
|
||||||
public static readonly Color QuarterAxisColor = Color.FromArgb(unchecked((int)0xFF_E0E0E0));
|
public static readonly Color QuarterAxisColor = Color.FromArgb(unchecked((int)0xFF_E0E0E0));
|
||||||
@ -200,7 +201,7 @@ public partial class GraphForm : Form
|
|||||||
Graphics g = e.Graphics;
|
Graphics g = e.Graphics;
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
|
||||||
Brush background = new SolidBrush(Color.White);
|
Brush background = new SolidBrush(BackgroundColor);
|
||||||
g.FillRectangle(background, e.ClipRectangle);
|
g.FillRectangle(background, e.ClipRectangle);
|
||||||
|
|
||||||
PaintGrid(g);
|
PaintGrid(g);
|
||||||
@ -231,7 +232,7 @@ public partial class GraphForm : Form
|
|||||||
if (ables[i].ShouldSelectGraphable(this, graphMousePos, 2.5))
|
if (ables[i].ShouldSelectGraphable(this, graphMousePos, 2.5))
|
||||||
{
|
{
|
||||||
Float2 selectedPoint = ables[i].GetSelectedPoint(this, graphMousePos);
|
Float2 selectedPoint = ables[i].GetSelectedPoint(this, graphMousePos);
|
||||||
GraphUiCircle select = new(selectedPoint, 8);
|
GraphUiCircle select = new(selectedPoint);
|
||||||
|
|
||||||
Int2 textPos = GraphSpaceToScreenSpace(select.center);
|
Int2 textPos = GraphSpaceToScreenSpace(select.center);
|
||||||
textPos.y -= (int)(DpiFloat * 32 / 192);
|
textPos.y -= (int)(DpiFloat * 32 / 192);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public abstract class Graphable
|
|||||||
|
|
||||||
public abstract IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph);
|
public abstract IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph);
|
||||||
|
|
||||||
public abstract Graphable DeepCopy();
|
public abstract Graphable ShallowCopy();
|
||||||
|
|
||||||
public virtual void EraseCache() { }
|
public virtual void EraseCache() { }
|
||||||
public virtual long GetCacheBytes() => 0;
|
public virtual long GetCacheBytes() => 0;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class ColumnTable : Graphable
|
|||||||
|
|
||||||
public override long GetCacheBytes() => 16 * tableXY.Count;
|
public override long GetCacheBytes() => 16 * tableXY.Count;
|
||||||
|
|
||||||
public override Graphable DeepCopy() => new ColumnTable(width / 0.75, tableXY.ToArray().ToDictionary());
|
public override Graphable ShallowCopy() => new ColumnTable(width / 0.75, tableXY);
|
||||||
|
|
||||||
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -116,7 +116,7 @@ public class Equation : Graphable, IIntegrable, IDerivable, ITranslatableXY
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Graphable DeepCopy() => new Equation(equ);
|
public override Graphable ShallowCopy() => new Equation(equ);
|
||||||
|
|
||||||
public override long GetCacheBytes() => cache.Count * 16;
|
public override long GetCacheBytes() => cache.Count * 16;
|
||||||
|
|
||||||
|
|||||||
58
Base/Graphables/EquationDifference.cs
Normal file
58
Base/Graphables/EquationDifference.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using Graphing.Abstract;
|
||||||
|
using Graphing.Forms;
|
||||||
|
using Graphing.Parts;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Graphing.Graphables;
|
||||||
|
|
||||||
|
public class EquationDifference : Graphable, ITranslatableX, IEquationConvertible
|
||||||
|
{
|
||||||
|
public double Position
|
||||||
|
{
|
||||||
|
get => _position;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_position = value;
|
||||||
|
points = new Float2(equA.GetValueAt(value), equB.GetValueAt(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private double _position;
|
||||||
|
|
||||||
|
public double OffsetX
|
||||||
|
{
|
||||||
|
get => Position;
|
||||||
|
set => Position = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly Equation equA, equB;
|
||||||
|
protected Float2 points; // X represents equA.y, Y represents equB.y
|
||||||
|
|
||||||
|
public EquationDifference(double position, Equation equA, Equation equB)
|
||||||
|
{
|
||||||
|
this.equA = equA;
|
||||||
|
this.equB = equB;
|
||||||
|
|
||||||
|
Name = $"Difference between {equA.Name} and {equB.Name}";
|
||||||
|
|
||||||
|
Position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
||||||
|
{
|
||||||
|
Float2 pA = new(Position, points.x),
|
||||||
|
pB = new(Position, points.y),
|
||||||
|
pC = new(Position, (points.x + points.y) / 2);
|
||||||
|
return [new GraphUiText($"{points.x - points.y:0.00}", pC),
|
||||||
|
new GraphUiCircle(pA), new GraphUiCircle(pB), new GraphLine(pA, pB)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public double DistanceAtPoint(double x) => equA.GetValueAt(x) - equB.GetValueAt(x);
|
||||||
|
|
||||||
|
public override Graphable ShallowCopy() => new EquationDifference(Position, equA, equB);
|
||||||
|
|
||||||
|
public Equation ToEquation() => new(DistanceAtPoint)
|
||||||
|
{
|
||||||
|
Color = Color,
|
||||||
|
Name = Name
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -47,7 +47,7 @@ public class IntegralEquation : Graphable, IIntegrable, IDerivable
|
|||||||
usingAlt = true;
|
usingAlt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Graphable DeepCopy() => new IntegralEquation(this);
|
public override Graphable ShallowCopy() => new IntegralEquation(this);
|
||||||
|
|
||||||
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
||||||
{
|
{
|
||||||
@ -178,8 +178,8 @@ public class IntegralEquation : Graphable, IIntegrable, IDerivable
|
|||||||
|
|
||||||
public Graphable Derive()
|
public Graphable Derive()
|
||||||
{
|
{
|
||||||
if (usingAlt) return altBaseEqu!.DeepCopy();
|
if (usingAlt) return altBaseEqu!.ShallowCopy();
|
||||||
else return (Equation)baseEqu!.DeepCopy();
|
else return (Equation)baseEqu!.ShallowCopy();
|
||||||
}
|
}
|
||||||
public Graphable Integrate() => new IntegralEquation(this);
|
public Graphable Integrate() => new IntegralEquation(this);
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ public class SlopeField : Graphable
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Graphable DeepCopy() => new SlopeField(detail, equ);
|
public override Graphable ShallowCopy() => new SlopeField(detail, equ);
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public class TangentLine : Graphable, IEquationConvertible, ITranslatableX
|
|||||||
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
|
||||||
{
|
{
|
||||||
Float2 point = new(Position, currentSlope.y);
|
Float2 point = new(Position, currentSlope.y);
|
||||||
return [MakeSlopeLine(), new GraphUiCircle(point, 8)];
|
return [MakeSlopeLine(), new GraphUiCircle(point)];
|
||||||
}
|
}
|
||||||
protected GraphLine MakeSlopeLine()
|
protected GraphLine MakeSlopeLine()
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ public class TangentLine : Graphable, IEquationConvertible, ITranslatableX
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Graphable DeepCopy() => new TangentLine(length, Position, parent);
|
public override Graphable ShallowCopy() => new TangentLine(length, Position, parent);
|
||||||
|
|
||||||
public override void EraseCache() => slopeCache.Clear();
|
public override void EraseCache() => slopeCache.Clear();
|
||||||
public override long GetCacheBytes() => slopeCache.Count * 24;
|
public override long GetCacheBytes() => slopeCache.Count * 24;
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public record struct GraphUiCircle : IGraphPart
|
|||||||
center = new();
|
center = new();
|
||||||
radius = 1;
|
radius = 1;
|
||||||
}
|
}
|
||||||
public GraphUiCircle(Float2 center, int radius)
|
public GraphUiCircle(Float2 center, int radius = 8)
|
||||||
{
|
{
|
||||||
this.center = center;
|
this.center = center;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
|
|||||||
38
Base/Parts/GraphUiText.cs
Normal file
38
Base/Parts/GraphUiText.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using Graphing.Forms;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace Graphing.Parts;
|
||||||
|
|
||||||
|
public record struct GraphUiText : IGraphPart
|
||||||
|
{
|
||||||
|
public string text;
|
||||||
|
public Float2 position;
|
||||||
|
public bool background;
|
||||||
|
|
||||||
|
private readonly Font font;
|
||||||
|
private readonly Brush? backgroundBrush;
|
||||||
|
|
||||||
|
public GraphUiText(string text, Float2 position, bool background = true)
|
||||||
|
{
|
||||||
|
font = new Font("Segoe UI", 8, FontStyle.Bold);
|
||||||
|
|
||||||
|
this.text = text;
|
||||||
|
this.position = position;
|
||||||
|
this.background = background;
|
||||||
|
|
||||||
|
if (background) backgroundBrush = new SolidBrush(GraphForm.BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly void Render(in GraphForm form, in Graphics g, in Pen p)
|
||||||
|
{
|
||||||
|
Int2 posScreen = form.GraphSpaceToScreenSpace(position);
|
||||||
|
posScreen.y -= (int)(form.DpiFloat * font.Size * 2 / 192);
|
||||||
|
if (background)
|
||||||
|
{
|
||||||
|
SizeF size = g.MeasureString(text, font);
|
||||||
|
g.FillRectangle(backgroundBrush!, new Rectangle(posScreen.x, posScreen.y,
|
||||||
|
(int)size.Width, (int)size.Height));
|
||||||
|
}
|
||||||
|
g.DrawString(text, font, p.Brush, new Point(posScreen.x, posScreen.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,15 +16,10 @@ internal static class Program
|
|||||||
|
|
||||||
GraphForm graph = new("One Of The Graphing Calculators Of All Time");
|
GraphForm graph = new("One Of The Graphing Calculators Of All Time");
|
||||||
|
|
||||||
Equation equ = new(Math.Sin);
|
Equation equA = new(Math.Sin),
|
||||||
SlopeField sf = new(2, (x, y) => Math.Cos(x));
|
equB = new(Math.Cos);
|
||||||
TangentLine tl = new(2, 2, equ);
|
EquationDifference diff = new(2, equA, equB);
|
||||||
graph.Graph(equ, sf, tl);
|
graph.Graph(equA, equB, diff);
|
||||||
|
|
||||||
// Now, when integrating equations, the result is much less jagged
|
|
||||||
// and much faster. Try it out! You can also select points along
|
|
||||||
// equations and such as well. Click on an equation to see for
|
|
||||||
// yourself!
|
|
||||||
|
|
||||||
Application.Run(graph);
|
Application.Run(graph);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user