Skip to content

Commit

Permalink
Added error handling in FGWaypoint in case a supplied or calculated l…
Browse files Browse the repository at this point in the history
…atitude exceeds 90 degrees prior (#536)
  • Loading branch information
jonsberndt authored Dec 17, 2021
1 parent 9362e4f commit 01da461
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/models/flight_control/FGWaypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,37 @@ bool FGWaypoint::Run(void )
double target_longitude_rad = target_longitude->GetValue() * target_longitude_unit;
source.SetPositionGeodetic(source_longitude_rad, source_latitude_rad, 0.0);

if (fabs(target_latitude_rad) > M_PI/2.0) {
cerr << endl;
cerr << "Target latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl;
cerr << "(is longitude being mistakenly supplied?)" << endl;
cerr << endl;
throw("Waypoint target latitude exceeded 90 degrees.");
}

if (fabs(source_latitude_rad) > M_PI/2.0) {
cerr << endl;
cerr << "Source latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl;
cerr << "(is longitude being mistakenly supplied?)" << endl;
cerr << endl;
throw("Source latitude exceeded 90 degrees.");
}

if (WaypointType == eHeading) { // Calculate Heading

double heading_to_waypoint_rad = source.GetHeadingTo(target_longitude_rad,
target_latitude_rad);

if (eUnit == eDeg) Output = heading_to_waypoint_rad * radtodeg;
else Output = heading_to_waypoint_rad;

} else { // Calculate Distance

double wp_distance = source.GetDistanceTo(target_longitude_rad,
target_latitude_rad);

if (eUnit == eMeters) Output = FeetToMeters(wp_distance);
else Output = wp_distance;

}

Clip();
Expand Down

0 comments on commit 01da461

Please sign in to comment.