Пример #1
0
        /// <summary>
        /// Compares the imput rectangles and caculates the portion of the new rctangle not included in the old.
        /// </summary>
        /// <param name="current"> The current rectangle</param>
        /// <param name="previous">The previous rectangle</param>
        /// <returns>An array of rectangles describing the difference between the input rectangles.</returns>
        /// <remarks>
        /// This funtion is a liner exclusive OR on 2 rectangles. It is catagorized by specifying the order of the
        /// rectangles in a linear fashion so that the xor'd intersection is directional. A natural XOR intersection
        /// would include the portions of both rectangles not found the intersction of the two. A Linear XOR includes
        /// only the portion of the current rectangle not found in the intersection of the two.
        /// </remarks>
        public static RectangleF[] GetRegionScans(RectangleF current, RectangleF previous)
        {
            // If the extents are equal, or one contains the other, or they're not intersecting there's nothing
            // to do. Return the current rectangle.
            if (
                !current.Equals(previous) &&
                !Contains(current, previous) &&
                !Contains(previous, current) &&
                IntersectsWith(current, previous))
            {
                // Get the horizontal rectangle, uncovered from a north or south pan
                RectangleF h = RectangleFHelper.FromLTRB(
                    current.Left,  //current.Left < previous.Left ? current.Left : previous.Left,
                    current.Top < previous.Top ? current.Top : previous.Bottom,
                    current.Right, //current.Left < previous.Left ? previous.Right : current.Right,
                    current.Top < previous.Top ? previous.Top : current.Bottom
                    );

                // Get the vertical rectangle, uncovered from an east or west pan
                RectangleF v = RectangleFHelper.FromLTRB(
                    current.Left < previous.Left ? current.Left : previous.Right,
                    current.Top < previous.Top ? previous.Top : current.Top,
                    current.Left < previous.Left ? previous.Left : current.Right,
                    current.Top < previous.Top ? current.Bottom : previous.Bottom
                    );

                // Retangles with no width or height are excluded
                if ((h.Height <= 0 || h.Width <= 0) && (v.Height <= 0 || v.Width <= 0))
                {
                    return new RectangleF[] { current }
                }
                ;

                // Retangles with no width or height are excluded
                if (h.Height <= 0 || h.Width <= 0)
                {
                    return new RectangleF[] { v }
                }
                ;
                if (v.Height <= 0 || v.Width <= 0)
                {
                    return new RectangleF[] { h }
                }
                ;

                return(new RectangleF[] { h, v });
            }

            return(new RectangleF[] { current });
        }
Пример #2
0
        /// <summary>
        /// Calculates the bounding rectangle for the supplied points.
        /// </summary>
        /// <returns></returns>
        public static RectangleF ComputeBoundingBox(PointF[] projectedPoints)
        {
            // ffs
            if (projectedPoints.Length == 0)
            {
                return(RectangleF.Empty);
            }

            // Now figure out which points represent the maximum bounds, starting
            // with the first point
            float projectedLeft   = projectedPoints[0].X;
            float projectedRight  = projectedPoints[0].X;
            float projectedTop    = projectedPoints[0].Y;
            float projectedBottom = projectedPoints[0].Y;

            // Now consider all other points
            int Limit = projectedPoints.Length;

            for (int index = 1; index < Limit; index++)
            {
                // Get the current projected point
                PointF projectedPoint = projectedPoints[index];

                // Now see if it exceeds the current bounds
                if (projectedPoint.X < projectedLeft)
                {
                    projectedLeft = projectedPoint.X;
                }
                if (projectedPoint.X > projectedRight)
                {
                    projectedRight = projectedPoint.X;
                }
                if (projectedPoint.Y < projectedTop)
                {
                    projectedTop = projectedPoint.Y;
                }
                if (projectedPoint.Y > projectedBottom)
                {
                    projectedBottom = projectedPoint.Y;
                }
            }

            // finally, return a rectangle with these bounds
#if PocketPC
            return(RectangleFHelper.FromLTRB(projectedLeft, projectedTop, projectedRight, projectedBottom));
#else
            return(RectangleF.FromLTRB(projectedLeft, projectedTop, projectedRight, projectedBottom));
#endif
        }
Пример #3
0
 public static RectangleF Inflate(RectangleF rectangle, float x, float y)
 {
     return(RectangleFHelper.FromLTRB(rectangle.X - x, rectangle.Y - y, rectangle.Right + x, rectangle.Bottom + y));
 }