Nez.Portable/Utils/Extensions/RectangleExt.cs
/// <summary>
/// given the points of a polygon calculates the bounds
/// </summary>
/// <returns>The from polygon points.</returns>
/// <param name="points">Points.</param>
given the points of a polygon calculates the bounds
given the points of a polygon calculates the bounds
public static Rectangle boundsFromPolygonPoints(Vector2[] points)
        {
            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));
        }
public static Rectangle boundsFromPolygonPoints ( Vector2 [ ] points ) { 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 ) ) ; }
given the points of a polygon calculates the bounds
given the points of a polygon calculates the bounds
// we need to find the min/max x/y values
The from polygon points.
The from polygon points .
points
Vector2[]
None