Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws an image on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="nativeImage"></param>
        protected override void DrawImage(Target2DWrapper <global::Android.Graphics.Canvas> target,
                                          double left, double top, double right, double bottom, INativeImage nativeImage)
        {
            var rectangle = new RectangleF2D(left, top, right - left, bottom - top);

            this.DrawImage(target, rectangle, nativeImage);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="target">Target.</param>
        /// <param name="bounds">Bounds.</param>
        /// <param name="imageData">Image data.</param>
        /// <param name="tag">Tag.</param>
        protected override object DrawImage(Target2DWrapper <CGContextWrapper> target, RectangleF2D bounds, byte[] imageData, object tag)
        {
            target.Target.CGContext.SetAllowsFontSubpixelQuantization(true);
            target.Target.CGContext.SetAllowsFontSmoothing(true);
            target.Target.CGContext.SetAllowsAntialiasing(true);
            target.Target.CGContext.SetAllowsSubpixelPositioning(true);
            target.Target.CGContext.SetShouldAntialias(true);

            PointF2D bottomLeft  = new PointF2D(this.Tranform(bounds.BottomLeft [0], bounds.BottomLeft [1]));
            PointF2D bottomRight = new PointF2D(this.Tranform(bounds.BottomRight [0], bounds.BottomRight [1]));
            PointF2D topLeft     = new PointF2D(this.Tranform(bounds.TopLeft [0], bounds.TopLeft [1]));
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            RectangleF2D transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                                        topLeft - bottomLeft);


            target.Target.CGContext.SaveState();
            target.Target.CGContext.TranslateCTM((float)transformed.BottomLeft [0], (float)transformed.BottomLeft [1]);
            target.Target.CGContext.RotateCTM(-(float)((Radian)transformed.Angle).Value);

            if (tag is CGImage)
            {
                CGImage image = tag as CGImage;

                target.Target.CGContext.DrawImage(new RectangleF(0, 0,
                                                                 (float)transformed.Width, (float)transformed.Height), image);
            }

            target.Target.CGContext.RestoreState();

            return(tag);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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;
        }
        TextShape CreateCustomTextualMarker(ComplexShape markerShape)
        {
            RectangleF2D box = new RectangleF2D(-15, -15, 30, 30);

            EllipseShape eShape = new EllipseShape(box);
            TextShape    txt    = new TextShape();

            eShape.BeginUpdate();
            eShape.Name = "bg";
            eShape.Appearance.ContentBrush = new SolidBrushObject(Color.White);
            eShape.Appearance.BorderBrush  = new SolidBrushObject(Color.Black);
            eShape.Appearance.BorderWidth  = 2;
            eShape.EndUpdate();

            txt.BeginUpdate();
            txt.Name = "marketText";
            txt.Text = "Test";
            txt.Box  = box;
            txt.AppearanceText.TextBrush = new SolidBrushObject(Color.Black);
            txt.AppearanceText.Font      = new Font("Tahoma", 8f);
            txt.ShadingFlags             = ShadingFlags.NoShading;
            txt.EndUpdate();

            markerShape.AddRange(new BaseShape[] { eShape, txt });
            return(txt);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="target">Target.</param>
        /// <param name="bounds">Bounds.</param>
        /// <param name="imageData">Image data.</param>
        /// <param name="tag">Tag.</param>
        protected override object DrawImage(Target2DWrapper <Canvas> target, RectangleF2D bounds, byte[] imageData, object tag)
        {
            global::Android.Graphics.Bitmap image = (tag as global::Android.Graphics.Bitmap);
            if (image == null)
            {
                image = global::Android.Graphics.BitmapFactory.DecodeByteArray(
                    imageData, 0, imageData.Length);
            }

            PointF2D bottomLeft  = new PointF2D(this.Tranform(bounds.BottomLeft [0], bounds.BottomLeft [1]));
            PointF2D bottomRight = new PointF2D(this.Tranform(bounds.BottomRight [0], bounds.BottomRight [1]));
            PointF2D topLeft     = new PointF2D(this.Tranform(bounds.TopLeft [0], bounds.TopLeft [1]));
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            RectangleF2D transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                                        topLeft - bottomLeft);


            target.Target.Save();
            target.Target.Translate((float)transformed.BottomLeft [0], (float)transformed.BottomLeft [1]);
            target.Target.Rotate(-(float)((Degree)transformed.Angle).Value);
            target.Target.DrawBitmap(image, new global::Android.Graphics.Rect(0, 0, image.Width, image.Height),
                                     new global::Android.Graphics.RectF(0, 0,
                                                                        (float)transformed.Width, (float)transformed.Height),
                                     null);
            target.Target.Restore();

            return(tag);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="target">Target.</param>
        /// <param name="bounds">Bounds.</param>
        /// <param name="nativeImage">Image data.</param>
        protected override void DrawImage(Target2DWrapper <Canvas> target, RectangleF2D bounds, INativeImage nativeImage)
        {
            var nativeAndroidImage = (nativeImage as NativeImage);

            global::Android.Graphics.Bitmap image = nativeAndroidImage.Image;
            this.Transform(bounds.BottomLeft [0], bounds.BottomLeft [1], _transformed1);
            PointF2D bottomLeft = new PointF2D(_transformed1[0], _transformed1[1]);

            this.Transform(bounds.BottomRight [0], bounds.BottomRight [1], _transformed1);
            PointF2D bottomRight = new PointF2D(_transformed1[0], _transformed1[1]);

            this.Transform(bounds.TopLeft [0], bounds.TopLeft [1], _transformed1);
            PointF2D topLeft = new PointF2D(_transformed1[0], _transformed1[1]);
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            var transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                               topLeft - bottomLeft);

            _paint.AntiAlias    = true;
            _paint.FilterBitmap = true;
            target.Target.Save();
            target.Target.Translate((float)transformed.BottomLeft [0], (float)transformed.BottomLeft [1]);
            target.Target.Rotate(-(float)((Degree)transformed.Angle).Value);
            if (image != null)
            {
                target.Target.DrawBitmap(image,
                                         new global::Android.Graphics.Rect(0, 0, image.Width, image.Height),
                                         new global::Android.Graphics.RectF(0, 0, (float)transformed.Width, (float)transformed.Height),
                                         _paint);
            }
            target.Target.Restore();
        }
