MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / calculateSpeed

Method calculateSpeed

src/Savegame/MovingTarget.cpp:148–170  ·  view source on GitHub ↗

* Calculates the speed vector based on the * great circle distance to destination and * current raw speed. */

Source from the content-addressed store, hash-verified

146 * current raw speed.
147 */
148void MovingTarget::calculateSpeed()
149{
150 if (_dest != 0)
151 {
152 double dLon, dLat, length;
153 dLon = sin(_dest->getLongitude() - _lon) * cos(_dest->getLatitude());
154 dLat = cos(_lat) * sin(_dest->getLatitude()) - sin(_lat) * cos(_dest->getLatitude()) * cos(_dest->getLongitude() - _lon);
155 length = sqrt(dLon * dLon + dLat * dLat);
156 _speedLat = dLat / length * _speedRadian;
157 _speedLon = dLon / length * _speedRadian / cos(_lat + _speedLat);
158 // Check for invalid speeds when a division by zero occurs due to near-zero values
159 if (!(_speedLon == _speedLon) || !(_speedLat == _speedLat))
160 {
161 _speedLon = 0;
162 _speedLat = 0;
163 }
164 }
165 else
166 {
167 _speedLon = 0;
168 _speedLat = 0;
169 }
170}
171
172/**
173 * Checks if the moving target has reached its destination.

Callers

nothing calls this directly

Calls 2

getLongitudeMethod · 0.45
getLatitudeMethod · 0.45

Tested by

no test coverage detected