Exemplo n.º 1
0
        public static AaBox BoundingBox(IEnumerable <Sphere> spheres)
        {
            var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (var sphere in spheres)
            {
                CodingHelper.UpdateIfLess(ref min.X, sphere.Center.X - sphere.Radius);
                CodingHelper.UpdateIfLess(ref min.Y, sphere.Center.Y - sphere.Radius);
                CodingHelper.UpdateIfLess(ref min.Z, sphere.Center.Z - sphere.Radius);
                CodingHelper.UpdateIfGreater(ref max.X, sphere.Center.X + sphere.Radius);
                CodingHelper.UpdateIfGreater(ref max.Y, sphere.Center.Y + sphere.Radius);
                CodingHelper.UpdateIfGreater(ref max.Z, sphere.Center.Z + sphere.Radius);
            }
            var halfSizeVec = (max - min) / 2;

            if (halfSizeVec.X < 0)
            {
                throw new ArgumentException("'spheres' parameter cannot be empty.");
            }
            return(new AaBox
            {
                Center = (min + max) / 2,
                HalfSize = new Size3(halfSizeVec)
            });
        }
Exemplo n.º 2
0
        public static AaBox BoundingBox(IEnumerable <Vector3> points)
        {
            var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (var point in points)
            {
                CodingHelper.UpdateIfLess(ref min.X, point.X);
                CodingHelper.UpdateIfLess(ref min.Y, point.Y);
                CodingHelper.UpdateIfLess(ref min.Z, point.Z);
                CodingHelper.UpdateIfGreater(ref max.X, point.X);
                CodingHelper.UpdateIfGreater(ref max.Y, point.Y);
                CodingHelper.UpdateIfGreater(ref max.Z, point.Z);
            }
            var halfSizeVec = (max - min) / 2;

            if (halfSizeVec.X < 0)
            {
                throw new ArgumentException("'points' parameter cannot be empty.");
            }
            return(new AaBox
            {
                Center = (min + max) / 2,
                HalfSize = new Size3(halfSizeVec)
            });
        }
Exemplo n.º 3
0
        public static AaRectangle2 BoundingRect(IEnumerable <AaRectangle2> rects)
        {
            var minX = float.MaxValue;
            var minY = float.MaxValue;
            var maxX = float.MinValue;
            var maxY = float.MinValue;

            foreach (var rect in rects)
            {
                CodingHelper.UpdateIfLess(ref minX, rect.MinX);
                CodingHelper.UpdateIfLess(ref minY, rect.MinY);
                CodingHelper.UpdateIfGreater(ref maxX, rect.MaxX);
                CodingHelper.UpdateIfGreater(ref maxY, rect.MaxY);
            }

            return(minX != float.MaxValue ? FromBounds(minX, maxX, minY, maxY) : new AaRectangle2());
        }
Exemplo n.º 4
0
        public static AaRectangle2 BoundingRect(IEnumerable <Vector2> points)
        {
            var minX = float.MaxValue;
            var minY = float.MaxValue;
            var maxX = float.MinValue;
            var maxY = float.MinValue;

            foreach (var point in points)
            {
                CodingHelper.UpdateIfLess(ref minX, point.X);
                CodingHelper.UpdateIfLess(ref minY, point.Y);
                CodingHelper.UpdateIfGreater(ref maxX, point.X);
                CodingHelper.UpdateIfGreater(ref maxY, point.Y);
            }

            return(minX != float.MaxValue ? FromBounds(minX, maxX, minY, maxY) : new AaRectangle2());
        }