Example #1
0
        /// <summary>
        /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.HitTest (ref BoundingRect, bool)"/>
        /// </summary>
        /// <param name="Rect"></param>
        /// <param name="IncludeControlPoints"></param>
        /// <returns></returns>
        public override bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints)
        {
            ClipRect clr = new ClipRect(ref Rect);

            if (clr.ArcHitTest(center, radius, 0, new GeoPoint2D(center.x + radius, center.y), new GeoPoint2D(center.x, center.y + radius)))
            {
                return(true);
            }
            if (clr.ArcHitTest(center, radius, 1, new GeoPoint2D(center.x, center.y + radius), new GeoPoint2D(center.x - radius, center.y)))
            {
                return(true);
            }
            if (clr.ArcHitTest(center, radius, 2, new GeoPoint2D(center.x - radius, center.y), new GeoPoint2D(center.x, center.y - radius)))
            {
                return(true);
            }
            if (clr.ArcHitTest(center, radius, 3, new GeoPoint2D(center.x, center.y - radius), new GeoPoint2D(center.x + radius, center.y)))
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.HitTest (ref BoundingRect, bool)"/>
        /// </summary>
        /// <param name="Rect"></param>
        /// <param name="IncludeControlPoints"></param>
        /// <returns></returns>
        public override bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints)
        {
            if (sweep < 0)
            {   // 19.8.15: bin nicht sicher, ob das mit negativem sweep auch geht, deshalb hier umdrehen
                return((new Arc2D(Center, Radius, start + sweep, -sweep)).HitTest(ref Rect, IncludeControlPoints));
            }
            ClipRect clr = new ClipRect(ref Rect);

            int StartQuadrant = start.Quadrant;
            int EndQuadrant   = (start + sweep).Quadrant;
            int numQuads;

            if (sweep < 0.0)
            {
                numQuads = StartQuadrant - EndQuadrant;
            }
            else
            {
                numQuads = EndQuadrant - StartQuadrant;
            }
            if (numQuads < 0)
            {
                numQuads += 4;
            }
            // siehe bei GetExtent, die folgende Abfrage war falsch!
            // if (Math.Abs(sweep) > 2 * Math.PI / 3) numQuads = 4; // mehr als 270°
            if (EndQuadrant == StartQuadrant)
            {   // wenns mehr als halbrum geht, dann ganzrum
                if (Math.Abs(sweep) > Math.PI)
                {
                    numQuads = 4;
                }
            }
            BoundingRect res = BoundingRect.EmptyBoundingRect;
            int          q   = StartQuadrant;

            // im Folgenden die ganz überschrittenen Quadranten betrachten, also ganze Viertelbögen
            for (int i = 1; i < numQuads; ++i) // [hier war < numQuads, es muss aber <= heißen, sonst funktionierts nicht immer]<- das ist falsch, es muss < sein,
            {                                  // ganze Viertelbögen betrachten
                // q startet mit dem StartQuadranten, also zuerst quadranten weiterschalten
                if (sweep < 0.0)
                {
                    q -= 1;
                }
                else
                {
                    q += 1;
                }
                if (q < 0)
                {
                    q += 4;
                }
                if (q > 3)
                {
                    q -= 4;
                }
                switch (q) // Achse zur Rechten betrachten
                {
                case 0:
                    if (clr.ArcHitTest(Center, Radius, 0, new GeoPoint2D(Center.x + Radius, Center.y), new GeoPoint2D(Center.x, Center.y + Radius)))
                    {
                        return(true);
                    }
                    break;

                case 1:
                    if (clr.ArcHitTest(Center, Radius, 1, new GeoPoint2D(Center.x, Center.y + Radius), new GeoPoint2D(Center.x - Radius, Center.y)))
                    {
                        return(true);
                    }
                    break;

                case 2:
                    if (clr.ArcHitTest(Center, Radius, 2, new GeoPoint2D(Center.x - Radius, Center.y), new GeoPoint2D(Center.x, Center.y - Radius)))
                    {
                        return(true);
                    }
                    break;

                case 3:
                    if (clr.ArcHitTest(Center, Radius, 3, new GeoPoint2D(Center.x, Center.y - Radius), new GeoPoint2D(Center.x + Radius, Center.y)))
                    {
                        return(true);
                    }
                    break;
                }
            }
            if (numQuads == 0)
            {   // Start und Ende im selben Quadranten
                // nur das Bogenstück selbst betrachten
                if (sweep > 0.0)
                {
                    if (clr.ArcHitTest(Center, Radius, StartQuadrant % 4, StartPoint, EndPoint))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (clr.ArcHitTest(Center, Radius, StartQuadrant % 4, EndPoint, StartPoint))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                // Start und Ende in verschiedenen Quadranten
                // zwei Abschnitte betrachten
                if (sweep > 0.0)
                {
                    GeoPoint2D p1;
                    switch (StartQuadrant) // Achse zur Rechten betrachten
                    {
                    default:
                    case 0:
                        p1 = new GeoPoint2D(Center.x, Center.y + Radius);
                        break;

                    case 1:
                        p1 = new GeoPoint2D(Center.x - Radius, Center.y);
                        break;

                    case 2:
                        p1 = new GeoPoint2D(Center.x, Center.y - Radius);
                        break;

                    case 3:
                        p1 = new GeoPoint2D(Center.x + Radius, Center.y);
                        break;
                    }
                    if (clr.ArcHitTest(Center, Radius, StartQuadrant % 4, StartPoint, p1))
                    {
                        return(true);
                    }
                    switch (EndQuadrant) // Achse zur Rechten betrachten
                    {
                    default:
                    case 1:
                        p1 = new GeoPoint2D(Center.x, Center.y + Radius);
                        break;

                    case 2:
                        p1 = new GeoPoint2D(Center.x - Radius, Center.y);
                        break;

                    case 3:
                        p1 = new GeoPoint2D(Center.x, Center.y - Radius);
                        break;

                    case 0:
                        p1 = new GeoPoint2D(Center.x + Radius, Center.y);
                        break;
                    }
                    if (clr.ArcHitTest(Center, Radius, EndQuadrant % 4, p1, EndPoint))
                    {
                        return(true);
                    }
                }
                else
                {
                    GeoPoint2D p1;
                    switch (StartQuadrant) // Achse zur Rechten betrachten
                    {
                    default:
                    case 1:
                        p1 = new GeoPoint2D(Center.x, Center.y + Radius);
                        break;

                    case 2:
                        p1 = new GeoPoint2D(Center.x - Radius, Center.y);
                        break;

                    case 3:
                        p1 = new GeoPoint2D(Center.x, Center.y - Radius);
                        break;

                    case 0:
                        p1 = new GeoPoint2D(Center.x + Radius, Center.y);
                        break;
                    }
                    if (clr.ArcHitTest(Center, Radius, StartQuadrant % 4, p1, StartPoint))
                    {
                        return(true);
                    }
                    switch (EndQuadrant) // Achse zur Rechten betrachten
                    {
                    default:
                    case 0:
                        p1 = new GeoPoint2D(Center.x, Center.y + Radius);
                        break;

                    case 1:
                        p1 = new GeoPoint2D(Center.x - Radius, Center.y);
                        break;

                    case 2:
                        p1 = new GeoPoint2D(Center.x, Center.y - Radius);
                        break;

                    case 3:
                        p1 = new GeoPoint2D(Center.x + Radius, Center.y);
                        break;
                    }
                    if (clr.ArcHitTest(Center, Radius, EndQuadrant % 4, EndPoint, p1))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }