Beispiel #1
0
 /// <summary>
 ///     Constructor for the Shape3D class.
 /// </summary>
 /// <param name="shapeType">The ShapeType of the 3D shape.</param>
 /// <param name="baseShape">The Shape2D on which the 3D shape is built.</param>
 /// <param name="height">The height of the 3D shape.</param>
 protected Shape3D(ShapeType shapeType, Shape2D baseShape, double height)
     : base(shapeType)
 {
     _baseShape = baseShape;
     Height     = height;
 }
Beispiel #2
0
        /// <summary>
        /// Returns an Array of sorted Shapes based on argument list.
        /// </summary>
        /// <param name="get3D">True if the returned Shapes should be 3D shapes.</param>
        /// <param name="numberOfShapes">Number of Shapes to include in the returned Array.</param>
        /// <returns>An Array of sorted Shapes.</returns>
        private static Shape[] GetShapes(bool get3D, int numberOfShapes)
        {
            Random random = new Random();

            ShapeType[] shapeTypes3D = { ShapeType.Cuboid, ShapeType.Cylinder, ShapeType.Sphere };
            ShapeType[] shapeTypes2D = { ShapeType.Ellipse, ShapeType.Rectangle };


            Shape2D[] shapes2D = new Shape2D[numberOfShapes];
            Shape3D[] shapes3D = new Shape3D[numberOfShapes];

            for (int i = 0; i < numberOfShapes; i++)
            {
                double w = random.NextDouble() * 100 + 0.1;
                double l = random.NextDouble() * 100 + 0.1;
                double h = random.NextDouble() * 100 + 0.1;

                Shape2D shape2D = null;
                Shape3D shape3D = null;

                if (get3D)
                {
                    ShapeType shapeType = shapeTypes3D[random.Next(shapeTypes3D.Length)];
                    switch (shapeType)
                    {
                    case ShapeType.Cylinder:
                        shape3D = new Cylinder(w, l, h);
                        break;

                    case ShapeType.Cuboid:
                        shape3D = new Cuboid(w, l, h);
                        break;

                    case ShapeType.Sphere:
                        shape3D = new Sphere(w);
                        break;
                    }
                    shapes3D[i] = shape3D;
                }
                else
                {
                    ShapeType shapeType = shapeTypes2D[random.Next(shapeTypes2D.Length)];
                    switch (shapeType)
                    {
                    case ShapeType.Rectangle:
                        shape2D = new Rectangle(w, l);
                        break;

                    case ShapeType.Ellipse:
                        shape2D = new Ellipse(w, l);
                        break;
                    }
                    shapes2D[i] = shape2D;
                }
            }

            Shape[] shapes = new Shape[numberOfShapes];

            if (get3D)
            {
                shapes = shapes3D
                         .OrderBy(shape => shape.ShapeType.ToString())
                         .ThenByDescending(shape => shape.Volume)
                         .ToArray();
            }
            else
            {
                shapes = shapes2D
                         .OrderBy(shape => shape.ShapeType.ToString())
                         .ThenByDescending(shape => shape.Area)
                         .ToArray();;
            }

            return(shapes);
        }