static void Main(string[] args)
 {
     Rectangle r = new Rectangle(20,10,10,5);
     r.getArea();
     r.getPerimeter();
     Console.WriteLine("Area=" + r.area);
     Console.WriteLine("Perimerer=" + r.perimeter);
     Console.Read();
 }
示例#2
0
        /// <summary>
        /// Rotate some rectangle figure
        /// </summary>
        /// <param name="rectangle">An instance of rectangle.</param>
        /// <param name="angle">The angle in radians.</param>
        /// <returns>Returns an rotated rectangle</returns>
        public static Rectangle Rotate(Rectangle rectangle, double angle)
        {
            double sinus = Math.Abs(Math.Sin(angle));
            double cosinus = Math.Abs(Math.Cos(angle));

            return new Rectangle(
                cosinus * rectangle.Width + sinus * rectangle.Height,
                sinus * rectangle.Width + cosinus * rectangle.Height);
        }
        public void Contains()
        {
            Rect rec = new Rect(new Point(), new Point(3, 5));

            //Assert.AreEquals point within the Rect
            Assert.AreEqual(rec.contains(new Point(1, 1)), true);
            //Assert.AreEquals point outside of the Rect
            Assert.AreEqual(rec.contains(new Point(10, 10)), false);
        }
        public void GetCenter()
        {
            Rect  rec    = new Rect(new Point(), new Point(3, 5));
            Point center = rec.getCenter();

            //Correct center?
            Assert.AreEqual(center.getX(), 1.5);
            Assert.AreEqual(center.getY(), 2.5);
        }
示例#5
0
 static void Main(string[] args)
 {
     new UIHelper().header();
                 new UIHelper().exerciseHeader(2, "Создать класс с именем Rectangle");
                 Rectangle rect = new Rectangle(10,20);
                 rect.AreaCalculator();
                 rect.PerimeterCalculator();
                 Console.WriteLine("Area = " + rect.Area);
                 Console.WriteLine("Perimeter = " + rect.Perimeter);
                 Console.ReadKey();
 }
        public void GetUpperLeftVertex()
        {
            //p1 will be upperLeft
            Point p1  = new Point(0, 10);
            Point p2  = new Point(5, 5);
            Rect  rec = new Rect(p1, p2);

            //Is p1 same as upperLeft?
            Assert.AreEqual(rec.getUpperLeftVertex().getX(), p1.getX());
            Assert.AreEqual(rec.getUpperLeftVertex().getY(), p1.getY());
        }
示例#7
0
        static void Main()
        {
            double width = 200;
            double height = 30;
            Rectangle rectangle = new Rectangle(width, height);
            Console.WriteLine("Rectangle: {0}", rectangle);

            double angleInDegrees = 90;
            double angleInRadians = angleInDegrees * Math.PI / 180;
            Rectangle rotatedRectangle = Rectangle.Rotate(rectangle, angleInRadians);
            Console.WriteLine("Rotated rectangle: {0}", rotatedRectangle);
        }
        public void Translate()
        {
            Rect rec = new Rect(new Point(), 3, 5);

            rec.translate(5, 5);

            //Did it move upperLeft?
            Assert.AreEqual(rec.getUpperLeftVertex().getX(), 5);
            Assert.AreEqual(rec.getUpperLeftVertex().getY(), 10);

            //Did it move lowerRight?
            Assert.AreEqual(rec.getWidth(), 3);
            Assert.AreEqual(rec.getHeight(), 5);
        }
        public void Constructor3Args()
        {
            //Less testing seems to be needed for this,
            //as the width and height cannot be smaller than the initial point

            //(P1 x0, ) test
            //Same as rec.upperLeft = (0, 5);
            //rec.lowerRight = (5, 0);
            Rect test1 = new Rect(new Point(0, 0), 5, 3);

            //UpperLeft Assert.AreEqual
            Assert.AreEqual(test1.getUpperLeftVertex().getX(), 0);
            Assert.AreEqual(test1.getUpperLeftVertex().getY(), 3);
            //Width and Height Assert.AreEqual for lowerRight
            Assert.AreEqual(test1.getWidth(), 5);
            Assert.AreEqual(test1.getHeight(), 3);
        }
        public void Constructor2Args()
        {
            //Does is initalize the correct bounds of the Rect?
            //(P1 x0, P1 y10) test
            Rect test1 = new Rect(new Point(0, 10), new Point(5, 5));

            Assert.AreEqual(test1.getUpperLeftVertex().getX(), 0);
            Assert.AreEqual(test1.getUpperLeftVertex().getY(), 10);
            //Width and Height Assert.AreEqual for lowerRight boundry
            Assert.AreEqual(test1.getWidth(), 5);
            Assert.AreEqual(test1.getHeight(), 5);

            //(P1 x0, P2 y5) test
            Rect test2 = new Rect(new Point(0, 0), new Point(5, 5));

            Assert.AreEqual(test2.getUpperLeftVertex().getX(), 0);
            Assert.AreEqual(test2.getUpperLeftVertex().getY(), 5);
            //Width and Height Assert.AreEqual for lowerRight boundry
            Assert.AreEqual(test2.getWidth(), 5);
            Assert.AreEqual(test2.getHeight(), 5);

            //(P2 x5, P1 y10) test
            Rect test3 = new Rect(new Point(10, 10), new Point(5, 5));

            Assert.AreEqual(test3.getUpperLeftVertex().getX(), 5);
            Assert.AreEqual(test3.getUpperLeftVertex().getY(), 10);
            //Width and Height Assert.AreEqual for lowerRight boundry
            Assert.AreEqual(test3.getWidth(), 5);
            Assert.AreEqual(test3.getHeight(), 5);

            //(P2 x5, P2 y5) test
            Rect test4 = new Rect(new Point(10, 0), new Point(5, 5));

            Assert.AreEqual(test4.getUpperLeftVertex().getX(), 5);
            Assert.AreEqual(test4.getUpperLeftVertex().getY(), 5);
            //Width and Height Assert.AreEqual for lowerRight boundry
            Assert.AreEqual(test4.getWidth(), 5);
            Assert.AreEqual(test4.getHeight(), 5);
        }
示例#11
0
        public void AddVoucherImage(string jobIdLocation, Document pdf, AdjustmentLetter letter, IFileReader fileReader)
        {
            var secondPage = pdf.Pages.Add();

            var drn = letter.AdjustedVoucher.voucher.documentReferenceNumber;
            var fs = fileReader.LoadImage(jobIdLocation, letter.ProcessingDate, drn);

            if (fs != null)
            {
                secondPage.Resources.Images.Add(fs);

                secondPage.Contents.Add(new Operator.GSave());

                //// Create Rectangle and Matrix objects
                var rectangle = new Rectangle(ReportConstants.LowerLeftX, ReportConstants.LowerLeftY, ReportConstants.UpperRightX, ReportConstants.UpperRightY);
                var matrix = new Aspose.Pdf.DOM.Matrix(new[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });

                //// Using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
                secondPage.Contents.Add(new Operator.ConcatenateMatrix(matrix));
                var ximage = secondPage.Resources.Images[secondPage.Resources.Images.Count];

                //// Using Do operator: this operator draws image
                secondPage.Contents.Add(new Operator.Do(ximage.Name));

                //// Using GRestore operator: this operator restores graphics state
                secondPage.Contents.Add(new Operator.GRestore());
            }
            else
            {
                Log.Warning("Image not found for voucher {@voucher} to attach to letter",
                    new { jobIdentifier = letter.JobIdentifier, processingDate = letter.ProcessingDate, DRN = drn });
            }
        }