public void DrawViewLine(ViewLines viewlines) { double slope; double intercept; switch (viewlines) { case ViewLines.origin: if (y - mainWindow.viewPoint.Y == 0) slope = 0; else if (x - mainWindow.viewPoint.X == 0) slope = -1 * Math.Sign(y - mainWindow.viewPoint.Y) * 10000; else //Calculate y slope slope = (y - mainWindow.viewPoint.Y) / (x - mainWindow.viewPoint.X); //Generate line startLine = new Line(); startLine.X1 = x; startLine.Y1 = y; //Start point intercept = startLine.Y1 - startLine.X1 * slope; if (x > mainWindow.viewPoint.X) startLine.X2 = mainWindow.WindowBottomRight.X; else startLine.X2 = mainWindow.WindowTopLeft.X; startLine.Y2 = slope * startLine.X2 + intercept; // y = mx + b ololol //Check if the y value is outside the window bounds. if it is, set y value to window bounds and calculate x from it instead. if (startLine.Y2 > mainWindow.WindowBottomRight.Y) { startLine.Y2 = mainWindow.WindowBottomRight.Y; startLine.X2 = (startLine.Y2 - intercept) / slope; } else if (startLine.Y2 < mainWindow.WindowTopLeft.Y) { startLine.Y2 = mainWindow.WindowTopLeft.Y; startLine.X2 = (startLine.Y2 - intercept) / slope; } break; case ViewLines.endpoint: if (next.y - mainWindow.viewPoint.Y == 0) slope = 0; else if (next.x - mainWindow.viewPoint.X == 0) slope = -1 * Math.Sign(next.y - mainWindow.viewPoint.Y) * 1000000; else //Calculate y slope slope = (next.y - mainWindow.viewPoint.Y) / (next.x - mainWindow.viewPoint.X); //Generate line endLine = new Line(); endLine.X1 = next.x; endLine.Y1 = next.y; intercept = endLine.Y1 - endLine.X1 * slope; if (next.x > mainWindow.viewPoint.X) endLine.X2 = mainWindow.WindowBottomRight.X; else endLine.X2 = mainWindow.WindowTopLeft.X; endLine.Y2 = slope * endLine.X2 + intercept; //Check if the y value is outside the window bounds. if it is, set y value to window bounds and calculate x from it instead. if (endLine.Y2 > mainWindow.WindowBottomRight.Y) { endLine.Y2 = mainWindow.WindowBottomRight.Y; endLine.X2 = (endLine.Y2 - intercept) / slope; } else if (endLine.Y2 < mainWindow.WindowTopLeft.Y) { endLine.Y2 = mainWindow.WindowTopLeft.Y; endLine.X2 = (endLine.Y2 - intercept) / slope; } break; case ViewLines.both: DrawViewLine(ViewLines.origin); DrawViewLine(ViewLines.endpoint); break; } }
public void DrawViewLine(ViewLines viewlines) { double slope; double intercept; switch (viewlines) { case ViewLines.origin: if (y - mainWindow.viewPoint.Y == 0) { slope = 0; } else if (x - mainWindow.viewPoint.X == 0) { slope = -1 * Math.Sign(y - mainWindow.viewPoint.Y) * 10000; } else //Calculate y slope { slope = (y - mainWindow.viewPoint.Y) / (x - mainWindow.viewPoint.X); } //Generate line startLine = new Line(); startLine.X1 = x; startLine.Y1 = y; //Start point intercept = startLine.Y1 - startLine.X1 * slope; if (x > mainWindow.viewPoint.X) { startLine.X2 = mainWindow.WindowBottomRight.X; } else { startLine.X2 = mainWindow.WindowTopLeft.X; } startLine.Y2 = slope * startLine.X2 + intercept; // y = mx + b ololol //Check if the y value is outside the window bounds. if it is, set y value to window bounds and calculate x from it instead. if (startLine.Y2 > mainWindow.WindowBottomRight.Y) { startLine.Y2 = mainWindow.WindowBottomRight.Y; startLine.X2 = (startLine.Y2 - intercept) / slope; } else if (startLine.Y2 < mainWindow.WindowTopLeft.Y) { startLine.Y2 = mainWindow.WindowTopLeft.Y; startLine.X2 = (startLine.Y2 - intercept) / slope; } break; case ViewLines.endpoint: if (next.y - mainWindow.viewPoint.Y == 0) { slope = 0; } else if (next.x - mainWindow.viewPoint.X == 0) { slope = -1 * Math.Sign(next.y - mainWindow.viewPoint.Y) * 1000000; } else //Calculate y slope { slope = (next.y - mainWindow.viewPoint.Y) / (next.x - mainWindow.viewPoint.X); } //Generate line endLine = new Line(); endLine.X1 = next.x; endLine.Y1 = next.y; intercept = endLine.Y1 - endLine.X1 * slope; if (next.x > mainWindow.viewPoint.X) { endLine.X2 = mainWindow.WindowBottomRight.X; } else { endLine.X2 = mainWindow.WindowTopLeft.X; } endLine.Y2 = slope * endLine.X2 + intercept; //Check if the y value is outside the window bounds. if it is, set y value to window bounds and calculate x from it instead. if (endLine.Y2 > mainWindow.WindowBottomRight.Y) { endLine.Y2 = mainWindow.WindowBottomRight.Y; endLine.X2 = (endLine.Y2 - intercept) / slope; } else if (endLine.Y2 < mainWindow.WindowTopLeft.Y) { endLine.Y2 = mainWindow.WindowTopLeft.Y; endLine.X2 = (endLine.Y2 - intercept) / slope; } break; case ViewLines.both: DrawViewLine(ViewLines.origin); DrawViewLine(ViewLines.endpoint); break; } }