示例#1
0
        /// <summary>
        ///     Obtains the center point (x,y) of an hexagon given its LocationUv (u,v)
        /// </summary>
        /// <param name="location"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns></returns>
        public static PointXY GetCenterPointXYOfHexagonLocationUV(HexagonLocationUV location,
                                                                  HexagonDefinition hexagonDefinition)
        {
            var x = hexagonDefinition.NarrowWidth * location.U;
            var y = hexagonDefinition.Height * (location.U * 0.5 + location.V);

            return(new PointXY(x, y));
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns></returns>
        public static int GetDistanceBetweenHexagonLocationUVs(HexagonLocationUV source, HexagonLocationUV destination,
                                                               HexagonDefinition hexagonDefinition)
        {
            var du = destination.U - source.U;
            var dv = destination.V - source.V;

            return(du * dv > 0 ? Math.Abs(du + dv) : Math.Max(Math.Abs(du), Math.Abs(dv)));
        }
示例#3
0
        /// <summary>
        ///     Determines if a specified point (x,y) is inside a given hexagon Location (u,v)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="location"></param>
        /// <param name="hexagonDefinition"></param>
        /// <returns>True if inside the hexagon, false otherwise</returns>
        public static bool IsPointXYInsideHexagonLocationUV(PointXY point, HexagonLocationUV location,
                                                            HexagonDefinition hexagonDefinition)
        {
            var center = GetCenterPointXYOfHexagonLocationUV(location, hexagonDefinition);

            var d  = hexagonDefinition.Diameter;
            var dx = Math.Abs(point.X - center.X) / d;
            var dy = Math.Abs(point.Y - center.Y) / d;
            var a  = 0.25 * Math.Sqrt(3.0);

            return(dy <= a && a * dx + 0.25 * dy <= 0.5 * a);
        }
示例#4
0
        public static IList <PointXY> GetPointsXYOfHexagon(HexagonLocationUV location, HexagonDefinition hexagonDefinition)
        {
            var center = GetCenterPointXYOfHexagonLocationUV(location, hexagonDefinition);

            return(new List <PointXY>
            {
                new PointXY(center.X - hexagonDefinition.Diameter / 2.0, center.Y),
                new PointXY(center.X - hexagonDefinition.EdgeSize / 2.0, center.Y - hexagonDefinition.Height / 2.0),
                new PointXY(center.X + hexagonDefinition.EdgeSize / 2.0, center.Y - hexagonDefinition.Height / 2.0),
                new PointXY(center.X + hexagonDefinition.Diameter / 2.0, center.Y),
                new PointXY(center.X + hexagonDefinition.EdgeSize / 2.0, center.Y + hexagonDefinition.Height / 2.0),
                new PointXY(center.X - hexagonDefinition.EdgeSize / 2.0, center.Y + hexagonDefinition.Height / 2.0),
                new PointXY(center.X - hexagonDefinition.Diameter / 2.0, center.Y)
            });
        }
示例#5
0
 private bool Equals(HexagonLocationUV other)
 {
     return(U == other.U && V == other.V);
 }