/// <summary> /// Numbers the of cells text changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="TextChangedEventArgs"/> instance containing the event data.</param> private void NumberOfCellsTextChanged(object sender, TextChangedEventArgs e) { var textBox = sender as TextBox; if (textBox != null) { int number; var success = int.TryParse(((TextBox)sender).Text, out number); if (success & number >= 0) { TotalCells = number; ResetGridAttributes(); InitializeGrid(); } else { textBox.Text = TotalCells.ToString(CultureInfo.InvariantCulture); } } }
public void Query(Vector2 position, float radius, Action <IEnumerable <SpaceUnit> > actionOnFoundUnits) { Point start = new Point( (int)Math.Floor((position.X - radius) / CellSize.X), (int)Math.Floor((position.Y - radius) / CellSize.Y)); Point end = new Point( (int)Math.Ceiling((position.X + radius) / CellSize.X), (int)Math.Ceiling((position.Y + radius) / CellSize.Y)); start = Vector2.Clamp(start.ToVector2(), Vector2.Zero, TotalCells.ToVector2()).ToPoint(); end = Vector2.Clamp(end.ToVector2(), Vector2.Zero, TotalCells.ToVector2()).ToPoint(); for (int y = start.Y; y < end.Y; y++) { for (int x = start.X; x < end.X; x++) { //if (Circle.Intercects(position, radius, new Rectangle(new Point(x, y) * CellSize, CellSize))) actionOnFoundUnits.Invoke(Cells[y][x]); } } }