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()); }
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); }
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 }); }
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; }
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); }
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; }
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); }
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); } }
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); }
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]); }
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); }
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); }
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 }
/// <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)); }
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(); } }
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); } } } } }
public SpatialSheet(SpatialTree <TNode> tree, int level, int TileLevel, CoordinateRectangle rectangle) : base(tree, level, TileLevel) { Rectangle = rectangle; }
public InterseptResult RectangleContains(CoordinateRectangle rectangle) { return ((CoordinateRectangle)this).RectangleContains(rectangle); }
virtual protected void TranslateCoords() { _screenView = _centerCoordinate.GetScreenViewFromCenter(Width, Height, _level); _coordinateView = ScreenView; }
/// <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)); }
public InterseptResult LineContains(CoordinateRectangle line) { return ((CoordinateRectangle)this).LineContains(line); }
public IntersectResult RectangleContains(CoordinateRectangle rectangle) { return(((CoordinateRectangle)this).RectangleContains(rectangle)); }
public IntersectResult LineContains(CoordinateRectangle line) { return(((CoordinateRectangle)this).LineContains(line)); }