public static dynamic[] RandomizeObjects(int type, int n, double maximum, double minimum) { dynamic[] objects = new dynamic[n]; if (type == 0) { for (int i = 0; i < n; i++) { Random rnd = new Random(); int index = rnd.Next(2); switch ((ShapeType)index) { case ShapeType.Ellipse: objects[i] = new Ellipse(rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum); break; case ShapeType.Rectangle: objects[i] = new Rectangle(rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum); break; } } } else if (type == 1) { for (int i = 0; i < n; i++) { Random rnd = new Random(); int index = rnd.Next(2, 5); switch ((ShapeType)index) { case ShapeType.Sphere: objects[i] = new Sphere(rnd.NextDouble() * (maximum - minimum) + minimum); break; case ShapeType.Cuboid: objects[i] = new Cuboid(rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum); break; case ShapeType.Cylinder: objects[i] = new Cylinder(rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum, rnd.NextDouble() * (maximum - minimum) + minimum); break; } } } return(objects); }
/// <summary> /// Returns a list with shapes. /// </summary> private static List <string> ShapeLists(bool is3D) { RandomClass random = new RandomClass(); List <Shape2D> shapes2d = new List <Shape2D>(); List <Shape3D> shapes3d = new List <Shape3D>(); List <string> shapes = new List <string>(); Shape2D shape2d; Shape3D shape3d; ShapeType shapeType; int min = 1; int max = 50; Random r = new Random(); int randomNumber = r.Next(5, 16); for (int i = 0; i < randomNumber; i++) { shapeType = (ShapeType)random.RandomShape(is3D); if (shapeType == ShapeType.Cuboid) { shape3d = new Cuboid(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max)); shapes3d.Add(shape3d); } else if (shapeType == ShapeType.Cylinder) { shape3d = new Cylinder(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max)); shapes3d.Add(shape3d); } else if (shapeType == ShapeType.Sphere) { shape3d = new Sphere(random.RandomNumberShapes(min, max)); shapes3d.Add(shape3d); } else if (shapeType == ShapeType.Ellipse) { shape2d = new Ellipse(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max)); shapes2d.Add(shape2d); } else if (shapeType == ShapeType.Rectangle) { shape2d = new Rectangle(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max)); shapes2d.Add(shape2d); } } if (is3D) { shapes3d = shapes3d.OrderBy(x => x.ShapeType) .ThenBy(x => x.Volume) .ToList(); foreach (var i in shapes3d) { shapes.Add(i.ToString("R")); } } else { shapes2d = shapes2d.OrderBy(x => x.ShapeType) .ThenBy(x => x.Area) .ToList(); foreach (var i in shapes2d) { shapes.Add(i.ToString("R")); } } return(shapes); }