コード例 #1
0
        public HashItem[] FindNearestCable(GeomCoordinate pt)
        {
            var list = new NearestSet();

            try
            {
                _lockCr.EnterReadLock();

                if (_rCableTree.NodeCount == 0)
                {
                    return(list.ToArray());
                }

                var res = _rCableTree.Distance(pt, CoordinateTolerance);
                foreach (var node in res)
                {
                    var row = (MapDb.CablesRow)node.Row;

                    var cableRect = new CoordinateRectangle(row.Longitude1, row.Latitude1, row.Longitude2, row.Latitude2);

                    var distance = cableRect.LineDistance(pt);
                    list.Add(new HashItem(distance, row.ID));
                }
            }
            finally
            {
                _lockCr.ExitReadLock();
            }

            return(list.OrderBy(item => item.Key).ToArray());
        }
コード例 #2
0
        public void Initialize()
        {
            mockTileFactory            = new Mock <IViewModelTilesFactory>();
            mockBlockFactory           = new Mock <IFactory <IRenderable> >();
            mockEmptyComponentsFactory = new Mock <IFactory <IRenderable> >();
            mockBatteryFactory         = new Mock <IFactory <IRenderable> >();
            mockPipeLinkFactory        = new Mock <IFactory <IRenderable> >();
            mockPipeFactory            = new Mock <IFactory <IRenderable, ICurve> >();

            var mockEmptyTile = new Mock <IActivateableWorldObject>();

            tiles = new IActivateableWorldObject[6, 4];
            var rect = new CoordinateRectangle(Coordinates.Zero, new Coordinate(4, 6));

            foreach (var coordinate in rect.Points)
            {
                tiles.Set(coordinate, mockEmptyTile.Object);
            }

            mockBlueprintBuilder = new Mock <IBlueprintBuilder>();
            mockBlueprint        = new Mock <IBlueprint>();
            mockTileFactory.Setup(factory =>
                                  factory.CreateTiles(It.IsAny <Coordinate>(), It.IsAny <IRectangleSection>())).Returns(tiles);

            var mockDetails = new Mock <IDetails <IShipComponent> >();

            viewModelFactory = new ViewModelFactory(
                mockTileFactory.Object,
                mockBlockFactory.Object,
                mockBatteryFactory.Object,
                mockEmptyComponentsFactory.Object,
                mockPipeLinkFactory.Object,
                mockPipeFactory.Object,
                mockDetails.Object);
        }
コード例 #3
0
        private void DownloadThread(CancellationToken ct)
        {
            var leftBound  = new Coordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new Coordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            var mapBlockCount = 0;

            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth  = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;
                mapBlockCount += (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
            }

            var mapBlockNumber = 0;

            BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth  = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new GoogleBlock(x, y, mapLevel);

                        var fileName = Properties.Settings.GetMapFileName(block);
                        if (!File.Exists(fileName))
                        {
                            MapLayer.DownloadImageFromGoogle(block, false);
                        }

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                        if (ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }
            }
            BeginInvoke(ProgressEvent, new Object[] { 101, mapBlockNumber, mapBlockCount });
        }
コード例 #4
0
 public GoogleRectangle(CoordinateRectangle coordinateRect, int level)
 {
     var pLeftTop = new GoogleCoordinate(coordinateRect.LeftTop, level);
     var pRightBottom = new GoogleCoordinate(coordinateRect.RightBottom, level);
     Left = pLeftTop.X;
     Top = pLeftTop.Y;
     Right = pRightBottom.X;
     Bottom = pRightBottom.Y;
     Level = level;
 }
コード例 #5
0
        public void CornersAreSetCorrectly()
        {
            var bottomLeftCorner = new Coordinate(0, 1);
            var topRightCorner   = new Coordinate(2, 3);

            var rectangle = new CoordinateRectangle(bottomLeftCorner, topRightCorner);

            Assert.AreEqual(bottomLeftCorner, rectangle.bottomLeftCorner);
            Assert.AreEqual(topRightCorner, rectangle.topRightCorner);
        }
コード例 #6
0
ファイル: GoogleRectangle.cs プロジェクト: Opzet/SimpleMap
        public ScreenRectangle(CoordinateRectangle coordinateRect, int level)
        {
            var pLeftTop     = new ScreenCoordinate(coordinateRect.LeftTop, level);
            var pRightBottom = new ScreenCoordinate(coordinateRect.RightBottom, level);

            Left   = pLeftTop.X;
            Top    = pLeftTop.Y;
            Right  = pRightBottom.X;
            Bottom = pRightBottom.Y;
            Level  = level;
        }
