// Method to calculate shape surface public double CalculateSurface(GeometricShape shape) { double result = 0; if (shape.ShapeName == Circle) { result = Math.Round(Math.PI * Math.Pow(shape.Radius, 2), 2); return(result); } if (shape.ShapeName == Square) { result = Math.Pow(shape.Length, 2); return(result); } if (shape.ShapeName == Triangle) { if (shape.Length != 0 && shape.Width != 0) { result = Math.Round((shape.Length * shape.Width) / 2, 2); return(result); } } return(result); }
// Methode to calculate shape circumference public double CalculateCircumference(GeometricShape shape) { double result = 0; if (shape.ShapeName == Circle) { result = Math.Round(2 * shape.Radius * Math.PI, 2); return(result); } if (shape.ShapeName == Square) { result = 4 * shape.Length; return(result); } if (shape.ShapeName == Triangle) { if (shape.Length != 0 && shape.Width != 0) { result = Math.Round(shape.Length + shape.Width + shape.Height, 2); return(result); } } return(result); }
static void Main() { Circle circle = new Circle(); GeometricShape shape = circle; DrawShape(shape); DrawShape(circle); }
public static float CalculatePerimeter(GeometricShape shape) { float perimeter = 0; if (shape.Points.Length < 2) { Console.WriteLine("GeometricShape does not have enough points (at least 2)"); return(0); } for (int i = 0; i < shape.Points.Length; i++) { if ((i + 1) != shape.Points.Length) { float a = shape.Points[i].x - shape.Points[i + 1].x; float b = shape.Points[i].y - shape.Points[i + 1].y; if (a < 0) { a = -a; } if (b < 0) { b = -b; } float sqrtC = (a * a) + (b * b); perimeter += MathF.Sqrt(sqrtC); } if (((i + 1) == shape.Points.Length) && shape.Points.Length > 2) { float a = shape.Points[i].x - shape.Points[0].x; float b = shape.Points[i].y - shape.Points[0].y; if (a < 0) { a = -a; } if (b < 0) { b = -b; } float sqrtC = (a * a) + (b * b); perimeter += MathF.Sqrt(sqrtC); } } Console.WriteLine($"{shape.ShapeType} Perimeter = {perimeter}"); return(perimeter); }
public void TestResumenListaConUnCuadrado() { var cuadrados = new List <GeometricShape> { new Square(5) }; var resumen = GeometricShape.Print(cuadrados, Language.Es); Assert.AreEqual("<h1>Reporte de Formas</h1>1 Cuadrado | Area 25 | Perimetro 20 <br/>TOTAL:<br/>1 Formas Perimetro 20 Area 25", resumen); }
public void TestResumenListaConMasCuadrados() { var cuadrados = new List <GeometricShape> { new Square(5), new Square(1), new Square(3) }; var resumen = GeometricShape.Print(cuadrados, Language.En); Assert.AreEqual("<h1>Shapes report</h1>3 Squares | Area 35 | Perimeter 36 <br/>TOTAL:<br/>3 Shapes Perimeter 36 Area 35", resumen); }
public void TestResumenListaConTrapecioEnCastellano() { var formas = new List <GeometricShape> { new IsoscelesTrapezium(6.71m, 3, 9) }; var resumen = GeometricShape.Print(formas, Language.Es); Assert.AreEqual( "<h1>Reporte de Formas</h1>1 Trapecio | Area 36,01 | Perimetro 25,42 <br/>TOTAL:<br/>1 Formas Perimetro 25,42 Area 36,01", resumen); }
// Method to calculate 3th side of triangle public double CalculateSideTriangle(GeometricShape shape) { double result = 0; if (shape.ShapeName == Triangle) { if (shape.Length != 0 && shape.Width != 0) { result = Math.Round(Math.Sqrt((Math.Pow(shape.Length, 2) + Math.Pow(shape.Width, 2))), 2); } } return(result); }
static void Main() { Rectangle rectangle = new Rectangle(); Circle circle = new Circle(); Drawing drawing = new Drawing(); drawing.Add(rectangle); drawing.Add(circle); for (int i = 0; i < drawing.Count; ++i) { GeometricShape shape = drawing[i]; shape.Draw(); } }
public void TestResumenListaConMasTipos() { var formas = new List <GeometricShape> { new Square(5), new Circle(3), new EquilatereTriangle(4), new Square(2), new EquilatereTriangle(9), new Circle(2.75m), new EquilatereTriangle(4.2m) }; var resumen = GeometricShape.Print(formas, Language.En); Assert.AreEqual( "<h1>Shapes report</h1>2 Squares | Area 29 | Perimeter 28 <br/>2 Circles | Area 13,01 | Perimeter 18,06 <br/>3 Triangles | Area 49,64 | Perimeter 51,6 <br/>TOTAL:<br/>7 Shapes Perimeter 97,66 Area 91,65", resumen); }
public void TestResumenListaConMasTiposEnCastellano() { var formas = new List <GeometricShape> { new Square(5), new Circle(3), new EquilatereTriangle(4), new Square(2), new EquilatereTriangle(9), new Circle(2.75m), new EquilatereTriangle(4.2m) }; var resumen = GeometricShape.Print(formas, Language.Es); Assert.AreEqual( "<h1>Reporte de Formas</h1>2 Cuadrados | Area 29 | Perimetro 28 <br/>2 Círculos | Area 13,01 | Perimetro 18,06 <br/>3 Triángulos | Area 49,64 | Perimetro 51,6 <br/>TOTAL:<br/>7 Formas Perimetro 97,66 Area 91,65", resumen); }
public void TestResumenListaConMasTiposEnItaliano() { var formas = new List <GeometricShape> { new Square(5), new Circle(3), new EquilatereTriangle(4), new Square(2), new EquilatereTriangle(9), new Circle(2.75m), new EquilatereTriangle(4.2m) }; var resumen = GeometricShape.Print(formas, Language.It); Assert.AreEqual( "<h1>Rapporto forma</h1>2 Quadrato | Area 29 | Perimetro 28 <br/>2 Cerchi | Area 13,01 | Perimetro 18,06 <br/>3 Triangoli | Area 49,64 | Perimetro 51,6 <br/>TOTALE:<br/>7 Forme Perimetro 97,66 Area 91,65", resumen); }
public void Dispose() { if (ArrayIds == null) { throw new InvalidOperationException("Already disposed."); } var gl = XEngineContext.Graphics; gl.DeleteBuffers(BufferIds.Length, BufferIds); gl.DeleteVertexArrays(ArrayIds.Length, ArrayIds); ArrayIds = null; BufferIds = null; _shape = null; shared = 0u; KeepAlive = false; Disposed = true; }
public string PrintCount(GeometricShape shape) { switch (shape.TypeE) { case EGeometricShapes.Circle: return(shape.Count + " " + (shape.Count == 1 ? "Kreis" : "Kreise")); case EGeometricShapes.EquilateralTriangle: return(shape.Count + " " + (shape.Count == 1 ? "Gleichseitiges Dreieck" : "Gleichseitiges Dreiecke")); case EGeometricShapes.Square: return(shape.Count + " " + (shape.Count == 1 ? "Quadrat" : "Quadrate")); case EGeometricShapes.Trapeze: return(shape.Count + " " + (shape.Count == 1 ? "Trapezoide" : "Trapezoides")); case EGeometricShapes.Rectangle: return(shape.Count + " " + (shape.Count == 1 ? "Rechteck" : "Rechteckes")); default: return(""); } }
static GeometricShape[] generateShapes(int numShapes, int minHeight, int maxHeight, int minWidth, int maxWidth) { GeometricShape[] shapes = new GeometricShape[numShapes]; Random rando = new Random(); int width, height, shapeType; for (int i = 0; i < shapes.Length; i++) { GeometricShape newShape; width = rando.Next(minWidth, maxWidth); height = rando.Next(minHeight, maxHeight); shapeType = rando.Next(0, 3); if (shapeType == 0) { newShape = new Triangle(height, width); } else if (shapeType == 1) { newShape = new Rectangle(height, width); } else if (shapeType == 2) { newShape = new Square(height, width); } else if (shapeType == 3) { newShape = new Square(height); } else { newShape = new Rectangle(0, 0); } shapes[i] = newShape; } return(shapes); }
private AimTemplateTreeGeometricShapeNode.GeometricShapes GeometricShapesFromXsdGeometricShapeValue(GeometricShape geometricShapeValue) { var geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point; switch (geometricShapeValue) { case GeometricShape.Point: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point; break; case GeometricShape.Polyline: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polyline; break; case GeometricShape.MultiPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.MultiPoint; break; case GeometricShape.Circle: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Circle; break; case GeometricShape.Ellipse: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipse; break; case GeometricShape.Item3DPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point3D; break; case GeometricShape.Item3DPolygon: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polygon3D; break; case GeometricShape.Item3DPolyline: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polyline3D; break; case GeometricShape.Item3DEllipse: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipse3D; break; case GeometricShape.Item3DEllipsoid: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipsoid3D; break; case GeometricShape.Item3DMultiPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.MultiPoint3D; break; } return geometricShape; }
private AimTemplateTreeGeometricShapeNode.GeometricShapes GeometricShapesFromXsdGeometricShapeValue(GeometricShape geometricShapeValue) { var geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point; switch (geometricShapeValue) { case GeometricShape.Point: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point; break; case GeometricShape.Polyline: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polyline; break; case GeometricShape.MultiPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.MultiPoint; break; case GeometricShape.Circle: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Circle; break; case GeometricShape.Ellipse: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipse; break; case GeometricShape.Item3DPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Point3D; break; case GeometricShape.Item3DPolygon: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polygon3D; break; case GeometricShape.Item3DPolyline: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Polyline3D; break; case GeometricShape.Item3DEllipse: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipse3D; break; case GeometricShape.Item3DEllipsoid: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.Ellipsoid3D; break; case GeometricShape.Item3DMultiPoint: geometricShape = AimTemplateTreeGeometricShapeNode.GeometricShapes.MultiPoint3D; break; } return(geometricShape); }
public string PrintPerimeter(GeometricShape shape) { return($"Umfang: {shape.Perimeter:#.##} <br/>"); }
public void Add( GeometricShape shape ) { shapes.Add( shape ); }
public SelectedShapeInformationMessage(GeometricShape shapeInfo) { ShapeInfo = shapeInfo; }
public void Add(GeometricShape shape) { shapes.Add(shape); }
private static void DrawShape(GeometricShape shape) { shape.Draw(); }
public GeometricShapeObjectAdapter(GeometricShape adaptee) { this.adaptee = adaptee; }
public void TestResumenListaVacia() { Assert.AreEqual("<h1>Lista vacía de formas!</h1>", GeometricShape.Print(new List <GeometricShape>(), Language.Es)); }
public string PrintArea(GeometricShape shape) { return($"Bereich: {shape.Area:#.##}"); }
public void TestResumenListaVaciaFormasEnIngles() { Assert.AreEqual("<h1>Empty list of shapes!</h1>", GeometricShape.Print(new List <GeometricShape>(), Language.En)); }