Пример #1
0
        /// <summary>
        /// Returns an inflated copy of the box.
        /// </summary>
        /// <param name="box">The box to copy and inflate. This is not modified.</param>
        /// <param name="x">The amount to inflate horizontally.</param>
        /// <param name="y">The amount to inflate vertically.</param>
        /// <returns>A newly created inflated box.</returns>
        public static BoxF Inflate(BoxF box, float x, float y)
        {
            BoxF ef = box;

            ef.Inflate(x, y);
            return(ef);
        }
Пример #2
0
        /// <summary>
        /// Creates a BoxF structre with the specified center and size.
        /// </summary>
        /// <param name="cx">The center x-coordinate of the box.</param>
        /// <param name="cy">The center y-coordinate of the box.</param>
        /// <param name="width">The width of the box.</param>
        /// <param name="height">The height of the box.</param>
        /// <returns>A new box created from the coordinates.</returns>
        public static BoxF FromCenterAndSize(float cx, float cy, float width, float height)
        {
            BoxF retval = new BoxF(0, 0, width, height);

            retval.Center = new Vector2(cx, cy);
            return(retval);
        }
 public static void DrawRectangle(this SpriteBatch spriteBatch, BoxF bounds, Color color)
 {
     Initialize(spriteBatch.GraphicsDevice);
     spriteBatch.Draw(pixel, new Vector2(bounds.X, bounds.Y), null, color, 0f, Vector2.Zero, new Vector2(bounds.Width, 1f), 0, 0f);
     spriteBatch.Draw(pixel, new Vector2(bounds.X, bounds.Y + (bounds.Height - 1f)), null, color, 0f, Vector2.Zero, new Vector2(bounds.Width, 1f), 0, 0f);
     spriteBatch.Draw(pixel, new Vector2(bounds.X, bounds.Y), null, color, 0f, Vector2.Zero, new Vector2(1f, bounds.Height), 0, 0f);
     spriteBatch.Draw(pixel, new Vector2(bounds.X + (bounds.Width - 1f), bounds.Y), null, color, 0f, Vector2.Zero, new Vector2(1f, bounds.Height), 0, 0f);
 }
Пример #4
0
        /// <summary>
        /// Creates the smallest possible box that can contain both of two box that form a union.
        /// </summary>
        /// <param name="a">The first box to union.</param>
        /// <param name="b">The second box to union.</param>
        /// <returns>A box that represents the union of two boxes.</returns>
        public static BoxF Union(BoxF a, BoxF b)
        {
            float x    = Math.Min(a.X, b.X);
            float num2 = Math.Max((float)(a.X + a.Width), (float)(b.X + b.Width));
            float y    = Math.Min(a.Y, b.Y);
            float num4 = Math.Max((float)(a.Y + a.Height), (float)(b.Y + b.Height));

            return(new BoxF(x, y, num2 - x, num4 - y));
        }
Пример #5
0
        /// <summary>
        /// Replaces this BoxF structure with the intersection of itself and the specified BoxF structure.
        /// </summary>
        /// <param name="box">The box to intersect.</param>
        public void Intersect(BoxF box)
        {
            BoxF ef = Intersect(box, this);

            this.X      = ef.X;
            this.Y      = ef.Y;
            this.Width  = ef.Width;
            this.Height = ef.Height;
        }
Пример #6
0
        /// <summary>
        /// Tests whether obj is a BoxF with the same location and size of this BoxF.
        /// </summary>
        /// <param name="obj">The object to test.</param>
        /// <returns>A value indicating if the object matches this BoxF.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is BoxF))
            {
                return(false);
            }
            BoxF ef = (BoxF)obj;

            return((((ef.X == this.X) && (ef.Y == this.Y)) && (ef.Width == this.Width)) && (ef.Height == this.Height));
        }
