Line data Source code
1 : /* 2 : * location.cpp 3 : * Copyright (C) Andrew Tridgell 2011 4 : * 5 : * This file is free software: you can redistribute it and/or modify it 6 : * under the terms of the GNU General Public License as published by the 7 : * Free Software Foundation, either version 3 of the License, or 8 : * (at your option) any later version. 9 : * 10 : * This file is distributed in the hope that it will be useful, but 11 : * WITHOUT ANY WARRANTY; without even the implied warranty of 12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 : * See the GNU General Public License for more details. 14 : * 15 : * You should have received a copy of the GNU General Public License along 16 : * with this program. If not, see <http://www.gnu.org/licenses/>. 17 : */ 18 : 19 : /* 20 : * this module deals with calculations involving locations 21 : */ 22 : #include <stdlib.h> 23 : #include "AP_Math.h" 24 : #include "location.h" 25 : 26 : // return bearing_rad in radians between two positions 27 850793 : float get_bearing_rad(const Vector2f &origin, const Vector2f &destination) 28 : { 29 850793 : return wrap_2PI(atan2f(destination.y - origin.y, destination.x - origin.x)); 30 : } 31 : 32 : // return bearing_cd in centi-degrees between two positions 33 460030 : float get_bearing_cd(const Vector2f &origin, const Vector2f &destination) 34 : { 35 460030 : return rad_to_cd(get_bearing_rad(origin, destination)); 36 : } 37 : 38 : // return true when lat and lng are within range 39 9 : bool check_lat(float lat) 40 : { 41 9 : return fabsf(lat) <= 90; 42 : } 43 9 : bool check_lng(float lng) 44 : { 45 9 : return fabsf(lng) <= 180; 46 : } 47 19933 : bool check_lat(int32_t lat) 48 : { 49 19933 : return labs(lat) <= 90*1e7; 50 : } 51 19930 : bool check_lng(int32_t lng) 52 : { 53 19930 : return labs(lng) <= 180*1e7; 54 : } 55 0 : bool check_latlng(float lat, float lng) 56 : { 57 0 : return check_lat(lat) && check_lng(lng); 58 : } 59 4465 : bool check_latlng(int32_t lat, int32_t lng) 60 : { 61 4465 : return check_lat(lat) && check_lng(lng); 62 : } 63 :