Skip to content

Commit bc702ab

Browse files
jonsberndtseanmcleod
authored andcommitted
Added error handling in FGWaypoint in case a supplied or calculated latitude exceeds 90 degrees prior (JSBSim-Team#536)
Co-authored-by: Sean McLeod <sean@seanmcleod.com>
1 parent a8ef2fa commit bc702ab

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/models/flight_control/FGWaypoint.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,37 @@ bool FGWaypoint::Run(void )
182182
double target_longitude_rad = target_longitude->GetValue() * target_longitude_unit;
183183
source.SetPosition(source_longitude_rad, source_latitude_rad, radius);
184184

185+
if (fabs(target_latitude_rad) > M_PI/2.0) {
186+
cerr << endl;
187+
cerr << "Target latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl;
188+
cerr << "(is longitude being mistakenly supplied?)" << endl;
189+
cerr << endl;
190+
throw("Waypoint target latitude exceeded 90 degrees.");
191+
}
192+
193+
if (fabs(source_latitude_rad) > M_PI/2.0) {
194+
cerr << endl;
195+
cerr << "Source latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl;
196+
cerr << "(is longitude being mistakenly supplied?)" << endl;
197+
cerr << endl;
198+
throw("Source latitude exceeded 90 degrees.");
199+
}
200+
185201
if (WaypointType == eHeading) { // Calculate Heading
202+
186203
double heading_to_waypoint_rad = source.GetHeadingTo(target_longitude_rad,
187204
target_latitude_rad);
188205

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

192209
} else { // Calculate Distance
210+
193211
double wp_distance = source.GetDistanceTo(target_longitude_rad,
194212
target_latitude_rad);
195-
196213
if (eUnit == eMeters) Output = FeetToMeters(wp_distance);
197214
else Output = wp_distance;
215+
198216
}
199217

200218
Clip();

0 commit comments

Comments
 (0)