/// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestPoint(XPoint point, Rect2 rect, ISet <BaseShape> selected, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(point, threshold, dx, dy).IntersectsWith(rect))
            {
                if (selected != null)
                {
                    selected.Add(point);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ellipse"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestEllipse(XEllipse ellipse, Rect2 rect, ISet <BaseShape> selected, double dx, double dy)
        {
            if (RectangleBounds.GetEllipseBounds(ellipse, dx, dy).IntersectsWith(rect))
            {
                if (selected != null)
                {
                    selected.Add(ellipse);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestText(XText text, Rect2 rect, ISet <BaseShape> selected, double dx, double dy)
        {
            if (RectangleBounds.GetTextBounds(text, dx, dy).IntersectsWith(rect))
            {
                if (selected != null)
                {
                    selected.Add(text);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arc"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestArc(XArc arc, Rect2 rect, ISet <BaseShape> selected, double dx, double dy)
        {
            if (RectangleBounds.GetArcBounds(arc, dx, dy).IntersectsWith(rect))
            {
                if (selected != null)
                {
                    selected.Add(arc);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="rect"></param>
        /// <param name="selected"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestLine(XLine line, Rect2 rect, ISet <BaseShape> selected, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(line.Start, threshold, dx, dy).IntersectsWith(rect) ||
                RectangleBounds.GetPointBounds(line.End, threshold, dx, dy).IntersectsWith(rect) ||
                MathHelpers.LineIntersectsWithRect(rect, new Point2(line.Start.X, line.Start.Y), new Point2(line.End.X, line.End.Y)))
            {
                if (selected != null)
                {
                    selected.Add(line);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestRectangle(XRectangle rectangle, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(rectangle.TopLeft, threshold, dx, dy).Contains(v))
            {
                return(rectangle.TopLeft);
            }

            if (RectangleBounds.GetPointBounds(rectangle.BottomRight, threshold, dx, dy).Contains(v))
            {
                return(rectangle.BottomRight);
            }

            if (RectangleBounds.GetRectangleBounds(rectangle, dx, dy).Contains(v))
            {
                return(rectangle);
            }

            return(null);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestLine(XLine line, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(line.Start, threshold, dx, dy).Contains(v))
            {
                return(line.Start);
            }

            if (RectangleBounds.GetPointBounds(line.End, threshold, dx, dy).Contains(v))
            {
                return(line.End);
            }

            if (LineBounds.Contains(line, v, threshold, dx, dy))
            {
                return(line);
            }

            return(null);
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="group"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestGroup(XGroup group, Vector2 v, double threshold, double dx, double dy)
        {
            foreach (var connector in group.Connectors.Reverse())
            {
                if (RectangleBounds.GetPointBounds(connector, threshold, dx, dy).Contains(v))
                {
                    return(connector);
                }
            }

            var result = HitTest(group.Shapes.Reverse(), v, threshold, dx, dy);

            if (result != null)
            {
                return(group);
            }

            return(null);
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestText(XText text, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(text.TopLeft, threshold, dx, dy).Contains(v))
            {
                return(text.TopLeft);
            }

            if (RectangleBounds.GetPointBounds(text.BottomRight, threshold, dx, dy).Contains(v))
            {
                return(text.BottomRight);
            }

            if (RectangleBounds.GetTextBounds(text, dx, dy).Contains(v))
            {
                return(text);
            }

            return(null);
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestPath(XPath path, Vector2 v, double threshold, double dx, double dy)
        {
            if (path.Geometry != null)
            {
                var points = path.GetPoints().ToImmutableArray();
                foreach (var point in points)
                {
                    if (RectangleBounds.GetPointBounds(point, threshold, dx, dy).Contains(v))
                    {
                        return(point);
                    }
                }

                if (ConvexHullBounds.Contains(points, v, dx, dy))
                {
                    return(path);
                }
            }

            return(null);
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="quadraticBezier"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestQuadraticBezier(XQuadraticBezier quadraticBezier, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(quadraticBezier.Point1, threshold, dx, dy).Contains(v))
            {
                return(quadraticBezier.Point1);
            }

            if (RectangleBounds.GetPointBounds(quadraticBezier.Point2, threshold, dx, dy).Contains(v))
            {
                return(quadraticBezier.Point2);
            }

            if (RectangleBounds.GetPointBounds(quadraticBezier.Point3, threshold, dx, dy).Contains(v))
            {
                return(quadraticBezier.Point3);
            }

            if (ConvexHullBounds.Contains(quadraticBezier.GetPoints().ToImmutableArray(), v, dx, dy))
            {
                return(quadraticBezier);
            }

            return(null);
        }