Almost done. Added coordinates for selected points.

This commit is contained in:
That_One_Nerd 2024-03-18 14:07:21 -04:00
parent 55cb7af2ac
commit c30ced7578
3 changed files with 28 additions and 10 deletions

View File

@ -206,22 +206,38 @@ public partial class GraphForm : Form
clientMousePos.Y)); clientMousePos.Y));
// Draw the actual graphs. // Draw the actual graphs.
Pen[] graphPens = new Pen[ables.Count];
for (int i = 0; i < ables.Count; i++) for (int i = 0; i < ables.Count; i++)
{ {
IEnumerable<IGraphPart> lines = ables[i].GetItemsToRender(this); IEnumerable<IGraphPart> lines = ables[i].GetItemsToRender(this);
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);
graphPens[i] = graphPen;
foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen); foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen);
}
// Equation selection detection. // Equation selection detection.
// This system lets you select multiple graphs, and that's cool by me. // This system lets you select multiple graphs, and that's cool by me.
if (ableDrag) if (ableDrag)
{
Font textFont = new(Font.Name, 8, FontStyle.Bold);
for (int i = 0; i < ables.Count; i++)
{ {
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, 8);
select.Render(this, g, graphPen);
Int2 textPos = GraphSpaceToScreenSpace(select.center);
textPos.y -= (int)(DpiFloat * 32 / 192);
string content = $"({selectedPoint.x:0.00}, {selectedPoint.y:0.00})";
SizeF textSize = g.MeasureString(content, textFont);
g.FillRectangle(background, new Rectangle(textPos.x, textPos.y,
(int)textSize.Width, (int)textSize.Height));
g.DrawString(content, textFont, graphPens[i].Brush, new Point(textPos.x, textPos.y));
select.Render(this, g, graphPens[i]);
} }
} }
} }

View File

@ -23,9 +23,11 @@ public record struct GraphUiCircle : IGraphPart
if (!double.IsFinite(center.x) || !double.IsFinite(center.y) || if (!double.IsFinite(center.x) || !double.IsFinite(center.y) ||
!double.IsFinite(radius) || radius == 0) return; !double.IsFinite(radius) || radius == 0) return;
int rad = (int)(form.DpiFloat * radius / 192);
Int2 centerPix = form.GraphSpaceToScreenSpace(center); Int2 centerPix = form.GraphSpaceToScreenSpace(center);
g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - radius, g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - rad,
centerPix.y - radius), centerPix.y - rad),
new Size(radius * 2, radius * 2))); new Size(rad * 2, rad * 2)));
} }
} }

View File

@ -10,12 +10,12 @@ internal static class Program
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
GraphForm graph = new("One Of The Graphing Calculators Of All Time"); GraphForm graph = new("One Of The Graphing Calculators Of All Time");
Equation possibleA = new(x => x * x * x); Equation possibleA = new(Math.Sin);
SlopeField sf = new(2, (x, y) => 1 / x); SlopeField sf = new(2, (x, y) => Math.Cos(x));
TangentLine tl = new(2, 2, possibleA); TangentLine tl = new(2, 2, possibleA);
graph.Graph(possibleA, sf, tl); graph.Graph(possibleA, sf, tl);