Пример #1
0
        /// <summary>
        /// Find the intersection points of an arc and the infinite line p1-p2
        /// that is closest to point p1.
        /// </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 a   = Bounds;
            float      num = PenWidth / 2f;

            GoObject.InflateRect(ref a, num, num);
            return(GoEllipse.NearestIntersectionOnArc(a, p1, p2, out result, StartAngle, SweepAngle));
        }
Пример #2
0
        /// <summary>
        /// Create and initialize a <see cref="T:Northwoods.Go.GoShape" />.
        /// </summary>
        /// <param name="p">the <see cref="T:Northwoods.Go.GoPort" /> created for this node by <see cref="M:Northwoods.Go.GoBasicNode.CreatePort" /></param>
        /// <returns>
        /// By default this returns a <see cref="T:Northwoods.Go.GoEllipse" /> that is somewhat larger than the port <paramref name="p" />.
        /// </returns>
        /// <remarks>
        /// By default the ellipse uses a white brush--set the <see cref="P:Northwoods.Go.GoBasicNode.Pen" />
        /// and <see cref="P:Northwoods.Go.GoBasicNode.Brush" /> properties to change the appearance.
        /// The shape is not itself selectable, resizable, or reshapable.
        /// </remarks>
        /// <example>
        /// If you override this method, you may want the definition to do
        /// some of the things that the standard definition does:
        /// <code>
        ///  protected virtual GoShape CreateShape(GoPort p) {
        ///    // create the bigger circle/ellipse around and behind the port
        ///    GoShape e = new GoEllipse();
        ///    SizeF psize = p.Size;
        ///    e.Size = new SizeF(psize.Width + 2*7, psize.Height + 2*7);
        ///    e.Selectable = false;
        ///    e.Resizable = false;
        ///    e.Reshapable = false;
        ///    e.Brush = GoShape.Brushes_White;
        ///    return e;
        ///  }
        /// </code>
        /// </example>
        protected virtual GoShape CreateShape(GoPort p)
        {
            GoEllipse goEllipse = new GoEllipse();
            SizeF     size      = p.Size;

            goEllipse.Size       = new SizeF(size.Width + 2f * DefaultShapeMargin.Width, size.Height + 2f * DefaultShapeMargin.Height);
            goEllipse.Selectable = false;
            goEllipse.Resizable  = false;
            goEllipse.Reshapable = false;
            goEllipse.Brush      = GoShape.Brushes_White;
            return(goEllipse);
        }
Пример #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);
        }
Пример #4
0
        /// <summary>
        /// Find the intersection points of a pie and the infinite line p1-p2
        /// that is closest to point p1.
        /// </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 a   = Bounds;
            float      num = PenWidth / 2f;

            GoObject.InflateRect(ref a, num, num);
            float num2       = a.Width / 2f;
            float num3       = a.Height / 2f;
            float num4       = a.X + num2;
            float num5       = a.Y + num3;
            float num6       = p1.X - num4;
            float num7       = p1.Y - num5;
            float startAngle = StartAngle;
            float sweepAngle = SweepAngle;
            float num8       = startAngle + sweepAngle;

            if (num8 > 360f)
            {
                num8 -= 360f;
            }
            bool  result2 = false;
            float num9    = 1E+21f;

            result = default(PointF);
            if (-0.01f < num6 && num6 < 0.01f)
            {
                num6 = 0.01f;
            }
            if (-0.01f < num7 && num7 < 0.01f)
            {
                num7 = 0.01f;
            }
            PointF result3;

            if (sweepAngle >= 360f)
            {
                if (GoEllipse.NearestIntersectionOnEllipse(a, p1, p2, out result3))
                {
                    float num10 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                    if (num10 < num9)
                    {
                        result2 = true;
                        result  = result3;
                        num9    = num10;
                    }
                }
            }
            else if (sweepAngle + startAngle > 360f)
            {
                if (GoEllipse.NearestIntersectionOnArc(a, p1, p2, out result3, startAngle, 360f - startAngle))
                {
                    float num11 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                    if (num11 < num9)
                    {
                        result2 = true;
                        result  = result3;
                        num9    = num11;
                    }
                }
                if (GoEllipse.NearestIntersectionOnArc(a, p1, p2, out result3, 0f, sweepAngle - (360f - startAngle)))
                {
                    float num12 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                    if (num12 < num9)
                    {
                        result2 = true;
                        result  = result3;
                        num9    = num12;
                    }
                }
            }
            else if (GoEllipse.NearestIntersectionOnArc(a, p1, p2, out result3, startAngle, sweepAngle))
            {
                float num13 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                if (num13 < num9)
                {
                    result2 = true;
                    result  = result3;
                    num9    = num13;
                }
            }
            PointF pointAtAngle = GetPointAtAngle(startAngle);

            if (GoStroke.NearestIntersectionOnLine(new PointF(num4, num5), pointAtAngle, p1, p2, out result3))
            {
                float num14 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                if (num14 < num9)
                {
                    result2 = true;
                    result  = result3;
                    num9    = num14;
                }
            }
            PointF pointAtAngle2 = GetPointAtAngle(num8);

            if (GoStroke.NearestIntersectionOnLine(new PointF(num4, num5), pointAtAngle2, p1, p2, out result3))
            {
                float num15 = (p1.X - result3.X) * (p1.X - result3.X) + (p1.Y - result3.Y) * (p1.Y - result3.Y);
                if (num15 < num9)
                {
                    result2 = true;
                    result  = result3;
                    num9    = num15;
                }
            }
            return(result2);
        }