public void RequestCarTest(double gX, double gY, double eX, double eY, DirectionCar direction) { var road = new Road(new Vector(0, 50), new Vector(100, 50), 10, 100); var garage1 = new Garage(new Vector(80, 20), 10); var garage2 = new Garage(new Vector(20, 80), 10); var building = new Building(new Vector(gX, gY), 1); var city = new CityBuilder() .Road(road) .Building(garage1) .Building(garage2) .Building(building) .Build(); var group = new CustomerGroup(1, building, building); GPSSystem.RequestCar(new Destination { Road = road, Location = building.Location }, group); Assert.IsNotEmpty(city.Cars); var car = city.Cars[0]; Assert.AreEqual(eX, car.Location.X, 0.5); Assert.AreEqual(eY, car.Location.Y, 0.5); Assert.AreEqual(direction, car.Direction); }
public void TestOutOfRangeCollisionSensor(Direction directionSensor, DirectionCar directionCar, double range, double carX, double carY, double secCarX, double secCarY) { var city = new CityBuilder() .Road(new Vector(10, 0), new Vector(10, 50), 40) .Build(); var sensorCar = new CarBuilder() .Location(new Vector(carX, carY)) .Direction(directionCar) .Sensor(car => new CollisionSensor(car, directionSensor, range)) .Build(); city.Cars.Add(sensorCar); city.Cars.Add(new CarBuilder() .Location(new Vector(secCarX, secCarY)) .Direction(directionCar) .Build()); var sensor = sensorCar.Controller.GetSensors <CollisionSensor>(directionSensor).First(); sensor.SubScribeSensorEvent(EventThrownBad); sensor.Controller.Update(); Assert.Pass(); }
public Car CreateCar(int id, Vector location, Garage garage, DirectionCar direction) { var car = new Car(id, this, location, new List <Sensor>(), garage, direction, 5, 10); var sensors = Sensors .Select(prototype => prototype.Create(car, prototype.Direction, prototype.Range)) .ToList(); car.Sensors.AddRange(sensors); return(car); }
/// <summary> /// Checks if there are any cars in the range of the sensor with the sensors direction /// </summary> /// <param name="sensorDir">the Direction of a sensor</param> /// <returns>a list of cars in range</returns> private List <IEntity> GetEntitiesInRange(DirectionCar sensorDir) // TODO: Why is sensorDir not used? { var car = Sensor.Car; var range = Math.Min(car.CurrentRoad.Width / 4.0, Sensor.Range); var direction = car.Direction.RotateTo(Sensor.Direction); var add = Vector.Multiply(direction, car.Length / 2.0 + range / 2.0); var center = Vector.Add(car.Location, add); return(City.Instance.Controller.GetEntitiesInRange(center, range) .FindAll(entity => !entity.Equals(car))); }
/*[TestCase(35, 85, DirectionCar.North, 90, 60, 2, 3, 0, 90, 75)] * [TestCase(45, 5, DirectionCar.West, 45, 90, 5, 0, 3, 35, 70)] * [TestCase(35, 85, DirectionCar.North, 90, 60, 2, 2, 0, 102.5, 60)]*/ public void GetDirectionTest(double cX, double cY, DirectionCar direction, double dX, double dY, int road, int destRoad, int intersection, double eX, double eY) { var roads = new[] { new Road(new Vector(35, 80), new Vector(35, 100), 10, 0), new Road(new Vector(0, 75), new Vector(30, 75), 10, 0), new Road(new Vector(40, 75), new Vector(90, 75), 10, 0), new Road(new Vector(95, 70), new Vector(95, 10), 10, 0), new Road(new Vector(40, 5), new Vector(90, 5), 10, 0), new Road(new Vector(35, 10), new Vector(35, 70), 10, 0) }; var intersections = new[] { new Intersection(new Vector(35, 75), 10), new Intersection(new Vector(95, 75), 10), new Intersection(new Vector(95, 5), 10), new Intersection(new Vector(35, 5), 10) }; var city = new CityBuilder() .Road(roads[0]) .Road(roads[1]) .Road(roads[2]) .Road(roads[3]) .Road(roads[4]) .Road(roads[5]) .Intersection(intersections[0]) .Intersection(intersections[1]) .Intersection(intersections[2]) .Intersection(intersections[3]) .Build(); var car = new Car(1, CarModel.GetModel("TestModel"), new Vector(cX, cY), new List <Sensor>(), null, direction, 5, 5); city.Cars.Add(car); car.Destination = new Destination { Location = new Vector(dX, dY), Road = roads[destRoad] }; var carDestination = GPSSystem.GetDirection(car, intersections[intersection]); Assert.AreEqual(roads[road], carDestination.Road); Assert.AreEqual(eX, carDestination.Location.X, 0.01); Assert.AreEqual(eY, carDestination.Location.Y, 0.01); }
public void TestSpawnCar(double gx, double gy, DirectionCar direction, double ex, double ey) { var city = new CityBuilder() .Road(new Vector(10, 0), new Vector(10, 100), 10) .Road(new Vector(0, 90), new Vector(100, 90), 10) .Build(); var garage = new Garage(new Vector(gx, gy), 20); city.Buildings.Add(garage); var car = garage.SpawnCar(0, new Destination()); car.Direction = direction; Assert.AreEqual(ex, car.Location.X, 0.5); Assert.AreEqual(ey, car.Location.Y, 0.5); }
public static Vector GetVector(this DirectionCar current) { switch (current) { case DirectionCar.North: return(new Vector(0, -1)); case DirectionCar.East: return(new Vector(1, 0)); case DirectionCar.South: return(new Vector(0, 1)); case DirectionCar.West: return(new Vector(-1, 0)); default: throw new ArgumentException($"Unknown direction {current}"); } }
public static DirectionCar GetPrevious(this DirectionCar current) { switch (current) { case DirectionCar.North: return(DirectionCar.West); case DirectionCar.East: return(DirectionCar.North); case DirectionCar.South: return(DirectionCar.East); case DirectionCar.West: return(DirectionCar.South); default: throw new ArgumentException($"Unknown direction {current}"); } }
/// <summary> /// Converts the direction of the car into a direction of the sensor /// </summary> /// <param name="carDir">car direction</param> /// <returns>direction for the sensor</returns> private DirectionCar GetAbsoluteDirection(DirectionCar carDir) { switch (Sensor.Direction) { case Direction.Front: return(carDir); case Direction.Back: return(carDir.GetOpposite()); case Direction.Left: return(carDir.GetPrevious()); case Direction.Right: return(carDir.GetNext()); default: throw new ArgumentException($"Unknown direction {Sensor.Direction}"); } }
public static Vector RotateTo(this DirectionCar current, Direction rotation) { var direction = current.GetVector(); switch (rotation) { case Direction.Front: return(direction); case Direction.Right: return(new Vector(-direction.Y, direction.X)); case Direction.Left: return(new Vector(direction.Y, -direction.X)); case Direction.Back: return(new Vector(-direction.X, -direction.Y)); default: throw new ArgumentException($"Unknown rotation {rotation}"); } }
/// <summary> /// Calculate the relative angle between an absolute direction and a vector. /// </summary> public static double VectorToAngle(Vector vector, DirectionCar direction) { return(Vector.AngleBetween(vector, direction.GetVector())); }
public CarBuilder Direction(DirectionCar direction) { this.direction = direction; return(this); }