示例#1
0
        /// <summary>
        /// Creates between 5 and 20 3D shapes.
        /// </summary>
        /// <returns>An array with 5 to 20 3D shapes</returns>
        private static Shape3D[] Randomize3DShapes()
        {
            Random random    = new Random();
            int    numShapes = random.Next(5, 21);

            Shape3D[] shapes = new Shape3D[numShapes];
            for (int i = 0; i < numShapes; i++)
            {
                switch (random.Next(0, 3))
                {
                case 0:
                    shapes[i] = new Cuboid(Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0));
                    break;

                case 1:
                    shapes[i] = new Cylinder(Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0));
                    break;

                case 2:
                    shapes[i] = new Sphere(Extensions.NextDouble(random, 5.0, 100.0));
                    break;
                }
            }
            Array.Sort(shapes);
            return(shapes);
        }
        private static Shape3D[] Randomize3DShapes()
        {
            Random randomInstance  = new Random();
            int    numberOfFiguers = randomInstance.Next(5, 21);

            Shape3D[] returnArray = new Shape3D[numberOfFiguers];

            for (int i = 0; i < numberOfFiguers; i++)
            {
                int    randomShape = randomInstance.Next(3, 6);
                double height      = (randomInstance.NextDouble() * (99 - 5) + 5);
                double length      = (randomInstance.NextDouble() * (99 - 5) + 5);
                double width       = (randomInstance.NextDouble() * (99 - 5) + 5);
                switch (randomShape)
                {
                case 3:
                    returnArray[i] = new Cuboid(length, width, height);
                    break;

                case 4:
                    returnArray[i] = new Cylinder(length, width, height);
                    break;

                case 5:
                    returnArray[i] = new Sphere(length);
                    break;
                }
            }
            return(returnArray);
        }
示例#3
0
        public int CompareTo(object obj)
        {
            int     result;
            Shape3D objShape3D = obj as Shape3D;

            if (obj == null)
            {
                return(1);
            }

            if (!(obj is Shape3D))
            {
                throw new ArgumentException("parametern i CompareTo är inte av typen Shape3D");
            }
            result = Volume.CompareTo(objShape3D.Volume);
            return(result);
        }
示例#4
0
        /// <summary>
        /// Compares this shape with another object, to help sorting methods sort it.
        /// </summary>
        /// <param name="obj">Object to compare this shape with</param>
        /// <returns>
        /// 1 if this shapes area is bigger than the objects
        /// 0 if this shapes area is the same as the objects
        /// -1 if this shapes area is smaller than the objects
        /// </returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            Shape3D otherShape3D = obj as Shape3D;

            if (otherShape3D != null)
            {
                return(this.Volume.CompareTo(otherShape3D.Volume));
            }
            else
            {
                throw new FormatException();
            }
        }
示例#5
0
        /// <summary>
        /// Returns 5-20 random 3d shapes that have sides of 5-100
        /// </summary>
        public static Shape3D[] Randomize3DShapes()
        {
            int numberOfShapes = random.Next(5, 21);
            Shape3D[] shapes = new Shape3D[numberOfShapes];

            for (int i = 0; i < numberOfShapes; i++) {
                Shape3D shape;
                switch (random.Next(3, 6)) {
                    case 3:
                        shape = new Cuboid(random.NextDouble(5, 100), random.NextDouble(5, 100), random.NextDouble(5, 100));
                        break;
                    case 4:
                        shape = new Cylinder(random.NextDouble(5, 50), random.NextDouble(5, 50), random.NextDouble(5, 100));
                        break;
                    case 5:
                        shape = new Sphere(random.NextDouble(5, 50));
                        break;
                    default:
                        shape = null;
                        break;
                }
                shapes[i] = shape;
            }

            return shapes;
        }