Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cubicBezier"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestCubicBezier(XCubicBezier cubicBezier, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(cubicBezier.Point1, threshold, dx, dy).Contains(v))
            {
                return(cubicBezier.Point1);
            }

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

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

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

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

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

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

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

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

            if (RectangleBounds.GetArcBounds(arc, dx, dy).Contains(v))
            {
                return(arc);
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestPoint(XPoint point, Vector2 v, double threshold, double dx, double dy)
        {
            if (RectangleBounds.GetPointBounds(point, threshold, dx, dy).Contains(v))
            {
                return(point);
            }

            return(null);
        }
        /// <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="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);
        }