示例#1
0
        public override IDrawableObject GetObjectAt(float x, float y, TransformParams t, ref float dist)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            float     width  = t.Transform(mWidth);
            float     height = t.Transform(mHeight);
            Vector2DF pos    = t.Transform(new Vector2DF(mX - mWidth / 2f, mY - mHeight / 2f));

            return(VisualizationUtils.PointInsideRect(x, y, new RectangleF(pos.X, pos.Y, width, height)) ? this : null);
        }
示例#2
0
        private static bool LineIntersectRectangle(Vector2DF pt1, Vector2DF pt2, RectangleF rect, ref Vector2DF isectPt1, ref Vector2DF isectPt2)
        {
            // note that this does not work properly in the case when the line lies on one of the rectangle's vertical edges
            // this is not a problem for the partial rendering of lines since the rectangles are inflated prior to determining
            // intersections
            float y = 0, x = 0;
            ArrayList <Vector2DF> points = new ArrayList <Vector2DF>(2);

            if (LineIntersectVertical(pt1, pt2, rect.X, ref y))
            {
                if (y > rect.Y && y < rect.Y + rect.Height)
                {
                    points.Add(new Vector2DF(rect.X, y));
                }
            }
            if (LineIntersectVertical(pt1, pt2, rect.X + rect.Width, ref y))
            {
                if (y > rect.Y && y < rect.Y + rect.Height)
                {
                    points.Add(new Vector2DF(rect.X + rect.Width, y));
                }
            }
            if (LineIntersectHorizontal(pt1, pt2, rect.Y, ref x))
            {
                if (x > rect.X && x < rect.X + rect.Width)
                {
                    points.Add(new Vector2DF(x, rect.Y));
                }
            }
            if (LineIntersectHorizontal(pt1, pt2, rect.Y + rect.Height, ref x))
            {
                if (x > rect.X && x < rect.X + rect.Width)
                {
                    points.Add(new Vector2DF(x, rect.Y + rect.Height));
                }
            }
            if (points.Count == 2)
            {
                isectPt1 = points[0];
                isectPt2 = points[1];
                return(true);
            }
            else if (points.Count == 1)
            {
                isectPt1 = points[0];
                isectPt2 = VisualizationUtils.PointInsideRect(pt1.X, pt1.Y, rect) ? pt1 : pt2;
                return(true);
            }
            else if (VisualizationUtils.PointInsideRect(pt1.X, pt1.Y, rect) && VisualizationUtils.PointInsideRect(pt2.X, pt2.Y, rect))
            {
                isectPt1 = pt1;
                isectPt2 = pt2;
                return(true);
            }
            return(false);
        }
示例#3
0
        public static bool IsObjectAt(Image image, float x, float y, float ptX, float ptY, TransformParams t)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            // TODO: other exceptions
            float     width  = t.Transform(image.Width);
            float     height = t.Transform(image.Height);
            Vector2DF pos    = t.Transform(new Vector2DF(x, y));

            return(VisualizationUtils.PointInsideRect(ptX, ptY, new RectangleF(pos.X, pos.Y, width, height)));
        }
示例#4
0
文件: Line.cs 项目: mgrcar/Detextive
        private static bool LineIntersectRectangle(Vector2D pt1, Vector2D pt2, RectangleF rect, ref Vector2D isect_pt1, ref Vector2D isect_pt2)
        {
            float y = 0, x = 0;
            ArrayList <Vector2D> points = new ArrayList <Vector2D>(2);

            if (LineIntersectVertical(pt1, pt2, rect.X, ref y))
            {
                if (y > rect.Y && y < rect.Y + rect.Height)
                {
                    points.Add(new Vector2D(rect.X, y));
                }
            }
            if (LineIntersectVertical(pt1, pt2, rect.X + rect.Width, ref y))
            {
                if (y > rect.Y && y < rect.Y + rect.Height)
                {
                    points.Add(new Vector2D(rect.X + rect.Width, y));
                }
            }
            if (LineIntersectHorizontal(pt1, pt2, rect.Y, ref x))
            {
                if (x > rect.X && x < rect.X + rect.Width)
                {
                    points.Add(new Vector2D(x, rect.Y));
                }
            }
            if (LineIntersectHorizontal(pt1, pt2, rect.Y + rect.Height, ref x))
            {
                if (x > rect.X && x < rect.X + rect.Width)
                {
                    points.Add(new Vector2D(x, rect.Y + rect.Height));
                }
            }
            if (points.Count == 2)
            {
                isect_pt1 = points[0];
                isect_pt2 = points[1];
                return(true);
            }
            else if (points.Count == 1)
            {
                isect_pt1 = points[0];
                isect_pt2 = VisualizationUtils.PointInsideRect(pt1.X, pt1.Y, rect) ? pt1 : pt2;
                return(true);
            }
            else if (VisualizationUtils.PointInsideRect(pt1.X, pt1.Y, rect) && VisualizationUtils.PointInsideRect(pt2.X, pt2.Y, rect))
            {
                isect_pt1 = pt1;
                isect_pt2 = pt2;
                return(true);
            }
            return(false);
        }