Ejemplo n.º 1
0
        internal Rect GetTileBounds(double tileGridScale, Point tileGridTopLeft, Size viewportSize)
        {
            var scale  = tileGridScale / ViewportScale;
            var matrix = new Matrix(scale, 0d, 0d, scale, 0d, 0d);

            matrix.Rotate(-ViewportRotation);

            // viewport origin in map coordinates
            //
            var origin = InverseViewportTransform.Transform(new Point());

            // translate origin to tile grid origin in pixels
            //
            matrix.Translate(
                tileGridScale * (origin.X - tileGridTopLeft.X),
                tileGridScale * (tileGridTopLeft.Y - origin.Y));

            // transforms viewport bounds to tile pixel bounds
            //
            var transform = new MatrixTransform {
                Matrix = matrix
            };

            return(transform.TransformBounds(new Rect(0d, 0d, viewportSize.Width, viewportSize.Height)));
        }
Ejemplo n.º 2
0
        public Task When_Identity_And_TransformBounds() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform();

            Assert.AreEqual(new Rect(0, 0, 0, 0), SUT.TransformBounds(new Rect(0, 0, 0, 0)));
        });
    protected override void OnWindowPositionChanged(Rect rcBoundingBox)
    {
        DpiScale dpiScale = VisualTreeHelper.GetDpi(this);

        base.OnWindowPositionChanged(rcBoundingBox);
        Rect newRect = ScaleRectDownFromDPI(rcBoundingBox, dpiScale);
        Rect finalRect;

        if (ParentScrollViewer != null)
        {
            ParentScrollViewer.ScrollChanged += ParentScrollViewer_ScrollChanged;
            ParentScrollViewer.SizeChanged   += ParentScrollViewer_SizeChanged;
            ParentScrollViewer.Loaded        += ParentScrollViewer_Loaded;
        }
        if (Scrolling || Resizing)
        {
            if (ParentScrollViewer == null)
            {
                return;
            }
            MatrixTransform tr = RootVisual.TransformToDescendant(ParentScrollViewer) as MatrixTransform;

            var scrollRect = new Rect(new Size(ParentScrollViewer.ViewportWidth, ParentScrollViewer.ViewportHeight));
            var c          = tr.TransformBounds(newRect);

            var intersect = Rect.Intersect(scrollRect, c);
            if (!intersect.IsEmpty)
            {
                tr        = ParentScrollViewer.TransformToDescendant(this) as MatrixTransform;
                intersect = tr.TransformBounds(intersect);
                finalRect = ScaleRectUpToDPI(intersect, dpiScale);
            }
            else
            {
                finalRect = intersect = new Rect();
            }

            int x1 = (int)Math.Round(finalRect.X);
            int y1 = (int)Math.Round(finalRect.Y);
            int x2 = (int)Math.Round(finalRect.Right);
            int y2 = (int)Math.Round(finalRect.Bottom);
            SetRegion(x1, y1, x2, y2);
            this.Scrolling = false;
            this.Resizing  = false;
        }
        LocationChanged?.Invoke(this, new EventArgs());
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Transforms a Rect in viewport coordinates to a BoundingBox in geographic coordinates.
        /// </summary>
        public BoundingBox ViewportRectToBoundingBox(Rect rect)
        {
            var transform = new MatrixTransform {
                Matrix = InverseViewportTransform
            };

            return(RectToBoundingBox(transform.TransformBounds(rect)));
        }
Ejemplo n.º 5
0
        public async Task When_Identity_And_TransformBounds()
        {
            await Dispatch(() =>
            {
                var SUT = new MatrixTransform();

                Assert.AreEqual(new Rect(0, 0, 0, 0), SUT.TransformBounds(new Rect(0, 0, 0, 0)));
            });
        }
Ejemplo n.º 6
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            MatrixTransform m = (MatrixTransform)AdornedElement.TransformToVisual(this);

            Rect r = m.TransformBounds(new Rect(new Point(0, 0), AdornedElement.DesiredSize));

            hilightRect.Arrange(r);

            return(finalSize);
        }
Ejemplo n.º 7
0
        public static Rect TransformRectangle(this Matrix matrix, Rect rectangle)
        {
            var matrixTransform = new MatrixTransform
            {
                Matrix = matrix
            };

            var transformedRect = matrixTransform.TransformBounds(rectangle);

            return(transformedRect);
        }
Ejemplo n.º 8
0
        public void TransformBounds()
        {
            var rect      = new Rect(-1, 1, 5, 2);
            var transform = new MatrixTransform(MatrixTest.GetIncrementalMatrix(10, 3));
            var result    = transform.TransformBounds(rect);

            result.X.Should().Be(28);
            result.Y.Should().Be(31);
            result.Width.Should().Be(82);
            result.Height.Should().Be(103);
        }
Ejemplo n.º 9
0
        public Task When_Translate_And_TransformBounds() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.Create(1, 0, 0, 1, 10, 20)
            };

            Assert.AreEqual(
                new Rect(10, 20, 5, 6),
                SUT.TransformBounds(new Rect(0, 0, 5, 6))
                );
        });
Ejemplo n.º 10
0
        private Rect GetTileIndexBounds(int zoomLevel)
        {
            var scale     = (1 << zoomLevel) / 360d;
            var transform = new MatrixTransform
            {
                Matrix = parentMap.ViewportTransform.Matrix
                         .Invert()             // view to map coordinates
                         .Translate(180d, -180d)
                         .Scale(scale, -scale) // map coordinates to tile indices
            };

            return(transform.TransformBounds(new Rect(new Point(), parentMap.RenderSize)));
        }
