/// <summary>Construct a new instance of extent <paramref name="sizeHexes"/> and /// initialized using <paramref name="initializer"/>.</summary> public BlockedBoardStorage32x32(HexSize sizeHexes, Func <HexCoords, T> initializer) : base(sizeHexes) { backingStore = new List <List <List <T> > >((MapSizeHexes.Height + _buffer) / _grouping); for (var y = 0; y < backingStore.Capacity; y++) { backingStore.Add(new List <List <T> >((MapSizeHexes.Width + _buffer) / _grouping)); for (var x = 0; x < backingStore[y].Capacity; x++) { backingStore[y].Add(new List <T>(_grouping * _grouping)); } } var result = Parallel.For(0, backingStore.Capacity, y => { var boardRow = backingStore[y]; for (var x = 0; x < boardRow.Capacity; x++) { var boardCell = backingStore[y][x]; for (var i = 0; i < _grouping; i++) { for (var j = 0; j < _grouping; j++) { var coords = HexCoords.NewUserCoords(x * _grouping + j, y * _grouping + i); boardCell.Add(IsOnboard(coords) ? initializer(coords) : default(T)); } } } }); }
/// <summary>Return the coordinate vector of this hex in the User frame.</summary> public HexCoords CustomToUser(IntVector2D coords) => HexCoords.NewUserCoords(coords * MatrixUserToCustom);
/// <summary>Return the coordinate vector of this hex in the User frame.</summary> public static HexCoords CustomToUser(this IntVector2D @this) { return(HexCoords.NewUserCoords(@this * MatrixUserToCustom)); }
/// <summary>By default, landmark all four corners and midpoints of all 4 sides.</summary> /// <remarks>Pre-processing time on start-up can be reduced by decreasing the number of landmarks, /// though at the possible expense of longer path-finding times.</remarks> /// <param name="size"></param> protected static IFastList <HexCoords> DefaultLandmarks(HexSize size) { return(new HexPoint[] { new HexPoint(0, 0), new HexPoint(size.Width / 2, 0), new HexPoint(size.Width - 1, 0), new HexPoint(0, size.Height / 2), new HexPoint(size.Width - 1, size.Height / 2), new HexPoint(0, size.Height - 1), new HexPoint(size.Width / 2, size.Height - 1), new HexPoint(size.Width - 1, size.Height - 1) }.Select(p => HexCoords.NewUserCoords(p)).ToFastList()); }
/// <inheritdoc/> public virtual Point ScrollPositionToCenterOnHex(HexCoords coordsNewCenterHex) { return(HexCenterPoint(HexCoords.NewUserCoords( coordsNewCenterHex.User - (new IntVector2D(Host.VisibleRectangle.Size.User) / 2) ))); }
/// <summary>Returns the scroll position to center a specified hex in viewport.</summary> /// <param name="this"></param> /// <param name="coordsNewCenterHex"><c>HexCoords</c> for the hex to be centered in viewport.</param> /// <param name="visibleRectangle"></param> /// <returns>Pixel coordinates in Client reference frame.</returns> public static HexPoint ScrollPositionToCenterOnHex(this IHexgrid @this, HexCoords coordsNewCenterHex, CoordsRectangle visibleRectangle) => @this.HexCenterPoint(HexCoords.NewUserCoords(coordsNewCenterHex.User - (visibleRectangle.Size.User / 2)));