Пример #7
0
        /// <summary>
        /// Returns a BoxF structure that represents the intersection of two boxes. If there is no intersection, an empty BoxF is returned.
        /// </summary>
        /// <param name="a">The first box to intersect.</param>
        /// <param name="b">The second box to intersect.</param>
        /// <returns>A box that represents the intersection of two boxes.</returns>
        public static BoxF Intersect(BoxF a, BoxF b)
        {
            float x    = Math.Max(a.X, b.X);
            float num2 = Math.Min((float)(a.X + a.Width), (float)(b.X + b.Width));
            float y    = Math.Max(a.Y, b.Y);
            float num4 = Math.Min((float)(a.Y + a.Height), (float)(b.Y + b.Height));

            if ((num2 >= x) && (num4 >= y))
            {
                return(new BoxF(x, y, num2 - x, num4 - y));
            }
            return(Empty);
        }
        public static BoxF GetBounds(IEnumerable <Vector2> points)
        {
            float left   = float.MaxValue;
            float top    = float.MaxValue;
            float right  = float.MinValue;
            float bottom = float.MinValue;

            foreach (Vector2 p in points)
            {
                left   = Math.Min(left, p.X);
                top    = Math.Min(top, p.Y);
                right  = Math.Max(right, p.X);
                bottom = Math.Max(bottom, p.Y);
            }
            return(BoxF.FromLTRB(left, top, right, bottom));
        }
Пример #9
0
 /// <summary>
 /// Converts the specified BoxF structure to a Box structure by rounding the BoxF values to the
 /// next higher integer values.
 /// </summary>
 /// <param name="value">The box to be converted.</param>
 /// <returns>A converted box.</returns>
 public static Box Ceiling(BoxF value)
 {
     return(new Box((int)Math.Ceiling((double)value.X), (int)Math.Ceiling((double)value.Y), (int)Math.Ceiling((double)value.Width), (int)Math.Ceiling((double)value.Height)));
 }
 public static void FillRectangle(this SpriteBatch spriteBatch, BoxF bounds, Color color)
 {
     Initialize(spriteBatch.GraphicsDevice);
     spriteBatch.Draw(pixel, bounds.Location, null, color, 0f, Vector2.Zero, bounds.Size.ToVector2(), 0, 0f);
 }
Пример #11
0
 static BoxF()
 {
     Empty = new BoxF();
 }
Пример #12
0
 /// <summary>
 /// Translates the upper-left coordinate of the box by the specified point.
 /// </summary>
 /// <param name="box">The box to adjust. This is not affected.</param>
 /// <param name="offset">The amount to translate in the x and y direction.</param>
 /// <returns>A new translated box.</returns>
 public static BoxF Offset(BoxF box, Vector2 offset)
 {
     return(new BoxF(box.Location + offset, box.Size));
 }
Пример #13
0
 /// <summary>
 /// Determines if this box intersects with another box.
 /// </summary>
 /// <param name="box">The box to test.</param>
 /// <returns>A value indicating if the two boxes intersect.</returns>
 public bool IntersectsWith(BoxF box)
 {
     return((((box.X < (this.X + this.Width)) && (this.X < (box.X + box.Width))) && (box.Y < (this.Y + this.Height))) && (this.Y < (box.Y + box.Height)));
 }
Пример #14
0
 /// <summary>
 /// Determines if the rectangular region represented by box is entirely contained within this BoxF structure.
 /// </summary>
 /// <param name="box">The box to test.</param>
 /// <returns>A value indicating if this box contains the box.</returns>
 public bool Contains(BoxF box)
 {
     return((((this.X <= box.X) && ((box.X + box.Width) <= (this.X + this.Width))) && (this.Y <= box.Y)) && ((box.Y + box.Height) <= (this.Y + this.Height)));
 }
Пример #15
0
 /// <summary>
 /// Converts the specified BoxF to a Box by truncating the BoxF values.
 /// </summary>
 /// <param name="value">The box to be converted.</param>
 /// <returns>A converted box.</returns>
 public static Box Truncate(BoxF value)
 {
     return(new Box((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height));
 }
Пример #16
0
 /// <summary>
 /// Converts the specified BoxF to a Box by rounding the BoxF values to the nearest integer values.
 /// </summary>
 /// <param name="value">The box to be converted.</param>
 /// <returns>A converted box.</returns>
 public static Box Round(BoxF value)
 {
     return(new Box((int)Math.Round((double)value.X), (int)Math.Round((double)value.Y), (int)Math.Round((double)value.Width), (int)Math.Round((double)value.Height)));
 }
Пример #17
0
 /// <summary>
 /// Translates the upper-left coordinate of the box by the specified point.
 /// </summary>
 /// <param name="box">The box to adjust. This is not affected.</param>
 /// <param name="dx">The amount to translate in the x direction.</param>
 /// <param name="dy">The amount to translate in the y direction.</param>
 /// <returns>A new translated box.</returns>
 public static BoxF Offset(BoxF box, float dx, float dy)
 {
     return(new BoxF(box.X + dx, box.Y + dy, box.Width, box.height));
 }