public void GetItems(Line line, IntegerHandler callback) { Vector2 start = line.DebutV2; Vector2 direction = line.FinV2 - start; Vector2 multipliedDirection; float length = line.Longueur; direction.Normalize(); bool wantsNext = true; for (int i = 0; i < length; i += CellSize / 2) { Vector2.Multiply(ref direction, i, out multipliedDirection); Vector2 position; Vector2.Add(ref start, ref multipliedDirection, out position); Vector2.Subtract(ref position, ref SpaceUpperLeft, out position); Vector2.Divide(ref position, CellSize, out position); int x_1 = (int) position.X; int y_1 = (int) position.Y; if (x_1 >= 0 && x_1 < NbColumns && y_1 >= 0 && y_1 < NbRows) for (int k = 0; k < Grid[y_1][x_1].Count; k++) { if (!wantsNext) return; wantsNext = callback(Grid[y_1][x_1][k]); } } }
public IEnumerable<int> GetItems(Line line) { Vector2 start = line.DebutV2; Vector2 direction = line.FinV2 - start; Vector2 multipliedDirection; float length = line.Longueur; direction.Normalize(); for (int i = 0; i < length; i+= CellSize / 2) { Vector2.Multiply(ref direction, i, out multipliedDirection); Vector2 position; Vector2.Add(ref start, ref multipliedDirection, out position); Vector2.Subtract(ref position, ref SpaceUpperLeft, out position); Vector2.Divide(ref position, CellSize, out position); int x_1 = (int)position.X; int y_1 = (int)position.Y; if (x_1 >= 0 && x_1 < NbColumns && y_1 >= 0 && y_1 < NbRows) for (int k = 0; k < Grid[y_1][x_1].Count; k++) yield return Grid[y_1][x_1][k]; } }
public static bool LineRectangleCollision(Line line, PhysicalRectangle rectangle) { return Collisions.LineRectangleCollision(line, rectangle); }