public void SelectGemTile(Vector3Int centerCubeCoordinates, GemType gemType) { var colouredBorderTile = gemType == GemType.Blue ? _blueBorderHexTile : _redBorderHexTile; SetTile(centerCubeCoordinates, colouredBorderTile); var neighbours = CoordinateUtils.Neighbours(centerCubeCoordinates) .Where(_boardTilesCubeCoordinates.Contains).ToList(); var jumpNeighbours = neighbours.SelectMany(CoordinateUtils.Neighbours) .Where(cell => _boardTilesCubeCoordinates.Contains(cell) && !neighbours.Contains(cell) && centerCubeCoordinates != cell); var emptyNeighbours = neighbours.Where(cell => GemPlacementManager.Instance.GemTypeAt(cell) == GemType.None); var emptyJumpNeighbours = jumpNeighbours.Where(cell => GemPlacementManager.Instance.GemTypeAt(cell) == GemType.None); foreach (var cubeCoord in emptyNeighbours) { SetTile(cubeCoord, _borderHexTile); } foreach (var cubeCoord in emptyJumpNeighbours) { SetTile(cubeCoord, colouredBorderTile); } }
/// <summary> /// 刷新Mobike数据 /// </summary> public void RefreshmobikeInfo() { //获取车辆位置信息 var mobikecars = new List <mobikeInfo>(); NetUtils.GetmobikeCars(out mobikecars); if (mobikecars == null) { view.ShowError("数据出现问题,可能是mobike用户认证出错 返回示例数据"); mobikecars = SampleData.mobikeSampleList; } IFeatureClass featureclass = CreateFeatureClass("mobike"); IFeatureCursor featureCursor = featureclass.Insert(true); //遍历照片链表 以创建缓存的形式插入数据 foreach (var c in mobikecars) { IPoint pPoint = new PointClass(); //坐标转换 var t = CoordinateUtils.gcj02_To_Wgs84(c.distY, c.distX); pPoint.PutCoords(t.longtitude, t.latitude); pPoint.SpatialReference = ApplicationV.GlobalMapControl.SpatialReference; pPoint.Project(ApplicationV.GlobalMapControl.SpatialReference); IFeatureBuffer featureBuffer = featureclass.CreateFeatureBuffer(); featureBuffer.Shape = pPoint; featureBuffer.set_Value(featureBuffer.Fields.FindField("Latitude"), t.latitude); featureBuffer.set_Value(featureBuffer.Fields.FindField("Longtitude"), t.longtitude); featureCursor.InsertFeature(featureBuffer); } featureCursor.Flush(); //创建图层 IFeatureLayer pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.FeatureClass = featureclass; pFeaturelayer.Name = "mobike分布"; //修饰该图层 IPictureMarkerSymbol mobikeMarkerSymbol = new PictureMarkerSymbolClass(); mobikeMarkerSymbol.Size = 18; mobikeMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG, ApplicationV.Data_ImgPath + "//mobike.png"); // ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); // pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; // var pRgbColor = ColorUtils.GetRgbColor(226, 61, 14); // pMarkerSymbol.Color = pRgbColor; ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = (ISymbol)mobikeMarkerSymbol; (pFeaturelayer as IGeoFeatureLayer).Renderer = pSimpleRenderer as IFeatureRenderer; //正式归为图层 ofoLayer = pFeaturelayer as ILayer; ApplicationV.GlobalMapControl.AddLayer(ofoLayer); ApplicationV.GlobalMapControl.Refresh(); }
private IEnumerator DoMove(Vector3Int from, Vector3Int to) { switch (CoordinateUtils.CubeDistance(from, to)) { case 1: yield return(DoSplitMove(to)); break; case 2: yield return(DoJumpMove(from, to)); break; } UpdateGemCountersText(); CheckWinner(); SwitchPlayer(); if (Settings.GameMode == GameMode.PvC && _currentPlayer == GemType.Blue) { var aiMove = Ai.GetMove(new Board( GridManager.Instance.Grid(), GemPlacementManager.Instance.GetGemCoordinates(GemType.Red), GemPlacementManager.Instance.GetGemCoordinates(GemType.Blue))); yield return(DoMove(aiMove.From, aiMove.To)); } HighlightCurrentPlayerGems(); _moveInProgress = false; }
public void ShowCellBorders(List <Vector3Int> cubeCoordinates) { foreach (var cubeCoordinate in cubeCoordinates) { Board.SetTile(CoordinateUtils.CubeToOffset(cubeCoordinate), _borderHexTile); } }
private void ReadBoard() { var tilemaps = _grid.GetComponentsInChildren <Tilemap>(); foreach (var tileMap in tilemaps) { if (tileMap.name == "Board") { _board = tileMap; break; } } if (_board == null) { throw new Exception("No Board tilemap found"); } _board.CompressBounds(); foreach (var position in _board.cellBounds.allPositionsWithin) { if (_board.GetTile(position) != null) { _boardTilesCubeCoordinates.Add(CoordinateUtils.OffsetToCube(position)); } } }
public IEnumerator SwapGemsAround(GemType gemType, Vector3Int cubeCoordinates) { var neighboursToSwap = CoordinateUtils.Neighbours(cubeCoordinates) .Where(n => { var gemTypeAt = GemTypeAt(n); return(gemTypeAt != GemType.None && gemTypeAt != gemType); }) .ToList(); if (neighboursToSwap.Count <= 0) { yield break; } EffectsManager.Instance.PlayDisappearSound(); foreach (var coroutine in neighboursToSwap.Select(n => StartCoroutine(RemoveGem(n))).ToList()) { yield return(coroutine); } EffectsManager.Instance.PlayAppearSound(); foreach (var coroutine in neighboursToSwap.Select(n => StartCoroutine(PutGem(gemType, n))).ToList()) { yield return(coroutine); } }
public void MakeDemoTile(LLBoundingBox boundary) { MaximumHeight = float.NegativeInfinity; MinimumHeight = float.PositiveInfinity; if (GridSize != QMConstants.DemoResolutionGridSize) { GridSize = QMConstants.DemoResolutionGridSize; Array.Resize(ref ElevGrid, GridSize * GridSize); Array.Resize(ref EcefPoints, GridSize * GridSize); } var step = 20.0F / (GridSize - 1); var XStep = (boundary.East - boundary.West) / (GridSize - 1); var YStep = (boundary.North - boundary.South) / (GridSize - 1); float hgt; int pos = 0; double XPos; double YPos = boundary.South; for (int y = 0; y < GridSize; y++) { hgt = QMConstants.DemoBaseHgt; XPos = boundary.West; for (int x = 0; x < GridSize; x++) { // height ElevGrid[pos] = hgt; if (hgt < MinimumHeight) { MinimumHeight = hgt; } if (hgt > MaximumHeight) { MaximumHeight = hgt; } hgt = hgt + step; // ECEF EcefPoints[pos] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(XPos), Y = MapUtils.Deg2Rad(YPos), Z = hgt }); XPos = XPos + XStep; pos++; } YPos = YPos + YStep; // increase y } HasData = true; East = boundary.East; West = boundary.West; North = boundary.North; South = boundary.South; }
private static List <KeyValuePair <AiMove, int> > Estimate(Board board, List <AiMove> moves) { return(moves.Select(move => { var value = CoordinateUtils.CubeDistance(move.From, move.To) == 1 ? 1 : 0; var enemySwapCount = board.RedGemsCountAround(move.To); value += enemySwapCount; return new KeyValuePair <AiMove, int>(move, value); }).ToList()); }
private bool CanMoveFrom(Vector3Int pos) { var neighbours = CoordinateUtils.Neighbours(pos).Where(GridManager.Instance.CellInBounds).ToList(); if (neighbours.Any(n => GemPlacementManager.Instance.GemTypeAt(n) == GemType.None)) { return(true); } var jumpNeighbours = neighbours.SelectMany(CoordinateUtils.Neighbours).Where(GridManager.Instance.CellInBounds); return(jumpNeighbours.Any(n => GemPlacementManager.Instance.GemTypeAt(n) == GemType.None)); }
/// <summary> /// Initializes a Range made up of cells, based on a range string /// like "A1" or "B2:LC65536". /// </summary> public Range( string rangeString, Worksheet worksheet, SLDocument document ) { this._document = document; this._worksheet = worksheet; this._type = RangeType.Cells; (_minRowIndex, _minColIndex, _maxRowIndex, _maxColIndex) = CoordinateUtils.RangeStringToCoords(rangeString); }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); var board = GridManager.Instance.Board; var tilePosition = board.WorldToCell(pos); var tile = board.GetTile(tilePosition); if (tile != null) { GameManager.Instance.TileClicked(CoordinateUtils.OffsetToCube(tilePosition)); } } }
private IEnumerator SpawnStartingGems() { var tilemaps = _grid.GetComponentsInChildren <Tilemap>(); Tilemap startingPoints = null; foreach (var tileMap in tilemaps) { if (tileMap.name == "StartingPoints") { startingPoints = tileMap; } } if (startingPoints == null) { throw new Exception("No StartingPoints tilemap found"); } startingPoints.CompressBounds(); var coroutines = new List <Coroutine>(); foreach (var position in startingPoints.cellBounds.allPositionsWithin) { var cubeCoord = CoordinateUtils.OffsetToCube(position); if (startingPoints.GetTile(position) == _redGemTile) { coroutines.Add(StartCoroutine(GemPlacementManager.Instance.PutGem(GemType.Red, cubeCoord))); } if (startingPoints.GetTile(position) == _blueGemTile) { coroutines.Add(StartCoroutine(GemPlacementManager.Instance.PutGem(GemType.Blue, cubeCoord))); } } Destroy(startingPoints.gameObject); EffectsManager.Instance.PlayAppearSound(); foreach (var coroutine in coroutines) { yield return(coroutine); } GameManager.Instance.BoardInitialized(); }
/// <summary> /// Returns a Range object matching the specified range string, but relative to /// the top left corner of this Range. The Microsoft Excel equivalent of this /// method is Range.Range. /// </summary> /// <param name="rangeString"> /// For example, "A2:IV65536" or "B3" /// </param> public Range RelativeRange(string rangeString) { ( int relMinRowIndex, int relMinColIndex, int relMaxRowIndex, int relMaxColIndex ) = CoordinateUtils.RangeStringToCoords(rangeString); return(new Range( this._minRowIndex + relMinRowIndex - 1, this._minColIndex + relMinColIndex - 1, this._minRowIndex + relMaxRowIndex - 1, this._minColIndex + relMaxColIndex - 1, this._type, this._worksheet, this._document )); }
/// <summary> /// 获取最后生成的照片点图层 /// </summary> /// <returns></returns> public ILayer GetPhotosLayer() { IFeatureClass featureclass = CreateFeatureClass(); IFeatureCursor featureCursor = featureclass.Insert(true); //遍历照片链表 以创建缓存的形式插入数据 foreach (var p in PhotoList) { IPoint pPoint = new PointClass(); //坐标转换 var t = CoordinateUtils.gcj02_To_Wgs84(p.latitude, p.longtitude); pPoint.PutCoords(t.longtitude, t.latitude); pPoint.SpatialReference = mainMapControl.SpatialReference; pPoint.Project(mainMapControl.SpatialReference); IFeatureBuffer featureBuffer = featureclass.CreateFeatureBuffer(); featureBuffer.Shape = pPoint; featureBuffer.set_Value(featureBuffer.Fields.FindField("Name"), p.name); featureBuffer.set_Value(featureBuffer.Fields.FindField("Latitude"), p.latitude); featureBuffer.set_Value(featureBuffer.Fields.FindField("Longtitude"), p.longtitude); featureBuffer.set_Value(featureBuffer.Fields.FindField("OSSpath"), p.osspath); featureCursor.InsertFeature(featureBuffer); } featureCursor.Flush(); //创建图层 IFeatureLayer pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.FeatureClass = featureclass; pFeaturelayer.Name = "特征地物照片点"; //修饰该图层 ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare; var pRgbColor = ColorUtils.GetRgbColor(186, 114, 208); pMarkerSymbol.Color = pRgbColor; ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = (ISymbol)pMarkerSymbol; (pFeaturelayer as IGeoFeatureLayer).Renderer = pSimpleRenderer as IFeatureRenderer; return(pFeaturelayer as ILayer); }
/// <summary> /// Convert 2 dimensional result array to a one dimensional DEM array for tilebuilder /// </summary> /// <param name="minElev"></param> /// <param name="maxElev"></param> /// <returns></returns> private void ConvertGridToDEM(float minElev, float maxElev) { _log.LogDebug($"Tile.({TileX},{TileY}) ConvertGridToDEM, MinElev:{minElev}, MaxElev:{maxElev}, GridSize:{TileGridSize}, FirstPos:{GriddedElevDataArray[0, 0].Easting},{GriddedElevDataArray[0, 0].Northing},{GriddedElevDataArray[0, 0].Elevation}"); ElevData.MaximumHeight = maxElev; ElevData.MinimumHeight = minElev; var defaultElev = LowestElevation; var yRange = TileBoundaryLL.North - TileBoundaryLL.South; var xRange = TileBoundaryLL.East - TileBoundaryLL.West; var xStep = xRange / (TileGridSize - 1); var yStep = yRange / (TileGridSize - 1); var k = 0; for (int y = 0; y < TileGridSize; y++) { for (int x = 0; x < TileGridSize; x++) { // calculate LL position var lat = TileBoundaryLL.South + (y * yStep); var lon = TileBoundaryLL.West + (x * xStep); var elev = GriddedElevDataArray[x, y].Elevation == CellPassConsts.NullHeight ? defaultElev : GriddedElevDataArray[x, y].Elevation; if (elev < ElevData.MinimumHeight) { ElevData.MinimumHeight = elev; // reset to base } ElevData.EcefPoints[k] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(lon), Y = MapUtils.Deg2Rad(lat), Z = elev }); if (ElevData.ElevGrid[k] != elev) { ElevData.ElevGrid[k] = elev; // missing data set to lowest } k++; } } // Normal Calculation if (ElevData.HasLighting) { ComputeNormalMap(); } }
public void MakeEmptyTile(LLBoundingBox boundary, bool hasLighting) { HasLighting = hasLighting; if (GridSize != QMConstants.FlatResolutionGridSize) { GridSize = QMConstants.FlatResolutionGridSize; Array.Resize(ref ElevGrid, GridSize * GridSize); Array.Resize(ref EcefPoints, GridSize * GridSize); if (hasLighting) { VertexNormals = new byte[GridSize * GridSize * 2]; Triangles = new Triangle[(GridSize - 1) * (GridSize - 1) * 2]; } } Clear(); HasData = false; East = boundary.East; West = boundary.West; North = boundary.North; South = boundary.South; MaximumHeight = LowestElevation; MinimumHeight = LowestElevation; EcefPoints[0] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(East), Y = MapUtils.Deg2Rad(South), Z = LowestElevation }); EcefPoints[1] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(West), Y = MapUtils.Deg2Rad(South), Z = LowestElevation }); EcefPoints[2] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(East), Y = MapUtils.Deg2Rad(North), Z = LowestElevation }); EcefPoints[3] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(West), Y = MapUtils.Deg2Rad(North), Z = LowestElevation }); }
private IEnumerator AnimateHexPins(Vector3Int cubeCoordinates) { var neighbours = CoordinateUtils.Neighbours(cubeCoordinates); var directions = neighbours.Where(n => GemPlacementManager.Instance.GemTypeAt(n) != GemType.None && GemPlacementManager.Instance.GemTypeAt(n) != _currentPlayer) .Select(n => CoordinateUtils.GetDirection(cubeCoordinates, n)) .ToList(); if (directions.Count == 0) { yield return(null); } else { yield return(Instantiate( _hexPinsPrefab, GridManager.Instance.GetTileCenterPosition(cubeCoordinates), Quaternion.identity) .Animate(directions, _currentPlayer)); } }
/// <summary> /// Returns a range made of columns. For example, /// FromColumnRange("AB") or FromColumnRange("B:IV"). /// </summary> public static Range FromColumnRange( string columnNameRange, Worksheet worksheet, SLDocument document ) { string[] colNames = columnNameRange.Contains(":") ? columnNameRange.Split(new char[] { ':' }) : new string[] { columnNameRange, columnNameRange }; int minColIndex = CoordinateUtils.ToColumnIndex(colNames[0]); int maxColIndex = CoordinateUtils.ToColumnIndex(colNames[1]); return(new ExcelWrapper.Range( 1, minColIndex, ROW_INDEX_INFINITY, maxColIndex, RangeType.Columns, worksheet, document )); }
public void BoundingSphere_CoordinateUtils_CalculateHeader() { var ecefPoints = new Vector3[4]; ecefPoints[0] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(1.00001), Y = MapUtils.Deg2Rad(1.00001), Z = 0 }); ecefPoints[1] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(1.00002), Y = MapUtils.Deg2Rad(1.00001), Z = 0 }); ecefPoints[2] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(1.00001), Y = MapUtils.Deg2Rad(1.00002), Z = 10 }); ecefPoints[3] = CoordinateUtils.geo_to_ecef(new Vector3() { X = MapUtils.Deg2Rad(1.00002), Y = MapUtils.Deg2Rad(1.00002), Z = 10 }); BBSphere sphere = new BBSphere(); sphere.FromPoints(ecefPoints); var rad = Math.Round(sphere.Radius, 2); rad.Should().Be(5.06); var geo = CoordinateUtils.ecef_to_geo(sphere.Center); var alt = Math.Round(geo.Z, 1); alt.Should().Be(5.0); var lon = Math.Round(MapUtils.Rad2Deg(geo.X), 6); var lat = Math.Round(MapUtils.Rad2Deg(geo.Y), 6); lon.Should().Be(1.000015); lat.Should().Be(1.000015); }
private static bool InSplitRange(Vector3Int from, Vector3Int to) { return(CoordinateUtils.CubeDistance(from, to) == 2); }
public Ring() { A = CoordinateUtils.SetCoordinate("A"); InR = InputReader.GetIntValue("Введите внутренний радиус: "); ExR = InputReader.GetIntValue("Введите внешний радиус: "); }
public Line() { A = CoordinateUtils.SetCoordinate("A"); B = CoordinateUtils.SetCoordinate("B"); }
public Triangle() { A = CoordinateUtils.SetCoordinate("A"); B = CoordinateUtils.SetCoordinate("B"); C = CoordinateUtils.SetCoordinate("C"); }
private void SetTile(Vector3Int cubeCoordinates, TileBase hexTile) { var offsetCoordinates = CoordinateUtils.CubeToOffset(cubeCoordinates); _board.SetTile(offsetCoordinates, hexTile); }
private List <Vector3Int> ValidNeighbours(Vector3Int cell) { return(CoordinateUtils.Neighbours(cell) .Where(Grid.Contains) .ToList()); }
public void DeselectTile(Vector3Int cubeCoordinates) { _board.SetTile(CoordinateUtils.CubeToOffset(cubeCoordinates), _hexTile); }
public Round() { A = CoordinateUtils.SetCoordinate("A"); R = InputReader.GetIntValue("Введите радиус: "); }
public Vector3 GetTileCenterPosition(Vector3Int cubeCoordinates) { return(Board.GetCellCenterWorld(CoordinateUtils.CubeToOffset(cubeCoordinates))); }