コード例 #1
0
 static void Main()
 {
     Shapes.Point pt = new Shapes.Point(10, 10);
     Console.WriteLine(pt.X);
     Console.WriteLine(pt.Y);
     pt.Move(10, 10);
     Console.WriteLine(pt.X);
     Console.WriteLine(pt.Y);
     Console.WriteLine("<%END%>");
 }
コード例 #2
0
        public void TestCopy()
        {
            ShapeFactory sf = new ShapeFactory();

            Shapes.Point p1 = sf.MakePoint(-123.45, -23.45);
            Assert.AreEqual(-123.45, p1.X, 0);
            Assert.AreEqual(-23.45, p1.Y, 0);

            Shapes.Point p2 = p1.Copy();
            Assert.AreNotSame(p1, p2);
            Assert.AreEqual(p1.X, p2.X, 0);
            Assert.AreEqual(p1.Y, p2.Y, 0);
        }
コード例 #3
0
        public void TestMoveX()
        {
            Shapes.Point p1 = new Shapes.Point(1, 2);

            p1.MoveX(10);
            Assert.AreEqual(11, p1.X, 0);
            Assert.AreEqual(2, p1.Y, 0);

            p1.MoveX(0.1234);
            Assert.AreEqual(11.1234, p1.X, 0);
            Assert.AreEqual(2, p1.Y, 0);

            p1.MoveX(-20);
            Assert.AreEqual(-8.8766, p1.X, 0);
            Assert.AreEqual(2, p1.Y, 0);

            p1.MoveX(0);
            Assert.AreEqual(-8.8766, p1.X, 0);
            Assert.AreEqual(2, p1.Y, 0);

            try
            {
                p1.MoveX(double.PositiveInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }


            try
            {
                p1.MoveX(double.NegativeInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                p1.MoveX(double.NaN);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }
        }
コード例 #4
0
        public void AddShapeToTwoComposits()
        {
            var c       = new CompositeShape();
            var co      = new CompositeShape();
            var rpoint1 = new Point(20, 20);
            var rpoint2 = new Point(30, 20);
            var rpoint3 = new Point(30, 30);
            var rpoint4 = new Point(20, 30);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            Assert.That(() => co.Add(rect), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo("This shape has already been added to a composite"));
        }
コード例 #5
0
        public void CompositeShape()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);
            points.Add(tpoint1);
            points.Add(tpoint2);
            points.Add(tpoint3);

            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());
            Assert.AreEqual(Color.Empty, composite.Fill);
            Assert.AreEqual(Color.Black, composite.Stroke);
            composite.Fill = Color.Aqua;
            Assert.AreEqual(Color.Aqua, composite.Fill);



            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
        }
コード例 #6
0
        public void ScaleTest()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(1, 1);
            var rpoint2 = new Point(2, 1);
            var rpoint3 = new Point(2, 2);
            var rpoint4 = new Point(1, 2);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(1, 0);
            var tpoint3  = new Point(0, 1);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            c.Add(triangle);
            var area = c.ComputeArea() * 2;

            c.Scale(2);
            Assert.Less(Math.Abs(c.ComputeArea() - area), .000000000000001);
        }
コード例 #7
0
        public void RemoveAllShapes()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(20, 20);
            var rpoint2 = new Point(30, 20);
            var rpoint3 = new Point(30, 30);
            var rpoint4 = new Point(20, 30);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            c.Add(triangle);

            c.RemoveAllShapes();
            Assert.AreEqual(0, c.Points.Count);
            Assert.AreEqual(0, c.thisShapesList.Count);
        }
コード例 #8
0
        public void TrianglePoints()
        {
            var point1   = new Point(0, 0);
            var point2   = new Point(3, 0);
            var point3   = new Point(0, 3);
            var triangle = new Triangle(point1, point2, point3);

            Assert.AreEqual(Color.Empty, triangle.Fill);
            triangle.Fill = Color.Aqua;
            Assert.AreEqual(Color.Aqua, triangle.Fill);
            Assert.AreEqual(Color.Black, triangle.Stroke);
            Assert.AreEqual(point1, triangle.Points[0]);
            Assert.AreEqual(point2, triangle.Points[1]);
            Assert.AreEqual(point3, triangle.Points[2]);
            Assert.AreEqual(point1, triangle.Lines[0].Point1);
            Assert.AreEqual(point2, triangle.Lines[0].Point2);
            Assert.AreEqual(point2, triangle.Lines[1].Point1);
            Assert.AreEqual(point3, triangle.Lines[1].Point2);
            Assert.AreEqual(point3, triangle.Lines[2].Point1);
            Assert.AreEqual(point1, triangle.Lines[2].Point2);
            Assert.IsFalse(triangle.CompositeShape);
        }
