コード例 #1
0
        public void TestRectangleF2DFitAndKeepAspectRatio()
        {
            double       delta     = 0.00001;
            RectangleF2D rectangle = new RectangleF2D(0, 0, 1, 1);

            PointF2D[] points = new PointF2D[] {
                new PointF2D(2, 2),
                new PointF2D(1, 1)
            };

            RectangleF2D fitted = rectangle.FitAndKeepAspectRatio(points, 0);

            Assert.AreEqual(1, fitted.Width, delta);
            Assert.AreEqual(1, fitted.Height, delta);
            Assert.AreEqual(1, fitted.BottomLeft[0], delta);
            Assert.AreEqual(1, fitted.BottomLeft[1], delta);
            Assert.AreEqual(2, fitted.TopRight[0], delta);
            Assert.AreEqual(2, fitted.TopRight[1], delta);

            // this should create the exact same rectangle as in the other tests.
            rectangle = RectangleF2D.FromBoundsAndCenter(System.Math.Sqrt(2) * 2,
                                                         System.Math.Sqrt(2) * 2, 0, 0, 45);
            fitted = rectangle.FitAndKeepAspectRatio(points, 0);
            Assert.AreEqual(System.Math.Sqrt(2), fitted.Width, delta);
            Assert.AreEqual(System.Math.Sqrt(2), fitted.Height, delta);
            Assert.AreEqual(0.5, fitted.BottomLeft[0], delta);
            Assert.AreEqual(1.5, fitted.BottomLeft[1], delta);
            Assert.AreEqual(2.5, fitted.TopRight[0], delta);
            Assert.AreEqual(1.5, fitted.TopRight[1], delta);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="OsmSharp.UI.Renderer.View2D"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="centerX">The center x.</param>
        /// <param name="centerY">The center y.</param>
        /// <param name="xInverted">When true x increases from left to right, when false otherwise.</param>
        /// <param name="yInverted">When true y increases from bottom to top, when false otherwise.</param>
        /// <param name="angleY"></param>
        public static View2D CreateFromCenterAndSize(double width, double height, double centerX, double centerY,
                                                     bool xInverted, bool yInverted, Degree angleY)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "width has to be larger and not equal to zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "height has to be larger and not equal to zero.");
            }

            return(new View2D(RectangleF2D.FromBoundsAndCenter(width, height,
                                                               centerX, centerY, angleY), xInverted, yInverted));
        }
コード例 #3
0
        public void TestRectangleF2DOuterBox()
        {
            double delta = 0.00001;
            // this should create the exact same rectangle as in the other tests.
            RectangleF2D rectangle = RectangleF2D.FromBoundsAndCenter(System.Math.Sqrt(2) * 2,
                                                                      System.Math.Sqrt(2) * 2, 3, 1, 45);

            // get the box and tests it's bounds.
            BoxF2D box = rectangle.BoundingBox;

            Assert.AreEqual(1, box.Min[0], delta);
            Assert.AreEqual(-1, box.Min[1], delta);
            Assert.AreEqual(5, box.Max[0], delta);
            Assert.AreEqual(3, box.Max[1], delta);
        }
コード例 #4
0
        public void TestRectangleF2DCreateFromBoundsAndCenter()
        {
            double delta = 0.00001;
            // this should create the exact same rectangle as in the other tests.
            RectangleF2D rectangle = RectangleF2D.FromBoundsAndCenter(System.Math.Sqrt(2) * 2,
                                                                      System.Math.Sqrt(2) * 2, 3, 1, 45);

            RectangleF2D rectangleReference = new RectangleF2D(1, 1, System.Math.Sqrt(2) * 2,
                                                               System.Math.Sqrt(2) * 2, 45);

            Assert.AreEqual(rectangleReference.Height, rectangle.Height);
            Assert.AreEqual(rectangleReference.Width, rectangle.Width);
            Assert.AreEqual(rectangleReference.BottomLeft[0], rectangle.BottomLeft[0], delta);
            Assert.AreEqual(rectangleReference.BottomLeft[1], rectangle.BottomLeft[1], delta);
            Assert.AreEqual(rectangleReference.TopLeft[0], rectangle.TopLeft[0], delta);
            Assert.AreEqual(rectangleReference.TopLeft[1], rectangle.TopLeft[1], delta);
            Assert.AreEqual(rectangleReference.TopRight[0], rectangle.TopRight[0], delta);
            Assert.AreEqual(rectangleReference.TopRight[1], rectangle.TopRight[1], delta);
            Assert.AreEqual(rectangleReference.BottomRight[0], rectangle.BottomRight[0], delta);
            Assert.AreEqual(rectangleReference.BottomRight[1], rectangle.BottomRight[1], delta);
        }