Nez.RectangleExt.fromMinMaxPoints C# (CSharp) Méthode

fromMinMaxPoints() public static méthode

creates a Rectangle given min/max points (top-left, bottom-right points)
public static fromMinMaxPoints ( Point min, Point max ) : Rectangle
min Point Minimum.
max Point Max.
Résultat Microsoft.Xna.Framework.Rectangle
		public static Rectangle fromMinMaxPoints( Point min, Point max )
		{
			return new Rectangle( min.X, min.Y, max.X - min.X, max.Y - min.Y );
		}

Usage Example

Exemple #1
0
        /// <summary>
        /// given the points of a polygon calculates the bounds
        /// </summary>
        /// <returns>The from polygon points.</returns>
        /// <param name="points">Points.</param>
        public static Rectangle boundsFromPolygonPoints(Vector2[] points)
        {
            // we need to find the min/max x/y values
            var minX = float.PositiveInfinity;
            var minY = float.PositiveInfinity;
            var maxX = float.NegativeInfinity;
            var maxY = float.NegativeInfinity;

            for (var i = 0; i < points.Length; i++)
            {
                var pt = points[i];

                if (pt.X < minX)
                {
                    minX = pt.X;
                }
                if (pt.X > maxX)
                {
                    maxX = pt.X;
                }

                if (pt.Y < minY)
                {
                    minY = pt.Y;
                }
                if (pt.Y > maxY)
                {
                    maxY = pt.Y;
                }
            }

            return(RectangleExt.fromMinMaxPoints(new Point((int)minX, (int)minY), new Point((int)maxX, (int)maxY)));
        }