private static XYPoint MovePoint <L>( IDictionary <XYPoint, SupportRectangleWithId> points, L quadTree, Random random, SupportQuadTreeConfig config, AdderUnique <L> adder, Remover <L> remover) { var coordinates = points.Keys.ToArray(); XYPoint oldCoordinate; XYPoint newCoordinate; while (true) { oldCoordinate = coordinates[random.Next(coordinates.Length)]; var direction = random.Next(4); var newX = oldCoordinate.X; var newY = oldCoordinate.Y; if (direction == 0 && newX > config.X) { newX--; } if (direction == 1 && newY > config.Y) { newY--; } if (direction == 2 && newX < config.X + config.Width - 1) { newX++; } if (direction == 3 && newY < config.Y + config.Height - 1) { newY++; } newCoordinate = new XYPoint(newX, newY); if (!points.ContainsKey(newCoordinate)) { break; } } var moved = points.Delete(oldCoordinate); remover.Invoke(quadTree, moved); moved.X = newCoordinate.X; moved.Y = newCoordinate.Y; adder.Invoke(quadTree, moved); points.Put(newCoordinate, moved); // Comment-me-in: // log.info("Moving " + moved.getId() + " from " + printPoint(oldCoordinate.getX(), oldCoordinate.getY()) + " to " + printPoint(newCoordinate.getX(), newCoordinate.getY())); return(newCoordinate); }
public SupportQuadTreeToolUnique( Factory <L> factory, Generator generator, AdderUnique <L> adderUnique, Remover <L> remover, Querier <L> querier, bool pointInsideChecking) { this.factory = factory; this.generator = generator; this.adderUnique = adderUnique; this.remover = remover; this.querier = querier; this.pointInsideChecking = pointInsideChecking; }