Example #1
0
        public static IEnumerable <HexagonLocationUV> GetHexagonsIntersectedByLine(PointXY startPoint, PointXY endPoint, HexagonDefinition hexagonDefinition)
        {
            var startHexagon = HexagonUtils.GetHexagonLocationUVForPointXY(startPoint, hexagonDefinition);
            var endHexagon   = HexagonUtils.GetHexagonLocationUVForPointXY(endPoint, hexagonDefinition);

            var minU = new[] { startHexagon.U, endHexagon.U }.Min() - 1;
            var maxU = new[] { startHexagon.U, endHexagon.U }.Max() + 1;

            var minV = new[] { startHexagon.V, endHexagon.V }.Min() - 1;
            var maxV = new[] { startHexagon.V, endHexagon.V }.Max() + 1;

            var matchingHexagons = new List <HexagonLocationUV>();

            for (var u = minU; u <= maxU; u++)
            {
                for (var v = minV; v <= maxV; v++)
                {
                    var points = HexagonUtils.GetPointsXYOfHexagon(new HexagonLocationUV(u, v), hexagonDefinition);

                    for (var k = 0; k < points.Count() - 1; k++)
                    {
                        var p0 = points[k];
                        var p1 = points[k + 1];

                        if (GetLineIntersection(p0, p1, startPoint, endPoint) != null)
                        {
                            matchingHexagons.Add(new HexagonLocationUV(u, v));
                            break;
                        }
                    }
                }
            }

            return(matchingHexagons);
        }
Example #2
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)));
                    }
                }
            }
        }
Example #3
0
        public void GetHexagonLocationUVForPointXY(double x, double y, int u, int v)
        {
            var hexagonLocationUV = HexagonUtils.GetHexagonLocationUVForPointXY(new PointXY(x, y), _hexagonDefinition);

            Assert.Equal(new HexagonLocationUV(u, v), hexagonLocationUV);
        }