コード例 #1
0
ファイル: RectangleF2D.cs プロジェクト: hungdluit/OsmSharp
        public bool Overlaps(RectangleF2D rectangle)
        {
            if (rectangle.Contains(this.BottomLeft) || rectangle.Contains(this.BottomRight) || (rectangle.Contains(this.TopLeft) || rectangle.Contains(this.TopRight)) || (this.Contains(rectangle.BottomLeft) || this.Contains(rectangle.BottomRight) || (this.Contains(rectangle.TopLeft) || this.Contains(rectangle.TopRight))))
            {
                return(true);
            }
            List <LineF2D> lineF2DList1 = new List <LineF2D>();

            lineF2DList1.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lineF2DList1.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lineF2DList1.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lineF2DList1.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            List <LineF2D> lineF2DList2 = new List <LineF2D>();

            lineF2DList2.Add(new LineF2D(rectangle.BottomLeft, rectangle.BottomRight, true));
            lineF2DList2.Add(new LineF2D(rectangle.BottomRight, rectangle.TopRight, true));
            lineF2DList2.Add(new LineF2D(rectangle.TopRight, rectangle.TopLeft, true));
            lineF2DList2.Add(new LineF2D(rectangle.TopLeft, rectangle.BottomLeft, true));
            foreach (LineF2D lineF2D in lineF2DList1)
            {
                foreach (LineF2D line in lineF2DList2)
                {
                    if (lineF2D.Intersects(line))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: View2D.cs プロジェクト: nubix-biz/OsmSharp
        /// <summary>
        /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.View2D"/> class.
        /// </summary>
        private View2D(RectangleF2D rectangle, bool invertX, bool invertY)
        {
            _invertX = invertX;
            _invertY = invertY;

            _rectangle = rectangle;
        }
コード例 #3
0
ファイル: ImageTilted2D.cs プロジェクト: Climbatize/OsmSharp
        /// <summary>
        /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.Scene.Scene2DPrimitives.TiltedImage2D"/> class.
        /// </summary>
        /// <param name="bounds">Bounds.</param>
        /// <param name="imageData">Image data.</param>
        public ImageTilted2D(RectangleF2D bounds, byte[] imageData, float minZoom, float maxZoom)
        {
            _bounds = bounds;
            this.ImageData = imageData;

            this.MinZoom = minZoom;
            this.MaxZoom = maxZoom;
        }
コード例 #4
0
ファイル: ImageTilted2D.cs プロジェクト: JoeCooper/ui
        /// <summary>
        /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.Scene.Scene2DPrimitives.TiltedImage2D"/> class.
        /// </summary>
        /// <param name="bounds">Bounds.</param>
        /// <param name="nativeImage">Image data.</param>
        public ImageTilted2D(RectangleF2D bounds, INativeImage nativeImage, float minZoom, float maxZoom)
        {
            _bounds = bounds;
            this.NativeImage = nativeImage;

            this.MinZoom = minZoom;
            this.MaxZoom = maxZoom;
        }
コード例 #5
0
ファイル: RectangleF2D.cs プロジェクト: jboneng/OsmSharp
        /// <summary>
        /// Fits this rectangle to the given points.
        /// </summary>
        /// <param name="points">The points to wrap the rectangle around.</param>
        /// <param name="percentage">The margin in percentage.</param>
        /// <returns></returns>
        public RectangleF2D Fit(PointF2D[] points, double percentage)
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }
            if (points.Length < 2)
            {
                throw new ArgumentOutOfRangeException("Rectangle fit needs at least two points.");
            }

            // calculate the center.
            double[] center = new double[] { points[0][0], points[0][1] };
            for (int idx = 1; idx < points.Length; idx++)
            {
                center[0] = center[0] + points[idx][0];
                center[1] = center[1] + points[idx][1];
            }
            center[0] = center[0] / points.Length;
            center[1] = center[1] / points.Length;
            PointF2D centerPoint = new PointF2D(center);

            LineF2D line = null;
            // calculate the width.
            double width = 0;

            for (int idx = 0; idx < points.Length; idx++)
            {
                line = new LineF2D(points[idx], points[idx] + this._vectorY);
                double distance = line.Distance(centerPoint);
                if (distance > width)
                { // the distance is larger.
                    width = distance;
                }
            }
            width = width * 2;

            // calculate the height.
            double height = 0;

            for (int idx = 0; idx < points.Length; idx++)
            {
                line = new LineF2D(points[idx], points[idx] + this._vectorX);
                double distance = line.Distance(centerPoint);
                if (distance > height)
                { // this distance is larger.
                    height = distance;
                }
            }
            height = height * 2;

            // expand with the given percentage.
            width  = width + (width / 100.0 * percentage);
            height = height + (height / 100.0 * percentage);

            return(RectangleF2D.FromBoundsAndCenter(width, height, centerPoint[0], centerPoint[1],
                                                    this.DirectionY));
        }
コード例 #6
0
ファイル: RectangleF2D.cs プロジェクト: hungdluit/OsmSharp
        public override bool Equals(object obj)
        {
            RectangleF2D rectangleF2D = obj as RectangleF2D;

            if (rectangleF2D != null && rectangleF2D.BottomLeft.Equals((object)this.BottomLeft) && rectangleF2D.DirectionX.Equals((object)this.DirectionX))
            {
                return(rectangleF2D.DirectionY.Equals((object)this.DirectionY));
            }
            return(false);
        }
コード例 #7
0
ファイル: RectangleF2D.cs プロジェクト: teleavtomatika/core
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="OsmSharp.Math.Primitives.RectangleF2D"/>.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="OsmSharp.Math.Primitives.RectangleF2D"/>.</param>
        /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
        /// <see cref="OsmSharp.Math.Primitives.RectangleF2D"/>; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            RectangleF2D rectangle = (obj as RectangleF2D);

            if (rectangle != null)
            {
                return(rectangle.BottomLeft.Equals(this.BottomLeft) &&
                       rectangle.DirectionX.Equals(this.DirectionX) &&
                       rectangle.DirectionY.Equals(this.DirectionY));
            }
            return(false);
        }
