//Dictionary<double, double> zz = new Dictionary<double, double>(); //private double aaa; //private double bbb; //private double aaaY; //private double bbbY; private bool TryGetPointAt(IOperation operation, double screenX, out int value) { value = -1; var x = FunctionCalc.GetXFromScreenX(screenX); var result = FunctionCalc.GetYFromX(operation, x); if (double.IsNaN(result) || double.IsInfinity(result)) { return(false); } result = FunctionCalc.GetScreenYFromY(result); //if (result > Height) // result = Height; //if (result < -1) // result = -1; result = MinMax(result, -1, Height); value = (int)result; //if (value >= 0 && value < Height) { return(true); } //return false; }
private void DrawCoordinateSystem(Graphics graphics) { const int borderSpace = 10; var pen = new Pen(Color.Blue); var brush = new SolidBrush(Color.Blue); var font = new Form().Font; // vertical line var lineX = MinMax( (int)FunctionCalc.GetScreenXFromX(0), borderSpace * 2, Width - borderSpace * 2); graphics.DrawLines(pen, GetLineWithArrow(lineX, borderSpace, lineX, Height - borderSpace)); foreach (var y in GetLabelPoints(FunctionCalc.Scale.Y, FunctionCalc.GetYFromScreenY(Height - borderSpace), borderSpace, FunctionCalc.GetScreenYFromY)) { graphics.DrawLine(pen, lineX - 2, (int)y, lineX + 2, (int)y); var value = (float)FunctionCalc.GetYFromScreenY(y); if (Math.Abs(value) > 1e-12) { graphics.DrawString(value.ToString(CultureInfo.InvariantCulture), font, brush, lineX + 5, (int)y - 4); } } // horizontal line var lineY = MinMax( (int)FunctionCalc.GetScreenYFromY(0), borderSpace * 2, Height - borderSpace * 2); graphics.DrawLines(pen, GetLineWithArrow(borderSpace, lineY, Width - borderSpace, lineY)); foreach (var x in GetLabelPoints(FunctionCalc.Scale.X, FunctionCalc.GetXFromScreenX(borderSpace), Width - borderSpace, FunctionCalc.GetScreenXFromX)) { graphics.DrawLine(pen, (int)x, lineY - 2, (int)x, lineY + 2); var value = (float)FunctionCalc.GetXFromScreenX(x); if (Math.Abs(value) > 1e-12) { graphics.DrawString(value.ToString(CultureInfo.InvariantCulture), font, brush, (int)x - 4, lineY + 5); } else { if (Math.Abs(value) > 0) { } } } }