Accord.Imaging.Drawing.CheckEndPoint C# (CSharp) Method

CheckEndPoint() private static method

private static CheckEndPoint ( int width, int height, IntPoint start, IntPoint &end ) : void
width int
height int
start IntPoint
end IntPoint
return void
        private static void CheckEndPoint(int width, int height, IntPoint start, ref IntPoint end)
        {
            if (end.X >= width)
            {
                int newEndX = width - 1;

                double c = (double)(newEndX - start.X) / (end.X - start.X);

                end.Y = (int)(start.Y + c * (end.Y - start.Y));
                end.X = newEndX;
            }

            if (end.Y >= height)
            {
                int newEndY = height - 1;

                double c = (double)(newEndY - start.Y) / (end.Y - start.Y);

                end.X = (int)(start.X + c * (end.X - start.X));
                end.Y = newEndY;
            }

            if (end.X < 0)
            {
                double c = (double)(0 - start.X) / (end.X - start.X);

                end.Y = (int)(start.Y + c * (end.Y - start.Y));
                end.X = 0;
            }

            if (end.Y < 0)
            {
                double c = (double)(0 - start.Y) / (end.Y - start.Y);

                end.X = (int)(start.X + c * (end.X - start.X));
                end.Y = 0;
            }
        }
    }