コード例 #7
0
        private        Vector2[,] CreateMatrixPoints(Vector2 initialPosition, Vector2 xDirection, Vector2 yDirection,
                                                     Coordinate dimensions)
        {
            var corners         = new Vector2[dimensions.Y, dimensions.X];
            var splitsRectangle = new CoordinateRectangle(Coordinates.Zero, dimensions);

            foreach (var coordinate in splitsRectangle.Points)
            {
                corners.Set(coordinate, initialPosition + coordinate.X * xDirection + coordinate.Y * yDirection);
            }
            return(corners);
        }
コード例 #8
0
        private void GetFullMapThread(CancellationToken ct)
        {
            var leftBound  = new Coordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new Coordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            try
            {
                var mapWidth  = Convert.ToInt32((new GoogleCoordinate(rectBound.RightTop, _mapLevel)).X - (new GoogleCoordinate(rectBound.LeftTop, _mapLevel)).X) + 2 * GoogleBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new GoogleCoordinate(rectBound.LeftBottom, _mapLevel)).Y - (new GoogleCoordinate(rectBound.LeftTop, _mapLevel)).Y) + 2 * GoogleBlock.BlockSize;

                var image    = GraphicLayer.CreateCompatibleBitmap(null, mapWidth, mapHeight, _mapPiFormat);
                var graphics = Graphics.FromImage(image);

                var viewBound      = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, _mapLevel);
                var blockView      = viewBound.BlockView;
                var mapBlockCount  = (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
                var mapBlockNumber = 0;

                BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new GoogleBlock(x, y, _mapLevel);
                        var bmp   = GraphicLayer.CreateCompatibleBitmap(
                            MapLayer.DownloadImageFromFile(block) ?? MapLayer.DownloadImageFromGoogle(block, true),
                            GoogleBlock.BlockSize, GoogleBlock.BlockSize, _mapPiFormat);

                        var rect = ((GoogleRectangle)block).GetScreenRect(viewBound);
                        graphics.DrawImageUnscaled(bmp, rect.Location.X, rect.Location.Y);

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                        if (ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }

                BeginInvoke(SaveMapEvent, new Object[] { image });
            }
            catch (Exception e)
            {
                BeginInvoke(ProgressEvent, new Object[] { 101, 0, 0 });
                MessageBox.Show(e.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #9
0
        public         Rectangle[,] Split(Coordinate dimensions)
        {
            var splits              = new Rectangle[dimensions.Y, dimensions.X];
            var corners             = CreateSplitCorners(dimensions);
            var coordinateRectangle = new CoordinateRectangle(Coordinates.Zero, dimensions);

            foreach (var position in coordinateRectangle.Points)
            {
                splits.Set(position,
                           new Rectangle(corners.Get(position), corners.Get(position + Coordinates.Up + Coordinates.Right)));
            }
            return(splits);
        }
コード例 #10
0
        public void CheckIfCorrectCoordinatesAreIteratedOver()
        {
            var bottomLeftCorner = new Coordinate(0, 1);
            var topRightCorner   = new Coordinate(2, 3);

            var rectangle = new CoordinateRectangle(bottomLeftCorner, topRightCorner);
            var points    = rectangle.Points.ToArray();

            Assert.AreEqual(new Coordinate(0, 1), points[0]);
            Assert.AreEqual(new Coordinate(1, 1), points[1]);
            Assert.AreEqual(new Coordinate(0, 2), points[2]);
            Assert.AreEqual(new Coordinate(1, 2), points[3]);
        }
コード例 #11
0
ファイル: SpatialTree.cs プロジェクト: wasn-eu/SimpleMap
        public HashSet <ISpatialTreeNode> Query(CoordinateRectangle rectangle)
        {
            //for debug to see how many iterations used for a search
            var i = SpatialQueryIterator.Start();

            var res = new HashSet <ISpatialTreeNode>();

            _root.Query(res, rectangle, InterseptResult.None, i);

            //index turning
            System.Diagnostics.Trace.WriteLine(string.Format("{5} Level nodes {1} {2} {3} {4}, Query iterations - {0:d}",
                                                             i.Value, NodeDimension[0], NodeDimension[1], NodeDimension[2], NodeDimension[3], typeof(TNode).Name));

            return(res);
        }
コード例 #12
0
        public IActivateableWorldObject[,] CreateTiles(Coordinate dimensions, IRectangleSection fittingRectangle)
        {
            var tiles     = new IActivateableWorldObject[dimensions.Y, dimensions.X];
            var tileRects = fittingRectangle.Section.Split(dimensions);

            var coordinateRectangle = new CoordinateRectangle(Coordinates.Zero, dimensions);

            foreach (var coordinate in coordinateRectangle.Points)
            {
                tiles.Set(coordinate, tileFactory.Create());
                tiles.Get(coordinate).Position = tileRects.Get(coordinate).Center;
                tiles.Get(coordinate).Scale    = tileRects.Get(coordinate).Dimensions;
            }
            return(tiles);
        }
コード例 #13
0
        private void GenerateSampleData()
        {
            _netLayer.ClearData();

            //--sample for show smothness
            var rnd    = new Random();
            var rangeX = Convert.ToInt32((Settings.Default.RightMapBound - Settings.Default.LeftMapBound) * 100000);
            var rangeY = Convert.ToInt32((Settings.Default.TopMapBound - Settings.Default.BottomMapBound) * 100000);

            var longitude1 = Convert.ToDecimal(Settings.Default.LeftMapBound + (double)rnd.Next(0, rangeX) / 100000);
            var latitude1  = Convert.ToDecimal(Settings.Default.BottomMapBound + (double)rnd.Next(0, rangeY) / 100000);

            var cableDbRows  = new MapDb.CablesDataTable();
            var vertexDbRows = new MapDb.VertexesDataTable();

            while (cableDbRows.Count < 200)
            {
                var cableRow = cableDbRows.NewCablesRow();

                cableRow.Longitude1 = longitude1;
                cableRow.Latitude1  = latitude1;
                cableRow.Longitude2 = Convert.ToDecimal(Settings.Default.LeftMapBound + (double)rnd.Next(0, rangeX) / 100000);
                cableRow.Latitude2  = Convert.ToDecimal(Settings.Default.BottomMapBound + (double)rnd.Next(0, rangeY) / 100000);
                var rect = new CoordinateRectangle(cableRow.Longitude1, cableRow.Latitude1, cableRow.Longitude2, cableRow.Latitude2);
                cableRow.Length = Convert.ToDecimal(rect.LineLength);
                if (cableRow.Length <= 5000 && cableRow.Length > 200)
                {
                    longitude1       = cableRow.Longitude2;
                    latitude1        = cableRow.Latitude2;
                    cableRow.Caption = rect.ToString();
                    cableDbRows.AddCablesRow(cableRow);

                    var vertexRow = vertexDbRows.NewVertexesRow();

                    vertexRow.Longitude = longitude1;
                    vertexRow.Latitude  = latitude1;

                    var pt = new GeomCoordinate(vertexRow.Longitude, vertexRow.Latitude);
                    vertexRow.Caption = pt.ToString();
                    vertexDbRows.AddVertexesRow(vertexRow);
                }
            }
            _netLayer.MergeData(vertexDbRows);
            _netLayer.MergeData(cableDbRows);
            //--end sample
        }
コード例 #14
0
ファイル: GoogleMapUtilities.cs プロジェクト: Opzet/SimpleMap
        /// <summary>
        /// Line cross
        /// </summary>
        public static bool CheckLinesIntersection(CoordinateRectangle line1, CoordinateRectangle line2)
        {
            double d = (line1.Left - line1.Right) * (line2.Bottom - line2.Top) - (line1.Top - line1.Bottom) * (line2.Right - line2.Left);

            if (Math.Abs(d) < 0.000000001)
            {
                return(false);
            }

            double da = (line1.Left - line2.Left) * (line2.Bottom - line2.Top) - (line1.Top - line2.Top) * (line2.Right - line2.Left);
            double db = (line1.Left - line1.Right) * (line1.Top - line2.Top) - (line1.Top - line1.Bottom) * (line1.Left - line2.Left);

            double ta = da / d;
            double tb = db / d;

            return((0 <= ta) && (ta <= 1) && (0 <= tb) && (tb <= 1));
        }
コード例 #15
0
        private void RedrawCables(ScreenRectangle localScreenView)
        {
            try
            {
                _lockCr.EnterReadLock();

                if (_rCableTree.NodeCount == 0)
                {
                    return;
                }

                var res = _rCableTree.Query(localScreenView);
                foreach (var node in res)
                {
                    var row = (MapDb.CablesRow)node.Row;

                    var cabRect = new CoordinateRectangle(row.Longitude1, row.Latitude1, row.Longitude2, row.Latitude2);
                    var rect    = cabRect.GetScreenRect(localScreenView);

                    DrawLine(rect, 2, Color.Blue);

                    if (Level >= 14)
                    {
                        var caption = row.Caption;
                        if (!String.IsNullOrEmpty(caption))
                        {
                            var coordinate = cabRect.LineMiddlePoint;
                            var point      = coordinate.GetScreenPoint(localScreenView);
                            DrawString(caption, HalfVertexSize.Height, Point.Add(point, HalfVertexSize));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //do nothing
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                _lockCr.ExitReadLock();
            }
        }
コード例 #16
0
        public void Query(HashSet <ISpatialTreeNode> hashSet, CoordinateRectangle rectangle, IntersectResult parentResult, SpatialQueryIterator i)
        {
            //Query elements on the map by coordinate ractengle(indexed search)
            lock (this)
            {
                if (!IsBottomSheet)
                {
                    if (Sheets.HasChilds)
                    {
                        foreach (var sheet in Sheets.Values)
                        {
                            var res = parentResult == IntersectResult.Supersets ? IntersectResult.Supersets : IntersectResult.None;

                            if (res != IntersectResult.Supersets)
                            {
                                i.Next();

                                res = sheet.Rectangle.RectangleContains(rectangle);
                            }
                            if (res != IntersectResult.None)
                            {
                                sheet.Query(hashSet, rectangle, res, i);
                            }
                            if (res == IntersectResult.Contains)
                            {
                                break;
                            }
                        }
                    }
                }
                else if (Content.HasChilds)
                {
                    foreach (var node in Content.Values)
                    {
                        var res = parentResult == IntersectResult.Supersets ? IntersectResult.Supersets : IntersectResult.None;
                        if (res != IntersectResult.Supersets)
                        {
                            i.Next();

                            switch (node.NodeType)
                            {
                            case SpatialTreeNodeTypes.Point:
                                res = rectangle.PointContains(node.Coordinate);
                                break;

                            case SpatialTreeNodeTypes.Line:
                                res = rectangle.LineContains(node.Rectangle);
                                break;

                            case SpatialTreeNodeTypes.Rectangle:
                                res = rectangle.RectangleContains(node.Rectangle);
                                break;

                            case SpatialTreeNodeTypes.Poligon:
                                res = rectangle.PoligonContains(node.Poligon);
                                break;
                            }
                        }
                        if (res != IntersectResult.None)
                        {
                            hashSet.Add(node);
                        }
                    }
                }
            }
        }
コード例 #17
0
 public SpatialSheet(SpatialTree <TNode> tree, int level, int TileLevel, CoordinateRectangle rectangle)
     : base(tree, level, TileLevel)
 {
     Rectangle = rectangle;
 }
コード例 #18
0
 public InterseptResult RectangleContains(CoordinateRectangle rectangle)
 {
     return ((CoordinateRectangle)this).RectangleContains(rectangle);
 }
コード例 #19
0
 virtual protected void TranslateCoords()
 {
     _screenView     = _centerCoordinate.GetScreenViewFromCenter(Width, Height, _level);
     _coordinateView = ScreenView;
 }
コード例 #20
0
        /// <summary>
        /// Line cross
        /// </summary>
        public static bool CheckLinesInterseption(CoordinateRectangle line1, CoordinateRectangle line2)
        {
            double d = (line1.Left - line1.Right) * (line2.Bottom - line2.Top) - (line1.Top - line1.Bottom) * (line2.Right - line2.Left);

            if (Math.Abs(d) < 0.000000001)
                return false;

            double da = (line1.Left - line2.Left) * (line2.Bottom - line2.Top) - (line1.Top - line2.Top) * (line2.Right - line2.Left);
            double db = (line1.Left - line1.Right) * (line1.Top - line2.Top) - (line1.Top - line1.Bottom) * (line1.Left - line2.Left);

            double ta = da / d;
            double tb = db / d;

            return ((0 <= ta) && (ta <= 1) && (0 <= tb) && (tb <= 1));
        }
コード例 #21
0
 public InterseptResult LineContains(CoordinateRectangle line)
 {
     return ((CoordinateRectangle)this).LineContains(line);
 }
コード例 #22
0
ファイル: GoogleRectangle.cs プロジェクト: Opzet/SimpleMap
 public IntersectResult RectangleContains(CoordinateRectangle rectangle)
 {
     return(((CoordinateRectangle)this).RectangleContains(rectangle));
 }
コード例 #23
0
ファイル: GoogleRectangle.cs プロジェクト: Opzet/SimpleMap
 public IntersectResult LineContains(CoordinateRectangle line)
 {
     return(((CoordinateRectangle)this).LineContains(line));
 }