Пример #1
0
        public static bool IsObjectAt(float ptX, float ptY, TransformParams t, float x1, float y1, float x2, float y2, ref float dist)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            Vector2DF pt1 = t.Transform(new Vector2DF(x1, y1));
            Vector2DF pt2 = t.Transform(new Vector2DF(x2, y2));

            return(VisualizationUtils.TestLineHit(new Vector2DF(ptX, ptY), pt1, pt2, mHitDist, ref dist));
        }
Пример #2
0
        public static bool IsObjectAt(float pt_x, float pt_y, TransformParams tr, float x1, float y1, float x2, float y2, ref float dist)
        {
            Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
            Vector2D pt1 = tr.Transform(new Vector2D(x1, y1));
            Vector2D pt2 = tr.Transform(new Vector2D(x2, y2));

            return(VisualizationUtils.TestLineHit(new Vector2D(pt_x, pt_y), pt1, pt2, m_hit_dist, ref dist));
        }
Пример #3
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);
        }
Пример #4
0
 public Label(string label, Font font, float x, float y)
 {
     // TODO: exceptions
     mLabel = label;
     mFont  = font;
     mX     = x;
     mY     = y;
     VisualizationUtils.MeasureString(label, font, out mWidth, out mHeight);
 }
Пример #5
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);
        }
Пример #6
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)));
        }
Пример #7
0
        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);
        }
Пример #8
0
        public static BoundingArea GetBoundingArea(float x1, float y1, float x2, float y2)
        {
#if !SIMPLE_BOUNDING_AREA
            if (x1 == x2 || y1 == y2)
            {
                return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)));
            }
            float     delta   = Math.Abs((x2 - x1) / (y2 - y1));
            float     stepMax = (float)Math.Sqrt(mMaxBoxArea / delta + delta * mMaxBoxArea);
            Vector2DF line    = new Vector2DF(x1, y1, x2, y2);
            float     lineLen = line.GetLength();
            if (stepMax >= lineLen)
            {
                return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)));
            }
            BoundingArea boundingArea = new BoundingArea();
            int          steps        = (int)Math.Ceiling(lineLen / stepMax);
            Vector2DF    stepVec      = line;
            stepVec.SetLength(lineLen / (float)steps);
            Vector2DF pt1 = new Vector2DF(x1, y1);
            Vector2DF pt2;
            for (int i = 0; i < steps - 1; i++)
            {
                pt2 = pt1 + stepVec;
                boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y));
                pt1 = pt2;
            }
            pt2 = new Vector2DF(x2, y2);
            boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y));
            return(boundingArea);
#else
            BoundingArea boundingArea = new BoundingArea();
            boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(x1, y1, x2, y2));
            return(boundingArea);
#endif
        }