コード例 #8
0
ファイル: View2D.cs プロジェクト: JoeCooper/ui
		/// <summary>
		/// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.View2D"/> class.
		/// </summary>
		private View2D(RectangleF2D rectangle, bool invertX, bool invertY)
		{
			_invertX = invertX;
			_invertY = invertY;

			_rectangle = rectangle;

            var box = _rectangle.BoundingBox;
            _minX = box.Min[0];
            _minY = box.Min[1];
            _maxX = box.Max[0];
            _maxY = box.Max[1];
		}
コード例 #9
0
ファイル: RectangleF2D.cs プロジェクト: hungdluit/OsmSharp
        public RectangleF2D Fit(PointF2D[] points, double percentage)
        {
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }
            if (points.Length < 2)
            {
                throw new ArgumentOutOfRangeException("Rectangle fit needs at least two points.");
            }
            double[] values = new double[2]
            {
                points[0][0],
                points[0][1]
            };
            for (int index = 1; index < points.Length; ++index)
            {
                values[0] = values[0] + points[index][0];
                values[1] = values[1] + points[index][1];
            }
            values[0] = values[0] / (double)points.Length;
            values[1] = values[1] / (double)points.Length;
            PointF2D p    = new PointF2D(values);
            double   num1 = 0.0;

            for (int index = 0; index < points.Length; ++index)
            {
                double num2 = new LineF2D(points[index], points[index] + this._vectorY).Distance(p);
                if (num2 > num1)
                {
                    num1 = num2;
                }
            }
            double num3 = num1 * 2.0;
            double num4 = 0.0;

            for (int index = 0; index < points.Length; ++index)
            {
                double num2 = new LineF2D(points[index], points[index] + this._vectorX).Distance(p);
                if (num2 > num4)
                {
                    num4 = num2;
                }
            }
            double num5 = num4 * 2.0;

            return(RectangleF2D.FromBoundsAndCenter(num3 + num3 / 100.0 * percentage, num5 + num5 / 100.0 * percentage, p[0], p[1], this.DirectionY));
        }
