File indexing completed on 2024-12-08 10:16:04
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef OSM_GEOMATH_H 0008 #define OSM_GEOMATH_H 0009 0010 #include "datatypes.h" 0011 0012 #include <cmath> 0013 0014 namespace OSM { 0015 0016 /** Degree to radian conversion. */ 0017 constexpr inline double degToRad(double deg) 0018 { 0019 return deg / 180.0 * M_PI; 0020 } 0021 /** Radian to degree conversion. */ 0022 constexpr inline double radToDeg(double rad) 0023 { 0024 return rad / M_PI * 180.0; 0025 } 0026 0027 /** Distance between two coordinates. */ 0028 double distance(double lat1, double lon1, double lat2, double lon2); 0029 0030 /** Distance between @p coord1 and @p coord2 in meter. */ 0031 double distance(Coordinate coord1, Coordinate coord2); 0032 0033 /** Distance in meters between a line segment defined by @p l1 and @p l2 to a point @p p. */ 0034 double distance(Coordinate l1, Coordinate l2, Coordinate p); 0035 0036 /** Distance between the given polygon and coordinate, in meter. */ 0037 double distance(const std::vector<const OSM::Node*> &path, Coordinate coord); 0038 0039 } 0040 0041 #endif // OSM_GEOMATH_H