private bool FindIntersectingPoints(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22)
        {
            double pixelHeight;

            pixelHeight = bitmap.PixelHeight;
            if (y11 <= -pixelHeight)
            {
                y11 = -2 * pixelHeight;
            }
            if (y12 <= -pixelHeight)
            {
                y12 = -2 * pixelHeight;
            }
            if (y21 <= -pixelHeight)
            {
                y21 = -2 * pixelHeight;
            }
            if (y22 <= -pixelHeight)
            {
                y22 = -2 * pixelHeight;
            }

            if (y11 >= 2 * pixelHeight)
            {
                y11 = 4 * pixelHeight;
            }
            if (y12 >= 2 * pixelHeight)
            {
                y12 = 4 * pixelHeight;
            }
            if (y21 >= 2 * pixelHeight)
            {
                y21 = 4 * pixelHeight;
            }
            if (y22 >= 2 * pixelHeight)
            {
                y22 = 4 * pixelHeight;
            }

            intersectingPoint = new Point();

            // First  line  slope and intersect( y = mx+c )
            double m = WriteableBitmapExtensions.Slope(x11, y11, x12, y12);
            double c = double.NaN;

            if (!double.IsInfinity(m))
            {
                c = WriteableBitmapExtensions.Intersect(x12, y12, m);
            }

            // Second line slope and intersect
            double m1 = WriteableBitmapExtensions.Slope(x21, y21, x22, y22);
            double c1 = double.NaN;

            if (!double.IsInfinity(m1))
            {
                c1 = WriteableBitmapExtensions.Intersect(x21, y21, m1);
            }

            // point intersecting for both straight line.(Cross point for lines)
            double x = (c1 - c) / (m - m1);

            intersectingPoint.X = (int)x;
            intersectingPoint.Y = (int)(m * x) + c;

            return((double.IsNaN(x) || double.IsNaN(intersectingPoint.Y)) ? false : true);
        }
        private void UpdatePoints2(double xStart, double yStart, double xEnd, double yEnd, double leftThickness, double rightThickness)
        {
            GetLinePoints(xStart, yStart, xEnd, yEnd, leftThickness, rightThickness, points2);

            bool parallelLine = false;

            if (points1[0] == points1[2])
            {
                parallelLine = !(points2[0] == points2[2] && points1[0] != points2[0]);
            }
            else if (points2[0] == points2[2])
            {
                parallelLine = true;
            }
            else
            {
                // both lines are not parallel to the y-axis;
                var m1 = Math.Floor(WriteableBitmapExtensions.Slope(points1[2], points1[1], points1[0], points1[3]));
                var m2 = Math.Floor(WriteableBitmapExtensions.Slope(points2[2], points2[1], points2[0], points2[3]));
                if (m1 != m2)
                {
                    parallelLine = true;
                }
            }

            if (parallelLine)
            {
                bool line1 = FindIntersectingPoints(points1[0], points1[1], points1[2], points1[3], points2[0], points2[1], points2[2], points2[3]);
                if (line1)
                {
                    points1[2] = points2[0] = points2[8] = (int)(intersectingPoint.X);
                    points1[3] = points2[1] = points2[9] = (int)(intersectingPoint.Y);
                }
            }

            parallelLine = false;
            if (points1[4] == points1[6])
            {
                parallelLine = !(points2[4] == points2[6] && points1[4] != points2[4]);
            }
            else if (points2[4] == points2[6])
            {
                parallelLine = true;
            }
            else
            {
                var m3 = Math.Floor(WriteableBitmapExtensions.Slope(points1[6], points1[5], points1[4], points1[7]));
                var m4 = Math.Floor(WriteableBitmapExtensions.Slope(points2[6], points2[5], points2[4], points2[7]));
                if (m3 != m4)
                {
                    parallelLine = true;
                }
            }

            if (parallelLine)
            {
                bool line = FindIntersectingPoints(points1[4], points1[5], points1[6], points1[7], points2[4], points2[5], points2[6], points2[7]);
                if (line)
                {
                    points1[5] = points2[7] = (int)(intersectingPoint.Y);
                    points1[4] = points2[6] = (int)(intersectingPoint.X);
                }
            }
        }