/// <summary> /// Creates between 5 and 20 2D shapes. /// </summary> /// <returns>An array with 5 to 20 2D shapes</returns> private static Shape2D[] Randomize2DShapes() { Random random = new Random(); int numShapes = random.Next(5, 21); Shape2D[] shapes = new Shape2D[numShapes]; for (int i = 0; i < numShapes; i++) { switch (random.Next(0, 3)) { case 0: shapes[i] = new Ellipse(Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0)); break; case 1: shapes[i] = new Ellipse(Extensions.NextDouble(random, 5.0, 100.0)); break; case 2: shapes[i] = new Rectangle(Extensions.NextDouble(random, 5.0, 100.0), Extensions.NextDouble(random, 5.0, 100.0)); break; } } Array.Sort(shapes); return(shapes); }
/// <summary> /// Returns 5-20 random 2d shapes that have sides of 5-100 /// </summary> public static Shape2D[] Randomize2DShapes() { int numberOfShapes = random.Next(5, 21); Shape2D[] shapes = new Shape2D[numberOfShapes]; for (int i = 0; i < numberOfShapes; i++) { Shape2D shape; switch (random.Next(3)) { case 0: shape = new Ellipse(random.NextDouble(5, 100), random.NextDouble(5, 100)); break; case 1: shape = new Ellipse(random.NextDouble(5, 100)); break; case 2: shape = new Rectangle(random.NextDouble(5, 100), random.NextDouble(5, 100)); break; default: shape = null; break; } shapes[i] = shape; } return shapes; }
private static Shape2D[] Randomize2DShapes() { Random randomInstance = new Random(); int numberOfFiguers = randomInstance.Next(5, 21); Shape2D[] returnArray = new Shape2D[numberOfFiguers]; for (int i = 0; i < numberOfFiguers; i++) { int randomShape = randomInstance.Next(0, 3); double length = (randomInstance.NextDouble() * (99 - 5) + 5); double width = (randomInstance.NextDouble() * (99 - 5) + 5); switch (randomShape) { case 0: returnArray[i] = new Ellipse(length, width); break; case 1: returnArray[i] = new Ellipse(length); break; case 2: returnArray[i] = new Rectangle(length, width); break; } } return(returnArray); }
public int CompareTo(object obj) { int results; Shape2D objShaped2D = obj as Shape2D; if (obj == null) { return(1); } if (!(obj is Shape2D)) { throw new ArgumentException("parametern i CompareTo är inte av typen Shape2D"); } results = Area.CompareTo(objShaped2D.Area); return(results); }
/// <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); } Shape2D otherShape2D = obj as Shape2D; if (otherShape2D != null) { return(this.Area.CompareTo(otherShape2D.Area)); } else { throw new FormatException(); } }
protected Shape3D(ShapeType shapeType, Shape2D baseShape, double height) : base(shapeType) { _baseShape = baseShape; Height = height; }