Ejemplo n.º 10
0
        /// <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;
        }
Ejemplo n.º 11
0
        /// <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;
        }
Ejemplo n.º 12
0
        /// <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];
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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]);
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Draws an image on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="right"></param>
        /// <param name="bottom"></param>
        /// <param name="nativeImage"></param>
        /// <returns>The image.</returns>
        protected override void DrawImage(Target2DWrapper <CGContextWrapper> target, double left, double top, double right,
                                          double bottom, INativeImage nativeImage)
        {
            // get the native image.
            var iosNativeImage = (nativeImage as NativeImage);

            // get CGImage.
            CGImage image = iosNativeImage.Image;

            var bounds = new RectangleF2D(left, bottom, (left - right),
                                          (top - bottom));

            target.Target.CGContext.SetAllowsFontSubpixelQuantization(true);
            target.Target.CGContext.SetAllowsFontSmoothing(true);
            target.Target.CGContext.SetAllowsAntialiasing(true);
            target.Target.CGContext.SetAllowsSubpixelPositioning(true);
            target.Target.CGContext.SetShouldAntialias(true);

            PointF2D bottomLeft  = new PointF2D(this.Transform(bounds.BottomLeft[0], bounds.BottomLeft[1]));
            PointF2D bottomRight = new PointF2D(this.Transform(bounds.BottomRight[0], bounds.BottomRight[1]));
            PointF2D topLeft     = new PointF2D(this.Transform(bounds.TopLeft[0], bounds.TopLeft[1]));
            //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1]));

            RectangleF2D transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft),
                                                        topLeft - bottomLeft);

            target.Target.CGContext.SaveState();
            target.Target.CGContext.TranslateCTM((float)transformed.BottomLeft[0], (float)transformed.BottomLeft[1]);
            target.Target.CGContext.RotateCTM(-(float)((Radian)transformed.Angle).Value);
            target.Target.CGContext.ScaleCTM(-1, 1);

            // build rectangle.
            _rectangle.X      = 0;
            _rectangle.Y      = 0;
            _rectangle.Width  = (float)transformed.Width;
            _rectangle.Height = (float)transformed.Height;
            target.Target.CGContext.DrawImage(_rectangle, image);

            target.Target.CGContext.RestoreState();
        }
Ejemplo n.º 20
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)));
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Draws the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="target">Target.</param>
 /// <param name="bounds">Bounds.</param>
 /// <param name="imageData">Image data.</param>
 /// <param name="tag">Tag.</param>
 protected abstract void DrawImage(Target2DWrapper <TTarget> target, RectangleF2D bounds, INativeImage tag);
Ejemplo n.º 22
0
        /// <summary>
        /// Fites this view around the given points but keeps aspect ratio and
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public View2D Fit(PointF2D[] points, double percentage)
        {
            RectangleF2D rotated = this.Rectangle.FitAndKeepAspectRatio(points, percentage);

            return(new View2D(rotated, _invertX, _invertY));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Draws the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="target">Target.</param>
 /// <param name="bounds">Bounds.</param>
 /// <param name="nativeImage">Image data.</param>
 protected override void DrawImage(Target2DWrapper <Graphics> target, RectangleF2D bounds, INativeImage nativeImage)
 {
 }
Ejemplo n.º 24
0
 /// <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));
 }
Ejemplo n.º 25
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]);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Draws the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="target">Target.</param>
 /// <param name="bounds">Bounds.</param>
 /// <param name="imageData">Image data.</param>
 /// <param name="tag">Tag.</param>
 protected override object DrawImage(Target2DWrapper <Graphics> target, RectangleF2D bounds, byte[] imageData, object tag)
 {
     return(tag);
 }
Ejemplo n.º 27
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 abstract uint AddImage(int layer, float minZoom, float maxZoom, RectangleF2D rectangle, byte[] imageData, object tag);
Ejemplo n.º 28
0
        /// <summary>
        /// Rotates this view around it's center with a given angle and returns the modified version.
        /// </summary>
        /// <returns>The around center.</returns>
        /// <param name="angle">Angle.</param>
        public View2D RotateAroundCenter(Radian angle)
        {
            RectangleF2D rotated = this.Rectangle.RotateAroundCenter(angle);

            return(new View2D(rotated, _invertX, _invertY));
        }
Ejemplo n.º 29
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)
 {
     return(_nonSimplifiedScene.AddImage(layer, minZoom, maxZoom, rectangle, imageData, tag));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Draws the image.
 /// </summary>
 /// <returns>The image.</returns>
 /// <param name="target">Target.</param>
 /// <param name="bounds">Bounds.</param>
 /// <param name="nativeImage">Image data.</param>
 protected override void DrawImage(Target2DWrapper <RenderContext> target, RectangleF2D bounds, INativeImage nativeImage)
 {
     DrawImage(target, bounds.TopLeft[0], bounds.TopLeft[1], bounds.BottomRight[0], bounds.BottomRight[1], nativeImage);
 }