public void Clip_and_draw_line(double from_x, double from_y, double to_x, double to_y, Color PenColor) { bool inside; // Reset if all the line segment is outside the window. // Original line coordinates double x1 = from_x; double y1 = from_y; double x2 = to_x; double y2 = to_y; inside = true; // Assume some part of the line segment is inside the window. if (from_x < 0) { inside = Clip_edge(ref from_x, ref from_y, 0, x1, y1, x2, y2, to_x >= 0); } else { if (to_x < 0) { inside = Clip_edge(ref to_x, ref to_y, 0, x2, y2, x1, y1, from_x >= 0); } } if (inside) { if (from_x > ClipWidth) { inside = Clip_edge(ref from_x, ref from_y, ClipWidth, x1, y1, x2, y2, to_x <= ClipWidth); } else { if (to_x > ClipWidth) { inside = Clip_edge(ref to_x, ref to_y, ClipWidth, x2, y2, x1, y1, from_x <= ClipWidth); } } } if (inside) { if (from_y < 0) { inside = Clip_edge(ref from_y, ref from_x, 0, y1, x1, y2, x2, to_y >= 0); } else { if (to_y < 0) { inside = Clip_edge(ref to_y, ref to_x, 0, y2, x2, y1, x1, from_y >= 0); } } } if (inside) { if (from_y > ClipHeight) { inside = Clip_edge(ref from_y, ref from_x, ClipHeight, y1, x1, y2, x2, to_y <= ClipHeight); } else { if (to_y > ClipHeight) { inside = Clip_edge(ref to_y, ref to_x, ClipHeight, y2, x2, y1, x1, from_y <= ClipHeight); } } if (inside) { DrawCanvasPen.Color = new SKColor(PenColor.R, PenColor.G, PenColor.B); DrawCanvas.DrawLine(XAxisAdjust + XAxesDirection * (int)Math.Truncate(from_x), YAxisAdjust - YAxesDirection * (int)Math.Truncate(from_y), XAxisAdjust + XAxesDirection * (int)Math.Truncate(to_x), YAxisAdjust - YAxesDirection * (int)Math.Truncate(to_y), DrawCanvasPen); } } }