// Checks whether the planes received from the decoder are in the defined airspace public void DetectAirplaneInAirspace(object sender, PlaneDecodedEventArgs e) { List <FlightData> planesInAirspace = new List <FlightData>(); // List in which to store the planes that are within the airspace foreach (var plane in e.Planes) // Iterates through the planes sent from the decoder { // Checks to see if the given plane is within the boundaries of the airspace, and if it is, adds it to the aforementioned list if ((Math.Abs(plane.xCoordinate - _airspace.Center._x) <= (_airspace.SideLength / 2)) && (Math.Abs(plane.yCoordinate - _airspace.Center._y) <= (_airspace.SideLength / 2)) && (plane.zCoordinate >= _airspace.MinHeight) && (plane.zCoordinate <= _airspace.MaxHeight)) { planesInAirspace.Add(plane); } } // Invokes an event if there are planes present in the airspace if (planesInAirspace.Count > 0) { OnAirplaneDetected(new PlaneDetectorEventArgs { PlanesInAirspace = planesInAirspace }); } }
private void OnPlaneDecodedEvent(PlaneDecodedEventArgs e) { PlaneDecodedEvent?.Invoke(this, e); }