Ejemplo n.º 11
0
        public Task When_Rotate_And_TransformBounds() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 2))
            };

            Assert.AreEqual(
                new Rect(-7, 1, 6, 5),
                SUT.TransformBounds(new Rect(1, 1, 5, 6))
                );
        });
Ejemplo n.º 12
0
        public async Task When_Rotate_And_TransformBounds()
        {
            await Dispatch(() =>
            {
                var SUT = new MatrixTransform()
                {
                    Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 2))
                };

                Assert.AreEqual(
                    new Rect(-7, 1, 6, 5),
                    SUT.TransformBounds(new Rect(1, 1, 5, 6))
                    );
            });
        }
Ejemplo n.º 13
0
        public async Task When_Translate_And_TransformBounds()
        {
            await Dispatch(() =>
            {
                var SUT = new MatrixTransform()
                {
                    Matrix = new Matrix(1, 0, 0, 1, 10, 20)
                };

                Assert.AreEqual(
                    new Rect(10, 20, 5, 6),
                    SUT.TransformBounds(new Rect(0, 0, 5, 6))
                    );
            });
        }
Ejemplo n.º 14
0
        public Task When_RotateQuarter_And_TransformBounds() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 4))
            };

            var expected = new Rect(-4.242640495300293, 1.4142135381698608, 7.77817440032959, 7.7781739234924316);
            var actual   = SUT.TransformBounds(new Rect(1, 1, 5, 6));

            Assert.AreEqual(expected.X, actual.X, 1e-5, $"X: {expected} != {actual}");
            Assert.AreEqual(expected.Y, actual.Y, 1e-5, $"Y: {expected} != {actual}");
            Assert.AreEqual(expected.Width, actual.Width, 1e-5, $"W: {expected} != {actual}");
            Assert.AreEqual(expected.Height, actual.Height, 1e-5, $"H: {expected} != {actual}");
        });
        protected void UpdateSlider()
        {
            double currentSliderPos = _xSlider.Value;

            _xSlider.Minimum = PrimitiveDataRange.Left;
            _xSlider.Maximum = PrimitiveDataRange.Right;
            _xSlider.Value   = currentSliderPos;
            Rect transformedRect = _shapeTransform.TransformBounds(PrimitiveDataRange);

            double leftMargin  = CanvasRect.Left + transformedRect.Left - 5;
            double rightMargin = CanvasRect.Right - transformedRect.Right - 5;

            _xSlider.Margin = new Thickness(leftMargin, 0, rightMargin, 0);
            //_xSlider.Clip = new RectangleGeometry(new Rect(new Point(-leftMargin,0), CanvasRect.Size));
            _xSlider.SmallChange = _gridLineCanvas.LastSpacingX * 0.1;
            _xSlider.LargeChange = _gridLineCanvas.LastSpacingX;
        }
Ejemplo n.º 16
0
        public async Task When_RotateQuarter_And_TransformBounds()
        {
            await Dispatch(() =>
            {
                var SUT = new MatrixTransform()
                {
                    Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 4))
                };

                var expected = new Rect(-4.24264097213745, 1.41421353816986, 7.77817463874817, 7.77817499637604);
                var actual   = SUT.TransformBounds(new Rect(1, 1, 5, 6));

                Assert.AreEqual(expected.Y, actual.Y, 1e-10, $"{expected} != {actual}");
                Assert.AreEqual(expected.X, actual.X, 1e-10, $"{expected} != {actual}");
                Assert.AreEqual(expected.Width, actual.Width, 1e-10, $"{expected} != {actual}");
                Assert.AreEqual(expected.Height, actual.Height, 1e-10, $"{expected} != {actual}");
            });
        }
Ejemplo n.º 17
0
        private TileGrid GetTileGrid()
        {
            var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
            var tileScale     = (1 << tileZoomLevel);
            var scale         = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * TileSource.TileSize);
            var tileCenter    = GetTileCenter(tileScale);
            var viewCenter    = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);

            var transform = new MatrixTransform
            {
                Matrix = MatrixEx.TranslateScaleRotateTranslate(viewCenter, scale, -parentMap.Heading, tileCenter)
            };

            var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));

            return(new TileGrid(tileZoomLevel,
                                (int)Math.Floor(bounds.X), (int)Math.Floor(bounds.Y),
                                (int)Math.Floor(bounds.X + bounds.Width), (int)Math.Floor(bounds.Y + bounds.Height)));
        }
Ejemplo n.º 18
0
        private TileGrid GetTileGrid()
        {
            var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
            var tileScale     = (double)(1 << tileZoomLevel);
            var scale         = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * MapProjection.TileSize);
            var tileCenter    = new Point(tileScale * (0.5 + parentMap.Center.Longitude / 360d),
                                          tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
            var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);

            var transform = new MatrixTransform
            {
                Matrix = MapProjection.CreateTransformMatrix(viewCenter, scale, -parentMap.Heading, tileCenter)
            };

            var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));

            return(new TileGrid(tileZoomLevel,
                                (int)Math.Floor(bounds.X), (int)Math.Floor(bounds.Y),
                                (int)Math.Floor(bounds.X + bounds.Width), (int)Math.Floor(bounds.Y + bounds.Height)));
        }