コード例 #10
0
ファイル: RectangleF2D.cs プロジェクト: teleavtomatika/core
        /// <summary>
        /// Fits this rectangle to this given points and keeps aspect ratio.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="percentage"></param>
        /// <returns></returns>
        public RectangleF2D FitAndKeepAspectRatio(PointF2D[] points, double percentage)
        {
            RectangleF2D fitted = this;

            if (points.Length > 1)
            { // multiple points can be fitted and zoomed to.
                fitted = this.Fit(points, percentage);
            }
            else if (points.Length == 1)
            { // a single point can only be moved to.
                fitted = new RectangleF2D(points[0][0], points[0][1], this.Width, this.Height, this.Angle);
            }

            // although this may seem a strange approach, think about
            // numerical stability before changing this!

            double width       = fitted.Width;
            double height      = fitted.Height;
            double targetRatio = this.Width / this.Height; // this is the target ratio.

            if (fitted.Height > fitted.Width)
            { // the height is bigger.
                double targetWidth = fitted.Height * targetRatio;
                if (targetWidth < fitted.Width)
                { // increase height instead.
                    height = fitted.Width / targetRatio;
                }
                else
                { // ok, the width is increased and ratio's match now.
                    width = targetWidth;
                }
            }
            else
            { // the width is bigger.
                double targetHeight = fitted.Width / targetRatio;
                if (targetHeight < fitted.Height)
                { // increase width instead.
                    width = fitted.Height * targetRatio;
                }
                else
                { // ok, the height is increase and ratio's match now.
                    height = targetHeight;
                }
            }
            return(RectangleF2D.FromBoundsAndCenter(width, height,
                                                    fitted.Center[0], fitted.Center[1], fitted.DirectionY));
        }
コード例 #11
0
ファイル: RectangleF2D.cs プロジェクト: hungdluit/OsmSharp
        public RectangleF2D FitAndKeepAspectRatio(PointF2D[] points, double percentage)
        {
            RectangleF2D rectangleF2D = this;

            if (points.Length > 1)
            {
                rectangleF2D = this.Fit(points, percentage);
            }
            else if (points.Length == 1)
            {
                rectangleF2D = new RectangleF2D(points[0][0], points[0][1], this.Width, this.Height, this.Angle);
            }
            double width  = rectangleF2D.Width;
            double height = rectangleF2D.Height;
            double num1   = this.Width / this.Height;

            if (rectangleF2D.Height > rectangleF2D.Width)
            {
                double num2 = rectangleF2D.Height * num1;
                if (num2 < rectangleF2D.Width)
                {
                    height = rectangleF2D.Width / num1;
                }
                else
                {
                    width = num2;
                }
            }
            else
            {
                double num2 = rectangleF2D.Width / num1;
                if (num2 < rectangleF2D.Height)
                {
                    width = rectangleF2D.Height * num1;
                }
                else
                {
                    height = num2;
                }
            }
            return(RectangleF2D.FromBoundsAndCenter(width, height, rectangleF2D.Center[0], rectangleF2D.Center[1], rectangleF2D.DirectionY));
        }
コード例 #12
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);
        }
