예제 #1
0
        /// <summary>
        /// The closest point of a parallelogram that intersects with a given line
        /// is the closest such point of each of its four line segments.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool GetNearestIntersectionPoint(PointF p1, PointF p2, out PointF result)
        {
            RectangleF bounds = Bounds;
            float      shift  = PenWidth / 2f;

            PointF[] points  = getPoints();
            PointF   pointF  = GoShape.ExpandPointOnEdge(points[0], bounds, shift);
            PointF   pointF2 = GoShape.ExpandPointOnEdge(points[1], bounds, shift);
            PointF   pointF3 = GoShape.ExpandPointOnEdge(points[2], bounds, shift);
            PointF   pointF4 = GoShape.ExpandPointOnEdge(points[3], bounds, shift);
            float    x       = p1.X;
            float    y       = p1.Y;
            float    num     = 1E+21f;
            PointF   pointF5 = default(PointF);

            if (GoStroke.NearestIntersectionOnLine(pointF, pointF2, p1, p2, out PointF result2))
            {
                float num2 = (result2.X - x) * (result2.X - x) + (result2.Y - y) * (result2.Y - y);
                if (num2 < num)
                {
                    num     = num2;
                    pointF5 = result2;
                }
            }
            if (GoStroke.NearestIntersectionOnLine(pointF2, pointF3, p1, p2, out result2))
            {
                float num3 = (result2.X - x) * (result2.X - x) + (result2.Y - y) * (result2.Y - y);
                if (num3 < num)
                {
                    num     = num3;
                    pointF5 = result2;
                }
            }
            if (GoStroke.NearestIntersectionOnLine(pointF3, pointF4, p1, p2, out result2))
            {
                float num4 = (result2.X - x) * (result2.X - x) + (result2.Y - y) * (result2.Y - y);
                if (num4 < num)
                {
                    num     = num4;
                    pointF5 = result2;
                }
            }
            if (GoStroke.NearestIntersectionOnLine(pointF4, pointF, p1, p2, out result2))
            {
                float num5 = (result2.X - x) * (result2.X - x) + (result2.Y - y) * (result2.Y - y);
                if (num5 < num)
                {
                    num     = num5;
                    pointF5 = result2;
                }
            }
            result = pointF5;
            return(num < 1E+21f);
        }
예제 #2
0
        /// <summary>
        /// The closest intersection point of a polygon with a line is the
        /// closest such point for each of its segments.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        /// <remarks>
        /// This currently does not always take into account any Pen width.
        /// </remarks>
        public override bool GetNearestIntersectionPoint(PointF p1, PointF p2, out PointF result)
        {
            RectangleF bounds = Bounds;
            float      num    = PenWidth / 2f;
            float      num2   = 1E+21f;
            PointF     pointF = default(PointF);

            checked
            {
                PointF result2;
                if (Style == GoPolygonStyle.Bezier)
                {
                    for (int i = 3; i < myPointsCount; i += 3)
                    {
                        PointF point  = GetPoint(i - 3);
                        PointF point2 = GetPoint(i - 2);
                        if (i + 3 >= myPointsCount)
                        {
                            i = myPointsCount - 1;
                        }
                        PointF point3 = GetPoint(i - 1);
                        PointF point4 = GetPoint(i);
                        if (GoStroke.BezierNearestIntersectionOnLine(point, point2, point3, point4, p1, p2, num, out result2))
                        {
                            float num3 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                            if (num3 < num2)
                            {
                                num2   = num3;
                                pointF = result2;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < PointsCount; j++)
                    {
                        PointF a = GoShape.ExpandPointOnEdge(GetPoint(j), bounds, num);
                        PointF b = GoShape.ExpandPointOnEdge(GetPoint((j + 1 < PointsCount) ? (j + 1) : 0), bounds, num);
                        if (GoStroke.NearestIntersectionOnLine(a, b, p1, p2, out result2))
                        {
                            float num4 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                            if (num4 < num2)
                            {
                                num2   = num4;
                                pointF = result2;
                            }
                        }
                    }
                }
                result = pointF;
                return(num2 < 1E+21f);
            }
        }
예제 #3
0
        /// <summary>
        /// The closest point of a cylinder that intersects with a given line
        /// is the closest such point of each two line segments and two ellipses.
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool GetNearestIntersectionPoint(PointF p1, PointF p2, out PointF result)
        {
            RectangleF bounds = Bounds;
            float      shift  = PenWidth / 2f;

            PointF[]   points = getPoints();
            PointF     a      = GoShape.ExpandPointOnEdge(points[0], bounds, shift);
            PointF     b      = GoShape.ExpandPointOnEdge(points[1], bounds, shift);
            PointF     a2     = GoShape.ExpandPointOnEdge(points[2], bounds, shift);
            PointF     b2     = GoShape.ExpandPointOnEdge(points[3], bounds, shift);
            float      num    = 1E+21f;
            PointF     pointF = default(PointF);
            RectangleF rect;
            RectangleF rect2;
            float      startAngle;
            float      startAngle2;

            if (Orientation == Orientation.Vertical)
            {
                rect        = new RectangleF(bounds.X, bounds.Y, bounds.Width, MinorRadius * 2f);
                rect2       = new RectangleF(bounds.X, bounds.Y + bounds.Height - MinorRadius * 2f, bounds.Width, MinorRadius * 2f);
                startAngle  = 180f;
                startAngle2 = 0f;
            }
            else
            {
                rect        = new RectangleF(bounds.X, bounds.Y, MinorRadius * 2f, bounds.Height);
                rect2       = new RectangleF(bounds.X + bounds.Width - MinorRadius * 2f, bounds.Y, MinorRadius * 2f, bounds.Height);
                startAngle  = 90f;
                startAngle2 = 270f;
            }
            if (GoEllipse.NearestIntersectionOnArc(rect, p1, p2, out PointF result2, startAngle, 180f))
            {
                float num2 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                if (num2 < num)
                {
                    num    = num2;
                    pointF = result2;
                }
            }
            if (Orientation == Orientation.Horizontal)
            {
                if (GoEllipse.NearestIntersectionOnArc(rect2, p1, p2, out result2, 270f, 90f))
                {
                    float num3 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                    if (num3 < num)
                    {
                        num    = num3;
                        pointF = result2;
                    }
                }
                if (GoEllipse.NearestIntersectionOnArc(rect2, p1, p2, out result2, 0f, 90f))
                {
                    float num4 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                    if (num4 < num)
                    {
                        num    = num4;
                        pointF = result2;
                    }
                }
            }
            else if (GoEllipse.NearestIntersectionOnArc(rect2, p1, p2, out result2, startAngle2, 180f))
            {
                float num5 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                if (num5 < num)
                {
                    num    = num5;
                    pointF = result2;
                }
            }
            if (GoStroke.NearestIntersectionOnLine(a, b, p1, p2, out result2))
            {
                float num6 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                if (num6 < num)
                {
                    num    = num6;
                    pointF = result2;
                }
            }
            if (GoStroke.NearestIntersectionOnLine(a2, b2, p1, p2, out result2))
            {
                float num7 = (result2.X - p1.X) * (result2.X - p1.X) + (result2.Y - p1.Y) * (result2.Y - p1.Y);
                if (num7 < num)
                {
                    num    = num7;
                    pointF = result2;
                }
            }
            result = pointF;
            return(num < 1E+21f);
        }