private void toolStripButtonEllipse_Click(object sender, EventArgs e) { CurrentFactory = new EllipseShapeFactory(); Factory current = new EllipseFactory(pnlMain); CurrentDrawman = current.FactoryMethod(); }
public void TestScale() { ShapeFactory sf = new EllipseFactory(); Ellipse myEllipse = (Ellipse)sf.Create2dShape(); myEllipse.Center.X = 1; myEllipse.Center.Y = 2; myEllipse.VertRadius = 5; myEllipse.HorizRadius = 6; Assert.AreEqual(1, myEllipse.Center.X, 0); Assert.AreEqual(2, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); myEllipse.Scale(3); Assert.AreEqual(1, myEllipse.Center.X, 0); Assert.AreEqual(2, myEllipse.Center.Y, 0); Assert.AreEqual(15, myEllipse.VertRadius, 0); Assert.AreEqual(18, myEllipse.HorizRadius, 0); myEllipse.Scale(0.2); Assert.AreEqual(1, myEllipse.Center.X, 0); Assert.AreEqual(2, myEllipse.Center.Y, 0); Assert.AreEqual(3, myEllipse.VertRadius, 0); Assert.AreEqual(3.6, myEllipse.HorizRadius, 0); try { myEllipse.Scale(double.PositiveInfinity); Assert.Fail("Expected exception not thrown"); } catch (Exception) { // ignore } try { myEllipse.Scale(double.NegativeInfinity); Assert.Fail("Expected exception not thrown"); } catch (Exception) { // ignore } try { myEllipse.Scale(double.NaN); Assert.Fail("Expected exception not thrown"); } catch (Exception) { // ignore } }
private void btnCreate_Click(object sender, EventArgs e) { if (cmboShapeType.SelectedItem is null) { errorMessage("Please select a type of shape"); } else if (ValidateInfo()) { ShapeFactory factory = null; switch (cmboShapeType.SelectedItem.ToString()) { case "Circle": Shapes.Point CirclePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new CircleFactory(CirclePoint, Int32.Parse(txtRadius1.Text)); break; case "Ellipse": Shapes.Point EllipsePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new EllipseFactory(EllipsePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text)); break; case "Rectangle": Shapes.Point RectanglePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new RectangleFactory(RectanglePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text)); break; case "Square": Shapes.Point SquarePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new SquareFactory(SquarePoint, Int32.Parse(txtRadius1.Text)); break; case "Triangle": Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text)); Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text)); factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3); break; case "Composite Image": factory = new CompositeImageFactory(filepath); break; case "Embedded Pic": Shapes.Point EmbeddedPoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new EmbeddedPicFactory(EmbeddedPoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text), filepath); break; } Shape shape = factory.GetShape(); Console.WriteLine(shape.ShapeType); shapeToDraw = shape; this.Close(); } }
public void TestValidConstruction() { ShapeFactory sf = new EllipseFactory(); Ellipse ellipse = (Ellipse)sf.Create2dShape(); ellipse.Center.X = 1; ellipse.Center.Y = 3; ellipse.VertRadius = 2.5; ellipse.HorizRadius = 3.5; Assert.AreEqual(1, ellipse.Center.X); Assert.AreEqual(3, ellipse.Center.Y); Assert.AreEqual(2.5, ellipse.VertRadius); Assert.AreEqual(3.5, ellipse.HorizRadius); }
public Shape getShape(int initialX, int initialY, int secondaryX, int secondaryY, bool add) { if (designation == shapeDesignation.EMBEDDED_PIC) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { string file = openFileDialog1.FileName; Console.WriteLine(openFileDialog1.FileName); embeddedPicFilepath = openFileDialog1.FileName; } } ShapeFactory factory = null; switch (designation) { case shapeDesignation.CIRCLE: Shapes.Point CirclePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY)); factory = new CircleFactory(CirclePoint, Math.Abs(secondaryX - initialX)); break; case shapeDesignation.ELLIPSE: Shapes.Point EllipsePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY)); factory = new EllipseFactory(EllipsePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX)); break; case shapeDesignation.RECTANGLE: Shapes.Point RectanglePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY)); factory = new RectangleFactory(RectanglePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX)); break; case shapeDesignation.SQUARE: Shapes.Point SquarePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY)); factory = new SquareFactory(SquarePoint, Math.Abs(secondaryX - initialX)); break; case shapeDesignation.TRIANGLE: //TODO: Figure out rectangular triangle drawing //Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); //Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text)); //Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text)); //factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3); break; case shapeDesignation.EMBEDDED_PIC: Shapes.Point EmbeddedPoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY)); factory = new EmbeddedPicFactory(EmbeddedPoint, Math.Abs(secondaryX - initialX), Math.Abs(secondaryY - initialY), embeddedPicFilepath); break; case shapeDesignation.LINE: //TODO: Create Line in shapes break; default: return(null); } Shape shape = factory.GetShape(); if (add) { addToList(shape); } return(shape); }
public void TestMove() { ShapeFactory sf = new EllipseFactory(); Ellipse myEllipse = (Ellipse)sf.Create2dShape(); myEllipse.Center.X = 1; myEllipse.Center.Y = 2; myEllipse.VertRadius = 5; myEllipse.HorizRadius = 6; Assert.AreEqual(1, myEllipse.Center.X, 0); Assert.AreEqual(2, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); myEllipse.Move(3, 4); Assert.AreEqual(4, myEllipse.Center.X, 0); Assert.AreEqual(6, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); myEllipse.Move(0.123, 0.456); Assert.AreEqual(4.123, myEllipse.Center.X, 0); Assert.AreEqual(6.456, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); myEllipse.Move(-0.123, -0.456); Assert.AreEqual(4, myEllipse.Center.X, 0); Assert.AreEqual(6, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); myEllipse.Move(-12, -26); Assert.AreEqual(-8, myEllipse.Center.X, 0); Assert.AreEqual(-20, myEllipse.Center.Y, 0); Assert.AreEqual(5, myEllipse.VertRadius, 0); Assert.AreEqual(6, myEllipse.HorizRadius, 0); try { myEllipse.Move(double.PositiveInfinity, 1); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-x value", e.Message); } try { myEllipse.Move(double.NegativeInfinity, 1); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-x value", e.Message); } try { myEllipse.Move(double.NaN, 1); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-x value", e.Message); } try { myEllipse.Move(1, double.PositiveInfinity); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-y value", e.Message); } try { myEllipse.Move(1, double.PositiveInfinity); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-y value", e.Message); } try { myEllipse.Move(1, double.NaN); Assert.Fail("Expected exception not thrown"); } catch (ShapeException e) { Assert.AreEqual("Invalid delta-y value", e.Message); } }
public void HandleEvent() { ellipseFactory = new EllipseFactory(); Canvas.CurFigureFactory = ellipseFactory; }