Compare commits

...

1 Commits
main ... canary

Author SHA1 Message Date
3ed0f80454 Replaced DpiFloat with ScalingFactor 2024-08-19 11:54:47 -04:00
11 changed files with 26 additions and 26 deletions

View File

@ -41,7 +41,7 @@ public partial class GraphColorPickerForm : Form
MessageLabel.Text = $"Pick a color for {able.Name}."; MessageLabel.Text = $"Pick a color for {able.Name}.";
// Add preset buttons. // Add preset buttons.
int size = (int)(graph.DpiFloat * 48 / 192); int size = (int)(graph.ScalingFactor * 48);
int position = 0; int position = 0;
foreach (uint cId in Graphable.DefaultColors) foreach (uint cId in Graphable.DefaultColors)
{ {

View File

@ -29,7 +29,7 @@ public partial class GraphForm : Form
public Float2 ScreenCenter { get; set; } public Float2 ScreenCenter { get; set; }
public Float2 Dpi { get; private set; } public Float2 Dpi { get; private set; }
public float DpiFloat { get; private set; } public float ScalingFactor { get; private set; }
public Float2 ZoomLevel public Float2 ZoomLevel
{ {
@ -92,7 +92,7 @@ public partial class GraphForm : Form
Dpi = new(tempG.DpiX, tempG.DpiY); Dpi = new(tempG.DpiX, tempG.DpiY);
tempG.Dispose(); tempG.Dispose();
DpiFloat = (float)((Dpi.x + Dpi.y) / 2); ScalingFactor = (float)((Dpi.x + Dpi.y) / 384.0);
ables = []; ables = [];
ZoomLevel = new(1, 1); ZoomLevel = new(1, 1);
@ -142,7 +142,7 @@ public partial class GraphForm : Form
// Draw horizontal/vertical quarter-axis. // Draw horizontal/vertical quarter-axis.
Brush quarterBrush = new SolidBrush(QuarterAxisColor); Brush quarterBrush = new SolidBrush(QuarterAxisColor);
Pen quarterPen = new(quarterBrush, DpiFloat * 2 / 192); Pen quarterPen = new(quarterBrush, ScalingFactor * 2);
for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x += axisScaleX / 4) for (double x = Math.Ceiling(MinVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x <= Math.Floor(MaxVisibleGraph.x * 4 / axisScaleX) * axisScaleX / 4; x += axisScaleX / 4)
{ {
@ -159,7 +159,7 @@ public partial class GraphForm : Form
// Draw horizontal/vertical semi-axis. // Draw horizontal/vertical semi-axis.
Brush semiBrush = new SolidBrush(SemiAxisColor); Brush semiBrush = new SolidBrush(SemiAxisColor);
Pen semiPen = new(semiBrush, DpiFloat * 2 / 192); Pen semiPen = new(semiBrush, ScalingFactor * 2);
for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= Math.Floor(MaxVisibleGraph.x / axisScaleX) * axisScaleX; x += axisScaleX) for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= Math.Floor(MaxVisibleGraph.x / axisScaleX) * axisScaleX; x += axisScaleX)
{ {
@ -175,7 +175,7 @@ public partial class GraphForm : Form
} }
Brush mainLineBrush = new SolidBrush(MainAxisColor); Brush mainLineBrush = new SolidBrush(MainAxisColor);
Pen mainLinePen = new(mainLineBrush, DpiFloat * 3 / 192); Pen mainLinePen = new(mainLineBrush, ScalingFactor * 3);
// Draw the main axis (on top of the semi axis). // Draw the main axis (on top of the semi axis).
Int2 startCenterY = GraphSpaceToScreenSpace(new Float2(0, MinVisibleGraph.y)), Int2 startCenterY = GraphSpaceToScreenSpace(new Float2(0, MinVisibleGraph.y)),
@ -194,8 +194,8 @@ public partial class GraphForm : Form
Font textFont = new(Font.Name, 9, FontStyle.Regular); Font textFont = new(Font.Name, 9, FontStyle.Regular);
// X-axis // X-axis
int minX = (int)(DpiFloat * 50 / 192), int minX = (int)(ScalingFactor * 50),
maxX = ClientRectangle.Height - (int)(DpiFloat * 40 / 192); maxX = ClientRectangle.Height - (int)(ScalingFactor * 40);
for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= MaxVisibleGraph.x; x += axisScaleX) for (double x = Math.Ceiling(MinVisibleGraph.x / axisScaleX) * axisScaleX; x <= MaxVisibleGraph.x; x += axisScaleX)
{ {
if (x == 0) x = 0; // Fixes -0 if (x == 0) x = 0; // Fixes -0
@ -209,7 +209,7 @@ public partial class GraphForm : Form
} }
// Y-axis // Y-axis
int minY = (int)(DpiFloat * 10 / 192); int minY = (int)(ScalingFactor * 10);
for (double y = Math.Ceiling(MinVisibleGraph.y / axisScaleY) * axisScaleY; y <= MaxVisibleGraph.y; y += axisScaleY) for (double y = Math.Ceiling(MinVisibleGraph.y / axisScaleY) * axisScaleY; y <= MaxVisibleGraph.y; y += axisScaleY)
{ {
if (y == 0) continue; if (y == 0) continue;
@ -217,7 +217,7 @@ public partial class GraphForm : Form
Int2 screenPos = GraphSpaceToScreenSpace(new Float2(0, y)); Int2 screenPos = GraphSpaceToScreenSpace(new Float2(0, y));
string result = y.ToString(); string result = y.ToString();
int maxY = ClientRectangle.Width - (int)(DpiFloat * (textFont.Height * result.Length * 0.40 + 15) / 192); int maxY = ClientRectangle.Width - (int)(ScalingFactor * (textFont.Height * result.Length * 0.40 + 15));
if (screenPos.x < minY) screenPos.x = minY; if (screenPos.x < minY) screenPos.x = minY;
else if (screenPos.x > maxY) screenPos.x = maxY; else if (screenPos.x > maxY) screenPos.x = maxY;
@ -247,7 +247,7 @@ public partial class GraphForm : Form
{ {
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, ScalingFactor * 3);
graphPens[i] = graphPen; graphPens[i] = graphPen;
foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen); foreach (IGraphPart gp in lines) gp.Render(this, g, graphPen);
} }
@ -274,7 +274,7 @@ public partial class GraphForm : Form
if (boxPosA.x > boxPosB.x) (boxPosA.x, boxPosB.x) = (boxPosB.x, boxPosA.x); if (boxPosA.x > boxPosB.x) (boxPosA.x, boxPosB.x) = (boxPosB.x, boxPosA.x);
if (boxPosA.y > boxPosB.y) (boxPosA.y, boxPosB.y) = (boxPosB.y, boxPosA.y); if (boxPosA.y > boxPosB.y) (boxPosA.y, boxPosB.y) = (boxPosB.y, boxPosA.y);
Pen boxPen = new(ZoomBoxColor, 2 * DpiFloat / 192); Pen boxPen = new(ZoomBoxColor, ScalingFactor * 2);
g.DrawRectangle(boxPen, new(boxPosA.x, boxPosA.y, g.DrawRectangle(boxPen, new(boxPosA.x, boxPosA.y,
boxPosB.x - boxPosA.x, boxPosB.x - boxPosA.x,
boxPosB.y - boxPosA.y)); boxPosB.y - boxPosA.y));

View File

@ -37,9 +37,9 @@ public partial class ViewCacheForm : Form
CachePie.Values.Add((able.Color, thisBytes)); CachePie.Values.Add((able.Color, thisBytes));
totalBytes += thisBytes; totalBytes += thisBytes;
int buttonHeight = (int)(refForm.DpiFloat * 46 / 192), int buttonHeight = (int)(refForm.ScalingFactor * 46),
buttonWidth = (int)(refForm.DpiFloat * 92 / 192), buttonWidth = (int)(refForm.ScalingFactor * 92),
buttonSpaced = (int)(refForm.DpiFloat * 98 / 192); buttonSpaced = (int)(refForm.ScalingFactor * 98);
if (index < labelCache.Count) if (index < labelCache.Count)
{ {

View File

@ -91,7 +91,7 @@ public class ColumnTable : Graphable
} }
int totalDist = (int)Math.Sqrt(distX * distX + distY * distY); int totalDist = (int)Math.Sqrt(distX * distX + distY * distY);
return totalDist < 50 * factor * graph.DpiFloat / 192; return totalDist < 50 * factor * graph.ScalingFactor;
} }
public override IEnumerable<IGraphPart> GetSelectionItemsToRender(in GraphForm graph, Float2 graphMousePos) public override IEnumerable<IGraphPart> GetSelectionItemsToRender(in GraphForm graph, Float2 graphMousePos)
{ {

View File

@ -43,7 +43,7 @@ public class Equation : Graphable, IIntegrable, IDerivable, ITranslatableXY, ICo
double epsilon = Math.Abs(graph.ScreenSpaceToGraphSpace(new Int2(0, 0)).x double epsilon = Math.Abs(graph.ScreenSpaceToGraphSpace(new Int2(0, 0)).x
- graph.ScreenSpaceToGraphSpace(new Int2(step / 2, 0)).x) / 5; - graph.ScreenSpaceToGraphSpace(new Int2(step / 2, 0)).x) / 5;
epsilon *= graph.DpiFloat / 192; epsilon *= graph.ScalingFactor;
List<IGraphPart> lines = []; List<IGraphPart> lines = [];
@ -142,7 +142,7 @@ public class Equation : Graphable, IIntegrable, IDerivable, ITranslatableXY, ICo
(_, _, int index) = NearestCachedPoint(graphMousePos.x); (_, _, int index) = NearestCachedPoint(graphMousePos.x);
Int2 screenCachePos = graph.GraphSpaceToScreenSpace(cache[index]); Int2 screenCachePos = graph.GraphSpaceToScreenSpace(cache[index]);
double allowedDist = factor * graph.DpiFloat * 80 / 192; double allowedDist = factor * graph.ScalingFactor * 80;
Int2 dist = new(screenCachePos.x - screenMousePos.x, Int2 dist = new(screenCachePos.x - screenMousePos.x,
screenCachePos.y - screenMousePos.y); screenCachePos.y - screenMousePos.y);

View File

@ -71,7 +71,7 @@ public class EquationDifference : Graphable, ITranslatableX, IConvertEquation
Int2 diff = new(screenMousePos.x - nearestPixelPoint.x, Int2 diff = new(screenMousePos.x - nearestPixelPoint.x,
screenMousePos.y - nearestPixelPoint.y); screenMousePos.y - nearestPixelPoint.y);
int dist = (int)Math.Sqrt(diff.x * diff.x + diff.y * diff.y); int dist = (int)Math.Sqrt(diff.x * diff.x + diff.y * diff.y);
return dist < 50 * factor * graph.DpiFloat / 192; return dist < 50 * factor * graph.ScalingFactor;
} }
public override IEnumerable<IGraphPart> GetSelectionItemsToRender(in GraphForm graph, Float2 graphMousePos) public override IEnumerable<IGraphPart> GetSelectionItemsToRender(in GraphForm graph, Float2 graphMousePos)
{ {

View File

@ -54,7 +54,7 @@ public class IntegralEquation : Graphable, IIntegrable, IDerivable
const int step = 10; const int step = 10;
double epsilon = Math.Abs(graph.ScreenSpaceToGraphSpace(new Int2(0, 0)).x double epsilon = Math.Abs(graph.ScreenSpaceToGraphSpace(new Int2(0, 0)).x
- graph.ScreenSpaceToGraphSpace(new Int2(step / 2, 0)).x) / 5; - graph.ScreenSpaceToGraphSpace(new Int2(step / 2, 0)).x) / 5;
epsilon *= graph.DpiFloat / 192; epsilon *= graph.ScalingFactor;
List<IGraphPart> lines = []; List<IGraphPart> lines = [];
Int2 originLocation = graph.GraphSpaceToScreenSpace(new Float2(0, 0)); Int2 originLocation = graph.GraphSpaceToScreenSpace(new Float2(0, 0));
@ -227,7 +227,7 @@ public class IntegralEquation : Graphable, IIntegrable, IDerivable
Int2 screenPos = graph.GraphSpaceToScreenSpace(new Float2(graphMousePos.x, Int2 screenPos = graph.GraphSpaceToScreenSpace(new Float2(graphMousePos.x,
IntegralAtPoint(graphMousePos.x))); IntegralAtPoint(graphMousePos.x)));
double allowedDist = factor * graph.DpiFloat * 80 / 192; double allowedDist = factor * graph.ScalingFactor * 80;
Int2 dist = new(screenPos.x - screenMousePos.x, Int2 dist = new(screenPos.x - screenMousePos.x,
screenPos.y - screenMousePos.y); screenPos.y - screenMousePos.y);

View File

@ -111,7 +111,7 @@ public class SlopeField : Graphable
if (graphMousePos.x < Math.Min(line.a.x, line.b.x) || if (graphMousePos.x < Math.Min(line.a.x, line.b.x) ||
graphMousePos.x > Math.Max(line.a.x, line.b.x)) return false; graphMousePos.x > Math.Max(line.a.x, line.b.x)) return false;
double allowedDist = factor * graph.DpiFloat * 10 / 192; double allowedDist = factor * graph.ScalingFactor * 10;
double lineX = graphMousePos.x, double lineX = graphMousePos.x,
lineY = slope * (lineX - nearestPos.x) + nearestPos.y; lineY = slope * (lineX - nearestPos.x) + nearestPos.y;

View File

@ -100,7 +100,7 @@ public class TangentLine : Graphable, IConvertEquation, ITranslatableX
if (graphMousePos.x < Math.Min(line.a.x - 0.25, line.b.x - 0.25) || if (graphMousePos.x < Math.Min(line.a.x - 0.25, line.b.x - 0.25) ||
graphMousePos.x > Math.Max(line.a.x + 0.25, line.b.x + 0.25)) return false; graphMousePos.x > Math.Max(line.a.x + 0.25, line.b.x + 0.25)) return false;
double allowedDist = factor * graph.DpiFloat * 80 / 192; double allowedDist = factor * graph.ScalingFactor * 80;
double lineX = graphMousePos.x, double lineX = graphMousePos.x,
lineY = currentSlope.x * (lineX - Position) + currentSlope.y; lineY = currentSlope.x * (lineX - Position) + currentSlope.y;

View File

@ -24,7 +24,7 @@ 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); int rad = (int)(form.ScalingFactor * radius);
Int2 centerPix = form.GraphSpaceToScreenSpace(center); Int2 centerPix = form.GraphSpaceToScreenSpace(center);
g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - rad, g.FillEllipse(pen.Brush, new Rectangle(new Point(centerPix.x - rad,

View File

@ -74,8 +74,8 @@ public record struct GraphUiText : IGraphPart
break; break;
} }
posScreen.x += (int)(offsetPix.x * form.DpiFloat / 192); posScreen.x += (int)(offsetPix.x * form.ScalingFactor);
posScreen.y += (int)(offsetPix.y * form.DpiFloat / 192); posScreen.y += (int)(offsetPix.y * form.ScalingFactor);
if (background) if (background)
{ {