コード例 #13
0
ファイル: RectangleF2D.cs プロジェクト: teleavtomatika/core
        /// <summary>
        /// Returns true if this rectangle overlaps with the given box.
        /// </summary>
        /// <param name="rectangle">Rectangle.</param>
        public bool Overlaps(RectangleF2D rectangle)
        {
            // Yes, I know this code can be shorter but it would turn into a mess!
            if (rectangle.Contains(this.BottomLeft) || rectangle.Contains(this.BottomRight) ||
                rectangle.Contains(this.TopLeft) || rectangle.Contains(this.TopRight))
            {
                return(true);
            }
            if (this.Contains(rectangle.BottomLeft) || this.Contains(rectangle.BottomRight) ||
                this.Contains(rectangle.TopLeft) || this.Contains(rectangle.TopRight))
            {
                return(true);
            }

            List <LineF2D> lines = new List <LineF2D>();

            lines.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lines.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lines.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lines.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            List <LineF2D> otherLines = new List <LineF2D>();

            otherLines.Add(new LineF2D(rectangle.BottomLeft, rectangle.BottomRight, true));
            otherLines.Add(new LineF2D(rectangle.BottomRight, rectangle.TopRight, true));
            otherLines.Add(new LineF2D(rectangle.TopRight, rectangle.TopLeft, true));
            otherLines.Add(new LineF2D(rectangle.TopLeft, rectangle.BottomLeft, true));
            foreach (LineF2D line in lines)
            {
                foreach (LineF2D otherLine in otherLines)
                {
                    if (line.Intersects(otherLine))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #14
0
        public void TestRectangleF2DRotationAroundPoint()
        {
            double delta = 0.00001;

            RectangleF2D rectangle = new RectangleF2D (2, 2, 1, 1);
            RectangleF2D rotatedRectangle = rectangle.RotateAround (90, new PointF2D (2, 2));

            Assert.AreEqual (2, rotatedRectangle.BottomLeft [0], delta);
            Assert.AreEqual (2, rotatedRectangle.BottomLeft [1], delta);
            Assert.AreEqual (2, rotatedRectangle.BottomRight [0], delta);
            Assert.AreEqual (1, rotatedRectangle.BottomRight [1], delta);
            Assert.AreEqual (3, rotatedRectangle.TopLeft [0], delta);
            Assert.AreEqual (2, rotatedRectangle.TopLeft [1], delta);
            Assert.AreEqual (3, rotatedRectangle.TopRight [0], delta);
            Assert.AreEqual (1, rotatedRectangle.TopRight [1], delta);
        }
コード例 #15
0
ファイル: Matrix2D.cs プロジェクト: JoeCooper/ui
        /// <summary>
        /// Creates a tranformation matrix that transforms coordinates from inside the given rectangle to a viewport of given size. The bottom-left of the rectangle is assumed to be the origin.
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="invertX"></param>
        /// <param name="invertY"></param>
        /// <returns></returns>
        public static Matrix2D FromRectangle(RectangleF2D rectangle, double width, double height, bool invertX, bool invertY)
        {
            Matrix2D invert;
            if (!invertX && !invertY)
            { // everything normal.
                invert = Matrix2D.Scale(1, 1);
            }
            else if (!invertX && invertY)
            { // only y inverted.
                invert = Matrix2D.Scale(1, -1);
            }
            else if (invertX && !invertY)
            { // only x inverted.
                invert = Matrix2D.Scale(-1, 1);
            }
            else
            { // both inverted.
                invert = Matrix2D.Scale(-1, -1);
            }

            // translate the bottom-left of the rectangle to the origin.
            var translate = Matrix2D.Translate(-rectangle.BottomLeft[0], -rectangle.BottomLeft[1]);

            // rotate the rectangle to align with x-y axis.
            var rotate = Matrix2D.Rotate(-((Radian)rectangle.Angle).Value);

            // scale to match the width/height that was given.
            var scale = Matrix2D.Scale(width / rectangle.Width, height / rectangle.Height);

            return invert * translate * rotate * scale;
        }
コード例 #16
0
ファイル: Matrix2D.cs プロジェクト: JoeCooper/ui
 /// <summary>
 /// Creates a tranformation matrix that transforms coordinates from inside the given rectangle to a viewport of given size. The bottom-left of the rectangle is assumed to be the origin.
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <returns></returns>
 public static Matrix2D FromRectangle(RectangleF2D rectangle, double width, double height)
 {
     return Matrix2D.FromRectangle(rectangle, width, height, false, false);
 }
コード例 #17
0
ファイル: Matrix2D.cs プロジェクト: JoeCooper/ui
        /// <summary>
        /// Creates a transformation matrix that transforms coordinates the viewport of given size to inside the given rectangle. The bottom-left of the rectangle is assumed to be the origin.
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="invertX"></param>
        /// <param name="invertY"></param>
        /// <returns></returns>
        public static Matrix2D ToRectangle(RectangleF2D rectangle, double width, double height, bool invertX, bool invertY)
        {
            // scale to match the width/height that was given.
            var scale = Matrix2D.Scale(rectangle.Width / width, rectangle.Height / height);

            // rotate to align with rectangle.
            var rotate = Matrix2D.Rotate(((Radian)rectangle.Angle).Value);

            // translate to the bottom-left of the rectangle.
            var translate = Matrix2D.Translate(rectangle.BottomLeft[0], rectangle.BottomLeft[1]);

            Matrix2D invert;
            if (!invertX && !invertY)
            { // everything normal.
                invert = Matrix2D.Scale(1, 1);
            }
            else if (!invertX && invertY)
            { // only y inverted.
                invert = Matrix2D.Scale(1, -1);
            }
            else if (invertX && !invertY)
            { // only x inverted.
                invert = Matrix2D.Scale(-1, 1);
            }
            else
            { // both inverted.
                invert = Matrix2D.Scale(-1, -1);
            }

            return scale * rotate * translate * invert;
        }
コード例 #18
0
ファイル: RectangleF2D.cs プロジェクト: jmorken/OSM-bigroute
        /// <summary>
        /// Returns true if this rectangle overlaps with the given box.
        /// </summary>
        /// <param name="rectangle">Rectangle.</param>
        public bool Overlaps(RectangleF2D rectangle)
        {
            // Yes, I know this code can be shorter but it would turn into a mess!
            if (rectangle.Contains(this.BottomLeft) || rectangle.Contains(this.BottomRight) ||
                rectangle.Contains(this.TopLeft) || rectangle.Contains(this.TopRight))
            {
                return true;
            }
            if (this.Contains(rectangle.BottomLeft) || this.Contains(rectangle.BottomRight) ||
                this.Contains(rectangle.TopLeft) || this.Contains(rectangle.TopRight))
            {
                return true;
            }

            List<LineF2D> lines = new List<LineF2D>();
            lines.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lines.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lines.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lines.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            List<LineF2D> otherLines = new List<LineF2D>();
            otherLines.Add(new LineF2D(rectangle.BottomLeft, rectangle.BottomRight, true));
            otherLines.Add(new LineF2D(rectangle.BottomRight, rectangle.TopRight, true));
            otherLines.Add(new LineF2D(rectangle.TopRight, rectangle.TopLeft, true));
            otherLines.Add(new LineF2D(rectangle.TopLeft, rectangle.BottomLeft, true));
            foreach (LineF2D line in lines)
            {
                foreach (LineF2D otherLine in otherLines)
                {
                    if (line.Intersects(otherLine))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
コード例 #19
0
ファイル: RectangleF2D.cs プロジェクト: jboneng/OsmSharp
 /// <summary>
 /// Creates a new RectangleF2D from given bounds, center and angle.
 /// </summary>
 /// <param name="centerX"></param>
 /// <param name="centerY"></param>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 /// <param name="angleY">The angle.</param>
 /// <returns></returns>
 public static RectangleF2D FromBoundsAndCenter(double width, double height, double centerX, double centerY, Degree angleY)
 {
     return(RectangleF2D.FromBoundsAndCenter(width, height, centerX, centerY, VectorF2D.FromAngleY(angleY)));
 }
コード例 #20
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);
        }
コード例 #21
0
        public void TestRectangleF2DNoDirection()
        {
            RectangleF2D rectangle = new RectangleF2D (0, 0, 1, 1);
            Assert.AreEqual(0, rectangle.BottomLeft[0]);
            Assert.AreEqual(0, rectangle.BottomLeft[1]);
            Assert.AreEqual(1, rectangle.BottomRight[0]);
            Assert.AreEqual(0, rectangle.BottomRight[1]);
            Assert.AreEqual(0, rectangle.TopLeft[0]);
            Assert.AreEqual(1, rectangle.TopLeft[1]);
            Assert.AreEqual(1, rectangle.TopRight[0]);
            Assert.AreEqual(1, rectangle.TopRight[1]);
            Assert.AreEqual (0, rectangle.Angle.Value);

            BoxF2D box = rectangle.BoundingBox;
            Assert.AreEqual(0, box.Min[0]);
            Assert.AreEqual(0, box.Min[1]);
            Assert.AreEqual(1, box.Max[0]);
            Assert.AreEqual(1, box.Max[1]);

            Assert.IsTrue(rectangle.Contains(0.25, 0.75));
            Assert.IsFalse(rectangle.Contains(1.2, 0.25));
            Assert.IsFalse(rectangle.Contains(0.25, 1.2));

            Assert.IsTrue(rectangle.Contains(new PointF2D(0.25, 0.75)));
            Assert.IsFalse(rectangle.Contains(new PointF2D(1.2, 0.25)));
            Assert.IsFalse(rectangle.Contains(new PointF2D(0.25, 1.2)));

            Assert.AreEqual(1, rectangle.Distance(new PointF2D(2, 0)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(1, 0)));
            Assert.AreEqual(1, rectangle.Distance(new PointF2D(0, 2)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(0, 1)));

            Assert.AreEqual(1, rectangle.Distance(new PointF2D(-1, 0.5)));
            Assert.AreEqual(0, rectangle.Distance(new PointF2D(0, 0.5)));

            Assert.AreEqual(1, rectangle.Height);
            Assert.AreEqual(1, rectangle.Width);

            double[] converted = rectangle.TransformFrom (100, 100, false, false,
                                                         new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (0.25, converted [0]);
            Assert.AreEqual (0.75, converted [1]);
            double[] convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                           converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0]);
            Assert.AreEqual (75, convertedBack [1]);

            converted = rectangle.TransformFrom (100, 100, false, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (0.25, converted [0]);
            Assert.AreEqual (0.25, converted [1]);
            convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0]);
            Assert.AreEqual (25, convertedBack [1]);

            converted = rectangle.TransformFrom (100, 100, true, false,
                                                 new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (0.75, converted [0]);
            Assert.AreEqual (0.75, converted [1]);
            convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (75, convertedBack [0]);
            Assert.AreEqual (75, convertedBack [1]);

            converted = rectangle.TransformFrom (100, 100, true, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (0.75, converted [0]);
            Assert.AreEqual (0.25, converted [1]);
            convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (75, convertedBack [0]);
            Assert.AreEqual (25, convertedBack [1]);
        }
コード例 #22
0
        public void TestRectangleF2DOutsideTransforms()
        {
            RectangleF2D rectangle = new RectangleF2D (0, 0, 1, 1);

            double[] converted = rectangle.TransformFrom (100, 100, false, false,
                                                          new double[] { -100, -100 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (-1, converted [0]);
            Assert.AreEqual (-1, converted [1]);
            double[] convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (-100, convertedBack [0]);
            Assert.AreEqual (-100, convertedBack [1]);
        }
コード例 #23
0
ファイル: OpenGLRenderer2D.cs プロジェクト: jboneng/OsmSharp
 protected override object DrawImage(Target2DWrapper <OpenGLTarget2D> target, OsmSharp.Math.Primitives.RectangleF2D bounds, byte[] imageData, object tag)
 {
     return(tag);
 }
コード例 #24
0
        public void TestRectangleF2DDirection()
        {
            double delta = 0.00001;
            RectangleF2D rectangle = new RectangleF2D (1, 1, System.Math.Sqrt (2) * 2,
                                                       System.Math.Sqrt (2) * 2, 45);
            Assert.AreEqual (45, rectangle.Angle.Value, delta);

            double[] converted = rectangle.TransformFrom (100, 100, false, false,
                                                          new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (3, converted [0], delta);
            Assert.AreEqual (2, converted [1], delta);
            double[] convertedBack = rectangle.TransformTo (100, 100, false, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0], delta);
            Assert.AreEqual (75, convertedBack [1], delta);

            converted = rectangle.TransformFrom (100, 100, true, false,
                                                          new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (4, converted [0], delta);
            Assert.AreEqual (1, converted [1], delta);
            convertedBack = rectangle.TransformTo (100, 100, true, false,
                                                            converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0], delta);
            Assert.AreEqual (75, convertedBack [1], delta);

            converted = rectangle.TransformFrom (100, 100, false, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (2, converted [0], delta);
            Assert.AreEqual (1, converted [1], delta);
            convertedBack = rectangle.TransformTo (100, 100, false, true,
                                                   converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0], delta);
            Assert.AreEqual (75, convertedBack [1], delta);

            converted = rectangle.TransformFrom (100, 100, true, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual (2, converted.Length);
            Assert.AreEqual (3, converted [0], delta);
            Assert.AreEqual (0, converted [1], delta);
            convertedBack = rectangle.TransformTo (100, 100, true, true,
                                                   converted);
            Assert.AreEqual (2, convertedBack.Length);
            Assert.AreEqual (25, convertedBack [0], delta);
            Assert.AreEqual (75, convertedBack [1], delta);

            rectangle = new RectangleF2D(new PointF2D(1, 1), System.Math.Sqrt(2) * 2,
                                                       System.Math.Sqrt(2) * 2, new VectorF2D(1,1));

            converted = rectangle.TransformFrom(100, 100, false, false,
                                                          new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(3, converted[0], delta);
            Assert.AreEqual(2, converted[1], delta);
            convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                            converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack[0], delta);
            Assert.AreEqual(75, convertedBack[1], delta);

            converted = rectangle.TransformFrom(100, 100, true, false,
                                                          new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(4, converted[0], delta);
            Assert.AreEqual(1, converted[1], delta);
            convertedBack = rectangle.TransformTo(100, 100, true, false,
                                                            converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack[0], delta);
            Assert.AreEqual(75, convertedBack[1], delta);

            converted = rectangle.TransformFrom(100, 100, false, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(2, converted[0], delta);
            Assert.AreEqual(1, converted[1], delta);
            convertedBack = rectangle.TransformTo(100, 100, false, true,
                                                   converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack[0], delta);
            Assert.AreEqual(75, convertedBack[1], delta);

            converted = rectangle.TransformFrom(100, 100, true, true,
                                                 new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(3, converted[0], delta);
            Assert.AreEqual(0, converted[1], delta);
            convertedBack = rectangle.TransformTo(100, 100, true, true,
                                                   converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack[0], delta);
            Assert.AreEqual(75, convertedBack[1], delta);
        }
コード例 #25
0
        /// <summary>
        /// Adds the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="layer">Layer.</param>
        /// <param name="minZoom">Minimum zoom.</param>
        /// <param name="maxZoom">Max zoom.</param>
        /// <param name="rectangle">Rectangle.</param>
        /// <param name="imageData">Image data.</param>
        /// <param name="tag">Tag.</param>
        public override uint AddImage(int layer, float minZoom, float maxZoom, RectangleF2D rectangle, byte[] imageData, object tag)
        {
            if (imageData == null)
                throw new ArgumentNullException("imageData");

            lock (_primitives)
            {
                uint id = _nextId;
                _nextId++;

                var imageTilted2D = new ImageTilted2D (rectangle, imageData, minZoom, maxZoom);
                imageTilted2D.Tag = tag;
                this.AddPrimitive(layer, id, imageTilted2D);
                return id;
            }
        }
コード例 #26
0
 protected override void DrawImage(Target2DWrapper <OpenGLTarget2D> target, OsmSharp.Math.Primitives.RectangleF2D bounds, INativeImage tag)
 {
 }
コード例 #27
0
        public void TestRectangleF2DOverlaps()
        {
            double delta = 0.00001;
            RectangleF2D rectangle = new RectangleF2D(1, 1, System.Math.Sqrt(2) * 2,
                                                       System.Math.Sqrt(2) * 2, 45);

            double[] converted = rectangle.TransformFrom(100, 100, false, false,
                                                          new double[] { 25, 75 });
            Assert.AreEqual(2, converted.Length);
            Assert.AreEqual(3, converted[0], delta);
            Assert.AreEqual(2, converted[1], delta);
            double[] convertedBack = rectangle.TransformTo(100, 100, false, false,
                                                            converted);
            Assert.AreEqual(2, convertedBack.Length);
            Assert.AreEqual(25, convertedBack[0], delta);
            Assert.AreEqual(75, convertedBack[1], delta);

            Assert.IsFalse(rectangle.Overlaps(new BoxF2D(5, 3, 6, 4)));
            Assert.IsTrue(rectangle.Overlaps(new BoxF2D(3.5, 1.5, 4.5, 2.5)));
            Assert.IsTrue(rectangle.Overlaps(new BoxF2D(2, 0.5, 3, 1.5)));
            Assert.IsTrue(rectangle.Overlaps(new BoxF2D(0, -2, 4, 6)));
            Assert.IsTrue(rectangle.Overlaps(new BoxF2D(4, -2, 6, 4)));
            Assert.IsTrue(rectangle.Overlaps(new BoxF2D(1.5, -2, 2.5, 4)));
        }
コード例 #28
0
ファイル: Scene2DLayered.cs プロジェクト: vcotlearov/OsmSharp
 /// <summary>
 /// Adds the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="layer">Layer.</param>
 /// <param name="minZoom">Minimum zoom.</param>
 /// <param name="maxZoom">Max zoom.</param>
 /// <param name="rectangle">Rectangle.</param>
 /// <param name="imageData">Image data.</param>
 /// <param name="tag">Tag.</param>
 public override uint AddImage(int layer, float minZoom, float maxZoom, RectangleF2D rectangle, byte[] imageData, object tag)
 {
     return _nonSimplifiedScene.AddImage (layer, minZoom, maxZoom, rectangle, imageData, tag);
 }
コード例 #29
0
ファイル: Scene2D.cs プロジェクト: robert-hickey/OsmSharp
 /// <summary>
 /// Adds the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="layer">Layer.</param>
 /// <param name="minZoom">Minimum zoom.</param>
 /// <param name="maxZoom">Max zoom.</param>
 /// <param name="rectangle">Rectangle.</param>
 /// <param name="imageData">Image data.</param>
 /// <param name="tag">Tag.</param>
 public abstract uint AddImage(int layer, float minZoom, float maxZoom, RectangleF2D rectangle, byte[] imageData, object tag);