コード例 #1
0
        public void GetHexagonsInsideBoundingBox()
        {
            IList <HexagonLocationUV> resultsA = HexagonUtils
                                                 .GetHexagonsInsideBoundingBox(new PointXY(0, -20), new PointXY(450, 100), _hexagonDefinition).ToList();

            Assert.Equal(resultsA[0], new HexagonLocationUV(0, 0));
            Assert.Equal(resultsA[1], new HexagonLocationUV(0, 1));
            Assert.Equal(resultsA[2], new HexagonLocationUV(1, -1));
            Assert.Equal(resultsA[3], new HexagonLocationUV(1, 0));
            Assert.Equal(resultsA[4], new HexagonLocationUV(2, -1));
            Assert.Equal(resultsA[5], new HexagonLocationUV(2, 0));
            Assert.Equal(resultsA[6], new HexagonLocationUV(3, -2));
            Assert.Equal(resultsA[7], new HexagonLocationUV(3, -1));

            IList <HexagonLocationUV> resultsB = HexagonUtils
                                                 .GetHexagonsInsideBoundingBox(new PointXY(0, -20), new PointXY(320, 20), _hexagonDefinition).ToList();

            Assert.Equal(resultsB[0], new HexagonLocationUV(0, 0));
            Assert.Equal(resultsB[1], new HexagonLocationUV(1, -1));
            Assert.Equal(resultsB[2], new HexagonLocationUV(1, 0));
            Assert.Equal(resultsB[3], new HexagonLocationUV(2, -1));

            IList <HexagonLocationUV> resultsC = HexagonUtils
                                                 .GetHexagonsInsideBoundingBox(new PointXY(150, -20), new PointXY(320, 20), _hexagonDefinition).ToList();

            Assert.Equal(resultsC[0], new HexagonLocationUV(1, -1));
            Assert.Equal(resultsC[1], new HexagonLocationUV(1, 0));
            Assert.Equal(resultsC[2], new HexagonLocationUV(2, -1));
        }
コード例 #2
0
        public IActionResult Get(int z, int x, int y)
        {
            using (var destinationImage = new Image <Rgba32>(TileSize, TileSize))
            {
                if (z >= 7)
                {
                    var hexSize = 500;


                    var size = (int)(hexSize / Math.Pow(2, 10 - z));

                    var hexagonDefinition = new HexagonDefinition(size, 10);

                    //Tile offset
                    var pixelX = x * TileSize;
                    var pixelY = y * TileSize;

                    var topLeft     = new PointXY(pixelX - size, pixelY - size);
                    var bottomRight = new PointXY(pixelX + TileSize + size, pixelY + TileSize + size);

                    foreach (HexagonLocationUV hexagon in HexagonUtils.GetHexagonsInsideBoundingBox(topLeft, bottomRight, hexagonDefinition))
                    {
                        PointXY center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagon, hexagonDefinition);

                        IList <PointXY> hexagonPoints = HexagonUtils
                                                        .GetHexagonPixels(size, new PointXY(center.X - pixelX, center.Y - pixelY)).ToList();

                        PointF[] points = hexagonPoints.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray();

                        destinationImage.Mutate(ctx => ctx

                                                .DrawLines(
                                                    new Rgba32(200, 200, 200, 200),
                                                    5,
                                                    points)
                                                .DrawLines(
                                                    new Rgba32(100, 100, 100, 200),
                                                    2,
                                                    points));
                    }
                }

                Stream outputStream = new MemoryStream();

                destinationImage.Save(outputStream, new PngEncoder());
                outputStream.Seek(0, SeekOrigin.Begin);
                return(this.File(outputStream, "image/png"));
            }
        }
コード例 #3
0
        public IEnumerable <Hexagon> ProcessArea(GeoData geoData, LayersLoaderTarget[] targets = null)
        {
            foreach (PointXY[] geoCoordinates in geoData.Points)
            {
                var topLeftCoordinate     = new PointXY(geoCoordinates.Min(c => c.X), geoCoordinates.Min(c => c.Y));
                var bottomRightCoordinate = new PointXY(geoCoordinates.Max(c => c.X), geoCoordinates.Max(c => c.Y));

                var hexagonLocations = HexagonUtils.GetHexagonsInsideBoundingBox(topLeftCoordinate, bottomRightCoordinate, hexagonDefinition);

                foreach (var hexagonLocation in hexagonLocations)
                {
                    var center = HexagonUtils.GetCenterPointXYOfHexagonLocationUV(hexagonLocation, hexagonDefinition);

                    if (AreaHelper.IsPointInsidePolygon(center.X, center.Y, geoCoordinates))
                    {
                        yield return(CreateHexagon(geoData, targets, hexagonLocation, (geo, target) => geo.Values[target.SourceField]));
                    }
                }
            }
        }
コード例 #4
0
        private IEnumerable <Hexagon> ProcessPixel(GeoData geoData, LayersLoaderTarget[] targets)
        {
            foreach (PointXY[] coordinates in geoData.Points)
            {
                if (coordinates.Length == 1)
                //Single point mode
                {
                    var hexagonLocation = HexagonUtils.GetHexagonLocationUVForPointXY(coordinates[0], hexagonDefinition);

                    yield return(CreateHexagon(geoData, targets, hexagonLocation, (geo, target) => target.Handler == null ? 1 : valueHandlerFactory.GetInstance(target.Handler).GetValue(geo)));
                }
                else
                //Square mode
                {
                    IList <HexagonLocationUV> hexagons = HexagonUtils.GetHexagonsInsideBoundingBox(coordinates[0], coordinates[1], hexagonDefinition).ToList();

                    foreach (var hexagonLocation in hexagons)
                    {
                        yield return(CreateHexagon(geoData, targets, hexagonLocation, (geo, target) => target.Handler == null ? 1 : valueHandlerFactory.GetInstance(target.Handler).GetValue(geo)));
                    }
                }
            }
        }