public HexagonBuilder SetNextHexagons() { _hex.NearHexagons = new List <Point>(); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X, (float)(_hex.Center.Y + 2 * GeometryOperation.GetHeight()) ) ) ); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X + (GeometryOperation.CurSize * 3) / 2, (float)(_hex.Center.Y + GeometryOperation.GetHeight()) ) ) ); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X + (GeometryOperation.CurSize * 3) / 2, (float)(_hex.Center.Y - GeometryOperation.GetHeight()) ) ) ); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X, (float)(_hex.Center.Y - GeometryOperation.GetHeight() * 2) ) ) ); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X - (GeometryOperation.CurSize * 3) / 2, (float)(_hex.Center.Y - GeometryOperation.GetHeight()) ) ) ); _hex.NearHexagons.Add( Point.Round( new PointF( _hex.Center.X - (GeometryOperation.CurSize * 3) / 2, (float)(_hex.Center.Y + GeometryOperation.GetHeight()) ) ) ); return(this); }
private Point GetNearestCenter(Point input) { foreach (Hexagon hex in _map) { if (GeometryOperation.IsPointInHex(hex.Faces, input)) { return(hex.Center); } } return(Point.Empty); }
private Point SearchNextNode(Point start, Point end) { List <Point> line = GeometryOperation.GetPointsInLine(start, end); foreach (var hex in _near.Keys.Join(_near.Where(l => l.Key.Center.Equals(start)).FirstOrDefault() .Value, o => o.Center, i => i, (o, i) => new { o.Faces, o.Center })) { foreach (Point p in line) { if (GeometryOperation.IsPointInHex(hex.Faces, p)) { return(hex.Center); } } } return(Point.Empty); }
private void DenyCenter(Point hexCenter) { int size = 20; int h = (int)Math.Round(GeometryOperation.GetHeight()); int w = (int)Math.Round(GeometryOperation.GetProiection()); Point pointDenied = new Point(hexCenter.X - size, hexCenter.Y - h); _pointsDone.Add(hexCenter); for (int index_x = 0; index_x <= w * 2 + size; index_x++) { for (int index_y = 0; index_y <= h * 2; index_y++) { _pointsDone.Add(new Point(pointDenied.X + index_x, pointDenied.Y + index_y)); } } }
public HexagonBuilder BuildHexagon(Point center) { _hex = new Hexagon() { Center = center, Faces = new List <Face>() }; // Side 1 _hex.Faces.Add(new Face() { Points = new Point[] { Point.Round( new PointF( center.X - GeometryOperation.CurSize / 2, (float)(center.Y + GeometryOperation.GetHeight()) ) ), Point.Round( new PointF( center.X + GeometryOperation.CurSize / 2, (float)(center.Y + GeometryOperation.GetHeight()) ) ) } }); // Side 2 _hex.Faces.Add(new Face() { Points = new Point[] { Point.Round( new PointF( center.X + GeometryOperation.CurSize / 2, (float)(center.Y + GeometryOperation.GetHeight()) ) ), new Point(GeometryOperation.CurSize + center.X, center.Y) } }); // Side 3 _hex.Faces.Add(new Face() { Points = new Point[] { new Point(GeometryOperation.CurSize + center.X, center.Y), Point.Round( new PointF( center.X + GeometryOperation.CurSize / 2, (float)(center.Y - GeometryOperation.GetHeight()) ) ) } }); // Side 4 _hex.Faces.Add(new Face() { Points = new Point[] { Point.Round( new PointF( center.X + GeometryOperation.CurSize / 2, (float)(center.Y - GeometryOperation.GetHeight()) ) ), Point.Round( new PointF( center.X - GeometryOperation.CurSize / 2, (float)(center.Y - GeometryOperation.GetHeight()) ) ) } }); // Side 5 _hex.Faces.Add(new Face() { Points = new Point[] { Point.Round( new PointF( center.X - GeometryOperation.CurSize / 2, (float)(center.Y - GeometryOperation.GetHeight()) ) ), new Point(center.X - GeometryOperation.CurSize, center.Y) } }); // Side 6 _hex.Faces.Add(new Face() { Points = new Point[] { new Point(center.X - GeometryOperation.CurSize, center.Y), Point.Round( new PointF( center.X - GeometryOperation.CurSize / 2, (float)(center.Y + GeometryOperation.GetHeight()) ) ) } }); return(this); }