コード例 #9
0
        public void RemoveShapeTest()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);


            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());

            composite.RemoveShape(triangle);

            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
            Assert.AreEqual(rect.ComputeArea(), composite.ComputeArea());
        }
コード例 #10
0
        public void TestMethod1()
        {
            Bitmap image = new Bitmap("C:\\Users\\Camron Martinez\\Desktop\\Current OO Homework\\HW3\\HW3-OO\\Minimal (c-sharp)\\ShapesTests\\Usu-Logo.bmp");
            List <Shapes.Point> points = new List <Shapes.Point>();

            Shapes.Point p1 = new Shapes.Point("Null", "Null", 0, 0);
            Shapes.Point p2 = new Shapes.Point("Null", "Null", 0, 0);
            Shapes.Point p3 = new Shapes.Point("Null", "Null", 0, 0);
            Shapes.Point p4 = new Shapes.Point("Null", "Null", 0, 0);
            points.Add(p1);
            points.Add(p2);
            points.Add(p3);
            points.Add(p4);

            //EmbeddedPicture myEmbed = new EmbeddedPicture("Embed1", "AquaMarine", image, 5, 5, points);
            EmbeddedPicture myEmbed  = EmbeddedPictureFactory.getEmbeddedPicture("Embed1", "AquaMarine", image, 5, 5, points);
            EmbeddedPicture myEmbed2 = EmbeddedPictureFactory.getEmbeddedPicture("Embed1", "AquaMarine", image, 5, 5, points);
            Bitmap          image2   = new Bitmap(image, 5, 5);

            Assert.AreEqual(myEmbed.Width, 5);
            Assert.AreEqual(myEmbed.Height, 5);
            Assert.AreEqual(myEmbed.storedImage.Size, image2.Size);
            Assert.AreEqual(myEmbed.storedImage.Flags, image2.Flags);

            Assert.AreEqual(myEmbed.ComputeArea(), 25);
            myEmbed.Add(p1);
            myEmbed.Move(1, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[0].X, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[0].Y, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[1].X, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[1].Y, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[2].X, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[2].Y, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[3].X, 1);
            Assert.AreEqual(myEmbed.myEmbeddedPicturePoints[3].Y, 1);
        }
コード例 #11
0
        public void TestMove()
        {
            Shapes.Point p1 = new Shapes.Point(1, 2);

            p1.Move(10, 20);
            Assert.AreEqual(11, p1.X, 0);
            Assert.AreEqual(22, p1.Y, 0);

            p1.Move(0.222, 0.333);
            Assert.AreEqual(11.222, p1.X, 0);
            Assert.AreEqual(22.333, p1.Y, 0);

            p1.Move(-0.222, -0.333);
            Assert.AreEqual(11, p1.X, 0);
            Assert.AreEqual(22, p1.Y, 0);

            p1.Move(-20, -30);
            Assert.AreEqual(-9, p1.X, 0);
            Assert.AreEqual(-8, p1.Y, 0);

            try
            {
                p1.Move(1, double.PositiveInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }

            try
            {
                p1.Move(1, double.NegativeInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }

            try
            {
                p1.Move(1, double.NaN);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }

            try
            {
                p1.Move(double.PositiveInfinity, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                p1.Move(double.NegativeInfinity, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                p1.Move(double.NaN, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }
        }
コード例 #12
0
ファイル: TextShape.cs プロジェクト: osherz/OZ.Games.Shapes
 public TextShape(string text, Color color, Point location, Font font) : this(text, color, location)
 {
     Font = font;
 }
コード例 #13
0
ファイル: TextShape.cs プロジェクト: osherz/OZ.Games.Shapes
 public TextShape(string text, Color color, Point location) : base(color, location)
 {
     Text = text;
 }
コード例 #14
0
        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);
        }